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;
}
bool FindMethodLocalVariables::VisitDeclRefExpr(DeclRefExpr* e) {
  switch(_state) {
    case LHS: {
//      _os << "#######: DeclRefExpr: " << getVariableName(e) << ", lvalue: " << e->getDecl()->getDeclKindName() << "\n";
      
      //    e->dumpAll();
      ValueDecl* vd = e->getDecl();
      if (vd == NULL)
        break;
      
      QualType q = vd->getType();
      const Type* t = q.getTypePtr();
      
      Decl* d = e->getDecl();
      if (d == NULL)
        break;
      
      string declKind(d->getDeclKindName());
      if ((getDataMembertype(e) == "enum sc_core::sc_time_unit") ||
          (declKind == "CXXMethod"))      {
        break;
      }
      string name = getVariableName(e);
      if ((_inMethodVariables.find(name)) != _inMethodVariables.end()) {
        // Found entry.
        break;
      }
      //      _os << "=> @@@@@@@@@@@@@@@@@@@@@@@@@@@ Insert\n";
      /// Prepare variable information.
      VariableTypeInfo v(_os);
      v._name = getVariableName(e);
      v._expr = e;
      v._isArray = t->isConstantArrayType();
      v._type = getDataMembertype(e);
      if (v._isArray) {
        if (const ConstantArrayType* ca = dyn_cast<ConstantArrayType>(t)) {
          v._arraySize = ca->getSize();
        }
      }
      
      /// Freed in the destructor of VariableTypeInfo.
      FindTemplateTypes te;
      te.Enumerate(t);
      v._tempArgs = te;
//      v.print();
      
      _inMethodVariables.insert(kvType(v._name, v));
      break;
    }
    case RHS: {
      //_os << "\n=> DeclRefExpr\n";
      break;
    }
  };
  
  return true;
}