Ejemplo n.º 1
0
void
StructProcessor::processStructNode(GNode* node,StructAdaptor& structAdaptor) throw (Error)
{
	if(node->getTreeCode()!="record_type")
	{
		throw Error();
	}
	GNode* fieldNode = globalASTTreePointer->findNodeByIndex(node->getProperty("flds")->mNodeProperty);
	while(fieldNode->getTreeCode()!="type_decl")
	{
		if(fieldNode->getTreeCode()=="field_decl")
		{
			processFieldDecl(fieldNode,structAdaptor);
		}
		else if(fieldNode->getTreeCode()=="var_decl")
		{
			processVarDecl(fieldNode,structAdaptor);
		}
		else
		{
			throw Error();
		}
		fieldNode = globalASTTreePointer->findNodeByIndex(fieldNode->getProperty("chan")->mNodeProperty);
	}
}
Ejemplo n.º 2
0
string FunctionCallNodeProcessor::getParameterName(GNode *node) {
    GNode* paNameNode = globalASTTreePointer->findNodeByIndex(node->getProperty("name")->mNodeProperty);
    if(paNameNode->getTreeCode()=="identifier_node")
    {
        if(paNameNode->getProperty("strg")!=NULL) {
            return paNameNode->getProperty("strg")->mStringProperty;
        }
    }
    return "";
}
Ejemplo n.º 3
0
bool
StructProcessor::isFieldPointer(GNode* node)
{
	GNode* typeNode = globalASTTreePointer->findNodeByIndex(node->getProperty("type")->mNodeProperty);
	if(typeNode->getTreeCode()=="pointer_type")
	{
		return true;
	}
	return false;
}
Ejemplo n.º 4
0
//The simple statement contained in statement-list in the source program is organized as
//the structure of cleanup_point_expr, a typical organization is such as:
//cleanup_point_expr --> expr_stmt --> convert_expr --> actual stmt (like mofify_expr)
CStmt* CCleanupStmt::ConstructCleanupStmt(GNode *pNode)
{
    if("cleanup_point_expr" != pNode->getTreeCode())
	return 0;
    GNode *pExprStmt = NodeProcessor::getOperand(pNode, 0);
    if(0 == pExprStmt)
	return 0;
    string strLine = NodeProcessor::getFieldStr(pExprStmt, "line");
    int iLine = Util::stringToInt(strLine);
    string strExpr = NodeProcessor::getFieldStr(pExprStmt, "expr");
    if("" == strExpr)
	return 0;
    strExpr.erase(0, 1);
    int iExpr = Util::stringToInt(strExpr);
    GTree *pTree = pNode->_getTree();
    map<int, GNode*> map_node = pTree->_getNodeMap();
    GNode *pStmt = map_node[iExpr];
    if("convert_expr" == pStmt->getTreeCode())
    {
	GNode *pConvert = NodeProcessor::getOperand(pStmt, 0);
	if(0 == pConvert)
	    return 0;
	if("modify_expr" == pConvert->getTreeCode())
	{
	    CModifyStmt *pModifyStmt = new CModifyStmt;
	    pModifyStmt->ConstructStmt(pConvert);
	    pModifyStmt->SetLine(iLine);
	    return ((CStmt*) pModifyStmt);
	}
	if("preincrement_expr" == pConvert->getTreeCode())
	{
	    CPreIncreStmt *pPreIncreStmt = new CPreIncreStmt;
	    pPreIncreStmt->ConstructStmt(pConvert);
	    pPreIncreStmt->SetLine(iLine);
	    return ((CStmt*) pPreIncreStmt);
	}
	if("postincrement_expr" == pConvert->getTreeCode())
	{
	    CPostIncreStmt *pPostIncreStmt = new CPostIncreStmt;
	    pPostIncreStmt->ConstructStmt(pConvert);
	    pPostIncreStmt->SetLine(iLine);
	    return ((CStmt*) pPostIncreStmt);
	}
	if("predecrement_expr" == pConvert->getTreeCode())
	{
	    CPreDecreStmt *pPreDecreStmt = new CPreDecreStmt;
	    pPreDecreStmt->ConstructStmt(pConvert);
	    pPreDecreStmt->SetLine(iLine);
	    return ((CStmt*) pPreDecreStmt);
	}
	if("postdecrement_expr" == pConvert->getTreeCode())
	{
	    CPostDecreStmt *pPostDecreStmt = new CPostDecreStmt;
	    pPostDecreStmt->ConstructStmt(pConvert);
	    pPostDecreStmt->SetLine(iLine);
	    return ((CStmt*) pPostDecreStmt);
	}
    }
    return 0;
}
Ejemplo n.º 5
0
void ReducibleIfAnalyzer::analyzeNode(GNode *node, const vector<int> &context)
{
    GNode *testingNode = NodeProcessor::getOperand(node, 0);
    GNode *ifIfNode = NodeProcessor::getOperand(node, 2);
    GNode *logicLeftNode, *logicRightNode;
    if(NodeProcessor::isLogicAnd(testingNode))
    {
	logicLeftNode = NodeProcessor::getOperand(testingNode, 0);
	logicRightNode = NodeProcessor::getOperand(testingNode, 1);
	if(NodeProcessor::isCompareOperation(logicLeftNode))
	{
	    LogicUnit temp;
	    if(NULL != logicLeftNode)
		temp.ope = logicLeftNode->getTreeCode();
	    GNode *op0Node = NodeProcessor::getOperand(logicLeftNode, 0);
	    GNode *op1Node = NodeProcessor::getOperand(logicLeftNode, 1);
	    temp.left = NodeProcessor::getSimpleOperation(op0Node);
	    temp.right = NodeProcessor::getSimpleOperation(op1Node);
	    vec_LogicUnit.push_back(temp);
	    if(NodeProcessor::isCompareOperation(logicRightNode))
	    {
		if(NULL != logicRightNode)
		    temp.ope = logicRightNode->getTreeCode();
		GNode *op0Node = NodeProcessor::getOperand(logicRightNode, 0);
		GNode *op1Node = NodeProcessor::getOperand(logicRightNode, 1);
		temp.left = NodeProcessor::getSimpleOperation(op0Node);
		temp.right = NodeProcessor::getSimpleOperation(op1Node);
		vec_LogicUnit.push_back(temp);
	    }
	}
    }
    else
    {
	return ;
    }
    if(NodeProcessor::isCondExpr(ifIfNode))
    {
	GNode *ifIfTesting = NodeProcessor::getOperand(ifIfNode, 0);
	if(NodeProcessor::isCompareOperation(ifIfTesting))
	{
	    LogicUnit temp;
	    if(NULL != ifIfTesting)
	    temp.ope = ifIfTesting->getTreeCode();
	    GNode *op0Node = NodeProcessor::getOperand(ifIfTesting, 0);
	    GNode *op1Node = NodeProcessor::getOperand(ifIfTesting, 1);
	    temp.left = NodeProcessor::getSimpleOperation(op0Node);
	    temp.right = NodeProcessor::getSimpleOperation(op1Node);
	    vec_LogicUnit.push_back(temp);
	    GNode *ifIfElseNode = NodeProcessor::getOperand(ifIfNode, 2);
	    if(NodeProcessor::isCondExpr(ifIfElseNode))
	    {
		if(vec_LogicUnit[0].anti(vec_LogicUnit[2]))
		{
		    int lineNum;
		    if(NULL != node)
			lineNum = Util::stringToInt(node->getProperty("line")->mStringProperty);
		    Logger::a("ReducibleAnalyzer") << "if statement is reducible" \
			<< SrcManager::getInstance().getFullFileName() << lineNum \
			<< SrcManager::getInstance().getLine(lineNum) << endl;
		    stringstream reportMsgStream;
		    reportMsgStream << "ReducibleAnalyzer: if statement is reducible" << endl;
		    string reportMsg = reportMsgStream.str();
		    ReportManager::getInstance().insertReport(SrcManager::getInstance().getFullFileName(), lineNum, reportMsg);
		}
	    }
	}
    }
}