1 package org.jacorb.idl; 2 3 22 23 24 import java.io.PrintWriter ; 25 import java.util.*; 26 27 import org.apache.log.*; 28 29 35 36 public class IdlSymbol 37 extends org.jacorb.idl.runtime.symbol 38 { 39 private static int num = 10000; 40 public String pack_name = ""; 41 String name = ""; 42 43 protected boolean is_pseudo = false; protected boolean included = false; 45 protected boolean inhibitionFlag = false; 46 47 str_token token; 48 49 protected String _id; 50 private String _version; 51 52 protected IdlSymbol enclosing_symbol; 53 54 protected String omg_package_prefix = ""; 55 private Hashtable imports = new Hashtable(); 56 57 String typeName; 58 59 protected static final char fileSeparator = 60 System.getProperty( "file.separator" ).charAt( 0 ); 61 62 Logger logger; 63 64 66 PositionInfo myPosition = null; 67 68 71 72 public IdlSymbol( int num ) 73 { 74 super( num ); 75 inhibitionFlag = parser.getInhibitionState(); 76 logger = parser.getLogger(); 77 myPosition = lexer.getPosition(); 78 } 79 80 81 85 86 void set_included( boolean i ) 87 { 88 included = i; 89 } 90 91 92 96 97 public boolean is_included() 98 { 99 return included; 100 } 101 102 105 106 public void set_pseudo() 107 { 108 is_pseudo = true; 109 } 110 111 114 115 public boolean is_pseudo() 116 { 117 return is_pseudo; 118 } 119 120 public void set_token( str_token i ) 121 { 122 token = i; 123 if( token != null ) 124 { 125 if( token.pragma_prefix.equals( "omg.org" ) ) 126 { 127 omg_package_prefix = "org.omg."; 128 } 129 set_name( token.str_val ); 130 } 131 } 132 133 public str_token get_token() 134 { 135 return token; 136 } 137 138 139 142 143 public String name() 144 { 145 return name; 146 } 147 148 149 150 155 156 public void escapeName() 157 { 158 if( !name.startsWith( "_" ) && 159 !pack_name.startsWith( "org.omg.Messaging" ) && 161 lexer.strictJavaEscapeCheck( name ) ) 162 { 163 name = "_" + name; 164 } 165 } 166 167 public boolean isEscaped() 168 { 169 return name().startsWith( "_" ); 170 } 171 172 public String deEscapeName() 173 { 174 String tmp = name(); 175 176 if( tmp.startsWith( "_" ) ) 177 { 178 tmp = tmp.substring( 1 ); 179 } 180 181 return tmp; 182 } 183 184 public void setPackage( String s ) 185 { 186 s = parser.pack_replace( s ); 187 if( pack_name.length() > 0 ) 188 pack_name = s + "." + pack_name; 189 else 190 pack_name = s; 191 } 192 193 public void setEnclosingSymbol( IdlSymbol s ) 194 { 195 if( enclosing_symbol != null && enclosing_symbol != s ) 196 throw new RuntimeException ( "Compiler Error: trying to reassign container for " + 197 name ); 198 199 enclosing_symbol = s; 200 } 201 202 public IdlSymbol getEnclosingSymbol() 203 { 204 return enclosing_symbol; 205 } 206 207 public static int new_num() 208 { 209 return num++; 210 } 211 212 213 214 public void set_name( String n ) 215 { 216 name = n; 217 } 218 219 222 223 String full_name() 224 { 225 if( name.length() == 0 ) 226 { 227 return null; 228 } 229 230 if( pack_name.length() > 0 ) 231 { 232 return pack_name + "." + name; 233 } 234 else 235 return name; 236 } 237 238 242 243 String javaName() 244 { 245 if( name.length() == 0 ) 246 return null; 247 if( pack_name.length() > 0 ) 248 { 249 if( !pack_name.startsWith( "org.omg" ) ) 250 { 251 return omg_package_prefix + pack_name + "." + name; 252 } 253 else 254 return pack_name + "." + name; 255 } 256 else 257 return name; 258 } 259 260 264 265 public String omgPrefix() 266 { 267 return omg_package_prefix; 268 } 269 270 271 272 273 public void parse() 274 throws ParseException 275 { 276 } 277 278 public void print( PrintWriter ps ) 279 { 280 throw new java.lang.RuntimeException ( "--abstract--!" ); 281 } 282 283 public void printImport( PrintWriter ps ) 284 { 285 if( !pack_name.equals( "" ) ) 286 { 287 for( Enumeration e = imports.keys(); e.hasMoreElements(); ) 288 { 289 String name = (String )e.nextElement(); 290 ps.println( "import " + name + ";" ); 291 } 292 ps.println(); 293 } 294 } 295 296 303 304 public void addImportedAlias( String alias ) 305 { 306 if( logger.isDebugEnabled() ) 307 logger.debug( "addImportedAlias " + alias ); 308 if( alias.indexOf( '.' ) < 0 && !BaseType.isBasicName( alias ) ) 309 { 310 imports.put( alias + "Helper", "" ); 311 } 312 } 313 314 321 322 public void addImportedName( String name ) 323 { 324 if ( name != null && name.endsWith( "[]" ) ) 326 { 327 name = name.substring( 0, name.length() - 2 ); 328 } 329 330 if( name != null && name.indexOf( '.' ) < 0 && !BaseType.isBasicName( name ) ) 332 { 333 addImportedName( name, null ); 334 } 335 } 336 337 345 346 public void addImportedName( String name, TypeSpec type ) 347 { 348 if( name != null && name.indexOf( '.' ) < 0 && !BaseType.isBasicName( name ) ) 349 { 350 if( logger.isDebugEnabled() ) 351 logger.debug( "addImportedName " + name ); 352 353 356 if( ( type == null ) || !BaseType.isBasicName( type.toString() ) ) 357 { 358 imports.put( name, "" ); 359 } 360 imports.put( name + "Helper", "" ); 361 } 362 } 363 364 372 373 public void addImportedNameHolder( String name ) 374 { 375 if( name.indexOf( '.' ) < 0 && !BaseType.isBasicName( name ) ) 376 { 377 if( logger.isDebugEnabled() ) 378 logger.debug( "addImportedNameHolder " + name ); 379 380 imports.put( name, "" ); 381 } 382 } 383 384 public void setPrintPhaseNames() 385 { 386 if( pack_name.length() > 0 ) 387 { 388 typeName = ScopedName.unPseudoName( pack_name + "." + name ); 389 if( !typeName.startsWith( "org.omg" ) ) 390 { 391 typeName = omg_package_prefix + typeName; 392 } 393 pack_name = typeName.substring( 0, typeName.lastIndexOf( "." ) ); 394 } 395 else 396 typeName = ScopedName.unPseudoName( name ); 397 398 if( logger.isDebugEnabled() ) 399 logger.debug( "setPrintPhaseNames: pack_name " + 400 pack_name + ", name " + name + 401 " typename " + typeName ); 402 } 403 404 public void printIdMethod( PrintWriter ps ) 405 { 406 ps.println( "\tpublic static String id()" ); 407 ps.println( "\t{" ); 408 ps.println( "\t\treturn \"" + id() + "\";" ); 409 ps.println( "\t}" ); 410 } 411 412 415 416 public String id() 417 { 418 IdlSymbol enc = enclosing_symbol; 419 StringBuffer sb = new StringBuffer (); 420 ScopeData sd = null; 421 str_token enctoken = null; 422 423 if( logger.isDebugEnabled() ) 424 logger.debug( "Id for name " + name ); 425 426 if( _id == null ) 427 { 428 do 429 { 430 if (enc != null) 431 { 432 enctoken = enc.get_token(); 435 436 if (enc instanceof Scope) 437 { 438 sd = ((Scope)enc).getScopeData (); 439 if (sd == null) 440 { 441 org.jacorb.idl.parser.fatal_error 442 ( 443 "ScopeDate null for " + name + " " + 444 this.getClass().getName(), null 445 ); 446 } 447 } 448 449 if (sd != null && sd.idMap.get (name) != null) 450 { 451 _id = (String )sd.idMap.get (name); 452 break; 453 } 454 else 456 { 457 if (token != null && 467 ( 468 "".equals (token.pragma_prefix) || 469 enctoken.pragma_prefix.equals (token.pragma_prefix) 470 )) 471 { 472 String enclosingName = enc.name; 473 if( enc instanceof Module ) 478 { 479 String enclosingModuleName = 480 ((Module)enc).originalModuleName (); 481 482 if ( !enclosingModuleName.startsWith ("org")) 483 { 484 enclosingName = ((Module)enc).originalModuleName (); 485 } 486 487 if( enc.isEscaped ()) 489 { 490 enclosingName = enclosingName.substring (1); 491 } 492 } 493 sb.insert (0, enclosingName + "/"); 494 enc = enc.getEnclosingSymbol (); 495 } 496 else 497 { 498 break; 499 } 500 } 501 } 502 else if (parser.scopes.size () == 1 && 504 parser.currentScopeData ().idMap.get (name) != null) 505 { 506 _id = (String )parser.currentScopeData ().idMap.get (name); 507 break; 508 } 509 else 510 { 511 break; 514 } 515 } 516 while (enc != null); 517 518 if (_id == null) 519 { 520 if( isEscaped() ) 522 { 523 sb.append( name.substring( 1 ) ); 524 } 525 else 526 { 527 sb.append( name ); 528 } 529 if( token != null && token.pragma_prefix.length() > 0 ) 530 { 531 _id = 532 ( 533 "IDL:" + token.pragma_prefix + 534 "/" + sb.toString().replace( '.', '/' ) + ":" + version () 535 ); 536 } 537 else 538 { 539 _id = "IDL:" + sb.toString().replace( '.', '/' ) + ":" + version(); 540 } 541 } 542 } 543 if( logger.isDebugEnabled() ) 544 logger.debug( "Id for name " + name + " is " + _id ); 545 return _id; 546 } 547 548 private String version() 549 { 550 IdlSymbol enc = this; 551 String tmp; 552 553 if( _version == null ) 554 { 555 while( true ) 556 { 557 while( enc != null && !( enc instanceof Scope ) ) 558 { 559 enc = enc.getEnclosingSymbol(); 560 } 561 if( enc != null ) 562 { 563 ScopeData sd = ( (Scope)enc ).getScopeData(); 564 if( sd == null ) 565 { 566 org.jacorb.idl.parser.fatal_error( "ScopeData null for " + name + " " + 567 this.getClass().getName(), null ); 568 } 569 Hashtable h = sd.versionMap; 570 571 tmp = (String )h.get( name ); 573 if( tmp != null ) 574 { 575 _version = tmp; 576 break; 577 } 578 enc = enc.getEnclosingSymbol(); 579 } 580 else if (parser.scopes.size () == 1 && 582 parser.currentScopeData ().versionMap.get (name) != null) 583 { 584 _version = (String )parser.currentScopeData ().versionMap.get (name); 585 break; 586 } 587 else 588 { 589 _version = "1.0"; 590 break; 591 } 592 } 593 594 596 if( enc != null ) 597 enc = enc.getEnclosingSymbol(); 598 599 while( true ) 600 { 601 while( enc != null && !( enc instanceof Scope ) ) 602 { 603 enc = enc.getEnclosingSymbol(); 604 } 605 if( enc != null ) 606 { 607 Hashtable h = ( (Scope)enc ).getScopeData().versionMap; 609 tmp = (String )h.get( name ); 610 611 if( tmp != null ) 612 { 613 lexer.emit_error( "Version for " + name + 614 " already declared!", enc.get_token() ); 615 break; 616 } 617 else 618 enc = enc.getEnclosingSymbol(); 619 } 620 else 621 { 622 break; 623 } 624 } 625 } 626 return _version; 627 } 628 629 630 633 634 protected boolean generateIncluded() 635 { 636 return parser.generateIncluded() && !( inhibitionFlag ); 637 } 638 639 642 643 public void accept( IDLTreeVisitor visitor ) 644 { 645 } 647 } 648 | Popular Tags |