Example #1
0
bool RewriteUtils::getEntireDeclGroupStrAndRemove(DeclGroupRef DGR,
                                                  std::string &Str)
{
  Decl *FirstD, *LastD;
  if (DGR.isSingleDecl()) {
    FirstD = DGR.getSingleDecl();
    LastD = FirstD;
  }
  else {
    DeclGroupRef::iterator I = DGR.begin();
    FirstD = (*I);

    DeclGroupRef::iterator E = DGR.end();
    --E;
    LastD = (*E);
  }

  SourceRange FirstRange = FirstD->getSourceRange();
  SourceLocation StartLoc = FirstRange.getBegin();
  SourceRange LastRange = LastD->getSourceRange();
  SourceLocation EndLoc = getEndLocationUntil(LastRange, ';');

  getStringBetweenLocs(Str, StartLoc, EndLoc);
  return !TheRewriter->RemoveText(SourceRange(StartLoc, EndLoc));
}
 // This gets called *while the source is being parsed* - the full AST does not
 // exist yet.
 bool HandleTopLevelDecl(DeclGroupRef DR) override {
   for (DeclGroupRef::iterator b = DR.begin(), e = DR.end(); b != e; ++b) {
     // llvm::errs() << "This is a toplevel decl!\n";
     //(*b)->dump();
   }
   return true;
 }
Example #3
0
SourceLocation RewriteUtils::getDeclGroupRefEndLoc(DeclGroupRef DGR)
{
  Decl *LastD;

  if (DGR.isSingleDecl()) {
    LastD = DGR.getSingleDecl();
  }
  else {
    DeclGroupRef::iterator E = DGR.end();
    --E;
    LastD = (*E);
  }

#if 0
  VarDecl *VD = dyn_cast<VarDecl>(LastD);
  TransAssert(VD && "Bad VD!");
  SourceRange VarRange = VD->getSourceRange();
  return getEndLocationFromBegin(VarRange);
#endif

  // The LastD could be a RecordDecl
  SourceRange Range = LastD->getSourceRange();
  SourceLocation EndLoc = getEndLocationFromBegin(Range);
  TransAssert(EndLoc.isValid() && "Invalid EndLoc!");
  return EndLoc;
}
 virtual bool HandleTopLevelDecl(DeclGroupRef DR) {
     for (DeclGroupRef::iterator b = DR.begin(), e = DR.end(); b != e; ++b) {
         // Travel each function declaration using MyASTVisitor
         Visitor.TraverseDecl(*b);
     }
     return true;
 }
Example #5
0
bool CombineLocalVarDecl::HandleTopLevelDecl(DeclGroupRef D) 
{
  for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) {
    CollectionVisitor->TraverseDecl(*I);
  }
  return true;
}
bool RemoveNestedFunction::HandleTopLevelDecl(DeclGroupRef D)
{
  for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) {
    NestedInvocationVisitor->TraverseDecl(*I);
  }
  return true;
}
 virtual bool HandleTopLevelDecl(DeclGroupRef DR) {
   for (auto DB = DR.begin(), DE = DR.end(); DB != DE; ++DB) {
     // Traverse the declaration using our AST visitor.
     Visitor.TraverseDecl(*DB);
   }
   return true;
 }
Example #8
0
 // Override the method that gets called for each parsed top-level
 // declaration.
 bool HandleTopLevelDecl(DeclGroupRef DR) override {
   for (DeclGroupRef::iterator b = DR.begin(), e = DR.end(); b != e; ++b) {
     // Traverse the declaration using our AST visitor.
     visitor.TraverseDecl(*b);
   }
   return true;
 }
Example #9
0
bool BinOpSimplification::HandleTopLevelDecl(DeclGroupRef D) 
{
  for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) {
    BinOpCollectionVisitor->TraverseDecl(*I);
  }
  return true;
}
Example #10
0
 void Transaction::appendUnique(DeclGroupRef DGR) {
   for (const_iterator I = decls_begin(), E = decls_end(); I != E; ++I) {
     if (DGR.isNull() || (*I).getAsOpaquePtr() == DGR.getAsOpaquePtr())
       return;
   }
   m_DeclQueue.push_back(DGR);
 }
Example #11
0
bool UnionToStruct::isTheFirstDecl(const VarDecl *VD)
{
  // always return false if VD is declared in a LinkageSpecDecl,
  // because the first decl should be implicitly declared union record,
  // which is handled by rewriteOneRecordDecl
  const DeclContext *Ctx = VD->getDeclContext();
  if (dyn_cast<LinkageSpecDecl>(Ctx)) {
    return false;
  }

  DeclGroupRef DGR;
  if (const DeclStmt *DS = VarToDeclStmt[VD])
    DGR = DS->getDeclGroup();
  else
    DGR = VarToDeclGroup[VD];

  TransAssert(!DGR.isNull() && "Bad DeclRefGroup!");

  if (DGR.isSingleDecl())
    return true;

  DeclGroupRef::const_iterator I = DGR.begin();
  const VarDecl *FirstVD = dyn_cast<VarDecl>(*I);
  if (!FirstVD)
    return false;

  return (VD == FirstVD);
}
Example #12
0
  bool DeclCollector::HandleTopLevelDecl(DeclGroupRef DGR) {
    // if that decl comes from an AST File, i.e. PCH/PCM, no transaction needed
    // pipe it directly to codegen.
    if (comesFromASTReader(DGR)) {
      if (m_CodeGen) {
        for (DeclGroupRef::iterator I = DGR.begin(), E = DGR.end();
             I != E; ++I) {
          if (NamespaceDecl* ND = dyn_cast<NamespaceDecl>(*I)) {
            for (NamespaceDecl::decl_iterator IN = ND->decls_begin(),
                   EN = ND->decls_end(); IN != EN; ++IN)
              // Recurse over decls inside the namespace, like
              // CodeGenModule::EmitNamespace() does.
              HandleTopLevelDecl(DeclGroupRef(*IN));
          } else {
            if (!shouldIgnoreDeclFromASTReader(*I)) {
              m_CodeGen->HandleTopLevelDecl(DeclGroupRef(*I));
            }
            // FIXME: once modules are there this is not needed anymore.
            // it is used to simulate modules and the ASTDeserializationListener
            // for sources that are included to describe the library that was
            // built from the sources (ACLiC).
            if (!(*I)->isFromASTFile() && m_Interp->getASTDeserializationListener())
              m_Interp->getASTDeserializationListener()->DeclRead(0, *I);
          }
        }
      }
      return true;
    }

    Transaction::DelayCallInfo DCI(DGR, Transaction::kCCIHandleTopLevelDecl);
    m_CurTransaction->append(DCI);
    return true;
  }
Example #13
0
void SimplifyStructUnionDecl::doCombination(void)
{
  TransAssert(TheDeclGroupRefs.size() == 2);
  void *P2 = TheDeclGroupRefs.pop_back_val();
  void *P1 = TheDeclGroupRefs.pop_back_val();

  DeclGroupRef FirstDGR = DeclGroupRef::getFromOpaquePtr(P1);
  DeclGroupRef SecondDGR = DeclGroupRef::getFromOpaquePtr(P2);

  SourceLocation EndLoc = 
    RewriteHelper->getDeclGroupRefEndLoc(FirstDGR);

  std::string DStr;
  RewriteHelper->getDeclGroupStrAndRemove(SecondDGR, DStr);

  // it's a single RecordDecl
  if (FirstDGR.isSingleDecl())
    TheRewriter.InsertText(EndLoc, DStr, /*InsertAfter=*/false);
  else
    TheRewriter.InsertText(EndLoc, ", " + DStr, /*InsertAfter=*/false);

  if (isSafeToRemoveName()) {
    SourceLocation NameLocStart = TheRecordDecl->getLocation();
    std::string Name = TheRecordDecl->getNameAsString();
    TheRewriter.RemoveText(NameLocStart, Name.size());
  }
}
Example #14
0
bool LiftAssignmentExpr::HandleTopLevelDecl(DeclGroupRef D) 
{
  for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) {
    CollectionVisitor->TraverseDecl(*I);
  }
  return true;
}
bool ASTVistor::HandleTopLevelDecl(DeclGroupRef DG)
{
   for (DeclGroupRef::iterator i = DG.begin(), e = DG.end(); i != e; ++i) {
      const Decl *D = *i;
      if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
         if (!FD->hasBody()) continue;
         if (CI_.getSourceManager().isInSystemHeader(FD->getLocation())) {
            //loc.print(llvm::errs(), CI_.getSourceManager());
            continue;
         }

         std::vector<std::string> params;
         for (FunctionDecl::param_const_iterator it = FD->param_begin(); it != FD->param_end(); ++it) {
            params.push_back((*it)->getOriginalType().getAsString());
         }

         fmt_.AddDefinition(FD->getQualifiedNameAsString(), FD->getResultType().getAsString(), params);

         this->TraverseStmt(FD->getBody());

         fmt_.EndDefinition();
      }
   }

   ost_.flush();

   return true;
}
Example #16
0
bool SimpleInliner::HandleTopLevelDecl(DeclGroupRef D) 
{
  for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) {
    FunctionStmtVisitor->TraverseDecl(*I);
  }
  return true;
}
Example #17
0
bool CDaoASTConsumer::HandleTopLevelDecl(DeclGroupRef group)
{
	for (DeclGroupRef::iterator it = group.begin(); it != group.end(); ++it) {
		HandleDeclaration( *it );
	}
	return true;
}
Example #18
0
        virtual bool HandleTopLevelDecl( DeclGroupRef group ) override
        {
            for( auto itr = group.begin(); itr != group.end(); ++itr )
            {
                // if this decl is a reflectable type ...

                auto tagDecl = dyn_cast<TagDecl>( *itr );

                if( tagDecl== nullptr )
                {
                    continue;
                }

                // should we reflect it?

                mReflect.SetDefault( false );

                if( mReflect.ParseComment( mContext->getCommentForDecl( tagDecl, nullptr ) ) == false )
                {
                    continue;
                }

                // recursively write it out decl and all contained types

                mReflect.SetDefault( true );
                mVisitor.TraverseDecl( tagDecl );
            }

            return true;
        }
Example #19
0
 // Override the method that gets called for each parsed top-level
 // declaration.
 virtual bool HandleTopLevelDecl(DeclGroupRef DR) {
     for (DeclGroupRef::iterator b = DR.begin(), e = DR.end();
          b != e; ++b)
         // Traverse the declaration using our AST visitor.
         mpVisitor->TraverseDecl(*b);
     return true;
 }
Example #20
0
bool ReduceArraySize::HandleTopLevelDecl(DeclGroupRef D) 
{
  for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) {
    CollectionVisitor->TraverseDecl(*I);
  }
  return true;
}
Example #21
0
  bool Transaction::comesFromASTReader(DeclGroupRef DGR) const {
    assert(!DGR.isNull() && "DeclGroupRef is Null!");
    if (getCompilationOpts().CodeGenerationForModule)
      return true;

    // Take the first/only decl in the group.
    Decl* D = *DGR.begin();
    return D->isFromASTFile();
  }
Example #22
0
bool RemoveUnusedVar::HandleTopLevelDecl(DeclGroupRef D) 
{
  for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) {
    VarDecl *VD = dyn_cast<VarDecl>(*I);
    if (VD)
      VarToDeclGroup[VD] = D;
  }
  return true;
}
bool MyASTConsumer::HandleTopLevelDecl(DeclGroupRef d)
{
  typedef DeclGroupRef::iterator iter;

  for (iter b = d.begin(), e = d.end(); b != e; ++b){
    rv.TraverseDecl(*b);
  }
  return true; // keep going
}
Example #24
0
  bool DeclCollector::comesFromASTReader(DeclGroupRef DGR) const {
    assert(!DGR.isNull() && "DeclGroupRef is Null!");
    assert(m_CurTransaction && "No current transaction when deserializing");
    if (m_CurTransaction->getCompilationOpts().CodeGenerationForModule)
      return true;

    // Take the first/only decl in the group.
    Decl* D = *DGR.begin();
    return D->isFromASTFile();
  }
Example #25
0
bool AnalysisConsumer::HandleTopLevelDecl(DeclGroupRef DG) {
 storeTopLevelDecls(DG);
 for (DeclGroupRef::iterator i = DG.begin(), e = DG.end(); i != e; i++) {
		Decl *D = *i;
		string ssStart = D->getLocStart().printToString(Mgr->getASTContext().getSourceManager());
		//std::cout<<"HandleTopLevelDecl: "<<ssStart<<std::endl;
 
  }
  return true;
}
Example #26
0
bool UnionToStruct::HandleTopLevelDecl(DeclGroupRef D) 
{
  for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) {
    if (VarDecl *VD = dyn_cast<VarDecl>(*I))
      VarToDeclGroup[VD] = D;

    CollectionVisitor->TraverseDecl(*I);
  }
  return true;
}
Example #27
0
void AnalysisConsumer::storeTopLevelDecls(DeclGroupRef DG) {
  for (DeclGroupRef::iterator I = DG.begin(), E = DG.end(); I != E; ++I) {

    // Skip ObjCMethodDecl, wait for the objc container to avoid
    // analyzing twice.
    if (isa<ObjCMethodDecl>(*I))
      continue;

    LocalTUDecls.push_back(*I);
  }
}
Example #28
0
 bool VisitDeclStmt(DeclStmt* DS) {
   DeclGroupRef DGR = DS->getDeclGroup();
   for (DeclGroupRef::const_iterator I = DGR.begin(), 
          E = DGR.end(); I != E; ++I) {
     if (isCandidate(*I)) {
       m_ShouldVisitSubTree = true;
       return false; // returning false will abort the in-depth traversal.
     }
   }
   return true;
 }
Example #29
0
bool AggregateToScalar::HandleTopLevelDecl(DeclGroupRef D) 
{
  for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) {
    VarDecl *VD = dyn_cast<VarDecl>(*I);
    if (VD)
      VarDeclToDeclGroupMap[VD] = D;

    AggregateAccessVisitor->TraverseDecl(*I);
  }
  return true;
}
void ASTConsumerHTML::HandleInterestingDecl(DeclGroupRef D) {

    for (DeclGroupRef::iterator it = D.begin(); it != D.end(); ++it) {
        Decl *decl = *it;
        if (decl) {
            log << "\n" << decl << " HandleInterestingDecl" << "\n";
            decl->print(log);
            log << "\n";
        }
    }
}