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.impl.*;
14 import net.sourceforge.phpdt.internal.compiler.lookup.*;
15 import net.sourceforge.phpdt.internal.compiler.IAbstractSyntaxTreeVisitor;
17 public abstract class AstNode implements BaseTypes, CompilerModifiers, TypeConstants, TypeIds {
19 public int sourceStart, sourceEnd;
21 //some global provision for the hierarchy
22 public final static Constant NotAConstant = Constant.NotAConstant;
24 // storage for internal flags (32 bits)
25 public int bits = IsReachableMASK; // reachable by default
28 // Reach . . . . . . . . . . . . . . . . . O O O O O O V VrR R R R
29 public static final int ReturnTypeIDMASK = 15; // 4 lower bits for operators
30 public static final int ValueForReturnMASK = 16; // for binary expressions
31 public static final int OnlyValueRequiredMASK = 32; // for binary expressions
32 public static final int OperatorSHIFT = 6;
33 public static final int OperatorMASK = 63 << OperatorSHIFT;
35 // for name references only
36 // Reach . . . . . . . . . . . . . . . . D D D D D D D D VrF R R R
37 public static final int RestrictiveFlagMASK = 7;
38 // 3 lower bits for name references
39 public static final int FirstAssignmentToLocalMASK = 8;
40 // for single name references
41 public static final int DepthSHIFT = 5;
42 public static final int DepthMASK = 0xFF << DepthSHIFT;
43 // 8 bits for actual depth value (max. 255)
45 // for statements only
46 public static final int IsReachableMASK = 0x80000000; // highest bit
47 public static final int IsLocalDeclarationReachableMASK = 0x40000000; // below highest bit
49 // for type declaration only
50 public static final int AddAssertionMASK = 1; // lowest bit
52 // for type, method and field declarations only
53 public static final int HasLocalTypeMASK = 2;
54 // cannot conflict with AddAssertionMASK
57 public final static int BitMask1= 0x1; // decimal 1
58 public final static int BitMask2= 0x2; // decimal 2
59 public final static int BitMask3= 0x4; // decimal 4
60 public final static int BitMask4= 0x8; // decimal 8
61 public final static int BitMask5= 0x10; // decimal 16
62 public final static int BitMask6= 0x20; // decimal 32
63 public final static int BitMask7= 0x40; // decimal 64
64 public final static int BitMask8= 0x80; // decimal 128
65 public final static int BitMask9= 0x100; // decimal 256
66 public final static int BitMask10= 0x200; // decimal 512
67 public final static int BitMask11= 0x400; // decimal 1024
68 public final static int BitMask12= 0x800; // decimal 2048
69 public final static int BitMask13= 0x1000; // decimal 4096
70 public final static int BitMask14= 0x2000; // decimal 8192
71 public final static int BitMask15= 0x4000; // decimal 16384
72 public final static int BitMask16= 0x8000; // decimal 32768
73 public final static int BitMask17= 0x10000; // decimal 65536
74 public final static int BitMask18= 0x20000; // decimal 131072
75 public final static int BitMask19= 0x40000; // decimal 262144
76 public final static int BitMask20= 0x80000; // decimal 524288
77 public final static int BitMask21= 0x100000; // decimal 1048576
78 public final static int BitMask22= 0x200000; // decimal 2097152
79 public final static int BitMask23= 0x400000; // decimal 4194304
80 public final static int BitMask24= 0x800000; // decimal 8388608
81 public final static int BitMask25= 0x1000000; // decimal 16777216
82 public final static int BitMask26= 0x2000000; // decimal 33554432
83 public final static int BitMask27= 0x4000000; // decimal 67108864
84 public final static int BitMask28= 0x8000000; // decimal 134217728
85 public final static int BitMask29= 0x10000000; // decimal 268435456
86 public final static int BitMask30= 0x20000000; // decimal 536870912
87 public final static int BitMask31= 0x40000000; // decimal 1073741824
88 public final static int BitMask32= 0x80000000; // decimal 2147483648
92 * AstNode constructor comment.
99 public boolean cannotReturn() {
103 public AstNode concreteStatement() {
107 /* Answer true if the field use is considered deprecated.
108 * An access in the same compilation unit is allowed.
110 public final boolean isFieldUseDeprecated(FieldBinding field, Scope scope) {
112 return field.isViewedAsDeprecated()
113 && !scope.isDefinedInSameUnit(field.declaringClass);
116 /* Answer true if the method use is considered deprecated.
117 * An access in the same compilation unit is allowed.
119 public final boolean isMethodUseDeprecated(MethodBinding method, Scope scope) {
120 return method.isViewedAsDeprecated()
121 && !scope.isDefinedInSameUnit(method.declaringClass);
124 public boolean isSuper() {
129 public boolean isThis() {
134 /* Answer true if the type use is considered deprecated.
135 * An access in the same compilation unit is allowed.
137 public final boolean isTypeUseDeprecated(TypeBinding type, Scope scope) {
139 if (type.isArrayType())
140 type = ((ArrayBinding) type).leafComponentType;
141 if (type.isBaseType())
144 ReferenceBinding refType = (ReferenceBinding) type;
145 return refType.isViewedAsDeprecated() && !scope.isDefinedInSameUnit(refType);
148 public static String modifiersString(int modifiers) {
150 String s = ""; //$NON-NLS-1$
151 if ((modifiers & AccPublic) != 0)
152 s = s + "public "; //$NON-NLS-1$
153 if ((modifiers & AccPrivate) != 0)
154 s = s + "private "; //$NON-NLS-1$
155 if ((modifiers & AccProtected) != 0)
156 s = s + "protected "; //$NON-NLS-1$
157 if ((modifiers & AccStatic) != 0)
158 s = s + "static "; //$NON-NLS-1$
159 if ((modifiers & AccFinal) != 0)
160 s = s + "final "; //$NON-NLS-1$
161 if ((modifiers & AccSynchronized) != 0)
162 s = s + "synchronized "; //$NON-NLS-1$
163 if ((modifiers & AccVolatile) != 0)
164 s = s + "volatile "; //$NON-NLS-1$
165 if ((modifiers & AccTransient) != 0)
166 s = s + "transient "; //$NON-NLS-1$
167 if ((modifiers & AccNative) != 0)
168 s = s + "native "; //$NON-NLS-1$
169 if ((modifiers & AccAbstract) != 0)
170 s = s + "abstract "; //$NON-NLS-1$
175 * @deprecated - use field instead
177 public int sourceEnd() {
182 * @deprecated - use field instead
184 public int sourceStart() {
188 public static String tabString(int tab) {
190 String s = ""; //$NON-NLS-1$
191 for (int i = tab; i > 0; i--)
192 s = s + " "; //$NON-NLS-1$
196 public String toString() {
201 public String toString(int tab) {
203 return "****" + super.toString() + "****"; //$NON-NLS-2$ //$NON-NLS-1$
206 public void traverse(IAbstractSyntaxTreeVisitor visitor, BlockScope scope) {