src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/LangCall.java
author joehw
Wed, 18 Oct 2017 13:25:49 -0700
changeset 47359 e1a6c0168741
parent 47216 71c04702a3d5
child 48409 5ab69533994b
permissions -rw-r--r--
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked Reviewed-by: lancea, rriggs, mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
     3
 * @LastModified: Oct 2017
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
/*
44797
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     6
 * Licensed to the Apache Software Foundation (ASF) under one or more
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     7
 * contributor license agreements.  See the NOTICE file distributed with
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     8
 * this work for additional information regarding copyright ownership.
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     9
 * The ASF licenses this file to You under the Apache License, Version 2.0
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    10
 * (the "License"); you may not use this file except in compliance with
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    11
 * the License.  You may obtain a copy of the License at
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *
44797
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    13
 *      http://www.apache.org/licenses/LICENSE-2.0
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
package com.sun.org.apache.xalan.internal.xsltc.compiler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
import com.sun.org.apache.bcel.internal.generic.ILOAD;
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
import com.sun.org.apache.bcel.internal.generic.INVOKESTATIC;
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import com.sun.org.apache.bcel.internal.generic.InstructionList;
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.FilterGenerator;
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.StringType;
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    34
import java.util.List;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
 * @author Morten Jorgensen
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
final class LangCall extends FunctionCall {
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
    private Expression _lang;
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
    private Type _langType;
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
     * Get the parameters passed to function:
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
     *   lang(string)
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
     */
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    47
    public LangCall(QName fname, List<Expression> arguments) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
        super(fname, arguments);
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
        _lang = argument(0);
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
    public Type typeCheck(SymbolTable stable) throws TypeCheckError {
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
        _langType = _lang.typeCheck(stable);
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
        if (!(_langType instanceof StringType)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
            _lang = new CastExpr(_lang, Type.String);
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
        return Type.Boolean;
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
    public Type getType() {
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
        return(Type.Boolean);
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
     * This method is called when the constructor is compiled in
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
     * Stylesheet.compileConstructor() and not as the syntax tree is traversed.
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
    public void translate(ClassGenerator classGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
                          MethodGenerator methodGen) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
        final ConstantPoolGen cpg = classGen.getConstantPool();
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
        final InstructionList il = methodGen.getInstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
        final int tst = cpg.addMethodref(BASIS_LIBRARY_CLASS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
                                         "testLanguage",
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
                                         "("+STRING_SIG+DOM_INTF_SIG+"I)Z");
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
        _lang.translate(classGen,methodGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
        il.append(methodGen.loadDOM());
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
        if (classGen instanceof FilterGenerator)
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
            il.append(new ILOAD(1));
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
            il.append(methodGen.loadContextNode());
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
        il.append(new INVOKESTATIC(tst));
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
}