Stubbed foreach node.

This commit is contained in:
Jack Conradson 2016-06-06 10:49:40 -07:00
parent 0c9174decc
commit 260b0fd40f
3 changed files with 65 additions and 1 deletions

View File

@ -53,6 +53,7 @@ import org.elasticsearch.painless.antlr.PainlessParser.DeclvarContext;
import org.elasticsearch.painless.antlr.PainlessParser.DelimiterContext;
import org.elasticsearch.painless.antlr.PainlessParser.DoContext;
import org.elasticsearch.painless.antlr.PainlessParser.DynamicContext;
import org.elasticsearch.painless.antlr.PainlessParser.EachContext;
import org.elasticsearch.painless.antlr.PainlessParser.EmptyContext;
import org.elasticsearch.painless.antlr.PainlessParser.ExprContext;
import org.elasticsearch.painless.antlr.PainlessParser.ExpressionContext;
@ -118,6 +119,7 @@ import org.elasticsearch.painless.node.SContinue;
import org.elasticsearch.painless.node.SDeclBlock;
import org.elasticsearch.painless.node.SDeclaration;
import org.elasticsearch.painless.node.SDo;
import org.elasticsearch.painless.node.SEach;
import org.elasticsearch.painless.node.SExpression;
import org.elasticsearch.painless.node.SFor;
import org.elasticsearch.painless.node.SIf;
@ -271,6 +273,16 @@ public final class Walker extends PainlessParserBaseVisitor<Object> {
}
}
@Override
public Object visitEach(EachContext ctx) {
String type = ctx.decltype().getText();
String name = ctx.ID().getText();
AExpression expression = (AExpression)visit(ctx.expression());
SBlock block = (SBlock)visit(ctx.trailer());
return new SEach(location(ctx), type, name, expression, block);
}
@Override
public Object visitDecl(DeclContext ctx) {
return visit(ctx.declaration());

View File

@ -0,0 +1,51 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.painless.node;
import org.elasticsearch.painless.Location;
import org.elasticsearch.painless.MethodWriter;
import org.elasticsearch.painless.Variables;
public class SEach extends AStatement {
final String type;
final String name;
AExpression expression;
AStatement block;
public SEach(final Location location, final String type, final String name, final AExpression expression, final SBlock block) {
super(location);
this.type = type;
this.name = name;
this.expression = expression;
this.block = block;
}
@Override
AStatement analyze(Variables variables) {
return null;
}
@Override
void write(MethodWriter writer) {
}
}

View File

@ -90,7 +90,8 @@
* <p>
* Generally, statement nodes have member data that evaluate legal control-flow during the analysis phase.
* The typical order for statement nodes is for each node to call analyze on it's children during the analysis phase
* and write on it's children during the writing phase. No modifications are made to the structure of statement nodes.
* and write on it's children during the writing phase. Upon analysis completion, a statement will return either
* itself or another statement node depending on if a shortcut or def type was found.
* <p>
* Generally, expression nodes have member data that evaluate static types. The typical order for an expression node
* during the analysis phase looks like the following: