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.phpeclipse.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;
28 public abstract class ASTNode implements BaseTypes, CompilerModifiers, 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 reference kind (name ref) | add assertion (type decl)
37 public final static int Bit2 = 0x2; // return type (operators) | name reference kind (name ref) | has local type (type, method, field decl)
38 public final static int Bit3 = 0x4; // return type (operators) | name reference kind (name ref) | implicit this (this ref)
39 public final static int Bit4 = 0x8; // return type (operators) | first assignment to local (local decl)
40 public final static int Bit5 = 0x10; // value for return (binary expression) |
41 public final static int Bit6 = 0x20; // depth (name ref, msg) | only value required (binary expression)
42 public final static int Bit7 = 0x40; // depth (name ref, msg) | operator (operators)
43 public final static int Bit8 = 0x80; // depth (name ref, msg) | operator (operators)
44 public final static int Bit9 = 0x100; // depth (name ref, msg) | operator (operators)
45 public final static int Bit10= 0x200; // depth (name ref, msg) | operator (operators)
46 public final static int Bit11 = 0x400; // depth (name ref, msg) | operator (operators)
47 public final static int Bit12 = 0x800; // depth (name ref, msg) | operator (operators)
48 public final static int Bit13 = 0x1000; // depth (name ref, msg)
49 public final static int Bit14 = 0x2000; // assigned (reference lhs)
50 public final static int Bit15 = 0x4000;
51 public final static int Bit16 = 0x8000;
52 public final static int Bit17 = 0x10000;
53 public final static int Bit18 = 0x20000;
54 public final static int Bit19 = 0x40000;
55 public final static int Bit20 = 0x80000;
56 public final static int Bit21 = 0x100000;
57 public final static int Bit22 = 0x200000; // parenthesis count (expression)
58 public final static int Bit23 = 0x400000; // parenthesis count (expression)
59 public final static int Bit24 = 0x800000; // parenthesis count (expression)
60 public final static int Bit25 = 0x1000000; // parenthesis count (expression)
61 public final static int Bit26 = 0x2000000; // parenthesis count (expression)
62 public final static int Bit27 = 0x4000000; // parenthesis count (expression)
63 public final static int Bit28 = 0x8000000; // parenthesis count (expression)
64 public final static int Bit29 = 0x10000000; // parenthesis count (expression)
65 public final static int Bit30 = 0x20000000; // assignment with no effect (assignment)
66 public final static int Bit31 = 0x40000000; // local declaration reachable (local decl)
67 public final static int Bit32 = 0x80000000; // reachable (statement)
69 public int bits = IsReachableMASK; // reachable by default
72 public static final int ReturnTypeIDMASK = Bit1|Bit2|Bit3|Bit4;
73 public static final int OperatorSHIFT = 6; // Bit7 -> Bit12
74 public static final int OperatorMASK = Bit7|Bit8|Bit9|Bit10|Bit11|Bit12; // 6 bits for operator ID
76 // for binary expressions
77 public static final int ValueForReturnMASK = Bit5;
78 public static final int OnlyValueRequiredMASK = Bit6;
80 // for name references
81 public static final int RestrictiveFlagMASK = Bit1|Bit2|Bit3;
82 public static final int FirstAssignmentToLocalMASK = Bit4;
85 public static final int IsImplicitThisMask = Bit3;
87 // for single name references
88 public static final int DepthSHIFT = 5; // Bit6 -> Bit13
89 public static final int DepthMASK = Bit6|Bit7|Bit8|Bit9|Bit10|Bit11|Bit12|Bit13; // 8 bits for actual depth value (max. 255)
92 public static final int IsReachableMASK = Bit32;
93 public static final int IsLocalDeclarationReachableMASK = Bit31;
95 // for type declaration
96 public static final int AddAssertionMASK = Bit1;
98 // for type, method and field declarations
99 public static final int HasLocalTypeMASK = Bit2; // cannot conflict with AddAssertionMASK
102 public static final int ParenthesizedSHIFT = 21; // Bit22 -> Bit29
103 public static final int ParenthesizedMASK = Bit22|Bit23|Bit24|Bit25|Bit26|Bit27|Bit28|Bit29; // 8 bits for parenthesis count value (max. 255)
106 public static final int IsAssignmentWithNoEffectMASK = Bit30;
108 // for references on lhs of assignment (set only for true assignments, as opposed to compound ones)
109 public static final int IsStrictlyAssignedMASK = Bit14;
116 public boolean cannotReturn() {
120 public ASTNode concreteStatement() {
124 /* Answer true if the field use is considered deprecated.
125 * An access in the same compilation unit is allowed.
127 public final boolean isFieldUseDeprecated(FieldBinding field, Scope scope) {
129 if (field.isPrivate() && !scope.isDefinedInField(field)) {
130 // ignore cases where field is used from within inside itself
131 field.modifiers |= AccPrivateUsed;
134 if (!field.isViewedAsDeprecated()) return false;
136 // inside same unit - no report
137 if (scope.isDefinedInSameUnit(field.declaringClass)) return false;
139 // if context is deprecated, may avoid reporting
140 // if (!scope.environment().options.reportDeprecationInsideDeprecatedCode && scope.isInsideDeprecatedCode()) return false;
144 public boolean isImplicitThis() {
149 /* Answer true if the method use is considered deprecated.
150 * An access in the same compilation unit is allowed.
152 public final boolean isMethodUseDeprecated(MethodBinding method, Scope scope) {
154 if (method.isPrivate() && !scope.isDefinedInMethod(method)) {
155 // ignore cases where method is used from within inside itself (e.g. direct recursions)
156 method.modifiers |= AccPrivateUsed;
159 if (!method.isViewedAsDeprecated()) return false;
161 // inside same unit - no report
162 if (scope.isDefinedInSameUnit(method.declaringClass)) return false;
164 // if context is deprecated, may avoid reporting
165 // if (!scope.environment().options.reportDeprecationInsideDeprecatedCode && scope.isInsideDeprecatedCode()) return false;
169 public boolean isSuper() {
174 public boolean isThis() {
179 /* Answer true if the type use is considered deprecated.
180 * An access in the same compilation unit is allowed.
182 public final boolean isTypeUseDeprecated(TypeBinding type, Scope scope) {
184 if (type.isArrayType())
185 type = ((ArrayBinding) type).leafComponentType;
186 if (type.isBaseType())
189 ReferenceBinding refType = (ReferenceBinding) type;
191 if (refType.isPrivate() && !scope.isDefinedInType(refType)) {
192 // ignore cases where type is used from within inside itself
193 refType.modifiers |= AccPrivateUsed;
196 if (!refType.isViewedAsDeprecated()) return false;
198 // inside same unit - no report
199 if (scope.isDefinedInSameUnit(refType)) return false;
201 // if context is deprecated, may avoid reporting
202 // if (!scope.environment().options.reportDeprecationInsideDeprecatedCode && scope.isInsideDeprecatedCode()) return false;
206 public static String modifiersString(int modifiers) {
208 String s = ""; //$NON-NLS-1$
209 if ((modifiers & AccPublic) != 0)
210 s = s + "public "; //$NON-NLS-1$
211 if ((modifiers & AccPrivate) != 0)
212 s = s + "private "; //$NON-NLS-1$
213 if ((modifiers & AccProtected) != 0)
214 s = s + "protected "; //$NON-NLS-1$
215 if ((modifiers & AccStatic) != 0)
216 s = s + "static "; //$NON-NLS-1$
217 if ((modifiers & AccFinal) != 0)
218 s = s + "final "; //$NON-NLS-1$
219 // if ((modifiers & AccSynchronized) != 0)
220 // s = s + "synchronized "; //$NON-NLS-1$
221 // if ((modifiers & AccVolatile) != 0)
222 // s = s + "volatile "; //$NON-NLS-1$
223 // if ((modifiers & AccTransient) != 0)
224 // s = s + "transient "; //$NON-NLS-1$
225 // if ((modifiers & AccNative) != 0)
226 // s = s + "native "; //$NON-NLS-1$
227 if ((modifiers & AccAbstract) != 0)
228 s = s + "abstract "; //$NON-NLS-1$
233 * @deprecated - use field instead
235 public int sourceEnd() {
240 * @deprecated - use field instead
242 public int sourceStart() {
246 public static String tabString(int tab) {
248 String s = ""; //$NON-NLS-1$
249 for (int i = tab; i > 0; i--)
250 s = s + " "; //$NON-NLS-1$
254 public String toString() {
259 public String toString(int tab) {
261 return "****" + super.toString() + "****"; //$NON-NLS-2$ //$NON-NLS-1$
264 public void traverse(IAbstractSyntaxTreeVisitor visitor, BlockScope scope) {