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

Function TypeAddMember

NULLC/Callbacks.cpp:4879–4898  ·  view source on GitHub ↗

Add class member

Source from the content-addressed store, hash-verified

4877
4878// Add class member
4879void TypeAddMember(const char* pos, const char* varName)
4880{
4881 if(!currType)
4882 ThrowError(pos, "ERROR: auto cannot be used for class members");
4883 if(!currType->hasFinished)
4884 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());
4885 // Align members to their default alignment, but not larger that 4 bytes
4886 unsigned int alignment = currType->alignBytes > 4 ? 4 : currType->alignBytes;
4887 if(alignment && newType->size % alignment != 0)
4888 newType->size += alignment - (newType->size % alignment);
4889 newType->AddMemberVariable(varName, currType);
4890 if(newType->size > 64 * 1024)
4891 ThrowError(pos, "ERROR: class size cannot exceed 65535 bytes");
4892 if(currType->hasFinalizer)
4893 ThrowError(pos, "ERROR: class '%s' implements 'finalize' so only a reference or an unsized array of '%s' can be put in a class", currType->GetFullTypeName(), currType->GetFullTypeName());
4894
4895 VariableInfo *varInfo = (VariableInfo*)AddVariable(pos, InplaceStr(varName, (int)strlen(varName)), false);
4896 varInfo->isGlobal = true;
4897 varInfo->parentType = newType;
4898}
4899
4900void TypeAddConstant(const char* pos, const char* constName)
4901{

Callers 1

ParseClassBodyFunction · 0.85

Calls 5

ThrowErrorFunction · 0.85
AddVariableFunction · 0.85
InplaceStrClass · 0.85
GetFullTypeNameMethod · 0.80
AddMemberVariableMethod · 0.80

Tested by

no test coverage detected