KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xalan > xsltc > compiler > UnaryOpExpr


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 /*
17  * $Id: UnaryOpExpr.java,v 1.8 2004/02/16 22:25:10 minchau Exp $
18  */

19
20 package org.apache.xalan.xsltc.compiler;
21
22 import org.apache.bcel.generic.InstructionList;
23 import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
24 import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
25 import org.apache.xalan.xsltc.compiler.util.MethodType;
26 import org.apache.xalan.xsltc.compiler.util.Type;
27 import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
28
29 /**
30  * @author Jacek Ambroziak
31  * @author Santiago Pericas-Geertsen
32  */

33 final class UnaryOpExpr extends Expression {
34     private Expression _left;
35     
36     public UnaryOpExpr(Expression left) {
37     (_left = left).setParent(this);
38     }
39
40     /**
41      * Returns true if this expressions contains a call to position(). This is
42      * needed for context changes in node steps containing multiple predicates.
43      */

44     public boolean hasPositionCall() {
45     return(_left.hasPositionCall());
46     }
47
48     /**
49      * Returns true if this expressions contains a call to last()
50      */

51     public boolean hasLastCall() {
52             return(_left.hasLastCall());
53     }
54     
55     public void setParser(Parser parser) {
56     super.setParser(parser);
57     _left.setParser(parser);
58     }
59     
60     public Type typeCheck(SymbolTable stable) throws TypeCheckError {
61     final Type tleft = _left.typeCheck(stable);
62     final MethodType ptype = lookupPrimop(stable, "u-",
63                           new MethodType(Type.Void,
64                                  tleft));
65     
66     if (ptype != null) {
67         final Type arg1 = (Type) ptype.argsType().elementAt(0);
68         if (!arg1.identicalTo(tleft)) {
69         _left = new CastExpr(_left, arg1);
70         }
71         return _type = ptype.resultType();
72     }
73
74     throw new TypeCheckError(this);
75     }
76
77     public String JavaDoc toString() {
78     return "u-" + '(' + _left + ')';
79     }
80
81     public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
82     InstructionList il = methodGen.getInstructionList();
83     _left.translate(classGen, methodGen);
84     il.append(_type.NEG());
85     }
86 }
87
88
Popular Tags