changeset 33:ed446c8485ec

CODETOOLS-7902332 jasm should support nested static arguments of bootstrap methods
author lkuskov
date Mon, 15 Oct 2018 15:48:11 -0700
parents ace7df328bb1
children 9dca9ca5771e
files src/org/openjdk/asmtools/jasm/ParserCP.java
diffstat 1 files changed, 18 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- a/src/org/openjdk/asmtools/jasm/ParserCP.java	Mon Sep 24 14:22:06 2018 -0700
+++ b/src/org/openjdk/asmtools/jasm/ParserCP.java	Mon Oct 15 15:48:11 2018 -0700
@@ -24,6 +24,7 @@
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.function.BiFunction;
 
 import static org.openjdk.asmtools.jasm.JasmTokens.Token;
 import static org.openjdk.asmtools.jasm.Tables.*;
@@ -430,7 +431,21 @@
         @Override
         public ConstantPool.ConstValue_IndyPair visitInvokedynamic(ConstType tag) {
             debugStr("------- [ParserCPVisitor.visitInvokeDynamic]: ");
-            ConstantPool.ConstValue_IndyPair obj = null;
+            final BiFunction<BootstrapMethodData, ConstantPool.ConstCell, ConstantPool.ConstValue_IndyPair> ctor =
+                    (bsmData, napeCell) -> new ConstantPool.ConstValue_IndyPair(bsmData, napeCell);
+            return visitBsm(ctor);
+        }
+
+        @Override
+        public ConstantPool.ConstValue_CondyPair visitDynamic(ConstType tag) {
+            debugStr("------- [ParserCPVisitor.visitDynamic]: ");
+            final BiFunction<BootstrapMethodData, ConstantPool.ConstCell, ConstantPool.ConstValue_CondyPair> ctor =
+                    (bsmData, napeCell) -> new ConstantPool.ConstValue_CondyPair(bsmData, napeCell);
+            return visitBsm(ctor);
+        }
+
+        private <E extends ConstantPool.ConstValue_IndyOrCondyPair> E visitBsm(BiFunction<BootstrapMethodData, ConstantPool.ConstCell, E> ctor) {
+            E obj = null;
             try {
                 if (scanner.token == Token.INTVAL) {
                     // Handle explicit constant pool form
@@ -447,54 +462,7 @@
                     // Put a placeholder in place of BSM.
                     // resolve placeholder after the attributes are scanned.
                     BootstrapMethodData bsmData = new BootstrapMethodData(bsmIndex);
-                    obj = new ConstantPool.ConstValue_IndyPair(bsmData, parser.pool.getCell(cpx));
-
-                } else {
-                    // Handle full form
-                    ConstantPool.ConstCell MHCell = parser.pool.FindCell(parseConstValue(ConstType.CONSTANT_METHODHANDLE));
-                    scanner.expect(Token.COLON);
-                    ConstantPool.ConstCell NapeCell = parser.pool.FindCell(parseConstValue(ConstType.CONSTANT_NAMEANDTYPE));
-
-                    ArrayList<ConstantPool.ConstCell> bsm_args = new ArrayList<>(256);
-
-                    for (boolean sep = false; scanner.token != Token.SEMICOLON; sep = true) {
-                        if (sep) scanner.expect(Token.COMMA);
-                        bsm_args.add(parseConstRef(null));
-                        scanner.idValue = null; // Clear tag
-                    }
-
-                    BootstrapMethodData bsmData = new BootstrapMethodData(MHCell, bsm_args);
-                    parser.cd.addBootstrapMethod(bsmData);
-                    obj = new ConstantPool.ConstValue_IndyPair(bsmData, NapeCell);
-                }
-            } catch (IOException e) {
-                IOProb = e;
-            }
-            return obj;
-        }
-
-        @Override
-        public ConstantPool.ConstValue_CondyPair visitDynamic(ConstType tag) {
-            debugStr("------- [ParserCPVisitor.visitDynamic]: ");
-            ConstantPool.ConstValue_CondyPair obj = null;
-            try {
-                if (scanner.token == Token.INTVAL) {
-                    // Handle explicit constant pool form
-                    int bsmIndex = scanner.intValue;
-                    scanner.scan();
-                    scanner.expect(Token.COLON);
-                    if (scanner.token != Token.CPINDEX) {
-                        env.traceln("token=" + scanner.token);
-                        env.error(scanner.pos, "token.expected", "<CPINDEX>");
-                        throw new Scanner.SyntaxError();
-                    }
-                    int cpx = scanner.intValue;
-                    scanner.scan();
-                    // Put a placeholder in place of BSM.
-                    // resolve placeholder after the attributes are scanned.
-                    BootstrapMethodData bsmData = new BootstrapMethodData(bsmIndex);
-                    obj = new ConstantPool.ConstValue_CondyPair(bsmData, parser.pool.getCell(cpx));
-
+                    obj =   ctor.apply(bsmData, parser.pool.getCell(cpx));
                 } else {
                     // Handle full form
                     ConstantPool.ConstCell MHCell = parser.pool.FindCell(parseConstValue(ConstType.CONSTANT_METHODHANDLE));
@@ -527,7 +495,7 @@
                     }
                     BootstrapMethodData bsmData = new BootstrapMethodData(MHCell, bsm_args);
                     parser.cd.addBootstrapMethod(bsmData);
-                    obj = new ConstantPool.ConstValue_CondyPair(bsmData, NapeCell);
+                    obj = ctor.apply(bsmData, NapeCell);
                 }
             } catch (IOException e) {
                 IOProb = e;