PhoenixHPCProxy  0.8.0
Lightweight HPC proxy
Loading...
Searching...
No Matches
HeaderParser Class Reference

Parse the configuration a create the vector of sources. More...

#include <HeaderParser.h>

+ Inheritance diagram for HeaderParser:
+ Collaboration diagram for HeaderParser:

Public Member Functions

const PVecSourcegetVecSource () const
 Get the parsed vector of PSource.
 
 HeaderParser ()
 Default constructor of HeaderParser.
 
 HeaderParser (const HeaderParser &other)
 Copy constructor of HeaderParser.
 
HeaderParseroperator= (const HeaderParser &other)
 Definition of equal operator of HeaderParser.
 
virtual ~HeaderParser ()
 Destructor of HeaderParser.
 

Protected Member Functions

void copyHeaderParser (const HeaderParser &other)
 Copy function of HeaderParser.
 
virtual bool parseFile ()
 Parse the input file.
 
virtual void postLoadFile ()
 Initialisation to be done just after loading a file.
 
virtual void preLoadFile ()
 Initialisation to be done just before loading a file.
 

Private Member Functions

void incrementCurrentChar ()
 Increment current char position.
 
void initialisationHeaderParser ()
 Initialisation function of the class HeaderParser.
 
bool parseArgument (PArgument &argument)
 Parse a PAttribute.
 
bool parseDocString ()
 Parse a doc string.
 
bool parseFunction (PFunction &function)
 Parse a PFunction.
 
bool parseMacro ()
 Parse a macro.
 
void parseTemplateDef (PString &templateDef)
 Parse a template definition.
 
void parseType (PString &type)
 Parse a data type.
 
void playOtherCode ()
 Add the other code parsed into the current PSource.
 

Private Attributes

PSource p_currentSource
 Current source to be parsed.
 
PString p_lastDocString
 Last documentation string.
 
PString p_otherCode
 Other code which is not a function prototype.
 
PVecSource p_vecSource
 Vector of parsed PSource.
 

Detailed Description

Parse the configuration a create the vector of sources.

Definition at line 14 of file HeaderParser.h.

Constructor & Destructor Documentation

◆ HeaderParser() [1/2]

HeaderParser::HeaderParser ( )

Default constructor of HeaderParser.

Definition at line 10 of file HeaderParser.cpp.

10 {
12}
void initialisationHeaderParser()
Initialisation function of the class HeaderParser.

References initialisationHeaderParser().

Referenced by copyHeaderParser(), HeaderParser(), and operator=().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ HeaderParser() [2/2]

HeaderParser::HeaderParser ( const HeaderParser & other)

Copy constructor of HeaderParser.

Parameters
other: class to copy

Definition at line 17 of file HeaderParser.cpp.

17 {
18 copyHeaderParser(other);
19}
void copyHeaderParser(const HeaderParser &other)
Copy function of HeaderParser.

References copyHeaderParser(), and HeaderParser().

+ Here is the call graph for this function:

◆ ~HeaderParser()

HeaderParser::~HeaderParser ( )
virtual

Destructor of HeaderParser.

Definition at line 22 of file HeaderParser.cpp.

22 {
23
24}

Member Function Documentation

◆ copyHeaderParser()

void HeaderParser::copyHeaderParser ( const HeaderParser & other)
protected

Copy function of HeaderParser.

Parameters
other: class to copy

Definition at line 45 of file HeaderParser.cpp.

45 {
47}
PVecSource p_vecSource
Vector of parsed PSource.

References HeaderParser(), and p_vecSource.

Referenced by HeaderParser(), and operator=().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getVecSource()

const PVecSource & HeaderParser::getVecSource ( ) const

Get the parsed vector of PSource.

Returns
parsed vector of PSource

Definition at line 38 of file HeaderParser.cpp.

38 {
39 return p_vecSource;
40}

References p_vecSource.

Referenced by createSourceFromConfig().

+ Here is the caller graph for this function:

◆ incrementCurrentChar()

void HeaderParser::incrementCurrentChar ( )
private

Increment current char position.

Parameters
[out]textObj: obh to be used to store text

Definition at line 96 of file HeaderParser.cpp.

96 {
97 //If nothing is known I need to save the current char in the other code
98 char ch = p_parser->getCurrentCh();
99 if(ch == '~'){ch = ' ';}
100 p_otherCode += ch;
101 p_parser->getNextChar();
102}
PString p_otherCode
Other code which is not a function prototype.

References p_otherCode.

Referenced by parseFile().

+ Here is the caller graph for this function:

◆ initialisationHeaderParser()

void HeaderParser::initialisationHeaderParser ( )
private

Initialisation function of the class HeaderParser.

Definition at line 89 of file HeaderParser.cpp.

89 {
90
91}

Referenced by HeaderParser().

+ Here is the caller graph for this function:

◆ operator=()

HeaderParser & HeaderParser::operator= ( const HeaderParser & other)

Definition of equal operator of HeaderParser.

Parameters
other: class to copy
Returns
copied class

Definition at line 30 of file HeaderParser.cpp.

30 {
31 copyHeaderParser(other);
32 return *this;
33}

References copyHeaderParser(), and HeaderParser().

+ Here is the call graph for this function:

◆ parseArgument()

bool HeaderParser::parseArgument ( PArgument & arg)
private

Parse a PAttribute.

Parameters
[out]arg: PArgument to be parsed
Returns
true on success, false otherwise

Definition at line 223 of file HeaderParser.cpp.

223 {
224 if(p_parser->isMatchRewind(")")){return true;}
225 PString type("");
226 parseType(type);
227
228 PString varName(""), ptrRef(""), tmpPtrRef("");
229
230 tmpPtrRef = p_parser->getNextToken();
231
232 if(isPtrRef(tmpPtrRef)){
233 do{
234 ptrRef += tmpPtrRef;
235 tmpPtrRef = p_parser->getNextToken();
236// if(tmpPtrRef == "__restrict__"){ptrRef += " ";}
237
238 }while(isPtrRef(tmpPtrRef));
239
240 varName = tmpPtrRef;
241 }else{
242 ptrRef = tmpPtrRef;
243 varName = ptrRef;
244 ptrRef = "";
245 }
246 std::cerr << "HeaderParser::parseArgument : type = '"<<type<<", ptrRef = '"<<ptrRef<<"', varName = '"<<varName<<"'" << std::endl;
247 PString defaultValue("");
248 if(p_parser->isMatch("=")){ //Some default value
249 defaultValue = p_parser->getNextToken();
250 //If double quote are not token, even default strings are single token
251 p_parser->pushPosition();
252 PString nexToken(p_parser->getNextToken());
253 if(nexToken == "("){ //We call a function/constructor
254 defaultValue += p_parser->getUntilKeyWithoutPaternRecurse(")", "(");
255 }else{
256 p_parser->popPosition(); //It was not a function/constructor call
257 }
258 }
259 arg.setName(varName);
260 arg.setPtrRef(ptrRef);
261 arg.setType(type);
262 arg.setDefaultValue(defaultValue);
263 return true;
264}
bool isPtrRef(const PString &str)
Say if the given string is a pointer or a reference.
void parseType(PString &type)
Parse a data type.
void setPtrRef(const PString &ptrRef)
Sets the ptrRef of the PArgument.
Definition PRepr.cpp:60
void setType(const PString &type)
Sets the type of the PArgument.
Definition PRepr.cpp:46
void setName(const PString &name)
Sets the name of the PArgument.
Definition PRepr.cpp:39
void setDefaultValue(const PString &defaultValue)
Sets the defaultValue of the PArgument.
Definition PRepr.cpp:53

References isPtrRef(), parseType(), PArgument::setDefaultValue(), PArgument::setName(), PArgument::setPtrRef(), and PArgument::setType().

Referenced by parseFunction().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseDocString()

bool HeaderParser::parseDocString ( )
private

Parse a doc string.

Returns
true on success, false otherwise

Definition at line 129 of file HeaderParser.cpp.

129 {
130 if(!p_parser->isMatch("///")){return false;}
131 p_lastDocString = p_parser->getUntilKeyWithoutPatern("\n");
132
133 return true;
134}
PString p_lastDocString
Last documentation string.

References p_lastDocString.

Referenced by parseFile(), and parseFunction().

+ Here is the caller graph for this function:

◆ parseFile()

bool HeaderParser::parseFile ( )
protectedvirtual

Parse the input file.

Returns
true on success, false otherwise

Definition at line 52 of file HeaderParser.cpp.

52 {
53 if(!p_run) return false;
54 p_lastDocString = "";
55 p_otherCode = "";
56 p_currentSource.setName(p_parser->getFileName().getFileName());
57 p_parser->skipWhiteSpace();
58 //To parse the file we need to read char by char until we get something we know
59 while(!p_parser->isEndOfFile() && p_run){ //If we are not at the end of the file
60 PFunction function;
61 if(parseDocString()){}
62 else if(p_parser->isMatch("//")){p_parser->getUntilKeyWithoutPatern("\n");} //Skip comment
63 else if(p_parser->isMatch("/*")){p_parser->getUntilKeyWithoutPatern("*/");} //Skip comment
64 else if(parseMacro()){}
65 else if(parseFunction(function)){
66 p_currentSource.getVecFunction().push_back(function);
67 }else{
69 }
70 p_parser->skipWhiteSpace();
71 }
73 return true;
74}
PSource p_currentSource
Current source to be parsed.
bool parseMacro()
Parse a macro.
bool parseDocString()
Parse a doc string.
void incrementCurrentChar()
Increment current char position.
bool parseFunction(PFunction &function)
Parse a PFunction.

References incrementCurrentChar(), p_currentSource, p_lastDocString, p_otherCode, p_vecSource, parseDocString(), parseFunction(), and parseMacro().

+ Here is the call graph for this function:

◆ parseFunction()

bool HeaderParser::parseFunction ( PFunction & function)
private

Parse a PFunction.

Parameters
[out]function: PFunction to be parsed
Returns
true on success, false otherwise

Definition at line 140 of file HeaderParser.cpp.

140 {
141 p_parser->pushPosition();
142 PString templateDef(""), returnType("");
143 parseTemplateDef(templateDef);
144 parseType(returnType);
145 std::cerr << "HeaderParser::parseFunction : returnType = '"<<returnType<<"'" << std::endl;
146 PString functionName(p_parser->getNextToken());
147 if(functionName == ""){return false;} //This is not a function
149 p_lastDocString = "";
150 //Let's get the arguments of the function
151 if(!p_parser->isMatch("(")){return false;} //This is not a function
152 function.setName(functionName);
153 function.setOutputType(returnType);
154 while(!p_parser->isEndOfFile() && !p_parser->isMatch(")") && p_run){
155 PArgument arg;
156 if(parseDocString()){}
157 else if(p_parser->isMatch("//")){p_parser->getUntilKeyWithoutPatern("\n");} //Skip comment
158 else if(p_parser->isMatch("/*")){p_parser->getUntilKeyWithoutPatern("*/");} //Skip comment
159 else if(parseArgument(arg)){
160 function.getVecArgument().push_back(arg);
161 if(!p_parser->isMatch(",") && !isMatchRewind(")")){
162 errorAt();
163 std::cerr << "HeaderParser::parseFunction : expect ',' or ')' after function definition '"<<functionName<<"'" << std::endl;
164 return true;
165 }
166 }else{
167 errorAt();
168 std::cerr << "HeaderParser::parseFunction : cannot parse attribute" << std::endl;
169 return true;
170 }
171 p_parser->skipWhiteSpace();
172
173 }
174 if(!p_parser->isMatch(";")){
175 errorAt();
176 std::cerr << "HeaderParser::parseFunction : expect ';' after function definition '"<<functionName<<"'" << std::endl;
177 return true;
178 }
180 return true;
181
182}
void playOtherCode()
Add the other code parsed into the current PSource.
void parseTemplateDef(PString &templateDef)
Parse a template definition.
bool parseArgument(PArgument &argument)
Parse a PAttribute.
void setName(const PString &name)
Sets the name of the PFunction.
Definition PRepr.cpp:159
void setOutputType(const PString &outputType)
Sets the outputType of the PFunction.
Definition PRepr.cpp:180
void setDocString(const PString &docString)
Sets the docString of the PFunction.
Definition PRepr.cpp:166
const std::vector< PArgument > & getVecArgument() const
Gets the vecArgument of the PFunction.
Definition PRepr.cpp:229

References PFunction::getVecArgument(), p_lastDocString, parseArgument(), parseDocString(), parseTemplateDef(), parseType(), playOtherCode(), PFunction::setDocString(), PFunction::setName(), and PFunction::setOutputType().

Referenced by parseFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseMacro()

bool HeaderParser::parseMacro ( )
private

Parse a macro.

Returns
true on success, false otherwise

Definition at line 117 of file HeaderParser.cpp.

117 {
118 if(!p_parser->isMatch("#")){return false;}
119 PString macro("#" + p_parser->getUntilKeyWithoutPatern("\n") + "\n");
120 PFunction func;
121 func.setOtherCode(macro);
122 p_currentSource.getVecFunction().push_back(func);
123 return true;
124}
void setOtherCode(const PString &otherCode)
Sets the otherCode of the PFunction.
Definition PRepr.cpp:194

References p_currentSource, and PFunction::setOtherCode().

Referenced by parseFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseTemplateDef()

void HeaderParser::parseTemplateDef ( PString & templateDef)
private

Parse a template definition.

Parameters
[out]templateDef: template definition

Definition at line 187 of file HeaderParser.cpp.

187 {
188 if(!p_parser->isMatchToken("template")){return;}
189
190 if(!p_parser->isMatch("<")){
191 errorAt();
192 std::cerr << "HeaderParser::parseTemplateDef : expect '<' after 'template' token" << std::endl;
193 return;
194 }
195 templateDef += "template<";
196 bool isTemplate(true);
197 while(!p_parser->isEndOfFile() && isTemplate && p_run){
198 templateDef += p_parser->getNextToken(); //Some typename
199 templateDef += " ";
200 templateDef += p_parser->getNextToken(); //Some T
201 if(p_parser->isMatch(">")){isTemplate = false;}
202 else if(!p_parser->isMatch(",")){
203 errorAt();
204 std::cerr << "HeaderParser::parseTemplateDef : expect '>' or ',' after template definition '"<<templateDef<<"'" << std::endl;
205 return;
206 }
207 }
208 templateDef += ">";
209}

Referenced by parseFunction().

+ Here is the caller graph for this function:

◆ parseType()

void HeaderParser::parseType ( PString & type)
private

Parse a data type.

Parameters
[out]type: type to be parsed

Definition at line 269 of file HeaderParser.cpp.

269 {
270 type = "";
271 PString token(p_parser->getNextToken());
272 while(token == "const" || token == "unsigned" || token == "long"){
273 type += token + " ";
274 token = p_parser->getNextToken();
275 }
276 type += token;
277}

Referenced by parseArgument(), and parseFunction().

+ Here is the caller graph for this function:

◆ playOtherCode()

void HeaderParser::playOtherCode ( )
private

Add the other code parsed into the current PSource.

Definition at line 105 of file HeaderParser.cpp.

105 {
106 if(p_otherCode != ""){
107 PFunction other;
109 p_currentSource.getVecFunction().push_back(other);
110 p_otherCode = "";
111 }
112}

References p_currentSource, p_otherCode, and PFunction::setOtherCode().

Referenced by parseFunction().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ postLoadFile()

void HeaderParser::postLoadFile ( )
protectedvirtual

Initialisation to be done just after loading a file.

Definition at line 84 of file HeaderParser.cpp.

84 {
85
86}

◆ preLoadFile()

void HeaderParser::preLoadFile ( )
protectedvirtual

Initialisation to be done just before loading a file.

Definition at line 77 of file HeaderParser.cpp.

77 {
78 //Save the current source
79 p_parser->setWhiteSpace(" \t\n");
80 p_parser->setSeparator(",;{}()");
81}

Member Data Documentation

◆ p_currentSource

PSource HeaderParser::p_currentSource
private

Current source to be parsed.

Definition at line 48 of file HeaderParser.h.

Referenced by parseFile(), parseMacro(), and playOtherCode().

◆ p_lastDocString

PString HeaderParser::p_lastDocString
private

Last documentation string.

Definition at line 44 of file HeaderParser.h.

Referenced by parseDocString(), parseFile(), and parseFunction().

◆ p_otherCode

PString HeaderParser::p_otherCode
private

Other code which is not a function prototype.

Definition at line 46 of file HeaderParser.h.

Referenced by incrementCurrentChar(), parseFile(), and playOtherCode().

◆ p_vecSource

PVecSource HeaderParser::p_vecSource
private

Vector of parsed PSource.

Definition at line 50 of file HeaderParser.h.

Referenced by copyHeaderParser(), getVecSource(), and parseFile().


The documentation for this class was generated from the following files: