KickJava   Java API By Example, From Geeks To Geeks.

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


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

38
39 public class ThrowStmt extends Stmt {
40
41     public void unparse(CodeWriter writer) {
42         writer.writeKeyword("throw");
43         writer.requiredSpace();
44         writer.write(expr);
45         writer.closeStmt();
46     }
47
48     public void checkSpec() {
49         getExpr().assertType(getTypeManager().getThrowableType());
50     }
51
52     // ------------------------------
53
// INTRO from FlowCheckerPass
54

55     public void walkFlow(FlowCheckerPass w) {
56         w.process(getExpr());
57         w.doReturn();
58         w.setLive(false);
59         w.setExns(w.getExns().add((NameType) expr.getType()));
60         w.setVars(w.getAllVars());
61     }
62
63     // ------------------------------
64
// INTRO from ByteCodeCleanupPass
65

66     public void walkCleanup(ByteCodeCleanupPass w) {
67         w.setLive(false);
68     }
69
70     // ------------------------------
71
// bcg
72

73     protected void cgStmt(CodeBuilder cb) {
74         expr.cgValue(cb);
75         cb.emitATHROW();
76     }
77
78     //BEGIN: Generated from @child and @property
79
protected Expr expr;
80     public Expr getExpr() { return expr; }
81     public void setExpr(Expr _expr) {
82         if (_expr != null) _expr.setParent(this);
83         expr = _expr;
84     }
85
86     public ThrowStmt(SourceLocation location, Expr _expr) {
87         super(location);
88         setExpr(_expr);
89     }
90     protected ThrowStmt(SourceLocation source) {
91         super(source);
92     }
93
94     public ASTObject copyWalk(CopyWalker walker) {
95         ThrowStmt ret = new ThrowStmt(getSourceLocation());
96         ret.preCopy(walker, this);
97         if (expr != null) ret.setExpr( (Expr)walker.process(expr) );
98         return ret;
99     }
100
101     public ASTObject getChildAt(int childIndex) {
102         switch(childIndex) {
103         case 0: return expr;
104         default: return super.getChildAt(childIndex);
105         }
106     }
107      public String JavaDoc getChildNameAt(int childIndex) {
108         switch(childIndex) {
109         case 0: return "expr";
110         default: return super.getChildNameAt(childIndex);
111         }
112     }
113      public void setChildAt(int childIndex, ASTObject child) {
114         switch(childIndex) {
115         case 0: setExpr((Expr)child); return;
116         default: super.setChildAt(childIndex, child); return;
117         }
118     }
119      public int getChildCount() {
120         return 1;
121     }
122
123     public String JavaDoc getDefaultDisplayName() {
124         return "ThrowStmt()";
125     }
126
127     //END: Generated from @child and @property
128
}
129
130
131
Popular Tags