KickJava   Java API By Example, From Geeks To Geeks.

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


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.cst.*;
30
31 import org.aspectj.compiler.base.bcg.CodeBuilder;
32 import org.aspectj.compiler.base.bcg.Label;
33
34 /**
35  * @grammar ...
36  */

37
38 public abstract class Stmt extends ASTObject {
39
40     /** checks whether control must be live to reach this statement.
41         Block statements, for example, need not cause the "unreachable
42         statement" error if they are empty. This is used as part of
43         {@link org.aspectj.compiler.base.FlowCheckerPass}. */

44     public boolean mustBeLive() { return true; }
45
46     public boolean isBreakable() { return false; }
47     public boolean isContinuable() { return false; }
48
49     public boolean isEmpty() { return false; }
50
51     public void requireBlockStmt() {
52         this.showError("block statement required");
53     }
54     
55     public void requireStmt() {
56         ;
57     }
58
59     // ------------------------------
60
// Intro: FlowCheckerPass
61

62     private boolean completesNormallyFlag;
63     public void setCompletesNormally(boolean b) { completesNormallyFlag = b; }
64     public boolean completesNormally() { return completesNormallyFlag; }
65
66     // ------------------------------
67
// bcg
68

69     /** The purpose of this procedure is to dispatch to {@link
70         #cg}, but to perform an invariant check beforehand to make
71         sure the current stack size is zero. This method is final only
72         because it seems unlikely that anybody would want to override
73         it (they should rather provide a definition for {@link
74         #cg}). If there is a good reason to override this, the
75         final modifier can be removed. */

76     final void cgTop(CodeBuilder cb) {
77         registerLocation(cb);
78         cgStmt(cb);
79         if (cb.getStackSize() != 0) {
80             showWarning("Sanity check: stack size is " + cb.getStackSize() +
81                         " after stmt " + this);
82             //display(0);
83
cb.emitStackSize();
84             cb.setStackSize(0);
85         }
86     }
87
88     // overridden in break and continue
89
protected void registerLocation(CodeBuilder cb) {
90         cb.enterLocation(getSourceLocation());
91     }
92
93     /** This procedure does the work of generating bytecode. Its main
94         requirement is to leave the stack empty. This method should
95         only be called from {@link #cgTop}. */

96     protected void cgStmt(CodeBuilder cb) {
97         throw new RuntimeException JavaDoc("Invalid statement " + this);
98     }
99
100     //BEGIN: Generated from @child and @property
101

102     public Stmt(SourceLocation location) {
103         super(location);
104
105     }
106
107
108     public String JavaDoc getDefaultDisplayName() {
109         return "Stmt()";
110     }
111
112     //END: Generated from @child and @property
113
}
114
115
116
117
118
119
120
Popular Tags