01: /*
02: * CompilerPnutsImpl.java
03: *
04: * Copyright (c) 1997-2007 Sun Microsystems, Inc. All Rights Reserved.
05: *
06: * See the file "LICENSE.txt" for information on usage and redistribution
07: * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
08: */
09: package pnuts.compiler;
10:
11: import pnuts.lang.Context;
12: import pnuts.lang.PnutsImpl;
13: import pnuts.lang.SimpleNode;
14:
15: /**
16: * A subclass of PnutsImpl that always compiles scripts.
17: *
18: * @see pnuts.lang.PnutsImpl
19: * @see pnuts.ext.CachedPnutsImpl
20: */
21: public class CompilerPnutsImpl extends PnutsImpl {
22:
23: Compiler compiler = new Compiler();
24:
25: public CompilerPnutsImpl() {
26: compiler.setConstantFolding(true);
27: }
28:
29: public CompilerPnutsImpl(boolean includeLineNo) {
30: compiler.includeLineNo(includeLineNo);
31: }
32:
33: public CompilerPnutsImpl(boolean includeLineNo,
34: boolean useDynamicProxy) {
35: this (includeLineNo, includeLineNo, useDynamicProxy);
36: }
37:
38: public CompilerPnutsImpl(boolean includeLineNo,
39: boolean includeColumnNo, boolean useDynamicProxy) {
40: compiler.automatic = true;
41: compiler.useDynamicProxy(useDynamicProxy);
42: compiler.includeLineNo(includeLineNo);
43: compiler.includeColumnNo(includeColumnNo);
44: compiler.setConstantFolding(true);
45: }
46:
47: public void setProperty(String key, String value) {
48: if ("pnuts.compiler.useDynamicProxy".equals(key)) {
49: compiler.useDynamicProxy("true".equalsIgnoreCase(value));
50: } else if ("pnuts.compiler.traceMode".equals(key)) {
51: compiler.setTraceMode("true".equalsIgnoreCase(value));
52: } else if ("pnuts.compiler.optimize".equals(key)) {
53: compiler.includeLineNo(!"true".equalsIgnoreCase(value));
54: }
55: super .setProperty(key, value);
56: }
57:
58: public void includeLineNo(boolean flag) {
59: compiler.includeLineNo(flag);
60: }
61:
62: public void includeColumnNo(boolean flag) {
63: compiler.includeColumnNo(flag);
64: }
65:
66: protected Object acceptNode(SimpleNode node, Context context) {
67: return node.accept(compiler, context);
68: }
69: }
|