* *.cs: Removed DeclContainer from EmitContext.
svn path=/trunk/mcs/; revision=140072
+2009-08-17 Marek Safar <marek.safar@gmail.com>
+
+ * *.cs: Removed DeclContainer from EmitContext.
+
2009-08-17 Marek Safar <marek.safar@gmail.com>
* *.cs: Add IResolveContext::CurrentTypeParameters.
TypeArguments targs = new TypeArguments ();
if (tparams.Length < CountTypeParameters) {
- TypeParameter[] parent_tparams = ec.DeclContainer.Parent.PartialContainer.TypeParameters;
+ TypeParameter[] parent_tparams = ec.GenericDeclContainer.Parent.PartialContainer.TypeParameters;
for (int i = 0; i < parent_tparams.Length; ++i)
targs.Add (new TypeParameterExpr (parent_tparams[i], Location));
}
{
// TODO: Implement clone
aec = new EmitContext (
- ec.ResolveContext, ec.DeclContainer,
+ ec.ResolveContext, ec.GenericDeclContainer,
Location, null, ReturnType,
(ec.InUnsafe ? Modifiers.UNSAFE : 0), /* No constructor */ false);
return null;
}
- if ((source.eclass == ExprClass.Type) && (source is TypeExpr)) {
- source.Error_UnexpectedKind (ec.DeclContainer, "variable or value", loc);
- return null;
- } else if ((RootContext.Version == LanguageVersion.ISO_1) &&
+ if ((RootContext.Version == LanguageVersion.ISO_1) &&
(source is MethodGroupExpr)){
((MethodGroupExpr) source).ReportUsageError ();
return null;
//
// TODO: Use ResolveContext only
- EmitContext f_ec = new EmitContext (rc, rc.DeclContainer, loc, null, TypeManager.void_type, 0, true);
+ EmitContext f_ec = new EmitContext (rc, rc.GenericDeclContainer, loc, null, TypeManager.void_type, 0, true);
f_ec.IsStatic = ec.IsStatic;
f_ec.CurrentBlock = ec.CurrentBlock;
return null;
}
+ public FullNamedExpression LookupNamespaceAlias (string name)
+ {
+ return tc.Parent.LookupNamespaceAlias (name);
+ }
+
public FullNamedExpression LookupNamespaceOrType (string name, Location loc, bool ignore_cs0104)
{
TypeParameter[] tp = CurrentTypeParameters;
//
TypeContainer CurrentTypeDefinition { get; }
- // Obsolete
- DeclSpace DeclContainer { get; }
-
bool IsInObsoleteScope { get; }
bool IsInUnsafeScope { get; }
ExtensionMethodGroupExpr LookupExtensionMethod (Type extensionType, string name, Location loc);
FullNamedExpression LookupNamespaceOrType (string name, Location loc, bool ignore_cs0104);
+ FullNamedExpression LookupNamespaceAlias (string name);
// the declcontainer to lookup for type-parameters. Should only use LookupGeneric on it.
//
get { return ResolveContext.CurrentTypeDefinition; }
}
- // IResolveContext.DeclContainer
- public DeclSpace DeclContainer {
- get { return decl_space; }
- }
-
// IResolveContext.GenericDeclContainer
public DeclSpace GenericDeclContainer {
- get { return DeclContainer; }
+ get { return decl_space; }
}
public bool CheckState {
return ResolveContext.LookupNamespaceOrType (name, loc, ignore_cs0104);
}
+ public FullNamedExpression LookupNamespaceAlias (string name)
+ {
+ return ResolveContext.LookupNamespaceAlias (name);
+ }
+
#endregion
}
return RootContext.ToplevelTypes.LookupNamespaceOrType (name, loc, ignore_cs0104);
}
+ public FullNamedExpression LookupNamespaceAlias (string name)
+ {
+ throw new NotImplementedException ();
+ }
+
#endregion
}
return Parent.LookupExtensionMethod (extensionType, name, loc);
}
+ public virtual FullNamedExpression LookupNamespaceAlias (string name)
+ {
+ return Parent.NamespaceEntry.LookupNamespaceAlias (name);
+ }
+
public virtual FullNamedExpression LookupNamespaceOrType (string name, Location loc, bool ignore_cs0104)
{
return Parent.LookupNamespaceOrType (name, loc, ignore_cs0104);
/// <summary>
/// Reports that we were expecting `expr' to be of class `expected'
/// </summary>
- public void Error_UnexpectedKind (DeclSpace ds, string expected, Location loc)
+ public void Error_UnexpectedKind (MemberCore mc, string expected, Location loc)
{
- Error_UnexpectedKind (ds, expected, ExprClassName, loc);
+ Error_UnexpectedKind (mc, expected, ExprClassName, loc);
}
- public void Error_UnexpectedKind (DeclSpace ds, string expected, string was, Location loc)
+ public void Error_UnexpectedKind (MemberCore mc, string expected, string was, Location loc)
{
- string name = GetSignatureForError ();
- if (ds != null)
- name = ds.GetSignatureForError () + '.' + name;
+ string name;
+ if (mc != null)
+ name = mc.GetSignatureForError ();
+ else
+ name = GetSignatureForError ();
Report.Error (118, loc, "`{0}' is a `{1}' but a `{2}' was expected",
name, was, expected);
if (!TypeManager.IsGenericTypeDefinition (t) && !TypeManager.IsGenericType (t))
return null;
- DeclSpace ds = ec.DeclContainer;
+ if (ec.CurrentType == null)
+ return null;
+
+ DeclSpace ds = ec.CurrentTypeDefinition;
while (ds != null && !IsNestedChild (t, ds.TypeBuilder))
ds = ds.Parent;
protected virtual void Error_TypeOrNamespaceNotFound (IResolveContext ec)
{
- MemberCore mc = ec.DeclContainer.GetDefinition (Name);
- if (mc != null) {
- Error_UnexpectedKind (ec.DeclContainer, "type", GetMemberType (mc), loc);
- return;
- }
+ if (ec.CurrentType != null) {
+ if (ec.CurrentTypeDefinition != null) {
+ MemberCore mc = ec.CurrentTypeDefinition.GetDefinition (Name);
+ if (mc != null) {
+ Error_UnexpectedKind (mc, "type", GetMemberType (mc), loc);
+ return;
+ }
+ }
- string ns = ec.DeclContainer.NamespaceEntry.NS.Name;
- string fullname = (ns.Length > 0) ? ns + "." + Name : Name;
- foreach (Assembly a in GlobalRootNamespace.Instance.Assemblies) {
- Type type = a.GetType (fullname);
- if (type != null) {
- Report.SymbolRelatedToPreviousError (type);
- Expression.ErrorIsInaccesible (loc, TypeManager.CSharpName (type));
- return;
+ string ns = ec.CurrentType.Namespace;
+ string fullname = (ns.Length > 0) ? ns + "." + Name : Name;
+ foreach (Assembly a in GlobalRootNamespace.Instance.Assemblies) {
+ Type type = a.GetType (fullname);
+ if (type != null) {
+ Report.SymbolRelatedToPreviousError (type);
+ Expression.ErrorIsInaccesible (loc, TypeManager.CSharpName (type));
+ return;
+ }
}
- }
- Type t = ec.DeclContainer.LookupAnyGeneric (Name);
- if (t != null) {
- Namespace.Error_InvalidNumberOfTypeArguments (t, loc);
- return;
+ if (ec.CurrentTypeDefinition != null) {
+ Type t = ec.CurrentTypeDefinition.LookupAnyGeneric (Name);
+ if (t != null) {
+ Namespace.Error_InvalidNumberOfTypeArguments (t, loc);
+ return;
+ }
+ }
}
if (targs != null) {
- FullNamedExpression retval = ec.DeclContainer.LookupNamespaceOrType (SimpleName.RemoveGenericArity (Name), loc, true);
+ FullNamedExpression retval = ec.LookupNamespaceOrType (SimpleName.RemoveGenericArity (Name), loc, true);
if (retval != null) {
Namespace.Error_TypeArgumentsCannotBeUsed (retval, loc);
return;
Type almost_matched_type = null;
ArrayList almost_matched = null;
- for (DeclSpace lookup_ds = ec.DeclContainer; lookup_ds != null; lookup_ds = lookup_ds.Parent) {
- // either RootDeclSpace or GenericMethod
- if (lookup_ds.TypeBuilder == null)
- continue;
-
- e = MemberLookup (ec.CurrentType, lookup_ds.TypeBuilder, Name, loc);
+ for (Type lookup_ds = ec.CurrentType; lookup_ds != null; lookup_ds = lookup_ds.DeclaringType) {
+ e = MemberLookup (ec.CurrentType, lookup_ds, Name, loc);
if (e != null) {
PropertyExpr pe = e as PropertyExpr;
if (pe != null) {
}
if (almost_matched == null && almost_matched_members.Count > 0) {
- almost_matched_type = lookup_ds.TypeBuilder;
+ almost_matched_type = lookup_ds;
almost_matched = (ArrayList) almost_matched_members.Clone ();
}
}
almost_matched_members = almost_matched;
if (almost_matched_type == null)
almost_matched_type = ec.CurrentType;
+
+ string type_name = ec.ResolveContext.CurrentType == null ? null : ec.ResolveContext.CurrentType.Name;
return Error_MemberLookupFailed (ec.CurrentType, null, almost_matched_type, Name,
- ec.DeclContainer.Name, AllMemberTypes, AllBindingFlags);
+ type_name, AllMemberTypes, AllBindingFlags);
}
if (e is MemberExpr) {
// Optimization for build-in types
// TODO: Iterators don't set current container
- if (TypeManager.IsStruct (type) && type == ec.DeclContainer.TypeBuilder && ec.CurrentIterator == null) {
+ if (TypeManager.IsStruct (type) && TypeManager.IsEqual (type, ec.ResolveContext.CurrentType) && ec.CurrentIterator == null) {
LoadFromPtr (ig, type);
} else {
IFixedBuffer ff = AttributeTester.GetFixedBuffer (FieldInfo);
method = ml as MethodGroupExpr;
if (method == null) {
- ml.Error_UnexpectedKind (ec.DeclContainer, "method group", loc);
+ ml.Error_UnexpectedKind (ResolveFlags.MethodGroup, loc);
return null;
}
}
int errors = Report.Errors;
- // TODO: Implement ec.Namespace
-
- expr = ec.DeclContainer.NamespaceEntry.LookupAlias (alias);
+ expr = ec.LookupNamespaceAlias (alias);
if (expr == null) {
if (errors == Report.Errors)
Report.Error (432, loc, "Alias `{0}' not found", alias);
return null;
}
- if (!texpr.CheckAccessLevel (ec.DeclContainer)) {
+ if (!texpr.CheckAccessLevel (ec.GenericDeclContainer)) {
Report.SymbolRelatedToPreviousError (member_lookup.Type);
ErrorIsInaccesible (loc, TypeManager.CSharpName (member_lookup.Type));
return null;
}
Expression member_lookup = MemberLookup (
- rc.DeclContainer.TypeBuilder, expr_type, expr_type, LookupIdentifier,
+ rc.CurrentType, expr_type, expr_type, LookupIdentifier,
MemberTypes.NestedType, BindingFlags.Public | BindingFlags.NonPublic, loc);
if (member_lookup == null) {
if (silent)
protected virtual void Error_IdentifierNotFound (IResolveContext rc, FullNamedExpression expr_type, string identifier)
{
Expression member_lookup = MemberLookup (
- rc.DeclContainer.TypeBuilder, expr_type.Type, expr_type.Type, SimpleName.RemoveGenericArity (identifier),
+ rc.CurrentType, expr_type.Type, expr_type.Type, SimpleName.RemoveGenericArity (identifier),
MemberTypes.NestedType, BindingFlags.Public | BindingFlags.NonPublic, loc);
if (member_lookup != null) {
}
member_lookup = MemberLookup (
- rc.DeclContainer.TypeBuilder, expr_type.Type, expr_type.Type, identifier,
+ rc.CurrentType, expr_type.Type, expr_type.Type, identifier,
MemberTypes.All, BindingFlags.Public | BindingFlags.NonPublic, loc);
if (member_lookup == null) {
}
// Looks-up a alias named @name in this and surrounding namespace declarations
- public FullNamedExpression LookupAlias (string name)
+ public FullNamedExpression LookupNamespaceAlias (string name)
{
for (NamespaceEntry n = this; n != null; n = n.ImplicitParent) {
if (n.using_aliases == null)
{
return PartialContainer.IsClsComplianceRequired ();
}
+
+ public override FullNamedExpression LookupNamespaceAlias (string name)
+ {
+ return NamespaceEntry.LookupNamespaceAlias (name);
+ }
}
}