1 package org.jacorb.idl; 2 3 22 23 import java.io.PrintWriter ; 24 25 29 30 class PrimaryExpr 31 extends IdlSymbol 32 { 33 public IdlSymbol symbol; 34 35 private boolean contained = false; 36 private ConstDecl declared_in; 37 38 public PrimaryExpr( int num ) 39 { 40 super( num ); 41 } 42 43 public void print( PrintWriter ps ) 44 { 45 if( symbol instanceof ConstExpr ) 46 { 47 ps.print( "(" ); 48 symbol.print( ps ); 49 ps.print( ")" ); 50 } 51 else if( symbol instanceof ScopedName ) 52 { 53 ps.print( ( (ScopedName)symbol ).resolvedName() ); 54 } 55 else symbol.print( ps ); 57 } 58 59 public void parse() 60 { 61 symbol.parse(); 62 } 63 64 public void setDeclaration( ConstDecl declared_in ) 65 { 66 this.declared_in = declared_in; 67 if( symbol instanceof Literal ) 68 ( (Literal)symbol ).setDeclaration( declared_in ); 69 } 70 71 public void setPackage( String s ) 72 { 73 s = parser.pack_replace( s ); 74 if( pack_name.length() > 0 ) 75 pack_name = s + "." + pack_name; 76 else 77 pack_name = s; 78 79 symbol.setPackage( s ); 80 } 81 82 int pos_int_const() 83 { 84 if( symbol instanceof ConstExpr ) 85 { 86 return ( (ConstExpr)symbol ).pos_int_const(); 87 } 88 else if( symbol instanceof ScopedName ) 89 { 90 ConstExprEvaluator eval = 91 new ConstExprEvaluator( ConstDecl.namedValue( (ScopedName)symbol )); 92 if( logger.isDebugEnabled() ) 93 logger.debug( "PrimaryExpr: returning value " + eval.getValue().intValue()); 94 95 return eval.getValue().intValue(); 96 } 97 else 98 return Integer.parseInt( ( (Literal)symbol ).toString() ); 99 } 100 101 public String value() 102 { 103 if( symbol instanceof ConstExpr ) 104 { 105 return "(" + ( (ConstExpr)symbol ).value() + ")"; 106 } 107 else if( symbol instanceof ScopedName ) 108 { 109 return ConstDecl.namedValue( (ScopedName)symbol ); 110 } 111 else 112 return ( (Literal)symbol ).toString(); 113 } 114 115 public String toString() 116 { 117 if( symbol instanceof ConstExpr ) 118 { 119 return "(" + ( (ConstExpr)symbol ).toString() + ")"; 120 } 121 else if( symbol instanceof ScopedName ) 122 { 123 return ( (ScopedName)symbol ).resolvedName(); 124 } 125 else 126 { 127 return ( (Literal)symbol ).toString(); 128 } 129 } 130 131 public str_token get_token() 132 { 133 return symbol.get_token(); 134 } 135 } 136 | Popular Tags |