Browse Source

Merge pull request #18828 from rmuir/ownReferences

painless: method references to user functions
Robert Muir 9 năm trước cách đây
mục cha
commit
7c8eb184ee
23 tập tin đã thay đổi với 780 bổ sung596 xóa
  1. 1 4
      modules/lang-painless/build.gradle
  2. 0 1
      modules/lang-painless/licenses/asm-5.0.4.jar.sha1
  3. 0 1
      modules/lang-painless/licenses/asm-commons-5.0.4.jar.sha1
  4. 1 0
      modules/lang-painless/licenses/asm-debug-all-5.1.jar.sha1
  5. 0 1
      modules/lang-painless/licenses/asm-tree-5.0.4.jar.sha1
  6. 1 0
      modules/lang-painless/src/main/antlr/PainlessLexer.g4
  7. 99 97
      modules/lang-painless/src/main/antlr/PainlessLexer.tokens
  8. 2 2
      modules/lang-painless/src/main/antlr/PainlessParser.g4
  9. 99 97
      modules/lang-painless/src/main/antlr/PainlessParser.tokens
  10. 32 9
      modules/lang-painless/src/main/java/org/elasticsearch/painless/Def.java
  11. 41 0
      modules/lang-painless/src/main/java/org/elasticsearch/painless/Definition.java
  12. 77 38
      modules/lang-painless/src/main/java/org/elasticsearch/painless/FunctionRef.java
  13. 7 11
      modules/lang-painless/src/main/java/org/elasticsearch/painless/MethodWriter.java
  14. 7 3
      modules/lang-painless/src/main/java/org/elasticsearch/painless/WriterConstants.java
  15. 208 205
      modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/PainlessLexer.java
  16. 105 98
      modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/PainlessParser.java
  17. 3 0
      modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/Walker.java
  18. 19 1
      modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EFunctionRef.java
  19. 0 2
      modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ELambda.java
  20. 0 1
      modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SExpression.java
  21. 17 6
      modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SFunction.java
  22. 41 17
      modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SSource.java
  23. 20 2
      modules/lang-painless/src/test/java/org/elasticsearch/painless/FunctionRefTests.java

+ 1 - 4
modules/lang-painless/build.gradle

@@ -26,10 +26,7 @@ esplugin {
 
 dependencies {
   compile 'org.antlr:antlr4-runtime:4.5.1-1'
-  compile 'org.ow2.asm:asm:5.0.4'
-  compile 'org.ow2.asm:asm-commons:5.0.4'
-  compile 'org.ow2.asm:asm-tree:5.0.4'
-  testCompile 'org.ow2.asm:asm-util:5.0.4'
+  compile 'org.ow2.asm:asm-debug-all:5.1'
 }
 
 dependencyLicenses {

+ 0 - 1
modules/lang-painless/licenses/asm-5.0.4.jar.sha1

@@ -1 +0,0 @@
-0da08b8cce7bbf903602a25a3a163ae252435795

+ 0 - 1
modules/lang-painless/licenses/asm-commons-5.0.4.jar.sha1

@@ -1 +0,0 @@
-5a556786086c23cd689a0328f8519db93821c04c

+ 1 - 0
modules/lang-painless/licenses/asm-debug-all-5.1.jar.sha1

@@ -0,0 +1 @@
+dde860d586960d55a87cd52c4fc1f5059c89cbc6

+ 0 - 1
modules/lang-painless/licenses/asm-tree-5.0.4.jar.sha1

@@ -1 +0,0 @@
-396ce0c07ba2b481f25a70195c7c94922f0d1b0b

+ 1 - 0
modules/lang-painless/src/main/antlr/PainlessLexer.g4

@@ -51,6 +51,7 @@ NEW:       'new';
 TRY:       'try';
 CATCH:     'catch';
 THROW:     'throw';
+THIS:      'this';
 
 BOOLNOT: '!';
 BWNOT:   '~';

+ 99 - 97
modules/lang-painless/src/main/antlr/PainlessLexer.tokens

@@ -21,59 +21,60 @@ NEW=20
 TRY=21
 CATCH=22
 THROW=23
-BOOLNOT=24
-BWNOT=25
-MUL=26
-DIV=27
-REM=28
-ADD=29
-SUB=30
-LSH=31
-RSH=32
-USH=33
-LT=34
-LTE=35
-GT=36
-GTE=37
-EQ=38
-EQR=39
-NE=40
-NER=41
-BWAND=42
-XOR=43
-BWOR=44
-BOOLAND=45
-BOOLOR=46
-COND=47
-COLON=48
-REF=49
-ARROW=50
-INCR=51
-DECR=52
-ASSIGN=53
-AADD=54
-ASUB=55
-AMUL=56
-ADIV=57
-AREM=58
-AAND=59
-AXOR=60
-AOR=61
-ALSH=62
-ARSH=63
-AUSH=64
-OCTAL=65
-HEX=66
-INTEGER=67
-DECIMAL=68
-STRING=69
-TRUE=70
-FALSE=71
-NULL=72
-TYPE=73
-ID=74
-DOTINTEGER=75
-DOTID=76
+THIS=24
+BOOLNOT=25
+BWNOT=26
+MUL=27
+DIV=28
+REM=29
+ADD=30
+SUB=31
+LSH=32
+RSH=33
+USH=34
+LT=35
+LTE=36
+GT=37
+GTE=38
+EQ=39
+EQR=40
+NE=41
+NER=42
+BWAND=43
+XOR=44
+BWOR=45
+BOOLAND=46
+BOOLOR=47
+COND=48
+COLON=49
+REF=50
+ARROW=51
+INCR=52
+DECR=53
+ASSIGN=54
+AADD=55
+ASUB=56
+AMUL=57
+ADIV=58
+AREM=59
+AAND=60
+AXOR=61
+AOR=62
+ALSH=63
+ARSH=64
+AUSH=65
+OCTAL=66
+HEX=67
+INTEGER=68
+DECIMAL=69
+STRING=70
+TRUE=71
+FALSE=72
+NULL=73
+TYPE=74
+ID=75
+DOTINTEGER=76
+DOTID=77
 '{'=3
 '}'=4
 '['=5
@@ -95,47 +96,48 @@ DOTID=76
 'try'=21
 'catch'=22
 'throw'=23
-'!'=24
-'~'=25
-'*'=26
-'/'=27
-'%'=28
-'+'=29
-'-'=30
-'<<'=31
-'>>'=32
-'>>>'=33
-'<'=34
-'<='=35
-'>'=36
-'>='=37
-'=='=38
-'==='=39
-'!='=40
-'!=='=41
-'&'=42
-'^'=43
-'|'=44
-'&&'=45
-'||'=46
-'?'=47
-':'=48
-'::'=49
-'->'=50
-'++'=51
-'--'=52
-'='=53
-'+='=54
-'-='=55
-'*='=56
-'/='=57
-'%='=58
-'&='=59
-'^='=60
-'|='=61
-'<<='=62
-'>>='=63
-'>>>='=64
-'true'=70
-'false'=71
-'null'=72
+'this'=24
+'!'=25
+'~'=26
+'*'=27
+'/'=28
+'%'=29
+'+'=30
+'-'=31
+'<<'=32
+'>>'=33
+'>>>'=34
+'<'=35
+'<='=36
+'>'=37
+'>='=38
+'=='=39
+'==='=40
+'!='=41
+'!=='=42
+'&'=43
+'^'=44
+'|'=45
+'&&'=46
+'||'=47
+'?'=48
+':'=49
+'::'=50
+'->'=51
+'++'=52
+'--'=53
+'='=54
+'+='=55
+'-='=56
+'*='=57
+'/='=58
+'%='=59
+'&='=60
+'^='=61
+'|='=62
+'<<='=63
+'>>='=64
+'>>>='=65
+'true'=71
+'false'=72
+'null'=73

+ 2 - 2
modules/lang-painless/src/main/antlr/PainlessParser.g4

@@ -196,5 +196,5 @@ lamtype
 
 funcref
     : TYPE REF ( ID | NEW )
-    | ID REF ID
-    ;
+    | ( ID | THIS ) REF ID
+    ;

+ 99 - 97
modules/lang-painless/src/main/antlr/PainlessParser.tokens

@@ -21,59 +21,60 @@ NEW=20
 TRY=21
 CATCH=22
 THROW=23
-BOOLNOT=24
-BWNOT=25
-MUL=26
-DIV=27
-REM=28
-ADD=29
-SUB=30
-LSH=31
-RSH=32
-USH=33
-LT=34
-LTE=35
-GT=36
-GTE=37
-EQ=38
-EQR=39
-NE=40
-NER=41
-BWAND=42
-XOR=43
-BWOR=44
-BOOLAND=45
-BOOLOR=46
-COND=47
-COLON=48
-REF=49
-ARROW=50
-INCR=51
-DECR=52
-ASSIGN=53
-AADD=54
-ASUB=55
-AMUL=56
-ADIV=57
-AREM=58
-AAND=59
-AXOR=60
-AOR=61
-ALSH=62
-ARSH=63
-AUSH=64
-OCTAL=65
-HEX=66
-INTEGER=67
-DECIMAL=68
-STRING=69
-TRUE=70
-FALSE=71
-NULL=72
-TYPE=73
-ID=74
-DOTINTEGER=75
-DOTID=76
+THIS=24
+BOOLNOT=25
+BWNOT=26
+MUL=27
+DIV=28
+REM=29
+ADD=30
+SUB=31
+LSH=32
+RSH=33
+USH=34
+LT=35
+LTE=36
+GT=37
+GTE=38
+EQ=39
+EQR=40
+NE=41
+NER=42
+BWAND=43
+XOR=44
+BWOR=45
+BOOLAND=46
+BOOLOR=47
+COND=48
+COLON=49
+REF=50
+ARROW=51
+INCR=52
+DECR=53
+ASSIGN=54
+AADD=55
+ASUB=56
+AMUL=57
+ADIV=58
+AREM=59
+AAND=60
+AXOR=61
+AOR=62
+ALSH=63
+ARSH=64
+AUSH=65
+OCTAL=66
+HEX=67
+INTEGER=68
+DECIMAL=69
+STRING=70
+TRUE=71
+FALSE=72
+NULL=73
+TYPE=74
+ID=75
+DOTINTEGER=76
+DOTID=77
 '{'=3
 '}'=4
 '['=5
@@ -95,47 +96,48 @@ DOTID=76
 'try'=21
 'catch'=22
 'throw'=23
-'!'=24
-'~'=25
-'*'=26
-'/'=27
-'%'=28
-'+'=29
-'-'=30
-'<<'=31
-'>>'=32
-'>>>'=33
-'<'=34
-'<='=35
-'>'=36
-'>='=37
-'=='=38
-'==='=39
-'!='=40
-'!=='=41
-'&'=42
-'^'=43
-'|'=44
-'&&'=45
-'||'=46
-'?'=47
-':'=48
-'::'=49
-'->'=50
-'++'=51
-'--'=52
-'='=53
-'+='=54
-'-='=55
-'*='=56
-'/='=57
-'%='=58
-'&='=59
-'^='=60
-'|='=61
-'<<='=62
-'>>='=63
-'>>>='=64
-'true'=70
-'false'=71
-'null'=72
+'this'=24
+'!'=25
+'~'=26
+'*'=27
+'/'=28
+'%'=29
+'+'=30
+'-'=31
+'<<'=32
+'>>'=33
+'>>>'=34
+'<'=35
+'<='=36
+'>'=37
+'>='=38
+'=='=39
+'==='=40
+'!='=41
+'!=='=42
+'&'=43
+'^'=44
+'|'=45
+'&&'=46
+'||'=47
+'?'=48
+':'=49
+'::'=50
+'->'=51
+'++'=52
+'--'=53
+'='=54
+'+='=55
+'-='=56
+'*='=57
+'/='=58
+'%='=59
+'&='=60
+'^='=61
+'|='=62
+'<<='=63
+'>>='=64
+'>>>='=65
+'true'=71
+'false'=72
+'null'=73

+ 32 - 9
modules/lang-painless/src/main/java/org/elasticsearch/painless/Def.java

@@ -23,7 +23,6 @@ import org.elasticsearch.painless.Definition.Method;
 import org.elasticsearch.painless.Definition.RuntimeClass;
 
 import java.lang.invoke.CallSite;
-import java.lang.invoke.LambdaConversionException;
 import java.lang.invoke.LambdaMetafactory;
 import java.lang.invoke.MethodHandle;
 import java.lang.invoke.MethodHandles;
@@ -219,11 +218,11 @@ public final class Def {
      * @param args args passed to callsite
      * @param recipe bitset marking functional parameters
      * @return pointer to matching method to invoke. never returns null.
-     * @throws LambdaConversionException if a method reference cannot be converted to an functional interface
      * @throws IllegalArgumentException if no matching whitelisted method was found.
+     * @throws Throwable if a method reference cannot be converted to an functional interface
      */
      static MethodHandle lookupMethod(Lookup lookup, MethodType callSiteType, 
-             Class<?> receiverClass, String name, Object args[], long recipe) throws LambdaConversionException {
+             Class<?> receiverClass, String name, Object args[], long recipe) throws Throwable {
          // simple case: no lambdas
          if (recipe == 0) {
              return lookupMethodInternal(receiverClass, name, args.length - 1).handle;
@@ -302,7 +301,7 @@ public final class Def {
       * so we simply need to lookup the matching implementation method based on receiver type.
       */
      static MethodHandle lookupReference(Lookup lookup, String interfaceClass, 
-                                         Class<?> receiverClass, String name) throws LambdaConversionException {
+                                         Class<?> receiverClass, String name) throws Throwable {
          Definition.Type interfaceType = Definition.getType(interfaceClass);
          Method interfaceMethod = interfaceType.struct.getFunctionalMethod();
          if (interfaceMethod == null) {
@@ -313,12 +312,32 @@ public final class Def {
          return lookupReferenceInternal(lookup, interfaceType, implMethod.owner.name, implMethod.name, receiverClass);
      }
      
-     /** Returns a method handle to an implementation of clazz, given method reference signature 
-      * @throws LambdaConversionException if a method reference cannot be converted to an functional interface
-      */
+     /** Returns a method handle to an implementation of clazz, given method reference signature. */
      private static MethodHandle lookupReferenceInternal(Lookup lookup, Definition.Type clazz, String type,
-                                                         String call, Class<?>... captures) throws LambdaConversionException {
-         FunctionRef ref = new FunctionRef(clazz, type, call, captures);
+                                                         String call, Class<?>... captures) throws Throwable {
+         final FunctionRef ref;
+         if ("this".equals(type)) {
+             // user written method
+             Method interfaceMethod = clazz.struct.getFunctionalMethod();
+             if (interfaceMethod == null) {
+                 throw new IllegalArgumentException("Cannot convert function reference [" + type + "::" + call + "] " +
+                                                    "to [" + clazz.name + "], not a functional interface");
+             }
+             int arity = interfaceMethod.arguments.size() + captures.length;
+             final MethodHandle handle;
+             try {
+                 MethodHandle accessor = lookup.findStaticGetter(lookup.lookupClass(), 
+                                                                 getUserFunctionHandleFieldName(call, arity), 
+                                                                 MethodHandle.class);
+                 handle = (MethodHandle) accessor.invokeExact();
+             } catch (NoSuchFieldException | IllegalAccessException e) {
+                 throw new IllegalArgumentException("Unknown call [" + call + "] with [" + arity + "] arguments.");
+             }
+             ref = new FunctionRef(clazz, interfaceMethod, handle, captures);
+         } else {
+             // whitelist lookup
+             ref = new FunctionRef(clazz, type, call, captures);
+         }
          final CallSite callSite;
          if (ref.needsBridges()) {
              callSite = LambdaMetafactory.altMetafactory(lookup, 
@@ -342,6 +361,10 @@ public final class Def {
          return callSite.dynamicInvoker().asType(MethodType.methodType(clazz.clazz, captures));
      }
      
+     /** gets the field name used to lookup up the MethodHandle for a function. */
+     public static String getUserFunctionHandleFieldName(String name, int arity) {
+         return "handle$" + name + "$" + arity;
+     }
 
     /**
      * Looks up handle for a dynamic field getter (field load)

+ 41 - 0
modules/lang-painless/src/main/java/org/elasticsearch/painless/Definition.java

@@ -27,6 +27,7 @@ import java.io.InputStreamReader;
 import java.io.LineNumberReader;
 import java.lang.invoke.MethodHandle;
 import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
 import java.lang.reflect.Modifier;
 import java.nio.charset.StandardCharsets;
 import java.time.LocalDate;
@@ -198,6 +199,46 @@ public final class Definition {
             this.modifiers = modifiers;
             this.handle = handle;
         }
+        
+        /** 
+         * Returns MethodType for this method.
+         * <p>
+         * This works even for user-defined Methods (where the MethodHandle is null).
+         */
+        public MethodType getMethodType() {
+            // we have a methodhandle already (e.g. whitelisted class)
+            // just return its type
+            if (handle != null) {
+                return handle.type();
+            }
+            // otherwise compute it
+            final Class<?> params[];
+            final Class<?> returnValue;
+            if (Modifier.isStatic(modifiers)) {
+                // static method: straightforward copy
+                params = new Class<?>[arguments.size()];
+                for (int i = 0; i < arguments.size(); i++) {
+                    params[i] = arguments.get(i).clazz;
+                }
+                returnValue = rtn.clazz;
+            } else if ("<init>".equals(name)) {
+                // constructor: returns the owner class
+                params = new Class<?>[arguments.size()];
+                for (int i = 0; i < arguments.size(); i++) {
+                    params[i] = arguments.get(i).clazz;
+                }
+                returnValue = owner.clazz;
+            } else {
+                // virtual/interface method: add receiver class
+                params = new Class<?>[1 + arguments.size()];
+                params[0] = owner.clazz;
+                for (int i = 0; i < arguments.size(); i++) {
+                    params[i + 1] = arguments.get(i).clazz;
+                }
+                returnValue = rtn.clazz;
+            }
+            return MethodType.methodType(returnValue, params);
+        }
     }
 
     public static final class Field {

+ 77 - 38
modules/lang-painless/src/main/java/org/elasticsearch/painless/FunctionRef.java

@@ -49,14 +49,83 @@ public class FunctionRef {
     public final Handle implMethodASM;
     
     /**
-     * Creates a new FunctionRef.
+     * Creates a new FunctionRef, which will resolve {@code type::call} from the whitelist.
      * @param expected interface type to implement.
      * @param type the left hand side of a method reference expression
      * @param call the right hand side of a method reference expression
      * @param captures captured arguments
-     */
+     */    
     public FunctionRef(Definition.Type expected, String type, String call, Class<?>... captures) {
-        boolean isCtorReference = "new".equals(call);
+        this(expected, expected.struct.getFunctionalMethod(), lookup(expected, type, call, captures.length > 0), captures);
+    }
+
+    /**
+     * Creates a new FunctionRef (already resolved)
+     * @param expected interface type to implement
+     * @param method functional interface method
+     * @param impl implementation method
+     * @param captures captured arguments
+     */   
+    public FunctionRef(Definition.Type expected, Definition.Method method, Definition.Method impl, Class<?>... captures) {
+        // e.g. compareTo
+        invokedName = method.name;
+        // e.g. (Object)Comparator
+        invokedType = MethodType.methodType(expected.clazz, captures);
+        // e.g. (Object,Object)int
+        interfaceMethodType = method.getMethodType().dropParameterTypes(0, 1);
+
+        final int tag;
+        if ("<init>".equals(impl.name)) {
+            tag = Opcodes.H_NEWINVOKESPECIAL;
+        } else if (Modifier.isStatic(impl.modifiers)) {
+            tag = Opcodes.H_INVOKESTATIC;
+        } else if (impl.owner.clazz.isInterface()) {
+            tag = Opcodes.H_INVOKEINTERFACE;
+        } else {
+            tag = Opcodes.H_INVOKEVIRTUAL;
+        }
+        final String owner;
+        final boolean ownerIsInterface;
+        if (impl.owner == null) {
+            // owner == null: script class itself
+            ownerIsInterface = false;
+            owner = WriterConstants.CLASS_TYPE.getInternalName();
+        } else {
+            ownerIsInterface = impl.owner.clazz.isInterface();
+            owner = impl.owner.type.getInternalName();
+        }
+        implMethodASM = new Handle(tag, owner, impl.name, impl.method.getDescriptor(), ownerIsInterface);
+        implMethod = impl.handle;
+        
+        // remove any prepended captured arguments for the 'natural' signature.
+        samMethodType = impl.getMethodType().dropParameterTypes(0, captures.length);
+    }
+
+    /**
+     * Creates a new FunctionRef (low level). 
+     * <p>
+     * This will <b>not</b> set implMethodASM. It is for runtime use only.
+     */
+    public FunctionRef(Definition.Type expected, Definition.Method method, MethodHandle impl, Class<?>... captures) {
+        // e.g. compareTo
+        invokedName = method.name;
+        // e.g. (Object)Comparator
+        invokedType = MethodType.methodType(expected.clazz, captures);
+        // e.g. (Object,Object)int
+        interfaceMethodType = method.getMethodType().dropParameterTypes(0, 1);
+
+        implMethod = impl;
+        
+        implMethodASM = null;
+        
+        // remove any prepended captured arguments for the 'natural' signature.
+        samMethodType = impl.type().dropParameterTypes(0, captures.length);
+    }
+
+    /** 
+     * Looks up {@code type::call} from the whitelist, and returns a matching method.
+     */
+    private static Definition.Method lookup(Definition.Type expected, String type, String call, boolean receiverCaptured) {
         // check its really a functional interface
         // for e.g. Comparable
         Method method = expected.struct.getFunctionalMethod();
@@ -64,17 +133,12 @@ public class FunctionRef {
             throw new IllegalArgumentException("Cannot convert function reference [" + type + "::" + call + "] " +
                                                "to [" + expected.name + "], not a functional interface");
         }
-        // e.g. compareTo
-        invokedName = method.name;
-        // e.g. (Object)Comparator
-        invokedType = MethodType.methodType(expected.clazz, captures);
-        // e.g. (Object,Object)int
-        interfaceMethodType = method.handle.type().dropParameterTypes(0, 1);
+
         // lookup requested method
         Definition.Struct struct = Definition.getType(type).struct;
         final Definition.Method impl;
         // ctor ref
-        if (isCtorReference) {
+        if ("new".equals(call)) {
             impl = struct.constructors.get(new Definition.MethodKey("<init>", method.arguments.size()));
         } else {
             // look for a static impl first
@@ -82,7 +146,7 @@ public class FunctionRef {
             if (staticImpl == null) {
                 // otherwise a virtual impl
                 final int arity;
-                if (captures.length > 0) {
+                if (receiverCaptured) {
                     // receiver captured
                     arity = method.arguments.size();
                 } else {
@@ -98,34 +162,9 @@ public class FunctionRef {
             throw new IllegalArgumentException("Unknown reference [" + type + "::" + call + "] matching " +
                                                "[" + expected + "]");
         }
-        
-        final int tag;
-        if (isCtorReference) {
-            tag = Opcodes.H_NEWINVOKESPECIAL;
-        } else if (Modifier.isStatic(impl.modifiers)) {
-            tag = Opcodes.H_INVOKESTATIC;
-        } else {
-            tag = Opcodes.H_INVOKEVIRTUAL;
-        }
-        if (impl.owner.clazz.isInterface()) {
-            implMethodASM = new Handle(tag, struct.type.getInternalName(), impl.name, impl.method.getDescriptor());
-        } else {
-            implMethodASM = new Handle(tag, impl.owner.type.getInternalName(), impl.name, impl.method.getDescriptor());
-        }
-        implMethod = impl.handle;
-        if (isCtorReference) {
-            samMethodType = MethodType.methodType(interfaceMethodType.returnType(), impl.handle.type().parameterArray());
-        } else if (Modifier.isStatic(impl.modifiers)) {
-            samMethodType = impl.handle.type();
-        } else if (captures.length > 0) {
-            // drop the receiver, we capture it
-            samMethodType = impl.handle.type().dropParameterTypes(0, 1);
-        } else {
-            // ensure the receiver type is exact and not a superclass type
-            samMethodType = impl.handle.type().changeParameterType(0, struct.clazz);
-        }
+        return impl;
     }
-    
+
     /** Returns true if you should ask LambdaMetaFactory to construct a bridge for the interface signature */
     public boolean needsBridges() {
         // currently if the interface differs, we ask for a bridge, but maybe we should do smarter checking?

+ 7 - 11
modules/lang-painless/src/main/java/org/elasticsearch/painless/MethodWriter.java

@@ -87,7 +87,6 @@ import static org.elasticsearch.painless.WriterConstants.UTILITY_TYPE;
  * shared by the nodes of the Painless tree.
  */
 public final class MethodWriter extends GeneratorAdapter {
-    private final ClassWriter parent;
     private final BitSet statements;
 
     private final Deque<List<org.objectweb.asm.Type>> stringConcatArgs =
@@ -97,17 +96,9 @@ public final class MethodWriter extends GeneratorAdapter {
         super(Opcodes.ASM5, cw.visitMethod(access, method.getName(), method.getDescriptor(), null, null),
                 access, method.getName(), method.getDescriptor());
 
-        this.parent = cw;
         this.statements = statements;
     }
 
-    /**
-     * @return A new {@link MethodWriter} with the specified access and signature.
-     */
-    public MethodWriter newMethodWriter(int access, Method method) {
-        return new MethodWriter(access, method, parent, statements);
-    }
-
     /**
      * Marks a new statement boundary.
      * <p>
@@ -355,11 +346,16 @@ public final class MethodWriter extends GeneratorAdapter {
     }
 
     @Override
-    public void visitEnd() {
+    public void endMethod() {
         if (stringConcatArgs != null && !stringConcatArgs.isEmpty()) {
             throw new IllegalStateException("String concat bytecode not completed.");
         }
-        super.visitEnd();
+        super.endMethod();
+    }
+
+    @Override
+    public void visitEnd() {
+        throw new AssertionError("Should never call this method on MethodWriter, use endMethod() instead");
     }
 
 }

+ 7 - 3
modules/lang-painless/src/main/java/org/elasticsearch/painless/WriterConstants.java

@@ -28,6 +28,7 @@ import org.objectweb.asm.commons.Method;
 
 import java.lang.invoke.CallSite;
 import java.lang.invoke.LambdaMetafactory;
+import java.lang.invoke.MethodHandle;
 import java.lang.invoke.MethodHandles;
 import java.lang.invoke.MethodType;
 import java.util.BitSet;
@@ -46,6 +47,7 @@ public final class WriterConstants {
     public final static Type CLASS_TYPE        = Type.getObjectType(CLASS_NAME.replace('.', '/'));
 
     public final static Method CONSTRUCTOR = getAsmMethod(void.class, "<init>", String.class, String.class, BitSet.class);
+    public final static Method CLINIT      = getAsmMethod(void.class, "<clinit>");
     public final static Method EXECUTE     =
         getAsmMethod(Object.class, "execute", Map.class, Scorer.class, LeafDocLookup.class, Object.class);
 
@@ -65,13 +67,15 @@ public final class WriterConstants {
     public final static Type UTILITY_TYPE = Type.getType(Utility.class);
     public final static Method STRING_TO_CHAR = getAsmMethod(char.class, "StringTochar", String.class);
     public final static Method CHAR_TO_STRING = getAsmMethod(String.class, "charToString", char.class);
+    
+    public final static Type METHOD_HANDLE_TYPE = Type.getType(MethodHandle.class);
 
     /** dynamic callsite bootstrap signature */
     public final static MethodType DEF_BOOTSTRAP_TYPE =
         MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class, MethodType.class, int.class, Object[].class);
     public final static Handle DEF_BOOTSTRAP_HANDLE =
         new Handle(Opcodes.H_INVOKESTATIC, Type.getInternalName(DefBootstrap.class),
-            "bootstrap", DEF_BOOTSTRAP_TYPE.toMethodDescriptorString());
+            "bootstrap", DEF_BOOTSTRAP_TYPE.toMethodDescriptorString(), false);
 
     public final static Type DEF_UTIL_TYPE = Type.getType(Def.class);
     public final static Method DEF_TO_BOOLEAN         = getAsmMethod(boolean.class, "DefToboolean"       , Object.class);
@@ -114,7 +118,7 @@ public final class WriterConstants {
                                   MethodType.class, Object[].class);
     public final static Handle LAMBDA_BOOTSTRAP_HANDLE =
             new Handle(Opcodes.H_INVOKESTATIC, Type.getInternalName(LambdaMetafactory.class),
-                "altMetafactory", LAMBDA_BOOTSTRAP_TYPE.toMethodDescriptorString());
+                "altMetafactory", LAMBDA_BOOTSTRAP_TYPE.toMethodDescriptorString(), false);
 
     /** dynamic invokedynamic bootstrap for indy string concats (Java 9+) */
     public final static Handle INDY_STRING_CONCAT_BOOTSTRAP_HANDLE;
@@ -126,7 +130,7 @@ public final class WriterConstants {
             final MethodType type = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class, MethodType.class);
             // ensure it is there:
             MethodHandles.publicLookup().findStatic(factory, methodName, type);
-            bs = new Handle(Opcodes.H_INVOKESTATIC, Type.getInternalName(factory), methodName, type.toMethodDescriptorString());
+            bs = new Handle(Opcodes.H_INVOKESTATIC, Type.getInternalName(factory), methodName, type.toMethodDescriptorString(), false);
         } catch (ReflectiveOperationException e) {
             // not Java 9 - we set it null, so MethodWriter uses StringBuilder:
             bs = null;

+ 208 - 205
modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/PainlessLexer.java

@@ -22,14 +22,14 @@ class PainlessLexer extends Lexer {
   public static final int
     WS=1, COMMENT=2, LBRACK=3, RBRACK=4, LBRACE=5, RBRACE=6, LP=7, RP=8, DOT=9, 
     COMMA=10, SEMICOLON=11, IF=12, ELSE=13, WHILE=14, DO=15, FOR=16, CONTINUE=17, 
-    BREAK=18, RETURN=19, NEW=20, TRY=21, CATCH=22, THROW=23, BOOLNOT=24, BWNOT=25, 
-    MUL=26, DIV=27, REM=28, ADD=29, SUB=30, LSH=31, RSH=32, USH=33, LT=34, 
-    LTE=35, GT=36, GTE=37, EQ=38, EQR=39, NE=40, NER=41, BWAND=42, XOR=43, 
-    BWOR=44, BOOLAND=45, BOOLOR=46, COND=47, COLON=48, REF=49, ARROW=50, INCR=51, 
-    DECR=52, ASSIGN=53, AADD=54, ASUB=55, AMUL=56, ADIV=57, AREM=58, AAND=59, 
-    AXOR=60, AOR=61, ALSH=62, ARSH=63, AUSH=64, OCTAL=65, HEX=66, INTEGER=67, 
-    DECIMAL=68, STRING=69, TRUE=70, FALSE=71, NULL=72, TYPE=73, ID=74, DOTINTEGER=75, 
-    DOTID=76;
+    BREAK=18, RETURN=19, NEW=20, TRY=21, CATCH=22, THROW=23, THIS=24, BOOLNOT=25, 
+    BWNOT=26, MUL=27, DIV=28, REM=29, ADD=30, SUB=31, LSH=32, RSH=33, USH=34, 
+    LT=35, LTE=36, GT=37, GTE=38, EQ=39, EQR=40, NE=41, NER=42, BWAND=43, 
+    XOR=44, BWOR=45, BOOLAND=46, BOOLOR=47, COND=48, COLON=49, REF=50, ARROW=51, 
+    INCR=52, DECR=53, ASSIGN=54, AADD=55, ASUB=56, AMUL=57, ADIV=58, AREM=59, 
+    AAND=60, AXOR=61, AOR=62, ALSH=63, ARSH=64, AUSH=65, OCTAL=66, HEX=67, 
+    INTEGER=68, DECIMAL=69, STRING=70, TRUE=71, FALSE=72, NULL=73, TYPE=74, 
+    ID=75, DOTINTEGER=76, DOTID=77;
   public static final int AFTER_DOT = 1;
   public static String[] modeNames = {
     "DEFAULT_MODE", "AFTER_DOT"
@@ -38,35 +38,35 @@ class PainlessLexer extends Lexer {
   public static final String[] ruleNames = {
     "WS", "COMMENT", "LBRACK", "RBRACK", "LBRACE", "RBRACE", "LP", "RP", "DOT", 
     "COMMA", "SEMICOLON", "IF", "ELSE", "WHILE", "DO", "FOR", "CONTINUE", 
-    "BREAK", "RETURN", "NEW", "TRY", "CATCH", "THROW", "BOOLNOT", "BWNOT", 
-    "MUL", "DIV", "REM", "ADD", "SUB", "LSH", "RSH", "USH", "LT", "LTE", "GT", 
-    "GTE", "EQ", "EQR", "NE", "NER", "BWAND", "XOR", "BWOR", "BOOLAND", "BOOLOR", 
-    "COND", "COLON", "REF", "ARROW", "INCR", "DECR", "ASSIGN", "AADD", "ASUB", 
-    "AMUL", "ADIV", "AREM", "AAND", "AXOR", "AOR", "ALSH", "ARSH", "AUSH", 
-    "OCTAL", "HEX", "INTEGER", "DECIMAL", "STRING", "TRUE", "FALSE", "NULL", 
-    "TYPE", "ID", "DOTINTEGER", "DOTID"
+    "BREAK", "RETURN", "NEW", "TRY", "CATCH", "THROW", "THIS", "BOOLNOT", 
+    "BWNOT", "MUL", "DIV", "REM", "ADD", "SUB", "LSH", "RSH", "USH", "LT", 
+    "LTE", "GT", "GTE", "EQ", "EQR", "NE", "NER", "BWAND", "XOR", "BWOR", 
+    "BOOLAND", "BOOLOR", "COND", "COLON", "REF", "ARROW", "INCR", "DECR", 
+    "ASSIGN", "AADD", "ASUB", "AMUL", "ADIV", "AREM", "AAND", "AXOR", "AOR", 
+    "ALSH", "ARSH", "AUSH", "OCTAL", "HEX", "INTEGER", "DECIMAL", "STRING", 
+    "TRUE", "FALSE", "NULL", "TYPE", "ID", "DOTINTEGER", "DOTID"
   };
 
   private static final String[] _LITERAL_NAMES = {
     null, null, null, "'{'", "'}'", "'['", "']'", "'('", "')'", "'.'", "','", 
     "';'", "'if'", "'else'", "'while'", "'do'", "'for'", "'continue'", "'break'", 
-    "'return'", "'new'", "'try'", "'catch'", "'throw'", "'!'", "'~'", "'*'", 
-    "'/'", "'%'", "'+'", "'-'", "'<<'", "'>>'", "'>>>'", "'<'", "'<='", "'>'", 
-    "'>='", "'=='", "'==='", "'!='", "'!=='", "'&'", "'^'", "'|'", "'&&'", 
-    "'||'", "'?'", "':'", "'::'", "'->'", "'++'", "'--'", "'='", "'+='", "'-='", 
-    "'*='", "'/='", "'%='", "'&='", "'^='", "'|='", "'<<='", "'>>='", "'>>>='", 
-    null, null, null, null, null, "'true'", "'false'", "'null'"
+    "'return'", "'new'", "'try'", "'catch'", "'throw'", "'this'", "'!'", "'~'", 
+    "'*'", "'/'", "'%'", "'+'", "'-'", "'<<'", "'>>'", "'>>>'", "'<'", "'<='", 
+    "'>'", "'>='", "'=='", "'==='", "'!='", "'!=='", "'&'", "'^'", "'|'", 
+    "'&&'", "'||'", "'?'", "':'", "'::'", "'->'", "'++'", "'--'", "'='", "'+='", 
+    "'-='", "'*='", "'/='", "'%='", "'&='", "'^='", "'|='", "'<<='", "'>>='", 
+    "'>>>='", null, null, null, null, null, "'true'", "'false'", "'null'"
   };
   private static final String[] _SYMBOLIC_NAMES = {
     null, "WS", "COMMENT", "LBRACK", "RBRACK", "LBRACE", "RBRACE", "LP", "RP", 
     "DOT", "COMMA", "SEMICOLON", "IF", "ELSE", "WHILE", "DO", "FOR", "CONTINUE", 
-    "BREAK", "RETURN", "NEW", "TRY", "CATCH", "THROW", "BOOLNOT", "BWNOT", 
-    "MUL", "DIV", "REM", "ADD", "SUB", "LSH", "RSH", "USH", "LT", "LTE", "GT", 
-    "GTE", "EQ", "EQR", "NE", "NER", "BWAND", "XOR", "BWOR", "BOOLAND", "BOOLOR", 
-    "COND", "COLON", "REF", "ARROW", "INCR", "DECR", "ASSIGN", "AADD", "ASUB", 
-    "AMUL", "ADIV", "AREM", "AAND", "AXOR", "AOR", "ALSH", "ARSH", "AUSH", 
-    "OCTAL", "HEX", "INTEGER", "DECIMAL", "STRING", "TRUE", "FALSE", "NULL", 
-    "TYPE", "ID", "DOTINTEGER", "DOTID"
+    "BREAK", "RETURN", "NEW", "TRY", "CATCH", "THROW", "THIS", "BOOLNOT", 
+    "BWNOT", "MUL", "DIV", "REM", "ADD", "SUB", "LSH", "RSH", "USH", "LT", 
+    "LTE", "GT", "GTE", "EQ", "EQR", "NE", "NER", "BWAND", "XOR", "BWOR", 
+    "BOOLAND", "BOOLOR", "COND", "COLON", "REF", "ARROW", "INCR", "DECR", 
+    "ASSIGN", "AADD", "ASUB", "AMUL", "ADIV", "AREM", "AAND", "AXOR", "AOR", 
+    "ALSH", "ARSH", "AUSH", "OCTAL", "HEX", "INTEGER", "DECIMAL", "STRING", 
+    "TRUE", "FALSE", "NULL", "TYPE", "ID", "DOTINTEGER", "DOTID"
   };
   public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);
 
@@ -125,7 +125,7 @@ class PainlessLexer extends Lexer {
   @Override
   public boolean sempred(RuleContext _localctx, int ruleIndex, int predIndex) {
     switch (ruleIndex) {
-    case 72:
+    case 73:
       return TYPE_sempred((RuleContext)_localctx, predIndex);
     }
     return true;
@@ -139,7 +139,7 @@ class PainlessLexer extends Lexer {
   }
 
   public static final String _serializedATN =
-    "\3\u0430\ud6d1\u8206\uad2d\u4417\uaef1\u8d80\uaadd\2N\u0213\b\1\b\1\4"+
+    "\3\u0430\ud6d1\u8206\uad2d\u4417\uaef1\u8d80\uaadd\2O\u021a\b\1\b\1\4"+
     "\2\t\2\4\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\4\n\t\n"+
     "\4\13\t\13\4\f\t\f\4\r\t\r\4\16\t\16\4\17\t\17\4\20\t\20\4\21\t\21\4\22"+
     "\t\22\4\23\t\23\4\24\t\24\4\25\t\25\4\26\t\26\4\27\t\27\4\30\t\30\4\31"+
@@ -148,181 +148,184 @@ class PainlessLexer extends Lexer {
     "+\4,\t,\4-\t-\4.\t.\4/\t/\4\60\t\60\4\61\t\61\4\62\t\62\4\63\t\63\4\64"+
     "\t\64\4\65\t\65\4\66\t\66\4\67\t\67\48\t8\49\t9\4:\t:\4;\t;\4<\t<\4=\t"+
     "=\4>\t>\4?\t?\4@\t@\4A\tA\4B\tB\4C\tC\4D\tD\4E\tE\4F\tF\4G\tG\4H\tH\4"+
-    "I\tI\4J\tJ\4K\tK\4L\tL\4M\tM\3\2\6\2\u009e\n\2\r\2\16\2\u009f\3\2\3\2"+
-    "\3\3\3\3\3\3\3\3\7\3\u00a8\n\3\f\3\16\3\u00ab\13\3\3\3\3\3\3\3\3\3\3\3"+
-    "\7\3\u00b2\n\3\f\3\16\3\u00b5\13\3\3\3\3\3\5\3\u00b9\n\3\3\3\3\3\3\4\3"+
-    "\4\3\5\3\5\3\6\3\6\3\7\3\7\3\b\3\b\3\t\3\t\3\n\3\n\3\n\3\n\3\13\3\13\3"+
-    "\f\3\f\3\r\3\r\3\r\3\16\3\16\3\16\3\16\3\16\3\17\3\17\3\17\3\17\3\17\3"+
-    "\17\3\20\3\20\3\20\3\21\3\21\3\21\3\21\3\22\3\22\3\22\3\22\3\22\3\22\3"+
-    "\22\3\22\3\22\3\23\3\23\3\23\3\23\3\23\3\23\3\24\3\24\3\24\3\24\3\24\3"+
-    "\24\3\24\3\25\3\25\3\25\3\25\3\26\3\26\3\26\3\26\3\27\3\27\3\27\3\27\3"+
-    "\27\3\27\3\30\3\30\3\30\3\30\3\30\3\30\3\31\3\31\3\32\3\32\3\33\3\33\3"+
-    "\34\3\34\3\35\3\35\3\36\3\36\3\37\3\37\3 \3 \3 \3!\3!\3!\3\"\3\"\3\"\3"+
-    "\"\3#\3#\3$\3$\3$\3%\3%\3&\3&\3&\3\'\3\'\3\'\3(\3(\3(\3(\3)\3)\3)\3*\3"+
-    "*\3*\3*\3+\3+\3,\3,\3-\3-\3.\3.\3.\3/\3/\3/\3\60\3\60\3\61\3\61\3\62\3"+
-    "\62\3\62\3\63\3\63\3\63\3\64\3\64\3\64\3\65\3\65\3\65\3\66\3\66\3\67\3"+
-    "\67\3\67\38\38\38\39\39\39\3:\3:\3:\3;\3;\3;\3<\3<\3<\3=\3=\3=\3>\3>\3"+
-    ">\3?\3?\3?\3?\3@\3@\3@\3@\3A\3A\3A\3A\3A\3B\3B\6B\u0185\nB\rB\16B\u0186"+
-    "\3B\5B\u018a\nB\3C\3C\3C\6C\u018f\nC\rC\16C\u0190\3C\5C\u0194\nC\3D\3"+
-    "D\3D\7D\u0199\nD\fD\16D\u019c\13D\5D\u019e\nD\3D\5D\u01a1\nD\3E\3E\3E"+
-    "\7E\u01a6\nE\fE\16E\u01a9\13E\5E\u01ab\nE\3E\3E\6E\u01af\nE\rE\16E\u01b0"+
-    "\5E\u01b3\nE\3E\3E\5E\u01b7\nE\3E\6E\u01ba\nE\rE\16E\u01bb\5E\u01be\n"+
-    "E\3E\5E\u01c1\nE\3F\3F\3F\3F\3F\3F\7F\u01c9\nF\fF\16F\u01cc\13F\3F\3F"+
-    "\3F\3F\3F\3F\3F\7F\u01d5\nF\fF\16F\u01d8\13F\3F\5F\u01db\nF\3G\3G\3G\3"+
-    "G\3G\3H\3H\3H\3H\3H\3H\3I\3I\3I\3I\3I\3J\3J\3J\3J\7J\u01f1\nJ\fJ\16J\u01f4"+
-    "\13J\3J\3J\3K\3K\7K\u01fa\nK\fK\16K\u01fd\13K\3L\3L\3L\7L\u0202\nL\fL"+
-    "\16L\u0205\13L\5L\u0207\nL\3L\3L\3M\3M\7M\u020d\nM\fM\16M\u0210\13M\3"+
-    "M\3M\6\u00a9\u00b3\u01ca\u01d6\2N\4\3\6\4\b\5\n\6\f\7\16\b\20\t\22\n\24"+
-    "\13\26\f\30\r\32\16\34\17\36\20 \21\"\22$\23&\24(\25*\26,\27.\30\60\31"+
-    "\62\32\64\33\66\348\35:\36<\37> @!B\"D#F$H%J&L\'N(P)R*T+V,X-Z.\\/^\60"+
-    "`\61b\62d\63f\64h\65j\66l\67n8p9r:t;v<x=z>|?~@\u0080A\u0082B\u0084C\u0086"+
-    "D\u0088E\u008aF\u008cG\u008eH\u0090I\u0092J\u0094K\u0096L\u0098M\u009a"+
-    "N\4\2\3\21\5\2\13\f\17\17\"\"\4\2\f\f\17\17\3\2\629\4\2NNnn\4\2ZZzz\5"+
-    "\2\62;CHch\3\2\63;\3\2\62;\b\2FFHHNNffhhnn\4\2GGgg\4\2--//\4\2HHhh\4\2"+
-    "$$^^\5\2C\\aac|\6\2\62;C\\aac|\u0230\2\4\3\2\2\2\2\6\3\2\2\2\2\b\3\2\2"+
-    "\2\2\n\3\2\2\2\2\f\3\2\2\2\2\16\3\2\2\2\2\20\3\2\2\2\2\22\3\2\2\2\2\24"+
-    "\3\2\2\2\2\26\3\2\2\2\2\30\3\2\2\2\2\32\3\2\2\2\2\34\3\2\2\2\2\36\3\2"+
-    "\2\2\2 \3\2\2\2\2\"\3\2\2\2\2$\3\2\2\2\2&\3\2\2\2\2(\3\2\2\2\2*\3\2\2"+
-    "\2\2,\3\2\2\2\2.\3\2\2\2\2\60\3\2\2\2\2\62\3\2\2\2\2\64\3\2\2\2\2\66\3"+
-    "\2\2\2\28\3\2\2\2\2:\3\2\2\2\2<\3\2\2\2\2>\3\2\2\2\2@\3\2\2\2\2B\3\2\2"+
-    "\2\2D\3\2\2\2\2F\3\2\2\2\2H\3\2\2\2\2J\3\2\2\2\2L\3\2\2\2\2N\3\2\2\2\2"+
-    "P\3\2\2\2\2R\3\2\2\2\2T\3\2\2\2\2V\3\2\2\2\2X\3\2\2\2\2Z\3\2\2\2\2\\\3"+
-    "\2\2\2\2^\3\2\2\2\2`\3\2\2\2\2b\3\2\2\2\2d\3\2\2\2\2f\3\2\2\2\2h\3\2\2"+
-    "\2\2j\3\2\2\2\2l\3\2\2\2\2n\3\2\2\2\2p\3\2\2\2\2r\3\2\2\2\2t\3\2\2\2\2"+
-    "v\3\2\2\2\2x\3\2\2\2\2z\3\2\2\2\2|\3\2\2\2\2~\3\2\2\2\2\u0080\3\2\2\2"+
-    "\2\u0082\3\2\2\2\2\u0084\3\2\2\2\2\u0086\3\2\2\2\2\u0088\3\2\2\2\2\u008a"+
-    "\3\2\2\2\2\u008c\3\2\2\2\2\u008e\3\2\2\2\2\u0090\3\2\2\2\2\u0092\3\2\2"+
-    "\2\2\u0094\3\2\2\2\2\u0096\3\2\2\2\3\u0098\3\2\2\2\3\u009a\3\2\2\2\4\u009d"+
-    "\3\2\2\2\6\u00b8\3\2\2\2\b\u00bc\3\2\2\2\n\u00be\3\2\2\2\f\u00c0\3\2\2"+
-    "\2\16\u00c2\3\2\2\2\20\u00c4\3\2\2\2\22\u00c6\3\2\2\2\24\u00c8\3\2\2\2"+
-    "\26\u00cc\3\2\2\2\30\u00ce\3\2\2\2\32\u00d0\3\2\2\2\34\u00d3\3\2\2\2\36"+
-    "\u00d8\3\2\2\2 \u00de\3\2\2\2\"\u00e1\3\2\2\2$\u00e5\3\2\2\2&\u00ee\3"+
-    "\2\2\2(\u00f4\3\2\2\2*\u00fb\3\2\2\2,\u00ff\3\2\2\2.\u0103\3\2\2\2\60"+
-    "\u0109\3\2\2\2\62\u010f\3\2\2\2\64\u0111\3\2\2\2\66\u0113\3\2\2\28\u0115"+
-    "\3\2\2\2:\u0117\3\2\2\2<\u0119\3\2\2\2>\u011b\3\2\2\2@\u011d\3\2\2\2B"+
-    "\u0120\3\2\2\2D\u0123\3\2\2\2F\u0127\3\2\2\2H\u0129\3\2\2\2J\u012c\3\2"+
-    "\2\2L\u012e\3\2\2\2N\u0131\3\2\2\2P\u0134\3\2\2\2R\u0138\3\2\2\2T\u013b"+
-    "\3\2\2\2V\u013f\3\2\2\2X\u0141\3\2\2\2Z\u0143\3\2\2\2\\\u0145\3\2\2\2"+
-    "^\u0148\3\2\2\2`\u014b\3\2\2\2b\u014d\3\2\2\2d\u014f\3\2\2\2f\u0152\3"+
-    "\2\2\2h\u0155\3\2\2\2j\u0158\3\2\2\2l\u015b\3\2\2\2n\u015d\3\2\2\2p\u0160"+
-    "\3\2\2\2r\u0163\3\2\2\2t\u0166\3\2\2\2v\u0169\3\2\2\2x\u016c\3\2\2\2z"+
-    "\u016f\3\2\2\2|\u0172\3\2\2\2~\u0175\3\2\2\2\u0080\u0179\3\2\2\2\u0082"+
-    "\u017d\3\2\2\2\u0084\u0182\3\2\2\2\u0086\u018b\3\2\2\2\u0088\u019d\3\2"+
-    "\2\2\u008a\u01aa\3\2\2\2\u008c\u01da\3\2\2\2\u008e\u01dc\3\2\2\2\u0090"+
-    "\u01e1\3\2\2\2\u0092\u01e7\3\2\2\2\u0094\u01ec\3\2\2\2\u0096\u01f7\3\2"+
-    "\2\2\u0098\u0206\3\2\2\2\u009a\u020a\3\2\2\2\u009c\u009e\t\2\2\2\u009d"+
-    "\u009c\3\2\2\2\u009e\u009f\3\2\2\2\u009f\u009d\3\2\2\2\u009f\u00a0\3\2"+
-    "\2\2\u00a0\u00a1\3\2\2\2\u00a1\u00a2\b\2\2\2\u00a2\5\3\2\2\2\u00a3\u00a4"+
-    "\7\61\2\2\u00a4\u00a5\7\61\2\2\u00a5\u00a9\3\2\2\2\u00a6\u00a8\13\2\2"+
-    "\2\u00a7\u00a6\3\2\2\2\u00a8\u00ab\3\2\2\2\u00a9\u00aa\3\2\2\2\u00a9\u00a7"+
-    "\3\2\2\2\u00aa\u00ac\3\2\2\2\u00ab\u00a9\3\2\2\2\u00ac\u00b9\t\3\2\2\u00ad"+
-    "\u00ae\7\61\2\2\u00ae\u00af\7,\2\2\u00af\u00b3\3\2\2\2\u00b0\u00b2\13"+
-    "\2\2\2\u00b1\u00b0\3\2\2\2\u00b2\u00b5\3\2\2\2\u00b3\u00b4\3\2\2\2\u00b3"+
-    "\u00b1\3\2\2\2\u00b4\u00b6\3\2\2\2\u00b5\u00b3\3\2\2\2\u00b6\u00b7\7,"+
-    "\2\2\u00b7\u00b9\7\61\2\2\u00b8\u00a3\3\2\2\2\u00b8\u00ad\3\2\2\2\u00b9"+
-    "\u00ba\3\2\2\2\u00ba\u00bb\b\3\2\2\u00bb\7\3\2\2\2\u00bc\u00bd\7}\2\2"+
-    "\u00bd\t\3\2\2\2\u00be\u00bf\7\177\2\2\u00bf\13\3\2\2\2\u00c0\u00c1\7"+
-    "]\2\2\u00c1\r\3\2\2\2\u00c2\u00c3\7_\2\2\u00c3\17\3\2\2\2\u00c4\u00c5"+
-    "\7*\2\2\u00c5\21\3\2\2\2\u00c6\u00c7\7+\2\2\u00c7\23\3\2\2\2\u00c8\u00c9"+
-    "\7\60\2\2\u00c9\u00ca\3\2\2\2\u00ca\u00cb\b\n\3\2\u00cb\25\3\2\2\2\u00cc"+
-    "\u00cd\7.\2\2\u00cd\27\3\2\2\2\u00ce\u00cf\7=\2\2\u00cf\31\3\2\2\2\u00d0"+
-    "\u00d1\7k\2\2\u00d1\u00d2\7h\2\2\u00d2\33\3\2\2\2\u00d3\u00d4\7g\2\2\u00d4"+
-    "\u00d5\7n\2\2\u00d5\u00d6\7u\2\2\u00d6\u00d7\7g\2\2\u00d7\35\3\2\2\2\u00d8"+
-    "\u00d9\7y\2\2\u00d9\u00da\7j\2\2\u00da\u00db\7k\2\2\u00db\u00dc\7n\2\2"+
-    "\u00dc\u00dd\7g\2\2\u00dd\37\3\2\2\2\u00de\u00df\7f\2\2\u00df\u00e0\7"+
-    "q\2\2\u00e0!\3\2\2\2\u00e1\u00e2\7h\2\2\u00e2\u00e3\7q\2\2\u00e3\u00e4"+
-    "\7t\2\2\u00e4#\3\2\2\2\u00e5\u00e6\7e\2\2\u00e6\u00e7\7q\2\2\u00e7\u00e8"+
-    "\7p\2\2\u00e8\u00e9\7v\2\2\u00e9\u00ea\7k\2\2\u00ea\u00eb\7p\2\2\u00eb"+
-    "\u00ec\7w\2\2\u00ec\u00ed\7g\2\2\u00ed%\3\2\2\2\u00ee\u00ef\7d\2\2\u00ef"+
-    "\u00f0\7t\2\2\u00f0\u00f1\7g\2\2\u00f1\u00f2\7c\2\2\u00f2\u00f3\7m\2\2"+
-    "\u00f3\'\3\2\2\2\u00f4\u00f5\7t\2\2\u00f5\u00f6\7g\2\2\u00f6\u00f7\7v"+
-    "\2\2\u00f7\u00f8\7w\2\2\u00f8\u00f9\7t\2\2\u00f9\u00fa\7p\2\2\u00fa)\3"+
-    "\2\2\2\u00fb\u00fc\7p\2\2\u00fc\u00fd\7g\2\2\u00fd\u00fe\7y\2\2\u00fe"+
-    "+\3\2\2\2\u00ff\u0100\7v\2\2\u0100\u0101\7t\2\2\u0101\u0102\7{\2\2\u0102"+
-    "-\3\2\2\2\u0103\u0104\7e\2\2\u0104\u0105\7c\2\2\u0105\u0106\7v\2\2\u0106"+
-    "\u0107\7e\2\2\u0107\u0108\7j\2\2\u0108/\3\2\2\2\u0109\u010a\7v\2\2\u010a"+
-    "\u010b\7j\2\2\u010b\u010c\7t\2\2\u010c\u010d\7q\2\2\u010d\u010e\7y\2\2"+
-    "\u010e\61\3\2\2\2\u010f\u0110\7#\2\2\u0110\63\3\2\2\2\u0111\u0112\7\u0080"+
-    "\2\2\u0112\65\3\2\2\2\u0113\u0114\7,\2\2\u0114\67\3\2\2\2\u0115\u0116"+
-    "\7\61\2\2\u01169\3\2\2\2\u0117\u0118\7\'\2\2\u0118;\3\2\2\2\u0119\u011a"+
-    "\7-\2\2\u011a=\3\2\2\2\u011b\u011c\7/\2\2\u011c?\3\2\2\2\u011d\u011e\7"+
-    ">\2\2\u011e\u011f\7>\2\2\u011fA\3\2\2\2\u0120\u0121\7@\2\2\u0121\u0122"+
-    "\7@\2\2\u0122C\3\2\2\2\u0123\u0124\7@\2\2\u0124\u0125\7@\2\2\u0125\u0126"+
-    "\7@\2\2\u0126E\3\2\2\2\u0127\u0128\7>\2\2\u0128G\3\2\2\2\u0129\u012a\7"+
-    ">\2\2\u012a\u012b\7?\2\2\u012bI\3\2\2\2\u012c\u012d\7@\2\2\u012dK\3\2"+
-    "\2\2\u012e\u012f\7@\2\2\u012f\u0130\7?\2\2\u0130M\3\2\2\2\u0131\u0132"+
-    "\7?\2\2\u0132\u0133\7?\2\2\u0133O\3\2\2\2\u0134\u0135\7?\2\2\u0135\u0136"+
-    "\7?\2\2\u0136\u0137\7?\2\2\u0137Q\3\2\2\2\u0138\u0139\7#\2\2\u0139\u013a"+
-    "\7?\2\2\u013aS\3\2\2\2\u013b\u013c\7#\2\2\u013c\u013d\7?\2\2\u013d\u013e"+
-    "\7?\2\2\u013eU\3\2\2\2\u013f\u0140\7(\2\2\u0140W\3\2\2\2\u0141\u0142\7"+
-    "`\2\2\u0142Y\3\2\2\2\u0143\u0144\7~\2\2\u0144[\3\2\2\2\u0145\u0146\7("+
-    "\2\2\u0146\u0147\7(\2\2\u0147]\3\2\2\2\u0148\u0149\7~\2\2\u0149\u014a"+
-    "\7~\2\2\u014a_\3\2\2\2\u014b\u014c\7A\2\2\u014ca\3\2\2\2\u014d\u014e\7"+
-    "<\2\2\u014ec\3\2\2\2\u014f\u0150\7<\2\2\u0150\u0151\7<\2\2\u0151e\3\2"+
-    "\2\2\u0152\u0153\7/\2\2\u0153\u0154\7@\2\2\u0154g\3\2\2\2\u0155\u0156"+
-    "\7-\2\2\u0156\u0157\7-\2\2\u0157i\3\2\2\2\u0158\u0159\7/\2\2\u0159\u015a"+
-    "\7/\2\2\u015ak\3\2\2\2\u015b\u015c\7?\2\2\u015cm\3\2\2\2\u015d\u015e\7"+
-    "-\2\2\u015e\u015f\7?\2\2\u015fo\3\2\2\2\u0160\u0161\7/\2\2\u0161\u0162"+
-    "\7?\2\2\u0162q\3\2\2\2\u0163\u0164\7,\2\2\u0164\u0165\7?\2\2\u0165s\3"+
-    "\2\2\2\u0166\u0167\7\61\2\2\u0167\u0168\7?\2\2\u0168u\3\2\2\2\u0169\u016a"+
-    "\7\'\2\2\u016a\u016b\7?\2\2\u016bw\3\2\2\2\u016c\u016d\7(\2\2\u016d\u016e"+
-    "\7?\2\2\u016ey\3\2\2\2\u016f\u0170\7`\2\2\u0170\u0171\7?\2\2\u0171{\3"+
-    "\2\2\2\u0172\u0173\7~\2\2\u0173\u0174\7?\2\2\u0174}\3\2\2\2\u0175\u0176"+
-    "\7>\2\2\u0176\u0177\7>\2\2\u0177\u0178\7?\2\2\u0178\177\3\2\2\2\u0179"+
-    "\u017a\7@\2\2\u017a\u017b\7@\2\2\u017b\u017c\7?\2\2\u017c\u0081\3\2\2"+
-    "\2\u017d\u017e\7@\2\2\u017e\u017f\7@\2\2\u017f\u0180\7@\2\2\u0180\u0181"+
-    "\7?\2\2\u0181\u0083\3\2\2\2\u0182\u0184\7\62\2\2\u0183\u0185\t\4\2\2\u0184"+
-    "\u0183\3\2\2\2\u0185\u0186\3\2\2\2\u0186\u0184\3\2\2\2\u0186\u0187\3\2"+
-    "\2\2\u0187\u0189\3\2\2\2\u0188\u018a\t\5\2\2\u0189\u0188\3\2\2\2\u0189"+
-    "\u018a\3\2\2\2\u018a\u0085\3\2\2\2\u018b\u018c\7\62\2\2\u018c\u018e\t"+
-    "\6\2\2\u018d\u018f\t\7\2\2\u018e\u018d\3\2\2\2\u018f\u0190\3\2\2\2\u0190"+
-    "\u018e\3\2\2\2\u0190\u0191\3\2\2\2\u0191\u0193\3\2\2\2\u0192\u0194\t\5"+
-    "\2\2\u0193\u0192\3\2\2\2\u0193\u0194\3\2\2\2\u0194\u0087\3\2\2\2\u0195"+
-    "\u019e\7\62\2\2\u0196\u019a\t\b\2\2\u0197\u0199\t\t\2\2\u0198\u0197\3"+
-    "\2\2\2\u0199\u019c\3\2\2\2\u019a\u0198\3\2\2\2\u019a\u019b\3\2\2\2\u019b"+
-    "\u019e\3\2\2\2\u019c\u019a\3\2\2\2\u019d\u0195\3\2\2\2\u019d\u0196\3\2"+
-    "\2\2\u019e\u01a0\3\2\2\2\u019f\u01a1\t\n\2\2\u01a0\u019f\3\2\2\2\u01a0"+
-    "\u01a1\3\2\2\2\u01a1\u0089\3\2\2\2\u01a2\u01ab\7\62\2\2\u01a3\u01a7\t"+
-    "\b\2\2\u01a4\u01a6\t\t\2\2\u01a5\u01a4\3\2\2\2\u01a6\u01a9\3\2\2\2\u01a7"+
-    "\u01a5\3\2\2\2\u01a7\u01a8\3\2\2\2\u01a8\u01ab\3\2\2\2\u01a9\u01a7\3\2"+
-    "\2\2\u01aa\u01a2\3\2\2\2\u01aa\u01a3\3\2\2\2\u01ab\u01b2\3\2\2\2\u01ac"+
-    "\u01ae\5\24\n\2\u01ad\u01af\t\t\2\2\u01ae\u01ad\3\2\2\2\u01af\u01b0\3"+
-    "\2\2\2\u01b0\u01ae\3\2\2\2\u01b0\u01b1\3\2\2\2\u01b1\u01b3\3\2\2\2\u01b2"+
-    "\u01ac\3\2\2\2\u01b2\u01b3\3\2\2\2\u01b3\u01bd\3\2\2\2\u01b4\u01b6\t\13"+
-    "\2\2\u01b5\u01b7\t\f\2\2\u01b6\u01b5\3\2\2\2\u01b6\u01b7\3\2\2\2\u01b7"+
-    "\u01b9\3\2\2\2\u01b8\u01ba\t\t\2\2\u01b9\u01b8\3\2\2\2\u01ba\u01bb\3\2"+
-    "\2\2\u01bb\u01b9\3\2\2\2\u01bb\u01bc\3\2\2\2\u01bc\u01be\3\2\2\2\u01bd"+
-    "\u01b4\3\2\2\2\u01bd\u01be\3\2\2\2\u01be\u01c0\3\2\2\2\u01bf\u01c1\t\r"+
-    "\2\2\u01c0\u01bf\3\2\2\2\u01c0\u01c1\3\2\2\2\u01c1\u008b\3\2\2\2\u01c2"+
-    "\u01ca\7$\2\2\u01c3\u01c4\7^\2\2\u01c4\u01c9\7$\2\2\u01c5\u01c6\7^\2\2"+
-    "\u01c6\u01c9\7^\2\2\u01c7\u01c9\n\16\2\2\u01c8\u01c3\3\2\2\2\u01c8\u01c5"+
-    "\3\2\2\2\u01c8\u01c7\3\2\2\2\u01c9\u01cc\3\2\2\2\u01ca\u01cb\3\2\2\2\u01ca"+
-    "\u01c8\3\2\2\2\u01cb\u01cd\3\2\2\2\u01cc\u01ca\3\2\2\2\u01cd\u01db\7$"+
-    "\2\2\u01ce\u01d6\7)\2\2\u01cf\u01d0\7^\2\2\u01d0\u01d5\7)\2\2\u01d1\u01d2"+
-    "\7^\2\2\u01d2\u01d5\7^\2\2\u01d3\u01d5\n\16\2\2\u01d4\u01cf\3\2\2\2\u01d4"+
-    "\u01d1\3\2\2\2\u01d4\u01d3\3\2\2\2\u01d5\u01d8\3\2\2\2\u01d6\u01d7\3\2"+
-    "\2\2\u01d6\u01d4\3\2\2\2\u01d7\u01d9\3\2\2\2\u01d8\u01d6\3\2\2\2\u01d9"+
-    "\u01db\7)\2\2\u01da\u01c2\3\2\2\2\u01da\u01ce\3\2\2\2\u01db\u008d\3\2"+
-    "\2\2\u01dc\u01dd\7v\2\2\u01dd\u01de\7t\2\2\u01de\u01df\7w\2\2\u01df\u01e0"+
-    "\7g\2\2\u01e0\u008f\3\2\2\2\u01e1\u01e2\7h\2\2\u01e2\u01e3\7c\2\2\u01e3"+
-    "\u01e4\7n\2\2\u01e4\u01e5\7u\2\2\u01e5\u01e6\7g\2\2\u01e6\u0091\3\2\2"+
-    "\2\u01e7\u01e8\7p\2\2\u01e8\u01e9\7w\2\2\u01e9\u01ea\7n\2\2\u01ea\u01eb"+
-    "\7n\2\2\u01eb\u0093\3\2\2\2\u01ec\u01f2\5\u0096K\2\u01ed\u01ee\5\24\n"+
-    "\2\u01ee\u01ef\5\u0096K\2\u01ef\u01f1\3\2\2\2\u01f0\u01ed\3\2\2\2\u01f1"+
-    "\u01f4\3\2\2\2\u01f2\u01f0\3\2\2\2\u01f2\u01f3\3\2\2\2\u01f3\u01f5\3\2"+
-    "\2\2\u01f4\u01f2\3\2\2\2\u01f5\u01f6\6J\2\2\u01f6\u0095\3\2\2\2\u01f7"+
-    "\u01fb\t\17\2\2\u01f8\u01fa\t\20\2\2\u01f9\u01f8\3\2\2\2\u01fa\u01fd\3"+
-    "\2\2\2\u01fb\u01f9\3\2\2\2\u01fb\u01fc\3\2\2\2\u01fc\u0097\3\2\2\2\u01fd"+
-    "\u01fb\3\2\2\2\u01fe\u0207\7\62\2\2\u01ff\u0203\t\b\2\2\u0200\u0202\t"+
-    "\t\2\2\u0201\u0200\3\2\2\2\u0202\u0205\3\2\2\2\u0203\u0201\3\2\2\2\u0203"+
-    "\u0204\3\2\2\2\u0204\u0207\3\2\2\2\u0205\u0203\3\2\2\2\u0206\u01fe\3\2"+
-    "\2\2\u0206\u01ff\3\2\2\2\u0207\u0208\3\2\2\2\u0208\u0209\bL\4\2\u0209"+
-    "\u0099\3\2\2\2\u020a\u020e\t\17\2\2\u020b\u020d\t\20\2\2\u020c\u020b\3"+
-    "\2\2\2\u020d\u0210\3\2\2\2\u020e\u020c\3\2\2\2\u020e\u020f\3\2\2\2\u020f"+
-    "\u0211\3\2\2\2\u0210\u020e\3\2\2\2\u0211\u0212\bM\4\2\u0212\u009b\3\2"+
-    "\2\2!\2\3\u009f\u00a9\u00b3\u00b8\u0186\u0189\u0190\u0193\u019a\u019d"+
-    "\u01a0\u01a7\u01aa\u01b0\u01b2\u01b6\u01bb\u01bd\u01c0\u01c8\u01ca\u01d4"+
-    "\u01d6\u01da\u01f2\u01fb\u0203\u0206\u020e\5\b\2\2\4\3\2\4\2\2";
+    "I\tI\4J\tJ\4K\tK\4L\tL\4M\tM\4N\tN\3\2\6\2\u00a0\n\2\r\2\16\2\u00a1\3"+
+    "\2\3\2\3\3\3\3\3\3\3\3\7\3\u00aa\n\3\f\3\16\3\u00ad\13\3\3\3\3\3\3\3\3"+
+    "\3\3\3\7\3\u00b4\n\3\f\3\16\3\u00b7\13\3\3\3\3\3\5\3\u00bb\n\3\3\3\3\3"+
+    "\3\4\3\4\3\5\3\5\3\6\3\6\3\7\3\7\3\b\3\b\3\t\3\t\3\n\3\n\3\n\3\n\3\13"+
+    "\3\13\3\f\3\f\3\r\3\r\3\r\3\16\3\16\3\16\3\16\3\16\3\17\3\17\3\17\3\17"+
+    "\3\17\3\17\3\20\3\20\3\20\3\21\3\21\3\21\3\21\3\22\3\22\3\22\3\22\3\22"+
+    "\3\22\3\22\3\22\3\22\3\23\3\23\3\23\3\23\3\23\3\23\3\24\3\24\3\24\3\24"+
+    "\3\24\3\24\3\24\3\25\3\25\3\25\3\25\3\26\3\26\3\26\3\26\3\27\3\27\3\27"+
+    "\3\27\3\27\3\27\3\30\3\30\3\30\3\30\3\30\3\30\3\31\3\31\3\31\3\31\3\31"+
+    "\3\32\3\32\3\33\3\33\3\34\3\34\3\35\3\35\3\36\3\36\3\37\3\37\3 \3 \3!"+
+    "\3!\3!\3\"\3\"\3\"\3#\3#\3#\3#\3$\3$\3%\3%\3%\3&\3&\3\'\3\'\3\'\3(\3("+
+    "\3(\3)\3)\3)\3)\3*\3*\3*\3+\3+\3+\3+\3,\3,\3-\3-\3.\3.\3/\3/\3/\3\60\3"+
+    "\60\3\60\3\61\3\61\3\62\3\62\3\63\3\63\3\63\3\64\3\64\3\64\3\65\3\65\3"+
+    "\65\3\66\3\66\3\66\3\67\3\67\38\38\38\39\39\39\3:\3:\3:\3;\3;\3;\3<\3"+
+    "<\3<\3=\3=\3=\3>\3>\3>\3?\3?\3?\3@\3@\3@\3@\3A\3A\3A\3A\3B\3B\3B\3B\3"+
+    "B\3C\3C\6C\u018c\nC\rC\16C\u018d\3C\5C\u0191\nC\3D\3D\3D\6D\u0196\nD\r"+
+    "D\16D\u0197\3D\5D\u019b\nD\3E\3E\3E\7E\u01a0\nE\fE\16E\u01a3\13E\5E\u01a5"+
+    "\nE\3E\5E\u01a8\nE\3F\3F\3F\7F\u01ad\nF\fF\16F\u01b0\13F\5F\u01b2\nF\3"+
+    "F\3F\6F\u01b6\nF\rF\16F\u01b7\5F\u01ba\nF\3F\3F\5F\u01be\nF\3F\6F\u01c1"+
+    "\nF\rF\16F\u01c2\5F\u01c5\nF\3F\5F\u01c8\nF\3G\3G\3G\3G\3G\3G\7G\u01d0"+
+    "\nG\fG\16G\u01d3\13G\3G\3G\3G\3G\3G\3G\3G\7G\u01dc\nG\fG\16G\u01df\13"+
+    "G\3G\5G\u01e2\nG\3H\3H\3H\3H\3H\3I\3I\3I\3I\3I\3I\3J\3J\3J\3J\3J\3K\3"+
+    "K\3K\3K\7K\u01f8\nK\fK\16K\u01fb\13K\3K\3K\3L\3L\7L\u0201\nL\fL\16L\u0204"+
+    "\13L\3M\3M\3M\7M\u0209\nM\fM\16M\u020c\13M\5M\u020e\nM\3M\3M\3N\3N\7N"+
+    "\u0214\nN\fN\16N\u0217\13N\3N\3N\6\u00ab\u00b5\u01d1\u01dd\2O\4\3\6\4"+
+    "\b\5\n\6\f\7\16\b\20\t\22\n\24\13\26\f\30\r\32\16\34\17\36\20 \21\"\22"+
+    "$\23&\24(\25*\26,\27.\30\60\31\62\32\64\33\66\348\35:\36<\37> @!B\"D#"+
+    "F$H%J&L\'N(P)R*T+V,X-Z.\\/^\60`\61b\62d\63f\64h\65j\66l\67n8p9r:t;v<x"+
+    "=z>|?~@\u0080A\u0082B\u0084C\u0086D\u0088E\u008aF\u008cG\u008eH\u0090"+
+    "I\u0092J\u0094K\u0096L\u0098M\u009aN\u009cO\4\2\3\21\5\2\13\f\17\17\""+
+    "\"\4\2\f\f\17\17\3\2\629\4\2NNnn\4\2ZZzz\5\2\62;CHch\3\2\63;\3\2\62;\b"+
+    "\2FFHHNNffhhnn\4\2GGgg\4\2--//\4\2HHhh\4\2$$^^\5\2C\\aac|\6\2\62;C\\a"+
+    "ac|\u0237\2\4\3\2\2\2\2\6\3\2\2\2\2\b\3\2\2\2\2\n\3\2\2\2\2\f\3\2\2\2"+
+    "\2\16\3\2\2\2\2\20\3\2\2\2\2\22\3\2\2\2\2\24\3\2\2\2\2\26\3\2\2\2\2\30"+
+    "\3\2\2\2\2\32\3\2\2\2\2\34\3\2\2\2\2\36\3\2\2\2\2 \3\2\2\2\2\"\3\2\2\2"+
+    "\2$\3\2\2\2\2&\3\2\2\2\2(\3\2\2\2\2*\3\2\2\2\2,\3\2\2\2\2.\3\2\2\2\2\60"+
+    "\3\2\2\2\2\62\3\2\2\2\2\64\3\2\2\2\2\66\3\2\2\2\28\3\2\2\2\2:\3\2\2\2"+
+    "\2<\3\2\2\2\2>\3\2\2\2\2@\3\2\2\2\2B\3\2\2\2\2D\3\2\2\2\2F\3\2\2\2\2H"+
+    "\3\2\2\2\2J\3\2\2\2\2L\3\2\2\2\2N\3\2\2\2\2P\3\2\2\2\2R\3\2\2\2\2T\3\2"+
+    "\2\2\2V\3\2\2\2\2X\3\2\2\2\2Z\3\2\2\2\2\\\3\2\2\2\2^\3\2\2\2\2`\3\2\2"+
+    "\2\2b\3\2\2\2\2d\3\2\2\2\2f\3\2\2\2\2h\3\2\2\2\2j\3\2\2\2\2l\3\2\2\2\2"+
+    "n\3\2\2\2\2p\3\2\2\2\2r\3\2\2\2\2t\3\2\2\2\2v\3\2\2\2\2x\3\2\2\2\2z\3"+
+    "\2\2\2\2|\3\2\2\2\2~\3\2\2\2\2\u0080\3\2\2\2\2\u0082\3\2\2\2\2\u0084\3"+
+    "\2\2\2\2\u0086\3\2\2\2\2\u0088\3\2\2\2\2\u008a\3\2\2\2\2\u008c\3\2\2\2"+
+    "\2\u008e\3\2\2\2\2\u0090\3\2\2\2\2\u0092\3\2\2\2\2\u0094\3\2\2\2\2\u0096"+
+    "\3\2\2\2\2\u0098\3\2\2\2\3\u009a\3\2\2\2\3\u009c\3\2\2\2\4\u009f\3\2\2"+
+    "\2\6\u00ba\3\2\2\2\b\u00be\3\2\2\2\n\u00c0\3\2\2\2\f\u00c2\3\2\2\2\16"+
+    "\u00c4\3\2\2\2\20\u00c6\3\2\2\2\22\u00c8\3\2\2\2\24\u00ca\3\2\2\2\26\u00ce"+
+    "\3\2\2\2\30\u00d0\3\2\2\2\32\u00d2\3\2\2\2\34\u00d5\3\2\2\2\36\u00da\3"+
+    "\2\2\2 \u00e0\3\2\2\2\"\u00e3\3\2\2\2$\u00e7\3\2\2\2&\u00f0\3\2\2\2(\u00f6"+
+    "\3\2\2\2*\u00fd\3\2\2\2,\u0101\3\2\2\2.\u0105\3\2\2\2\60\u010b\3\2\2\2"+
+    "\62\u0111\3\2\2\2\64\u0116\3\2\2\2\66\u0118\3\2\2\28\u011a\3\2\2\2:\u011c"+
+    "\3\2\2\2<\u011e\3\2\2\2>\u0120\3\2\2\2@\u0122\3\2\2\2B\u0124\3\2\2\2D"+
+    "\u0127\3\2\2\2F\u012a\3\2\2\2H\u012e\3\2\2\2J\u0130\3\2\2\2L\u0133\3\2"+
+    "\2\2N\u0135\3\2\2\2P\u0138\3\2\2\2R\u013b\3\2\2\2T\u013f\3\2\2\2V\u0142"+
+    "\3\2\2\2X\u0146\3\2\2\2Z\u0148\3\2\2\2\\\u014a\3\2\2\2^\u014c\3\2\2\2"+
+    "`\u014f\3\2\2\2b\u0152\3\2\2\2d\u0154\3\2\2\2f\u0156\3\2\2\2h\u0159\3"+
+    "\2\2\2j\u015c\3\2\2\2l\u015f\3\2\2\2n\u0162\3\2\2\2p\u0164\3\2\2\2r\u0167"+
+    "\3\2\2\2t\u016a\3\2\2\2v\u016d\3\2\2\2x\u0170\3\2\2\2z\u0173\3\2\2\2|"+
+    "\u0176\3\2\2\2~\u0179\3\2\2\2\u0080\u017c\3\2\2\2\u0082\u0180\3\2\2\2"+
+    "\u0084\u0184\3\2\2\2\u0086\u0189\3\2\2\2\u0088\u0192\3\2\2\2\u008a\u01a4"+
+    "\3\2\2\2\u008c\u01b1\3\2\2\2\u008e\u01e1\3\2\2\2\u0090\u01e3\3\2\2\2\u0092"+
+    "\u01e8\3\2\2\2\u0094\u01ee\3\2\2\2\u0096\u01f3\3\2\2\2\u0098\u01fe\3\2"+
+    "\2\2\u009a\u020d\3\2\2\2\u009c\u0211\3\2\2\2\u009e\u00a0\t\2\2\2\u009f"+
+    "\u009e\3\2\2\2\u00a0\u00a1\3\2\2\2\u00a1\u009f\3\2\2\2\u00a1\u00a2\3\2"+
+    "\2\2\u00a2\u00a3\3\2\2\2\u00a3\u00a4\b\2\2\2\u00a4\5\3\2\2\2\u00a5\u00a6"+
+    "\7\61\2\2\u00a6\u00a7\7\61\2\2\u00a7\u00ab\3\2\2\2\u00a8\u00aa\13\2\2"+
+    "\2\u00a9\u00a8\3\2\2\2\u00aa\u00ad\3\2\2\2\u00ab\u00ac\3\2\2\2\u00ab\u00a9"+
+    "\3\2\2\2\u00ac\u00ae\3\2\2\2\u00ad\u00ab\3\2\2\2\u00ae\u00bb\t\3\2\2\u00af"+
+    "\u00b0\7\61\2\2\u00b0\u00b1\7,\2\2\u00b1\u00b5\3\2\2\2\u00b2\u00b4\13"+
+    "\2\2\2\u00b3\u00b2\3\2\2\2\u00b4\u00b7\3\2\2\2\u00b5\u00b6\3\2\2\2\u00b5"+
+    "\u00b3\3\2\2\2\u00b6\u00b8\3\2\2\2\u00b7\u00b5\3\2\2\2\u00b8\u00b9\7,"+
+    "\2\2\u00b9\u00bb\7\61\2\2\u00ba\u00a5\3\2\2\2\u00ba\u00af\3\2\2\2\u00bb"+
+    "\u00bc\3\2\2\2\u00bc\u00bd\b\3\2\2\u00bd\7\3\2\2\2\u00be\u00bf\7}\2\2"+
+    "\u00bf\t\3\2\2\2\u00c0\u00c1\7\177\2\2\u00c1\13\3\2\2\2\u00c2\u00c3\7"+
+    "]\2\2\u00c3\r\3\2\2\2\u00c4\u00c5\7_\2\2\u00c5\17\3\2\2\2\u00c6\u00c7"+
+    "\7*\2\2\u00c7\21\3\2\2\2\u00c8\u00c9\7+\2\2\u00c9\23\3\2\2\2\u00ca\u00cb"+
+    "\7\60\2\2\u00cb\u00cc\3\2\2\2\u00cc\u00cd\b\n\3\2\u00cd\25\3\2\2\2\u00ce"+
+    "\u00cf\7.\2\2\u00cf\27\3\2\2\2\u00d0\u00d1\7=\2\2\u00d1\31\3\2\2\2\u00d2"+
+    "\u00d3\7k\2\2\u00d3\u00d4\7h\2\2\u00d4\33\3\2\2\2\u00d5\u00d6\7g\2\2\u00d6"+
+    "\u00d7\7n\2\2\u00d7\u00d8\7u\2\2\u00d8\u00d9\7g\2\2\u00d9\35\3\2\2\2\u00da"+
+    "\u00db\7y\2\2\u00db\u00dc\7j\2\2\u00dc\u00dd\7k\2\2\u00dd\u00de\7n\2\2"+
+    "\u00de\u00df\7g\2\2\u00df\37\3\2\2\2\u00e0\u00e1\7f\2\2\u00e1\u00e2\7"+
+    "q\2\2\u00e2!\3\2\2\2\u00e3\u00e4\7h\2\2\u00e4\u00e5\7q\2\2\u00e5\u00e6"+
+    "\7t\2\2\u00e6#\3\2\2\2\u00e7\u00e8\7e\2\2\u00e8\u00e9\7q\2\2\u00e9\u00ea"+
+    "\7p\2\2\u00ea\u00eb\7v\2\2\u00eb\u00ec\7k\2\2\u00ec\u00ed\7p\2\2\u00ed"+
+    "\u00ee\7w\2\2\u00ee\u00ef\7g\2\2\u00ef%\3\2\2\2\u00f0\u00f1\7d\2\2\u00f1"+
+    "\u00f2\7t\2\2\u00f2\u00f3\7g\2\2\u00f3\u00f4\7c\2\2\u00f4\u00f5\7m\2\2"+
+    "\u00f5\'\3\2\2\2\u00f6\u00f7\7t\2\2\u00f7\u00f8\7g\2\2\u00f8\u00f9\7v"+
+    "\2\2\u00f9\u00fa\7w\2\2\u00fa\u00fb\7t\2\2\u00fb\u00fc\7p\2\2\u00fc)\3"+
+    "\2\2\2\u00fd\u00fe\7p\2\2\u00fe\u00ff\7g\2\2\u00ff\u0100\7y\2\2\u0100"+
+    "+\3\2\2\2\u0101\u0102\7v\2\2\u0102\u0103\7t\2\2\u0103\u0104\7{\2\2\u0104"+
+    "-\3\2\2\2\u0105\u0106\7e\2\2\u0106\u0107\7c\2\2\u0107\u0108\7v\2\2\u0108"+
+    "\u0109\7e\2\2\u0109\u010a\7j\2\2\u010a/\3\2\2\2\u010b\u010c\7v\2\2\u010c"+
+    "\u010d\7j\2\2\u010d\u010e\7t\2\2\u010e\u010f\7q\2\2\u010f\u0110\7y\2\2"+
+    "\u0110\61\3\2\2\2\u0111\u0112\7v\2\2\u0112\u0113\7j\2\2\u0113\u0114\7"+
+    "k\2\2\u0114\u0115\7u\2\2\u0115\63\3\2\2\2\u0116\u0117\7#\2\2\u0117\65"+
+    "\3\2\2\2\u0118\u0119\7\u0080\2\2\u0119\67\3\2\2\2\u011a\u011b\7,\2\2\u011b"+
+    "9\3\2\2\2\u011c\u011d\7\61\2\2\u011d;\3\2\2\2\u011e\u011f\7\'\2\2\u011f"+
+    "=\3\2\2\2\u0120\u0121\7-\2\2\u0121?\3\2\2\2\u0122\u0123\7/\2\2\u0123A"+
+    "\3\2\2\2\u0124\u0125\7>\2\2\u0125\u0126\7>\2\2\u0126C\3\2\2\2\u0127\u0128"+
+    "\7@\2\2\u0128\u0129\7@\2\2\u0129E\3\2\2\2\u012a\u012b\7@\2\2\u012b\u012c"+
+    "\7@\2\2\u012c\u012d\7@\2\2\u012dG\3\2\2\2\u012e\u012f\7>\2\2\u012fI\3"+
+    "\2\2\2\u0130\u0131\7>\2\2\u0131\u0132\7?\2\2\u0132K\3\2\2\2\u0133\u0134"+
+    "\7@\2\2\u0134M\3\2\2\2\u0135\u0136\7@\2\2\u0136\u0137\7?\2\2\u0137O\3"+
+    "\2\2\2\u0138\u0139\7?\2\2\u0139\u013a\7?\2\2\u013aQ\3\2\2\2\u013b\u013c"+
+    "\7?\2\2\u013c\u013d\7?\2\2\u013d\u013e\7?\2\2\u013eS\3\2\2\2\u013f\u0140"+
+    "\7#\2\2\u0140\u0141\7?\2\2\u0141U\3\2\2\2\u0142\u0143\7#\2\2\u0143\u0144"+
+    "\7?\2\2\u0144\u0145\7?\2\2\u0145W\3\2\2\2\u0146\u0147\7(\2\2\u0147Y\3"+
+    "\2\2\2\u0148\u0149\7`\2\2\u0149[\3\2\2\2\u014a\u014b\7~\2\2\u014b]\3\2"+
+    "\2\2\u014c\u014d\7(\2\2\u014d\u014e\7(\2\2\u014e_\3\2\2\2\u014f\u0150"+
+    "\7~\2\2\u0150\u0151\7~\2\2\u0151a\3\2\2\2\u0152\u0153\7A\2\2\u0153c\3"+
+    "\2\2\2\u0154\u0155\7<\2\2\u0155e\3\2\2\2\u0156\u0157\7<\2\2\u0157\u0158"+
+    "\7<\2\2\u0158g\3\2\2\2\u0159\u015a\7/\2\2\u015a\u015b\7@\2\2\u015bi\3"+
+    "\2\2\2\u015c\u015d\7-\2\2\u015d\u015e\7-\2\2\u015ek\3\2\2\2\u015f\u0160"+
+    "\7/\2\2\u0160\u0161\7/\2\2\u0161m\3\2\2\2\u0162\u0163\7?\2\2\u0163o\3"+
+    "\2\2\2\u0164\u0165\7-\2\2\u0165\u0166\7?\2\2\u0166q\3\2\2\2\u0167\u0168"+
+    "\7/\2\2\u0168\u0169\7?\2\2\u0169s\3\2\2\2\u016a\u016b\7,\2\2\u016b\u016c"+
+    "\7?\2\2\u016cu\3\2\2\2\u016d\u016e\7\61\2\2\u016e\u016f\7?\2\2\u016fw"+
+    "\3\2\2\2\u0170\u0171\7\'\2\2\u0171\u0172\7?\2\2\u0172y\3\2\2\2\u0173\u0174"+
+    "\7(\2\2\u0174\u0175\7?\2\2\u0175{\3\2\2\2\u0176\u0177\7`\2\2\u0177\u0178"+
+    "\7?\2\2\u0178}\3\2\2\2\u0179\u017a\7~\2\2\u017a\u017b\7?\2\2\u017b\177"+
+    "\3\2\2\2\u017c\u017d\7>\2\2\u017d\u017e\7>\2\2\u017e\u017f\7?\2\2\u017f"+
+    "\u0081\3\2\2\2\u0180\u0181\7@\2\2\u0181\u0182\7@\2\2\u0182\u0183\7?\2"+
+    "\2\u0183\u0083\3\2\2\2\u0184\u0185\7@\2\2\u0185\u0186\7@\2\2\u0186\u0187"+
+    "\7@\2\2\u0187\u0188\7?\2\2\u0188\u0085\3\2\2\2\u0189\u018b\7\62\2\2\u018a"+
+    "\u018c\t\4\2\2\u018b\u018a\3\2\2\2\u018c\u018d\3\2\2\2\u018d\u018b\3\2"+
+    "\2\2\u018d\u018e\3\2\2\2\u018e\u0190\3\2\2\2\u018f\u0191\t\5\2\2\u0190"+
+    "\u018f\3\2\2\2\u0190\u0191\3\2\2\2\u0191\u0087\3\2\2\2\u0192\u0193\7\62"+
+    "\2\2\u0193\u0195\t\6\2\2\u0194\u0196\t\7\2\2\u0195\u0194\3\2\2\2\u0196"+
+    "\u0197\3\2\2\2\u0197\u0195\3\2\2\2\u0197\u0198\3\2\2\2\u0198\u019a\3\2"+
+    "\2\2\u0199\u019b\t\5\2\2\u019a\u0199\3\2\2\2\u019a\u019b\3\2\2\2\u019b"+
+    "\u0089\3\2\2\2\u019c\u01a5\7\62\2\2\u019d\u01a1\t\b\2\2\u019e\u01a0\t"+
+    "\t\2\2\u019f\u019e\3\2\2\2\u01a0\u01a3\3\2\2\2\u01a1\u019f\3\2\2\2\u01a1"+
+    "\u01a2\3\2\2\2\u01a2\u01a5\3\2\2\2\u01a3\u01a1\3\2\2\2\u01a4\u019c\3\2"+
+    "\2\2\u01a4\u019d\3\2\2\2\u01a5\u01a7\3\2\2\2\u01a6\u01a8\t\n\2\2\u01a7"+
+    "\u01a6\3\2\2\2\u01a7\u01a8\3\2\2\2\u01a8\u008b\3\2\2\2\u01a9\u01b2\7\62"+
+    "\2\2\u01aa\u01ae\t\b\2\2\u01ab\u01ad\t\t\2\2\u01ac\u01ab\3\2\2\2\u01ad"+
+    "\u01b0\3\2\2\2\u01ae\u01ac\3\2\2\2\u01ae\u01af\3\2\2\2\u01af\u01b2\3\2"+
+    "\2\2\u01b0\u01ae\3\2\2\2\u01b1\u01a9\3\2\2\2\u01b1\u01aa\3\2\2\2\u01b2"+
+    "\u01b9\3\2\2\2\u01b3\u01b5\5\24\n\2\u01b4\u01b6\t\t\2\2\u01b5\u01b4\3"+
+    "\2\2\2\u01b6\u01b7\3\2\2\2\u01b7\u01b5\3\2\2\2\u01b7\u01b8\3\2\2\2\u01b8"+
+    "\u01ba\3\2\2\2\u01b9\u01b3\3\2\2\2\u01b9\u01ba\3\2\2\2\u01ba\u01c4\3\2"+
+    "\2\2\u01bb\u01bd\t\13\2\2\u01bc\u01be\t\f\2\2\u01bd\u01bc\3\2\2\2\u01bd"+
+    "\u01be\3\2\2\2\u01be\u01c0\3\2\2\2\u01bf\u01c1\t\t\2\2\u01c0\u01bf\3\2"+
+    "\2\2\u01c1\u01c2\3\2\2\2\u01c2\u01c0\3\2\2\2\u01c2\u01c3\3\2\2\2\u01c3"+
+    "\u01c5\3\2\2\2\u01c4\u01bb\3\2\2\2\u01c4\u01c5\3\2\2\2\u01c5\u01c7\3\2"+
+    "\2\2\u01c6\u01c8\t\r\2\2\u01c7\u01c6\3\2\2\2\u01c7\u01c8\3\2\2\2\u01c8"+
+    "\u008d\3\2\2\2\u01c9\u01d1\7$\2\2\u01ca\u01cb\7^\2\2\u01cb\u01d0\7$\2"+
+    "\2\u01cc\u01cd\7^\2\2\u01cd\u01d0\7^\2\2\u01ce\u01d0\n\16\2\2\u01cf\u01ca"+
+    "\3\2\2\2\u01cf\u01cc\3\2\2\2\u01cf\u01ce\3\2\2\2\u01d0\u01d3\3\2\2\2\u01d1"+
+    "\u01d2\3\2\2\2\u01d1\u01cf\3\2\2\2\u01d2\u01d4\3\2\2\2\u01d3\u01d1\3\2"+
+    "\2\2\u01d4\u01e2\7$\2\2\u01d5\u01dd\7)\2\2\u01d6\u01d7\7^\2\2\u01d7\u01dc"+
+    "\7)\2\2\u01d8\u01d9\7^\2\2\u01d9\u01dc\7^\2\2\u01da\u01dc\n\16\2\2\u01db"+
+    "\u01d6\3\2\2\2\u01db\u01d8\3\2\2\2\u01db\u01da\3\2\2\2\u01dc\u01df\3\2"+
+    "\2\2\u01dd\u01de\3\2\2\2\u01dd\u01db\3\2\2\2\u01de\u01e0\3\2\2\2\u01df"+
+    "\u01dd\3\2\2\2\u01e0\u01e2\7)\2\2\u01e1\u01c9\3\2\2\2\u01e1\u01d5\3\2"+
+    "\2\2\u01e2\u008f\3\2\2\2\u01e3\u01e4\7v\2\2\u01e4\u01e5\7t\2\2\u01e5\u01e6"+
+    "\7w\2\2\u01e6\u01e7\7g\2\2\u01e7\u0091\3\2\2\2\u01e8\u01e9\7h\2\2\u01e9"+
+    "\u01ea\7c\2\2\u01ea\u01eb\7n\2\2\u01eb\u01ec\7u\2\2\u01ec\u01ed\7g\2\2"+
+    "\u01ed\u0093\3\2\2\2\u01ee\u01ef\7p\2\2\u01ef\u01f0\7w\2\2\u01f0\u01f1"+
+    "\7n\2\2\u01f1\u01f2\7n\2\2\u01f2\u0095\3\2\2\2\u01f3\u01f9\5\u0098L\2"+
+    "\u01f4\u01f5\5\24\n\2\u01f5\u01f6\5\u0098L\2\u01f6\u01f8\3\2\2\2\u01f7"+
+    "\u01f4\3\2\2\2\u01f8\u01fb\3\2\2\2\u01f9\u01f7\3\2\2\2\u01f9\u01fa\3\2"+
+    "\2\2\u01fa\u01fc\3\2\2\2\u01fb\u01f9\3\2\2\2\u01fc\u01fd\6K\2\2\u01fd"+
+    "\u0097\3\2\2\2\u01fe\u0202\t\17\2\2\u01ff\u0201\t\20\2\2\u0200\u01ff\3"+
+    "\2\2\2\u0201\u0204\3\2\2\2\u0202\u0200\3\2\2\2\u0202\u0203\3\2\2\2\u0203"+
+    "\u0099\3\2\2\2\u0204\u0202\3\2\2\2\u0205\u020e\7\62\2\2\u0206\u020a\t"+
+    "\b\2\2\u0207\u0209\t\t\2\2\u0208\u0207\3\2\2\2\u0209\u020c\3\2\2\2\u020a"+
+    "\u0208\3\2\2\2\u020a\u020b\3\2\2\2\u020b\u020e\3\2\2\2\u020c\u020a\3\2"+
+    "\2\2\u020d\u0205\3\2\2\2\u020d\u0206\3\2\2\2\u020e\u020f\3\2\2\2\u020f"+
+    "\u0210\bM\4\2\u0210\u009b\3\2\2\2\u0211\u0215\t\17\2\2\u0212\u0214\t\20"+
+    "\2\2\u0213\u0212\3\2\2\2\u0214\u0217\3\2\2\2\u0215\u0213\3\2\2\2\u0215"+
+    "\u0216\3\2\2\2\u0216\u0218\3\2\2\2\u0217\u0215\3\2\2\2\u0218\u0219\bN"+
+    "\4\2\u0219\u009d\3\2\2\2!\2\3\u00a1\u00ab\u00b5\u00ba\u018d\u0190\u0197"+
+    "\u019a\u01a1\u01a4\u01a7\u01ae\u01b1\u01b7\u01b9\u01bd\u01c2\u01c4\u01c7"+
+    "\u01cf\u01d1\u01db\u01dd\u01e1\u01f9\u0202\u020a\u020d\u0215\5\b\2\2\4"+
+    "\3\2\4\2\2";
   public static final ATN _ATN =
     new ATNDeserializer().deserialize(_serializedATN.toCharArray());
   static {

+ 105 - 98
modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/PainlessParser.java

@@ -19,14 +19,14 @@ class PainlessParser extends Parser {
   public static final int
     WS=1, COMMENT=2, LBRACK=3, RBRACK=4, LBRACE=5, RBRACE=6, LP=7, RP=8, DOT=9, 
     COMMA=10, SEMICOLON=11, IF=12, ELSE=13, WHILE=14, DO=15, FOR=16, CONTINUE=17, 
-    BREAK=18, RETURN=19, NEW=20, TRY=21, CATCH=22, THROW=23, BOOLNOT=24, BWNOT=25, 
-    MUL=26, DIV=27, REM=28, ADD=29, SUB=30, LSH=31, RSH=32, USH=33, LT=34, 
-    LTE=35, GT=36, GTE=37, EQ=38, EQR=39, NE=40, NER=41, BWAND=42, XOR=43, 
-    BWOR=44, BOOLAND=45, BOOLOR=46, COND=47, COLON=48, REF=49, ARROW=50, INCR=51, 
-    DECR=52, ASSIGN=53, AADD=54, ASUB=55, AMUL=56, ADIV=57, AREM=58, AAND=59, 
-    AXOR=60, AOR=61, ALSH=62, ARSH=63, AUSH=64, OCTAL=65, HEX=66, INTEGER=67, 
-    DECIMAL=68, STRING=69, TRUE=70, FALSE=71, NULL=72, TYPE=73, ID=74, DOTINTEGER=75, 
-    DOTID=76;
+    BREAK=18, RETURN=19, NEW=20, TRY=21, CATCH=22, THROW=23, THIS=24, BOOLNOT=25, 
+    BWNOT=26, MUL=27, DIV=28, REM=29, ADD=30, SUB=31, LSH=32, RSH=33, USH=34, 
+    LT=35, LTE=36, GT=37, GTE=38, EQ=39, EQR=40, NE=41, NER=42, BWAND=43, 
+    XOR=44, BWOR=45, BOOLAND=46, BOOLOR=47, COND=48, COLON=49, REF=50, ARROW=51, 
+    INCR=52, DECR=53, ASSIGN=54, AADD=55, ASUB=56, AMUL=57, ADIV=58, AREM=59, 
+    AAND=60, AXOR=61, AOR=62, ALSH=63, ARSH=64, AUSH=65, OCTAL=66, HEX=67, 
+    INTEGER=68, DECIMAL=69, STRING=70, TRUE=71, FALSE=72, NULL=73, TYPE=74, 
+    ID=75, DOTINTEGER=76, DOTID=77;
   public static final int
     RULE_source = 0, RULE_function = 1, RULE_parameters = 2, RULE_statement = 3, 
     RULE_trailer = 4, RULE_block = 5, RULE_empty = 6, RULE_initializer = 7, 
@@ -45,23 +45,23 @@ class PainlessParser extends Parser {
   private static final String[] _LITERAL_NAMES = {
     null, null, null, "'{'", "'}'", "'['", "']'", "'('", "')'", "'.'", "','", 
     "';'", "'if'", "'else'", "'while'", "'do'", "'for'", "'continue'", "'break'", 
-    "'return'", "'new'", "'try'", "'catch'", "'throw'", "'!'", "'~'", "'*'", 
-    "'/'", "'%'", "'+'", "'-'", "'<<'", "'>>'", "'>>>'", "'<'", "'<='", "'>'", 
-    "'>='", "'=='", "'==='", "'!='", "'!=='", "'&'", "'^'", "'|'", "'&&'", 
-    "'||'", "'?'", "':'", "'::'", "'->'", "'++'", "'--'", "'='", "'+='", "'-='", 
-    "'*='", "'/='", "'%='", "'&='", "'^='", "'|='", "'<<='", "'>>='", "'>>>='", 
-    null, null, null, null, null, "'true'", "'false'", "'null'"
+    "'return'", "'new'", "'try'", "'catch'", "'throw'", "'this'", "'!'", "'~'", 
+    "'*'", "'/'", "'%'", "'+'", "'-'", "'<<'", "'>>'", "'>>>'", "'<'", "'<='", 
+    "'>'", "'>='", "'=='", "'==='", "'!='", "'!=='", "'&'", "'^'", "'|'", 
+    "'&&'", "'||'", "'?'", "':'", "'::'", "'->'", "'++'", "'--'", "'='", "'+='", 
+    "'-='", "'*='", "'/='", "'%='", "'&='", "'^='", "'|='", "'<<='", "'>>='", 
+    "'>>>='", null, null, null, null, null, "'true'", "'false'", "'null'"
   };
   private static final String[] _SYMBOLIC_NAMES = {
     null, "WS", "COMMENT", "LBRACK", "RBRACK", "LBRACE", "RBRACE", "LP", "RP", 
     "DOT", "COMMA", "SEMICOLON", "IF", "ELSE", "WHILE", "DO", "FOR", "CONTINUE", 
-    "BREAK", "RETURN", "NEW", "TRY", "CATCH", "THROW", "BOOLNOT", "BWNOT", 
-    "MUL", "DIV", "REM", "ADD", "SUB", "LSH", "RSH", "USH", "LT", "LTE", "GT", 
-    "GTE", "EQ", "EQR", "NE", "NER", "BWAND", "XOR", "BWOR", "BOOLAND", "BOOLOR", 
-    "COND", "COLON", "REF", "ARROW", "INCR", "DECR", "ASSIGN", "AADD", "ASUB", 
-    "AMUL", "ADIV", "AREM", "AAND", "AXOR", "AOR", "ALSH", "ARSH", "AUSH", 
-    "OCTAL", "HEX", "INTEGER", "DECIMAL", "STRING", "TRUE", "FALSE", "NULL", 
-    "TYPE", "ID", "DOTINTEGER", "DOTID"
+    "BREAK", "RETURN", "NEW", "TRY", "CATCH", "THROW", "THIS", "BOOLNOT", 
+    "BWNOT", "MUL", "DIV", "REM", "ADD", "SUB", "LSH", "RSH", "USH", "LT", 
+    "LTE", "GT", "GTE", "EQ", "EQR", "NE", "NER", "BWAND", "XOR", "BWOR", 
+    "BOOLAND", "BOOLOR", "COND", "COLON", "REF", "ARROW", "INCR", "DECR", 
+    "ASSIGN", "AADD", "ASUB", "AMUL", "ADIV", "AREM", "AAND", "AXOR", "AOR", 
+    "ALSH", "ARSH", "AUSH", "OCTAL", "HEX", "INTEGER", "DECIMAL", "STRING", 
+    "TRUE", "FALSE", "NULL", "TYPE", "ID", "DOTINTEGER", "DOTID"
   };
   public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);
 
@@ -1500,7 +1500,7 @@ class PainlessParser extends Parser {
         chain(true);
         setState(226);
         _la = _input.LA(1);
-        if ( !(((((_la - 53)) & ~0x3f) == 0 && ((1L << (_la - 53)) & ((1L << (ASSIGN - 53)) | (1L << (AADD - 53)) | (1L << (ASUB - 53)) | (1L << (AMUL - 53)) | (1L << (ADIV - 53)) | (1L << (AREM - 53)) | (1L << (AAND - 53)) | (1L << (AXOR - 53)) | (1L << (AOR - 53)) | (1L << (ALSH - 53)) | (1L << (ARSH - 53)) | (1L << (AUSH - 53)))) != 0)) ) {
+        if ( !(((((_la - 54)) & ~0x3f) == 0 && ((1L << (_la - 54)) & ((1L << (ASSIGN - 54)) | (1L << (AADD - 54)) | (1L << (ASUB - 54)) | (1L << (AMUL - 54)) | (1L << (ADIV - 54)) | (1L << (AREM - 54)) | (1L << (AAND - 54)) | (1L << (AXOR - 54)) | (1L << (AOR - 54)) | (1L << (ALSH - 54)) | (1L << (ARSH - 54)) | (1L << (AUSH - 54)))) != 0)) ) {
         _errHandler.recoverInline(this);
         } else {
           consume();
@@ -1908,7 +1908,7 @@ class PainlessParser extends Parser {
         if (!( !_localctx.c )) throw new FailedPredicateException(this, " !$c ");
         setState(307);
         _la = _input.LA(1);
-        if ( !(((((_la - 65)) & ~0x3f) == 0 && ((1L << (_la - 65)) & ((1L << (OCTAL - 65)) | (1L << (HEX - 65)) | (1L << (INTEGER - 65)) | (1L << (DECIMAL - 65)))) != 0)) ) {
+        if ( !(((((_la - 66)) & ~0x3f) == 0 && ((1L << (_la - 66)) & ((1L << (OCTAL - 66)) | (1L << (HEX - 66)) | (1L << (INTEGER - 66)) | (1L << (DECIMAL - 66)))) != 0)) ) {
         _errHandler.recoverInline(this);
         } else {
           consume();
@@ -2863,6 +2863,7 @@ class PainlessParser extends Parser {
       return getToken(PainlessParser.ID, i);
     }
     public TerminalNode NEW() { return getToken(PainlessParser.NEW, 0); }
+    public TerminalNode THIS() { return getToken(PainlessParser.THIS, 0); }
     public FuncrefContext(ParserRuleContext parent, int invokingState) {
       super(parent, invokingState);
     }
@@ -2897,11 +2898,17 @@ class PainlessParser extends Parser {
         }
         }
         break;
+      case THIS:
       case ID:
         enterOuterAlt(_localctx, 2);
         {
         setState(445);
-        match(ID);
+        _la = _input.LA(1);
+        if ( !(_la==THIS || _la==ID) ) {
+        _errHandler.recoverInline(this);
+        } else {
+          consume();
+        }
         setState(446);
         match(REF);
         setState(447);
@@ -3013,7 +3020,7 @@ class PainlessParser extends Parser {
   }
 
   public static final String _serializedATN =
-    "\3\u0430\ud6d1\u8206\uad2d\u4417\uaef1\u8d80\uaadd\3N\u01c5\4\2\t\2\4"+
+    "\3\u0430\ud6d1\u8206\uad2d\u4417\uaef1\u8d80\uaadd\3O\u01c5\4\2\t\2\4"+
     "\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\4\n\t\n\4\13\t"+
     "\13\4\f\t\f\4\r\t\r\4\16\t\16\4\17\t\17\4\20\t\20\4\21\t\21\4\22\t\22"+
     "\4\23\t\23\4\24\t\24\4\25\t\25\4\26\t\26\4\27\t\27\4\30\t\30\4\31\t\31"+
@@ -3048,57 +3055,57 @@ class PainlessParser extends Parser {
     "\3\31\3\31\3\31\3\31\3\31\7\31\u01ab\n\31\f\31\16\31\u01ae\13\31\5\31"+
     "\u01b0\n\31\3\31\5\31\u01b3\n\31\3\31\3\31\3\31\3\32\5\32\u01b9\n\32\3"+
     "\32\3\32\3\33\3\33\3\33\3\33\3\33\3\33\5\33\u01c3\n\33\3\33\2\3\36\34"+
-    "\2\4\6\b\n\f\16\20\22\24\26\30\32\34\36 \"$&(*,.\60\62\64\2\r\3\2\67B"+
-    "\3\2\34\36\3\2\37 \3\2!#\3\2$\'\3\2(+\3\2\65\66\3\2CF\4\2\32\33\37 \3"+
-    "\2MN\4\2\26\26LL\u01f3\29\3\2\2\2\4D\3\2\2\2\6I\3\2\2\2\b\u00a7\3\2\2"+
-    "\2\n\u00ab\3\2\2\2\f\u00ad\3\2\2\2\16\u00b6\3\2\2\2\20\u00ba\3\2\2\2\22"+
-    "\u00bc\3\2\2\2\24\u00be\3\2\2\2\26\u00c7\3\2\2\2\30\u00cf\3\2\2\2\32\u00d4"+
-    "\3\2\2\2\34\u00e0\3\2\2\2\36\u00eb\3\2\2\2 \u0148\3\2\2\2\"\u016c\3\2"+
-    "\2\2$\u0180\3\2\2\2&\u0186\3\2\2\2(\u018d\3\2\2\2*\u018f\3\2\2\2,\u0193"+
-    "\3\2\2\2.\u01a3\3\2\2\2\60\u01b2\3\2\2\2\62\u01b8\3\2\2\2\64\u01c2\3\2"+
-    "\2\2\668\5\4\3\2\67\66\3\2\2\28;\3\2\2\29\67\3\2\2\29:\3\2\2\2:?\3\2\2"+
-    "\2;9\3\2\2\2<>\5\b\5\2=<\3\2\2\2>A\3\2\2\2?=\3\2\2\2?@\3\2\2\2@B\3\2\2"+
-    "\2A?\3\2\2\2BC\7\2\2\3C\3\3\2\2\2DE\5\26\f\2EF\7L\2\2FG\5\6\4\2GH\5\f"+
-    "\7\2H\5\3\2\2\2IU\7\t\2\2JK\5\26\f\2KR\7L\2\2LM\7\f\2\2MN\5\26\f\2NO\7"+
-    "L\2\2OQ\3\2\2\2PL\3\2\2\2QT\3\2\2\2RP\3\2\2\2RS\3\2\2\2SV\3\2\2\2TR\3"+
-    "\2\2\2UJ\3\2\2\2UV\3\2\2\2VW\3\2\2\2WX\7\n\2\2X\7\3\2\2\2YZ\7\16\2\2Z"+
-    "[\7\t\2\2[\\\5\36\20\2\\]\7\n\2\2]a\5\n\6\2^_\7\17\2\2_b\5\n\6\2`b\6\5"+
-    "\2\2a^\3\2\2\2a`\3\2\2\2b\u00a8\3\2\2\2cd\7\20\2\2de\7\t\2\2ef\5\36\20"+
-    "\2fi\7\n\2\2gj\5\n\6\2hj\5\16\b\2ig\3\2\2\2ih\3\2\2\2j\u00a8\3\2\2\2k"+
-    "l\7\21\2\2lm\5\f\7\2mn\7\20\2\2no\7\t\2\2op\5\36\20\2pq\7\n\2\2qr\5\34"+
-    "\17\2r\u00a8\3\2\2\2st\7\22\2\2tv\7\t\2\2uw\5\20\t\2vu\3\2\2\2vw\3\2\2"+
-    "\2wx\3\2\2\2xz\7\r\2\2y{\5\36\20\2zy\3\2\2\2z{\3\2\2\2{|\3\2\2\2|~\7\r"+
-    "\2\2}\177\5\22\n\2~}\3\2\2\2~\177\3\2\2\2\177\u0080\3\2\2\2\u0080\u0083"+
-    "\7\n\2\2\u0081\u0084\5\n\6\2\u0082\u0084\5\16\b\2\u0083\u0081\3\2\2\2"+
-    "\u0083\u0082\3\2\2\2\u0084\u00a8\3\2\2\2\u0085\u0086\7\22\2\2\u0086\u0087"+
-    "\7\t\2\2\u0087\u0088\5\26\f\2\u0088\u0089\7L\2\2\u0089\u008a\7\62\2\2"+
-    "\u008a\u008b\5\36\20\2\u008b\u008c\7\n\2\2\u008c\u008d\5\n\6\2\u008d\u00a8"+
-    "\3\2\2\2\u008e\u008f\5\24\13\2\u008f\u0090\5\34\17\2\u0090\u00a8\3\2\2"+
-    "\2\u0091\u0092\7\23\2\2\u0092\u00a8\5\34\17\2\u0093\u0094\7\24\2\2\u0094"+
-    "\u00a8\5\34\17\2\u0095\u0096\7\25\2\2\u0096\u0097\5\36\20\2\u0097\u0098"+
-    "\5\34\17\2\u0098\u00a8\3\2\2\2\u0099\u009a\7\27\2\2\u009a\u009c\5\f\7"+
-    "\2\u009b\u009d\5\32\16\2\u009c\u009b\3\2\2\2\u009d\u009e\3\2\2\2\u009e"+
-    "\u009c\3\2\2\2\u009e\u009f\3\2\2\2\u009f\u00a8\3\2\2\2\u00a0\u00a1\7\31"+
-    "\2\2\u00a1\u00a2\5\36\20\2\u00a2\u00a3\5\34\17\2\u00a3\u00a8\3\2\2\2\u00a4"+
-    "\u00a5\5\36\20\2\u00a5\u00a6\5\34\17\2\u00a6\u00a8\3\2\2\2\u00a7Y\3\2"+
-    "\2\2\u00a7c\3\2\2\2\u00a7k\3\2\2\2\u00a7s\3\2\2\2\u00a7\u0085\3\2\2\2"+
-    "\u00a7\u008e\3\2\2\2\u00a7\u0091\3\2\2\2\u00a7\u0093\3\2\2\2\u00a7\u0095"+
-    "\3\2\2\2\u00a7\u0099\3\2\2\2\u00a7\u00a0\3\2\2\2\u00a7\u00a4\3\2\2\2\u00a8"+
-    "\t\3\2\2\2\u00a9\u00ac\5\f\7\2\u00aa\u00ac\5\b\5\2\u00ab\u00a9\3\2\2\2"+
-    "\u00ab\u00aa\3\2\2\2\u00ac\13\3\2\2\2\u00ad\u00b1\7\5\2\2\u00ae\u00b0"+
-    "\5\b\5\2\u00af\u00ae\3\2\2\2\u00b0\u00b3\3\2\2\2\u00b1\u00af\3\2\2\2\u00b1"+
-    "\u00b2\3\2\2\2\u00b2\u00b4\3\2\2\2\u00b3\u00b1\3\2\2\2\u00b4\u00b5\7\6"+
-    "\2\2\u00b5\r\3\2\2\2\u00b6\u00b7\7\r\2\2\u00b7\17\3\2\2\2\u00b8\u00bb"+
-    "\5\24\13\2\u00b9\u00bb\5\36\20\2\u00ba\u00b8\3\2\2\2\u00ba\u00b9\3\2\2"+
-    "\2\u00bb\21\3\2\2\2\u00bc\u00bd\5\36\20\2\u00bd\23\3\2\2\2\u00be\u00bf"+
-    "\5\26\f\2\u00bf\u00c4\5\30\r\2\u00c0\u00c1\7\f\2\2\u00c1\u00c3\5\30\r"+
-    "\2\u00c2\u00c0\3\2\2\2\u00c3\u00c6\3\2\2\2\u00c4\u00c2\3\2\2\2\u00c4\u00c5"+
-    "\3\2\2\2\u00c5\25\3\2\2\2\u00c6\u00c4\3\2\2\2\u00c7\u00cc\7K\2\2\u00c8"+
-    "\u00c9\7\7\2\2\u00c9\u00cb\7\b\2\2\u00ca\u00c8\3\2\2\2\u00cb\u00ce\3\2"+
-    "\2\2\u00cc\u00ca\3\2\2\2\u00cc\u00cd\3\2\2\2\u00cd\27\3\2\2\2\u00ce\u00cc"+
-    "\3\2\2\2\u00cf\u00d2\7L\2\2\u00d0\u00d1\7\67\2\2\u00d1\u00d3\5\36\20\2"+
-    "\u00d2\u00d0\3\2\2\2\u00d2\u00d3\3\2\2\2\u00d3\31\3\2\2\2\u00d4\u00d5"+
-    "\7\30\2\2\u00d5\u00d6\7\t\2\2\u00d6\u00d7\7K\2\2\u00d7\u00d8\7L\2\2\u00d8"+
+    "\2\4\6\b\n\f\16\20\22\24\26\30\32\34\36 \"$&(*,.\60\62\64\2\16\3\28C\3"+
+    "\2\35\37\3\2 !\3\2\"$\3\2%(\3\2),\3\2\66\67\3\2DG\4\2\33\34 !\3\2NO\4"+
+    "\2\26\26MM\4\2\32\32MM\u01f3\29\3\2\2\2\4D\3\2\2\2\6I\3\2\2\2\b\u00a7"+
+    "\3\2\2\2\n\u00ab\3\2\2\2\f\u00ad\3\2\2\2\16\u00b6\3\2\2\2\20\u00ba\3\2"+
+    "\2\2\22\u00bc\3\2\2\2\24\u00be\3\2\2\2\26\u00c7\3\2\2\2\30\u00cf\3\2\2"+
+    "\2\32\u00d4\3\2\2\2\34\u00e0\3\2\2\2\36\u00eb\3\2\2\2 \u0148\3\2\2\2\""+
+    "\u016c\3\2\2\2$\u0180\3\2\2\2&\u0186\3\2\2\2(\u018d\3\2\2\2*\u018f\3\2"+
+    "\2\2,\u0193\3\2\2\2.\u01a3\3\2\2\2\60\u01b2\3\2\2\2\62\u01b8\3\2\2\2\64"+
+    "\u01c2\3\2\2\2\668\5\4\3\2\67\66\3\2\2\28;\3\2\2\29\67\3\2\2\29:\3\2\2"+
+    "\2:?\3\2\2\2;9\3\2\2\2<>\5\b\5\2=<\3\2\2\2>A\3\2\2\2?=\3\2\2\2?@\3\2\2"+
+    "\2@B\3\2\2\2A?\3\2\2\2BC\7\2\2\3C\3\3\2\2\2DE\5\26\f\2EF\7M\2\2FG\5\6"+
+    "\4\2GH\5\f\7\2H\5\3\2\2\2IU\7\t\2\2JK\5\26\f\2KR\7M\2\2LM\7\f\2\2MN\5"+
+    "\26\f\2NO\7M\2\2OQ\3\2\2\2PL\3\2\2\2QT\3\2\2\2RP\3\2\2\2RS\3\2\2\2SV\3"+
+    "\2\2\2TR\3\2\2\2UJ\3\2\2\2UV\3\2\2\2VW\3\2\2\2WX\7\n\2\2X\7\3\2\2\2YZ"+
+    "\7\16\2\2Z[\7\t\2\2[\\\5\36\20\2\\]\7\n\2\2]a\5\n\6\2^_\7\17\2\2_b\5\n"+
+    "\6\2`b\6\5\2\2a^\3\2\2\2a`\3\2\2\2b\u00a8\3\2\2\2cd\7\20\2\2de\7\t\2\2"+
+    "ef\5\36\20\2fi\7\n\2\2gj\5\n\6\2hj\5\16\b\2ig\3\2\2\2ih\3\2\2\2j\u00a8"+
+    "\3\2\2\2kl\7\21\2\2lm\5\f\7\2mn\7\20\2\2no\7\t\2\2op\5\36\20\2pq\7\n\2"+
+    "\2qr\5\34\17\2r\u00a8\3\2\2\2st\7\22\2\2tv\7\t\2\2uw\5\20\t\2vu\3\2\2"+
+    "\2vw\3\2\2\2wx\3\2\2\2xz\7\r\2\2y{\5\36\20\2zy\3\2\2\2z{\3\2\2\2{|\3\2"+
+    "\2\2|~\7\r\2\2}\177\5\22\n\2~}\3\2\2\2~\177\3\2\2\2\177\u0080\3\2\2\2"+
+    "\u0080\u0083\7\n\2\2\u0081\u0084\5\n\6\2\u0082\u0084\5\16\b\2\u0083\u0081"+
+    "\3\2\2\2\u0083\u0082\3\2\2\2\u0084\u00a8\3\2\2\2\u0085\u0086\7\22\2\2"+
+    "\u0086\u0087\7\t\2\2\u0087\u0088\5\26\f\2\u0088\u0089\7M\2\2\u0089\u008a"+
+    "\7\63\2\2\u008a\u008b\5\36\20\2\u008b\u008c\7\n\2\2\u008c\u008d\5\n\6"+
+    "\2\u008d\u00a8\3\2\2\2\u008e\u008f\5\24\13\2\u008f\u0090\5\34\17\2\u0090"+
+    "\u00a8\3\2\2\2\u0091\u0092\7\23\2\2\u0092\u00a8\5\34\17\2\u0093\u0094"+
+    "\7\24\2\2\u0094\u00a8\5\34\17\2\u0095\u0096\7\25\2\2\u0096\u0097\5\36"+
+    "\20\2\u0097\u0098\5\34\17\2\u0098\u00a8\3\2\2\2\u0099\u009a\7\27\2\2\u009a"+
+    "\u009c\5\f\7\2\u009b\u009d\5\32\16\2\u009c\u009b\3\2\2\2\u009d\u009e\3"+
+    "\2\2\2\u009e\u009c\3\2\2\2\u009e\u009f\3\2\2\2\u009f\u00a8\3\2\2\2\u00a0"+
+    "\u00a1\7\31\2\2\u00a1\u00a2\5\36\20\2\u00a2\u00a3\5\34\17\2\u00a3\u00a8"+
+    "\3\2\2\2\u00a4\u00a5\5\36\20\2\u00a5\u00a6\5\34\17\2\u00a6\u00a8\3\2\2"+
+    "\2\u00a7Y\3\2\2\2\u00a7c\3\2\2\2\u00a7k\3\2\2\2\u00a7s\3\2\2\2\u00a7\u0085"+
+    "\3\2\2\2\u00a7\u008e\3\2\2\2\u00a7\u0091\3\2\2\2\u00a7\u0093\3\2\2\2\u00a7"+
+    "\u0095\3\2\2\2\u00a7\u0099\3\2\2\2\u00a7\u00a0\3\2\2\2\u00a7\u00a4\3\2"+
+    "\2\2\u00a8\t\3\2\2\2\u00a9\u00ac\5\f\7\2\u00aa\u00ac\5\b\5\2\u00ab\u00a9"+
+    "\3\2\2\2\u00ab\u00aa\3\2\2\2\u00ac\13\3\2\2\2\u00ad\u00b1\7\5\2\2\u00ae"+
+    "\u00b0\5\b\5\2\u00af\u00ae\3\2\2\2\u00b0\u00b3\3\2\2\2\u00b1\u00af\3\2"+
+    "\2\2\u00b1\u00b2\3\2\2\2\u00b2\u00b4\3\2\2\2\u00b3\u00b1\3\2\2\2\u00b4"+
+    "\u00b5\7\6\2\2\u00b5\r\3\2\2\2\u00b6\u00b7\7\r\2\2\u00b7\17\3\2\2\2\u00b8"+
+    "\u00bb\5\24\13\2\u00b9\u00bb\5\36\20\2\u00ba\u00b8\3\2\2\2\u00ba\u00b9"+
+    "\3\2\2\2\u00bb\21\3\2\2\2\u00bc\u00bd\5\36\20\2\u00bd\23\3\2\2\2\u00be"+
+    "\u00bf\5\26\f\2\u00bf\u00c4\5\30\r\2\u00c0\u00c1\7\f\2\2\u00c1\u00c3\5"+
+    "\30\r\2\u00c2\u00c0\3\2\2\2\u00c3\u00c6\3\2\2\2\u00c4\u00c2\3\2\2\2\u00c4"+
+    "\u00c5\3\2\2\2\u00c5\25\3\2\2\2\u00c6\u00c4\3\2\2\2\u00c7\u00cc\7L\2\2"+
+    "\u00c8\u00c9\7\7\2\2\u00c9\u00cb\7\b\2\2\u00ca\u00c8\3\2\2\2\u00cb\u00ce"+
+    "\3\2\2\2\u00cc\u00ca\3\2\2\2\u00cc\u00cd\3\2\2\2\u00cd\27\3\2\2\2\u00ce"+
+    "\u00cc\3\2\2\2\u00cf\u00d2\7M\2\2\u00d0\u00d1\78\2\2\u00d1\u00d3\5\36"+
+    "\20\2\u00d2\u00d0\3\2\2\2\u00d2\u00d3\3\2\2\2\u00d3\31\3\2\2\2\u00d4\u00d5"+
+    "\7\30\2\2\u00d5\u00d6\7\t\2\2\u00d6\u00d7\7L\2\2\u00d7\u00d8\7M\2\2\u00d8"+
     "\u00d9\7\n\2\2\u00d9\u00da\5\f\7\2\u00da\33\3\2\2\2\u00db\u00e1\7\r\2"+
     "\2\u00dc\u00e1\7\2\2\3\u00dd\u00de\b\17\1\2\u00de\u00df\7\6\2\2\u00df"+
     "\u00e1\b\17\1\2\u00e0\u00db\3\2\2\2\u00e0\u00dc\3\2\2\2\u00e0\u00dd\3"+
@@ -3113,27 +3120,27 @@ class PainlessParser extends Parser {
     "\2\u00fb\u0127\3\2\2\2\u00fc\u00fd\f\13\2\2\u00fd\u00fe\t\6\2\2\u00fe"+
     "\u00ff\5\36\20\f\u00ff\u0100\b\20\1\2\u0100\u0127\3\2\2\2\u0101\u0102"+
     "\f\n\2\2\u0102\u0103\t\7\2\2\u0103\u0104\5\36\20\13\u0104\u0105\b\20\1"+
-    "\2\u0105\u0127\3\2\2\2\u0106\u0107\f\t\2\2\u0107\u0108\7,\2\2\u0108\u0109"+
+    "\2\u0105\u0127\3\2\2\2\u0106\u0107\f\t\2\2\u0107\u0108\7-\2\2\u0108\u0109"+
     "\5\36\20\n\u0109\u010a\b\20\1\2\u010a\u0127\3\2\2\2\u010b\u010c\f\b\2"+
-    "\2\u010c\u010d\7-\2\2\u010d\u010e\5\36\20\t\u010e\u010f\b\20\1\2\u010f"+
-    "\u0127\3\2\2\2\u0110\u0111\f\7\2\2\u0111\u0112\7.\2\2\u0112\u0113\5\36"+
+    "\2\u010c\u010d\7.\2\2\u010d\u010e\5\36\20\t\u010e\u010f\b\20\1\2\u010f"+
+    "\u0127\3\2\2\2\u0110\u0111\f\7\2\2\u0111\u0112\7/\2\2\u0112\u0113\5\36"+
     "\20\b\u0113\u0114\b\20\1\2\u0114\u0127\3\2\2\2\u0115\u0116\f\6\2\2\u0116"+
-    "\u0117\7/\2\2\u0117\u0118\5\36\20\7\u0118\u0119\b\20\1\2\u0119\u0127\3"+
-    "\2\2\2\u011a\u011b\f\5\2\2\u011b\u011c\7\60\2\2\u011c\u011d\5\36\20\6"+
-    "\u011d\u011e\b\20\1\2\u011e\u0127\3\2\2\2\u011f\u0120\f\4\2\2\u0120\u0121"+
-    "\7\61\2\2\u0121\u0122\5\36\20\2\u0122\u0123\7\62\2\2\u0123\u0124\5\36"+
-    "\20\4\u0124\u0125\b\20\1\2\u0125\u0127\3\2\2\2\u0126\u00ed\3\2\2\2\u0126"+
-    "\u00f2\3\2\2\2\u0126\u00f7\3\2\2\2\u0126\u00fc\3\2\2\2\u0126\u0101\3\2"+
-    "\2\2\u0126\u0106\3\2\2\2\u0126\u010b\3\2\2\2\u0126\u0110\3\2\2\2\u0126"+
+    "\u0117\7\60\2\2\u0117\u0118\5\36\20\7\u0118\u0119\b\20\1\2\u0119\u0127"+
+    "\3\2\2\2\u011a\u011b\f\5\2\2\u011b\u011c\7\61\2\2\u011c\u011d\5\36\20"+
+    "\6\u011d\u011e\b\20\1\2\u011e\u0127\3\2\2\2\u011f\u0120\f\4\2\2\u0120"+
+    "\u0121\7\62\2\2\u0121\u0122\5\36\20\2\u0122\u0123\7\63\2\2\u0123\u0124"+
+    "\5\36\20\4\u0124\u0125\b\20\1\2\u0125\u0127\3\2\2\2\u0126\u00ed\3\2\2"+
+    "\2\u0126\u00f2\3\2\2\2\u0126\u00f7\3\2\2\2\u0126\u00fc\3\2\2\2\u0126\u0101"+
+    "\3\2\2\2\u0126\u0106\3\2\2\2\u0126\u010b\3\2\2\2\u0126\u0110\3\2\2\2\u0126"+
     "\u0115\3\2\2\2\u0126\u011a\3\2\2\2\u0126\u011f\3\2\2\2\u0127\u012a\3\2"+
     "\2\2\u0128\u0126\3\2\2\2\u0128\u0129\3\2\2\2\u0129\37\3\2\2\2\u012a\u0128"+
     "\3\2\2\2\u012b\u012c\6\21\16\3\u012c\u012d\t\b\2\2\u012d\u0149\5\"\22"+
     "\2\u012e\u012f\6\21\17\3\u012f\u0130\5\"\22\2\u0130\u0131\t\b\2\2\u0131"+
     "\u0149\3\2\2\2\u0132\u0133\6\21\20\3\u0133\u0149\5\"\22\2\u0134\u0135"+
     "\6\21\21\3\u0135\u0136\t\t\2\2\u0136\u0149\b\21\1\2\u0137\u0138\6\21\22"+
-    "\3\u0138\u0139\7H\2\2\u0139\u0149\b\21\1\2\u013a\u013b\6\21\23\3\u013b"+
-    "\u013c\7I\2\2\u013c\u0149\b\21\1\2\u013d\u013e\6\21\24\3\u013e\u013f\7"+
-    "J\2\2\u013f\u0149\b\21\1\2\u0140\u0141\6\21\25\3\u0141\u0142\t\n\2\2\u0142"+
+    "\3\u0138\u0139\7I\2\2\u0139\u0149\b\21\1\2\u013a\u013b\6\21\23\3\u013b"+
+    "\u013c\7J\2\2\u013c\u0149\b\21\1\2\u013d\u013e\6\21\24\3\u013e\u013f\7"+
+    "K\2\2\u013f\u0149\b\21\1\2\u0140\u0141\6\21\25\3\u0141\u0142\t\n\2\2\u0142"+
     "\u0149\5 \21\2\u0143\u0144\7\t\2\2\u0144\u0145\5\26\f\2\u0145\u0146\7"+
     "\n\2\2\u0146\u0147\5 \21\2\u0147\u0149\3\2\2\2\u0148\u012b\3\2\2\2\u0148"+
     "\u012e\3\2\2\2\u0148\u0132\3\2\2\2\u0148\u0134\3\2\2\2\u0148\u0137\3\2"+
@@ -3143,7 +3150,7 @@ class PainlessParser extends Parser {
     "\3\2\2\2\u014f\u016d\3\2\2\2\u0150\u014e\3\2\2\2\u0151\u0152\5\26\f\2"+
     "\u0152\u0156\5(\25\2\u0153\u0155\5&\24\2\u0154\u0153\3\2\2\2\u0155\u0158"+
     "\3\2\2\2\u0156\u0154\3\2\2\2\u0156\u0157\3\2\2\2\u0157\u016d\3\2\2\2\u0158"+
-    "\u0156\3\2\2\2\u0159\u015a\7\26\2\2\u015a\u015f\7K\2\2\u015b\u015c\7\7"+
+    "\u0156\3\2\2\2\u0159\u015a\7\26\2\2\u015a\u015f\7L\2\2\u015b\u015c\7\7"+
     "\2\2\u015c\u015d\5\36\20\2\u015d\u015e\7\b\2\2\u015e\u0160\3\2\2\2\u015f"+
     "\u015b\3\2\2\2\u0160\u0161\3\2\2\2\u0161\u015f\3\2\2\2\u0161\u0162\3\2"+
     "\2\2\u0162\u016a\3\2\2\2\u0163\u0167\5(\25\2\u0164\u0166\5&\24\2\u0165"+
@@ -3153,14 +3160,14 @@ class PainlessParser extends Parser {
     "\2\2\u016c\u0159\3\2\2\2\u016d#\3\2\2\2\u016e\u016f\6\23\26\3\u016f\u0170"+
     "\7\t\2\2\u0170\u0171\5\36\20\2\u0171\u0172\7\n\2\2\u0172\u0173\b\23\1"+
     "\2\u0173\u0181\3\2\2\2\u0174\u0175\6\23\27\3\u0175\u0176\7\t\2\2\u0176"+
-    "\u0177\5 \21\2\u0177\u0178\7\n\2\2\u0178\u0181\3\2\2\2\u0179\u0181\7G"+
-    "\2\2\u017a\u0181\7L\2\2\u017b\u017c\7L\2\2\u017c\u0181\5,\27\2\u017d\u017e"+
-    "\7\26\2\2\u017e\u017f\7K\2\2\u017f\u0181\5,\27\2\u0180\u016e\3\2\2\2\u0180"+
+    "\u0177\5 \21\2\u0177\u0178\7\n\2\2\u0178\u0181\3\2\2\2\u0179\u0181\7H"+
+    "\2\2\u017a\u0181\7M\2\2\u017b\u017c\7M\2\2\u017c\u0181\5,\27\2\u017d\u017e"+
+    "\7\26\2\2\u017e\u017f\7L\2\2\u017f\u0181\5,\27\2\u0180\u016e\3\2\2\2\u0180"+
     "\u0174\3\2\2\2\u0180\u0179\3\2\2\2\u0180\u017a\3\2\2\2\u0180\u017b\3\2"+
     "\2\2\u0180\u017d\3\2\2\2\u0181%\3\2\2\2\u0182\u0183\6\24\30\3\u0183\u0187"+
     "\5(\25\2\u0184\u0185\6\24\31\3\u0185\u0187\5*\26\2\u0186\u0182\3\2\2\2"+
     "\u0186\u0184\3\2\2\2\u0187\'\3\2\2\2\u0188\u0189\7\13\2\2\u0189\u018a"+
-    "\7N\2\2\u018a\u018e\5,\27\2\u018b\u018c\7\13\2\2\u018c\u018e\t\13\2\2"+
+    "\7O\2\2\u018a\u018e\5,\27\2\u018b\u018c\7\13\2\2\u018c\u018e\t\13\2\2"+
     "\u018d\u0188\3\2\2\2\u018d\u018b\3\2\2\2\u018e)\3\2\2\2\u018f\u0190\7"+
     "\7\2\2\u0190\u0191\5\36\20\2\u0191\u0192\7\b\2\2\u0192+\3\2\2\2\u0193"+
     "\u019c\7\t\2\2\u0194\u0199\5.\30\2\u0195\u0196\7\f\2\2\u0196\u0198\5."+
@@ -3174,11 +3181,11 @@ class PainlessParser extends Parser {
     "\u01ae\3\2\2\2\u01ac\u01aa\3\2\2\2\u01ac\u01ad\3\2\2\2\u01ad\u01b0\3\2"+
     "\2\2\u01ae\u01ac\3\2\2\2\u01af\u01a7\3\2\2\2\u01af\u01b0\3\2\2\2\u01b0"+
     "\u01b1\3\2\2\2\u01b1\u01b3\7\n\2\2\u01b2\u01a5\3\2\2\2\u01b2\u01a6\3\2"+
-    "\2\2\u01b3\u01b4\3\2\2\2\u01b4\u01b5\7\64\2\2\u01b5\u01b6\5\f\7\2\u01b6"+
+    "\2\2\u01b3\u01b4\3\2\2\2\u01b4\u01b5\7\65\2\2\u01b5\u01b6\5\f\7\2\u01b6"+
     "\61\3\2\2\2\u01b7\u01b9\5\26\f\2\u01b8\u01b7\3\2\2\2\u01b8\u01b9\3\2\2"+
-    "\2\u01b9\u01ba\3\2\2\2\u01ba\u01bb\7L\2\2\u01bb\63\3\2\2\2\u01bc\u01bd"+
-    "\7K\2\2\u01bd\u01be\7\63\2\2\u01be\u01c3\t\f\2\2\u01bf\u01c0\7L\2\2\u01c0"+
-    "\u01c1\7\63\2\2\u01c1\u01c3\7L\2\2\u01c2\u01bc\3\2\2\2\u01c2\u01bf\3\2"+
+    "\2\u01b9\u01ba\3\2\2\2\u01ba\u01bb\7M\2\2\u01bb\63\3\2\2\2\u01bc\u01bd"+
+    "\7L\2\2\u01bd\u01be\7\64\2\2\u01be\u01c3\t\f\2\2\u01bf\u01c0\t\r\2\2\u01c0"+
+    "\u01c1\7\64\2\2\u01c1\u01c3\7M\2\2\u01c2\u01bc\3\2\2\2\u01c2\u01bf\3\2"+
     "\2\2\u01c3\65\3\2\2\2*9?RUaivz~\u0083\u009e\u00a7\u00ab\u00b1\u00ba\u00c4"+
     "\u00cc\u00d2\u00e0\u00eb\u0126\u0128\u0148\u014e\u0156\u0161\u0167\u016a"+
     "\u016c\u0180\u0186\u018d\u0199\u019c\u01a3\u01ac\u01af\u01b2\u01b8\u01c2";

+ 3 - 0
modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/Walker.java

@@ -449,6 +449,7 @@ public final class Walker extends PainlessParserBaseVisitor<Object> {
         throw location(ctx).createError(new IllegalStateException("Illegal tree structure."));
     }
 
+    @Override
     public Object visitDeclvar(DeclvarContext ctx) {
         throw location(ctx).createError(new IllegalStateException("Illegal tree structure."));
     }
@@ -958,6 +959,8 @@ public final class Walker extends PainlessParserBaseVisitor<Object> {
                 methodText = ctx.ID(0).getText();
             }
             return new EFunctionRef(location(ctx), ctx.TYPE().getText(), methodText);
+        } else if (ctx.THIS() != null) {
+            return new EFunctionRef(location(ctx), ctx.THIS().getText(), ctx.ID(0).getText());
         } else {
             // capturing object::method
             return new ECapturingFunctionRef(location(ctx), ctx.ID(0).getText(), ctx.ID(1).getText());

+ 19 - 1
modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EFunctionRef.java

@@ -23,6 +23,8 @@ import org.elasticsearch.painless.Definition;
 import org.elasticsearch.painless.FunctionRef;
 import org.elasticsearch.painless.Location;
 import org.elasticsearch.painless.MethodWriter;
+import org.elasticsearch.painless.Definition.Method;
+import org.elasticsearch.painless.Definition.MethodKey;
 import org.elasticsearch.painless.Locals;
 import org.objectweb.asm.Type;
 
@@ -53,7 +55,23 @@ public class EFunctionRef extends AExpression {
             actual = Definition.getType("String");
         } else {
             try {
-                ref = new FunctionRef(expected, type, call);
+                if ("this".equals(type)) {
+                    // user's own function
+                    Method interfaceMethod = expected.struct.getFunctionalMethod();
+                    if (interfaceMethod == null) {
+                        throw new IllegalArgumentException("Cannot convert function reference [" + type + "::" + call + "] " +
+                                                           "to [" + expected.name + "], not a functional interface");
+                    }
+                    Method implMethod = locals.getMethod(new MethodKey(call, interfaceMethod.arguments.size()));
+                    if (implMethod == null) {
+                        throw new IllegalArgumentException("Cannot convert function reference [" + type + "::" + call + "] " +
+                                                           "to [" + expected.name + "], function not found");
+                    }
+                    ref = new FunctionRef(expected, interfaceMethod, implMethod);
+                } else {
+                    // whitelist lookup
+                    ref = new FunctionRef(expected, type, call);
+                }
             } catch (IllegalArgumentException e) {
                 throw createError(e);
             }

+ 0 - 2
modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ELambda.java

@@ -33,8 +33,6 @@ public class ELambda extends AExpression {
     final List<String> paramNameStrs;
     final List<AStatement> statements;
 
-    Locals locals = null;
-
     public ELambda(FunctionReserved reserved, Location location,
                    List<String> paramTypes, List<String> paramNames, List<AStatement> statements) {
         super(location);

+ 0 - 1
modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SExpression.java

@@ -19,7 +19,6 @@
 
 package org.elasticsearch.painless.node;
 
-import org.elasticsearch.painless.Definition;
 import org.elasticsearch.painless.Definition.Type;
 import org.elasticsearch.painless.Location;
 import org.elasticsearch.painless.Definition.Sort;

+ 17 - 6
modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SFunction.java

@@ -19,6 +19,7 @@
 
 package org.elasticsearch.painless.node;
 
+import org.elasticsearch.painless.Def;
 import org.elasticsearch.painless.Definition;
 import org.elasticsearch.painless.Definition.Method;
 import org.elasticsearch.painless.Definition.Sort;
@@ -29,10 +30,13 @@ import org.elasticsearch.painless.Locals.FunctionReserved;
 import org.elasticsearch.painless.Locals.Variable;
 import org.elasticsearch.painless.Location;
 import org.elasticsearch.painless.MethodWriter;
+import org.objectweb.asm.ClassWriter;
 import org.objectweb.asm.Opcodes;
 
 import java.lang.invoke.MethodType;
+import java.lang.reflect.Modifier;
 import java.util.ArrayList;
+import java.util.BitSet;
 import java.util.Collections;
 import java.util.List;
 
@@ -94,7 +98,7 @@ public class SFunction extends AStatement {
 
         org.objectweb.asm.commons.Method method =
             new org.objectweb.asm.commons.Method(name, MethodType.methodType(rtnType.clazz, paramClasses).toMethodDescriptorString());
-        this.method = new Method(name, null, rtnType, paramTypes, method, 0, null);
+        this.method = new Method(name, null, rtnType, paramTypes, method, Modifier.STATIC | Modifier.PRIVATE, null);
     }
 
     @Override
@@ -131,11 +135,16 @@ public class SFunction extends AStatement {
 
         locals.decrementScope();
     }
+    
+    /** Writes the function to given ClassWriter. */
+    void write (ClassWriter writer, BitSet statements) {
+        final MethodWriter function = new MethodWriter(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC, method.method, writer, statements);
+        write(function);
+        function.endMethod();
+    }
 
     @Override
-    void write(MethodWriter writer) {
-        MethodWriter function = writer.newMethodWriter(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC, method.method);
-
+    void write(MethodWriter function) {
         if (reserved.getMaxLoopCounter() > 0) {
             // if there is infinite loop protection, we do this once:
             // int #loop = settings.getMaxLoopCounter()
@@ -157,7 +166,9 @@ public class SFunction extends AStatement {
                 throw createError(new IllegalStateException("Illegal tree structure."));
             }
         }
-
-        function.endMethod();
+    }
+    
+    String getStaticHandleFieldName() {
+        return Def.getUserFunctionHandleFieldName(name, parameters.size());
     }
 }

+ 41 - 17
modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SSource.java

@@ -26,11 +26,13 @@ import org.elasticsearch.painless.Locals;
 import org.elasticsearch.painless.Locals.ExecuteReserved;
 import org.elasticsearch.painless.Locals.Variable;
 import org.elasticsearch.painless.WriterConstants;
-import org.objectweb.asm.ClassWriter;
-import org.objectweb.asm.Opcodes;
 import org.elasticsearch.painless.Location;
 import org.elasticsearch.painless.MethodWriter;
 
+import org.objectweb.asm.ClassWriter;
+import org.objectweb.asm.Handle;
+import org.objectweb.asm.Opcodes;
+
 import java.util.BitSet;
 import java.util.Collections;
 import java.util.HashMap;
@@ -133,37 +135,59 @@ public final class SSource extends AStatement {
         writer.visit(classVersion, classAccess, className, null, classBase, classInterfaces);
         writer.visitSource(Location.computeSourceName(name, source), null);
 
-        // Create the execute MethodWriter.
-
         expressions = new BitSet(source.length());
-        MethodWriter execute = new MethodWriter(Opcodes.ACC_PUBLIC, EXECUTE, writer, expressions);
-
-        // Write the constructor.
 
-        MethodWriter constructor = execute.newMethodWriter(Opcodes.ACC_PUBLIC, CONSTRUCTOR);
+        // Write the constructor:
+        MethodWriter constructor = new MethodWriter(Opcodes.ACC_PUBLIC, CONSTRUCTOR, writer, expressions);
         constructor.loadThis();
         constructor.loadArgs();
         constructor.invokeConstructor(org.objectweb.asm.Type.getType(Executable.class), CONSTRUCTOR);
         constructor.returnValue();
         constructor.endMethod();
 
-        // Write the execute method.
-
+        // Write the execute method:
+        MethodWriter execute = new MethodWriter(Opcodes.ACC_PUBLIC, EXECUTE, writer, expressions);
         write(execute);
         execute.endMethod();
+        
+        // Write all functions:
+        for (SFunction function : functions) {
+            function.write(writer, expressions);
+        }
 
-        // End writing the class and store the generated bytes.
-
+        // Write a static field with Handle (function reference) for every function:
+        if (!functions.isEmpty()) {
+            for (SFunction function : functions) {
+                writer.visitField(Opcodes.ACC_FINAL | Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC, 
+                        function.getStaticHandleFieldName(), 
+                        WriterConstants.METHOD_HANDLE_TYPE.getDescriptor(), 
+                        null, 
+                        null).visitEnd();
+            }
+            final MethodWriter clinit = new MethodWriter(Opcodes.ACC_STATIC, 
+                                                   WriterConstants.CLINIT, writer, expressions);
+            for (SFunction function : functions) {
+                final Handle handle = new Handle(Opcodes.H_INVOKESTATIC, 
+                                           CLASS_TYPE.getInternalName(), 
+                                           function.name, 
+                                           function.method.method.getDescriptor(), 
+                                           false);
+                clinit.push(handle);
+                clinit.putStatic(CLASS_TYPE, 
+                                 function.getStaticHandleFieldName(), 
+                                 WriterConstants.METHOD_HANDLE_TYPE);
+            }
+            clinit.returnValue();
+            clinit.endMethod();
+        }
+        
+        // End writing the class and store the generated bytes:
         writer.visitEnd();
         bytes = writer.toByteArray();
     }
-
+    
     @Override
     void write(MethodWriter writer) {
-        for (SFunction function : functions) {
-            function.write(writer);
-        }
-
         if (reserved.usesScore()) {
             // if the _score value is used, we do this once:
             // final double _score = scorer.score();

+ 20 - 2
modules/lang-painless/src/test/java/org/elasticsearch/painless/FunctionRefTests.java

@@ -19,8 +19,6 @@
 
 package org.elasticsearch.painless;
 
-import java.util.Comparator;
-
 public class FunctionRefTests extends ScriptTestCase {
 
     public void testStaticMethodReference() {
@@ -110,6 +108,26 @@ public class FunctionRefTests extends ScriptTestCase {
                 "def test = new org.elasticsearch.painless.FeatureTest(2,3);" + 
                 "return test.twoFunctionsOfX(x::concat, y::substring);"));
     }
+    
+    public void testOwnStaticMethodReference() {
+        assertEquals(2, exec("int mycompare(int i, int j) { j - i } " +
+                             "List l = new ArrayList(); l.add(2); l.add(1); l.sort(this::mycompare); return l.get(0);"));
+    }
+    
+    public void testOwnStaticMethodReferenceDef() {
+        assertEquals(2, exec("int mycompare(int i, int j) { j - i } " +
+                             "def l = new ArrayList(); l.add(2); l.add(1); l.sort(this::mycompare); return l.get(0);"));
+    }
+
+    public void testInterfaceDefaultMethod() {
+        assertEquals("bar", exec("String f(BiFunction function) { function.apply('foo', 'bar') }" + 
+                                 "Map map = new HashMap(); f(map::getOrDefault)"));
+    }
+    
+    public void testInterfaceDefaultMethodDef() {
+        assertEquals("bar", exec("String f(BiFunction function) { function.apply('foo', 'bar') }" + 
+                                 "def map = new HashMap(); f(map::getOrDefault)"));
+    }
 
     public void testMethodMissing() {
         IllegalArgumentException expected = expectScriptThrows(IllegalArgumentException.class, () -> {