1 package org.jacorb.idl; 2 3 22 23 import java.util.*; 24 25 class SwitchBody 26 extends IdlSymbol 27 { 28 29 30 Vector caseListVector = new Vector(); 31 32 TypeSpec ts = null; 33 UnionType myUnion = null; 34 35 public SwitchBody( int num ) 36 { 37 super( num ); 38 } 39 40 public void setTypeSpec( TypeSpec s ) 41 { 42 ts = s; 43 for( Enumeration e = caseListVector.elements(); e.hasMoreElements(); ) 44 { 45 Case c = (Case)e.nextElement(); 46 c.setPackage( pack_name ); 47 c.setTypeSpec( s ); 48 } 49 } 50 51 55 56 public void setUnion( UnionType ut ) 57 { 58 myUnion = ut; 59 for( Enumeration e = caseListVector.elements(); e.hasMoreElements(); ) 60 { 61 Case c = (Case)e.nextElement(); 62 c.setUnion( ut ); 63 } 64 } 65 66 public void setEnclosingSymbol( IdlSymbol s ) 67 { 68 if( enclosing_symbol != null && enclosing_symbol != s ) 69 throw new RuntimeException ( "Compiler Error: trying to reassign container for " + name ); 70 enclosing_symbol = s; 71 for( Enumeration e = caseListVector.elements(); e.hasMoreElements(); ) 72 ( (IdlSymbol)e.nextElement() ).setEnclosingSymbol( s ); 73 } 74 75 public void setPackage( String s ) 76 { 77 s = parser.pack_replace( s ); 78 if( pack_name.length() > 0 ) 79 pack_name = s + "." + pack_name; 80 else 81 pack_name = s; 82 83 if( ts != null ) 84 ts.setPackage( s ); 85 } 86 87 90 91 public void parse() 92 { 93 Hashtable usedLabelNames = new Hashtable(); 94 95 for( Enumeration e = caseListVector.elements(); e.hasMoreElements(); ) 96 { 97 Case theCase = (Case)e.nextElement(); 98 theCase.parse(); 99 100 102 IdlSymbol[] labels = theCase.getLabels(); 103 104 for( int i = 0; i < labels.length; i++ ) 105 { 106 if( labels[ i ] != null ) { 108 IdlSymbol sym = 109 (IdlSymbol)usedLabelNames.get( labels[ i ].toString() ); 110 111 if( sym != null ) 112 { 113 parser.error( "Duplicate case label <" + 114 sym.toString() + ">", sym.get_token() ); 115 } 116 117 usedLabelNames.put( labels[ i ].toString(), labels[ i ] ); 118 } 119 } 120 } 121 usedLabelNames.clear(); 122 123 ts.parse(); 124 myUnion.addImportedName( ts.typeName() ); 125 126 } 127 128 public void print( java.io.PrintWriter ps ) 129 { 130 for( Enumeration e = caseListVector.elements(); e.hasMoreElements(); ) 131 { 132 Case c = (Case)e.nextElement(); 133 c.print( ps ); 134 } 135 } 136 137 } 138 139 140 141 142 143 144 | Popular Tags |