コード例 #1
0
ファイル: discardAssignment.C プロジェクト: 8l/rose
void
CompassAnalyses::DiscardAssignment::Traversal::
visit(SgNode* node)
   { 
     if (isSgAssignOp(node))
     {
       // simple case: the parent of a "real" assignment op must be an
       // expression statement
       if (!isSgExprStatement(node->get_parent()))
       {
         output->addOutput(new CheckerOutput(node));
       }
       else
       {
         // not so simple case: the parent is an expression statement, but if
         // that statement is an if/loop condition, we still want to complain
         SgNode *assignment = node->get_parent();
         SgNode *p = assignment->get_parent();
         SgDoWhileStmt *dws;
         SgForStatement *fs;
         SgIfStmt *is;
         SgSwitchStatement *ss;
         SgWhileStmt *ws;

         if ((dws = isSgDoWhileStmt(p)) && dws->get_condition() == assignment)
         {
           output->addOutput(new CheckerOutput(node));
         }
         else if ((fs = isSgForStatement(p)) && fs->get_test() == assignment)
         {
           output->addOutput(new CheckerOutput(node));
         }
         else if ((is = isSgIfStmt(p)) && is->get_conditional() == assignment)
         {
           output->addOutput(new CheckerOutput(node));
         }
         else if ((ss = isSgSwitchStatement(p)) && ss->get_item_selector() == assignment)
         {
           output->addOutput(new CheckerOutput(node));
         }
         else if ((ws = isSgWhileStmt(p)) && ws->get_condition() == assignment)
         {
           output->addOutput(new CheckerOutput(node));
         }
       }
     }
     else if (SgMemberFunctionRefExp *mf = isSgMemberFunctionRefExp(node))
     {
       // not so simple case: call to operator= member function that is not an
       // expression statement by itself
       SgFunctionCallExp *call = isSgFunctionCallExp(mf->get_parent()->get_parent());
       if (call && !isSgExprStatement(call->get_parent())
        && mf->get_parent() == call->get_function()
        && std::strcmp(mf->get_symbol()->get_name().str(), "operator=") == 0)
       {
         output->addOutput(new CheckerOutput(call));
       }
     }
   } //End of the visit function.
コード例 #2
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*> 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;
}
コード例 #3
0
ファイル: AstFixup.C プロジェクト: Federico2014/edg4x-rose
// DQ (2/6/2010): This codes was moved from tests/trestTranslator.C
// It is not currently called within the the fixup of the AST.
// Note that this used to be called using: 
//      if (getenv("ROSE_TEST_ELSE_DISAMBIGUATION") != NULL) removeEmptyElses(project);
// But I didn't feel that we wanted evnvironment variable based testing like this.
// This is a fixup that we might want later.
void removeEmptyElses(SgNode* top)
   {
     std::vector<SgNode*> ifs = NodeQuery::querySubTree(top, V_SgIfStmt);
     for (size_t i = 0; i < ifs.size(); ++i)
        {
          SgIfStmt* s = isSgIfStmt(ifs[i]);
          if (isSgBasicBlock(s->get_false_body()) && isSgBasicBlock(s->get_false_body())->get_statements().empty())
             {
               s->set_false_body(NULL);
             }
        }
   }
コード例 #4
0
void
CompassAnalyses::ExplicitTestForNonBooleanValue::Traversal::
visit(SgNode* node)
   { 
  // Implement your traversal here.  
        // 1. conditional expression
        if(NULL != isSgBasicBlock(node))
        {
          Rose_STL_Container<SgNode*> conditionalExpList = NodeQuery::querySubTree(node, V_SgConditionalExp);
          for(Rose_STL_Container<SgNode*>::iterator i=conditionalExpList.begin(); i != conditionalExpList.end(); i++)
          {
            SgConditionalExp* conditionalExp = isSgConditionalExp(*i);
            //ROSE_ASSERT(conditionalExp != NULL);

            if(NULL != conditionalExp && NULL != isSgCastExp(conditionalExp->get_conditional_exp()))
            {
              output->addOutput(new CheckerOutput(conditionalExp));
            }
          }
        } else {

          SgExprStatement* exprStatement = NULL;

          // 2. test statement in a if statement
          SgIfStmt* ifStmt = isSgIfStmt(node);
          if(NULL != ifStmt)
            exprStatement = isSgExprStatement(ifStmt->get_conditional());

          // 3. test statement in a while statement
          SgWhileStmt* whileStmt = isSgWhileStmt(node);
          if(NULL != whileStmt)
            exprStatement = isSgExprStatement(whileStmt->get_condition());

          // 4. test statement in a do-while statement
          SgDoWhileStmt* doWhileStmt = isSgDoWhileStmt(node);
          if(NULL != doWhileStmt)
            exprStatement = isSgExprStatement(doWhileStmt->get_condition());

          // 5. test statement in a for statement
          SgForStatement* forStatement = isSgForStatement(node);
          if(NULL != forStatement)
            exprStatement = isSgExprStatement(forStatement->get_test());

          if(NULL != exprStatement && NULL != isSgCastExp(exprStatement->get_expression()))
          {
            output->addOutput(new CheckerOutput(node));
          }
        }

   } //End of the visit function.
コード例 #5
0
ファイル: DataflowCFG.C プロジェクト: Federico2014/edg4x-rose
 bool isDataflowInteresting(CFGNode cn) {
         ROSE_ASSERT (cn.getNode());
         return (cn.getNode()->cfgIsIndexInteresting(cn.getIndex()) && 
                //!isSgFunctionRefExp(cn.getNode()) &&
                !isSgExprListExp(cn.getNode()) &&
                !isSgForInitStatement(cn.getNode()) &&
                //!isSgVarRefExp(cn.getNode()) &&
                //!isSgValueExp(cn.getNode()) &&
                //!isSgExprStatement(cn.getNode()) &&
                !(isSgInitializedName(cn.getNode()) && cn.getIndex()==0)) 
                ||
                (isSgIfStmt(cn.getNode()) &&
                 cn.getIndex()==1 || cn.getIndex()==2);
 }
コード例 #6
0
void
CompassAnalyses::FloatingPointExactComparison::Traversal::
visit(SgNode* node)
   { 
  // Implement your traversal here.  

     SgExprStatement* exprStatement = NULL;

     SgIfStmt* ifStmt = isSgIfStmt(node);
     if(NULL != ifStmt)
       exprStatement = isSgExprStatement(ifStmt->get_conditional());

     SgWhileStmt* whileStmt = isSgWhileStmt(node);
     if(NULL != whileStmt)
       exprStatement = isSgExprStatement(whileStmt->get_condition());

     SgDoWhileStmt* doWhileStmt = isSgDoWhileStmt(node);
     if(NULL != doWhileStmt)
       exprStatement = isSgExprStatement(doWhileStmt->get_condition());

     SgForStatement* forStatement = isSgForStatement(node);
     if(NULL != forStatement)
       exprStatement = isSgExprStatement(forStatement->get_test());

     if(NULL != exprStatement && NULL != isSgNotEqualOp(exprStatement->get_expression()))
     {
       SgNotEqualOp* comparison = isSgNotEqualOp(exprStatement->get_expression());
       if((comparison->get_lhs_operand_i() != NULL &&
           isSgDoubleVal(comparison->get_lhs_operand_i()) != NULL) ||
          (comparison->get_rhs_operand_i() != NULL &&
           isSgDoubleVal(comparison->get_rhs_operand_i()) != NULL))
       {
         output->addOutput(new CheckerOutput(comparison));
       }
     }

     if(NULL != exprStatement && NULL != isSgEqualityOp(exprStatement->get_expression()))
     {
       SgEqualityOp* comparison = isSgEqualityOp(exprStatement->get_expression());
       if((comparison->get_lhs_operand_i() != NULL &&
           isSgDoubleVal(comparison->get_lhs_operand_i()) != NULL) ||
          (comparison->get_rhs_operand_i() != NULL &&
           isSgDoubleVal(comparison->get_rhs_operand_i()) != NULL))
       {
         output->addOutput(new CheckerOutput(comparison));
       }
     }

   } //End of the visit function.
コード例 #7
0
ファイル: HtSageUtils.cpp プロジェクト: CarlEbeling/OpenHT
SgStatement *findSafeInsertPoint(SgNode *node) {
    SgStatement *insertPoint = SageInterface::getEnclosingStatement(node);
    SgStatement *es = isSgExprStatement(insertPoint);
    SgStatement *esParent = es ? isSgStatement(es->get_parent()) : 0;
    if (es && (isSgSwitchStatement(esParent) || isSgIfStmt(esParent))) {
      // Make sure insertion point is outside of the condition of an if-stmt
      // or the selector of a switch-stmt.
      insertPoint = esParent; 
    } else {
      if (esParent) {
        assert(isSgBasicBlock(esParent));
      }
    }
    return insertPoint;
}
コード例 #8
0
ファイル: test2004_46.C プロジェクト: Federico2014/edg4x-rose
void
MyInsert::visit ( SgNode* astNode )
{

 if(SgIfStmt * ifst=isSgIfStmt(astNode))
   {
   printf("found If stmt\n");
   Sg_File_Info *finfo=new Sg_File_Info(CURRENT_FILE, 1, 1);
   SgName temporary("temp");
   SgVariableDeclaration * stmt=new SgVariableDeclaration(finfo, 
temporary, new SgTypeInt());
   //SgReturnStmt * stmt=new SgReturnStmt(finfo);
   SgStatement * bb=ifst->get_scope();
   bb->insert_statement(ifst, stmt, TRUE);
  }
}
コード例 #9
0
void
SgIfStmt::fixupCopy_symbols(SgNode* copy, SgCopyHelp & help) const
   {
#if DEBUG_FIXUP_COPY
     printf ("Inside of SgIfStmt::fixupCopy_symbols() this = %p = %s  copy = %p \n",this,this->class_name().c_str(),copy);
#endif

  // SgStatement::fixupCopy_symbols(copy,help);
     SgScopeStatement::fixupCopy_symbols(copy,help);

     SgIfStmt* ifStatement_copy = isSgIfStmt(copy);
     ROSE_ASSERT(ifStatement_copy != NULL);

  // The symbol table should not have been setup yet!
  // ROSE_ASSERT(ifStatement_copy->get_symbol_table()->size() == 0);

     this->get_conditional()->fixupCopy_symbols(ifStatement_copy->get_conditional(),help);

     ROSE_ASSERT(this->get_true_body() != NULL);
     ROSE_ASSERT(ifStatement_copy->get_true_body() != NULL);
     if (isSgScopeStatement(ifStatement_copy->get_true_body())) 
        {
       // ROSE_ASSERT(isSgScopeStatement(ifStatement_copy->get_true_body())->get_symbol_table() != NULL);
       // ROSE_ASSERT(isSgScopeStatement(ifStatement_copy->get_true_body())->get_symbol_table()->size()  == 0);
          ROSE_ASSERT(isSgScopeStatement(ifStatement_copy->get_true_body())->symbol_table_size() == 0);
        }

  // printf ("\nProcess the TRUE body of the SgIfStmt \n\n");

     this->get_true_body()->fixupCopy_symbols(ifStatement_copy->get_true_body(),help);

     ROSE_ASSERT((this->get_false_body() != NULL) == (ifStatement_copy->get_false_body() != NULL));
     if (isSgScopeStatement(ifStatement_copy->get_false_body())) 
        {
       // ROSE_ASSERT(isSgScopeStatement(ifStatement_copy->get_false_body())->get_symbol_table() != NULL);
       // ROSE_ASSERT(isSgScopeStatement(ifStatement_copy->get_false_body())->get_symbol_table()->size()  == 0);
          ROSE_ASSERT(isSgScopeStatement(ifStatement_copy->get_false_body())->symbol_table_size() == 0);
        }

  // printf ("\nProcess the FALSE body of the SgIfStmt \n\n");

     if (this->get_false_body() != NULL) {
       this->get_false_body()->fixupCopy_symbols(ifStatement_copy->get_false_body(),help);
     }

  // printf ("\nLeaving SgIfStmt::fixupCopy_symbols() this = %p = %s  copy = %p \n",this,this->class_name().c_str(),copy);
   }
コード例 #10
0
ファイル: smtQueryLib.cpp プロジェクト: 8l/rose
void getSgScopeStatement(SgScopeStatement* scopeStat) {
	VariantT var = scopeStat->variantT();
	std::string scopeStatStr = "";
	switch (var) {
		case V_SgBasicBlock:
			{
			getSgBasicBlock(isSgBasicBlock(scopeStat));
			break;
			}

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

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

		case V_SgForStatement:
			{
		//	std::cout << "SgForStatement is not yet implemented" << std::endl;
			#ifdef FORLOOPONCETHROUGH
			forOnceThrough(isSgForStatement(scopeStat));
				
			
			#else
			std::cout << "SgForStatement is not yet implemented" << std::endl;
			ROSE_ASSERT(false);
			#endif
			break;
			}

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

		case V_SgIfStmt:
			{
			getSgIfStmt(isSgIfStmt(scopeStat));
			break;
			}

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

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

		case V_SgForAllStatement:

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

		case V_SgAssociateStatement:

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

		case V_SgBlockDataStatement:

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

		case V_SgNamespaceDefinitionStatement:

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

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

		case V_SgFunctionDefinition:
			{
			getSgFunctionDefinition(isSgFunctionDefinition(scopeStat));
			break;
			}

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

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

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

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

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

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

		default:
			{
			std::cout << " Unknown node type!: " << scopeStat->class_name() << std::endl;
			ROSE_ASSERT(false);
			}
	}
	return;
}