Mon Apr 29 15:32:02 CEST 2002 Paolo Molaro <lupus@ximian.com>
[mono.git] / mcs / mcs / old-code.cs
1 #else
2
3                 bla bla bla
4                 //
5                 // This code is more conformant to the spec (it follows it step by step),
6                 // but it has not been tested yet, and there is nothing here that is not
7                 // caught by the above code.  But it might be a better foundation to improve
8                 // on in the future
9                 //
10                 public ResolveTypeMemberAccess (EmitContext ec, Expression member_lookup,
11                                                 Expression left, Location loc)
12                 {
13                         if (member_lookup is TypeExpr){
14                                 member_lookup.Resolve (ec);
15                                 return member_lookup;
16                         }
17                         
18                         if (member_lookup is MethodGroupExpr){
19                                 if (!mg.RemoveStaticMethods ()){
20                                         SimpleName.Error120 (loc, mg.Methods [0].Name); 
21                                         return null;
22                                 }
23                                 
24                                 return member_lookup;
25                         }
26                         
27                         if (member_lookup is PropertyExpr){
28                                 PropertyExpr pe = (PropertyExpr) member_lookup;
29                                         
30                                         if (!pe.IsStatic){
31                                                 SimpleName.Error120 (loc, pe.PropertyInfo.Name);
32                                                 return null;
33                                         }
34                                         return pe;
35                         }
36                         
37                         if (member_lookup is FieldExpr){
38                                 FieldExpr fe = (FieldExpr) member_lookup;
39                                 FieldInfo fi = fe.FieldInfo;
40                                 
41                                 if (fi is FieldBuilder) {
42                                         Const c = TypeManager.LookupConstant ((FieldBuilder) fi);
43                                         
44                                         if (c != null) {
45                                                 object o = c.LookupConstantValue (ec);
46                                                 return Constantify (o, fi.FieldType);
47                                         }
48                                 }
49                                 
50                                 if (fi.IsLiteral) {
51                                         Type t = fi.FieldType;
52                                         Type decl_type = fi.DeclaringType;
53                                         object o;
54                                         
55                                         if (fi is FieldBuilder)
56                                                 o = TypeManager.GetValue ((FieldBuilder) fi);
57                                         else
58                                                 o = fi.GetValue (fi);
59                                         
60                                         if (decl_type.IsSubclassOf (TypeManager.enum_type)) {
61                                                 Expression enum_member = MemberLookup (
62                                                         ec, decl_type, "value__", loc); 
63                                                 
64                                                 Enum en = TypeManager.LookupEnum (decl_type);
65                                                 
66                                                 Constant c;
67                                                 if (en != null)
68                                                         c = Constantify (o, en.UnderlyingType);
69                                                 else 
70                                                         c = Constantify (o, enum_member.Type);
71                                                 
72                                                 return new EnumConstant (c, decl_type);
73                                         }
74                                         
75                                         Expression exp = Constantify (o, t);
76                                         
77                                         return exp;
78                                 }
79
80                                 if (!fe.FieldInfo.IsStatic){
81                                         error176 (loc, fe.FieldInfo.Name);
82                                         return null;
83                                 }
84                                 return member_lookup;
85                         }
86
87                         if (member_lookup is EventExpr){
88
89                                 EventExpr ee = (EventExpr) member_lookup;
90                                 
91                                 //
92                                 // If the event is local to this class, we transform ourselves into
93                                 // a FieldExpr
94                                 //
95
96                                 Expression ml = MemberLookup (
97                                         ec, ec.TypeContainer.TypeBuilder, ee.EventInfo.Name,
98                                         MemberTypes.Event, AllBindingFlags, loc);
99
100                                 if (ml != null) {
101                                         MemberInfo mi = ec.TypeContainer.GetFieldFromEvent ((EventExpr) ml);
102
103                                         ml = ExprClassFromMemberInfo (ec, mi, loc);
104                                         
105                                         if (ml == null) {
106                                                 Report.Error (-200, loc, "Internal error!!");
107                                                 return null;
108                                         }
109
110                                         return ResolveMemberAccess (ec, ml, left, loc);
111                                 }
112
113                                 if (!ee.IsStatic) {
114                                         SimpleName.Error120 (loc, ee.EventInfo.Name);
115                                         return null;
116                                 }
117                                 
118                                 return ee;
119                         }
120
121                         Console.WriteLine ("Left is: " + left);
122                         Report.Error (-100, loc, "Support for [" + member_lookup + "] is not present yet");
123                         Environment.Exit (0);
124
125                         return null;
126                 }
127                 
128                 public ResolveInstanceMemberAccess (EmitContext ec, Expression member_lookup,
129                                                     Expression left, Location loc)
130                 {
131                         if (member_lookup is MethodGroupExpr){
132                                 //
133                                 // Instance.MethodGroup
134                                 //
135                                 if (!mg.RemoveStaticMethods ()){
136                                         error176 (loc, mg.Methods [0].Name);
137                                         return null;
138                                 }
139                                 
140                                 mg.InstanceExpression = left;
141                                         
142                                 return member_lookup;
143                         }
144
145                         if (member_lookup is PropertyExpr){
146                                 PropertyExpr pe = (PropertyExpr) member_lookup;
147
148                                 if (pe.IsStatic){
149                                         error176 (loc, pe.PropertyInfo.Name);
150                                         return null;
151                                 }
152                                 pe.InstanceExpression = left;
153                                 
154                                 return pe;
155                         }
156
157                         Type left_type = left.type;
158
159                         if (left_type.IsValueType){
160                         } else {
161                                 
162                         }
163                 }
164                 
165                 public override Expression DoResolve (EmitContext ec)
166                 {
167                         //
168                         // We are the sole users of ResolveWithSimpleName (ie, the only
169                         // ones that can cope with it
170                         //
171                         expr = expr.ResolveWithSimpleName (ec);
172
173                         if (expr == null)
174                                 return null;
175
176                         if (expr is SimpleName){
177                                 SimpleName child_expr = (SimpleName) expr;
178                                 
179                                 expr = new SimpleName (child_expr.Name + "." + Identifier, loc);
180
181                                 return expr.ResolveWithSimpleName (ec);
182                         }
183
184                         //
185                         // Handle enums here when they are in transit.
186                         // Note that we cannot afford to hit MemberLookup in this case because
187                         // it will fail to find any members at all (Why?)
188                         //
189
190                         Type expr_type = expr.Type;
191                         if (expr_type.IsSubclassOf (TypeManager.enum_type)) {
192                                 
193                                 Enum en = TypeManager.LookupEnum (expr_type);
194                                 
195                                 if (en != null) {
196                                         object value = en.LookupEnumValue (ec, Identifier, loc);
197
198                                         if (value == null)
199                                                 return null;
200                                         
201                                         Constant c = Constantify (value, en.UnderlyingType);
202                                         return new EnumConstant (c, expr_type);
203                                 }
204                         }
205
206                         member_lookup = MemberLookup (ec, expr.Type, Identifier, loc);
207
208                         if (member_lookup == null)
209                                 return null;
210
211                         if (expr is TypeExpr)
212                                 return ResolveTypeMemberAccess (ec, member_lookup, expr, loc);
213                         else
214                                 return ResolveInstanceMemberAccess (ec, member_lookup, expr, loc);
215                 }
216 #endif