KickJava   Java API By Example, From Geeks To Geeks.

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


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
35 /**
36  * @grammar rand1 <op> rand2
37  */

38 public class BitwiseOpExpr 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.isBoolean() && ty2.isBoolean()) {
47             return getTypeManager().booleanType;
48         } else if (ty1.isIntegral() && ty2.isIntegral()) {
49             return getTypeManager().binaryNumericPromotion(ty1, ty2);
50         } else {
51             showOperatorTypeError(op, ty1, ty2);
52             return getTypeManager().anyType;
53         }
54     }
55
56     protected Type getLiftType() {
57         return getType();
58     }
59
60     protected LiteralExpr halfFold(Type type, LiteralExpr lit1, LiteralExpr lit2) {
61         return type.foldBitwiseOp(getOp(), lit1, lit2);
62     }
63
64     // ------------------------------
65
// bcg
66
protected void cgValue(CodeBuilder cb) {
67         Type ty = getLiftType();
68         getRand1().cgValue(cb, ty);
69         getRand2().cgValue(cb, ty);
70         ty.emitBitwiseOp(cb, getOp());
71     }
72
73     protected void cgOp(CodeBuilder cb, Type ty) {
74         ty.emitBitwiseOp(cb, getOp());
75     }
76
77     //BEGIN: Generated from @child and @property
78

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