KickJava   Java API By Example, From Geeks To Geeks.

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


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.*;
29
30 import org.aspectj.compiler.base.bcg.CodeBuilder;
31 import org.aspectj.compiler.base.bcg.Label;
32
33 abstract public class RefType extends Type {
34     public RefType(JavaCompiler compiler) {
35         super(compiler);
36     }
37
38     // constant folding
39
final LiteralExpr foldPlusOp(LiteralExpr rand) { return unsupportedFold(); }
40     final LiteralExpr foldMinusOp(LiteralExpr rand) { return unsupportedFold(); }
41     final LiteralExpr foldBitNotOp(LiteralExpr rand) { return unsupportedFold(); }
42     final LiteralExpr foldLogNotOp(LiteralExpr rand) { return unsupportedFold(); }
43     final LiteralExpr foldNumericOp(String JavaDoc op, LiteralExpr lit1, LiteralExpr lit2) { return unsupportedFold(); }
44     final LiteralExpr foldBitwiseOp(String JavaDoc op, LiteralExpr lit1, LiteralExpr lit2) { return unsupportedFold(); }
45     final LiteralExpr foldShiftOp(String JavaDoc op, LiteralExpr lit1, LiteralExpr lit2) { return unsupportedFold(); }
46     final LiteralExpr foldNumericTestOp(String JavaDoc op, LiteralExpr lit1, LiteralExpr lit2) { return unsupportedFold(); }
47     
48     // overridden in nameType, for String
49
LiteralExpr foldCast(LiteralExpr lit) { return unsupportedFold(); }
50     LiteralExpr foldAddOp(LiteralExpr lit1, LiteralExpr lit2) { return unsupportedFold(); }
51     LiteralExpr foldEqualityTestOp(String JavaDoc op, LiteralExpr lit1, LiteralExpr lit2) { return unsupportedFold(); }
52
53     // code gen
54
void emitCast(CodeBuilder cb, Type castTo) {
55         if (castTo.isAssignableFrom(this)) return;
56         if (!(castTo instanceof RefType)) {
57             System.err.println("can't emit cast for " + this + " to " + castTo);
58             return;
59         }
60         cb.emitCHECKCAST((RefType)castTo);
61     }
62
63     void emitEqualityCompare(CodeBuilder cb, String JavaDoc op, Label t, Label f) {
64         if (op == "==") cb.emitIF_ACMPEQ(t, f);
65         else if (op == "!=") cb.emitIF_ACMPNE(t, f);
66     }
67
68     void emitAload(CodeBuilder cb) { cb.emitAALOAD(); }
69     void emitAstore(CodeBuilder cb) { cb.emitAASTORE(); }
70     void emitNewarray(CodeBuilder cb) { cb.emitANEWARRAY(this); }
71     void emitInstanceof(CodeBuilder cb) { cb.emitINSTANCEOF(this); }
72
73     public void emitLoad(CodeBuilder cb, int loc) { cb.emitALOAD(loc); }
74     public void emitStore(CodeBuilder cb, int loc) { cb.emitASTORE(loc); }
75     public void emitReturn(CodeBuilder cb) { cb.emitARETURN(); }
76
77     String JavaDoc getInternalId() {
78         return getId();
79     }
80
81     // general type-based emitters
82
final void emitBitNot(CodeBuilder cb) { unsupportedEmit(); }
83     final void emitLogNot(CodeBuilder cb) { unsupportedEmit(); }
84     final void emitZero(CodeBuilder cb) { unsupportedEmit(); }
85     final void emitOne(CodeBuilder cb) { unsupportedEmit(); }
86     final void emitMinusOne(CodeBuilder cb) { unsupportedEmit(); }
87     final void emitAdd(CodeBuilder cb) { unsupportedEmit(); }
88     final void emitNeg(CodeBuilder cb) { unsupportedEmit(); }
89     final void emitNumericOp(CodeBuilder cb, String JavaDoc op) { unsupportedEmit(); }
90     final void emitBitwiseOp(CodeBuilder cb, String JavaDoc op) { unsupportedEmit(); }
91     final void emitShiftOp(CodeBuilder cb, String JavaDoc op) { unsupportedEmit(); }
92     final void emitNumericCompare(CodeBuilder cb, String JavaDoc op, Label t, Label f) {
93         throw new RuntimeException JavaDoc("Type " + this + " doesn't support op " + op);
94     }
95
96     // ------------------------------
97
// "fast" opcode handling
98

99     final boolean hasFastEqualityTestOp() { return true; }
100     final void emitFastEqualityTestOp(CodeBuilder cb, EqualityTestOpExpr e,
101                                 Label t, Label f) {
102         Expr rand1 = e.getRand1();
103         Expr rand2 = e.getRand2();
104         String JavaDoc op = e.getOp();
105         if (rand1.isConstantZero()) {
106             rand2.cgValue(cb, this);
107             emitEqualityCompare0(cb, op, t, f);
108         } else if (rand2.isConstantZero()) {
109             rand1.cgValue(cb, this);
110             emitEqualityCompare0(cb, op, t, f);
111         } else {
112             rand1.cgValue(cb, this);
113             rand2.cgValue(cb, this);
114             emitEqualityCompare(cb, op, t, f);
115         }
116     }
117     private void emitEqualityCompare0(CodeBuilder cb, String JavaDoc op, Label t, Label f) {
118         if (op == "==") cb.emitIFNULL(t, f);
119         else if (op == "!=") cb.emitIFNONNULL(t, f);
120     }
121 }
122
Popular Tags