1 /* |
1 /* |
2 * reserved comment block |
2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT REMOVE OR ALTER! |
3 * @LastModified: Oct 2017 |
4 */ |
4 */ |
5 /* |
5 /* |
6 * Licensed to the Apache Software Foundation (ASF) under one or more |
6 * Licensed to the Apache Software Foundation (ASF) under one or more |
7 * contributor license agreements. See the NOTICE file distributed with |
7 * contributor license agreements. See the NOTICE file distributed with |
8 * this work for additional information regarding copyright ownership. |
8 * this work for additional information regarding copyright ownership. |
19 * limitations under the License. |
19 * limitations under the License. |
20 */ |
20 */ |
21 |
21 |
22 package com.sun.org.apache.xalan.internal.xsltc.compiler; |
22 package com.sun.org.apache.xalan.internal.xsltc.compiler; |
23 |
23 |
24 import java.util.ArrayList; |
|
25 |
|
26 import com.sun.org.apache.bcel.internal.classfile.Field; |
24 import com.sun.org.apache.bcel.internal.classfile.Field; |
27 import com.sun.org.apache.bcel.internal.generic.ALOAD; |
25 import com.sun.org.apache.bcel.internal.generic.ALOAD; |
28 import com.sun.org.apache.bcel.internal.generic.ILOAD; |
|
29 import com.sun.org.apache.bcel.internal.generic.ASTORE; |
26 import com.sun.org.apache.bcel.internal.generic.ASTORE; |
30 import com.sun.org.apache.bcel.internal.generic.BranchHandle; |
27 import com.sun.org.apache.bcel.internal.generic.BranchHandle; |
31 import com.sun.org.apache.bcel.internal.generic.CHECKCAST; |
28 import com.sun.org.apache.bcel.internal.generic.CHECKCAST; |
32 import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen; |
29 import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen; |
|
30 import com.sun.org.apache.bcel.internal.generic.D2I; |
33 import com.sun.org.apache.bcel.internal.generic.GETFIELD; |
31 import com.sun.org.apache.bcel.internal.generic.GETFIELD; |
34 import com.sun.org.apache.bcel.internal.generic.GOTO; |
32 import com.sun.org.apache.bcel.internal.generic.GOTO; |
35 import com.sun.org.apache.bcel.internal.generic.IFNONNULL; |
33 import com.sun.org.apache.bcel.internal.generic.IFNONNULL; |
|
34 import com.sun.org.apache.bcel.internal.generic.ILOAD; |
36 import com.sun.org.apache.bcel.internal.generic.INVOKESPECIAL; |
35 import com.sun.org.apache.bcel.internal.generic.INVOKESPECIAL; |
37 import com.sun.org.apache.bcel.internal.generic.INVOKESTATIC; |
36 import com.sun.org.apache.bcel.internal.generic.INVOKESTATIC; |
38 import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL; |
37 import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL; |
39 import com.sun.org.apache.bcel.internal.generic.InstructionList; |
38 import com.sun.org.apache.bcel.internal.generic.InstructionList; |
40 import com.sun.org.apache.bcel.internal.generic.D2I; |
|
41 import com.sun.org.apache.bcel.internal.generic.LocalVariableGen; |
39 import com.sun.org.apache.bcel.internal.generic.LocalVariableGen; |
42 import com.sun.org.apache.bcel.internal.generic.NEW; |
40 import com.sun.org.apache.bcel.internal.generic.NEW; |
43 import com.sun.org.apache.bcel.internal.generic.PUSH; |
41 import com.sun.org.apache.bcel.internal.generic.PUSH; |
44 import com.sun.org.apache.bcel.internal.generic.PUTFIELD; |
42 import com.sun.org.apache.bcel.internal.generic.PUTFIELD; |
45 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator; |
43 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator; |
48 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.NodeCounterGenerator; |
46 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.NodeCounterGenerator; |
49 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.RealType; |
47 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.RealType; |
50 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type; |
48 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type; |
51 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError; |
49 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError; |
52 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util; |
50 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util; |
|
51 import java.util.ArrayList; |
|
52 import java.util.List; |
53 |
53 |
54 /** |
54 /** |
55 * @author Jacek Ambroziak |
55 * @author Jacek Ambroziak |
56 * @author Santiago Pericas-Geertsen |
56 * @author Santiago Pericas-Geertsen |
57 */ |
57 */ |
84 |
84 |
85 private int _level = LEVEL_SINGLE; |
85 private int _level = LEVEL_SINGLE; |
86 private boolean _formatNeeded = false; |
86 private boolean _formatNeeded = false; |
87 |
87 |
88 private String _className = null; |
88 private String _className = null; |
89 private ArrayList _closureVars = null; |
89 private List<VariableRefBase> _closureVars = null; |
90 |
90 |
91 // -- Begin Closure interface -------------------- |
91 // -- Begin Closure interface -------------------- |
92 |
92 |
93 /** |
93 /** |
94 * Returns true if this closure is compiled in an inner class (i.e. |
94 * Returns true if this closure is compiled in an inner class (i.e. |
116 /** |
116 /** |
117 * Add new variable to the closure. |
117 * Add new variable to the closure. |
118 */ |
118 */ |
119 public void addVariable(VariableRefBase variableRef) { |
119 public void addVariable(VariableRefBase variableRef) { |
120 if (_closureVars == null) { |
120 if (_closureVars == null) { |
121 _closureVars = new ArrayList(); |
121 _closureVars = new ArrayList<>(); |
122 } |
122 } |
123 |
123 |
124 // Only one reference per variable |
124 // Only one reference per variable |
125 if (!_closureVars.contains(variableRef)) { |
125 if (!_closureVars.contains(variableRef)) { |
126 _closureVars.add(variableRef); |
126 _closureVars.add(variableRef); |
393 // Add a new instance variable for each var in closure |
393 // Add a new instance variable for each var in closure |
394 final int closureLen = (_closureVars == null) ? 0 : |
394 final int closureLen = (_closureVars == null) ? 0 : |
395 _closureVars.size(); |
395 _closureVars.size(); |
396 |
396 |
397 for (int i = 0; i < closureLen; i++) { |
397 for (int i = 0; i < closureLen; i++) { |
398 VariableBase var = |
398 VariableBase var = (_closureVars.get(i)).getVariable(); |
399 ((VariableRefBase) _closureVars.get(i)).getVariable(); |
|
400 |
399 |
401 nodeCounterGen.addField(new Field(ACC_PUBLIC, |
400 nodeCounterGen.addField(new Field(ACC_PUBLIC, |
402 cpg.addUtf8(var.getEscapedName()), |
401 cpg.addUtf8(var.getEscapedName()), |
403 cpg.addUtf8(var.getType().toSignature()), |
402 cpg.addUtf8(var.getType().toSignature()), |
404 null, cpg.getConstantPool())); |
403 null, cpg.getConstantPool())); |