Пример #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;
 }
Пример #3
0
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;
}
Пример #4
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;
 }
 // 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;
 }
Пример #6
0
bool LiftAssignmentExpr::HandleTopLevelDecl(DeclGroupRef D) 
{
  for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) {
    CollectionVisitor->TraverseDecl(*I);
  }
  return true;
}
Пример #7
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));
}
Пример #8
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;
}
Пример #9
0
bool RemoveNestedFunction::HandleTopLevelDecl(DeclGroupRef D)
{
  for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) {
    NestedInvocationVisitor->TraverseDecl(*I);
  }
  return true;
}
Пример #10
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;
  }
Пример #11
0
bool CombineLocalVarDecl::HandleTopLevelDecl(DeclGroupRef D) 
{
  for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) {
    CollectionVisitor->TraverseDecl(*I);
  }
  return true;
}
Пример #12
0
bool SimpleInliner::HandleTopLevelDecl(DeclGroupRef D) 
{
  for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) {
    FunctionStmtVisitor->TraverseDecl(*I);
  }
  return true;
}
Пример #13
0
 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;
 }
Пример #14
0
bool ReduceArraySize::HandleTopLevelDecl(DeclGroupRef D) 
{
  for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) {
    CollectionVisitor->TraverseDecl(*I);
  }
  return true;
}
Пример #15
0
bool BinOpSimplification::HandleTopLevelDecl(DeclGroupRef D) 
{
  for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) {
    BinOpCollectionVisitor->TraverseDecl(*I);
  }
  return true;
}
Пример #16
0
bool CDaoASTConsumer::HandleTopLevelDecl(DeclGroupRef group)
{
	for (DeclGroupRef::iterator it = group.begin(); it != group.end(); ++it) {
		HandleDeclaration( *it );
	}
	return true;
}
Пример #17
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;
        }
Пример #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;
 }
Пример #19
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;
}
Пример #20
0
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
}
Пример #21
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;
}
Пример #22
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;
}
Пример #23
0
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";
        }
    }
}
Пример #24
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);
  }
}
Пример #25
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;
}
Пример #26
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;
 }
Пример #27
0
    bool HandleTopLevelDecl(DeclGroupRef DG) override {
      if (Diags.hasErrorOccurred())
        return true;

      HandlingTopLevelDeclRAII HandlingDecl(*this);

      // Make sure to emit all elements of a Decl.
      for (DeclGroupRef::iterator I = DG.begin(), E = DG.end(); I != E; ++I)
        Builder->EmitTopLevelDecl(*I);

      return true;
    }
Пример #28
0
bool ASTStructExtractor::HandleTopLevelDecl(DeclGroupRef D) {
  DeclGroupRef::iterator decl_iterator;

  for (decl_iterator = D.begin(); decl_iterator != D.end(); ++decl_iterator) {
    Decl *decl = *decl_iterator;

    ExtractFromTopLevelDecl(decl);
  }

  if (m_passthrough)
    return m_passthrough->HandleTopLevelDecl(D);
  return true;
}
Пример #29
0
bool
SimplePrinterConsumer::HandleTopLevelDecl(DeclGroupRef D) {
	if(D.begin() == D.end()) {
		return true;
	}
	Decl *firstD = *(D.begin());
	if(compInst->getSourceManager().isInSystemHeader(firstD->getLocation())) {
		return true;
	}

	PrintingPolicy policy = compInst->getASTContext().getPrintingPolicy();
	NullStmt *nullSt = new (compInst->getASTContext()) NullStmt(SourceLocation());

	for(DeclGroupRef::iterator 
		   I = D.begin(), E = D.end();
		   I != E; ++I) {
		Decl *dd = *I;

		DPRINT("PrintingPolicy: %d %d %d %d %d", policy.SuppressSpecifiers, policy.SuppressScope, policy.SuppressTag, policy.SuppressUnwrittenScope, policy.SuppressSpecifiers);
		
		dd->print(out, policy);
		nullSt->printPretty(out, NULL, policy);
		if(dd->hasBody()) {
			Stmt *ss = dd->getBody();
			// Print Stmts
			//dd->dump();
			//StmtPrinter(compInst, dd->getBody()).TraverseDecl(dd);

			// CFG
			
			OwningPtr<CFG> cfg;
			cfg.reset(CFG::buildCFG((const Decl*)dd, (Stmt*)(dd->getBody()), &compInst->getASTContext(), CFG::BuildOptions()));
			assert(cfg.get() != NULL && "build CFG failed.");
			cfg->dump(compInst->getLangOpts(), true);
			cfg->viewCFG(compInst->getLangOpts());
		}
	}
	return true;
};
Пример #30
0
// This function skips type specifiers
bool RewriteUtils::getDeclGroupStrAndRemove(DeclGroupRef DGR, 
                                   std::string &Str)
{
  if (DGR.isSingleDecl()) {
    Decl *D = DGR.getSingleDecl();
    VarDecl *VD = dyn_cast<VarDecl>(D);
    TransAssert(VD && "Bad VarDecl!");

    // We need to get the outermost TypeLocEnd instead of the StartLoc of
    // a var name, because we need to handle the case below:
    //   int *x;
    //   int *y;
    // If we rely on the StartLoc of a var name, then we will make bad
    // transformation like:
    //   int *x, y;
    SourceLocation TypeLocEnd = getVarDeclTypeLocEnd(VD);
    SourceRange VarRange = VD->getSourceRange();

    SourceLocation LocEnd = getEndLocationUntil(VarRange, ';');

    getStringBetweenLocs(Str, TypeLocEnd, LocEnd);

    SourceLocation StartLoc = VarRange.getBegin();
    SourceLocation NewEndLoc = getLocationAfterSkiping(LocEnd, ';');
    return !(TheRewriter->RemoveText(SourceRange(StartLoc, NewEndLoc)));
  }

  TransAssert(DGR.getDeclGroup().size() > 1);

  DeclGroupRef::iterator I = DGR.begin();
  DeclGroupRef::iterator E = DGR.end();
  --E;

  Decl *FirstD = (*I);
  VarDecl *FirstVD = dyn_cast<VarDecl>(FirstD);
  Decl *LastD = (*E);
  VarDecl *LastVD = dyn_cast<VarDecl>(LastD);

  TransAssert(FirstVD && "Bad First VarDecl!");
  TransAssert(LastVD && "Bad First VarDecl!");

  SourceLocation TypeLocEnd = getVarDeclTypeLocEnd(FirstVD);
  SourceRange LastVarRange = LastVD->getSourceRange();
  SourceLocation LastEndLoc = getEndLocationUntil(LastVarRange, ';');
  getStringBetweenLocs(Str, TypeLocEnd, LastEndLoc);

  SourceLocation StartLoc = FirstVD->getLocStart();
  SourceLocation NewLastEndLoc = getLocationAfterSkiping(LastEndLoc, ';');
  return !(TheRewriter->RemoveText(SourceRange(StartLoc, NewLastEndLoc)));
}