Example #1
0
bool SimplifyStructUnionDecl::HandleTopLevelDecl(DeclGroupRef DGR) 
{
  DeclGroupRef::iterator DI = DGR.begin();
  if (isInIncludedFile(*DI))
    return true;

  const RecordDecl *RD = dyn_cast<RecordDecl>(*DI);
  if (RD) {
    addOneRecordDecl(RD, DGR);
    return true;
  }

  VarDecl *VD = dyn_cast<VarDecl>(*DI);
  if (!VD)
    return true;

  const Type *T = VD->getType().getTypePtr();

  RD = getBaseRecordDecl(T);
  if (!RD)
    return true;

  const Decl *CanonicalD = RD->getCanonicalDecl();
  void *DGRPointer = RecordDeclToDeclGroup[CanonicalD];
  if (!DGRPointer)
    return true;

  ValidInstanceNum++;
  if (ValidInstanceNum != TransformationCounter)
    return true;

  TheRecordDecl = dyn_cast<RecordDecl>(CanonicalD);
  TheDeclGroupRefs.push_back(DGRPointer);
  TheDeclGroupRefs.push_back(DGR.getAsOpaquePtr());

  for (DeclGroupRef::iterator I = DGR.begin(), E = DGR.end(); I != E; ++I) {
    VarDecl *VD = dyn_cast<VarDecl>(*I);
    TransAssert(VD && "Bad VarDecl!");
    CombinedVars.insert(VD);
  }

  DeclGroupRef DefDGR = DeclGroupRef::getFromOpaquePtr(DGRPointer);
  for (DeclGroupRef::iterator I = DefDGR.begin(), 
       E = DefDGR.end(); I != E; ++I) {
    VarDecl *VD = dyn_cast<VarDecl>(*I);
    if (VD)
      CombinedVars.insert(VD);
  }
  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;
 }
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;
}
 // 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 #5
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));
}
Example #6
0
  bool DeclCollector::Transform(DeclGroupRef& DGR) {
    // Do not tranform recursively, e.g. when emitting a DeclExtracted decl.
    if (m_Transforming)
      return true;

    struct TransformingRAII {
      bool& m_Transforming;
      TransformingRAII(bool& Transforming): m_Transforming(Transforming) {
        m_Transforming = true;
      }
      ~TransformingRAII() { m_Transforming = false; }
    } transformingUpdater(m_Transforming);

    llvm::SmallVector<Decl*, 4> ReplacedDecls;
    bool HaveReplacement = false;
    for (Decl* D: DGR) {
      ASTTransformer::Result NewDecl = TransformDecl(D);
      if (!NewDecl.getInt())
        return false;
      HaveReplacement |= (NewDecl.getPointer() != D);
      if (NewDecl.getPointer())
        ReplacedDecls.push_back(NewDecl.getPointer());
    }
    if (HaveReplacement)
      DGR = DeclGroupRef::Create((*DGR.begin())->getASTContext(),
                                 ReplacedDecls.data(), ReplacedDecls.size());
    return true;
  }
Example #7
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 #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
bool CombineLocalVarDecl::HandleTopLevelDecl(DeclGroupRef D) 
{
  for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) {
    CollectionVisitor->TraverseDecl(*I);
  }
  return true;
}
Example #11
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 #12
0
bool ReduceArraySize::HandleTopLevelDecl(DeclGroupRef D) 
{
  for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) {
    CollectionVisitor->TraverseDecl(*I);
  }
  return true;
}
Example #13
0
bool SimpleInliner::HandleTopLevelDecl(DeclGroupRef D) 
{
  for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) {
    FunctionStmtVisitor->TraverseDecl(*I);
  }
  return true;
}
Example #14
0
bool RemoveNestedFunction::HandleTopLevelDecl(DeclGroupRef D)
{
  for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) {
    NestedInvocationVisitor->TraverseDecl(*I);
  }
  return true;
}
Example #15
0
bool CDaoASTConsumer::HandleTopLevelDecl(DeclGroupRef group)
{
	for (DeclGroupRef::iterator it = group.begin(); it != group.end(); ++it) {
		HandleDeclaration( *it );
	}
	return true;
}
 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 #17
0
bool LiftAssignmentExpr::HandleTopLevelDecl(DeclGroupRef D) 
{
  for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) {
    CollectionVisitor->TraverseDecl(*I);
  }
  return true;
}
Example #18
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 #19
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 #20
0
 void DeclCollector::HandleInterestingDecl(DeclGroupRef DGR) {
   assert(m_CurTransaction && "Missing transction");
   Transaction::DelayCallInfo DCI(DGR, Transaction::kCCIHandleInterestingDecl);
   m_CurTransaction->append(DCI);
   if (m_Consumer
       && (!comesFromASTReader(DGR) || !shouldIgnore(*DGR.begin())))
     m_Consumer->HandleTopLevelDecl(DGR);
 }
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 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 #25
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 #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);
  }
}
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";
        }
    }
}
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;
}
Example #30
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;
 }