Browse Source

Updated mcs (fixed parser bug).

newNRvisualizers
Mike Krüger 13 years ago
parent
commit
637a7daae2
  1. 16
      ICSharpCode.NRefactory.CSharp/Parser/mcs/anonymous.cs
  2. 46
      ICSharpCode.NRefactory.CSharp/Parser/mcs/attribute.cs
  3. 2
      ICSharpCode.NRefactory.CSharp/Parser/mcs/class.cs
  4. 4
      ICSharpCode.NRefactory.CSharp/Parser/mcs/context.cs
  5. 19
      ICSharpCode.NRefactory.CSharp/Parser/mcs/convert.cs
  6. 1194
      ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.cs
  7. 3
      ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.jay
  8. 29
      ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-tokenizer.cs
  9. 95
      ICSharpCode.NRefactory.CSharp/Parser/mcs/ecore.cs
  10. 6
      ICSharpCode.NRefactory.CSharp/Parser/mcs/eval.cs
  11. 41
      ICSharpCode.NRefactory.CSharp/Parser/mcs/expression.cs
  12. 26
      ICSharpCode.NRefactory.CSharp/Parser/mcs/flowanalysis.cs
  13. 2
      ICSharpCode.NRefactory.CSharp/Parser/mcs/generic.cs
  14. 7
      ICSharpCode.NRefactory.CSharp/Parser/mcs/import.cs
  15. 2
      ICSharpCode.NRefactory.CSharp/Parser/mcs/iterators.cs
  16. 5
      ICSharpCode.NRefactory.CSharp/Parser/mcs/module.cs
  17. 31
      ICSharpCode.NRefactory.CSharp/Parser/mcs/namespace.cs
  18. 2
      ICSharpCode.NRefactory.CSharp/Parser/mcs/parameter.cs
  19. 2
      ICSharpCode.NRefactory.CSharp/Parser/mcs/pending.cs
  20. 17
      ICSharpCode.NRefactory.CSharp/Parser/mcs/statement.cs
  21. 150
      ICSharpCode.NRefactory.CSharp/Parser/mcs/support.cs
  22. 1
      ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/CodeCompletionBugTests.cs
  23. 23
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Bugs/ParserBugTests.cs

16
ICSharpCode.NRefactory.CSharp/Parser/mcs/anonymous.cs

@ -1101,9 +1101,19 @@ namespace Mono.CSharp { @@ -1101,9 +1101,19 @@ namespace Mono.CSharp {
if (d_params.Count != Parameters.Count)
return false;
var ptypes = Parameters.Types;
var dtypes = d_params.Types;
for (int i = 0; i < Parameters.Count; ++i) {
if (type_inference.ExactInference (Parameters.Types[i], d_params.Types[i]) == 0)
if (type_inference.ExactInference (ptypes[i], dtypes[i]) == 0) {
//
// Continue when 0 (quick path) does not mean inference failure. Checking for
// same type handles cases like int -> int
//
if (ptypes[i] == dtypes[i])
continue;
return false;
}
}
return true;
@ -1644,9 +1654,9 @@ namespace Mono.CSharp { @@ -1644,9 +1654,9 @@ namespace Mono.CSharp {
var sm = src_block.ParametersBlock.TopBlock.StateMachine;
//
// Remove hoisted this demand when simple instance method is enough
// Remove hoisted this demand when simple instance method is enough (no hoisted variables only this)
//
if (src_block.HasCapturedThis) {
if (src_block.HasCapturedThis && src_block.ParametersBlock.StateMachine == null) {
src_block.ParametersBlock.TopBlock.RemoveThisReferenceFromChildrenBlock (src_block);
//

46
ICSharpCode.NRefactory.CSharp/Parser/mcs/attribute.cs

@ -143,6 +143,12 @@ namespace Mono.CSharp { @@ -143,6 +143,12 @@ namespace Mono.CSharp {
}
}
public bool ResolveError {
get {
return resolve_error;
}
}
public ATypeNameExpression TypeExpression {
get {
return expression;
@ -275,7 +281,7 @@ namespace Mono.CSharp { @@ -275,7 +281,7 @@ namespace Mono.CSharp {
/// <summary>
/// Tries to resolve the type of the attribute. Flags an error if it can't, and complain is true.
/// </summary>
void ResolveAttributeType ()
void ResolveAttributeType (bool comparisonOnly)
{
SessionReportPrinter resolve_printer = new SessionReportPrinter ();
ReportPrinter prev_recorder = Report.SetPrinter (resolve_printer);
@ -310,9 +316,12 @@ namespace Mono.CSharp { @@ -310,9 +316,12 @@ namespace Mono.CSharp {
}
if (t1_is_attr && t2_is_attr && t1 != t2) {
Report.Error (1614, Location, "`{0}' is ambiguous between `{1}' and `{2}'. Use either `@{0}' or `{0}Attribute'",
GetSignatureForError (), expression.GetSignatureForError (), expanded.GetSignatureForError ());
resolve_error = true;
if (!comparisonOnly) {
Report.Error (1614, Location, "`{0}' is ambiguous between `{1}' and `{2}'. Use either `@{0}' or `{0}Attribute'",
GetSignatureForError (), expression.GetSignatureForError (), expanded.GetSignatureForError ());
resolve_error = true;
}
return;
}
@ -326,6 +335,9 @@ namespace Mono.CSharp { @@ -326,6 +335,9 @@ namespace Mono.CSharp {
return;
}
if (comparisonOnly)
return;
resolve_error = true;
if (t1 != null) {
@ -345,10 +357,10 @@ namespace Mono.CSharp { @@ -345,10 +357,10 @@ namespace Mono.CSharp {
resolve_printer.Merge (prev_recorder);
}
public TypeSpec ResolveType ()
public TypeSpec ResolveTypeForComparison ()
{
if (Type == null && !resolve_error)
ResolveAttributeType ();
ResolveAttributeType (true);
return Type;
}
@ -430,7 +442,7 @@ namespace Mono.CSharp { @@ -430,7 +442,7 @@ namespace Mono.CSharp {
arg_resolved = true;
if (Type == null) {
ResolveAttributeType ();
ResolveAttributeType (false);
if (Type == null)
return null;
}
@ -1133,15 +1145,13 @@ namespace Mono.CSharp { @@ -1133,15 +1145,13 @@ namespace Mono.CSharp {
Attrs.Add (a);
#if FULL_AST
var s = new List<Attribute>();
s.Add(a);
Sections.Add (s);
Sections.Add (Attrs);
#endif
}
public Attributes (List<Attribute> attrs)
{
Attrs = new List<Attribute>(attrs);
Attrs = attrs;
#if FULL_AST
Sections.Add (attrs);
#endif
@ -1213,6 +1223,16 @@ namespace Mono.CSharp { @@ -1213,6 +1223,16 @@ namespace Mono.CSharp {
}
}
public bool HasResolveError()
{
foreach (var a in Attrs) {
if (a.ResolveError)
return true;
}
return false;
}
public Attribute Search (PredefinedAttribute t)
{
return Search (null, t);
@ -1224,7 +1244,7 @@ namespace Mono.CSharp { @@ -1224,7 +1244,7 @@ namespace Mono.CSharp {
if (explicitTarget != null && a.ExplicitTarget != explicitTarget)
continue;
if (a.ResolveType () == t)
if (a.ResolveTypeForComparison () == t)
return a;
}
return null;
@ -1238,7 +1258,7 @@ namespace Mono.CSharp { @@ -1238,7 +1258,7 @@ namespace Mono.CSharp {
List<Attribute> ar = null;
foreach (Attribute a in Attrs) {
if (a.ResolveType () == t) {
if (a.ResolveTypeForComparison () == t) {
if (ar == null)
ar = new List<Attribute> (Attrs.Count);
ar.Add (a);

2
ICSharpCode.NRefactory.CSharp/Parser/mcs/class.cs

@ -3344,7 +3344,7 @@ namespace Mono.CSharp @@ -3344,7 +3344,7 @@ namespace Mono.CSharp
{
// for extern static method must be specified either DllImport attribute or MethodImplAttribute.
// We are more strict than csc and report this as an error because SRE does not allow emit that
if ((ModFlags & Modifiers.EXTERN) != 0 && !is_external_implementation) {
if ((ModFlags & Modifiers.EXTERN) != 0 && !is_external_implementation && (OptAttributes == null || !OptAttributes.HasResolveError ())) {
if (this is Constructor) {
Report.Warning (824, 1, Location,
"Constructor `{0}' is marked `external' but has no external implementation specified", GetSignatureForError ());

4
ICSharpCode.NRefactory.CSharp/Parser/mcs/context.cs

@ -475,14 +475,14 @@ namespace Mono.CSharp @@ -475,14 +475,14 @@ namespace Mono.CSharp
// or it's a parameter
//
if (CurrentAnonymousMethod.IsIterator)
return local.IsParameter || CurrentBlock.Explicit.HasYield;
return local.IsParameter || local.Block.Explicit.HasYield;
//
// Capture only if this or any of child blocks contain await
// or it's a parameter
//
if (CurrentAnonymousMethod is AsyncInitializer)
return local.IsParameter || CurrentBlock.Explicit.HasAwait;
return local.IsParameter || local.Block.Explicit.HasAwait || CurrentBlock.Explicit.HasAwait;
return local.Block.ParametersBlock != CurrentBlock.ParametersBlock.Original;
}

19
ICSharpCode.NRefactory.CSharp/Parser/mcs/convert.cs

@ -1090,12 +1090,13 @@ namespace Mono.CSharp { @@ -1090,12 +1090,13 @@ namespace Mono.CSharp {
Expression source_type_expr;
if (source_type.IsNullableType) {
// No implicit conversion S? -> T for non-reference types
if (implicitOnly && !TypeSpec.IsReferenceType (target_type) && !target_type.IsNullableType)
return null;
source_type_expr = Nullable.Unwrap.Create (source);
source_type = source_type_expr.Type;
// No unwrapping conversion S? -> T for non-reference types
if (implicitOnly && !TypeSpec.IsReferenceType (target_type) && !target_type.IsNullableType) {
source_type_expr = source;
} else {
source_type_expr = Nullable.Unwrap.Create (source);
source_type = source_type_expr.Type;
}
} else {
source_type_expr = source;
}
@ -1196,7 +1197,11 @@ namespace Mono.CSharp { @@ -1196,7 +1197,11 @@ namespace Mono.CSharp {
var c = source as Constant;
if (c != null) {
source = c.TryReduce (ec, s_x);
} else {
if (source == null)
c = null;
}
if (c == null) {
source = implicitOnly ?
ImplicitConversionStandard (ec, source_type_expr, s_x, loc) :
ExplicitConversionStandard (ec, source_type_expr, s_x, loc);

1194
ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.cs

File diff suppressed because it is too large Load Diff

3
ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.jay

@ -1657,7 +1657,8 @@ parameter_array @@ -1657,7 +1657,8 @@ parameter_array
| opt_attributes params_modifier type error
{
Error_SyntaxError (yyToken);
$$ = null;
$$ = new ParamsParameter ((FullNamedExpression) $3, null, (Attributes) $1, Location.Null);
}
;

29
ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-tokenizer.cs

@ -1798,7 +1798,7 @@ namespace Mono.CSharp @@ -1798,7 +1798,7 @@ namespace Mono.CSharp
if (peek_char () == '\n') {
putback_char = -1;
}
x = '\n';
advance_line ();
} else if (x == '\n') {
@ -1809,26 +1809,6 @@ namespace Mono.CSharp @@ -1809,26 +1809,6 @@ namespace Mono.CSharp
return x;
}
int get_char_withwithoutskippingwindowseol ()
{
int x;
if (putback_char != -1) {
x = putback_char;
putback_char = -1;
} else {
x = reader.Read ();
}
if (x == '\r') {
} else if (x == '\n') {
advance_line ();
} else {
col++;
}
return x;
}
void advance_line ()
{
line++;
@ -2478,6 +2458,11 @@ namespace Mono.CSharp @@ -2478,6 +2458,11 @@ namespace Mono.CSharp
}
Report.Warning (1634, 1, Location, "Expected disable or restore");
// Eat any remaining characters on the line
while (c != '\n' && c != -1)
c = get_char ();
return;
}
@ -2916,7 +2901,7 @@ namespace Mono.CSharp @@ -2916,7 +2901,7 @@ namespace Mono.CSharp
#endif
while (true){
c = get_char_withwithoutskippingwindowseol ();
c = get_char ();
if (c == '"') {
if (quoted && peek_char () == '"') {
if (pos == value_builder.Length)

95
ICSharpCode.NRefactory.CSharp/Parser/mcs/ecore.cs

@ -323,14 +323,7 @@ namespace Mono.CSharp { @@ -323,14 +323,7 @@ namespace Mono.CSharp {
public virtual void Error_ValueAssignment (ResolveContext rc, Expression rhs)
{
if (rhs == EmptyExpression.LValueMemberAccess || rhs == EmptyExpression.LValueMemberOutAccess) {
rc.Report.SymbolRelatedToPreviousError (type);
if (rc.CurrentInitializerVariable != null) {
rc.Report.Error (1918, loc, "Members of value type `{0}' cannot be assigned using a property `{1}' object initializer",
type.GetSignatureForError (), GetSignatureForError ());
} else {
rc.Report.Error (1612, loc, "Cannot modify a value type return value of `{0}'. Consider storing the value in a temporary variable",
GetSignatureForError ());
}
// Already reported as CS1612
} else {
rc.Report.Error (131, loc, "The left-hand side of an assignment must be a variable, a property or an indexer");
}
@ -2947,6 +2940,30 @@ namespace Mono.CSharp { @@ -2947,6 +2940,30 @@ namespace Mono.CSharp {
}
public bool ResolveInstanceExpression (ResolveContext rc, Expression rhs)
{
if (!ResolveInstanceExpressionCore (rc, rhs))
return false;
//
// Check intermediate value modification which won't have any effect
//
if (rhs != null && InstanceExpression.Type.IsStruct &&
(InstanceExpression is PropertyExpr || InstanceExpression is IndexerExpr || InstanceExpression is Invocation)) {
if (rc.CurrentInitializerVariable != null) {
rc.Report.Error (1918, loc, "Members of value type `{0}' cannot be assigned using a property `{1}' object initializer",
InstanceExpression.Type.GetSignatureForError (), InstanceExpression.GetSignatureForError ());
} else {
rc.Report.Error (1612, loc,
"Cannot modify a value type return value of `{0}'. Consider storing the value in a temporary variable",
InstanceExpression.GetSignatureForError ());
}
}
return true;
}
bool ResolveInstanceExpressionCore (ResolveContext rc, Expression rhs)
{
if (IsStatic) {
if (InstanceExpression != null) {
@ -3010,7 +3027,7 @@ namespace Mono.CSharp { @@ -3010,7 +3027,7 @@ namespace Mono.CSharp {
var me = InstanceExpression as MemberExpr;
if (me != null) {
me.ResolveInstanceExpression (rc, rhs);
me.ResolveInstanceExpressionCore (rc, rhs);
// Using this check to detect probing instance expression resolve
if (!rc.OmitStructFlowAnalysis) {
@ -4020,19 +4037,20 @@ namespace Mono.CSharp { @@ -4020,19 +4037,20 @@ namespace Mono.CSharp {
//
// Foo (int i) is better than Foo (int i, long l = 0)
// Foo (params int[] args) is better than Foo (int i = 0, params int[] args)
// Foo (string s, params string[] args) is better than Foo (params string[] args)
//
// Prefer non-optional version
//
// LAMESPEC: Specification claims this should be done at last but the opposite is true
//
if (candidate_params == best_params && candidate_pd.Count != best_pd.Count) {
if (candidate_pd.Count >= best_pd.Count)
return false;
if (j < candidate_pd.Count && candidate_pd.FixedParameters[j].HasDefaultValue)
return false;
return true;
if (j < best_pd.Count && best_pd.FixedParameters[j].HasDefaultValue)
return true;
return candidate_pd.Count >= best_pd.Count;
}
//
@ -4374,16 +4392,32 @@ namespace Mono.CSharp { @@ -4374,16 +4392,32 @@ namespace Mono.CSharp {
// if the type matches
//
Expression e = fp.DefaultValue;
if (!(e is Constant) || e.Type.IsGenericOrParentIsGeneric || e.Type.IsGenericParameter) {
if (!(e is Constant) || e.Type != ptypes [i]) {
//
// LAMESPEC: No idea what the exact rules are for System.Reflection.Missing.Value instead of null
//
if (e == EmptyExpression.MissingValue && ptypes[i].BuiltinType == BuiltinTypeSpec.Type.Object || ptypes[i].BuiltinType == BuiltinTypeSpec.Type.Dynamic) {
var ptype = ptypes [i];
if (e == EmptyExpression.MissingValue && ptype.BuiltinType == BuiltinTypeSpec.Type.Object || ptype.BuiltinType == BuiltinTypeSpec.Type.Dynamic) {
e = new MemberAccess (new MemberAccess (new MemberAccess (
new QualifiedAliasMember (QualifiedAliasMember.GlobalAlias, "System", loc), "Reflection", loc), "Missing", loc), "Value", loc);
} else if (e is Constant) {
//
// Handles int to int? conversions
//
e = Convert.ImplicitConversionStandard (ec, e, ptype, loc);
//
// When constant type paramter contains type argument
//
// Foo (T[] arg = null)
//
if (e == null) {
e = new DefaultValueExpression (new TypeExpression (ptype, loc), loc);
}
} else {
e = new DefaultValueExpression (new TypeExpression (ptypes [i], loc), loc);
e = new DefaultValueExpression (new TypeExpression (ptype, loc), loc);
}
e = e.Resolve (ec);
}
@ -4852,13 +4886,18 @@ namespace Mono.CSharp { @@ -4852,13 +4886,18 @@ namespace Mono.CSharp {
return null;
//
// Check ObsoleteAttribute on the best method
// Don't run possibly expensive checks in probing mode
//
ObsoleteAttribute oa = best_candidate.GetAttributeObsolete ();
if (oa != null && !rc.IsObsolete)
AttributeTester.Report_ObsoleteMessage (oa, best_candidate.GetSignatureForError (), loc, rc.Report);
if (!rc.IsInProbingMode) {
//
// Check ObsoleteAttribute on the best method
//
ObsoleteAttribute oa = best_candidate.GetAttributeObsolete ();
if (oa != null && !rc.IsObsolete)
AttributeTester.Report_ObsoleteMessage (oa, best_candidate.GetSignatureForError (), loc, rc.Report);
best_candidate.MemberDefinition.SetIsUsed ();
best_candidate.MemberDefinition.SetIsUsed ();
}
args = best_candidate_args;
return (T) best_candidate;
@ -4881,7 +4920,7 @@ namespace Mono.CSharp { @@ -4881,7 +4920,7 @@ namespace Mono.CSharp {
if (a is CollectionElementInitializer.ElementInitializerArgument) {
ec.Report.SymbolRelatedToPreviousError (method);
if ((expected_par.FixedParameters[idx].ModFlags & Parameter.Modifier.RefOutMask) != 0) {
ec.Report.Error (1954, loc, "The best overloaded collection initalizer method `{0}' cannot have 'ref', or `out' modifier",
ec.Report.Error (1954, loc, "The best overloaded collection initalizer method `{0}' cannot have `ref' or `out' modifier",
TypeManager.CSharpSignature (method));
return;
}
@ -4915,7 +4954,12 @@ namespace Mono.CSharp { @@ -4915,7 +4954,12 @@ namespace Mono.CSharp {
p2 = paramType.GetSignatureForErrorIncludingAssemblyName ();
}
ec.Report.Error (1503, loc,
if ((mod & Parameter.Modifier.RefOutMask) != 0) {
p1 = Parameter.GetModifierSignature (a.Modifier) + " " + p1;
p2 = Parameter.GetModifierSignature (a.Modifier) + " " + p2;
}
ec.Report.Error (1503, a.Expr.Location,
"Argument `#{0}' cannot convert `{1}' expression to type `{2}'", index, p1, p2);
}
}
@ -6057,11 +6101,6 @@ namespace Mono.CSharp { @@ -6057,11 +6101,6 @@ namespace Mono.CSharp {
return null;
}
// if the property/indexer returns a value type, and we try to set a field in it
if (right_side == EmptyExpression.LValueMemberAccess || right_side == EmptyExpression.LValueMemberOutAccess) {
Error_ValueAssignment (ec, right_side);
}
if (eclass == ExprClass.Unresolved) {
var expr = OverloadResolve (ec, right_side);
if (expr == null)

6
ICSharpCode.NRefactory.CSharp/Parser/mcs/eval.cs

@ -653,7 +653,11 @@ namespace Mono.CSharp @@ -653,7 +653,11 @@ namespace Mono.CSharp
}
module.CreateContainer ();
source_file.EnableUsingClausesRedefinition ();
// Disable module and source file re-definition checks
module.EnableRedefinition ();
source_file.EnableRedefinition ();
module.Define ();
if (Report.Errors != 0){

41
ICSharpCode.NRefactory.CSharp/Parser/mcs/expression.cs

@ -4630,11 +4630,32 @@ namespace Mono.CSharp @@ -4630,11 +4630,32 @@ namespace Mono.CSharp
//
type = false_type;
if (false_type.BuiltinType != BuiltinTypeSpec.Type.Dynamic && Convert.ImplicitConversion (ec, false_expr, true_type, loc) != null) {
ec.Report.Error (172, true_expr.Location,
"Type of conditional expression cannot be determined as `{0}' and `{1}' convert implicitly to each other",
true_type.GetSignatureForError (), false_type.GetSignatureForError ());
return null;
if (false_type.BuiltinType != BuiltinTypeSpec.Type.Dynamic) {
var conv_false_expr = Convert.ImplicitConversion (ec, false_expr, true_type, loc);
//
// LAMESPEC: There seems to be hardcoded promotition to int type when
// both sides are numeric constants and one side is int constant and
// other side is numeric constant convertible to int.
//
// var res = condition ? (short)1 : 1;
//
// Type of res is int even if according to the spec the conversion is
// ambiguous because 1 literal can be converted to short.
//
if (conv_false_expr != null) {
if (conv_false_expr is IntConstant && conv is Constant) {
type = true_type;
conv_false_expr = null;
} else if (type.BuiltinType == BuiltinTypeSpec.Type.Int && conv_false_expr is Constant) {
conv_false_expr = null;
}
}
if (conv_false_expr != null) {
ec.Report.Error (172, true_expr.Location,
"Type of conditional expression cannot be determined as `{0}' and `{1}' convert implicitly to each other",
true_type.GetSignatureForError (), false_type.GetSignatureForError ());
}
}
true_expr = conv;
@ -7065,7 +7086,7 @@ namespace Mono.CSharp @@ -7065,7 +7086,7 @@ namespace Mono.CSharp
// 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
// things in other cases because we don't know where this will be hoisted
// until top-level block is fully resolved
//
top.AddThisReferenceFromChildrenBlock (block.Explicit);
@ -8555,11 +8576,6 @@ namespace Mono.CSharp @@ -8555,11 +8576,6 @@ namespace Mono.CSharp
if (res == null)
return null;
bool lvalue_instance = rhs != null && type.IsStruct && (Expr is Invocation || Expr is PropertyExpr);
if (lvalue_instance) {
Expr.Error_ValueAssignment (ec, EmptyExpression.LValueMemberAccess);
}
return res.ResolveLValue (ec, rhs);
}
@ -9351,6 +9367,9 @@ namespace Mono.CSharp @@ -9351,6 +9367,9 @@ namespace Mono.CSharp
public UserCast (MethodSpec method, Expression source, Location l)
{
if (source == null)
throw new ArgumentNullException ("source");
this.method = method;
this.source = source;
type = method.ReturnType;

26
ICSharpCode.NRefactory.CSharp/Parser/mcs/flowanalysis.cs

@ -422,9 +422,9 @@ namespace Mono.CSharp @@ -422,9 +422,9 @@ namespace Mono.CSharp
return Parent.CheckRethrow (loc);
}
public virtual bool AddResumePoint (ResumableStatement stmt, out int pc)
public virtual bool AddResumePoint (ResumableStatement stmt, ResumableStatement current, out int pc)
{
return Parent.AddResumePoint (stmt, out pc);
return Parent.AddResumePoint (stmt, current, out pc);
}
// returns true if we crossed an unwind-protected region (try/catch/finally, lock, using, ...)
@ -651,9 +651,9 @@ namespace Mono.CSharp @@ -651,9 +651,9 @@ namespace Mono.CSharp
this.iterator = iterator;
}
public override bool AddResumePoint (ResumableStatement stmt, out int pc)
public override bool AddResumePoint (ResumableStatement stmt, ResumableStatement current, out int pc)
{
pc = iterator.AddResumePoint (stmt);
pc = iterator.AddResumePoint (current);
return false;
}
}
@ -673,7 +673,7 @@ namespace Mono.CSharp @@ -673,7 +673,7 @@ namespace Mono.CSharp
return false;
}
public override bool AddResumePoint (ResumableStatement stmt, out int pc)
public override bool AddResumePoint (ResumableStatement stmt, ResumableStatement current, out int pc)
{
throw new InternalErrorException ("A yield in a non-iterator block");
}
@ -750,16 +750,16 @@ namespace Mono.CSharp @@ -750,16 +750,16 @@ namespace Mono.CSharp
return CurrentUsageVector.Next != null || Parent.CheckRethrow (loc);
}
public override bool AddResumePoint (ResumableStatement stmt, out int pc)
public override bool AddResumePoint (ResumableStatement stmt, ResumableStatement current, out int pc)
{
int errors = Report.Errors;
Parent.AddResumePoint (tc.IsTryCatchFinally ? stmt : tc, out pc);
Parent.AddResumePoint (stmt, tc.IsTryCatchFinally ? current : tc, out pc);
if (errors == Report.Errors) {
if (stmt is AwaitStatement) {
if (CurrentUsageVector.Next != null) {
Report.Error (1985, stmt.loc, "The `await' operator cannot be used in the body of a catch clause");
} else {
this.tc.AddResumePoint (stmt, pc);
this.tc.AddResumePoint (current, pc);
}
} else {
if (CurrentUsageVector.Next == null)
@ -815,9 +815,9 @@ namespace Mono.CSharp @@ -815,9 +815,9 @@ namespace Mono.CSharp
return CurrentUsageVector.Next != null || Parent.CheckRethrow (loc);
}
*/
public override bool AddResumePoint (ResumableStatement stmt, out int pc)
public override bool AddResumePoint (ResumableStatement stmt, ResumableStatement current, out int pc)
{
pc = async_init.AddResumePoint (stmt);
pc = async_init.AddResumePoint (current);
return true;
}
@ -969,13 +969,13 @@ namespace Mono.CSharp @@ -969,13 +969,13 @@ namespace Mono.CSharp
return false;
}
public override bool AddResumePoint (ResumableStatement stmt, out int pc)
public override bool AddResumePoint (ResumableStatement stmt, ResumableStatement current, out int pc)
{
int errors = Report.Errors;
Parent.AddResumePoint (this.stmt, out pc);
Parent.AddResumePoint (stmt, this.stmt, out pc);
if (errors == Report.Errors) {
if (finally_vector == null)
this.stmt.AddResumePoint (stmt, pc);
this.stmt.AddResumePoint (current, pc);
else {
if (stmt is AwaitStatement) {
Report.Error (1984, stmt.loc, "The `await' operator cannot be used in the body of a finally clause");

2
ICSharpCode.NRefactory.CSharp/Parser/mcs/generic.cs

@ -2866,7 +2866,7 @@ namespace Mono.CSharp { @@ -2866,7 +2866,7 @@ namespace Mono.CSharp {
for (int i = 0; i < ga_u.Length; ++i)
score += ExactInference (ga_u [i], ga_v [i]);
return score > 0 ? 1 : 0;
return System.Math.Min (1, score);
}
// If V is one of the unfixed type arguments

7
ICSharpCode.NRefactory.CSharp/Parser/mcs/import.cs

@ -1974,6 +1974,10 @@ namespace Mono.CSharp @@ -1974,6 +1974,10 @@ namespace Mono.CSharp
foreach (var member in all) {
switch (member.MemberType) {
case MemberTypes.Constructor:
if (declaringType.IsInterface)
continue;
goto case MemberTypes.Method;
case MemberTypes.Method:
MethodBase mb = (MethodBase) member;
var attrs = mb.Attributes;
@ -2094,6 +2098,9 @@ namespace Mono.CSharp @@ -2094,6 +2098,9 @@ namespace Mono.CSharp
throw new NotImplementedException (member.ToString ());
}
if (imported.IsStatic && declaringType.IsInterface)
continue;
cache.AddMemberImported (imported);
}
}

2
ICSharpCode.NRefactory.CSharp/Parser/mcs/iterators.cs

@ -60,7 +60,7 @@ namespace Mono.CSharp @@ -60,7 +60,7 @@ namespace Mono.CSharp
machine_initializer = bc.CurrentAnonymousMethod as T;
if (!bc.CurrentBranching.CurrentUsageVector.IsUnreachable)
unwind_protect = bc.CurrentBranching.AddResumePoint (this, out resume_pc);
unwind_protect = bc.CurrentBranching.AddResumePoint (this, this, out resume_pc);
return true;
}

5
ICSharpCode.NRefactory.CSharp/Parser/mcs/module.cs

@ -412,6 +412,11 @@ namespace Mono.CSharp @@ -412,6 +412,11 @@ namespace Mono.CSharp
return base.DefineContainer ();
}
public void EnableRedefinition ()
{
is_defined = false;
}
public override void EmitContainer ()
{
if (OptAttributes != null)

31
ICSharpCode.NRefactory.CSharp/Parser/mcs/namespace.cs

@ -910,13 +910,33 @@ namespace Mono.CSharp { @@ -910,13 +910,33 @@ namespace Mono.CSharp {
}
} else {
names_container.DefinedNames.Add (name, tc);
var tdef = tc.PartialContainer;
if (tdef != null) {
//
// Same name conflict in different namespace containers
//
var conflict = ns.GetAllTypes (name);
if (conflict != null) {
foreach (var e in conflict) {
if (e.Arity == mn.Arity) {
mc = (MemberCore) e.MemberDefinition;
break;
}
}
}
if (mc != null) {
Report.SymbolRelatedToPreviousError (mc);
Report.Error (101, tc.Location, "The namespace `{0}' already contains a definition for `{1}'",
GetSignatureForError (), mn.GetSignatureForError ());
} else {
ns.AddType (Module, tdef.Definition);
}
}
}
base.AddTypeContainer (tc);
var tdef = tc.PartialContainer;
if (tdef != null)
ns.AddType (Module, tdef.Definition);
}
public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
@ -1277,8 +1297,9 @@ namespace Mono.CSharp { @@ -1277,8 +1297,9 @@ namespace Mono.CSharp {
}
}
public void EnableUsingClausesRedefinition ()
public void EnableRedefinition ()
{
is_defined = false;
namespace_using_table = null;
}

2
ICSharpCode.NRefactory.CSharp/Parser/mcs/parameter.cs

@ -418,7 +418,7 @@ namespace Mono.CSharp { @@ -418,7 +418,7 @@ namespace Mono.CSharp {
TypeSpec caller_type;
foreach (var attr in attributes.Attrs) {
var atype = attr.ResolveType ();
var atype = attr.ResolveTypeForComparison ();
if (atype == null)
continue;

2
ICSharpCode.NRefactory.CSharp/Parser/mcs/pending.cs

@ -692,7 +692,7 @@ namespace Mono.CSharp { @@ -692,7 +692,7 @@ namespace Mono.CSharp {
container.GetSignatureForError (), mi.GetSignatureForError (), candidate.GetSignatureForError ());
} else if ((candidate.Modifiers & Modifiers.PUBLIC) == 0) {
Report.Error (737, container.Location,
"`{0}' does not implement interface member `{1}' and the best implementing candidate `{2}' in not public",
"`{0}' does not implement interface member `{1}' and the best implementing candidate `{2}' is not public",
container.GetSignatureForError (), mi.GetSignatureForError (), candidate.GetSignatureForError ());
} else {
Report.Error (738, container.Location,

17
ICSharpCode.NRefactory.CSharp/Parser/mcs/statement.cs

@ -2534,10 +2534,17 @@ namespace Mono.CSharp { @@ -2534,10 +2534,17 @@ namespace Mono.CSharp {
// 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;
for (Block b = Original.Explicit; b != null; b = b.Parent) {
if (b.Parent != null) {
var s = b.Parent.Explicit.AnonymousMethodStorey;
if (s != null) {
storey.HoistedThis = s.HoistedThis;
break;
}
}
if (b.Explicit == b.Explicit.ParametersBlock && b.Explicit.ParametersBlock.StateMachine != null) {
storey.HoistedThis = b.Explicit.ParametersBlock.StateMachine.HoistedThis;
break;
}
}
@ -2835,7 +2842,7 @@ namespace Mono.CSharp { @@ -2835,7 +2842,7 @@ namespace Mono.CSharp {
// Overwrite original for comparison purposes when linking cross references
// between anonymous methods
//
Original = source;
Original = source.Original;
}
#region Properties

150
ICSharpCode.NRefactory.CSharp/Parser/mcs/support.cs

@ -127,156 +127,6 @@ namespace Mono.CSharp { @@ -127,156 +127,6 @@ namespace Mono.CSharp {
return true;
}
}
#if !FULL_AST
/// <summary>
/// This is an arbitrarily seekable StreamReader wrapper.
///
/// It uses a self-tuning buffer to cache the seekable data,
/// but if the seek is too far, it may read the underly
/// stream all over from the beginning.
/// </summary>
public class SeekableStreamReader : IDisposable
{
public const int DefaultReadAheadSize = 2048;
StreamReader reader;
Stream stream;
char[] buffer;
int read_ahead_length; // the length of read buffer
int buffer_start; // in chars
int char_count; // count of filled characters in buffer[]
int pos; // index into buffer[]
public SeekableStreamReader (Stream stream, Encoding encoding, char[] sharedBuffer = null)
{
this.stream = stream;
this.buffer = sharedBuffer;
InitializeStream (DefaultReadAheadSize);
reader = new StreamReader (stream, encoding, true);
}
public void Dispose ()
{
// Needed to release stream reader buffers
reader.Dispose ();
}
void InitializeStream (int read_length_inc)
{
read_ahead_length += read_length_inc;
int required_buffer_size = read_ahead_length * 2;
if (buffer == null || buffer.Length < required_buffer_size)
buffer = new char [required_buffer_size];
stream.Position = 0;
buffer_start = char_count = pos = 0;
}
/// <remarks>
/// This value corresponds to the current position in a stream of characters.
/// The StreamReader hides its manipulation of the underlying byte stream and all
/// character set/decoding issues. Thus, we cannot use this position to guess at
/// the corresponding position in the underlying byte stream even though there is
/// a correlation between them.
/// </remarks>
public int Position {
get {
return buffer_start + pos;
}
set {
//
// If the lookahead was too small, re-read from the beginning. Increase the buffer size while we're at it
// This should never happen until we are parsing some weird source code
//
if (value < buffer_start) {
InitializeStream (read_ahead_length);
//
// Discard buffer data after underlying stream changed position
// Cannot use handy reader.DiscardBufferedData () because it for
// some strange reason resets encoding as well
//
reader = new StreamReader (stream, reader.CurrentEncoding, true);
}
while (value > buffer_start + char_count) {
pos = char_count;
if (!ReadBuffer ())
throw new InternalErrorException ("Seek beyond end of file: " + (buffer_start + char_count - value));
}
pos = value - buffer_start;
}
}
bool ReadBuffer ()
{
int slack = buffer.Length - char_count;
//
// read_ahead_length is only half of the buffer to deal with
// reads ahead and moves back without re-reading whole buffer
//
if (slack <= read_ahead_length) {
//
// shift the buffer to make room for read_ahead_length number of characters
//
int shift = read_ahead_length - slack;
Array.Copy (buffer, shift, buffer, 0, char_count - shift);
// Update all counters
pos -= shift;
char_count -= shift;
buffer_start += shift;
slack += shift;
}
char_count += reader.Read (buffer, char_count, slack);
return pos < char_count;
}
public char GetChar (int position)
{
if (buffer_start <= position && position < buffer.Length)
return buffer[position];
return '\0';
}
public char[] ReadChars (int fromPosition, int toPosition)
{
char[] chars = new char[toPosition - fromPosition];
if (buffer_start <= fromPosition && toPosition <= buffer_start + buffer.Length) {
Array.Copy (buffer, fromPosition - buffer_start, chars, 0, chars.Length);
} else {
throw new NotImplementedException ();
}
return chars;
}
public int Peek ()
{
if ((pos >= char_count) && !ReadBuffer ())
return -1;
return buffer [pos];
}
public int Read ()
{
if ((pos >= char_count) && !ReadBuffer ())
return -1;
return buffer [pos++];
}
}
#endif
public class UnixUtils {
[System.Runtime.InteropServices.DllImport ("libc", EntryPoint="isatty")]
extern static int _isatty (int fd);

1
ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/CodeCompletionBugTests.cs

@ -74,7 +74,6 @@ namespace ICSharpCode.NRefactory.CSharp.CodeCompletion @@ -74,7 +74,6 @@ namespace ICSharpCode.NRefactory.CSharp.CodeCompletion
#region ICompletionData implementation
public void AddOverload (ICompletionData data)
{
throw new NotImplementedException ();
}
public CompletionCategory CompletionCategory {

23
ICSharpCode.NRefactory.Tests/CSharp/Parser/Bugs/ParserBugTests.cs

@ -387,7 +387,7 @@ class Foo @@ -387,7 +387,7 @@ class Foo
public void TestBug5389()
{
string code =
@"class Foo
@"class Foo
{
static Dictionary<Tuple<Type, string>, string> CreatePropertyMap ()
{
@ -410,6 +410,27 @@ class Foo @@ -410,6 +410,27 @@ class Foo
}
Assert.IsTrue(passed);
}
[Test()]
public void TestIncompleteParameter()
{
string code =
@"class Foo
{
void Bar (params System.A) {}
}
";
var unit = SyntaxTree.Parse(code);
var type = unit.Members.First() as TypeDeclaration;
var method = type.Members.First() as MethodDeclaration;
bool passed = method.Parameters.Count == 1;
if (!passed) {
Console.WriteLine("Expected:" + code);
Console.WriteLine("Was:" + unit.GetText());
}
Assert.IsTrue(passed);
}
}
}

Loading…
Cancel
Save