1 /*
2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
3  */
4 /*
5  * Licensed to the Apache Software Foundation (ASF) under one or more
6  * contributor license agreements.  See the NOTICE file distributed with
7  * this work for additional information regarding copyright ownership.
8  * The ASF licenses this file to You under the Apache License, Version 2.0
9  * (the "License"); you may not use this file except in compliance with
10  * the License.  You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 package com.sun.org.apache.xalan.internal.xsltc.compiler.util;
22 
23 import com.sun.org.apache.bcel.internal.generic.ALOAD;
24 import com.sun.org.apache.bcel.internal.generic.ASTORE;
25 import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
26 import com.sun.org.apache.bcel.internal.generic.Instruction;
27 import com.sun.org.apache.bcel.internal.generic.InstructionList;
28 import com.sun.org.apache.bcel.internal.generic.Type;
29 
30 /**
31  * @author Santiago Pericas-Geertsen
32  */
33 public final class AttributeSetMethodGenerator extends MethodGenerator {
34 
35     protected static final int CURRENT_INDEX  = 4;
36     private static final int PARAM_START_INDEX = 5;
37 
38     private static final String[] argNames = new String[4];
39     private static final com.sun.org.apache.bcel.internal.generic.Type[] argTypes =
40         new com.sun.org.apache.bcel.internal.generic.Type[4];
41 
42     static {
43         argTypes[0] = Util.getJCRefType(DOM_INTF_SIG);
44         argTypes[1] = Util.getJCRefType(NODE_ITERATOR_SIG);
45         argTypes[2] = Util.getJCRefType(TRANSLET_OUTPUT_SIG);
46         argTypes[3] = com.sun.org.apache.bcel.internal.generic.Type.INT;
47         argNames[0] = DOCUMENT_PNAME;
48         argNames[1] = ITERATOR_PNAME;
49         argNames[2] = TRANSLET_OUTPUT_PNAME;
50         argNames[3] = NODE_PNAME;
51     }
52 
AttributeSetMethodGenerator(String methodName, ClassGenerator classGen)53    public AttributeSetMethodGenerator(String methodName, ClassGenerator classGen) {
54         super(com.sun.org.apache.bcel.internal.Const.ACC_PRIVATE,
55               com.sun.org.apache.bcel.internal.generic.Type.VOID,
56               argTypes, argNames, methodName,
57               classGen.getClassName(),
58               new InstructionList(),
59               classGen.getConstantPool());
60    }
61 
getLocalIndex(String name)62     public int getLocalIndex(String name) {
63         if (name.equals("current")) {
64             return CURRENT_INDEX;
65         }
66         return super.getLocalIndex(name);
67     }
68 
loadParameter(int index)69     public Instruction loadParameter(int index) {
70         return new ALOAD(index + PARAM_START_INDEX);
71     }
72 
storeParameter(int index)73     public Instruction storeParameter(int index) {
74         return new ASTORE(index + PARAM_START_INDEX);
75     }
76 }
77