KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jruby > compiler > NodeCompilerFactory


1 /***** BEGIN LICENSE BLOCK *****
2  * Version: CPL 1.0/GPL 2.0/LGPL 2.1
3  *
4  * The contents of this file are subject to the Common Public
5  * License Version 1.0 (the "License"); you may not use this file
6  * except in compliance with the License. You may obtain a copy of
7  * the License at http://www.eclipse.org/legal/cpl-v10.html
8  *
9  * Software distributed under the License is distributed on an "AS
10  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
11  * implied. See the License for the specific language governing
12  * rights and limitations under the License.
13  *
14  * Copyright (C) 2006 Charles O Nutter <headius@headius.com>
15  *
16  * Alternatively, the contents of this file may be used under the terms of
17  * either of the GNU General Public License Version 2 or later (the "GPL"),
18  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
19  * in which case the provisions of the GPL or the LGPL are applicable instead
20  * of those above. If you wish to allow use of your version of this file only
21  * under the terms of either the GPL or the LGPL, and not to allow others to
22  * use your version of this file under the terms of the CPL, indicate your
23  * decision by deleting the provisions above and replace them with the notice
24  * and other provisions required by the GPL or the LGPL. If you do not delete
25  * the provisions above, a recipient may use your version of this file under
26  * the terms of any one of the CPL, the GPL or the LGPL.
27  ***** END LICENSE BLOCK *****/

28
29 package org.jruby.compiler;
30
31 import org.jruby.ast.Node;
32 import org.jruby.ast.NodeTypes;
33
34 /**
35  *
36  * @author headius
37  */

38 public class NodeCompilerFactory {
39     public static YARVNodesCompiler getYARVCompiler() {
40         return new YARVNodesCompiler();
41     }
42     public static NodeCompiler getCompiler(Node node) {
43         switch (node.nodeId) {
44         case NodeTypes.ALIASNODE:
45             return new AliasNodeCompiler();
46         case NodeTypes.ANDNODE:
47             return new AndNodeCompiler();
48         case NodeTypes.ARRAYNODE:
49             return new ArrayNodeCompiler();
50         case NodeTypes.BEGINNODE:
51             return new BeginNodeCompiler();
52         case NodeTypes.BIGNUMNODE:
53             return new BignumNodeCompiler();
54         case NodeTypes.BLOCKNODE:
55             return new BlockNodeCompiler();
56         case NodeTypes.CALLNODE:
57             return new CallNodeCompiler();
58         case NodeTypes.CONSTNODE:
59             return new ConstNodeCompiler();
60         case NodeTypes.DASGNNODE:
61             return new DAsgnNodeCompiler();
62         case NodeTypes.DEFNNODE:
63             return new DefnNodeCompiler();
64         case NodeTypes.DVARNODE:
65             return new DVarNodeCompiler();
66         case NodeTypes.FALSENODE:
67             return new FalseNodeCompiler();
68         case NodeTypes.FCALLNODE:
69             return new FCallNodeCompiler();
70         case NodeTypes.FIXNUMNODE:
71             return new FixnumNodeCompiler();
72         case NodeTypes.GLOBALASGNNODE:
73             return new GlobalAsgnNodeCompiler();
74         case NodeTypes.GLOBALVARNODE:
75             return new GlobalVarNodeCompiler();
76         case NodeTypes.IFNODE:
77             return new IfNodeCompiler();
78         case NodeTypes.INSTASGNNODE:
79             return new InstAsgnNodeCompiler();
80         case NodeTypes.INSTVARNODE:
81             return new InstVarNodeCompiler();
82         //case NodeTypes.ITERNODE:
83
// return new IterNodeCompiler();
84
case NodeTypes.LOCALASGNNODE:
85             return new LocalAsgnNodeCompiler();
86         case NodeTypes.LOCALVARNODE:
87             return new LocalVarNodeCompiler();
88         case NodeTypes.NEWLINENODE:
89             return new NewlineNodeCompiler();
90         case NodeTypes.NILNODE:
91             return new NilNodeCompiler();
92         case NodeTypes.NOTNODE:
93             return new NotNodeCompiler();
94         case NodeTypes.ORNODE:
95             return new OrNodeCompiler();
96         case NodeTypes.ROOTNODE:
97             return new RootNodeCompiler();
98         case NodeTypes.SELFNODE:
99             return new SelfNodeCompiler();
100         case NodeTypes.SPLATNODE:
101             return new SplatNodeCompiler();
102         case NodeTypes.STRNODE:
103             return new StringNodeCompiler();
104         case NodeTypes.SVALUENODE:
105             return new SValueNodeCompiler();
106         case NodeTypes.SYMBOLNODE:
107             return new SymbolNodeCompiler();
108         case NodeTypes.TRUENODE:
109             return new TrueNodeCompiler();
110         case NodeTypes.VCALLNODE:
111             return new VCallNodeCompiler();
112         case NodeTypes.WHILENODE:
113             return new WhileNodeCompiler();
114         case NodeTypes.YIELDNODE:
115             return new YieldNodeCompiler();
116         case NodeTypes.ZARRAYNODE:
117             return new ZArrayNodeCompiler();
118         }
119         
120         throw new NotCompilableException("Can't compile node: " + node);
121     }
122     
123     public static NodeCompiler getArgumentsCompiler(Node node) {
124         switch (node.nodeId) {
125         case NodeTypes.ARRAYNODE:
126             return new ArrayNodeArgsCompiler();
127         }
128         
129         throw new NotCompilableException("Can't compile argument node: " + node);
130     }
131     
132     public static NodeCompiler getAssignmentCompiler(Node node) {
133         switch (node.nodeId) {
134             // disabled for now; incomplete
135
//case NodeTypes.MULTIPLEASGNNODE:
136
// return new MultipleAsgnNodeAsgnCompiler();
137
}
138         
139         throw new NotCompilableException("Can't compile assignment node: " + node);
140     }
141 }
142
Popular Tags