Skip to content

Commit

Permalink
Updated mcs/fixed parser bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Krüger committed Nov 14, 2013
1 parent ecb2435 commit 50733f5
Show file tree
Hide file tree
Showing 44 changed files with 1,282 additions and 805 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ void AddIssue(AstNode node)
if (containsInvocations && isDeclareStatement) {
//add the column ';' that will be removed after the next line replacement
var expression = (Statement)variableNode.Initializer.Clone();
if (ContainsOtherAssignments(variableInitializer.Parent) && varDecl != null ) {
if (containsLaterAssignments && varDecl != null) {
var clonedDefinition = (VariableDeclarationStatement)varDecl.Clone();

var shortExpressionType = CreateShortType(ctx, expressionType, node);
Expand All @@ -312,7 +312,7 @@ void AddIssue(AstNode node)
script.Replace(node.Parent, expression);
return;
}
if (isDeclareStatement && !containsRefOrOut && !ContainsOtherAssignments(variableInitializer.Parent)) {
if (isDeclareStatement && !containsRefOrOut && !containsLaterAssignments&& !ContainsOtherAssignments(variableInitializer.Parent)) {
script.Remove(node.Parent);
return;
}
Expand Down
92 changes: 54 additions & 38 deletions ICSharpCode.NRefactory.CSharp/Parser/mcs/anonymous.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,27 @@ public StoreyFieldPair (AnonymousMethodStorey storey, Field field)
sealed class ThisInitializer : Statement
{
readonly HoistedThis hoisted_this;
readonly AnonymousMethodStorey parent;

public ThisInitializer (HoistedThis hoisted_this)
public ThisInitializer (HoistedThis hoisted_this, AnonymousMethodStorey parent)
{
this.hoisted_this = hoisted_this;
this.parent = parent;
}

protected override void DoEmit (EmitContext ec)
{
hoisted_this.EmitAssign (ec, new CompilerGeneratedThis (ec.CurrentType, loc), false, false);
Expression source;

if (parent == null)
source = new CompilerGeneratedThis (ec.CurrentType, loc);
else {
source = new FieldExpr (parent.HoistedThis.Field, Location.Null) {
InstanceExpression = new CompilerGeneratedThis (ec.CurrentType, Location.Null)
};
}

hoisted_this.EmitAssign (ec, source, false, false);
}

protected override void CloneTo (CloneContext clonectx, Statement target)
Expand Down Expand Up @@ -230,22 +242,24 @@ protected override void CloneTo (CloneContext clonectx, Statement target)
public Expression Instance;

bool initialize_hoisted_this;
AnonymousMethodStorey hoisted_this_parent;

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),
: base (parent, MakeMemberName (host, name, parent.PartialContainer.CounterAnonymousContainers, tparams, block.StartLocation),
tparams, 0, kind)
{
OriginalSourceBlock = block;
ID = parent.Module.CounterAnonymousContainers++;
ID = parent.PartialContainer.CounterAnonymousContainers++;
}

public void AddCapturedThisField (EmitContext ec)
public void AddCapturedThisField (EmitContext ec, AnonymousMethodStorey parent)
{
TypeExpr type_expr = new TypeExpression (ec.CurrentType, Location);
Field f = AddCompilerGeneratedField ("$this", type_expr);
hoisted_this = new HoistedThis (this, f);

initialize_hoisted_this = true;
hoisted_this_parent = parent;
}

public Field AddCapturedVariable (string name, TypeSpec type)
Expand Down Expand Up @@ -554,7 +568,7 @@ void EmitHoistedFieldsInitialization (ResolveContext rc, EmitContext ec)
// referenced indirectly
//
if (initialize_hoisted_this) {
rc.CurrentBlock.AddScopeStatement (new ThisInitializer (hoisted_this));
rc.CurrentBlock.AddScopeStatement (new ThisInitializer (hoisted_this, hoisted_this_parent));
}

//
Expand Down Expand Up @@ -957,6 +971,12 @@ public virtual bool HasExplicitParameters {
}
}

public override bool IsSideEffectFree {
get {
return true;
}
}

public ParametersCompiled Parameters {
get {
return Block.Parameters;
Expand Down Expand Up @@ -1013,9 +1033,9 @@ TypeSpec CompatibleChecks (ResolveContext ec, TypeSpec delegate_type)
return null;
}

protected bool VerifyExplicitParameters (ResolveContext ec, TypeSpec delegate_type, AParametersCollection parameters)
protected bool VerifyExplicitParameters (ResolveContext ec, TypeInferenceContext tic, TypeSpec delegate_type, AParametersCollection parameters)
{
if (VerifyParameterCompatibility (ec, delegate_type, parameters, ec.IsInProbingMode))
if (VerifyParameterCompatibility (ec, tic, delegate_type, parameters, ec.IsInProbingMode))
return true;

if (!ec.IsInProbingMode)
Expand All @@ -1026,7 +1046,7 @@ protected bool VerifyExplicitParameters (ResolveContext ec, TypeSpec delegate_ty
return false;
}

protected bool VerifyParameterCompatibility (ResolveContext ec, TypeSpec delegate_type, AParametersCollection invoke_pd, bool ignore_errors)
protected bool VerifyParameterCompatibility (ResolveContext ec, TypeInferenceContext tic, TypeSpec delegate_type, AParametersCollection invoke_pd, bool ignore_errors)
{
if (Parameters.Count != invoke_pd.Count) {
if (ignore_errors)
Expand Down Expand Up @@ -1059,14 +1079,11 @@ protected bool VerifyParameterCompatibility (ResolveContext ec, TypeSpec delegat
continue;

TypeSpec type = invoke_pd.Types [i];

if (tic != null)
type = tic.InflateGenericArgument (ec, type);

//
// Assumes that generic mvar parameters are always inflated
//
if (ImplicitDelegateCreation.ContainsMethodTypeParameter (type))
continue;

if (!TypeSpecComparer.IsEqual (invoke_pd.Types [i], Parameters.Types [i])) {
if (!TypeSpecComparer.IsEqual (type, Parameters.Types [i])) {
if (ignore_errors)
return false;

Expand All @@ -1084,7 +1101,7 @@ Parameters.Types [i].GetSignatureForError (),
//
// Infers type arguments based on explicit arguments
//
public bool ExplicitTypeInference (ResolveContext ec, TypeInferenceContext type_inference, TypeSpec delegate_type)
public bool ExplicitTypeInference (TypeInferenceContext type_inference, TypeSpec delegate_type)
{
if (!HasExplicitParameters)
return false;
Expand Down Expand Up @@ -1298,7 +1315,7 @@ protected virtual ParametersCompiled ResolveParameters (ResolveContext ec, TypeI
return ParametersCompiled.CreateFullyResolved (fixedpars, delegate_parameters.Types);
}

if (!VerifyExplicitParameters (ec, delegate_type, delegate_parameters)) {
if (!VerifyExplicitParameters (ec, tic, delegate_type, delegate_parameters)) {
return null;
}

Expand Down Expand Up @@ -1511,7 +1528,7 @@ public AnonymousExpression Compatible (ResolveContext ec, AnonymousExpression ae

var bc = ec as BlockContext;
if (bc != null)
aec.FlowOffset = bc.FlowOffset;
aec.AssignmentInfoOffset = bc.AssignmentInfoOffset;

var errors = ec.Report.Errors;

Expand All @@ -1524,10 +1541,14 @@ public AnonymousExpression Compatible (ResolveContext ec, AnonymousExpression ae

//
// If e is synchronous the inferred return type is T
// If e is asynchronous the inferred return type is Task<T>
// If e is asynchronous and the body of F is either an expression classified as nothing
// or a statement block where no return statements have expressions, the inferred return type is Task
// If e is async and has an inferred result type T, the inferred return type is Task<T>
//
if (block.IsAsync && ReturnType != null) {
ReturnType = ec.Module.PredefinedTypes.TaskGeneric.TypeSpec.MakeGenericType (ec, new [] { ReturnType });
ReturnType = ReturnType.Kind == MemberKind.Void ?
ec.Module.PredefinedTypes.Task.TypeSpec :
ec.Module.PredefinedTypes.TaskGeneric.TypeSpec.MakeGenericType (ec, new [] { ReturnType });
}
}

Expand Down Expand Up @@ -1666,7 +1687,7 @@ AnonymousMethodMethod DoCreateMethodHost (EmitContext ec)
// enough. No hoisted variables only 'this' and don't need to
// propagate this to value type state machine.
//
StateMachine sm_parent = null;
StateMachine sm_parent;
var pb = src_block.ParametersBlock;
do {
sm_parent = pb.StateMachine;
Expand All @@ -1678,18 +1699,17 @@ AnonymousMethodMethod DoCreateMethodHost (EmitContext ec)
} else if (sm_parent.Kind == MemberKind.Struct) {
//
// Special case where parent class is used to emit instance method
// because currect storey is of value type (async host). We cannot
// because currect storey is of value type (async host) and we cannot
// use ldftn on non-boxed instances either to share mutated state
//
parent = sm_parent.Parent.PartialContainer;
} else if (sm is IteratorStorey) {
//
// For iterators we can host everything in one class
//
parent = storey = sm;
}
}

//
// For iterators we can host everything in one class
//
if (sm is IteratorStorey)
parent = storey = sm;
}

modifiers = storey != null ? Modifiers.INTERNAL : Modifiers.PRIVATE;
Expand All @@ -1704,7 +1724,7 @@ AnonymousMethodMethod DoCreateMethodHost (EmitContext ec)
parent = ec.CurrentTypeDefinition.Parent.PartialContainer;

string name = CompilerGeneratedContainer.MakeName (parent != storey ? block_name : null,
"m", null, ec.Module.CounterAnonymousMethods++);
"m", null, parent.PartialContainer.CounterAnonymousMethods++);

MemberName member_name;
if (storey == null && ec.CurrentTypeParameters != null) {
Expand Down Expand Up @@ -1812,12 +1832,8 @@ public override void Emit (EmitContext ec)
// 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;
}
}
if (ec.CurrentAnonymousMethod != null && ec.AsyncTaskStorey != null)
ec.Emit (OpCodes.Ldfld, ec.AsyncTaskStorey.HoistedThis.Field.Spec);
}

var delegate_method = method.Spec;
Expand Down Expand Up @@ -1996,7 +2012,7 @@ protected override bool DoDefineMembers ()

Method tostring = new Method (this, new TypeExpression (Compiler.BuiltinTypes.String, loc),
Modifiers.PUBLIC | Modifiers.OVERRIDE | Modifiers.DEBUGGER_HIDDEN, new MemberName ("ToString", loc),
Mono.CSharp.ParametersCompiled.EmptyReadOnlyParameters, null);
ParametersCompiled.EmptyReadOnlyParameters, null);

ToplevelBlock equals_block = new ToplevelBlock (Compiler, equals.ParameterInfo, loc);

Expand Down Expand Up @@ -2105,7 +2121,7 @@ protected override bool DoDefineMembers ()
Method hashcode = new Method (this, new TypeExpression (Compiler.BuiltinTypes.Int, loc),
Modifiers.PUBLIC | Modifiers.OVERRIDE | Modifiers.DEBUGGER_HIDDEN,
new MemberName ("GetHashCode", loc),
Mono.CSharp.ParametersCompiled.EmptyReadOnlyParameters, null);
ParametersCompiled.EmptyReadOnlyParameters, null);

//
// Modified FNV with good avalanche behavior and uniform
Expand Down
6 changes: 3 additions & 3 deletions ICSharpCode.NRefactory.CSharp/Parser/mcs/assembly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ void SetEntryPoint ()
return;
}

var mtype = texpr.Type.MemberDefinition as ClassOrStruct;
var mtype = texpr.MemberDefinition as ClassOrStruct;
if (mtype == null) {
Report.Error (1556, "`{0}' specified for Main method must be a valid class or struct", main_class);
return;
Expand Down Expand Up @@ -1110,13 +1110,13 @@ public virtual void SetVersion (Version version, Location loc)
}
}

abstract class AssemblyReferencesLoader<T>
abstract class AssemblyReferencesLoader<T> where T : class
{
protected readonly CompilerContext compiler;

protected readonly List<string> paths;

public AssemblyReferencesLoader (CompilerContext compiler)
protected AssemblyReferencesLoader (CompilerContext compiler)
{
this.compiler = compiler;

Expand Down
4 changes: 3 additions & 1 deletion ICSharpCode.NRefactory.CSharp/Parser/mcs/assign.cs
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,9 @@ protected override Expression ResolveConversions (ResolveContext ec)
if (b == null) {
if (source is ReducedExpression)
b = ((ReducedExpression) source).OriginalExpression as Binary;
else if (source is Nullable.LiftedBinaryOperator) {
else if (source is ReducedExpression.ReducedConstantExpression) {
b = ((ReducedExpression.ReducedConstantExpression) source).OriginalExpression as Binary;
} else if (source is Nullable.LiftedBinaryOperator) {
var po = ((Nullable.LiftedBinaryOperator) source);
if (po.UserOperator == null)
b = po.Binary;
Expand Down
11 changes: 3 additions & 8 deletions ICSharpCode.NRefactory.CSharp/Parser/mcs/async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public Expression GetResultExpression (EmitContext ec)

public void EmitPrologue (EmitContext ec)
{
awaiter = ((AsyncTaskStorey) machine_initializer.Storey).AddAwaiter (expr.Type, loc);
awaiter = ((AsyncTaskStorey) machine_initializer.Storey).AddAwaiter (expr.Type);

var fe_awaiter = new FieldExpr (awaiter, loc);
fe_awaiter.InstanceExpression = new CompilerGeneratedThis (ec.CurrentType, loc);
Expand Down Expand Up @@ -415,11 +415,6 @@ protected override BlockContext CreateBlockContext (ResolveContext rc)
return ctx;
}

public override Expression CreateExpressionTree (ResolveContext ec)
{
return base.CreateExpressionTree (ec);
}

public override void Emit (EmitContext ec)
{
throw new NotImplementedException ();
Expand Down Expand Up @@ -489,12 +484,12 @@ protected override TypeAttributes TypeAttr {

#endregion

public Field AddAwaiter (TypeSpec type, Location loc)
public Field AddAwaiter (TypeSpec type)
{
if (mutator != null)
type = mutator.Mutate (type);

List<Field> existing_fields = null;
List<Field> existing_fields;
if (awaiter_fields.TryGetValue (type, out existing_fields)) {
foreach (var f in existing_fields) {
if (f.IsAvailableForReuse) {
Expand Down
6 changes: 4 additions & 2 deletions ICSharpCode.NRefactory.CSharp/Parser/mcs/attribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ public void Emit (Dictionary<Attribute, List<Attribute>> allEmitted)
cdata = encoder.ToArray ();
}

if (!ctor.DeclaringType.IsConditionallyExcluded (context, Location)) {
if (!ctor.DeclaringType.IsConditionallyExcluded (context)) {
try {
foreach (Attributable target in targets)
target.ApplyAttributeBuilder (this, ctor, cdata, predefined);
Expand Down Expand Up @@ -1170,7 +1170,7 @@ public Attributes (Attribute a)

public Attributes (List<Attribute> attrs)
{
Attrs = attrs;
Attrs = attrs ?? new List<Attribute> ();
#if FULL_AST
Sections.Add (attrs);
#endif
Expand Down Expand Up @@ -1669,6 +1669,7 @@ public class PredefinedAttributes
public readonly PredefinedAttribute UnsafeValueType;
public readonly PredefinedAttribute UnmanagedFunctionPointer;
public readonly PredefinedDebuggerBrowsableAttribute DebuggerBrowsable;
public readonly PredefinedAttribute DebuggerStepThrough;

// New in .NET 3.5
public readonly PredefinedAttribute Extension;
Expand Down Expand Up @@ -1735,6 +1736,7 @@ public PredefinedAttributes (ModuleContainer module)
UnsafeValueType = new PredefinedAttribute (module, "System.Runtime.CompilerServices", "UnsafeValueTypeAttribute");
UnmanagedFunctionPointer = new PredefinedAttribute (module, "System.Runtime.InteropServices", "UnmanagedFunctionPointerAttribute");
DebuggerBrowsable = new PredefinedDebuggerBrowsableAttribute (module, "System.Diagnostics", "DebuggerBrowsableAttribute");
DebuggerStepThrough = new PredefinedAttribute (module, "System.Diagnostics", "DebuggerStepThroughAttribute");

Extension = new PredefinedAttribute (module, "System.Runtime.CompilerServices", "ExtensionAttribute");

Expand Down
2 changes: 1 addition & 1 deletion ICSharpCode.NRefactory.CSharp/Parser/mcs/cfold.cs
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ static public Constant BinaryFold (ResolveContext ec, Binary.Operator oper,

IntConstant sic = right.ConvertImplicitly (ec.BuiltinTypes.Int) as IntConstant;
if (sic == null){
Binary.Error_OperatorCannotBeApplied (ec, left, right, oper, loc); ;
Binary.Error_OperatorCannotBeApplied (ec, left, right, oper, loc);
return null;
}
int rshift_val = sic.Value;
Expand Down
Loading

0 comments on commit 50733f5

Please sign in to comment.