< prev index next >

src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/BinOpExpr.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 


  66     /**
  67      * Returns true if this expressions contains a call to last()
  68      */
  69     public boolean hasLastCall() {
  70             return (_left.hasLastCall() || _right.hasLastCall());
  71     }
  72 
  73     public void setParser(Parser parser) {
  74         super.setParser(parser);
  75         _left.setParser(parser);
  76         _right.setParser(parser);
  77     }
  78 
  79     public Type typeCheck(SymbolTable stable) throws TypeCheckError {
  80         final Type tleft = _left.typeCheck(stable);
  81         final Type tright = _right.typeCheck(stable);
  82         final MethodType ptype = lookupPrimop(stable, Ops[_op],
  83                                               new MethodType(Type.Void,
  84                                                              tleft, tright));
  85         if (ptype != null) {
  86             final Type arg1 = (Type) ptype.argsType().get(0);
  87             if (!arg1.identicalTo(tleft)) {
  88                 _left = new CastExpr(_left, arg1);
  89             }
  90             final Type arg2 = (Type) ptype.argsType().get(1);
  91             if (!arg2.identicalTo(tright)) {
  92                 _right = new CastExpr(_right, arg1);
  93             }
  94             return _type = ptype.resultType();
  95         }
  96         throw new TypeCheckError(this);
  97     }
  98 
  99     public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
 100         final InstructionList il = methodGen.getInstructionList();
 101 
 102         _left.translate(classGen, methodGen);
 103         _right.translate(classGen, methodGen);
 104 
 105         switch (_op) {
 106         case PLUS:
 107             il.append(_type.ADD());
 108             break;
 109         case MINUS:
 110             il.append(_type.SUB());
   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 


  66     /**
  67      * Returns true if this expressions contains a call to last()
  68      */
  69     public boolean hasLastCall() {
  70             return (_left.hasLastCall() || _right.hasLastCall());
  71     }
  72 
  73     public void setParser(Parser parser) {
  74         super.setParser(parser);
  75         _left.setParser(parser);
  76         _right.setParser(parser);
  77     }
  78 
  79     public Type typeCheck(SymbolTable stable) throws TypeCheckError {
  80         final Type tleft = _left.typeCheck(stable);
  81         final Type tright = _right.typeCheck(stable);
  82         final MethodType ptype = lookupPrimop(stable, Ops[_op],
  83                                               new MethodType(Type.Void,
  84                                                              tleft, tright));
  85         if (ptype != null) {
  86             final Type arg1 = ptype.argsType().get(0);
  87             if (!arg1.identicalTo(tleft)) {
  88                 _left = new CastExpr(_left, arg1);
  89             }
  90             final Type arg2 = ptype.argsType().get(1);
  91             if (!arg2.identicalTo(tright)) {
  92                 _right = new CastExpr(_right, arg1);
  93             }
  94             return _type = ptype.resultType();
  95         }
  96         throw new TypeCheckError(this);
  97     }
  98 
  99     public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
 100         final InstructionList il = methodGen.getInstructionList();
 101 
 102         _left.translate(classGen, methodGen);
 103         _right.translate(classGen, methodGen);
 104 
 105         switch (_op) {
 106         case PLUS:
 107             il.append(_type.ADD());
 108             break;
 109         case MINUS:
 110             il.append(_type.SUB());
< prev index next >