1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051 |
- /*
- ===========================================================================
- Doom 3 GPL Source Code
- Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
- This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
- Doom 3 Source Code is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- Doom 3 Source Code is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
- In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
- If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
- ===========================================================================
- */
- #include "../idlib/precompiled.h"
- #pragma hdrstop
- #include "TypeInfoGen.h"
- #define TYPE_INFO_GEN_VERSION "1.0"
- /*
- ================
- idTypeInfoGen::idTypeInfoGen
- ================
- */
- idTypeInfoGen::idTypeInfoGen( void ) {
- }
- /*
- ================
- idTypeInfoGen::~idTypeInfoGen
- ================
- */
- idTypeInfoGen::~idTypeInfoGen( void ) {
- constants.DeleteContents( true );
- enums.DeleteContents( true );
- classes.DeleteContents( true );
- }
- /*
- ================
- idTypeInfoGen::GetInheritance
- ================
- */
- int idTypeInfoGen::GetInheritance( const char *typeName ) const {
- int i;
- for ( i = 0; i < classes.Num(); i++ ) {
- if ( classes[i]->typeName.Cmp( typeName ) == 0 ) {
- if ( classes[i]->superType[0] != '\0' ) {
- return 1 + GetInheritance( classes[i]->superType );
- }
- break;
- }
- }
- return 0;
- }
- /*
- ================
- idTypeInfoGen::EvaluateIntegerString
- ================
- */
- int idTypeInfoGen::EvaluateIntegerString( const idStr &string ) {
- idParser src;
- idStr evalString;
- if ( string.Find( "::" ) != -1 ) {
- return 0;
- }
- evalString = "$evalint(" + string + ")";
- src.LoadMemory( evalString, evalString.Length(), "eval integer" );
- return src.ParseInt();
- }
- /*
- ================
- idTypeInfoGen::EvaluateFloatString
- ================
- */
- float idTypeInfoGen::EvaluateFloatString( const idStr &string ) {
- idParser src;
- idStr evalString;
- if ( string.Find( "::" ) != -1 ) {
- return 0.0f;
- }
- evalString = "$evalfloat(" + string + ")";
- src.LoadMemory( evalString, evalString.Length(), "eval float" );
- return src.ParseFloat();
- }
- /*
- ================
- idTypeInfoGen::FindConstant
- ================
- */
- idConstantInfo *idTypeInfoGen::FindConstant( const char *name ) {
- int i;
- for ( i = 0; i < constants.Num(); i++ ) {
- if ( constants[i]->name.Cmp( name ) == 0 ) {
- return constants[i];
- }
- }
- return NULL;
- }
- /*
- ================
- idTypeInfoGen::GetIntegerConstant
- ================
- */
- int idTypeInfoGen::GetIntegerConstant( const char *scope, const char *name, idParser &src ) {
- idConstantInfo *constant = FindConstant( idStr( scope ) + name );
- if ( constant == NULL ) {
- constant = FindConstant( name );
- }
- if ( constant ) {
- return EvaluateIntegerString( constant->value );
- }
- src.Warning( "unknown value '%s' in constant expression", name );
- return 0;
- }
- /*
- ================
- idTypeInfoGen::GetFloatConstant
- ================
- */
- float idTypeInfoGen::GetFloatConstant( const char *scope, const char *name, idParser &src ) {
- idConstantInfo *constant = FindConstant( idStr( scope ) + name );
- if ( constant == NULL ) {
- constant = FindConstant( name );
- }
- if ( constant ) {
- return EvaluateFloatString( constant->value );
- }
- src.Warning( "unknown value '%s' in constant expression", name );
- return 0;
- }
- /*
- ================
- idTypeInfoGen::ParseArraySize
- ================
- */
- int idTypeInfoGen::ParseArraySize( const char *scope, idParser &src ) {
- idToken token;
- idStr sizeString, constantString;
- int size, totalSize;
- if ( !src.CheckTokenString( "[" ) ) {
- return 0;
- }
- totalSize = 1;
- sizeString = "";
- while( src.ReadToken( &token ) ) {
- if ( token == "]" ) {
- if ( sizeString.Length() ) {
- size = EvaluateIntegerString( sizeString );
- if ( size ) {
- totalSize *= size;
- }
- sizeString = "";
- }
- if ( !src.CheckTokenString( "[" ) ) {
- break;
- }
- } else if ( token.type == TT_NAME ) {
- constantString = token;
- while( src.CheckTokenString( "::" ) ) {
- src.ExpectTokenType( TT_NAME, 0, &token );
- constantString += "::" + token;
- }
- sizeString += va( "%d", GetIntegerConstant( scope, constantString, src ) );
- } else {
- sizeString += token;
- }
- }
- return totalSize;
- }
- /*
- ================
- idTypeInfoGen::ParseConstantValue
- ================
- */
- void idTypeInfoGen::ParseConstantValue( const char *scope, idParser &src, idStr &value ) {
- idToken token;
- idStr constantString;
- int indent = 0;
- while( src.ReadToken( &token ) ) {
- if ( token == "(" ) {
- indent++;
- } else if ( token == ")" ) {
- indent--;
- } else if ( indent == 0 && ( token == ";" || token == "," || token == "}" ) ) {
- src.UnreadToken( &token );
- break;
- } else if ( token.type == TT_NAME ) {
- constantString = token;
- while( src.CheckTokenString( "::" ) ) {
- src.ExpectTokenType( TT_NAME, 0, &token );
- constantString += "::" + token;
- }
- value += va( "%d", GetIntegerConstant( scope, constantString, src ) );
- continue;
- }
- value += token;
- }
- }
- /*
- ================
- idTypeInfoGen::ParseEnumType
- ================
- */
- idEnumTypeInfo *idTypeInfoGen::ParseEnumType( const char *scope, bool isTemplate, bool typeDef, idParser &src ) {
- int value;
- idToken token;
- idEnumTypeInfo *typeInfo;
- idEnumValueInfo enumValue;
- idStr valueString;
- typeInfo = new idEnumTypeInfo;
- typeInfo->scope = scope;
- typeInfo->isTemplate = isTemplate;
- if ( src.CheckTokenType( TT_NAME, 0, &token ) ) {
- typeInfo->typeName = token;
- typeInfo->unnamed = false;
- } else {
- sprintf( typeInfo->typeName, "enum_%d", enums.Num() );
- typeInfo->unnamed = true;
- }
- if ( !src.CheckTokenString( "{" ) ) {
- src.UnreadToken( &token );
- delete typeInfo;
- return NULL;
- }
- value = -1;
- while( src.ExpectTokenType( TT_NAME, 0, &token ) ) {
- enumValue.name = token;
- if ( src.CheckTokenString( "=" ) ) {
- idStr valueString;
- ParseConstantValue( scope, src, valueString );
- if ( valueString.Length() ) {
- value = EvaluateIntegerString( valueString );
- }
- } else {
- value++;
- }
- enumValue.value = value;
- typeInfo->values.Append( enumValue );
- // add a constant for the enum value
- idConstantInfo *constantInfo = new idConstantInfo;
- constantInfo->name = scope + enumValue.name;
- constantInfo->type = "int";
- constantInfo->value = va( "%d", value );
- constants.Append( constantInfo );
- src.CheckTokenString( "," );
- if ( src.CheckTokenString( "}" ) ) {
- break;
- }
- }
- if ( typeDef ) {
- if ( src.CheckTokenType( TT_NAME, 0, &token ) ) {
- typeInfo->typeName = token;
- typeInfo->unnamed = false;
- }
- src.ExpectTokenString( ";" );
- }
- //common->Printf( "enum %s%s\n", typeInfo->scope.c_str(), typeInfo->typeName.c_str() );
- return typeInfo;
- }
- /*
- ================
- idTypeInfoGen::ParseClassType
- ================
- */
- idClassTypeInfo *idTypeInfoGen::ParseClassType( const char *scope, const char *templateArgs, bool isTemplate, bool typeDef, idParser &src ) {
- idToken token;
- idClassTypeInfo *typeInfo;
- typeInfo = new idClassTypeInfo;
- typeInfo->scope = scope;
- typeInfo->isTemplate = isTemplate;
- if ( src.CheckTokenType( TT_NAME, 0, &token ) ) {
- typeInfo->typeName = token + templateArgs;
- typeInfo->unnamed = false;
- } else {
- sprintf( typeInfo->typeName, "class_%d%s", classes.Num(), templateArgs );
- typeInfo->unnamed = true;
- }
- if ( src.CheckTokenString( ":" ) ) {
- if ( !src.ExpectTokenType( TT_NAME, 0, &token ) ) {
- delete typeInfo;
- return NULL;
- }
- while( token == "public" ||
- token == "protected" ||
- token == "private" ) {
- if ( !src.ExpectTokenType( TT_NAME, 0, &token ) ) {
- delete typeInfo;
- return NULL;
- }
- typeInfo->superType = token;
- // read template arguments
- if ( src.CheckTokenString( "<" ) ) {
- int indent = 1;
- typeInfo->superType += "< ";
- while( src.ReadToken( &token ) ) {
- if ( token == "<" ) {
- indent++;
- } else if ( token == ">" ) {
- indent--;
- if ( indent == 0 ) {
- break;
- }
- }
- typeInfo->superType += token + " ";
- }
- typeInfo->superType += ">";
- }
- // check for multiple inheritance
- if ( !src.CheckTokenString( "," ) ) {
- break;
- }
- if ( !src.ExpectTokenType( TT_NAME, 0, &token ) ) {
- delete typeInfo;
- return NULL;
- }
- src.Warning( "multiple inheritance not supported for '%s%s'", typeInfo->scope.c_str(), typeInfo->typeName.c_str() );
- }
- }
- if ( !src.CheckTokenString( "{" ) ) {
- src.UnreadToken( &token );
- delete typeInfo;
- return NULL;
- }
- ParseScope( typeInfo->scope + typeInfo->typeName + "::", typeInfo->isTemplate, src, typeInfo );
- if ( typeDef ) {
- if ( src.CheckTokenType( TT_NAME, 0, &token ) ) {
- typeInfo->typeName = token + templateArgs;
- typeInfo->unnamed = false;
- }
- src.ExpectTokenString( ";" );
- }
- //common->Printf( "class %s%s : %s\n", typeInfo->scope.c_str(), typeInfo->typeName.c_str(), typeInfo->superType.c_str() );
- return typeInfo;
- }
- /*
- ================
- idTypeInfoGen::ParseScope
- ================
- */
- void idTypeInfoGen::ParseScope( const char *scope, bool isTemplate, idParser &src, idClassTypeInfo *typeInfo ) {
- int indent;
- idToken token;
- idClassTypeInfo *classInfo;
- idEnumTypeInfo *enumInfo;
- idStr varType;
- bool isConst = false;
- bool isStatic = false;
- indent = 1;
- while( indent ) {
- if ( !src.ReadToken( &token ) ) {
- break;
- }
- if ( token == "{" ) {
- do {
- if ( token == "{" ) {
- indent++;
- } else if ( token == "}" ) {
- indent--;
- }
- varType += token + " ";
- } while( indent > 1 && src.ReadToken( &token ) );
- } else if ( token == "}" ) {
- assert( indent == 1 );
- indent--;
- } else if ( token == "<" ) {
- do {
- if ( token == "<" ) {
- indent++;
- } else if ( token == ">" ) {
- indent--;
- }
- varType += token + " ";
- } while( indent > 1 && src.ReadToken( &token ) );
- } else if ( token == ";" ) {
- varType = "";
- isConst = false;
- isStatic = false;
- } else if ( token == "public" || token == "protected" || token == "private" ) {
- if ( !src.ExpectTokenString( ":" ) ) {
- break;
- }
- varType = "";
- isConst = false;
- isStatic = false;
- } else if ( token == "friend" ) {
- // skip friend classes/methods
- while( src.ReadToken( &token ) ) {
- if ( token == "{" ) {
- indent++;
- } else if ( token == "}" ) {
- indent--;
- if ( indent == 1 ) {
- break;
- }
- } else if ( token == ";" && indent == 1 ) {
- break;
- }
- }
- varType = "";
- isConst = false;
- isStatic = false;
- } else if ( token == "template" ) {
- varType = "";
- if ( src.CheckTokenString( "<" ) ) {
- int indent = 1;
- varType += "< ";
- while( src.ReadToken( &token ) ) {
- if ( token == "<" ) {
- indent++;
- } else if ( token == ">" ) {
- indent--;
- if ( indent == 0 ) {
- break;
- }
- }
- varType += token + " ";
- }
- varType += ">";
- }
- if ( src.CheckTokenString( "class" ) ) {
- // parse template class
- classInfo = ParseClassType( scope, varType, true, false, src );
- if ( classInfo ) {
- classes.Append( classInfo );
- }
- } else {
- // skip template methods
- while( src.ReadToken( &token ) ) {
- if ( token == "{" ) {
- indent++;
- } else if ( token == "}" ) {
- indent--;
- if ( indent == 1 ) {
- break;
- }
- } else if ( token == ";" && indent == 1 ) {
- break;
- }
- }
- }
- varType = "";
- isConst = false;
- isStatic = false;
- } else if ( token == "namespace" ) {
- // parse namespace
- classInfo = ParseClassType( scope, "", isTemplate, false, src );
- delete classInfo;
- } else if ( token == "class" ) {
- // parse class
- classInfo = ParseClassType( scope, "", isTemplate, false, src );
- if ( classInfo ) {
- classes.Append( classInfo );
- }
- } else if ( token == "struct" ) {
- // parse struct
- classInfo = ParseClassType( scope, "", isTemplate, false, src );
- if ( classInfo ) {
- classes.Append( classInfo );
- varType = classInfo->scope + classInfo->typeName;
- }
- } else if ( token == "union" ) {
- // parse union
- classInfo = ParseClassType( scope, "", isTemplate, false, src );
- if ( classInfo ) {
- classes.Append( classInfo );
- }
- } else if ( token == "enum" ) {
- // parse enum
- enumInfo = ParseEnumType( scope, isTemplate, false, src );
- if ( enumInfo ) {
- enums.Append( enumInfo );
- varType = enumInfo->scope + enumInfo->typeName;
- }
- } else if ( token == "typedef" ) {
- if ( token == "class" ) {
- // parse typedef class
- classInfo = ParseClassType( scope, "", isTemplate, true, src );
- if ( classInfo ) {
- classes.Append( classInfo );
- }
- } else if ( src.CheckTokenString( "struct" ) ) {
- // parse typedef struct
- classInfo = ParseClassType( scope, "", isTemplate, true, src );
- if ( classInfo ) {
- classes.Append( classInfo );
- }
- } else if ( src.CheckTokenString( "union" ) ) {
- // parse typedef union
- classInfo = ParseClassType( scope, "", isTemplate, true, src );
- if ( classInfo ) {
- classes.Append( classInfo );
- }
- } else if ( src.CheckTokenString( "enum" ) ) {
- // parse typedef enum
- enumInfo = ParseEnumType( scope, isTemplate, true, src );
- if ( enumInfo ) {
- enums.Append( enumInfo );
- }
- } else {
- // skip other typedefs
- while( src.ReadToken( &token ) ) {
- if ( token == "{" ) {
- indent++;
- } else if ( token == "}" ) {
- indent--;
- } else if ( token == ";" && indent == 1 ) {
- break;
- }
- }
- }
- varType = "";
- isConst = false;
- isStatic = false;
- } else if ( token == "const" ) {
- varType += token + " ";
- isConst = true;
- } else if ( token == "static" ) {
- varType += token + " ";
- isStatic = true;
- } else if ( token.type == TT_NAME ) {
-
- assert( indent == 1 );
- // if this is a class operator
- if ( token == "operator" ) {
- while( src.ReadToken( &token ) ) {
- if ( token == "(" ) {
- src.UnreadToken( &token );
- break;
- }
- }
- }
- // if this is a class method
- if ( src.CheckTokenString( "(" ) ) {
- indent++;
- while( indent > 1 && src.ReadToken( &token ) ) {
- if ( token == "(" ) {
- indent++;
- } else if ( token == ")" ) {
- indent--;
- }
- }
- if ( src.CheckTokenString( "(" ) ) {
- indent++;
- while( indent > 1 && src.ReadToken( &token ) ) {
- if ( token == "(" ) {
- indent++;
- } else if ( token == ")" ) {
- indent--;
- }
- }
- }
- if ( src.CheckTokenString( "const" ) ) {
- }
- if ( src.CheckTokenString( "=" ) ) {
- src.ExpectTokenString( "0" );
- } else if ( src.CheckTokenString( "{" ) ) {
- indent++;
- while( indent > 1 && src.ReadToken( &token ) ) {
- if ( token == "{" ) {
- indent++;
- } else if ( token == "}" ) {
- indent--;
- }
- }
- }
- varType = "";
- isConst = false;
- isStatic = false;
- } else if ( ( isStatic || isConst ) && src.CheckTokenString( "=" ) ) {
- // constant
- idConstantInfo *constantInfo = new idConstantInfo;
- constantInfo->name = scope + token;
- constantInfo->type = varType;
- constantInfo->type.StripTrailing( ' ' );
- ParseConstantValue( scope, src, constantInfo->value );
- constants.Append( constantInfo );
- } else if ( isStatic ) {
- // static class variable
- varType += token + " ";
- } else {
- // check for class variables
- while( 1 ) {
- int arraySize = ParseArraySize( scope, src );
- if ( arraySize ) {
- idClassVariableInfo var;
- var.name = token;
- var.type = varType;
- var.type.StripTrailing( ' ' );
- var.type += va( "[%d]", arraySize );
- var.bits = 0;
- typeInfo->variables.Append( var );
- if ( !src.CheckTokenString( "," ) ) {
- varType = "";
- isConst = false;
- isStatic = false;
- break;
- }
- varType.StripTrailing( "* " );
- } else {
- int bits = 0;
- if ( src.CheckTokenString( ":" ) ) {
- idToken bitSize;
- src.ExpectTokenType( TT_NUMBER, TT_INTEGER, &bitSize );
- bits = bitSize.GetIntValue();
- }
- if ( src.CheckTokenString( "," ) ) {
- idClassVariableInfo var;
- var.name = token;
- var.type = varType;
- var.type.StripTrailing( ' ' );
- var.bits = bits;
- typeInfo->variables.Append( var );
- varType.StripTrailing( "* " );
- } else if ( src.CheckTokenString( ";" ) ) {
- idClassVariableInfo var;
- var.name = token;
- var.type = varType;
- var.type.StripTrailing( ' ' );
- var.bits = bits;
- typeInfo->variables.Append( var );
- varType = "";
- isConst = false;
- isStatic = false;
- break;
- } else {
- varType += token + " ";
- break;
- }
- }
- while( src.CheckTokenString( "*" ) ) {
- varType += "* ";
- }
- if ( !src.ExpectTokenType( TT_NAME, 0, &token ) ) {
- break;
- }
- }
- }
- } else {
- varType += token + " ";
- }
- }
- }
- /*
- ================
- idTypeInfoGen::AddDefine
- ================
- */
- void idTypeInfoGen::AddDefine( const char *define ) {
- defines.Append( define );
- }
- /*
- ================
- idTypeInfoGen::CreateTypeInfo
- ================
- */
- void idTypeInfoGen::CreateTypeInfo( const char *path ) {
- int i, j, inheritance;
- idStr fileName;
- idFileList *files;
- idParser src;
- common->Printf( "Type Info Generator v"TYPE_INFO_GEN_VERSION" (c) 2004 id Software\n" );
- common->Printf( "%s\n", path );
- files = fileSystem->ListFilesTree( path, ".cpp" );
- for ( i = 0; i < files->GetNumFiles(); i++ ) {
- fileName = fileSystem->RelativePathToOSPath( files->GetFile( i ) );
- common->Printf( "processing '%s' for type info...\n", fileName.c_str() );
- if ( !src.LoadFile( fileName, true ) ) {
- common->Warning( "couldn't load %s", fileName.c_str() );
- continue;
- }
- src.SetFlags( LEXFL_NOBASEINCLUDES );
- for ( j = 0; j < defines.Num(); j++ ) {
- src.AddDefine( defines[j] );
- }
- idClassTypeInfo *typeInfo = new idClassTypeInfo;
- ParseScope( "", false, src, typeInfo );
- delete typeInfo;
- src.FreeSource();
- break;
- }
- fileSystem->FreeFileList( files );
- numTemplates = 0;
- for ( i = 0; i < classes.Num(); i++ ) {
- if ( classes[i]->isTemplate ) {
- numTemplates++;
- }
- }
- maxInheritance = 0;
- maxInheritanceClass = "";
- for ( i = 0; i < classes.Num(); i++ ) {
- inheritance = GetInheritance( classes[i]->typeName );
- if ( inheritance > maxInheritance ) {
- maxInheritance = inheritance;
- maxInheritanceClass = classes[i]->typeName;
- }
- }
- common->Printf( "%d constants\n", constants.Num() );
- common->Printf( "%d enums\n", enums.Num() );
- common->Printf( "%d classes/structs/unions\n", classes.Num() );
- common->Printf( "%d templates\n", numTemplates );
- common->Printf( "%d max inheritance level for '%s'\n", maxInheritance, maxInheritanceClass.c_str() );
- }
- /*
- ================
- CleanName
- ================
- */
- void CleanName( idStr &name ) {
- name.Replace( "::", "_" );
- name.Replace( " , ", "_" );
- name.Replace( "< ", "_" );
- name.Replace( " >", "_" );
- name.Replace( " ", "_" );
- }
- /*
- ================
- idTypeInfoGen::WriteTypeInfo
- ================
- */
- void idTypeInfoGen::WriteTypeInfo( const char *fileName ) const {
- int i, j;
- idStr path, define;
- idFile *file;
- path = fileSystem->RelativePathToOSPath( fileName );
- file = fileSystem->OpenExplicitFileWrite( path );
- if ( !file ) {
- common->Warning( "couldn't open %s", path.c_str() );
- return;
- }
- common->Printf( "writing %s...\n", path.c_str() );
- path.ExtractFileName( define );
- define.Replace( ".", "_" );
- define.ToUpper();
- file->WriteFloatString(
- "\n"
- "#ifndef __%s__\n"
- "#define __%s__\n"
- "\n"
- "/*\n"
- "===================================================================================\n"
- "\n"
- "\tThis file has been generated with the Type Info Generator v"TYPE_INFO_GEN_VERSION" (c) 2004 id Software\n"
- "\n"
- "\t%d constants\n"
- "\t%d enums\n"
- "\t%d classes/structs/unions\n"
- "\t%d templates\n"
- "\t%d max inheritance level for '%s'\n"
- "\n"
- "===================================================================================\n"
- "*/\n"
- "\n", define.c_str(), define.c_str(), constants.Num(), enums.Num(), classes.Num(),
- numTemplates, maxInheritance, maxInheritanceClass.c_str() );
- file->WriteFloatString(
- "typedef struct {\n"
- "\t" "const char * name;\n"
- "\t" "const char * type;\n"
- "\t" "const char * value;\n"
- "} constantInfo_t;\n"
- "\n"
- "typedef struct {\n"
- "\t" "const char * name;\n"
- "\t" "int value;\n"
- "} enumValueInfo_t;\n"
- "\n"
- "typedef struct {\n"
- "\t" "const char * typeName;\n"
- "\t" "const enumValueInfo_t * values;\n"
- "} enumTypeInfo_t;\n"
- "\n"
- "typedef struct {\n"
- "\t" "const char * type;\n"
- "\t" "const char * name;\n"
- "\t" "int offset;\n"
- "\t" "int size;\n"
- "} classVariableInfo_t;\n"
- "\n"
- "typedef struct {\n"
- "\t" "const char * typeName;\n"
- "\t" "const char * superType;\n"
- "\t" "int size;\n"
- "\t" "const classVariableInfo_t * variables;\n"
- "} classTypeInfo_t;\n"
- "\n" );
- // constants
- file->WriteFloatString( "static constantInfo_t constantInfo[] = {\n" );
- for ( i = 0; i < constants.Num(); i++ ) {
- idConstantInfo *info = constants[i];
- file->WriteFloatString( "\t{ \"%s\", \"%s\", \"%s\" },\n", info->type.c_str(), info->name.c_str(), info->value.c_str() );
- }
- file->WriteFloatString( "\t{ NULL, NULL, NULL }\n" );
- file->WriteFloatString( "};\n\n" );
- // enum values
- for ( i = 0; i < enums.Num(); i++ ) {
- idEnumTypeInfo *info = enums[i];
- idStr typeInfoName = info->scope + info->typeName;
- CleanName( typeInfoName );
- file->WriteFloatString( "static enumValueInfo_t %s_typeInfo[] = {\n", typeInfoName.c_str() );
- for ( j = 0; j < info->values.Num(); j++ ) {
- if ( info->isTemplate ) {
- file->WriteFloatString( "//" );
- }
- file->WriteFloatString( "\t{ \"%s\", %d },\n", info->values[j].name.c_str(), info->values[j].value );
- }
- file->WriteFloatString( "\t{ NULL, 0 }\n" );
- file->WriteFloatString( "};\n\n" );
- }
- // enums
- file->WriteFloatString( "static enumTypeInfo_t enumTypeInfo[] = {\n" );
- for ( i = 0; i < enums.Num(); i++ ) {
- idEnumTypeInfo *info = enums[i];
- idStr typeName = info->scope + info->typeName;
- idStr typeInfoName = typeName;
- CleanName( typeInfoName );
- if ( info->isTemplate ) {
- file->WriteFloatString( "//" );
- }
- file->WriteFloatString( "\t{ \"%s\", %s_typeInfo },\n", typeName.c_str(), typeInfoName.c_str() );
- }
- file->WriteFloatString( "\t{ NULL, NULL }\n" );
- file->WriteFloatString( "};\n\n" );
- // class variables
- for ( i = 0; i < classes.Num(); i++ ) {
- idClassTypeInfo *info = classes[i];
- idStr typeName = info->scope + info->typeName;
- idStr typeInfoName = typeName;
- CleanName( typeInfoName );
- file->WriteFloatString( "static classVariableInfo_t %s_typeInfo[] = {\n", typeInfoName.c_str() );
- for ( j = 0; j < info->variables.Num(); j++ ) {
- const char *varName = info->variables[j].name.c_str();
- const char *varType = info->variables[j].type.c_str();
- if ( info->unnamed || info->isTemplate || info->variables[j].bits != 0 ) {
- file->WriteFloatString( "//" );
- }
- file->WriteFloatString( "\t{ \"%s\", \"%s\", (int)(&((%s *)0)->%s), sizeof( ((%s *)0)->%s ) },\n",
- varType, varName, typeName.c_str(), varName, typeName.c_str(), varName );
- }
- file->WriteFloatString( "\t{ NULL, 0 }\n" );
- file->WriteFloatString( "};\n\n" );
- }
- // classes
- file->WriteFloatString( "static classTypeInfo_t classTypeInfo[] = {\n" );
- for ( i = 0; i < classes.Num(); i++ ) {
- idClassTypeInfo *info = classes[i];
- idStr typeName = info->scope + info->typeName;
- idStr typeInfoName = typeName;
- CleanName( typeInfoName );
- if ( info->unnamed || info->isTemplate ) {
- file->WriteFloatString( "//" );
- }
- file->WriteFloatString( "\t{ \"%s\", \"%s\", sizeof(%s), %s_typeInfo },\n",
- typeName.c_str(), info->superType.c_str(), typeName.c_str(), typeInfoName.c_str() );
- }
- file->WriteFloatString( "\t{ NULL, NULL, 0, NULL }\n" );
- file->WriteFloatString( "};\n\n" );
- file->WriteFloatString( "#endif /* !__%s__ */\n", define.c_str() );
- fileSystem->CloseFile( file );
- }
|