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

Function AddVariable

NULLC/Callbacks.cpp:1181–1217  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1179}
1180
1181VariableInfo* AddVariable(const char* pos, InplaceStr variableName, bool preserveNamespace)
1182{
1183 CodeInfo::lastKnownStartPos = pos;
1184
1185 InplaceStr varName = preserveNamespace ? GetNameInNamespace(variableName) : variableName;
1186
1187 unsigned int hash = GetStringHash(varName.begin, varName.end);
1188
1189 if(TypeInfo **info = CodeInfo::classMap.find(hash))
1190 ThrowError(pos, "ERROR: name '%.*s' is already taken for a class", varName.end-varName.begin, varName.begin);
1191
1192 // Check for variables with the same name in current scope
1193 if(VariableInfo ** info = varMap.find(hash))
1194 if((*info)->blockDepth >= varInfoTop.size())
1195 ThrowError(pos, "ERROR: name '%.*s' is already taken for a variable in current scope", varName.end-varName.begin, varName.begin);
1196 // Check for functions with the same name
1197 CheckCollisionWithFunction(pos, varName, hash, varInfoTop.size());
1198
1199 if((currType && currType->alignBytes != 0) || currAlign != TypeInfo::UNSPECIFIED_ALIGNMENT)
1200 {
1201 unsigned int offset = GetAlignmentOffset(pos, currAlign != TypeInfo::UNSPECIFIED_ALIGNMENT ? currAlign : currType->alignBytes);
1202 varTop += offset;
1203 }
1204 if(currType && currType->hasFinalizer)
1205 ThrowError(pos, "ERROR: cannot create '%s' that implements 'finalize' on stack", currType->GetFullTypeName());
1206 if(currType && !currType->hasFinished && currType != newType)
1207 ThrowError(pos, "ERROR: type '%s' is not fully defined. You can use '%s ref' or '%s[]' at this point", currType->GetFullTypeName(), currType->GetFullTypeName(), currType->GetFullTypeName());
1208 CodeInfo::varInfo.push_back(new VariableInfo(currDefinedFunc.size() > 0 ? currDefinedFunc.back() : NULL, varName, hash, varTop, currType, currDefinedFunc.size() == 0));
1209 varDefined = true;
1210 CodeInfo::varInfo.back()->blockDepth = varInfoTop.size();
1211 if(currType)
1212 varTop += currType->size;
1213 if(varTop > (1 << 24))
1214 ThrowError(pos, "ERROR: variable size limit exceeded");
1215 varMap.insert(hash, CodeInfo::varInfo.back());
1216 return CodeInfo::varInfo.back();
1217}
1218
1219void AddVariableReserveNode(const char* pos)
1220{

Callers 12

AddInplaceVariableFunction · 0.85
AddArrayIteratorFunction · 0.85
FunctionStartFunction · 0.85
FunctionEndFunction · 0.85
AddFunctionCallNodeFunction · 0.85
TypeAddMemberFunction · 0.85
TypeAddConstantFunction · 0.85
TypeContinueFunction · 0.85
AddListGeneratorFunction · 0.85
ImportModuleMethod · 0.85
ParseAddVariableFunction · 0.85

Calls 10

GetNameInNamespaceFunction · 0.85
ThrowErrorFunction · 0.85
GetAlignmentOffsetFunction · 0.85
GetFullTypeNameMethod · 0.80
insertMethod · 0.80
GetStringHashFunction · 0.70
findMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected