MCPcopy Create free account
hub / github.com/dhewm/dhewm3 / ParseObjectDef

Method ParseObjectDef

neo/game/script/Script_Compiler.cpp:2026–2098  ·  view source on GitHub ↗

================ idCompiler::ParseObjectDef ================ */

Source from the content-addressed store, hash-verified

2024================
2025*/
2026void idCompiler::ParseObjectDef( const char *objname ) {
2027 idTypeDef *objtype;
2028 idTypeDef *type;
2029 idTypeDef *parentType;
2030 idTypeDef *fieldtype;
2031 idStr name;
2032 const char *fieldname;
2033 idTypeDef newtype( ev_field, NULL, "", 0, NULL );
2034 idVarDef *oldscope;
2035 int i;
2036
2037 oldscope = scope;
2038 if ( scope->Type() != ev_namespace ) {
2039 Error( "Objects cannot be defined within functions or other objects" );
2040 }
2041
2042 // make sure it doesn't exist before we create it
2043 if ( gameLocal.program.FindType( objname ) != NULL ) {
2044 Error( "'%s' : redefinition; different basic types", objname );
2045 }
2046
2047 // base type
2048 if ( !CheckToken( ":" ) ) {
2049 parentType = &type_object;
2050 } else {
2051 parentType = ParseType();
2052 if ( !parentType->Inherits( &type_object ) ) {
2053 Error( "Objects may only inherit from objects." );
2054 }
2055 }
2056
2057 objtype = gameLocal.program.AllocType( ev_object, NULL, objname, parentType == &type_object ? 0 : parentType->Size(), parentType );
2058 objtype->def = gameLocal.program.AllocDef( objtype, objname, scope, true );
2059 scope = objtype->def;
2060
2061 // inherit all the functions
2062 for( i = 0; i < parentType->NumFunctions(); i++ ) {
2063 const function_t *func = parentType->GetFunction( i );
2064 objtype->AddFunction( func );
2065 }
2066
2067 ExpectToken( "{" );
2068
2069 do {
2070 if ( CheckToken( ";" ) ) {
2071 // skip semicolons, which are harmless and ok syntax
2072 continue;
2073 }
2074
2075 fieldtype = ParseType();
2076 newtype.SetFieldType( fieldtype );
2077
2078 fieldname = va( "%s field", fieldtype->Name() );
2079 newtype.SetName( fieldname );
2080
2081 ParseName( name );
2082
2083 // check for a function prototype or declaraction

Callers

nothing calls this directly

Calls 15

vaFunction · 0.85
ErrorFunction · 0.50
TypeMethod · 0.45
FindTypeMethod · 0.45
InheritsMethod · 0.45
AllocTypeMethod · 0.45
SizeMethod · 0.45
AllocDefMethod · 0.45
NumFunctionsMethod · 0.45
GetFunctionMethod · 0.45
AddFunctionMethod · 0.45
SetFieldTypeMethod · 0.45

Tested by

no test coverage detected