本文整理汇总了C++中SourceManager::getFilename方法的典型用法代码示例。如果您正苦于以下问题:C++ SourceManager::getFilename方法的具体用法?C++ SourceManager::getFilename怎么用?C++ SourceManager::getFilename使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SourceManager
的用法示例。
在下文中一共展示了SourceManager::getFilename方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PrintExpected
/// Takes a list of diagnostics that were expected to have been generated
/// but were not and produces a diagnostic to the user from this.
static unsigned PrintExpected(DiagnosticsEngine &Diags,
SourceManager &SourceMgr,
std::vector<Directive *> &DL, const char *Kind) {
if (DL.empty())
return 0;
SmallString<256> Fmt;
llvm::raw_svector_ostream OS(Fmt);
for (const auto *D : DL) {
if (D->DiagnosticLoc.isInvalid())
OS << "\n File *";
else
OS << "\n File " << SourceMgr.getFilename(D->DiagnosticLoc);
if (D->MatchAnyLine)
OS << " Line *";
else
OS << " Line " << SourceMgr.getPresumedLineNumber(D->DiagnosticLoc);
if (D->DirectiveLoc != D->DiagnosticLoc)
OS << " (directive at "
<< SourceMgr.getFilename(D->DirectiveLoc) << ':'
<< SourceMgr.getPresumedLineNumber(D->DirectiveLoc) << ')';
OS << ": " << D->Text;
}
Diags.Report(diag::err_verify_inconsistent_diags).setForceEmit()
<< Kind << /*Unexpected=*/false << OS.str();
return DL.size();
}
示例2: Message
ClangTidyMessage::ClangTidyMessage(StringRef Message,
const SourceManager &Sources,
SourceLocation Loc)
: Message(Message) {
FilePath = Sources.getFilename(Loc);
FileOffset = Sources.getFileOffset(Loc);
}
示例3: Message
ClangTidyMessage::ClangTidyMessage(StringRef Message,
const SourceManager &Sources,
SourceLocation Loc)
: Message(Message) {
assert(Loc.isValid() && Loc.isFileID());
FilePath = Sources.getFilename(Loc);
FileOffset = Sources.getFileOffset(Loc);
}
示例4: toString
std::string toString(SourceManager& sourceManager, SourceLocation loc) {
//return loc.printToString(sourceManager);
std::string fileName = sourceManager.getFilename(loc).str();
if (fileName.length() > 30)
fileName = fileName.substr(fileName.length() - 30);
std::ostringstream os;
os << fileName << ":" <<
sourceManager.getExpansionLineNumber(loc) << ":" <<
sourceManager.getExpansionColumnNumber(loc);
return os.str();
}
示例5: createSourceRangeForStmt
template <typename T> FullSourceRange createSourceRangeForStmt(const T *S, SourceManager &sourceManager) {
FullSourceRange sourceRange;
sourceRange.startingLineNumber = sourceManager.getSpellingLineNumber(S->getLocStart());
sourceRange.endingLineNumber = sourceManager.getSpellingLineNumber(S->getLocEnd());
sourceRange.startingColumnNumber = sourceManager.getSpellingColumnNumber(S->getLocStart());
sourceRange.endingColumnNumber = sourceManager.getSpellingColumnNumber(S->getLocEnd());
sourceRange.filePath = sourceManager.getFilename(sourceManager.getSpellingLoc(S->getLocStart()));
return sourceRange;
}
示例6: PrintExpected
/// \brief Takes a list of diagnostics that were expected to have been generated
/// but were not and produces a diagnostic to the user from this.
static unsigned PrintExpected(DiagnosticsEngine &Diags, SourceManager &SourceMgr,
DirectiveList &DL, const char *Kind) {
if (DL.empty())
return 0;
SmallString<256> Fmt;
llvm::raw_svector_ostream OS(Fmt);
for (DirectiveList::iterator I = DL.begin(), E = DL.end(); I != E; ++I) {
Directive &D = **I;
OS << "\n File " << SourceMgr.getFilename(D.DiagnosticLoc)
<< " Line " << SourceMgr.getPresumedLineNumber(D.DiagnosticLoc);
if (D.DirectiveLoc != D.DiagnosticLoc)
OS << " (directive at "
<< SourceMgr.getFilename(D.DirectiveLoc) << ':'
<< SourceMgr.getPresumedLineNumber(D.DirectiveLoc) << ')';
OS << ": " << D.Text;
}
Diags.Report(diag::err_verify_inconsistent_diags).setForceEmit()
<< Kind << /*Unexpected=*/false << OS.str();
return DL.size();
}
示例7: FindSymbol
bool FindSymbol(ASTContext &Context, const SourceManager &SourceMgr,
unsigned SymbolOffset, const std::string &QualifiedName) {
DiagnosticsEngine &Engine = Context.getDiagnostics();
const SourceLocation Point =
SourceMgr.getLocForStartOfFile(SourceMgr.getMainFileID())
.getLocWithOffset(SymbolOffset);
if (!Point.isValid()) {
ErrorOccurred = true;
unsigned InvalidOffset = Engine.getCustomDiagID(
DiagnosticsEngine::Error,
"SourceLocation in file %0 at offset %1 is invalid");
Engine.Report(Point, InvalidOffset) << SourceMgr.getFilename(Point)
<< SymbolOffset;
return false;
}
const NamedDecl *FoundDecl = QualifiedName.empty()
? getNamedDeclAt(Context, Point)
: getNamedDeclFor(Context, QualifiedName);
if (FoundDecl == nullptr) {
if (QualifiedName.empty()) {
FullSourceLoc FullLoc(Point, SourceMgr);
unsigned CouldNotFindSymbolAt = Engine.getCustomDiagID(
DiagnosticsEngine::Error,
"clang-rename could not find symbol (offset %0)");
Engine.Report(Point, CouldNotFindSymbolAt) << SymbolOffset;
ErrorOccurred = true;
return false;
}
unsigned CouldNotFindSymbolNamed = Engine.getCustomDiagID(
DiagnosticsEngine::Error, "clang-rename could not find symbol %0");
Engine.Report(CouldNotFindSymbolNamed) << QualifiedName;
ErrorOccurred = true;
return false;
}
// If FoundDecl is a constructor or destructor, we want to instead take
// the Decl of the corresponding class.
if (const auto *CtorDecl = dyn_cast<CXXConstructorDecl>(FoundDecl))
FoundDecl = CtorDecl->getParent();
else if (const auto *DtorDecl = dyn_cast<CXXDestructorDecl>(FoundDecl))
FoundDecl = DtorDecl->getParent();
SpellingNames.push_back(FoundDecl->getNameAsString());
AdditionalUSRFinder Finder(FoundDecl, Context);
USRList.push_back(Finder.Find());
return true;
}
示例8: VisitCallExpr
bool VisitCallExpr(CallExpr* call) {
//outs() << "do found" << "\n";
NamedDecl* calleedecl = (NamedDecl*)call->getCalleeDecl();
if (calleedecl != NULL) {
//ignore macro expansion
SourceLocation loc = call->getLocStart();
if (!sm->isInMainFile(loc))
return true;
if (call->getCalleeDecl()->isFunctionOrFunctionTemplate()) {
SourceRange sr = call->getCalleeDecl()->getAsFunction()->getSourceRange();
SourceLocation start_pos = sr.getBegin();
if (!start_pos.isValid()) {
//outs() << "error: invalid location." << "\n";
//outfile << "error: invalid location." << "\n";
return true;
}
else {
StringRef headerFilename = sm->getFilename(start_pos);
string fullheaderfile = headerFilename.str();
if (fullheaderfile == "")
return true;
if (fullheaderfile.find(project_name) < fullheaderfile.length())
return true;
if (fullheaderfile[0] != '/')
return true;
/*
int i;
for (i = fullheaderfile.length() - 1; i >=0; i--)
if (fullheaderfile[i] == '/')
break;
string headerfile;
if (fullheaderfile.substr(fullheaderfile.length()-2, 2) == ".h")
headerfile = fullheaderfile.substr(i+1, fullheaderfile.length() - i - 3);
else
headerfile = fullheaderfile.substr(i+1, fullheaderfile.length() - i - 1);
bool flag = false;
for (int j = 0; j < API_NUM; j++)
{
bool flag2 = true;
for (int k = 0; k < headerfile.length(); k++){
if (headerfile[k] != APIList[j][k])
flag2 = false;
}
if (flag2 == true){
flag = true;
}
}
if (!flag)
return true;
*/
}
}
else {
//return true;
}
outs() << "Found " << calleedecl->getQualifiedNameAsString() <<" at: ";
//outfile << "Found " << calleedecl->getQualifiedNameAsString() <<" at: ";
string s = calleedecl->getQualifiedNameAsString();
qualified_name = "";
short_name = "";
unsigned int pos = s.length()-1;
while (pos > 0) {
if (s[pos] == ':' && s[pos-1] == ':')
break;
pos--;
}
if (pos == 0)
pos = -1;
short_name = s.substr(pos+1, s.length()-pos-1);
int mark = 0;
for (unsigned int i = 0; i < s.length(); i++) {
if (s[i] == ',')
s[i] = ';';
if (s[i] == '<') {
mark ++;
}
if (i > 0) {
if (s[i-1] == '>') {
mark --;
}
}
if (mark == 0 || i >= pos+1)
qualified_name = qualified_name + s[i];
}
StringRef filename = sm->getFilename(loc);
//unsigned int col = sm->getSpellingColumnNumber(loc);
//unsigned int line = sm->getSpellingLineNumber(loc);
outs() << filename << "\n";
//file_name = filename.str();
//outfile << filename.str() << "\n";
//outfile <<filename.str();
//outs() << ", line: " <<line<< " column: " << col << "\n";
//outfile << ", line: " <<line<< " column: " << col << "\n";
//get parent function
if (CurrentFunc != NULL) {
SourceRange sr = CurrentFunc->getSourceRange();
//.........这里部分代码省略.........