Add class member
| 4877 | |
| 4878 | // Add class member |
| 4879 | void 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 | |
| 4900 | void TypeAddConstant(const char* pos, const char* constName) |
| 4901 | { |
no test coverage detected