ASTConsumer *InsertBracesFrontendAction::CreateASTConsumer(
    CompilerInstance &Compiler, StringRef InFile) {
  
  ASTContext *ctx = &Compiler.getASTContext();
  rewriter = Rewriter(ctx->getSourceManager(), ctx->getLangOpts());
  return new InsertBracesASTConsumer(rewriter);
}
Exemplo n.º 2
0
    Expression SpecRewriter::Do(ESolver* Solver, const Expression& Exp,
                                vector<EvalRule>& EvalRules,
                                vector<const AuxVarOperator*>& BaseAuxVarsOps,
                                vector<const AuxVarOperator*>& DerivedAuxVarOps)
    {
        SpecRewriter Rewriter(Solver);
        Exp->Accept(&Rewriter);
        EvalRules = Rewriter.EvalRules;
        BaseAuxVarsOps = Rewriter.BaseAuxVarOps;
        DerivedAuxVarOps = Rewriter.DerivedAuxVarOps;

        // Assign positions for base and derived aux vars
        uint32 AuxVarCounter = 0;
        for (auto const& BaseAV : BaseAuxVarsOps) {
            BaseAV->SetPosition(AuxVarCounter++);
        }
        for (auto const& DerivedAV : DerivedAuxVarOps) {
            DerivedAV->SetPosition(AuxVarCounter++);
        }

        // Fixup the param maps in the eval rules
        for (auto const& Rule : EvalRules) {
            ParamMapFixup::Do(Rule.GetRHS());
        }
        
        return Rewriter.RewriteStack.back();
    }
Exemplo n.º 3
0
/// Simplify users of induction variables within this
/// loop. This does not actually change or add IVs.
bool simplifyLoopIVs(Loop *L, ScalarEvolution *SE, DominatorTree *DT,
                     LoopInfo *LI, SmallVectorImpl<WeakTrackingVH> &Dead) {
  SCEVExpander Rewriter(*SE, SE->getDataLayout(), "indvars");
#ifndef NDEBUG
  Rewriter.setDebugType(DEBUG_TYPE);
#endif
  bool Changed = false;
  for (BasicBlock::iterator I = L->getHeader()->begin(); isa<PHINode>(I); ++I) {
    Changed |= simplifyUsersOfIV(cast<PHINode>(I), SE, DT, LI, Dead, Rewriter);
  }
  return Changed;
}
Exemplo n.º 4
0
void clang::DoRewriteTest(Preprocessor &PP, raw_ostream* OS) {
  SourceManager &SM = PP.getSourceManager();
  const LangOptions &LangOpts = PP.getLangOptions();

  TokenRewriter Rewriter(SM.getMainFileID(), SM, LangOpts);

  // Throw <i> </i> tags around comments.
  for (TokenRewriter::token_iterator I = Rewriter.token_begin(),
       E = Rewriter.token_end(); I != E; ++I) {
    if (I->isNot(tok::comment)) continue;

    Rewriter.AddTokenBefore(I, "<i>");
    Rewriter.AddTokenAfter(I, "</i>");
  }


  // Print out the output.
  for (TokenRewriter::token_iterator I = Rewriter.token_begin(),
       E = Rewriter.token_end(); I != E; ++I)
    *OS << PP.getSpelling(*I);
}