예제 #1
0
파일: Expr.cpp 프로젝트: atomontage/c2ffi
static best_guess tok_type(clang::Preprocessor &pp, const char *macro_name,
                           const clang::Token &t, StringSet *seen) {
    using namespace clang;
    tok::TokenKind k = t.getKind();

    if(k == tok::identifier) {
        IdentifierInfo *ii = t.getIdentifierInfo();
        if(ii && !seen->count(ii->getNameStart()))
            return macro_type(pp, ii->getNameStart(),
                              pp.getMacroInfo(ii), seen);

        return tok_ok;
    }

    if (k == tok::l_paren || k == tok::r_paren || k == tok::amp || k == tok::plus ||
        k == tok::star || k == tok::minus || k == tok::tilde || k == tok::slash ||
        k == tok::percent || k == tok::lessless || k == tok::greatergreater ||
        k == tok::caret || k == tok::pipe || k == tok::exclaim ||
        k == tok::kw_int || k == tok::kw_float || k == tok::kw_double ||
        k == tok::kw_long || k == tok::kw_signed || k == tok::kw_unsigned)

        return tok_ok;

    return tok_invalid;
}
예제 #2
0
static Optional<clang::QualType> builtinTypeForToken(const clang::Token &tok,
    const clang::ASTContext &context) {
  switch (tok.getKind()) {
  case clang::tok::kw_short:
    return clang::QualType(context.ShortTy);
  case clang::tok::kw_long:
    return clang::QualType(context.LongTy);
  case clang::tok::kw___int64:
    return clang::QualType(context.LongLongTy);
  case clang::tok::kw___int128:
    return clang::QualType(context.Int128Ty);
  case clang::tok::kw_signed:
    return clang::QualType(context.IntTy);
  case clang::tok::kw_unsigned:
    return clang::QualType(context.UnsignedIntTy);
  case clang::tok::kw_void:
    return clang::QualType(context.VoidTy);
  case clang::tok::kw_char:
    return clang::QualType(context.CharTy);
  case clang::tok::kw_int:
    return clang::QualType(context.IntTy);
  case clang::tok::kw_float:
    return clang::QualType(context.FloatTy);
  case clang::tok::kw_double:
    return clang::QualType(context.DoubleTy);
  case clang::tok::kw_wchar_t:
    return clang::QualType(context.WCharTy);
  case clang::tok::kw_bool:
    return clang::QualType(context.BoolTy);
  case clang::tok::kw_char16_t:
    return clang::QualType(context.Char16Ty);
  case clang::tok::kw_char32_t:
    return clang::QualType(context.Char32Ty);
  default:
    return llvm::None;
  }
}