< prev index next >

src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/LogicalExpr.java

Print this page


   1 /*
   2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
   3  * @LastModified: Oct 2017
   4  */
   5 /*
   6  * Licensed to the Apache Software Foundation (ASF) under one or more
   7  * contributor license agreements.  See the NOTICE file distributed with
   8  * this work for additional information regarding copyright ownership.
   9  * The ASF licenses this file to You under the Apache License, Version 2.0
  10  * (the "License"); you may not use this file except in compliance with
  11  * the License.  You may obtain a copy of the License at
  12  *
  13  *      http://www.apache.org/licenses/LICENSE-2.0
  14  *
  15  * Unless required by applicable law or agreed to in writing, software
  16  * distributed under the License is distributed on an "AS IS" BASIS,
  17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18  * See the License for the specific language governing permissions and
  19  * limitations under the License.
  20  */
  21 
  22 package com.sun.org.apache.xalan.internal.xsltc.compiler;
  23 


 120      */
 121     public String toString() {
 122         return Ops[_op] + '(' + _left + ", " + _right + ')';
 123     }
 124 
 125     /**
 126      * Type-check this expression, and possibly child expressions.
 127      */
 128     public Type typeCheck(SymbolTable stable) throws TypeCheckError {
 129         // Get the left and right operand types
 130         Type tleft = _left.typeCheck(stable);
 131         Type tright = _right.typeCheck(stable);
 132 
 133         // Check if the operator supports the two operand types
 134         MethodType wantType = new MethodType(Type.Void, tleft, tright);
 135         MethodType haveType = lookupPrimop(stable, Ops[_op], wantType);
 136 
 137         // Yes, the operation is supported
 138         if (haveType != null) {
 139             // Check if left-hand side operand must be type casted
 140             Type arg1 = (Type)haveType.argsType().get(0);
 141             if (!arg1.identicalTo(tleft))
 142                 _left = new CastExpr(_left, arg1);
 143             // Check if right-hand side operand must be type casted
 144             Type arg2 = (Type) haveType.argsType().get(1);
 145             if (!arg2.identicalTo(tright))
 146                 _right = new CastExpr(_right, arg1);
 147             // Return the result type for the operator we will use
 148             return _type = haveType.resultType();
 149         }
 150         throw new TypeCheckError(this);
 151     }
 152 
 153     /**
 154      * Compile the expression - leave boolean expression on stack
 155      */
 156     public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
 157         translateDesynthesized(classGen, methodGen);
 158         synthesize(classGen, methodGen);
 159     }
 160 
 161     /**
 162      * Compile expression and update true/false-lists
 163      */
 164     public void translateDesynthesized(ClassGenerator classGen,


   1 /*
   2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
   3  * @LastModified: Nov 2017
   4  */
   5 /*
   6  * Licensed to the Apache Software Foundation (ASF) under one or more
   7  * contributor license agreements.  See the NOTICE file distributed with
   8  * this work for additional information regarding copyright ownership.
   9  * The ASF licenses this file to You under the Apache License, Version 2.0
  10  * (the "License"); you may not use this file except in compliance with
  11  * the License.  You may obtain a copy of the License at
  12  *
  13  *      http://www.apache.org/licenses/LICENSE-2.0
  14  *
  15  * Unless required by applicable law or agreed to in writing, software
  16  * distributed under the License is distributed on an "AS IS" BASIS,
  17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18  * See the License for the specific language governing permissions and
  19  * limitations under the License.
  20  */
  21 
  22 package com.sun.org.apache.xalan.internal.xsltc.compiler;
  23 


 120      */
 121     public String toString() {
 122         return Ops[_op] + '(' + _left + ", " + _right + ')';
 123     }
 124 
 125     /**
 126      * Type-check this expression, and possibly child expressions.
 127      */
 128     public Type typeCheck(SymbolTable stable) throws TypeCheckError {
 129         // Get the left and right operand types
 130         Type tleft = _left.typeCheck(stable);
 131         Type tright = _right.typeCheck(stable);
 132 
 133         // Check if the operator supports the two operand types
 134         MethodType wantType = new MethodType(Type.Void, tleft, tright);
 135         MethodType haveType = lookupPrimop(stable, Ops[_op], wantType);
 136 
 137         // Yes, the operation is supported
 138         if (haveType != null) {
 139             // Check if left-hand side operand must be type casted
 140             Type arg1 = haveType.argsType().get(0);
 141             if (!arg1.identicalTo(tleft))
 142                 _left = new CastExpr(_left, arg1);
 143             // Check if right-hand side operand must be type casted
 144             Type arg2 = haveType.argsType().get(1);
 145             if (!arg2.identicalTo(tright))
 146                 _right = new CastExpr(_right, arg1);
 147             // Return the result type for the operator we will use
 148             return _type = haveType.resultType();
 149         }
 150         throw new TypeCheckError(this);
 151     }
 152 
 153     /**
 154      * Compile the expression - leave boolean expression on stack
 155      */
 156     public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
 157         translateDesynthesized(classGen, methodGen);
 158         synthesize(classGen, methodGen);
 159     }
 160 
 161     /**
 162      * Compile expression and update true/false-lists
 163      */
 164     public void translateDesynthesized(ClassGenerator classGen,


< prev index next >