本文整理汇总了C++中ASTUnit类的典型用法代码示例。如果您正苦于以下问题:C++ ASTUnit类的具体用法?C++ ASTUnit怎么用?C++ ASTUnit使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ASTUnit类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: clang_getDeclObjCTypeEncoding
CXString clang_getDeclObjCTypeEncoding(CXCursor C) {
if (!clang_isDeclaration(C.kind))
return cxstring::createCXString("");
const Decl *D = static_cast<const Decl*>(C.data[0]);
ASTUnit *AU = cxcursor::getCursorASTUnit(C);
ASTContext &Ctx = AU->getASTContext();
std::string encoding;
if (const ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(D)) {
if (Ctx.getObjCEncodingForMethodDecl(OMD, encoding))
return cxstring::createCXString("?");
} else if (const ObjCPropertyDecl *OPD = dyn_cast<ObjCPropertyDecl>(D))
Ctx.getObjCEncodingForPropertyDecl(OPD, NULL, encoding);
else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
Ctx.getObjCEncodingForFunctionDecl(FD, encoding);
else {
QualType Ty;
if (const TypeDecl *TD = dyn_cast<TypeDecl>(D))
Ty = Ctx.getTypeDeclType(TD);
if (const ValueDecl *VD = dyn_cast<ValueDecl>(D))
Ty = VD->getType();
else return cxstring::createCXString("?");
Ctx.getObjCEncodingForType(Ty, encoding);
}
return cxstring::createCXString(encoding);
}
示例2: findMacroRefsInFile
static bool findMacroRefsInFile(CXTranslationUnit TU, CXCursor Cursor,
const FileEntry *File,
CXCursorAndRangeVisitor Visitor) {
if (Cursor.kind != CXCursor_MacroDefinition &&
Cursor.kind != CXCursor_MacroExpansion)
return false;
ASTUnit *Unit = cxtu::getASTUnit(TU);
SourceManager &SM = Unit->getSourceManager();
FileID FID = SM.translateFile(File);
const IdentifierInfo *Macro = 0;
if (Cursor.kind == CXCursor_MacroDefinition)
Macro = getCursorMacroDefinition(Cursor)->getName();
else
Macro = getCursorMacroExpansion(Cursor).getName();
if (!Macro)
return false;
FindFileMacroRefVisitData data(*Unit, File, Macro, Visitor);
SourceRange Range(SM.getLocForStartOfFile(FID), SM.getLocForEndOfFile(FID));
CursorVisitor FindMacroRefsVisitor(TU,
findFileMacroRefVisit, &data,
/*VisitPreprocessorLast=*/false,
/*VisitIncludedEntities=*/false,
Range);
return FindMacroRefsVisitor.visitPreprocessedEntitiesInRegion();
}
示例3:
ASTContext& CursorHelper::getASTContext(CXCursor node)
{
ASTUnit *astUnit =
static_cast<ASTUnit *>(
static_cast<CXTranslationUnit>(node.data[2])->TUData);
return astUnit->getASTContext();
}
示例4: clang_getLocation
CXSourceLocation clang_getLocation(CXTranslationUnit TU,
CXFile file,
unsigned line,
unsigned column) {
if (cxtu::isNotUsableTU(TU)) {
LOG_BAD_TU(TU);
return clang_getNullLocation();
}
if (!file)
return clang_getNullLocation();
if (line == 0 || column == 0)
return clang_getNullLocation();
LogRef Log = Logger::make(__func__);
ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
ASTUnit::ConcurrencyCheck Check(*CXXUnit);
const FileEntry *File = static_cast<const FileEntry *>(file);
SourceLocation SLoc = CXXUnit->getLocation(File, line, column);
if (SLoc.isInvalid()) {
if (Log)
*Log << llvm::format("(\"%s\", %d, %d) = invalid",
File->getName().str().c_str(), line, column);
return clang_getNullLocation();
}
CXSourceLocation CXLoc =
cxloc::translateSourceLocation(CXXUnit->getASTContext(), SLoc);
if (Log)
*Log << llvm::format("(\"%s\", %d, %d) = ", File->getName().str().c_str(),
line, column)
<< CXLoc;
return CXLoc;
}
示例5: clang_getCursorCompletionString
CXCompletionString clang_getCursorCompletionString(CXCursor cursor) {
enum CXCursorKind kind = clang_getCursorKind(cursor);
if (clang_isDeclaration(kind)) {
const Decl *decl = getCursorDecl(cursor);
if (const NamedDecl *namedDecl = dyn_cast_or_null<NamedDecl>(decl)) {
ASTUnit *unit = getCursorASTUnit(cursor);
CodeCompletionResult Result(namedDecl, CCP_Declaration);
CodeCompletionString *String
= Result.CreateCodeCompletionString(unit->getASTContext(),
unit->getPreprocessor(),
unit->getCodeCompletionTUInfo().getAllocator(),
unit->getCodeCompletionTUInfo(),
true);
return String;
}
}
else if (kind == CXCursor_MacroDefinition) {
const MacroDefinition *definition = getCursorMacroDefinition(cursor);
const IdentifierInfo *MacroInfo = definition->getName();
ASTUnit *unit = getCursorASTUnit(cursor);
CodeCompletionResult Result(MacroInfo);
CodeCompletionString *String
= Result.CreateCodeCompletionString(unit->getASTContext(),
unit->getPreprocessor(),
unit->getCodeCompletionTUInfo().getAllocator(),
unit->getCodeCompletionTUInfo(),
false);
return String;
}
return NULL;
}
示例6: lfort_getLocation
CXSourceLocation lfort_getLocation(CXProgram tu,
CXFile file,
unsigned line,
unsigned column) {
if (!tu || !file)
return lfort_getNullLocation();
bool Logging = ::getenv("LIBLFORT_LOGGING");
ASTUnit *CXXUnit = static_cast<ASTUnit *>(tu->PgmData);
ASTUnit::ConcurrencyCheck Check(*CXXUnit);
const FileEntry *File = static_cast<const FileEntry *>(file);
SourceLocation SLoc = CXXUnit->getLocation(File, line, column);
if (SLoc.isInvalid()) {
if (Logging)
llvm::errs() << "lfort_getLocation(\"" << File->getName()
<< "\", " << line << ", " << column << ") = invalid\n";
return lfort_getNullLocation();
}
if (Logging)
llvm::errs() << "lfort_getLocation(\"" << File->getName()
<< "\", " << line << ", " << column << ") = "
<< SLoc.getRawEncoding() << "\n";
return cxloc::translateSourceLocation(CXXUnit->getASTContext(), SLoc);
}
示例7: GetASTUnitForProjectFile
std::vector<ASTMemoryUsage> TranslationUnitManager::GetMemoryUsageForProjectFile(ProjectFile* file)
{
ASTUnit* tu = GetASTUnitForProjectFile(file);
std::vector<ASTMemoryUsage> usages;
if (tu)
{
//AST Context
ASTContext& ctx = tu->getASTContext();
usages.emplace_back(AST_Nodes, ctx.getASTAllocatedMemory());
usages.emplace_back(AST_Identifiers, ctx.Idents.getAllocator().getTotalMemory());
usages.emplace_back(AST_Selectors, ctx.Selectors.getTotalMemory());
usages.emplace_back(AST_SideTables, ctx.getSideTableAllocatedMemory());
//Source Manager
usages.emplace_back(SM_ContentCache, ctx.getSourceManager().getContentCacheSize());
const SourceManager::MemoryBufferSizes& srcBufs = tu->getSourceManager().getMemoryBufferSizes();
usages.emplace_back(SM_Malloc, srcBufs.malloc_bytes);
usages.emplace_back(SM_Mmap, srcBufs.mmap_bytes);
usages.emplace_back(SM_DataStructures, tu->getSourceManager().getDataStructureSizes());
// Preprocessor
Preprocessor& PP = tu->getPreprocessor();
usages.emplace_back(PP_Total, PP.getTotalMemory());
usages.emplace_back(PP_HeaderSearch, PP.getHeaderSearchInfo().getTotalMemory());
if (PP.getPreprocessorOpts().DetailedRecord)
usages.emplace_back(ASTMemoryUsage(PP_PreprocessingRecord, PP.getPreprocessingRecord()->getTotalMemory()));
}
return usages;
}
示例8: indexPreprocessingRecord
static void indexPreprocessingRecord(ASTUnit &Unit, IndexingContext &IdxCtx) {
Preprocessor &PP = Unit.getPreprocessor();
if (!PP.getPreprocessingRecord())
return;
// FIXME: Only deserialize inclusion directives.
PreprocessingRecord::iterator I, E;
std::tie(I, E) = Unit.getLocalPreprocessingEntities();
bool isModuleFile = Unit.isModuleFile();
for (; I != E; ++I) {
PreprocessedEntity *PPE = *I;
if (InclusionDirective *ID = dyn_cast<InclusionDirective>(PPE)) {
SourceLocation Loc = ID->getSourceRange().getBegin();
// Modules have synthetic main files as input, give an invalid location
// if the location points to such a file.
if (isModuleFile && Unit.isInMainFileID(Loc))
Loc = SourceLocation();
IdxCtx.ppIncludedFile(Loc, ID->getFileName(),
ID->getFile(),
ID->getKind() == InclusionDirective::Import,
!ID->wasInQuotes(), ID->importedModule());
}
}
}
示例9: clang_getDeclObjCTypeEncoding
CXString clang_getDeclObjCTypeEncoding(CXCursor C) {
if ((C.kind < CXCursor_FirstDecl) || (C.kind > CXCursor_LastDecl))
return cxstring::createCXString("");
Decl *D = static_cast<Decl*>(C.data[0]);
CXTranslationUnit TU = static_cast<CXTranslationUnit>(C.data[2]);
ASTUnit *AU = static_cast<ASTUnit*>(TU->TUData);
ASTContext &Ctx = AU->getASTContext();
std::string encoding;
if (ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(D)) {
if (Ctx.getObjCEncodingForMethodDecl(OMD, encoding))
return cxstring::createCXString("?");
} else if (ObjCPropertyDecl *OPD = dyn_cast<ObjCPropertyDecl>(D))
Ctx.getObjCEncodingForPropertyDecl(OPD, NULL, encoding);
else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
Ctx.getObjCEncodingForFunctionDecl(FD, encoding);
else {
QualType Ty;
if (TypeDecl *TD = dyn_cast<TypeDecl>(D))
Ty = Ctx.getTypeDeclType(TD);
if (ValueDecl *VD = dyn_cast<ValueDecl>(D))
Ty = VD->getType();
else return cxstring::createCXString("?");
Ctx.getObjCEncodingForType(Ty, encoding);
}
return cxstring::createCXString(encoding);
}
示例10: assert
SourceRange cxcursor::getCursorPreprocessingDirective(CXCursor C) {
assert(C.kind == CXCursor_PreprocessingDirective);
SourceRange Range(SourceLocation::getFromPtrEncoding(C.data[0]),
SourceLocation::getFromPtrEncoding(C.data[1]));
ASTUnit *TU = getCursorASTUnit(C);
return TU->mapRangeFromPreamble(Range);
}
示例11: indexTranslationUnit
static void indexTranslationUnit(ASTUnit &Unit, IndexingContext &IdxCtx) {
// FIXME: Only deserialize stuff from the last chained PCH, not the PCH/Module
// that it depends on.
bool OnlyLocal = !Unit.isMainFileAST() && Unit.getOnlyLocalDecls();
if (OnlyLocal) {
for (ASTUnit::top_level_iterator TL = Unit.top_level_begin(),
TLEnd = Unit.top_level_end();
TL != TLEnd; ++TL) {
IdxCtx.indexTopLevelDecl(*TL);
if (IdxCtx.shouldAbort())
return;
}
} else {
TranslationUnitDecl *TUDecl = Unit.getASTContext().getTranslationUnitDecl();
for (TranslationUnitDecl::decl_iterator
I = TUDecl->decls_begin(), E = TUDecl->decls_end(); I != E; ++I) {
IdxCtx.indexTopLevelDecl(*I);
if (IdxCtx.shouldAbort())
return;
}
}
}
示例12: indexPreprocessingRecord
static void indexPreprocessingRecord(ASTUnit &Unit, IndexingContext &IdxCtx) {
Preprocessor &PP = Unit.getPreprocessor();
if (!PP.getPreprocessingRecord())
return;
PreprocessingRecord &PPRec = *PP.getPreprocessingRecord();
// FIXME: Only deserialize inclusion directives.
// FIXME: Only deserialize stuff from the last chained PCH, not the PCH/Module
// that it depends on.
bool OnlyLocal = !Unit.isMainFileAST() && Unit.getOnlyLocalDecls();
PreprocessingRecord::iterator I, E;
if (OnlyLocal) {
I = PPRec.local_begin();
E = PPRec.local_end();
} else {
I = PPRec.begin();
E = PPRec.end();
}
for (; I != E; ++I) {
PreprocessedEntity *PPE = *I;
if (InclusionDirective *ID = dyn_cast<InclusionDirective>(PPE)) {
IdxCtx.ppIncludedFile(ID->getSourceRange().getBegin(), ID->getFileName(),
ID->getFile(), ID->getKind() == InclusionDirective::Import,
!ID->wasInQuotes());
}
}
}
示例13: clang_indexTranslationUnit_Impl
static void clang_indexTranslationUnit_Impl(void *UserData) {
IndexTranslationUnitInfo *ITUI =
static_cast<IndexTranslationUnitInfo*>(UserData);
CXTranslationUnit TU = ITUI->TU;
CXClientData client_data = ITUI->client_data;
IndexerCallbacks *client_index_callbacks = ITUI->index_callbacks;
unsigned index_callbacks_size = ITUI->index_callbacks_size;
unsigned index_options = ITUI->index_options;
ITUI->result = 1; // init as error.
if (!TU)
return;
if (!client_index_callbacks || index_callbacks_size == 0)
return;
CIndexer *CXXIdx = (CIndexer*)TU->CIdx;
if (CXXIdx->isOptEnabled(CXGlobalOpt_ThreadBackgroundPriorityForIndexing))
setThreadBackgroundPriority();
IndexerCallbacks CB;
memset(&CB, 0, sizeof(CB));
unsigned ClientCBSize = index_callbacks_size < sizeof(CB)
? index_callbacks_size : sizeof(CB);
memcpy(&CB, client_index_callbacks, ClientCBSize);
OwningPtr<IndexingContext> IndexCtx;
IndexCtx.reset(new IndexingContext(client_data, CB, index_options, TU));
// Recover resources if we crash before exiting this method.
llvm::CrashRecoveryContextCleanupRegistrar<IndexingContext>
IndexCtxCleanup(IndexCtx.get());
OwningPtr<IndexingConsumer> IndexConsumer;
IndexConsumer.reset(new IndexingConsumer(*IndexCtx));
// Recover resources if we crash before exiting this method.
llvm::CrashRecoveryContextCleanupRegistrar<IndexingConsumer>
IndexConsumerCleanup(IndexConsumer.get());
ASTUnit *Unit = static_cast<ASTUnit *>(TU->TUData);
if (!Unit)
return;
ASTUnit::ConcurrencyCheck Check(*Unit);
FileManager &FileMgr = Unit->getFileManager();
if (Unit->getOriginalSourceFileName().empty())
IndexCtx->enteredMainFile(0);
else
IndexCtx->enteredMainFile(FileMgr.getFile(Unit->getOriginalSourceFileName()));
IndexConsumer->Initialize(Unit->getASTContext());
indexPreprocessingRecord(*Unit, *IndexCtx);
indexTranslationUnit(*Unit, *IndexCtx);
indexDiagnostics(TU, *IndexCtx);
ITUI->result = 0;
}
示例14: clang_getDiagnostic
CXDiagnostic clang_getDiagnostic(CXTranslationUnit Unit, unsigned Index) {
ASTUnit *CXXUnit = static_cast<ASTUnit *>(Unit->TUData);
if (!CXXUnit || Index >= CXXUnit->stored_diag_size())
return 0;
return new CXStoredDiagnostic(CXXUnit->stored_diag_begin()[Index],
CXXUnit->getASTContext().getLangOptions());
}
示例15: assert
SourceRange cxcursor::getCursorPreprocessingDirective(CXCursor C) {
assert(C.kind == CXCursor_PreprocessingDirective);
SourceRange Range = SourceRange(SourceLocation::getFromRawEncoding(
reinterpret_cast<uintptr_t> (C.data[0])),
SourceLocation::getFromRawEncoding(
reinterpret_cast<uintptr_t> (C.data[1])));
ASTUnit *TU = getCursorASTUnit(C);
return TU->mapRangeFromPreamble(Range);
}