KickJava   Java API By Example, From Geeks To Geeks.

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


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
31 import java.util.*;
32
33 import org.aspectj.compiler.base.bcg.CodeBuilder;
34 import org.aspectj.compiler.base.bcg.Label;
35
36 /**
37  * @grammar rand1 <op> rand2
38  */

39 public class EqualityTestOpExpr extends BinopExpr {
40
41     protected Type discoverType() {
42         Type ty1 = getRand1().getType();
43         Type ty2 = getRand2().getType();
44
45         if (ty1 instanceof RefType && ty2 instanceof RefType) {
46             if (! (ty1.isCoercableTo(ty2) || ty2.isCoercableTo(ty1))) {
47                 showError("incomparable types: " + ty1.getString() +
48                           " and " + ty2.getString());
49             }
50         } else if ((ty1 instanceof RefType || ty2 instanceof RefType) ||
51                    ! ((ty1.isBoolean() && ty2.isBoolean()) ||
52                       (ty1.isNumeric() && ty2.isNumeric()))) {
53             showOperatorTypeError(op, ty1, ty2);
54         }
55         return getTypeManager().booleanType;
56     }
57
58     protected Type getLiftType() {
59         Type ty1 = getRand1().getType();
60         Type ty2 = getRand2().getType();
61
62         if (ty1.isBoolean() && ty2.isBoolean()) {
63             return getTypeManager().booleanType;
64         } else if (ty1.isNumeric() && ty2.isNumeric()) {
65             return getTypeManager().binaryNumericPromotion(ty1, ty2);
66         } else if (ty1 instanceof RefType && ty2 instanceof RefType) {
67             return getTypeManager().getObjectType();
68         } else {
69             showOperatorTypeError(op, ty1, ty2);
70             return getTypeManager().anyType;
71         }
72     }
73
74     protected LiteralExpr halfFold(Type type, LiteralExpr lit1, LiteralExpr lit2) {
75         return type.foldEqualityTestOp(getOp(), lit1, lit2);
76     }
77
78     // ------------------------------
79
// bcg
80

81     protected void cgTest(CodeBuilder cb, Label t, Label f) {
82         Type liftType = getLiftType();
83         if (liftType.hasFastEqualityTestOp()) {
84             liftType.emitFastEqualityTestOp(cb, this, t, f);
85         } else {
86             getRand1().cgValue(cb, liftType);
87             getRand2().cgValue(cb, liftType);
88             liftType.emitEqualityCompare(cb, getOp(), t, f);
89         }
90     }
91
92     protected void cgOp(CodeBuilder cb, Type ty) {
93         throw new RuntimeException JavaDoc("Attempt to generate code for effect op "
94                                    + getOp());
95     }
96
97     //BEGIN: Generated from @child and @property
98

99     public EqualityTestOpExpr(SourceLocation location, Expr _rand1, String JavaDoc _op, Expr _rand2) {
100         super(location, _rand1, _op, _rand2);
101
102     }
103     protected EqualityTestOpExpr(SourceLocation source) {
104         super(source);
105     }
106
107     public ASTObject copyWalk(CopyWalker walker) {
108         EqualityTestOpExpr ret = new EqualityTestOpExpr(getSourceLocation());
109         ret.preCopy(walker, this);
110         if (rand1 != null) ret.setRand1( (Expr)walker.process(rand1) );
111         ret.op = op;
112         if (rand2 != null) ret.setRand2( (Expr)walker.process(rand2) );
113         return ret;
114     }
115
116
117     public String JavaDoc getDefaultDisplayName() {
118         return "EqualityTestOpExpr(op: "+op+")";
119     }
120
121     //END: Generated from @child and @property
122
}
123
Popular Tags