continue;
Operator o = operators [i];
- Report.Error (216, o.Location,
+ container.Report.Error (216, o.Location,
"The operator `{0}' requires a matching operator `{1}' to also be defined",
o.GetSignatureForError (), Operator.GetName (o.GetMatchingOperator ()));
}
- if (has_equality_or_inequality && Report.WarningLevel > 2) {
+ if (has_equality_or_inequality && container.Report.WarningLevel > 2) {
if (container.Methods == null || !container.HasEquals)
- Report.Warning (660, 2, container.Location, "`{0}' defines operator == or operator != but does not override Object.Equals(object o)", container.GetSignatureForError ());
+ container.Report.Warning (660, 2, container.Location, "`{0}' defines operator == or operator != but does not override Object.Equals(object o)", container.GetSignatureForError ());
if (container.Methods == null || !container.HasGetHashCode)
- Report.Warning (661, 2, container.Location, "`{0}' defines operator == or operator != but does not override Object.GetHashCode()", container.GetSignatureForError ());
+ container.Report.Warning (661, 2, container.Location, "`{0}' defines operator == or operator != but does not override Object.GetHashCode()", container.GetSignatureForError ());
}
}
}
}
+ //
+ // Different context is needed when resolving type container base
+ // types. Type names come from the parent scope but type parameter
+ // names from the container scope.
+ //
+ struct BaseContext : IMemberContext
+ {
+ TypeContainer tc;
+
+ public BaseContext (TypeContainer tc)
+ {
+ this.tc = tc;
+ }
+
+ #region IMemberContext Members
+
+ public CompilerContext Compiler {
+ get { return tc.Compiler; }
+ }
+
+ public Type CurrentType {
+ get { return tc.Parent.CurrentType; }
+ }
+
+ public TypeParameter[] CurrentTypeParameters {
+ get { return tc.PartialContainer.CurrentTypeParameters; }
+ }
+
+ public TypeContainer CurrentTypeDefinition {
+ get { return tc.Parent.CurrentTypeDefinition; }
+ }
+
+ public bool IsObsolete {
+ get { return tc.IsObsolete; }
+ }
+
+ public bool IsUnsafe {
+ get { return tc.IsUnsafe; }
+ }
+
+ public bool IsStatic {
+ get { return tc.IsStatic; }
+ }
+
+ public string GetSignatureForError ()
+ {
+ throw new NotImplementedException ();
+ }
+
+ public ExtensionMethodGroupExpr LookupExtensionMethod (Type extensionType, string name, Location loc)
+ {
+ 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;
+ if (tp != null) {
+ TypeParameter t = TypeParameter.FindTypeParameter (tp, name);
+ if (t != null)
+ return new TypeParameterExpr (t, loc);
+ }
+
+ return tc.Parent.LookupNamespaceOrType (name, loc, ignore_cs0104);
+ }
+
+ #endregion
+ }
+
[Flags]
enum CachedMethods
{
}
}
- public void ResolveFieldInitializers (EmitContext ec)
+ public void ResolveFieldInitializers (BlockContext ec)
{
if (partial_parts != null) {
foreach (TypeContainer part in partial_parts) {
DoResolveFieldInitializers (ec);
}
- void DoResolveFieldInitializers (EmitContext ec)
+ void DoResolveFieldInitializers (BlockContext ec)
{
if (ec.IsStatic) {
if (initialized_static_fields == null)
}
}
- //
- // Emits the instance field initializers
- //
- public bool EmitFieldInitializers (EmitContext ec)
- {
- if (partial_parts != null) {
- foreach (TypeContainer part in partial_parts)
- part.EmitFieldInitializers (ec);
- }
-
- ArrayList fields;
-
- if (ec.IsStatic){
- fields = initialized_static_fields;
- } else {
- fields = initialized_fields;
- }
-
- if (fields == null)
- return true;
-
- foreach (FieldInitializer f in fields) {
- f.EmitStatement (ec);
- }
- return true;
- }
-
public override string DocComment {
get {
return comment;
int count = type_bases.Count;
TypeExpr [] ifaces = null;
+ IMemberContext base_context = new BaseContext (this);
for (int i = 0, j = 0; i < count; i++){
FullNamedExpression fne = (FullNamedExpression) type_bases [i];
// it does ObsoleteAttribute and constraint checks which require
// base type to be set
//
- TypeExpr fne_resolved = fne.ResolveAsBaseTerminal (this, false);
+ TypeExpr fne_resolved = fne.ResolveAsBaseTerminal (base_context, false);
if (fne_resolved == null)
continue;
if (i == 0 && Kind == Kind.Class && !fne_resolved.Type.IsInterface) {
- base_class = fne_resolved;
+ if (fne_resolved is DynamicTypeExpr)
+ Report.Error (1965, Location, "Class `{0}' cannot derive from the dynamic type",
+ GetSignatureForError ());
+ else
+ base_class = fne_resolved;
continue;
}
if (base_class == TypeManager.system_object_expr)
base_class = new_base_class;
else {
- if (new_base_class != null && !new_base_class.Equals (base_class)) {
+ if (new_base_class != null && !TypeManager.IsEqual (new_base_class.Type, base_class.Type)) {
Report.SymbolRelatedToPreviousError (base_class.Location, "");
Report.Error (263, part.Location,
"Partial declarations of `{0}' must not specify different base classes",
default_parent = TypeManager.value_type;
else if (Kind == Kind.Enum)
default_parent = TypeManager.enum_type;
+ else if (Kind == Kind.Delegate)
+ default_parent = TypeManager.multicast_delegate_type;
//
// Sets .size to 1 for structs with no instance fields
int type_size = Kind == Kind.Struct && first_nonstatic_field == null ? 1 : 0;
if (IsTopLevel){
- if (TypeManager.NamespaceClash (Name, Location)) {
+ if (GlobalRootNamespace.Instance.IsNamespace (Name)) {
+ Report.Error (519, Location, "`{0}' clashes with a predefined namespace", Name);
return false;
}
#if GMCS_SOURCE
GenericTypeParameterBuilder[] gen_params = TypeBuilder.DefineGenericParameters (param_names);
- int offset = CountTypeParameters - CurrentTypeParameters.Length;
+ int offset = CountTypeParameters;
+ if (CurrentTypeParameters != null)
+ offset -= CurrentTypeParameters.Length;
+
if (offset > 0) {
nested_gen_params = new GenericTypeParameterBuilder [offset];
Array.Copy (gen_params, nested_gen_params, offset);
// Let's do it as soon as possible, since code below can call DefineType() on classes
// that depend on us to be populated before they are.
//
- if (!(this is CompilerGeneratedClass))
+ if (!(this is CompilerGeneratedClass) && !(this is Delegate))
RootContext.RegisterOrder (this);
if (!CheckRecursiveDefinition (this))
void UpdateTypeParameterConstraints (TypeContainer part)
{
- TypeParameter[] current_params = CurrentTypeParameters;
+ TypeParameter[] current_params = type_params;
for (int i = 0; i < current_params.Length; i++) {
- Constraints c = part.CurrentTypeParameters [i].Constraints;
+ Constraints c = part.type_params [i].Constraints;
if (c == null)
continue;
throw new InternalErrorException ();
TypeExpr current_type = null;
-
- foreach (TypeParameter type_param in CurrentTypeParameters) {
- if (!type_param.Resolve (this)) {
- error = true;
- return false;
+ if (CurrentTypeParameters != null) {
+ foreach (TypeParameter type_param in CurrentTypeParameters) {
+ if (!type_param.Resolve (this)) {
+ error = true;
+ return false;
+ }
}
- }
- if (partial_parts != null && is_generic) {
- foreach (TypeContainer part in partial_parts)
- UpdateTypeParameterConstraints (part);
+ if (partial_parts != null) {
+ foreach (TypeContainer part in partial_parts)
+ UpdateTypeParameterConstraints (part);
+ }
}
for (int i = 0; i < TypeParameters.Length; ++i) {
return false;
}
- CurrentType = current_type.Type;
+ currentType = current_type.Type;
return true;
}
return true;
}
+ public override TypeParameter[] CurrentTypeParameters {
+ get {
+ return PartialContainer.type_params;
+ }
+ }
+
/// <summary>
/// Populates our TypeBuilder with fields and methods
/// </summary>
if (iface_exprs != null) {
foreach (TypeExpr iface in iface_exprs) {
ObsoleteAttribute oa = AttributeTester.GetObsoleteAttribute (iface.Type);
- if ((oa != null) && !IsInObsoleteScope)
+ if ((oa != null) && !IsObsolete)
AttributeTester.Report_ObsoleteMessage (
- oa, iface.GetSignatureForError (), Location);
+ oa, iface.GetSignatureForError (), Location, Report);
GenericTypeExpr ct = iface as GenericTypeExpr;
if (ct != null) {
if (base_type != null) {
ObsoleteAttribute obsolete_attr = AttributeTester.GetObsoleteAttribute (base_type.Type);
- if (obsolete_attr != null && !IsInObsoleteScope)
- AttributeTester.Report_ObsoleteMessage (obsolete_attr, base_type.GetSignatureForError (), Location);
+ if (obsolete_attr != null && !IsObsolete)
+ AttributeTester.Report_ObsoleteMessage (obsolete_attr, base_type.GetSignatureForError (), Location, Report);
GenericTypeExpr ct = base_type as GenericTypeExpr;
if ((ct != null) && !ct.CheckConstraints (this))
return;
}
- static void CheckMemberUsage (MemberCoreArrayList al, string member_type)
+ void CheckMemberUsage (MemberCoreArrayList al, string member_type)
{
if (al == null)
return;
}
if (pending != null)
- pending.VerifyPendingMethods ();
+ pending.VerifyPendingMethods (Report);
if (Report.Errors > 0)
return;
if (Kind == Kind.Struct){
if ((flags & va) != 0){
- Modifiers.Error_InvalidModifier (mc.Location, "virtual or abstract");
+ Modifiers.Error_InvalidModifier (mc.Location, "virtual or abstract", Report);
ok = false;
}
}
//
internal override void GenerateDocComment (DeclSpace ds)
{
- DocUtil.GenerateTypeDocComment (this, ds);
+ DocUtil.GenerateTypeDocComment (this, ds, Report);
}
public override string DocCommentHeader {
Location);
AddConstructor (c);
- c.Block = new ToplevelBlock (ParametersCompiled.EmptyReadOnlyParameters, Location);
+ c.Block = new ToplevelBlock (Compiler, ParametersCompiled.EmptyReadOnlyParameters, Location);
}
public override bool Define ()
public override ExtensionMethodGroupExpr LookupExtensionMethod (Type extensionType, string name, Location loc)
{
- return NamespaceEntry.LookupExtensionMethod (extensionType, this, name, loc);
+ DeclSpace top_level = Parent;
+ if (top_level != null) {
+ while (top_level.Parent != null)
+ top_level = top_level.Parent;
+
+ ArrayList candidates = NamespaceEntry.NS.LookupExtensionMethod (extensionType, this, name);
+ if (candidates != null)
+ return new ExtensionMethodGroupExpr (candidates, NamespaceEntry, extensionType, loc);
+ }
+
+ return NamespaceEntry.LookupExtensionMethod (extensionType, name, loc);
}
protected override TypeAttributes TypeAttr {
: base (ns, parent, name, attrs, Kind.Class)
{
int accmods = Parent.Parent == null ? Modifiers.INTERNAL : Modifiers.PRIVATE;
- this.ModFlags = Modifiers.Check (AllowedModifiers, mod, accmods, Location);
+ this.ModFlags = Modifiers.Check (AllowedModifiers, mod, accmods, Location, Report);
if (IsStatic && RootContext.Version == LanguageVersion.ISO_1) {
Report.FeatureIsNotAvailable (Location, "static classes");
else if (Name != "System.Object")
base_class = TypeManager.system_object_expr;
} else {
- if (Kind == Kind.Class && base_class is TypeParameterExpr){
+ if (Kind == Kind.Class && TypeManager.IsGenericParameter (base_class.Type)){
Report.Error (
689, base_class.Location,
"Cannot derive from `{0}' because it is a type parameter",
return true;
}
- bool IsStatic {
- get {
- return (ModFlags & Modifiers.STATIC) != 0;
- }
- }
-
//
// FIXME: How do we deal with the user specifying a different
// layout?
else
accmods = Modifiers.PRIVATE;
- this.ModFlags = Modifiers.Check (AllowedModifiers, mod, accmods, Location);
+ this.ModFlags = Modifiers.Check (AllowedModifiers, mod, accmods, Location, Report);
this.ModFlags |= Modifiers.SEALED;
}
else
accmods = Modifiers.PRIVATE;
- this.ModFlags = Modifiers.Check (AllowedModifiers, mod, accmods, name.Location);
+ this.ModFlags = Modifiers.Check (AllowedModifiers, mod, accmods, name.Location, Report);
}
public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb, PredefinedAttributes pa)
//
internal override void OnGenerateDocComment (XmlElement el)
{
- DocUtil.OnMethodGenerateDocComment (this, el);
+ DocUtil.OnMethodGenerateDocComment (this, el, Report);
}
//
protected virtual bool CheckForDuplications ()
{
return Parent.MemberCache.CheckExistingMembersOverloads (
- this, GetFullName (MemberName), ParametersCompiled.EmptyReadOnlyParameters);
+ this, GetFullName (MemberName), ParametersCompiled.EmptyReadOnlyParameters, Report);
}
//
if (!IsInterface && (base_method.IsVirtual || base_method.IsAbstract)) {
Report.Warning (114, 2, Location, "`{0}' hides inherited member `{1}'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword",
GetSignatureForError (), TypeManager.CSharpSignature (base_method));
+ if (base_method.IsAbstract){
+ Report.Error (533, Location, "`{0}' hides inherited abstract member `{1}'",
+ GetSignatureForError (), TypeManager.CSharpSignature (base_method));
+ ok = false;
+ }
} else {
Report.Warning (108, 2, Location, "`{0}' hides inherited member `{1}'. Use the new keyword if hiding was intended",
GetSignatureForError (), TypeManager.CSharpSignature (base_method));
Parent.PartialContainer.VerifyImplements (this);
}
- Modifiers.Check (Modifiers.AllowedExplicitImplFlags, explicit_mod_flags, 0, Location);
+ Modifiers.Check (Modifiers.AllowedExplicitImplFlags, explicit_mod_flags, 0, Location, Report);
}
return base.Define ();
protected bool DefineParameters (ParametersCompiled parameters)
{
- IResolveContext rc = GenericMethod == null ? this : (IResolveContext)ds;
-
- if (!parameters.Resolve (rc))
+ if (!parameters.Resolve (this))
return false;
bool error = false;
Parameter p = parameters [i];
if (p.HasDefaultValue && (IsExplicitImpl || this is Operator || (this is Indexer && parameters.Count == 1)))
- p.Warning_UselessOptionalParameter ();
+ p.Warning_UselessOptionalParameter (Report);
if (p.CheckAccessibility (this))
continue;
if (MemberName.IsGeneric)
name = MemberName.MakeName (name, MemberName.TypeArguments);
- return Parent.MemberCache.CheckExistingMembersOverloads (this, name, Parameters);
+ return Parent.MemberCache.CheckExistingMembersOverloads (this, name, Parameters, Report);
}
- public virtual EmitContext CreateEmitContext (DeclSpace tc, ILGenerator ig)
+ public virtual EmitContext CreateEmitContext (ILGenerator ig)
{
return new EmitContext (
- this, tc, this.ds, Location, ig, MemberType, ModFlags, false);
+ this, ig, MemberType);
}
protected override bool ResolveMemberType ()
// Current method is turned into automatically generated
// wrapper which creates an instance of iterator
//
- Iterator.CreateIterator (this, Parent.PartialContainer, ModFlags);
+ Iterator.CreateIterator (this, Parent.PartialContainer, ModFlags, Compiler);
ModFlags |= Modifiers.DEBUGGER_HIDDEN;
}
MethodData = new MethodData (
this, ModFlags, flags, this, MethodBuilder, GenericMethod, base_method);
- if (!MethodData.Define (Parent.PartialContainer, GetFullName (MemberName)))
+ if (!MethodData.Define (Parent.PartialContainer, GetFullName (MemberName), Report))
return false;
MethodBuilder = MethodData.MethodBuilder;
}
if (p.HasDefaultValue && IsPartialImplementation)
- ((Parameter) p).Warning_UselessOptionalParameter ();
+ ((Parameter) p).Warning_UselessOptionalParameter (Report);
}
}
}
if ((ModFlags & Modifiers.DEBUGGER_HIDDEN) != 0)
PredefinedAttributes.Get.DebuggerHidden.EmitAttribute (MethodBuilder);
+ if (TypeManager.IsDynamicType (ReturnType)) {
+ return_attributes = new ReturnParameter (MethodBuilder, Location);
+ return_attributes.EmitPredefined (PredefinedAttributes.Get.Dynamic, Location);
+ }
+
if (OptAttributes != null)
OptAttributes.Emit ();
const int AllowedInterfaceModifiers =
Modifiers.NEW | Modifiers.UNSAFE;
+ Method partialMethodImplementation;
+
public Method (DeclSpace parent, GenericMethod generic,
FullNamedExpression return_type, int mod,
MemberName name, ParametersCompiled parameters, Attributes attrs)
return base.GetSignatureForError () + Parameters.GetSignatureForError ();
}
- static void Error_DuplicateEntryPoint (Method b)
+ void Error_DuplicateEntryPoint (Method b)
{
Report.Error (17, b.Location,
"Program `{0}' has more than one entry point defined: `{1}'",
(Parameters[0].ModFlags & ~Parameter.Modifier.PARAMS) == Parameter.Modifier.NONE;
}
+ public override FullNamedExpression LookupNamespaceOrType (string name, Location loc, bool ignore_cs0104)
+ {
+ TypeParameter[] tp = CurrentTypeParameters;
+ if (tp != null) {
+ TypeParameter t = TypeParameter.FindTypeParameter (tp, name);
+ if (t != null)
+ return new TypeParameterExpr (t, loc);
+ }
+
+ return base.LookupNamespaceOrType (name, loc, ignore_cs0104);
+ }
+
public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb, PredefinedAttributes pa)
{
if (a.Type == pa.Conditional) {
return true;
}
+ public override TypeParameter[] CurrentTypeParameters {
+ get {
+ if (GenericMethod != null)
+ return GenericMethod.CurrentTypeParameters;
+
+ return null;
+ }
+ }
+
//
// Creates the type
//
if (!base.Define ())
return false;
+ if (partialMethodImplementation != null && IsPartialDefinition)
+ MethodBuilder = partialMethodImplementation.MethodBuilder;
+
if (RootContext.StdLib && TypeManager.IsSpecialType (ReturnType)) {
- Error1599 (Location, ReturnType);
+ Error1599 (Location, ReturnType, Report);
return false;
}
Report.Debug (64, "METHOD EMIT", this, MethodBuilder, Location, Block, MethodData);
if (IsPartialDefinition) {
//
- // Do attribute checks only when partial implementation does not exist
+ // Use partial method implementation builder for partial method declaration attributes
//
- if (MethodBuilder == null)
- base.Emit ();
-
- return;
- }
-
- if ((ModFlags & Modifiers.PARTIAL) != 0 && (caching_flags & Flags.PartialDefinitionExists) == 0)
+ if (partialMethodImplementation != null) {
+ MethodBuilder = partialMethodImplementation.MethodBuilder;
+ return;
+ }
+ } else if ((ModFlags & Modifiers.PARTIAL) != 0 && (caching_flags & Flags.PartialDefinitionExists) == 0) {
Report.Error (759, Location, "A partial method `{0}' implementation is missing a partial method declaration",
GetSignatureForError ());
+ }
base.Emit ();
return base.EnableOverloadChecks (overload);
}
- public static void Error1599 (Location loc, Type t)
+ public static void Error1599 (Location loc, Type t, Report Report)
{
Report.Error (1599, loc, "Method or delegate cannot return type `{0}'", TypeManager.CSharpName (t));
}
public void SetPartialDefinition (Method methodDefinition)
{
caching_flags |= Flags.PartialDefinitionExists;
- methodDefinition.MethodBuilder = MethodBuilder;
+ methodDefinition.partialMethodImplementation = this;
for (int i = 0; i < methodDefinition.Parameters.Count; ++i ) {
Parameters [i].DefaultValue = methodDefinition.Parameters [i].DefaultValue;
if (attributes == null) {
attributes = methodDefinition.attributes;
- attributes.AttachTo (this);
} else {
attributes.Attrs.AddRange (methodDefinition.attributes.Attrs);
}
if (!Parameters.IsEmpty) {
ArrayList al = (ArrayList)Parent.PartialContainer.MemberCache.Members [Name];
if (al.Count > 1)
- MemberCache.VerifyClsParameterConflict (al, this, MethodBuilder);
+ MemberCache.VerifyClsParameterConflict (al, this, MethodBuilder, Report);
}
return true;
}
}
- public override Expression CreateExpressionTree (EmitContext ec)
+ public override Expression CreateExpressionTree (ResolveContext ec)
{
throw new NotSupportedException ("ET");
}
- public ExpressionStatement Resolve (ConstructorBuilder caller_builder, EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
+ eclass = ExprClass.Value;
+
+ // TODO: ec.GetSignatureForError ()
+ ConstructorBuilder caller_builder = ((Constructor) ec.MemberContext).ConstructorBuilder;
+
if (argument_list != null) {
bool dynamic;
- argument_list.Resolve (ec, out dynamic);
+
+ //
+ // Spec mandates that constructor initializer will not have `this' access
+ //
+ using (ec.Set (ResolveContext.Options.BaseInitializer)) {
+ argument_list.Resolve (ec, out dynamic);
+ }
+
if (dynamic) {
SimpleName ctor = new SimpleName (ConstructorBuilder.ConstructorName, loc);
return new DynamicInvocation (ctor, argument_list, loc).Resolve (ec) as ExpressionStatement;
}
}
+ type = ec.CurrentType;
if (this is ConstructorBaseInitializer) {
- if (ec.ContainerType.BaseType == null)
+ if (ec.CurrentType.BaseType == null)
return this;
- type = ec.ContainerType.BaseType;
- if (TypeManager.IsStruct (ec.ContainerType)) {
- Report.Error (522, loc,
+ type = ec.CurrentType.BaseType;
+ if (TypeManager.IsStruct (ec.CurrentType)) {
+ ec.Report.Error (522, loc,
"`{0}': Struct constructors cannot call base constructors", TypeManager.CSharpSignature (caller_builder));
return this;
}
//
// struct D { public D (int a) : this () {}
//
- if (TypeManager.IsStruct (ec.ContainerType) && argument_list == null)
- return this;
-
- type = ec.ContainerType;
+ if (TypeManager.IsStruct (ec.CurrentType) && argument_list == null)
+ return this;
}
base_constructor_group = MemberLookupFinal (
if (base_constructor_group == null)
return this;
+
+ if (!ec.IsStatic)
+ base_constructor_group.InstanceExpression = ec.GetThis (loc);
ConstructorInfo base_ctor = (ConstructorInfo)base_constructor_group;
-
+
if (base_ctor == caller_builder){
- Report.Error (516, loc, "Constructor `{0}' cannot call itself", TypeManager.CSharpSignature (caller_builder));
+ ec.Report.Error (516, loc, "Constructor `{0}' cannot call itself", TypeManager.CSharpSignature (caller_builder));
}
return this;
}
- public override Expression DoResolve (EmitContext ec)
- {
- throw new NotSupportedException ();
- }
-
public override void Emit (EmitContext ec)
{
// It can be null for static initializers
return;
ec.Mark (loc);
- if (!ec.IsStatic)
- base_constructor_group.InstanceExpression = ec.GetThis (loc);
-
+
base_constructor_group.EmitCall (ec, argument_list);
}
if ((caching_flags & Flags.MethodOverloadsExist) != 0)
Parent.MemberCache.CheckExistingMembersOverloads (this, ConstructorInfo.ConstructorName,
- Parameters);
+ Parameters, Report);
if (Parent.PartialContainer.Kind == Kind.Struct) {
if (Parameters.Count == 0) {
// It's here only to report an error
if (block != null && block.IsIterator) {
member_type = TypeManager.void_type;
- Iterator.CreateIterator (this, Parent.PartialContainer, ModFlags);
+ Iterator.CreateIterator (this, Parent.PartialContainer, ModFlags, Compiler);
}
return true;
base.Emit ();
- EmitContext ec = CreateEmitContext (null, null);
-
//
// If we use a "this (...)" constructor initializer, then
// do not emit field initializers, they are initialized in the other constructor
bool emit_field_initializers = ((ModFlags & Modifiers.STATIC) != 0) ||
!(Initializer is ConstructorThisInitializer);
+ BlockContext bc = new BlockContext (this, block, TypeManager.void_type);
+ bc.Set (ResolveContext.Options.ConstructorScope);
+
if (emit_field_initializers)
- Parent.PartialContainer.ResolveFieldInitializers (ec);
+ Parent.PartialContainer.ResolveFieldInitializers (bc);
if (block != null) {
// If this is a non-static `struct' constructor and doesn't have any
((ModFlags & Modifiers.STATIC) == 0) && (Initializer == null))
block.AddThisVariable (Parent, Location);
- if (!block.ResolveMeta (ec, Parameters))
- block = null;
-
if (block != null && (ModFlags & Modifiers.STATIC) == 0){
if (Parent.PartialContainer.Kind == Kind.Class && Initializer == null)
Initializer = new GeneratedBaseInitializer (Location);
- //
- // Spec mandates that Initializers will not have `this' access
- //
if (Initializer != null) {
- ec.IsStatic = true;
- ExpressionStatement expr = Initializer.Resolve (ConstructorBuilder, ec);
- ec.IsStatic = false;
- block.AddScopeStatement (new StatementExpression (expr));
+ block.AddScopeStatement (new StatementExpression (Initializer));
}
}
}
Parameters.ApplyAttributes (ConstructorBuilder);
-
- SourceMethod source = null;
- if (block == null)
- ec.OmitDebuggingInfo = true;
- else
- source = SourceMethod.Create (Parent, ConstructorBuilder, block);
- bool unreachable = false;
- if (block != null) {
- if (!ec.ResolveTopBlock (null, block, Parameters, this, out unreachable))
- return;
+ SourceMethod source = SourceMethod.Create (Parent, ConstructorBuilder, block);
- ec.EmitMeta (block);
+ if (block != null) {
+ if (block.Resolve (null, bc, Parameters, this)) {
+ EmitContext ec = new EmitContext (this, ConstructorBuilder.GetILGenerator (), bc.ReturnType);
+ ec.With (EmitContext.Options.ConstructorScope, true);
- if (Report.Errors > 0)
- return;
+ if (!ec.HasReturnLabel && bc.HasReturnLabel) {
+ ec.ReturnLabel = bc.ReturnLabel;
+ ec.HasReturnLabel = true;
+ }
- ec.EmitResolvedTopBlock (block, unreachable);
+ block.Emit (ec);
+ }
}
if (source != null)
if (!Parameters.IsEmpty) {
ArrayList al = (ArrayList)Parent.MemberCache.Members [ConstructorInfo.ConstructorName];
if (al.Count > 2)
- MemberCache.VerifyClsParameterConflict (al, this, ConstructorBuilder);
+ MemberCache.VerifyClsParameterConflict (al, this, ConstructorBuilder, Report);
if (TypeManager.IsSubclassOf (Parent.TypeBuilder, TypeManager.attribute_type)) {
foreach (Type param in Parameters.Types) {
}
}
- public EmitContext CreateEmitContext (DeclSpace ds, ILGenerator ig)
+ public EmitContext CreateEmitContext (ILGenerator ig)
{
- ILGenerator ig_ = ConstructorBuilder.GetILGenerator ();
- EmitContext ec = new EmitContext (this, Parent, Location, ig_, TypeManager.void_type, ModFlags, true);
- ec.CurrentBlock = block;
- return ec;
+ throw new NotImplementedException ();
}
public bool IsExcluded()
Attributes OptAttributes { get; }
ToplevelBlock Block { get; set; }
- EmitContext CreateEmitContext (DeclSpace ds, ILGenerator ig);
+ EmitContext CreateEmitContext (ILGenerator ig);
ObsoleteAttribute GetObsoleteAttribute ();
string GetSignatureForError ();
bool IsExcluded ();
this.parent_method = parent_method;
}
- public bool Define (DeclSpace parent, string method_full_name)
+ public bool Define (DeclSpace parent, string method_full_name, Report Report)
{
string name = method.MethodName.Basename;
if (implementing != null)
parent_method = implementing;
- EmitContext ec = method.CreateEmitContext (container, null);
- if (!GenericMethod.DefineType (ec, builder, parent_method, is_override))
+ if (!GenericMethod.DefineType (GenericMethod, builder, parent_method, is_override))
return false;
}
methodbuilder_attrs_field = typeof (MethodBuilder).GetField ("attrs", BindingFlags.NonPublic | BindingFlags.Instance);
methodbuilder_attrs_field.SetValue (builder, flags);
} catch {
- Report.RuntimeMissingSupport (method.Location, "Generic method MethodAttributes");
+ RootContext.ToplevelTypes.Compiler.Report.RuntimeMissingSupport (method.Location, "Generic method MethodAttributes");
}
}
}
//
public void Emit (DeclSpace parent)
{
- ToplevelBlock block = method.Block;
-
- EmitContext ec;
- if (block != null)
- ec = method.CreateEmitContext (parent, builder.GetILGenerator ());
- else
- ec = method.CreateEmitContext (parent, null);
-
method.ParameterInfo.ApplyAttributes (MethodBuilder);
if (GenericMethod != null)
SourceMethod source = SourceMethod.Create (parent, MethodBuilder, method.Block);
- ec.EmitTopBlock (method, block);
+ ToplevelBlock block = method.Block;
+ if (block != null) {
+ BlockContext bc = new BlockContext ((IMemberContext) method, block, method.ReturnType);
+ if (block.Resolve (null, bc, method.ParameterInfo, method)) {
+ EmitContext ec = method.CreateEmitContext (MethodBuilder.GetILGenerator ());
+ if (!ec.HasReturnLabel && bc.HasReturnLabel) {
+ ec.ReturnLabel = bc.ReturnLabel;
+ ec.HasReturnLabel = true;
+ }
+
+ block.Emit (ec);
+ }
+ }
if (source != null) {
method.EmitExtraSymbolInfo (source);
Type base_type = Parent.PartialContainer.BaseCache.Container.Type;
if (base_type != null && Block != null) {
- MethodGroupExpr method_expr = Expression.MethodLookup (Parent.TypeBuilder, base_type, MetadataName, Location);
+ MethodGroupExpr method_expr = Expression.MethodLookup (Parent.Module.Compiler, Parent.TypeBuilder, base_type, MetadataName, Location);
if (method_expr == null)
throw new NotImplementedException ();
method_expr.IsBase = true;
method_expr.InstanceExpression = new CompilerGeneratedThis (Parent.TypeBuilder, Location);
- ToplevelBlock new_block = new ToplevelBlock (Block.StartLocation);
+ ToplevelBlock new_block = new ToplevelBlock (Compiler, Block.StartLocation);
new_block.EndLocation = Block.EndLocation;
Block finaly_block = new ExplicitBlock (new_block, Location, Location);
{
this.ds = generic != null ? generic : (DeclSpace) parent;
this.type_name = type;
- ModFlags = Modifiers.Check (allowed_mod, mod, def_mod, Location);
+ ModFlags = Modifiers.Check (allowed_mod, mod, def_mod, Location, Report);
GenericMethod = generic;
if (GenericMethod != null)
GenericMethod.ModFlags = ModFlags;
if (member_type != null)
throw new InternalErrorException ("Multi-resolve");
- IResolveContext rc = GenericMethod == null ? this : (IResolveContext) ds;
- TypeExpr te = type_name.ResolveAsTypeTerminal (rc, false);
+ TypeExpr te = type_name.ResolveAsTypeTerminal (this, false);
if (te == null)
return false;
return;
if (MemberType.IsSealed && MemberType.IsAbstract) {
- Error_VariableOfStaticClass (Location, GetSignatureForError (), MemberType);
+ Error_VariableOfStaticClass (Location, GetSignatureForError (), MemberType, Report);
}
CheckBase ();
public override void Emit ()
{
+ if (TypeManager.IsDynamicType (member_type))
+ PredefinedAttributes.Get.Dynamic.EmitAttribute (FieldBuilder);
+
if ((ModFlags & Modifiers.COMPILER_GENERATED) != 0 && !Parent.IsCompilerGenerated)
PredefinedAttributes.Get.CompilerGenerated.EmitAttribute (FieldBuilder);
base.Emit ();
}
- public static void Error_VariableOfStaticClass (Location loc, string variable_name, Type static_class)
+ public static void Error_VariableOfStaticClass (Location loc, string variable_name, Type static_class, Report Report)
{
Report.SymbolRelatedToPreviousError (static_class);
Report.Error (723, loc, "`{0}': cannot declare variables of static types",
{
base.DoMemberTypeIndependentChecks ();
- if (!Parent.IsInUnsafeScope)
- Expression.UnsafeError (Location);
+ if (!Parent.IsUnsafe)
+ Expression.UnsafeError (Report, Location);
if (Parent.PartialContainer.Kind != Kind.Struct) {
Report.Error (1642, Location, "`{0}': Fixed size buffer fields may only be members of structs",
public override void Emit()
{
- EmitContext ec = new EmitContext (this, Parent, Location, null, TypeManager.void_type, ModFlags);
- Constant c = size_expr.ResolveAsConstant (ec, this);
+ ResolveContext rc = new ResolveContext (this);
+ Constant c = size_expr.ResolveAsConstant (rc, this);
if (c == null)
return;
- IntConstant buffer_size_const = c.ImplicitConversionRequired (ec, TypeManager.int32_type, Location) as IntConstant;
+ IntConstant buffer_size_const = c.ImplicitConversionRequired (rc, TypeManager.int32_type, Location) as IntConstant;
if (buffer_size_const == null)
return;
Type[] required_modifier = null;
if ((ModFlags & Modifiers.VOLATILE) != 0) {
if (TypeManager.isvolatile_type == null)
- TypeManager.isvolatile_type = TypeManager.CoreLookupType (
+ TypeManager.isvolatile_type = TypeManager.CoreLookupType (Compiler,
"System.Runtime.CompilerServices", "IsVolatile", Kind.Class, true);
if (TypeManager.isvolatile_type != null)
Attributes = attrs;
Location = loc;
Parameters = p;
- ModFlags = Modifiers.Check (AllowedModifiers, mod, 0, loc);
+ ModFlags = Modifiers.Check (AllowedModifiers, mod, 0, loc, RootContext.ToplevelTypes.Compiler.Report);
}
}
}
}
+ public EmitContext CreateEmitContext (ILGenerator ig)
+ {
+ return new EmitContext (this, ig, ReturnType);
+ }
+
public bool IsExcluded ()
{
return false;
public abstract ParametersCompiled ParameterInfo { get ; }
public abstract Type ReturnType { get; }
- public abstract EmitContext CreateEmitContext (DeclSpace ds, ILGenerator ig);
#endregion
if (((ModFlags & Modifiers.DEBUGGER_HIDDEN) != 0))
PredefinedAttributes.Get.DebuggerHidden.EmitAttribute (method_data.MethodBuilder);
+ if (TypeManager.IsDynamicType (ReturnType)) {
+ return_attributes = new ReturnParameter (method_data.MethodBuilder, Location);
+ return_attributes.EmitPredefined (PredefinedAttributes.Get.Dynamic, Location);
+ }
+
if (OptAttributes != null)
OptAttributes.Emit ();
method_data = new MethodData (method, ModFlags, flags, this);
- if (!method_data.Define (parent, method.GetFullName (MemberName)))
+ if (!method_data.Define (parent, method.GetFullName (MemberName), Report))
return null;
return method_data.MethodBuilder;
public override MethodBuilder Define (DeclSpace parent)
{
- parameters.Resolve (ResolveContext);
+ parameters.Resolve (this);
base.Define (parent);
method_data = new MethodData (method, ModFlags, flags, this);
- if (!method_data.Define (parent, method.GetFullName (MemberName)))
+ if (!method_data.Define (parent, method.GetFullName (MemberName), Report))
return null;
return method_data.MethodBuilder;
CheckAbstractAndExtern (block != null);
if (block != null && block.IsIterator)
- Iterator.CreateIterator (this, Parent.PartialContainer, ModFlags);
+ Iterator.CreateIterator (this, Parent.PartialContainer, ModFlags, Compiler);
return null;
}
}
}
- public override EmitContext CreateEmitContext (DeclSpace ds, ILGenerator ig)
- {
- return new EmitContext (this,
- ds, method.ds, method.Location, ig, ReturnType,
- method.ModFlags, false);
- }
-
public override ObsoleteAttribute GetObsoleteAttribute ()
{
return method.GetObsoleteAttribute ();
if ((caching_flags & Flags.MethodOverloadsExist) == 0)
return true;
- return Parent.MemberCache.CheckExistingMembersOverloads (this, Name, ParameterInfo);
+ return Parent.MemberCache.CheckExistingMembersOverloads (this, Name, ParameterInfo, Report);
}
}
// case, we do not actually emit the ".property", so there is nowhere to
// put the attribute
//
- if (PropertyBuilder != null && OptAttributes != null)
- OptAttributes.Emit ();
+ if (PropertyBuilder != null) {
+ if (OptAttributes != null)
+ OptAttributes.Emit ();
+
+ if (TypeManager.IsDynamicType (member_type))
+ PredefinedAttributes.Get.Dynamic.EmitAttribute (PropertyBuilder);
+ }
if (!Get.IsDummy)
Get.Emit (Parent);
fe.InstanceExpression = new CompilerGeneratedThis (fe.Type, Location);
// Create get block
- Get.Block = new ToplevelBlock (ParametersCompiled.EmptyReadOnlyParameters, Location);
+ Get.Block = new ToplevelBlock (Compiler, ParametersCompiled.EmptyReadOnlyParameters, Location);
Return r = new Return (fe, Location);
Get.Block.AddStatement (r);
// Create set block
- Set.Block = new ToplevelBlock (Set.ParameterInfo, Location);
+ Set.Block = new ToplevelBlock (Compiler, Set.ParameterInfo, Location);
Assign a = new SimpleAssign (fe, new SimpleName ("value", Location));
Set.Block.AddStatement (new StatementExpression (a));
}
if ((method.ModFlags & Modifiers.STATIC) == 0)
f_expr.InstanceExpression = new CompilerGeneratedThis (field_info.FieldType, Location);
- block = new ToplevelBlock (ParameterInfo, Location);
+ block = new ToplevelBlock (Compiler, ParameterInfo, Location);
block.AddStatement (new StatementExpression (
new CompoundAssign (Operation,
f_expr,
method_data = new MethodData (method, method.ModFlags,
method.flags | MethodAttributes.HideBySig | MethodAttributes.SpecialName, this);
- if (!method_data.Define (parent, method.GetFullName (MemberName)))
+ if (!method_data.Define (parent, method.GetFullName (MemberName), Report))
return null;
MethodBuilder mb = method_data.MethodBuilder;
}
}
- public override EmitContext CreateEmitContext (DeclSpace ds, ILGenerator ig)
- {
- return new EmitContext (
- this, method.Parent, Location, ig, ReturnType,
- method.ModFlags, false);
- }
-
public override ObsoleteAttribute GetObsoleteAttribute ()
{
return method.GetObsoleteAttribute ();
public override MethodBuilder Define (DeclSpace parent)
{
- parameters.Resolve (ResolveContext);
+ parameters.Resolve (this);
return base.Define (parent);
}
protected override bool CheckForDuplications ()
{
- return Parent.MemberCache.CheckExistingMembersOverloads (this, GetFullName (MemberName), parameters);
+ return Parent.MemberCache.CheckExistingMembersOverloads (this, GetFullName (MemberName), parameters, Report);
}
public override bool Define ()
// imlicit and explicit operator of same types are not allowed
if (OperatorType == OpType.Explicit)
- Parent.MemberCache.CheckExistingMembersOverloads (this, GetMetadataName (OpType.Implicit), Parameters);
+ Parent.MemberCache.CheckExistingMembersOverloads (this, GetMetadataName (OpType.Implicit), Parameters, Report);
else if (OperatorType == OpType.Implicit)
- Parent.MemberCache.CheckExistingMembersOverloads (this, GetMetadataName (OpType.Explicit), Parameters);
+ Parent.MemberCache.CheckExistingMembersOverloads (this, GetMetadataName (OpType.Explicit), Parameters, Report);
Type declaring_type = MethodData.DeclaringType;
Type return_type = MemberType;
Type first_arg_type_unwrap = first_arg_type;
if (TypeManager.IsNullableType (first_arg_type))
- first_arg_type_unwrap = TypeManager.GetTypeArguments (first_arg_type) [0];
+ first_arg_type_unwrap = TypeManager.TypeToCoreType (TypeManager.GetTypeArguments (first_arg_type) [0]);
Type return_type_unwrap = return_type;
if (TypeManager.IsNullableType (return_type))
- return_type_unwrap = TypeManager.GetTypeArguments (return_type) [0];
+ return_type_unwrap = TypeManager.TypeToCoreType (TypeManager.GetTypeArguments (return_type) [0]);
+
+ if (TypeManager.IsDynamicType (return_type) || TypeManager.IsDynamicType (first_arg_type)) {
+ Report.Error (1964, Location,
+ "User-defined operator `{0}' cannot convert to or from the dynamic type",
+ GetSignatureForError ());
+
+ return false;
+ }
//
// Rules for conversion operators