KickJava   Java API By Example, From Geeks To Geeks.

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


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.AssignmentCheckerPass;
28 import org.aspectj.compiler.base.*;
29 import org.aspectj.compiler.crosscuts.AccessFixer;
30
31 import java.util.*;
32
33 import org.aspectj.compiler.base.bcg.CodeBuilder;
34
35 /**
36  *
37  * @grammar x {*=, /=, %=, -=} y
38  */

39 public class NumericAssignExpr extends AssignExpr {
40
41     public Type discoverType() {
42         Type ty1 = lhs.getType();
43         Type ty2 = rhs.getType();
44         if (! ((ty1 instanceof NumericType)
45                && (ty2 instanceof NumericType))) {
46             showOperatorTypeError(op, ty1, ty2);
47         }
48         return ty1;
49     }
50
51     // ------------------------------
52
// bcg
53
protected void cgValue(CodeBuilder cb) {
54         cgValueEffect(cb, true);
55     }
56     protected void cgEffect(CodeBuilder cb) {
57         cgValueEffect(cb, false);
58     }
59     private void cgValueEffect(CodeBuilder cb, boolean needsValue) {
60         AssignableExpr lhs = getLhs();
61         Expr rhs = getRhs();
62         Type lhsTy = lhs.getType();
63         Type rhsTy = rhs.getType();
64         String JavaDoc op = getOp();
65         Type ty = getTypeManager().binaryNumericPromotion(lhsTy, rhsTy);
66         lhs.cgLvalue(cb);
67         lhs.cgDupLvalue(cb);
68         lhs.cgLtoRvalue(cb);
69         lhsTy.emitCast(cb, ty);
70         rhs.cgValue(cb, ty);
71         ty.emitNumericOp(cb, op);
72         ty.emitCast(cb, lhsTy);
73         if (needsValue) lhs.cgDupRvalue(cb);
74         lhs.cgAssignment(cb);
75     }
76
77     //BEGIN: Generated from @child and @property
78

79     public NumericAssignExpr(SourceLocation location, AssignableExpr _lhs, String JavaDoc _op, Expr _rhs) {
80         super(location, _lhs, _op, _rhs);
81
82     }
83     protected NumericAssignExpr(SourceLocation source) {
84         super(source);
85     }
86
87     public ASTObject copyWalk(CopyWalker walker) {
88         NumericAssignExpr ret = new NumericAssignExpr(getSourceLocation());
89         ret.preCopy(walker, this);
90         if (lhs != null) ret.setLhs( (AssignableExpr)walker.process(lhs) );
91         ret.op = op;
92         if (rhs != null) ret.setRhs( (Expr)walker.process(rhs) );
93         return ret;
94     }
95
96
97     public String JavaDoc getDefaultDisplayName() {
98         return "NumericAssignExpr(op: "+op+")";
99     }
100
101     //END: Generated from @child and @property
102
}
103
Popular Tags