Docker-in-Docker (DinD) capabilities of public runners deactivated. More info

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

Fix one token operator

parent e0096644
Pipeline #99080 passed with stages
in 10 minutes and 9 seconds
......@@ -3,9 +3,9 @@ cmake_minimum_required(VERSION 3.0)
# compileLibTestGenerator(test_math_operator_parser "PTestOperatorParser" parser_operator.pdecparser)
compileMainTestGenerator(test_math_operator_parser "PTestOperatorParser" parser_operator.pdecparser main_test.cpp)
# compileMainTestGenerator(test_math_operator_parser "PTestOperatorParser" parser_operator.pdecparser main_test.cpp)
# Only when the test will be OK
# compileTestGenerator(test_math_operator_parser "PTestOperatorParser" parser_operator.pdecparser main_test.cpp var_decl.txt)
compileTestGenerator(test_math_operator_parser "PTestOperatorParser" parser_operator.pdecparser main_test.cpp fileAdd.math)
......@@ -4,11 +4,25 @@
Licence : CeCILL-C
****************************************/
#include "OptionParser.h"
// To get the generated parser
#include "PTestOperatorParserFull.h"
using namespace std;
///Create the OptionParser of this program
/** @return OptionParser of this program
*/
OptionParser createOptionParser(){
OptionParser parser(true, __PROGRAM_VERSION__);
parser.setExampleLongOption("use_parser --input=fileName.shadok");
parser.setExampleShortOption("use_parser -i fileName.shadok");
parser.addOption("input", "i", OptionType::FILENAME, true, "input shadok file name");
return parser;
}
///Test the conversion of and add expression into a string
/** @return true on success, false otherwise
*/
......@@ -29,6 +43,8 @@ bool testExprAddToString(){
std::string exprStr = gExprVarName(exprAdd);
std::cout << "testExprAddToString : exprAdd = '"<<exprStr<<"'" << std::endl;
// std::cout << "testExprAddToString : exprAdd ok example :"<< std::endl;
// exprAdd.print();
return exprStr == "(a+b)";
}
......@@ -111,10 +127,41 @@ bool testExprAdd3ToString(){
return exprStr == "((a+b)+(c+d))";
}
///Parse a source file
/** @param fileName : name of the source file
* @return true on success, false otherwise
*/
bool testParseFileName(const std::string & fileName){
//We create the parser
PTestOperatorParser parser;
if(!parser.load(fileName)){
cerr << "testParseFileName : can't load file '"<<fileName<<"'" << endl;
return false;
}
//We get the parsed internal representation
PExpr & source = parser.getPExprE();
std::cout << "PExpr full stmt :" << std::endl;
source.print();
std::string exprStr = gExprVarName(source);
std::cout << "testParseFileName : exprStr = '"<<exprStr<<"'" << std::endl;
return exprStr == "(a+b)";
}
int main(int argc, char** argv){
OptionParser optionParser = createOptionParser();
optionParser.parseArgument(argc, argv);
const OptionMode & defaultMode = optionParser.getDefaultMode();
std::string fileName("");
defaultMode.getValue(fileName, "input");
bool b(testExprAddToString());
b &= testExprAdd2ToString();
b &= testExprAdd3ToString();
b &= testParseFileName(fileName);
if(b){return 0;}
else{return -1;}
}
......
......@@ -809,6 +809,21 @@ std::string graph_cpp_parseFileSource(const PTabGraphToken & tabGraphToken){
}
}
body += "\t//Put all the other else for all the concerned graphs\n";
body += "\t//No need to parse the operators here because we integrate them in the parsing of attribute\n";
// const PVecOperator & vecOperator = tabGraphToken.getVecOperator();
// if(vecOperator.size() != 0lu){
// for(PVecOperator::const_iterator it(vecOperator.begin()); it != vecOperator.end(); ++it){
// body += "\t";
// if(useElse){
// body += "else ";
// }
// // body += "if(" + it->getName() + "(p_"+it->getVarType() + it->getVarName() + ")){}\n";
//
// useElse = true;
// }
// }
const PVecGraphToken & vecGraph = tabGraphToken.getVecGraph();
if(vecGraph.size() != 0lu){
for(PVecGraphToken::const_iterator it(vecGraph.begin()); it != vecGraph.end(); ++it){
......
......@@ -43,30 +43,33 @@ std::string graph_cpp_graphTokenImplementation(const PTabGraphToken & tabGraphTo
if(vecToken.size() == 0lu){return "\treturn true; //No sub tokens in the current graph\n";}
long unsigned int tokenIndex(1lu);
body += getTypeCheckInit(graphToken.getVarName(), graphToken.getVarType());
body += "\t//Check if this graph is used by Operator\n";
//Standard graph token parsing part
for(PVecToken::const_iterator it(vecToken.begin()); it != vecToken.end(); ++it){
body += "\tif(!"+it->getFunctionName()+"Do("+graphToken.getVarName()+")){\n";
for(long unsigned int i(0lu); i < tokenIndex; ++i){
body += "\t\t"+vecToken[tokenIndex - i - 1lu].getFunctionName()+"Undo("+graphToken.getVarName()+");\n";
}
body += "\t\treturn false;\n";
body += "\t}\n";
++tokenIndex;
}
body += "\t//repr_cpp_graphToken : Check if this graph is used by Operator\n";
PVecOperator vecOp;
search_operatorByGraphUse(vecOp, tabGraphToken.getVecOperator(), graphToken.getName());
if(vecOp.size() != 0lu){ //Operator Part
std::string prevElse("");
body += "\t//This graph is used by the following Operator\n";
body += "\t//repr_cpp_graphToken : This graph is used by the following Operator\n";
for(PVecOperator::iterator it(vecOp.begin()); it != vecOp.end(); ++it){
std::string opValue(repr_cpp_operator_getEnumValue(it->getValueEnum()));
std::string baseFctName("Operator" + repr_cpp_operator_getEnumValue(it->getValueEnum()));
body += "\t"+prevElse+"if(" + graphToken.getName() + baseFctName + "Do("+graphToken.getVarName()+")){return true;}\n";
prevElse = "else ";
}
body += "\t//Now continue the standard parsing without Operator\n";
}
//Standard graph token parsing part
for(PVecToken::const_iterator it(vecToken.begin()); it != vecToken.end(); ++it){
body += "\tif(!"+it->getFunctionName()+"Do("+graphToken.getVarName()+")){\n";
for(long unsigned int i(0lu); i < tokenIndex; ++i){
body += "\t\t"+vecToken[tokenIndex - i - 1lu].getFunctionName()+"Undo("+graphToken.getVarName()+");\n";
}
body += "\t\treturn false;\n";
body += "\t}\n";
++tokenIndex;
body += "\t//repr_cpp_graphToken : Now continue the standard parsing without Operator\n";
}
body += "\treturn true;\n";
body += "}\n\n";
......
......@@ -34,8 +34,30 @@ std::string repr_cpp_tokenOperatorHeader(const PTabGraphToken & tabGraphToken, c
*/
std::string repr_cpp_singleTokenOperator(const POperator & op, const PGraphToken & graphToken){
std::string body(""), name(graphToken.getName()), varName(graphToken.getVarName()), varType(graphToken.getVarType());
body += "\t//Let's parse an Operator with 1 token\n";
body += "\tif(isMatch(\""+op.getVecToken().front()+"\")){return false;}\n";
body += "\t//repr_cpp_token_operator : Let's parse an Operator with 1 token\n";
body += "\t//repr_cpp_token_operator : the first operand is already parsed and given as parameter\n";
body += "\t//repr_cpp_token_operator : it would be great to add a while\n\n";
body += "\tif(!isMatch(\""+op.getVecToken().front()+"\")){return false;}\n";
body += "\t//repr_cpp_token_operator : Let's call the graph token of the second operand\n";
body += "\tPStmt rightOp = "+op.getExprClass()+"_default();\n";
std::string rightOperandGraph(op.getVecExprGraph().back());
body += "\tif(!" + rightOperandGraph + "(rightOp)){return false;}\n";
body += "\t//repr_cpp_token_operator : here the operator is well parsed\n";
body += "\tPStmt op = "+op.getExprClass()+"_default();\n";
// body += "\top.setType("+op.getValueEnum()+");\n";
body += "\t"+op.getExprClass()+"_set"+firstToUpper(op.getAttrEnum())+"(op, "+op.getValueEnum()+");\n";
body += "\tPStmt & vecOperand = PExpr_getVecOperand(op);\n";
body += "\tvecOperand.push_back("+varName+");\n";
body += "\tvecOperand.push_back(rightOp);\n";
body += "\t//repr_cpp_token_operator : Finally, put the operator in the in/out parameter\n";
body += "\t"+varName+" = op;\n";
return body;
}
......@@ -47,7 +69,7 @@ std::string repr_cpp_singleTokenOperator(const POperator & op, const PGraphToken
*/
std::string repr_cpp_doubleTokenOperator(const POperator & op, const PGraphToken & graphToken){
std::string body(""), name(graphToken.getName()), varName(graphToken.getVarName()), varType(graphToken.getVarType());
body += "\t//Let's parse an Operator with 2 tokens\n";
body += "\t//repr_cpp_token_operator : Let's parse an Operator with 2 tokens\n";
return body;
}
......@@ -59,7 +81,7 @@ std::string repr_cpp_doubleTokenOperator(const POperator & op, const PGraphToken
*/
std::string repr_cpp_tripleTokenOperator(const POperator & op, const PGraphToken & graphToken){
std::string body(""), name(graphToken.getName()), varName(graphToken.getVarName()), varType(graphToken.getVarType());
body += "\t//Let's parse an Operator with 3 tokens\n";
body += "\t//repr_cpp_token_operator : Let's parse an Operator with 3 tokens\n";
return body;
}
......@@ -92,7 +114,7 @@ std::string repr_cpp_tokenOperatorSourceOperatorDo(const std::string & parserNam
}
body += "\tPStmt & _vecOp = " + varType + "_get"+firstToUpper(op.getVecOp())+"(" + varName + ");\n";
body += "\t//If there is no operand\n";
body += "\t//repr_cpp_token_operator : If there is no operand\n";
body += "\tif(_vecOp.size() == 0lu){return false;}\n";
body +="\treturn false;\n";
......
......@@ -206,6 +206,26 @@ bool PStmt::isType(unsigned int type) const{
return p_type == type;
}
///Print the PStmt
/** @param indentation : indentation of the print
*/
void PStmt::print(const std::string & indentation) const{
std::cout << indentation << "PStmt(type = "<<p_type<<", sign = "<<p_sign<<", datasize = " << p_data.size();
if(p_data.size() != 0lu){
std::cout << ", data = "<<((void*)p_data.data());
}
std::cout << ")";
if(p_vecStmt.size() != 0lu){
std::cout << "{" << std::endl;
for(std::vector<PStmt>::const_iterator it(p_vecStmt.begin()); it != p_vecStmt.end(); ++it){
it->print(indentation + "\t");
}
std::cout << indentation << "}" << std::endl;
}else{
std::cout << ";" << std::endl;
}
}
///Copy function of PStmt
/** @param other : class to copy
*/
......
......@@ -62,6 +62,8 @@ class PStmt{
bool isType(unsigned int type) const;
void print(const std::string & indentation = "") const;
protected:
void copyPStmt(const PStmt & other);
......
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