Permalink
Browse files

extracting NamedValueStatement

  • Loading branch information...
1 parent 4d69163 commit 29f29f981e048ef88e75f51f0a225533b2bebaba @qmx qmx committed Dec 29, 2011
@@ -17,7 +17,6 @@
package org.dynjs.parser;
import me.qmx.internal.org.objectweb.asm.Opcodes;
-import me.qmx.jitescript.CodeBlock;
import org.antlr.runtime.tree.CommonTree;
import org.dynjs.compiler.DynJSCompiler;
import org.dynjs.parser.statement.BlockStatement;
@@ -31,6 +30,7 @@
import org.dynjs.parser.statement.FunctionStatement;
import org.dynjs.parser.statement.IfStatement;
import org.dynjs.parser.statement.LogicalOperationStatement;
+import org.dynjs.parser.statement.NamedValueStatement;
import org.dynjs.parser.statement.NotEqualsOperationStatement;
import org.dynjs.parser.statement.NotOperationStatement;
import org.dynjs.parser.statement.NullLiteralStatement;
@@ -432,15 +432,7 @@ public Statement propertyNameNumeric(Statement numericLiteral) {
}
public Statement namedValue(final Statement propertyName, final Statement expr) {
- return new Statement() {
- @Override
- public CodeBlock getCodeBlock() {
- return CodeBlock.newCodeBlock()
- .append(propertyName.getCodeBlock())
- .append(expr.getCodeBlock())
- .invokeinterface(DynJSCompiler.Types.Scope, "define", sig(void.class, String.class, Object.class));
- }
- };
+ return new NamedValueStatement(propertyName, expr);
}
public Statement arrayLiteral(List<Statement> exprs) {
@@ -0,0 +1,26 @@
+package org.dynjs.parser.statement;
+
+import me.qmx.jitescript.CodeBlock;
+import org.dynjs.compiler.DynJSCompiler;
+import org.dynjs.parser.Statement;
+
+import static me.qmx.jitescript.util.CodegenUtils.sig;
+
+public class NamedValueStatement implements Statement {
+
+ private final Statement propertyName;
+ private final Statement expr;
+
+ public NamedValueStatement(Statement propertyName, Statement expr) {
+ this.propertyName = propertyName;
+ this.expr = expr;
+ }
+
+ @Override
+ public CodeBlock getCodeBlock() {
+ return CodeBlock.newCodeBlock()
+ .append(propertyName.getCodeBlock())
+ .append(expr.getCodeBlock())
+ .invokeinterface(DynJSCompiler.Types.Scope, "define", sig(void.class, String.class, Object.class));
+ }
+}

0 comments on commit 29f29f9

Please sign in to comment.