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
10 public ResolveTypeMemberAccess (EmitContext ec
, Expression member_lookup
,
11 Expression left
, Location loc
)
13 if (member_lookup
is TypeExpr
){
14 member_lookup
.Resolve (ec
);
18 if (member_lookup
is MethodGroupExpr
){
19 if (!mg
.RemoveStaticMethods ()){
20 SimpleName
.Error120 (loc
, mg
.Methods
[0].Name
);
27 if (member_lookup
is PropertyExpr
){
28 PropertyExpr pe
= (PropertyExpr
) member_lookup
;
31 SimpleName
.Error120 (loc
, pe
.PropertyInfo
.Name
);
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
);
45 object o
= c
.LookupConstantValue (ec
);
46 return Constantify (o
, fi
.FieldType
);
51 Type t
= fi
.FieldType
;
52 Type decl_type
= fi
.DeclaringType
;
55 if (fi
is FieldBuilder
)
56 o
= TypeManager
.GetValue ((FieldBuilder
) 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
);
68 c
= Constantify (o
, en
.UnderlyingType
);
70 c
= Constantify (o
, enum_member
.Type
);
72 return new EnumConstant (c
, decl_type
);
75 Expression exp
= Constantify (o
, t
);
80 if (!fe
.FieldInfo
.IsStatic
){
81 error176 (loc
, fe
.FieldInfo
.Name
);
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
96 Expression ml
= MemberLookup (
97 ec
, ec
.TypeContainer
.TypeBuilder
, ee
.EventInfo
.Name
,
98 MemberTypes
.Event
, AllBindingFlags
, loc
);
101 MemberInfo mi
= ec
.TypeContainer
.GetFieldFromEvent ((EventExpr
) ml
);
103 ml
= ExprClassFromMemberInfo (ec
, mi
, loc
);
106 Report
.Error (-200, loc
, "Internal error!!");
110 return ResolveMemberAccess (ec
, ml
, left
, loc
);
114 SimpleName
.Error120 (loc
, ee
.EventInfo
.Name
);
121 Console
.WriteLine ("Left is: " + left
);
122 Report
.Error (-100, loc
, "Support for [" + member_lookup
+ "] is not present yet");
123 Environment
.Exit (0);
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
);
140 mg
.InstanceExpression
= left
;
142 return member_lookup
;
145 if (member_lookup
is PropertyExpr
){
146 PropertyExpr pe
= (PropertyExpr
) member_lookup
;
149 error176 (loc
, pe
.PropertyInfo
.Name
);
152 Console
.WriteLine ("HERE *************");
153 pe
.InstanceExpression
= left
;
158 Type left_type
= left
.type
;
160 if (left_type
.IsValueType
){
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
);
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
);
197 object value = en
.LookupEnumValue (ec
, Identifier
, loc
);
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)
212 if (expr
is TypeExpr
)
213 return ResolveTypeMemberAccess (ec
, member_lookup
, expr
, loc
);
215 return ResolveInstanceMemberAccess (ec
, member_lookup
, expr
, loc
);