Example #1
0
void ExternalASTMerger::FindExternalLexicalDecls(
    const DeclContext *DC, llvm::function_ref<bool(Decl::Kind)> IsKindWeWant,
    SmallVectorImpl<Decl *> &Result) {
  ForEachMatchingDC(
      DC, Importers,
      [&](const ImporterPair &IP, Source<const DeclContext *> SourceDC) {
        for (const Decl *SourceDecl : SourceDC.get()->decls()) {
          if (IsKindWeWant(SourceDecl->getKind())) {
            Decl *ImportedDecl =
                IP.Forward->Import(const_cast<Decl *>(SourceDecl));
            assert(ImportedDecl->getDeclContext() == DC);
            (void)ImportedDecl;
          }
        }
      });
}
bool FlattenCFGTransformer::execute() {
	this->renamer = new VarRenamer(this->resMgr);
	this->preTranser = new StmtPretransformer(this->resMgr);
	OwningPtr<RefVarToPtrMap> refMap(new RefVarToPtrMap(0));
	assert(refMap.get() && "reference variable map alloc failed");
	this->dclMover = new LocalDeclMover(this->resMgr, refMap.get());
	this->flat = new CFGFlattener(this->resMgr);

	TranslationUnitDecl *decls = this->resMgr.getCompilerInstance().getASTContext().getTranslationUnitDecl();
	for(TranslationUnitDecl::decl_iterator I = decls->decls_begin(), E = decls->decls_end();
			I != E; ++I) {
		Decl *D = *I;
		DPRINT("TUDecl %s %x | Ctx %x -> p %x", D->getDeclKindName(), (unsigned int)D, (unsigned int)D->getDeclContext(), (unsigned int)decls);
		SourceLocation Loc = D->getLocation();

		if(Loc.isInvalid() 
				|| this->compInst.getSourceManager().isInSystemHeader(Loc)){
			continue;
		}

		if(HandleAnyFunctionDecl(D)) {
			continue;
		} else if(HandleAnyClassDecl(D)) {
			continue;
		}
	}

	delete this->renamer;
	delete this->preTranser;
	delete this->dclMover;
	delete this->flat;
	refMap.reset();

	return true;
}