KickJava   Java API By Example, From Geeks To Geeks.

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


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 BitwiseAssignExpr extends AssignExpr {
40
41     public Type discoverType() {
42         Type ty1 = lhs.getType();
43         Type ty2 = rhs.getType();
44         if (! (((ty1 instanceof IntegralType)
45                 && (ty2 instanceof IntegralType))
46                || ((ty1 instanceof BooleanType)
47                    && (ty2 instanceof BooleanType)))) {
48             showOperatorTypeError(op, ty1, ty2);
49         }
50         return ty1;
51     }
52
53     // ------------------------------
54
// INTRO from FlowCheckerPass
55

56     // If we're a boolean operator, we have to make sure to lose
57
// information. 'if (b &= false)' doesn't flow like 'if (false)',
58
// for some reason I can't understand. As specified in JLS 16.1.7
59
public void walkFlow(FlowCheckerPass w) {
60         super.walkFlow(w);
61         if (getType().isBoolean()) {
62             w.setVars(w.getVars().getTrue().join(w.getVars().getFalse()));
63         }
64     }
65
66     // ------------------------------
67
// bcg
68
protected void cgValue(CodeBuilder cb) {
69         cgValueEffect(cb, true);
70     }
71     protected void cgEffect(CodeBuilder cb) {
72         cgValueEffect(cb, false);
73     }
74     private void cgValueEffect(CodeBuilder cb, boolean needsValue) {
75         AssignableExpr lhs = getLhs();
76         Expr rhs = getRhs();
77         Type lhsTy = lhs.getType();
78         Type rhsTy = rhs.getType();
79         String JavaDoc op = getOp();
80         Type ty = (lhsTy instanceof BooleanType)
81             ? lhsTy
82             : getTypeManager().binaryNumericPromotion(lhsTy, rhsTy);
83         lhs.cgLvalue(cb);
84         lhs.cgDupLvalue(cb);
85         lhs.cgLtoRvalue(cb);
86         lhsTy.emitCast(cb, ty);
87         rhs.cgValue(cb, ty);
88         ty.emitBitwiseOp(cb, op);
89         ty.emitCast(cb, lhsTy);
90         if (needsValue) lhs.cgDupRvalue(cb);
91         lhs.cgAssignment(cb);
92     }
93
94     //BEGIN: Generated from @child and @property
95

96     public BitwiseAssignExpr(SourceLocation location, AssignableExpr _lhs, String JavaDoc _op, Expr _rhs) {
97         super(location, _lhs, _op, _rhs);
98
99     }
100     protected BitwiseAssignExpr(SourceLocation source) {
101         super(source);
102     }
103
104     public ASTObject copyWalk(CopyWalker walker) {
105         BitwiseAssignExpr ret = new BitwiseAssignExpr(getSourceLocation());
106         ret.preCopy(walker, this);
107         if (lhs != null) ret.setLhs( (AssignableExpr)walker.process(lhs) );
108         ret.op = op;
109         if (rhs != null) ret.setRhs( (Expr)walker.process(rhs) );
110         return ret;
111     }
112
113
114     public String JavaDoc getDefaultDisplayName() {
115         return "BitwiseAssignExpr(op: "+op+")";
116     }
117
118     //END: Generated from @child and @property
119
}
120
Popular Tags