public void flattenSymbolTable ( boolean flattenAllTables ) { if ( ! flattenAllTables ) { List < Symbol > newSymbols = new ArrayList < Symbol > ( ) ; if ( this . symbolTable != null ) { // Just replace "symbols" with the symbols in this object's // symbol table. Can't just work from symbolTable map since // we need to retain duplicate parameters. for ( int i = 0 ; i < symbols . size ( ) ; i ++ ) { Symbol symbol = symbols . get ( i ) ; if ( symbol . getContainingTable ( ) == this ) { newSymbols . add ( symbol ) ; } } } symbols = newSymbols ; } variableNames = new String [ symbols . size ( ) ] ; isConsts = new boolean [ symbols . size ( ) ] ; for ( int i = 0 ; i < symbols . size ( ) ; i ++ ) { Symbol symbol = symbols . get ( i ) ; variableNames [ i ] = symbol . getName ( ) ; isConsts [ i ] = symbol . getDeclType ( ) == Token . CONST ; symbol . setIndex ( i ) ; } }
Assign every symbol a unique integer index . Generate arrays of variable names and constness that can be indexed by those indices .