Commit 6c9369b3 authored by Pierre Aubert's avatar Pierre Aubert
Browse files

Update c++ prototype parsing

parent 85685003
Pipeline #94888 passed with stages
in 2 minutes and 52 seconds
......@@ -77,7 +77,7 @@ bool HeaderParser::parseFile(){
void HeaderParser::preLoadFile(){
//Save the current source
p_parser->setWhiteSpace(" \t\n");
p_parser->setSeparator(",;{}[]()");
p_parser->setSeparator(",;{}()");
}
///Initialisation to be done just after loading a file
......@@ -105,22 +105,21 @@ bool HeaderParser::parseDocString(){
* @return true on success, false otherwise
*/
bool HeaderParser::parseFunction(PFunction & function){
std::string tableName(p_parser->getNextToken());
if(tableName == ""){return true;}
std::string dataSetName(tableName);
p_parser->pushPosition();
std::string templateDef(""), returnType("");
parseTemplateDef(templateDef);
parseType(returnType);
std::string functionName(p_parser->getNextToken());
if(functionName == ""){return false;} //This is not a function
function.setDocString(p_lastDocString);
p_lastDocString = "";
if(p_parser->isMatch("[")){
dataSetName = p_parser->getUntilKeyWithoutPatern("]");
}
if(!p_parser->isMatch("{")){
errorAt();
std::cerr << "HeaderParser::parseTable : expect '{' after function name '"<<tableName<<"'" << std::endl;
return true;
}
function.setName(tableName);
//Let's get the arguments of the function
if(!p_parser->isMatch("(")){return false;} //This is not a function
function.setName(functionName);
while(!p_parser->isEndOfFile() && !p_parser->isMatch("}") && p_run){
while(!p_parser->isEndOfFile() && !p_parser->isMatch(")") && p_run){
PArgument arg;
if(parseDocString()){}
else if(p_parser->isMatch("//")){p_parser->getUntilKeyWithoutPatern("\n");} //Skip comment
......@@ -128,7 +127,7 @@ bool HeaderParser::parseFunction(PFunction & function){
function.getVecArgument().push_back(arg);
}else{
errorAt();
std::cerr << "HeaderParser::parseTable : cannot parse attribute" << std::endl;
std::cerr << "HeaderParser::parseFunction : cannot parse attribute" << std::endl;
return true;
}
p_parser->skipWhiteSpace();
......@@ -137,28 +136,70 @@ bool HeaderParser::parseFunction(PFunction & function){
}
///Parse a template definition
/** @param[out] templateDef : template definition
*/
void HeaderParser::parseTemplateDef(std::string & templateDef){
if(!p_parser->isMatchToken("template")){return;}
if(!p_parser->isMatch("<")){
errorAt();
std::cerr << "HeaderParser::parseTemplateDef : expect '<' after 'template' token" << std::endl;
return;
}
templateDef += "template<";
bool isTemplate(true);
while(!p_parser->isEndOfFile() && isTemplate && p_run){
templateDef += p_parser->getNextToken(); //Some typename
templateDef += " ";
templateDef += p_parser->getNextToken(); //Some T
if(p_parser->isMatch(">")){isTemplate = false;}
else if(!p_parser->isMatch(">")){
errorAt();
std::cerr << "HeaderParser::parseTemplateDef : expect ',' or ',' after template definition '"<<templateDef<<"'" << std::endl;
return;
}
}
templateDef += ">";
}
///Parse a PAttribute
/** @param[out] arg : PArgument to be parsed
* @return true on success, false otherwise
*/
bool HeaderParser::parseArgument(PArgument & arg){
if(p_parser->isMatchRewind("}")){return true;}
if(p_parser->isMatchRewind(")")){return true;}
std::string type("");
parseType(type);
std::string varName(p_parser->getNextToken());
std::string colName(varName);
if(p_parser->isMatch("[")){
colName = p_parser->getUntilKeyWithoutPatern("]");
std::string varName(""), ptrRef("");
ptrRef = p_parser->getNextToken();
if(findCharsInString(ptrRef, "&*")){
while(findCharsInString(ptrRef, "&*")){
ptrRef += p_parser->getNextToken();
}
varName = p_parser->getNextToken();
}else{
varName = ptrRef;
ptrRef = "";
}
if(!p_parser->isMatch(";")){
errorAt();
std::cerr << "HeaderParser::parseAttribute : expect ';' at the end of the definition of the '"<<varName<<"' attribute" << std::endl;
return true;
std::string defaultValue("");
if(p_parser->isMatch("=")){ //Some default value
defaultValue = p_parser->getNextToken();
//If double quote are not token, even default strings are single token
p_parser->pushPosition();
std::string nexToken(p_parser->getNextToken());
if(nexToken == "("){ //We call a function/constructor
defaultValue += p_parser->getUntilKeyWithoutPaternRecurse(")", "(");
}else{
p_parser->popPosition(); //It was not a function/constructor call
}
}
arg.setName(varName);
arg.setPtrRef(ptrRef);
arg.setType(type);
arg.setDefaultValue(defaultValue);
return true;
}
......
......@@ -32,6 +32,7 @@ class HeaderParser : public PMultiFileParser{
bool parseDocString();
bool parseFunction(PFunction & function);
void parseTemplateDef(std::string & templateDef);
bool parseArgument(PArgument & argument);
void parseType(std::string & type);
......
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