MCPcopy Create free account
hub / github.com/WheretIB/nullc / ParseAddVariable

Function ParseAddVariable

NULLC/Parser.cpp:1283–1327  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1281}
1282
1283bool 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
1329bool ParseVariableDefineSub(Lexeme** str)
1330{

Callers 1

ParseVariableDefineSubFunction · 0.85

Calls 13

ThrowErrorFunction · 0.85
ParseLexemFunction · 0.85
AddVariableFunction · 0.85
InplaceStrClass · 0.85
ParseVaribleSetFunction · 0.85
AddDefineVariableNodeFunction · 0.85
AddPopNodeFunction · 0.85
GetSelectedTypeFunction · 0.85
HasConstructorFunction · 0.85
AddGetAddressNodeFunction · 0.85

Tested by

no test coverage detected