1 20 21 package org.jacorb.idl; 22 23 28 29 import java.io.PrintWriter ; 30 import java.util.*; 31 32 public class Member 33 extends Declaration 34 { 35 public TypeSpec type_spec; 36 37 42 SymbolList declarators; 43 44 public Vector extendVector; 45 public TypeDeclaration containingType; 46 47 public Declarator declarator; 48 49 public Member( int num ) 50 { 51 super( num ); 52 } 53 54 public void setPackage( String s ) 55 { 56 s = parser.pack_replace( s ); 57 if( pack_name.length() > 0 ) 58 pack_name = s + "." + pack_name; 59 else 60 pack_name = s; 61 62 type_spec.setPackage( s ); 63 if ( declarators != null ) 64 declarators.setPackage( s ); 65 } 66 67 public void setEnclosingSymbol( IdlSymbol s ) 68 { 69 enclosing_symbol = s; 70 type_spec.setEnclosingSymbol( s ); 71 for( Enumeration e = declarators.v.elements(); e.hasMoreElements(); ) 72 ( (Declarator)e.nextElement() ).setEnclosingSymbol( s ); 73 } 74 75 76 public void setContainingType( TypeDeclaration t ) 77 { 78 containingType = t; 79 } 80 81 84 public void setExtendVector( Vector v ) 85 { 86 extendVector = v; 87 } 88 89 93 public Member extractMember( Declarator d ) 94 { 95 Member result = new Member( new_num() ); 96 result.declarator = d; 97 return result; 98 } 99 100 104 public void parse() 105 { 106 boolean clone_and_parse = true; 107 108 if( extendVector == null ) 109 throw new ParseException("Internal Compiler Error: extendVector not set!", this.myPosition ); 110 111 if( type_spec.typeSpec() instanceof ScopedName ) 112 { 113 token = type_spec.typeSpec().get_token(); 114 String name = type_spec.typeSpec().toString(); 115 116 type_spec = ( (ScopedName)type_spec.typeSpec() ).resolvedTypeSpec(); 117 enclosing_symbol.addImportedName( name, type_spec ); 118 119 if( type_spec instanceof AliasTypeSpec ) 120 { 121 AliasTypeSpec aliasTS = (AliasTypeSpec)type_spec; 122 TypeSpec originalType = aliasTS.originalType (); 123 if( originalType instanceof SequenceType ) 124 { 125 SequenceType sequenceTS = (SequenceType)originalType; 126 if( sequenceTS.elementTypeSpec().typeName().equals( containingType.typeName()) ) 127 sequenceTS.setRecursive (); 128 } 129 } 130 131 clone_and_parse = false; 132 if( type_spec instanceof ConstrTypeSpec ) 133 { 134 if( ( (ConstrTypeSpec)type_spec.typeSpec() ).c_type_spec instanceof StructType ) 135 { 136 if( 137 ( (ConstrTypeSpec)type_spec.typeSpec() ).c_type_spec.typeName().equals( containingType.typeName() ) 138 ) 139 { 140 parser.fatal_error( "Illegal type recursion (use sequence<" + 141 containingType.typeName() + "> instead)", token ); 142 } 143 } 144 } 145 } 146 else if( type_spec.typeSpec() instanceof SequenceType ) 147 { 148 TypeSpec ts = ( (SequenceType)type_spec.typeSpec() ).elementTypeSpec().typeSpec(); 149 SequenceType seqTs = (SequenceType)type_spec.typeSpec(); 150 while( ts instanceof SequenceType ) 151 { 152 seqTs = (SequenceType)ts; 153 ts = ( (SequenceType)ts.typeSpec() ).elementTypeSpec().typeSpec(); 154 } 155 156 if( ScopedName.isRecursionScope( ts.typeName() ) ) 157 { 158 seqTs.setRecursive(); 159 } 160 } 161 else if( type_spec instanceof ConstrTypeSpec ) 162 { 163 type_spec.parse(); 164 } 165 166 String tokName = null; 167 if( token != null && token.line_val != null ) 168 { 169 tokName = token.line_val.trim(); 170 if( tokName.length() == 0 ) 171 { 172 tokName = null; 173 } 174 } 175 176 for( Enumeration e = declarators.v.elements(); e.hasMoreElements(); ) 177 { 178 Declarator d = (Declarator)e.nextElement(); 179 String dName = d.name(); 180 181 if( tokName != null ) 182 { 183 184 if (org.jacorb.idl.parser.strict_names) 185 { 186 if( dName.equalsIgnoreCase( tokName ) ) 188 { 189 parser.fatal_error( "Declarator " + dName + 190 " already defined in scope.", token ); 191 } 192 } 193 else 194 { 195 if( dName.equals( tokName ) ) 197 { 198 parser.fatal_error( "Declarator " + dName + 199 " already defined in scope.", token ); 200 } 201 } 202 } 203 204 209 Member m = extractMember( d ); 210 211 TypeSpec ts = type_spec.typeSpec(); 212 213 218 219 if( clone_and_parse || d.d instanceof ArrayDeclarator ) 220 { 221 222 223 if( d.d instanceof ArrayDeclarator ) 224 { 225 ts = new ArrayTypeSpec( new_num(), ts, (ArrayDeclarator)d.d, pack_name ); 226 ts.parse(); 227 } 228 else if( !( ts instanceof BaseType ) ) 229 { 230 ts = (TypeSpec)ts.clone(); 231 if( !( ts instanceof ConstrTypeSpec ) ) 232 ts.set_name( d.name() ); 233 234 236 if( !e.hasMoreElements() ) 237 ts.parse(); 238 } 239 } 240 241 if( !( d.d instanceof ArrayDeclarator ) ) 243 { 244 try 245 { 246 NameTable.define( containingType + "." + d.name(), 247 "declarator" ); 248 } 249 catch( NameAlreadyDefined nad ) 250 { 251 parser.fatal_error( "Declarator " + d.name() + 252 " already defined in scope.", token ); 253 } 254 } 255 256 259 m.type_spec = ts; 260 m.pack_name = this.pack_name; 261 m.name = this.name; 262 extendVector.addElement( m ); 263 } 264 declarators = null; 265 } 266 267 270 271 public void print( PrintWriter ps ) 272 { 273 member_print( ps, "\tpublic " ); 274 } 275 276 279 280 public void member_print( PrintWriter ps, String prefix ) 281 { 282 283 284 if( ( type_spec.typeSpec() instanceof ConstrTypeSpec && 285 !( ( ( (ConstrTypeSpec)type_spec.typeSpec() ).c_type_spec.declaration() 286 instanceof Interface ) || 287 ( ( (ConstrTypeSpec)type_spec.typeSpec() ).c_type_spec.declaration() 288 instanceof Value ) ) ) || 289 type_spec.typeSpec() instanceof SequenceType || 290 type_spec.typeSpec() instanceof ArrayTypeSpec ) 291 { 292 type_spec.print( ps ); 293 } 294 295 296 if( type_spec.typeSpec() instanceof StringType ) 297 ps.print( prefix + type_spec.toString() + " " + declarator.toString() + " = \"\";" ); 298 else 299 ps.print( prefix + type_spec.toString() + " " + declarator.toString() + ";" ); 300 } 301 302 public TypeSpec typeSpec() 303 { 304 return type_spec.typeSpec(); 305 } 306 } 307 | Popular Tags |