MCPcopy Create free account
hub / github.com/mozilla/rhino / IRFactory

Class IRFactory

rhino/src/main/java/org/mozilla/javascript/IRFactory.java:92–2637  ·  view source on GitHub ↗

This class rewrites the parse tree into an IR suitable for codegen. @see Node @author Mike McCabe @author Norris Boyd

Source from the content-addressed store, hash-verified

90 * @author Norris Boyd
91 */
92public final class IRFactory {
93 private static final int LOOP_DO_WHILE = 0;
94 private static final int LOOP_WHILE = 1;
95 private static final int LOOP_FOR = 2;
96
97 private static final int ALWAYS_TRUE_BOOLEAN = 1;
98 private static final int ALWAYS_FALSE_BOOLEAN = -1;
99
100 private Parser parser;
101 private AstNodePosition astNodePos;
102 private boolean outerScopeIsStrict;
103
104 public IRFactory(CompilerEnvirons env, String sourceString) {
105 this(env, null, sourceString, env.getErrorReporter());
106 }
107
108 /** Use {@link #IRFactory(CompilerEnvirons, String, String, ErrorReporter)} */
109 @Deprecated
110 public IRFactory(CompilerEnvirons env, String sourceString, ErrorReporter errorReporter) {
111 this(env, null, sourceString, errorReporter);
112 }
113
114 public IRFactory(
115 CompilerEnvirons env,
116 String sourceName,
117 String sourceString,
118 ErrorReporter errorReporter) {
119 parser = new Parser(env, errorReporter);
120 astNodePos = new AstNodePosition(sourceString);
121 parser.currentPos = astNodePos;
122 parser.setSourceURI(sourceName);
123 }
124
125 /** Transforms the tree into a lower-level IR suitable for codegen. */
126 public ScriptNode transformTree(AstRoot root) {
127 parser.currentScriptOrFn = root;
128 parser.inUseStrictDirective = root.isInStrictMode();
129
130 if (Token.printTrees) {
131 System.out.println("IRFactory.transformTree");
132 System.out.println(root.debugPrint());
133 }
134
135 astNodePos.push(root);
136 try {
137 return (ScriptNode) transform(root);
138 } catch (Parser.ParserException e) {
139 parser.reportErrorsIfExists(root.getLineno());
140 return null;
141 } finally {
142 astNodePos.pop();
143 }
144 }
145
146 // Might want to convert this to polymorphism - move transform*
147 // functions into the AstNode subclasses. OTOH that would make
148 // IR transformation part of the public AST API - desirable?
149 // Another possibility: create AstTransformer interface and adapter.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected