KickJava   Java API By Example, From Geeks To Geeks.

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


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 NumericOpExpr extends BinopExpr {
40
41     protected Type discoverType() {
42         Expr rand1 = getRand1();
43         Expr rand2 = getRand2();
44         Type ty1 = rand1.getType();
45         Type ty2 = rand2.getType();
46
47         Type anyType = getTypeManager().anyType;
48
49         if (ty1.isMissing() || ty2.isMissing()) {
50             return anyType;
51         } else if (ty1 instanceof NumericType && ty2 instanceof NumericType) {
52             return getTypeManager().binaryNumericPromotion(ty1, ty2);
53         } else {
54             showOperatorTypeError(op, ty1, ty2);
55             return anyType;
56         }
57     }
58
59     protected Type getLiftType() {
60         return getType();
61     }
62
63     protected LiteralExpr halfFold(Type type, LiteralExpr lit1, LiteralExpr lit2) {
64         return type.foldNumericOp(getOp(), lit1, lit2);
65     }
66
67     // ------------------------------
68
// bcg
69

70     protected void cgValue(CodeBuilder cb) {
71         Type liftType = getLiftType();
72         getRand1().cgValue(cb, liftType);
73         getRand2().cgValue(cb, liftType);
74         liftType.emitNumericOp(cb, getOp());
75     }
76
77     protected void cgOp(CodeBuilder cb, Type ty) {
78         ty.emitNumericOp(cb, getOp());
79     }
80
81     //BEGIN: Generated from @child and @property
82

83     public NumericOpExpr(SourceLocation location, Expr _rand1, String JavaDoc _op, Expr _rand2) {
84         super(location, _rand1, _op, _rand2);
85
86     }
87     protected NumericOpExpr(SourceLocation source) {
88         super(source);
89     }
90
91     public ASTObject copyWalk(CopyWalker walker) {
92         NumericOpExpr ret = new NumericOpExpr(getSourceLocation());
93         ret.preCopy(walker, this);
94         if (rand1 != null) ret.setRand1( (Expr)walker.process(rand1) );
95         ret.op = op;
96         if (rand2 != null) ret.setRand2( (Expr)walker.process(rand2) );
97         return ret;
98     }
99
100
101     public String JavaDoc getDefaultDisplayName() {
102         return "NumericOpExpr(op: "+op+")";
103     }
104
105     //END: Generated from @child and @property
106
}
107
Popular Tags