KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > compiler > base > ByteCodeCleanupPass


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;
26
27 import org.aspectj.compiler.base.ast.*;
28 import org.aspectj.compiler.base.*;
29
30 import java.util.*;
31
32 /** This pass is responsible for removing dead and/or useless code
33     from the AST. As such, it includes some control-related stuff
34     otherwise found in the flow-related passes. It should signal no
35     errors.
36 */

37
38 public class ByteCodeCleanupPass extends WalkerPass {
39     public ByteCodeCleanupPass(JavaCompiler compiler) {
40         super(compiler);
41     }
42
43     public String JavaDoc getDisplayName() {
44         return "clean up ast";
45     }
46
47     public ASTObject process(ASTObject object) {
48         object.walkCleanup(this);
49         ASTObject ret = object.postCleanup(this);
50         if (ret instanceof Stmt) {
51             ((Stmt)ret).setCompletesNormally(isLive());
52         }
53         return ret;
54     }
55
56     private boolean liveFlag = true;
57     public void setLive(boolean b) { liveFlag = b; }
58     public boolean isLive() { return liveFlag; }
59
60     // ------------------------------
61
private ControlContext context = new ControlContext();
62     
63     public void enterContext(Stmt s) { context.enter(s); }
64     public void leaveContext() { context.exit(); }
65
66     public void doBreak(String JavaDoc label) {
67         breaks.add(context.getBreakTarget(label));
68     }
69
70     public void doContinue(String JavaDoc label) {
71         continues.add(context.getContinueTarget(label));
72     }
73
74     private Set breaks = new HashSet();
75     private Set continues = new HashSet();
76
77     public boolean isBroken(Stmt s) { return breaks.contains(s); }
78     public boolean isContinued(Stmt s) { return continues.contains(s); }
79 }
80
Popular Tags