KickJava   Java API By Example, From Geeks To Geeks.

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


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.FlowCheckerPass;
28 import org.aspectj.compiler.base.JavaCompiler;
29 import org.aspectj.compiler.base.CodeWriter;
30 import java.io.IOException JavaDoc;
31
32 import java.util.*;
33
34 import org.aspectj.compiler.base.bcg.CodeBuilder;
35 import org.aspectj.compiler.base.bcg.Label;
36
37 /**
38  * Exprs (ArrayInitializer?), Stmts, Decs, NameTypeDs, Formals
39  * @grammar (expr, )* expr
40  * @children Expr expr
41  */

42
43 public class Exprs extends Expr {
44
45     public Type discoverType() {
46         return getTypeManager().voidType;
47     }
48
49     public Exprs(SourceLocation source, int n) {
50         this(source,new Expr[n]);
51     }
52
53     public void unparse(CodeWriter writer) throws IOException JavaDoc {
54         writer.writeChildrenWithCommas(this);
55     }
56
57     // ------------------------------
58
// bcg
59

60     void cgValues(CodeBuilder cb, Formals fs) {
61         for (int i = 0, len = size; i < len; i++) {
62             children[i].cgValue(cb, fs.get(i).getType());
63         }
64     }
65     void cgEffects(CodeBuilder cb) {
66         for (int i = 0, len = size; i < len; i++) {
67             children[i].cgEffect(cb);
68         }
69     }
70
71     //BEGIN: Generated from @child and @property
72
protected int size;
73     public Expr[] children;
74
75     public Exprs(SourceLocation location, Expr[] _children) {
76         super(location);
77         for(int i=0; i<_children.length; i++) {
78             if (_children[i] != null) _children[i].setParent(this);
79         }
80         children = _children;
81         size = _children.length;
82     }
83
84     public Exprs(SourceLocation location) {
85         this(location, new Expr[] {});
86     }
87
88     public Exprs(SourceLocation location, Expr child1) {
89         this(location, new Expr[] {child1});
90     }
91
92     public Exprs(SourceLocation location, Expr child1, Expr child2) {
93         this(location, new Expr[] {child1, child2});
94     }
95
96     public Exprs(SourceLocation location, Expr child1, Expr child2, Expr child3) {
97         this(location, new Expr[] {child1, child2, child3});
98     }
99
100     public ASTObject copyWalk(CopyWalker walker) {
101         final int N = size;
102         Expr[] copiedChildren = new Expr[N];
103         int newIndex = 0;
104         for(int oldIndex=0; oldIndex<N; oldIndex++) {
105             Expr newChild = (Expr)walker.process(children[oldIndex]);
106             if (newChild != null) copiedChildren[newIndex++] = newChild;
107         }
108         Exprs ret = new Exprs(getSourceLocation(),copiedChildren);
109         ret.size = newIndex;
110         ret.setSource(this);
111         return ret;
112     }
113
114     public ASTObject getChildAt(int childIndex) { return get(childIndex); }
115     public void setChildAt(int childIndex, ASTObject child) { set(childIndex, (Expr)child); }
116     public String JavaDoc getChildNameAt(int childIndex) { return "expr"+childIndex; }
117
118     public int getChildCount() { return size; }
119     public int size() { return size; }
120
121     public Expr get(int index) {
122         if (index >= size) throw new ArrayIndexOutOfBoundsException JavaDoc();
123         return children[index];
124     }
125
126     public void set(int index, Expr child) {
127         if (index >= size) throw new ArrayIndexOutOfBoundsException JavaDoc();
128         children[index] = child;
129         child.setParent(this);
130     }
131
132     public void resize(int newSize) {
133         if (newSize > children.length) {
134             Expr[] newChildren = new Expr[children.length*2 + 1];
135             System.arraycopy(children, 0, newChildren, 0, children.length);
136             children = newChildren;
137         }
138         size = newSize;
139     }
140
141     public void addAll(Exprs collection) {
142         addAll(size, collection);
143     }
144
145     public void addAll(int index, Exprs collection) {
146         for(int i=0; i<collection.size(); i++) {
147             add(index+i, collection.get(i));
148         }
149     }
150
151     public void add(Expr child) {
152         add(size, child);
153     }
154
155     public void add(int index, Expr child) {
156         if (child == null) return;
157
158         if (index < 0 || index > size) throw new ArrayIndexOutOfBoundsException JavaDoc();
159
160         resize(size+1);
161
162         for(int moveIndex = size-1; moveIndex > index; moveIndex--) {
163             children[moveIndex] = children[moveIndex-1];
164         }
165
166         children[index] = child;
167         child.setParent(this);
168     }
169
170     public void remove(int index) {
171         if (index < 0 || index > size) throw new ArrayIndexOutOfBoundsException JavaDoc();
172
173         size -= 1;
174
175         for(int moveIndex = index; moveIndex < size; moveIndex++) {
176             children[moveIndex] = children[moveIndex+1];
177         }
178     }
179
180     public String JavaDoc getDefaultDisplayName() {
181         return "Exprs()";
182     }
183
184     //END: Generated from @child and @property
185
}
186
Popular Tags