/* ================ 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::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::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 + " "; } } }
/* ================ sdDeclToolTip::ParseTimeline ================ */ bool sdDeclToolTip::ParseTimeline( idParser& src ) { idToken token; src.SkipUntilString( "{", &token ); while ( true ) { if( !src.ReadToken( &token ) ) { return false; } if ( !token.Icmp( "onTime" ) ) { src.ReadToken( &token ); int time; if ( token.type == TT_NUMBER ) { time = ( token.GetIntValue() / 100.0f ) * GetLength(); } else if ( token.type == TT_NAME && !token.Icmp( "end" ) ) { time = TLTIME_END; } else { src.Error( "sdDeclToolTip::ParseTimeline number expected for 'onTime'" ); return false; } timelinePair_t event; event.first = time; if ( timeline.Num() > 0 ) { timelinePair_t lastEvent = timeline.Back(); if ( lastEvent.first > time && time != TLTIME_END ) { src.Error( "sdDeclToolTip::ParseTimeline time events must be in increasing order: '%i'", time ); return false; } } src.ReadToken( &token ); if ( !token.Icmp( "guiEvent" ) ) { event.second.eventType = TL_GUIEVENT; if( !src.ExpectTokenType( TT_STRING, 0, &token ) ) { src.Error( "sdDeclToolTip::ParseTimeline string expected after 'guiEvent'" ); return false; } event.second.arg1 = token; } else if ( !token.Icmp( "pause" ) ) { event.second.eventType = TL_PAUSE; } else if ( !token.Icmp( "unpause" ) ) { event.second.eventType = TL_UNPAUSE; } else if ( !token.Icmp( "showInventory" ) ) { event.second.eventType = TL_SHOWINVENTORY; if( !src.ExpectTokenType( TT_STRING, 0, &token ) ) { src.Error( "sdDeclToolTip::ParseTimeline string expected after 'guiEvent'" ); return false; } event.second.arg1 = token; } else if ( !token.Icmp( "hideInventory" ) ) { event.second.eventType = TL_HIDEINVENTORY; } else if ( !token.Icmp( "waypointHighlight" ) ) { event.second.eventType = TL_WAYPOINTHIGHLIGHT; if( !src.ExpectTokenType( TT_STRING, 0, &token ) ) { src.Error( "sdDeclToolTip::ParseTimeline string expected after 'guiEvent'" ); return false; } event.second.arg1 = token; } else if ( !token.Icmp( "lookAtTask" ) ) { event.second.eventType = TL_LOOKATTASK; } else { src.Error( "sdDeclToolTip::ParseTimeline unexpected timeline event '%s'", token.c_str() ); return false; } timeline.Append( event ); } else if ( !token.Icmp( "unpauseWeaponSlot" ) ) { if( !src.ExpectTokenType( TT_NUMBER, 0, &token ) ) { src.Error( "sdDeclToolTip::ParseTimeline number expected after 'unpauseWeaponSlot'" ); return false; } unpauseWeaponSlot = token.GetIntValue(); if ( unpauseWeaponSlot > 9 || unpauseWeaponSlot < 0 ) { src.Warning( "sdDeclToolTip::ParseTimeline 0-9 expected as value for 'unpauseWeaponSlot'" ); unpauseWeaponSlot = -1; } unpauseKeyString.SetKey( va( "_weapon%i", unpauseWeaponSlot - 1 ) ); } else if( !token.Cmp( "}" ) ) { break; } else { src.Error( "sdDeclToolTip::ParseTimeline Invalid Token '%s'", token.c_str() ); return false; } } return true; }