KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > compiler > base > ast > NumericTestOpExpr


1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  *
3  * This file is part of the compiler and core tools for the AspectJ(tm)
4  * programming language; see http://aspectj.org
5  *
6  * The contents of this file are subject to the Mozilla Public License
7  * Version 1.1 (the "License"); you may not use this file except in
8  * compliance with the License. You may obtain a copy of the License at
9  * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is AspectJ.
17  *
18  * The Initial Developer of the Original Code is Xerox Corporation. Portions
19  * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
20  * All Rights Reserved.
21  *
22  * Contributor(s):
23  */

24
25 package org.aspectj.compiler.base.ast;
26
27 import org.aspectj.compiler.base.JavaCompiler;
28 import org.aspectj.compiler.base.CodeWriter;
29 import java.io.IOException JavaDoc;
30 import org.aspectj.compiler.base.bcg.CodeBuilder;
31 import org.aspectj.compiler.base.bcg.Label;
32
33 import java.util.*;
34
35 /**
36  * @grammar rand1 <op> rand2
37  */

38 public class NumericTestOpExpr extends BinopExpr {
39
40     protected Type discoverType() {
41         Expr rand1 = getRand1();
42         Expr rand2 = getRand2();
43         Type ty1 = rand1.getType();
44         Type ty2 = rand2.getType();
45
46         if (!(ty1 instanceof NumericType && ty2 instanceof NumericType)) {
47             showOperatorTypeError(op, ty1, ty2);
48         }
49         return getTypeManager().booleanType;
50     }
51
52     protected Type getLiftType() {
53         Expr rand1 = getRand1();
54         Expr rand2 = getRand2();
55         Type ty1 = rand1.getType();
56         Type ty2 = rand2.getType();
57
58         if (ty1 instanceof NumericType && ty2 instanceof NumericType) {
59             return getTypeManager().binaryNumericPromotion(ty1, ty2);
60         } else {
61             showOperatorTypeError(op, ty1, ty2);
62             return getTypeManager().anyType;
63         }
64     }
65
66     protected LiteralExpr halfFold(Type type, LiteralExpr lit1, LiteralExpr lit2) {
67         return type.foldNumericTestOp(getOp(), lit1, lit2);
68     }
69
70     // ------------------------------
71
// bcg
72

73     protected void cgTest(CodeBuilder cb, Label t, Label f) {
74         Type liftType = getLiftType();
75         if (liftType.hasFastNumericTestOp()) {
76             liftType.emitFastNumericTestOp(cb, this, t, f);
77         } else {
78             getRand1().cgValue(cb, liftType);
79             getRand2().cgValue(cb, liftType);
80             liftType.emitNumericCompare(cb, getOp(), t, f);
81         }
82     }
83
84     protected void cgOp(CodeBuilder cb, Type ty) {
85         throw new RuntimeException JavaDoc("Attempt to generate code for effect op "
86                                    + getOp());
87     }
88
89     //BEGIN: Generated from @child and @property
90

91     public NumericTestOpExpr(SourceLocation location, Expr _rand1, String JavaDoc _op, Expr _rand2) {
92         super(location, _rand1, _op, _rand2);
93
94     }
95     protected NumericTestOpExpr(SourceLocation source) {
96         super(source);
97     }
98
99     public ASTObject copyWalk(CopyWalker walker) {
100         NumericTestOpExpr ret = new NumericTestOpExpr(getSourceLocation());
101         ret.preCopy(walker, this);
102         if (rand1 != null) ret.setRand1( (Expr)walker.process(rand1) );
103         ret.op = op;
104         if (rand2 != null) ret.setRand2( (Expr)walker.process(rand2) );
105         return ret;
106     }
107
108
109     public String JavaDoc getDefaultDisplayName() {
110         return "NumericTestOpExpr(op: "+op+")";
111     }
112
113     //END: Generated from @child and @property
114
}
115
Popular Tags