**** Merged from MCS ****
[mono-project.git] / mcs / mcs / old-code.cs
blobcb7c31a0e26b6b19169ec222425abb58a1f19435
1 #else
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)
13 if (member_lookup is TypeExpr){
14 member_lookup.Resolve (ec);
15 return member_lookup;
18 if (member_lookup is MethodGroupExpr){
19 if (!mg.RemoveStaticMethods ()){
20 SimpleName.Error120 (loc, mg.Methods [0].Name);
21 return null;
24 return member_lookup;
27 if (member_lookup is PropertyExpr){
28 PropertyExpr pe = (PropertyExpr) member_lookup;
30 if (!pe.IsStatic){
31 SimpleName.Error120 (loc, pe.PropertyInfo.Name);
32 return null;
34 return pe;
37 if (member_lookup is FieldExpr){
38 FieldExpr fe = (FieldExpr) member_lookup;
39 FieldInfo fi = fe.FieldInfo;
41 if (fi is FieldBuilder) {
42 Const c = TypeManager.LookupConstant ((FieldBuilder) fi);
44 if (c != null) {
45 object o = c.LookupConstantValue (ec);
46 return Constantify (o, fi.FieldType);
50 if (fi.IsLiteral) {
51 Type t = fi.FieldType;
52 Type decl_type = fi.DeclaringType;
53 object o;
55 if (fi is FieldBuilder)
56 o = TypeManager.GetValue ((FieldBuilder) fi);
57 else
58 o = fi.GetValue (fi);
60 if (decl_type.IsSubclassOf (TypeManager.enum_type)) {
61 Expression enum_member = MemberLookup (
62 ec, decl_type, "value__", loc);
64 Enum en = TypeManager.LookupEnum (decl_type);
66 Constant c;
67 if (en != null)
68 c = Constantify (o, en.UnderlyingType);
69 else
70 c = Constantify (o, enum_member.Type);
72 return new EnumConstant (c, decl_type);
75 Expression exp = Constantify (o, t);
77 return exp;
80 if (!fe.FieldInfo.IsStatic){
81 error176 (loc, fe.FieldInfo.Name);
82 return null;
84 return member_lookup;
87 if (member_lookup is EventExpr){
89 EventExpr ee = (EventExpr) member_lookup;
92 // If the event is local to this class, we transform ourselves into
93 // a FieldExpr
96 Expression ml = MemberLookup (
97 ec, ec.TypeContainer.TypeBuilder, ee.EventInfo.Name,
98 MemberTypes.Event, AllBindingFlags, loc);
100 if (ml != null) {
101 MemberInfo mi = ec.TypeContainer.GetFieldFromEvent ((EventExpr) ml);
103 ml = ExprClassFromMemberInfo (ec, mi, loc);
105 if (ml == null) {
106 Report.Error (-200, loc, "Internal error!!");
107 return null;
110 return ResolveMemberAccess (ec, ml, left, loc);
113 if (!ee.IsStatic) {
114 SimpleName.Error120 (loc, ee.EventInfo.Name);
115 return null;
118 return ee;
121 Console.WriteLine ("Left is: " + left);
122 Report.Error (-100, loc, "Support for [" + member_lookup + "] is not present yet");
123 Environment.Exit (0);
125 return null;
128 public ResolveInstanceMemberAccess (EmitContext ec, Expression member_lookup,
129 Expression left, Location loc)
131 if (member_lookup is MethodGroupExpr){
133 // Instance.MethodGroup
135 if (!mg.RemoveStaticMethods ()){
136 error176 (loc, mg.Methods [0].Name);
137 return null;
140 mg.InstanceExpression = left;
142 return member_lookup;
145 if (member_lookup is PropertyExpr){
146 PropertyExpr pe = (PropertyExpr) member_lookup;
148 if (pe.IsStatic){
149 error176 (loc, pe.PropertyInfo.Name);
150 return null;
152 Console.WriteLine ("HERE *************");
153 pe.InstanceExpression = left;
155 return pe;
158 Type left_type = left.type;
160 if (left_type.IsValueType){
161 } else {
166 public override Expression DoResolve (EmitContext ec)
169 // We are the sole users of ResolveWithSimpleName (ie, the only
170 // ones that can cope with it
172 expr = expr.ResolveWithSimpleName (ec);
174 if (expr == null)
175 return null;
177 if (expr is SimpleName){
178 SimpleName child_expr = (SimpleName) expr;
180 expr = new SimpleName (child_expr.Name + "." + Identifier, loc);
182 return expr.ResolveWithSimpleName (ec);
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?)
191 Type expr_type = expr.Type;
192 if (expr_type.IsSubclassOf (TypeManager.enum_type)) {
194 Enum en = TypeManager.LookupEnum (expr_type);
196 if (en != null) {
197 object value = en.LookupEnumValue (ec, Identifier, loc);
199 if (value == null)
200 return null;
202 Constant c = Constantify (value, en.UnderlyingType);
203 return new EnumConstant (c, expr_type);
207 member_lookup = MemberLookup (ec, expr.Type, Identifier, loc);
209 if (member_lookup == null)
210 return null;
212 if (expr is TypeExpr)
213 return ResolveTypeMemberAccess (ec, member_lookup, expr, loc);
214 else
215 return ResolveInstanceMemberAccess (ec, member_lookup, expr, loc);
217 #endif