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


C++ ASTContext::getSourceManager方法代码示例

本文整理汇总了C++中ASTContext::getSourceManager方法的典型用法代码示例。如果您正苦于以下问题:C++ ASTContext::getSourceManager方法的具体用法?C++ ASTContext::getSourceManager怎么用?C++ ASTContext::getSourceManager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ASTContext的用法示例。


在下文中一共展示了ASTContext::getSourceManager方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: InsertBracesASTConsumer

ASTConsumer *InsertBracesFrontendAction::CreateASTConsumer(
    CompilerInstance &Compiler, StringRef InFile) {
  
  ASTContext *ctx = &Compiler.getASTContext();
  rewriter = Rewriter(ctx->getSourceManager(), ctx->getLangOpts());
  return new InsertBracesASTConsumer(rewriter);
}
开发者ID:cwwwu,项目名称:AutoInstrumenter,代码行数:7,代码来源:InsertBracesFrontendAction.cpp

示例2: VisitCallExpr

    bool VisitCallExpr(CallExpr *E) {
        llvm::errs() << "I see a CallExpr\n";
        E->dump();


        Expr *callee = E->getCallee();

        if (ImplicitCastExpr *ica = llvm::dyn_cast<ImplicitCastExpr>(callee)) {
            callee = ica->getSubExpr();
        }

        if (DeclRefExpr *dref = llvm::dyn_cast<DeclRefExpr>(callee)) {
            llvm::errs() << "declref:\n";
            dref->dump();

            NamedDecl *d = dref->getFoundDecl();
            ASTContext &Context = d->getASTContext();
            SourceManager &SM = Context.getSourceManager();

            if (dref->hasQualifier()) {
                llvm::errs() << "  has qualifier in name.\n";
                NestedNameSpecifierLoc lc = dref->getQualifierLoc();

                llvm::errs() << "    begin loc: " << lc.getBeginLoc().printToString(SM)
                             << "\n";
                llvm::errs() << "    end loc: " << lc.getEndLoc().printToString(SM)
                             << "\n";
            }

            if (UsingShadowDecl *sh = llvm::dyn_cast<UsingShadowDecl>(d)) {
                NamedDecl *td = sh->getTargetDecl();
                FoundRealDecl(td);
                //d->dump();
            } else {
                FoundRealDecl(d);
                //d->dump();
            }
        } else if (UnresolvedLookupExpr *ule = dyn_cast<UnresolvedLookupExpr>(callee)) {
            llvm::errs() << "unresolved\n";
            ASTContext* Context;
            SourceManager* SM;
            for (const auto *d : ule->decls()) {
                FoundRealDecl(d);
                Context = &d->getASTContext();
                SM = &Context->getSourceManager();
            }
            llvm::errs() << "    begin loc: " << ule->getLocStart().printToString(*SM)
                         << "\n";
            llvm::errs() << "    end loc: " << ule->getLocEnd().printToString(*SM)
                         << "\n";

            NestedNameSpecifierLoc ll = ule->getQualifierLoc();
            llvm::errs() << "    nested begin loc: "
                         << ll.getBeginLoc().printToString(*SM) << "\n";
            llvm::errs() << "    nested end loc: "
                         << ll.getEndLoc().printToString(*SM) << "\n";
        }

        return true;
    }
开发者ID:hfeeki,项目名称:llvm-clang-samples,代码行数:60,代码来源:try_matcher.cpp

示例3: findTokenAfterLocation

/// \brief \arg Loc is the end of a statement range. This returns the location
/// of the token of expected type following the statement.
/// If no token of this type is found or the location is inside a macro, the returned
/// source location will be invalid.
SourceLocation findTokenAfterLocation(SourceLocation loc, ASTContext& Ctx,
        tok::TokenKind tokenType)
{
    SourceManager &SM = Ctx.getSourceManager();
    if (loc.isMacroID()) {
        if (!Lexer::isAtEndOfMacroExpansion(loc, SM, Ctx.getLangOpts(), &loc))
            return SourceLocation();
    }
    loc = Lexer::getLocForEndOfToken(loc, /*Offset=*/0, SM, Ctx.getLangOpts());

    // Break down the source location.
    std::pair<FileID, unsigned> locInfo = SM.getDecomposedLoc(loc);

    // Try to load the file buffer.
    bool invalidTemp = false;
    StringRef file = SM.getBufferData(locInfo.first, &invalidTemp);
    if (invalidTemp)
        return SourceLocation();

    const char *tokenBegin = file.data() + locInfo.second;

    // Lex from the start of the given location.
    Lexer lexer(SM.getLocForStartOfFile(locInfo.first), Ctx.getLangOpts(),
            file.begin(), tokenBegin, file.end());
    Token tok;
    lexer.LexFromRawLexer(tok);
    if (tok.isNot(tokenType))
        return SourceLocation();

    return tok.getLocation();
}
开发者ID:slycelote,项目名称:caide-cpp-inliner,代码行数:35,代码来源:util.cpp

示例4: HandleTranslationUnit

  void HandleTranslationUnit(ASTContext &Context) override {
    const auto &SourceMgr = Context.getSourceManager();
    std::vector<SourceLocation> RenamingCandidates;
    std::vector<SourceLocation> NewCandidates;

    for (const auto &USR : USRs) {
      NewCandidates = getLocationsOfUSR(USR, Context.getTranslationUnitDecl());
      RenamingCandidates.insert(RenamingCandidates.end(), NewCandidates.begin(),
                                NewCandidates.end());
      NewCandidates.clear();
    }

    auto PrevNameLen = PrevName.length();
    if (PrintLocations)
      for (const auto &Loc : RenamingCandidates) {
        FullSourceLoc FullLoc(Loc, SourceMgr);
        errs() << "clang-rename: renamed at: " << SourceMgr.getFilename(Loc)
               << ":" << FullLoc.getSpellingLineNumber() << ":"
               << FullLoc.getSpellingColumnNumber() << "\n";
        Replaces.insert(tooling::Replacement(SourceMgr, Loc, PrevNameLen,
                                             NewName));
      }
    else
      for (const auto &Loc : RenamingCandidates)
        Replaces.insert(tooling::Replacement(SourceMgr, Loc, PrevNameLen,
                                             NewName));
  }
开发者ID:DanielJump,项目名称:swang,代码行数:27,代码来源:RenamingAction.cpp

示例5: HandleOneRename

  void HandleOneRename(ASTContext &Context, const std::string &NewName,
                       const std::string &PrevName,
                       const std::vector<std::string> &USRs) {
    const SourceManager &SourceMgr = Context.getSourceManager();

    SymbolOccurrences Occurrences = tooling::getOccurrencesOfUSRs(
        USRs, PrevName, Context.getTranslationUnitDecl());
    if (PrintLocations) {
      for (const auto &Occurrence : Occurrences) {
        FullSourceLoc FullLoc(Occurrence.getNameRanges()[0].getBegin(),
                              SourceMgr);
        errs() << "clang-rename: renamed at: " << SourceMgr.getFilename(FullLoc)
               << ":" << FullLoc.getSpellingLineNumber() << ":"
               << FullLoc.getSpellingColumnNumber() << "\n";
      }
    }
    // FIXME: Support multi-piece names.
    // FIXME: better error handling (propagate error out).
    StringRef NewNameRef = NewName;
    Expected<std::vector<AtomicChange>> Change =
        createRenameReplacements(Occurrences, SourceMgr, NewNameRef);
    if (!Change) {
      llvm::errs() << "Failed to create renaming replacements for '" << PrevName
                   << "'! " << llvm::toString(Change.takeError()) << "\n";
      return;
    }
    convertChangesToFileReplacements(*Change, &FileToReplaces);
  }
开发者ID:hfinkel,项目名称:clang-bgq,代码行数:28,代码来源:RenamingAction.cpp

示例6: renameLocation

void SynthesizeRemovalConsumer::renameLocation(SourceLocation L,
  std::string& N) {
  if (L.isMacroID()) {        
    // TODO: emit error using diagnostics
    SourceManager &SM = astContext->getSourceManager();
    if (SM.isMacroArgExpansion(L) || SM.isInSystemMacro(L)) {
      // see if it's the macro expansion we can handle
      // e.g.
      //   #define call(x) x
      //   call(y());   // if we want to rename y()
      L = SM.getSpellingLoc(L);
      
      // this falls through to the rename routine below
    }
    else {
      // if the spelling location is from an actual file that we can
      // touch, then do the replacement, but show a warning          
      SourceManager &SM = astContext->getSourceManager();
      auto SL = SM.getSpellingLoc(L);
      FullSourceLoc FSL(SL, SM);
      const FileEntry *FE = SM.getFileEntryForID(FSL.getFileID());
      if (FE) {
        llvm::errs() << "Warning: Rename attempted as a result of macro "
                     << "expansion may break things, at: " << loc(L) << "\n";            
        L = SL;
        // this falls through to the rename routine below
      }
      else {
        // cannot handle this case
        llvm::errs() << "Error: Token is resulted from macro expansion"
          " and is therefore not renamed, at: " << loc(L) << "\n";
        return;
      }
    }
  }
    
  if (shouldIgnore(L)) {
    return;
  }
    
  auto LE = preprocessor->getLocForEndOfToken(L);
  if (LE.isValid()) {        
    // getLocWithOffset returns the location *past* the token, hence -1
    auto E = LE.getLocWithOffset(-1);
    rewriter.ReplaceText(SourceRange(L, E), N);
  }
}  
开发者ID:antmd,项目名称:synthaway,代码行数:47,代码来源:synthaway.cpp

示例7: Initialize

    void Initialize(ASTContext &context) {
        //llvm::errs() << "initializing consumer\n";
        Context = &context;
        SM = &Context->getSourceManager();

        // Get the ID and start/end of the main file.
        MainFileID = SM->getMainFileID();
    }
开发者ID:netsym,项目名称:minissf,代码行数:8,代码来源:annotate.cpp

示例8: printSourceLocation

static void printSourceLocation(SourceLocation loc, ASTContext &Ctx,
                                raw_ostream &OS) {
  SourceManager &SM = Ctx.getSourceManager();
  PresumedLoc PL = SM.getPresumedLoc(loc);

  OS << llvm::sys::path::filename(PL.getFilename());
  OS << ":" << PL.getLine() << ":"
            << PL.getColumn();
}
开发者ID:CSI-LLVM,项目名称:clang,代码行数:9,代码来源:arcmt-test.cpp

示例9: run

/// \brief The LoopFixer callback, which determines if loops discovered by the
/// matchers are convertible, printing information about the loops if so.
void LoopFixer::run(const MatchFinder::MatchResult &Result) {
  const BoundNodes &Nodes = Result.Nodes;
  Confidence ConfidenceLevel(TCK_Safe);
  ASTContext *Context = Result.Context;
  const ForStmt *TheLoop = Nodes.getStmtAs<ForStmt>(LoopName);

  if (!Context->getSourceManager().isFromMainFile(TheLoop->getForLoc()))
    return;

  // Check that we have exactly one index variable and at most one end variable.
  const VarDecl *LoopVar = Nodes.getDeclAs<VarDecl>(IncrementVarName);
  const VarDecl *CondVar = Nodes.getDeclAs<VarDecl>(ConditionVarName);
  const VarDecl *InitVar = Nodes.getDeclAs<VarDecl>(InitVarName);
  if (!areSameVariable(LoopVar, CondVar) || !areSameVariable(LoopVar, InitVar))
    return;
  const VarDecl *EndVar = Nodes.getDeclAs<VarDecl>(EndVarName);
  const VarDecl *ConditionEndVar =
      Nodes.getDeclAs<VarDecl>(ConditionEndVarName);
  if (EndVar && !areSameVariable(EndVar, ConditionEndVar))
    return;

  // If the end comparison isn't a variable, we can try to work with the
  // expression the loop variable is being tested against instead.
  const CXXMemberCallExpr *EndCall =
      Nodes.getStmtAs<CXXMemberCallExpr>(EndCallName);
  const Expr *BoundExpr = Nodes.getStmtAs<Expr>(ConditionBoundName);
  // If the loop calls end()/size() after each iteration, lower our confidence
  // level.
  if (FixerKind != LFK_Array && !EndVar)
    ConfidenceLevel.lowerTo(TCK_Reasonable);

  const Expr *ContainerExpr = NULL;
  bool ContainerNeedsDereference = false;
  // FIXME: Try to put most of this logic inside a matcher. Currently, matchers
  // don't allow the right-recursive checks in digThroughConstructors.
  if (FixerKind == LFK_Iterator)
    ContainerExpr = findContainer(Context, LoopVar->getInit(),
                                  EndVar ? EndVar->getInit() : EndCall,
                                  &ContainerNeedsDereference);
  else if (FixerKind == LFK_PseudoArray) {
    if (!EndCall)
      return;
    ContainerExpr = EndCall->getImplicitObjectArgument();
    const MemberExpr *Member = dyn_cast<MemberExpr>(EndCall->getCallee());
    if (!Member)
      return;
    ContainerNeedsDereference = Member->isArrow();
  }
  // We must know the container or an array length bound.
  if (!ContainerExpr && !BoundExpr)
    return;

  findAndVerifyUsages(Context, LoopVar, EndVar, ContainerExpr, BoundExpr,
                      ContainerNeedsDereference, TheLoop, ConfidenceLevel);
}
开发者ID:sam-panzer,项目名称:clang-loop-converter,代码行数:57,代码来源:LoopActions.cpp

示例10: HandleTranslationUnit

 void HandleTranslationUnit(ASTContext &Context) override {
   const SourceManager &SourceMgr = Context.getSourceManager();
   for (unsigned Offset : SymbolOffsets) {
     if (!FindSymbol(Context, SourceMgr, Offset, ""))
       return;
   }
   for (const std::string &QualifiedName : QualifiedNames) {
     if (!FindSymbol(Context, SourceMgr, 0, QualifiedName))
       return;
   }
 }
开发者ID:irods,项目名称:clang-tools-extra,代码行数:11,代码来源:USRFindingAction.cpp

示例11: HandleInlineMethodDefinition

    void HandleInlineMethodDefinition(CXXMethodDecl *D) override {
      PrettyStackTraceDecl CrashInfo(D, SourceLocation(),
                                     Context->getSourceManager(),
                                     "LLVM IR generation of inline method");
      if (llvm::TimePassesIsEnabled)
        LLVMIRGeneration.startTimer();

      Gen->HandleInlineMethodDefinition(D);

      if (llvm::TimePassesIsEnabled)
        LLVMIRGeneration.stopTimer();
    }
开发者ID:oyeniyi-wale,项目名称:clang,代码行数:12,代码来源:CodeGenAction.cpp

示例12: HandleTranslationUnit

  // This gets called only when the full TU is completely parsed.
  void HandleTranslationUnit(ASTContext &Context) {
    llvm::errs() << "********* The whole TU *************\n";
    Context.getTranslationUnitDecl()->dump();

    llvm::errs() << "****** going over the decls stored in it:\n";
    for (auto *D : Context.getTranslationUnitDecl()->decls()) {
      llvm::errs() << "Decl in the TU:\n";
      D->dump();
      llvm::errs() << "Its start location is: '"
                   << D->getLocStart().printToString(Context.getSourceManager())
                   << "'\n";
    }
  }
开发者ID:hg570820,项目名称:llvm-clang-samples,代码行数:14,代码来源:toplevel_decls.cpp

示例13: HandleTopLevelDecl

    virtual void HandleTopLevelDecl(DeclGroupRef D) {
      PrettyStackTraceDecl CrashInfo(*D.begin(), SourceLocation(),
                                     Context->getSourceManager(),
                                     "LLVM IR generation of declaration");

      if (llvm::TimePassesIsEnabled)
        LLVMIRGeneration.startTimer();

      Gen->HandleTopLevelDecl(D);

      if (llvm::TimePassesIsEnabled)
        LLVMIRGeneration.stopTimer();
    }
开发者ID:ACSOP,项目名称:android_external_clang,代码行数:13,代码来源:CodeGenAction.cpp

示例14: HandleTranslationUnit

void MethodMoveTransform::HandleTranslationUnit(ASTContext &C)
{
	auto movingSpec = TransformRegistry::get().config["MethodMove"].begin();
	movingClassName = movingSpec->first.as<std::string>();
	clang::SourceManager &SM = C.getSourceManager();
	clang::FileManager &FM = SM.getFileManager();
	if(FM.getFile(movingSpec->second.as<std::string>()) == SM.getFileEntryForID(SM.getMainFileID()))
	{
		llvm::errs() << "MovingClassName: " << movingClassName << "\n";
		llvm::errs() << SM.getFileEntryForID(SM.getMainFileID())->getName() << "\n";
		auto TUD = C.getTranslationUnitDecl();
		processDeclContext(TUD);
	}
}
开发者ID:emchristiansen,项目名称:refactorial,代码行数:14,代码来源:MethodMoveTransform.cpp

示例15: convertCommentToXML

void CommentToXMLConverter::convertCommentToXML(const FullComment *FC,
                                                SmallVectorImpl<char> &XML,
                                                const ASTContext &Context) {
  if (!FormatContext || (FormatInMemoryUniqueId % 1000) == 0) {
    // Create a new format context, or re-create it after some number of
    // iterations, so the buffers don't grow too large.
    FormatContext.reset(new SimpleFormatContext(Context.getLangOpts()));
  }

  CommentASTToXMLConverter Converter(FC, XML, Context.getCommentCommandTraits(),
                                     Context.getSourceManager(), *FormatContext,
                                     FormatInMemoryUniqueId++);
  Converter.visit(FC);
}
开发者ID:ADonut,项目名称:LLVM-GPGPU,代码行数:14,代码来源:CommentToXML.cpp


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