KickJava   Java API By Example, From Geeks To Geeks.

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


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.cst.*;
29
30 /**
31   * @grammar ...
32   * @child Expr value
33   * @child VarDec tmpDec
34   */

35 public class ReferenceExpr extends Expr {
36     public Type discoverType() { return value.getType(); }
37
38     public ReferenceExpr(SourceLocation source, Expr value) {
39         this(source, value, new VarDec(source, value.getType().makeTypeD(), "tmp", null));
40     }
41
42     public Expr makeReference() {
43         return getAST().makeVar(tmpDec);
44     }
45
46     public VarDec makeVarDec() {
47         tmpDec.getModifiers().setFinal(true);
48         tmpDec.setInitializer(value);
49         return tmpDec;
50     }
51
52     // ------------------------------
53
// INTRO from FlowCheckerPass
54

55     public void walkFlow(FlowCheckerPass w) {
56         throw new RuntimeException JavaDoc("Unhandled reference expr");
57     }
58
59     // INTRO from ASTFixerPass
60
public ASTObject postFixAST(final ASTFixerPass fixer) {
61         BlockStmt body = getEnclosingCodeDec().getBody();
62         body.addTemporary(tmpDec); // this will screw up the walker...
63
return getAST().makeParen(getAST().makeSet(tmpDec, value));
64     }
65
66     //BEGIN: Generated from @child and @property
67
protected Expr value;
68     public Expr getValue() { return value; }
69     public void setValue(Expr _value) {
70         if (_value != null) _value.setParent(this);
71         value = _value;
72     }
73
74     protected VarDec tmpDec;
75     public VarDec getTmpDec() { return tmpDec; }
76     public void setTmpDec(VarDec _tmpDec) {
77         if (_tmpDec != null) _tmpDec.setParent(this);
78         tmpDec = _tmpDec;
79     }
80
81     public ReferenceExpr(SourceLocation location, Expr _value, VarDec _tmpDec) {
82         super(location);
83         setValue(_value);
84         setTmpDec(_tmpDec);
85     }
86     protected ReferenceExpr(SourceLocation source) {
87         super(source);
88     }
89
90     public ASTObject copyWalk(CopyWalker walker) {
91         ReferenceExpr ret = new ReferenceExpr(getSourceLocation());
92         ret.preCopy(walker, this);
93         if (value != null) ret.setValue( (Expr)walker.process(value) );
94         if (tmpDec != null) ret.setTmpDec( (VarDec)walker.process(tmpDec) );
95         return ret;
96     }
97
98     public ASTObject getChildAt(int childIndex) {
99         switch(childIndex) {
100         case 0: return value;
101         case 1: return tmpDec;
102         default: return super.getChildAt(childIndex);
103         }
104     }
105      public String JavaDoc getChildNameAt(int childIndex) {
106         switch(childIndex) {
107         case 0: return "value";
108         case 1: return "tmpDec";
109         default: return super.getChildNameAt(childIndex);
110         }
111     }
112      public void setChildAt(int childIndex, ASTObject child) {
113         switch(childIndex) {
114         case 0: setValue((Expr)child); return;
115         case 1: setTmpDec((VarDec)child); return;
116         default: super.setChildAt(childIndex, child); return;
117         }
118     }
119      public int getChildCount() {
120         return 2;
121     }
122
123     public String JavaDoc getDefaultDisplayName() {
124         return "ReferenceExpr()";
125     }
126
127     //END: Generated from @child and @property
128
}
129
Popular Tags