**** Merged r40732-r40872 from MCS ****
authorMartin Baulig <martin@novell.com>
Tue, 22 Mar 2005 10:12:21 +0000 (10:12 -0000)
committerMartin Baulig <martin@novell.com>
Tue, 22 Mar 2005 10:12:21 +0000 (10:12 -0000)
svn path=/trunk/mcs/; revision=42082

1  2 
mcs/gmcs/ChangeLog
mcs/gmcs/OPTIMIZE
mcs/gmcs/attribute.cs
mcs/gmcs/class.cs
mcs/gmcs/constant.cs
mcs/gmcs/driver.cs
mcs/gmcs/ecore.cs
mcs/gmcs/expression.cs
mcs/gmcs/iterators.cs
mcs/gmcs/literal.cs
mcs/gmcs/rootcontext.cs

index bce9deb7b2a47cdc4c3abb805d8d1d0d76a09b26,973569a3d2ba6efb3bea69bdce29d287b59fbbc6..8457cd836766cb61a9c5ff50db380ebab615af27
++2005-02-18  Marek Safar  <marek.safar@seznam.cz>
++
++      * class.cs (EmitFieldInitializers): Don't emit field initializer
++      for default values when optimilization is on.
++      
++      * constant.cs (Constant.IsDefaultValue): New property.
++      
++      * driver.cs: Add /optimize handling.
++      
++      * constant.cs,
++      * ecore.cs,
++      * literal.cs: Implement new IsDefaultValue property.
++      
++      * rootcontext.cs (Optimize): New field, holds /optimize option.
++
++2005-02-18  Raja R Harinath  <rharinath@novell.com>
++
++      Fix crasher in re-opened #72347.
++      * namespace.cs (Namespace.Lookup): Return null if
++      DeclSpace.DefineType returns null.
++
++      Fix #72678.
++      * expression.cs (Argument.Resolve): Handle a case of CS0120 here.
++
++2005-02-18  Raja R Harinath  <rharinath@novell.com>
++
++      Fix remainder of #63202.  Change semantics of DoResolveLValue: it
++      now returns null if it cannot resolve to an lvalue.
++      * ecore.cs (Expression.DoResolveLValue): Return 'null' by default.
++      (Expression.ResolveLValue): Emit CS0131 error if DoResolveLValue
++      returned null.  Remove check for SimpleName.
++      (EventExpr.DoResolveLValue): New.
++      * iterators.cs (Iterator.FieldExpression.DoResolveLValue): New.
++      * expression.cs (Argument.Error_LValueRequired): New.  Move CS1510
++      error from ...
++      (Argument.Resolve): ... here.  Use it.  Use DoResolveLValue to
++      avoid CS0131 error.
++      (Unary.ResolveOperator): Move CS0211 check ...
++      (Unary.DoResolve): ... here.  Use DoResolveLValue to avoid
++      CS0131 error.
++      (Unary.DoResolveLValue): Simplify.
++      (AddressOf.DoResolveLValue): New.
++      (ArrayAccess.DoResolveLValue): New.
++
++2005-02-16  Marek Safar  <marek.safar@seznam.cz>
++
++      * attribute.cs (Attribute.Resolve): Add arguments casting for
++      when types doesn't match ctor arguments.
++
++2005-02-16  Raja R Harinath  <rharinath@novell.com>
++
++      Fix parts of #63202.
++      * expression.cs (UnaryMutator.ResolveOperator): Remove redundant
++      lookup of operator in base type.  Ensure that all checks happen
++      when the operator resolves to an "op_..." method.
++
 +2005-02-15  Raja R Harinath  <rharinath@novell.com>
 +
 +      Fix #71992.
 +      * namespace.cs (NamespaceEntry.LookupNamespaceOrType): Add
 +      'ignore_cs0104' parameter.  Pass it to ...
 +      (NamespaceEntry.Lookup): ... this.
 +      * decl.cs (DeclSpace.LookupType): Add 'ignore_cs0104' parameter.
 +      * ecore.cs (SimpleName.ResolveAsTypeStep): Update.
 +      (TypeLookupExpression.DoResolveAsTypeStep): Update.
 +      * expression.cs (MemberAccess.IdenticalNameAndTypeName):
 +      Update.  Request that cs0104 errors be ignored.
 +      (ComposedCast.ResolveAsTypeStep): Update.
 +
 +2005-02-14  Raja R Harinath  <rharinath@novell.com>
 +
 +      Fix #59209.
 +      * expression.cs (Invocation.BetterFunction): Remove support for
 +      comparing virtual functions and their overrides.
 +      (Invocation.IsOverride): New.
 +      (Invocation.OverloadResolve): Don't consider 'override' functions
 +      during candidate selection.  Store them in a lookaside list.
 +      If the selected method is a 'virtual' function, use the list to
 +      find any overrides that are closer to the LHS type.
 +
 +2005-02-14  Marek Safar  <marek.safar@seznam.cz>
 +
 +      * expression.cs (New.DoResolve): Add complex core type reduction.
 +      (New.Constantify): Converts complex core type syntax like 'new int ()'
 +      to simple constant.
 +      
 +2005-02-14  Raja R Harinath  <rharinath@novell.com>
 +
 +      * decl.cs (EntryType.EntryType): New constructor to create an
 +      updated copy of a cache entry.
 +      (MemberCache.AddMethods): Use it.
 +      (MemberCache.ClearDeclaredOnly): Remove.
 +      (MemberCache.MemberCache): Update.
 +
 +2005-02-11  Miguel de Icaza  <miguel@novell.com>
 +
 +      * codegen.cs (EmitContext): Introduce the `MethodIsStatic'
 +      variable.  This one is represents the actual low-level declaration
 +      of the method, as opposed to the semantic level `IsStatic'.   
 +
 +      An anonymous method which is hosted into a static method might be
 +      actually an instance method.  IsStatic would reflect the
 +      container, while MethodIsStatic represents the actual code
 +      generated.
 +
 +      * expression.cs (ParameterReference): Use the new MethodIsStatic
 +      instead of IsStatic.
 +
 +      * anonymous.cs (AnonymousMethod.Compatible): Pass the
 +      Modifiers.STATIC to the Anonymous' Method EmitContext if static is
 +      set on the current EmitContext. 
 +
 +      * expression.cs (Cast): Overload DoResolveLValue so we can pass
 +      resolve our casted expression as an LValue.  This triggers the
 +      proper LValue processing that is later required by Assign.
 +
 +      This fixes 72347.
 +
 +      * cs-tokenizer.cs (pp_and): recurse on pp_and, fixes #61903.
 +
 +2005-02-11  Marek Safar  <marek.safar@seznam.cz>
 +
 +      C# 2.0 Fixed buffer implementation
 +
 +      * anonymous.cs: Update after RegisterHelperClass renaming.
 +
 +      * attribute.cs (AttributeTester.fixed_buffer_cache):
 +      Cache of external fixed buffers.
 +      (AttributeTester.GetFixedBuffer): Returns IFixedBuffer
 +      implementation if field is fixed buffer else null.
 +
 +      * class.cs
 +      (TypeContainer.AddField): Accept FieldMember instead of Field.
 +      (FieldBase.IsFieldClsCompliant): Extracted code from
 +      VerifyClsCompliance descendant customization.
 +      (FixedField): New class handles fixed buffer fields.
 +      (FixedFieldExternal): Keeps information about imported fixed
 +      buffer.
 +      (IFixedField): Make access to internal or external fixed buffer
 +      same.
 +
 +      * cs-parser.jay: Add fixed buffer parsing.
 +
 +      * ecore.cs (FieldExpr.Emit): Add special emit case for fixed
 +      buffer.
 +
 +      * expression.cs (Indirection): Extended implementation to accept
 +      fixed buffer field.
 +      (PointerArithmetic.Emit): Get element from fixed buffer as well.
 +      (ElementAccess.MakePointerAccess): Get type as parameter.
 +      (DoResolve): Add fixed buffer field expression conversion.
 +      (DoResolveLValue): Ditto.
 +      (FixedBufferPtr): New class. Moved most of original ArrayPtr.
 +      (ArrayPtr): Derives from FixedBufferPtr.
 +      (ArrayPtr.Emit): Add extra emit for array elements.
 +
 +      * flowanalysis.cs.cs (StructInfo): Use FieldMember.
 +
 +      * rootcontext.cs (CloseTypes): Emit CompilerGenerated attribute
 +      for compiler generated types.
 +      (RegisterCompilerGeneratedType): Renamed from RegisterHelperClass.
 +
 +      * statement.cs (Fixed): Refactored to be easier add fixed buffer
 +      and consume less memory.
 +      (Fixed.Resolve): Add fixed buffer case.
 +
 +      * typemanager.cs (compiler_generated_attr_ctor,
 +      fixed_buffer_attr_ctor): Add new 2.0 compiler attributes.
 +      (HasElementType): Add our own implementation to work on every
 +      runtime.
 +
 +2005-02-11  Miguel de Icaza  <miguel@novell.com>
 +
 +      * anonymous.cs (CaptureContext): Track whether `this' has been
 +      referenced.   
 +
 +      * expression.cs (This.ResolveBase): Call CaptureThis.  Before we
 +      only captured `this' if it was implicitly done (instance
 +      methods/variables were used). 
 +
 +      * codegen.cs (EmitContext.CaptureThis): New method to flag that
 +      `this' must be captured.
 +
 +2005-01-30  Miguel de Icaza  <miguel@novell.com>
 + 
 +      * anonymous.cs (CreateMethodHost): If there Scope.ScopeTypeBuilder
 +      is null it means that there has been no need to capture anything,
 +      so we just create a sibling.
 +
 +      Renamed `EmitHelperClasses' to `EmitAnonymousHelperClasses'
 +
 +      Just a partial fix.  The other half is fairly elusive.
 +      
 +2005-02-10  Raja R Harinath  <rharinath@novell.com>
 +
 +      Fix #52586, cs0121-4.cs.
 +      * decl.cs (MemberCache.DeepCopy): Rename from SetupCache.  Take
 +      and return a hashtable.
 +      (MemberCache.ClearDeclaredOnly): New.
 +      (MemberCache.MemberCache): Update to change.  Make a deep copy of
 +      the method_hash of a base type too.
 +      (MemberCache.AddMethods): Adapt to having a deep copy of the base
 +      type methods.  Overwrite entries with the same MethodHandle so
 +      that the ReflectedType is correct.  The process leaves in base
 +      virtual functions and their overrides as distinct entries.
 +      (CacheEntry): Now a class instead of a struct.  It shouldn't alter
 +      matters since it was boxed in a ArrayList before.
 +      (CacheEntry.Member, CacheEntry.EntryType): Remove 'readonly'
 +      modifier.
 +      * expression.cs (Invocation.BetterFunction): Simplify.  Handle the
 +      case of a virtual function and its override (choose the overload
 +      as better).
 +      (Invocation.OverloadResolve): Avoid 'override' members during
 +      'applicable_type' calculation.
 +
 +2005-02-09  Raja R Harinath  <rharinath@novell.com>
 +
 +      Combine two near-redundant caches.
 +      * typemanager.cs (method_params): Rename from method_internal_params.
 +      (TypeManager.GetParameterData): New.  Replace
 +      Invocation.GetParameterData.
 +      (TypeManager.LookupParametersByBuilder): Remove.
 +      * expression.cs (Invocation.method_parameter_cache): Remove.
 +      (Invocation.GetParameterData): Remove.
 +      Update to changes.
 +      * anonymous.cs, attribute.cs, convert.cs, delegate.cs:
 +      Update to changes.
 +
 +2005-02-08  Raja R Harinath  <rharinath@novell.com>
 +
 +      Fix #72015.
 +      * delegate.cs (Delegate.DefineType): When bootstrapping corlib, if
 +      TypeManager.multicast_delegate_type is null, resolve it by looking
 +      up "System.MulticastDelegate".
 +      * rootcontext.cs (RootContext.ResolveCore): Simplify.
 +
 +2005-02-07  Abin Thomas (NOSIP)  <projectmonokochi@rediffmail.com>
 +          Anoob V.E (NOSIP)  <projectmonokochi@rediffmail.com>
 +          Harilal P.R (NOSIP)  <projectmonokochi@rediffmail.com>
 +
 +      Fix cs0164.cs.
 +      * statement.cs (LabeledStatement.Resolve): Don't set 'referenced'.
 +      (LabeledStatement.AddReference): New.  Set 'referenced'.
 +      (Goto.Resolve): Use it.
 +
 +2005-02-05  John Luke  <john.luke@gmail.com>
 +
 +      * driver.cs: remove duplicate -doc line in Usage ()
 +
 +2005-02-04  Raja R Harinath  <rharinath@novell.com>
 +
 +      * location.cs (Location.AddFile): Fix CS2002 error report.
 +
 +2005-02-02  Martin Baulig  <martin@ximian.com>
 +
 +      * delegate.cs (Delegate.DefineType): Report an internal error if
 +      TypeManager.multicast_delegate_type is null.  See bug #72015 for
 +      details.        
 +
 +2005-02-02  Raja R Harinath  <rharinath@novell.com>
 +
 +      Fix a crasher in a variant of #31984.
 +      * const.cs (Constant.CheckBase): New override that defers the
 +      new-or-override check in case the base type hasn't been populated
 +      yet.
 +      (Constant.Define): Ensure the new-or-override check is performed.
 +
 +2005-02-01  Duncan Mak  <duncan@ximian.com>
 +
 +      * const.cs (LookupConstantValue): Check that `ce' is not null
 +      before calling GetValue ().
 +
 +2005-02-01  Raja R Harinath  <rharinath@novell.com>
 +
 +      Fix test-334.cs (#69519).
 +      * cs-parser.jay (using_alias_directive): Pass in an expression to
 +      NamespaceEntry.UsingAlias.
 +      (using_namespace_directive): Pass in an expression to
 +      NamespaceEntry.Using.
 +      (namespace_name): Don't flatten to a string.
 +      * namespace.cs (NamespaceEntry.AliasEntry): Store an expression.
 +      (NamespaceEntry.AliasEntry.Resolve): Lookup using
 +      ResolveAsTypeStep.
 +      (NamespaceEntry.UsingEntry): Likewise.
 +      (NamespaceEntry.Using,NamespaceEntry.UsingAlias): Update to
 +      changes.
 +      (NamespaceEntry.LookupForUsing): Remove.
 +      (NamespaceEntry.LookupNamespaceOrType): Add support for dotted
 +      names.
 +      (NamespaceEntry.Lookup): Remove support for dotted names.
 +
 +2005-02-01  Raja R Harinath  <rharinath@novell.com>
 +
 +      * namespace.cs (NamespaceEntry.NamespaceEntry): Simplify, and
 +      split into two.
 +      (NamespaceEntry.ImplicitParent): Compute on demand.
 +      (NamespaceEntry.Doppelganger): New implicit namespace-entry that
 +      parallels the current.
 +      (NamespaceEntry.LookupForUsing): Use it.
 +      (NamespaceEntry.Lookup): If the current namespace-entry is
 +      implicit, don't search aliases and using tables.
 +
 +2005-02-01  Raja R Harinath  <rharinath@novell.com>
 +
 +      Fix #31984.
 +      * class.cs (TypeContainer.DoDefineMembers): Don't initialize
 +      BaseCache here.
 +      (TypeContainer.BaseCache): Compute on demand.
 +      (TypeContainer.FindMembers): Define constants and types if they're
 +      not already created.
 +      (FieldMember.Define): Move resetting of ec.InUnsafe before error
 +      check.
 +      * const.cs (Constant.Define): Make idempotent.
 +
 +2005-01-29  Miguel de Icaza  <miguel@novell.com>
 +
 +      * pending.cs: Produce better code (no nops produced by using Ldarg
 +      + value).
 +      
 +      * pending.cs (PendingImplementation.DefineProxy): It was not `arg
 +      i - 1' it should be arg + 1.
 +
 +      Fixes bug #71819.
 +
 +2005-01-28  Raja R Harinath  <rharinath@novell.com>
 +
 +      * attribute.cs (Attribute.CheckAttributeType): Make private
 +      non-virtual.
 +      (Attribute.ResolveType): Make virtual.
 +      (GlobalAttribute.ResolveType,GlobalAttribute.Resolve): Simplify
 +      handling of RootContext.Tree.Types.
 +
 +2005-01-27  Raja R Harinath  <rharinath@novell.com>
 +
 +      Update attribute-handling to use the SimpleName/MemberAccess
 +      mechanisms.
 +      * cs-parser.jay (attribute): Pass in an expression to the
 +      constructors of Attribute and GlobalAttribute.
 +      * attribute.cs (Attribute): Take an expression for the name.
 +      (Attribute.ResolvePossibleAttributeTypes): New.  Resolves the
 +      passed in attribute name expression.
 +      (Attribute.CheckAttributeType): Use it.
 +      * ecore.cs (FullNamedExpression.ResolveAsTypeStep): New.
 +      * expression.cs (MemberAccess.ResolveAsTypeStep): Move body to ...
 +      (MemberAccess.ResolveNamespaceOrType): ... here.  Add 'silent'
 +      argument to prevent error messages if the lookup fails.
 +
 +2005-01-27  Marek Safar  <marek.safar@seznam.cz>
 +
 +      * expression.cs (Indirection): Implemented IVariable interface
 +      to support indirection in AddressOf operator.
 +      (PointerArithmetic.Emit): Add optimalization for case where
 +      result can be precomputed.
 +
 +2005-01-26  Martin Baulig  <martin@ximian.com>
 +
 +      * class.cs (TypeContainer.AttributeTargets): Return the correct
 +      AttributeTargets depending on our `Kind' instead of throwing an
 +      exception; fixes #71632.
 +
 +2005-01-26  Marek Safar  <marek.safar@seznam.cz>
 +
 +      Fix #71257
 +      * expression.cs (MemberAccess.ResolveMemberAccess): Add CS0176 test for
 +      constant members.
 +
 +2005-03-17  Martin Baulig  <martin@ximian.com>
 +
 +      * anonymous.cs (AnonymousMethod.method_modifiers): Change default
 +      from `Modifiers.INTERNAL' to `Modifiers.PRIVATE'.  Fixes #73260.
 +
 +2005-03-17  Martin Baulig  <martin@ximian.com>
 +
 +      * anonymous.cs (AnonymousMethod.EmitMethod): Changed return type
 +      to bool so we can return an error condition.
 +      (AnonymousDelegate.Emit): Check whether AnonymousMethod.EmitMethod()
 +      returned an error.
 +
 +2005-03-17  Martin Baulig  <martin@ximian.com>
 +
 +      * generic.cs (TypeMananager.IsIEnumerable): New public method.
 +
 +      * convert.cs (Convert.ImplicitReferenceConversion(Exists)): Allow
 +      converting from an array-type of T to `IEnumerable<T>'.
 +
 +2005-03-16  Martin Baulig  <martin@ximian.com>
 +
 +      * generic.cs (Nullable.Unwrap): Implement IAssignMethod.
 +      (Nullable.LiftedUnaryMutator): New public class.
 +
 +      * expression.cs (UnaryMutator.DoResolve): Added support for
 +      Nullable Types.
 +
 +2005-03-14  Martin Baulig  <martin@ximian.com>
 +
 +      * generic.cs (Nullable.NullCoalescingOperator): Implemented.
 +
 +2005-03-14  Martin Baulig  <martin@ximian.com>
 +
 +      * generic.cs (Nullable.LiftedBinaryOperator): Added support for
 +      the comparision operators `<', `>', `<=' and `>='.
 +
 +2005-03-13  Martin Baulig  <martin@ximian.com>
 +
 +      * generic.cs
 +      (Nullable.NullLiteral): Renamed to `Nullable.NullableLiteral' to
 +      avoid confusion with the `NullLiteral'.
 +      (Nullable.LiftedBinaryOperator): Correctly implement `==' and '!='.
 +
 +2005-03-13  Martin Baulig  <martin@ximian.com>
 +
 +      * expression.cs (Binary.ResolveOperator): For `==' and `!=', allow
 +      comparing arbitrary types with the null literal.
 +
 +2005-03-13  Martin Baulig  <martin@ximian.com>
 +
 +      * generic.cs (Nullable.LiftedBinaryOperator): Add support for the
 +      boolean operators '&&', '||', '&' and '|'.
 +      (Nullable.OperatorTrueOrFalse): New public class.
 +
 +      * ecore.cs (Expression.GetOperatorTrue/False): Return an `Expression'
 +      instead of a `StaticCallExpr'; added support for nullables.
 +
 +2005-03-10  Martin Baulig  <martin@ximian.com>
 +
 +      * expression.cs
 +      (ArrayAccess.EmitDynamicInitializers): Use `etype.IsValueType'
 +      rather than `etype.IsSubclassOf (TypeManager.value_type)'.      
 +
 +2005-03-07  Martin Baulig  <martin@ximian.com>
 +
 +      * generic.cs (Nullable.Unwrap): Implement IMemoryLocation and make
 +      it work if `expr' is not an IMemoryLocation.
 +      (Nullable.Lifted): Implement IMemoryLocation.
 +      (Nullable.LiftedConversion.ResolveUnderlying): Use the correct
 +      target type.
 +
 +2005-03-05  Martin Baulig  <martin@ximian.com>
 +
 +      * generic.cs (Nullable.Unwrap, Wrap): New protected classes.
 +      (Nullable.Lifted): New abstract class; rewrote the lifted conversions.
 +      (Nullable): Added support for lifted unary and binary operators.
 +
 +      * expression.cs (Unary.DoResolve): Added support for nullable types.
 +      (Binary.DoResolve): Likewise.
 +      (Conditional.DoResolve): Likewise.
 +
 +2005-03-02  Martin Baulig  <martin@ximian.com>
 +
 +      * decl.cs (DeclSpace.SetParameterInfo): Make this virtual.
 +
 +      * class.cs (ClassPart.SetParameterInfo): Override this.
 +      (PartialContainer.SetParameterInfo): Override this.
 +      (TypeContainer.CheckConstraints): New protected method.
 +      (PartialContainer.CheckConstraints): Override this and check
 +      whether the same contraints were specified in all parts of a
 +      partial generic type definition.
 +      (PartialContainer.UpdateConstraints): New public method.
 +
 +      * generic.cs (TypeParameter.UpdateConstraints): New public method.
 +
 +2005-03-02  Martin Baulig  <martin@ximian.com>
 +
 +      Committing a patch from Carlos Alberto Cortez to fix #72887.
 +
 +      * convert.cs (Convert.ExplicitReferenceConversionExists): Allow
 +      casts from `T []' to `int []'.
 +
 +2005-03-02  Martin Baulig  <martin@ximian.com>
 +
 +      * generic.cs (TypeManager.IsEqual): Make this symmetric.
 +
 +      * expression.cs (Binary.ResolveOperator): When resolving a
 +      BinaryDelegate, use `TypeManager.IsEqual (l, r)' rather than just
 +      `=='.  Fixes #71866.  See gen-127.cs.
 +
 +2005-03-02  Martin Baulig  <martin@ximian.com>
 +
 +      * class.cs (TypeContainer.DoDefineMembers): We also need a default
 +      static constructor in static classes.
 +
 +2005-03-02  Martin Baulig  <martin@ximian.com>
 +
 +      * generic.cs
 +      (NullableType.Name, NullableType.FullName): Add a "?" to the name.
 +      (Nullable.LiftedConversion): Added support for user-defined
 +      conversions.
 +
 +      * cs-tokenizer.cs (Tokenizer.PutbackCloseParens): New public method.
 +
 +      * cs-parser.jay: Use ComposedCast everywhere instead of
 +      NullableType, so we don't need to check for NullableType
 +      everywhere.
 +      (conditional_expression): Added `INTERR CLOSE_PARENS' rule for the
 +      case where we'll be resolved into a `parenthesized_expression_0'
 +      afterwards.
 +
 +      * convert.cs
 +      (Convert.UserDefinedConversion): Added nullable conversions.
 +
 +2005-02-28  Martin Baulig  <martin@ximian.com>
 +
 +      * generic.cs (TypeManager.IsNullableType): New static method.
 +      (Nullable): New abstract class.
 +      (Nullable.NullLiteral): New public class.
 +      (Nullable.LiftedConversion): New public class.
 +
 +      * cs-parser.jay (non_expression_type): Changed `builtin_types' to
 +      `builtin_types opt_nullable'.
 +
 +      * convert.cs
 +      (Convert.ImplicitConversionStandard): Added nullable conversions.
 +      (Convert.ExplicitConversionStandard): Likewise.
 +      (Convert.ExplicitConversion): Likewise.
 +
 +2005-02-26  Martin Baulig  <martin@ximian.com>
 +
 +      * expression.cs (ComposedCast.DoResolveAsTypeStep): Allow `dim' to
 +      begin with a "?", for instance "?[]".  Don't do a type lookup if
 +      `dim' is empty.
 +
 +2005-02-25  Martin Baulig  <martin@ximian.com>
 +
 +      The first part of Nullable Types :-)
 +
 +      * generic.cs (NullableType): New public class.
 +      (NullCoalescingOperator): New public class.
 +      (TypeArguments.Resolve): Add a CS0306 check.
 +
 +      * cs-parser.jay (opt_error_modifier): Removed, this was unused.
 +      (opt_nullable): New rule.
 +      (type): Added `opt_nullable' to `namespace_or_type_name',
 +      `builtin_types' and `pointer_type'.
 +      (array_type): Added `opt_nullable'.
 +      (opt_rank_specifier_or_nullable): New rule; this is the
 +      combination of `opt_rank_specifier' and `opt_nullable'.
 +      (opt_error): New rule; catch errors here.
 +      (nullable_type_or_conditional): New rule; we use this to check for
 +      nullable and still detect the conditional operator.
 +      (local_variable_type): Use `opt_rank_specifier_or_nullable'
 +      instead `opt_rank_specifier'.
 +
 +      * expression.cs (ComposedCast.DoResolveAsTypeStep): Added support
 +      for nullables.
 +
 +2005-02-24  Martin Baulig  <martin@ximian.com>
 +
 +      * README, README.Changes: Removed; they're old and obsolete.
 +
 +2005-02-22  Martin Baulig  <martin@ximian.com>
 +
 +      * generic.cs (TypeParameter.Resolve): If resolving the constraints
 +      returned an error, set `constraints' to null to avoid a crash
 +      later on.
 +      (TypeParameter.ResolveType): Likewise.
 +
 +2005-02-22  Martin Baulig  <martin@ximian.com>
 +
 +      * generic.cs
 +      (Constraints.ResolveTypes): Protect against being called twice.
 +      (Constraints.CheckInterfaceMethod): Don't call ResolveTypes().
 +      (TypeParameter.ResolveType): New public method; calls
 +      constraints.ResolveTypes().
 +      (TypeParameter.DefineType): Moved constraints.ResolveType() out
 +      into the new ResolveType().
 +      (GenericMethod.Define): Call ResolveType() on all our
 +      TypeParameter's.        
 +
 +2005-02-21  Martin Baulig  <martin@ximian.com>
 +
 +      * generic.cs
 +      (TypeManager.generic_nullable_type): New static public field.
 +      (TypeManager.InitGenericCoreType): Lookup "System.Nullable`1".
 +
 +      * rootcontext.cs
 +      (RootContext.ResolveCore): Resolve "System.Nullable`1".
 +
  2005-02-15  Martin Baulig  <martin@ximian.com>
  
        * generic.cs (ConstructedType.Constraints): Correctly check
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..6fa1e31e9477610de21b983da451900d5b07ddec
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,26 @@@
++This document describes all code optimalizations performed by Mono C# compiler
++when optimalizations are enabled via /optimize+ option.
++
++Optimalizations:
++
++* Instance field initializer to default value
++---------------------------------------------
++
++Code to optimize:
++
++class C
++{
++    enum E
++    {
++      Test
++    }
++    
++    int i = 0;  // Field will not be redundantly assigned
++    int i2 = new int (); // This will be also completely optimized out
++    
++    E e = E.Test; // Even this will go out.
++    
++}
++
++
++
index 0451f60cb2b1c882cba36dc3f6a8a4dfac65c086,30d6a61dcced525a185d747c6f7662f4d3588d41..1e6a5e7137de37b6d05da6e358f8c85cbe364144
@@@ -572,6 -544,6 +572,16 @@@ namespace Mono.CSharp 
                                        return null;
                                }
  
++                              object value = pos_values [j];
++                              if (value != null && a.Type != value.GetType () && a.Type.IsPrimitive) {
++                                      bool fail;
++                                      pos_values [j] = TypeManager.ChangeType (value, a.Type, out fail);
++                                      if (fail) {
++                                              // TODO: Can failed ?
++                                              throw new NotImplementedException ();
++                                      }
++                              }
++
                                if (j < last_real_param)
                                        continue;
                                
index 6027fe321f6e7e56c76e966cf4bf08f0f079ce55,4162d78065bf9d763a790e028271cc3e087aa921..568fe966540b13b7a4cb02e3f7b72e9a2108d128
@@@ -866,6 -866,6 +866,14 @@@ namespace Mono.CSharp 
                                if (a == null)
                                        return false;
  
++                              if (RootContext.Optimize) {
++                                      Constant c = e as Constant;
++                                      if (c != null) {
++                                              if (c.IsDefaultValue)
++                                                      continue;
++                                      }
++                              }
++
                                a.EmitStatement (ec);
                        }
  
index 73de93f06f273af931fca1d08ccc103eaea55966,73de93f06f273af931fca1d08ccc103eaea55966..576c18a3b8f468b31ce02459bcd0f851ae980653
@@@ -162,6 -162,6 +162,10 @@@ namespace Mono.CSharp 
                        return null;
                }
                
++              public abstract bool IsDefaultValue {
++                      get;
++              }
++
                public abstract bool IsNegative {
                        get;
                }
                                ec.ig.Emit (OpCodes.Ldc_I4_0);
                }
                
++              public override bool IsDefaultValue {
++                      get {
++                              return !Value;
++                      }
++              }
++
                public override bool IsNegative {
                        get {
                                return false;
                        return new IntConstant (Value);
                }
                
++              public override bool IsDefaultValue {
++                      get {
++                              return Value == 0;
++                      }
++              }
++
                public override bool IsNegative {
                        get {
                                return false;
                        return new IntConstant (Value);
                }
                
++              public override bool IsDefaultValue {
++                      get {
++                              return Value == 0;
++                      }
++              }
++
                public override bool IsNegative {
                        get {
                                return false;
                        return new IntConstant (Value);
                }
                
++              public override bool IsDefaultValue {
++                      get {
++                              return Value == 0;
++                      }
++              }
++
                public override bool IsNegative {
                        get {
                                return Value < 0;
                {
                        return new IntConstant (Value);
                }
++
++              public override bool IsDefaultValue {
++                      get {
++                              return Value == 0;
++                      }
++              }
                
                public override bool IsZeroInteger {
                        get { return Value == 0; }
                        return new IntConstant (Value);
                }
                
++              public override bool IsDefaultValue {
++                      get {
++                              return Value == 0;
++                      }
++              }
++
                public override bool IsNegative {
                        get {
                                return false;
                {
                        return this;
                }
++
++              public override bool IsDefaultValue {
++                      get {
++                              return Value == 0;
++                      }
++              }
                
                public override bool IsNegative {
                        get {
                        return null;
                }
                
++              public override bool IsDefaultValue {
++                      get {
++                              return Value == 0;
++                      }
++              }
++
                public override bool IsNegative {
                        get {
                                return false;
                        return null;
                }
                
++              public override bool IsDefaultValue {
++                      get {
++                              return Value == 0;
++                      }
++              }
++
                public override bool IsNegative {
                        get {
                                return Value < 0;
                        return null;
                }
                
++              public override bool IsDefaultValue {
++                      get {
++                              return Value == 0;
++                      }
++              }
++
                public override bool IsNegative {
                        get {
                                return false;
                        return null;
                }
  
++              public override bool IsDefaultValue {
++                      get {
++                              return Value == 0;
++                      }
++              }
++
                public override bool IsNegative {
                        get {
                                return Value < 0;
                        return null;
                }
  
++              public override bool IsDefaultValue {
++                      get {
++                              return Value == 0;
++                      }
++              }
++
                public override bool IsNegative {
                        get {
                                return Value < 0;
                        ig.Emit (OpCodes.Newobj, TypeManager.void_decimal_ctor_five_args);
                }
  
++              public override bool IsDefaultValue {
++                      get {
++                              return Value == 0;
++                      }
++              }
++
                public override bool IsNegative {
                        get {
                                return Value < 0;
                                ec.ig.Emit (OpCodes.Ldstr, Value);
                }
  
++              public override bool IsDefaultValue {
++                      get {
++                              return Value == null;
++                      }
++              }
++
                public override bool IsNegative {
                        get {
                                return false;
index 3d915575128ac0d0eb03816332aff8465d5b48d9,02f218d5e5e946da36bdda9137915c0708689059..4d74fe1cddae5ed9814fb48b9de6ac95a1f6eb9c
@@@ -220,7 -220,8 +220,8 @@@ namespace Mono.CShar
                                "   -noconfig[+|-]     Disables implicit references to assemblies\n" +
                                "   -nostdlib[+|-]     Does not load core libraries\n" +
                                "   -nowarn:W1[,W2]    Disables one or more warnings\n" + 
++                              "   -optimize[+|-]     Enables code optimalizations" + Environment.NewLine +
                                "   -out:FNAME         Specifies output file\n" +
 -                              "   -doc:XMLFILE         Generates xml documentation into specified file\n" +
                                "   -pkg:P1[,Pn]       References packages P1..Pn\n" + 
                                "   --expect-error X   Expect that error X will be encountered\n" +
                                "   -recurse:SPEC      Recursively compiles the files in SPEC ([dir]/file)\n" + 
  
                        case "/optimize":
                        case "/optimize+":
++                              RootContext.Optimize = true;
++                              return true;
++
                        case "/optimize-":
++                              RootContext.Optimize = false;
++                              return true;
++
                        case "/incremental":
                        case "/incremental+":
                        case "/incremental-":
index a0eba82f5500dfbf09e3cff7ffffac6d842b4f6e,4fb48ea2434a804d5654c938b07583b720961938..baf528bffae03ddaec3782e7ac4c4bb39085d332
@@@ -299,7 -299,7 +299,7 @@@ namespace Mono.CSharp 
  
                public virtual Expression DoResolveLValue (EmitContext ec, Expression right_side)
                {
--                      return DoResolve (ec);
++                      return null;
                }
  
                //
                /// </remarks>
                public Expression ResolveLValue (EmitContext ec, Expression right_side)
                {
++                      int errors = Report.Errors;
                        Expression e = DoResolveLValue (ec, right_side);
  
--                      if (e != null){
--                              if (e is SimpleName){
--                                      SimpleName s = (SimpleName) e;
--                                      MemberLookupFailed (ec, null, ec.ContainerType, s.Name,
--                                                          ec.DeclSpace.Name, loc);
--                                      return null;
--                              }
++                      if (e == null) {
++                              if (errors == Report.Errors)
++                                      Report.Error (131, Location, "The left-hand side of an assignment or mutating operation must be a variable, property or indexer");
++                              return null;
++                      }
  
++                      if (e != null){
                                if (e.eclass == ExprClass.Invalid)
                                        throw new Exception ("Expression " + e +
                                                             " ExprClass is Invalid after resolve");
                public EmptyCast (Expression child, Type return_type)
                {
                        eclass = child.eclass;
++                      loc = child.Location;
                        type = return_type;
                        this.child = child;
                }
                        child.Emit (ec);
                }
  
++              public override bool IsDefaultValue {
++                      get {
++                              throw new NotImplementedException ();
++                      }
++              }
++
                public override bool IsNegative {
                        get {
                                return false;
                {
                        return Child.ConvertToInt ();
                }
--              
++
++              public override bool IsDefaultValue {
++                      get {
++                              return Child.IsDefaultValue;
++                      }
++              }
++
                public override bool IsZeroInteger {
                        get { return Child.IsZeroInteger; }
                }
                        return true;
                }
  
++              public override Expression DoResolveLValue (EmitContext ec, Expression right_side)
++              {
++                      return DoResolve (ec);
++              }
++
                public override Expression DoResolve (EmitContext ec)
                {
                        if (instance_expr != null) {
index d395ac505f5b59b4efc81c15aee6379b760864c9,2bd435d050d4b1cce2e2279d285a7b75e0448f51..4a7f5f28b7edaf741f0467dbda5c051f4934ac2c
@@@ -416,11 -416,11 +416,6 @@@ namespace Mono.CSharp 
                                return this;
  
                        case Operator.AddressOf:
--                              if (Expr.eclass != ExprClass.Variable){
--                                      Error (211, "Cannot take the address of non-variables");
--                                      return null;
--                              }
--                              
                                if (!ec.InUnsafe) {
                                        UnsafeError (loc); 
                                        return null;
  
                public override Expression DoResolve (EmitContext ec)
                {
--                      if (Oper == Operator.AddressOf)
--                              Expr = Expr.ResolveLValue (ec, new EmptyExpression ());
++                      if (Oper == Operator.AddressOf) {
++                              Expr = Expr.DoResolveLValue (ec, new EmptyExpression ());
++
++                              if (Expr == null || Expr.eclass != ExprClass.Variable){
++                                      Error (211, "Cannot take the address of non-variables");
++                                      return null;
++                              }
++                      }
                        else
                                Expr = Expr.Resolve (ec);
                        
                public override Expression DoResolveLValue (EmitContext ec, Expression right)
                {
                        if (Oper == Operator.Indirection)
--                              return base.DoResolveLValue (ec, right);
++                              return DoResolve (ec);
  
--                      Error (131, "The left-hand side of an assignment must be a " +
--                             "variable, property or indexer");
                        return null;
                }
  
                        expr.Emit (ec);
                }
  
++              public override Expression DoResolveLValue (EmitContext ec, Expression right_side)
++              {
++                      return DoResolve (ec);
++              }
++
                public override Expression DoResolve (EmitContext ec)
                {
                        //
  
                        mg = MemberLookup (ec, expr_type, op_name, MemberTypes.Method, AllBindingFlags, loc);
  
--                      if (mg == null && expr_type.BaseType != null)
--                              mg = MemberLookup (ec, expr_type.BaseType, op_name,
--                                                 MemberTypes.Method, AllBindingFlags, loc);
--                      
                        if (mg != null) {
                                method = StaticCallExpr.MakeSimpleCall (
                                        ec, (MethodGroupExpr) mg, expr, loc);
  
                                type = method.Type;
--                              return this;
++                      } else if (!IsIncrementableNumber (expr_type)) {
++                              Error (187, "No such operator '" + OperName (mode) + "' defined for type '" +
++                                     TypeManager.CSharpName (expr_type) + "'");
++                                 return null;
                        }
  
                        //
                        type = expr_type;
                        if (expr.eclass == ExprClass.Variable){
                                LocalVariableReference var = expr as LocalVariableReference;
--                              if ((var != null) && var.IsReadOnly)
++                              if ((var != null) && var.IsReadOnly) {
                                        Error (1604, "cannot assign to `" + var.Name + "' because it is readonly");
--                              if (IsIncrementableNumber (expr_type) ||
--                                  expr_type == TypeManager.decimal_type){
--                                      return this;
++                                      return null;
                                }
--                      } else if (expr.eclass == ExprClass.IndexerAccess){
--                              IndexerAccess ia = (IndexerAccess) expr;
--                              
--                              expr = ia.ResolveLValue (ec, this);
++                      } else if (expr.eclass == ExprClass.IndexerAccess || expr.eclass == ExprClass.PropertyAccess){
++                              expr = expr.ResolveLValue (ec, this);
                                if (expr == null)
                                        return null;
--
--                              return this;
--                      } else if (expr.eclass == ExprClass.PropertyAccess){
--                              PropertyExpr pe = (PropertyExpr) expr;
--
--                              if (pe.VerifyAssignable ())
--                                      return this;
--
--                              return null;
                        } else {
                                expr.Error_UnexpectedKind ("variable, indexer or property access", loc);
                                return null;
                        }
  
--                      Error (187, "No such operator '" + OperName (mode) + "' defined for type '" +
--                             TypeManager.CSharpName (expr_type) + "'");
--                      return null;
++                      return this;
                }
  
                public override Expression DoResolve (EmitContext ec)
                        return true;
                }
                
++              void Error_LValueRequired (Location loc)
++              {
++                      Report.Error (1510, loc, "An lvalue is required as an argument to out or ref");
++              }
++
                public bool Resolve (EmitContext ec, Location loc)
                {
                        if (ArgType == AType.Ref) {
                                                return false;
                                        }
                                }
--                              Expr = Expr.ResolveLValue (ec, Expr);
--                      } else if (ArgType == AType.Out)
--                              Expr = Expr.ResolveLValue (ec, EmptyExpression.Null);
++                              Expr = Expr.DoResolveLValue (ec, Expr);
++                              if (Expr == null)
++                                      Error_LValueRequired (loc);
++                      } else if (ArgType == AType.Out) {
++                              Expr = Expr.DoResolveLValue (ec, EmptyExpression.Null);
++                              if (Expr == null)
++                                      Error_LValueRequired (loc);
++                      }
                        else
                                Expr = Expr.Resolve (ec);
  
                        if (Expr == null)
                                return false;
  
++                      if (Expr is IMemberExpr) {
++                              IMemberExpr me = Expr as IMemberExpr;
++
++                              //
++                              // This can happen with the following code:
++                              //
++                              //   class X {}
++                              //   class Y {
++                              //     public Y (X x) {}
++                              //   }
++                              //   class Z : Y {
++                              //     X X;
++                              //     public Z () : base (X) {}
++                              //   }
++                              //
++                              // SimpleNameResolve is conservative about flagging the X as
++                              // an error since it has identical name and type.  However,
++                              // because there's no MemberAccess, that is not really justified.
++                              // It is still simpler to fix it here, rather than in SimpleNameResolve.
++                              //
++                              if (me.IsInstance && me.InstanceExpression == null) {
++                                      SimpleName.Error_ObjectRefRequired (ec, loc, me.Name);
++                                      return false;
++                              }
++                      }
++
                        if (ArgType == AType.Expression)
                                return true;
                        else {
                                                "A property or indexer can not be passed as an out or ref " +
                                                "parameter");
                                } else {
--                                      Report.Error (
--                                              1510, loc,
--                                              "An lvalue is required as an argument to out or ref");
++                                      Error_LValueRequired (loc);
                                }
                                return false;
                        }
                                                    IsAncestralType (decl_type, next_applicable_type))
                                                        continue;
  
 -                                              candidates[k++] = candidates[i];
 +                                              candidates [k++] = candidates [i];
  
- #if false
-                                               //
-                                               // Methods marked 'override' don't take part in 'applicable_type'
-                                               // computation.
-                                               //
-                                               if (!me.IsBase &&
-                                                   candidate.IsVirtual &&
-                                                   (candidate.Attributes & MethodAttributes.NewSlot) == 0)
-                                                       continue;
- #endif
                                                if (next_applicable_type == null ||
                                                    IsAncestralType (next_applicable_type, decl_type))
                                                        next_applicable_type = decl_type;
                        loc = l;
                }
  
++              public override Expression DoResolveLValue (EmitContext ec, Expression right_side)
++              {
++                      return DoResolve (ec);
++              }
++
                public override Expression DoResolve (EmitContext ec)
                {
  #if false
index 85cd202458601957feeb19acffd112fa21a28714,85cd202458601957feeb19acffd112fa21a28714..56bb333c94bec63521c23aa16b249520298a98c2
@@@ -804,6 -804,6 +804,11 @@@ namespace Mono.CSharp 
                                this.field = field;
                        }
  
++                      public override Expression DoResolveLValue (EmitContext ec, Expression right_side)
++                      {
++                              return DoResolve (ec);
++                      }
++
                        public override Expression DoResolve (EmitContext ec)
                        {
                                FieldExpr fexpr = new FieldExpr (field.FieldBuilder, loc);
index 0a97d502b5046af510de45853feb4e18fba29e99,0a97d502b5046af510de45853feb4e18fba29e99..1d7396536c633b41126120195e4daa076cd97620
@@@ -79,7 -79,7 +79,13 @@@ namespace Mono.CSharp 
                {
                        ec.ig.Emit (OpCodes.Ldnull);
                }
--              
++
++              public override bool IsDefaultValue {
++                      get {
++                              return true;
++                      }
++              }
++
                public override bool IsNegative {
                        get {
                                return false;
index dffeaeda752431eefb44d53b2282f3e9887bda9f,2824da00840d2b489a253daa496655bd89113fc5..3e79b457aa602170bd62349baaee892530a75467
@@@ -71,6 -71,6 +71,11 @@@ namespace Mono.CSharp 
  
                public static bool VerifyClsCompliance = true;
  
++              /// <summary>
++              /// Holds /optimize option
++              /// </summary>
++              public static bool Optimize = true;
++
                public static LanguageVersion Version = LanguageVersion.Default;
  
                //