当前位置: 首页>>代码示例>>C++>>正文


C++ SourceManager::getFilename方法代码示例

本文整理汇总了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();
}
开发者ID:jvesely,项目名称:clang,代码行数:30,代码来源:VerifyDiagnosticConsumer.cpp

示例2: Message

ClangTidyMessage::ClangTidyMessage(StringRef Message,
                                   const SourceManager &Sources,
                                   SourceLocation Loc)
    : Message(Message) {
  FilePath = Sources.getFilename(Loc);
  FileOffset = Sources.getFileOffset(Loc);
}
开发者ID:czchen,项目名称:clang-tools-extra,代码行数:7,代码来源:ClangTidyDiagnosticConsumer.cpp

示例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);
}
开发者ID:chee-z,项目名称:clang-tools-extra,代码行数:8,代码来源:ClangTidyDiagnosticConsumer.cpp

示例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();
}
开发者ID:slycelote,项目名称:caide-cpp-inliner,代码行数:11,代码来源:util.cpp

示例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;
}
开发者ID:parallaxe,项目名称:Macoun2014,代码行数:11,代码来源:main.cpp

示例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();
}
开发者ID:ADonut,项目名称:LLVM-GPGPU,代码行数:24,代码来源:VerifyDiagnosticConsumer.cpp

示例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;
  }
开发者ID:irods,项目名称:clang-tools-extra,代码行数:51,代码来源:USRFindingAction.cpp

示例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();
//.........这里部分代码省略.........
开发者ID:zouda,项目名称:find-source,代码行数:101,代码来源:find-source.cpp


注:本文中的SourceManager::getFilename方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。