01: /*
02: * $Id: ComprehensionNode.java,v 1.2 2002/09/16 08:05:04 jkl Exp $
03: *
04: * Copyright (c) 2002 Njet Communications Ltd. All Rights Reserved.
05: *
06: * Use is subject to license terms, as defined in
07: * Anvil Sofware License, Version 1.1. See LICENSE
08: * file, or http://njet.org/license-1.1.txt
09: */
10: package anvil.script.expression;
11:
12: import anvil.ErrorListener;
13: import anvil.core.Any;
14: import anvil.core.Array;
15: import anvil.codec.Code;
16: import anvil.codec.ConstantPool;
17: import anvil.script.statements.Statement;
18: import anvil.script.compiler.ByteCompiler;
19: import anvil.script.Context;
20: import java.io.IOException;
21:
22: /**
23: * class ComprehensionNode
24: *
25: * @author: Jani Lehtimäki
26: */
27: public abstract class ComprehensionNode extends Node {
28:
29: protected Statement _stmt;
30: protected VariableNode _var;
31:
32: public ComprehensionNode() {
33: super ();
34: }
35:
36: public void init(Statement stmt, VariableNode var) {
37: _stmt = stmt;
38: _var = var;
39: }
40:
41: public abstract int getClassReference(ConstantPool pool);
42:
43: public abstract int typeOf();
44:
45: public Node optimize() {
46: return this ;
47: }
48:
49: public void check(ErrorListener context) {
50: super .check(context);
51: _var.check(context);
52: _stmt.check(context);
53: }
54:
55: public void compile(ByteCompiler context, int operation) {
56: Code code = context.getCode();
57: _var.compile(context, new Node() {
58: public void compile(ByteCompiler context, int operation) {
59: Code code_ = context.getCode();
60: ConstantPool pool = code_.getPool();
61: int clazz = getClassReference(pool);
62: code_.anew(clazz);
63: code_.dup();
64: code_.invokespecial(pool.addMethodRef(clazz, "<init>",
65: "()V"));
66: }
67: });
68: code.pop();
69: _stmt.compile(context);
70: _var.compile(context, GET);
71: if (operation == GET_BOOLEAN) {
72: context.any2boolean();
73: }
74: }
75:
76: }
|