Commit a4557676 authored by Pierre Aubert's avatar Pierre Aubert
Browse files

Add function to get the last operand of an operator

parent 146586c0
......@@ -60,6 +60,7 @@ std::string repr_cpp_operatorHeader(const PTabGraphToken & tabGraphToken){
body += "\n";
body += "bool isAnOperator(const PStmt & _op);\n";
body += "long get_priority_operator(const PStmt & _op);\n";
body += "PStmt* get_last_operand_of_operator(PStmt & _op);\n";
body += "\n\n";
body += "#endif\n\n\n";
......@@ -78,11 +79,12 @@ std::string repr_cpp_operatorSource(const PTabGraphToken & tabGraphToken, const
PMapVecOperator mapOp;
repr_cpp_operatorGetClass(mapOp, tabGraphToken.getVecOperator());
body += "///Say if the given expression is an operator\n";
body += "/**\t@param _op : expression to be checked\n";
body += " * \t@return true if it is an expression, false otherwise\n";
body += "///Say if the given PStmt is an operator\n";
body += "/**\t@param _op : PStmt to be checked\n";
body += " * \t@return true if it is an PStmt, false otherwise\n";
body += "*/\n";
body += "bool isAnOperator(const PStmt & _op){\n";
body += "\t//repr_cpp_operator : say if the given PStmt is an operator\n";
std::string prevElse("");
for(PMapVecOperator::iterator itVec(mapOp.begin()); itVec != mapOp.end(); ++itVec){
body += "\t"+prevElse+"if(is"+(itVec->first)+"(_op)){\n";
......@@ -98,11 +100,12 @@ std::string repr_cpp_operatorSource(const PTabGraphToken & tabGraphToken, const
body += "\treturn false;\n";
body += "}\n\n";
body += "///Get the priority of the given expression\n";
body += "/**\t@param _op : expression to be checked\n";
body += " * \t@return priority of the expression, -1 otherwise\n";
body += "///Get the priority of the given PStmt\n";
body += "/**\t@param _op : PStmt to be checked\n";
body += " * \t@return priority of the PStmt, -1 otherwise\n";
body += "*/\n";
body += "long get_priority_operator(const PStmt & _op){\n";
body += "\t//repr_cpp_operator : Get the priority of the given operator\n";
prevElse = "";
for(PMapVecOperator::iterator itVec(mapOp.begin()); itVec != mapOp.end(); ++itVec){
body += "\t"+prevElse+"if(is"+(itVec->first)+"(_op)){\n";
......@@ -116,6 +119,31 @@ std::string repr_cpp_operatorSource(const PTabGraphToken & tabGraphToken, const
}
body += "\n";
body += "\treturn -1l;\n";
body += "}\n\n";
body += "///Get the last operand of the given PStmt\n";
body += "/**\t@param _op : expression to be checked\n";
body += " * \t@return pointer to the last operand of the given operator, NULL otherwise\n";
body += "*/\n";
body += "PStmt* get_last_operand_of_operator(PStmt & _op){\n";
body += "\t//repr_cpp_operator : Get the last operand of the given operator\n";
body += "\tPStmt * outputPtr = NULL;\n";
prevElse = "";
for(PMapVecOperator::iterator itVec(mapOp.begin()); itVec != mapOp.end(); ++itVec){
body += "\t"+prevElse+"if(is"+(itVec->first)+"(_op)){\n";
std::string itPrevElse("");
for(PVecOperator::iterator it(itVec->second.begin()); it != itVec->second.end(); ++it){
body += "\t\t"+itPrevElse+"if("+it->getExprClass()+"_get"+firstToUpper(it->getAttrEnum())+"(_op) == "+it->getValueEnum()+"){\n";
body += "\t\t\t//repr_cpp_operator : let's get the number of operand of this operator\n";
body += "\t\t\tPStmt & vecOp = "+it->getExprClass()+"_get"+firstToUpper(it->getVecOp())+"(_op);\n";
body += "\t\t\tif(vecOp.size() != 0lu){outputPtr = &(vecOp.back());}\n";
body += "\t\t}\n";
itPrevElse = "else ";
}
body += "\t}";
prevElse = "else ";
}
body += "\n\treturn outputPtr;\n";
body += "}\n\n\n";
return body;
}
......
......@@ -51,7 +51,7 @@ std::string repr_cpp_singleTokenOperator(const POperator & op, const PGraphToken
body += "\tPStmt op = "+op.getExprClass()+"_default();\n";
body += "\t"+op.getExprClass()+"_set"+firstToUpper(op.getAttrEnum())+"(op, "+op.getValueEnum()+");\n";
body += "\tPStmt & vecOperand = PExpr_getVecOperand(op);\n";
body += "\tPStmt & vecOperand = "+op.getExprClass()+"_get"+firstToUpper(op.getVecOp())+"(op);\n";
body += "\t\n";
body += "\tbool isStandardPushBack(true);\n";
body += "\tif(isAnOperator(e)){\n";
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment