1 20 21 package org.jacorb.idl; 22 23 27 28 import java.io.PrintWriter ; 29 import java.util.*; 30 31 public class TypeDef 32 extends TypeDeclaration 33 { 34 public TypeDeclarator type_declarator; 35 private Vector typeSpecs = new Vector(); 36 37 public TypeDef( int num ) 38 { 39 super( num ); 40 pack_name = ""; 41 } 42 43 public Vector getTypeSpecs() 44 { 45 return typeSpecs; 46 } 47 48 public void setPackage( String s ) 49 { 50 s = parser.pack_replace( s ); 51 if( pack_name.length() > 0 ) 52 pack_name = s + "." + pack_name; 53 else 54 pack_name = s; 55 type_declarator.setPackage( s ); 56 } 57 58 public void set_included( boolean i ) 59 { 60 included = i; 61 } 62 63 public String id() 64 { 65 return type_declarator.id(); 66 } 67 68 public void setEnclosingSymbol( IdlSymbol s ) 69 { 70 if( enclosing_symbol != null && enclosing_symbol != s ) 71 { 72 if( logger.isErrorEnabled()) 73 { 74 logger.error( "Typedef.setEnclosingSymbol: was " + 75 enclosing_symbol.getClass().getName() + 76 " now: " + s.getClass().getName() ); 77 } 78 79 throw new RuntimeException ( "Compiler Error: trying to reassign container for " + 80 name ); 81 } 82 enclosing_symbol = s; 83 type_declarator.setEnclosingSymbol( s ); 84 } 85 86 public void parse() 87 { 88 for( Enumeration e = type_declarator.declarators.v.elements(); 89 e.hasMoreElements(); ) 90 { 91 Declarator d = (Declarator)e.nextElement(); 92 d.escapeName(); 93 94 try 95 { 96 AliasTypeSpec alias = 97 new AliasTypeSpec( (TypeSpec)type_declarator.type_spec() ); 98 99 100 101 if( d.d instanceof ArrayDeclarator ) 102 { 103 108 alias = 109 new AliasTypeSpec( 110 new ArrayTypeSpec( new_num(), alias.originalType(), 111 (ArrayDeclarator)d.d, pack_name ) 112 ); 113 alias.parse(); 114 } 115 else 116 { 117 if( !( e.hasMoreElements() ) ) 118 alias.parse(); 119 } 120 alias.set_name( d.name() ); 121 alias.setPackage( pack_name ); 122 alias.setEnclosingSymbol( enclosing_symbol ); 123 alias.set_token( d.d.get_token() ); 124 alias.set_included( included ); 125 126 typeSpecs.addElement( alias ); 127 NameTable.define( d.full_name(), "type" ); 128 TypeMap.typedef( d.full_name(), alias ); 129 } 130 catch( NameAlreadyDefined n ) 131 { 132 parser.error( "TypeDef'd name " + d.name() + 133 " already defined. ", d.token ); 134 } 135 } 136 } 137 138 public void print( PrintWriter ps ) 139 { 140 if( included && !generateIncluded() ) 141 return; 142 143 for( Enumeration e = typeSpecs.elements(); 144 e.hasMoreElements(); ) 145 { 146 ( (AliasTypeSpec)e.nextElement() ).print( ps ); 147 } 148 149 } 150 151 153 154 public void accept( IDLTreeVisitor visitor ) 155 { 156 for( Enumeration e = typeSpecs.elements(); 157 e.hasMoreElements(); ) 158 { 159 ( (AliasTypeSpec)e.nextElement() ).accept( visitor ); 160 } 161 visitor.visitTypeDef( this ); 162 } 163 164 165 166 } 167 168 169 | Popular Tags |