1 33 34 package bsh; 35 36 class BSHTypedVariableDeclaration extends SimpleNode 37 { 38 public Modifiers modifiers; 39 40 BSHTypedVariableDeclaration(int id) { super(id); } 41 42 private BSHType getTypeNode() { 43 return ((BSHType)jjtGetChild(0)); 44 } 45 46 Class evalType( CallStack callstack, Interpreter interpreter ) 47 throws EvalError 48 { 49 BSHType typeNode = getTypeNode(); 50 return typeNode.getType( callstack, interpreter ); 51 } 52 53 BSHVariableDeclarator [] getDeclarators() 54 { 55 int n = jjtGetNumChildren(); 56 int start=1; 57 BSHVariableDeclarator [] bvda = new BSHVariableDeclarator[ n-start ]; 58 for (int i = start; i < n; i++) 59 { 60 bvda[i-start] = (BSHVariableDeclarator)jjtGetChild(i); 61 } 62 return bvda; 63 } 64 65 69 public Object eval( CallStack callstack, Interpreter interpreter) 70 throws EvalError 71 { 72 try { 73 NameSpace namespace = callstack.top(); 74 BSHType typeNode = getTypeNode(); 75 Class type = typeNode.getType( callstack, interpreter ); 76 77 BSHVariableDeclarator [] bvda = getDeclarators(); 78 for (int i = 0; i < bvda.length; i++) 79 { 80 BSHVariableDeclarator dec = bvda[i]; 81 82 Object value = dec.eval( typeNode, callstack, interpreter); 85 86 try { 87 namespace.setTypedVariable( 88 dec.name, type, value, modifiers ); 89 } catch ( UtilEvalError e ) { 90 throw e.toEvalError( this, callstack ); 91 } 92 } 93 } catch ( EvalError e ) { 94 e.reThrow( "Typed variable declaration" ); 95 } 96 97 return Primitive.VOID; 98 } 99 100 public String getTypeDescriptor( 101 CallStack callstack, Interpreter interpreter, String defaultPackage ) 102 { 103 return getTypeNode().getTypeDescriptor( 104 callstack, interpreter, defaultPackage ); 105 } 106 } 107 | Popular Tags |