int main(int argc, char** argv) {
	SgProject* proj = frontend(argc,argv);
	SgFunctionDeclaration* mainDecl = SageInterface::findMain(proj);
	SgFunctionDefinition* mainDef = mainDecl->get_definition();
	std::vector<SgNode*> ifExps;
	ifExps = NodeQuery::querySubTree(mainDef, V_SgIfStmt);
	for (int i = 0; i < ifExps.size(); i++) {
		getIfConds(isSgIfStmt(ifExps[i]), isSgScopeStatement(mainDef));
	}
	
	std::vector<SgNode*> assignNodes = NodeQuery::querySubTree(mainDef, V_SgVariableDeclaration);
	std::cout << assignNodes.size() << " nodes found" << std::endl;
	std::vector<SgBinaryOp*> bin_ops;
	std::vector<SgUnaryOp*> un_ops;
	std::vector<SgNode*> other;
	std::vector<SgExpression*> results;
	for (std::vector<SgNode*>::iterator i = assignNodes.begin(); i != assignNodes.end(); i++) {
	
		SgVariableDeclaration* vdecl = isSgVariableDeclaration(*i);
		SgInitializedNamePtrList vlst = vdecl->get_variables();
		SgInitializedName* initName = isSgInitializedName((*(vlst.begin())));
		SgExpression* exp = isSgAssignInitializer(initName->get_initializer())->get_operand();
		std::cout << exp->class_name() << std::endl;
		if (!isSgFunctionCallExp(exp)) {
			getExps(exp, isSgInitializedName(*i), results, 0);
		
	
	std::cout << "prefixes" << std::endl;
	for (int j = 0; j < prefixes.size(); j++) {
	        SgExprStatement* expSt = SageBuilder::buildExprStatement_nfi(prefixes[j]);
		SageInterface::insertStatement(isSgVariableDeclaration(*i),expSt,true);
		
		std::cout << prefixes[j]->class_name() << std::endl;
	}
	std::cout << "results" << std::endl;
	for (int j = 0; j < results.size(); j++) {
		std::cout << results[j]->class_name() << std::endl;
	}
	std::cout << "postfixes" << std::endl;
	for (int j = 0; j < postfixes.size(); j++) {
		SgExprStatement* expSt = SageBuilder::buildExprStatement_nfi(postfixes[j]);
                SageInterface::insertStatement(isSgVariableDeclaration(*i),expSt,false);
		std::cout << postfixes[j]->class_name() << std::endl;
	}
	
	replaceExps(exp,vdecl);
	simplifyExps(exp);
	}
		
	}
			
	backend(proj);
	return 0;
}
Ejemplo n.º 2
0
   bool compare_types(SgInitializedName* f_name, SgInitializedName* c_name)
   {
      SgType* c_type = c_name->get_type();
      SgType* f_type = f_name->get_type();
      SgExpression* f_kind_type = f_type->get_type_kind();
      bool hasValue = false;
      SgVariableDeclaration* var_dec = isSgVariableDeclaration(f_name->get_declaration());
      if (var_dec!= NULL) {
         SgTypeModifier type_mod = var_dec->get_declarationModifier().get_typeModifier();
         hasValue = type_mod.isValue();
      }

      SgType* f_to_c_type = fortran_to_c_type(f_type, f_kind_type, hasValue);

      if (f_to_c_type != NULL) {
         std::cout << "f_to_c_type is " << f_to_c_type->class_name() << ": " << f_to_c_type << std::endl;
         if (f_to_c_type == c_type) {
            std::cout << "f_to_c_type is equal to c_type, returning true" << std::endl;
            return true;
         }
      }
      else {
         std::cout << "f_to_c_type is NULL, returning false" << std::endl;
         return false;
      }

      std::cout << "\t compare_types(): Types don't match, returning false" << std::endl;

      return false;
   }
Ejemplo n.º 3
0
/*QY: This is used to support traversal of AST by the POET interpreter*/
bool POETAstInterface::MatchAstTypeName(const Ast& n, const std::string& tname)
{ 
 if (tname == "EXP") {
     return AstInterface::IsExpression((SgNode*)n) != AST_NULL;
 }
 else if (tname == "ExpStmt") {
    SgExprStatement* s = isSgExprStatement((SgNode*)n);
    return (s != 0);
 }
 else if (tname == "FunctionDecl") {
     return AstInterface :: IsFunctionDefinition((SgNode*)n);
 }
 else if (tname == "For") {
     return isSgForStatement((SgNode*)n) != 0;
 }
 else if (tname == "Assign") {
     return AstInterface::IsAssignment((SgNode*)n);
 }
 else if (tname == "Pragma") {
   return isSgPragmaDeclaration((SgNode*)n) != 0;
 }
 else if (tname == "VarDecl") {
     return isSgVariableDeclaration((SgNode*)n) != 0;
 }
 else if (tname == "Variable") {
    return isSgInitializedName((SgNode*)n);
 }
 else if (tname == "Loop") {}
 else std::cerr << "does not recognize type name:" << tname << "\n";
 return false;
}
Ejemplo n.º 4
0
bool
TaintAnalysis::magic_tainted(SgNode *node, FiniteVarsExprsProductLattice *prodLat) {
    if (isSgInitializedName(node)) {
        SgInitializedName *iname = isSgInitializedName(node);
        std::string vname = iname->get_name().getString();
        TaintLattice *tlat = dynamic_cast<TaintLattice*>(prodLat->getVarLattice(varID(iname)));
        if (tlat && 0==vname.compare(0, 7, "TAINTED")) {
            bool modified = tlat->set_vertex(TaintLattice::VERTEX_TAINTED);
            if (debug) {
                *debug <<"TaintAnalysis::magic_tainted: lattice is magically " <<tlat->to_string()
                       <<(modified?" (modified)":" (not modified)") <<"\n";
            }
            return modified;
        }
    } else if (isSgVarRefExp(node)) {
        SgVarRefExp *vref = isSgVarRefExp(node);
        std::string vname = vref->get_symbol()->get_name().getString();
        TaintLattice *tlat = dynamic_cast<TaintLattice*>(prodLat->getVarLattice(varID(vref)));
        if (tlat && 0==vname.compare(0, 7, "TAINTED")) {
            bool modified = tlat->set_vertex(TaintLattice::VERTEX_TAINTED);
            if (debug) {
                *debug <<"TaintAnalysis::magic_tainted: lattice is magically " <<tlat->to_string()
                       <<(modified?" (modified)":" (not modified)") <<"\n";
            }
            return modified;
        }
    } else if (isSgVariableDeclaration(node)) {
        SgVariableDeclaration *vdecl = isSgVariableDeclaration(node);
        const SgInitializedNamePtrList &inames = vdecl->get_variables();
        for (size_t i=0; i<inames.size(); ++i) {
            std::string vname = inames[i]->get_name().getString();
            TaintLattice *tlat = dynamic_cast<TaintLattice*>(prodLat->getVarLattice(varID(inames[i])));
            if (tlat && 0==vname.compare(0, 7, "TAINTED")) {
                bool modified = tlat->set_vertex(TaintLattice::VERTEX_TAINTED);
                if (debug) {
                    *debug <<"TaintAnalysis::magic_tainted: lattice is magically " <<tlat->to_string()
                           <<(modified?" (modified)":" (not modified)") <<"\n";
                }
                return modified;
            }
        }
    }

    return false;
}
Ejemplo n.º 5
0
void
CompassAnalyses::StaticConstructorInitialization::Traversal::
visit(SgNode* node)
   { 
  // Test for static initialization of variables of type class, such initializations where they are 
  // static or appear in global scope can be called in an order dependent upon the compiler and this 
  // can lead to subtle bugs in large scale applications.

     SgVariableDeclaration* variableDeclaration = isSgVariableDeclaration(node);

     if (variableDeclaration != NULL)
        {
          SgInitializedNamePtrList::iterator i = variableDeclaration->get_variables().begin();
          while (i != variableDeclaration->get_variables().end())
             {
               SgInitializedName* initializedName = *i;

            // Check the type and see if it is a class (check for typedefs too)
               SgType* variableType = initializedName->get_type();

               SgClassType *classType = isSgClassType(variableType);
               if (classType != NULL)
                  {
                 // Now check if this is a global or namespace variable or an static class member
                 // This might also have to be a test for other scopes as well.
                    SgScopeStatement* scope = variableDeclaration->get_scope();
                    if (isSgGlobal(scope) != NULL || isSgNamespaceDefinitionStatement(scope) != NULL)
                       {
                      // printf ("Found a global variable defining a class = %p \n",initializedName);
                      // variableDeclaration->get_file_info()->display("global variable defining a class");
                         output->addOutput(new CheckerOutput(initializedName));
                       }

                    if (isSgClassDefinition(scope) != NULL)
                       {
                      // Now check if it is a static data member
                         if (variableDeclaration->get_declarationModifier().get_storageModifier().isStatic() == true)
                            {
                           // printf ("Found a static data member defining a class = %p \n",initializedName);
                           // variableDeclaration->get_file_info()->display("static data member defining a class");
                              output->addOutput(new CheckerOutput(initializedName));
                            }
                       }
                  }

            // increment though the variables in the declaration (typically just one)
               i++;
             }
        }

   } //End of the visit function.
Ejemplo n.º 6
0
void
SgVariableDeclaration::fixupCopy_symbols(SgNode* copy, SgCopyHelp & help) const
   {
#if DEBUG_FIXUP_COPY
     printf ("Inside of SgVariableDeclaration::fixupCopy_symbols() for %p = %s copy = %p \n",this,this->class_name().c_str(),copy);
#endif

  // Also call the base class version of the fixupCopycopy() member function
     SgDeclarationStatement::fixupCopy_symbols(copy,help);

     SgVariableDeclaration* variableDeclaration_copy = isSgVariableDeclaration(copy);
     ROSE_ASSERT(variableDeclaration_copy != NULL);

  // DQ (10/14/2007): Handle the case of a type defined in the base type of the typedef (similar problem for SgVariableDeclaration).
  // printf ("this = %p this->get_variableDeclarationContainsBaseTypeDefiningDeclaration() = %s \n",this,this->get_variableDeclarationContainsBaseTypeDefiningDeclaration() ? "true" : "false");
     if (this->get_variableDeclarationContainsBaseTypeDefiningDeclaration() == true)
        {
          ROSE_ASSERT(variableDeclaration_copy->get_variableDeclarationContainsBaseTypeDefiningDeclaration() == true);
          SgDeclarationStatement* baseTypeDeclaration_original = this->get_baseTypeDefiningDeclaration();
          SgDeclarationStatement* baseTypeDeclaration_copy     = variableDeclaration_copy->get_baseTypeDefiningDeclaration();

          ROSE_ASSERT(baseTypeDeclaration_original != NULL);
          ROSE_ASSERT(baseTypeDeclaration_copy != NULL);

       // printf ("In SgVariableDeclaration::fixupCopy_symbols(): Calling fixupCopy on %p = %s \n",baseTypeDeclaration_original,baseTypeDeclaration_original->class_name().c_str());

          baseTypeDeclaration_original->fixupCopy_symbols(baseTypeDeclaration_copy,help);
        }

     const SgInitializedNamePtrList & variableList_original = this->get_variables();
     SgInitializedNamePtrList & variableList_copy           = variableDeclaration_copy->get_variables();

  // printf ("Inside of SgVariableDeclaration::fixupCopy_symbols(): variableList_original.size() = %ld \n",(long)variableList_original.size());

     ROSE_ASSERT(variableList_original.size() == variableList_copy.size());

     SgInitializedNamePtrList::const_iterator i_original = variableList_original.begin();
     SgInitializedNamePtrList::iterator i_copy           = variableList_copy.begin();

  // Iterate over both lists to match up the correct pairs of SgInitializedName objects
     while ( (i_original != variableList_original.end()) && (i_copy != variableList_copy.end()) )
        {
       // printf ("Looping over the initialized names in the variable declaration variable = %p = %s \n",(*i_copy),(*i_copy)->get_name().str());

          (*i_original)->fixupCopy_symbols(*i_copy,help);

          i_original++;
          i_copy++;
        }
   }
TEST(SageInterfaceTypeEquivalence, ConstVarIntLiteralArrayIsEqual){
  ::SgGlobal *global = new SgGlobal();
  // build assign-initializer, build variable declaration, build varrefexp
  ::SgBasicBlock* bb = SageBuilder::buildBasicBlock();
  bb->set_parent(global);
  ::SgAssignInitializer* init = SageBuilder::buildAssignInitializer(SageBuilder::buildIntVal(42), SageBuilder::buildIntType());
  ::SgVariableDeclaration* vDecl = isSgVariableDeclaration(SageBuilder::buildVariableDeclaration(SgName("refVar"), SageBuilder::buildConstType(SageBuilder::buildIntType()), init, bb));
//  vDecl->get_declarationModifier().get_typeModifier().get_constVolatileModifier().setConst();
  ::SgVarRefExp* vRef = SageBuilder::buildVarRefExp(vDecl);
  ::SgArrayType* a_7 = SageBuilder::buildArrayType(SageBuilder::buildIntType(), vRef);
  ::SgArrayType* a_8 = SageBuilder::buildArrayType(SageBuilder::buildIntType(), vRef);
  bool tcRef = SageInterface::checkTypesAreEqual(a_7, a_8);
  EXPECT_EQ(tcRef, true);
  delete global;
}
void UnparseHeadersTransformVisitor::visit(SgNode* node) {
    //Use a pointer to a constant SgVariableDeclaration to be able to call the constant getter variableDeclaration -> get_variables(), 
    //which does not mark the node as modified.
    const SgVariableDeclaration* variableDeclaration = isSgVariableDeclaration(node);
    if (variableDeclaration != NULL) {
        const SgInitializedNamePtrList& nameList = variableDeclaration -> get_variables();
        for (SgInitializedNamePtrList::const_iterator nameListIterator = nameList.begin(); nameListIterator != nameList.end(); nameListIterator++) {
            string originalName = ((*nameListIterator) -> get_name()).getString();
            //Rename any variable, whose name ends with matchEnding.
            if (originalName.size() >= matchEndingSize && originalName.compare(originalName.size() - matchEndingSize, matchEndingSize, matchEnding) == 0) { 
                SageInterface::set_name(*nameListIterator, originalName + renameEnding);
            }
        }
    }	
}
Ejemplo n.º 9
0
void
Traversal::visit(SgNode* node)
   {
     SgVariableDeclaration* variableDeclaration = isSgVariableDeclaration(node);

  // Look for variable declarations appearing in global scope!
  // if (variableDeclaration != NULL && isSgGlobal(variableDeclaration->get_parent()) != NULL)
     if (variableDeclaration != NULL)
        {
          SgInitializedNamePtrList::iterator i = variableDeclaration->get_variables().begin();
          while (i != variableDeclaration->get_variables().end())
             {
               SgInitializedName* initializedName = *i;

            // Check the type and see if it is a class (check for typedefs too)
               SgType* variableType = initializedName->get_type();

               SgClassType *classType = isSgClassType(variableType);
               if (classType != NULL)
                  {
                 // Now check if this is a global variable or an static class member
                    SgScopeStatement* scope = variableDeclaration->get_scope();
                    if (isSgGlobal(scope) != NULL)
                       {
                         printf ("Found a global variable defining a class \n");
                      // variableDeclaration->get_file_info()->display("global variable defining a class");
                         outputPositionInformation(variableDeclaration);
                       }

                    if (isSgClassDefinition(scope) != NULL)
                       {
                      // Now check if it is a static data member
                         if (variableDeclaration->get_declarationModifier().get_storageModifier().isStatic() == true)
                            {
                              printf ("Found a static data member defining a class \n");
                           // variableDeclaration->get_file_info()->display("static data member defining a class");
                              outputPositionInformation(variableDeclaration);
                            }
                       }
                  }

            // increment though the variables in the declaration (typically just one)
               i++;
             }
        }
   }
VariableIdSet AnalysisAbstractionLayer::astSubTreeVariables(SgNode* node, VariableIdMapping& vidm) {
  VariableIdSet vset;
  RoseAst ast(node);
  for(RoseAst::iterator i=ast.begin();i!=ast.end();++i) {
    VariableId vid; // default creates intentionally an invalid id.
    if(SgVariableDeclaration* varDecl=isSgVariableDeclaration(*i)) {
      vid=vidm.variableId(varDecl);
    } else if(SgVarRefExp* varRefExp=isSgVarRefExp(*i)) {
      vid=vidm.variableId(varRefExp);
    } else if(SgInitializedName* initName=isSgInitializedName(*i)) {
      vid=vidm.variableId(initName);
    }
    if(vid.isValid())
      vset.insert(vid);
  }
  return vset;
}
void
FindVariableDeclarations::visit ( SgNode* astNode )
   {
     SgBasicBlock* block = isSgBasicBlock(astNode);
     if (block != NULL)
        {
          SgStatementPtrList & listOfStatements = block->get_statements();
          for (size_t i = 0; i < listOfStatements.size(); i++)
             {
               SgVariableDeclaration* variableDeclaration = isSgVariableDeclaration(listOfStatements[i]);
               if (variableDeclaration != NULL)
                  {
                    printf ("Found a variable decaration in a SgBasicBlock at: \n");
                    variableDeclaration->get_file_info()->display("Found a variable decaration in a SgBasicBlock");
                  }
             }
        }
   }
Ejemplo n.º 12
0
    bool findPublicVarMembers (SgNode *node, string &str) {
	SgVariableDeclaration *decl;
	if (decl = isSgVariableDeclaration(node)) {
	    SgDeclarationModifier &dfm = decl->get_declarationModifier();
	    if (dfm.get_accessModifier().isPublic()) {
		// check if it belongs to a class
		SgStatement *block = ((SgVariableDeclaration *) node)->get_scope();
		SgClassDefinition *classDef;
		if (classDef = isSgClassDefinition(block)) {
		    if (classDef->get_declaration()->get_class_type() == SgClassDeclaration::e_class) {
                        str = classDef->get_qualified_name().getString();		   
                        return true;
                    }
		}
	    } 
	}
	return false;
    }    
Ejemplo n.º 13
0
int main(int argc, char* argv[]) {
	SgProject* proj = frontend(argc,argv);
	SgFunctionDeclaration* mainDecl = SageInterface::findMain(proj);
	SgFunctionDefinition* mainDef = mainDecl->get_definition();
//	std::vector<SgNode*> dotExps = NodeQuery::querySubTree(mainDef, V_SgDotExp);
	std::vector<SgNode*> varRefs = NodeQuery::querySubTree(mainDef,V_SgVarRefExp);
	int classExps = 0;
	for (unsigned int i = 0; i < varRefs.size(); i++) {
		if (isSgClassType(isSgVarRefExp(varRefs[i])->get_type())) {
			SgClassType* ct = isSgClassType(isSgVarRefExp(varRefs[i])->get_type());
			std::cout << "name of ref: " << isSgVarRefExp(varRefs[i])->get_symbol()->get_name().getString() << std::endl;
			if (SageInterface::isStructType(ct)) {
			SgDeclarationStatement* decl = isSgType(ct)->getAssociatedDeclaration();
			SgDeclarationStatement* defining_decl = decl->get_definingDeclaration();
			if (!(defining_decl->isNameOnly())) {	
				if (isSgClassDeclaration(defining_decl)) {
				if (isSgClassDeclaration(defining_decl)->get_definition()) {
				SgDeclarationStatementPtrList member_stats = isSgClassDeclaration(defining_decl)->get_definition()->get_members();
				SgDeclarationStatementPtrList::iterator j = member_stats.begin();
				for (; j != member_stats.end(); j++) {
					SgDeclarationStatement* d = isSgDeclarationStatement(*j);
					std::cout << "decl stat name: " << d->class_name() << std::endl;
					SgInitializedNamePtrList init_lst = isSgVariableDeclaration(d)->get_variables();
					SgInitializedNamePtrList::iterator k = init_lst.begin();
					std::cout << "variables in initialized name ptr list..." << std::endl;
					for (; k != init_lst.end(); k++) {
						std::cout << isSgInitializedName(*k)->get_name().getString() << std::endl;
						std::cout << isSgInitializedName(*k)->get_type()->class_name() << std::endl;
					}
				}
					
				classExps+=1;
				}
				}
			}
			
			
			}
		}
	}	
	std::cout << "num class_exp: " << classExps << std::endl;
	return 0;
}	
Ejemplo n.º 14
0
void fixupEdgBugDuplicateVariablesInAST()
   {
  // DQ (3/11/2006): Introduce tracking of performance of ROSE.
     TimingPerformance timer1 ("Fixup known EDG bug where some variable declarations are dropped from the source sequence lists:");

     std::set<SgVariableDeclaration*> declarations_to_remove;

  // Loop over all variables added using the convert_field_use() function.
     std::set<SgVariableDeclaration*>::iterator i = nodesAddedWithinFieldUseSet.begin();
     while (i != nodesAddedWithinFieldUseSet.end())
        {
          SgVariableDeclaration* var_decl = *i;
          SgName name = var_decl->get_variables()[0]->get_name();

          SgClassDefinition* classDefinition = isSgClassDefinition(var_decl->get_parent());
          ROSE_ASSERT(classDefinition != NULL);

          std::vector<SgDeclarationStatement*> & members = classDefinition->get_members();

       // Loop over all data members in the class.
          std::vector<SgDeclarationStatement*>::iterator j = members.begin();
          while (j != members.end())
             {
               SgVariableDeclaration* possible_matching_variable_declaration = isSgVariableDeclaration(*j);
               if (possible_matching_variable_declaration != NULL && possible_matching_variable_declaration != var_decl)
                  {
                    if (possible_matching_variable_declaration->get_variables()[0]->get_name() == name)
                       {
#if 0
                         printf ("matching variable declaration found for name = %s \n",name.str());
#endif
                         declarations_to_remove.insert(var_decl);
                       }
                  }
 
               j++;
             }

          i++;
        }

  // Now remove all of the variable declarations that we detected to be duplicates.
     std::set<SgVariableDeclaration*>::iterator k = declarations_to_remove.begin();
     while (k != declarations_to_remove.end())
        {
          SgDeclarationStatement* var_decl = *k;

          SgClassDefinition* classDefinition = isSgClassDefinition(var_decl->get_parent());
          ROSE_ASSERT(classDefinition != NULL);

          std::vector<SgDeclarationStatement*> myvector;
          myvector.push_back(*k);

          std::vector<SgDeclarationStatement*> & members = classDefinition->get_members();

       // members.erase(*k);
       // members.erase(myvector.begin(),myvector.end());

       // This is the remove/erase idiom.
          members.erase(remove(members.begin(), members.end(), *k), members.end());

          k++;
        }

   }
Ejemplo n.º 15
0
void DataFlow<Annotation, Language, Runtime>::createContextFromLoopTree(
  const LoopTrees<Annotation> & loop_trees,
  context_t & context
) const {
  assert(context.datas.empty());
  assert(context.datas_in.empty());
  assert(context.datas_out.empty());
  assert(context.accesses_map.empty());

  typename std::set<Data<Annotation> *>::iterator it_data;

  const std::vector<Data<Annotation> *> & data_vect = loop_trees.getDatas();
  context.datas.insert(data_vect.begin(), data_vect.end());
  for (it_data = context.datas.begin(); it_data != context.datas.end(); it_data++) {
    assert(*it_data != NULL);
    if ((*it_data)->isFlowIn())
      context.datas_in.insert(*it_data);
    if ((*it_data)->isFlowOut())
      context.datas_out.insert(*it_data);
  }

  const std::vector<typename LoopTrees<Annotation>::node_t *> & nodes = loop_trees.getNodes();
  typename std::vector<typename LoopTrees<Annotation>::node_t *>::const_iterator it_node;
  for (it_node = nodes.begin(); it_node != nodes.end(); it_node++) {
    typename LoopTrees<Annotation>::cond_t * cond = dynamic_cast<typename LoopTrees<Annotation>::cond_t *>(*it_node);
    typename LoopTrees<Annotation>::stmt_t * stmt = dynamic_cast<typename LoopTrees<Annotation>::stmt_t *>(*it_node);

    if (cond == NULL && stmt == NULL) continue;

    typename std::map<typename LoopTrees<Annotation>::node_t *, accesses_list_t>::iterator it_access = 
          context.accesses_map.insert(std::pair<typename LoopTrees<Annotation>::node_t *, accesses_list_t>(*it_node, accesses_list_t())).first;

    std::vector<data_access_t> & read  = it_access->second.reads;
    std::vector<data_access_t> & write = it_access->second.writes;

    if (cond != NULL) {
      assert(false); /// \todo
    }
    else if (stmt != NULL) {
      SgExprStatement * expr_stmt = isSgExprStatement(stmt->statement);
      SgVariableDeclaration * var_decl = isSgVariableDeclaration(stmt->statement);
      if (expr_stmt != NULL) {
        SgExpression * exp = expr_stmt->get_expression();
        assert(exp != NULL);

        SgBinaryOp * bin_op = isSgBinaryOp(exp);
        if (bin_op != NULL) {
          SgExpression * lhs_exp = bin_op->get_lhs_operand_i();
          SgExpression * rhs_exp = bin_op->get_rhs_operand_i();

          assert(lhs_exp != NULL && rhs_exp != NULL);

          SgAssignOp * assign_op = isSgAssignOp(exp);
          SgCompoundAssignOp * compound_assign_op = isSgCompoundAssignOp(exp);

          assert((assign_op != NULL) xor (compound_assign_op != NULL)); // FIXME expression statement are not always made of assignement

          if (assign_op != NULL || compound_assign_op != NULL) {
            append_access(lhs_exp, write, context); // add access in lhs to write set
            append_access(rhs_exp, read,  context); // add access in rhs to read set
          }
          if (compound_assign_op != NULL) {
            append_access(lhs_exp, read,  context); // add access in lhs to read set
          }
        }
        else assert(false); // FIXME expression statement are not always made of binary op
      }
      else if (var_decl != NULL) {
        assert(var_decl->get_variables().size() == 1);
        SgInitializedName * init_name = isSgInitializedName(var_decl->get_variables()[0]);
        assert(init_name != NULL);
        SgInitializer * init = isSgInitializer(init_name->get_initptr());
        if (init != NULL) {
          SgAssignInitializer * assign_init = isSgAssignInitializer(init);
          if (assign_init != NULL) {
            SgExpression * exp = assign_init->get_operand_i();
            assert(exp != NULL);
            append_access(exp, read, context);
          }
          else assert(false);
        }
      }
      else assert(false);
    }
  }
}
int main(int argc, char **argv)
{
  SgProject *project = frontend(argc, argv);
  
  // Instantiate a class hierarchy wrapper.
  ClassHierarchyWrapper classHierarchy( project );

  std::list<SgNode *> nodes2 = NodeQuery::querySubTree(project,
						      V_SgVariableDefinition);

  for (std::list<SgNode *>::iterator it = nodes2.begin();
       it != nodes2.end(); ++it ) {

    SgNode *n = *it;
    ROSE_ASSERT(n != NULL);

    SgVariableDefinition *varDefn =
      isSgVariableDefinition(n);
    ROSE_ASSERT(varDefn != NULL);

    std::cout << "Var defn: " << varDefn->unparseToCompleteString() << std::endl;

  }

  std::list<SgNode *> nodes1 = NodeQuery::querySubTree(project,
						      V_SgVariableDeclaration);

  for (std::list<SgNode *>::iterator it = nodes1.begin();
       it != nodes1.end(); ++it ) {

    SgNode *n = *it;
    ROSE_ASSERT(n != NULL);

    SgVariableDeclaration *varDecl =
      isSgVariableDeclaration(n);
    ROSE_ASSERT(varDecl != NULL);

    SgInitializedNamePtrList &variables =
      varDecl->get_variables();
    SgInitializedNamePtrList::iterator varIter;
    for (varIter = variables.begin(); 
	 varIter != variables.end(); ++varIter) {
      
      SgNode *var = *varIter;
      ROSE_ASSERT(var != NULL);
      
      SgInitializedName *initName =
	isSgInitializedName(var);
      ROSE_ASSERT(initName != NULL);
      
      if ( isSgClassType(initName->get_type()) ) {

	SgClassType *classType = isSgClassType(initName->get_type());
	ROSE_ASSERT(classType != NULL);

	SgDeclarationStatement *declStmt = classType->get_declaration();
	ROSE_ASSERT(declStmt != NULL);
	
	SgClassDeclaration *classDeclaration = isSgClassDeclaration(declStmt);
	ROSE_ASSERT(classDeclaration != NULL);
      
	//	std::cout << "From var decl got: " << classDeclaration->unparseToCompleteString() << std::endl;

	SgClassDefinition *classDefinition =
	  classDeclaration->get_definition();
	if ( classDefinition != NULL ) {
	  std::cout << "From var decl got: " << classDefinition->unparseToCompleteString() << std::endl;
	}

      }

    }
    

  }

  std::list<SgNode *> nodes = NodeQuery::querySubTree(project,
						      V_SgClassDeclaration);

  for (std::list<SgNode *>::iterator it = nodes.begin();
       it != nodes.end(); ++it ) {

    SgNode *n = *it;
    ROSE_ASSERT(n != NULL);

    SgClassDeclaration *classDeclaration1 =
      isSgClassDeclaration(n);
    ROSE_ASSERT(classDeclaration1 != NULL);

    SgDeclarationStatement *definingDecl =
      classDeclaration1->get_definingDeclaration();
    if ( definingDecl == NULL )
      continue;
    
    SgClassDeclaration *classDeclaration =
      isSgClassDeclaration(definingDecl);
    ROSE_ASSERT(classDeclaration != NULL);


    SgClassDefinition *classDefinition =
      classDeclaration->get_definition();
    ROSE_ASSERT(classDefinition != NULL);

    std::cout << "Calling getSubclasses on " << classDefinition->unparseToCompleteString() << std::endl;

    SgClassDefinitionPtrList subclasses = 
      classHierarchy.getSubclasses(classDefinition);

    // Iterate over all subclasses.
    for (SgClassDefinitionPtrList::iterator subclassIt = subclasses.begin();
	 subclassIt != subclasses.end(); ++subclassIt) {
      
      SgClassDefinition *subclass = *subclassIt;
      ROSE_ASSERT(subclass != NULL);
      
      std::cout << "subclass" << std::endl;

    }

  }
#if 0
#if 0
  std::list<SgNode *> nodes = NodeQuery::querySubTree(project,
						      V_SgClassDefinition);

  for (std::list<SgNode *>::iterator it = nodes.begin();
       it != nodes.end(); ++it ) {

    SgNode *n = *it;
    ROSE_ASSERT(n != NULL);

    SgClassDefinition *classDefinition =
      isSgClassDefinition(n);
    ROSE_ASSERT(classDefinition != NULL);

    std::cout << "Calling getSubclasses on " << classDefinition->unparseToCompleteString() << std::endl;

    SgClassDefinitionPtrList subclasses = 
      classHierarchy.getSubclasses(classDefinition);

    // Iterate over all subclasses.
    for (SgClassDefinitionPtrList::iterator subclassIt = subclasses.begin();
	 subclassIt != subclasses.end(); ++subclassIt) {
      
      SgClassDefinition *subclass = *subclassIt;
      ROSE_ASSERT(subclass != NULL);
      
      std::cout << "subclass" << std::endl;

    }

  }
#else
  // Collect all function/method invocations.
  std::list<SgNode *> nodes = NodeQuery::querySubTree(project,
						      V_SgFunctionCallExp);

  unsigned int numCallSites = 0;
  unsigned int numMonomorphicCallSites = 0;
  unsigned int numPossibleResolutions = 0;

  // Visit each call site.
  for (std::list<SgNode *>::iterator it = nodes.begin();
       it != nodes.end(); ++it ) {

    SgNode *n = *it;
    ROSE_ASSERT(n != NULL);

    SgFunctionCallExp *functionCallExp =
      isSgFunctionCallExp(n);
    ROSE_ASSERT(functionCallExp != NULL);

    // We are only interested in examining method invocations.
    bool isDotExp = false;
    if ( !isMethodCall(functionCallExp, isDotExp) )
      continue;
    
    numCallSites++;
    // Certainly can be resolved to the static method.
    numPossibleResolutions++;

    if ( isDotExp ) {
      // If this is a dot expression (i.e., a.foo()), we can
      // statically determine its type.
      numMonomorphicCallSites++;
      continue;
    }

    // Retrieve the static function declaration.
    SgFunctionDeclaration *functionDeclaration = 
      getFunctionDeclaration(functionCallExp);

    // Ensure it is actually a method declaration.
    SgMemberFunctionDeclaration *memberFunctionDeclaration =
      isSgMemberFunctionDeclaration(functionDeclaration);
    ROSE_ASSERT(memberFunctionDeclaration != NULL);

    unsigned int numOverridesForMethod = 0;

    if ( ( isVirtual(functionDeclaration) ) ||
	 ( isDeclaredVirtualWithinAncestor(functionDeclaration) ) ) {
      
      SgClassDefinition *classDefinition = 
	isSgClassDefinition(memberFunctionDeclaration->get_scope());
      ROSE_ASSERT(classDefinition != NULL);
      
      SgClassDefinitionPtrList subclasses = 
	classHierarchy.getSubclasses(classDefinition);

      // Iterate over all subclasses.
      for (SgClassDefinitionPtrList::iterator subclassIt = subclasses.begin();
	   subclassIt != subclasses.end(); ++subclassIt) {

	SgClassDefinition *subclass = *subclassIt;
	ROSE_ASSERT(subclass != NULL);

	std::cout << "subclass" << std::endl;

	// Iterate over all of the methods defined in this subclass.
	SgDeclarationStatementPtrList &decls =
	  subclass->get_members();
	for (SgDeclarationStatementPtrList::iterator declIter = decls.begin();
	     declIter != decls.end(); ++declIter) {

	  SgDeclarationStatement *declStmt = *declIter;
	  ROSE_ASSERT(declStmt != NULL);

	  SgMemberFunctionDeclaration *method =
	    isSgMemberFunctionDeclaration(declStmt);
	  if ( method == NULL ) {
	    continue;
	  }

	  // Determine whether subclass of the class defining this
	  // method overrides the method.
	  if ( methodOverridesVirtualMethod(method, 
					    memberFunctionDeclaration) ) {
	    numOverridesForMethod++;
	  }

	}

      }

      if ( numOverridesForMethod == 0 )
	numMonomorphicCallSites++;
      numPossibleResolutions += numOverridesForMethod;

      std::cout << "Method invocation has " << numOverridesForMethod + 1 << " possible resolutions " << std::endl;
      std::cout << functionCallExp->unparseToCompleteString() << std::endl;

    }

  }
#endif
#endif
  return 0;
}
Ejemplo n.º 17
0
MySynthesizedAttribute
MyTraversal::evaluateRewriteSynthesizedAttribute (
		SgNode* astNode,
		MyInheritedAttribute inheritedAttribute,
		SubTreeSynthesizedAttributes synthesizedAttributeList )
{
	MySynthesizedAttribute returnAttribute;

	switch(astNode->variantT())
	{

		case V_SgVarRefExp: {
				cout << " found V_SgVarRefExp " << astNode->unparseToString() <<  endl;
				if(mReplaceVariable) {
					if( ( strcmp( astNode->unparseToString().c_str(), VARIABLE_NAME )==0 ) &&
							( isSgTypeInt(isSgVarRefExp(astNode)->get_type()) )
						) {
						returnAttribute.setVarRefFound( true );
						AstRestructure::unparserReplace( isSgVarRefExp(astNode), "newInt" );
						cout << "   replacing with 'newInt' " << endl;
					}
				}
			} break;

		case V_SgVariableDeclaration: {
				SgVariableDeclaration *varDecl = isSgVariableDeclaration(astNode);
				cout << " found V_SgVariableDeclaration " << astNode->unparseToString() <<  endl;
				// replace only integer variables called "i"
				if( (varDecl->get_traversalSuccessorContainer().size() > 0) &&
                                    isSgInitializedName( varDecl->get_traversalSuccessorContainer()[0]) && 
                                                ( strcmp(isSgInitializedName(varDecl->get_traversalSuccessorContainer()[0])->get_name().str(), VARIABLE_NAME )==0 ) &&
						( isSgTypeInt(isSgInitializedName(varDecl->get_traversalSuccessorContainer()[0])->get_type()) )
					) {
					// found declaration of "int i"
					string newDeclaration("int newInt = i + 100;");
					returnAttribute.insert( varDecl, newDeclaration, HighLevelCollectionTypedefs::LocalScope, HighLevelCollectionTypedefs::AfterCurrentPosition );
					assert( mReplaceVariable==0 ); // if it's true, there is another "int i", and this transformation wont work...
					mReplaceVariable = 1;
					cout << "   inserted: '" << newDeclaration <<"' , starting variable replacement " <<  endl;
				}
			} break;

		default:
			break;
	} // node type

	bool synth = false;
	for( SubTreeSynthesizedAttributes::iterator i=synthesizedAttributeList.begin();
             i!= synthesizedAttributeList.end(); i++ ) {
                if( (*i).getVarRefFound() ) synth = true;
	}
	if( synth ) {
		returnAttribute.setVarRefFound( true );
		if(isSgStatement( astNode )) {
			cout << "   new statement " << " : '" << astNode->unparseToString() << "' " << endl;
			returnAttribute.setVarRefFound( false );
			//if(!isSgReturnStmt( astNode )) { // DEBUG, this should work!??!?
				returnAttribute.replace( astNode, astNode->unparseToString(), HighLevelCollectionTypedefs::LocalScope );
			//}
		}
	}

	if(isSgScopeStatement(astNode)) {
		// dont replace variable in higher scopes...
		if(mReplaceVariable > 0) {
			mReplaceVariable--;
			cerr << "end of scope " << mReplaceVariable << endl;
		}
	} 

	return returnAttribute;
}
Ejemplo n.º 18
0
void
TypeTransformation::visit ( SgNode* astNode )
{
    SgVariableDeclaration* variableDeclaration = isSgVariableDeclaration(astNode);
    if (variableDeclaration != NULL)
    {
#if 0
        // One way to know where you are when your doing a transformation (debugging).
        printf ("Found a variable decaration: \n");
        variableDeclaration->get_file_info()->display("Found a variable decaration");
#endif
        SgInitializedNamePtrList & varList = variableDeclaration->get_variables();
        SgInitializedNamePtrList::iterator i = varList.begin();

        bool transformed = false;

        // Iterate over the SgInitializedName objects.
        while (i != varList.end())
        {
            SgPointerType* pointerType = isSgPointerType((*i)->get_type());
            if (pointerType != NULL)
            {
                // Types are shared, so don't modify the types directly, but point to a new type.
                (*i)->set_type(SageBuilder::buildRestrictType((*i)->get_type()));
#if 1
                printf ("In TypeTransformation::visit(): Calling setTransformation on SgInitializedName: i = %p = %s \n",*i,(*i)->get_name().str());
#endif
                // DQ (4/14/2015): Explicitly set this as containing a transformation (we might want
                // to alternatively fixup the token-based unparsing frontier tests to triggered based
                // on the setting of the isModified flag in each IR node.
                // (*i)->set_containsTransformation(true);
                // (*i)->setTransformation();

                transformed = true;
            }

            i++;
        }

        if (transformed == true)
        {
#if 0
            // DQ (4/16/2015): That this can be commented out means that we have general support in place to
            // interpret transformations from status of the isModified flags that are set by all of the
            // set_* access functions.  This interpretation of the isModified flag status to explicitly
            // mark transformations is handled in the function:
            // SimpleFrontierDetectionForTokenStreamMapping::evaluateInheritedAttribute()
            // in file: simpleFrontierDetection.C

            // DQ (4/14/2015): Mark the SgVariableDeclaration as being a transformation.
            variableDeclaration->setTransformation();

            // Also set to be output in the generated code.
            variableDeclaration->setOutputInCodeGeneration();

            // By definition: for this to be a transformation it cannot also contain a transforamtion.
            ROSE_ASSERT(variableDeclaration->get_containsTransformation() == false);
            ROSE_ASSERT(variableDeclaration->isTransformation() == true);
#endif
        }
    }
}
Ejemplo n.º 19
0
  //! Translate generated Pragma Attributes one by one
  void translatePragmas (std::vector <MPI_PragmaAttribute*>& Attribute_List)
  {
    std::vector<MPI_PragmaAttribute*>::iterator iter;
    for (iter = Attribute_List.begin(); iter!=Attribute_List.end(); iter ++)
    {
      MPI_PragmaAttribute* cur_attr = *iter; 
      cout<<"Translating ..." << cur_attr->toString() <<endl;
      SgScopeStatement* scope = cur_attr->pragma_node ->get_scope();
      ROSE_ASSERT (scope != NULL);
      // simply obtain the default value and remove the pragma
      if (cur_attr-> pragma_type == pragma_mpi_device_default)
      {
        mpi_device_default_choice = cur_attr->default_semantics;
        // no automatic handling of attached preprocessed info. for now
        removeStatement(cur_attr->pragma_node, false);
      }
      // find omp target device(mpi:all) begin
      else if (cur_attr-> pragma_type == pragma_mpi_device_all_begin)
      {
        iter ++; // additional increment once
        MPI_PragmaAttribute* end_attribute = *iter; 
        ROSE_ASSERT (end_attribute->pragma_type = pragma_mpi_device_all_end);
        removeStatement(cur_attr->pragma_node, false);
        removeStatement(end_attribute ->pragma_node, false);
      }  
      else if (cur_attr-> pragma_type == pragma_mpi_device_master_begin)
      { // TODO refactor into a function
        iter ++; // additional increment once
        MPI_PragmaAttribute* end_attribute = *iter; 
        ROSE_ASSERT (end_attribute->pragma_type = pragma_mpi_device_master_end);

        //insert a if (rank) .. after the end pragma
        SgIfStmt * ifstmt = buildIfStmt (buildEqualityOp(buildVarRefExp("_xomp_rank", scope), buildIntVal(0)), buildBasicBlock(), NULL);
        insertStatementAfter (end_attribute->pragma_node, ifstmt);
        SgBasicBlock * bb = isSgBasicBlock(ifstmt->get_true_body());

        SgStatement* next_stmt = getNextStatement(cur_attr->pragma_node); // the next stmt is BB, skip it by starting the search from it
        ROSE_ASSERT (next_stmt != NULL);
        // normalize all declarations
        while ( next_stmt != end_attribute ->pragma_node)
        {
          // save current stmt before getting next one 
          SgStatement* cur_stmt = next_stmt; 
          next_stmt = getNextStatement (next_stmt);
          ROSE_ASSERT (next_stmt != NULL);

          if (SgVariableDeclaration* decl = isSgVariableDeclaration (cur_stmt))
            splitVariableDeclaration (decl);
        }
        // move all non-declaration statements in between into the block
        next_stmt = getNextStatement(cur_attr->pragma_node); //reset from the beginning
        while ( next_stmt != end_attribute ->pragma_node) 
        {
          // save current stmt before getting next one 
          SgStatement* cur_stmt = next_stmt; 
          next_stmt = getNextStatement (next_stmt);
          ROSE_ASSERT (next_stmt != NULL);
           
          if (!isSgVariableDeclaration(cur_stmt))
          {
            // now remove the current stmt
            removeStatement (cur_stmt, false);
            appendStatement(cur_stmt, bb);
          }
        }
        
        // remove pragmas
        removeStatement(cur_attr->pragma_node, false);
        removeStatement(end_attribute ->pragma_node, false);
      }  

    }  // end for
  } // end translatePragmas ()
Ejemplo n.º 20
0
  //return name for various named constructs
  string roseNode::getName() const
  {
    string result;
    ROSE_ASSERT(mNode!=NULL);
    // only declarations with symbols in ROSE have user-level names
    // need to double check this
    if (isSgFile(mNode)) 
    {
      return isSgFile(mNode)->get_file_info()->get_filenameString ();
    } 
    else  if (isSgProject(mNode))
    { // No name field for rose projects
      return "";
    }
    else if (isSgFunctionDefinition(mNode))
    {
      SgFunctionDefinition* def = isSgFunctionDefinition(mNode);
      return (def->get_declaration()->search_for_symbol_from_symbol_table()->get_name()).getString();
    }  

    SgDeclarationStatement* decl = isSgDeclarationStatement(mNode); 
    if (decl)
    {
      switch (decl->variantT())
      { 
        case V_SgVariableDeclaration:
          {
            SgVariableSymbol * symbol=SageInterface::getFirstVarSym(isSgVariableDeclaration(decl));
            result = symbol->get_name();
            break;
          }
        case V_SgClassDeclaration:
        case V_SgTypedefDeclaration:
        case V_SgNamespaceDeclarationStatement:
        case V_SgFunctionDeclaration:
        case V_SgTemplateDeclaration:
        case V_SgMemberFunctionDeclaration:
          {
            result = (decl->search_for_symbol_from_symbol_table()->get_name()).getString();
            ROSE_ASSERT(result.length()!=0);
            break;
          }
         // No explicit name available
        case V_SgCtorInitializerList:
        case V_SgPragmaDeclaration:
        case V_SgFunctionParameterList:
        case V_SgUsingDirectiveStatement:
        case V_SgStmtDeclarationStatement:
          {
            break;
          }
        default:
          {
            cerr<<"error, unhandled declaration type in roseNode::getName(): "<<mNode->class_name()<<endl;
            ROSE_ASSERT(false);
            break;
          }
      }// end switch
    }
    return result ;
  }
Ejemplo n.º 21
0
void flattenScopes(SgFunctionDefinition * fDef)
{
	// * 3.3: find all variables in the function,give them a unique name and move them to the bgeinning of the function, this is allowed because this is for C only!!!. This would not work for classes which must be constructed

	// rename variables
	list<SgNode*> varDeclList=NodeQuery::querySubTree(fDef,V_SgInitializedName);
	for (list<SgNode*>::iterator varDecl=varDeclList.begin();varDecl!=varDeclList.end();varDecl++)
	{
		tring varName=isSgInitializedName(*varDecl)->get_name().getString();
		char numberCString[255];
		sprintf(numberCString,"%i",idNr);
		string newVarName=string("PML")+string(numberCString)+string("_")+varName;
		idNr++;

		isSgInitializedName(*varDecl)->set_name(SgName(newVarName.c_str()));		
	}					

	list<SgNode*> newDeclList;
	varDeclList.clear();
	varDeclList=NodeQuery::querySubTree(procFuncVec[procNr],V_SgVariableDeclaration);
	// the move the variable declaration to the function begin and replace the old declaration site with a definition
	for (list<SgNode*>::iterator varDecl=varDeclList.begin();varDecl!=varDeclList.end();varDecl++)
	{
		SgVariableDeclaration * varDeclStmt=isSgVariableDeclaration(*varDecl);
		SgVariableDefinition * varDef=varDeclStmt->get_definition();
		SgInitializedName *iniName=isSgInitializedName(varDef->get_vardefn());
		if (iniName->get_initializer () !=NULL)
		{
			//				cout <<"VarDecl >"<<iniName->get_name().getString()<<"< has initilizer >"<<iniName->get_initializer ()->unparseToString()<<"<"<<endl;
			// determine if it is safe to separate initializer from decl
			// for now true
			if (1)
			{
				Sg_File_Info  * fi=Sg_File_Info::generateDefaultFileInfoForTransformationNode();
				SgVarRefExp * varRef=new	SgVarRefExp (Sg_File_Info::generateDefaultFileInfoForTransformationNode(),new SgVariableSymbol(iniName));
				SgType * type=isSgAssignInitializer(iniName->get_initializer())->get_type ();
				SgAssignInitializer * sai=isSgAssignInitializer(iniName->get_initializer());
				if (sai==NULL)
				{
					cerr<<"isSgAssignInitializer(iniName->get_initializer())=NULL"<<endl;
					exit(-1);
				}
				SgExpression *lhs,*rhs;
				lhs=varRef;
				rhs=sai->get_operand ();
				if (lhs==NULL)
				{
					cerr<<"lhs=NULL"<<endl;
					exit(-1);
				}
				if (rhs==NULL)
				{
					cerr<<"rhs=NULL"<<endl;
					exit(-1);
				}
				SgAssignOp * assignment=new SgAssignOp(Sg_File_Info::generateDefaultFileInfoForTransformationNode(),lhs,rhs);
				SgExprStatement * expr=new SgExprStatement(fi,assignment);
				if (expr==NULL)
				{
					cerr<<"construction of expr failed"<<endl;
				}
				isSgAssignInitializer(iniName->get_initializer ())->set_operand(NULL);
				free(iniName->get_initializer ());
				iniName->set_initializer (NULL);
				// put the iniName in the list
				newDeclList.push_back(varDeclStmt);
				if (isSgStatement(varDeclStmt)==NULL)
				{
					cerr<<"isSgStatement(varDeclStmt)==NULL"<<endl;
				}
				LowLevelRewrite::replace(isSgStatement(varDeclStmt),isSgStatement(expr));					
			}				
		}
		else
		{
			cout <<"VarDecl >"<<iniName->get_name().getString()<<"> is uninitialized"<<endl;
			newDeclList.push_back(varDeclStmt);
			LowLevelRewrite::remove(isSgStatement(varDeclStmt));
		}
	}

	for (list<SgNode*>::iterator varDecl=newDeclList.begin();varDecl!=newDeclList.end();varDecl++)
	{
		fDef->prepend_statement(isSgStatement(*varDecl));
	}
	return ;
}
Ejemplo n.º 22
0
void getSgDeclarationStatement(SgDeclarationStatement* declStat) {
	VariantT var = declStat->variantT();
	std::string declStatStr = "";
	switch (var) {
		case V_SgEnumDeclaration:
			{
			SgEnumDeclaration* enum_decl = isSgEnumDeclaration(declStat);
			std::string enum_str_name = enum_decl->get_name().getString();
                        std::cout << ";enum_str_name = " << enum_str_name << std::endl;
                        if (enums_defined.find(enum_str_name) == enums_defined.end()) {
                                std::cout << ";enum not yet defined" << std::endl;
                                std::string enum_name = enum_decl->get_name().getString();
                                std::stringstream enum_z3;
                                enum_z3 << "(declare-datatypes () ((" << enum_name;
                                SgInitializedNamePtrList enumerated_values = enum_decl->get_enumerators();
                                for (SgInitializedNamePtrList::iterator j = enumerated_values.begin(); j != enumerated_values.end(); j++) {
                                        SgName enum_value_name = (*j)->get_name();
                                        enum_z3 << " " << enum_value_name.getString();
                                }
                                enum_z3 << ")))";
                                std::cout << enum_z3.str() << std::endl;
                                enums_defined[enum_str_name] = enum_z3.str();
                        }
			break;
			}

		case V_SgFunctionParameterList:
			{
			std::cout << "SgFunctionParameterList is not yet implemented" << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgTypedefDeclaration:
			{
			std::cout << "SgTypedefDeclaration is not yet implemented" << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgVariableDeclaration:
			{
			SgVariableDeclaration* varDecl = isSgVariableDeclaration(declStat);
			SgInitializedName* nam = SageInterface::getFirstInitializedName(varDecl);
		/*	SgInitializedNamePtrList list = varDecl->get_variables();
			std::stringstream declStatStrStream;
			int checkOne = 0;
			for (SgInitializedNamePtrList::iterator i = list.begin(); i != list.end(); i++) {
				if (checkOne == 1) {
					std::cout << "InitializedNamePtrList should have only one InitializedName" << std::endl;
					ROSE_ASSERT(false);
				}
				SgInitializedName* ithName = isSgInitializedName(*i);
				declStatStrStream << getSgInitializedName(*i) << "\n";
				checkOne++;
			}
		*/
			declStatStr = getSgInitializedName(nam) + "\n";

			break;
			}

		case V_SgVariableDefinition:
			{
			std::cout << "SgVariableDefinition is not yet implemented" << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgAttributeSpecificationStatement:

			{
			std::cout << "SgAttributeSpecificationStatement is not yet implemented" << std::endl; ;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgCommonBlock:

			{
			std::cout << "SgCommonBlock is not yet implemented" << std::endl; ;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgEquivalenceStatement:

			{
			std::cout << "SgEquivalenceStatement is not yet implemented" << std::endl; ;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgImplicitStatement:

			{
			std::cout << "SgImplicitStatement is not yet implemented" << std::endl; ;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgNamelistStatement:

			{
			std::cout << "SgNamelistStatement is not yet implemented" << std::endl; ;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgNamespaceDeclarationStatement:

			{
			std::cout << "SgNamespaceDeclarationStatement is not yet implemented" << std::endl; ;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgTemplateInstantiationDirectiveStatement:

			{
			std::cout << "SgTemplateInstantiationDirectiveStatement is not yet implemented" << std::endl; ;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgUsingDeclarationStatement:

			{
			std::cout << "SgUsingDeclarationStatement is not yet implemented" << std::endl; ;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgUsingDirectiveStatement:

			{
			std::cout << "SgUsingDirectiveStatement is not yet implemented" << std::endl; ;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgClassDeclaration:
			{
			std::cout << "SgClassDeclaration should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgContainsStatement:
			{
			std::cout << "SgContainsStatement should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgFunctionDeclaration:
			{
			std::cout << "SgFunctionDeclaration should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgTemplateDeclaration:
			{
			std::cout << "SgTemplateDeclaration should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgAsmStmt:
			{
			std::cout << "SgAsmStmt should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgC_PreprocessorDirectiveStatement:
			{
			std::cout << "SgC_PreprocessorDirectiveStatement should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgClinkageDeclarationStatement:
			{
			std::cout << "SgClinkageDeclarationStatement should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgCtorInitializerList:
			{
			std::cout << "SgCtorInitializerList should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgFormatStatement:
			{
			std::cout << "SgFormatStatement should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgFortranIncludeLine:
			{
			std::cout << "SgFortranIncludeLine should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgImportStatement:
			{
			std::cout << "SgImportStatement should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgInterfaceStatement:
			{
			std::cout << "SgInterfaceStatement should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgJavaImportStatement:
			{
			std::cout << "SgJavaImportStatement should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgNamespaceAliasDeclarationStatement:
			{
			std::cout << "SgNamespaceAliasDeclarationStatement should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgStmtDeclarationStatement:
			{
			std::cout << "SgStmtDeclarationStatement should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgUseStatement:
			{
			std::cout << "SgUseStatement should not be found here! " << std::endl;
			ROSE_ASSERT(false);
			break;
			}

		case V_SgPragmaDeclaration:
			{
					
			//std::cout << "pragmas skipped" << std::endl;
		//	declStatStr=";;pragma\n";
			break;
			}	
		default:
			{
			std::cout << " Unknown node type!: " << declStat->class_name() << std::endl;
			ROSE_ASSERT(false);
			}
	}
	declarations.push_back(declStatStr);
	return;
}