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