Browse Source

Updated mcs.

pull/32/merge
Mike Krüger 12 years ago
parent
commit
a2b1873c89
  1. 8
      ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs
  2. 3
      ICSharpCode.NRefactory.CSharp/Parser/mcs/argument.cs
  3. 4
      ICSharpCode.NRefactory.CSharp/Parser/mcs/class.cs
  4. 10372
      ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.cs
  5. 138
      ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.jay
  6. 9
      ICSharpCode.NRefactory.CSharp/Parser/mcs/ecore.cs
  7. 80
      ICSharpCode.NRefactory.CSharp/Parser/mcs/location.cs
  8. 2
      ICSharpCode.NRefactory.CSharp/Parser/mcs/parameter.cs

8
ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs

@ -327,6 +327,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -327,6 +327,7 @@ namespace ICSharpCode.NRefactory.CSharp
AttributeSection ConvertAttributeSection (IEnumerable<Mono.CSharp.Attribute> optAttributes)
{
if (optAttributes == null)
return null;
AttributeSection result = new AttributeSection ();
@ -334,7 +335,6 @@ namespace ICSharpCode.NRefactory.CSharp @@ -334,7 +335,6 @@ namespace ICSharpCode.NRefactory.CSharp
int pos = 0;
if (loc != null)
result.AddChild (new CSharpTokenNode (Convert (loc [pos++]), Roles.LBracket), Roles.LBracket);
var first = optAttributes.FirstOrDefault ();
string target = first != null ? first.ExplicitTarget : null;
@ -351,6 +351,9 @@ namespace ICSharpCode.NRefactory.CSharp @@ -351,6 +351,9 @@ namespace ICSharpCode.NRefactory.CSharp
int attributeCount = 0;
foreach (var attr in GetAttributes (optAttributes)) {
result.AddChild (attr, Roles.Attribute);
if (loc != null && pos + 1 < loc.Count)
result.AddChild (new CSharpTokenNode (Convert (loc [pos++]), Roles.Comma), Roles.Comma);
attributeCount++;
}
// Left and right bracket + commas between the attributes
@ -358,6 +361,8 @@ namespace ICSharpCode.NRefactory.CSharp @@ -358,6 +361,8 @@ namespace ICSharpCode.NRefactory.CSharp
// optional comma
if (loc != null && pos < loc.Count - 1 && loc.Count == locCount + 1)
result.AddChild (new CSharpTokenNode (Convert (loc [pos++]), Roles.Comma), Roles.Comma);
foreach (var l in loc)
Console.WriteLine( Convert (l));
if (loc != null && pos < loc.Count)
result.AddChild (new CSharpTokenNode (Convert (loc [pos++]), Roles.RBracket), Roles.RBracket);
return result;
@ -508,7 +513,6 @@ namespace ICSharpCode.NRefactory.CSharp @@ -508,7 +513,6 @@ namespace ICSharpCode.NRefactory.CSharp
var newType = new TypeDeclaration ();
newType.ClassType = ClassType.Class;
AddAttributeSection(newType, c);
var location = LocationsBag.GetMemberLocation(c);
AddModifiers(newType, location);
int curLoc = 0;

3
ICSharpCode.NRefactory.CSharp/Parser/mcs/argument.cs

@ -47,9 +47,6 @@ namespace Mono.CSharp @@ -47,9 +47,6 @@ namespace Mono.CSharp
public Argument (Expression expr)
{
if (expr == null)
throw new ArgumentNullException ();
this.Expr = expr;
}

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

@ -3546,7 +3546,9 @@ namespace Mono.CSharp @@ -3546,7 +3546,9 @@ namespace Mono.CSharp
{
this.Parent = parent;
this.type_expr = type;
ModFlags = ModifiersExtensions.Check (allowed_mod, mod, def_mod, Location, Report);
if (name != MemberName.Null)
ModFlags = ModifiersExtensions.Check (allowed_mod, mod, def_mod, Location, Report);
}
#region Properties

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

File diff suppressed because it is too large Load Diff

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

@ -148,6 +148,7 @@ namespace Mono.CSharp @@ -148,6 +148,7 @@ namespace Mono.CSharp
List<Location> attributeCommas = new List<Location> ();
List<Location> attributeArgumentCommas = new List<Location> ();
List<Location> parameterListCommas = new List<Location> ();
Stack<Location> location_stack;
%}
%token EOF
@ -672,7 +673,7 @@ attribute_sections @@ -672,7 +673,7 @@ attribute_sections
if (locationListStack.Count > 0)
lbag.AddLocation (sect, locationListStack.Pop ());
if (attributeCommas.Count > 0) {
lbag.AppendTo (sect, attributeCommas);
lbag.AddLocation (sect, attributeCommas);
attributeCommas.Clear ();
}
}
@ -694,6 +695,7 @@ attribute_sections @@ -694,6 +695,7 @@ attribute_sections
attribute_section
: OPEN_BRACKET
{
PushLocation (GetLocation ($1));
lexer.parsing_attribute_section = true;
savedOpenLocation = GetLocation ($1);
}
@ -720,21 +722,25 @@ attribute_section_cont @@ -720,21 +722,25 @@ attribute_section_cont
else
$$ = $4;
current_attr_target = null;
lexer.parsing_attribute_section = false;
lbag.InsertLocation ($$, 0, PopLocation ());
if ($5 != null) {
locationListStack.Push (new List<Location>(new [] { savedOpenLocation, savedCloseLocation, GetLocation ($2), GetLocation ($5), GetLocation ($6) }));
lbag.AddLocation ($$, GetLocation ($2), GetLocation ($5), GetLocation ($6));
} else {
locationListStack.Push (new List<Location>(new [] { savedOpenLocation, savedCloseLocation, GetLocation ($2), GetLocation ($6) }));
lbag.AddLocation ($$, GetLocation ($2), GetLocation ($6));
}
current_attr_target = null;
lexer.parsing_attribute_section = false;
}
| attribute_list opt_comma CLOSE_BRACKET
{
$$ = $1;
lbag.InsertLocation ($$, 0, PopLocation ());
if ($2 != null) {
locationListStack.Push (new List<Location>(new [] { savedOpenLocation, GetLocation ($2), GetLocation ($3) }));
lbag.AddLocation ($$, GetLocation($2), GetLocation ($3));
} else {
locationListStack.Push (new List<Location>(new [] { savedOpenLocation, GetLocation ($3) }));
lbag.AddLocation ($$, GetLocation($3));
}
}
| IDENTIFIER error
@ -774,8 +780,10 @@ attribute_list @@ -774,8 +780,10 @@ attribute_list
| attribute_list COMMA attribute
{
var attrs = (List<Attribute>) $1;
attrs.Add ((Attribute) $3);
attributeCommas.Add (GetLocation ($2));
if (attrs != null) {
attrs.Add ((Attribute) $3);
lbag.AddLocation (attrs, GetLocation ($2));
}
$$ = attrs;
}
@ -947,13 +955,14 @@ class_member_declaration @@ -947,13 +955,14 @@ class_member_declaration
| destructor_declaration
| type_declaration
| attributes_without_members
| incomplete_member
| error
{
report.Error (1519, lexer.Location, "Unexpected symbol `{0}' in class, struct, or interface member declaration",
GetSymbolName (yyToken));
$$ = null;
lexer.parsing_generic_declaration = false;
}
}
;
struct_declaration
@ -2075,7 +2084,7 @@ operator_declaration @@ -2075,7 +2084,7 @@ operator_declaration
lbag.AddMember (op, GetModifierLocations (), lbag.GetLocations (decl));
if ($5 == null) { // Semicolon
lbag.AppendTo (op, savedLocation);
lbag.AddLocation (op, savedLocation);
}
}
@ -2615,6 +2624,23 @@ attributes_without_members @@ -2615,6 +2624,23 @@ attributes_without_members
lexer.putback ('}');
}
;
// For full ast try to recover incomplete ambiguous member
// declaration in form on class X { public int }
incomplete_member
: opt_attributes opt_modifiers member_type CLOSE_BRACE
{
report.Error (1519, lexer.Location, "Unexpected symbol `}' in class, struct, or interface member declaration");
lexer.putback ('}');
lexer.parsing_generic_declaration = false;
FullNamedExpression type = (FullNamedExpression) $3;
current_field = new Field (current_type, type, (Modifiers) $2, MemberName.Null, (Attributes) $1);
current_type.AddField (current_field);
$$ = current_field;
}
;
enum_declaration
: opt_attributes
@ -3103,7 +3129,7 @@ type_list @@ -3103,7 +3129,7 @@ type_list
{
var types = (List<FullNamedExpression>) $1;
types.Add ((FullNamedExpression) $3);
lbag.AppendTo (types, GetLocation ($2));
lbag.AddLocation (types, GetLocation ($2));
$$ = types;
}
;
@ -3339,7 +3365,7 @@ member_initializer_list @@ -3339,7 +3365,7 @@ member_initializer_list
{
var a = (List<Expression>)$1;
a.Add ((Expression) $3);
lbag.AppendTo (a, GetLocation ($2));
lbag.AddLocation (a, GetLocation ($2));
$$ = a;
}
| member_initializer_list error {
@ -3413,7 +3439,7 @@ argument_list @@ -3413,7 +3439,7 @@ argument_list
Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
list.Add ((Argument) $3);
lbag.AppendTo (list, GetLocation ($2));
lbag.AddLocation (list, GetLocation ($2));
$$ = list;
}
| argument_list COMMA named_argument
@ -3428,7 +3454,7 @@ argument_list @@ -3428,7 +3454,7 @@ argument_list
}
list.Add (a);
lbag.AppendTo (list, GetLocation ($2));
lbag.AddLocation (list, GetLocation ($2));
$$ = list;
}
| argument_list COMMA error
@ -3504,23 +3530,19 @@ element_access @@ -3504,23 +3530,19 @@ element_access
;
expression_list
: expression
: expression_or_error
{
var list = new List<Expression> (4);
list.Add ((Expression) $1);
$$ = list;
}
| expression_list COMMA expression
| expression_list COMMA expression_or_error
{
var list = (List<Expression>) $1;
list.Add ((Expression) $3);
lbag.AppendTo (list, GetLocation ($2));
lbag.AddLocation (list, GetLocation ($2));
$$ = list;
}
| expression_list error {
Error_SyntaxError (yyToken);
$$ = $1;
}
;
expression_list_arguments
@ -3537,7 +3559,7 @@ expression_list_arguments @@ -3537,7 +3559,7 @@ expression_list_arguments
Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
args.Add ((Argument) $3);
lbag.AppendTo (args, GetLocation ($2));
lbag.AddLocation (args, GetLocation ($2));
$$ = args;
}
;
@ -3690,7 +3712,7 @@ anonymous_type_parameters @@ -3690,7 +3712,7 @@ anonymous_type_parameters
{
var a = (List<AnonymousTypeParameter>) $1;
a.Add ((AnonymousTypeParameter) $3);
lbag.AppendTo (a, GetLocation ($2));
lbag.AddLocation (a, GetLocation ($2));
$$ = a;
}
@ -3803,7 +3825,7 @@ variable_initializer_list @@ -3803,7 +3825,7 @@ variable_initializer_list
{
var list = (List<Expression>) $1;
list.Add ((Expression) $3);
lbag.AppendTo (list, GetLocation ($2));
lbag.AddLocation (list, GetLocation ($2));
$$ = list;
}
;
@ -4453,6 +4475,14 @@ conditional_expression @@ -4453,6 +4475,14 @@ conditional_expression
$$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
lbag.AddLocation ($$, GetLocation ($4));
}
| null_coalescing_expression INTERR expression COLON CLOSE_BRACE
{
Error_SyntaxError (Token.CLOSE_BRACE);
$$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
lbag.AddLocation ($$, GetLocation ($4));
lexer.putback ('}');
}
;
assignment_expression
@ -4980,7 +5010,7 @@ type_parameter_constraints @@ -4980,7 +5010,7 @@ type_parameter_constraints
}
constraints.Add ((FullNamedExpression) $3);
lbag.AppendTo (constraints, GetLocation ($2));
lbag.AddLocation (constraints, GetLocation ($2));
$$ = constraints;
}
;
@ -5353,7 +5383,10 @@ block_variable_declaration @@ -5353,7 +5383,10 @@ block_variable_declaration
{
$$ = current_variable;
current_variable = null;
lbag.AppendTo ($$, GetLocation ($6));
if ($4 != null)
lbag.AddLocation ($$, PopLocation (), GetLocation ($6));
else
lbag.AddLocation ($$, GetLocation ($6));
}
| CONST variable_type identifier_inside_body
{
@ -5389,21 +5422,8 @@ opt_local_variable_initializer @@ -5389,21 +5422,8 @@ opt_local_variable_initializer
| ASSIGN block_variable_initializer
{
current_variable.Initializer = (Expression) $2;
lbag.AppendTo (current_variable, GetLocation ($1));
}
| ASSIGN error
{
if (yyToken == Token.OPEN_BRACKET_EXPR) {
report.Error (650, lexer.Location,
"Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. To declare a fixed size buffer field, use the fixed keyword before the field type");
current_variable.Initializer = ErrorExpression.Create (650, lexer.Location,
"Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. To declare a fixed size buffer field, use the fixed keyword before the field type");
} else {
Error_SyntaxError (yyToken);
current_variable.Initializer = ErrorExpression.Create (0, lexer.Location,
"Syntax error");
}
lbag.AppendTo (current_variable, GetLocation ($1));
PushLocation (GetLocation ($1));
$$ = current_variable;
}
| error
{
@ -5733,7 +5753,7 @@ for_statement_cont @@ -5733,7 +5753,7 @@ for_statement_cont
{
For f = (For) $0;
f.Initializer = (Statement) $1;
lbag.AppendTo (f, GetLocation ($2));
lbag.AddLocation (f, GetLocation ($2));
$$ = f;
}
for_statement_condition
@ -5744,7 +5764,7 @@ for_statement_cont @@ -5744,7 +5764,7 @@ for_statement_cont
report.Error (1525, GetLocation ($2), "Unexpected symbol ')', expected ';'");
For f = (For) $0;
f.Initializer = (Statement) $1;
lbag.AppendTo (f, GetLocation ($2));
lbag.AddLocation (f, GetLocation ($2));
$$ = end_block (GetLocation ($2));
}
;
@ -5754,7 +5774,7 @@ for_statement_condition @@ -5754,7 +5774,7 @@ for_statement_condition
{
For f = (For) $0;
f.Condition = (BooleanExpression) $1;
lbag.AppendTo (f, GetLocation ($2));
lbag.AddLocation (f, GetLocation ($2));
$$ = f;
}
for_statement_end
@ -5766,7 +5786,7 @@ for_statement_condition @@ -5766,7 +5786,7 @@ for_statement_condition
report.Error (1525, GetLocation ($2), "Unexpected symbol ')', expected ';'");
For f = (For) $0;
f.Condition = (BooleanExpression) $1;
lbag.AppendTo (f, GetLocation ($2));
lbag.AddLocation (f, GetLocation ($2));
$$ = end_block (GetLocation ($2));
}
;
@ -5782,7 +5802,7 @@ for_statement_end @@ -5782,7 +5802,7 @@ for_statement_end
Warning_EmptyStatement (GetLocation ($3));
f.Statement = (Statement) $3;
lbag.AppendTo (f, GetLocation ($2));
lbag.AddLocation (f, GetLocation ($2));
$$ = end_block (GetLocation ($2));
}
@ -5809,6 +5829,9 @@ for_initializer @@ -5809,6 +5829,9 @@ for_initializer
opt_local_variable_initializer opt_variable_declarators
{
$$ = current_variable;
if ($4 != null)
lbag.AddLocation (current_variable, PopLocation ());
current_variable = null;
}
| statement_expression_list
@ -5838,7 +5861,7 @@ statement_expression_list @@ -5838,7 +5861,7 @@ statement_expression_list
lbag.AddStatement (sl, GetLocation ($2));
} else {
sl.Add ((Statement) $3);
lbag.AppendTo (sl, GetLocation ($2));
lbag.AddLocation (sl, GetLocation ($2));
}
@ -6295,7 +6318,7 @@ using_or_fixed_variable_initializer @@ -6295,7 +6318,7 @@ using_or_fixed_variable_initializer
| ASSIGN variable_initializer
{
current_variable.Initializer = (Expression) $2;
lbag.AppendTo (current_variable, GetLocation ($1));
lbag.AddLocation (current_variable, GetLocation ($1));
$$ = current_variable;
}
;
@ -7138,6 +7161,23 @@ List<Tuple<Modifiers, Location>> GetModifierLocations () @@ -7138,6 +7161,23 @@ List<Tuple<Modifiers, Location>> GetModifierLocations ()
return result;
}
[System.Diagnostics.Conditional ("FULL_AST")]
void PushLocation (Location loc)
{
if (location_stack == null)
location_stack = new Stack<Location> ();
location_stack.Push (loc);
}
Location PopLocation ()
{
if (location_stack == null)
return Location.Null;
return location_stack.Pop ();
}
string CheckAttributeTarget (string a, Location l)
{
switch (a) {

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

@ -4560,17 +4560,18 @@ namespace Mono.CSharp { @@ -4560,17 +4560,18 @@ namespace Mono.CSharp {
// It can be applicable in expanded form (when not doing exact match like for delegates)
//
if (score != 0 && (p_mod & Parameter.Modifier.PARAMS) != 0 && (restrictions & Restrictions.CovariantDelegate) == 0) {
if (!params_expanded_form)
if (!params_expanded_form) {
pt = ((ElementTypeSpec) pt).Element;
}
if (score > 0)
score = IsArgumentCompatible (ec, a, Parameter.Modifier.NONE, pt);
if (score == 0) {
params_expanded_form = true;
} else if (score < 0) {
if (score < 0) {
params_expanded_form = true;
dynamicArgument = true;
} else if (score == 0 || arg_count > pd.Count) {
params_expanded_form = true;
}
}

80
ICSharpCode.NRefactory.CSharp/Parser/mcs/location.cs

@ -597,6 +597,31 @@ if (checkpoints.Length <= CheckpointIndex) throw new Exception (String.Format (" @@ -597,6 +597,31 @@ if (checkpoints.Length <= CheckpointIndex) throw new Exception (String.Format ("
{
Modifiers = mods;
locations = locs != null ? new List<Location> (locs) : null;
/*
public readonly IList<Tuple<Modifiers, Location>> Modifiers;
List<Location> locations;
public MemberLocations (IList<Tuple<Modifiers, Location>> mods)
{
Modifiers = mods;
}
public MemberLocations (IList<Tuple<Modifiers, Location>> mods, Location loc)
: this (mods)
{
AddLocations (loc);
}
public MemberLocations (IList<Tuple<Modifiers, Location>> mods, Location[] locs)
: this (mods)
{
AddLocations (locs);
}
public MemberLocations (IList<Tuple<Modifiers, Location>> mods, List<Location> locs)
: this (mods)
{
locations = locs;*/
}
#region Properties
@ -615,6 +640,15 @@ if (checkpoints.Length <= CheckpointIndex) throw new Exception (String.Format (" @@ -615,6 +640,15 @@ if (checkpoints.Length <= CheckpointIndex) throw new Exception (String.Format ("
#endregion
public void AddLocations (Location loc)
{
if (locations == null) {
locations = new List<Location> ();
}
locations.Add (loc);
}
public void AddLocations (params Location[] additional)
{
@ -627,7 +661,7 @@ if (checkpoints.Length <= CheckpointIndex) throw new Exception (String.Format (" @@ -627,7 +661,7 @@ if (checkpoints.Length <= CheckpointIndex) throw new Exception (String.Format ("
if (additional == null)
return;
if (locations == null) {
locations = new List<Location>(additional);
locations = new List<Location> (additional);
} else {
locations.AddRange (additional);
}
@ -639,7 +673,7 @@ if (checkpoints.Length <= CheckpointIndex) throw new Exception (String.Format (" @@ -639,7 +673,7 @@ if (checkpoints.Length <= CheckpointIndex) throw new Exception (String.Format ("
private set;
}
Dictionary<object, List<Location>> simple_locs = new Dictionary<object, List<Location>> (ReferenceEquality<object>.Default);
Dictionary<object, List<Location>> simple_locs = new Dictionary<object, List<Location>> (ReferenceEquality<object>.Default);
Dictionary<MemberCore, MemberLocations> member_locs = new Dictionary<MemberCore, MemberLocations> (ReferenceEquality<MemberCore>.Default);
[Conditional ("FULL_AST")]
@ -653,7 +687,24 @@ if (checkpoints.Length <= CheckpointIndex) throw new Exception (String.Format (" @@ -653,7 +687,24 @@ if (checkpoints.Length <= CheckpointIndex) throw new Exception (String.Format ("
{
if (element == null || locations == null)
return;
simple_locs.Add (element, new List<Location> (locations));
List<Location> found;
if (!simple_locs.TryGetValue (element, out found)) {
simple_locs.Add (element, new List<Location> (locations));
return;
}
found.AddRange(locations);
}
[Conditional ("FULL_AST")]
public void InsertLocation (object element, int index, Location location)
{
List<Location> found;
if (!simple_locs.TryGetValue (element, out found)) {
found = new List<Location> ();
simple_locs.Add (element, found);
}
found.Insert (index, location);
}
[Conditional ("FULL_AST")]
@ -681,6 +732,7 @@ if (checkpoints.Length <= CheckpointIndex) throw new Exception (String.Format (" @@ -681,6 +732,7 @@ if (checkpoints.Length <= CheckpointIndex) throw new Exception (String.Format ("
}
member_locs.Add (member, new MemberLocations (modLocations, locations));
}
[Conditional ("FULL_AST")]
public void AddMember (MemberCore member, IList<Tuple<Modifiers, Location>> modLocations, IEnumerable<Location> locations)
{
@ -697,26 +749,6 @@ if (checkpoints.Length <= CheckpointIndex) throw new Exception (String.Format (" @@ -697,26 +749,6 @@ if (checkpoints.Length <= CheckpointIndex) throw new Exception (String.Format ("
member_locs.Add (member, new MemberLocations (modLocations, locations));
}
[Conditional ("FULL_AST")]
public void AppendTo (object existing, params Location[] locations)
{
AppendTo (existing, (IEnumerable<Location>)locations);
}
[Conditional ("FULL_AST")]
public void AppendTo (object existing, IEnumerable<Location> locations)
{
if (existing == null)
return;
List<Location> locs;
if (simple_locs.TryGetValue (existing, out locs)) {
simple_locs [existing].AddRange (locations);
return;
}
AddLocation (existing, locations);
}
[Conditional ("FULL_AST")]
public void AppendToMember (MemberCore existing, params Location[] locations)
{
@ -741,7 +773,7 @@ if (checkpoints.Length <= CheckpointIndex) throw new Exception (String.Format (" @@ -741,7 +773,7 @@ if (checkpoints.Length <= CheckpointIndex) throw new Exception (String.Format ("
{
if (element == null)
return null;
List<Location > found;
List<Location> found;
simple_locs.TryGetValue (element, out found);
return found;
}

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

@ -993,7 +993,7 @@ namespace Mono.CSharp { @@ -993,7 +993,7 @@ namespace Mono.CSharp {
if (FixedParameters [pos].HasExtensionMethodModifier)
return "this " + type;
Parameter.Modifier mod = FixedParameters [pos].ModFlags;
var mod = FixedParameters[pos].ModFlags & Parameter.Modifier.ModifierMask;
if (mod == 0)
return type;

Loading…
Cancel
Save