KickJava   Java API By Example, From Geeks To Geeks.

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


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
29 import org.aspectj.compiler.base.bcg.CodeBuilder;
30
31 /**
32  * @grammar super
33  */

34 public class SuperExpr extends Expr {
35     public final Type discoverType() {
36         return getThisType().getSuperClassType();
37     }
38     
39     public NameType getThisType() {
40         return (NameType) getDeclaringType();
41     }
42
43     public void unparse(CodeWriter writer) {
44         if (inAllowedPosition()) {
45             writer.writeKeyword("super");
46         } else {
47             writer.writeKeyword("this");
48         }
49     }
50
51
52     // ------------------------------
53
// Intro: from SpecChecker
54

55     // this is very similar to the test in TypeExpr
56
public void checkSpec() {
57         super.checkSpec();
58   
59         if (!inAllowedPosition()) showError("bad identifier");
60     }
61     
62     
63     public boolean inAllowedPosition() {
64         // we are only allowed in a limited number of places.
65
ASTObject self = this;
66         ASTObject parent = getParent();
67
68         // the check for the reverse pointer may not actually be necessary
69
if (parent instanceof Expr) {
70             if (parent instanceof CallExpr) {
71                 if (((CallExpr)parent).getExpr() == self) return true;
72             } else if (parent instanceof FieldAccessExpr) {
73                 if (((FieldAccessExpr)parent).getExpr() == self) return true;
74             }
75         }
76         
77         return false;
78     }
79     
80     
81     // ------------------------------
82
// INTRO from InnerInfoPass -- should have a more generic name
83

84     public void postInnerInfo(InnerInfoPass walker) {
85         if (!walker.isAccessibleExactly(getThisType())) {
86             if (!fromSource() && getParent().fromSource()) {
87                 getParent().showError("no instance available");
88             } else {
89                 showError("no instance available");
90             }
91         }
92     }
93
94     // ------------------------------
95
// bcg
96

97     protected void cgValue(CodeBuilder cb) {
98         cb.emitALOAD(0);
99     }
100
101     //BEGIN: Generated from @child and @property
102

103     public SuperExpr(SourceLocation location) {
104         super(location);
105
106     }
107
108     public ASTObject copyWalk(CopyWalker walker) {
109         SuperExpr ret = new SuperExpr(getSourceLocation());
110         ret.preCopy(walker, this);
111
112         return ret;
113     }
114
115
116     public String JavaDoc getDefaultDisplayName() {
117         return "SuperExpr()";
118     }
119
120     //END: Generated from @child and @property
121
}
122
Popular Tags