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

Function TypeAddConstant

NULLC/Callbacks.cpp:4900–4927  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4898}
4899
4900void TypeAddConstant(const char* pos, const char* constName)
4901{
4902 if(CodeInfo::nodeList.back()->nodeType != typeNodeNumber)
4903 ThrowError(pos, "ERROR: expression didn't evaluate to a constant number");
4904
4905 unsigned size = newType->size;
4906 unsigned memberCount = newType->memberCount;
4907 bool hasPointers = newType->hasPointers;
4908
4909 if(currType)
4910 ((NodeNumber*)CodeInfo::nodeList.back())->ConvertTo(currType);
4911 newType->AddMemberVariable(constName, currType ? currType : CodeInfo::nodeList.back()->typeInfo);
4912 newType->lastVariable->defaultValue = CodeInfo::nodeList.back();
4913 CodeInfo::nodeList.pop_back();
4914
4915 newType->size = size;
4916 newType->memberCount = memberCount;
4917 newType->hasPointers = hasPointers;
4918
4919 for(TypeInfo::MemberVariable *curr = newType->firstVariable; curr && curr != newType->lastVariable; curr = curr->next)
4920 {
4921 if(curr->nameHash == newType->lastVariable->nameHash)
4922 ThrowError(pos, "ERROR: name '%s' is already taken for a variable in current scope", constName);
4923 }
4924 VariableInfo *varInfo = (VariableInfo*)AddVariable(pos, InplaceStr(constName, (int)strlen(constName)));
4925 varInfo->isGlobal = true;
4926 varInfo->parentType = newType;
4927}
4928
4929void TypePrototypeFinish()
4930{

Callers 2

ParseClassBodyFunction · 0.85
ParseEnumFunction · 0.85

Calls 6

ThrowErrorFunction · 0.85
AddVariableFunction · 0.85
InplaceStrClass · 0.85
ConvertToMethod · 0.80
AddMemberVariableMethod · 0.80
pop_backMethod · 0.45

Tested by

no test coverage detected