1 33 34 35 package bsh; 36 37 class BSHBlock extends SimpleNode 38 { 39 public boolean isSynchronized = false; 40 41 BSHBlock(int id) { super(id); } 42 43 public Object eval( CallStack callstack, Interpreter interpreter) 44 throws EvalError 45 { 46 return eval( callstack, interpreter, false ); 47 } 48 49 59 public Object eval( 60 CallStack callstack, Interpreter interpreter, 61 boolean overrideNamespace ) 62 throws EvalError 63 { 64 Object syncValue = null; 65 if ( isSynchronized ) 66 { 67 SimpleNode exp = ((SimpleNode)jjtGetChild(0)); 69 syncValue = exp.eval(callstack, interpreter); 70 } 71 72 Object ret; 73 if ( isSynchronized ) synchronized( syncValue ) 75 { 76 ret = evalBlock( 77 callstack, interpreter, overrideNamespace, null); 78 } 79 else 80 ret = evalBlock( 81 callstack, interpreter, overrideNamespace, null ); 82 83 return ret; 84 } 85 86 Object evalBlock( 87 CallStack callstack, Interpreter interpreter, 88 boolean overrideNamespace, NodeFilter nodeFilter ) 89 throws EvalError 90 { 91 Object ret = Primitive.VOID; 92 NameSpace enclosingNameSpace = null; 93 if ( !overrideNamespace ) 94 { 95 enclosingNameSpace= callstack.top(); 96 BlockNameSpace bodyNameSpace = 97 new BlockNameSpace( enclosingNameSpace ); 98 99 callstack.swap( bodyNameSpace ); 100 } 101 102 int startChild = isSynchronized ? 1 : 0; 103 int numChildren = jjtGetNumChildren(); 104 105 try { 106 110 for(int i=startChild; i<numChildren; i++) 111 { 112 SimpleNode node = ((SimpleNode)jjtGetChild(i)); 113 114 if ( nodeFilter != null && !nodeFilter.isVisible( node ) ) 115 continue; 116 117 if ( node instanceof BSHClassDeclaration ) 118 node.eval( callstack, interpreter ); 119 } 120 for(int i=startChild; i<numChildren; i++) 121 { 122 SimpleNode node = ((SimpleNode)jjtGetChild(i)); 123 if ( node instanceof BSHClassDeclaration ) 124 continue; 125 126 if ( nodeFilter != null && !nodeFilter.isVisible( node ) ) 128 continue; 129 130 ret = node.eval( callstack, interpreter ); 131 132 if ( ret instanceof ReturnControl ) 134 break; 135 } 136 } finally { 137 if ( !overrideNamespace ) 139 callstack.swap( enclosingNameSpace ); 140 } 141 return ret; 142 } 143 144 public interface NodeFilter { 145 public boolean isVisible( SimpleNode node ); 146 } 147 148 } 149 150 | Popular Tags |