| 1281 | } |
| 1282 | |
| 1283 | bool ParseAddVariable(Lexeme** str) |
| 1284 | { |
| 1285 | if((*str)->type != lex_string) |
| 1286 | return false; |
| 1287 | |
| 1288 | if((*str)->length >= NULLC_MAX_VARIABLE_NAME_LENGTH) |
| 1289 | ThrowError((*str)->pos, "ERROR: variable name length is limited to 2048 symbols"); |
| 1290 | |
| 1291 | Lexeme *varName = *str; |
| 1292 | (*str)++; |
| 1293 | |
| 1294 | if(ParseLexem(str, lex_obracket)) |
| 1295 | ThrowError((*str)->pos, "ERROR: array size must be specified after typename"); |
| 1296 | |
| 1297 | VariableInfo *varInfo = AddVariable((*str)->pos, InplaceStr(varName->pos, varName->length)); |
| 1298 | |
| 1299 | if(ParseLexem(str, lex_set)) |
| 1300 | { |
| 1301 | Lexeme *curr = *str; |
| 1302 | if(!ParseVaribleSet(str)) |
| 1303 | ThrowError((*str)->pos, "ERROR: expression not found after '='"); |
| 1304 | AddDefineVariableNode(curr->pos, varInfo); |
| 1305 | AddPopNode((*str)->pos); |
| 1306 | }else{ |
| 1307 | // Try to call constructor with no arguments |
| 1308 | TypeInfo *info = GetSelectedType(); |
| 1309 | // Handle array types |
| 1310 | TypeInfo *base = info; |
| 1311 | while(base && base->arrLevel && base->arrSize != TypeInfo::UNSIZED_ARRAY) // Unsized arrays are not initialized |
| 1312 | base = base->subType; |
| 1313 | bool callDefault = false; |
| 1314 | bool hasConstructor = base ? HasConstructor(base, 0, &callDefault) : NULL; |
| 1315 | if(hasConstructor) |
| 1316 | { |
| 1317 | const char *name = base->genericBase ? base->genericBase->name : base->name; |
| 1318 | if(callDefault) |
| 1319 | name = GetDefaultConstructorName(name); |
| 1320 | AddGetAddressNode((*str)->pos, varInfo->name); |
| 1321 | AddDefaultConstructorCall((*str)->pos, name); |
| 1322 | }else{ |
| 1323 | AddVariableReserveNode((*str)->pos); |
| 1324 | } |
| 1325 | } |
| 1326 | return true; |
| 1327 | } |
| 1328 | |
| 1329 | bool ParseVariableDefineSub(Lexeme** str) |
| 1330 | { |
no test coverage detected