KickJava   Java API By Example, From Geeks To Geeks.

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


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.*;
28 import java.io.IOException JavaDoc;
29
30 import org.aspectj.compiler.base.bcg.CodeBuilder;
31 import org.aspectj.compiler.base.bcg.Label;
32
33 public final class BooleanType extends PrimitiveType {
34
35     public String JavaDoc getName() { return "boolean"; }
36     public int getTypeIndex() { return Type.BOOLEAN; }
37     public Type getRefType() { return getTypeManager().getType("java.lang", "Boolean"); }
38     public Expr getNullExpr() { return getAST().makeLiteral(false); }
39     public String JavaDoc getDescriptor() { return "Z"; }
40
41     public BooleanType(JavaCompiler compiler) {
42         super(compiler);
43     }
44
45     // ------------------------------
46
// folding
47
final LiteralExpr foldPlusOp(LiteralExpr rand) { return unsupportedFold(); }
48     final LiteralExpr foldMinusOp(LiteralExpr rand) { return unsupportedFold(); }
49     final LiteralExpr foldBitNotOp(LiteralExpr rand) { return unsupportedFold(); }
50     final LiteralExpr foldAddOp(LiteralExpr lit1, LiteralExpr lit2) { return unsupportedFold(); }
51     final LiteralExpr foldNumericOp(String JavaDoc op, LiteralExpr lit1, LiteralExpr lit2) { return unsupportedFold(); }
52     final LiteralExpr foldShiftOp(String JavaDoc op, LiteralExpr lit1, LiteralExpr lit2) { return unsupportedFold(); }
53     final LiteralExpr foldNumericTestOp(String JavaDoc op, LiteralExpr lit1, LiteralExpr lit2) { return unsupportedFold(); }
54
55     LiteralExpr foldLogNotOp(LiteralExpr rand) {
56         return getAST().makeLiteral(! rand.getBooleanValue());
57     }
58     LiteralExpr foldCast(LiteralExpr rand) {
59         return getAST().makeLiteral(rand.getBooleanValue());
60     }
61
62     LiteralExpr foldEqualityTestOp(String JavaDoc op, LiteralExpr lit1, LiteralExpr lit2) {
63         final AST ast = getAST();
64         boolean a = lit1.getBooleanValue();
65         boolean b = lit2.getBooleanValue();
66         if (op == "==") return ast.makeLiteral(a == b);
67         else if (op == "!=") return ast.makeLiteral(a != b);
68         else throw new RuntimeException JavaDoc("bad op " + op);
69     }
70     LiteralExpr foldBitwiseOp(String JavaDoc op, LiteralExpr lit1, LiteralExpr lit2) {
71         final AST ast = getAST();
72         boolean a = lit1.getBooleanValue();
73         boolean b = lit2.getBooleanValue();
74         if (op == "&") return ast.makeLiteral(a & b);
75         else if (op == "|") return ast.makeLiteral(a | b);
76         else if (op == "^") return ast.makeLiteral(a ^ b);
77         else throw new RuntimeException JavaDoc("bad bitwise op " + op);
78     }
79
80     // ------------------------------
81
// code generation
82
final void emitCast(CodeBuilder cb, Type castTo) {}
83
84     final void emitLogNot(CodeBuilder cb) { cb.emitIntConstant(1); cb.emitIXOR(); }
85
86     final void emitAload(CodeBuilder cb) { cb.emitBALOAD(); }
87     final void emitAstore(CodeBuilder cb) { cb.emitBASTORE(); }
88
89     public final void emitLoad(CodeBuilder cb, int loc) { cb.emitILOAD(loc); }
90     public final void emitStore(CodeBuilder cb, int loc) { cb.emitISTORE(loc); }
91     public final void emitReturn(CodeBuilder cb) { cb.emitIRETURN(); }
92
93     void emitEqualityCompare(CodeBuilder cb, String JavaDoc op, Label t, Label f) {
94         if (op == "==") cb.emitIF_ICMPEQ(t, f);
95         else if (op == "!=") cb.emitIF_ICMPNE(t, f);
96     }
97     void emitBitwiseOp(CodeBuilder cb, String JavaDoc op) {
98         if (op == "&") cb.emitIAND();
99         else if (op == "|") cb.emitIOR();
100         else if (op == "^") cb.emitIXOR();
101     }
102
103     final void emitZero(CodeBuilder cb) { unsupportedEmit(); }
104     final void emitOne(CodeBuilder cb) { unsupportedEmit(); }
105     final void emitMinusOne(CodeBuilder cb) { unsupportedEmit(); }
106     final void emitAdd(CodeBuilder cb) { unsupportedEmit(); }
107     final void emitBitNot(CodeBuilder cb) { unsupportedEmit(); }
108     final void emitNumericOp(CodeBuilder cb, String JavaDoc op) { unsupportedEmit(); }
109     final void emitShiftOp(CodeBuilder cb, String JavaDoc op) { unsupportedEmit(); }
110     final void emitNeg(CodeBuilder cb) { unsupportedEmit(); }
111     final void emitNumericCompare(CodeBuilder cb, String JavaDoc op, Label t, Label f) {
112         unsupportedEmit();
113     }
114
115     // ------------------------------
116
// "fast" opcode handling
117

118     boolean hasFastEqualityTestOp() { return true; }
119     void emitFastEqualityTestOp(CodeBuilder cb, EqualityTestOpExpr e,
120                                 Label t, Label f) {
121         Expr rand1 = e.getRand1();
122         Expr rand2 = e.getRand2();
123         String JavaDoc op = e.getOp();
124         if (rand1 instanceof LiteralExpr) {
125             if (rand1.isConstantTrue() ^ (op != "==")) rand2.cgTest(cb, t, f);
126             else rand2.cgTest(cb, f, t);
127         } else if (rand2 instanceof LiteralExpr) {
128             if (rand2.isConstantTrue() ^ (op != "==")) rand1.cgTest(cb, t, f);
129             else rand1.cgTest(cb, f, t);
130         } else {
131             rand1.cgValue(cb, this);
132             rand2.cgValue(cb, this);
133             emitEqualityCompare(cb, op, t, f);
134         }
135     }
136 }
137
Popular Tags