KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.aspectj.compiler.base.JavaCompiler;
29 import org.aspectj.compiler.base.CodeWriter;
30 import java.io.IOException JavaDoc;
31
32 import org.aspectj.compiler.base.bcg.CodeBuilder;
33 import org.aspectj.compiler.base.bcg.Label;
34
35 /**
36   * @grammar label: stmt;
37   * @property String label
38   * @child Stmt stmt
39   */

40
41 public class LabeledStmt extends Stmt {
42
43     public void unparse(CodeWriter writer) throws IOException JavaDoc {
44         writer.write(label);
45         writer.write(": ");
46         writer.write(stmt);
47     }
48     
49     public void requireStmt() {
50         this.showError("labeled statement not allowed here");
51     }
52     
53     public void checkSpec() {
54         if (!(stmt instanceof LabeledStmt)) {
55             stmt.requireStmt();
56         }
57         super.checkSpec();
58     }
59
60     // ------------------------------
61
// INTRO from FlowCheckerPass
62

63     public void walkFlow(FlowCheckerPass w) {
64         if (w.isLabelUsed(getLabel())) {
65             showError("duplicate definition of label " + getLabel());
66         }
67         w.enterContext(this);
68         w.process(getStmt());
69         w.leaveContext();
70         w.setLive(w.isLive() || w.isBroken(this));
71         w.setVars(w.getVars().join(w.getBreakVars(this)));
72     }
73
74     // ------------------------------
75
// Intro: ByteCodeCleanupPass
76

77     public void walkCleanup(ByteCodeCleanupPass w) {
78         w.enterContext(this);
79         w.process(getStmt());
80         w.leaveContext();
81         w.setLive(w.isLive() || w.isBroken(this));
82     }
83
84     // does this "optimization" even do anything?
85
public ASTObject postCleanup(ByteCodeCleanupPass walker) {
86         if (getStmt() instanceof EmptyStmt) {
87             return getStmt();
88         } else {
89             return this;
90         }
91     }
92
93     // ------------------------------
94
// bcg
95

96     protected void cgStmt(CodeBuilder cb) {
97         Label endLab = cb.genLabel();
98         cb.enterNonWindingContext(this, endLab, null);
99         stmt.cgTop(cb);
100         cb.leaveContext();
101         cb.emitLabel(endLab);
102     }
103
104     // ------------------------------
105
// flow
106

107 // protected FlowEnv checkFlow(FlowEnv env) {
108
// return getStmt().checkLabeledFlow(env, getLabel());
109
// }
110

111     //BEGIN: Generated from @child and @property
112
protected String JavaDoc label;
113     public String JavaDoc getLabel() { return label; }
114     public void setLabel(String JavaDoc _label) { label = _label; }
115
116     protected Stmt stmt;
117     public Stmt getStmt() { return stmt; }
118     public void setStmt(Stmt _stmt) {
119         if (_stmt != null) _stmt.setParent(this);
120         stmt = _stmt;
121     }
122
123     public LabeledStmt(SourceLocation location, String JavaDoc _label, Stmt _stmt) {
124         super(location);
125         setLabel(_label);
126         setStmt(_stmt);
127     }
128     protected LabeledStmt(SourceLocation source) {
129         super(source);
130     }
131
132     public ASTObject copyWalk(CopyWalker walker) {
133         LabeledStmt ret = new LabeledStmt(getSourceLocation());
134         ret.preCopy(walker, this);
135         ret.label = label;
136         if (stmt != null) ret.setStmt( (Stmt)walker.process(stmt) );
137         return ret;
138     }
139
140     public ASTObject getChildAt(int childIndex) {
141         switch(childIndex) {
142         case 0: return stmt;
143         default: return super.getChildAt(childIndex);
144         }
145     }
146      public String JavaDoc getChildNameAt(int childIndex) {
147         switch(childIndex) {
148         case 0: return "stmt";
149         default: return super.getChildNameAt(childIndex);
150         }
151     }
152      public void setChildAt(int childIndex, ASTObject child) {
153         switch(childIndex) {
154         case 0: setStmt((Stmt)child); return;
155         default: super.setChildAt(childIndex, child); return;
156         }
157     }
158      public int getChildCount() {
159         return 1;
160     }
161
162     public String JavaDoc getDefaultDisplayName() {
163         return "LabeledStmt(label: "+label+")";
164     }
165
166     //END: Generated from @child and @property
167
}
168
169
170
Popular Tags