本文整理汇总了C++中AST::getFileName方法的典型用法代码示例。如果您正苦于以下问题:C++ AST::getFileName方法的具体用法?C++ AST::getFileName怎么用?C++ AST::getFileName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AST
的用法示例。
在下文中一共展示了AST::getFileName方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: analyse
void DepGenerator::analyse(const AST& ast) {
const string& modName = ast.getModuleName();
const string& fileName = ast.getFileName();
ModInfo* info = getInfo(modName);
info->addFile(fileName, ast);
}
示例2: analyse
void TagWriter::analyse(const AST& ast) {
currentFile = getFile(ast.getFileName());
for (unsigned i=0; i<ast.numTypes(); i++) {
TagVisitor visitor(*this, ast.getType(i), SM);
visitor.run();
}
for (unsigned i=0; i<ast.numVars(); i++) {
TagVisitor visitor(*this, ast.getVar(i), SM);
visitor.run();
}
for (unsigned i=0; i<ast.numFunctions(); i++) {
TagVisitor visitor(*this, ast.getFunction(i), SM);
visitor.run();
}
// TODO TypeDecls ArrayValueDecls
}
示例3: finder
void C2Builder::rewriterTest(SourceManager& SM, LangOptions& LangOpts) {
#if 0
// FOR TESTING rename global test.aa -> bb
const std::string modName = "test";
const std::string oldName = "aa";
const std::string newName = "bb";
// Step 1a: find Module
const Module* M = 0;
const Module* mod = findModule(modName);
assert(M && "unknown module");
assert(!M->isExternal() && "cannot replace symbol in external module");
// Step 1b: find Decl
Decl* D = M->findSymbol(oldName);
assert(D && "unknown decl");
// Step 2a: replace Decl itself
Rewriter rewriter;
rewriter.setSourceMgr(SM, LangOpts);
rewriter.ReplaceText(D->getLocation(), oldName.size(), newName);
// Step 2b: replace all references
// TODO only in mainComponent
const ModuleList& mods = mainComponent->getModules();
for (unsigned m=0; m<mods.size(); m++) {
const AstList& files = mods[m]->getFiles();
for (unsigned a=0; a<files.size(); a++) {
AST* ast = files[a];
RefFinder finder(*ast, D);
unsigned count = finder.find();
if (count) printf("replaced %d references in %s\n", count, files[i]->getFileName().c_str());
for (unsigned i=0; i<count; i++) {
std::string temp = finder.locs[i].printToString(SM);
printf("loc %d -> %s\n", finder.locs[i].getRawEncoding(), temp.c_str());
PresumedLoc loc = SM.getPresumedLoc(finder.locs[i]);
assert(!loc.isInvalid() && "Invalid location");
printf(" -> %s:%d:%d\n", loc.getFilename(), loc.getLine(), loc.getColumn());
std::pair<FileID, unsigned> Off = SM.getDecomposedExpansionLoc(finder.locs[i]);
printf("-> offset %d\n", Off.second);
rewriter.ReplaceText(finder.locs[i], oldName.size(), newName);
}
}
}
// Step 3: reparse and check
// TODO
// print output
for (unsigned m=0; m<mods.size(); m++) {
const AstList& files = mods[m]->getFiles();
for (unsigned a=0; a<files.size(); a++) {
AST* ast = files[a];
const RewriteBuffer *RewriteBuf =
rewriter.getRewriteBufferFor(ast->fileID);
if (RewriteBuf) {
printf("====== %s ======\n", ast->getFileName().c_str());
llvm::outs() << std::string(RewriteBuf->begin(), RewriteBuf->end());
}
}
}
// also works!
//bool err = rewriter.overwriteChangedFiles();
//printf("errors = %d\n", err);
#endif
}