jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/FunctionCall.java
author dfuchs
Fri, 17 May 2013 10:40:21 +0200
changeset 17538 d8d911c4e5d4
parent 12458 d601e4bba306
child 21467 ed77f0ff062c
permissions -rw-r--r--
8013900: More warnings compiling jaxp. Summary: Some internal implementation classes in Jaxp were redefining equals() without redefining hashCode(). This patch adds hashCode() methods that are consistent with equals(). Reviewed-by: chegar, joehw
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     2
 * reserved comment block
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     6
 * Copyright 2001-2004 The Apache Software Foundation.
7f561c08de6b Initial load
duke
parents:
diff changeset
     7
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
     8
 * Licensed under the Apache License, Version 2.0 (the "License");
7f561c08de6b Initial load
duke
parents:
diff changeset
     9
 * you may not use this file except in compliance with the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    10
 * You may obtain a copy of the License at
7f561c08de6b Initial load
duke
parents:
diff changeset
    11
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *     http://www.apache.org/licenses/LICENSE-2.0
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
 * $Id: FunctionCall.java,v 1.2.4.1 2005/09/12 10:31:32 pvedula Exp $
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
package com.sun.org.apache.xalan.internal.xsltc.compiler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
import java.lang.reflect.Constructor;
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import java.lang.reflect.Method;
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
import java.lang.reflect.Modifier;
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
import java.util.Enumeration;
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
import java.util.Hashtable;
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
import java.util.Vector;
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
import com.sun.org.apache.bcel.internal.generic.IFEQ;
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE;
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
import com.sun.org.apache.bcel.internal.generic.INVOKESPECIAL;
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
import com.sun.org.apache.bcel.internal.generic.INVOKESTATIC;
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL;
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
import com.sun.org.apache.bcel.internal.generic.InstructionConstants;
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
import com.sun.org.apache.bcel.internal.generic.InstructionList;
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
import com.sun.org.apache.bcel.internal.generic.InvokeInstruction;
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
import com.sun.org.apache.bcel.internal.generic.LocalVariableGen;
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
import com.sun.org.apache.bcel.internal.generic.NEW;
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
import com.sun.org.apache.bcel.internal.generic.PUSH;
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.BooleanType;
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.IntType;
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodType;
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MultiHashtable;
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ObjectType;
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ReferenceType;
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
    56
import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12458
diff changeset
    57
import java.util.Objects;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
 * @author Jacek Ambroziak
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
 * @author Santiago Pericas-Geertsen
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
 * @author Morten Jorgensen
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
 * @author Erwin Bolwidt <ejb@klomp.org>
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
 * @author Todd Miller
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
class FunctionCall extends Expression {
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
    // Name of this function call
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
    private QName  _fname;
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
    // Arguments to this function call (might not be any)
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
    private final Vector _arguments;
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
    // Empty argument list, used for certain functions
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
    private final static Vector EMPTY_ARG_LIST = new Vector(0);
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
    // Valid namespaces for Java function-call extension
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
    protected final static String EXT_XSLTC =
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
        TRANSLET_URI;
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
    protected final static String JAVA_EXT_XSLTC =
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
        EXT_XSLTC + "/java";
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
    protected final static String EXT_XALAN =
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
        "http://xml.apache.org/xalan";
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
    protected final static String JAVA_EXT_XALAN =
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
        "http://xml.apache.org/xalan/java";
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
    protected final static String JAVA_EXT_XALAN_OLD =
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
        "http://xml.apache.org/xslt/java";
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
    protected final static String EXSLT_COMMON =
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
        "http://exslt.org/common";
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
    protected final static String EXSLT_MATH =
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
        "http://exslt.org/math";
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
    protected final static String EXSLT_SETS =
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
        "http://exslt.org/sets";
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
    protected final static String EXSLT_DATETIME =
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
        "http://exslt.org/dates-and-times";
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
    protected final static String EXSLT_STRINGS =
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
        "http://exslt.org/strings";
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
    // Namespace format constants
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
    protected final static int NAMESPACE_FORMAT_JAVA = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
    protected final static int NAMESPACE_FORMAT_CLASS = 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
    protected final static int NAMESPACE_FORMAT_PACKAGE = 2;
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
    protected final static int NAMESPACE_FORMAT_CLASS_OR_PACKAGE = 3;
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
    // Namespace format
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
    private int _namespace_format = NAMESPACE_FORMAT_JAVA;
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
     * Stores reference to object for non-static Java calls
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
    Expression _thisArgument = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
    // External Java function's class/method/signature
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
    private String      _className;
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
    private Class       _clazz;
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
    private Method      _chosenMethod;
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
    private Constructor _chosenConstructor;
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
    private MethodType  _chosenMethodType;
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
    // Encapsulates all unsupported external function calls
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
    private boolean    unresolvedExternal;
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
    // If FunctionCall is a external java constructor
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
    private boolean     _isExtConstructor = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
    // If the java method is static
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
    private boolean       _isStatic = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
    // Legal conversions between internal and Java types.
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
    private static final MultiHashtable _internal2Java = new MultiHashtable();
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
    // Legal conversions between Java and internal types.
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
    private static final Hashtable _java2Internal = new Hashtable();
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
    // The mappings between EXSLT extension namespaces and implementation classes
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
    private static final Hashtable _extensionNamespaceTable = new Hashtable();
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
    // Extension functions that are implemented in BasisLibrary
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
    private static final Hashtable _extensionFunctionTable = new Hashtable();
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
     * inner class to used in internal2Java mappings, contains
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
     * the Java type and the distance between the internal type and
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
     * the Java type.
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
    static class JavaType {
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
        public Class  type;
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
        public int distance;
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
        public JavaType(Class type, int distance){
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
            this.type = type;
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
            this.distance = distance;
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
        }
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12458
diff changeset
   160
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12458
diff changeset
   161
        @Override
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12458
diff changeset
   162
        public int hashCode() {
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12458
diff changeset
   163
            return Objects.hashCode(this.type);
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12458
diff changeset
   164
        }
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12458
diff changeset
   165
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12458
diff changeset
   166
        @Override
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
        public boolean equals(Object query){
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12458
diff changeset
   168
            return query != null && query.equals(type);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
     * Defines 2 conversion tables:
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
     * 1. From internal types to Java types and
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
     * 2. From Java types to internal types.
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
     * These two tables are used when calling external (Java) functions.
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
    static {
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
        try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
            final Class nodeClass     = Class.forName("org.w3c.dom.Node");
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
            final Class nodeListClass = Class.forName("org.w3c.dom.NodeList");
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
            // -- Internal to Java --------------------------------------------
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
            // Type.Boolean -> { boolean(0), Boolean(1), Object(2) }
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
            _internal2Java.put(Type.Boolean, new JavaType(Boolean.TYPE, 0));
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
            _internal2Java.put(Type.Boolean, new JavaType(Boolean.class, 1));
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
            _internal2Java.put(Type.Boolean, new JavaType(Object.class, 2));
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
            // Type.Real -> { double(0), Double(1), float(2), long(3), int(4),
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
            //                short(5), byte(6), char(7), Object(8) }
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
            _internal2Java.put(Type.Real, new JavaType(Double.TYPE, 0));
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
            _internal2Java.put(Type.Real, new JavaType(Double.class, 1));
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
            _internal2Java.put(Type.Real, new JavaType(Float.TYPE, 2));
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
            _internal2Java.put(Type.Real, new JavaType(Long.TYPE, 3));
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
            _internal2Java.put(Type.Real, new JavaType(Integer.TYPE, 4));
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
            _internal2Java.put(Type.Real, new JavaType(Short.TYPE, 5));
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
            _internal2Java.put(Type.Real, new JavaType(Byte.TYPE, 6));
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
            _internal2Java.put(Type.Real, new JavaType(Character.TYPE, 7));
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
            _internal2Java.put(Type.Real, new JavaType(Object.class, 8));
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
            // Type.Int must be the same as Type.Real
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
            _internal2Java.put(Type.Int, new JavaType(Double.TYPE, 0));
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
            _internal2Java.put(Type.Int, new JavaType(Double.class, 1));
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
            _internal2Java.put(Type.Int, new JavaType(Float.TYPE, 2));
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
            _internal2Java.put(Type.Int, new JavaType(Long.TYPE, 3));
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
            _internal2Java.put(Type.Int, new JavaType(Integer.TYPE, 4));
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
            _internal2Java.put(Type.Int, new JavaType(Short.TYPE, 5));
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
            _internal2Java.put(Type.Int, new JavaType(Byte.TYPE, 6));
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
            _internal2Java.put(Type.Int, new JavaType(Character.TYPE, 7));
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
            _internal2Java.put(Type.Int, new JavaType(Object.class, 8));
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
            // Type.String -> { String(0), Object(1) }
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
            _internal2Java.put(Type.String, new JavaType(String.class, 0));
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
            _internal2Java.put(Type.String, new JavaType(Object.class, 1));
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
            // Type.NodeSet -> { NodeList(0), Node(1), Object(2), String(3) }
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
            _internal2Java.put(Type.NodeSet, new JavaType(nodeListClass, 0));
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
            _internal2Java.put(Type.NodeSet, new JavaType(nodeClass, 1));
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
            _internal2Java.put(Type.NodeSet, new JavaType(Object.class, 2));
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
            _internal2Java.put(Type.NodeSet, new JavaType(String.class, 3));
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
            // Type.Node -> { Node(0), NodeList(1), Object(2), String(3) }
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
            _internal2Java.put(Type.Node, new JavaType(nodeListClass, 0));
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
            _internal2Java.put(Type.Node, new JavaType(nodeClass, 1));
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
            _internal2Java.put(Type.Node, new JavaType(Object.class, 2));
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
            _internal2Java.put(Type.Node, new JavaType(String.class, 3));
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
            // Type.ResultTree -> { NodeList(0), Node(1), Object(2), String(3) }
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
            _internal2Java.put(Type.ResultTree, new JavaType(nodeListClass, 0));
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
            _internal2Java.put(Type.ResultTree, new JavaType(nodeClass, 1));
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
            _internal2Java.put(Type.ResultTree, new JavaType(Object.class, 2));
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
            _internal2Java.put(Type.ResultTree, new JavaType(String.class, 3));
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
            _internal2Java.put(Type.Reference, new JavaType(Object.class, 0));
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
            // Possible conversions between Java and internal types
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
            _java2Internal.put(Boolean.TYPE, Type.Boolean);
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
            _java2Internal.put(Void.TYPE, Type.Void);
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
            _java2Internal.put(Character.TYPE, Type.Real);
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
            _java2Internal.put(Byte.TYPE, Type.Real);
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
            _java2Internal.put(Short.TYPE, Type.Real);
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
            _java2Internal.put(Integer.TYPE, Type.Real);
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
            _java2Internal.put(Long.TYPE, Type.Real);
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
            _java2Internal.put(Float.TYPE, Type.Real);
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
            _java2Internal.put(Double.TYPE, Type.Real);
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
            _java2Internal.put(String.class, Type.String);
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
            _java2Internal.put(Object.class, Type.Reference);
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
            // Conversions from org.w3c.dom.Node/NodeList to internal NodeSet
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
            _java2Internal.put(nodeListClass, Type.NodeSet);
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
            _java2Internal.put(nodeClass, Type.NodeSet);
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
            // Initialize the extension namespace table
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
            _extensionNamespaceTable.put(EXT_XALAN, "com.sun.org.apache.xalan.internal.lib.Extensions");
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
            _extensionNamespaceTable.put(EXSLT_COMMON, "com.sun.org.apache.xalan.internal.lib.ExsltCommon");
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
            _extensionNamespaceTable.put(EXSLT_MATH, "com.sun.org.apache.xalan.internal.lib.ExsltMath");
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
            _extensionNamespaceTable.put(EXSLT_SETS, "com.sun.org.apache.xalan.internal.lib.ExsltSets");
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
            _extensionNamespaceTable.put(EXSLT_DATETIME, "com.sun.org.apache.xalan.internal.lib.ExsltDatetime");
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
            _extensionNamespaceTable.put(EXSLT_STRINGS, "com.sun.org.apache.xalan.internal.lib.ExsltStrings");
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
            // Initialize the extension function table
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
            _extensionFunctionTable.put(EXSLT_COMMON + ":nodeSet", "nodeset");
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
            _extensionFunctionTable.put(EXSLT_COMMON + ":objectType", "objectType");
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
            _extensionFunctionTable.put(EXT_XALAN + ":nodeset", "nodeset");
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
        catch (ClassNotFoundException e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
            System.err.println(e);
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
    public FunctionCall(QName fname, Vector arguments) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
        _fname = fname;
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
        _arguments = arguments;
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
        _type = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
    public FunctionCall(QName fname) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
        this(fname, EMPTY_ARG_LIST);
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
    public String getName() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
        return(_fname.toString());
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12458
diff changeset
   288
    @Override
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
    public void setParser(Parser parser) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
        super.setParser(parser);
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
        if (_arguments != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
            final int n = _arguments.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
            for (int i = 0; i < n; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
                final Expression exp = (Expression)_arguments.elementAt(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
                exp.setParser(parser);
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
                exp.setParent(this);
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
    public String getClassNameFromUri(String uri)
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
        String className = (String)_extensionNamespaceTable.get(uri);
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
        if (className != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
            return className;
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
            if (uri.startsWith(JAVA_EXT_XSLTC)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
                int length = JAVA_EXT_XSLTC.length() + 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
                return (uri.length() > length) ? uri.substring(length) : EMPTYSTRING;
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
            else if (uri.startsWith(JAVA_EXT_XALAN)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
                int length = JAVA_EXT_XALAN.length() + 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   314
                return (uri.length() > length) ? uri.substring(length) : EMPTYSTRING;
7f561c08de6b Initial load
duke
parents:
diff changeset
   315
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   316
            else if (uri.startsWith(JAVA_EXT_XALAN_OLD)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
                int length = JAVA_EXT_XALAN_OLD.length() + 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
                return (uri.length() > length) ? uri.substring(length) : EMPTYSTRING;
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
            else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
                int index = uri.lastIndexOf('/');
7f561c08de6b Initial load
duke
parents:
diff changeset
   322
                return (index > 0) ? uri.substring(index+1) : uri;
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
7f561c08de6b Initial load
duke
parents:
diff changeset
   327
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
     * Type check a function call. Since different type conversions apply,
7f561c08de6b Initial load
duke
parents:
diff changeset
   329
     * type checking is different for standard and external (Java) functions.
7f561c08de6b Initial load
duke
parents:
diff changeset
   330
     */
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12458
diff changeset
   331
    @Override
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   332
    public Type typeCheck(SymbolTable stable)
7f561c08de6b Initial load
duke
parents:
diff changeset
   333
        throws TypeCheckError
7f561c08de6b Initial load
duke
parents:
diff changeset
   334
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   335
        if (_type != null) return _type;
7f561c08de6b Initial load
duke
parents:
diff changeset
   336
7f561c08de6b Initial load
duke
parents:
diff changeset
   337
        final String namespace = _fname.getNamespace();
7f561c08de6b Initial load
duke
parents:
diff changeset
   338
        String local = _fname.getLocalPart();
7f561c08de6b Initial load
duke
parents:
diff changeset
   339
7f561c08de6b Initial load
duke
parents:
diff changeset
   340
        if (isExtension()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   341
            _fname = new QName(null, null, local);
7f561c08de6b Initial load
duke
parents:
diff changeset
   342
            return typeCheckStandard(stable);
7f561c08de6b Initial load
duke
parents:
diff changeset
   343
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   344
        else if (isStandard()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   345
            return typeCheckStandard(stable);
7f561c08de6b Initial load
duke
parents:
diff changeset
   346
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   347
        // Handle extension functions (they all have a namespace)
7f561c08de6b Initial load
duke
parents:
diff changeset
   348
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   349
            try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   350
                _className = getClassNameFromUri(namespace);
7f561c08de6b Initial load
duke
parents:
diff changeset
   351
7f561c08de6b Initial load
duke
parents:
diff changeset
   352
                final int pos = local.lastIndexOf('.');
7f561c08de6b Initial load
duke
parents:
diff changeset
   353
                if (pos > 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   354
                    _isStatic = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   355
                    if (_className != null && _className.length() > 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   356
                        _namespace_format = NAMESPACE_FORMAT_PACKAGE;
7f561c08de6b Initial load
duke
parents:
diff changeset
   357
                        _className = _className + "." + local.substring(0, pos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   358
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   359
                    else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   360
                        _namespace_format = NAMESPACE_FORMAT_JAVA;
7f561c08de6b Initial load
duke
parents:
diff changeset
   361
                        _className = local.substring(0, pos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   362
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   363
7f561c08de6b Initial load
duke
parents:
diff changeset
   364
                    _fname = new QName(namespace, null, local.substring(pos + 1));
7f561c08de6b Initial load
duke
parents:
diff changeset
   365
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   366
                else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   367
                    if (_className != null && _className.length() > 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   368
                        try {
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   369
                            _clazz = ObjectFactory.findProviderClass(_className, true);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   370
                            _namespace_format = NAMESPACE_FORMAT_CLASS;
7f561c08de6b Initial load
duke
parents:
diff changeset
   371
                        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   372
                        catch (ClassNotFoundException e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   373
                            _namespace_format = NAMESPACE_FORMAT_PACKAGE;
7f561c08de6b Initial load
duke
parents:
diff changeset
   374
                        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   375
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   376
                    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   377
                        _namespace_format = NAMESPACE_FORMAT_JAVA;
7f561c08de6b Initial load
duke
parents:
diff changeset
   378
7f561c08de6b Initial load
duke
parents:
diff changeset
   379
                    if (local.indexOf('-') > 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   380
                        local = replaceDash(local);
7f561c08de6b Initial load
duke
parents:
diff changeset
   381
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   382
7f561c08de6b Initial load
duke
parents:
diff changeset
   383
                    String extFunction = (String)_extensionFunctionTable.get(namespace + ":" + local);
7f561c08de6b Initial load
duke
parents:
diff changeset
   384
                    if (extFunction != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   385
                        _fname = new QName(null, null, extFunction);
7f561c08de6b Initial load
duke
parents:
diff changeset
   386
                        return typeCheckStandard(stable);
7f561c08de6b Initial load
duke
parents:
diff changeset
   387
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   388
                    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   389
                        _fname = new QName(namespace, null, local);
7f561c08de6b Initial load
duke
parents:
diff changeset
   390
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   391
7f561c08de6b Initial load
duke
parents:
diff changeset
   392
                return typeCheckExternal(stable);
7f561c08de6b Initial load
duke
parents:
diff changeset
   393
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   394
            catch (TypeCheckError e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   395
                ErrorMsg errorMsg = e.getErrorMsg();
7f561c08de6b Initial load
duke
parents:
diff changeset
   396
                if (errorMsg == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   397
                    final String name = _fname.getLocalPart();
7f561c08de6b Initial load
duke
parents:
diff changeset
   398
                    errorMsg = new ErrorMsg(ErrorMsg.METHOD_NOT_FOUND_ERR, name);
7f561c08de6b Initial load
duke
parents:
diff changeset
   399
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   400
                getParser().reportError(ERROR, errorMsg);
7f561c08de6b Initial load
duke
parents:
diff changeset
   401
                return _type = Type.Void;
7f561c08de6b Initial load
duke
parents:
diff changeset
   402
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   403
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   404
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   405
7f561c08de6b Initial load
duke
parents:
diff changeset
   406
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   407
     * Type check a call to a standard function. Insert CastExprs when needed.
7f561c08de6b Initial load
duke
parents:
diff changeset
   408
     * If as a result of the insertion of a CastExpr a type check error is
7f561c08de6b Initial load
duke
parents:
diff changeset
   409
     * thrown, then catch it and re-throw it with a new "this".
7f561c08de6b Initial load
duke
parents:
diff changeset
   410
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   411
    public Type typeCheckStandard(SymbolTable stable) throws TypeCheckError {
7f561c08de6b Initial load
duke
parents:
diff changeset
   412
        _fname.clearNamespace();        // HACK!!!
7f561c08de6b Initial load
duke
parents:
diff changeset
   413
7f561c08de6b Initial load
duke
parents:
diff changeset
   414
        final int n = _arguments.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   415
        final Vector argsType = typeCheckArgs(stable);
7f561c08de6b Initial load
duke
parents:
diff changeset
   416
        final MethodType args = new MethodType(Type.Void, argsType);
7f561c08de6b Initial load
duke
parents:
diff changeset
   417
        final MethodType ptype =
7f561c08de6b Initial load
duke
parents:
diff changeset
   418
            lookupPrimop(stable, _fname.getLocalPart(), args);
7f561c08de6b Initial load
duke
parents:
diff changeset
   419
7f561c08de6b Initial load
duke
parents:
diff changeset
   420
        if (ptype != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   421
            for (int i = 0; i < n; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   422
                final Type argType = (Type) ptype.argsType().elementAt(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   423
                final Expression exp = (Expression)_arguments.elementAt(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   424
                if (!argType.identicalTo(exp.getType())) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   425
                    try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   426
                        _arguments.setElementAt(new CastExpr(exp, argType), i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   427
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   428
                    catch (TypeCheckError e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   429
                        throw new TypeCheckError(this); // invalid conversion
7f561c08de6b Initial load
duke
parents:
diff changeset
   430
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   431
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   432
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   433
            _chosenMethodType = ptype;
7f561c08de6b Initial load
duke
parents:
diff changeset
   434
            return _type = ptype.resultType();
7f561c08de6b Initial load
duke
parents:
diff changeset
   435
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   436
        throw new TypeCheckError(this);
7f561c08de6b Initial load
duke
parents:
diff changeset
   437
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   438
7f561c08de6b Initial load
duke
parents:
diff changeset
   439
7f561c08de6b Initial load
duke
parents:
diff changeset
   440
7f561c08de6b Initial load
duke
parents:
diff changeset
   441
    public Type typeCheckConstructor(SymbolTable stable) throws TypeCheckError{
7f561c08de6b Initial load
duke
parents:
diff changeset
   442
        final Vector constructors = findConstructors();
7f561c08de6b Initial load
duke
parents:
diff changeset
   443
        if (constructors == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   444
            // Constructor not found in this class
7f561c08de6b Initial load
duke
parents:
diff changeset
   445
            throw new TypeCheckError(ErrorMsg.CONSTRUCTOR_NOT_FOUND,
7f561c08de6b Initial load
duke
parents:
diff changeset
   446
                _className);
7f561c08de6b Initial load
duke
parents:
diff changeset
   447
7f561c08de6b Initial load
duke
parents:
diff changeset
   448
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   449
7f561c08de6b Initial load
duke
parents:
diff changeset
   450
        final int nConstructors = constructors.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   451
        final int nArgs = _arguments.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   452
        final Vector argsType = typeCheckArgs(stable);
7f561c08de6b Initial load
duke
parents:
diff changeset
   453
7f561c08de6b Initial load
duke
parents:
diff changeset
   454
        // Try all constructors
7f561c08de6b Initial load
duke
parents:
diff changeset
   455
        int bestConstrDistance = Integer.MAX_VALUE;
7f561c08de6b Initial load
duke
parents:
diff changeset
   456
        _type = null;                   // reset
7f561c08de6b Initial load
duke
parents:
diff changeset
   457
        for (int j, i = 0; i < nConstructors; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   458
            // Check if all parameters to this constructor can be converted
7f561c08de6b Initial load
duke
parents:
diff changeset
   459
            final Constructor constructor =
7f561c08de6b Initial load
duke
parents:
diff changeset
   460
                (Constructor)constructors.elementAt(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   461
            final Class[] paramTypes = constructor.getParameterTypes();
7f561c08de6b Initial load
duke
parents:
diff changeset
   462
7f561c08de6b Initial load
duke
parents:
diff changeset
   463
            Class extType = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   464
            int currConstrDistance = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   465
            for (j = 0; j < nArgs; j++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   466
                // Convert from internal (translet) type to external (Java) type
7f561c08de6b Initial load
duke
parents:
diff changeset
   467
                extType = paramTypes[j];
7f561c08de6b Initial load
duke
parents:
diff changeset
   468
                final Type intType = (Type)argsType.elementAt(j);
7f561c08de6b Initial load
duke
parents:
diff changeset
   469
                Object match = _internal2Java.maps(intType, extType);
7f561c08de6b Initial load
duke
parents:
diff changeset
   470
                if (match != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   471
                    currConstrDistance += ((JavaType)match).distance;
7f561c08de6b Initial load
duke
parents:
diff changeset
   472
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   473
                else if (intType instanceof ObjectType) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   474
                    ObjectType objectType = (ObjectType)intType;
7f561c08de6b Initial load
duke
parents:
diff changeset
   475
                    if (objectType.getJavaClass() == extType)
7f561c08de6b Initial load
duke
parents:
diff changeset
   476
                        continue;
7f561c08de6b Initial load
duke
parents:
diff changeset
   477
                    else if (extType.isAssignableFrom(objectType.getJavaClass()))
7f561c08de6b Initial load
duke
parents:
diff changeset
   478
                        currConstrDistance += 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   479
                    else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   480
                        currConstrDistance = Integer.MAX_VALUE;
7f561c08de6b Initial load
duke
parents:
diff changeset
   481
                        break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   482
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   483
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   484
                else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   485
                    // no mapping available
7f561c08de6b Initial load
duke
parents:
diff changeset
   486
                    currConstrDistance = Integer.MAX_VALUE;
7f561c08de6b Initial load
duke
parents:
diff changeset
   487
                    break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   488
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   489
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   490
7f561c08de6b Initial load
duke
parents:
diff changeset
   491
            if (j == nArgs && currConstrDistance < bestConstrDistance ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   492
                _chosenConstructor = constructor;
7f561c08de6b Initial load
duke
parents:
diff changeset
   493
                _isExtConstructor = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   494
                bestConstrDistance = currConstrDistance;
7f561c08de6b Initial load
duke
parents:
diff changeset
   495
7f561c08de6b Initial load
duke
parents:
diff changeset
   496
                _type = (_clazz != null) ? Type.newObjectType(_clazz)
7f561c08de6b Initial load
duke
parents:
diff changeset
   497
                    : Type.newObjectType(_className);
7f561c08de6b Initial load
duke
parents:
diff changeset
   498
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   499
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   500
7f561c08de6b Initial load
duke
parents:
diff changeset
   501
        if (_type != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   502
            return _type;
7f561c08de6b Initial load
duke
parents:
diff changeset
   503
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   504
7f561c08de6b Initial load
duke
parents:
diff changeset
   505
        throw new TypeCheckError(ErrorMsg.ARGUMENT_CONVERSION_ERR, getMethodSignature(argsType));
7f561c08de6b Initial load
duke
parents:
diff changeset
   506
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   507
7f561c08de6b Initial load
duke
parents:
diff changeset
   508
7f561c08de6b Initial load
duke
parents:
diff changeset
   509
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   510
     * Type check a call to an external (Java) method.
7f561c08de6b Initial load
duke
parents:
diff changeset
   511
     * The method must be static an public, and a legal type conversion
7f561c08de6b Initial load
duke
parents:
diff changeset
   512
     * must exist for all its arguments and its return type.
7f561c08de6b Initial load
duke
parents:
diff changeset
   513
     * Every method of name <code>_fname</code> is inspected
7f561c08de6b Initial load
duke
parents:
diff changeset
   514
     * as a possible candidate.
7f561c08de6b Initial load
duke
parents:
diff changeset
   515
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   516
    public Type typeCheckExternal(SymbolTable stable) throws TypeCheckError {
7f561c08de6b Initial load
duke
parents:
diff changeset
   517
        int nArgs = _arguments.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   518
        final String name = _fname.getLocalPart();
7f561c08de6b Initial load
duke
parents:
diff changeset
   519
7f561c08de6b Initial load
duke
parents:
diff changeset
   520
        // check if function is a contructor 'new'
7f561c08de6b Initial load
duke
parents:
diff changeset
   521
        if (_fname.getLocalPart().equals("new")) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   522
            return typeCheckConstructor(stable);
7f561c08de6b Initial load
duke
parents:
diff changeset
   523
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   524
        // check if we are calling an instance method
7f561c08de6b Initial load
duke
parents:
diff changeset
   525
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   526
            boolean hasThisArgument = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   527
7f561c08de6b Initial load
duke
parents:
diff changeset
   528
            if (nArgs == 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   529
                _isStatic = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   530
7f561c08de6b Initial load
duke
parents:
diff changeset
   531
            if (!_isStatic) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   532
                if (_namespace_format == NAMESPACE_FORMAT_JAVA
7f561c08de6b Initial load
duke
parents:
diff changeset
   533
                    || _namespace_format == NAMESPACE_FORMAT_PACKAGE)
7f561c08de6b Initial load
duke
parents:
diff changeset
   534
                    hasThisArgument = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   535
7f561c08de6b Initial load
duke
parents:
diff changeset
   536
                Expression firstArg = (Expression)_arguments.elementAt(0);
7f561c08de6b Initial load
duke
parents:
diff changeset
   537
                Type firstArgType = (Type)firstArg.typeCheck(stable);
7f561c08de6b Initial load
duke
parents:
diff changeset
   538
7f561c08de6b Initial load
duke
parents:
diff changeset
   539
                if (_namespace_format == NAMESPACE_FORMAT_CLASS
7f561c08de6b Initial load
duke
parents:
diff changeset
   540
                    && firstArgType instanceof ObjectType
7f561c08de6b Initial load
duke
parents:
diff changeset
   541
                    && _clazz != null
7f561c08de6b Initial load
duke
parents:
diff changeset
   542
                    && _clazz.isAssignableFrom(((ObjectType)firstArgType).getJavaClass()))
7f561c08de6b Initial load
duke
parents:
diff changeset
   543
                    hasThisArgument = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   544
7f561c08de6b Initial load
duke
parents:
diff changeset
   545
                if (hasThisArgument) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   546
                    _thisArgument = (Expression) _arguments.elementAt(0);
7f561c08de6b Initial load
duke
parents:
diff changeset
   547
                    _arguments.remove(0); nArgs--;
7f561c08de6b Initial load
duke
parents:
diff changeset
   548
                    if (firstArgType instanceof ObjectType) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   549
                        _className = ((ObjectType) firstArgType).getJavaClassName();
7f561c08de6b Initial load
duke
parents:
diff changeset
   550
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   551
                    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   552
                        throw new TypeCheckError(ErrorMsg.NO_JAVA_FUNCT_THIS_REF, name);
7f561c08de6b Initial load
duke
parents:
diff changeset
   553
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   554
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   555
            else if (_className.length() == 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   556
                /*
7f561c08de6b Initial load
duke
parents:
diff changeset
   557
                 * Warn user if external function could not be resolved.
7f561c08de6b Initial load
duke
parents:
diff changeset
   558
                 * Warning will _NOT_ be issued is the call is properly
7f561c08de6b Initial load
duke
parents:
diff changeset
   559
                 * wrapped in an <xsl:if> or <xsl:when> element. For details
7f561c08de6b Initial load
duke
parents:
diff changeset
   560
                 * see If.parserContents() and When.parserContents()
7f561c08de6b Initial load
duke
parents:
diff changeset
   561
                 */
7f561c08de6b Initial load
duke
parents:
diff changeset
   562
                final Parser parser = getParser();
7f561c08de6b Initial load
duke
parents:
diff changeset
   563
                if (parser != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   564
                    reportWarning(this, parser, ErrorMsg.FUNCTION_RESOLVE_ERR,
7f561c08de6b Initial load
duke
parents:
diff changeset
   565
                                  _fname.toString());
7f561c08de6b Initial load
duke
parents:
diff changeset
   566
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   567
                unresolvedExternal = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   568
                return _type = Type.Int;        // use "Int" as "unknown"
7f561c08de6b Initial load
duke
parents:
diff changeset
   569
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   570
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   571
7f561c08de6b Initial load
duke
parents:
diff changeset
   572
        final Vector methods = findMethods();
7f561c08de6b Initial load
duke
parents:
diff changeset
   573
7f561c08de6b Initial load
duke
parents:
diff changeset
   574
        if (methods == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   575
            // Method not found in this class
7f561c08de6b Initial load
duke
parents:
diff changeset
   576
            throw new TypeCheckError(ErrorMsg.METHOD_NOT_FOUND_ERR, _className + "." + name);
7f561c08de6b Initial load
duke
parents:
diff changeset
   577
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   578
7f561c08de6b Initial load
duke
parents:
diff changeset
   579
        Class extType = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   580
        final int nMethods = methods.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   581
        final Vector argsType = typeCheckArgs(stable);
7f561c08de6b Initial load
duke
parents:
diff changeset
   582
7f561c08de6b Initial load
duke
parents:
diff changeset
   583
        // Try all methods to identify the best fit
7f561c08de6b Initial load
duke
parents:
diff changeset
   584
        int bestMethodDistance  = Integer.MAX_VALUE;
7f561c08de6b Initial load
duke
parents:
diff changeset
   585
        _type = null;                       // reset internal type
7f561c08de6b Initial load
duke
parents:
diff changeset
   586
        for (int j, i = 0; i < nMethods; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   587
            // Check if all paramteters to this method can be converted
7f561c08de6b Initial load
duke
parents:
diff changeset
   588
            final Method method = (Method)methods.elementAt(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   589
            final Class[] paramTypes = method.getParameterTypes();
7f561c08de6b Initial load
duke
parents:
diff changeset
   590
7f561c08de6b Initial load
duke
parents:
diff changeset
   591
            int currMethodDistance = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   592
            for (j = 0; j < nArgs; j++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   593
                // Convert from internal (translet) type to external (Java) type
7f561c08de6b Initial load
duke
parents:
diff changeset
   594
                extType = paramTypes[j];
7f561c08de6b Initial load
duke
parents:
diff changeset
   595
                final Type intType = (Type)argsType.elementAt(j);
7f561c08de6b Initial load
duke
parents:
diff changeset
   596
                Object match = _internal2Java.maps(intType, extType);
7f561c08de6b Initial load
duke
parents:
diff changeset
   597
                if (match != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   598
                    currMethodDistance += ((JavaType)match).distance;
7f561c08de6b Initial load
duke
parents:
diff changeset
   599
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   600
                else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   601
                    // no mapping available
7f561c08de6b Initial load
duke
parents:
diff changeset
   602
                    //
7f561c08de6b Initial load
duke
parents:
diff changeset
   603
                    // Allow a Reference type to match any external (Java) type at
7f561c08de6b Initial load
duke
parents:
diff changeset
   604
                    // the moment. The real type checking is performed at runtime.
7f561c08de6b Initial load
duke
parents:
diff changeset
   605
                    if (intType instanceof ReferenceType) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   606
                       currMethodDistance += 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   607
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   608
                    else if (intType instanceof ObjectType) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   609
                        ObjectType object = (ObjectType)intType;
7f561c08de6b Initial load
duke
parents:
diff changeset
   610
                        if (extType.getName().equals(object.getJavaClassName()))
7f561c08de6b Initial load
duke
parents:
diff changeset
   611
                            currMethodDistance += 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   612
                        else if (extType.isAssignableFrom(object.getJavaClass()))
7f561c08de6b Initial load
duke
parents:
diff changeset
   613
                            currMethodDistance += 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   614
                        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   615
                            currMethodDistance = Integer.MAX_VALUE;
7f561c08de6b Initial load
duke
parents:
diff changeset
   616
                            break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   617
                        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   618
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   619
                    else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   620
                        currMethodDistance = Integer.MAX_VALUE;
7f561c08de6b Initial load
duke
parents:
diff changeset
   621
                        break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   622
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   623
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   624
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   625
7f561c08de6b Initial load
duke
parents:
diff changeset
   626
            if (j == nArgs) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   627
                  // Check if the return type can be converted
7f561c08de6b Initial load
duke
parents:
diff changeset
   628
                  extType = method.getReturnType();
7f561c08de6b Initial load
duke
parents:
diff changeset
   629
7f561c08de6b Initial load
duke
parents:
diff changeset
   630
                  _type = (Type) _java2Internal.get(extType);
7f561c08de6b Initial load
duke
parents:
diff changeset
   631
                  if (_type == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   632
                      _type = Type.newObjectType(extType);
7f561c08de6b Initial load
duke
parents:
diff changeset
   633
                  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   634
7f561c08de6b Initial load
duke
parents:
diff changeset
   635
                  // Use this method if all parameters & return type match
7f561c08de6b Initial load
duke
parents:
diff changeset
   636
                  if (_type != null && currMethodDistance < bestMethodDistance) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   637
                      _chosenMethod = method;
7f561c08de6b Initial load
duke
parents:
diff changeset
   638
                      bestMethodDistance = currMethodDistance;
7f561c08de6b Initial load
duke
parents:
diff changeset
   639
                  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   640
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   641
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   642
7f561c08de6b Initial load
duke
parents:
diff changeset
   643
        // It is an error if the chosen method is an instance menthod but we don't
7f561c08de6b Initial load
duke
parents:
diff changeset
   644
        // have a this argument.
7f561c08de6b Initial load
duke
parents:
diff changeset
   645
        if (_chosenMethod != null && _thisArgument == null &&
7f561c08de6b Initial load
duke
parents:
diff changeset
   646
            !Modifier.isStatic(_chosenMethod.getModifiers())) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   647
            throw new TypeCheckError(ErrorMsg.NO_JAVA_FUNCT_THIS_REF, getMethodSignature(argsType));
7f561c08de6b Initial load
duke
parents:
diff changeset
   648
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   649
7f561c08de6b Initial load
duke
parents:
diff changeset
   650
        if (_type != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   651
            if (_type == Type.NodeSet) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   652
                getXSLTC().setMultiDocument(true);
7f561c08de6b Initial load
duke
parents:
diff changeset
   653
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   654
            return _type;
7f561c08de6b Initial load
duke
parents:
diff changeset
   655
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   656
7f561c08de6b Initial load
duke
parents:
diff changeset
   657
        throw new TypeCheckError(ErrorMsg.ARGUMENT_CONVERSION_ERR, getMethodSignature(argsType));
7f561c08de6b Initial load
duke
parents:
diff changeset
   658
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   659
7f561c08de6b Initial load
duke
parents:
diff changeset
   660
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   661
     * Type check the actual arguments of this function call.
7f561c08de6b Initial load
duke
parents:
diff changeset
   662
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   663
    public Vector typeCheckArgs(SymbolTable stable) throws TypeCheckError {
7f561c08de6b Initial load
duke
parents:
diff changeset
   664
        final Vector result = new Vector();
7f561c08de6b Initial load
duke
parents:
diff changeset
   665
        final Enumeration e = _arguments.elements();
7f561c08de6b Initial load
duke
parents:
diff changeset
   666
        while (e.hasMoreElements()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   667
            final Expression exp = (Expression)e.nextElement();
7f561c08de6b Initial load
duke
parents:
diff changeset
   668
            result.addElement(exp.typeCheck(stable));
7f561c08de6b Initial load
duke
parents:
diff changeset
   669
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   670
        return result;
7f561c08de6b Initial load
duke
parents:
diff changeset
   671
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   672
7f561c08de6b Initial load
duke
parents:
diff changeset
   673
    protected final Expression argument(int i) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   674
        return (Expression)_arguments.elementAt(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   675
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   676
7f561c08de6b Initial load
duke
parents:
diff changeset
   677
    protected final Expression argument() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   678
        return argument(0);
7f561c08de6b Initial load
duke
parents:
diff changeset
   679
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   680
7f561c08de6b Initial load
duke
parents:
diff changeset
   681
    protected final int argumentCount() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   682
        return _arguments.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   683
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   684
7f561c08de6b Initial load
duke
parents:
diff changeset
   685
    protected final void setArgument(int i, Expression exp) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   686
        _arguments.setElementAt(exp, i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   687
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   688
7f561c08de6b Initial load
duke
parents:
diff changeset
   689
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   690
     * Compile the function call and treat as an expression
7f561c08de6b Initial load
duke
parents:
diff changeset
   691
     * Update true/false-lists.
7f561c08de6b Initial load
duke
parents:
diff changeset
   692
     */
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12458
diff changeset
   693
    @Override
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   694
    public void translateDesynthesized(ClassGenerator classGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   695
                                       MethodGenerator methodGen)
7f561c08de6b Initial load
duke
parents:
diff changeset
   696
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   697
        Type type = Type.Boolean;
7f561c08de6b Initial load
duke
parents:
diff changeset
   698
        if (_chosenMethodType != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   699
            type = _chosenMethodType.resultType();
7f561c08de6b Initial load
duke
parents:
diff changeset
   700
7f561c08de6b Initial load
duke
parents:
diff changeset
   701
        final InstructionList il = methodGen.getInstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
   702
        translate(classGen, methodGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   703
7f561c08de6b Initial load
duke
parents:
diff changeset
   704
        if ((type instanceof BooleanType) || (type instanceof IntType)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   705
            _falseList.add(il.append(new IFEQ(null)));
7f561c08de6b Initial load
duke
parents:
diff changeset
   706
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   707
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   708
7f561c08de6b Initial load
duke
parents:
diff changeset
   709
7f561c08de6b Initial load
duke
parents:
diff changeset
   710
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   711
     * Translate a function call. The compiled code will leave the function's
7f561c08de6b Initial load
duke
parents:
diff changeset
   712
     * return value on the JVM's stack.
7f561c08de6b Initial load
duke
parents:
diff changeset
   713
     */
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12458
diff changeset
   714
    @Override
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   715
    public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   716
        final int n = argumentCount();
7f561c08de6b Initial load
duke
parents:
diff changeset
   717
        final ConstantPoolGen cpg = classGen.getConstantPool();
7f561c08de6b Initial load
duke
parents:
diff changeset
   718
        final InstructionList il = methodGen.getInstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
   719
        final boolean isSecureProcessing = classGen.getParser().getXSLTC().isSecureProcessing();
7f561c08de6b Initial load
duke
parents:
diff changeset
   720
        int index;
7f561c08de6b Initial load
duke
parents:
diff changeset
   721
7f561c08de6b Initial load
duke
parents:
diff changeset
   722
        // Translate calls to methods in the BasisLibrary
7f561c08de6b Initial load
duke
parents:
diff changeset
   723
        if (isStandard() || isExtension()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   724
            for (int i = 0; i < n; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   725
                final Expression exp = argument(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   726
                exp.translate(classGen, methodGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   727
                exp.startIterator(classGen, methodGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   728
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   729
7f561c08de6b Initial load
duke
parents:
diff changeset
   730
            // append "F" to the function's name
7f561c08de6b Initial load
duke
parents:
diff changeset
   731
            final String name = _fname.toString().replace('-', '_') + "F";
7f561c08de6b Initial load
duke
parents:
diff changeset
   732
            String args = Constants.EMPTYSTRING;
7f561c08de6b Initial load
duke
parents:
diff changeset
   733
7f561c08de6b Initial load
duke
parents:
diff changeset
   734
            // Special precautions for some method calls
7f561c08de6b Initial load
duke
parents:
diff changeset
   735
            if (name.equals("sumF")) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   736
                args = DOM_INTF_SIG;
7f561c08de6b Initial load
duke
parents:
diff changeset
   737
                il.append(methodGen.loadDOM());
7f561c08de6b Initial load
duke
parents:
diff changeset
   738
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   739
            else if (name.equals("normalize_spaceF")) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   740
                if (_chosenMethodType.toSignature(args).
7f561c08de6b Initial load
duke
parents:
diff changeset
   741
                    equals("()Ljava/lang/String;")) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   742
                    args = "I"+DOM_INTF_SIG;
7f561c08de6b Initial load
duke
parents:
diff changeset
   743
                    il.append(methodGen.loadContextNode());
7f561c08de6b Initial load
duke
parents:
diff changeset
   744
                    il.append(methodGen.loadDOM());
7f561c08de6b Initial load
duke
parents:
diff changeset
   745
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   746
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   747
7f561c08de6b Initial load
duke
parents:
diff changeset
   748
            // Invoke the method in the basis library
7f561c08de6b Initial load
duke
parents:
diff changeset
   749
            index = cpg.addMethodref(BASIS_LIBRARY_CLASS, name,
7f561c08de6b Initial load
duke
parents:
diff changeset
   750
                                     _chosenMethodType.toSignature(args));
7f561c08de6b Initial load
duke
parents:
diff changeset
   751
            il.append(new INVOKESTATIC(index));
7f561c08de6b Initial load
duke
parents:
diff changeset
   752
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   753
        // Add call to BasisLibrary.unresolved_externalF() to generate
7f561c08de6b Initial load
duke
parents:
diff changeset
   754
        // run-time error message for unsupported external functions
7f561c08de6b Initial load
duke
parents:
diff changeset
   755
        else if (unresolvedExternal) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   756
            index = cpg.addMethodref(BASIS_LIBRARY_CLASS,
7f561c08de6b Initial load
duke
parents:
diff changeset
   757
                                     "unresolved_externalF",
7f561c08de6b Initial load
duke
parents:
diff changeset
   758
                                     "(Ljava/lang/String;)V");
7f561c08de6b Initial load
duke
parents:
diff changeset
   759
            il.append(new PUSH(cpg, _fname.toString()));
7f561c08de6b Initial load
duke
parents:
diff changeset
   760
            il.append(new INVOKESTATIC(index));
7f561c08de6b Initial load
duke
parents:
diff changeset
   761
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   762
        else if (_isExtConstructor) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   763
            if (isSecureProcessing)
7f561c08de6b Initial load
duke
parents:
diff changeset
   764
                translateUnallowedExtension(cpg, il);
7f561c08de6b Initial load
duke
parents:
diff changeset
   765
7f561c08de6b Initial load
duke
parents:
diff changeset
   766
            final String clazz =
7f561c08de6b Initial load
duke
parents:
diff changeset
   767
                _chosenConstructor.getDeclaringClass().getName();
7f561c08de6b Initial load
duke
parents:
diff changeset
   768
            Class[] paramTypes = _chosenConstructor.getParameterTypes();
7f561c08de6b Initial load
duke
parents:
diff changeset
   769
            LocalVariableGen[] paramTemp = new LocalVariableGen[n];
7f561c08de6b Initial load
duke
parents:
diff changeset
   770
7f561c08de6b Initial load
duke
parents:
diff changeset
   771
            // Backwards branches are prohibited if an uninitialized object is
7f561c08de6b Initial load
duke
parents:
diff changeset
   772
            // on the stack by section 4.9.4 of the JVM Specification, 2nd Ed.
7f561c08de6b Initial load
duke
parents:
diff changeset
   773
            // We don't know whether this code might contain backwards branches
7f561c08de6b Initial load
duke
parents:
diff changeset
   774
            // so we mustn't create the new object until after we've created
7f561c08de6b Initial load
duke
parents:
diff changeset
   775
            // the suspect arguments to its constructor.  Instead we calculate
7f561c08de6b Initial load
duke
parents:
diff changeset
   776
            // the values of the arguments to the constructor first, store them
7f561c08de6b Initial load
duke
parents:
diff changeset
   777
            // in temporary variables, create the object and reload the
7f561c08de6b Initial load
duke
parents:
diff changeset
   778
            // arguments from the temporaries to avoid the problem.
7f561c08de6b Initial load
duke
parents:
diff changeset
   779
7f561c08de6b Initial load
duke
parents:
diff changeset
   780
            for (int i = 0; i < n; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   781
                final Expression exp = argument(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   782
                Type expType = exp.getType();
7f561c08de6b Initial load
duke
parents:
diff changeset
   783
                exp.translate(classGen, methodGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   784
                // Convert the argument to its Java type
7f561c08de6b Initial load
duke
parents:
diff changeset
   785
                exp.startIterator(classGen, methodGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   786
                expType.translateTo(classGen, methodGen, paramTypes[i]);
7f561c08de6b Initial load
duke
parents:
diff changeset
   787
                paramTemp[i] =
7f561c08de6b Initial load
duke
parents:
diff changeset
   788
                    methodGen.addLocalVariable("function_call_tmp"+i,
7f561c08de6b Initial load
duke
parents:
diff changeset
   789
                                               expType.toJCType(),
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   790
                                               null, null);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   791
                paramTemp[i].setStart(
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   792
                        il.append(expType.STORE(paramTemp[i].getIndex())));
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   793
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   794
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   795
7f561c08de6b Initial load
duke
parents:
diff changeset
   796
            il.append(new NEW(cpg.addClass(_className)));
7f561c08de6b Initial load
duke
parents:
diff changeset
   797
            il.append(InstructionConstants.DUP);
7f561c08de6b Initial load
duke
parents:
diff changeset
   798
7f561c08de6b Initial load
duke
parents:
diff changeset
   799
            for (int i = 0; i < n; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   800
                final Expression arg = argument(i);
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   801
                paramTemp[i].setEnd(
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   802
                        il.append(arg.getType().LOAD(paramTemp[i].getIndex())));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   803
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   804
7f561c08de6b Initial load
duke
parents:
diff changeset
   805
            final StringBuffer buffer = new StringBuffer();
7f561c08de6b Initial load
duke
parents:
diff changeset
   806
            buffer.append('(');
7f561c08de6b Initial load
duke
parents:
diff changeset
   807
            for (int i = 0; i < paramTypes.length; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   808
                buffer.append(getSignature(paramTypes[i]));
7f561c08de6b Initial load
duke
parents:
diff changeset
   809
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   810
            buffer.append(')');
7f561c08de6b Initial load
duke
parents:
diff changeset
   811
            buffer.append("V");
7f561c08de6b Initial load
duke
parents:
diff changeset
   812
7f561c08de6b Initial load
duke
parents:
diff changeset
   813
            index = cpg.addMethodref(clazz,
7f561c08de6b Initial load
duke
parents:
diff changeset
   814
                                     "<init>",
7f561c08de6b Initial load
duke
parents:
diff changeset
   815
                                     buffer.toString());
7f561c08de6b Initial load
duke
parents:
diff changeset
   816
            il.append(new INVOKESPECIAL(index));
7f561c08de6b Initial load
duke
parents:
diff changeset
   817
7f561c08de6b Initial load
duke
parents:
diff changeset
   818
            // Convert the return type back to our internal type
7f561c08de6b Initial load
duke
parents:
diff changeset
   819
            (Type.Object).translateFrom(classGen, methodGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   820
                                _chosenConstructor.getDeclaringClass());
7f561c08de6b Initial load
duke
parents:
diff changeset
   821
7f561c08de6b Initial load
duke
parents:
diff changeset
   822
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   823
        // Invoke function calls that are handled in separate classes
7f561c08de6b Initial load
duke
parents:
diff changeset
   824
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   825
            if (isSecureProcessing)
7f561c08de6b Initial load
duke
parents:
diff changeset
   826
                translateUnallowedExtension(cpg, il);
7f561c08de6b Initial load
duke
parents:
diff changeset
   827
7f561c08de6b Initial load
duke
parents:
diff changeset
   828
            final String clazz = _chosenMethod.getDeclaringClass().getName();
7f561c08de6b Initial load
duke
parents:
diff changeset
   829
            Class[] paramTypes = _chosenMethod.getParameterTypes();
7f561c08de6b Initial load
duke
parents:
diff changeset
   830
7f561c08de6b Initial load
duke
parents:
diff changeset
   831
            // Push "this" if it is an instance method
7f561c08de6b Initial load
duke
parents:
diff changeset
   832
            if (_thisArgument != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   833
                _thisArgument.translate(classGen, methodGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   834
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   835
7f561c08de6b Initial load
duke
parents:
diff changeset
   836
            for (int i = 0; i < n; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   837
                final Expression exp = argument(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   838
                exp.translate(classGen, methodGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   839
                // Convert the argument to its Java type
7f561c08de6b Initial load
duke
parents:
diff changeset
   840
                exp.startIterator(classGen, methodGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   841
                exp.getType().translateTo(classGen, methodGen, paramTypes[i]);
7f561c08de6b Initial load
duke
parents:
diff changeset
   842
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   843
7f561c08de6b Initial load
duke
parents:
diff changeset
   844
            final StringBuffer buffer = new StringBuffer();
7f561c08de6b Initial load
duke
parents:
diff changeset
   845
            buffer.append('(');
7f561c08de6b Initial load
duke
parents:
diff changeset
   846
            for (int i = 0; i < paramTypes.length; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   847
                buffer.append(getSignature(paramTypes[i]));
7f561c08de6b Initial load
duke
parents:
diff changeset
   848
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   849
            buffer.append(')');
7f561c08de6b Initial load
duke
parents:
diff changeset
   850
            buffer.append(getSignature(_chosenMethod.getReturnType()));
7f561c08de6b Initial load
duke
parents:
diff changeset
   851
7f561c08de6b Initial load
duke
parents:
diff changeset
   852
            if (_thisArgument != null && _clazz.isInterface()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   853
                index = cpg.addInterfaceMethodref(clazz,
7f561c08de6b Initial load
duke
parents:
diff changeset
   854
                                     _fname.getLocalPart(),
7f561c08de6b Initial load
duke
parents:
diff changeset
   855
                                     buffer.toString());
7f561c08de6b Initial load
duke
parents:
diff changeset
   856
                il.append(new INVOKEINTERFACE(index, n+1));
7f561c08de6b Initial load
duke
parents:
diff changeset
   857
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   858
            else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   859
                index = cpg.addMethodref(clazz,
7f561c08de6b Initial load
duke
parents:
diff changeset
   860
                                     _fname.getLocalPart(),
7f561c08de6b Initial load
duke
parents:
diff changeset
   861
                                     buffer.toString());
7f561c08de6b Initial load
duke
parents:
diff changeset
   862
                il.append(_thisArgument != null ? (InvokeInstruction) new INVOKEVIRTUAL(index) :
7f561c08de6b Initial load
duke
parents:
diff changeset
   863
                          (InvokeInstruction) new INVOKESTATIC(index));
7f561c08de6b Initial load
duke
parents:
diff changeset
   864
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   865
7f561c08de6b Initial load
duke
parents:
diff changeset
   866
            // Convert the return type back to our internal type
7f561c08de6b Initial load
duke
parents:
diff changeset
   867
            _type.translateFrom(classGen, methodGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   868
                                _chosenMethod.getReturnType());
7f561c08de6b Initial load
duke
parents:
diff changeset
   869
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   870
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   871
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12458
diff changeset
   872
    @Override
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   873
    public String toString() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   874
        return "funcall(" + _fname + ", " + _arguments + ')';
7f561c08de6b Initial load
duke
parents:
diff changeset
   875
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   876
7f561c08de6b Initial load
duke
parents:
diff changeset
   877
    public boolean isStandard() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   878
        final String namespace = _fname.getNamespace();
7f561c08de6b Initial load
duke
parents:
diff changeset
   879
        return (namespace == null) || (namespace.equals(Constants.EMPTYSTRING));
7f561c08de6b Initial load
duke
parents:
diff changeset
   880
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   881
7f561c08de6b Initial load
duke
parents:
diff changeset
   882
    public boolean isExtension() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   883
        final String namespace = _fname.getNamespace();
7f561c08de6b Initial load
duke
parents:
diff changeset
   884
        return (namespace != null) && (namespace.equals(EXT_XSLTC));
7f561c08de6b Initial load
duke
parents:
diff changeset
   885
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   886
7f561c08de6b Initial load
duke
parents:
diff changeset
   887
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   888
     * Returns a vector with all methods named <code>_fname</code>
7f561c08de6b Initial load
duke
parents:
diff changeset
   889
     * after stripping its namespace or <code>null</code>
7f561c08de6b Initial load
duke
parents:
diff changeset
   890
     * if no such methods exist.
7f561c08de6b Initial load
duke
parents:
diff changeset
   891
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   892
    private Vector findMethods() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   893
7f561c08de6b Initial load
duke
parents:
diff changeset
   894
          Vector result = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   895
          final String namespace = _fname.getNamespace();
7f561c08de6b Initial load
duke
parents:
diff changeset
   896
7f561c08de6b Initial load
duke
parents:
diff changeset
   897
          if (_className != null && _className.length() > 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   898
            final int nArgs = _arguments.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   899
            try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   900
              if (_clazz == null) {
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   901
                _clazz = ObjectFactory.findProviderClass(_className, true);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   902
7f561c08de6b Initial load
duke
parents:
diff changeset
   903
                if (_clazz == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   904
                  final ErrorMsg msg =
7f561c08de6b Initial load
duke
parents:
diff changeset
   905
                        new ErrorMsg(ErrorMsg.CLASS_NOT_FOUND_ERR, _className);
7f561c08de6b Initial load
duke
parents:
diff changeset
   906
                  getParser().reportError(Constants.ERROR, msg);
7f561c08de6b Initial load
duke
parents:
diff changeset
   907
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   908
              }
7f561c08de6b Initial load
duke
parents:
diff changeset
   909
7f561c08de6b Initial load
duke
parents:
diff changeset
   910
              final String methodName = _fname.getLocalPart();
7f561c08de6b Initial load
duke
parents:
diff changeset
   911
              final Method[] methods = _clazz.getMethods();
7f561c08de6b Initial load
duke
parents:
diff changeset
   912
7f561c08de6b Initial load
duke
parents:
diff changeset
   913
              for (int i = 0; i < methods.length; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   914
                final int mods = methods[i].getModifiers();
7f561c08de6b Initial load
duke
parents:
diff changeset
   915
                // Is it public and same number of args ?
7f561c08de6b Initial load
duke
parents:
diff changeset
   916
                if (Modifier.isPublic(mods)
7f561c08de6b Initial load
duke
parents:
diff changeset
   917
                    && methods[i].getName().equals(methodName)
7f561c08de6b Initial load
duke
parents:
diff changeset
   918
                    && methods[i].getParameterTypes().length == nArgs)
7f561c08de6b Initial load
duke
parents:
diff changeset
   919
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
   920
                  if (result == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   921
                    result = new Vector();
7f561c08de6b Initial load
duke
parents:
diff changeset
   922
                  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   923
                  result.addElement(methods[i]);
7f561c08de6b Initial load
duke
parents:
diff changeset
   924
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   925
              }
7f561c08de6b Initial load
duke
parents:
diff changeset
   926
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   927
            catch (ClassNotFoundException e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   928
                  final ErrorMsg msg = new ErrorMsg(ErrorMsg.CLASS_NOT_FOUND_ERR, _className);
7f561c08de6b Initial load
duke
parents:
diff changeset
   929
                  getParser().reportError(Constants.ERROR, msg);
7f561c08de6b Initial load
duke
parents:
diff changeset
   930
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   931
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   932
          return result;
7f561c08de6b Initial load
duke
parents:
diff changeset
   933
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   934
7f561c08de6b Initial load
duke
parents:
diff changeset
   935
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   936
     * Returns a vector with all constructors named <code>_fname</code>
7f561c08de6b Initial load
duke
parents:
diff changeset
   937
     * after stripping its namespace or <code>null</code>
7f561c08de6b Initial load
duke
parents:
diff changeset
   938
     * if no such methods exist.
7f561c08de6b Initial load
duke
parents:
diff changeset
   939
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   940
    private Vector findConstructors() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   941
        Vector result = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   942
        final String namespace = _fname.getNamespace();
7f561c08de6b Initial load
duke
parents:
diff changeset
   943
7f561c08de6b Initial load
duke
parents:
diff changeset
   944
        final int nArgs = _arguments.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   945
        try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   946
          if (_clazz == null) {
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   947
            _clazz = ObjectFactory.findProviderClass(_className, true);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   948
7f561c08de6b Initial load
duke
parents:
diff changeset
   949
            if (_clazz == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   950
              final ErrorMsg msg = new ErrorMsg(ErrorMsg.CLASS_NOT_FOUND_ERR, _className);
7f561c08de6b Initial load
duke
parents:
diff changeset
   951
              getParser().reportError(Constants.ERROR, msg);
7f561c08de6b Initial load
duke
parents:
diff changeset
   952
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   953
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   954
7f561c08de6b Initial load
duke
parents:
diff changeset
   955
          final Constructor[] constructors = _clazz.getConstructors();
7f561c08de6b Initial load
duke
parents:
diff changeset
   956
7f561c08de6b Initial load
duke
parents:
diff changeset
   957
          for (int i = 0; i < constructors.length; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   958
              final int mods = constructors[i].getModifiers();
7f561c08de6b Initial load
duke
parents:
diff changeset
   959
              // Is it public, static and same number of args ?
7f561c08de6b Initial load
duke
parents:
diff changeset
   960
              if (Modifier.isPublic(mods) &&
7f561c08de6b Initial load
duke
parents:
diff changeset
   961
                  constructors[i].getParameterTypes().length == nArgs)
7f561c08de6b Initial load
duke
parents:
diff changeset
   962
              {
7f561c08de6b Initial load
duke
parents:
diff changeset
   963
                if (result == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   964
                  result = new Vector();
7f561c08de6b Initial load
duke
parents:
diff changeset
   965
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   966
                result.addElement(constructors[i]);
7f561c08de6b Initial load
duke
parents:
diff changeset
   967
              }
7f561c08de6b Initial load
duke
parents:
diff changeset
   968
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   969
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   970
        catch (ClassNotFoundException e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   971
          final ErrorMsg msg = new ErrorMsg(ErrorMsg.CLASS_NOT_FOUND_ERR, _className);
7f561c08de6b Initial load
duke
parents:
diff changeset
   972
          getParser().reportError(Constants.ERROR, msg);
7f561c08de6b Initial load
duke
parents:
diff changeset
   973
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   974
7f561c08de6b Initial load
duke
parents:
diff changeset
   975
        return result;
7f561c08de6b Initial load
duke
parents:
diff changeset
   976
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   977
7f561c08de6b Initial load
duke
parents:
diff changeset
   978
7f561c08de6b Initial load
duke
parents:
diff changeset
   979
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   980
     * Compute the JVM signature for the class.
7f561c08de6b Initial load
duke
parents:
diff changeset
   981
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   982
    static final String getSignature(Class clazz) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   983
        if (clazz.isArray()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   984
            final StringBuffer sb = new StringBuffer();
7f561c08de6b Initial load
duke
parents:
diff changeset
   985
            Class cl = clazz;
7f561c08de6b Initial load
duke
parents:
diff changeset
   986
            while (cl.isArray()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   987
                sb.append("[");
7f561c08de6b Initial load
duke
parents:
diff changeset
   988
                cl = cl.getComponentType();
7f561c08de6b Initial load
duke
parents:
diff changeset
   989
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   990
            sb.append(getSignature(cl));
7f561c08de6b Initial load
duke
parents:
diff changeset
   991
            return sb.toString();
7f561c08de6b Initial load
duke
parents:
diff changeset
   992
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   993
        else if (clazz.isPrimitive()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   994
            if (clazz == Integer.TYPE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   995
                return "I";
7f561c08de6b Initial load
duke
parents:
diff changeset
   996
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   997
            else if (clazz == Byte.TYPE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   998
                return "B";
7f561c08de6b Initial load
duke
parents:
diff changeset
   999
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1000
            else if (clazz == Long.TYPE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1001
                return "J";
7f561c08de6b Initial load
duke
parents:
diff changeset
  1002
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1003
            else if (clazz == Float.TYPE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1004
                return "F";
7f561c08de6b Initial load
duke
parents:
diff changeset
  1005
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1006
            else if (clazz == Double.TYPE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1007
                return "D";
7f561c08de6b Initial load
duke
parents:
diff changeset
  1008
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1009
            else if (clazz == Short.TYPE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1010
                return "S";
7f561c08de6b Initial load
duke
parents:
diff changeset
  1011
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1012
            else if (clazz == Character.TYPE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1013
                return "C";
7f561c08de6b Initial load
duke
parents:
diff changeset
  1014
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1015
            else if (clazz == Boolean.TYPE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1016
                return "Z";
7f561c08de6b Initial load
duke
parents:
diff changeset
  1017
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1018
            else if (clazz == Void.TYPE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1019
                return "V";
7f561c08de6b Initial load
duke
parents:
diff changeset
  1020
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1021
            else {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1022
                final String name = clazz.toString();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1023
                ErrorMsg err = new ErrorMsg(ErrorMsg.UNKNOWN_SIG_TYPE_ERR,name);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1024
                throw new Error(err.toString());
7f561c08de6b Initial load
duke
parents:
diff changeset
  1025
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1026
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1027
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1028
            return "L" + clazz.getName().replace('.', '/') + ';';
7f561c08de6b Initial load
duke
parents:
diff changeset
  1029
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1030
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1031
7f561c08de6b Initial load
duke
parents:
diff changeset
  1032
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1033
     * Compute the JVM method descriptor for the method.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1034
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1035
    static final String getSignature(Method meth) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1036
        final StringBuffer sb = new StringBuffer();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1037
        sb.append('(');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1038
        final Class[] params = meth.getParameterTypes(); // avoid clone
7f561c08de6b Initial load
duke
parents:
diff changeset
  1039
        for (int j = 0; j < params.length; j++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1040
            sb.append(getSignature(params[j]));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1041
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1042
        return sb.append(')').append(getSignature(meth.getReturnType()))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1043
            .toString();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1044
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1045
7f561c08de6b Initial load
duke
parents:
diff changeset
  1046
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1047
     * Compute the JVM constructor descriptor for the constructor.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1048
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1049
    static final String getSignature(Constructor cons) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1050
        final StringBuffer sb = new StringBuffer();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1051
        sb.append('(');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1052
        final Class[] params = cons.getParameterTypes(); // avoid clone
7f561c08de6b Initial load
duke
parents:
diff changeset
  1053
        for (int j = 0; j < params.length; j++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1054
            sb.append(getSignature(params[j]));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1055
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1056
        return sb.append(")V").toString();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1057
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1058
7f561c08de6b Initial load
duke
parents:
diff changeset
  1059
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1060
     * Return the signature of the current method
7f561c08de6b Initial load
duke
parents:
diff changeset
  1061
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1062
    private String getMethodSignature(Vector argsType) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1063
        final StringBuffer buf = new StringBuffer(_className);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1064
        buf.append('.').append(_fname.getLocalPart()).append('(');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1065
7f561c08de6b Initial load
duke
parents:
diff changeset
  1066
        int nArgs = argsType.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1067
        for (int i = 0; i < nArgs; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1068
            final Type intType = (Type)argsType.elementAt(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1069
            buf.append(intType.toString());
7f561c08de6b Initial load
duke
parents:
diff changeset
  1070
            if (i < nArgs - 1) buf.append(", ");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1071
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1072
7f561c08de6b Initial load
duke
parents:
diff changeset
  1073
        buf.append(')');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1074
        return buf.toString();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1075
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1076
7f561c08de6b Initial load
duke
parents:
diff changeset
  1077
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1078
     * To support EXSLT extensions, convert names with dash to allowable Java names:
7f561c08de6b Initial load
duke
parents:
diff changeset
  1079
     * e.g., convert abc-xyz to abcXyz.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1080
     * Note: dashes only appear in middle of an EXSLT function or element name.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1081
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1082
    protected static String replaceDash(String name)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1083
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1084
        char dash = '-';
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12458
diff changeset
  1085
        final StringBuilder buff = new StringBuilder("");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1086
        for (int i = 0; i < name.length(); i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1087
        if (i > 0 && name.charAt(i-1) == dash)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1088
            buff.append(Character.toUpperCase(name.charAt(i)));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1089
        else if (name.charAt(i) != dash)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1090
            buff.append(name.charAt(i));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1091
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1092
        return buff.toString();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1093
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1094
7f561c08de6b Initial load
duke
parents:
diff changeset
  1095
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1096
     * Translate code to call the BasisLibrary.unallowed_extensionF(String)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1097
     * method.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1098
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1099
    private void translateUnallowedExtension(ConstantPoolGen cpg,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1100
                                             InstructionList il) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1101
        int index = cpg.addMethodref(BASIS_LIBRARY_CLASS,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1102
                                     "unallowed_extension_functionF",
7f561c08de6b Initial load
duke
parents:
diff changeset
  1103
                                     "(Ljava/lang/String;)V");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1104
        il.append(new PUSH(cpg, _fname.toString()));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1105
        il.append(new INVOKESTATIC(index));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1106
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1107
}