1 20 21 package org.jacorb.idl; 22 23 27 28 import java.io.PrintWriter ; 29 30 public class ParamDecl 31 extends IdlSymbol 32 { 33 public static final int MODE_IN = 1; 34 public static final int MODE_OUT = 2; 35 public static final int MODE_INOUT = 3; 36 37 public int paramAttribute; 38 public TypeSpec paramTypeSpec; 39 public SimpleDeclarator simple_declarator; 40 41 public ParamDecl( int num ) 42 { 43 super( num ); 44 } 45 46 49 public ParamDecl( int paramAttribute, 50 TypeSpec paramTypeSpec, 51 SimpleDeclarator simple_declarator ) 52 { 53 super( new_num()); 54 this.paramAttribute = paramAttribute; 55 this.paramTypeSpec = paramTypeSpec; 56 this.simple_declarator = simple_declarator; 57 } 58 59 62 public ParamDecl( int paramAttribute, 63 TypeSpec paramTypeSpec, 64 String name) 65 { 66 super( new_num() ); 67 this.paramAttribute = paramAttribute; 68 this.paramTypeSpec = paramTypeSpec; 69 this.simple_declarator = new SimpleDeclarator( new_num() ); 70 this.simple_declarator.name = name; 71 } 72 73 public void setPackage( String s ) 74 { 75 s = parser.pack_replace( s ); 76 if( pack_name.length() > 0 ) 77 pack_name = s + "." + pack_name; 78 else 79 pack_name = s; 80 paramTypeSpec.setPackage( s ); 81 } 82 83 87 public ParamDecl asIn() 88 { 89 return new ParamDecl( MODE_IN, 90 this.paramTypeSpec, 91 this.simple_declarator) ; 92 } 93 94 public void parse() 95 { 96 while( paramTypeSpec.typeSpec() instanceof ScopedName ) 97 { 98 TypeSpec ts = ( (ScopedName)paramTypeSpec.typeSpec() ).resolvedTypeSpec(); 99 if( ts != null ) 100 paramTypeSpec = ts; 101 } 102 103 if( paramTypeSpec == null ) 104 { 105 throw new ParseException("parameter TypeSpec is null " + name, this.myPosition ); 106 } 107 } 108 109 public void print( PrintWriter ps ) 110 { 111 switch( paramAttribute ) 112 { 113 case MODE_IN: 114 ps.print( paramTypeSpec.toString() ); 115 break; 116 case MODE_OUT: 117 case MODE_INOUT: 118 ps.print( paramTypeSpec.holderName() ); 119 break; 120 } 121 ps.print( " " + simple_declarator ); 122 } 123 124 public String printWriteStatement( String ps ) 125 { 126 return printWriteStatement( simple_declarator.toString(), ps ); 127 } 128 129 public String printWriteStatement( String name, String ps ) 130 { 131 if( paramAttribute != ParamDecl.MODE_IN ) 132 return paramTypeSpec.typeSpec().printWriteStatement( name + ".value", ps ); 133 else 134 return paramTypeSpec.typeSpec().printWriteStatement( name, ps ); 135 } 136 137 public String printReadExpression( String ps ) 138 { 139 return paramTypeSpec.typeSpec().printReadExpression( ps ); 140 } 141 142 public void accept( IDLTreeVisitor visitor ) 143 { 144 visitor.visitParamDecl( this ); 145 } 146 147 148 } 149 | Popular Tags |