From 66a365e84fb3b76648a30b74e5ae688a9ba6c5d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Kr=C3=BCger?= Date: Sat, 7 Apr 2012 10:44:39 +0200 Subject: [PATCH] Updated mcs. --- .../Parser/mcs/anonymous.cs | 282 +++++--- .../Parser/mcs/assign.cs | 8 +- .../Parser/mcs/async.cs | 56 +- .../Parser/mcs/cfold.cs | 8 +- .../Parser/mcs/codegen.cs | 12 +- .../Parser/mcs/const.cs | 2 +- .../Parser/mcs/constant.cs | 39 +- .../Parser/mcs/convert.cs | 8 +- .../Parser/mcs/cs-parser.cs | 602 +++++++++--------- .../Parser/mcs/cs-parser.jay | 4 +- .../Parser/mcs/cs-tokenizer.cs | 20 + .../Parser/mcs/doc.cs | 112 +++- .../Parser/mcs/driver.cs | 6 + .../Parser/mcs/ecore.cs | 13 +- .../Parser/mcs/expression.cs | 91 +-- .../Parser/mcs/iterators.cs | 107 +++- .../Parser/mcs/lambda.cs | 4 +- .../Parser/mcs/literal.cs | 8 +- .../Parser/mcs/method.cs | 2 +- .../Parser/mcs/parameter.cs | 4 +- .../Parser/mcs/statement.cs | 355 ++++++++--- .../TestStatementIndentation.cs | 3 - 22 files changed, 1098 insertions(+), 648 deletions(-) diff --git a/ICSharpCode.NRefactory.CSharp/Parser/mcs/anonymous.cs b/ICSharpCode.NRefactory.CSharp/Parser/mcs/anonymous.cs index 403de3c116..7ef97558f8 100644 --- a/ICSharpCode.NRefactory.CSharp/Parser/mcs/anonymous.cs +++ b/ICSharpCode.NRefactory.CSharp/Parser/mcs/anonymous.cs @@ -200,7 +200,7 @@ namespace Mono.CSharp { protected override void DoEmit (EmitContext ec) { - hoisted_this.EmitHoistingAssignment (ec); + hoisted_this.EmitAssign (ec, new CompilerGeneratedThis (ec.CurrentType, loc), false, false); } protected override void CloneTo (CloneContext clonectx, Statement target) @@ -212,7 +212,7 @@ namespace Mono.CSharp { // Unique storey ID public readonly int ID; - public readonly Block OriginalSourceBlock; + public readonly ExplicitBlock OriginalSourceBlock; // A list of StoreyFieldPair with local field keeping parent storey instance List used_parent_storeys; @@ -220,6 +220,7 @@ namespace Mono.CSharp { // A list of hoisted parameters protected List hoisted_params; + List hoisted_local_params; protected List hoisted_locals; // Hoisted this @@ -228,7 +229,9 @@ namespace Mono.CSharp { // Local variable which holds this storey instance public Expression Instance; - public AnonymousMethodStorey (Block block, TypeDefinition parent, MemberBase host, TypeParameters tparams, string name, MemberKind kind) + bool initialize_hoisted_this; + + public AnonymousMethodStorey (ExplicitBlock block, TypeDefinition parent, MemberBase host, TypeParameters tparams, string name, MemberKind kind) : base (parent, MakeMemberName (host, name, parent.Module.CounterAnonymousContainers, tparams, block.StartLocation), tparams, 0, kind) { @@ -239,18 +242,10 @@ namespace Mono.CSharp { public void AddCapturedThisField (EmitContext ec) { TypeExpr type_expr = new TypeExpression (ec.CurrentType, Location); - Field f = AddCompilerGeneratedField ("<>f__this", type_expr); - f.Define (); + Field f = AddCompilerGeneratedField ("$this", type_expr); hoisted_this = new HoistedThis (this, f); - // Inflated type instance has to be updated manually - if (Instance.Type is InflatedTypeSpec) { - var inflator = new TypeParameterInflator (this, Instance.Type, TypeParameterSpec.EmptyTypes, TypeSpec.EmptyTypes); - Instance.Type.MemberCache.AddMember (f.Spec.InflateMember (inflator)); - - inflator = new TypeParameterInflator (this, f.Parent.CurrentType, TypeParameterSpec.EmptyTypes, TypeSpec.EmptyTypes); - f.Parent.CurrentType.MemberCache.AddMember (f.Spec.InflateMember (inflator)); - } + initialize_hoisted_this = true; } public Field AddCapturedVariable (string name, TypeSpec type) @@ -310,38 +305,93 @@ namespace Mono.CSharp { used_parent_storeys.Add (new StoreyFieldPair (storey, f)); } - public void CaptureLocalVariable (ResolveContext ec, LocalVariable local_info) + public void CaptureLocalVariable (ResolveContext ec, LocalVariable localVariable) { - ec.CurrentBlock.Explicit.HasCapturedVariable = true; - if (ec.CurrentBlock.Explicit != local_info.Block.Explicit) - AddReferenceFromChildrenBlock (ec.CurrentBlock.Explicit); + if (this is StateMachine) { + if (ec.CurrentBlock.ParametersBlock != localVariable.Block.ParametersBlock) + ec.CurrentBlock.Explicit.HasCapturedVariable = true; + } else { + ec.CurrentBlock.Explicit.HasCapturedVariable = true; + } - if (local_info.HoistedVariant != null) - return; + var hoisted = localVariable.HoistedVariant; + if (hoisted != null && hoisted.Storey != this && hoisted.Storey.Kind == MemberKind.Struct) { + // TODO: It's too late the field is defined in HoistedLocalVariable ctor + hoisted.Storey.hoisted_locals.Remove (hoisted); + hoisted = null; + } - HoistedVariable var = new HoistedLocalVariable (this, local_info, GetVariableMangledName (local_info)); - local_info.HoistedVariant = var; + if (hoisted == null) { + hoisted = new HoistedLocalVariable (this, localVariable, GetVariableMangledName (localVariable)); + localVariable.HoistedVariant = hoisted; - if (hoisted_locals == null) - hoisted_locals = new List (); + if (hoisted_locals == null) + hoisted_locals = new List (); - hoisted_locals.Add (var); + hoisted_locals.Add (hoisted); + } + + if (ec.CurrentBlock.Explicit != localVariable.Block.Explicit) + hoisted.Storey.AddReferenceFromChildrenBlock (ec.CurrentBlock.Explicit); } - public void CaptureParameter (ResolveContext ec, ParameterReference param_ref) + public void CaptureParameter (ResolveContext ec, ParametersBlock.ParameterInfo parameterInfo, ParameterReference parameterReference) { - ec.CurrentBlock.Explicit.HasCapturedVariable = true; - AddReferenceFromChildrenBlock (ec.CurrentBlock.Explicit); + if (!(this is StateMachine)) { + ec.CurrentBlock.Explicit.HasCapturedVariable = true; + } - if (param_ref.GetHoistedVariable (ec) != null) - return; + var hoisted = parameterInfo.Parameter.HoistedVariant; + + if (parameterInfo.Block.StateMachine is AsyncTaskStorey) { + // + // Another storey in same block exists but state machine does not + // have parameter captured. We need to add it there as well to + // proxy parameter value correctly. + // + if (hoisted == null && parameterInfo.Block.StateMachine != this) { + var storey = parameterInfo.Block.StateMachine; - if (hoisted_params == null) - hoisted_params = new List (2); + hoisted = new HoistedParameter (storey, parameterReference); + parameterInfo.Parameter.HoistedVariant = hoisted; + + if (storey.hoisted_params == null) + storey.hoisted_params = new List (); + + storey.hoisted_params.Add (hoisted); + } + + // + // Lift captured parameter from value type storey to reference type one. Otherwise + // any side effects would be done on a copy + // + if (hoisted != null && hoisted.Storey != this && hoisted.Storey.Kind == MemberKind.Struct) { + if (hoisted_local_params == null) + hoisted_local_params = new List (); + + hoisted_local_params.Add (hoisted); + hoisted = null; + } + } + + if (hoisted == null) { + hoisted = new HoistedParameter (this, parameterReference); + parameterInfo.Parameter.HoistedVariant = hoisted; + + if (hoisted_params == null) + hoisted_params = new List (); + + hoisted_params.Add (hoisted); + } - var expr = new HoistedParameter (this, param_ref); - param_ref.Parameter.HoistedVariant = expr; - hoisted_params.Add (expr); + // + // Register link between current block and parameter storey. It will + // be used when setting up storey definition to deploy storey reference + // when parameters are used from multiple blocks + // + if (ec.CurrentBlock.Explicit != parameterInfo.Block) { + hoisted.Storey.AddReferenceFromChildrenBlock (ec.CurrentBlock.Explicit); + } } TypeExpr CreateStoreyTypeExpression (EmitContext ec) @@ -497,10 +547,10 @@ namespace Mono.CSharp { } // - // Define hoisted `this' in top-level storey only + // Initialize hoisted `this' only once, everywhere else will be + // referenced indirectly // - if (OriginalSourceBlock.Explicit.HasCapturedThis && !(Parent is AnonymousMethodStorey)) { - AddCapturedThisField (ec); + if (initialize_hoisted_this) { rc.CurrentBlock.AddScopeStatement (new ThisInitializer (hoisted_this)); } @@ -517,9 +567,20 @@ namespace Mono.CSharp { ec.CurrentAnonymousMethod = ae; } - protected virtual void EmitHoistedParameters (EmitContext ec, IList hoisted) + protected virtual void EmitHoistedParameters (EmitContext ec, List hoisted) { foreach (HoistedParameter hp in hoisted) { + // + // Parameters could be proxied via local fields for value type storey + // + if (hoisted_local_params != null) { + var local_param = hoisted_local_params.Find (l => l.Parameter.Parameter == hp.Parameter.Parameter); + var source = new FieldExpr (local_param.Field, Location); + source.InstanceExpression = new CompilerGeneratedThis (CurrentType, Location); + hp.EmitAssign (ec, source, false, false); + continue; + } + hp.EmitHoistingAssignment (ec); } } @@ -592,7 +653,12 @@ namespace Mono.CSharp { } public HoistedThis HoistedThis { - get { return hoisted_this; } + get { + return hoisted_this; + } + set { + hoisted_this = value; + } } public IList ReferencesFromChildrenBlock { @@ -660,6 +726,12 @@ namespace Mono.CSharp { this.field = field; } + public AnonymousMethodStorey Storey { + get { + return storey; + } + } + public void AddressOf (EmitContext ec, AddressOp mode) { GetFieldExpression (ec).AddressOf (ec, mode); @@ -741,7 +813,7 @@ namespace Mono.CSharp { public class HoistedParameter : HoistedVariable { - sealed class HoistedFieldAssign : Assign + sealed class HoistedFieldAssign : CompilerAssign { public HoistedFieldAssign (Expression target, Expression source) : base (target, source, source.Location) @@ -772,23 +844,32 @@ namespace Mono.CSharp { this.parameter = hp.parameter; } + #region Properties + public Field Field { get { return field; } } + public ParameterReference Parameter { + get { + return parameter; + } + } + + #endregion + public void EmitHoistingAssignment (EmitContext ec) { // // Remove hoisted redirection to emit assignment from original parameter // - HoistedVariable temp = parameter.Parameter.HoistedVariant; + var temp = parameter.Parameter.HoistedVariant; parameter.Parameter.HoistedVariant = null; - Assign a = new HoistedFieldAssign (GetFieldExpression (ec), parameter); - if (a.Resolve (new ResolveContext (ec.MemberContext)) != null) - a.EmitStatement (ec); + var a = new HoistedFieldAssign (GetFieldExpression (ec), parameter); + a.EmitStatement (ec); parameter.Parameter.HoistedVariant = temp; } @@ -814,13 +895,6 @@ namespace Mono.CSharp { return field; } } - - public void EmitHoistingAssignment (EmitContext ec) - { - SimpleAssign a = new SimpleAssign (GetFieldExpression (ec), new CompilerGeneratedThis (ec.CurrentType, field.Location)); - if (a.Resolve (new ResolveContext (ec.MemberContext)) != null) - a.EmitStatement (ec); - } } // @@ -1035,12 +1109,8 @@ namespace Mono.CSharp { } using (ec.Set (ResolveContext.Options.ProbingMode | ResolveContext.Options.InferReturnType)) { - var body = CompatibleMethodBody (ec, tic, InternalType.Arglist, delegate_type); + var body = CompatibleMethodBody (ec, tic, null, delegate_type); if (body != null) { - if (Block.IsAsync) { - AsyncInitializer.Create (ec, body.Block, body.Parameters, ec.CurrentMemberDefinition.Parent.PartialContainer, null, loc); - } - am = body.Compatible (ec, body); } else { am = null; @@ -1127,18 +1197,6 @@ namespace Mono.CSharp { am = CreateExpressionTree (ec, delegate_type); } } else { - if (Block.IsAsync) { - var rt = body.ReturnType; - if (rt.Kind != MemberKind.Void && - rt != ec.Module.PredefinedTypes.Task.TypeSpec && - !rt.IsGenericTask) { - ec.Report.Error (4010, loc, "Cannot convert async {0} to delegate type `{1}'", - GetSignatureForError (), type.GetSignatureForError ()); - } - - AsyncInitializer.Create (ec, body.Block, body.Parameters, ec.CurrentMemberDefinition.Parent.PartialContainer, rt, loc); - } - am = body.Compatible (ec); } } catch (CompletionResult) { @@ -1266,7 +1324,19 @@ namespace Mono.CSharp { ParametersBlock b = ec.IsInProbingMode ? (ParametersBlock) Block.PerformClone () : Block; - return CompatibleMethodFactory (return_type, delegate_type, p, b); + if (b.IsAsync) { + var rt = return_type; + if (rt != null && rt.Kind != MemberKind.Void && rt != ec.Module.PredefinedTypes.Task.TypeSpec && !rt.IsGenericTask) { + ec.Report.Error (4010, loc, "Cannot convert async {0} to delegate type `{1}'", + GetSignatureForError (), delegate_type.GetSignatureForError ()); + + return null; + } + + b = b.ConvertToAsyncTask (ec, ec.CurrentMemberDefinition.Parent.PartialContainer, p, return_type, loc); + } + + return CompatibleMethodFactory (return_type ?? InternalType.Arglist, delegate_type, p, b); } protected virtual AnonymousMethodBody CompatibleMethodFactory (TypeSpec return_type, TypeSpec delegate_type, ParametersCompiled p, ParametersBlock b) @@ -1366,6 +1436,15 @@ namespace Mono.CSharp { public abstract bool IsIterator { get; } public abstract AnonymousMethodStorey Storey { get; } + // + // The block that makes up the body for the anonymous method + // + public ParametersBlock Block { + get { + return block; + } + } + public AnonymousExpression Compatible (ResolveContext ec) { return Compatible (ec, this); @@ -1439,16 +1518,6 @@ namespace Mono.CSharp { b = b.Parent == null ? null : b.Parent.Explicit; } while (b != null); } - - // - // The block that makes up the body for the anonymous method - // - public ParametersBlock Block { - get { - return block; - } - } - } public class AnonymousMethodBody : AnonymousExpression @@ -1536,17 +1605,47 @@ namespace Mono.CSharp { // Modifiers modifiers; - if (Block.HasCapturedVariable || Block.HasCapturedThis) { - storey = FindBestMethodStorey (); + TypeDefinition parent = null; + + var src_block = Block.Original.Explicit; + if (src_block.HasCapturedVariable || src_block.HasCapturedThis) { + parent = storey = FindBestMethodStorey (); + + if (storey == null) { + var sm = src_block.ParametersBlock.TopBlock.StateMachine; + + // + // Remove hoisted this demand when simple instance method is enough + // + if (src_block.HasCapturedThis) { + src_block.ParametersBlock.TopBlock.RemoveThisReferenceFromChildrenBlock (src_block); + + // + // Special case where parent class is used to emit instance method + // because currect storey is of value type (async host) and we don't + // want to create another childer storey to host this reference only + // + if (sm != null && sm.Kind == MemberKind.Struct) + parent = sm.Parent.PartialContainer; + } + + // + // For iterators we can host everything in one class + // + if (sm is IteratorStorey) + parent = storey = sm; + } + modifiers = storey != null ? Modifiers.INTERNAL : Modifiers.PRIVATE; } else { if (ec.CurrentAnonymousMethod != null) - storey = ec.CurrentAnonymousMethod.Storey; + parent = storey = ec.CurrentAnonymousMethod.Storey; modifiers = Modifiers.STATIC | Modifiers.PRIVATE; } - var parent = storey != null ? storey : ec.CurrentTypeDefinition.Parent.PartialContainer; + if (parent == null) + parent = ec.CurrentTypeDefinition.Parent.PartialContainer; string name = CompilerGeneratedContainer.MakeName (parent != storey ? block_name : null, "m", null, ec.Module.CounterAnonymousMethods++); @@ -1651,6 +1750,17 @@ namespace Mono.CSharp { } } else { ec.EmitThis (); + + // + // Special case for value type storey where this is not lifted but + // droped off to parent class + // + for (var b = Block.Parent; b != null; b = b.Parent) { + if (b.ParametersBlock.StateMachine != null) { + ec.Emit (OpCodes.Ldfld, b.ParametersBlock.StateMachine.HoistedThis.Field.Spec); + break; + } + } } var delegate_method = method.Spec; @@ -1661,9 +1771,7 @@ namespace Mono.CSharp { // Mutate anonymous method instance type if we are in nested // hoisted generic anonymous method storey // - if (ec.CurrentAnonymousMethod != null && - ec.CurrentAnonymousMethod.Storey != null && - ec.CurrentAnonymousMethod.Storey.Mutator != null) { + if (ec.IsAnonymousStoreyMutateRequired) { t = storey.Mutator.Mutate (t); } @@ -1777,7 +1885,7 @@ namespace Mono.CSharp { c.Block = new ToplevelBlock (parent.Module.Compiler, c.ParameterInfo, loc); // - // Create fields and contructor body with field initialization + // Create fields and constructor body with field initialization // bool error = false; for (int i = 0; i < parameters.Count; ++i) { diff --git a/ICSharpCode.NRefactory.CSharp/Parser/mcs/assign.cs b/ICSharpCode.NRefactory.CSharp/Parser/mcs/assign.cs index a836a9a5af..673d586d10 100644 --- a/ICSharpCode.NRefactory.CSharp/Parser/mcs/assign.cs +++ b/ICSharpCode.NRefactory.CSharp/Parser/mcs/assign.cs @@ -343,7 +343,7 @@ namespace Mono.CSharp { type = target_type; if (!(target is IAssignMethod)) { - Error_ValueAssignment (ec, source); + target.Error_ValueAssignment (ec, source); return null; } @@ -572,10 +572,10 @@ namespace Mono.CSharp { // // Emit sequence symbol info even if we are in compiler generated - // block to allow debugging filed initializers when constructor is + // block to allow debugging field initializers when constructor is // compiler generated // - if (ec.HasSet (BuilderContext.Options.OmitDebugInfo)) { + if (ec.HasSet (BuilderContext.Options.OmitDebugInfo) && ec.HasMethodSymbolBuilder) { using (ec.With (BuilderContext.Options.OmitDebugInfo, false)) { ec.Mark (loc); } @@ -826,7 +826,7 @@ namespace Mono.CSharp { return new SimpleAssign (target, new DynamicConversion (target_type, CSharpBinderFlags.ConvertExplicit, arg, loc), loc).Resolve (ec); } - right.Error_ValueCannotBeConverted (ec, loc, target_type, false); + right.Error_ValueCannotBeConverted (ec, target_type, false); return null; } diff --git a/ICSharpCode.NRefactory.CSharp/Parser/mcs/async.cs b/ICSharpCode.NRefactory.CSharp/Parser/mcs/async.cs index d4a19ad722..4c0cce6127 100644 --- a/ICSharpCode.NRefactory.CSharp/Parser/mcs/async.cs +++ b/ICSharpCode.NRefactory.CSharp/Parser/mcs/async.cs @@ -411,12 +411,6 @@ namespace Mono.CSharp } } - public Block OriginalBlock { - get { - return block.Parent; - } - } - public TypeInferenceContext ReturnTypeInference { get { return return_inference; @@ -425,38 +419,6 @@ namespace Mono.CSharp #endregion - public static void Create (IMemberContext context, ParametersBlock block, ParametersCompiled parameters, TypeDefinition host, TypeSpec returnType, Location loc) - { - for (int i = 0; i < parameters.Count; i++) { - Parameter p = parameters[i]; - Parameter.Modifier mod = p.ModFlags; - if ((mod & Parameter.Modifier.RefOutMask) != 0) { - host.Compiler.Report.Error (1988, p.Location, - "Async methods cannot have ref or out parameters"); - return; - } - - if (p is ArglistParameter) { - host.Compiler.Report.Error (4006, p.Location, - "__arglist is not allowed in parameter list of async methods"); - return; - } - - if (parameters.Types[i].IsPointer) { - host.Compiler.Report.Error (4005, p.Location, - "Async methods cannot have unsafe parameters"); - return; - } - } - - if (!block.HasAwait) { - host.Compiler.Report.Warning (1998, 1, loc, - "Async block lacks `await' operator and will run synchronously"); - } - - block.WrapIntoAsyncTask (context, host, returnType); - } - protected override BlockContext CreateBlockContext (ResolveContext rc) { var ctx = base.CreateBlockContext (rc); @@ -507,8 +469,8 @@ namespace Mono.CSharp Dictionary> stack_fields; Dictionary> awaiter_fields; - public AsyncTaskStorey (IMemberContext context, AsyncInitializer initializer, TypeSpec type) - : base (initializer.OriginalBlock, initializer.Host, context.CurrentMemberDefinition as MemberBase, context.CurrentTypeParameters, "async", MemberKind.Class) + public AsyncTaskStorey (ParametersBlock block, IMemberContext context, AsyncInitializer initializer, TypeSpec type) + : base (block, initializer.Host, context.CurrentMemberDefinition as MemberBase, context.CurrentTypeParameters, "async", MemberKind.Struct) { return_type = type; awaiter_fields = new Dictionary> (); @@ -793,16 +755,10 @@ namespace Mono.CSharp InstanceExpression = new CompilerGeneratedThis (ec.CurrentType, Location) }; - // TODO: CompilerGeneratedThis is enough for structs - var temp_this = new LocalTemporary (CurrentType); - temp_this.EmitAssign (ec, new CompilerGeneratedThis (CurrentType, Location), false, false); - var args = new Arguments (2); args.Add (new Argument (awaiter, Argument.AType.Ref)); - args.Add (new Argument (temp_this, Argument.AType.Ref)); + args.Add (new Argument (new CompilerGeneratedThis (CurrentType, Location), Argument.AType.Ref)); mg.EmitCall (ec, args); - - temp_this.Release (ec); } public void EmitInitializer (EmitContext ec) @@ -832,14 +788,14 @@ namespace Mono.CSharp // // stateMachine.$builder = AsyncTaskMethodBuilder<{task-type}>.Create(); // - instance.Emit (ec); // .AddressOf (ec, AddressOp.Store); + instance.AddressOf (ec, AddressOp.Store); ec.Emit (OpCodes.Call, builder_factory); ec.Emit (OpCodes.Stfld, builder_field); // // stateMachine.$builder.Start<{storey-type}>(ref stateMachine); // - instance.Emit (ec); //.AddressOf (ec, AddressOp.Store); + instance.AddressOf (ec, AddressOp.Store); ec.Emit (OpCodes.Ldflda, builder_field); if (Task != null) ec.Emit (OpCodes.Dup); @@ -905,7 +861,7 @@ namespace Mono.CSharp protected override TypeSpec[] ResolveBaseTypes (out FullNamedExpression base_class) { - base_type = Compiler.BuiltinTypes.Object; // ValueType; + base_type = Compiler.BuiltinTypes.ValueType; base_class = null; var istate_machine = Module.PredefinedTypes.IAsyncStateMachine; diff --git a/ICSharpCode.NRefactory.CSharp/Parser/mcs/cfold.cs b/ICSharpCode.NRefactory.CSharp/Parser/mcs/cfold.cs index 7580124cee..9e2cfc8b96 100644 --- a/ICSharpCode.NRefactory.CSharp/Parser/mcs/cfold.cs +++ b/ICSharpCode.NRefactory.CSharp/Parser/mcs/cfold.cs @@ -149,7 +149,7 @@ namespace Mono.CSharp { case Binary.Operator.ExclusiveOr: result = BinaryFold (ec, oper, ((EnumConstant)left).Child, ((EnumConstant)right).Child, loc); if (result != null) - result = result.TryReduce (ec, lt, loc); + result = result.TryReduce (ec, lt); return result; /// @@ -158,7 +158,7 @@ namespace Mono.CSharp { case Binary.Operator.Subtraction: result = BinaryFold (ec, oper, ((EnumConstant)left).Child, ((EnumConstant)right).Child, loc); if (result != null) - result = result.TryReduce (ec, EnumSpec.GetUnderlyingType (lt), loc); + result = result.TryReduce (ec, EnumSpec.GetUnderlyingType (lt)); return result; /// @@ -340,7 +340,7 @@ namespace Mono.CSharp { if (result == null) return null; - result = result.TryReduce (ec, lt, loc); + result = result.TryReduce (ec, lt); if (result == null) return null; @@ -459,7 +459,7 @@ namespace Mono.CSharp { if (result == null) return null; - result = result.TryReduce (ec, lt, loc); + result = result.TryReduce (ec, lt); if (result == null) return null; diff --git a/ICSharpCode.NRefactory.CSharp/Parser/mcs/codegen.cs b/ICSharpCode.NRefactory.CSharp/Parser/mcs/codegen.cs index fc8c82e31f..026d410698 100644 --- a/ICSharpCode.NRefactory.CSharp/Parser/mcs/codegen.cs +++ b/ICSharpCode.NRefactory.CSharp/Parser/mcs/codegen.cs @@ -139,6 +139,12 @@ namespace Mono.CSharp } } + public bool HasMethodSymbolBuilder { + get { + return methodSymbols != null; + } + } + public bool HasReturnLabel { get { return return_label.HasValue; @@ -1090,9 +1096,11 @@ namespace Mono.CSharp return false; // - // It's non-virtual and will never be null + // It's non-virtual and will never be null and it can be determined + // whether it's known value or reference type by verifier // - if (!method.IsVirtual && (instance is This || instance is New || instance is ArrayCreation || instance is DelegateCreation)) + if (!method.IsVirtual && (instance is This || instance is New || instance is ArrayCreation || instance is DelegateCreation) && + !instance.Type.IsGenericParameter) return false; return true; diff --git a/ICSharpCode.NRefactory.CSharp/Parser/mcs/const.cs b/ICSharpCode.NRefactory.CSharp/Parser/mcs/const.cs index 7f91ce5eac..5eb93d129a 100644 --- a/ICSharpCode.NRefactory.CSharp/Parser/mcs/const.cs +++ b/ICSharpCode.NRefactory.CSharp/Parser/mcs/const.cs @@ -205,7 +205,7 @@ namespace Mono.CSharp { else if (!(expr is Constant)) Error_ExpressionMustBeConstant (rc, expr.Location, GetSignatureForError ()); else - expr.Error_ValueCannotBeConverted (rc, expr.Location, field.MemberType, false); + expr.Error_ValueCannotBeConverted (rc, field.MemberType, false); } expr = c; diff --git a/ICSharpCode.NRefactory.CSharp/Parser/mcs/constant.cs b/ICSharpCode.NRefactory.CSharp/Parser/mcs/constant.cs index 3869f1e805..4297c521d1 100644 --- a/ICSharpCode.NRefactory.CSharp/Parser/mcs/constant.cs +++ b/ICSharpCode.NRefactory.CSharp/Parser/mcs/constant.cs @@ -58,7 +58,7 @@ namespace Mono.CSharp { } #endif - public override void Error_ValueCannotBeConverted (ResolveContext ec, Location loc, TypeSpec target, bool expl) + public override void Error_ValueCannotBeConverted (ResolveContext ec, TypeSpec target, bool expl) { if (!expl && IsLiteral && BuiltinTypeSpec.IsPrimitiveTypeOrDecimal (target) && @@ -66,7 +66,7 @@ namespace Mono.CSharp { ec.Report.Error (31, loc, "Constant value `{0}' cannot be converted to a `{1}'", GetValueAsLiteral (), TypeManager.CSharpName (target)); } else { - base.Error_ValueCannotBeConverted (ec, loc, target, expl); + base.Error_ValueCannotBeConverted (ec, target, expl); } } @@ -74,7 +74,7 @@ namespace Mono.CSharp { { Constant c = ConvertImplicitly (type); if (c == null) - Error_ValueCannotBeConverted (ec, loc, type, false); + Error_ValueCannotBeConverted (ec, type, false); return c; } @@ -160,8 +160,11 @@ namespace Mono.CSharp { return new NullConstant (t, loc); } - throw new InternalErrorException ("Constant value `{0}' has unexpected underlying type `{1}'", - v, TypeManager.CSharpName (t)); +#if STATIC + throw new InternalErrorException ("Constant value `{0}' has unexpected underlying type `{1}'", v, t.GetSignatureForError ()); +#else + return null; +#endif } public override Expression CreateExpressionTree (ResolveContext ec) @@ -251,32 +254,38 @@ namespace Mono.CSharp { /// /// Attempts to do a compile-time folding of a constant cast. /// - public Constant TryReduce (ResolveContext ec, TypeSpec target_type, Location loc) + public Constant TryReduce (ResolveContext ec, TypeSpec target_type) { try { - return TryReduce (ec, target_type); - } - catch (OverflowException) { + return TryReduceConstant (ec, target_type); + } catch (OverflowException) { if (ec.ConstantCheckState && Type.BuiltinType != BuiltinTypeSpec.Type.Decimal) { ec.Report.Error (221, loc, "Constant value `{0}' cannot be converted to a `{1}' (use `unchecked' syntax to override)", GetValueAsLiteral (), target_type.GetSignatureForError ()); } else { - Error_ValueCannotBeConverted (ec, loc, target_type, false); + Error_ValueCannotBeConverted (ec, target_type, false); } return New.Constantify (target_type, loc); } } - Constant TryReduce (ResolveContext ec, TypeSpec target_type) + Constant TryReduceConstant (ResolveContext ec, TypeSpec target_type) { - if (Type == target_type) + if (Type == target_type) { + // + // Reducing literal value produces a new constant. Syntactically 10 is not same as (int)10 + // + if (IsLiteral) + return CreateConstantFromValue (target_type, GetValue (), loc); + return this; + } Constant c; if (target_type.IsEnum) { - c = TryReduce (ec, EnumSpec.GetUnderlyingType (target_type)); + c = TryReduceConstant (ec, EnumSpec.GetUnderlyingType (target_type)); if (c == null) return null; @@ -378,11 +387,11 @@ namespace Mono.CSharp { eclass = ExprClass.Value; } - public override void Error_ValueCannotBeConverted (ResolveContext ec, Location loc, TypeSpec target, bool expl) + public override void Error_ValueCannotBeConverted (ResolveContext ec, TypeSpec target, bool expl) { try { ConvertExplicitly (true, target); - base.Error_ValueCannotBeConverted (ec, loc, target, expl); + base.Error_ValueCannotBeConverted (ec, target, expl); } catch { diff --git a/ICSharpCode.NRefactory.CSharp/Parser/mcs/convert.cs b/ICSharpCode.NRefactory.CSharp/Parser/mcs/convert.cs index d28cc0dd06..a9a304dfc9 100644 --- a/ICSharpCode.NRefactory.CSharp/Parser/mcs/convert.cs +++ b/ICSharpCode.NRefactory.CSharp/Parser/mcs/convert.cs @@ -1195,7 +1195,7 @@ namespace Mono.CSharp { if (s_x != source_type) { var c = source as Constant; if (c != null) { - source = c.TryReduce (ec, s_x, loc); + source = c.TryReduce (ec, s_x); } else { source = implicitOnly ? ImplicitConversionStandard (ec, source_type_expr, s_x, loc) : @@ -1423,7 +1423,7 @@ namespace Mono.CSharp { if (e != null) return e; - source.Error_ValueCannotBeConverted (ec, loc, target_type, false); + source.Error_ValueCannotBeConverted (ec, target_type, false); return null; } @@ -2103,7 +2103,7 @@ namespace Mono.CSharp { if (ec.IsUnsafe && expr.Type.IsPointer && target_type.IsPointer && ((PointerContainer)expr.Type).Element.Kind == MemberKind.Void) return EmptyCast.Create (expr, target_type); - expr.Error_ValueCannotBeConverted (ec, l, target_type, true); + expr.Error_ValueCannotBeConverted (ec, target_type, true); return null; } @@ -2166,7 +2166,7 @@ namespace Mono.CSharp { if (e != null) return e; - expr.Error_ValueCannotBeConverted (ec, loc, target_type, true); + expr.Error_ValueCannotBeConverted (ec, target_type, true); return null; } } diff --git a/ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.cs b/ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.cs index 18a2ae98ef..1250501eae 100644 --- a/ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.cs +++ b/ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.cs @@ -1011,7 +1011,7 @@ namespace Mono.CSharp //t "for_statement_cont : opt_for_initializer CLOSE_PARENS", //t "$$89 :", //t "for_statement_condition : opt_for_condition SEMICOLON $$89 for_statement_end", -//t "for_statement_condition : opt_for_condition CLOSE_PARENS", +//t "for_statement_condition : boolean_expression CLOSE_PARENS", //t "for_statement_end : opt_for_iterator CLOSE_PARENS embedded_statement", //t "for_statement_end : error", //t "opt_for_initializer :", @@ -9476,7 +9476,7 @@ void case_972() 941, 959, 0, 0, 0, 68, 69, 72, 73, 0, 323, 314, 313, 0, 632, 208, 97, 0, 746, 766, 170, 0, 182, 0, 0, 0, 804, 881, 0, 0, - 0, 823, 810, 0, 831, 782, 485, 482, 791, 0, + 0, 0, 810, 0, 831, 782, 485, 482, 791, 0, 797, 0, 0, 789, 0, 794, 861, 523, 522, 878, 874, 0, 616, 0, 0, 893, 916, 0, 903, 0, 0, 930, 0, 74, 66, 0, 0, 0, 309, 0, @@ -9603,136 +9603,136 @@ void case_972() 0, 667,10923,10923, 9142, 396, -52, 698, 8374,11603, 308, 0, 679, 0, 722, 8079,10923, 728, 124, -260, 0,10923, 228,10379, 0, 0, 215,10923, 215, -279, - 474, 836, -281, 0, 466, -253, 850, -281,10923,10923, -10923, 113, 0, 825, 0, 7139, -272, 0, 0, 0, + 474, 827, -281, 0, 466, -253, 833, -281,10923,10923, +10923, 113, 0, 788, 0, 7139, -272, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3827, 0, 0, -12249, -279, 841, 807,10923, 0, 818, 0, 284, 0, - 0, 373, 0, 0, 798, 8514,10107, 0, 0,11603, +12249, -279, 783, 807,10923, 0, 793, 0, 284, 0, + 0, 373, 0, 0, 787, 8514,10107, 0, 0,11603, 10923,10923,10923,10923,10923,10923,10923,10923,10923,10923, 10923,11603,11603,11603, 8079, 8079,11603,11603,11603,11603, 11603,11603,11603,11603,11603,11603,11603,11603,11603,11603, 11603,11603,10923, 0, 0, 0, 0, 466, 0, 0, 0, 0,12339,12339, 0, 0, -281, 0, 0, 0, - 0, 389, 877, 0, 0, 0, 0, 0, 0, 0, - 8, 743, 817, 0, 820, 0, 818, 503, 503, 0, - -154, 0, 643, 503, 867, 0, -213,12893, 0, 0, + 0, 389, 812, 0, 0, 0, 0, 0, 0, 0, + 8, 743, 795, 0, 798, 0, 793, 503, 503, 0, + -154, 0, 643, 503, 828, 0, -213,12893, 0, 0, 0, 0, -181, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -174,12923, 0, 0, 0, - 0, 818, 0, 0, 869, 460, 0, 870, 0, 873, + 0, 793, 0, 0, 825, 460, 0, 860, 0, 861, -175, 228, 0, -260, 0, 0, 0, -281,10379, -184, - 0, 871, 0, 0, 0, -76, -69, 0, 334, 0, - 880, 0, 876, 0, 0, 0, 590, 0, 8198, 685, + 0, 862, 0, 0, 0, -76, -69, 0, 334, 0, + 874, 0, 870, 0, 0, 0, 590, 0, 8198, 685, 10923, 698,10107, 0, 7610, 0, 215, 0, 0, 0, - 881, 71, 0, 0, 197, 228, -159, 0, 984, 884, - 0, 76, -281, 0, 87, 0, 0, 0,10923, 958, - 0, 0, 0,10923, 966, 887, 0, 892, 893, 0, + 873, 71, 0, 0, 197, 228, -159, 0, 984, 875, + 0, 76, -281, 0, 87, 0, 0, 0,10923, 954, + 0, 0, 0,10923, 958, 876, 0, 881, 884, 0, 12249, 0, 0, -140, -283, 7139, 0, 0, 0, 0, 0, 0, 228, 0, 0, -8, 0, 0, 0, 215, - -279, -281, 8531, 0, 894, 0, 895,11603, 0, 897, - 7139, 0, 264, 0, 376, 0, 818, 0, -177,10923, -10923, 898, 1015, 0, 0, -5, 901, 0, 0, 0, + -279, -281, 8531, 0, 886, 0, 889,11603, 0, 888, + 7139, 0, 264, 0, 376, 0, 793, 0, -177,10923, +10923, 894, 1011, 0, 0, -5, 895, 0, 0, 0, 604, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 604, 604, 125, 125, -273, -273, -273, -273, 580, 580, 626, 380, 410, - 384, 405, 0, 902, -193, 0, 8671, 982, -281, 986, - -281, 8671, 8671, 900,10923, 0, 0, 877, 0, -281, - 0, 773, 818, 0, 0, 0, 0, -176, 8, 147, - 0, 8531, 643, 0, 906, 908, 0, 0, 0, 0, - 0, 0, -279, 910, 0, 911, 913, 0, 0, 0, - 0, 912, 8688, 872, 0, 179, 0, 0, 550, 0, -11059, 0, 914, 0, 0, 0, 622, 920, 0, 919, - 922, 923, 0, 0,10923, 0, -281, 0, 0, 721, - 0, 924, 0, 420, 0, 0, 6982, 0, 6982, 8357, + 384, 405, 0, 893, -193, 0, 8671, 977, -281, 979, + -281, 8671, 8671, 896,10923, 0, 0, 812, 0, -281, + 0, 746, 793, 0, 0, 0, 0, -176, 8, 147, + 0, 8531, 643, 0, 903, 902, 0, 0, 0, 0, + 0, 0, -279, 905, 0, 906, 908, 0, 0, 0, + 0, 907, 8688, 865, 0, 179, 0, 0, 550, 0, +11059, 0, 904, 0, 0, 0, 622, 914, 0, 913, + 916, 918, 0, 0,10923, 0, -281, 0, 0, 721, + 0, 919, 0, 420, 0, 0, 6982, 0, 6982, 8357, 0, 9142, 0, 0,10515, 114, 0, -274, -115, 0, - 865, 878, 0, 52, 0, 0, 931, 0, 0, 0, - 0, 0, 930, 0, 0, 938, 0, 4145, 0, 228, - 0, 0, 215, 509, 888, 0, -255, 0, 947, 937, + 866, 871, 0, 52, 0, 0, 924, 0, 0, 0, + 0, 0, 923, 0, 0, 931, 0, 4145, 0, 228, + 0, 0, 215, 509, 880, 0, -255, 0, 932, 930, 0, 0, 6982, 0, 0, 6982, 0,10923, 0,10923, - 8079, 0, 0, 228, 950, 228, 0, 0, 0, 0, + 8079, 0, 0, 228, 933, 228, 0, 0, 0, 0, 0, 0, 0, 0, 8671, 8079, 0, 0, -281,12249, - 983, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 966, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9971, 0, 0, 0, 0,10243, - 8671, 0, 7767, 951, 0, 0, 0, 0, 1034, 0, - 1037, 0, 0, 0, 796, 0, 959, 0, 0, 0, - 0, 0, 0, 916, 0, -154, 0, 0, 0, 0, - 643, 643, 0, 817, 962, 968, 926, 970, 872, 0, - 965, 0, 1085, 1086, 0, 0,10923, 0,10651, 971, - 622, 8531, 8079, 0, 151, 1090, 1094, 91, 973, 0, - 0, 0,10923, 0,10923, 1072, 0, 0, 0, 0, - 84,10787, 0, 0, 0, 0, 7903, 0, 1105, 0, - 466,10923, 1002, 8357, 1006, 0, 0, -281, 0, 38, - 0, 0, 818, 888, 0, -281, 0, -179, 0, 0, - 0, 1005, 0, 1035, 0, 0, 0, 0, 0, 0, + 8671, 0, 7767, 936, 0, 0, 0, 0, 1025, 0, + 1028, 0, 0, 0, 782, 0, 951, 0, 0, 0, + 0, 0, 0, 910, 0, -154, 0, 0, 0, 0, + 643, 643, 0, 795, 961, 955, 915, 965, 865, 0, + 959, 0, 1081, 1083, 0, 0,10923, 0,10651, 967, + 622, 8531, 8079, 0, 151, 1084, 1086, 91, 963, 0, + 0, 0,10923, 0,10923, 1065, 0, 0, 0, 0, + 84,10787, 0, 0, 0, 0, 7903, 0, 1090, 0, + 466,10923, 983, 8357, 986, 0, 0, -281, 0, 38, + 0, 0, 793, 880, 0, -281, 0, -179, 0, 0, + 0, 980, 0, 1018, 0, 0, 0, 0, 0, 0, 0, 699, 0, 0, 0, 0, 8374, 0, 0, -281, - 505, 951, 0, 8671, 0, 8671, 0, 1032, 8671, 0, - 0, 0, 541, 0, 0, 0, 1014, 817, 0, 0, -11195, 0, 0, 0, 1016, 4304, 0, 872, 0, 872, - 0, 872, 0, 0, 0, 0, -281, 1010, 971, 0, - 0, 0, -163, -160, 1017, 1018, 0, 0, 0, 0, - 0, 1012, 8357, 951, -193,10923, 0, 1023, 6982, 0, - 0, 0, 0, 0, 0, 1019, 0, 698, 0, 0, - 0, 0, 0, -194, 0, 1024, 818, 888, 0, 888, - 0, 951, 1025, 0, 0, 228, 0, 967, 1020, 0, - 0, 0, 0, 0, 8671, 1051, 8671, 8671, 0,10923, - 0, 0, 913, 238, 747, 0, 0, 0, 0, -241, - 0, 0, 0, 1033, 0, 0, 0, 1022, 0, 0, - 0, 483, 0, 1036, 1160, 1162, 0, 0, 951, 1047, - 951, 0, 0, 733, 0, 0, 0, 0, 0,10923, - 0, 1052, -170, 0, -170, 0, 0, 0, 0, 0, - 0, 228, 0,10923, 8062, 0, 0, 1074, 0, 833, - 1048, 0, 1053, 0, 0,11195, 10, -175, 0, 1049, - 1049, 1049,10651, 1055, 0,10923, 0, 0, 0, 0, - 0, 0, 6982, 1054, 0, 0, 7139, 0, 811, 6982, - 0, 1056, 0, 8671, 0, 0, 0, 0, 0,10923, - 0, 0, 8, 1058, 8, 8079, 1088, 1088, 1088, 0, + 505, 936, 0, 8671, 0, 8671, 0, 1023, 8671, 0, + 0, 0, 541, 0, 0, 0, 999, 795, 0, 0, +11195, 0, 0, 0, 1006, 4304, 0, 865, 0, 865, + 0, 865, 0, 0, 0, 0, -281, 1002, 967, 0, + 0, 0, -163, -160, 1009, 1010, 0, 0, 0, 0, + 0, 1012, 8357, 936, -193,10923, 0, 1014, 6982, 0, + 0, 0, 0, 0, 0, 1017, 0, 698, 0, 0, + 0, 0, 0, -194, 0, 1019, 793, 880, 0, 880, + 0, 936, 1020, 0, 0, 228, 0, 972, 1008, 0, + 0, 0, 0, 0, 8671, 1043, 8671, 8671, 0,10923, + 0, 0, 908, 238, 772, 0, 0, 0, 0, -241, + 0, 0, 0, 1029, 0, 0, 0, 1016, 0, 0, + 0, 483, 0, 1022, 1142, 1144, 0, 0, 936, 1044, + 936, 1045, 0, 1042, 0, 0, 0, 0, 0,10923, + 0, 1033, -170, 0, -170, 0, 0, 0, 0, 0, + 0, 228, 0,10923, 8062, 0, 0, 1072, 0, 824, + 1046, 0, 1051, 0, 0,11195, 10, -175, 0, 1047, + 1047, 1047,10651, 1053, 0,10923, 0, 0, 0, 0, + 0, 0, 6982, 1049, 0, 0, 7139, 0, 820, 6982, + 0, 1055, 0, 8671, 0, 0, 0, 0, 0,10923, + 0, 0, 8, 1054, 8, 8079, 1088, 1088, 1088, 0, 0,10923, 0, 6982, 8828, 0, 0, 7139, 0, 0, - 0, 0, 0, 1080, 8671,10923, 0, 8, 1063, 0, - 1027, 0, 1062, 0, 0, -95, 0, 1029, 0, 1088, - 0, 0, 0, 0, 0, 0, 0, 1076, 924, 0, - 7139, 0, 1101, 0, 1075, 1088, 0, 1084, 8, 0, - 8079, -151, 1087, 0, 1092, 1111, 6982, 1100, 8671, 0, - 0, 0, 0, 1102, 1075, 0, 0, 0,11899, 68, - 8, 0, 0, 0, 1097, 8671, 1106,10923, 0, 0, - 1110, 0, 0, 1114, 0, 0,12923, 828, 0, 1116, + 0, 0, 0, 1080, 8671,10923, 0, 8, 1061, 0, + 1013, 0, 1056, 0, 0, -95, 0, 1027, 0, 1088, + 0, 0, 0, 0, 0, 0, 0, 1064, 919, 0, + 7139, 0, 1099, 0, 1073, 1088, 0, 1085, 8, 0, + 8079, -151, 1087, 0, 1092, 1101, 6982, 1110, 8671, 0, + 0, 0, 0, 1067, 1073, 0, 0, 0,11899, 68, + 8, 0, 0, 0, 1095, 8671, 1076,10923, 0, 0, + 1111, 0, 0, 1107, 0, 0,12923, 841, 0, 1115, 68, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 611,12923, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1117, 8, 0, 68, -281, 0, - 1097, 0, 0, 1118,11899,12065, 0, 0, 0, 521, - 0, 0, 0,12097, 0, 0, 1125, 0, 0, 0, - 0, 8079, 8079, 295, 8374, 305, 215, 1157, 0, -279, - 4816, 0, 1190, 0, 0, 1075, 0, 0, 0, 1075, - 0, 1079, 1082, 0, 8079, -157, 0, 8079, 0, 1091, - 1132, 0, -279, 0, 24, 9890, 0, 1127, 1096, 53, - 548, 1078, 0, 0, 1075, 0, -279, 0, 1137, 1098, - 1134, 1130, 0, 1139, 1082, 1144, -175, 1136, 1135, 0, - 0, 1149, 1154, 0, 818, 0, 795, 0, 0, 0, - 1152, 0, -150, 0, 1143, 0, 0, 1158, 0, 1155, - 1159, 1161, 0, 1156, 0, -175, -175, 0, -175, 1163, - 1166, 0, 0, 0, 0, 1167, 73, 0, 1171, -175, - 1273, 1172, -175, 0, 521, 0, 8357, 1131, 1178, 1156, - 0, 1183, 1184, 118, 1164, 0, 0, -175,10651, 1141, - 1181, 1167, 0, 0,12923, 0, 8, 8, 0, 1142, - 1187, 1171, 0, 1193, 0,10923, 1148, 1191, 1172, 0, - 1196, -175, 0, -143, 0, 1151, 0, 0, 0, 0, - 0,12923, 0, 118, 118, 1168, 1197, 0, -150, 0, - 0, 237, 1202,12923, 0,12923, 0, 0, 8357, 1192, - 0, 0, 0, 1201, 1158, 0, 0, 0, 1200, 0, - 183, 0, 0, 0, 1088, 847, 1210, 0, 0, 0, - 0, 0, 0, 0, 0, 1265, 1318, 0, 0, 0, - 0, 0, 0, 1214, 1217, 8357, 0, 0, 0, 0, + 0, 0, 0, 0, 1116, 8, 0, 68, -281, 0, + 1095, 0, 0, 1113,11899,12065, 0, 0, 0, 521, + 0, 0, 0,12097, 0, 0, 1120, 0, 0, 0, + 0, 8079, 8079, 295, 8374, 305, 215, 1153, 0, -279, + 4816, 0, 1188, 0, 0, 1073, 0, 0, 0, 1073, + 0, 1077, 1079, 0, 8079, -157, 0, 8079, 0, 1082, + 1123, 0, -279, 0, 24, 9890, 0, 1127, 1091, 53, + 548, 1078, 0, 0, 1073, 0, -279, 0, 1136, 1096, + 1133, 1129, 0, 1135, 1079, 1137, -175, 1134, 1143, 0, + 0, 1139, 1150, 0, 793, 0, 797, 0, 0, 0, + 1149, 0, -150, 0, 1140, 0, 0, 1154, 0, 1155, + 1152, 1157, 0, 1156, 0, -175, -175, 0, -175, 1158, + 1159, 0, 0, 0, 0, 1160, 73, 0, 1161, -175, + 1271, 1162, -175, 0, 521, 0, 8357, 1121, 1165, 1156, + 0, 1173, 1174, 118, 1163, 0, 0, -175,10651, 1131, + 1178, 1160, 0, 0,12923, 0, 8, 8, 0, 1138, + 1179, 1161, 0, 1185, 0,10923, 1141, 1184, 1162, 0, + 1191, -175, 0, -143, 0, 1186, 0, 0, 0, 0, + 0,12923, 0, 118, 118, 1198, 1194, 0, -150, 0, + 0, 237, 1200,12923, 0,12923, 0, 0, 8357, 1189, + 0, 0, 0, 1199, 1154, 0, 0, 0, 1201, 0, + 183, 0, 0, 0, 1088, 854, 1203, 0, 0, 0, + 0, 0, 0, 0, 0, 1257, 1315, 0, 0, 0, + 0, 0, 0, 1209, 1210, 8357, 0, 0, 0, 0, 118, 551, 551, 0, 1088, 0, 0, 0, -58, -58, 0, 0, 0, 0, 0, 0, 0,10107,10107, 0, - 0, 0, 0, 0, 1221, 1218, 1219, 0, 0, 0, + 0, 0, 0, 0, 1217, 1216, 1218, 0, 0, 0, }; protected static readonly short [] yyRindex = { 1489, - 0, 0, 7296, 1489, 0, 0, 0, 1594, 0, 0, + 0, 0, 7296, 1489, 0, 0, 0, 1589, 0, 0, 3036, 2950, 0, 0, 0, 0, 0, 3036, 0, 0, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1596, 0, 0, 1596, 0, 0, 1594, + 0, 0, 0, 1591, 0, 0, 1591, 0, 0, 1589, 3107, 1241, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 1230, 0, 0, 0, 0, 0, 0, 0, 0, - 8845, 0, 1222, 0, 0, 0, 1222, 0, 0, 0, + 0, 1227, 0, 0, 0, 0, 0, 0, 0, 0, + 8845, 0, 1220, 0, 0, 0, 1220, 0, 0, 0, 0, 0, 0, 287, 0, 0, 0, 0, 0, 0, 0, 0, 201, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4527, 0, 0, 0, 0, @@ -9744,23 +9744,23 @@ void case_972() 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 83, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3150, 0, - 779, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 759, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1596, 172, 0, 0, 0, 0, 0, 0, + 0, 0, 1591, 172, 0, 0, 0, 0, 0, 0, 0, 3193, 526, 3236, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3508, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1231, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1229, 0, 0, 0, 0, 0, 3508, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2193, 0, 2703, 300, 2323, 0, 0, 0, 2453, 2323, 0, 0, 0, 0, - 0, 1230, 0, 0, 0, -57, 0, 0, 0, 0, + 0, 1227, 0, 0, 0, -57, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1232, 2557, 0, 0, 1222, 0, 3508, 0, 0, 0, + 1226, 2557, 0, 0, 1220, 0, 3508, 0, 0, 0, 0, 0, 0, 0, 0, 0, 158, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -9768,21 +9768,21 @@ void case_972() 0, 0, 0, 0, 0, 0, 0, 1586, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1284, 0, 0, 0, 0, 0, 0, 0, - 3299, 3342, 0, 0, 0, 0, 2047, 1596, 1596, 0, - -111, 0, 7627, 1596, 1602, 0, 0, 242, 0, 0, + 3299, 3342, 0, 0, 0, 0, 2047, 1591, 1591, 0, + -111, 0, 7627, 1591, 1599, 0, 0, 242, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 316,11752, 0, 0, 0, 0, 3508, 0, 0, 0, 0, 0, 0, 0, 0, -12141, 0, 0, 0, 0, 0, 0, 0, 742, 0, +12141, 0, 0, 0, 0, 0, 0, 0, 733, 0, 0, 0, 0, 0, 0, 0, 0, 0, 683, 956, - 0, 0, 1237, 0, 0, 0, 0, 0, 39, 0, - 0, 3985, 1234, 0, 0, 0, -198, 0, 0, 0, + 0, 0, 1234, 0, 0, 0, 0, 0, 39, 0, + 0, 3985, 1232, 0, 0, 0, -198, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1754, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1232, 0, 0, 6665, 0, 41, 0, 0, 0, 0, + 1226, 0, 0, 6665, 0, 41, 0, 0, 0, 0, 0, 0, 8985, 0, 0, 0, 0, 0, 0, -164, - 481, 0, 0, 0, 1235, 0, 0, 0, 0, 0, + 481, 0, 0, 0, 1233, 0, 0, 0, 0, 0, 0, 0, 3508, 0, 3508, 0, 4144, 0, 0, 0, 0, 161, 0, 0, 0, 0, 182, 0, 0, 0, 5014, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -9790,17 +9790,17 @@ void case_972() 5390, 5526, 5594, 5662, 5730, 5866, 5934, 6070, 6206, 6342, 6478, 6602, 0, 0, 528, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1284, 0, 0, - 0, 0, 2047, 0, 0, 0, 0, 1194, 9333, 0, - 0, 0, 9002, 0, 0, 765, 0, 0, 0, 0, - 0, 0, 675, 649, 0, 0, 1238, 0, 0, 0, - 0, 1244, 0, 0, 0, 0, 0, 0,11331, 0, - 0, 0, 782, 0, 0, 0,12393, 0, 0, 789, - 792, 793, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 748, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 1246, 0, 0, 0, 3574, 0, 0, 108, 0, + 0, 0, 2047, 0, 0, 0, 0, 1190, 9333, 0, + 0, 0, 9002, 0, 0, 779, 0, 0, 0, 0, + 0, 0, 675, 649, 0, 0, 1236, 0, 0, 0, + 0, 1240, 0, 0, 0, 0, 0, 0,11331, 0, + 0, 0, 776, 0, 0, 0,12393, 0, 0, 786, + 789, 792, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 742, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1243, 0, 0, 0, 3574, 0, 0, 108, 0, 86, 3667, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1248, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 326, 694, 0, 0, 0, 0, 0, 1245, + 0, 0, 1244, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 326, 694, 0, 0, 0, 0, 0, 1242, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8985, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -9809,39 +9809,39 @@ void case_972() 0, 0, 0, 564, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 133, 0, 471, 0, 0, 0, 0, 0, 0, 0, 0, -111, 0, 0, 0, 0, -12393, 7784, 0, 1249, 0, 752, 0, 0, 0, 0, - 1253, 0, 1203, 1204, 0, 0, 0, 0, 0, 1251, -12410, 0, 0, 0,12217, 0, 0, 0, 802, 0, +12393, 7784, 0, 1246, 0, 750, 0, 0, 0, 0, + 1250, 0, 1202, 1204, 0, 0, 0, 0, 0, 1245, +12410, 0, 0, 0,12217, 0, 0, 0, 791, 0, 0, 0, 0, 0, 0, 1921, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 3826, 0, 4303, 1256, 0, 0, 0, 1257, 0, 0, - 0, 0, 298, 0, 0, 0, 0, 802, 0, 0, + 3826, 0, 4303, 1251, 0, 0, 0, 1252, 0, 0, + 0, 0, 298, 0, 0, 0, 0, 791, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -244, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 803, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1266, 0, - 0, 0, 0, 0, 814, 822, 0, 0, 0, 0, - 0, 0, 0, 1269, 663, 755, 0, 0, 0, 0, + 802, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1249, 0, + 0, 0, 0, 0, 805, 814, 0, 0, 0, 0, + 0, 0, 0, 1255, 663, 1253, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3985, 0, 0, - 0, 0, 0, 1275, 0, 0, 298, 0, 0, 846, - 0, 1269, 0, 0, 0, 8985, 0, 628, 666, 0, + 0, 0, 0, 1273, 0, 0, 298, 0, 0, 848, + 0, 1255, 0, 0, 0, 8985, 0, 628, 666, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1238, 9179, 0, 0, 0, 0, 0,12474, + 0, 0, 1236, 9179, 0, 0, 0, 0, 0,12474, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 690, 0, 700, 0, 0, 0, 0, 1272, 0, - 760, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1278, 0, 7453, 0, 0, 0, 0, 0, + 0, 690, 0, 700, 0, 0, 0, 0, 1270, 0, + 754, 1267, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1276, 0, 7453, 0, 0, 0, 0, 0, 0, 8985, 0, 0, 0, 0, 0, 0, 0, 233, 592, 0, 0, 0, 0, 0,12543,12141, 0, 392, 392, 392, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0,12586, 0, -282, 0, 1258, 1258, 1258, 0, - 0, 0, 0, 0, 1276, 0, 0, -201, 0, 0, + 0, 0,12586, 0, -282, 0, 1279, 1279, 1279, 0, + 0, 0, 0, 0, 1275, 0, 0, -201, 0, 0, 0, 0, 0, 0, 0, 0, 0,12629, 0, 0, - 0, 0, 1279, 0, 0, 413, 0, 0, 0, 576, + 0, 0, 1280, 0, 0, 413, 0, 0, 0, 576, 0, 0, 0, 0, 0, 0, 0, 0, 1277, 0, 1282, 0, 0, 0, 2993, 1281, 451, 0, 265, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -9858,39 +9858,39 @@ void case_972() 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 232, 0, 1286, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2861, 0, 540, 0, 633, 0, - 0, 0, 0, 0, 0, 0,12141, 819, 0, 0, + 0, 0, 0, 0, 0, 0,12141, 818, 0, 0, 0, 0, 0, 0, 1288, 0, 408, 0, 0, 0, - 0, 0, 0, 0, 824, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 819, 0, 0, 0, 0, 0, 0, 0, 0, 1287, 0,12141,12141, 0,12173, 0, 0, 0, 0, 0, 0, 1291,12853, 0, 1292,12141, 11467, 1295,12141, 0, 0, 0, 0, 0, 0, 1307, 0, 0, 0,12823, 0, 0, 0,12141, 0, 0, 0, 1308, 0, 0, 339, 0,12747,12785, 0, 0, 0, 1310, 0, 0, 0, 0, 0, 0, 1311, 0, - 0,12141, 0, 613, 0, 830, 0, 0, 0, 0, - 0, 856, 0,12671,12709, 0, 0, 0, 0, 0, - 0, 0, 0, 1347, 0, 1392, 0, 0, 0, 831, + 0,12141, 0, 613, 0, 822, 0, 0, 0, 0, + 0, 858, 0,12671,12709, 0, 0, 0, 0, 0, + 0, 0, 0, 1347, 0, 1392, 0, 0, 0, 830, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 598, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12823, 9173,11639, 0, 598, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 1234, 1234, 0, + 0, 0, 0, 0, 0, 0, 0, 1232, 1232, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; protected static readonly short [] yyGindex = { 0, 0, 1614, 0, 0, 0, 1, -12, -172, -41, -50, 0, 1654, 1683, 725, 0, 2, 0, 0, 0, 0, 0, -921, -697, -219, -305, 0, 0, 0, 0, 0, - -223, 0, 0, 0, 745, 0, 851, 0, 0, 0, - 0, 594, 595, -17, -217, 0, 3, 0, 441, 0, + -223, 0, 0, 0, 745, 0, 846, 0, 0, 0, + 0, 595, 599, -17, -217, 0, 3, 0, 441, 0, 472,-1122, -730, -524, -507, -500, -498, -491, -471, 0, 0,-1157, 0, 13, 0, 129, 0,-1089, 0, 0, 0, -80, 258, 0, 0, 0, 302,-1062, 0, -270, - -289, 1026, 0, 0, 0, -893, 250, 0, 0, -503, - 0, 0, 317, 0, 0, 292, 0, 0, 321, 0, + -289, 1024, 0, 0, 0, -893, 250, 0, 0, -503, + 0, 0, 319, 0, 0, 292, 0, 0, 321, 0, -549, -984, 0, 0, 0, 0, 0, 421, -13, 0, - 0, 849, 852, 853, 1028, -497, 0, 0, -312, 854, + 0, 849, 850, 852, 1021, -497, 0, 0, -312, 864, 416, 0, -812, 0, 0, 0, 0, 0, 0, 0, 0, 221, 0, 0, 0, 0, 0, 0, 0, 0, 470, 0, 0, 0, 0, -337, 422, 0, 0, 0, @@ -9899,31 +9899,31 @@ void case_972() 0, 335, 0, 0, 340, 342, 259, 0, 0, 0, 0, 0, 0, 0, 0, 562, 0, 0, 0, 0, -54, 0, 310, -156, 0, 0, 409, 0, 467, 0, - 921, 0, 1233, -284, -261, -61, 572, 0, 568, 0, + 921, 0, 1230, -284, -261, -61, 572, 0, 569, 0, -32, 126, 0, 0, 929, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -258, 0, 1290, 0, 0, -767, 0, 0, 0, - 885, 0, -296, -133, 1039, 955, 0, 957, 0, 1174, - 1402, 1089, 0, 0, 777, 1700, 0, 0, 0, 0, + 877, 0, -296, -133, 1037, 960, 0, 957, 0, 1177, + 1405, 1089, 0, 0, 774, 1704, 0, 0, 0, 0, 1057, 0, 0, 0, 0, 0, -824, 1444, 0, 0, - 0, 0, 0, 1340, 439, 837, 749, 827, 1380, 1384, + 0, 0, 0, 1340, 439, 837, 749, 840, 1380, 1384, 1379, 1383, 1386, 0, 1382, 0, -595, 0, 0, 998, - 1242, -734, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, -286, 0, 0, 0, 0, -447, 0, 619, + 1238, -734, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, -286, 0, 0, 0, 0, -447, 0, 623, 0, 527, 0, 614, 0, 0, 0, 677, -530, -15, -311, -1, 0, 1640, 0, 92, 0, 112, 121, 128, 134, 135, 136, 137, 141, 142, 145, 0, -679, 0, - -28, 0, 0, 823, 0, 741, 0, 0, 0, 0, - 718, -335, 797, -859, 0, 835, -460, 0, 0, 0, - 0, 0, 0, 732, 0, 0, 736, 0, 0, 0, + -28, 0, 0, 817, 0, 744, 0, 0, 0, 0, + 718, -335, 796, -859, 0, 835, -460, 0, 0, 0, + 0, 0, 0, 734, 0, 0, 736, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 662, 0, 0, 0, 0, 0, 0, 0, - 0, -33, 0, 1289, 0, 0, 0, 905, 0, 0, + 0, 0, 664, 0, 0, 0, 0, 0, 0, 0, + 0, -33, 0, 1289, 0, 0, 0, 909, 0, 0, 0, 0, 0, 0, -167, 0, 0, 0, 0, 0, - 1395, 1170, 0, 0, 0, 1397, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 553, 0, 0, 0, 0, - 0, 0, 0, 0, 664, 0, 0, 0, 0, 0, - 0, 6, 979, 0, 0, 0, 985, + 1391, 1166, 0, 0, 0, 1396, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 558, 0, 0, 0, 0, + 0, 0, 0, 0, 665, 0, 0, 0, 0, 0, + 0, 6, 978, 0, 0, 0, 982, }; protected static readonly short [] yyTable = { 109, 234, 155, 737, 111, 18, 189, 323, 328, 516, 233, @@ -10036,79 +10036,79 @@ void case_972() 1017, 180, 810, 180, 334, 334, 923, 225, 1038, 228, 194, 923, 432, 923, 1133, 491, 923, 923, 491, 923, 923, 233, 871, 1161, 334, 194, 872, 520, 475, 194, - 326, 558, 334, 523, 1111, 334, 816, 432, 1112, 966, - 469, 231, 1157, 817, 115, 560, 233, 817, 1095, 821, - 1096, 65, 326, 821, 491, 65, 822, 113, 1223, 539, - 822, 753, 558, 434, 969, 753, 969, 816, 1090, 622, - 623, 624, 625, 544, 326, 435, 560, 1161, 830, 940, - 941, 334, 113, 194, 334, 761, 1339, 761, 156, 1228, - 156, 163, 164, 163, 164, 558, 923, 552, 1227, 1245, - 1339, 194, 194, 880, 67, 880, 67, 1149, 1150, 560, - 1228, 816, 579, 186, 1223, 186, 1126, 1127, 1370, 1227, - 1371, 157, 120, 157, 120, 1267, 231, 284, 816, 284, - 491, 1302, 1303, 127, 291, 127, 291, 1228, 348, 441, - 1488, 1489, 578, 258, 1245, 587, 1227, 521, 521, 638, - 638, 626, 627, 258, 1331, 620, 621, 1334, 258, 1138, - 1139, 348, 650, 326, 352, 669, 194, 653, 115, 752, - 32, 692, 115, 689, 694, 115, 715, 721, 24, 722, - 25, 768, 744, 26, 326, 761, 1299, 194, 27, 770, - 771, 1278, 28, 772, 773, 194, 791, 790, 805, 115, - 806, 30, 793, 115, 810, 818, 811, 840, 32, 820, - 824, 841, 435, 33, 847, 843, 844, 34, 113, 42, - 113, 864, 865, 196, 859, 866, 867, 873, 258, 36, - 889, 37, 893, 894, 896, 38, 115, 1349, 901, 906, - 258, 258, 258, 39, 40, 258, 258, 41, 905, 326, - 753, 914, 115, 498, 930, 920, 412, 935, 412, 498, - 937, 950, 942, 944, 113, 1405, 954, 113, 951, 956, - 959, 961, 326, 953, 967, 979, 290, 412, 412, 980, - 261, 989, 1432, 983, 285, 286, 287, 326, 293, 294, - 996, 326, 201, 306, 307, 1444, 1446, 412, 509, 740, - 312, 1299, 314, 1003, 318, 412, 1014, 1015, 412, 330, - 331, 491, 1028, 1032, 371, 1049, 1041, 1057, 1067, 1084, - 1055, 1056, 1432, 1432, 1065, 1077, 1081, 1087, 1454, 1099, - 1085, 320, 1103, 367, 202, 372, 373, 374, 375, 376, - 377, 378, 379, 380, 381, 1107, 1106, 1108, 1109, 1115, - 1125, 1128, 1129, 1136, 1141, 1153, 1168, 1182, 1147, 1160, - 1185, 740, 335, 326, 326, 1189, 338, 339, 340, 341, - 342, 343, 344, 345, 1187, 194, 1192, 1197, 1200, 1432, - 1201, 1205, 1259, 1210, 203, 204, 205, 206, 1211, 207, - 208, 209, 210, 211, 212, 213, 214, 1214, 740, 215, - 216, 217, 218, 219, 220, 221, 222, 1212, 1503, 1503, - 1264, 1262, 1218, 1268, 1275, 1512, 1512, 1265, 33, 1280, - 594, 594, 1301, 1309, 1322, 1344, 1326, 32, 326, 1327, - 194, 32, 1337, 1354, 1356, 1357, 258, 1365, 1336, 1359, - 475, 475, 32, 1345, 1361, 1347, 1363, 32, 194, 1367, - 1368, 32, 1373, 1378, 32, 1384, 1381, 326, 1415, 1388, - 1385, 1464, 1386, 1436, 1470, 1396, 32, 32, 1397, 939, - 1400, 32, 32, 312, 1410, 1417, 367, 32, 1426, 32, - 32, 32, 32, 1427, 1429, 1430, 1440, 32, 1439, 1450, - 113, 32, 1451, 32, 1453, 1455, 1456, 1458, 1471, 1475, - 1480, 1482, 1479, 32, 194, 194, 32, 1490, 32, 1474, - 1473, 584, 32, 194, 1496, 502, 513, 1497, 1518, 1519, - 1520, 194, 194, 9, 194, 965, 534, 850, 492, 529, - 1319, 957, 32, 602, 493, 449, 603, 29, 32, 32, - 21, 672, 1319, 491, 194, 29, 517, 194, 30, 312, - 207, 96, 939, 30, 660, 1319, 763, 939, 858, 939, + 326, 558, 334, 523, 817, 334, 816, 432, 817, 966, + 469, 231, 1157, 821, 115, 560, 233, 821, 435, 65, + 539, 830, 326, 65, 491, 753, 544, 113, 1223, 753, + 552, 334, 558, 434, 334, 940, 941, 816, 1090, 622, + 623, 624, 625, 1095, 326, 1096, 560, 1161, 969, 761, + 969, 761, 113, 194, 578, 156, 1339, 156, 163, 1228, + 163, 164, 880, 164, 880, 558, 923, 650, 1227, 1245, + 1339, 194, 194, 67, 186, 67, 186, 1126, 1127, 560, + 1228, 816, 579, 157, 1223, 157, 1149, 1150, 1370, 1227, + 1371, 120, 284, 120, 284, 127, 669, 127, 816, 689, + 491, 1302, 1303, 291, 587, 291, 348, 1228, 1267, 231, + 348, 441, 352, 258, 1245, 653, 1227, 1488, 1489, 521, + 521, 638, 638, 258, 1331, 620, 621, 1334, 258, 1138, + 1139, 692, 694, 326, 626, 627, 194, 715, 115, 752, + 32, 721, 115, 722, 744, 115, 761, 768, 24, 771, + 25, 770, 772, 26, 326, 773, 1299, 194, 27, 790, + 791, 1278, 28, 793, 805, 194, 806, 811, 810, 115, + 818, 30, 820, 115, 840, 841, 824, 435, 32, 847, + 843, 844, 42, 33, 859, 864, 865, 34, 113, 866, + 113, 867, 873, 889, 196, 893, 894, 896, 258, 36, + 901, 37, 906, 905, 914, 38, 115, 1349, 920, 930, + 258, 258, 258, 39, 40, 258, 258, 41, 935, 326, + 753, 937, 115, 498, 942, 951, 412, 944, 412, 498, + 950, 954, 953, 956, 113, 1405, 959, 113, 961, 979, + 967, 980, 326, 983, 989, 996, 290, 412, 412, 509, + 261, 1014, 1432, 1003, 285, 286, 287, 326, 293, 294, + 1015, 326, 201, 306, 307, 1444, 1446, 412, 1032, 740, + 312, 1299, 314, 1028, 318, 412, 1041, 1049, 412, 330, + 331, 491, 1055, 1056, 371, 1065, 1067, 1057, 1085, 1087, + 1077, 1081, 1432, 1432, 1084, 1099, 1103, 1107, 1454, 1108, + 1115, 320, 1106, 367, 202, 372, 373, 374, 375, 376, + 377, 378, 379, 380, 381, 1109, 1111, 1112, 1125, 1128, + 1129, 1136, 1141, 1147, 1153, 1160, 1168, 1182, 1185, 1189, + 1187, 740, 335, 326, 326, 1197, 338, 339, 340, 341, + 342, 343, 344, 345, 1192, 194, 1200, 1218, 1201, 1432, + 1259, 1262, 1205, 1210, 203, 204, 205, 206, 1211, 207, + 208, 209, 210, 211, 212, 213, 214, 1212, 740, 215, + 216, 217, 218, 219, 220, 221, 222, 1214, 1503, 1503, + 1265, 1264, 1268, 1275, 1280, 1512, 1512, 1301, 33, 1309, + 594, 594, 1322, 1337, 1326, 1344, 1327, 32, 326, 1336, + 194, 32, 1354, 1356, 1357, 1359, 258, 1361, 1345, 1367, + 475, 475, 32, 1347, 1363, 1365, 1368, 32, 194, 1373, + 1378, 32, 1381, 1385, 32, 1384, 1415, 326, 1386, 1388, + 1396, 1397, 1436, 1400, 1410, 1417, 32, 32, 1426, 939, + 1427, 32, 32, 312, 1429, 1430, 367, 32, 1439, 32, + 32, 32, 32, 1440, 1451, 1450, 1453, 32, 1455, 1456, + 113, 32, 1458, 32, 1470, 1471, 1464, 1475, 1480, 1479, + 1490, 1474, 1482, 32, 194, 194, 32, 1473, 32, 1496, + 1497, 584, 32, 194, 1518, 502, 513, 1519, 9, 1520, + 965, 194, 194, 534, 194, 850, 492, 602, 957, 529, + 1319, 493, 32, 449, 603, 29, 21, 672, 32, 32, + 491, 29, 1319, 517, 194, 30, 312, 194, 30, 207, + 763, 96, 939, 858, 764, 1319, 755, 939, 822, 939, 939, 939, 939, 939, 939, 939, 939, 939, 939, 335, - 755, 764, 787, 756, 1319, 788, 316, 824, 826, 683, + 787, 756, 823, 788, 1319, 660, 824, 316, 826, 683, 258, 939, 341, 939, 638, 939, 660, 939, 939, 939, 334, 638, 123, 230, 584, 53, 105, 287, 547, 584, 130, 584, 584, 584, 584, 584, 584, 584, 584, 584, - 584, 584, 124, 106, 113, 288, 131, 21, 113, 1131, - 1132, 113, 1033, 584, 949, 584, 1472, 584, 1277, 584, - 584, 584, 1269, 1441, 1481, 1423, 1428, 326, 849, 547, - 1457, 1316, 939, 976, 972, 113, 977, 978, 1329, 113, - 1514, 613, 614, 615, 862, 1276, 547, 547, 547, 547, + 584, 584, 124, 106, 113, 288, 131, 21, 113, 949, + 1131, 113, 1033, 584, 1132, 584, 1472, 584, 1277, 584, + 584, 584, 1269, 1441, 1481, 1423, 849, 326, 1428, 547, + 1457, 1316, 939, 976, 977, 113, 978, 862, 1329, 113, + 1514, 613, 614, 615, 972, 1276, 547, 547, 547, 547, 547, 547, 547, 547, 547, 547, 547, 547, 547, 547, 547, 547, 1273, 1351, 1506, 33, 1452, 1447, 1445, 33, - 1206, 1505, 113, 852, 584, 1372, 945, 1320, 1207, 922, - 33, 758, 326, 881, 804, 33, 924, 589, 113, 33, - 298, 995, 33, 705, 1068, 550, 628, 630, 879, 858, - 326, 629, 631, 633, 33, 33, 632, 919, 1194, 33, - 33, 1281, 775, 1148, 1198, 33, 405, 33, 33, 33, - 33, 1110, 1123, 1050, 1116, 33, 1179, 1061, 1080, 33, - 1118, 33, 1012, 1279, 748, 751, 648, 828, 649, 1184, - 947, 33, 0, 33, 33, 946, 33, 0, 0, 0, + 1206, 1505, 113, 852, 584, 1372, 945, 1320, 758, 1207, + 33, 881, 326, 995, 922, 33, 924, 804, 113, 33, + 589, 1068, 33, 705, 298, 550, 628, 630, 879, 858, + 326, 629, 631, 633, 33, 33, 632, 919, 775, 33, + 33, 1281, 1194, 1148, 1198, 33, 405, 33, 33, 33, + 33, 1061, 1123, 1050, 1110, 33, 1116, 1080, 1179, 33, + 1118, 33, 648, 828, 748, 751, 1012, 649, 1279, 947, + 1184, 33, 946, 33, 33, 0, 33, 0, 0, 0, 33, 0, 0, 0, 0, 0, 326, 326, 0, 0, 0, 502, 0, 0, 0, 326, 502, 502, 547, 0, 33, 0, 0, 326, 326, 0, 326, 33, 0, 0, @@ -11368,78 +11368,78 @@ void case_972() 771, 344, 1133, 346, 1097, 1103, 349, 350, 1106, 352, 353, 1133, 372, 1135, 412, 786, 376, 376, 1096, 790, 529, 1117, 420, 376, 372, 423, 1124, 1158, 376, 1399, - 368, 369, 1130, 372, 989, 1117, 1158, 376, 372, 372, - 374, 370, 551, 376, 1142, 374, 372, 556, 1209, 294, - 376, 372, 1148, 1290, 370, 376, 372, 1155, 1156, 391, - 392, 393, 394, 294, 573, 373, 1148, 1189, 376, 354, - 355, 373, 581, 844, 376, 374, 1313, 376, 370, 1210, - 372, 370, 370, 372, 372, 1181, 429, 343, 1210, 1211, - 1327, 862, 863, 372, 372, 374, 374, 367, 368, 1181, - 1231, 1199, 376, 370, 1265, 372, 354, 355, 1345, 1231, - 1347, 370, 374, 372, 376, 368, 369, 374, 1216, 376, - 1218, 1282, 1283, 374, 374, 376, 376, 1258, 414, 415, - 364, 365, 372, 285, 1256, 418, 1258, 372, 373, 364, - 365, 395, 396, 295, 1305, 389, 390, 1308, 300, 1101, - 1102, 414, 356, 662, 418, 369, 927, 418, 1113, 256, - 0, 372, 1117, 375, 372, 1120, 376, 368, 265, 374, - 267, 294, 372, 270, 683, 372, 1270, 948, 275, 294, - 374, 1259, 279, 372, 372, 956, 372, 374, 371, 1144, - 256, 288, 376, 1148, 374, 294, 375, 372, 295, 294, - 381, 374, 373, 300, 373, 375, 374, 304, 717, 418, - 719, 372, 374, 429, 381, 374, 374, 374, 370, 316, - 423, 318, 372, 374, 367, 322, 1181, 1321, 421, 373, - 382, 383, 384, 330, 331, 387, 388, 334, 372, 748, - 337, 372, 1197, 368, 374, 343, 371, 294, 373, 374, - 294, 370, 374, 418, 763, 1377, 367, 766, 371, 375, - 256, 256, 771, 418, 374, 256, 363, 392, 393, 256, - 61, 280, 1394, 381, 65, 66, 67, 786, 69, 70, - 256, 790, 285, 74, 75, 1407, 1408, 412, 367, 1387, - 81, 1385, 83, 368, 85, 420, 372, 343, 423, 90, - 91, 1399, 351, 370, 381, 376, 371, 376, 370, 423, - 374, 374, 1434, 1435, 372, 372, 372, 347, 1416, 367, - 381, 418, 381, 114, 327, 402, 403, 404, 405, 406, - 407, 408, 409, 410, 411, 256, 381, 256, 372, 368, - 347, 374, 370, 375, 370, 370, 339, 348, 375, 372, - 368, 1449, 93, 862, 863, 374, 97, 98, 99, 100, - 101, 102, 103, 104, 418, 1136, 418, 372, 348, 1491, - 376, 368, 356, 367, 377, 378, 379, 380, 367, 382, - 383, 384, 385, 386, 387, 388, 389, 368, 1486, 392, - 393, 394, 395, 396, 397, 398, 399, 367, 1492, 1493, - 371, 376, 381, 368, 368, 1499, 1500, 374, 0, 372, - 1508, 1509, 368, 337, 305, 369, 418, 257, 927, 418, - 1191, 261, 371, 367, 371, 376, 578, 373, 418, 371, - 1508, 1509, 272, 418, 371, 418, 381, 277, 1209, 371, - 367, 281, 371, 381, 284, 371, 369, 956, 256, 374, - 372, 381, 372, 370, 367, 373, 296, 297, 373, 256, - 374, 301, 302, 254, 374, 374, 257, 307, 418, 309, - 310, 311, 312, 376, 372, 372, 376, 317, 418, 418, - 989, 321, 376, 323, 372, 418, 376, 372, 372, 368, - 370, 372, 381, 333, 1265, 1266, 336, 368, 338, 315, - 263, 256, 342, 1274, 371, 0, 297, 371, 368, 372, - 372, 1282, 1283, 0, 1285, 0, 367, 376, 368, 310, - 1291, 0, 362, 372, 368, 372, 372, 370, 368, 369, - 367, 418, 1303, 368, 1305, 368, 372, 1308, 370, 367, - 418, 418, 339, 368, 367, 1316, 376, 344, 372, 346, + 368, 369, 1130, 372, 989, 1117, 1158, 376, 373, 370, + 294, 376, 551, 374, 1142, 372, 294, 556, 1209, 376, + 343, 373, 1148, 1290, 376, 354, 355, 1155, 1156, 391, + 392, 393, 394, 372, 573, 374, 1148, 1189, 370, 374, + 372, 376, 581, 844, 372, 370, 1313, 372, 370, 1210, + 372, 370, 372, 372, 374, 1181, 429, 356, 1210, 1211, + 1327, 862, 863, 372, 370, 374, 372, 354, 355, 1181, + 1231, 1199, 376, 370, 1265, 372, 367, 368, 1345, 1231, + 1347, 374, 374, 376, 376, 374, 369, 376, 1216, 375, + 1218, 1282, 1283, 374, 418, 376, 414, 1258, 368, 369, + 414, 415, 418, 285, 1256, 418, 1258, 364, 365, 372, + 373, 364, 365, 295, 1305, 389, 390, 1308, 300, 1101, + 1102, 372, 372, 662, 395, 396, 927, 376, 1113, 256, + 0, 368, 1117, 374, 372, 1120, 372, 294, 265, 374, + 267, 294, 372, 270, 683, 372, 1270, 948, 275, 374, + 372, 1259, 279, 376, 371, 956, 256, 375, 374, 1144, + 294, 288, 294, 1148, 372, 374, 381, 373, 295, 373, + 375, 374, 418, 300, 381, 372, 374, 304, 717, 374, + 719, 374, 374, 423, 429, 372, 374, 367, 370, 316, + 421, 318, 373, 372, 372, 322, 1181, 1321, 343, 374, + 382, 383, 384, 330, 331, 387, 388, 334, 294, 748, + 337, 294, 1197, 368, 374, 371, 371, 418, 373, 374, + 370, 367, 418, 375, 763, 1377, 256, 766, 256, 256, + 374, 256, 771, 381, 280, 256, 363, 392, 393, 367, + 61, 372, 1394, 368, 65, 66, 67, 786, 69, 70, + 343, 790, 285, 74, 75, 1407, 1408, 412, 370, 1387, + 81, 1385, 83, 351, 85, 420, 371, 376, 423, 90, + 91, 1399, 374, 374, 381, 372, 370, 376, 381, 347, + 372, 372, 1434, 1435, 423, 367, 381, 256, 1416, 256, + 368, 418, 381, 114, 327, 402, 403, 404, 405, 406, + 407, 408, 409, 410, 411, 372, 372, 376, 347, 374, + 370, 375, 370, 375, 370, 372, 339, 348, 368, 374, + 418, 1449, 93, 862, 863, 372, 97, 98, 99, 100, + 101, 102, 103, 104, 418, 1136, 348, 381, 376, 1491, + 356, 376, 368, 367, 377, 378, 379, 380, 367, 382, + 383, 384, 385, 386, 387, 388, 389, 367, 1486, 392, + 393, 394, 395, 396, 397, 398, 399, 368, 1492, 1493, + 374, 371, 368, 368, 372, 1499, 1500, 368, 0, 337, + 1508, 1509, 305, 371, 418, 369, 418, 257, 927, 418, + 1191, 261, 367, 371, 376, 371, 578, 371, 418, 371, + 1508, 1509, 272, 418, 381, 373, 367, 277, 1209, 371, + 381, 281, 369, 372, 284, 371, 256, 956, 372, 374, + 373, 373, 370, 374, 374, 374, 296, 297, 418, 256, + 376, 301, 302, 254, 372, 372, 257, 307, 418, 309, + 310, 311, 312, 376, 376, 418, 372, 317, 418, 376, + 989, 321, 372, 323, 367, 372, 381, 368, 370, 381, + 368, 315, 372, 333, 1265, 1266, 336, 263, 338, 371, + 371, 256, 342, 1274, 368, 0, 297, 372, 0, 372, + 0, 1282, 1283, 367, 1285, 376, 368, 372, 0, 310, + 1291, 368, 362, 372, 372, 370, 367, 418, 368, 369, + 368, 368, 1303, 372, 1305, 370, 367, 1308, 368, 418, + 376, 418, 339, 372, 376, 1316, 372, 344, 376, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 300, - 372, 376, 368, 372, 1335, 368, 368, 372, 372, 368, + 368, 372, 376, 368, 1335, 367, 372, 368, 372, 368, 722, 368, 367, 370, 263, 372, 376, 374, 375, 376, 373, 315, 376, 50, 339, 12, 376, 376, 329, 344, 376, 346, 347, 348, 349, 350, 351, 352, 353, 354, - 355, 356, 376, 376, 1113, 376, 376, 5, 1117, 1096, - 1096, 1120, 948, 368, 844, 370, 1439, 372, 1258, 374, - 375, 376, 1231, 1402, 1455, 1385, 1390, 1136, 683, 370, - 1419, 1291, 429, 865, 861, 1144, 865, 865, 1303, 1148, - 1500, 382, 383, 384, 697, 1256, 387, 388, 389, 390, + 355, 356, 376, 376, 1113, 376, 376, 5, 1117, 844, + 1096, 1120, 948, 368, 1096, 370, 1439, 372, 1258, 374, + 375, 376, 1231, 1402, 1455, 1385, 683, 1136, 1390, 370, + 1419, 1291, 429, 865, 865, 1144, 865, 697, 1303, 1148, + 1500, 382, 383, 384, 861, 1256, 387, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, 1244, 1322, 1494, 257, 1412, 1408, 1407, 261, - 1189, 1493, 1181, 0, 429, 1347, 836, 1291, 1191, 805, - 272, 529, 1191, 725, 591, 277, 810, 366, 1197, 281, - 71, 887, 284, 484, 998, 332, 397, 399, 722, 691, - 1209, 398, 400, 402, 296, 297, 401, 790, 1170, 301, - 302, 1265, 551, 1117, 1181, 307, 157, 309, 310, 311, - 312, 1061, 1085, 969, 1073, 317, 1145, 985, 1012, 321, - 1075, 323, 908, 1261, 525, 527, 422, 648, 422, 1156, - 842, 333, -1, 335, 336, 841, 338, -1, -1, -1, + 1189, 1493, 1181, 0, 429, 1347, 836, 1291, 529, 1191, + 272, 725, 1191, 887, 805, 277, 810, 591, 1197, 281, + 366, 998, 284, 484, 71, 332, 397, 399, 722, 691, + 1209, 398, 400, 402, 296, 297, 401, 790, 551, 301, + 302, 1265, 1170, 1117, 1181, 307, 157, 309, 310, 311, + 312, 985, 1085, 969, 1061, 317, 1073, 1012, 1145, 321, + 1075, 323, 422, 648, 525, 527, 908, 422, 1261, 842, + 1156, 333, 841, 335, 336, -1, 338, -1, -1, -1, 342, -1, -1, -1, -1, -1, 1265, 1266, -1, -1, -1, 256, -1, -1, -1, 1274, 261, 262, 509, -1, 362, -1, -1, 1282, 1283, -1, 1285, 369, -1, -1, @@ -12805,7 +12805,7 @@ public void parse () if (yacc_verbose_flag > 0) throw; - report.Error (589, lexer.Location, "Internal compiler error during parsing"); + report.Error (589, lexer.Location, "Internal compiler error during parsing" + e); } } } diff --git a/ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.jay b/ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.jay index 71d0ec0cef..e48df5a8b0 100644 --- a/ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.jay +++ b/ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.jay @@ -5401,7 +5401,7 @@ for_statement_condition { $$ = $4; } - | opt_for_condition CLOSE_PARENS { + | boolean_expression CLOSE_PARENS { report.Error (1525, GetLocation ($2), "Unexpected symbol ')', expected ';'"); For f = (For) $0; f.Condition = (BooleanExpression) $1; @@ -6796,7 +6796,7 @@ public void parse () if (yacc_verbose_flag > 0) throw; - report.Error (589, lexer.Location, "Internal compiler error during parsing"); + report.Error (589, lexer.Location, "Internal compiler error during parsing" + e); } } } diff --git a/ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-tokenizer.cs b/ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-tokenizer.cs index 0b7db95c62..945853a2f1 100644 --- a/ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-tokenizer.cs +++ b/ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-tokenizer.cs @@ -137,6 +137,11 @@ namespace Mono.CSharp pos = 0; } + public override string ToString () + { + return string.Format ("Token '{0}' at {1},{2}", Value, row, column); + } + public Location Location { get { return new Location (row, column); } } @@ -1266,10 +1271,24 @@ namespace Mono.CSharp int ntoken; int interrs = 1; int colons = 0; + int braces = 0; // // All shorcuts failed, do it hard way // while ((ntoken = xtoken ()) != Token.EOF) { + if (ntoken == Token.OPEN_BRACE) { + ++braces; + continue; + } + + if (ntoken == Token.CLOSE_BRACE) { + --braces; + continue; + } + + if (braces != 0) + continue; + if (ntoken == Token.SEMICOLON) break; @@ -1535,6 +1554,7 @@ namespace Mono.CSharp #endif number_pos = 0; var loc = Location; + bool hasLeadingDot = c == '.'; if (c >= '0' && c <= '9'){ if (c == '0'){ diff --git a/ICSharpCode.NRefactory.CSharp/Parser/mcs/doc.cs b/ICSharpCode.NRefactory.CSharp/Parser/mcs/doc.cs index 30c199f82e..e988178c43 100644 --- a/ICSharpCode.NRefactory.CSharp/Parser/mcs/doc.cs +++ b/ICSharpCode.NRefactory.CSharp/Parser/mcs/doc.cs @@ -397,10 +397,15 @@ namespace Mono.CSharp if (ParsedParameters != null) { var old_printer = mc.Module.Compiler.Report.SetPrinter (new NullReportPrinter ()); - foreach (var pp in ParsedParameters) { - pp.Resolve (mc); + try { + var context = new DocumentationMemberContext (mc, ParsedName ?? MemberName.Null); + + foreach (var pp in ParsedParameters) { + pp.Resolve (context); + } + } finally { + mc.Module.Compiler.Report.SetPrinter (old_printer); } - mc.Module.Compiler.Report.SetPrinter (old_printer); } if (type != null) { @@ -433,13 +438,15 @@ namespace Mono.CSharp if (m.Kind == MemberKind.Operator && !ParsedOperator.HasValue) continue; + var pm_params = pm.Parameters; + int i; for (i = 0; i < parsed_param_count; ++i) { var pparam = ParsedParameters[i]; - if (i >= pm.Parameters.Count || pparam == null || - pparam.TypeSpec != pm.Parameters.Types[i] || - (pparam.Modifier & Parameter.Modifier.RefOutMask) != (pm.Parameters.FixedParameters[i].ModFlags & Parameter.Modifier.RefOutMask)) { + if (i >= pm_params.Count || pparam == null || pparam.TypeSpec == null || + !TypeSpecComparer.Override.IsEqual (pparam.TypeSpec, pm_params.Types[i]) || + (pparam.Modifier & Parameter.Modifier.RefOutMask) != (pm_params.FixedParameters[i].ModFlags & Parameter.Modifier.RefOutMask)) { if (i > parameters_match) { parameters_match = i; @@ -459,7 +466,7 @@ namespace Mono.CSharp continue; } } else { - if (parsed_param_count != pm.Parameters.Count) + if (parsed_param_count != pm_params.Count) continue; } } @@ -612,6 +619,97 @@ namespace Mono.CSharp } } + // + // Type lookup of documentation references uses context of type where + // the reference is used but type parameters from cref value + // + sealed class DocumentationMemberContext : IMemberContext + { + readonly MemberCore host; + MemberName contextName; + + public DocumentationMemberContext (MemberCore host, MemberName contextName) + { + this.host = host; + this.contextName = contextName; + } + + public TypeSpec CurrentType { + get { + return host.CurrentType; + } + } + + public TypeParameters CurrentTypeParameters { + get { + return contextName.TypeParameters; + } + } + + public MemberCore CurrentMemberDefinition { + get { + return host.CurrentMemberDefinition; + } + } + + public bool IsObsolete { + get { + return false; + } + } + + public bool IsUnsafe { + get { + return host.IsStatic; + } + } + + public bool IsStatic { + get { + return host.IsStatic; + } + } + + public ModuleContainer Module { + get { + return host.Module; + } + } + + public string GetSignatureForError () + { + return host.GetSignatureForError (); + } + + public ExtensionMethodCandidates LookupExtensionMethod (TypeSpec extensionType, string name, int arity) + { + return null; + } + + public FullNamedExpression LookupNamespaceOrType (string name, int arity, LookupMode mode, Location loc) + { + if (arity == 0) { + var tp = CurrentTypeParameters; + if (tp != null) { + for (int i = 0; i < tp.Count; ++i) { + var t = tp[i]; + if (t.Name == name) { + t.Type.DeclaredPosition = i; + return new TypeParameterExpr (t, loc); + } + } + } + } + + return host.Parent.LookupNamespaceOrType (name, arity, mode, loc); + } + + public FullNamedExpression LookupNamespaceAlias (string name) + { + throw new NotImplementedException (); + } + } + class DocumentationParameter { public readonly Parameter.Modifier Modifier; diff --git a/ICSharpCode.NRefactory.CSharp/Parser/mcs/driver.cs b/ICSharpCode.NRefactory.CSharp/Parser/mcs/driver.cs index bcbf7c148f..e86263da6c 100644 --- a/ICSharpCode.NRefactory.CSharp/Parser/mcs/driver.cs +++ b/ICSharpCode.NRefactory.CSharp/Parser/mcs/driver.cs @@ -259,6 +259,12 @@ namespace Mono.CSharp output_file = output_file_name; } else { output_file_name = Path.GetFileName (output_file); + + if (string.IsNullOrEmpty (Path.GetFileNameWithoutExtension (output_file_name)) || + output_file_name.IndexOfAny (Path.GetInvalidFileNameChars ()) >= 0) { + Report.Error (2021, "Output file name is not valid"); + return false; + } } #if STATIC diff --git a/ICSharpCode.NRefactory.CSharp/Parser/mcs/ecore.cs b/ICSharpCode.NRefactory.CSharp/Parser/mcs/ecore.cs index 23a7f06cae..4fd4c95d63 100644 --- a/ICSharpCode.NRefactory.CSharp/Parser/mcs/ecore.cs +++ b/ICSharpCode.NRefactory.CSharp/Parser/mcs/ecore.cs @@ -240,7 +240,7 @@ namespace Mono.CSharp { Report.Error (1547, loc, "Keyword `void' cannot be used in this context"); } - public virtual void Error_ValueCannotBeConverted (ResolveContext ec, Location loc, TypeSpec target, bool expl) + public virtual void Error_ValueCannotBeConverted (ResolveContext ec, TypeSpec target, bool expl) { Error_ValueCannotBeConvertedCore (ec, loc, target, expl); } @@ -320,7 +320,7 @@ namespace Mono.CSharp { TypeManager.CSharpName (type), name); } - public void Error_ValueAssignment (ResolveContext rc, Expression rhs) + public virtual void Error_ValueAssignment (ResolveContext rc, Expression rhs) { if (rhs == EmptyExpression.LValueMemberAccess || rhs == EmptyExpression.LValueMemberOutAccess) { rc.Report.SymbolRelatedToPreviousError (type); @@ -915,7 +915,7 @@ namespace Mono.CSharp { converted = Convert.ImplicitConversion (ec, source, btypes.ULong, source.loc); if (converted == null) { - source.Error_ValueCannotBeConverted (ec, source.loc, btypes.Int, false); + source.Error_ValueCannotBeConverted (ec, btypes.Int, false); return null; } } @@ -3353,7 +3353,7 @@ namespace Mono.CSharp { call.Emit (ec, best_candidate, arguments, loc); } - public override void Error_ValueCannotBeConverted (ResolveContext ec, Location loc, TypeSpec target, bool expl) + public override void Error_ValueCannotBeConverted (ResolveContext ec, TypeSpec target, bool expl) { ec.Report.Error (428, loc, "Cannot convert method group `{0}' to non-delegate type `{1}'. Consider using parentheses to invoke the method", Name, TypeManager.CSharpName (target)); @@ -6294,9 +6294,10 @@ namespace Mono.CSharp { // // Don't capture temporary variables except when using - // state machine redirection + // state machine redirection and block yields // - if (ec.CurrentAnonymousMethod != null && ec.CurrentAnonymousMethod is StateMachineInitializer && ec.IsVariableCapturingRequired) { + if (ec.CurrentAnonymousMethod != null && ec.CurrentAnonymousMethod.IsIterator && + ec.CurrentBlock.Explicit.HasYield && ec.IsVariableCapturingRequired) { AnonymousMethodStorey storey = li.Block.Explicit.CreateAnonymousMethodStorey (ec); storey.CaptureLocalVariable (ec, li); } diff --git a/ICSharpCode.NRefactory.CSharp/Parser/mcs/expression.cs b/ICSharpCode.NRefactory.CSharp/Parser/mcs/expression.cs index 866a505327..3091426b4e 100644 --- a/ICSharpCode.NRefactory.CSharp/Parser/mcs/expression.cs +++ b/ICSharpCode.NRefactory.CSharp/Parser/mcs/expression.cs @@ -103,7 +103,12 @@ namespace Mono.CSharp protected override Expression DoResolve (ResolveContext ec) { - return expr.Resolve (ec); + var res = expr.Resolve (ec); + var constant = res as Constant; + if (constant != null && constant.IsLiteral) + return Constant.CreateConstantFromValue (res.Type, constant.GetValue (), expr.Location); + + return res; } public override Expression DoResolveLValue (ResolveContext ec, Expression right_side) @@ -142,10 +147,12 @@ namespace Mono.CSharp // This routine will attempt to simplify the unary expression when the // argument is a constant. // - Constant TryReduceConstant (ResolveContext ec, Constant e) + Constant TryReduceConstant (ResolveContext ec, Constant constant) { - if (e is EmptyConstantCast) - return TryReduceConstant (ec, ((EmptyConstantCast) e).child); + var e = constant; + + while (e is EmptyConstantCast) + e = ((EmptyConstantCast) e).child; if (e is SideEffectConstant) { Constant r = TryReduceConstant (ec, ((SideEffectConstant) e).value); @@ -220,7 +227,7 @@ namespace Mono.CSharp return new LongConstant (ec.BuiltinTypes, -lvalue, e.Location); case BuiltinTypeSpec.Type.UInt: - UIntLiteral uil = e as UIntLiteral; + UIntLiteral uil = constant as UIntLiteral; if (uil != null) { if (uil.Value == int.MaxValue + (uint) 1) return new IntLiteral (ec.BuiltinTypes, int.MinValue, e.Location); @@ -230,13 +237,13 @@ namespace Mono.CSharp case BuiltinTypeSpec.Type.ULong: - ULongLiteral ull = e as ULongLiteral; + ULongLiteral ull = constant as ULongLiteral; if (ull != null && ull.Value == 9223372036854775808) return new LongLiteral (ec.BuiltinTypes, long.MinValue, e.Location); return null; case BuiltinTypeSpec.Type.Float: - FloatLiteral fl = e as FloatLiteral; + FloatLiteral fl = constant as FloatLiteral; // For better error reporting if (fl != null) return new FloatLiteral (ec.BuiltinTypes, -fl.Value, e.Location); @@ -244,7 +251,7 @@ namespace Mono.CSharp return new FloatConstant (ec.BuiltinTypes, -((FloatConstant) e).Value, e.Location); case BuiltinTypeSpec.Type.Double: - DoubleLiteral dl = e as DoubleLiteral; + DoubleLiteral dl = constant as DoubleLiteral; // For better error reporting if (dl != null) return new DoubleLiteral (ec.BuiltinTypes, -dl.Value, e.Location); @@ -1687,19 +1694,19 @@ namespace Mono.CSharp return null; } - eclass = ExprClass.Value; + if (type.IsPointer && !ec.IsUnsafe) { + UnsafeError (ec, loc); + } + eclass = ExprClass.Value; + Constant c = expr as Constant; if (c != null) { - c = c.TryReduce (ec, type, loc); + c = c.TryReduce (ec, type); if (c != null) return c; } - if (type.IsPointer && !ec.IsUnsafe) { - UnsafeError (ec, loc); - } - var res = Convert.ExplicitConversion (ec, expr, type, loc); if (res == expr) return EmptyCast.Create (res, type); @@ -2654,7 +2661,7 @@ namespace Mono.CSharp return left; if (left.IsZeroInteger) - return left.TryReduce (ec, right.Type, loc); + return left.TryReduce (ec, right.Type); break; @@ -4497,7 +4504,7 @@ namespace Mono.CSharp // converted = GetOperatorTrue (ec, expr, loc); if (converted == null) { - expr.Error_ValueCannotBeConverted (ec, loc, type, false); + expr.Error_ValueCannotBeConverted (ec, type, false); return null; } @@ -4982,22 +4989,25 @@ namespace Mono.CSharp return this; } - public override Expression DoResolveLValue (ResolveContext ec, Expression right_side) + public override Expression DoResolveLValue (ResolveContext ec, Expression rhs) { - // is out param - if (right_side == EmptyExpression.OutAccess) + // + // Don't be too pedantic when variable is used as out param or for some broken code + // which uses property/indexer access to run some initialization + // + if (rhs == EmptyExpression.OutAccess || rhs.eclass == ExprClass.PropertyAccess || rhs.eclass == ExprClass.IndexerAccess) local_info.SetIsUsed (); if (local_info.IsReadonly && !ec.HasAny (ResolveContext.Options.FieldInitializerScope | ResolveContext.Options.UsingInitializerScope)) { int code; string msg; - if (right_side == EmptyExpression.OutAccess) { + if (rhs == EmptyExpression.OutAccess) { code = 1657; msg = "Cannot pass `{0}' as a ref or out argument because it is a `{1}'"; - } else if (right_side == EmptyExpression.LValueMemberAccess) { + } else if (rhs == EmptyExpression.LValueMemberAccess) { code = 1654; msg = "Cannot assign to members of `{0}' because it is a `{1}'"; - } else if (right_side == EmptyExpression.LValueMemberOutAccess) { + } else if (rhs == EmptyExpression.LValueMemberOutAccess) { code = 1655; msg = "Cannot pass members of `{0}' as ref or out arguments because it is a `{1}'"; - } else if (right_side == EmptyExpression.UnaryAddress) { + } else if (rhs == EmptyExpression.UnaryAddress) { code = 459; msg = "Cannot take the address of {1} `{0}'"; } else { code = 1656; msg = "Cannot assign to `{0}' because it is a `{1}'"; @@ -5010,7 +5020,7 @@ namespace Mono.CSharp if (eclass == ExprClass.Unresolved) DoResolveBase (ec); - return base.DoResolveLValue (ec, right_side); + return base.DoResolveLValue (ec, rhs); } public override int GetHashCode () @@ -5159,7 +5169,7 @@ namespace Mono.CSharp if (ec.IsVariableCapturingRequired && !pi.Block.ParametersBlock.IsExpressionTree) { AnonymousMethodStorey storey = pi.Block.Explicit.CreateAnonymousMethodStorey (ec); - storey.CaptureParameter (ec, this); + storey.CaptureParameter (ec, pi, this); } } @@ -7005,15 +7015,7 @@ namespace Mono.CSharp return null; AnonymousMethodStorey storey = ae.Storey; - while (storey != null) { - AnonymousMethodStorey temp = storey.Parent as AnonymousMethodStorey; - if (temp == null) - return storey.HoistedThis; - - storey = temp; - } - - return null; + return storey != null ? storey.HoistedThis : null; } public static bool IsThisAvailable (ResolveContext ec, bool ignoreAnonymous) @@ -7042,11 +7044,20 @@ namespace Mono.CSharp var block = ec.CurrentBlock; if (block != null) { - if (block.ParametersBlock.TopBlock.ThisVariable != null) - variable_info = block.ParametersBlock.TopBlock.ThisVariable.VariableInfo; + var top = block.ParametersBlock.TopBlock; + if (top.ThisVariable != null) + variable_info = top.ThisVariable.VariableInfo; AnonymousExpression am = ec.CurrentAnonymousMethod; - if (am != null && ec.IsVariableCapturingRequired) { + if (am != null && ec.IsVariableCapturingRequired && !block.Explicit.HasCapturedThis) { + // + // Hoisted this is almost like hoisted variable but not exactly. When + // there is no variable hoisted we can simply emit an instance method + // without lifting this into a storey. Unfotunatelly this complicates + // this in other cases because we don't know where this will be hoisted + // until top-level block is fully resolved + // + top.AddThisReferenceFromChildrenBlock (block.Explicit); am.SetHasThisAccess (); } } @@ -9279,11 +9290,15 @@ namespace Mono.CSharp return this; } + public override void Error_ValueAssignment (ResolveContext rc, Expression rhs) + { + } + public override void Error_UnexpectedKind (ResolveContext ec, ResolveFlags flags, Location loc) { } - public override void Error_ValueCannotBeConverted (ResolveContext ec, Location loc, TypeSpec target, bool expl) + public override void Error_ValueCannotBeConverted (ResolveContext ec, TypeSpec target, bool expl) { } diff --git a/ICSharpCode.NRefactory.CSharp/Parser/mcs/iterators.cs b/ICSharpCode.NRefactory.CSharp/Parser/mcs/iterators.cs index 06a7f26bc9..2586eada9d 100644 --- a/ICSharpCode.NRefactory.CSharp/Parser/mcs/iterators.cs +++ b/ICSharpCode.NRefactory.CSharp/Parser/mcs/iterators.cs @@ -11,10 +11,6 @@ // Copyright 2011 Xamarin Inc. // -// TODO: -// Flow analysis for Yield. -// - using System; using System.Collections.Generic; using Mono.CompilerServices.SymbolWriter; @@ -160,8 +156,9 @@ namespace Mono.CSharp Field pc_field; StateMachineMethod method; + int local_name_idx; - protected StateMachine (Block block, TypeDefinition parent, MemberBase host, TypeParameters tparams, string name, MemberKind kind) + protected StateMachine (ParametersBlock block, TypeDefinition parent, MemberBase host, TypeParameters tparams, string name, MemberKind kind) : base (block, parent, host, tparams, name, kind) { } @@ -197,6 +194,14 @@ namespace Mono.CSharp return base.DoDefineMembers (); } + + protected override string GetVariableMangledName (LocalVariable local_info) + { + if (local_info.IsCompilerGenerated) + return base.GetVariableMangledName (local_info); + + return "<" + local_info.Name + ">__" + local_name_idx++.ToString ("X"); + } } class IteratorStorey : StateMachine @@ -399,7 +404,6 @@ namespace Mono.CSharp TypeExpr iterator_type_expr; Field current_field; Field disposing_field; - int local_name_idx; TypeSpec generic_enumerator_type; TypeSpec generic_enumerable_type; @@ -558,19 +562,11 @@ namespace Mono.CSharp reset.Block.AddStatement (new Throw (new New (new TypeExpression (ex_type, Location), null, Location), Location)); } - protected override void EmitHoistedParameters (EmitContext ec, IList hoisted) + protected override void EmitHoistedParameters (EmitContext ec, List hoisted) { base.EmitHoistedParameters (ec, hoisted); base.EmitHoistedParameters (ec, hoisted_params_copy); } - - protected override string GetVariableMangledName (LocalVariable local_info) - { - if (local_info.IsCompilerGenerated) - return base.GetVariableMangledName (local_info); - - return "<" + local_info.Name + ">__" + local_name_idx++.ToString ("X"); - } } public class StateMachineMethod : Method @@ -702,8 +698,6 @@ namespace Mono.CSharp protected override Expression DoResolve (ResolveContext ec) { - storey = (StateMachine) block.Parent.ParametersBlock.AnonymousMethodStorey; - var ctx = CreateBlockContext (ec); Block.Resolve (ctx); @@ -730,7 +724,7 @@ namespace Mono.CSharp public override void Emit (EmitContext ec) { // - // Load Iterator storey instance + // Load state machine instance // storey.Instance.Emit (ec); } @@ -749,11 +743,7 @@ namespace Mono.CSharp iterator_body_end = ec.DefineLabel (); - if (ec.EmitAccurateDebugInfo && ec.Mark (Block.Original.StartLocation)) { - ec.Emit (OpCodes.Nop); - } - - block.Emit (ec); + block.EmitEmbedded (ec); ec.MarkLabel (iterator_body_end); @@ -816,11 +806,7 @@ namespace Mono.CSharp iterator_body_end = ec.DefineLabel (); - if (ec.EmitAccurateDebugInfo && ec.Mark (Block.Original.StartLocation)) { - ec.Emit (OpCodes.Nop); - } - - block.Emit (ec); + block.EmitEmbedded (ec); ec.MarkLabel (iterator_body_end); @@ -905,16 +891,51 @@ namespace Mono.CSharp ec.Emit (OpCodes.Stloc, skip_finally); } } + + public void SetStateMachine (StateMachine stateMachine) + { + this.storey = stateMachine; + } } // - // Iterators are implemented as hidden anonymous block + // Iterators are implemented as state machine blocks // public class Iterator : StateMachineInitializer { + sealed class TryFinallyBlockProxyStatement : Statement + { + TryFinallyBlock block; + Iterator iterator; + + public TryFinallyBlockProxyStatement (Iterator iterator, TryFinallyBlock block) + { + this.iterator = iterator; + this.block = block; + } + + protected override void CloneTo (CloneContext clonectx, Statement target) + { + throw new NotSupportedException (); + } + + protected override void DoEmit (EmitContext ec) + { + // + // Restore redirection for any captured variables + // + ec.CurrentAnonymousMethod = iterator; + + using (ec.With (BuilderContext.Options.OmitDebugInfo, !ec.HasMethodSymbolBuilder)) { + block.EmitFinallyBody (ec); + } + } + } + public readonly IMethodData OriginalMethod; public readonly bool IsEnumerable; public readonly TypeSpec OriginalIteratorType; + int finally_hosts_counter; public Iterator (ParametersBlock block, IMethodData method, TypeDefinition host, TypeSpec iterator_type, bool is_enumerable) : base (block, host, host.Compiler.BuiltinTypes.Bool) @@ -925,7 +946,9 @@ namespace Mono.CSharp this.type = method.ReturnType; } - public Block Container { + #region Properties + + public ToplevelBlock Container { get { return OriginalMethod.Block; } } @@ -937,6 +960,22 @@ namespace Mono.CSharp get { return true; } } + #endregion + + public Method CreateFinallyHost (TryFinallyBlock block) + { + var method = new Method (storey, new TypeExpression (storey.Compiler.BuiltinTypes.Void, loc), + Modifiers.COMPILER_GENERATED, new MemberName (CompilerGeneratedContainer.MakeName (null, null, "Finally", finally_hosts_counter++), loc), + ParametersCompiled.EmptyReadOnlyParameters, null); + + method.Block = new ToplevelBlock (method.Compiler, method.ParameterInfo, loc); + method.Block.IsCompilerGenerated = true; + method.Block.AddStatement (new TryFinallyBlockProxyStatement (this, block)); + + storey.AddMember (method); + return method; + } + public void EmitYieldBreak (EmitContext ec, bool unwind_protect) { ec.Emit (unwind_protect ? OpCodes.Leave : OpCodes.Br, move_next_error); @@ -972,11 +1011,13 @@ namespace Mono.CSharp public void EmitDispose (EmitContext ec) { + if (resume_points == null) + return; + Label end = ec.DefineLabel (); Label[] labels = null; - int n_resume_points = resume_points == null ? 0 : resume_points.Count; - for (int i = 0; i < n_resume_points; ++i) { + for (int i = 0; i < resume_points.Count; ++i) { ResumableStatement s = resume_points[i]; Label ret = s.PrepareForDispose (ec, end); if (ret.Equals (end) && labels == null) @@ -1089,7 +1130,7 @@ namespace Mono.CSharp parent.Compiler.Report.Error (1629, method.Location, "Unsafe code may not appear in iterators"); } - method.Block.WrapIntoIterator (method, parent, iterator_type, is_enumerable); + method.Block = method.Block.ConvertToIterator (method, parent, iterator_type, is_enumerable); } static bool CheckType (TypeSpec ret, TypeContainer parent, out TypeSpec original_iterator_type, out bool is_enumerable) diff --git a/ICSharpCode.NRefactory.CSharp/Parser/mcs/lambda.cs b/ICSharpCode.NRefactory.CSharp/Parser/mcs/lambda.cs index 2fba7ed473..d972450fc7 100644 --- a/ICSharpCode.NRefactory.CSharp/Parser/mcs/lambda.cs +++ b/ICSharpCode.NRefactory.CSharp/Parser/mcs/lambda.cs @@ -191,7 +191,7 @@ namespace Mono.CSharp { return Expr.CreateExpressionTree (ec); } - public override void Emit (EmitContext ec) + protected override void DoEmit (EmitContext ec) { if (statement != null) { statement.EmitStatement (ec); @@ -203,7 +203,7 @@ namespace Mono.CSharp { return; } - base.Emit (ec); + base.DoEmit (ec); } protected override bool DoResolve (BlockContext ec) diff --git a/ICSharpCode.NRefactory.CSharp/Parser/mcs/literal.cs b/ICSharpCode.NRefactory.CSharp/Parser/mcs/literal.cs index bb0370914b..bdbd57a4f7 100644 --- a/ICSharpCode.NRefactory.CSharp/Parser/mcs/literal.cs +++ b/ICSharpCode.NRefactory.CSharp/Parser/mcs/literal.cs @@ -50,7 +50,7 @@ namespace Mono.CSharp { } - public override void Error_ValueCannotBeConverted (ResolveContext ec, Location loc, TypeSpec t, bool expl) + public override void Error_ValueCannotBeConverted (ResolveContext ec, TypeSpec t, bool expl) { if (t.IsGenericParameter) { ec.Report.Error(403, loc, @@ -65,7 +65,7 @@ namespace Mono.CSharp return; } - base.Error_ValueCannotBeConverted (ec, loc, t, expl); + base.Error_ValueCannotBeConverted (ec, t, expl); } public override string GetValueAsLiteral () @@ -253,7 +253,7 @@ namespace Mono.CSharp { } - public override void Error_ValueCannotBeConverted (ResolveContext ec, Location loc, TypeSpec target, bool expl) + public override void Error_ValueCannotBeConverted (ResolveContext ec, TypeSpec target, bool expl) { if (target.BuiltinType == BuiltinTypeSpec.Type.Float) { Error_664 (ec, loc, "float", "f"); @@ -265,7 +265,7 @@ namespace Mono.CSharp return; } - base.Error_ValueCannotBeConverted (ec, loc, target, expl); + base.Error_ValueCannotBeConverted (ec, target, expl); } static void Error_664 (ResolveContext ec, Location loc, string type, string suffix) diff --git a/ICSharpCode.NRefactory.CSharp/Parser/mcs/method.cs b/ICSharpCode.NRefactory.CSharp/Parser/mcs/method.cs index c0090ae9f8..5f15beb0be 100644 --- a/ICSharpCode.NRefactory.CSharp/Parser/mcs/method.cs +++ b/ICSharpCode.NRefactory.CSharp/Parser/mcs/method.cs @@ -1196,7 +1196,7 @@ namespace Mono.CSharp { Report.Error (1983, Location, "The return type of an async method must be void, Task, or Task"); } - AsyncInitializer.Create (this, block, parameters, Parent.PartialContainer, ReturnType, Location); + block = (ToplevelBlock) block.ConvertToAsyncTask (this, Parent.PartialContainer, parameters, ReturnType, Location); ModFlags |= Modifiers.DEBUGGER_HIDDEN; } } diff --git a/ICSharpCode.NRefactory.CSharp/Parser/mcs/parameter.cs b/ICSharpCode.NRefactory.CSharp/Parser/mcs/parameter.cs index e0292b6c5f..365f876f0a 100644 --- a/ICSharpCode.NRefactory.CSharp/Parser/mcs/parameter.cs +++ b/ICSharpCode.NRefactory.CSharp/Parser/mcs/parameter.cs @@ -235,7 +235,7 @@ namespace Mono.CSharp { TemporaryVariableReference expr_tree_variable; - HoistedVariable hoisted_variant; + HoistedParameter hoisted_variant; public Parameter (FullNamedExpression type, string name, Modifier mod, Attributes attrs, Location loc) { @@ -549,7 +549,7 @@ namespace Mono.CSharp { // // Hoisted parameter variant // - public HoistedVariable HoistedVariant { + public HoistedParameter HoistedVariant { get { return hoisted_variant; } diff --git a/ICSharpCode.NRefactory.CSharp/Parser/mcs/statement.cs b/ICSharpCode.NRefactory.CSharp/Parser/mcs/statement.cs index 850c366da5..4a71f027d1 100644 --- a/ICSharpCode.NRefactory.CSharp/Parser/mcs/statement.cs +++ b/ICSharpCode.NRefactory.CSharp/Parser/mcs/statement.cs @@ -922,7 +922,7 @@ namespace Mono.CSharp { if (expr == null) return false; - if (expr.Type != block_return_type) { + if (expr.Type != block_return_type && expr.Type != InternalType.ErrorType) { expr = Convert.ImplicitConversionRequired (ec, expr, block_return_type, loc); if (expr == null) { @@ -1215,9 +1215,9 @@ namespace Mono.CSharp { res = c; } else { TypeSpec type = ec.Switch.SwitchType; - res = c.TryReduce (ec, type, c.Location); + res = c.TryReduce (ec, type); if (res == null) { - c.Error_ValueCannotBeConverted (ec, loc, type, true); + c.Error_ValueCannotBeConverted (ec, type, true); return false; } @@ -1681,7 +1681,7 @@ namespace Mono.CSharp { if (TypeSpec.IsReferenceType (li.Type)) initializer.Error_ConstantCanBeInitializedWithNullOnly (bc, li.Type, initializer.Location, li.Name); else - initializer.Error_ValueCannotBeConverted (bc, initializer.Location, li.Type, false); + initializer.Error_ValueCannotBeConverted (bc, li.Type, false); return null; } @@ -2056,8 +2056,8 @@ namespace Mono.CSharp { static int id; public int ID = id++; -// static int clone_id_counter; -// int clone_id; + static int clone_id_counter; + int clone_id; #endif // int assignable_slots; @@ -2369,7 +2369,7 @@ namespace Mono.CSharp { { Block target = (Block) t; #if DEBUG -// target.clone_id = clone_id_counter++; + target.clone_id = clone_id_counter++; #endif clonectx.AddBlockMap (this, target); @@ -2423,14 +2423,22 @@ namespace Mono.CSharp { } public bool HasCapturedThis { - set { flags = value ? flags | Flags.HasCapturedThis : flags & ~Flags.HasCapturedThis; } + set { + flags = value ? flags | Flags.HasCapturedThis : flags & ~Flags.HasCapturedThis; + } get { return (flags & Flags.HasCapturedThis) != 0; } } + // + // Used to indicate that the block has reference to parent + // block and cannot be made static when defining anonymous method + // public bool HasCapturedVariable { - set { flags = value ? flags | Flags.HasCapturedVariable : flags & ~Flags.HasCapturedVariable; } + set { + flags = value ? flags | Flags.HasCapturedVariable : flags & ~Flags.HasCapturedVariable; + } get { return (flags & Flags.HasCapturedVariable) != 0; } @@ -2457,11 +2465,12 @@ namespace Mono.CSharp { return ec.CurrentAnonymousMethod.Storey; // - // When referencing a variable in parent iterator/async storey - // from nested anonymous method + // When referencing a variable inside iterator where all + // variables will be captured anyway we don't need to create + // another storey context // - if (ParametersBlock.am_storey is StateMachine) { - return ParametersBlock.am_storey; + if (ParametersBlock.StateMachine is IteratorStorey) { + return ParametersBlock.StateMachine; } if (am_storey == null) { @@ -2479,7 +2488,7 @@ namespace Mono.CSharp { public override void Emit (EmitContext ec) { if (am_storey != null) { - DefineAnonymousStorey (ec); + DefineStoreyContainer (ec, am_storey); am_storey.EmitStoreyInstantiation (ec, this); } @@ -2503,57 +2512,112 @@ namespace Mono.CSharp { } } - void DefineAnonymousStorey (EmitContext ec) + protected void DefineStoreyContainer (EmitContext ec, AnonymousMethodStorey storey) { + if (ec.CurrentAnonymousMethod != null && ec.CurrentAnonymousMethod.Storey != null) { + storey.SetNestedStoryParent (ec.CurrentAnonymousMethod.Storey); + storey.Mutator = ec.CurrentAnonymousMethod.Storey.Mutator; + } + // // Creates anonymous method storey // - if (ec.CurrentAnonymousMethod != null && ec.CurrentAnonymousMethod.Storey != null) { + storey.CreateContainer (); + storey.DefineContainer (); + + if (Original.Explicit.HasCapturedThis && Original.ParametersBlock.TopBlock.ThisReferencesFromChildrenBlock != null) { + + // + // Only first storey in path will hold this reference. All children blocks will + // reference it indirectly using $ref field + // + for (Block b = Original.Explicit.Parent; b != null; b = b.Parent) { + var s = b.Explicit.AnonymousMethodStorey; + if (s != null) { + storey.HoistedThis = s.HoistedThis; + break; + } + } + // - // Creates parent storey reference when hoisted this is accessible + // We are the first storey on path and this has to be hoisted // - if (am_storey.OriginalSourceBlock.Explicit.HasCapturedThis) { - ExplicitBlock parent = am_storey.OriginalSourceBlock.Explicit.Parent.Explicit; + if (storey.HoistedThis == null) { + foreach (ExplicitBlock ref_block in Original.ParametersBlock.TopBlock.ThisReferencesFromChildrenBlock) { + // + // ThisReferencesFromChildrenBlock holds all reference even if they + // are not on this path. It saves some memory otherwise it'd have to + // be in every explicit block. We run this check to see if the reference + // is valid for this storey + // + Block block_on_path = ref_block; + for (; block_on_path != null && block_on_path != Original; block_on_path = block_on_path.Parent); - // - // Hoisted this exists in top-level parent storey only - // - while (parent.am_storey == null || parent.am_storey.Parent is AnonymousMethodStorey) - parent = parent.Parent.Explicit; + if (block_on_path == null) + continue; - am_storey.AddParentStoreyReference (ec, parent.am_storey); - } + if (storey.HoistedThis == null) + storey.AddCapturedThisField (ec); - am_storey.SetNestedStoryParent (ec.CurrentAnonymousMethod.Storey); + for (ExplicitBlock b = ref_block; b.AnonymousMethodStorey != storey; b = b.Parent.Explicit) { + if (b.AnonymousMethodStorey != null) { + b.AnonymousMethodStorey.AddParentStoreyReference (ec, storey); + b.AnonymousMethodStorey.HoistedThis = storey.HoistedThis; - // TODO MemberCache: Review - am_storey.Mutator = ec.CurrentAnonymousMethod.Storey.Mutator; - } + // + // Stop propagation inside same top block + // + if (b.ParametersBlock == ParametersBlock.Original) + break; + + b = b.ParametersBlock; + } + + var pb = b as ParametersBlock; + if (pb != null && pb.StateMachine != null) { + if (pb.StateMachine == storey) + break; + + pb.StateMachine.AddParentStoreyReference (ec, storey); + } - am_storey.CreateContainer (); - am_storey.DefineContainer (); + b.HasCapturedVariable = true; + } + } + } + } - var ref_blocks = am_storey.ReferencesFromChildrenBlock; + var ref_blocks = storey.ReferencesFromChildrenBlock; if (ref_blocks != null) { foreach (ExplicitBlock ref_block in ref_blocks) { - for (ExplicitBlock b = ref_block.Explicit; b.am_storey != am_storey; b = b.Parent.Explicit) { - if (b.am_storey != null) { - b.am_storey.AddParentStoreyReference (ec, am_storey); + for (ExplicitBlock b = ref_block; b.AnonymousMethodStorey != storey; b = b.Parent.Explicit) { + if (b.AnonymousMethodStorey != null) { + b.AnonymousMethodStorey.AddParentStoreyReference (ec, storey); + // // Stop propagation inside same top block - if (b.ParametersBlock.Original == ParametersBlock.Original) + // + if (b.ParametersBlock == ParametersBlock.Original) break; b = b.ParametersBlock; } + var pb = b as ParametersBlock; + if (pb != null && pb.StateMachine != null) { + if (pb.StateMachine == storey) + break; + + pb.StateMachine.AddParentStoreyReference (ec, storey); + } + b.HasCapturedVariable = true; } } } - am_storey.Define (); - am_storey.Parent.PartialContainer.AddCompilerGeneratedClass (am_storey); + storey.Define (); + storey.Parent.PartialContainer.AddCompilerGeneratedClass (storey); } public void RegisterAsyncAwait () @@ -2562,7 +2626,7 @@ namespace Mono.CSharp { while ((block.flags & Flags.AwaitBlock) == 0) { block.flags |= Flags.AwaitBlock; - if (block.Parent == null) + if (block is ParametersBlock) return; block = block.Parent.Explicit; @@ -2611,7 +2675,13 @@ namespace Mono.CSharp { #region Properties - public Block Block { + public ParametersBlock Block { + get { + return block; + } + } + + Block INamedBlockVariable.Block { get { return block; } @@ -2714,6 +2784,7 @@ namespace Mono.CSharp { bool resolved; protected bool unreachable; protected ToplevelBlock top_block; + protected StateMachine state_machine; public ParametersBlock (Block parent, ParametersCompiled parameters, Location start) : base (parent, 0, start, start) @@ -2753,6 +2824,7 @@ namespace Mono.CSharp { this.resolved = true; this.unreachable = source.unreachable; this.am_storey = source.am_storey; + this.state_machine = source.state_machine; ParametersBlock = this; @@ -2792,6 +2864,12 @@ namespace Mono.CSharp { } } + public StateMachine StateMachine { + get { + return state_machine; + } + } + public ToplevelBlock TopBlock { get { return top_block; @@ -2847,6 +2925,26 @@ namespace Mono.CSharp { return base.CreateExpressionTree (ec); } + public override void Emit (EmitContext ec) + { + if (state_machine != null && state_machine.OriginalSourceBlock != this) { + DefineStoreyContainer (ec, state_machine); + state_machine.EmitStoreyInstantiation (ec, this); + } + + base.Emit (ec); + } + + public void EmitEmbedded (EmitContext ec) + { + if (state_machine != null && state_machine.OriginalSourceBlock != this) { + DefineStoreyContainer (ec, state_machine); + state_machine.EmitStoreyInstantiation (ec, this); + } + + base.Emit (ec); + } + public ParameterInfo GetParameterInfo (Parameter p) { for (int i = 0; i < parameters.Count; ++i) { @@ -2969,37 +3067,71 @@ namespace Mono.CSharp { } } - public void WrapIntoIterator (IMethodData method, TypeDefinition host, TypeSpec iterator_type, bool is_enumerable) + public ToplevelBlock ConvertToIterator (IMethodData method, TypeDefinition host, TypeSpec iterator_type, bool is_enumerable) { - ParametersBlock pb = new ParametersBlock (this, ParametersCompiled.EmptyReadOnlyParameters, Location.Null); - pb.statements = statements; - pb.Original = this; + var iterator = new Iterator (this, method, host, iterator_type, is_enumerable); + var stateMachine = new IteratorStorey (iterator); - var iterator = new Iterator (pb, method, host, iterator_type, is_enumerable); - am_storey = new IteratorStorey (iterator); + state_machine = stateMachine; + iterator.SetStateMachine (stateMachine); - statements = new List (1); - AddStatement (new Return (iterator, iterator.Location)); - flags &= ~Flags.YieldBlock; - IsCompilerGenerated = true; + var tlb = new ToplevelBlock (host.Compiler, Parameters, Location.Null); + tlb.Original = this; + tlb.IsCompilerGenerated = true; + tlb.state_machine = stateMachine; + tlb.AddStatement (new Return (iterator, iterator.Location)); + return tlb; } - public void WrapIntoAsyncTask (IMemberContext context, TypeDefinition host, TypeSpec returnType) + public ParametersBlock ConvertToAsyncTask (IMemberContext context, TypeDefinition host, ParametersCompiled parameters, TypeSpec returnType, Location loc) { - ParametersBlock pb = new ParametersBlock (this, ParametersCompiled.EmptyReadOnlyParameters, Location.Null); - pb.statements = statements; - pb.Original = this; + for (int i = 0; i < parameters.Count; i++) { + Parameter p = parameters[i]; + Parameter.Modifier mod = p.ModFlags; + if ((mod & Parameter.Modifier.RefOutMask) != 0) { + host.Compiler.Report.Error (1988, p.Location, + "Async methods cannot have ref or out parameters"); + return this; + } + + if (p is ArglistParameter) { + host.Compiler.Report.Error (4006, p.Location, + "__arglist is not allowed in parameter list of async methods"); + return this; + } + + if (parameters.Types[i].IsPointer) { + host.Compiler.Report.Error (4005, p.Location, + "Async methods cannot have unsafe parameters"); + return this; + } + } + + if (!HasAwait) { + host.Compiler.Report.Warning (1998, 1, loc, + "Async block lacks `await' operator and will run synchronously"); + } var block_type = host.Module.Compiler.BuiltinTypes.Void; - var initializer = new AsyncInitializer (pb, host, block_type); + var initializer = new AsyncInitializer (this, host, block_type); initializer.Type = block_type; - am_storey = new AsyncTaskStorey (context, initializer, returnType); + var stateMachine = new AsyncTaskStorey (this, context, initializer, returnType); - statements = new List (1); - AddStatement (new StatementExpression (initializer)); - flags &= ~Flags.AwaitBlock; - IsCompilerGenerated = true; + state_machine = stateMachine; + initializer.SetStateMachine (stateMachine); + + var b = this is ToplevelBlock ? + new ToplevelBlock (host.Compiler, Parameters, Location.Null) : + new ParametersBlock (Parent, parameters, Location.Null) { + IsAsync = true, + }; + + b.Original = this; + b.IsCompilerGenerated = true; + b.state_machine = stateMachine; + b.AddStatement (new StatementExpression (initializer)); + return b; } } @@ -3013,11 +3145,7 @@ namespace Mono.CSharp { Dictionary names; Dictionary labels; - public HoistedVariable HoistedThisVariable; - - public Report Report { - get { return compiler.Report; } - } + List this_references; public ToplevelBlock (CompilerContext ctx, Location loc) : this (ctx, ParametersCompiled.EmptyReadOnlyParameters, loc) @@ -3054,6 +3182,31 @@ namespace Mono.CSharp { } } + public Report Report { + get { + return compiler.Report; + } + } + + // + // Used by anonymous blocks to track references of `this' variable + // + public List ThisReferencesFromChildrenBlock { + get { + return this_references; + } + } + + // + // Returns the "this" instance variable of this block. + // See AddThisVariable() for more information. + // + public LocalVariable ThisVariable { + get { + return this_variable; + } + } + public void AddLocalName (string name, INamedBlockVariable li, bool ignoreChildrenBlocks) { if (names == null) @@ -3174,6 +3327,20 @@ namespace Mono.CSharp { existing_list.Add (label); } + public void AddThisReferenceFromChildrenBlock (ExplicitBlock block) + { + if (this_references == null) + this_references = new List (); + + if (!this_references.Contains (block)) + this_references.Add (block); + } + + public void RemoveThisReferenceFromChildrenBlock (ExplicitBlock block) + { + this_references.Remove (block); + } + // // Creates an arguments set from all parameters, useful for method proxy calls // @@ -3284,14 +3451,6 @@ namespace Mono.CSharp { return null; } - // - // Returns the "this" instance variable of this block. - // See AddThisVariable() for more information. - // - public LocalVariable ThisVariable { - get { return this_variable; } - } - // // This is used by non-static `struct' constructors which do not have an // initializer - in this case, the constructor must initialize all of the @@ -4333,6 +4492,7 @@ namespace Mono.CSharp { protected Statement stmt; Label dispose_try_block; bool prepared_for_dispose, emitted_dispose; + Method finally_host; protected TryFinallyBlock (Statement stmt, Location loc) : base (loc) @@ -4351,7 +4511,7 @@ namespace Mono.CSharp { #endregion protected abstract void EmitTryBody (EmitContext ec); - protected abstract void EmitFinallyBody (EmitContext ec); + public abstract void EmitFinallyBody (EmitContext ec); public override Label PrepareForDispose (EmitContext ec, Label end) { @@ -4379,7 +4539,14 @@ namespace Mono.CSharp { } ec.MarkLabel (start_finally); - EmitFinallyBody (ec); + + if (finally_host != null) { + var ce = new CallEmitter (); + ce.InstanceExpression = new CompilerGeneratedThis (ec.CurrentType, loc); + ce.EmitPredefined (ec, finally_host.Spec, new Arguments (0)); + } else { + EmitFinallyBody (ec); + } ec.EndExceptionBlock (); } @@ -4423,12 +4590,10 @@ namespace Mono.CSharp { bool emit_dispatcher = j < labels.Length; if (emit_dispatcher) { - //SymbolWriter.StartIteratorDispatcher (ec.ig); ec.Emit (OpCodes.Ldloc, pc); ec.EmitInt (first_resume_pc); ec.Emit (OpCodes.Sub); ec.Emit (OpCodes.Switch, labels); - //SymbolWriter.EndIteratorDispatcher (ec.ig); } foreach (ResumableStatement s in resume_points) @@ -4439,10 +4604,34 @@ namespace Mono.CSharp { ec.BeginFinallyBlock (); - EmitFinallyBody (ec); + if (finally_host != null) { + var ce = new CallEmitter (); + ce.InstanceExpression = new CompilerGeneratedThis (ec.CurrentType, loc); + ce.EmitPredefined (ec, finally_host.Spec, new Arguments (0)); + } else { + EmitFinallyBody (ec); + } ec.EndExceptionBlock (); } + + public override bool Resolve (BlockContext bc) + { + // + // Finally block inside iterator is called from MoveNext and + // Dispose methods that means we need to lift the block into + // newly created host method to emit the body only once. The + // original block then simply calls the newly generated method. + // + if (bc.CurrentIterator != null && !bc.IsInProbingMode) { + var b = stmt as Block; + if (b != null && b.Explicit.HasYield) { + finally_host = bc.CurrentIterator.CreateFinallyHost (this); + } + } + + return base.Resolve (bc); + } } // @@ -4631,7 +4820,7 @@ namespace Mono.CSharp { Statement.Emit (ec); } - protected override void EmitFinallyBody (EmitContext ec) + public override void EmitFinallyBody (EmitContext ec) { // // if (lock_taken) Monitor.Exit (expr_copy) @@ -5234,6 +5423,7 @@ namespace Mono.CSharp { if (ok) ec.CurrentBranching.CreateSibling (fini, FlowBranching.SiblingType.Finally); + using (ec.With (ResolveContext.Options.FinallyScope, true)) { if (!fini.Resolve (ec)) ok = false; @@ -5251,7 +5441,7 @@ namespace Mono.CSharp { stmt.Emit (ec); } - protected override void EmitFinallyBody (EmitContext ec) + public override void EmitFinallyBody (EmitContext ec) { fini.Emit (ec); } @@ -5595,7 +5785,7 @@ namespace Mono.CSharp { stmt.Emit (ec); } - protected override void EmitFinallyBody (EmitContext ec) + public override void EmitFinallyBody (EmitContext ec) { decl.EmitDispose (ec); } @@ -6238,6 +6428,7 @@ namespace Mono.CSharp { target.type = type.Clone (clonectx); target.expr = expr.Clone (clonectx); target.body = (Block) body.Clone (clonectx); + target.statement = statement.Clone (clonectx); } public override object Accept (StructuralVisitor visitor) diff --git a/ICSharpCode.NRefactory.Tests/FormattingTests/TestStatementIndentation.cs b/ICSharpCode.NRefactory.Tests/FormattingTests/TestStatementIndentation.cs index 7a9505f6f2..fbc17ce14b 100644 --- a/ICSharpCode.NRefactory.Tests/FormattingTests/TestStatementIndentation.cs +++ b/ICSharpCode.NRefactory.Tests/FormattingTests/TestStatementIndentation.cs @@ -947,7 +947,6 @@ do { }"); } - [Ignore("Broken")] [Test()] [Ignore("Crashes due to overlapping changes")] public void TestForEachBraceForcementRemove () @@ -1105,7 +1104,6 @@ do { }"); } - [Ignore("Broken")] [Test()] [Ignore("Crashes due to overlapping changes")] public void TestIfForcementRemove () @@ -1415,7 +1413,6 @@ if (b) { }"); } - [Ignore("Broken")] [Test()] [Ignore("Crashes due to overlapping changes")] public void TestWhileForcementRemove ()