1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.ast;
13 import net.sourceforge.phpdt.internal.compiler.ASTVisitor;
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,
28 TypeConstants, TypeIds {
30 public int sourceStart, sourceEnd;
32 // some global provision for the hierarchy
33 public final static Constant NotAConstant = Constant.NotAConstant;
35 // storage for internal flags (32 bits) BIT USAGE
36 public final static int Bit1 = 0x1; // return type (operators) | name
37 // reference kind (name ref) | add
38 // assertion (type decl)
40 public final static int Bit2 = 0x2; // return type (operators) | name
41 // reference kind (name ref) | has local
42 // type (type, method, field decl)
44 public final static int Bit3 = 0x4; // return type (operators) | name
45 // reference kind (name ref) | implicit
48 public final static int Bit4 = 0x8; // return type (operators) | first
49 // assignment to local (local decl)
51 public final static int Bit5 = 0x10; // value for return (binary
54 public final static int Bit6 = 0x20; // depth (name ref, msg) | only
55 // value required (binary
58 public final static int Bit7 = 0x40; // depth (name ref, msg) | operator
61 public final static int Bit8 = 0x80; // depth (name ref, msg) | operator
64 public final static int Bit9 = 0x100; // depth (name ref, msg) | operator
67 public final static int Bit10 = 0x200; // depth (name ref, msg) | operator
70 public final static int Bit11 = 0x400; // depth (name ref, msg) | operator
73 public final static int Bit12 = 0x800; // depth (name ref, msg) | operator
76 public final static int Bit13 = 0x1000; // depth (name ref, msg)
78 public final static int Bit14 = 0x2000; // assigned (reference lhs)
80 public final static int Bit15 = 0x4000;
82 public final static int Bit16 = 0x8000;
84 public final static int Bit17 = 0x10000;
86 public final static int Bit18 = 0x20000;
88 public final static int Bit19 = 0x40000;
90 public final static int Bit20 = 0x80000;
92 public final static int Bit21 = 0x100000;
94 public final static int Bit22 = 0x200000; // parenthesis count
97 public final static int Bit23 = 0x400000; // parenthesis count
100 public final static int Bit24 = 0x800000; // parenthesis count
103 public final static int Bit25 = 0x1000000; // parenthesis count
106 public final static int Bit26 = 0x2000000; // parenthesis count
109 public final static int Bit27 = 0x4000000; // parenthesis count
112 public final static int Bit28 = 0x8000000; // parenthesis count
115 public final static int Bit29 = 0x10000000; // parenthesis count
118 public final static int Bit30 = 0x20000000; // assignment with no effect
121 public final static int Bit31 = 0x40000000; // local declaration reachable
124 public final static int Bit32 = 0x80000000; // reachable (statement)
126 public int bits = IsReachableMASK; // reachable by default
129 public static final int ReturnTypeIDMASK = Bit1 | Bit2 | Bit3 | Bit4;
131 public static final int OperatorSHIFT = 6; // Bit7 -> Bit12
133 public static final int OperatorMASK = Bit7 | Bit8 | Bit9 | Bit10 | Bit11
134 | Bit12; // 6 bits for operator ID
136 // for binary expressions
137 public static final int ValueForReturnMASK = Bit5;
139 public static final int OnlyValueRequiredMASK = Bit6;
141 // for name references
142 public static final int RestrictiveFlagMASK = Bit1 | Bit2 | Bit3;
144 public static final int FirstAssignmentToLocalMASK = Bit4;
146 // for this reference
147 public static final int IsImplicitThisMask = Bit3;
149 // for single name references
150 public static final int DepthSHIFT = 5; // Bit6 -> Bit13
152 public static final int DepthMASK = Bit6 | Bit7 | Bit8 | Bit9 | Bit10
153 | Bit11 | Bit12 | Bit13; // 8 bits for actual depth value (max.
157 public static final int IsReachableMASK = Bit32;
159 public static final int IsLocalDeclarationReachableMASK = Bit31;
161 // for type declaration
162 public static final int AddAssertionMASK = Bit1;
164 public static final int IsMemberTypeMASK = Bit11; // local member do not
165 // know it is local at
166 // parse time (need to
169 // for type, method and field declarations
170 public static final int HasLocalTypeMASK = Bit2; // cannot conflict with
174 public static final int ParenthesizedSHIFT = 21; // Bit22 -> Bit29
176 public static final int ParenthesizedMASK = Bit22 | Bit23 | Bit24 | Bit25
177 | Bit26 | Bit27 | Bit28 | Bit29; // 8 bits for parenthesis count
181 public static final int IsAssignmentWithNoEffectMASK = Bit30;
183 // for references on lhs of assignment (set only for true assignments, as
184 // opposed to compound ones)
185 public static final int IsStrictlyAssignedMASK = Bit14;
187 public static final int IsCompoundAssignedMASK = Bit17; // set only for
193 // for empty statement
194 public static final int IsUsefulEmptyStatementMASK = Bit1;
196 // for block and method declaration
197 public static final int UndocumentedEmptyBlockMASK = Bit4;
199 // for compilation unit
200 public static final int HasAllMethodBodies = Bit5;
202 // for references in Javadoc comments
203 public static final int InsideJavadoc = Bit16;
206 public static final int IsElseIfStatement = Bit30;
213 public boolean cannotReturn() {
217 public ASTNode concreteStatement() {
222 * Answer true if the field use is considered deprecated. An access in the
223 * same compilation unit is allowed.
225 public final boolean isFieldUseDeprecated(FieldBinding field, Scope scope) {
227 if (field.isPrivate() && !scope.isDefinedInField(field)) {
228 // ignore cases where field is used from within inside itself
229 field.modifiers |= AccPrivateUsed;
232 if (!field.isViewedAsDeprecated())
235 // inside same unit - no report
236 if (scope.isDefinedInSameUnit(field.declaringClass))
239 // if context is deprecated, may avoid reporting
241 // (!scope.environment().options.reportDeprecationInsideDeprecatedCode
242 // && scope.isInsideDeprecatedCode()) return false;
246 public boolean isImplicitThis() {
252 * Answer true if the method use is considered deprecated. An access in the
253 * same compilation unit is allowed.
255 public final boolean isMethodUseDeprecated(MethodBinding method, Scope scope) {
257 if (method.isPrivate() && !scope.isDefinedInMethod(method)) {
258 // ignore cases where method is used from within inside itself (e.g.
259 // direct recursions)
260 method.modifiers |= AccPrivateUsed;
263 if (!method.isViewedAsDeprecated())
266 // inside same unit - no report
267 if (scope.isDefinedInSameUnit(method.declaringClass))
270 // if context is deprecated, may avoid reporting
272 // (!scope.environment().options.reportDeprecationInsideDeprecatedCode
273 // && scope.isInsideDeprecatedCode()) return false;
277 public boolean isSuper() {
282 public boolean isThis() {
288 * Answer true if the type use is considered deprecated. An access in the
289 * same compilation unit is allowed.
291 public final boolean isTypeUseDeprecated(TypeBinding type, Scope scope) {
293 if (type.isArrayType())
294 type = ((ArrayBinding) type).leafComponentType;
295 if (type.isBaseType())
298 ReferenceBinding refType = (ReferenceBinding) type;
300 if (refType.isPrivate() && !scope.isDefinedInType(refType)) {
301 // ignore cases where type is used from within inside itself
302 refType.modifiers |= AccPrivateUsed;
305 if (!refType.isViewedAsDeprecated())
308 // inside same unit - no report
309 if (scope.isDefinedInSameUnit(refType))
312 // if context is deprecated, may avoid reporting
314 // (!scope.environment().options.reportDeprecationInsideDeprecatedCode
315 // && scope.isInsideDeprecatedCode()) return false;
319 public static String modifiersString(int modifiers) {
321 String s = ""; //$NON-NLS-1$
322 if ((modifiers & AccPublic) != 0)
323 s = s + "public "; //$NON-NLS-1$
324 if ((modifiers & AccPrivate) != 0)
325 s = s + "private "; //$NON-NLS-1$
326 if ((modifiers & AccProtected) != 0)
327 s = s + "protected "; //$NON-NLS-1$
328 if ((modifiers & AccStatic) != 0)
329 s = s + "static "; //$NON-NLS-1$
330 if ((modifiers & AccFinal) != 0)
331 s = s + "final "; //$NON-NLS-1$
332 // if ((modifiers & AccSynchronized) != 0)
333 // s = s + "synchronized "; //$NON-NLS-1$
334 // if ((modifiers & AccVolatile) != 0)
335 // s = s + "volatile "; //$NON-NLS-1$
336 // if ((modifiers & AccTransient) != 0)
337 // s = s + "transient "; //$NON-NLS-1$
338 // if ((modifiers & AccNative) != 0)
339 // s = s + "native "; //$NON-NLS-1$
340 if ((modifiers & AccAbstract) != 0)
341 s = s + "abstract "; //$NON-NLS-1$
345 public abstract StringBuffer print(int indent, StringBuffer output);
347 public static StringBuffer printIndent(int indent, StringBuffer output) {
349 for (int i = indent; i > 0; i--)
350 output.append(" "); //$NON-NLS-1$
354 public static StringBuffer printModifiers(int modifiers, StringBuffer output) {
356 if ((modifiers & AccPublic) != 0)
357 output.append("public "); //$NON-NLS-1$
358 if ((modifiers & AccPrivate) != 0)
359 output.append("private "); //$NON-NLS-1$
360 if ((modifiers & AccProtected) != 0)
361 output.append("protected "); //$NON-NLS-1$
362 if ((modifiers & AccStatic) != 0)
363 output.append("static "); //$NON-NLS-1$
364 if ((modifiers & AccFinal) != 0)
365 output.append("final "); //$NON-NLS-1$
366 // if ((modifiers & AccSynchronized) != 0)
367 // output.append("synchronized "); //$NON-NLS-1$
368 // if ((modifiers & AccVolatile) != 0)
369 // output.append("volatile "); //$NON-NLS-1$
370 // if ((modifiers & AccTransient) != 0)
371 // output.append("transient "); //$NON-NLS-1$
372 // if ((modifiers & AccNative) != 0)
373 // output.append("native "); //$NON-NLS-1$
374 if ((modifiers & AccAbstract) != 0)
375 output.append("abstract "); //$NON-NLS-1$
380 * @deprecated - use field instead
382 public int sourceEnd() {
387 * @deprecated - use field instead
389 public int sourceStart() {
393 public static String tabString(int tab) {
395 String s = ""; //$NON-NLS-1$
396 for (int i = tab; i > 0; i--)
397 s = s + " "; //$NON-NLS-1$
401 public String toString() {
406 public String toString(int tab) {
408 return "****" + super.toString() + "****"; //$NON-NLS-2$ //$NON-NLS-1$
411 public void traverse(ASTVisitor visitor, BlockScope scope) {