1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /* 6 * Copyright 2001-2004 The Apache Software Foundation. 7 * 8 * Licensed under the Apache License, Version 2.0 (the "License"); 9 * you may not use this file except in compliance with the License. 10 * You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 */ 20 /* 21 * $Id: UnaryOpExpr.java,v 1.2.4.1 2005/09/05 09:21:00 pvedula Exp $ 22 */ 23 24 package com.sun.org.apache.xalan.internal.xsltc.compiler; 25 26 import com.sun.org.apache.bcel.internal.generic.InstructionList; 27 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator; 28 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator; 29 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodType; 30 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type; 31 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError; 32 33 /** 34 * @author Jacek Ambroziak 35 * @author Santiago Pericas-Geertsen 36 */ 37 final class UnaryOpExpr extends Expression { 38 private Expression _left; 39 40 public UnaryOpExpr(Expression left) { 41 (_left = left).setParent(this); 42 } 43 44 /** 45 * Returns true if this expressions contains a call to position(). This is 46 * needed for context changes in node steps containing multiple predicates. 47 */ 48 public boolean hasPositionCall() { 49 return(_left.hasPositionCall()); 50 } 51 52 /** 53 * Returns true if this expressions contains a call to last() 54 */ 55 public boolean hasLastCall() { 56 return(_left.hasLastCall()); 57 } 58 59 public void setParser(Parser parser) { 60 super.setParser(parser); 61 _left.setParser(parser); 62 } 63 64 public Type typeCheck(SymbolTable stable) throws TypeCheckError { 65 final Type tleft = _left.typeCheck(stable); 66 final MethodType ptype = lookupPrimop(stable, "u-", 67 new MethodType(Type.Void, 68 tleft)); 69 70 if (ptype != null) { 71 final Type arg1 = (Type) ptype.argsType().elementAt(0); 72 if (!arg1.identicalTo(tleft)) { 73 _left = new CastExpr(_left, arg1); 74 } 75 return _type = ptype.resultType(); 76 } 77 78 throw new TypeCheckError(this); 79 } 80 81 public String toString() { 82 return "u-" + '(' + _left + ')'; 83 } 84 85 public void translate(ClassGenerator classGen, MethodGenerator methodGen) { 86 InstructionList il = methodGen.getInstructionList(); 87 _left.translate(classGen, methodGen); 88 il.append(_type.NEG()); 89 } 90 }