本文整理汇总了C++中clang::ASTContext类的典型用法代码示例。如果您正苦于以下问题:C++ ASTContext类的具体用法?C++ ASTContext怎么用?C++ ASTContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ASTContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: lineBasedShouldSuppress
bool lineBasedShouldSuppress(int beginLine, clang::ASTContext &context)
{
std::string filePath = getMainFilePath(context);
auto commentLinesIt = singleLineMapping.find(filePath);
std::set<int> commentLines;
if (commentLinesIt == singleLineMapping.end())
{
clang::RawCommentList commentList = context.getRawCommentList();
clang::ArrayRef<clang::RawComment *> commentArray = commentList.getComments();
for (auto comment : commentArray)
{
if (std::string::npos !=
comment->getRawText(context.getSourceManager()).find("//!OCLINT"))
{
clang::SourceLocation startLocation = comment->getLocStart();
int startLocationLine =
context.getSourceManager().getPresumedLineNumber(startLocation);
commentLines.insert(startLocationLine);
}
}
singleLineMapping[filePath] = commentLines;
}
else
{
commentLines = commentLinesIt->second;
}
return commentLines.find(beginLine) != commentLines.end();
}
示例2: getClangMetatypeType
static clang::CanQualType getClangMetatypeType(
const clang::ASTContext &clangCtx) {
clang::QualType clangType =
clangCtx.getObjCObjectType(clangCtx.ObjCBuiltinClassTy, 0, 0);
clangType = clangCtx.getObjCObjectPointerType(clangType);
return clangCtx.getCanonicalType(clangType);
}
示例3: StreamArr
static void StreamArr(llvm::raw_ostream& o, const void* V, clang::QualType Ty,
clang::ASTContext& C) {
const clang::ArrayType* ArrTy = Ty->getAsArrayTypeUnsafe();
clang::QualType ElementTy = ArrTy->getElementType();
if (ElementTy->isCharType())
StreamCharPtr(o, (const char*)V);
else if (Ty->isConstantArrayType()) {
// Stream a constant array by streaming up to 5 elements.
const clang::ConstantArrayType* CArrTy
= C.getAsConstantArrayType(Ty);
const llvm::APInt& APSize = CArrTy->getSize();
size_t ElBytes = C.getTypeSize(ElementTy) / C.getCharWidth();
size_t Size = (size_t)APSize.getZExtValue();
o << "{ ";
for (size_t i = 0; i < Size; ++i) {
StreamValue(o, (const char*) V + i * ElBytes, ElementTy, C);
if (i + 1 < Size) {
if (i == 4) {
o << "...";
break;
}
else o << ", ";
}
}
o << " }";
} else
StreamPtr(o, V);
}
示例4: getClangIdType
static clang::CanQualType getClangIdType(
const clang::ASTContext &clangCtx) {
clang::QualType clangType =
clangCtx.getObjCObjectType(clangCtx.ObjCBuiltinIdTy, nullptr, 0);
clangType = clangCtx.getObjCObjectPointerType(clangType);
return clangCtx.getCanonicalType(clangType);
}
示例5: getClangDecayedVaListType
static clang::CanQualType getClangDecayedVaListType(
const clang::ASTContext &clangCtx) {
clang::QualType clangType =
clangCtx.getCanonicalType(clangCtx.getBuiltinVaListType());
if (clangType->isConstantArrayType())
clangType = clangCtx.getDecayedType(clangType);
return clangCtx.getCanonicalType(clangType);
}
示例6: getClangVectorType
static clang::CanQualType getClangVectorType(const clang::ASTContext &ctx,
clang::BuiltinType::Kind eltKind,
clang::VectorType::VectorKind vecKind,
StringRef numEltsString) {
unsigned numElts;
bool failedParse = numEltsString.getAsInteger<unsigned>(10, numElts);
assert(!failedParse && "vector type name didn't end in count?");
(void) failedParse;
auto eltTy = getClangBuiltinTypeFromKind(ctx, eltKind);
auto vecTy = ctx.getVectorType(eltTy, numElts, vecKind);
return ctx.getCanonicalType(vecTy);
}
示例7: HandleTranslationUnit
virtual void HandleTranslationUnit(clang::ASTContext &ctx)
{
llvm::raw_ostream &out = llvm::errs();
clang::TranslationUnitDecl *translationUnit = ctx.getTranslationUnitDecl();
MyDeclVisitor(out, _astinfo).Visit(translationUnit);
}
示例8: markedParentsAsSuppress
bool markedParentsAsSuppress(const T &node, clang::ASTContext &context, oclint::RuleBase *rule)
{
const auto &parents = context.getParents(node);
if (parents.empty())
{
return false;
}
clang::ast_type_traits::DynTypedNode dynTypedNode = parents.front();
const clang::Decl *aDecl = dynTypedNode.get<clang::Decl>();
if (aDecl)
{
if (markedAsSuppress(aDecl, rule))
{
return true;
}
return markedParentsAsSuppress(*aDecl, context, rule);
}
const clang::Stmt *aStmt = dynTypedNode.get<clang::Stmt>();
if (aStmt)
{
return markedParentsAsSuppress(*aStmt, context, rule);
}
return false;
}
示例9: HandleTranslationUnit
void HandleTranslationUnit(clang::ASTContext &astContext) override {
const auto &sourceManager = astContext.getSourceManager();
const auto cursorSourceLocation = sourceManager.translateLineCol(sourceManager.getMainFileID(),
line,
column);
if (cursorSourceLocation.isValid())
collectUnifiedSymbolResoltions(astContext, cursorSourceLocation);
}
示例10: ExitIfError
void ExitIfError(clang::ASTContext &Context)
{
DiagnosticsEngine & diags = Context.getDiagnostics();
if (diags.hasErrorOccurred()) {
unsigned DiagID = diags.getCustomDiagID(DiagnosticsEngine::Fatal,
"previous errors prevent further compilation");
diags.Report(DiagID);
exit(1);
}
}
示例11: HandleTranslationUnit
void ReplaceArrayAccessWithIndex::HandleTranslationUnit(clang::ASTContext &Ctx)
{
TransAssert(Collector && "NULL Collector");
Collector->TraverseDecl(Ctx.getTranslationUnitDecl());
if (QueryInstanceOnly)
return;
if (TransformationCounter > ValidInstanceNum) {
TransError = TransMaxInstanceError;
return;
}
Ctx.getDiagnostics().setSuppressAllDiagnostics(false);
doRewrite();
if (Ctx.getDiagnostics().hasErrorOccurred() ||
Ctx.getDiagnostics().hasFatalErrorOccurred())
TransError = TransInternalError;
}
示例12: checkAndAnalyze
void WebCLConsumer::checkAndAnalyze(clang::ASTContext &context)
{
clang::TranslationUnitDecl *decl = context.getTranslationUnitDecl();
for (Visitors::iterator i = visitors_.begin(); i != visitors_.end(); ++i) {
// There is no point to continue if an error has been reported.
if (!hasErrors(context)) {
WebCLVisitor *visitor = (*i);
visitor->TraverseDecl(decl);
}
}
}
示例13: GetTokenBeforeLocation
clang::Token GetTokenBeforeLocation(clang::SourceLocation loc,
const clang::ASTContext& ast_context) {
clang::Token token;
token.setKind(clang::tok::unknown);
clang::LangOptions lang_options = ast_context.getLangOpts();
const clang::SourceManager& source_manager = ast_context.getSourceManager();
clang::SourceLocation file_start_loc =
source_manager.getLocForStartOfFile(source_manager.getFileID(loc));
loc = loc.getLocWithOffset(-1);
while (loc != file_start_loc) {
loc = clang::Lexer::GetBeginningOfToken(loc, source_manager, lang_options);
if (!clang::Lexer::getRawToken(loc, token, source_manager, lang_options)) {
if (!token.is(clang::tok::comment)) {
break;
}
}
loc = loc.getLocWithOffset(-1);
}
return token;
}
示例14:
PPIncludeCallback::PPIncludeCallback(
ParserContext& ctx_,
clang::ASTContext& astContext_,
MangledNameCache& mangledNameCache_,
clang::Preprocessor&) :
_ctx(ctx_),
_cppSourceType("CPP"),
_clangSrcMgr(astContext_.getSourceManager()),
_fileLocUtil(astContext_.getSourceManager()),
_mangledNameCache(mangledNameCache_)
{
}
示例15: collect
RangeSet collect(clang::ASTContext &astContext, oclint::RuleBase *rule)
{
_rule = rule;
_sourceManager = &astContext.getSourceManager();
_range.clear();
clang::DeclContext *decl = astContext.getTranslationUnitDecl();
for (clang::DeclContext::decl_iterator declIt = decl->decls_begin(),
declEnd = decl->decls_end(); declIt != declEnd; ++declIt)
{
clang::SourceLocation startLocation = (*declIt)->getLocStart();
if (startLocation.isValid() &&
_sourceManager->getMainFileID() == _sourceManager->getFileID(startLocation))
{
(void) /* explicitly ignore the return of this function */
clang::RecursiveASTVisitor<DeclAnnotationRangeCollector>::TraverseDecl(*declIt);
}
}
return _range;
}