GCC Code Coverage Report


Directory: ./
File: src/FrontEnd/parserClassConfig.cpp
Date: 2026-06-23 11:27:41
Exec Total Coverage
Lines: 100 144 69.4%
Functions: 9 10 90.0%
Branches: 157 298 52.7%

Line Branch Exec Source
1
2 /***************************************
3 Auteur : Pierre Aubert
4 Mail : pierre.aubert@lapp.in2p3.fr
5 Licence : CeCILL-C
6 ****************************************/
7
8 #include <iostream>
9 #include "class_attribute_utils.h"
10 #include "parserClassConfig.h"
11
12 ///Affiche une erreur de token non attendu
13 /** @param parser : file parser
14 * @param token : token qui pose problème
15 */
16 void errorUnexpectedToken(const PFileParser & parser, const PString & token){
17 std::cerr << "errorUnexpectedToken : '" << parser.getFileName() << "' line " << parser.getLine() << std::endl;
18 std::cerr << "unexpected token '" << token << "'" << std::endl;
19 }
20
21 ///Get class name from parser
22 /** @param parser : PFileParser to be used
23 * @return class name
24 */
25 9 PString getClassName(PFileParser & parser){
26
2/2
✓ Branch 0 (2→3) taken 9 times.
✓ Branch 2 (3→4) taken 9 times.
9 PString name = parser.getStrComposedOf("_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
27
3/4
✓ Branch 0 (14→15) taken 9 times.
✓ Branch 2 (15→16) taken 9 times.
✗ Branch 4 (17→6) not taken.
✓ Branch 5 (17→18) taken 9 times.
9 while(parser.isMatch("::")){
28 name += "::" + parser.getStrComposedOf("_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
29 }
30 9 return name;
31 }
32
33 ///Fonction qui met à jour un commentaire
34 /** @param parser : file parser
35 * @param currentComment : commentaire que l'on veut mettre à jour
36 * @return true si on l'a mis à jour, false sinon
37 */
38 40 bool updateCurrentComment(PFileParser & parser, PString & currentComment){
39
4/4
✓ Branch 0 (2→3) taken 40 times.
✓ Branch 2 (3→4) taken 40 times.
✓ Branch 4 (5→6) taken 19 times.
✓ Branch 5 (5→17) taken 21 times.
40 if(parser.isMatch("//")){
40
1/2
✗ Branch 0 (7→8) not taken.
✓ Branch 1 (7→9) taken 19 times.
19 if(currentComment != ""){currentComment += "\n";}
41
4/4
✓ Branch 0 (9→10) taken 19 times.
✓ Branch 2 (10→11) taken 19 times.
✓ Branch 4 (11→12) taken 19 times.
✓ Branch 6 (12→13) taken 19 times.
19 currentComment += "//" + parser.getUntilKeyWithoutPatern("\n");
42
3/4
✓ Branch 0 (17→18) taken 21 times.
✓ Branch 2 (18→19) taken 21 times.
✗ Branch 4 (20→21) not taken.
✓ Branch 5 (20→32) taken 21 times.
21 }else if(parser.isMatch("/*")){
43 if(currentComment != ""){currentComment += "\n";}
44 currentComment += "/*" + parser.getUntilKey("*/");
45 }else{
46 21 return false;
47 }
48 19 return true;
49 }
50
51 ///Update a template definition
52 /** @param parser : file parser
53 * @param currentTemplate : template to be updated
54 * @return true on success, false otherwise
55 */
56 7 bool updateCurrentTemplate(PFileParser & parser, PVecString & currentTemplate){
57
3/4
✓ Branch 0 (2→3) taken 7 times.
✓ Branch 2 (3→4) taken 7 times.
✓ Branch 4 (5→6) taken 7 times.
✗ Branch 5 (5→7) not taken.
7 if(!parser.isMatch("template")){return false;}
58 if(!parser.isMatch("<")){return false;}
59
60 currentTemplate = parser.getUntilKeyWithoutPaternRecurse(">", "<").split(',');
61
62 return true;
63 }
64
65 ///Parse a PClassConfig
66 /** @param[out] config : PClassConfig
67 * @param[out] parser : file parser
68 * @param[out] currentComment : current commet
69 * @return true on success, false otherwise
70 */
71 12 bool parseClassConfigAttribut(PClassConfig & config, PFileParser & parser, PString & currentComment){
72
1/1
✓ Branch 0 (2→3) taken 12 times.
12 parser.skipWhiteSpace();
73
4/4
✓ Branch 0 (3→4) taken 12 times.
✓ Branch 2 (4→5) taken 12 times.
✓ Branch 4 (5→6) taken 12 times.
✓ Branch 6 (6→7) taken 12 times.
12 PString attribut(parser.getUntilKeyWithoutPatern(";").eraseChar("\n"));
74
2/2
✓ Branch 0 (10→11) taken 12 times.
✓ Branch 2 (11→12) taken 12 times.
12 PVecString listToken(attribut.split(" \n\t"));
75
1/1
✓ Branch 0 (14→15) taken 12 times.
12 PString attributName(listToken.back());
76 12 listToken.pop_back();
77
1/1
✓ Branch 0 (16→17) taken 12 times.
12 PString attributType("");
78
2/2
✓ Branch 0 (33→18) taken 12 times.
✓ Branch 1 (33→34) taken 12 times.
48 for(PVecString::iterator it(listToken.begin()); it != listToken.end(); ++it){
79
2/2
✓ Branch 0 (20→21) taken 12 times.
✓ Branch 2 (21→22) taken 12 times.
12 attributType += *it + " ";
80 }
81
3/3
✓ Branch 0 (34→35) taken 12 times.
✓ Branch 2 (35→36) taken 12 times.
✓ Branch 4 (36→37) taken 12 times.
12 attributType = attributType.eraseFirstLastChar(" \n\t");
82
2/2
✓ Branch 0 (39→40) taken 12 times.
✓ Branch 2 (40→41) taken 12 times.
12 config.addAttribute(createClassAttribute(attributType, attributName, currentComment));
83
1/1
✓ Branch 0 (42→43) taken 12 times.
12 currentComment = "";
84 12 return true;
85 12 }
86
87 ///Parse the parents of the PClassConfig
88 /** @param[out] config : PClassConfig
89 * @param[out] parser : file parser
90 * @return true on success, false otherwise
91 */
92 6 bool parseParentOfClassConfig(PClassConfig & config, PFileParser & parser){
93
3/4
✓ Branch 0 (2→3) taken 6 times.
✓ Branch 2 (3→4) taken 6 times.
✓ Branch 4 (5→6) taken 6 times.
✗ Branch 5 (5→7) not taken.
6 if(!parser.isMatch("(")) return true;
94
95 while(!parser.isEndOfFile() && parser.isMatch(")")){
96 PString parentDef(getClassName(parser));
97 if(parentDef == ""){
98 break;
99 }
100 config.addParentClass(parentDef);
101 if(parser.isMatch(")")){break;}
102
103 if(!parser.isMatch(",")){
104 errorUnexpectedToken(parser, parser.getNextToken());
105 return false;
106 }
107 }
108 return true;
109 }
110
111 ///Parse enum attribute value
112 /** @param[out] config : PClassConfig
113 * @param[out] parser : file parser
114 * @param[out] currentComment : current commet
115 * @return true on success, false otherwise
116 */
117 2 bool parseEnumValue(PClassConfig & config, PFileParser & parser, PString & currentComment){
118
2/2
✓ Branch 0 (2→3) taken 2 times.
✓ Branch 2 (3→4) taken 2 times.
2 PString enumValue(getClassName(parser)), value("");
119
3/4
✓ Branch 0 (4→5) taken 2 times.
✓ Branch 2 (5→6) taken 2 times.
✓ Branch 4 (7→8) taken 2 times.
✗ Branch 5 (7→14) not taken.
2 if(!parser.isMatch("=")){
120
3/3
✓ Branch 0 (8→9) taken 2 times.
✓ Branch 2 (9→10) taken 2 times.
✓ Branch 4 (10→11) taken 2 times.
2 value = parser.getStrComposedOf("0123456789xu");
121 }
122
2/2
✓ Branch 0 (14→15) taken 2 times.
✓ Branch 2 (15→16) taken 2 times.
2 PClassAttribute attr(createClassAttribute("int /* just to remember*/", enumValue, currentComment));
123
1/1
✓ Branch 0 (17→18) taken 2 times.
2 attr.setDefaultValue(value);
124
1/1
✓ Branch 0 (18→19) taken 2 times.
2 config.addAttribute(attr);
125
1/1
✓ Branch 0 (19→20) taken 2 times.
2 currentComment = "";
126
2/2
✓ Branch 0 (20→21) taken 2 times.
✓ Branch 2 (21→22) taken 2 times.
2 parser.isMatch(","); //We consume the comma if there is one
127 2 return true;
128 2 }
129
130 ///Parse an enum definition
131 /** @param[out] listClassConfig : list of PClassConfig
132 * @param[out] parser : file parser
133 * @param[out] currentComment : current comment
134 * @return true on success, false otherwise
135 */
136 7 bool parseEnumConfig(std::vector<PClassConfig> & listClassConfig, PFileParser & parser, PString & currentComment){
137
4/4
✓ Branch 0 (2→3) taken 7 times.
✓ Branch 2 (3→4) taken 7 times.
✓ Branch 4 (5→6) taken 6 times.
✓ Branch 5 (5→7) taken 1 times.
7 if(!parser.isMatchToken("enum")){return false;}
138
1/1
✓ Branch 0 (7→8) taken 1 times.
1 PClassConfig config;
139
1/1
✓ Branch 0 (8→9) taken 1 times.
1 config.setIsEnum(true);
140
1/1
✓ Branch 0 (9→10) taken 1 times.
1 PString enumName(getClassName(parser)); //Get the name of the enum
141
4/4
✓ Branch 0 (10→11) taken 1 times.
✓ Branch 2 (11→12) taken 1 times.
✓ Branch 4 (12→13) taken 1 times.
✓ Branch 6 (13→14) taken 1 times.
1 std::cout << "parseEnumConfig : find enum : '"<<enumName<<"'" << std::endl;
142
1/1
✓ Branch 0 (14→15) taken 1 times.
1 config.setName(enumName);
143
1/1
✓ Branch 0 (15→16) taken 1 times.
1 config.setClassDocumentation(currentComment);
144
1/1
✓ Branch 0 (16→17) taken 1 times.
1 currentComment = "";
145
1/1
✓ Branch 0 (17→18) taken 1 times.
1 parser.skipWhiteSpace();
146
3/4
✓ Branch 0 (18→19) taken 1 times.
✓ Branch 2 (19→20) taken 1 times.
✗ Branch 4 (21→22) not taken.
✓ Branch 5 (21→30) taken 1 times.
1 if(!parser.isMatch("{")){
147 errorUnexpectedToken(parser, parser.getNextToken());
148 std::cerr << "\tExpect '{' after enum name '"<<enumName<<"'" << std::endl;
149 return false;
150 }
151 1 bool searchingData(true);
152
10/15
✓ Branch 0 (42→43) taken 3 times.
✓ Branch 2 (43→44) taken 3 times.
✗ Branch 3 (43→49) not taken.
✓ Branch 4 (44→45) taken 3 times.
✗ Branch 5 (44→49) not taken.
✓ Branch 6 (45→46) taken 3 times.
✓ Branch 8 (46→47) taken 3 times.
✓ Branch 10 (47→48) taken 2 times.
✓ Branch 11 (47→49) taken 1 times.
✓ Branch 12 (50→51) taken 3 times.
✗ Branch 13 (50→52) not taken.
✓ Branch 14 (52→31) taken 2 times.
✓ Branch 15 (52→53) taken 1 times.
✗ Branch 16 (71→72) not taken.
✗ Branch 17 (71→73) not taken.
4 while(!parser.isEndOfFile() && searchingData && !parser.isMatch("}")){
153
2/3
✓ Branch 0 (31→32) taken 2 times.
✗ Branch 2 (32→33) not taken.
✓ Branch 3 (32→34) taken 2 times.
2 if(updateCurrentComment(parser, currentComment)){}
154 else{ //Si ce n'est pas un séparateur, c'est que l'on a trouvé un nom, de PDataGroup ou de PDataVar ou PDataTable
155
2/3
✓ Branch 0 (34→35) taken 2 times.
✗ Branch 2 (35→36) not taken.
✓ Branch 3 (35→40) taken 2 times.
2 if(!parseEnumValue(config, parser, currentComment)){
156 errorUnexpectedToken(parser, parser.getNextToken());
157 return false;
158 }
159 }
160 }
161
1/1
✓ Branch 0 (53→54) taken 1 times.
1 listClassConfig.push_back(config);
162 1 return true;
163 1 }
164
165 ///Parse a PClassConfig
166 /** @param[out] listClassConfig : list of PClassConfig
167 * @param[out] parser : file parser
168 * @param[out] currentComment : current comment
169 * @param[out] listTemplate : list of the template to be used in the defined class
170 * @return true on success, false otherwise
171 */
172 6 bool parsePClassConfig(std::vector<PClassConfig> & listClassConfig, PFileParser & parser, PString & currentComment, PVecString & listTemplate){
173
1/1
✓ Branch 0 (2→3) taken 6 times.
6 PClassConfig config;
174
1/1
✓ Branch 0 (3→4) taken 6 times.
6 PString fullName(getClassName(parser));
175
1/1
✓ Branch 0 (4→5) taken 6 times.
6 size_t separator = fullName.rfind("::");
176
2/2
✓ Branch 0 (5→6) taken 6 times.
✓ Branch 2 (6→7) taken 6 times.
6 PString className, namespaceName;
177
1/2
✗ Branch 0 (7→8) not taken.
✓ Branch 1 (7→18) taken 6 times.
6 if(separator != PString::npos){
178 className = fullName.substr(separator + 2);
179 namespaceName = fullName.substr(0, separator);
180 std::cout << "parsePClassConfig : find namespaceName : '"<<namespaceName<<"'" << std::endl;
181 }else{
182
1/1
✓ Branch 0 (18→19) taken 6 times.
6 className = fullName;
183 }
184
4/4
✓ Branch 0 (19→20) taken 6 times.
✓ Branch 2 (20→21) taken 6 times.
✓ Branch 4 (21→22) taken 6 times.
✓ Branch 6 (22→23) taken 6 times.
6 std::cout << "parsePClassConfig : find className : '"<<className<<"'" << std::endl;
185
1/1
✓ Branch 0 (23→24) taken 6 times.
6 config.setName(className);
186
1/1
✓ Branch 0 (24→25) taken 6 times.
6 config.setNamespace(namespaceName);
187
1/1
✓ Branch 0 (25→26) taken 6 times.
6 config.setClassDocumentation(currentComment);
188
1/1
✓ Branch 0 (26→27) taken 6 times.
6 config.setListTemplate(listTemplate);
189
1/1
✓ Branch 0 (27→28) taken 6 times.
6 currentComment = "";
190 6 listTemplate.clear();
191
1/1
✓ Branch 0 (29→30) taken 6 times.
6 parser.skipWhiteSpace();
192
193
2/3
✓ Branch 0 (30→31) taken 6 times.
✗ Branch 2 (31→32) not taken.
✓ Branch 3 (31→45) taken 6 times.
6 if(!parseParentOfClassConfig(config, parser)){
194 std::cerr << "parsePClassConfig : file '" << parser.getFileName() << "' line " << parser.getLine() << std::endl;
195 std::cerr << "\tmissing ')' : can't parse parents of the class '"<<config.getName()<<"'" << std::endl;
196 }
197
2/3
✓ Branch 0 (45→46) taken 6 times.
✗ Branch 2 (46→47) not taken.
✓ Branch 3 (46→58) taken 6 times.
6 if(parser.isEndOfFile()){
198 std::cerr << "parsePClassConfig : file '" << parser.getFileName() << "' line " << parser.getLine() << std::endl;
199 std::cerr << "\tmissing '}'" << std::endl;
200 return false;
201 }
202
3/4
✓ Branch 0 (58→59) taken 6 times.
✓ Branch 2 (59→60) taken 6 times.
✗ Branch 4 (61→62) not taken.
✓ Branch 5 (61→70) taken 6 times.
6 if(!parser.isMatch("{")){
203 errorUnexpectedToken(parser, parser.getNextToken());
204 std::cerr << "\tExpect '{' after class name '"<<className<<"'" << std::endl;
205 return false;
206 }
207
208 6 bool searchingData(true);
209
10/15
✓ Branch 0 (82→83) taken 30 times.
✓ Branch 2 (83→84) taken 30 times.
✗ Branch 3 (83→89) not taken.
✓ Branch 4 (84→85) taken 30 times.
✗ Branch 5 (84→89) not taken.
✓ Branch 6 (85→86) taken 30 times.
✓ Branch 8 (86→87) taken 30 times.
✓ Branch 10 (87→88) taken 24 times.
✓ Branch 11 (87→89) taken 6 times.
✓ Branch 12 (90→91) taken 30 times.
✗ Branch 13 (90→92) not taken.
✓ Branch 14 (92→71) taken 24 times.
✓ Branch 15 (92→93) taken 6 times.
✗ Branch 16 (122→123) not taken.
✗ Branch 17 (122→124) not taken.
36 while(!parser.isEndOfFile() && searchingData && !parser.isMatch("}")){
210
3/3
✓ Branch 0 (71→72) taken 24 times.
✓ Branch 2 (72→73) taken 12 times.
✓ Branch 3 (72→74) taken 12 times.
24 if(updateCurrentComment(parser, currentComment)){}
211 else{ //Si ce n'est pas un séparateur, c'est que l'on a trouvé un nom, de PDataGroup ou de PDataVar ou PDataTable
212
2/3
✓ Branch 0 (74→75) taken 12 times.
✗ Branch 2 (75→76) not taken.
✓ Branch 3 (75→80) taken 12 times.
12 if(!parseClassConfigAttribut(config, parser, currentComment)){
213 errorUnexpectedToken(parser, parser.getNextToken());
214 return false;
215 }
216 }
217 }
218
1/1
✓ Branch 0 (93→94) taken 6 times.
6 listClassConfig.push_back(config);
219 6 return true;
220 6 }
221
222 ///Parser list class config
223 /** @param[out] listClassConfig : list of class config
224 * @param listInclude : list of include
225 * @param fileName : file name of the config
226 * @return true on success, false otherwise
227 */
228 6 bool parserClassConfig(std::vector<PClassConfig> & listClassConfig, PVecPath & listInclude, const PPath & fileName){
229
2/3
✓ Branch 0 (2→3) taken 6 times.
✗ Branch 2 (3→4) not taken.
✓ Branch 3 (3→5) taken 6 times.
6 if(fileName == "") return false;
230
1/1
✓ Branch 0 (5→6) taken 6 times.
6 PFileParser parser;
231
2/2
✓ Branch 0 (6→7) taken 6 times.
✓ Branch 2 (7→8) taken 6 times.
6 parser.setWhiteSpace(" \t\n");
232
2/2
✓ Branch 0 (9→10) taken 6 times.
✓ Branch 2 (10→11) taken 6 times.
6 parser.setSeparator("{};/*");
233
2/3
✓ Branch 0 (12→13) taken 6 times.
✗ Branch 2 (13→14) not taken.
✓ Branch 3 (13→15) taken 6 times.
6 if(!parser.open(fileName)) return false;
234
1/1
✓ Branch 0 (15→16) taken 6 times.
6 PString currentComment("");
235 6 PVecString listTemplate;
236
3/3
✓ Branch 0 (52→53) taken 20 times.
✓ Branch 2 (53→18) taken 14 times.
✓ Branch 3 (53→54) taken 6 times.
20 while(!parser.isEndOfFile()){
237
3/4
✓ Branch 0 (18→19) taken 14 times.
✓ Branch 2 (19→20) taken 14 times.
✗ Branch 4 (21→22) not taken.
✓ Branch 5 (21→38) taken 14 times.
14 if(parser.isMatch("#")){
238 if(parser.isMatch("include")){
239 listInclude.push_back(parser.getUntilKeyWithoutPatern("\n").eraseChar(" \t\n"));
240 }
241
3/3
✓ Branch 0 (38→39) taken 14 times.
✓ Branch 2 (39→40) taken 7 times.
✓ Branch 3 (39→50) taken 7 times.
14 }else if(updateCurrentComment(parser, currentComment)){}
242
2/3
✓ Branch 0 (40→41) taken 7 times.
✓ Branch 2 (41→42) taken 7 times.
✗ Branch 3 (41→50) not taken.
7 else if(updateCurrentTemplate(parser, listTemplate)){}
243
3/3
✓ Branch 0 (42→43) taken 7 times.
✓ Branch 2 (43→44) taken 6 times.
✓ Branch 3 (43→50) taken 1 times.
7 else if(parseEnumConfig(listClassConfig, parser, currentComment)){}
244 else{ //Si ce n'est pas un séparateur, c'est que l'on a trouvé un nom, de PClassConfig
245
2/3
✓ Branch 0 (44→45) taken 6 times.
✗ Branch 2 (45→46) not taken.
✓ Branch 3 (45→50) taken 6 times.
6 if(!parsePClassConfig(listClassConfig, parser, currentComment, listTemplate)){
246 errorUnexpectedToken(parser, parser.getNextToken());
247 return false;
248 }
249 }
250
1/1
✓ Branch 0 (50→51) taken 14 times.
14 parser.skipWhiteSpace();
251 }
252 6 return true;
253 6 }
254
255
256
257