first scanner /parser copied from the jdt java version
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / lookup / BaseTypeBinding.java
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
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  ******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.lookup;
12
13 public final class BaseTypeBinding extends TypeBinding {
14         public char[] simpleName;
15         private char [] constantPoolName;
16 BaseTypeBinding(int id, char[] name, char[] constantPoolName) {
17         this.tagBits |= IsBaseType;
18         this.id = id;
19         this.simpleName = name;
20         this.constantPoolName = constantPoolName;
21 }
22 /* Answer the receiver's constant pool name.
23 */
24
25 public char[] constantPoolName() {
26         return constantPoolName;
27 }
28 public PackageBinding getPackage() {
29         return null;
30 }
31 /* Answer true if the receiver type can be assigned to the argument type (right)
32 */
33
34 final boolean isCompatibleWith(TypeBinding right) {
35         if (this == right)
36                 return true;
37         if (!right.isBaseType())
38                 return this == NullBinding;
39
40         switch (right.id) {
41                 case T_boolean :
42                 case T_byte :
43                 case T_char :
44                         return false;
45                 case T_double :
46                         switch (id) {
47                                 case T_byte :
48                                 case T_char :
49                                 case T_short :
50                                 case T_int :
51                                 case T_long :
52                                 case T_float :
53                                         return true;
54                                 default :
55                                         return false;
56                         }
57                 case T_float :
58                         switch (id) {
59                                 case T_byte :
60                                 case T_char :
61                                 case T_short :
62                                 case T_int :
63                                 case T_long :
64                                         return true;
65                                 default :
66                                         return false;
67                         }
68                 case T_long :
69                         switch (id) {
70                                 case T_byte :
71                                 case T_char :
72                                 case T_short :
73                                 case T_int :
74                                         return true;
75                                 default :
76                                         return false;
77                         }
78                 case T_int :
79                         switch (id) {
80                                 case T_byte :
81                                 case T_char :
82                                 case T_short :
83                                         return true;
84                                 default :
85                                         return false;
86                         }
87                 case T_short :
88                         return (id == T_byte);
89         }
90         return false;
91 }
92 public static final boolean isNarrowing(int left, int right) {
93         //can "left" store a "right" using some narrowing conversion
94         //(is left smaller than right)
95
96         switch (left) {
97                 case T_boolean :
98                         return right == T_boolean;
99                 case T_char :
100                 case T_byte :
101                         if (right == T_byte) return true;
102                 case T_short :
103                         if (right == T_short) return true;
104                         if (right == T_char) return true;
105                 case T_int :
106                         if (right == T_int) return true;
107                 case T_long :
108                         if (right == T_long) return true;
109                 case T_float :
110                         if (right == T_float) return true;
111                 case T_double :
112                         if (right == T_double) return true;
113                 default :
114                         return false;
115         }
116 }
117 public static final boolean isWidening(int left, int right) {
118         //can "left" store a "right" using some widening conversion
119         //(is left "bigger" than right)
120
121         switch (left) {
122                 case T_boolean :
123                         return right == T_boolean;
124                 case T_char :
125                         return right == T_char;
126                 case T_double :
127                         if (right == T_double) return true;
128                 case T_float :
129                         if (right == T_float) return true;
130                 case T_long :
131                         if (right == T_long) return true;
132                 case T_int :
133                         if (right == T_int) return true;
134                         if (right == T_char) return true;
135                 case T_short :
136                         if (right == T_short) return true;
137                 case T_byte :
138                         if (right == T_byte) return true;
139                 default :
140                         return false;
141         }
142 }
143 public char[] qualifiedSourceName() {
144         return simpleName;
145 }
146 public char[] readableName() {
147         return simpleName;
148 }
149 public char[] sourceName() {
150         return simpleName;
151 }
152 public String toString() {
153         return new String(constantPoolName) + " (id=" + id + ")"; //$NON-NLS-1$ //$NON-NLS-2$
154 }
155 }