From a088d367f7d22267cc16bbcb7146f26a27168bb1 Mon Sep 17 00:00:00 2001 From: Jack Conradson Date: Mon, 6 Jun 2016 15:58:56 -0700 Subject: [PATCH] More comments. --- .../elasticsearch/painless/node/EChain.java | 12 +++++----- .../elasticsearch/painless/node/SDefEach.java | 23 +++++++++++++++++++ .../elasticsearch/painless/node/SEach.java | 3 +++ 3 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SDefEach.java diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EChain.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EChain.java index df0d670320d..9b2968db565 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EChain.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EChain.java @@ -269,14 +269,14 @@ public final class EChain extends AExpression { */ @Override void write(MethodWriter writer) { + writer.writeDebugInfo(location); + // For the case where the chain represents a String concatenation - // we must first write debug information, and then depending on the - // Java version write a StringBuilder or track types going onto the - // stack. This must be done before the links in the chain are read - // because we need the StringBuilder to be placed on the stack - // ahead of any potential concatenation arguments. + // we must, depending on the Java version, write a StringBuilder or + // track types going onto the stack. This must be done before the + // links in the chain are read because we need the StringBuilder to + // be placed on the stack ahead of any potential concatenation arguments. if (cat) { - writer.writeDebugInfo(location); writer.writeNewStrings(); } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SDefEach.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SDefEach.java new file mode 100644 index 00000000000..000fc42c7a0 --- /dev/null +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SDefEach.java @@ -0,0 +1,23 @@ +/* + * 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; + +public class SDefEach { +} diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SEach.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SEach.java index 0d7e81c2073..3266fdc9ba6 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SEach.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SEach.java @@ -88,6 +88,9 @@ public class SEach extends AStatement { Type itr = Definition.getType("Iterator"); variable = variables.addVariable(location, type, name, true, false); + + // We must store the iterator as a variable for securing a slot on the stack, and + // also add the location offset to make the name unique in case of nested for each loops. iterator = variables.addVariable(location, itr, "#itr" + location.getOffset(), true, false); method = expression.actual.struct.methods.get(new MethodKey("iterator", 0));