Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
2.6 KiB

  1. # Assuming all functions begin with ')' followed by '{', just find the matching brace and
  2. # add a line with 'g_pVCR->SyncToken("<random string here>");'
  3. import dlexer
  4. import sys
  5. import WildcardSearch
  6. class BlankStruct:
  7. pass
  8. def MatchParensBack( list, iStart ):
  9. parenCount = -1
  10. for i in range( 0, iStart ):
  11. if list[iStart-i].id == __TOKEN_OPENPAREN:
  12. parenCount += 1
  13. elif list[iStart-i].id == __TOKEN_CLOSEPAREN:
  14. parenCount -= 1
  15. if parenCount == 0:
  16. return iStart - i
  17. return -1
  18. # Setup the parser.
  19. parser = dlexer.DLexer( 0 )
  20. __TOKEN_NEWLINE = parser.AddToken( '\n' )
  21. __TOKEN_WHITESPACE = parser.AddToken( '[ \\t\\f\\v]+' )
  22. __TOKEN_OPENBRACE = parser.AddToken( '{' )
  23. __TOKEN_CLOSEBRACE = parser.AddToken( '}' )
  24. __TOKEN_OPENPAREN = parser.AddToken( '\(' )
  25. __TOKEN_CLOSEPAREN = parser.AddToken( '\)' )
  26. __TOKEN_COMMENT = parser.AddToken( r"\/\/.*" )
  27. __TOKEN_CONST = parser.AddToken( "const" )
  28. __TOKEN_IF = parser.AddToken( "if" )
  29. __TOKEN_WHILE = parser.AddToken( "while" )
  30. __TOKEN_FOR = parser.AddToken( "for" )
  31. __TOKEN_SWITCH = parser.AddToken( "switch" )
  32. __TOKEN_CLASS = parser.AddToken( "class" )
  33. __TOKEN_PUBLIC = parser.AddToken( "public" )
  34. __TOKEN_TYPEDEF = parser.AddToken( "typedef" )
  35. __TOKEN_BASECLASS = parser.AddToken( "BaseClass" )
  36. validChars = r"\~\@\#\$\%\^\&\!\w\.-/\[\]\<\>\""
  37. __TOKEN_IDENT = parser.AddToken( '[' + validChars + ']+' )
  38. __TOKEN_OPERATOR = parser.AddToken( "\=|\+" )
  39. __TOKEN_SCOPE_OPERATOR = parser.AddToken( "::" )
  40. __TOKEN_COLON = parser.AddToken( ":" )
  41. __TOKEN_IGNORE = parser.AddToken( r"\#|\;|\:|\||\?|\'|\\|\*|\-|\`|\," )
  42. for i in range( 1, len( sys.argv ) ):
  43. for filename in WildcardSearch.WildcardSearch( sys.argv[i] ):
  44. head = None
  45. # First, read all the tokens into a list.
  46. list = []
  47. parser.BeginReadFile( filename )
  48. while 1:
  49. m = parser.GetToken()
  50. if m:
  51. list.append( m )
  52. else:
  53. break
  54. # Make a list of all the non-whitespace ones.
  55. nw = []
  56. for token in list:
  57. if token.id == __TOKEN_NEWLINE or token.id == __TOKEN_WHITESPACE:
  58. token.iNonWhitespace = -2222
  59. else:
  60. token.iNonWhitespace = len( nw )
  61. nw.append( token )
  62. curLine = 1
  63. # Now, search for the patterns we're interested in.
  64. # Look for 'class <ident> : public <ident> {
  65. curClassName = ""
  66. curBaseClassName = ""
  67. for token in list:
  68. if token.id == __TOKEN_NEWLINE:
  69. curLine += 1
  70. elif token.id == __TOKEN_CLASS:
  71. i = token.iNonWhitespace
  72. if nw[i+1].id == __TOKEN_IDENT and nw[i+2].id == __TOKEN_COLON and nw[i+3].id == __TOKEN_PUBLIC and nw[i+4].id == __TOKEN_IDENT:
  73. curClassName = nw[i+1].val
  74. curBaseClassName = nw[i+4].val
  75. print "class %s : public %s" % (curClassName, curBaseClassName)