本文整理汇总了C++中SourceFile::getBufferID方法的典型用法代码示例。如果您正苦于以下问题:C++ SourceFile::getBufferID方法的具体用法?C++ SourceFile::getBufferID怎么用?C++ SourceFile::getBufferID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SourceFile
的用法示例。
在下文中一共展示了SourceFile::getBufferID方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: printUntilFirstDeclStarts
static void printUntilFirstDeclStarts(SourceFile &File, ASTPrinter &Printer) {
if (!File.getBufferID().hasValue())
return;
auto BufferID = *File.getBufferID();
auto &SM = File.getASTContext().SourceMgr;
CharSourceRange TextRange = SM.getRangeForBuffer(BufferID);
auto DeclStartLoc = getDeclStartPosition(File);
if (DeclStartLoc.isValid()) {
TextRange = CharSourceRange(SM, TextRange.getStart(), DeclStartLoc);
}
Printer << SM.extractText(TextRange, BufferID);
}
示例2: walker
std::pair<LineRange, std::string> swift::ide::reformat(LineRange Range,
CodeFormatOptions Options,
SourceManager &SM,
SourceFile &SF) {
FormatWalker walker(SF, SM);
auto SourceBufferID = SF.getBufferID().getValue();
StringRef Text = SM.getLLVMSourceMgr()
.getMemoryBuffer(SourceBufferID)->getBuffer();
size_t Offset = getOffsetOfTrimmedLine(Range.startLine(), Text);
SourceLoc Loc = SM.getLocForBufferStart(SourceBufferID)
.getAdvancedLoc(Offset);
FormatContext FC = walker.walkToLocation(Loc);
CodeFormatter CF(Options);
return CF.indent(Range.startLine(), FC, Text);
}
示例3: performCompile
//.........这里部分代码省略.........
debugFailWithCrash();
ASTContext &Context = Instance->getASTContext();
if (Action == FrontendOptions::REPL) {
runREPL(*Instance, ProcessCmdLine(Args.begin(), Args.end()),
Invocation.getParseStdlib());
return Context.hadError();
}
SourceFile *PrimarySourceFile = Instance->getPrimarySourceFile();
// We've been told to dump the AST (either after parsing or type-checking,
// which is already differentiated in CompilerInstance::performSema()),
// so dump or print the main source file and return.
if (Action == FrontendOptions::DumpParse ||
Action == FrontendOptions::DumpAST ||
Action == FrontendOptions::PrintAST ||
Action == FrontendOptions::DumpScopeMaps ||
Action == FrontendOptions::DumpTypeRefinementContexts ||
Action == FrontendOptions::DumpInterfaceHash) {
SourceFile *SF = PrimarySourceFile;
if (!SF) {
SourceFileKind Kind = Invocation.getSourceFileKind();
SF = &Instance->getMainModule()->getMainSourceFile(Kind);
}
if (Action == FrontendOptions::PrintAST)
SF->print(llvm::outs(), PrintOptions::printEverything());
else if (Action == FrontendOptions::DumpScopeMaps) {
ASTScope &scope = SF->getScope();
if (opts.DumpScopeMapLocations.empty()) {
scope.expandAll();
} else if (auto bufferID = SF->getBufferID()) {
SourceManager &sourceMgr = Instance->getSourceMgr();
// Probe each of the locations, and dump what we find.
for (auto lineColumn : opts.DumpScopeMapLocations) {
SourceLoc loc = sourceMgr.getLocForLineCol(*bufferID,
lineColumn.first,
lineColumn.second);
if (loc.isInvalid()) continue;
llvm::errs() << "***Scope at " << lineColumn.first << ":"
<< lineColumn.second << "***\n";
auto locScope = scope.findInnermostEnclosingScope(loc);
locScope->print(llvm::errs(), 0, false, false);
// Dump the AST context, too.
if (auto dc = locScope->getDeclContext()) {
dc->printContext(llvm::errs());
}
// Grab the local bindings introduced by this scope.
auto localBindings = locScope->getLocalBindings();
if (!localBindings.empty()) {
llvm::errs() << "Local bindings: ";
interleave(localBindings.begin(), localBindings.end(),
[&](ValueDecl *value) {
llvm::errs() << value->getFullName();
},
[&]() {
llvm::errs() << " ";
});
llvm::errs() << "\n";
}
}