1 /*******************************************************************************
2 * Copyright (c) 2000, 2001, 2002 International Business Machines Corp. and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v0.5
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v05.html
9 * IBM Corporation - initial API and implementation
10 ******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.ast;
13 import net.sourceforge.phpdt.internal.compiler.IAbstractSyntaxTreeVisitor;
14 import net.sourceforge.phpdt.internal.compiler.impl.Constant;
15 import net.sourceforge.phpdt.internal.compiler.lookup.ArrayBinding;
16 import net.sourceforge.phpdt.internal.compiler.lookup.BaseTypes;
17 import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope;
18 import net.sourceforge.phpdt.internal.compiler.lookup.CompilerModifiers;
19 import net.sourceforge.phpdt.internal.compiler.lookup.FieldBinding;
20 import net.sourceforge.phpdt.internal.compiler.lookup.MethodBinding;
21 import net.sourceforge.phpdt.internal.compiler.lookup.ReferenceBinding;
22 import net.sourceforge.phpdt.internal.compiler.lookup.Scope;
23 import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding;
24 import net.sourceforge.phpdt.internal.compiler.lookup.TypeConstants;
25 import net.sourceforge.phpdt.internal.compiler.lookup.TypeIds;
27 public abstract class AstNode implements BaseTypes, CompilerModifiers, TypeConstants, TypeIds {
29 public int sourceStart, sourceEnd;
31 //some global provision for the hierarchy
32 public final static Constant NotAConstant = Constant.NotAConstant;
34 // storage for internal flags (32 bits)
35 public int bits = IsReachableMASK; // reachable by default
38 // Reach . . . . . . . . . . . . . . . . . O O O O O O V VrR R R R
39 public static final int ReturnTypeIDMASK = 15; // 4 lower bits for operators
40 public static final int ValueForReturnMASK = 16; // for binary expressions
41 public static final int OnlyValueRequiredMASK = 32; // for binary expressions
42 public static final int OperatorSHIFT = 6;
43 public static final int OperatorMASK = 63 << OperatorSHIFT;
45 // for name references only
46 // Reach . . . . . . . . . . . . . . . . D D D D D D D D VrF R R R
47 public static final int RestrictiveFlagMASK = 7;
48 // 3 lower bits for name references
49 public static final int FirstAssignmentToLocalMASK = 8;
50 // for single name references
51 public static final int DepthSHIFT = 5;
52 public static final int DepthMASK = 0xFF << DepthSHIFT;
53 // 8 bits for actual depth value (max. 255)
55 // for statements only
56 public static final int IsReachableMASK = 0x80000000; // highest bit
57 public static final int IsLocalDeclarationReachableMASK = 0x40000000; // below highest bit
59 // for type declaration only
60 public static final int AddAssertionMASK = 1; // lowest bit
62 // for type, method and field declarations only
63 public static final int HasLocalTypeMASK = 2;
64 // cannot conflict with AddAssertionMASK
67 public final static int BitMask1= 0x1; // decimal 1
68 public final static int BitMask2= 0x2; // decimal 2
69 public final static int BitMask3= 0x4; // decimal 4
70 public final static int BitMask4= 0x8; // decimal 8
71 public final static int BitMask5= 0x10; // decimal 16
72 public final static int BitMask6= 0x20; // decimal 32
73 public final static int BitMask7= 0x40; // decimal 64
74 public final static int BitMask8= 0x80; // decimal 128
75 public final static int BitMask9= 0x100; // decimal 256
76 public final static int BitMask10= 0x200; // decimal 512
77 public final static int BitMask11= 0x400; // decimal 1024
78 public final static int BitMask12= 0x800; // decimal 2048
79 public final static int BitMask13= 0x1000; // decimal 4096
80 public final static int BitMask14= 0x2000; // decimal 8192
81 public final static int BitMask15= 0x4000; // decimal 16384
82 public final static int BitMask16= 0x8000; // decimal 32768
83 public final static int BitMask17= 0x10000; // decimal 65536
84 public final static int BitMask18= 0x20000; // decimal 131072
85 public final static int BitMask19= 0x40000; // decimal 262144
86 public final static int BitMask20= 0x80000; // decimal 524288
87 public final static int BitMask21= 0x100000; // decimal 1048576
88 public final static int BitMask22= 0x200000; // decimal 2097152
89 public final static int BitMask23= 0x400000; // decimal 4194304
90 public final static int BitMask24= 0x800000; // decimal 8388608
91 public final static int BitMask25= 0x1000000; // decimal 16777216
92 public final static int BitMask26= 0x2000000; // decimal 33554432
93 public final static int BitMask27= 0x4000000; // decimal 67108864
94 public final static int BitMask28= 0x8000000; // decimal 134217728
95 public final static int BitMask29= 0x10000000; // decimal 268435456
96 public final static int BitMask30= 0x20000000; // decimal 536870912
97 public final static int BitMask31= 0x40000000; // decimal 1073741824
98 public final static int BitMask32= 0x80000000; // decimal 2147483648
102 * AstNode constructor comment.
109 public boolean cannotReturn() {
113 public AstNode concreteStatement() {
117 /* Answer true if the field use is considered deprecated.
118 * An access in the same compilation unit is allowed.
120 public final boolean isFieldUseDeprecated(FieldBinding field, Scope scope) {
122 return field.isViewedAsDeprecated()
123 && !scope.isDefinedInSameUnit(field.declaringClass);
126 /* Answer true if the method use is considered deprecated.
127 * An access in the same compilation unit is allowed.
129 public final boolean isMethodUseDeprecated(MethodBinding method, Scope scope) {
130 return method.isViewedAsDeprecated()
131 && !scope.isDefinedInSameUnit(method.declaringClass);
134 public boolean isSuper() {
139 public boolean isThis() {
144 /* Answer true if the type use is considered deprecated.
145 * An access in the same compilation unit is allowed.
147 public final boolean isTypeUseDeprecated(TypeBinding type, Scope scope) {
149 if (type.isArrayType())
150 type = ((ArrayBinding) type).leafComponentType;
151 if (type.isBaseType())
154 ReferenceBinding refType = (ReferenceBinding) type;
155 return refType.isViewedAsDeprecated() && !scope.isDefinedInSameUnit(refType);
158 public static String modifiersString(int modifiers) {
160 String s = ""; //$NON-NLS-1$
161 if ((modifiers & AccPublic) != 0)
162 s = s + "public "; //$NON-NLS-1$
163 if ((modifiers & AccPrivate) != 0)
164 s = s + "private "; //$NON-NLS-1$
165 if ((modifiers & AccProtected) != 0)
166 s = s + "protected "; //$NON-NLS-1$
167 if ((modifiers & AccStatic) != 0)
168 s = s + "static "; //$NON-NLS-1$
169 if ((modifiers & AccFinal) != 0)
170 s = s + "final "; //$NON-NLS-1$
171 if ((modifiers & AccSynchronized) != 0)
172 s = s + "synchronized "; //$NON-NLS-1$
173 if ((modifiers & AccVolatile) != 0)
174 s = s + "volatile "; //$NON-NLS-1$
175 if ((modifiers & AccTransient) != 0)
176 s = s + "transient "; //$NON-NLS-1$
177 if ((modifiers & AccNative) != 0)
178 s = s + "native "; //$NON-NLS-1$
179 if ((modifiers & AccAbstract) != 0)
180 s = s + "abstract "; //$NON-NLS-1$
185 * @deprecated - use field instead
187 public int sourceEnd() {
192 * @deprecated - use field instead
194 public int sourceStart() {
198 public static String tabString(int tab) {
200 String s = ""; //$NON-NLS-1$
201 for (int i = tab; i > 0; i--)
202 s = s + " "; //$NON-NLS-1$
206 public String toString() {
211 public String toString(int tab) {
213 return "****" + super.toString() + "****"; //$NON-NLS-2$ //$NON-NLS-1$
216 public void traverse(IAbstractSyntaxTreeVisitor visitor, BlockScope scope) {