本文整理汇总了C++中TranslationUnitDecl类的典型用法代码示例。如果您正苦于以下问题:C++ TranslationUnitDecl类的具体用法?C++ TranslationUnitDecl怎么用?C++ TranslationUnitDecl使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TranslationUnitDecl类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
}
}
示例2: VarRenamer
bool FlattenCFGTransformer::execute() {
this->renamer = new VarRenamer(this->resMgr);
this->preTranser = new StmtPretransformer(this->resMgr);
OwningPtr<RefVarToPtrMap> refMap(new RefVarToPtrMap(0));
assert(refMap.get() && "reference variable map alloc failed");
this->dclMover = new LocalDeclMover(this->resMgr, refMap.get());
this->flat = new CFGFlattener(this->resMgr);
TranslationUnitDecl *decls = this->resMgr.getCompilerInstance().getASTContext().getTranslationUnitDecl();
for(TranslationUnitDecl::decl_iterator I = decls->decls_begin(), E = decls->decls_end();
I != E; ++I) {
Decl *D = *I;
DPRINT("TUDecl %s %x | Ctx %x -> p %x", D->getDeclKindName(), (unsigned int)D, (unsigned int)D->getDeclContext(), (unsigned int)decls);
SourceLocation Loc = D->getLocation();
if(Loc.isInvalid()
|| this->compInst.getSourceManager().isInSystemHeader(Loc)){
continue;
}
if(HandleAnyFunctionDecl(D)) {
continue;
} else if(HandleAnyClassDecl(D)) {
continue;
}
}
delete this->renamer;
delete this->preTranser;
delete this->dclMover;
delete this->flat;
refMap.reset();
return true;
}
示例3: HandleTranslationUnit
void ObjCMigrateASTConsumer::HandleTranslationUnit(ASTContext &Ctx) {
TranslationUnitDecl *TU = Ctx.getTranslationUnitDecl();
if (MigrateProperty)
for (DeclContext::decl_iterator D = TU->decls_begin(), DEnd = TU->decls_end();
D != DEnd; ++D) {
if (ObjCInterfaceDecl *CDecl = dyn_cast<ObjCInterfaceDecl>(*D))
migrateObjCInterfaceDecl(Ctx, CDecl);
else if (ObjCProtocolDecl *PDecl = dyn_cast<ObjCProtocolDecl>(*D))
ObjCProtocolDecls.insert(PDecl);
else if (const ObjCImplementationDecl *ImpDecl =
dyn_cast<ObjCImplementationDecl>(*D))
migrateProtocolConformance(Ctx, ImpDecl);
else if (const EnumDecl *ED = dyn_cast<EnumDecl>(*D)) {
DeclContext::decl_iterator N = D;
++N;
if (N != DEnd)
if (const TypedefDecl *TD = dyn_cast<TypedefDecl>(*N))
migrateNSEnumDecl(Ctx, ED, TD);
}
// migrate methods which can have instancetype as their result type.
if (ObjCContainerDecl *CDecl = dyn_cast<ObjCContainerDecl>(*D))
migrateInstanceType(Ctx, CDecl);
}
Rewriter rewriter(Ctx.getSourceManager(), Ctx.getLangOpts());
RewritesReceiver Rec(rewriter);
Editor->applyRewrites(Rec);
for (Rewriter::buffer_iterator
I = rewriter.buffer_begin(), E = rewriter.buffer_end(); I != E; ++I) {
FileID FID = I->first;
RewriteBuffer &buf = I->second;
const FileEntry *file = Ctx.getSourceManager().getFileEntryForID(FID);
assert(file);
SmallString<512> newText;
llvm::raw_svector_ostream vecOS(newText);
buf.write(vecOS);
vecOS.flush();
llvm::MemoryBuffer *memBuf = llvm::MemoryBuffer::getMemBufferCopy(
StringRef(newText.data(), newText.size()), file->getName());
SmallString<64> filePath(file->getName());
FileMgr.FixupRelativePath(filePath);
Remapper.remap(filePath.str(), memBuf);
}
if (IsOutputFile) {
Remapper.flushToFile(MigrateDir, Ctx.getDiagnostics());
} else {
Remapper.flushToDisk(MigrateDir, Ctx.getDiagnostics());
}
}
示例4: printAST
void ClangInternalState::printAST(llvm::raw_ostream& Out, ASTContext& C) {
TranslationUnitDecl* TU = C.getTranslationUnitDecl();
unsigned Indentation = 0;
bool PrintInstantiation = false;
std::string ErrMsg;
clang::PrintingPolicy policy = C.getPrintingPolicy();
TU->print(Out, policy, Indentation, PrintInstantiation);
// TODO: For future when we relpace the bump allocation with slab.
//
//Out << "Allocated memory: " << C.getAllocatedMemory();
//Out << "Side table allocated memory: " << C.getSideTableAllocatedMemory();
Out.flush();
}
示例5: getCompilerInstance
void ASTMergeAction::ExecuteAction() {
CompilerInstance &CI = getCompilerInstance();
CI.getDiagnostics().getClient()->BeginSourceFile(
CI.getASTContext().getLangOpts());
CI.getDiagnostics().SetArgToStringFn(&FormatASTNodeDiagnosticArgument,
&CI.getASTContext());
IntrusiveRefCntPtr<DiagnosticIDs>
DiagIDs(CI.getDiagnostics().getDiagnosticIDs());
for (unsigned I = 0, N = ASTFiles.size(); I != N; ++I) {
IntrusiveRefCntPtr<DiagnosticsEngine>
Diags(new DiagnosticsEngine(DiagIDs, &CI.getDiagnosticOpts(),
new ForwardingDiagnosticConsumer(
*CI.getDiagnostics().getClient()),
/*ShouldOwnClient=*/true));
std::unique_ptr<ASTUnit> Unit =
ASTUnit::LoadFromASTFile(ASTFiles[I], CI.getPCHContainerOperations(),
Diags, CI.getFileSystemOpts(), false);
if (!Unit)
continue;
ASTImporter Importer(CI.getASTContext(),
CI.getFileManager(),
Unit->getASTContext(),
Unit->getFileManager(),
/*MinimalImport=*/false);
TranslationUnitDecl *TU = Unit->getASTContext().getTranslationUnitDecl();
CI.getASTConsumer().Initialize(CI.getASTContext());
for (auto *D : TU->decls()) {
// Don't re-import __va_list_tag, __builtin_va_list.
if (const auto *ND = dyn_cast<NamedDecl>(D))
if (IdentifierInfo *II = ND->getIdentifier())
if (II->isStr("__va_list_tag") || II->isStr("__builtin_va_list"))
continue;
Decl *ToD = Importer.Import(D);
if (ToD) {
DeclGroupRef DGR(ToD);
CI.getASTConsumer().HandleTopLevelDecl(DGR);
}
}
}
AdaptedAction->ExecuteAction();
CI.getDiagnostics().getClient()->EndSourceFile();
}
示例6: getCompilerInstance
void ASTMergeAction::ExecuteAction() {
CompilerInstance &CI = getCompilerInstance();
CI.getDiagnostics().getClient()->BeginSourceFile(
CI.getASTContext().getLangOpts());
CI.getDiagnostics().SetArgToStringFn(&FormatASTNodeDiagnosticArgument,
&CI.getASTContext());
IntrusiveRefCntPtr<DiagnosticIDs>
DiagIDs(CI.getDiagnostics().getDiagnosticIDs());
for (unsigned I = 0, N = ASTFiles.size(); I != N; ++I) {
IntrusiveRefCntPtr<DiagnosticsEngine>
Diags(new DiagnosticsEngine(DiagIDs, &CI.getDiagnosticOpts(),
new ForwardingDiagnosticConsumer(
*CI.getDiagnostics().getClient()),
/*ShouldOwnClient=*/true));
ASTUnit *Unit = ASTUnit::LoadFromASTFile(ASTFiles[I], Diags,
CI.getFileSystemOpts(), false);
if (!Unit)
continue;
ASTImporter Importer(CI.getASTContext(),
CI.getFileManager(),
Unit->getASTContext(),
Unit->getFileManager(),
/*MinimalImport=*/false);
TranslationUnitDecl *TU = Unit->getASTContext().getTranslationUnitDecl();
for (DeclContext::decl_iterator D = TU->decls_begin(),
DEnd = TU->decls_end();
D != DEnd; ++D) {
// Don't re-import __va_list_tag, __builtin_va_list.
if (NamedDecl *ND = dyn_cast<NamedDecl>(*D))
if (IdentifierInfo *II = ND->getIdentifier())
if (II->isStr("__va_list_tag") || II->isStr("__builtin_va_list"))
continue;
Importer.Import(*D);
}
delete Unit;
}
AdaptedAction->ExecuteAction();
CI.getDiagnostics().getClient()->EndSourceFile();
}
示例7: HandleTranslationUnit
void ObjCMigrateASTConsumer::HandleTranslationUnit(ASTContext &Ctx) {
TranslationUnitDecl *TU = Ctx.getTranslationUnitDecl();
for (DeclContext::decl_iterator D = TU->decls_begin(), DEnd = TU->decls_end();
D != DEnd; ++D) {
if (ObjCInterfaceDecl *CDecl = dyn_cast<ObjCInterfaceDecl>(*D))
migrateObjCInterfaceDecl(Ctx, CDecl);
}
Rewriter rewriter(Ctx.getSourceManager(), Ctx.getLangOpts());
RewritesReceiver Rec(rewriter);
Editor->applyRewrites(Rec);
for (Rewriter::buffer_iterator
I = rewriter.buffer_begin(), E = rewriter.buffer_end(); I != E; ++I) {
FileID FID = I->first;
RewriteBuffer &buf = I->second;
const FileEntry *file = Ctx.getSourceManager().getFileEntryForID(FID);
assert(file);
SmallString<512> newText;
llvm::raw_svector_ostream vecOS(newText);
buf.write(vecOS);
vecOS.flush();
llvm::MemoryBuffer *memBuf = llvm::MemoryBuffer::getMemBufferCopy(
StringRef(newText.data(), newText.size()), file->getName());
SmallString<64> filePath(file->getName());
FileMgr.FixupRelativePath(filePath);
Remapper.remap(filePath.str(), memBuf);
}
if (IsOutputFile) {
Remapper.flushToFile(MigrateDir, Ctx.getDiagnostics());
} else {
Remapper.flushToDisk(MigrateDir, Ctx.getDiagnostics());
}
}
示例8: if
//.........这里部分代码省略.........
if (Path.size() > 1) {
for (unsigned I = 1, N = Path.size(); I != N; ++I) {
StringRef Name = Path[I].first->getName();
clang::Module *Sub = Module->findSubmodule(Name);
if (!Sub) {
// Attempt to perform typo correction to find a module name that works.
llvm::SmallVector<StringRef, 2> Best;
unsigned BestEditDistance = (std::numeric_limits<unsigned>::max)();
for (clang::Module::submodule_iterator J = Module->submodule_begin(),
JEnd = Module->submodule_end();
J != JEnd; ++J) {
unsigned ED = Name.edit_distance((*J)->Name,
/*AllowReplacements=*/true,
BestEditDistance);
if (ED <= BestEditDistance) {
if (ED < BestEditDistance) {
Best.clear();
BestEditDistance = ED;
}
Best.push_back((*J)->Name);
}
}
// If there was a clear winner, user it.
if (Best.size() == 1) {
getDiagnostics().Report(Path[I].second,
diag::err_no_submodule_suggest)
<< Path[I].first << Module->getFullModuleName() << Best[0]
<< SourceRange(Path[0].second, Path[I-1].second)
<< FixItHint::CreateReplacement(SourceRange(Path[I].second),
Best[0]);
Sub = Module->findSubmodule(Best[0]);
}
}
if (!Sub) {
// No submodule by this name. Complain, and don't look for further
// submodules.
getDiagnostics().Report(Path[I].second, diag::err_no_submodule)
<< Path[I].first << Module->getFullModuleName()
<< SourceRange(Path[0].second, Path[I-1].second);
break;
}
Module = Sub;
}
}
// Make the named module visible, if it's not already part of the module
// we are parsing.
if (ModuleName != getLangOpts().CurrentModule) {
if (!Module->IsFromModuleFile) {
// We have an umbrella header or directory that doesn't actually include
// all of the headers within the directory it covers. Complain about
// this missing submodule and recover by forgetting that we ever saw
// this submodule.
// FIXME: Should we detect this at module load time? It seems fairly
// expensive (and rare).
getDiagnostics().Report(ImportLoc, diag::warn_missing_submodule)
<< Module->getFullModuleName()
<< SourceRange(Path.front().second, Path.back().second);
return ModuleLoadResult(0, true);
}
// Check whether this module is available.
StringRef Feature;
if (!Module->isAvailable(getLangOpts(), getTarget(), Feature)) {
getDiagnostics().Report(ImportLoc, diag::err_module_unavailable)
<< Module->getFullModuleName()
<< Feature
<< SourceRange(Path.front().second, Path.back().second);
LastModuleImportLoc = ImportLoc;
LastModuleImportResult = ModuleLoadResult();
return ModuleLoadResult();
}
ModuleManager->makeModuleVisible(Module, Visibility);
}
// If this module import was due to an inclusion directive, create an
// implicit import declaration to capture it in the AST.
if (IsInclusionDirective && hasASTContext()) {
TranslationUnitDecl *TU = getASTContext().getTranslationUnitDecl();
ImportDecl *ImportD = ImportDecl::CreateImplicit(getASTContext(), TU,
ImportLoc, Module,
Path.back().second);
TU->addDecl(ImportD);
if (Consumer)
Consumer->HandleImplicitImportDecl(ImportD);
}
LastModuleImportLoc = ImportLoc;
LastModuleImportResult = ModuleLoadResult(Module, false);
return LastModuleImportResult;
}