Copied remotely
[mono.git] / mcs / gmcs / 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                                 Console.WriteLine ("HERE *************");
153                                 pe.InstanceExpression = left;
154                                 
155                                 return pe;
156                         }
157
158                         Type left_type = left.type;
159
160                         if (left_type.IsValueType){
161                         } else {
162                                 
163                         }
164                 }
165                 
166                 public override Expression DoResolve (EmitContext ec)
167                 {
168                         //
169                         // We are the sole users of ResolveWithSimpleName (ie, the only
170                         // ones that can cope with it
171                         //
172                         expr = expr.ResolveWithSimpleName (ec);
173
174                         if (expr == null)
175                                 return null;
176
177                         if (expr is SimpleName){
178                                 SimpleName child_expr = (SimpleName) expr;
179                                 
180                                 expr = new SimpleName (child_expr.Name + "." + Identifier, loc);
181
182                                 return expr.ResolveWithSimpleName (ec);
183                         }
184
185                         //
186                         // Handle enums here when they are in transit.
187                         // Note that we cannot afford to hit MemberLookup in this case because
188                         // it will fail to find any members at all (Why?)
189                         //
190
191                         Type expr_type = expr.Type;
192                         if (expr_type.IsSubclassOf (TypeManager.enum_type)) {
193                                 
194                                 Enum en = TypeManager.LookupEnum (expr_type);
195                                 
196                                 if (en != null) {
197                                         object value = en.LookupEnumValue (ec, Identifier, loc);
198
199                                         if (value == null)
200                                                 return null;
201                                         
202                                         Constant c = Constantify (value, en.UnderlyingType);
203                                         return new EnumConstant (c, expr_type);
204                                 }
205                         }
206
207                         member_lookup = MemberLookup (ec, expr.Type, Identifier, loc);
208
209                         if (member_lookup == null)
210                                 return null;
211
212                         if (expr is TypeExpr)
213                                 return ResolveTypeMemberAccess (ec, member_lookup, expr, loc);
214                         else
215                                 return ResolveInstanceMemberAccess (ec, member_lookup, expr, loc);
216                 }
217 #endif