Browse Source

Updated mcs.

newNRvisualizers
Mike Krüger 14 years ago
parent
commit
a8cd94e9e6
  1. 131
      ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs
  2. 79
      ICSharpCode.NRefactory.CSharp/Parser/mcs/anonymous.cs
  3. 11
      ICSharpCode.NRefactory.CSharp/Parser/mcs/assembly.cs
  4. 13
      ICSharpCode.NRefactory.CSharp/Parser/mcs/assign.cs
  5. 6
      ICSharpCode.NRefactory.CSharp/Parser/mcs/async.cs
  6. 103
      ICSharpCode.NRefactory.CSharp/Parser/mcs/attribute.cs
  7. 186
      ICSharpCode.NRefactory.CSharp/Parser/mcs/class.cs
  8. 6
      ICSharpCode.NRefactory.CSharp/Parser/mcs/codegen.cs
  9. 4
      ICSharpCode.NRefactory.CSharp/Parser/mcs/context.cs
  10. 9400
      ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.cs
  11. 349
      ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.jay
  12. 2
      ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-tokenizer.cs
  13. 259
      ICSharpCode.NRefactory.CSharp/Parser/mcs/decl.cs
  14. 9
      ICSharpCode.NRefactory.CSharp/Parser/mcs/delegate.cs
  15. 12
      ICSharpCode.NRefactory.CSharp/Parser/mcs/doc.cs
  16. 2
      ICSharpCode.NRefactory.CSharp/Parser/mcs/driver.cs
  17. 10
      ICSharpCode.NRefactory.CSharp/Parser/mcs/dynamic.cs
  18. 17
      ICSharpCode.NRefactory.CSharp/Parser/mcs/ecore.cs
  19. 14
      ICSharpCode.NRefactory.CSharp/Parser/mcs/eval.cs
  20. 277
      ICSharpCode.NRefactory.CSharp/Parser/mcs/expression.cs
  21. 220
      ICSharpCode.NRefactory.CSharp/Parser/mcs/generic.cs
  22. 32
      ICSharpCode.NRefactory.CSharp/Parser/mcs/iterators.cs
  23. 7
      ICSharpCode.NRefactory.CSharp/Parser/mcs/lambda.cs
  24. 26
      ICSharpCode.NRefactory.CSharp/Parser/mcs/linq.cs
  25. 70
      ICSharpCode.NRefactory.CSharp/Parser/mcs/literal.cs
  26. 12
      ICSharpCode.NRefactory.CSharp/Parser/mcs/location.cs
  27. 72
      ICSharpCode.NRefactory.CSharp/Parser/mcs/method.cs
  28. 588
      ICSharpCode.NRefactory.CSharp/Parser/mcs/namespace.cs
  29. 20
      ICSharpCode.NRefactory.CSharp/Parser/mcs/nullable.cs
  30. 19
      ICSharpCode.NRefactory.CSharp/Parser/mcs/parameter.cs
  31. 4
      ICSharpCode.NRefactory.CSharp/Parser/mcs/pending.cs
  32. 97
      ICSharpCode.NRefactory.CSharp/Parser/mcs/property.cs
  33. 14
      ICSharpCode.NRefactory.CSharp/Parser/mcs/reflection.cs
  34. 16
      ICSharpCode.NRefactory.CSharp/Parser/mcs/roottypes.cs
  35. 215
      ICSharpCode.NRefactory.CSharp/Parser/mcs/statement.cs
  36. 3
      ICSharpCode.NRefactory.CSharp/Parser/mcs/support.cs

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

@ -87,6 +87,13 @@ namespace ICSharpCode.NRefactory.CSharp
result.AddChild (new CSharpTokenNode (Convert (loc [loc.Count - 1]), 1), AstType.Roles.RChevron); result.AddChild (new CSharpTokenNode (Convert (loc [loc.Count - 1]), 1), AstType.Roles.RChevron);
} }
AstType ConvertToType (TypeParameter spec)
{
AstType result;
result = new SimpleType () { IdentifierToken = Identifier.Create (spec.Name, Convert (spec.Location)) };
return result;
}
AstType ConvertToType (MemberName memberName) AstType ConvertToType (MemberName memberName)
{ {
AstType result; AstType result;
@ -100,15 +107,15 @@ namespace ICSharpCode.NRefactory.CSharp
} else { } else {
result = new SimpleType () { IdentifierToken = Identifier.Create (memberName.Name, Convert (memberName.Location)) }; result = new SimpleType () { IdentifierToken = Identifier.Create (memberName.Name, Convert (memberName.Location)) };
} }
if (memberName.TypeArguments != null && !memberName.TypeArguments.IsEmpty) { if (memberName.TypeParameters != null) {
var chevronLocs = LocationsBag.GetLocations (memberName.TypeArguments); var chevronLocs = LocationsBag.GetLocations (memberName.TypeParameters);
if (chevronLocs != null) if (chevronLocs != null)
result.AddChild (new CSharpTokenNode (Convert (chevronLocs[chevronLocs.Count - 2]), 1), InvocationExpression.Roles.LChevron); result.AddChild (new CSharpTokenNode (Convert (chevronLocs[chevronLocs.Count - 2]), 1), InvocationExpression.Roles.LChevron);
int i = 0; for (int i = 0; i < memberName.TypeParameters.Count; i++) {
foreach (var arg in memberName.TypeArguments.Args) { var param = memberName.TypeParameters[i];
result.AddChild (ConvertToType (arg), AstType.Roles.TypeArgument); result.AddChild (new SimpleType (Identifier.Create (param.Name, Convert (param.Location))), AstType.Roles.TypeArgument);
if (chevronLocs != null && i < chevronLocs.Count - 2) if (chevronLocs != null && i < chevronLocs.Count - 2)
result.AddChild (new CSharpTokenNode (Convert (chevronLocs [i++]), 1), InvocationExpression.Roles.Comma); result.AddChild (new CSharpTokenNode (Convert (chevronLocs [i]), 1), InvocationExpression.Roles.Comma);
} }
if (chevronLocs != null) if (chevronLocs != null)
result.AddChild (new CSharpTokenNode (Convert (chevronLocs[chevronLocs.Count - 1]), 1), InvocationExpression.Roles.RChevron); result.AddChild (new CSharpTokenNode (Convert (chevronLocs[chevronLocs.Count - 1]), 1), InvocationExpression.Roles.RChevron);
@ -208,8 +215,8 @@ namespace ICSharpCode.NRefactory.CSharp
if (loc != null) if (loc != null)
result.AddChild (new CSharpTokenNode (Convert (loc [pos++]), 1), AttributeSection.Roles.LPar); result.AddChild (new CSharpTokenNode (Convert (loc [pos++]), 1), AttributeSection.Roles.LPar);
if (attr.PosArguments != null) { if (attr.PositionalArguments != null) {
foreach (var arg in attr.PosArguments) { foreach (var arg in attr.PositionalArguments) {
var na = arg as NamedArgument; var na = arg as NamedArgument;
if (na != null) { if (na != null) {
var newArg = new NamedArgumentExpression (); var newArg = new NamedArgumentExpression ();
@ -327,7 +334,7 @@ namespace ICSharpCode.NRefactory.CSharp
{ {
UsingDeclaration ud = new UsingDeclaration (); UsingDeclaration ud = new UsingDeclaration ();
ud.AddChild (new CSharpTokenNode (Convert (u.UsingLocation), "using".Length), UsingDeclaration.Roles.Keyword); ud.AddChild (new CSharpTokenNode (Convert (u.UsingLocation), "using".Length), UsingDeclaration.Roles.Keyword);
ud.AddChild (ConvertImport (u.NSpace), UsingDeclaration.ImportRole); ud.AddChild (ConvertToType (u.NSpace), UsingDeclaration.ImportRole);
ud.AddChild (new CSharpTokenNode (Convert (u.SemicolonLocation), 1), UsingDeclaration.Roles.Semicolon); ud.AddChild (new CSharpTokenNode (Convert (u.SemicolonLocation), 1), UsingDeclaration.Roles.Semicolon);
AddToNamespace (ud); AddToNamespace (ud);
} }
@ -338,7 +345,7 @@ namespace ICSharpCode.NRefactory.CSharp
ud.AddChild (new CSharpTokenNode (Convert (u.UsingLocation), "using".Length), UsingAliasDeclaration.Roles.Keyword); ud.AddChild (new CSharpTokenNode (Convert (u.UsingLocation), "using".Length), UsingAliasDeclaration.Roles.Keyword);
ud.AddChild (Identifier.Create (u.Identifier.Value, Convert (u.Identifier.Location)), UsingAliasDeclaration.AliasRole); ud.AddChild (Identifier.Create (u.Identifier.Value, Convert (u.Identifier.Location)), UsingAliasDeclaration.AliasRole);
ud.AddChild (new CSharpTokenNode (Convert (u.AssignLocation), 1), UsingAliasDeclaration.Roles.Assign); ud.AddChild (new CSharpTokenNode (Convert (u.AssignLocation), 1), UsingAliasDeclaration.Roles.Assign);
ud.AddChild (ConvertImport (u.Nspace), UsingAliasDeclaration.ImportRole); ud.AddChild (ConvertToType (u.Nspace), UsingAliasDeclaration.ImportRole);
ud.AddChild (new CSharpTokenNode (Convert (u.SemicolonLocation), 1), UsingAliasDeclaration.Roles.Semicolon); ud.AddChild (new CSharpTokenNode (Convert (u.SemicolonLocation), 1), UsingAliasDeclaration.Roles.Semicolon);
AddToNamespace (ud); AddToNamespace (ud);
} }
@ -358,19 +365,19 @@ namespace ICSharpCode.NRefactory.CSharp
if (memberName.Left != null) { if (memberName.Left != null) {
// left.name // left.name
var t = new MemberType(); var t = new MemberType();
t.IsDoubleColon = memberName.IsDoubleColon; // t.IsDoubleColon = memberName.IsDoubleColon;
t.AddChild (ConvertImport (memberName.Left), MemberType.TargetRole); t.AddChild (ConvertImport (memberName.Left), MemberType.TargetRole);
if (!memberName.DotLocation.IsNull) if (!memberName.DotLocation.IsNull)
t.AddChild (new CSharpTokenNode (Convert (memberName.DotLocation), 1), MemberType.Roles.Dot); t.AddChild (new CSharpTokenNode (Convert (memberName.DotLocation), 1), MemberType.Roles.Dot);
t.AddChild (Identifier.Create (memberName.Name, Convert(memberName.Location)), MemberType.Roles.Identifier); t.AddChild (Identifier.Create (memberName.Name, Convert(memberName.Location)), MemberType.Roles.Identifier);
AddTypeArguments (t, memberName.TypeArguments); AddTypeArguments (t, memberName);
return t; return t;
} else { } else {
SimpleType t = new SimpleType(); SimpleType t = new SimpleType();
t.AddChild (Identifier.Create (memberName.Name, Convert(memberName.Location)), SimpleType.Roles.Identifier); t.AddChild (Identifier.Create (memberName.Name, Convert(memberName.Location)), SimpleType.Roles.Identifier);
AddTypeArguments (t, memberName.TypeArguments); AddTypeArguments (t, memberName);
return t; return t;
} }
} }
@ -396,9 +403,7 @@ namespace ICSharpCode.NRefactory.CSharp
newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), "class".Length), TypeDeclaration.Roles.Keyword); newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), "class".Length), TypeDeclaration.Roles.Keyword);
newType.AddChild (Identifier.Create (c.MemberName.Name, Convert (c.MemberName.Location)), AstNode.Roles.Identifier); newType.AddChild (Identifier.Create (c.MemberName.Name, Convert (c.MemberName.Location)), AstNode.Roles.Identifier);
if (c.MemberName.TypeArguments != null) { AddTypeParameters (newType, c.MemberName);
AddTypeParameters (newType, c.MemberName.TypeArguments);
}
if (c.TypeBaseExpressions != null) { if (c.TypeBaseExpressions != null) {
if (location != null && curLoc < location.Count) if (location != null && curLoc < location.Count)
@ -445,9 +450,7 @@ namespace ICSharpCode.NRefactory.CSharp
if (location != null) if (location != null)
newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), "struct".Length), TypeDeclaration.Roles.Keyword); newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), "struct".Length), TypeDeclaration.Roles.Keyword);
newType.AddChild (Identifier.Create (s.MemberName.Name, Convert (s.MemberName.Location)), AstNode.Roles.Identifier); newType.AddChild (Identifier.Create (s.MemberName.Name, Convert (s.MemberName.Location)), AstNode.Roles.Identifier);
if (s.MemberName.TypeArguments != null) { AddTypeParameters (newType, s.MemberName);
AddTypeParameters (newType, s.MemberName.TypeArguments);
}
if (s.TypeBaseExpressions != null) { if (s.TypeBaseExpressions != null) {
if (location != null && curLoc < location.Count) if (location != null && curLoc < location.Count)
@ -492,9 +495,7 @@ namespace ICSharpCode.NRefactory.CSharp
if (location != null) if (location != null)
newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), "interface".Length), TypeDeclaration.Roles.Keyword); newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), "interface".Length), TypeDeclaration.Roles.Keyword);
newType.AddChild (Identifier.Create (i.MemberName.Name, Convert (i.MemberName.Location)), AstNode.Roles.Identifier); newType.AddChild (Identifier.Create (i.MemberName.Name, Convert (i.MemberName.Location)), AstNode.Roles.Identifier);
if (i.MemberName.TypeArguments != null) { AddTypeParameters (newType, i.MemberName);
AddTypeParameters (newType, i.MemberName.TypeArguments);
}
if (i.TypeBaseExpressions != null) { if (i.TypeBaseExpressions != null) {
if (location != null && curLoc < location.Count) if (location != null && curLoc < location.Count)
@ -538,9 +539,8 @@ namespace ICSharpCode.NRefactory.CSharp
newDelegate.AddChild (new CSharpTokenNode (Convert (location[0]), "delegate".Length), TypeDeclaration.Roles.Keyword); newDelegate.AddChild (new CSharpTokenNode (Convert (location[0]), "delegate".Length), TypeDeclaration.Roles.Keyword);
newDelegate.AddChild (ConvertToType (d.ReturnType), AstNode.Roles.Type); newDelegate.AddChild (ConvertToType (d.ReturnType), AstNode.Roles.Type);
newDelegate.AddChild (Identifier.Create (d.MemberName.Name, Convert (d.MemberName.Location)), AstNode.Roles.Identifier); newDelegate.AddChild (Identifier.Create (d.MemberName.Name, Convert (d.MemberName.Location)), AstNode.Roles.Identifier);
if (d.MemberName.TypeArguments != null) { AddTypeParameters (newDelegate, d.MemberName);
AddTypeParameters (newDelegate, d.MemberName.TypeArguments);
}
if (location != null) if (location != null)
newDelegate.AddChild (new CSharpTokenNode (Convert (location[1]), 1), DelegateDeclaration.Roles.LPar); newDelegate.AddChild (new CSharpTokenNode (Convert (location[1]), 1), DelegateDeclaration.Roles.LPar);
AddParameter (newDelegate, d.Parameters); AddParameter (newDelegate, d.Parameters);
@ -909,9 +909,7 @@ namespace ICSharpCode.NRefactory.CSharp
} }
newMethod.AddChild (Identifier.Create (m.MethodName.Name, Convert (m.Location)), AstNode.Roles.Identifier); newMethod.AddChild (Identifier.Create (m.MethodName.Name, Convert (m.Location)), AstNode.Roles.Identifier);
if (m.MemberName.TypeArguments != null) { AddTypeParameters (newMethod, m.MemberName);
AddTypeParameters (newMethod, m.MemberName.TypeArguments);
}
if (location != null) if (location != null)
newMethod.AddChild (new CSharpTokenNode (Convert (location[0]), 1), MethodDeclaration.Roles.LPar); newMethod.AddChild (new CSharpTokenNode (Convert (location[0]), 1), MethodDeclaration.Roles.LPar);
@ -1465,7 +1463,7 @@ namespace ICSharpCode.NRefactory.CSharp
public override object Visit (StatementErrorExpression statementErrorExpression) public override object Visit (StatementErrorExpression statementErrorExpression)
{ {
var result = new ExpressionStatement (); var result = new ExpressionStatement ();
var expr = statementErrorExpression.Expression.Accept (this) as Expression; var expr = statementErrorExpression.Expr.Accept (this) as Expression;
if (expr != null) if (expr != null)
result.AddChild ((Expression)expr, ExpressionStatement.Roles.Expression); result.AddChild ((Expression)expr, ExpressionStatement.Roles.Expression);
return result; return result;
@ -1849,13 +1847,13 @@ namespace ICSharpCode.NRefactory.CSharp
result.AddChild (new CSharpTokenNode (Convert (tryCatchStatement.loc), "try".Length), TryCatchStatement.TryKeywordRole); result.AddChild (new CSharpTokenNode (Convert (tryCatchStatement.loc), "try".Length), TryCatchStatement.TryKeywordRole);
if (tryCatchStatement.Block != null) if (tryCatchStatement.Block != null)
result.AddChild ((BlockStatement)tryCatchStatement.Block.Accept (this), TryCatchStatement.TryBlockRole); result.AddChild ((BlockStatement)tryCatchStatement.Block.Accept (this), TryCatchStatement.TryBlockRole);
if (tryCatchStatement.Specific != null) { if (tryCatchStatement.Clauses != null) {
foreach (Catch ctch in tryCatchStatement.Specific) { foreach (var ctch in tryCatchStatement.Clauses) {
result.AddChild (ConvertCatch (ctch), TryCatchStatement.CatchClauseRole); result.AddChild (ConvertCatch (ctch), TryCatchStatement.CatchClauseRole);
} }
} }
if (tryCatchStatement.General != null) // if (tryCatchStatement.General != null)
result.AddChild (ConvertCatch (tryCatchStatement.General), TryCatchStatement.CatchClauseRole); // result.AddChild (ConvertCatch (tryCatchStatement.General), TryCatchStatement.CatchClauseRole);
return result; return result;
} }
@ -1868,8 +1866,8 @@ namespace ICSharpCode.NRefactory.CSharp
result.AddChild (new CSharpTokenNode (Convert (usingStatement.loc), "using".Length), UsingStatement.Roles.Keyword); result.AddChild (new CSharpTokenNode (Convert (usingStatement.loc), "using".Length), UsingStatement.Roles.Keyword);
if (location != null) if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location [0]), 1), UsingStatement.Roles.LPar); result.AddChild (new CSharpTokenNode (Convert (location [0]), 1), UsingStatement.Roles.LPar);
if (usingStatement.Expression != null) if (usingStatement.Expr != null)
result.AddChild ((AstNode)usingStatement.Expression.Accept (this), UsingStatement.ResourceAcquisitionRole); result.AddChild ((AstNode)usingStatement.Expr.Accept (this), UsingStatement.ResourceAcquisitionRole);
if (location != null) if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location [1]), 1), UsingStatement.Roles.RPar); result.AddChild (new CSharpTokenNode (Convert (location [1]), 1), UsingStatement.Roles.RPar);
@ -1889,8 +1887,9 @@ namespace ICSharpCode.NRefactory.CSharp
if (location != null) if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location [0]), 1), ForeachStatement.Roles.LPar); result.AddChild (new CSharpTokenNode (Convert (location [0]), 1), ForeachStatement.Roles.LPar);
if (foreachStatement.TypeExpr != null) if (foreachStatement.TypeExpression != null)
result.AddChild (ConvertToType (foreachStatement.TypeExpr), ForeachStatement.Roles.Type); result.AddChild (ConvertToType (foreachStatement.TypeExpression), ForeachStatement.Roles.Type);
if (foreachStatement.Variable != null) if (foreachStatement.Variable != null)
result.AddChild (Identifier.Create (foreachStatement.Variable.Name, Convert (foreachStatement.Variable.Location)), ForeachStatement.Roles.Identifier); result.AddChild (Identifier.Create (foreachStatement.Variable.Name, Convert (foreachStatement.Variable.Location)), ForeachStatement.Roles.Identifier);
@ -1902,6 +1901,7 @@ namespace ICSharpCode.NRefactory.CSharp
if (location != null && location.Count > 2) if (location != null && location.Count > 2)
result.AddChild (new CSharpTokenNode (Convert (location [2]), 1), ForeachStatement.Roles.RPar); result.AddChild (new CSharpTokenNode (Convert (location [2]), 1), ForeachStatement.Roles.RPar);
if (foreachStatement.Statement != null) if (foreachStatement.Statement != null)
result.AddChild ((Statement)foreachStatement.Statement.Accept (this), ForeachStatement.Roles.EmbeddedStatement); result.AddChild ((Statement)foreachStatement.Statement.Accept (this), ForeachStatement.Roles.EmbeddedStatement);
@ -1981,9 +1981,7 @@ namespace ICSharpCode.NRefactory.CSharp
result.AddChild (Identifier.Create (memberAccess.Name, Convert (memberAccess.Location)), MemberReferenceExpression.Roles.Identifier); result.AddChild (Identifier.Create (memberAccess.Name, Convert (memberAccess.Location)), MemberReferenceExpression.Roles.Identifier);
if (memberAccess.TypeArguments != null) { AddTypeArguments (result, memberAccess);
AddTypeArguments (result, memberAccess.TypeArguments);
}
return result; return result;
} }
@ -2018,9 +2016,7 @@ namespace ICSharpCode.NRefactory.CSharp
{ {
var result = new IdentifierExpression (); var result = new IdentifierExpression ();
result.AddChild (Identifier.Create (simpleName.Name, Convert (simpleName.Location)), IdentifierExpression.Roles.Identifier); result.AddChild (Identifier.Create (simpleName.Name, Convert (simpleName.Location)), IdentifierExpression.Roles.Identifier);
if (simpleName.TypeArguments != null) { AddTypeArguments (result, simpleName);
AddTypeArguments (result, simpleName.TypeArguments);
}
return result; return result;
} }
@ -2260,7 +2256,7 @@ namespace ICSharpCode.NRefactory.CSharp
{ {
var result = new BinaryOperatorExpression (); var result = new BinaryOperatorExpression ();
result.Operator = BinaryOperatorType.NullCoalescing; result.Operator = BinaryOperatorType.NullCoalescing;
result.AddChild ((Expression)nullCoalescingOperator.Left.Accept (this), BinaryOperatorExpression.LeftRole); result.AddChild ((Expression)nullCoalescingOperator.LeftExpression.Accept (this), BinaryOperatorExpression.LeftRole);
result.AddChild (new CSharpTokenNode (Convert (nullCoalescingOperator.Location), 2), BinaryOperatorExpression.OperatorRole); result.AddChild (new CSharpTokenNode (Convert (nullCoalescingOperator.Location), 2), BinaryOperatorExpression.OperatorRole);
result.AddChild ((Expression)nullCoalescingOperator.Right.Accept (this), BinaryOperatorExpression.RightRole); result.AddChild ((Expression)nullCoalescingOperator.Right.Accept (this), BinaryOperatorExpression.RightRole);
return result; return result;
@ -2335,17 +2331,17 @@ namespace ICSharpCode.NRefactory.CSharp
} }
} }
void AddTypeParameters (AstNode parent, Mono.CSharp.TypeArguments typeArguments) void AddTypeParameters (AstNode parent, MemberName memberName)
{ {
if (typeArguments == null || typeArguments.IsEmpty) if (memberName == null || memberName.TypeParameters == null)
return; return;
var chevronLocs = LocationsBag.GetLocations (typeArguments); var chevronLocs = LocationsBag.GetLocations (memberName.TypeParameters);
if (chevronLocs != null) if (chevronLocs != null)
parent.AddChild (new CSharpTokenNode (Convert (chevronLocs[chevronLocs.Count - 2]), 1), InvocationExpression.Roles.LChevron); parent.AddChild (new CSharpTokenNode (Convert (chevronLocs[chevronLocs.Count - 2]), 1), InvocationExpression.Roles.LChevron);
for (int i = 0; i < typeArguments.Count; i++) { for (int i = 0; i < memberName.TypeParameters.Count; i++) {
if (chevronLocs != null && i > 0 && i - 1 < chevronLocs.Count) if (chevronLocs != null && i > 0 && i - 1 < chevronLocs.Count)
parent.AddChild (new CSharpTokenNode (Convert (chevronLocs[i - 1]), 1), InvocationExpression.Roles.Comma); parent.AddChild (new CSharpTokenNode (Convert (chevronLocs[i - 1]), 1), InvocationExpression.Roles.Comma);
var arg = (TypeParameterName)typeArguments.Args[i]; var arg = memberName.TypeParameters[i];
if (arg == null) if (arg == null)
continue; continue;
TypeParameterDeclaration tp = new TypeParameterDeclaration(); TypeParameterDeclaration tp = new TypeParameterDeclaration();
@ -2387,16 +2383,37 @@ namespace ICSharpCode.NRefactory.CSharp
parent.AddChild (new CSharpTokenNode (Convert (chevronLocs[chevronLocs.Count - 1]), 1), InvocationExpression.Roles.RChevron); parent.AddChild (new CSharpTokenNode (Convert (chevronLocs[chevronLocs.Count - 1]), 1), InvocationExpression.Roles.RChevron);
} }
void AddTypeArguments (AstNode parent, Mono.CSharp.TypeArguments typeArguments) void AddTypeArguments (AstNode parent, MemberName memberName)
{
if (memberName == null || memberName.TypeParameters == null)
return;
var chevronLocs = LocationsBag.GetLocations (memberName.TypeParameters);
if (chevronLocs != null)
parent.AddChild (new CSharpTokenNode (Convert (chevronLocs[chevronLocs.Count - 2]), 1), InvocationExpression.Roles.LChevron);
for (int i = 0; i < memberName.TypeParameters.Count; i++) {
var arg = memberName.TypeParameters[i];
if (arg == null)
continue;
parent.AddChild (ConvertToType (arg), InvocationExpression.Roles.TypeArgument);
if (chevronLocs != null && i < chevronLocs.Count - 2)
parent.AddChild (new CSharpTokenNode (Convert (chevronLocs[i]), 1), InvocationExpression.Roles.Comma);
}
if (chevronLocs != null)
parent.AddChild (new CSharpTokenNode (Convert (chevronLocs[chevronLocs.Count - 1]), 1), InvocationExpression.Roles.RChevron);
}
void AddTypeArguments (AstNode parent, ATypeNameExpression memberName)
{ {
if (typeArguments == null || typeArguments.IsEmpty) if (memberName == null || !memberName.HasTypeArguments)
return; return;
var chevronLocs = LocationsBag.GetLocations (typeArguments); var chevronLocs = LocationsBag.GetLocations (memberName.TypeArguments);
if (chevronLocs != null) if (chevronLocs != null)
parent.AddChild (new CSharpTokenNode (Convert (chevronLocs[chevronLocs.Count - 2]), 1), InvocationExpression.Roles.LChevron); parent.AddChild (new CSharpTokenNode (Convert (chevronLocs[chevronLocs.Count - 2]), 1), InvocationExpression.Roles.LChevron);
for (int i = 0; i < typeArguments.Count; i++) { for (int i = 0; i < memberName.TypeArguments.Count; i++) {
var arg = typeArguments.Args[i]; var arg = memberName.TypeArguments.Args[i];
if (arg == null) if (arg == null)
continue; continue;
parent.AddChild (ConvertToType (arg), InvocationExpression.Roles.TypeArgument); parent.AddChild (ConvertToType (arg), InvocationExpression.Roles.TypeArgument);
@ -2489,8 +2506,8 @@ namespace ICSharpCode.NRefactory.CSharp
{ {
var result = new InvocationExpression (); var result = new InvocationExpression ();
var location = LocationsBag.GetLocations (invocationExpression); var location = LocationsBag.GetLocations (invocationExpression);
if (invocationExpression.Expression != null) if (invocationExpression.Exp != null)
result.AddChild ((Expression)invocationExpression.Expression.Accept (this), InvocationExpression.Roles.TargetExpression); result.AddChild ((Expression)invocationExpression.Exp.Accept (this), InvocationExpression.Roles.TargetExpression);
if (location != null) if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), InvocationExpression.Roles.LPar); result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), InvocationExpression.Roles.LPar);
AddArguments (result, location, invocationExpression.Arguments); AddArguments (result, location, invocationExpression.Arguments);
@ -2796,7 +2813,7 @@ namespace ICSharpCode.NRefactory.CSharp
result.AddChild (new CSharpTokenNode (Convert (sizeOfExpression.Location), "sizeof".Length), TypeOfExpression.Roles.Keyword); result.AddChild (new CSharpTokenNode (Convert (sizeOfExpression.Location), "sizeof".Length), TypeOfExpression.Roles.Keyword);
if (location != null) if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), TypeOfExpression.Roles.LPar); result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), TypeOfExpression.Roles.LPar);
result.AddChild (ConvertToType (sizeOfExpression.QueriedType), TypeOfExpression.Roles.Type); result.AddChild (ConvertToType (sizeOfExpression.TypeExpression), TypeOfExpression.Roles.Type);
if (location != null) if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), TypeOfExpression.Roles.RPar); result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), TypeOfExpression.Roles.RPar);
return result; return result;

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

@ -36,15 +36,18 @@ namespace Mono.CSharp {
throw new InternalErrorException ("Helper class already defined!"); throw new InternalErrorException ("Helper class already defined!");
} }
protected static MemberName MakeMemberName (MemberBase host, string name, int unique_id, TypeParameter[] tparams, Location loc) protected static MemberName MakeMemberName (MemberBase host, string name, int unique_id, TypeParameters tparams, Location loc)
{ {
string host_name = host == null ? null : host.Name; string host_name = host == null ? null : host is InterfaceMemberBase ? ((InterfaceMemberBase)host).GetFullName (host.MemberName) : host.Name;
string tname = MakeName (host_name, "c", name, unique_id); string tname = MakeName (host_name, "c", name, unique_id);
TypeArguments args = null; TypeParameters args = null;
if (tparams != null) { if (tparams != null) {
args = new TypeArguments (); args = new TypeParameters (tparams.Count);
foreach (TypeParameter tparam in tparams)
args.Add (new TypeParameterName (tparam.Name, null, loc)); // Type parameters will be filled later when we have TypeContainer
// instance, for now we need only correct arity to create valid name
for (int i = 0; i < tparams.Count; ++i)
args.Add ((TypeParameter) null);
} }
return new MemberName (tname, args, loc); return new MemberName (tname, args, loc);
@ -81,15 +84,16 @@ namespace Mono.CSharp {
protected TypeParameterMutator mutator; protected TypeParameterMutator mutator;
public HoistedStoreyClass (TypeContainer parent, MemberName name, TypeParameter[] tparams, Modifiers mod) public HoistedStoreyClass (TypeContainer parent, MemberName name, TypeParameters tparams, Modifiers mod)
: base (parent, name, mod | Modifiers.PRIVATE) : base (parent, name, mod | Modifiers.PRIVATE)
{ {
if (tparams != null) { if (tparams != null) {
type_params = new TypeParameter[tparams.Length]; var type_params = name.TypeParameters;
var src = new TypeParameterSpec[tparams.Length]; var src = new TypeParameterSpec[tparams.Count];
var dst = new TypeParameterSpec[tparams.Length]; var dst = new TypeParameterSpec[tparams.Count];
for (int i = 0; i < type_params.Length; ++i) { for (int i = 0; i < tparams.Count; ++i) {
type_params[i] = tparams[i].CreateHoistedCopy (this, spec); type_params[i] = tparams[i].CreateHoistedCopy (this, spec);
src[i] = tparams[i].Type; src[i] = tparams[i].Type;
@ -99,7 +103,7 @@ namespace Mono.CSharp {
// A copy is not enough, inflate any type parameter constraints // A copy is not enough, inflate any type parameter constraints
// using a new type parameters // using a new type parameters
var inflator = new TypeParameterInflator (this, null, src, dst); var inflator = new TypeParameterInflator (this, null, src, dst);
for (int i = 0; i < type_params.Length; ++i) { for (int i = 0; i < tparams.Count; ++i) {
src[i].InflateConstraints (inflator, dst[i]); src[i].InflateConstraints (inflator, dst[i]);
} }
@ -196,7 +200,7 @@ namespace Mono.CSharp {
// Local variable which holds this storey instance // Local variable which holds this storey instance
public Expression Instance; public Expression Instance;
public AnonymousMethodStorey (Block block, TypeContainer parent, MemberBase host, TypeParameter[] tparams, string name) public AnonymousMethodStorey (Block block, TypeContainer parent, MemberBase host, TypeParameters tparams, string name)
: base (parent, MakeMemberName (host, name, unique_id, tparams, block.StartLocation), : base (parent, MakeMemberName (host, name, unique_id, tparams, block.StartLocation),
tparams, Modifiers.SEALED) tparams, Modifiers.SEALED)
{ {
@ -323,8 +327,8 @@ namespace Mono.CSharp {
// Use current method type parameter (MVAR) for top level storey only. All // Use current method type parameter (MVAR) for top level storey only. All
// nested storeys use class type parameter (VAR) // nested storeys use class type parameter (VAR)
// //
TypeParameter[] tparams = ec.CurrentAnonymousMethod != null && ec.CurrentAnonymousMethod.Storey != null ? var tparams = ec.CurrentAnonymousMethod != null && ec.CurrentAnonymousMethod.Storey != null ?
ec.CurrentAnonymousMethod.Storey.TypeParameters : ec.CurrentAnonymousMethod.Storey.CurrentTypeParameters :
ec.CurrentTypeParameters; ec.CurrentTypeParameters;
TypeArguments targs = new TypeArguments (); TypeArguments targs = new TypeArguments ();
@ -333,7 +337,7 @@ namespace Mono.CSharp {
// Use type parameter name instead of resolved type parameter // Use type parameter name instead of resolved type parameter
// specification to resolve to correctly nested type parameters // specification to resolve to correctly nested type parameters
// //
for (int i = 0; i < tparams.Length; ++i) for (int i = 0; i < tparams.Count; ++i)
targs.Add (new SimpleName (tparams [i].Name, Location)); // new TypeParameterExpr (tparams[i], Location)); targs.Add (new SimpleName (tparams [i].Name, Location)); // new TypeParameterExpr (tparams[i], Location));
storey_type_expr = new GenericTypeExpr (Definition, targs, Location); storey_type_expr = new GenericTypeExpr (Definition, targs, Location);
@ -347,19 +351,18 @@ namespace Mono.CSharp {
public void SetNestedStoryParent (AnonymousMethodStorey parentStorey) public void SetNestedStoryParent (AnonymousMethodStorey parentStorey)
{ {
Parent = parentStorey; Parent = parentStorey;
type_params = null;
spec.IsGeneric = false; spec.IsGeneric = false;
spec.DeclaringType = parentStorey.CurrentType; spec.DeclaringType = parentStorey.CurrentType;
MemberName.TypeArguments = null; MemberName.TypeParameters = null;
} }
protected override bool DoResolveTypeParameters () protected override bool DoResolveTypeParameters ()
{ {
// Although any storey can have type parameters they are all clones of method type // Although any storey can have type parameters they are all clones of method type
// parameters therefore have to mutate MVAR references in any of cloned constraints // parameters therefore have to mutate MVAR references in any of cloned constraints
if (type_params != null) { if (CurrentTypeParameters != null) {
for (int i = 0; i < type_params.Length; ++i) { for (int i = 0; i < CurrentTypeParameters.Count; ++i) {
var spec = type_params[i].Type; var spec = CurrentTypeParameters[i].Type;
spec.BaseType = mutator.Mutate (spec.BaseType); spec.BaseType = mutator.Mutate (spec.BaseType);
if (spec.InterfacesDefined != null) { if (spec.InterfacesDefined != null) {
var mutated = new TypeSpec[spec.InterfacesDefined.Length]; var mutated = new TypeSpec[spec.InterfacesDefined.Length];
@ -885,9 +888,8 @@ namespace Mono.CSharp {
public ParametersBlock Block; public ParametersBlock Block;
public AnonymousMethodExpression (bool isAsync, Location loc) public AnonymousMethodExpression (Location loc)
{ {
this.IsAsync = isAsync;
this.loc = loc; this.loc = loc;
this.compatibles = new Dictionary<TypeSpec, Expression> (); this.compatibles = new Dictionary<TypeSpec, Expression> ();
} }
@ -1588,16 +1590,17 @@ namespace Mono.CSharp {
MemberName member_name; MemberName member_name;
GenericMethod generic_method; GenericMethod generic_method;
if (storey == null && mc.MemberName.TypeArguments != null) { if (storey == null && ec.CurrentTypeParameters != null) {
member_name = new MemberName (name, mc.MemberName.TypeArguments.Clone (), Location);
var hoisted_tparams = ec.CurrentTypeParameters; var hoisted_tparams = ec.CurrentTypeParameters;
var type_params = new TypeParameter[hoisted_tparams.Length]; var type_params = new TypeParameters (hoisted_tparams.Count);
for (int i = 0; i < type_params.Length; ++i) { for (int i = 0; i < hoisted_tparams.Count; ++i) {
type_params[i] = hoisted_tparams[i].CreateHoistedCopy (parent, null); type_params.Add (hoisted_tparams[i].CreateHoistedCopy (parent, null));
} }
generic_method = new GenericMethod (parent.NamespaceEntry, parent, member_name, type_params, member_name = new MemberName (name, type_params, Location);
generic_method = new GenericMethod (parent.NamespaceEntry, parent, member_name, //type_params,
new TypeExpression (ReturnType, Location), parameters); new TypeExpression (ReturnType, Location), parameters);
} else { } else {
member_name = new MemberName (name, Location); member_name = new MemberName (name, Location);
@ -1782,16 +1785,15 @@ namespace Mono.CSharp {
string name = ClassNamePrefix + types_counter++; string name = ClassNamePrefix + types_counter++;
ParametersCompiled all_parameters; ParametersCompiled all_parameters;
TypeParameterName[] t_params; TypeParameters tparams = null;
SimpleName[] t_args; SimpleName[] t_args;
if (parameters.Count == 0) { if (parameters.Count == 0) {
all_parameters = ParametersCompiled.EmptyReadOnlyParameters; all_parameters = ParametersCompiled.EmptyReadOnlyParameters;
t_params = new TypeParameterName[0];
t_args = null; t_args = null;
} else { } else {
t_args = new SimpleName[parameters.Count]; t_args = new SimpleName[parameters.Count];
t_params = new TypeParameterName[parameters.Count]; tparams = new TypeParameters ();
Parameter[] ctor_params = new Parameter[parameters.Count]; Parameter[] ctor_params = new Parameter[parameters.Count];
for (int i = 0; i < parameters.Count; ++i) { for (int i = 0; i < parameters.Count; ++i) {
AnonymousTypeParameter p = parameters[i]; AnonymousTypeParameter p = parameters[i];
@ -1808,7 +1810,7 @@ namespace Mono.CSharp {
} }
t_args[i] = new SimpleName ("<" + p.Name + ">__T", p.Location); t_args[i] = new SimpleName ("<" + p.Name + ">__T", p.Location);
t_params[i] = new TypeParameterName (t_args[i].Name, null, p.Location); tparams.Add (new TypeParameter (i, new MemberName (t_args[i].Name, p.Location), null, null, Variance.None));
ctor_params[i] = new Parameter (t_args[i], p.Name, Parameter.Modifier.NONE, null, p.Location); ctor_params[i] = new Parameter (t_args[i], p.Name, Parameter.Modifier.NONE, null, p.Location);
} }
@ -1820,13 +1822,13 @@ namespace Mono.CSharp {
// named upon properties names // named upon properties names
// //
AnonymousTypeClass a_type = new AnonymousTypeClass (parent.NamespaceEntry.SlaveDeclSpace, AnonymousTypeClass a_type = new AnonymousTypeClass (parent.NamespaceEntry.SlaveDeclSpace,
new MemberName (name, new TypeArguments (t_params), loc), parameters, loc); new MemberName (name, tparams, loc), parameters, loc);
if (parameters.Count > 0) if (parameters.Count > 0)
a_type.SetParameterInfo (null); a_type.SetParameterInfo (null);
Constructor c = new Constructor (a_type, name, Modifiers.PUBLIC | Modifiers.DEBUGGER_HIDDEN, Constructor c = new Constructor (a_type, name, Modifiers.PUBLIC | Modifiers.DEBUGGER_HIDDEN,
null, all_parameters, null, loc); null, all_parameters, loc);
c.Block = new ToplevelBlock (parent.Module.Compiler, c.ParameterInfo, loc); c.Block = new ToplevelBlock (parent.Module.Compiler, c.ParameterInfo, loc);
// //
@ -1913,10 +1915,11 @@ namespace Mono.CSharp {
ToplevelBlock equals_block = new ToplevelBlock (Compiler, equals.ParameterInfo, loc); ToplevelBlock equals_block = new ToplevelBlock (Compiler, equals.ParameterInfo, loc);
TypeExpr current_type; TypeExpr current_type;
if (type_params != null) { if (CurrentTypeParameters != null) {
var targs = new TypeArguments (); var targs = new TypeArguments ();
foreach (var type_param in type_params) for (int i = 0; i < CurrentTypeParameters.Count; ++i) {
targs.Add (new TypeParameterExpr (type_param, type_param.Location)); targs.Add (new TypeParameterExpr (CurrentTypeParameters[i], Location));
}
current_type = new GenericTypeExpr (Definition, targs, loc); current_type = new GenericTypeExpr (Definition, targs, loc);
} else { } else {

11
ICSharpCode.NRefactory.CSharp/Parser/mcs/assembly.cs

@ -1090,8 +1090,7 @@ namespace Mono.CSharp
public abstract bool HasObjectType (T assembly); public abstract bool HasObjectType (T assembly);
protected abstract string[] GetDefaultReferences (); protected abstract string[] GetDefaultReferences ();
public abstract T LoadAssemblyFile (string fileName); public abstract T LoadAssemblyFile (string fileName, bool isImplicitReference);
public abstract T LoadAssemblyDefault (string assembly);
public abstract void LoadReferences (ModuleContainer module); public abstract void LoadReferences (ModuleContainer module);
protected void Error_FileNotFound (string fileName) protected void Error_FileNotFound (string fileName)
@ -1128,14 +1127,14 @@ namespace Mono.CSharp
// Load mscorlib.dll as the first // Load mscorlib.dll as the first
// //
if (module.Compiler.Settings.StdLib) { if (module.Compiler.Settings.StdLib) {
corlib_assembly = LoadAssemblyDefault ("mscorlib.dll"); corlib_assembly = LoadAssemblyFile ("mscorlib.dll", true);
} else { } else {
corlib_assembly = default (T); corlib_assembly = default (T);
} }
T a; T a;
foreach (string r in module.Compiler.Settings.AssemblyReferences) { foreach (string r in module.Compiler.Settings.AssemblyReferences) {
a = LoadAssemblyFile (r); a = LoadAssemblyFile (r, false);
if (a == null || EqualityComparer<T>.Default.Equals (a, corlib_assembly)) if (a == null || EqualityComparer<T>.Default.Equals (a, corlib_assembly))
continue; continue;
@ -1153,7 +1152,7 @@ namespace Mono.CSharp
} }
foreach (var entry in module.Compiler.Settings.AssemblyReferencesAliases) { foreach (var entry in module.Compiler.Settings.AssemblyReferencesAliases) {
a = LoadAssemblyFile (entry.Item2); a = LoadAssemblyFile (entry.Item2, false);
if (a == null) if (a == null)
continue; continue;
@ -1166,7 +1165,7 @@ namespace Mono.CSharp
if (compiler.Settings.LoadDefaultReferences) { if (compiler.Settings.LoadDefaultReferences) {
foreach (string r in GetDefaultReferences ()) { foreach (string r in GetDefaultReferences ()) {
a = LoadAssemblyDefault (r); a = LoadAssemblyFile (r, true);
if (a == null) if (a == null)
continue; continue;

13
ICSharpCode.NRefactory.CSharp/Parser/mcs/assign.cs

@ -418,6 +418,11 @@ namespace Mono.CSharp {
_target.target = target.Clone (clonectx); _target.target = target.Clone (clonectx);
_target.source = source.Clone (clonectx); _target.source = source.Clone (clonectx);
} }
public override object Accept (StructuralVisitor visitor)
{
return visitor.Visit (this);
}
} }
public class SimpleAssign : Assign public class SimpleAssign : Assign
@ -653,6 +658,12 @@ namespace Mono.CSharp {
this.left = left; this.left = left;
} }
public Binary.Operator Operator {
get {
return op;
}
}
protected override Expression DoResolve (ResolveContext ec) protected override Expression DoResolve (ResolveContext ec)
{ {
right = right.Resolve (ec); right = right.Resolve (ec);
@ -811,10 +822,10 @@ namespace Mono.CSharp {
ctarget.right = ctarget.source = source.Clone (clonectx); ctarget.right = ctarget.source = source.Clone (clonectx);
ctarget.target = target.Clone (clonectx); ctarget.target = target.Clone (clonectx);
} }
public override object Accept (StructuralVisitor visitor) public override object Accept (StructuralVisitor visitor)
{ {
return visitor.Visit (this); return visitor.Visit (this);
} }
} }
} }

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

@ -40,6 +40,12 @@ namespace Mono.CSharp
this.loc = loc; this.loc = loc;
} }
public Expression Expr {
get {
return expr;
}
}
protected override void CloneTo (CloneContext clonectx, Expression target) protected override void CloneTo (CloneContext clonectx, Expression target)
{ {
var t = (Await) target; var t = (Await) target;

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

@ -89,8 +89,7 @@ namespace Mono.CSharp {
public AttributeTargets Target; public AttributeTargets Target;
readonly ATypeNameExpression expression; readonly ATypeNameExpression expression;
public Arguments PosArguments; Arguments pos_args, named_args;
public Arguments NamedArguments;
bool resolve_error; bool resolve_error;
bool arg_resolved; bool arg_resolved;
@ -118,8 +117,8 @@ namespace Mono.CSharp {
{ {
this.expression = expr; this.expression = expr;
if (args != null) { if (args != null) {
PosArguments = args[0]; pos_args = args[0];
NamedArguments = args[1]; named_args = args[1];
} }
this.loc = loc; this.loc = loc;
ExplicitTarget = target; ExplicitTarget = target;
@ -132,6 +131,24 @@ namespace Mono.CSharp {
} }
} }
public Arguments NamedArguments {
get {
return named_args;
}
}
public Arguments PositionalArguments {
get {
return pos_args;
}
}
public ATypeNameExpression TypeExpression {
get {
return expression;
}
}
void AddModuleCharSet (ResolveContext rc) void AddModuleCharSet (ResolveContext rc)
{ {
const string dll_import_char_set = "CharSet"; const string dll_import_char_set = "CharSet";
@ -147,7 +164,7 @@ namespace Mono.CSharp {
} }
if (NamedArguments == null) if (NamedArguments == null)
NamedArguments = new Arguments (1); named_args = new Arguments (1);
var value = Constant.CreateConstant (rc.Module.PredefinedTypes.CharSet.TypeSpec, rc.Module.DefaultCharSet, Location); var value = Constant.CreateConstant (rc.Module.PredefinedTypes.CharSet.TypeSpec, rc.Module.DefaultCharSet, Location);
NamedArguments.Add (new NamedArgument (dll_import_char_set, loc, value)); NamedArguments.Add (new NamedArgument (dll_import_char_set, loc, value));
@ -156,8 +173,8 @@ namespace Mono.CSharp {
public Attribute Clone () public Attribute Clone ()
{ {
Attribute a = new Attribute (ExplicitTarget, expression, null, loc, nameEscaped); Attribute a = new Attribute (ExplicitTarget, expression, null, loc, nameEscaped);
a.PosArguments = PosArguments; a.pos_args = pos_args;
a.NamedArguments = NamedArguments; a.named_args = NamedArguments;
return a; return a;
} }
@ -432,14 +449,14 @@ namespace Mono.CSharp {
MethodSpec ctor; MethodSpec ctor;
// Try if the attribute is simple and has been resolved before // Try if the attribute is simple and has been resolved before
if (PosArguments != null || !context.Module.AttributeConstructorCache.TryGetValue (Type, out ctor)) { if (pos_args != null || !context.Module.AttributeConstructorCache.TryGetValue (Type, out ctor)) {
rc = CreateResolveContext (); rc = CreateResolveContext ();
ctor = ResolveConstructor (rc); ctor = ResolveConstructor (rc);
if (ctor == null) { if (ctor == null) {
return null; return null;
} }
if (PosArguments == null && ctor.Parameters.IsEmpty) if (pos_args == null && ctor.Parameters.IsEmpty)
context.Module.AttributeConstructorCache.Add (Type, ctor); context.Module.AttributeConstructorCache.Add (Type, ctor);
} }
@ -468,16 +485,16 @@ namespace Mono.CSharp {
MethodSpec ResolveConstructor (ResolveContext ec) MethodSpec ResolveConstructor (ResolveContext ec)
{ {
if (PosArguments != null) { if (pos_args != null) {
bool dynamic; bool dynamic;
PosArguments.Resolve (ec, out dynamic); pos_args.Resolve (ec, out dynamic);
if (dynamic) { if (dynamic) {
Error_AttributeArgumentIsDynamic (ec.MemberContext, loc); Error_AttributeArgumentIsDynamic (ec.MemberContext, loc);
return null; return null;
} }
} }
return Expression.ConstructorLookup (ec, Type, ref PosArguments, loc); return Expression.ConstructorLookup (ec, Type, ref pos_args, loc);
} }
bool ResolveNamedArguments (ResolveContext ec) bool ResolveNamedArguments (ResolveContext ec)
@ -637,7 +654,7 @@ namespace Mono.CSharp {
if (resolve_error) if (resolve_error)
return DefaultUsageAttribute; return DefaultUsageAttribute;
AttributeUsageAttribute usage_attribute = new AttributeUsageAttribute ((AttributeTargets)((Constant) PosArguments [0].Expr).GetValue ()); AttributeUsageAttribute usage_attribute = new AttributeUsageAttribute ((AttributeTargets) ((Constant) pos_args[0].Expr).GetValue ());
var field = GetNamedValue ("AllowMultiple") as BoolConstant; var field = GetNamedValue ("AllowMultiple") as BoolConstant;
if (field != null) if (field != null)
@ -660,10 +677,10 @@ namespace Mono.CSharp {
// But because a lot of attribute class code must be rewritten will be better to wait... // But because a lot of attribute class code must be rewritten will be better to wait...
Resolve (); Resolve ();
if (resolve_error || PosArguments.Count != 1 || !(PosArguments [0].Expr is Constant)) if (resolve_error || pos_args.Count != 1 || !(pos_args[0].Expr is Constant))
return null; return null;
return ((Constant) PosArguments [0].Expr).GetValue () as string; return ((Constant) pos_args[0].Expr).GetValue () as string;
} }
/// <summary> /// <summary>
@ -679,7 +696,7 @@ namespace Mono.CSharp {
if (resolve_error) if (resolve_error)
return null; return null;
return ((Constant) PosArguments[0].Expr).GetValue () as string; return ((Constant) pos_args[0].Expr).GetValue () as string;
} }
/// <summary> /// <summary>
@ -701,14 +718,14 @@ namespace Mono.CSharp {
if (resolve_error) if (resolve_error)
return null; return null;
if (PosArguments == null) if (pos_args == null)
return new ObsoleteAttribute (); return new ObsoleteAttribute ();
string msg = ((Constant) PosArguments[0].Expr).GetValue () as string; string msg = ((Constant) pos_args[0].Expr).GetValue () as string;
if (PosArguments.Count == 1) if (pos_args.Count == 1)
return new ObsoleteAttribute (msg); return new ObsoleteAttribute (msg);
return new ObsoleteAttribute (msg, ((BoolConstant) PosArguments[1].Expr).Value); return new ObsoleteAttribute (msg, ((BoolConstant) pos_args[1].Expr).Value);
} }
/// <summary> /// <summary>
@ -726,7 +743,7 @@ namespace Mono.CSharp {
if (resolve_error) if (resolve_error)
return false; return false;
return ((BoolConstant) PosArguments[0].Expr).Value; return ((BoolConstant) pos_args[0].Expr).Value;
} }
public TypeSpec GetCoClassAttributeValue () public TypeSpec GetCoClassAttributeValue ()
@ -812,7 +829,7 @@ namespace Mono.CSharp {
System.Security.Permissions.SecurityAction GetSecurityActionValue () System.Security.Permissions.SecurityAction GetSecurityActionValue ()
{ {
return (SecurityAction) ((Constant) PosArguments[0].Expr).GetValue (); return (SecurityAction) ((Constant) pos_args[0].Expr).GetValue ();
} }
/// <summary> /// <summary>
@ -822,9 +839,9 @@ namespace Mono.CSharp {
public void ExtractSecurityPermissionSet (MethodSpec ctor, ref SecurityType permissions) public void ExtractSecurityPermissionSet (MethodSpec ctor, ref SecurityType permissions)
{ {
#if STATIC #if STATIC
object[] values = new object [PosArguments.Count]; object[] values = new object[pos_args.Count];
for (int i = 0; i < values.Length; ++i) for (int i = 0; i < values.Length; ++i)
values [i] = ((Constant) PosArguments [i].Expr).GetValue (); values[i] = ((Constant) pos_args[i].Expr).GetValue ();
PropertyInfo[] prop; PropertyInfo[] prop;
object[] prop_values; object[] prop_values;
@ -865,7 +882,7 @@ namespace Mono.CSharp {
public CharSet GetCharSetValue () public CharSet GetCharSetValue ()
{ {
return (CharSet)System.Enum.Parse (typeof (CharSet), ((Constant) PosArguments [0].Expr).GetValue ().ToString ()); return (CharSet) System.Enum.Parse (typeof (CharSet), ((Constant) pos_args[0].Expr).GetValue ().ToString ());
} }
public bool HasField (string fieldName) public bool HasField (string fieldName)
@ -887,8 +904,8 @@ namespace Mono.CSharp {
public bool IsInternalCall () public bool IsInternalCall ()
{ {
MethodImplOptions options = 0; MethodImplOptions options = 0;
if (PosArguments.Count == 1) { if (pos_args.Count == 1) {
options = (MethodImplOptions) System.Enum.Parse (typeof (MethodImplOptions), ((Constant) PosArguments[0].Expr).GetValue ().ToString ()); options = (MethodImplOptions) System.Enum.Parse (typeof (MethodImplOptions), ((Constant) pos_args[0].Expr).GetValue ().ToString ());
} else if (HasField ("Value")) { } else if (HasField ("Value")) {
var named = GetNamedValue ("Value"); var named = GetNamedValue ("Value");
options = (MethodImplOptions) System.Enum.Parse (typeof (MethodImplOptions), named.GetValue ().ToString ()); options = (MethodImplOptions) System.Enum.Parse (typeof (MethodImplOptions), named.GetValue ().ToString ());
@ -902,19 +919,19 @@ namespace Mono.CSharp {
// //
public bool IsExplicitLayoutKind () public bool IsExplicitLayoutKind ()
{ {
if (PosArguments == null || PosArguments.Count != 1) if (pos_args == null || pos_args.Count != 1)
return false; return false;
var value = (LayoutKind) System.Enum.Parse (typeof (LayoutKind), ((Constant) PosArguments[0].Expr).GetValue ().ToString ()); var value = (LayoutKind) System.Enum.Parse (typeof (LayoutKind), ((Constant) pos_args[0].Expr).GetValue ().ToString ());
return value == LayoutKind.Explicit; return value == LayoutKind.Explicit;
} }
public Expression GetParameterDefaultValue () public Expression GetParameterDefaultValue ()
{ {
if (PosArguments == null) if (pos_args == null)
return null; return null;
return PosArguments[0].Expr; return pos_args[0].Expr;
} }
public override bool Equals (object obj) public override bool Equals (object obj)
@ -951,16 +968,16 @@ namespace Mono.CSharp {
} }
byte[] cdata; byte[] cdata;
if (PosArguments == null && named_values == null) { if (pos_args == null && named_values == null) {
cdata = AttributeEncoder.Empty; cdata = AttributeEncoder.Empty;
} else { } else {
AttributeEncoder encoder = new AttributeEncoder (); AttributeEncoder encoder = new AttributeEncoder ();
if (PosArguments != null) { if (pos_args != null) {
var param_types = ctor.Parameters.Types; var param_types = ctor.Parameters.Types;
for (int j = 0; j < PosArguments.Count; ++j) { for (int j = 0; j < pos_args.Count; ++j) {
var pt = param_types[j]; var pt = param_types[j];
var arg_expr = PosArguments[j].Expr; var arg_expr = pos_args[j].Expr;
if (j == 0) { if (j == 0) {
if ((Type == predefined.IndexerName || Type == predefined.Conditional) && arg_expr is Constant) { if ((Type == predefined.IndexerName || Type == predefined.Conditional) && arg_expr is Constant) {
string v = ((Constant) arg_expr).GetValue () as string; string v = ((Constant) arg_expr).GetValue () as string;
@ -984,15 +1001,15 @@ namespace Mono.CSharp {
"System.AttributeUsage"); "System.AttributeUsage");
} }
} else if (Type == predefined.MarshalAs) { } else if (Type == predefined.MarshalAs) {
if (PosArguments.Count == 1) { if (pos_args.Count == 1) {
var u_type = (UnmanagedType) System.Enum.Parse (typeof (UnmanagedType), ((Constant) PosArguments[0].Expr).GetValue ().ToString ()); var u_type = (UnmanagedType) System.Enum.Parse (typeof (UnmanagedType), ((Constant) pos_args[0].Expr).GetValue ().ToString ());
if (u_type == UnmanagedType.ByValArray && !(Owner is FieldBase)) { if (u_type == UnmanagedType.ByValArray && !(Owner is FieldBase)) {
Error_AttributeEmitError ("Specified unmanaged type is only valid on fields"); Error_AttributeEmitError ("Specified unmanaged type is only valid on fields");
} }
} }
} else if (Type == predefined.DllImport) { } else if (Type == predefined.DllImport) {
if (PosArguments.Count == 1 && PosArguments[0].Expr is Constant) { if (pos_args.Count == 1 && pos_args[0].Expr is Constant) {
var value = ((Constant) PosArguments[0].Expr).GetValue () as string; var value = ((Constant) pos_args[0].Expr).GetValue () as string;
if (string.IsNullOrEmpty (value)) if (string.IsNullOrEmpty (value))
Error_AttributeEmitError ("DllName cannot be empty"); Error_AttributeEmitError ("DllName cannot be empty");
} }
@ -1055,8 +1072,8 @@ namespace Mono.CSharp {
// Here we are testing attribute arguments for array usage (error 3016) // Here we are testing attribute arguments for array usage (error 3016)
if (Owner.IsClsComplianceRequired ()) { if (Owner.IsClsComplianceRequired ()) {
if (PosArguments != null) if (pos_args != null)
PosArguments.CheckArrayAsAttribute (context.Module.Compiler); pos_args.CheckArrayAsAttribute (context.Module.Compiler);
if (NamedArguments == null) if (NamedArguments == null)
return; return;
@ -1067,10 +1084,10 @@ namespace Mono.CSharp {
private Expression GetValue () private Expression GetValue ()
{ {
if (PosArguments == null || PosArguments.Count < 1) if (pos_args == null || pos_args.Count < 1)
return null; return null;
return PosArguments [0].Expr; return pos_args[0].Expr;
} }
public string GetString () public string GetString ()

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

@ -71,7 +71,7 @@ namespace Mono.CSharp
get { return tc.Parent.CurrentType; } get { return tc.Parent.CurrentType; }
} }
public TypeParameter[] CurrentTypeParameters { public TypeParameters CurrentTypeParameters {
get { return tc.PartialContainer.CurrentTypeParameters; } get { return tc.PartialContainer.CurrentTypeParameters; }
} }
@ -113,9 +113,9 @@ namespace Mono.CSharp
public FullNamedExpression LookupNamespaceOrType (string name, int arity, LookupMode mode, Location loc) public FullNamedExpression LookupNamespaceOrType (string name, int arity, LookupMode mode, Location loc)
{ {
if (arity == 0) { if (arity == 0) {
TypeParameter[] tp = CurrentTypeParameters; var tp = CurrentTypeParameters;
if (tp != null) { if (tp != null) {
TypeParameter t = TypeParameter.FindTypeParameter (tp, name); TypeParameter t = tp.Find (name);
if (t != null) if (t != null)
return new TypeParameterExpr (t, loc); return new TypeParameterExpr (t, loc);
} }
@ -201,7 +201,7 @@ namespace Mono.CSharp
// from classes from the arraylist `type_bases' // from classes from the arraylist `type_bases'
// //
protected TypeSpec base_type; protected TypeSpec base_type;
protected FullNamedExpression base_type_expr; // TODO: It's temporary variable FullNamedExpression base_type_expr; // TODO: It's temporary variable
protected TypeSpec[] iface_exprs; protected TypeSpec[] iface_exprs;
protected List<FullNamedExpression> type_bases; protected List<FullNamedExpression> type_bases;
@ -213,6 +213,11 @@ namespace Mono.CSharp
TypeContainer InTransit; TypeContainer InTransit;
GenericTypeParameterBuilder[] all_tp_builders; GenericTypeParameterBuilder[] all_tp_builders;
//
// All recursive type parameters put together sharing same
// TypeParameter instances
//
TypeParameters all_type_parameters;
public const string DefaultIndexerName = "Item"; public const string DefaultIndexerName = "Item";
@ -256,6 +261,12 @@ namespace Mono.CSharp
#region Properties #region Properties
public List<FullNamedExpression> BaseTypeExpressions {
get {
return type_bases;
}
}
public override TypeSpec CurrentType { public override TypeSpec CurrentType {
get { get {
if (current_type == null) { if (current_type == null) {
@ -263,7 +274,7 @@ namespace Mono.CSharp
// //
// Switch to inflated version as it's used by all expressions // Switch to inflated version as it's used by all expressions
// //
var targs = CurrentTypeParameters == null ? TypeSpec.EmptyTypes : CurrentTypeParameters.Select (l => l.Type).ToArray (); var targs = CurrentTypeParameters == null ? TypeSpec.EmptyTypes : CurrentTypeParameters.Types;
current_type = spec.MakeGenericType (this, targs); current_type = spec.MakeGenericType (this, targs);
} else { } else {
current_type = spec; current_type = spec;
@ -274,9 +285,9 @@ namespace Mono.CSharp
} }
} }
public override TypeParameter[] CurrentTypeParameters { public override TypeParameters CurrentTypeParameters {
get { get {
return PartialContainer.type_params; return PartialContainer.MemberName.TypeParameters;
} }
} }
@ -284,7 +295,7 @@ namespace Mono.CSharp
get { get {
int total = all_tp_builders.Length; int total = all_tp_builders.Length;
if (CurrentTypeParameters != null) { if (CurrentTypeParameters != null) {
return total - CurrentTypeParameters.Length; return total - CurrentTypeParameters.Count;
} }
return total; return total;
} }
@ -326,13 +337,19 @@ namespace Mono.CSharp
} }
} }
public TypeParameters TypeParametersAll {
get {
return all_type_parameters;
}
}
#endregion #endregion
public override void Accept (StructuralVisitor visitor) public override void Accept (StructuralVisitor visitor)
{ {
visitor.Visit (this); visitor.Visit (this);
} }
public bool AddMember (MemberCore symbol) public bool AddMember (MemberCore symbol)
{ {
return AddToContainer (symbol, symbol.MemberName.Basename); return AddToContainer (symbol, symbol.MemberName.Basename);
@ -450,14 +467,14 @@ namespace Mono.CSharp
AddTypeContainer (d); AddTypeContainer (d);
} }
private void AddMemberToList (MemberCore mc, List<MemberCore> alist, bool isexplicit) private void AddMemberToList (InterfaceMemberBase mc, List<MemberCore> alist)
{ {
if (ordered_explicit_member_list == null) { if (ordered_explicit_member_list == null) {
ordered_explicit_member_list = new List<MemberCore> (); ordered_explicit_member_list = new List<MemberCore> ();
ordered_member_list = new List<MemberCore> (); ordered_member_list = new List<MemberCore> ();
} }
if (isexplicit) { if (mc.IsExplicitImpl) {
if (Kind == MemberKind.Interface) { if (Kind == MemberKind.Interface) {
Report.Error (541, mc.Location, Report.Error (541, mc.Location,
"`{0}': explicit interface declaration can only be declared in a class or struct", "`{0}': explicit interface declaration can only be declared in a class or struct",
@ -482,10 +499,7 @@ namespace Mono.CSharp
if (methods == null) if (methods == null)
methods = new List<MemberCore> (); methods = new List<MemberCore> ();
if (method.MemberName.Left != null) AddMemberToList (method, methods);
AddMemberToList (method, methods, true);
else
AddMemberToList (method, methods, false);
} }
public void AddConstructor (Constructor c) public void AddConstructor (Constructor c)
@ -550,10 +564,7 @@ namespace Mono.CSharp
if (properties == null) if (properties == null)
properties = new List<MemberCore> (); properties = new List<MemberCore> ();
if (prop.MemberName.Left != null) AddMemberToList (prop, properties);
AddMemberToList (prop, properties, true);
else
AddMemberToList (prop, properties, false);
} }
public void AddEvent (Event e) public void AddEvent (Event e)
@ -575,10 +586,8 @@ namespace Mono.CSharp
orderedAllMembers.Add (i); orderedAllMembers.Add (i);
if (indexers == null) if (indexers == null)
indexers = new List<MemberCore> (); indexers = new List<MemberCore> ();
if (i.IsExplicitImpl)
AddMemberToList (i, indexers, true); AddMemberToList (i, indexers);
else
AddMemberToList (i, indexers, false);
} }
public void AddOperator (Operator op) public void AddOperator (Operator op)
@ -697,8 +706,7 @@ namespace Mono.CSharp
TypeParameterSpec[] ITypeDefinition.TypeParameters { TypeParameterSpec[] ITypeDefinition.TypeParameters {
get { get {
// TODO MemberCache: this is going to hurt return PartialContainer.CurrentTypeParameters.Types;
return PartialContainer.type_params.Select (l => l.Type).ToArray ();
} }
} }
@ -1105,21 +1113,64 @@ namespace Mono.CSharp
Parent.MemberCache.AddMember (spec); Parent.MemberCache.AddMember (spec);
if (IsGeneric) { if (IsGeneric) {
string[] param_names = new string[TypeParameters.Length]; var tparam_names = CreateTypeParameters ();
for (int i = 0; i < TypeParameters.Length; i++)
param_names [i] = TypeParameters[i].Name;
all_tp_builders = TypeBuilder.DefineGenericParameters (param_names); all_tp_builders = TypeBuilder.DefineGenericParameters (tparam_names);
int offset = CurrentTypeParametersStartIndex; if (CurrentTypeParameters != null)
for (int i = offset; i < all_tp_builders.Length; i++) { CurrentTypeParameters.Define (all_tp_builders, spec, CurrentTypeParametersStartIndex, this);
CurrentTypeParameters [i - offset].Define (all_tp_builders [i], spec);
}
} }
return true; return true;
} }
string[] CreateTypeParameters ()
{
string[] names;
int parent_offset = 0;
var parent_all = Parent.all_type_parameters;
if (parent_all != null) {
if (CurrentTypeParameters == null) {
all_type_parameters = Parent.all_type_parameters;
return Parent.all_tp_builders.Select (l => l.Name).ToArray ();
}
names = new string[parent_all.Count + CurrentTypeParameters.Count];
all_type_parameters = new TypeParameters (names.Length);
all_type_parameters.Add (Parent.all_type_parameters);
parent_offset = all_type_parameters.Count;
for (int i = 0; i < parent_offset; ++i)
names[i] = all_type_parameters[i].MemberName.Name;
} else {
names = new string[CurrentTypeParameters.Count];
}
for (int i = 0; i < CurrentTypeParameters.Count; ++i) {
if (all_type_parameters != null)
all_type_parameters.Add (MemberName.TypeParameters[i]);
var name = CurrentTypeParameters[i].MemberName.Name;
names[parent_offset + i] = name;
for (int ii = 0; ii < parent_offset + i; ++ii) {
if (names[ii] != name)
continue;
var tp = CurrentTypeParameters[i];
var conflict = all_type_parameters[ii];
tp.WarningParentNameConflict (conflict);
}
}
if (all_type_parameters == null)
all_type_parameters = CurrentTypeParameters;
return names;
}
// //
// Creates a proxy base method call inside this container for hoisted base member calls // Creates a proxy base method call inside this container for hoisted base member calls
// //
@ -1161,18 +1212,20 @@ namespace Mono.CSharp
// Copy all base generic method type parameters info // Copy all base generic method type parameters info
// //
var hoisted_tparams = method.GenericDefinition.TypeParameters; var hoisted_tparams = method.GenericDefinition.TypeParameters;
var type_params = new TypeParameter[hoisted_tparams.Length]; var tparams = new TypeParameters ();
targs = new TypeArguments (); targs = new TypeArguments ();
targs.Arguments = new TypeSpec[type_params.Length]; targs.Arguments = new TypeSpec[hoisted_tparams.Length];
for (int i = 0; i < type_params.Length; ++i) { for (int i = 0; i < hoisted_tparams.Length; ++i) {
var tp = hoisted_tparams[i]; var tp = hoisted_tparams[i];
targs.Add (new TypeParameterName (tp.Name, null, Location)); tparams.Add (new TypeParameter (tp, this, null, new MemberName (tp.Name, Location), null));
targs.Add (new SimpleName (tp.Name, Location));
targs.Arguments[i] = tp; targs.Arguments[i] = tp;
type_params[i] = new TypeParameter (tp, this, null, new MemberName (tp.Name), null);
} }
member_name = new MemberName (name, targs, Location); member_name = new MemberName (name, tparams, Location);
generic_method = new GenericMethod (NamespaceEntry, this, member_name, type_params, generic_method = new GenericMethod (NamespaceEntry, this, member_name,
new TypeExpression (method.ReturnType, Location), cloned_params); new TypeExpression (method.ReturnType, Location), cloned_params);
} else { } else {
member_name = new MemberName (name); member_name = new MemberName (name);
@ -1345,6 +1398,8 @@ namespace Mono.CSharp
part.spec = spec; part.spec = spec;
part.current_type = current_type; part.current_type = current_type;
part.TypeBuilder = TypeBuilder; part.TypeBuilder = TypeBuilder;
part.all_type_parameters = all_type_parameters;
part.all_tp_builders = all_tp_builders;
} }
} }
@ -1366,9 +1421,13 @@ namespace Mono.CSharp
type_defined = true; type_defined = true;
// TODO: Driver resolves only first level of namespace, do the rest here for now // Nested type share same namespace
if (IsTopLevel && (ModFlags & Modifiers.COMPILER_GENERATED) == 0) { if (IsTopLevel && !IsCompilerGenerated) {
NamespaceEntry.Resolve (); NamespaceEntry.Define ();
if (partial_parts != null) {
foreach (var part in partial_parts)
part.NamespaceEntry.Define ();
}
} }
if (!DefineBaseTypes ()) { if (!DefineBaseTypes ()) {
@ -1389,16 +1448,17 @@ namespace Mono.CSharp
if (PartialContainer.CurrentTypeParameters == null || PartialContainer == this) if (PartialContainer.CurrentTypeParameters == null || PartialContainer == this)
return; return;
TypeParameter[] tc_names = PartialContainer.CurrentTypeParameters; var tc_names = PartialContainer.CurrentTypeParameters;
for (int i = 0; i < tc_names.Length; ++i) { for (int i = 0; i < tc_names.Count; ++i) {
if (tc_names [i].Name != type_params [i].Name) { var tp = MemberName.TypeParameters[i];
if (tc_names[i].MemberName.Name != tp.MemberName.Name) {
Report.SymbolRelatedToPreviousError (PartialContainer.Location, ""); Report.SymbolRelatedToPreviousError (PartialContainer.Location, "");
Report.Error (264, Location, "Partial declarations of `{0}' must have the same type parameter names in the same order", Report.Error (264, Location, "Partial declarations of `{0}' must have the same type parameter names in the same order",
GetSignatureForError ()); GetSignatureForError ());
break; break;
} }
if (tc_names [i].Variance != type_params [i].Variance) { if (tc_names[i].Variance != tp.Variance) {
Report.SymbolRelatedToPreviousError (PartialContainer.Location, ""); Report.SymbolRelatedToPreviousError (PartialContainer.Location, "");
Report.Error (1067, Location, "Partial declarations of `{0}' must have the same type parameter variance modifiers", Report.Error (1067, Location, "Partial declarations of `{0}' must have the same type parameter variance modifiers",
GetSignatureForError ()); GetSignatureForError ());
@ -1431,15 +1491,14 @@ namespace Mono.CSharp
void UpdateTypeParameterConstraints (TypeContainer part) void UpdateTypeParameterConstraints (TypeContainer part)
{ {
TypeParameter[] current_params = type_params; for (int i = 0; i < CurrentTypeParameters.Count; i++) {
for (int i = 0; i < current_params.Length; i++) { if (CurrentTypeParameters[i].AddPartialConstraints (part, part.MemberName.TypeParameters[i]))
if (current_params [i].AddPartialConstraints (part, part.type_params [i]))
continue; continue;
Report.SymbolRelatedToPreviousError (Location, ""); Report.SymbolRelatedToPreviousError (Location, "");
Report.Error (265, part.Location, Report.Error (265, part.Location,
"Partial declarations of `{0}' have inconsistent constraints for type parameter `{1}'", "Partial declarations of `{0}' have inconsistent constraints for type parameter `{1}'",
GetSignatureForError (), current_params [i].GetSignatureForError ()); GetSignatureForError (), CurrentTypeParameters[i].GetSignatureForError ());
} }
} }
@ -1465,15 +1524,18 @@ namespace Mono.CSharp
protected virtual bool DoResolveTypeParameters () protected virtual bool DoResolveTypeParameters ()
{ {
if (CurrentTypeParameters == null) var tparams = CurrentTypeParameters;
if (tparams == null)
return true; return true;
if (PartialContainer != this) if (PartialContainer != this)
throw new InternalErrorException (); throw new InternalErrorException ();
var base_context = new BaseContext (this); var base_context = new BaseContext (this);
foreach (TypeParameter type_param in CurrentTypeParameters) { for (int i = 0; i < tparams.Count; ++i) {
if (!type_param.ResolveConstraints (base_context)) { var tp = tparams[i];
if (!tp.ResolveConstraints (base_context)) {
error = true; error = true;
return false; return false;
} }
@ -1892,7 +1954,7 @@ namespace Mono.CSharp
int current_starts_index = CurrentTypeParametersStartIndex; int current_starts_index = CurrentTypeParametersStartIndex;
for (int i = 0; i < all_tp_builders.Length; i++) { for (int i = 0; i < all_tp_builders.Length; i++) {
if (i < current_starts_index) { if (i < current_starts_index) {
TypeParameters[i].EmitConstraints (all_tp_builders [i]); all_type_parameters[i].EmitConstraints (all_tp_builders [i]);
} else { } else {
var tp = CurrentTypeParameters [i - current_starts_index]; var tp = CurrentTypeParameters [i - current_starts_index];
tp.CheckGenericConstraints (!IsObsolete); tp.CheckGenericConstraints (!IsObsolete);
@ -2238,9 +2300,9 @@ namespace Mono.CSharp
e = null; e = null;
if (arity == 0) { if (arity == 0) {
TypeParameter[] tp = CurrentTypeParameters; var tp = CurrentTypeParameters;
if (tp != null) { if (tp != null) {
TypeParameter tparam = TypeParameter.FindTypeParameter (tp, name); TypeParameter tparam = tp.Find (name);
if (tparam != null) if (tparam != null)
e = new TypeParameterExpr (tparam, Location.Null); e = new TypeParameterExpr (tparam, Location.Null);
} }
@ -2424,9 +2486,8 @@ namespace Mono.CSharp
} }
Constructor c = new Constructor (this, MemberName.Name, mods, Constructor c = new Constructor (this, MemberName.Name, mods,
null, ParametersCompiled.EmptyReadOnlyParameters, null, ParametersCompiled.EmptyReadOnlyParameters, Location);
new GeneratedBaseInitializer (Location), c.Initializer = new GeneratedBaseInitializer (Location);
Location);
AddConstructor (c); AddConstructor (c);
c.Block = new ToplevelBlock (Compiler, ParametersCompiled.EmptyReadOnlyParameters, Location); c.Block = new ToplevelBlock (Compiler, ParametersCompiled.EmptyReadOnlyParameters, Location);
@ -3068,7 +3129,7 @@ namespace Mono.CSharp
name, attrs) name, attrs)
{ {
IsInterface = parent.PartialContainer.Kind == MemberKind.Interface; IsInterface = parent.PartialContainer.Kind == MemberKind.Interface;
IsExplicitImpl = (MemberName.Left != null); IsExplicitImpl = (MemberName.ExplicitInterface != null);
explicit_mod_flags = mod; explicit_mod_flags = mod;
} }
@ -3291,7 +3352,7 @@ namespace Mono.CSharp
} }
if (IsExplicitImpl) { if (IsExplicitImpl) {
InterfaceType = MemberName.Left.GetTypeExpression ().ResolveAsType (Parent); InterfaceType = MemberName.ExplicitInterface.ResolveAsType (Parent);
if (InterfaceType == null) if (InterfaceType == null)
return false; return false;
@ -3428,7 +3489,6 @@ namespace Mono.CSharp
// //
public string ShortName { public string ShortName {
get { return MemberName.Name; } get { return MemberName.Name; }
set { SetMemberName (new MemberName (MemberName.Left, value, Location)); }
} }
// //

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

@ -112,8 +112,8 @@ namespace Mono.CSharp
get { return member_context.CurrentType; } get { return member_context.CurrentType; }
} }
public TypeParameter[] CurrentTypeParameters { public TypeParameters CurrentTypeParameters {
get { return member_context.CurrentTypeParameters; } get { return member_context.CurrentTypeParameters; }
} }
public MemberCore CurrentTypeDefinition { public MemberCore CurrentTypeDefinition {
@ -238,7 +238,7 @@ namespace Mono.CSharp
{ {
if (dynamic_site_container == null) { if (dynamic_site_container == null) {
var mc = member_context.CurrentMemberDefinition as MemberBase; var mc = member_context.CurrentMemberDefinition as MemberBase;
dynamic_site_container = new DynamicSiteClass (CurrentTypeDefinition.Parent.PartialContainer, mc, CurrentTypeParameters); dynamic_site_container = new DynamicSiteClass (CurrentTypeDefinition.Parent.PartialContainer, mc, member_context.CurrentTypeParameters);
CurrentTypeDefinition.Module.AddCompilerGeneratedClass (dynamic_site_container); CurrentTypeDefinition.Module.AddCompilerGeneratedClass (dynamic_site_container);
dynamic_site_container.CreateType (); dynamic_site_container.CreateType ();

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

@ -37,7 +37,7 @@ namespace Mono.CSharp
// //
// A scope type parameters either VAR or MVAR // A scope type parameters either VAR or MVAR
// //
TypeParameter[] CurrentTypeParameters { get; } TypeParameters CurrentTypeParameters { get; }
// //
// A member definition of the context. For partial types definition use // A member definition of the context. For partial types definition use
@ -393,7 +393,7 @@ namespace Mono.CSharp
get { return MemberContext.CurrentType; } get { return MemberContext.CurrentType; }
} }
public TypeParameter[] CurrentTypeParameters { public TypeParameters CurrentTypeParameters {
get { return MemberContext.CurrentTypeParameters; } get { return MemberContext.CurrentTypeParameters; }
} }

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

File diff suppressed because it is too large Load Diff

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

@ -428,19 +428,26 @@ extern_alias_directive
{ {
var lt = (Tokenizer.LocatedToken) $2; var lt = (Tokenizer.LocatedToken) $2;
string s = lt.Value; string s = lt.Value;
if (s != "alias"){ if (s != "alias") {
syntax_error (lt.Location, "`alias' expected"); syntax_error (lt.Location, "`alias' expected");
} else if (lang_version == LanguageVersion.ISO_1) {
FeatureIsNotAvailable (lt.Location, "external alias");
} else { } else {
lt = (Tokenizer.LocatedToken) $3; if (lang_version == LanguageVersion.ISO_1)
current_namespace.AddUsingExternalAlias (lt.Value, lt.Location, report); FeatureIsNotAvailable (lt.Location, "external alias");
ubag.AddExternAlias (GetLocation ($1), GetLocation ($2), lt, GetLocation ($4));
lt = (Tokenizer.LocatedToken) $3;
if (lt.Value == QualifiedAliasMember.GlobalAlias) {
RootNamespace.Error_GlobalNamespaceRedefined (report, lt.Location);
}
var na = new UsingExternAlias (new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1));
current_namespace.AddUsing (na);
lbag.AddLocation (na, GetLocation ($2), GetLocation ($4));
} }
} }
| EXTERN_ALIAS error | EXTERN_ALIAS error
{ {
syntax_error (GetLocation ($1), "`alias' expected"); // TODO: better Error_SyntaxError (yyToken);
} }
; ;
@ -450,20 +457,23 @@ using_directives
; ;
using_directive using_directive
: using_alias_directive : using_namespace
{
if (doc_support)
Lexer.doc_state = XmlCommentState.Allowed;
}
| using_namespace_directive
{ {
if (doc_support) if (doc_support)
Lexer.doc_state = XmlCommentState.Allowed; Lexer.doc_state = XmlCommentState.Allowed;
} }
; ;
using_alias_directive using_namespace
: USING IDENTIFIER ASSIGN namespace_or_type_name SEMICOLON : USING namespace_or_type_expr SEMICOLON
{
var un = new UsingNamespace ((ATypeNameExpression) $2, GetLocation ($1));
current_namespace.AddUsing (un);
ubag.AddUsing (GetLocation ($1), (ATypeNameExpression) $2, GetLocation ($3));
lbag.AddLocation (un, GetLocation ($3));
}
| USING IDENTIFIER ASSIGN namespace_or_type_expr SEMICOLON
{ {
var lt = (Tokenizer.LocatedToken) $2; var lt = (Tokenizer.LocatedToken) $2;
if (lang_version != LanguageVersion.ISO_1 && lt.Value == "global") { if (lang_version != LanguageVersion.ISO_1 && lt.Value == "global") {
@ -471,22 +481,17 @@ using_alias_directive
"An alias named `global' will not be used when resolving `global::'. The global namespace will be used instead"); "An alias named `global' will not be used when resolving `global::'. The global namespace will be used instead");
} }
current_namespace.AddUsingAlias (lt.Value, (MemberName) $4, GetLocation ($1)); var un = new UsingAliasNamespace (new SimpleMemberName (lt.Value, lt.Location), (ATypeNameExpression) $4, GetLocation ($1));
ubag.AddUsingAlias (GetLocation ($1), lt, GetLocation ($3), (MemberName) $4, GetLocation ($5)); current_namespace.AddUsing (un);
} ubag.AddUsingAlias (GetLocation ($1), lt, GetLocation ($3), (ATypeNameExpression) $4, GetLocation ($5));
lbag.AddLocation (un, GetLocation ($3), GetLocation ($5));
}
| USING error | USING error
{ {
Error_SyntaxError (yyToken); Error_SyntaxError (yyToken);
$$ = null; $$ = null;
} }
;
using_namespace_directive
: USING namespace_name SEMICOLON
{
current_namespace.AddUsing ((MemberName) $2, GetLocation ($1));
ubag.AddUsing (GetLocation ($1), (MemberName) $2, GetLocation ($3));
}
; ;
// //
@ -495,10 +500,10 @@ using_namespace_directive
// detach them // detach them
// //
namespace_declaration namespace_declaration
: opt_attributes NAMESPACE qualified_identifier : opt_attributes NAMESPACE namespace_name
{ {
Attributes attrs = (Attributes) $1; Attributes attrs = (Attributes) $1;
MemberName name = (MemberName) $3; var name = (MemberName) $3;
if (attrs != null) { if (attrs != null) {
bool valid_global_attrs = true; bool valid_global_attrs = true;
if ((current_namespace.DeclarationFound || current_namespace != file.NamespaceContainer)) { if ((current_namespace.DeclarationFound || current_namespace != file.NamespaceContainer)) {
@ -545,13 +550,13 @@ namespace_declaration
} }
; ;
qualified_identifier namespace_name
: IDENTIFIER : IDENTIFIER
{ {
var lt = (Tokenizer.LocatedToken) $1; var lt = (Tokenizer.LocatedToken) $1;
$$ = new MemberName (lt.Value, lt.Location); $$ = new MemberName (lt.Value, lt.Location);
} }
| qualified_identifier DOT IDENTIFIER | namespace_name DOT IDENTIFIER
{ {
var lt = (Tokenizer.LocatedToken) $3; var lt = (Tokenizer.LocatedToken) $3;
$$ = new MemberName ((MemberName) $1, lt.Value, lt.Location) { $$ = new MemberName ((MemberName) $1, lt.Value, lt.Location) {
@ -575,18 +580,6 @@ opt_comma
| COMMA | COMMA
; ;
namespace_name
: namespace_or_type_name
{
MemberName name = (MemberName) $1;
if (name.TypeArguments != null)
syntax_error (lexer.Location, "namespace name expected");
$$ = name;
}
;
opt_using_directives opt_using_directives
: /* empty */ : /* empty */
| using_directives | using_directives
@ -776,26 +769,18 @@ attribute
opt_attribute_arguments opt_attribute_arguments
{ {
--lexer.parsing_block; --lexer.parsing_block;
MemberName mname = (MemberName) $1;
if (mname.IsGeneric) { var tne = (ATypeNameExpression) $1;
report.Error (404, lexer.Location, if (tne.HasTypeArguments) {
"'<' unexpected: attributes cannot be generic"); report.Error (404, tne.Location, "Attributes cannot be generic");
} }
Arguments [] arguments = (Arguments []) $3; $$ = new Attribute (current_attr_target, tne, (Arguments[]) $3, GetLocation ($1), lexer.IsEscapedIdentifier (tne));
ATypeNameExpression expr = mname.GetTypeExpression ();
$$ = new Attribute (current_attr_target, expr, arguments, mname.Location, lexer.IsEscapedIdentifier (mname));
if (arguments != null) {
attributeArgumentCommas.Insert (0, savedAttrParenOpenLocation);
attributeArgumentCommas.Add (savedAttrParenCloseLocation);
lbag.AddLocation ($$, attributeArgumentCommas);
attributeArgumentCommas.Clear ();
}
} }
; ;
attribute_name attribute_name
: namespace_or_type_name : namespace_or_type_expr
; ;
opt_attribute_arguments opt_attribute_arguments
@ -1293,7 +1278,7 @@ method_header
current_local_parameters = (ParametersCompiled) $7; current_local_parameters = (ParametersCompiled) $7;
GenericMethod generic = null; GenericMethod generic = null;
if (name.TypeArguments != null) { if (name.TypeParameters != null) {
generic = new GenericMethod (current_namespace, current_class, name, generic = new GenericMethod (current_namespace, current_class, name,
(FullNamedExpression) $3, current_local_parameters); (FullNamedExpression) $3, current_local_parameters);
@ -1337,12 +1322,12 @@ method_header
MemberName name = (MemberName) $6; MemberName name = (MemberName) $6;
current_local_parameters = (ParametersCompiled) $9; current_local_parameters = (ParametersCompiled) $9;
if ($11 != null && name.TypeArguments == null) if ($11 != null && name.TypeParameters == null)
report.Error (80, lexer.Location, report.Error (80, lexer.Location,
"Constraints are not allowed on non-generic declarations"); "Constraints are not allowed on non-generic declarations");
GenericMethod generic = null; GenericMethod generic = null;
if (name.TypeArguments != null) { if (name.TypeParameters != null) {
generic = new GenericMethod (current_namespace, current_class, name, generic = new GenericMethod (current_namespace, current_class, name,
new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($4)), new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($4)),
current_local_parameters); current_local_parameters);
@ -2208,23 +2193,12 @@ constructor_declarator
OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
{ {
valid_param_mod = 0; valid_param_mod = 0;
current_local_parameters = (ParametersCompiled) $6; current_local_parameters = (ParametersCompiled) $6;
//
// start block here, so possible anonymous methods inside
// constructor initializer can get correct parent block
//
start_block (lexer.Location);
}
opt_constructor_initializer
{
var lt = (Tokenizer.LocatedToken) $3; var lt = (Tokenizer.LocatedToken) $3;
var mods = (Modifiers) $2; var mods = (Modifiers) $2;
ConstructorInitializer ci = (ConstructorInitializer) $9; var c = new Constructor (current_class, lt.Value, mods, (Attributes) $1, current_local_parameters, lt.Location);
Constructor c = new Constructor (current_class, lt.Value, mods,
(Attributes) $1, current_local_parameters, ci, lt.Location);
if (lt.Value != current_container.MemberName.Name) { if (lt.Value != current_container.MemberName.Name) {
report.Error (1520, c.Location, "Class, struct, or interface method must have a return type"); report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
} else if ((mods & Modifiers.STATIC) != 0) { } else if ((mods & Modifiers.STATIC) != 0) {
@ -2233,16 +2207,32 @@ constructor_declarator
"`{0}': static constructor cannot have an access modifier", "`{0}': static constructor cannot have an access modifier",
c.GetSignatureForError ()); c.GetSignatureForError ());
} }
if (ci != null) { }
lbag.AddMember (c, mod_locations, GetLocation ($5), GetLocation ($7));
$$ = c;
//
// start block here, so possible anonymous methods inside
// constructor initializer can get correct parent block
//
start_block (lexer.Location);
}
opt_constructor_initializer
{
if ($9 != null) {
var c = (Constructor) $8;
c.Initializer = (ConstructorInitializer) $9;
if (c.IsStatic) {
report.Error (514, c.Location, report.Error (514, c.Location,
"`{0}': static constructor cannot have an explicit `this' or `base' constructor call", "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
c.GetSignatureForError ()); c.GetSignatureForError ());
} }
} }
lbag.AddMember (c, GetModifierLocations (), GetLocation ($5), GetLocation ($7)); lbag.AddMember (c, GetModifierLocations (), GetLocation ($5), GetLocation ($7));
$$ = c; $$ = $8;
} }
; ;
@ -2324,7 +2314,7 @@ event_declaration
current_event_field = new EventField (current_class, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1); current_event_field = new EventField (current_class, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
current_container.AddEvent (current_event_field); current_container.AddEvent (current_event_field);
if (current_event_field.MemberName.Left != null) { if (current_event_field.MemberName.ExplicitInterface != null) {
report.Error (71, current_event_field.Location, "`{0}': An explicit interface implementation of an event must use property syntax", report.Error (71, current_event_field.Location, "`{0}': An explicit interface implementation of an event must use property syntax",
current_event_field.GetSignatureForError ()); current_event_field.GetSignatureForError ());
} }
@ -2709,33 +2699,33 @@ opt_nullable
} }
; ;
namespace_or_type_name namespace_or_type_expr
: member_name : member_name
| qualified_alias_member IDENTIFIER opt_type_argument_list | qualified_alias_member IDENTIFIER opt_type_argument_list
{ {
var lt1 = (Tokenizer.LocatedToken) $1; var lt1 = (Tokenizer.LocatedToken) $1;
var lt2 = (Tokenizer.LocatedToken) $2; var lt2 = (Tokenizer.LocatedToken) $2;
$$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location); $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
lbag.AddLocation ($$, GetLocation ($2));
} }
; ;
member_name member_name
: type_name : simple_name_expr
| namespace_or_type_name DOT IDENTIFIER opt_type_argument_list | namespace_or_type_expr DOT IDENTIFIER opt_type_argument_list
{ {
var lt = (Tokenizer.LocatedToken) $3; var lt = (Tokenizer.LocatedToken) $3;
$$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $4, lt.Location) { $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
DotLocation = GetLocation ($2) lbag.AddLocation ($$, GetLocation ($2));
};
} }
; ;
type_name simple_name_expr
: IDENTIFIER opt_type_argument_list : IDENTIFIER opt_type_argument_list
{ {
var lt = (Tokenizer.LocatedToken) $1; var lt = (Tokenizer.LocatedToken) $1;
$$ = new MemberName (lt.Value, (TypeArguments)$2, lt.Location); $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
} }
; ;
@ -2791,7 +2781,7 @@ type_declaration_name
{ {
lexer.parsing_generic_declaration = false; lexer.parsing_generic_declaration = false;
var lt = (Tokenizer.LocatedToken) $1; var lt = (Tokenizer.LocatedToken) $1;
$$ = new MemberName (lt.Value, (TypeArguments)$3, lt.Location); $$ = new MemberName (lt.Value, (TypeParameters)$3, lt.Location);
} }
; ;
@ -2799,7 +2789,7 @@ member_declaration_name
: method_declaration_name : method_declaration_name
{ {
MemberName mn = (MemberName)$1; MemberName mn = (MemberName)$1;
if (mn.TypeArguments != null) if (mn.TypeParameters != null)
syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments", syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
mn.GetSignatureForError ())); mn.GetSignatureForError ()));
} }
@ -2811,7 +2801,7 @@ method_declaration_name
{ {
lexer.parsing_generic_declaration = false; lexer.parsing_generic_declaration = false;
var lt = (Tokenizer.LocatedToken) $2; var lt = (Tokenizer.LocatedToken) $2;
$$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location); $$ = new MemberName (lt.Value, (TypeParameters) $3, (ATypeNameExpression) $1, lt.Location);
} }
; ;
@ -2824,7 +2814,7 @@ indexer_declaration_name
| explicit_interface THIS | explicit_interface THIS
{ {
lexer.parsing_generic_declaration = false; lexer.parsing_generic_declaration = false;
$$ = new MemberName ((MemberName) $1, TypeContainer.DefaultIndexerName, null, GetLocation ($2)); $$ = new MemberName (TypeContainer.DefaultIndexerName, null, (ATypeNameExpression) $1, GetLocation ($2));
} }
; ;
@ -2832,21 +2822,21 @@ explicit_interface
: IDENTIFIER opt_type_argument_list DOT : IDENTIFIER opt_type_argument_list DOT
{ {
var lt = (Tokenizer.LocatedToken) $1; var lt = (Tokenizer.LocatedToken) $1;
$$ = new MemberName (lt.Value, (TypeArguments) $2, lt.Location); $$ = new SimpleName (lt.Value, (TypeArguments) $2, lt.Location);
lbag.AddLocation ($$, GetLocation ($3)); lbag.AddLocation ($$, GetLocation ($3));
} }
| qualified_alias_member IDENTIFIER opt_type_argument_list DOT | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
{ {
var lt1 = (Tokenizer.LocatedToken) $1; var lt1 = (Tokenizer.LocatedToken) $1;
var lt2 = (Tokenizer.LocatedToken) $2; var lt2 = (Tokenizer.LocatedToken) $2;
$$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location); $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
lbag.AddLocation ($$, GetLocation ($4)); lbag.AddLocation ($$, GetLocation ($4));
} }
| explicit_interface IDENTIFIER opt_type_argument_list DOT | explicit_interface IDENTIFIER opt_type_argument_list DOT
{ {
var lt = (Tokenizer.LocatedToken) $2; var lt = (Tokenizer.LocatedToken) $2;
$$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location); $$ = new MemberAccess ((ATypeNameExpression) $1, lt.Value, (TypeArguments) $3, lt.Location);
lbag.AddLocation ($$, GetLocation ($4)); lbag.AddLocation ($$, GetLocation ($4));
} }
; ;
@ -2866,16 +2856,16 @@ opt_type_parameter_list
type_parameters type_parameters
: type_parameter : type_parameter
{ {
TypeArguments type_args = new TypeArguments (); var tparams = new TypeParameters ();
type_args.Add ((FullNamedExpression)$1); tparams.Add ((TypeParameter)$1);
$$ = type_args; $$ = tparams;
} }
| type_parameters COMMA type_parameter | type_parameters COMMA type_parameter
{ {
TypeArguments type_args = (TypeArguments) $1; var tparams = (TypeParameters) $1;
type_args.Add ((FullNamedExpression)$3); tparams.Add ((TypeParameter)$3);
$$ = type_args; $$ = tparams;
lbag.AppendTo (type_args, GetLocation ($2)); lbag.AddLocation ($3, GetLocation ($3));
} }
; ;
@ -2883,10 +2873,7 @@ type_parameter
: opt_attributes opt_type_parameter_variance IDENTIFIER : opt_attributes opt_type_parameter_variance IDENTIFIER
{ {
var lt = (Tokenizer.LocatedToken)$3; var lt = (Tokenizer.LocatedToken)$3;
var variance = (Variance) $2; $$ = new TypeParameter (new MemberName (lt.Value, lt.Location), (Attributes)$1, (Variance) $2);
$$ = new TypeParameterName (lt.Value, (Attributes)$1, variance, lt.Location);
if (variance != Variance.None)
lbag.AddLocation ($$, savedLocation);
} }
| error | error
{ {
@ -2895,7 +2882,7 @@ type_parameter
else else
Error_SyntaxError (yyToken); Error_SyntaxError (yyToken);
$$ = new TypeParameterName ("", null, lexer.Location); $$ = new TypeParameter (MemberName.Null, null, Variance.None);
} }
; ;
@ -2956,22 +2943,21 @@ type_expression_or_array
; ;
type_expression type_expression
: namespace_or_type_name opt_nullable : namespace_or_type_expr opt_nullable
{ {
MemberName name = (MemberName) $1;
if ($2 != null) { if ($2 != null) {
$$ = new ComposedCast (name.GetTypeExpression (), (ComposedTypeSpecifier) $2); $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
} else { } else {
if (name.Left == null && name.Name == "var") var sn = $1 as SimpleName;
$$ = new VarExpr (name.Location); if (sn != null && sn.Name == "var")
$$ = new VarExpr (sn.Location);
else else
$$ = name.GetTypeExpression (); $$ = $1;
} }
} }
| namespace_or_type_name pointer_stars | namespace_or_type_expr pointer_stars
{ {
$$ = new ComposedCast (((MemberName) $1).GetTypeExpression (), (ComposedTypeSpecifier) $2); $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
} }
| builtin_types opt_nullable | builtin_types opt_nullable
{ {
@ -3736,16 +3722,16 @@ unbound_type_name
DotLocation = GetLocation ($2) DotLocation = GetLocation ($2)
}; };
} }
| namespace_or_type_name DOT identifier_inside_body generic_dimension | namespace_or_type_expr DOT identifier_inside_body generic_dimension
{ {
var te = ((MemberName) $1).GetTypeExpression (); var tne = (ATypeNameExpression) $1;
if (te.HasTypeArguments) if (tne.HasTypeArguments)
Error_TypeExpected (GetLocation ($4)); Error_TypeExpected (GetLocation ($4));
var lt = (Tokenizer.LocatedToken) $3; var lt = (Tokenizer.LocatedToken) $3;
$$ = new MemberAccess (te, lt.Value, (int) $4, lt.Location) { $$ = new MemberAccess (tne, lt.Value, (int) $4, lt.Location) {
DotLocation = GetLocation ($2) DotLocation = GetLocation ($2)
}; };
} }
; ;
@ -5103,7 +5089,7 @@ statement_expression
ExpressionStatement s = $1 as ExpressionStatement; ExpressionStatement s = $1 as ExpressionStatement;
if (s == null) { if (s == null) {
Expression.Error_InvalidExpressionStatement (report, GetLocation ($1)); Expression.Error_InvalidExpressionStatement (report, GetLocation ($1));
$$ = new InvalidStatementExpression ($1 as Expression); $$ = new StatementErrorExpression ($1 as Expression);
} else { } else {
$$ = new StatementExpression (s); $$ = new StatementExpression (s);
} }
@ -5152,9 +5138,10 @@ if_statement
if ($7 is EmptyStatement) if ($7 is EmptyStatement)
Warning_EmptyStatement (GetLocation ($7)); Warning_EmptyStatement (GetLocation ($7));
} }
| IF open_parens_any boolean_expression error { | IF open_parens_any boolean_expression error
var eloc = GetLocation ($3); {
report.Error (1026, eloc, "Expected a ')'"); Error_SyntaxError (yyToken);
$$ = new If ((BooleanExpression) $3, null, GetLocation ($1)); $$ = new If ((BooleanExpression) $3, null, GetLocation ($1));
lbag.AddStatement ($$, GetLocation ($2)); lbag.AddStatement ($$, GetLocation ($2));
} }
@ -5171,6 +5158,13 @@ switch_statement
end_block (GetLocation ($8)); end_block (GetLocation ($8));
lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($5), GetLocation ($8)); lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($5), GetLocation ($8));
} }
| SWITCH open_parens_any expression error
{
Error_SyntaxError (yyToken);
$$ = new Switch ((Expression) $3, null, null, GetLocation ($1));
lbag.AddStatement ($$, GetLocation ($2));
}
; ;
opt_switch_sections opt_switch_sections
@ -5199,7 +5193,7 @@ switch_sections
} }
| error | error
{ {
Error_SyntaxError (yyToken); Error_SyntaxError (yyToken);
$$ = new List<SwitchSection> (); $$ = new List<SwitchSection> ();
} }
; ;
@ -5260,24 +5254,30 @@ while_statement
$$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1)); $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4)); lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
} }
| WHILE open_parens_any boolean_expression error
{
Error_SyntaxError (yyToken);
$$ = new While ((BooleanExpression) $3, null, GetLocation ($1));
lbag.AddStatement ($$, GetLocation ($2));
}
; ;
do_statement do_statement
: DO embedded_statement : DO embedded_statement WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
{ {
$$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1)); $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1));
lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7)); lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
} }
| DO embedded_statement error | DO embedded_statement error
{ {
var loc = GetLocation ($1); Error_SyntaxError (yyToken);
report.Error (-100, loc, "Expected `while'"); $$ = new Do ((Statement) $2, null, GetLocation ($1));
$$ = new Do ((Statement) $2, null, loc);
} }
| DO embedded_statement | DO embedded_statement WHILE open_parens_any boolean_expression error
WHILE open_parens_any boolean_expression error
{ {
Error_SyntaxError (yyToken);
$$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1)); $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1));
lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4)); lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4));
} }
@ -5383,10 +5383,35 @@ statement_expression_list
; ;
foreach_statement foreach_statement
: FOREACH open_parens_any type IN expression CLOSE_PARENS : FOREACH open_parens_any type error
{ {
report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement"); report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
$$ = null;
start_block (GetLocation ($2));
current_block.IsCompilerGenerated = true;
Foreach f = new Foreach ((Expression) $3, null, null, null, GetLocation ($1));
current_block.AddStatement (f);
lbag.AddStatement (f, GetLocation ($2));
$$ = end_block (GetLocation ($4));
}
| FOREACH open_parens_any type identifier_inside_body error
{
Error_SyntaxError (yyToken);
start_block (GetLocation ($2));
current_block.IsCompilerGenerated = true;
var lt = (Tokenizer.LocatedToken) $4;
var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
current_block.AddLocalName (li);
Foreach f = new Foreach ((Expression) $3, li, null, null, GetLocation ($1));
current_block.AddStatement (f);
lbag.AddStatement (f, GetLocation ($2));
$$ = end_block (GetLocation ($5));
} }
| FOREACH open_parens_any type identifier_inside_body IN expression CLOSE_PARENS | FOREACH open_parens_any type identifier_inside_body IN expression CLOSE_PARENS
{ {
@ -5544,9 +5569,9 @@ try_statement
$$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), true), (Block) $5, GetLocation ($1)); $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), true), (Block) $5, GetLocation ($1));
lbag.AddStatement ($$, GetLocation ($4)); lbag.AddStatement ($$, GetLocation ($4));
} }
| TRY block error | TRY block error
{ {
report.Error (1524, GetLocation ($1), "Expected catch or finally"); Error_SyntaxError (1524, yyToken);
$$ = new TryCatch ((Block) $2, null, GetLocation ($1), false); $$ = new TryCatch ((Block) $2, null, GetLocation ($1), false);
} }
; ;
@ -5564,15 +5589,11 @@ catch_clauses
var l = (List<Catch>) $1; var l = (List<Catch>) $1;
Catch c = (Catch) $2; Catch c = (Catch) $2;
if (l [0].IsGeneral) { if (l [l.Count - 1].IsGeneral) {
report.Error (1017, c.loc, "Try statement already has an empty catch block"); report.Error (1017, c.loc, "Try statement already has an empty catch block");
} else {
if (c.IsGeneral)
l.Insert (0, c);
else
l.Add (c);
} }
l.Add (c);
$$ = l; $$ = l;
} }
; ;
@ -5652,6 +5673,13 @@ lock_statement
$$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1)); $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4)); lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
} }
| LOCK open_parens_any expression error
{
Error_SyntaxError (yyToken);
$$ = new Lock ((Expression) $3, null, GetLocation ($1));
lbag.AddStatement ($$, GetLocation ($2));
}
; ;
fixed_statement fixed_statement
@ -5713,9 +5741,15 @@ using_statement
if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE) if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
Warning_EmptyStatement (GetLocation ($5)); Warning_EmptyStatement (GetLocation ($5));
Using u = new Using ((Expression) $3, (Statement) $5, GetLocation ($1)); $$ = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
lbag.AddStatement (u, GetLocation ($2), GetLocation ($4)); lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
$$ = u; }
| USING open_parens_any expression error
{
Error_SyntaxError (yyToken);
$$ = new Using ((Expression) $3, null, GetLocation ($1));
lbag.AddStatement ($$, GetLocation ($2));
} }
; ;
@ -5959,7 +5993,7 @@ let_clause
var sn = new Linq.RangeVariable (lt.Value, lt.Location); var sn = new Linq.RangeVariable (lt.Value, lt.Location);
$$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1)); $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
lbag.AddLocation ($$, GetLocation ($3)); lbag.AddLocation ($$, GetLocation ($3));
current_block.SetEndLocation (lexer.Location); current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent; current_block = current_block.Parent;
@ -6332,7 +6366,7 @@ doc_cref
} }
| doc_type_declaration_name DOT THIS | doc_type_declaration_name DOT THIS
{ {
$$ = new MemberName ((MemberName) $1, new MemberName (MemberCache.IndexerNameAlias)); $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
} }
| doc_type_declaration_name DOT THIS OPEN_BRACKET | doc_type_declaration_name DOT THIS OPEN_BRACKET
{ {
@ -6341,7 +6375,7 @@ doc_cref
opt_doc_parameters CLOSE_BRACKET opt_doc_parameters CLOSE_BRACKET
{ {
module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$6; module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$6;
$$ = new MemberName ((MemberName) $1, new MemberName (MemberCache.IndexerNameAlias)); $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
} }
| EXPLICIT OPERATOR type opt_doc_method_sig | EXPLICIT OPERATOR type opt_doc_method_sig
{ {
@ -6522,11 +6556,9 @@ DeclSpace pop_current_class ()
MemberName MemberName
MakeName (MemberName class_name) MakeName (MemberName class_name)
{ {
Namespace ns = current_namespace.NS;
if (current_container == module) { if (current_container == module) {
if (ns.Name.Length != 0) if (current_namespace.MemberName != MemberName.Null)
return new MemberName (ns.MemberName, class_name); return new MemberName (current_namespace.NS.MemberName, class_name);
else else
return class_name; return class_name;
} else { } else {
@ -6747,12 +6779,12 @@ void start_anonymous (bool isLambda, ParametersCompiled parameters, bool isAsync
if (lang_version <= LanguageVersion.ISO_2) if (lang_version <= LanguageVersion.ISO_2)
FeatureIsNotAvailable (loc, "lambda expressions"); FeatureIsNotAvailable (loc, "lambda expressions");
current_anonymous_method = new LambdaExpression (isAsync, loc); current_anonymous_method = new LambdaExpression (loc);
} else { } else {
if (lang_version == LanguageVersion.ISO_1) if (lang_version == LanguageVersion.ISO_1)
FeatureIsNotAvailable (loc, "anonymous methods"); FeatureIsNotAvailable (loc, "anonymous methods");
current_anonymous_method = new AnonymousMethodExpression (isAsync, loc); current_anonymous_method = new AnonymousMethodExpression (loc);
} }
async_block = isAsync; async_block = isAsync;
@ -6784,7 +6816,12 @@ AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
void Error_SyntaxError (int token) void Error_SyntaxError (int token)
{ {
Error_SyntaxError (0, token, "Unexpected symbol"); Error_SyntaxError (0, token);
}
void Error_SyntaxError (int error_code, int token)
{
Error_SyntaxError (error_code, token, "Unexpected symbol");
} }
void Error_SyntaxError (int error_code, int token, string msg) void Error_SyntaxError (int error_code, int token, string msg)

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

@ -324,7 +324,7 @@ namespace Mono.CSharp
escaped_identifiers.Add (loc); escaped_identifiers.Add (loc);
} }
public bool IsEscapedIdentifier (MemberName name) public bool IsEscapedIdentifier (ATypeNameExpression name)
{ {
return escaped_identifiers != null && escaped_identifiers.Contains (name.Location); return escaped_identifiers != null && escaped_identifiers.Contains (name.Location);
} }

259
ICSharpCode.NRefactory.CSharp/Parser/mcs/decl.cs

@ -36,18 +36,20 @@ namespace Mono.CSharp {
// Better name would be DottenName // Better name would be DottenName
// //
[DebuggerDisplay ("{GetSignatureForError()}")] [DebuggerDisplay ("{GetSignatureForError()}")]
public class MemberName { public class MemberName
public readonly string Name; {
public TypeArguments TypeArguments; public static readonly MemberName Null = new MemberName ("");
public readonly MemberName Left; public readonly string Name;
public TypeParameters TypeParameters;
public readonly FullNamedExpression ExplicitInterface;
public readonly Location Location; public readonly Location Location;
public static readonly MemberName Null = new MemberName (""); public readonly MemberName Left;
bool is_double_colon; public MemberName (string name)
: this (name, Location.Null)
public bool IsDoubleColon { get { return is_double_colon; } } { }
#if FULL_AST #if FULL_AST
public Location DotLocation { public Location DotLocation {
@ -55,61 +57,43 @@ namespace Mono.CSharp {
set; set;
} }
#endif #endif
private MemberName (MemberName left, string name, bool is_double_colon, public MemberName (string name, Location loc)
Location loc) : this (null, name, loc)
{ }
public MemberName (string name, TypeParameters tparams, Location loc)
{ {
this.Name = name; this.Name = name;
this.Location = loc; this.Location = loc;
this.is_double_colon = is_double_colon;
this.Left = left; this.TypeParameters = tparams;
} }
private MemberName (MemberName left, string name, bool is_double_colon, public MemberName (string name, TypeParameters tparams, FullNamedExpression explicitInterface, Location loc)
TypeArguments args, Location loc) : this (name, tparams, loc)
: this (left, name, is_double_colon, loc)
{ {
if (args != null && args.Count > 0) this.ExplicitInterface = explicitInterface;
this.TypeArguments = args;
} }
public MemberName (string name)
: this (name, Location.Null)
{ }
public MemberName (string name, Location loc)
: this (null, name, false, loc)
{ }
public MemberName (string name, TypeArguments args, Location loc)
: this (null, name, false, args, loc)
{ }
public MemberName (MemberName left, string name)
: this (left, name, left != null ? left.Location : Location.Null)
{ }
public MemberName (MemberName left, string name, Location loc) public MemberName (MemberName left, string name, Location loc)
: this (left, name, false, loc) {
{ } this.Name = name;
this.Location = loc;
public MemberName (MemberName left, string name, TypeArguments args, Location loc) this.Left = left;
: this (left, name, false, args, loc) }
{ }
public MemberName (string alias, string name, TypeArguments args, Location loc) public MemberName (MemberName left, string name, FullNamedExpression explicitInterface, Location loc)
: this (new MemberName (alias, loc), name, true, args, loc) : this (left, name, loc)
{ } {
this.ExplicitInterface = explicitInterface;
}
public MemberName (MemberName left, MemberName right) public MemberName (MemberName left, MemberName right)
: this (left, right, right.Location)
{ }
public MemberName (MemberName left, MemberName right, Location loc)
: this (null, right.Name, false, right.TypeArguments, loc)
{ {
if (right.is_double_colon) this.Name = right.Name;
throw new InternalErrorException ("Cannot append double_colon member name"); this.Location = right.Location;
this.Left = (right.Left == null) ? left : new MemberName (left, right.Left); this.TypeParameters = right.TypeParameters;
this.Left = left;
} }
// TODO: Remove // TODO: Remove
@ -120,13 +104,13 @@ namespace Mono.CSharp {
public int Arity { public int Arity {
get { get {
return TypeArguments == null ? 0 : TypeArguments.Count; return TypeParameters == null ? 0 : TypeParameters.Count;
} }
} }
public bool IsGeneric { public bool IsGeneric {
get { get {
if (TypeArguments != null) if (TypeParameters != null)
return true; return true;
else if (Left != null) else if (Left != null)
return Left.IsGeneric; return Left.IsGeneric;
@ -139,55 +123,31 @@ namespace Mono.CSharp {
{ {
string name = is_generic ? Basename : Name; string name = is_generic ? Basename : Name;
if (Left != null) if (Left != null)
return Left.GetName (is_generic) + (is_double_colon ? "::" : ".") + name; return Left.GetName (is_generic) + "." + name;
return name; return name;
} }
public ATypeNameExpression GetTypeExpression ()
{
if (Left == null) {
if (TypeArguments != null)
return new SimpleName (Name, TypeArguments, Location);
return new SimpleName (Name, Location);
}
if (is_double_colon) {
if (Left.Left != null)
throw new InternalErrorException ("The left side of a :: should be an identifier");
return new QualifiedAliasMember (Left.Name, Name, TypeArguments, Location);
}
Expression lexpr = Left.GetTypeExpression ();
var result = new MemberAccess (lexpr, Name, TypeArguments, Location);
#if FULL_AST
result.DotLocation = DotLocation;
#endif
return result;
}
public MemberName Clone ()
{
MemberName left_clone = Left == null ? null : Left.Clone ();
return new MemberName (left_clone, Name, is_double_colon, TypeArguments, Location);
}
public string Basename { public string Basename {
get { get {
if (TypeArguments != null) if (TypeParameters != null)
return MakeName (Name, TypeArguments); return MakeName (Name, TypeParameters);
return Name; return Name;
} }
} }
public string GetSignatureForError () public string GetSignatureForError ()
{ {
string append = TypeArguments == null ? "" : "<" + TypeArguments.GetSignatureForError () + ">"; string s = TypeParameters == null ? null : "<" + TypeParameters.GetSignatureForError () + ">";
s = Name + s;
if (ExplicitInterface != null)
s = ExplicitInterface.GetSignatureForError () + "." + s;
if (Left == null) if (Left == null)
return Name + append; return s;
string connect = is_double_colon ? "::" : ".";
return Left.GetSignatureForError () + connect + Name + append; return Left.GetSignatureForError () + "." + s;
} }
public override bool Equals (object other) public override bool Equals (object other)
@ -201,14 +161,12 @@ namespace Mono.CSharp {
return true; return true;
if (other == null || Name != other.Name) if (other == null || Name != other.Name)
return false; return false;
if (is_double_colon != other.is_double_colon)
return false;
if ((TypeArguments != null) && if ((TypeParameters != null) &&
(other.TypeArguments == null || TypeArguments.Count != other.TypeArguments.Count)) (other.TypeParameters == null || TypeParameters.Count != other.TypeParameters.Count))
return false; return false;
if ((TypeArguments == null) && (other.TypeArguments != null)) if ((TypeParameters == null) && (other.TypeParameters != null))
return false; return false;
if (Left == null) if (Left == null)
@ -222,27 +180,14 @@ namespace Mono.CSharp {
int hash = Name.GetHashCode (); int hash = Name.GetHashCode ();
for (MemberName n = Left; n != null; n = n.Left) for (MemberName n = Left; n != null; n = n.Left)
hash ^= n.Name.GetHashCode (); hash ^= n.Name.GetHashCode ();
if (is_double_colon)
hash ^= 0xbadc01d;
if (TypeArguments != null) if (TypeParameters != null)
hash ^= TypeArguments.Count << 5; hash ^= TypeParameters.Count << 5;
return hash & 0x7FFFFFFF; return hash & 0x7FFFFFFF;
} }
public int CountTypeArguments { public static string MakeName (string name, TypeParameters args)
get {
if (TypeArguments != null)
return TypeArguments.Count;
else if (Left != null)
return Left.CountTypeArguments;
else
return 0;
}
}
public static string MakeName (string name, TypeArguments args)
{ {
if (args == null) if (args == null)
return name; return name;
@ -871,7 +816,7 @@ namespace Mono.CSharp {
get { return this; } get { return this; }
} }
public virtual TypeParameter[] CurrentTypeParameters { public virtual TypeParameters CurrentTypeParameters {
get { return null; } get { return null; }
} }
@ -1275,12 +1220,9 @@ namespace Mono.CSharp {
protected Dictionary<string, MemberCore> defined_names; protected Dictionary<string, MemberCore> defined_names;
public TypeContainer PartialContainer; public TypeContainer PartialContainer;
protected readonly bool is_generic; protected readonly bool is_generic;
readonly int count_type_params;
protected TypeParameter[] type_params;
TypeParameter[] type_param_list;
// //
// Whether we are Generic // Whether we are Generic
@ -1306,12 +1248,9 @@ namespace Mono.CSharp {
Basename = name.Basename; Basename = name.Basename;
defined_names = new Dictionary<string, MemberCore> (); defined_names = new Dictionary<string, MemberCore> ();
PartialContainer = null; PartialContainer = null;
if (name.TypeArguments != null) { if (name.TypeParameters != null) {
is_generic = true; is_generic = true;
count_type_params = name.TypeArguments.Count;
} }
if (parent != null)
count_type_params += parent.count_type_params;
} }
/// <summary> /// <summary>
@ -1407,45 +1346,7 @@ namespace Mono.CSharp {
{ {
return MemberName.GetSignatureForError (); return MemberName.GetSignatureForError ();
} }
TypeParameter[] initialize_type_params ()
{
if (type_param_list != null)
return type_param_list;
DeclSpace the_parent = Parent;
if (this is GenericMethod)
the_parent = null;
var list = new List<TypeParameter> ();
if (the_parent != null && the_parent.IsGeneric) {
// FIXME: move generics info out of DeclSpace
TypeParameter[] parent_params = the_parent.TypeParameters;
list.AddRange (parent_params);
}
int count = type_params != null ? type_params.Length : 0;
for (int i = 0; i < count; i++) {
TypeParameter param = type_params [i];
list.Add (param);
if (Parent.CurrentTypeParameters != null) {
foreach (TypeParameter tp in Parent.CurrentTypeParameters) {
if (tp.Name != param.Name)
continue;
Report.SymbolRelatedToPreviousError (tp.Location, null);
Report.Warning (693, 3, param.Location,
"Type parameter `{0}' has the same name as the type parameter from outer type `{1}'",
param.Name, Parent.GetSignatureForError ());
}
}
}
type_param_list = new TypeParameter [list.Count];
list.CopyTo (type_param_list, 0);
return type_param_list;
}
#if FULL_AST #if FULL_AST
public List<Constraints> PlainConstraints { public List<Constraints> PlainConstraints {
get; get;
@ -1467,7 +1368,6 @@ namespace Mono.CSharp {
} }
} }
#endif #endif
public List<Constraints> Constraints { public List<Constraints> Constraints {
get; get;
private set; private set;
@ -1493,27 +1393,24 @@ namespace Mono.CSharp {
return; return;
} }
TypeParameterName[] names = MemberName.TypeArguments.GetDeclarations ();
type_params = new TypeParameter [names.Length];
// //
// Register all the names // Register all the names
// //
for (int i = 0; i < type_params.Length; i++) { for (int i = 0; i < MemberName.TypeParameters.Count; i++) {
TypeParameterName name = names [i]; var name = MemberName.TypeParameters [i];
Constraints constraints = null; Constraints constraints = null;
if (constraints_list != null) { if (constraints_list != null) {
int total = constraints_list.Count; int total = constraints_list.Count;
for (int ii = 0; ii < total; ++ii) { for (int ii = 0; ii < total; ++ii) {
Constraints constraints_at = (Constraints)constraints_list[ii]; Constraints constraints_at = constraints_list[ii];
// TODO: it is used by iterators only // TODO: it is used by iterators only
if (constraints_at == null) { if (constraints_at == null) {
constraints_list.RemoveAt (ii); constraints_list.RemoveAt (ii);
--total; --total;
continue; continue;
} }
if (constraints_at.TypeParameter.Value == name.Name) { if (constraints_at.TypeParameter.Value == name.MemberName.Name) {
constraints = constraints_at; constraints = constraints_at;
constraints_list.RemoveAt(ii); constraints_list.RemoveAt(ii);
break; break;
@ -1521,16 +1418,13 @@ namespace Mono.CSharp {
} }
} }
Variance variance = name.Variance;
if (name.Variance != Variance.None && !(this is Delegate || this is Interface)) { if (name.Variance != Variance.None && !(this is Delegate || this is Interface)) {
Report.Error (1960, name.Location, "Variant type parameters can only be used with interfaces and delegates"); Report.Error (1960, name.Location, "Variant type parameters can only be used with interfaces and delegates");
variance = Variance.None;
} }
type_params [i] = new TypeParameter ( MemberName.TypeParameters[i].Constraints = constraints;
Parent, i, new MemberName (name.Name, Location), constraints, name.OptAttributes, variance); if (name.MemberName != null)
AddToContainer (name, name.MemberName.Name);
AddToContainer (type_params [i], name.Name);
} }
if (constraints_list != null && constraints_list.Count > 0) { if (constraints_list != null && constraints_list.Count > 0) {
@ -1541,25 +1435,6 @@ namespace Mono.CSharp {
} }
} }
protected TypeParameter[] TypeParameters {
get {
if (!IsGeneric)
throw new InvalidOperationException ();
if ((PartialContainer != null) && (PartialContainer != this))
return PartialContainer.TypeParameters;
if (type_param_list == null)
initialize_type_params ();
return type_param_list;
}
}
public int CountTypeParameters {
get {
return count_type_params;
}
}
public override string[] ValidAttributeTargets { public override string[] ValidAttributeTargets {
get { return attribute_targets; } get { return attribute_targets; }
} }
@ -1570,10 +1445,8 @@ namespace Mono.CSharp {
return false; return false;
} }
if (type_params != null) { if (CurrentTypeParameters != null) {
foreach (TypeParameter tp in type_params) { CurrentTypeParameters.VerifyClsCompliance ();
tp.VerifyClsCompliance ();
}
} }
return true; return true;

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

@ -81,6 +81,13 @@ namespace Mono.CSharp {
return parameters; return parameters;
} }
} }
public FullNamedExpression TypExpression {
get {
return ReturnType;
}
}
#endregion #endregion
public override void Accept (StructuralVisitor visitor) public override void Accept (StructuralVisitor visitor)
@ -123,7 +130,7 @@ namespace Mono.CSharp {
); );
Constructor = new Constructor (this, Constructor.ConstructorName, Constructor = new Constructor (this, Constructor.ConstructorName,
Modifiers.PUBLIC, null, ctor_parameters, null, Location); Modifiers.PUBLIC, null, ctor_parameters, Location);
Constructor.Define (); Constructor.Define ();
// //

12
ICSharpCode.NRefactory.CSharp/Parser/mcs/doc.cs

@ -244,10 +244,8 @@ namespace Mono.CSharp
string tp_name = node.GetAttribute ("name"); string tp_name = node.GetAttribute ("name");
if (mc.CurrentTypeParameters != null) { if (mc.CurrentTypeParameters != null) {
foreach (var tp in mc.CurrentTypeParameters) { if (mc.CurrentTypeParameters.Find (tp_name) != null)
if (tp.Name == tp_name) return;
return;
}
} }
// TODO: CS1710, CS1712 // TODO: CS1710, CS1712
@ -269,10 +267,8 @@ namespace Mono.CSharp
var member = mc; var member = mc;
do { do {
if (member.CurrentTypeParameters != null) { if (member.CurrentTypeParameters != null) {
foreach (var tp in member.CurrentTypeParameters) { if (member.CurrentTypeParameters.Find (tp_name) != null)
if (tp.Name == tp_name) return;
return;
}
} }
member = member.Parent; member = member.Parent;

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

@ -300,7 +300,7 @@ namespace Mono.CSharp
tr.Start (TimeReporter.TimerType.UsingResolve); tr.Start (TimeReporter.TimerType.UsingResolve);
foreach (var source_file in ctx.SourceFiles) { foreach (var source_file in ctx.SourceFiles) {
source_file.NamespaceContainer.Resolve (); source_file.NamespaceContainer.Define ();
} }
tr.Stop (TimeReporter.TimerType.UsingResolve); tr.Stop (TimeReporter.TimerType.UsingResolve);

10
ICSharpCode.NRefactory.CSharp/Parser/mcs/dynamic.cs

@ -253,7 +253,7 @@ namespace Mono.CSharp
protected CSharpBinderFlags flags; protected CSharpBinderFlags flags;
TypeSpec binder_type; TypeSpec binder_type;
TypeParameter[] context_mvars; TypeParameters context_mvars;
public DynamicExpressionStatement (IDynamicBinder binder, Arguments args, Location loc) public DynamicExpressionStatement (IDynamicBinder binder, Arguments args, Location loc)
{ {
@ -349,7 +349,7 @@ namespace Mono.CSharp
var site_container = ec.CreateDynamicSite (); var site_container = ec.CreateDynamicSite ();
if (context_mvars != null) { if (context_mvars != null) {
TypeParameter[] tparam; TypeParameters tparam;
TypeContainer sc = site_container; TypeContainer sc = site_container;
do { do {
tparam = sc.CurrentTypeParameters; tparam = sc.CurrentTypeParameters;
@ -466,7 +466,7 @@ namespace Mono.CSharp
return; return;
if (del_type_instance_access == null) { if (del_type_instance_access == null) {
var dt = d.CurrentType.DeclaringType.MakeGenericType (module, context_mvars.Select (l => l.Type).ToArray ()); var dt = d.CurrentType.DeclaringType.MakeGenericType (module, context_mvars.Types);
del_type_instance_access = new TypeExpression (MemberCache.GetMember (dt, d.CurrentType), loc); del_type_instance_access = new TypeExpression (MemberCache.GetMember (dt, d.CurrentType), loc);
} }
@ -482,7 +482,7 @@ namespace Mono.CSharp
if (inflate_using_mvar || context_mvars == null) { if (inflate_using_mvar || context_mvars == null) {
gt = site_container.CurrentType; gt = site_container.CurrentType;
} else { } else {
gt = site_container.CurrentType.MakeGenericType (module, context_mvars.Select (l => l.Type).ToArray ()); gt = site_container.CurrentType.MakeGenericType (module, context_mvars.Types);
} }
// When site container already exists the inflated version has to be // When site container already exists the inflated version has to be
@ -957,7 +957,7 @@ namespace Mono.CSharp
sealed class DynamicSiteClass : HoistedStoreyClass sealed class DynamicSiteClass : HoistedStoreyClass
{ {
public DynamicSiteClass (TypeContainer parent, MemberBase host, TypeParameter[] tparams) public DynamicSiteClass (TypeContainer parent, MemberBase host, TypeParameters tparams)
: base (parent, MakeMemberName (host, "DynamicSite", parent.DynamicSitesCounter, tparams, Location.Null), tparams, Modifiers.STATIC) : base (parent, MakeMemberName (host, "DynamicSite", parent.DynamicSitesCounter, tparams, Location.Null), tparams, Modifiers.STATIC)
{ {
parent.DynamicSitesCounter++; parent.DynamicSitesCounter++;

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

@ -244,7 +244,7 @@ namespace Mono.CSharp {
protected void Error_ValueCannotBeConvertedCore (ResolveContext ec, Location loc, TypeSpec target, bool expl) protected void Error_ValueCannotBeConvertedCore (ResolveContext ec, Location loc, TypeSpec target, bool expl)
{ {
// The error was already reported as CS1660 // The error was already reported as CS1660
if (type == InternalType.AnonymousMethod) if (type == InternalType.AnonymousMethod || type == InternalType.ErrorType)
return; return;
string from_type = type.GetSignatureForError (); string from_type = type.GetSignatureForError ();
@ -2452,13 +2452,11 @@ namespace Mono.CSharp {
rc.Report.Error (841, loc, "A local variable `{0}' cannot be used before it is declared", Name); rc.Report.Error (841, loc, "A local variable `{0}' cannot be used before it is declared", Name);
} else { } else {
if (Arity > 0) { if (Arity > 0) {
TypeParameter[] tparams = rc.CurrentTypeParameters; var tparams = rc.CurrentTypeParameters;
if (tparams != null) { if (tparams != null) {
foreach (var ctp in tparams) { if (tparams.Find (Name) != null) {
if (ctp.Name == Name) { Error_TypeArgumentsCannotBeUsed (rc, "type parameter", Name, loc);
Error_TypeArgumentsCannotBeUsed (rc, "type parameter", Name, loc); return null;
return null;
}
} }
} }
@ -4418,7 +4416,10 @@ namespace Mono.CSharp {
var ac_p = p as ArrayContainer; var ac_p = p as ArrayContainer;
if (ac_p != null) { if (ac_p != null) {
var ac_q = ((ArrayContainer) q); var ac_q = q as ArrayContainer;
if (ac_q == null)
return null;
TypeSpec specific = MoreSpecific (ac_p.Element, ac_q.Element); TypeSpec specific = MoreSpecific (ac_p.Element, ac_q.Element);
if (specific == ac_p.Element) if (specific == ac_p.Element)
return p; return p;

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

@ -373,6 +373,7 @@ namespace Mono.CSharp
// Need to setup MemberCache // Need to setup MemberCache
parser_result.CreateType (); parser_result.CreateType ();
parser_result.NamespaceEntry.Define ();
var method = parser_result.Methods[0] as Method; var method = parser_result.Methods[0] as Method;
BlockContext bc = new BlockContext (method, method.Block, ctx.BuiltinTypes.Void); BlockContext bc = new BlockContext (method, method.Block, ctx.BuiltinTypes.Void);
@ -768,12 +769,17 @@ namespace Mono.CSharp
return sb.ToString (); return sb.ToString ();
} }
internal ICollection<string> GetUsingList () internal List<string> GetUsingList ()
{ {
var res = new List<string> (); var res = new List<string> ();
foreach (var ue in source_file.NamespaceContainer.Usings) foreach (var ue in source_file.NamespaceContainer.Usings) {
res.Add (ue.Name); if (ue.Alias != null || ue.ResolvedExpression == null)
continue;
res.Add (ue.NamespaceExpression.Name);
}
return res; return res;
} }
@ -814,7 +820,7 @@ namespace Mono.CSharp
public void LoadAssembly (string file) public void LoadAssembly (string file)
{ {
var loader = new DynamicLoader (importer, ctx); var loader = new DynamicLoader (importer, ctx);
var assembly = loader.LoadAssemblyFile (file); var assembly = loader.LoadAssemblyFile (file, false);
if (assembly == null) if (assembly == null)
return; return;

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

@ -801,18 +801,18 @@ namespace Mono.CSharp
LocalTemporary temporary; LocalTemporary temporary;
bool prepared; bool prepared;
public Expression Expr {
get {
return expr;
}
}
public Indirection (Expression expr, Location l) public Indirection (Expression expr, Location l)
{ {
this.expr = expr; this.expr = expr;
loc = l; loc = l;
} }
public Expression Expr {
get {
return expr;
}
}
public bool IsFixed { public bool IsFixed {
get { return true; } get { return true; }
} }
@ -1017,6 +1017,13 @@ namespace Mono.CSharp
// Holds the real operation // Holds the real operation
Expression operation; Expression operation;
public UnaryMutator (Mode m, Expression e, Location loc)
{
mode = m;
this.loc = loc;
expr = e;
}
public Mode UnaryMutatorMode { public Mode UnaryMutatorMode {
get { get {
return mode; return mode;
@ -1029,13 +1036,6 @@ namespace Mono.CSharp
} }
} }
public UnaryMutator (Mode m, Expression e, Location loc)
{
mode = m;
this.loc = loc;
expr = e;
}
public override bool ContainsEmitWithAwait () public override bool ContainsEmitWithAwait ()
{ {
return expr.ContainsEmitWithAwait (); return expr.ContainsEmitWithAwait ();
@ -1283,6 +1283,7 @@ namespace Mono.CSharp
target.expr = expr.Clone (clonectx); target.expr = expr.Clone (clonectx);
} }
public override object Accept (StructuralVisitor visitor) public override object Accept (StructuralVisitor visitor)
{ {
return visitor.Visit (this); return visitor.Visit (this);
@ -1371,6 +1372,10 @@ namespace Mono.CSharp
{ {
} }
protected override string OperatorName {
get { return "is"; }
}
public override Expression CreateExpressionTree (ResolveContext ec) public override Expression CreateExpressionTree (ResolveContext ec)
{ {
Arguments args = Arguments.CreateForExpressionTree (ec, null, Arguments args = Arguments.CreateForExpressionTree (ec, null,
@ -1545,10 +1550,6 @@ namespace Mono.CSharp
return this; return this;
} }
protected override string OperatorName {
get { return "is"; }
}
public override object Accept (StructuralVisitor visitor) public override object Accept (StructuralVisitor visitor)
{ {
return visitor.Visit (this); return visitor.Visit (this);
@ -1566,6 +1567,10 @@ namespace Mono.CSharp
{ {
} }
protected override string OperatorName {
get { return "as"; }
}
public override Expression CreateExpressionTree (ResolveContext ec) public override Expression CreateExpressionTree (ResolveContext ec)
{ {
Arguments args = Arguments.CreateForExpressionTree (ec, null, Arguments args = Arguments.CreateForExpressionTree (ec, null,
@ -1644,14 +1649,10 @@ namespace Mono.CSharp
return null; return null;
} }
protected override string OperatorName {
get { return "as"; }
}
public override object Accept (StructuralVisitor visitor) public override object Accept (StructuralVisitor visitor)
{ {
return visitor.Visit (this); return visitor.Visit (this);
} }
} }
// //
@ -1753,13 +1754,6 @@ namespace Mono.CSharp
public class DefaultValueExpression : Expression public class DefaultValueExpression : Expression
{ {
Expression expr; Expression expr;
public Expression Expr {
get {
return this.expr;
}
}
public DefaultValueExpression (Expression expr, Location loc) public DefaultValueExpression (Expression expr, Location loc)
{ {
@ -1767,6 +1761,12 @@ namespace Mono.CSharp
this.loc = loc; this.loc = loc;
} }
public Expression Expr {
get {
return this.expr;
}
}
public override bool IsSideEffectFree { public override bool IsSideEffectFree {
get { get {
return true; return true;
@ -2225,11 +2225,15 @@ namespace Mono.CSharp
} }
public Expression Left { public Expression Left {
get { return this.left; } get {
return this.left;
}
} }
public Expression Right { public Expression Right {
get { return this.right; } get {
return this.right;
}
} }
#endregion #endregion
@ -3385,6 +3389,8 @@ namespace Mono.CSharp
return this; return this;
} }
bool no_arg_conv = false;
// //
// LAMESPEC: method groups can be compared when they convert to other side delegate // LAMESPEC: method groups can be compared when they convert to other side delegate
// //
@ -3406,6 +3412,8 @@ namespace Mono.CSharp
left = result; left = result;
l = r; l = r;
} else {
no_arg_conv = l == r && !l.IsStruct;
} }
// //
@ -3418,11 +3426,12 @@ namespace Mono.CSharp
// bool operator != (bool a, bool b) // bool operator != (bool a, bool b)
// bool operator == (bool a, bool b) // bool operator == (bool a, bool b)
// //
// LAMESPEC: Reference equality comparison can apply to value types when // LAMESPEC: Reference equality comparison can apply to value/reference types when
// they implement an implicit conversion to any of types above. // they implement an implicit conversion to any of types above. This does
// not apply when both operands are of same reference type
// //
if (r.BuiltinType != BuiltinTypeSpec.Type.Object && l.BuiltinType != BuiltinTypeSpec.Type.Object) { if (r.BuiltinType != BuiltinTypeSpec.Type.Object && l.BuiltinType != BuiltinTypeSpec.Type.Object) {
result = ResolveOperatorPredefined (ec, ec.BuiltinTypes.OperatorsBinaryEquality, false, null); result = ResolveOperatorPredefined (ec, ec.BuiltinTypes.OperatorsBinaryEquality, no_arg_conv, null);
if (result != null) if (result != null)
return result; return result;
} }
@ -5235,7 +5244,7 @@ namespace Mono.CSharp
} }
} }
public Expression Expression { public Expression Exp {
get { get {
return expr; return expr;
} }
@ -5490,6 +5499,7 @@ namespace Mono.CSharp
return SLE.Expression.Call (instance_expr, (MethodInfo) mi.GetMetaInfo (), Arguments.MakeExpression (args, ctx)); return SLE.Expression.Call (instance_expr, (MethodInfo) mi.GetMetaInfo (), Arguments.MakeExpression (args, ctx));
#endif #endif
} }
public override object Accept (StructuralVisitor visitor) public override object Accept (StructuralVisitor visitor)
{ {
return visitor.Visit (this); return visitor.Visit (this);
@ -5541,6 +5551,12 @@ namespace Mono.CSharp
} }
} }
public Expression TypeExpression {
get {
return RequestedType;
}
}
#endregion #endregion
/// <summary> /// <summary>
@ -5933,6 +5949,12 @@ namespace Mono.CSharp
get { return elements.Count; } get { return elements.Count; }
} }
public List<Expression> Elements {
get {
return elements;
}
}
public Expression this [int index] { public Expression this [int index] {
get { get {
return elements [index]; return elements [index];
@ -5947,12 +5969,6 @@ namespace Mono.CSharp
variable = value; variable = value;
} }
} }
public List<Expression> Elements {
get {
return this.elements;
}
}
#endregion #endregion
public void Add (Expression expr) public void Add (Expression expr)
@ -6044,24 +6060,16 @@ namespace Mono.CSharp
// The number of constants in array initializers // The number of constants in array initializers
int const_initializers_count; int const_initializers_count;
// bool only_constant_initializers; bool only_constant_initializers;
public List<Expression> Arguments { public List<Expression> Arguments {
get { return this.arguments; } get { return this.arguments; }
} }
public ComposedTypeSpecifier Rank {
get { return this.rank; }
}
public FullNamedExpression NewType { public FullNamedExpression NewType {
get { return this.requested_base_type; } get { return this.requested_base_type; }
} }
public ArrayInitializer Initializers {
get { return this.initializers; }
}
public ArrayCreation (FullNamedExpression requested_base_type, List<Expression> exprs, ComposedTypeSpecifier rank, ArrayInitializer initializers, Location l) public ArrayCreation (FullNamedExpression requested_base_type, List<Expression> exprs, ComposedTypeSpecifier rank, ArrayInitializer initializers, Location l)
: this (requested_base_type, rank, initializers, l) : this (requested_base_type, rank, initializers, l)
{ {
@ -6099,6 +6107,24 @@ namespace Mono.CSharp
{ {
} }
public ComposedTypeSpecifier Rank {
get {
return this.rank;
}
}
public FullNamedExpression TypeExpression {
get {
return this.requested_base_type;
}
}
public ArrayInitializer Initializers {
get {
return this.initializers;
}
}
bool CheckIndices (ResolveContext ec, ArrayInitializer probe, int idx, bool specified_dims, int child_bounds) bool CheckIndices (ResolveContext ec, ArrayInitializer probe, int idx, bool specified_dims, int child_bounds)
{ {
if (initializers != null && bounds == null) { if (initializers != null && bounds == null) {
@ -6179,7 +6205,7 @@ namespace Mono.CSharp
++const_initializers_count; ++const_initializers_count;
} }
} else { } else {
// only_constant_initializers = false; only_constant_initializers = false;
} }
array_data.Add (element); array_data.Add (element);
@ -6284,7 +6310,7 @@ namespace Mono.CSharp
protected bool ResolveInitializers (ResolveContext ec) protected bool ResolveInitializers (ResolveContext ec)
{ {
// only_constant_initializers = true; only_constant_initializers = true;
if (arguments != null) { if (arguments != null) {
bool res = true; bool res = true;
@ -7124,8 +7150,8 @@ namespace Mono.CSharp
/// </summary> /// </summary>
public class Arglist : Expression public class Arglist : Expression
{ {
public Arguments Arguments { get; private set; } Arguments arguments;
public Arglist (Location loc) public Arglist (Location loc)
: this (null, loc) : this (null, loc)
{ {
@ -7133,18 +7159,24 @@ namespace Mono.CSharp
public Arglist (Arguments args, Location l) public Arglist (Arguments args, Location l)
{ {
Arguments = args; arguments = args;
loc = l; loc = l;
} }
public Arguments Arguments {
get {
return arguments;
}
}
public MetaType[] ArgumentTypes { public MetaType[] ArgumentTypes {
get { get {
if (Arguments == null) if (arguments == null)
return MetaType.EmptyTypes; return MetaType.EmptyTypes;
var retval = new MetaType[Arguments.Count]; var retval = new MetaType[arguments.Count];
for (int i = 0; i < retval.Length; i++) for (int i = 0; i < retval.Length; i++)
retval[i] = Arguments[i].Expr.Type.GetMetaInfo (); retval[i] = arguments[i].Expr.Type.GetMetaInfo ();
return retval; return retval;
} }
@ -7165,9 +7197,9 @@ namespace Mono.CSharp
{ {
eclass = ExprClass.Variable; eclass = ExprClass.Variable;
type = InternalType.Arglist; type = InternalType.Arglist;
if (Arguments != null) { if (arguments != null) {
bool dynamic; // Can be ignored as there is always only 1 overload bool dynamic; // Can be ignored as there is always only 1 overload
Arguments.Resolve (ec, out dynamic); arguments.Resolve (ec, out dynamic);
} }
return this; return this;
@ -7175,17 +7207,18 @@ namespace Mono.CSharp
public override void Emit (EmitContext ec) public override void Emit (EmitContext ec)
{ {
if (Arguments != null) if (arguments != null)
Arguments.Emit (ec); arguments.Emit (ec);
} }
protected override void CloneTo (CloneContext clonectx, Expression t) protected override void CloneTo (CloneContext clonectx, Expression t)
{ {
Arglist target = (Arglist) t; Arglist target = (Arglist) t;
if (Arguments != null) if (arguments != null)
target.Arguments = Arguments.Clone (clonectx); target.arguments = arguments.Clone (clonectx);
} }
public override object Accept (StructuralVisitor visitor) public override object Accept (StructuralVisitor visitor)
{ {
return visitor.Visit (this); return visitor.Visit (this);
@ -7207,6 +7240,12 @@ namespace Mono.CSharp
this.loc = loc; this.loc = loc;
} }
public FullNamedExpression TypeExpression {
get {
return texpr;
}
}
public override bool ContainsEmitWithAwait () public override bool ContainsEmitWithAwait ()
{ {
return false; return false;
@ -7597,12 +7636,12 @@ namespace Mono.CSharp
/// Implements the sizeof expression /// Implements the sizeof expression
/// </summary> /// </summary>
public class SizeOf : Expression { public class SizeOf : Expression {
public readonly Expression QueriedType; readonly Expression texpr;
TypeSpec type_queried; TypeSpec type_queried;
public SizeOf (Expression queried_type, Location l) public SizeOf (Expression queried_type, Location l)
{ {
this.QueriedType = queried_type; this.texpr = queried_type;
loc = l; loc = l;
} }
@ -7612,6 +7651,12 @@ namespace Mono.CSharp
} }
} }
public Expression TypeExpression {
get {
return texpr;
}
}
public override bool ContainsEmitWithAwait () public override bool ContainsEmitWithAwait ()
{ {
return false; return false;
@ -7625,7 +7670,7 @@ namespace Mono.CSharp
protected override Expression DoResolve (ResolveContext ec) protected override Expression DoResolve (ResolveContext ec)
{ {
type_queried = QueriedType.ResolveAsType (ec); type_queried = texpr.ResolveAsType (ec);
if (type_queried == null) if (type_queried == null)
return null; return null;
@ -7693,6 +7738,12 @@ namespace Mono.CSharp
this.alias = alias; this.alias = alias;
} }
public string Alias {
get {
return alias;
}
}
public override FullNamedExpression ResolveAsTypeOrNamespace (IMemberContext ec) public override FullNamedExpression ResolveAsTypeOrNamespace (IMemberContext ec)
{ {
if (alias == GlobalAlias) { if (alias == GlobalAlias) {
@ -7707,19 +7758,8 @@ namespace Mono.CSharp
ec.Module.Compiler.Report.Error (432, loc, "Alias `{0}' not found", alias); ec.Module.Compiler.Report.Error (432, loc, "Alias `{0}' not found", alias);
return null; return null;
} }
FullNamedExpression fne = base.ResolveAsTypeOrNamespace (ec); return base.ResolveAsTypeOrNamespace (ec);
if (fne == null)
return null;
if (expr.eclass == ExprClass.Type) {
ec.Module.Compiler.Report.Error (431, loc,
"Alias `{0}' cannot be used with '::' since it denotes a type. Consider replacing '::' with '.'", alias);
return null;
}
return fne;
} }
protected override Expression DoResolve (ResolveContext ec) protected override Expression DoResolve (ResolveContext ec)
@ -7727,13 +7767,6 @@ namespace Mono.CSharp
return ResolveAsTypeOrNamespace (ec); return ResolveAsTypeOrNamespace (ec);
} }
protected override void Error_IdentifierNotFound (IMemberContext rc, TypeSpec expr_type, string identifier)
{
rc.Module.Compiler.Report.Error (687, loc,
"A namespace alias qualifier `{0}' did not resolve to a namespace or a type",
GetSignatureForError ());
}
public override string GetSignatureForError () public override string GetSignatureForError ()
{ {
string name = Name; string name = Name;
@ -7746,6 +7779,14 @@ namespace Mono.CSharp
public override Expression LookupNameExpression (ResolveContext rc, MemberLookupRestrictions restrictions) public override Expression LookupNameExpression (ResolveContext rc, MemberLookupRestrictions restrictions)
{ {
if ((restrictions & MemberLookupRestrictions.InvocableOnly) != 0) {
rc.Module.Compiler.Report.Error (687, loc,
"The namespace alias qualifier `::' cannot be used to invoke a method. Consider using `.' instead",
GetSignatureForError ());
return null;
}
return DoResolve (rc); return DoResolve (rc);
} }
@ -8105,6 +8146,14 @@ namespace Mono.CSharp
return null; return null;
} }
var qam = this as QualifiedAliasMember;
if (qam != null) {
rc.Module.Compiler.Report.Error (431, loc,
"Alias `{0}' cannot be used with `::' since it denotes a type. Consider replacing `::' with `.'",
qam.Alias);
}
TypeSpec nested = null; TypeSpec nested = null;
while (expr_type != null) { while (expr_type != null) {
nested = MemberCache.FindNestedType (expr_type, Name, Arity); nested = MemberCache.FindNestedType (expr_type, Name, Arity);
@ -8265,6 +8314,7 @@ namespace Mono.CSharp
target.Expr = Expr.Clone (clonectx); target.Expr = Expr.Clone (clonectx);
} }
public override object Accept (StructuralVisitor visitor) public override object Accept (StructuralVisitor visitor)
{ {
return visitor.Visit (this); return visitor.Visit (this);
@ -8329,6 +8379,7 @@ namespace Mono.CSharp
target.Expr = Expr.Clone (clonectx); target.Expr = Expr.Clone (clonectx);
} }
public override object Accept (StructuralVisitor visitor) public override object Accept (StructuralVisitor visitor)
{ {
return visitor.Visit (this); return visitor.Visit (this);
@ -9539,15 +9590,7 @@ namespace Mono.CSharp
TypeSpec otype; TypeSpec otype;
Expression t; Expression t;
Expression count; Expression count;
public Expression TypeExpression {
get { return this.t; }
}
public Expression CountExpression {
get { return this.count; }
}
public StackAlloc (Expression type, Expression count, Location l) public StackAlloc (Expression type, Expression count, Location l)
{ {
t = type; t = type;
@ -9555,6 +9598,18 @@ namespace Mono.CSharp
loc = l; loc = l;
} }
public Expression TypeExpression {
get {
return this.t;
}
}
public Expression CountExpression {
get {
return this.count;
}
}
public override bool ContainsEmitWithAwait () public override bool ContainsEmitWithAwait ()
{ {
return false; return false;
@ -10033,18 +10088,18 @@ namespace Mono.CSharp
CollectionOrObjectInitializers initializers; CollectionOrObjectInitializers initializers;
IMemoryLocation instance; IMemoryLocation instance;
public CollectionOrObjectInitializers Initializers {
get {
return initializers;
}
}
public NewInitialize (FullNamedExpression requested_type, Arguments arguments, CollectionOrObjectInitializers initializers, Location l) public NewInitialize (FullNamedExpression requested_type, Arguments arguments, CollectionOrObjectInitializers initializers, Location l)
: base (requested_type, arguments, l) : base (requested_type, arguments, l)
{ {
this.initializers = initializers; this.initializers = initializers;
} }
public CollectionOrObjectInitializers Initializers {
get {
return initializers;
}
}
protected override void CloneTo (CloneContext clonectx, Expression t) protected override void CloneTo (CloneContext clonectx, Expression t)
{ {
base.CloneTo (clonectx, t); base.CloneTo (clonectx, t);
@ -10155,10 +10210,6 @@ namespace Mono.CSharp
readonly TypeContainer parent; readonly TypeContainer parent;
AnonymousTypeClass anonymous_type; AnonymousTypeClass anonymous_type;
public List<AnonymousTypeParameter> Parameters {
get { return this.parameters; }
}
public NewAnonymousType (List<AnonymousTypeParameter> parameters, TypeContainer parent, Location loc) public NewAnonymousType (List<AnonymousTypeParameter> parameters, TypeContainer parent, Location loc)
: base (null, null, loc) : base (null, null, loc)
{ {
@ -10166,6 +10217,12 @@ namespace Mono.CSharp
this.parent = parent; this.parent = parent;
} }
public List<AnonymousTypeParameter> Parameters {
get {
return this.parameters;
}
}
protected override void CloneTo (CloneContext clonectx, Expression target) protected override void CloneTo (CloneContext clonectx, Expression target)
{ {
if (parameters == null) if (parameters == null)
@ -10187,15 +10244,15 @@ namespace Mono.CSharp
if (type == null) if (type == null)
return null; return null;
int errors = ec.Report.Errors;
type.CreateType (); type.CreateType ();
type.DefineType (); type.DefineType ();
type.ResolveTypeParameters (); type.ResolveTypeParameters ();
type.Define (); type.Define ();
type.EmitType (); if ((ec.Report.Errors - errors) == 0) {
if (ec.Report.Errors == 0) parent.Module.AddAnonymousType (type);
type.CloseType (); }
parent.Module.AddAnonymousType (type);
return type; return type;
} }
@ -10237,7 +10294,7 @@ namespace Mono.CSharp
arguments = new Arguments (parameters.Count); arguments = new Arguments (parameters.Count);
TypeExpression [] t_args = new TypeExpression [parameters.Count]; TypeExpression [] t_args = new TypeExpression [parameters.Count];
for (int i = 0; i < parameters.Count; ++i) { for (int i = 0; i < parameters.Count; ++i) {
Expression e = ((AnonymousTypeParameter) parameters [i]).Resolve (ec); Expression e = parameters [i].Resolve (ec);
if (e == null) { if (e == null) {
error = true; error = true;
continue; continue;

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

@ -94,6 +94,12 @@ namespace Mono.CSharp {
#region Properties #region Properties
public List<FullNamedExpression> TypeExpressions {
get {
return constraints;
}
}
public Location Location { public Location Location {
get { get {
return loc; return loc;
@ -360,15 +366,24 @@ namespace Mono.CSharp {
GenericTypeParameterBuilder builder; GenericTypeParameterBuilder builder;
TypeParameterSpec spec; TypeParameterSpec spec;
public TypeParameter (DeclSpace parent, int index, MemberName name, Constraints constraints, Attributes attrs, Variance variance) public TypeParameter (int index, MemberName name, Constraints constraints, Attributes attrs, Variance variance)
: base (parent, name, attrs) : base (null, name, attrs)
{ {
this.constraints = constraints; this.constraints = constraints;
this.spec = new TypeParameterSpec (null, index, this, SpecialConstraint.None, variance, null); this.spec = new TypeParameterSpec (null, index, this, SpecialConstraint.None, variance, null);
} }
//
// Used by parser
//
public TypeParameter (MemberName name, Attributes attrs, Variance variance)
: base (null, name, attrs)
{
this.spec = new TypeParameterSpec (null, -1, this, SpecialConstraint.None, variance, null);
}
public TypeParameter (TypeParameterSpec spec, DeclSpace parent, TypeSpec parentSpec, MemberName name, Attributes attrs) public TypeParameter (TypeParameterSpec spec, DeclSpace parent, TypeSpec parentSpec, MemberName name, Attributes attrs)
: base (parent, name, attrs) : base (null, name, attrs)
{ {
this.spec = new TypeParameterSpec (parentSpec, spec.DeclaredPosition, spec.MemberDefinition, spec.SpecialConstraint, spec.Variance, null) { this.spec = new TypeParameterSpec (parentSpec, spec.DeclaredPosition, spec.MemberDefinition, spec.SpecialConstraint, spec.Variance, null) {
BaseType = spec.BaseType, BaseType = spec.BaseType,
@ -385,6 +400,15 @@ namespace Mono.CSharp {
} }
} }
public Constraints Constraints {
get {
return constraints;
}
set {
constraints = value;
}
}
public IAssemblyDefinition DeclaringAssembly { public IAssemblyDefinition DeclaringAssembly {
get { get {
return Module.DeclaringAssembly; return Module.DeclaringAssembly;
@ -440,12 +464,6 @@ namespace Mono.CSharp {
} }
} }
public Constraints Constraints {
get {
return this.constraints;
}
}
#endregion #endregion
// //
@ -509,11 +527,13 @@ namespace Mono.CSharp {
// with SRE (by calling `DefineGenericParameters()' on the TypeBuilder / // with SRE (by calling `DefineGenericParameters()' on the TypeBuilder /
// MethodBuilder). // MethodBuilder).
// //
public void Define (GenericTypeParameterBuilder type, TypeSpec declaringType) public void Define (GenericTypeParameterBuilder type, TypeSpec declaringType, TypeContainer parent)
{ {
if (builder != null) if (builder != null)
throw new InternalErrorException (); throw new InternalErrorException ();
// Needed to get compiler reference
this.Parent = parent;
this.builder = type; this.builder = type;
spec.DeclaringType = declaringType; spec.DeclaringType = declaringType;
spec.SetMetaInfo (type); spec.SetMetaInfo (type);
@ -625,16 +645,6 @@ namespace Mono.CSharp {
return true; return true;
} }
public static TypeParameter FindTypeParameter (TypeParameter[] tparams, string name)
{
foreach (var tp in tparams) {
if (tp.Name == name)
return tp;
}
return null;
}
public override bool IsClsComplianceRequired () public override bool IsClsComplianceRequired ()
{ {
return false; return false;
@ -645,6 +655,14 @@ namespace Mono.CSharp {
if (constraints != null) if (constraints != null)
constraints.VerifyClsCompliance (Report); constraints.VerifyClsCompliance (Report);
} }
public void WarningParentNameConflict (TypeParameter conflict)
{
conflict.Report.SymbolRelatedToPreviousError (conflict.Location, null);
conflict.Report.Warning (693, 3, Location,
"Type parameter `{0}' has the same name as the type parameter from outer type `{1}'",
GetSignatureForError (), conflict.CurrentType.GetSignatureForError ());
}
} }
[System.Diagnostics.DebuggerDisplay ("{DisplayDebugInfo()}")] [System.Diagnostics.DebuggerDisplay ("{DisplayDebugInfo()}")]
@ -654,7 +672,7 @@ namespace Mono.CSharp {
Variance variance; Variance variance;
SpecialConstraint spec; SpecialConstraint spec;
readonly int tp_pos; int tp_pos;
TypeSpec[] targs; TypeSpec[] targs;
TypeSpec[] ifaces_defined; TypeSpec[] ifaces_defined;
@ -684,6 +702,9 @@ namespace Mono.CSharp {
get { get {
return tp_pos; return tp_pos;
} }
set {
tp_pos = value;
}
} }
public bool HasSpecialConstructor { public bool HasSpecialConstructor {
@ -918,15 +939,8 @@ namespace Mono.CSharp {
public override string GetSignatureForDocumentation () public override string GetSignatureForDocumentation ()
{ {
int c = 0;
var type = DeclaringType;
while (type != null && type.DeclaringType != null) {
type = type.DeclaringType;
c += type.MemberDefinition.TypeParametersCount;
}
var prefix = IsMethodOwned ? "``" : "`"; var prefix = IsMethodOwned ? "``" : "`";
return prefix + (c + DeclaredPosition); return prefix + DeclaredPosition;
} }
public override string GetSignatureForError () public override string GetSignatureForError ()
@ -1364,13 +1378,13 @@ namespace Mono.CSharp {
// //
public class TypeParameterMutator public class TypeParameterMutator
{ {
readonly TypeParameter[] mvar; readonly TypeParameters mvar;
readonly TypeParameter[] var; readonly TypeParameters var;
Dictionary<TypeSpec, TypeSpec> mutated_typespec; Dictionary<TypeSpec, TypeSpec> mutated_typespec;
public TypeParameterMutator (TypeParameter[] mvar, TypeParameter[] var) public TypeParameterMutator (TypeParameters mvar, TypeParameters var)
{ {
if (mvar.Length != var.Length) if (mvar.Count != var.Count)
throw new ArgumentException (); throw new ArgumentException ();
this.mvar = mvar; this.mvar = mvar;
@ -1379,7 +1393,7 @@ namespace Mono.CSharp {
#region Properties #region Properties
public TypeParameter[] MethodTypeParameters { public TypeParameters MethodTypeParameters {
get { get {
return mvar; return mvar;
} }
@ -1416,7 +1430,7 @@ namespace Mono.CSharp {
public TypeParameterSpec Mutate (TypeParameterSpec tp) public TypeParameterSpec Mutate (TypeParameterSpec tp)
{ {
for (int i = 0; i < mvar.Length; ++i) { for (int i = 0; i < mvar.Count; ++i) {
if (mvar[i].Type == tp) if (mvar[i].Type == tp)
return var[i].Type; return var[i].Type;
} }
@ -1879,12 +1893,6 @@ namespace Mono.CSharp {
args.Add (type); args.Add (type);
} }
// TODO: Kill this monster
public TypeParameterName[] GetDeclarations ()
{
return args.ConvertAll (i => (TypeParameterName) i).ToArray ();
}
/// <summary> /// <summary>
/// We may only be used after Resolve() is called and return the fully /// We may only be used after Resolve() is called and return the fully
/// resolved types. /// resolved types.
@ -1911,6 +1919,12 @@ namespace Mono.CSharp {
} }
} }
public List<FullNamedExpression> TypeExpressions {
get {
return this.args;
}
}
public string GetSignatureForError() public string GetSignatureForError()
{ {
StringBuilder sb = new StringBuilder (); StringBuilder sb = new StringBuilder ();
@ -1998,32 +2012,95 @@ namespace Mono.CSharp {
} }
} }
public class TypeParameterName : SimpleName public class TypeParameters
{ {
Attributes attributes; List<TypeParameter> names;
Variance variance; TypeParameterSpec[] types;
public TypeParameterName (string name, Attributes attrs, Location loc) public TypeParameters ()
: this (name, attrs, Variance.None, loc)
{ {
names = new List<TypeParameter> ();
} }
public TypeParameterName (string name, Attributes attrs, Variance variance, Location loc) public TypeParameters (int count)
: base (name, loc)
{ {
attributes = attrs; names = new List<TypeParameter> (count);
this.variance = variance;
} }
public Attributes OptAttributes { #region Properties
public int Count {
get { get {
return attributes; return names.Count;
} }
} }
public Variance Variance { public TypeParameterSpec[] Types {
get { get {
return variance; return types;
}
}
#endregion
public void Add (TypeParameter tparam)
{
names.Add (tparam);
}
public void Add (TypeParameters tparams)
{
names.AddRange (tparams.names);
}
public void Define (GenericTypeParameterBuilder[] buiders, TypeSpec declaringType, int parentOffset, TypeContainer parent)
{
types = new TypeParameterSpec[Count];
for (int i = 0; i < types.Length; ++i) {
names[i].Define (buiders[i + parentOffset], declaringType, parent);
types[i] = names[i].Type;
types[i].DeclaredPosition = i + parentOffset;
}
}
public TypeParameter this[int index] {
get {
return names [index];
}
set {
names[index] = value;
}
}
public TypeParameter Find (string name)
{
foreach (var tp in names) {
if (tp.Name == name)
return tp;
}
return null;
}
public string GetSignatureForError ()
{
StringBuilder sb = new StringBuilder ();
for (int i = 0; i < Count; ++i) {
if (i > 0)
sb.Append (',');
var name = names[i];
if (name != null)
sb.Append (name.GetSignatureForError ());
}
return sb.ToString ();
}
public void VerifyClsCompliance ()
{
foreach (var tp in names) {
tp.VerifyClsCompliance ();
} }
} }
} }
@ -2443,16 +2520,9 @@ namespace Mono.CSharp {
this.parameters = parameters; this.parameters = parameters;
} }
public GenericMethod (NamespaceContainer ns, DeclSpace parent, MemberName name, TypeParameter[] tparams, public override TypeParameters CurrentTypeParameters {
FullNamedExpression return_type, ParametersCompiled parameters)
: this (ns, parent, name, return_type, parameters)
{
this.type_params = tparams;
}
public override TypeParameter[] CurrentTypeParameters {
get { get {
return base.type_params; return MemberName.TypeParameters;
} }
} }
@ -2483,11 +2553,13 @@ namespace Mono.CSharp {
/// </summary> /// </summary>
public bool Define (MethodOrOperator m) public bool Define (MethodOrOperator m)
{ {
TypeParameterName[] names = MemberName.TypeArguments.GetDeclarations (); var tparams = MemberName.TypeParameters;
string[] snames = new string [names.Length]; string[] snames = new string[MemberName.Arity];
var block = m.Block; var block = m.Block;
for (int i = 0; i < names.Length; i++) { var parent_tparams = Parent.TypeParametersAll;
string type_argument_name = names[i].Name;
for (int i = 0; i < snames.Length; i++) {
string type_argument_name = tparams[i].MemberName.Name;
if (block == null) { if (block == null) {
int idx = parameters.GetParameterIndexByName (type_argument_name); int idx = parameters.GetParameterIndexByName (type_argument_name);
@ -2505,12 +2577,18 @@ namespace Mono.CSharp {
variable.Block.Error_AlreadyDeclaredTypeParameter (type_argument_name, variable.Location); variable.Block.Error_AlreadyDeclaredTypeParameter (type_argument_name, variable.Location);
} }
if (parent_tparams != null) {
var tp = parent_tparams.Find (type_argument_name);
if (tp != null) {
tparams[i].WarningParentNameConflict (tp);
}
}
snames[i] = type_argument_name; snames[i] = type_argument_name;
} }
GenericTypeParameterBuilder[] gen_params = m.MethodBuilder.DefineGenericParameters (snames); GenericTypeParameterBuilder[] gen_params = m.MethodBuilder.DefineGenericParameters (snames);
for (int i = 0; i < TypeParameters.Length; i++) tparams.Define (gen_params, null, 0, Parent);
TypeParameters [i].Define (gen_params [i], null);
return true; return true;
} }
@ -2538,9 +2616,7 @@ namespace Mono.CSharp {
public new void VerifyClsCompliance () public new void VerifyClsCompliance ()
{ {
foreach (TypeParameter tp in TypeParameters) { MemberName.TypeParameters.VerifyClsCompliance ();
tp.VerifyClsCompliance ();
}
} }
} }

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

@ -33,16 +33,16 @@ namespace Mono.CSharp
protected T machine_initializer; protected T machine_initializer;
int resume_pc; int resume_pc;
public Expression Expr {
get { return this.expr; }
}
protected YieldStatement (Expression expr, Location l) protected YieldStatement (Expression expr, Location l)
{ {
this.expr = expr; this.expr = expr;
loc = l; loc = l;
} }
public Expression Expr {
get { return this.expr; }
}
protected override void CloneTo (CloneContext clonectx, Statement t) protected override void CloneTo (CloneContext clonectx, Statement t)
{ {
var target = (YieldStatement<T>) t; var target = (YieldStatement<T>) t;
@ -160,7 +160,7 @@ namespace Mono.CSharp
Field pc_field; Field pc_field;
StateMachineMethod method; StateMachineMethod method;
protected StateMachine (Block block, TypeContainer parent, MemberBase host, TypeParameter[] tparams, string name) protected StateMachine (Block block, TypeContainer parent, MemberBase host, TypeParameters tparams, string name)
: base (block, parent, host, tparams, name) : base (block, parent, host, tparams, name)
{ {
} }
@ -478,17 +478,14 @@ namespace Mono.CSharp
Define_Reset (); Define_Reset ();
if (Iterator.IsEnumerable) { if (Iterator.IsEnumerable) {
MemberName name = new MemberName (QualifiedAliasMember.GlobalAlias, "System", null, Location); FullNamedExpression explicit_iface = new TypeExpression (Compiler.BuiltinTypes.IEnumerable, Location);
name = new MemberName (name, "Collections", Location); var name = new MemberName ("GetEnumerator", null, explicit_iface, Location);
name = new MemberName (name, "IEnumerable", Location);
name = new MemberName (name, "GetEnumerator", Location);
if (generic_enumerator_type != null) { if (generic_enumerator_type != null) {
Method get_enumerator = new StateMachineMethod (this, null, enumerator_type, 0, name); Method get_enumerator = new StateMachineMethod (this, null, enumerator_type, 0, name);
name = new MemberName (name.Left.Left, "Generic", Location); explicit_iface = new GenericTypeExpr (Module.PredefinedTypes.IEnumerableGeneric.Resolve (), generic_args, Location);
name = new MemberName (name, "IEnumerable", generic_args, Location); name = new MemberName ("GetEnumerator", null, explicit_iface, Location);
name = new MemberName (name, "GetEnumerator", Location);
Method gget_enumerator = new GetEnumeratorMethod (this, generic_enumerator_type, name); Method gget_enumerator = new GetEnumeratorMethod (this, generic_enumerator_type, name);
// //
@ -510,20 +507,17 @@ namespace Mono.CSharp
void Define_Current (bool is_generic) void Define_Current (bool is_generic)
{ {
TypeExpr type; TypeExpr type;
FullNamedExpression explicit_iface;
MemberName name = new MemberName (QualifiedAliasMember.GlobalAlias, "System", null, Location);
name = new MemberName (name, "Collections", Location);
if (is_generic) { if (is_generic) {
name = new MemberName (name, "Generic", Location); explicit_iface = new GenericTypeExpr (Module.PredefinedTypes.IEnumeratorGeneric.Resolve (), generic_args, Location);
name = new MemberName (name, "IEnumerator", generic_args, Location);
type = iterator_type_expr; type = iterator_type_expr;
} else { } else {
name = new MemberName (name, "IEnumerator"); explicit_iface = new TypeExpression (Module.Compiler.BuiltinTypes.IEnumerator, Location);
type = new TypeExpression (Compiler.BuiltinTypes.Object, Location); type = new TypeExpression (Compiler.BuiltinTypes.Object, Location);
} }
name = new MemberName (name, "Current", Location); var name = new MemberName ("Current", null, explicit_iface, Location);
ToplevelBlock get_block = new ToplevelBlock (Compiler, Location); ToplevelBlock get_block = new ToplevelBlock (Compiler, Location);
get_block.AddStatement (new Return (new DynamicFieldExpr (CurrentField, Location), Location)); get_block.AddStatement (new Return (new DynamicFieldExpr (CurrentField, Location), Location));

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

@ -24,13 +24,8 @@ namespace Mono.CSharp {
// A list of Parameters (explicitly typed parameters) // A list of Parameters (explicitly typed parameters)
// An ImplicitLambdaParameter // An ImplicitLambdaParameter
// //
public LambdaExpression (bool isAsync, Location loc)
: base (isAsync, loc)
{
}
public LambdaExpression (Location loc) public LambdaExpression (Location loc)
: this (false, loc) : base (loc)
{ {
} }

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

@ -287,6 +287,12 @@ namespace Mono.CSharp.Linq
this.identifier = identifier; this.identifier = identifier;
} }
public RangeVariable Identifier {
get {
return identifier;
}
}
public FullNamedExpression IdentifierType { get; set; } public FullNamedExpression IdentifierType { get; set; }
protected Invocation CreateCastExpression (Expression lSide) protected Invocation CreateCastExpression (Expression lSide)
@ -476,6 +482,12 @@ namespace Mono.CSharp.Linq
} }
} }
public Expression SelectorExpression {
get {
return element_selector;
}
}
protected override void CreateArguments (ResolveContext ec, Parameter parameter, ref Arguments args) protected override void CreateArguments (ResolveContext ec, Parameter parameter, ref Arguments args)
{ {
base.CreateArguments (ec, parameter, ref args); base.CreateArguments (ec, parameter, ref args);
@ -519,6 +531,13 @@ namespace Mono.CSharp.Linq
get { return this.GetIntoVariable (); } get { return this.GetIntoVariable (); }
} }
public Join (QueryBlock block, RangeVariable lt, Expression inner, QueryBlock outerSelector, QueryBlock innerSelector, Location loc)
: base (block, lt, inner, loc)
{
this.outer_selector = outerSelector;
this.inner_selector = innerSelector;
}
public QueryBlock InnerSelector { public QueryBlock InnerSelector {
get { get {
return inner_selector; return inner_selector;
@ -530,13 +549,6 @@ namespace Mono.CSharp.Linq
return outer_selector; return outer_selector;
} }
} }
public Join (QueryBlock block, RangeVariable lt, Expression inner, QueryBlock outerSelector, QueryBlock innerSelector, Location loc)
: base (block, lt, inner, loc)
{
this.outer_selector = outerSelector;
this.inner_selector = innerSelector;
}
protected override void CreateArguments (ResolveContext ec, Parameter parameter, ref Arguments args) protected override void CreateArguments (ResolveContext ec, Parameter parameter, ref Arguments args)
{ {

70
ICSharpCode.NRefactory.CSharp/Parser/mcs/literal.cs

@ -95,8 +95,13 @@ namespace Mono.CSharp
} }
#if FULL_AST #if FULL_AST
char[] ILiteralConstant.ParsedValue { get; set; } public char[] ParsedValue { get; set; }
#endif #endif
public override object Accept (StructuralVisitor visitor)
{
return visitor.Visit (this);
}
} }
public class CharLiteral : CharConstant, ILiteralConstant public class CharLiteral : CharConstant, ILiteralConstant
@ -111,8 +116,13 @@ namespace Mono.CSharp
} }
#if FULL_AST #if FULL_AST
char[] ILiteralConstant.ParsedValue { get; set; } public char[] ParsedValue { get; set; }
#endif #endif
public override object Accept (StructuralVisitor visitor)
{
return visitor.Visit (this);
}
} }
public class IntLiteral : IntConstant, ILiteralConstant public class IntLiteral : IntConstant, ILiteralConstant
@ -143,8 +153,13 @@ namespace Mono.CSharp
} }
#if FULL_AST #if FULL_AST
char[] ILiteralConstant.ParsedValue { get; set; } public char[] ParsedValue { get; set; }
#endif #endif
public override object Accept (StructuralVisitor visitor)
{
return visitor.Visit (this);
}
} }
public class UIntLiteral : UIntConstant, ILiteralConstant public class UIntLiteral : UIntConstant, ILiteralConstant
@ -159,8 +174,13 @@ namespace Mono.CSharp
} }
#if FULL_AST #if FULL_AST
char[] ILiteralConstant.ParsedValue { get; set; } public char[] ParsedValue { get; set; }
#endif #endif
public override object Accept (StructuralVisitor visitor)
{
return visitor.Visit (this);
}
} }
public class LongLiteral : LongConstant, ILiteralConstant public class LongLiteral : LongConstant, ILiteralConstant
@ -175,8 +195,13 @@ namespace Mono.CSharp
} }
#if FULL_AST #if FULL_AST
char[] ILiteralConstant.ParsedValue { get; set; } public char[] ParsedValue { get; set; }
#endif #endif
public override object Accept (StructuralVisitor visitor)
{
return visitor.Visit (this);
}
} }
public class ULongLiteral : ULongConstant, ILiteralConstant public class ULongLiteral : ULongConstant, ILiteralConstant
@ -191,8 +216,13 @@ namespace Mono.CSharp
} }
#if FULL_AST #if FULL_AST
char[] ILiteralConstant.ParsedValue { get; set; } public char[] ParsedValue { get; set; }
#endif #endif
public override object Accept (StructuralVisitor visitor)
{
return visitor.Visit (this);
}
} }
public class FloatLiteral : FloatConstant, ILiteralConstant public class FloatLiteral : FloatConstant, ILiteralConstant
@ -207,8 +237,13 @@ namespace Mono.CSharp
} }
#if FULL_AST #if FULL_AST
char[] ILiteralConstant.ParsedValue { get; set; } public char[] ParsedValue { get; set; }
#endif #endif
public override object Accept (StructuralVisitor visitor)
{
return visitor.Visit (this);
}
} }
public class DoubleLiteral : DoubleConstant, ILiteralConstant public class DoubleLiteral : DoubleConstant, ILiteralConstant
@ -245,8 +280,13 @@ namespace Mono.CSharp
} }
#if FULL_AST #if FULL_AST
char[] ILiteralConstant.ParsedValue { get; set; } public char[] ParsedValue { get; set; }
#endif #endif
public override object Accept (StructuralVisitor visitor)
{
return visitor.Visit (this);
}
} }
public class DecimalLiteral : DecimalConstant, ILiteralConstant public class DecimalLiteral : DecimalConstant, ILiteralConstant
@ -261,8 +301,13 @@ namespace Mono.CSharp
} }
#if FULL_AST #if FULL_AST
char[] ILiteralConstant.ParsedValue { get; set; } public char[] ParsedValue { get; set; }
#endif #endif
public override object Accept (StructuralVisitor visitor)
{
return visitor.Visit (this);
}
} }
public class StringLiteral : StringConstant, ILiteralConstant public class StringLiteral : StringConstant, ILiteralConstant
@ -277,7 +322,12 @@ namespace Mono.CSharp
} }
#if FULL_AST #if FULL_AST
char[] ILiteralConstant.ParsedValue { get; set; } public char[] ParsedValue { get; set; }
#endif #endif
public override object Accept (StructuralVisitor visitor)
{
return visitor.Visit (this);
}
} }
} }

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

@ -796,10 +796,10 @@ if (checkpoints.Length <= CheckpointIndex) throw new Exception (String.Format ("
public readonly Location UsingLocation; public readonly Location UsingLocation;
public readonly Tokenizer.LocatedToken Identifier; public readonly Tokenizer.LocatedToken Identifier;
public readonly Location AssignLocation; public readonly Location AssignLocation;
public readonly MemberName Nspace; public readonly ATypeNameExpression Nspace;
public readonly Location SemicolonLocation; public readonly Location SemicolonLocation;
public AliasUsing (Location usingLocation, Tokenizer.LocatedToken identifier, Location assignLocation, MemberName nspace, Location semicolonLocation) public AliasUsing (Location usingLocation, Tokenizer.LocatedToken identifier, Location assignLocation, ATypeNameExpression nspace, Location semicolonLocation)
{ {
this.UsingLocation = usingLocation; this.UsingLocation = usingLocation;
this.Identifier = identifier; this.Identifier = identifier;
@ -817,10 +817,10 @@ if (checkpoints.Length <= CheckpointIndex) throw new Exception (String.Format ("
public class Using public class Using
{ {
public readonly Location UsingLocation; public readonly Location UsingLocation;
public readonly MemberName NSpace; public readonly ATypeNameExpression NSpace;
public readonly Location SemicolonLocation; public readonly Location SemicolonLocation;
public Using (Location usingLocation, MemberName nSpace, Location semicolonLocation) public Using (Location usingLocation, ATypeNameExpression nSpace, Location semicolonLocation)
{ {
this.UsingLocation = usingLocation; this.UsingLocation = usingLocation;
this.NSpace = nSpace; this.NSpace = nSpace;
@ -869,13 +869,13 @@ if (checkpoints.Length <= CheckpointIndex) throw new Exception (String.Format ("
} }
[Conditional ("FULL_AST")] [Conditional ("FULL_AST")]
public void AddUsingAlias (Location usingLocation, Tokenizer.LocatedToken identifier, Location assignLocation, MemberName nspace, Location semicolonLocation) public void AddUsingAlias (Location usingLocation, Tokenizer.LocatedToken identifier, Location assignLocation, ATypeNameExpression nspace, Location semicolonLocation)
{ {
curNamespace.Peek ().usings.Add (new AliasUsing (usingLocation, identifier, assignLocation, nspace, semicolonLocation)); curNamespace.Peek ().usings.Add (new AliasUsing (usingLocation, identifier, assignLocation, nspace, semicolonLocation));
} }
[Conditional ("FULL_AST")] [Conditional ("FULL_AST")]
public void AddUsing (Location usingLocation, MemberName nspace, Location semicolonLocation) public void AddUsing (Location usingLocation, ATypeNameExpression nspace, Location semicolonLocation)
{ {
curNamespace.Peek ().usings.Add (new Using (usingLocation, nspace, semicolonLocation)); curNamespace.Peek ().usings.Add (new Using (usingLocation, nspace, semicolonLocation));
} }

72
ICSharpCode.NRefactory.CSharp/Parser/mcs/method.cs

@ -875,7 +875,7 @@ namespace Mono.CSharp {
#region Properties #region Properties
public override TypeParameter[] CurrentTypeParameters { public override TypeParameters CurrentTypeParameters {
get { get {
if (GenericMethod != null) if (GenericMethod != null)
return GenericMethod.CurrentTypeParameters; return GenericMethod.CurrentTypeParameters;
@ -886,19 +886,23 @@ namespace Mono.CSharp {
public TypeParameterSpec[] TypeParameters { public TypeParameterSpec[] TypeParameters {
get { get {
// TODO: Cache this return CurrentTypeParameters.Types;
return CurrentTypeParameters.Select (l => l.Type).ToArray ();
} }
} }
public int TypeParametersCount { public int TypeParametersCount {
get { get {
return CurrentTypeParameters == null ? 0 : CurrentTypeParameters.Length; return CurrentTypeParameters == null ? 0 : CurrentTypeParameters.Count;
} }
} }
#endregion #endregion
public override void Accept (StructuralVisitor visitor)
{
visitor.Visit (this);
}
public static Method Create (DeclSpace parent, GenericMethod generic, FullNamedExpression returnType, Modifiers mod, public static Method Create (DeclSpace parent, GenericMethod generic, FullNamedExpression returnType, Modifiers mod,
MemberName name, ParametersCompiled parameters, Attributes attrs, bool hasConstraints) MemberName name, ParametersCompiled parameters, Attributes attrs, bool hasConstraints)
{ {
@ -966,9 +970,9 @@ namespace Mono.CSharp {
public override FullNamedExpression LookupNamespaceOrType (string name, int arity, LookupMode mode, Location loc) public override FullNamedExpression LookupNamespaceOrType (string name, int arity, LookupMode mode, Location loc)
{ {
if (arity == 0) { if (arity == 0) {
TypeParameter[] tp = CurrentTypeParameters; var tp = CurrentTypeParameters;
if (tp != null) { if (tp != null) {
TypeParameter t = TypeParameter.FindTypeParameter (tp, name); TypeParameter t = tp.Find (name);
if (t != null) if (t != null)
return new TypeParameterExpr (t, loc); return new TypeParameterExpr (t, loc);
} }
@ -1065,10 +1069,10 @@ namespace Mono.CSharp {
if (base_decl_tparams.Length != 0) { if (base_decl_tparams.Length != 0) {
base_decl_tparams = base_decl_tparams.Concat (base_tparams).ToArray (); base_decl_tparams = base_decl_tparams.Concat (base_tparams).ToArray ();
base_targs = base_targs.Concat (tparams.Select<TypeParameter, TypeSpec> (l => l.Type)).ToArray (); base_targs = base_targs.Concat (tparams.Types).ToArray ();
} else { } else {
base_decl_tparams = base_tparams; base_decl_tparams = base_tparams;
base_targs = tparams.Select (l => l.Type).ToArray (); base_targs = tparams.Types;
} }
} }
} else if (MethodData.implementing != null) { } else if (MethodData.implementing != null) {
@ -1085,7 +1089,7 @@ namespace Mono.CSharp {
} }
} }
for (int i = 0; i < tparams.Length; ++i) { for (int i = 0; i < tparams.Count; ++i) {
var tp = tparams[i]; var tp = tparams[i];
if (!tp.ResolveConstraints (this)) if (!tp.ResolveConstraints (this))
@ -1175,11 +1179,6 @@ namespace Mono.CSharp {
return true; return true;
} }
public override void Accept (StructuralVisitor visitor)
{
visitor.Visit (this);
}
// //
// Creates the type // Creates the type
// //
@ -1313,7 +1312,7 @@ namespace Mono.CSharp {
} }
if (CurrentTypeParameters != null) { if (CurrentTypeParameters != null) {
for (int i = 0; i < CurrentTypeParameters.Length; ++i) { for (int i = 0; i < CurrentTypeParameters.Count; ++i) {
var tp = CurrentTypeParameters [i]; var tp = CurrentTypeParameters [i];
tp.CheckGenericConstraints (false); tp.CheckGenericConstraints (false);
tp.Emit (); tp.Emit ();
@ -1528,20 +1527,16 @@ namespace Mono.CSharp {
public static readonly string ConstructorName = ".ctor"; public static readonly string ConstructorName = ".ctor";
public static readonly string TypeConstructorName = ".cctor"; public static readonly string TypeConstructorName = ".cctor";
// public Constructor (DeclSpace parent, string name, Modifiers mod, Attributes attrs, ParametersCompiled args, Location loc)
// The spec claims that static is not permitted, but
// my very own code has static constructors.
//
public Constructor (DeclSpace parent, string name, Modifiers mod, Attributes attrs, ParametersCompiled args,
ConstructorInitializer init, Location loc)
: base (parent, null, null, mod, AllowedModifiers, : base (parent, null, null, mod, AllowedModifiers,
new MemberName (name, loc), attrs, args) new MemberName (name, loc), attrs, args)
{ {
Initializer = init;
} }
public bool HasCompliantArgs { public bool HasCompliantArgs {
get { return has_compliant_args; } get {
return has_compliant_args;
}
} }
public override AttributeTargets AttributeTargets { public override AttributeTargets AttributeTargets {
@ -1569,6 +1564,11 @@ namespace Mono.CSharp {
(Initializer.Arguments == null); (Initializer.Arguments == null);
} }
public override void Accept (StructuralVisitor visitor)
{
visitor.Visit (this);
}
public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa) public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
{ {
if (a.IsValidSecurityAttribute ()) { if (a.IsValidSecurityAttribute ()) {
@ -1614,11 +1614,6 @@ namespace Mono.CSharp {
return true; return true;
} }
public override void Accept (StructuralVisitor visitor)
{
visitor.Visit (this);
}
// //
// Creates the ConstructorBuilder // Creates the ConstructorBuilder
// //
@ -2155,6 +2150,11 @@ namespace Mono.CSharp {
ModFlags |= Modifiers.PROTECTED | Modifiers.OVERRIDE; ModFlags |= Modifiers.PROTECTED | Modifiers.OVERRIDE;
} }
public override void Accept (StructuralVisitor visitor)
{
visitor.Visit (this);
}
public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa) public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
{ {
if (a.Type == pa.Conditional) { if (a.Type == pa.Conditional) {
@ -2164,10 +2164,6 @@ namespace Mono.CSharp {
base.ApplyAttributeBuilder (a, ctor, cdata, pa); base.ApplyAttributeBuilder (a, ctor, cdata, pa);
} }
public override void Accept (StructuralVisitor visitor)
{
visitor.Visit (this);
}
protected override bool CheckBase () protected override bool CheckBase ()
{ {
@ -2242,7 +2238,7 @@ namespace Mono.CSharp {
static MemberName SetupName (string prefix, InterfaceMemberBase member, Location loc) static MemberName SetupName (string prefix, InterfaceMemberBase member, Location loc)
{ {
return new MemberName (member.MemberName.Left, prefix + member.ShortName, loc); return new MemberName (member.MemberName.Left, prefix + member.ShortName, member.MemberName.ExplicitInterface, loc);
} }
public void UpdateName (InterfaceMemberBase member) public void UpdateName (InterfaceMemberBase member)
@ -2514,6 +2510,11 @@ namespace Mono.CSharp {
Block = block; Block = block;
} }
public override void Accept (StructuralVisitor visitor)
{
visitor.Visit (this);
}
public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa) public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
{ {
if (a.Type == pa.Conditional) { if (a.Type == pa.Conditional) {
@ -2524,11 +2525,6 @@ namespace Mono.CSharp {
base.ApplyAttributeBuilder (a, ctor, cdata, pa); base.ApplyAttributeBuilder (a, ctor, cdata, pa);
} }
public override void Accept (StructuralVisitor visitor)
{
visitor.Visit (this);
}
public override bool Define () public override bool Define ()
{ {
const Modifiers RequiredModifiers = Modifiers.PUBLIC | Modifiers.STATIC; const Modifiers RequiredModifiers = Modifiers.PUBLIC | Modifiers.STATIC;

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

@ -35,6 +35,11 @@ namespace Mono.CSharp {
} }
} }
public static void Error_GlobalNamespaceRedefined (Report report, Location loc)
{
report.Error (1681, loc, "The global extern alias cannot be redefined");
}
public void RegisterNamespace (Namespace child) public void RegisterNamespace (Namespace child)
{ {
if (child != this) if (child != this)
@ -117,11 +122,11 @@ namespace Mono.CSharp {
throw new InternalErrorException ("Namespace has a null fullname"); throw new InternalErrorException ("Namespace has a null fullname");
if (parent != null && parent.MemberName != MemberName.Null) if (parent != null && parent.MemberName != MemberName.Null)
MemberName = new MemberName (parent.MemberName, name); MemberName = new MemberName (parent.MemberName, name, Location.Null);
else if (name.Length == 0) else if (name.Length == 0)
MemberName = MemberName.Null; MemberName = MemberName.Null;
else else
MemberName = new MemberName (name); MemberName = new MemberName (name, Location.Null);
namespaces = new Dictionary<string, Namespace> (); namespaces = new Dictionary<string, Namespace> ();
cached_types = new Dictionary<string, TypeExpr> (); cached_types = new Dictionary<string, TypeExpr> ();
@ -578,37 +583,38 @@ namespace Mono.CSharp {
// //
public class NamespaceContainer : IMemberContext, ITypesContainer public class NamespaceContainer : IMemberContext, ITypesContainer
{ {
static readonly Namespace[] empty_namespaces = new Namespace[0];
static readonly string[] empty_using_list = new string[0];
Namespace ns; Namespace ns;
readonly ModuleContainer module; readonly ModuleContainer module;
readonly NamespaceContainer parent; readonly NamespaceContainer parent;
readonly CompilationSourceFile file; readonly CompilationSourceFile file;
readonly Location loc; readonly MemberName name;
NamespaceContainer implicit_parent; NamespaceContainer implicit_parent;
int symfile_id; int symfile_id;
// Namespace using import block List<UsingNamespace> clauses;
List<NamespaceUsingAlias> using_aliases;
List<NamespaceUsing> using_clauses; // Used by parsed to check for parser errors
public bool DeclarationFound; public bool DeclarationFound;
// End
bool resolved; bool resolved;
public readonly bool IsImplicit; public readonly bool IsImplicit;
public readonly TypeContainer SlaveDeclSpace; public readonly TypeContainer SlaveDeclSpace;
static readonly Namespace [] empty_namespaces = new Namespace [0];
static readonly string[] empty_using_list = new string[0];
Namespace [] namespace_using_table; Namespace[] namespace_using_table;
Dictionary<string, UsingAliasNamespace> aliases;
public NamespaceContainer (MemberName name, ModuleContainer module, NamespaceContainer parent, CompilationSourceFile sourceFile) public NamespaceContainer (MemberName name, ModuleContainer module, NamespaceContainer parent, CompilationSourceFile sourceFile)
{ {
this.module = module; this.module = module;
this.parent = parent; this.parent = parent;
this.file = sourceFile; this.file = sourceFile;
this.loc = name == null ? Location.Null : name.Location; this.name = name ?? MemberName.Null;
if (parent != null) if (parent != null)
ns = parent.NS.GetNamespace (name.GetName (), true); ns = parent.NS.GetNamespace (name.GetName (), true);
@ -634,105 +640,46 @@ namespace Mono.CSharp {
public Location Location { public Location Location {
get { get {
return loc; return name.Location;
} }
} }
public MemberName MemberName { public MemberName MemberName {
get { get {
return ns.MemberName; return name;
} }
} }
public CompilationSourceFile SourceFile { public NamespaceContainer Parent {
get { get {
return file; return parent;
} }
} }
public List<NamespaceUsing> Usings { public CompilationSourceFile SourceFile {
get { get {
return using_clauses; return file;
} }
} }
#endregion public List<UsingNamespace> Usings {
//
// Extracts the using alises and using clauses into a couple of
// arrays that might already have the same information; Used by the
// C# Eval mode.
//
public void Extract (List<NamespaceUsingAlias> out_using_aliases, List<NamespaceUsing> out_using_clauses)
{
if (using_aliases != null){
foreach (NamespaceUsingAlias uae in using_aliases){
bool replaced = false;
for (int i = 0; i < out_using_aliases.Count; i++){
NamespaceUsingAlias out_uea = (NamespaceUsingAlias) out_using_aliases [i];
if (out_uea.Alias == uae.Alias){
out_using_aliases [i] = uae;
replaced = true;
break;
}
}
if (!replaced)
out_using_aliases.Add (uae);
}
}
if (using_clauses != null){
foreach (NamespaceUsing ue in using_clauses){
bool found = false;
foreach (NamespaceUsing out_ue in out_using_clauses)
if (out_ue.Name == ue.Name){
found = true;
break;
}
if (!found)
out_using_clauses.Add (ue);
}
}
}
//
// According to section 16.3.1 (using-alias-directive), the namespace-or-type-name is
// resolved as if the immediately containing namespace body has no using-directives.
//
// Section 16.3.2 says that the same rule is applied when resolving the namespace-name
// in the using-namespace-directive.
//
// To implement these rules, the expressions in the using directives are resolved using
// the "doppelganger" (ghostly bodiless duplicate).
//
NamespaceContainer doppelganger;
NamespaceContainer Doppelganger {
get { get {
if (!IsImplicit && doppelganger == null) { return clauses;
doppelganger = new NamespaceContainer (module, ImplicitParent, file, ns, true);
doppelganger.using_aliases = using_aliases;
}
return doppelganger;
} }
} }
#endregion
public Namespace NS { public Namespace NS {
get { return ns; } get { return ns; }
} }
public NamespaceContainer Parent {
get { return parent; }
}
public NamespaceContainer ImplicitParent { public NamespaceContainer ImplicitParent {
get { get {
if (parent == null) if (parent == null)
return null; return null;
if (implicit_parent == null) { if (implicit_parent == null) {
implicit_parent = (parent.NS == ns.Parent) implicit_parent = (parent.ns == ns.Parent)
? parent ? parent
: new NamespaceContainer (module, parent, file, ns.Parent, false); : new NamespaceContainer (module, parent, file, ns.Parent, false);
} }
@ -740,78 +687,47 @@ namespace Mono.CSharp {
} }
} }
/// <summary> public void AddUsing (UsingNamespace un)
/// Records a new namespace for resolving name references
/// </summary>
public void AddUsing (MemberName name, Location loc)
{ {
if (DeclarationFound){ if (DeclarationFound){
Compiler.Report.Error (1529, loc, "A using clause must precede all other namespace elements except extern alias declarations"); Compiler.Report.Error (1529, un.Location, "A using clause must precede all other namespace elements except extern alias declarations");
} }
if (using_clauses == null) { if (clauses == null)
using_clauses = new List<NamespaceUsing> (); clauses = new List<UsingNamespace> ();
} else {
foreach (NamespaceUsing old_entry in using_clauses) {
if (name.Equals (old_entry.MemberName)) {
Compiler.Report.SymbolRelatedToPreviousError (old_entry.Location, old_entry.GetSignatureForError ());
Compiler.Report.Warning (105, 3, loc, "The using directive for `{0}' appeared previously in this namespace", name.GetSignatureForError ());
return;
}
}
}
using_clauses.Add (new NamespaceUsing (name));
}
public void AddUsingAlias (string alias, MemberName name, Location loc) clauses.Add (un);
{
if (DeclarationFound){
Compiler.Report.Error (1529, loc, "A using clause must precede all other namespace elements except extern alias declarations");
}
AddUsingAlias (new LocalUsingAliasEntry (alias, name, loc)); resolved = false;
} }
public void AddUsingExternalAlias (string alias, Location loc, Report Report) public void AddUsing (UsingAliasNamespace un)
{ {
bool not_first = using_clauses != null || DeclarationFound; if (DeclarationFound){
if (using_aliases != null && !not_first) { Compiler.Report.Error (1529, un.Location, "A using clause must precede all other namespace elements except extern alias declarations");
foreach (NamespaceUsingAlias uae in using_aliases) {
if (uae is LocalUsingAliasEntry) {
not_first = true;
break;
}
}
}
if (not_first)
Report.Error (439, loc, "An extern alias declaration must precede all other elements");
if (alias == "global") {
Error_GlobalNamespaceRedefined (loc, Report);
return;
} }
AddUsingAlias (new NamespaceUsingAlias (alias, loc)); AddAlias (un);
} }
void AddUsingAlias (NamespaceUsingAlias uae) void AddAlias (UsingAliasNamespace un)
{ {
if (using_aliases == null) { if (clauses == null) {
using_aliases = new List<NamespaceUsingAlias> (); clauses = new List<UsingNamespace> ();
} else { } else {
foreach (NamespaceUsingAlias entry in using_aliases) { foreach (var entry in clauses) {
if (uae.Alias == entry.Alias) { var a = entry as UsingAliasNamespace;
Compiler.Report.SymbolRelatedToPreviousError (uae.Location, uae.Alias); if (a != null && a.Alias.Value == un.Alias.Value) {
Compiler.Report.Error (1537, entry.Location, "The using alias `{0}' appeared previously in this namespace", Compiler.Report.SymbolRelatedToPreviousError (a.Location, "");
entry.Alias); Compiler.Report.Error (1537, un.Location,
return; "The using alias `{0}' appeared previously in this namespace", un.Alias.Value);
} }
} }
} }
using_aliases.Add (uae); clauses.Add (un);
resolved = false;
} }
// //
@ -821,7 +737,7 @@ namespace Mono.CSharp {
public ExtensionMethodCandidates LookupExtensionMethod (TypeSpec extensionType, string name, int arity) public ExtensionMethodCandidates LookupExtensionMethod (TypeSpec extensionType, string name, int arity)
{ {
List<MethodSpec> candidates = null; List<MethodSpec> candidates = null;
foreach (Namespace n in GetUsingTable ()) { foreach (Namespace n in namespace_using_table) {
var a = n.LookupExtensionMethod (this, extensionType, name, arity); var a = n.LookupExtensionMethod (this, extensionType, name, arity);
if (a == null) if (a == null)
continue; continue;
@ -866,7 +782,7 @@ namespace Mono.CSharp {
IEnumerable<string> all = Enumerable.Empty<string> (); IEnumerable<string> all = Enumerable.Empty<string> ();
for (NamespaceContainer curr_ns = this; curr_ns != null; curr_ns = curr_ns.ImplicitParent){ for (NamespaceContainer curr_ns = this; curr_ns != null; curr_ns = curr_ns.ImplicitParent){
foreach (Namespace using_ns in GetUsingTable ()){ foreach (Namespace using_ns in namespace_using_table){
if (prefix.StartsWith (using_ns.Name)){ if (prefix.StartsWith (using_ns.Name)){
int ld = prefix.LastIndexOf ('.'); int ld = prefix.LastIndexOf ('.');
if (ld != -1){ if (ld != -1){
@ -881,18 +797,35 @@ namespace Mono.CSharp {
return all.Distinct ().ToList (); return all.Distinct ().ToList ();
} }
//
// Looks-up a alias named @name in this and surrounding namespace declarations
//
public FullNamedExpression LookupExternAlias (string name)
{
if (aliases == null)
return null;
UsingAliasNamespace uan;
if (aliases.TryGetValue (name, out uan) && uan is UsingExternAlias)
return uan.ResolvedExpression;
return null;
}
//
// Looks-up a alias named @name in this and surrounding namespace declarations // Looks-up a alias named @name in this and surrounding namespace declarations
//
public FullNamedExpression LookupNamespaceAlias (string name) public FullNamedExpression LookupNamespaceAlias (string name)
{ {
for (NamespaceContainer n = this; n != null; n = n.ImplicitParent) { for (NamespaceContainer n = this; n != null; n = n.ImplicitParent) {
if (n.using_aliases == null) if (n.aliases == null)
continue; continue;
foreach (NamespaceUsingAlias ue in n.using_aliases) { UsingAliasNamespace uan;
if (ue.Alias == name) if (n.aliases.TryGetValue (name, out uan))
return ue.Resolve (Doppelganger ?? this, Doppelganger == null); return uan.ResolvedExpression;
}
} }
return null; return null;
@ -908,26 +841,19 @@ namespace Mono.CSharp {
// //
// Check aliases. // Check aliases.
// //
if (using_aliases != null && arity == 0) { if (aliases != null && arity == 0) {
foreach (NamespaceUsingAlias ue in using_aliases) { UsingAliasNamespace uan;
if (ue.Alias == name) { if (aliases.TryGetValue (name, out uan)) {
if (fne != null) { if (fne != null) {
if (Doppelganger != null) { // TODO: Namespace has broken location
if (mode == LookupMode.Normal) { //Report.SymbolRelatedToPreviousError (fne.Location, null);
// TODO: Namespace has broken location Compiler.Report.SymbolRelatedToPreviousError (uan.Location, null);
//Report.SymbolRelatedToPreviousError (fne.Location, null); Compiler.Report.Error (576, loc,
Compiler.Report.SymbolRelatedToPreviousError (ue.Location, null); "Namespace `{0}' contains a definition with same name as alias `{1}'",
Compiler.Report.Error (576, loc, GetSignatureForError (), name);
"Namespace `{0}' contains a definition with same name as alias `{1}'",
GetSignatureForError (), name);
}
} else {
return fne;
}
}
return ue.Resolve (Doppelganger ?? this, Doppelganger == null);
} }
return uan.ResolvedExpression;
} }
} }
@ -941,9 +867,11 @@ namespace Mono.CSharp {
// Check using entries. // Check using entries.
// //
FullNamedExpression match = null; FullNamedExpression match = null;
foreach (Namespace using_ns in GetUsingTable ()) { foreach (Namespace using_ns in namespace_using_table) {
//
// A using directive imports only types contained in the namespace, it // A using directive imports only types contained in the namespace, it
// does not import any nested namespaces // does not import any nested namespaces
//
fne = using_ns.LookupType (this, name, arity, mode, loc); fne = using_ns.LookupType (this, name, arity, mode, loc);
if (fne == null) if (fne == null)
continue; continue;
@ -983,41 +911,20 @@ namespace Mono.CSharp {
return match; return match;
} }
Namespace [] GetUsingTable ()
{
if (namespace_using_table != null)
return namespace_using_table;
if (using_clauses == null)
return empty_namespaces;
var list = new List<Namespace> (using_clauses.Count);
foreach (NamespaceUsing ue in using_clauses) {
Namespace using_ns = ue.Resolve (Doppelganger);
if (using_ns == null)
continue;
list.Add (using_ns);
}
if (Compiler.Settings.StatementMode)
return list.ToArray ();
namespace_using_table = list.ToArray ();
return namespace_using_table;
}
public int SymbolFileID { public int SymbolFileID {
get { get {
if (symfile_id == 0 && file.SourceFileEntry != null) { if (symfile_id == 0 && file.SourceFileEntry != null) {
int parent_id = parent == null ? 0 : parent.SymbolFileID; int parent_id = parent == null ? 0 : parent.SymbolFileID;
string [] using_list = empty_using_list; string [] using_list = empty_using_list;
if (using_clauses != null) { if (clauses != null) {
using_list = new string [using_clauses.Count]; // TODO: Why is it needed, what to do with aliases
for (int i = 0; i < using_clauses.Count; i++) var ul = new List<string> ();
using_list [i] = ((NamespaceUsing) using_clauses [i]).MemberName.GetName (); foreach (var c in clauses) {
ul.Add (c.ResolvedExpression.GetSignatureForError ());
}
using_list = ul.ToArray ();
} }
symfile_id = SymbolWriter.DefineNamespace (ns.Name, file.CompileUnitEntry, using_list, parent_id); symfile_id = SymbolWriter.DefineNamespace (ns.Name, file.CompileUnitEntry, using_list, parent_id);
@ -1036,11 +943,6 @@ namespace Mono.CSharp {
Console.WriteLine (" Try using -pkg:" + s); Console.WriteLine (" Try using -pkg:" + s);
} }
public static void Error_GlobalNamespaceRedefined (Location loc, Report Report)
{
Report.Error (1681, loc, "The global extern alias cannot be redefined");
}
public static void Error_NamespaceNotFound (Location loc, string name, Report Report) public static void Error_NamespaceNotFound (Location loc, string name, Report Report)
{ {
Report.Error (246, loc, "The type or namespace name `{0}' could not be found. Are you missing a using directive or an assembly reference?", Report.Error (246, loc, "The type or namespace name `{0}' could not be found. Are you missing a using directive or an assembly reference?",
@ -1069,29 +971,76 @@ namespace Mono.CSharp {
} }
} }
/// <summary> public void Define ()
/// Used to validate that all the using clauses are correct
/// after we are finished parsing all the files.
/// </summary>
public void Resolve ()
{ {
if (resolved) if (resolved)
return; return;
// FIXME: Because we call Define from bottom not top
if (parent != null)
parent.Define ();
namespace_using_table = empty_namespaces;
resolved = true; resolved = true;
if (using_aliases != null) { if (clauses != null) {
foreach (NamespaceUsingAlias ue in using_aliases) var list = new List<Namespace> (clauses.Count);
ue.Resolve (Doppelganger, Doppelganger == null); bool post_process_using_aliases = false;
}
for (int i = 0; i < clauses.Count; ++i) {
var entry = clauses[i];
if (entry.Alias != null) {
if (aliases == null)
aliases = new Dictionary<string, UsingAliasNamespace> ();
//
// Aliases are not available when resolving using section
// except extern aliases
//
if (entry is UsingExternAlias) {
entry.Define (this);
if (entry.ResolvedExpression != null)
aliases.Add (entry.Alias.Value, (UsingExternAlias) entry);
clauses.RemoveAt (i--);
} else {
post_process_using_aliases = true;
}
if (using_clauses != null) { continue;
foreach (NamespaceUsing ue in using_clauses) }
ue.Resolve (Doppelganger);
}
if (parent != null) entry.Define (this);
parent.Resolve ();
Namespace using_ns = entry.ResolvedExpression as Namespace;
if (using_ns == null)
continue;
if (list.Contains (using_ns)) {
Compiler.Report.Warning (105, 3, entry.Location,
"The using directive for `{0}' appeared previously in this namespace", using_ns.GetSignatureForError ());
} else {
list.Add (using_ns);
}
}
namespace_using_table = list.ToArray ();
if (post_process_using_aliases) {
for (int i = 0; i < clauses.Count; ++i) {
var entry = clauses[i];
if (entry.Alias != null) {
entry.Define (this);
if (entry.ResolvedExpression != null) {
aliases.Add (entry.Alias.Value, (UsingAliasNamespace) entry);
}
clauses.RemoveAt (i--);
}
}
}
}
} }
public string GetSignatureForError () public string GetSignatureForError ()
@ -1113,12 +1062,12 @@ namespace Mono.CSharp {
get { return SlaveDeclSpace.CurrentMemberDefinition; } get { return SlaveDeclSpace.CurrentMemberDefinition; }
} }
public TypeParameter[] CurrentTypeParameters { public TypeParameters CurrentTypeParameters {
get { return SlaveDeclSpace.CurrentTypeParameters; } get { return SlaveDeclSpace.CurrentTypeParameters; }
} }
public bool IsObsolete { public bool IsObsolete {
get { return SlaveDeclSpace.IsObsolete; } get { return false; }
} }
public bool IsUnsafe { public bool IsUnsafe {
@ -1136,106 +1085,199 @@ namespace Mono.CSharp {
#endregion #endregion
} }
public class NamespaceUsing public class UsingNamespace
{ {
readonly MemberName name; readonly ATypeNameExpression expr;
Namespace resolved; readonly Location loc;
protected FullNamedExpression resolved;
public NamespaceUsing (MemberName name) public UsingNamespace (ATypeNameExpression expr, Location loc)
{ {
this.name = name; this.expr = expr;
this.loc = loc;
} }
public string GetSignatureForError () #region Properties
{
return name.GetSignatureForError ();
}
public Location Location public virtual SimpleMemberName Alias {
{ get {
get { return name.Location; } return null;
}
} }
public MemberName MemberName public Location Location {
{ get {
get { return name; } return loc;
}
} }
public string Name public ATypeNameExpression NamespaceExpression {
{ get {
get { return GetSignatureForError (); } return expr;
}
} }
public Namespace Resolve (IMemberContext rc) public FullNamedExpression ResolvedExpression {
{ get {
if (resolved != null)
return resolved; return resolved;
}
}
FullNamedExpression fne = name.GetTypeExpression ().ResolveAsTypeOrNamespace (rc); #endregion
if (fne == null)
return null;
resolved = fne as Namespace; public string GetSignatureForError ()
if (resolved == null) { {
rc.Module.Compiler.Report.SymbolRelatedToPreviousError (fne.Type); return expr.GetSignatureForError ();
rc.Module.Compiler.Report.Error (138, Location, }
"`{0}' is a type not a namespace. A using namespace directive can only be applied to namespaces",
GetSignatureForError ()); public virtual void Define (NamespaceContainer ctx)
{
resolved = expr.ResolveAsTypeOrNamespace (ctx);
var ns = resolved as Namespace;
if (ns == null) {
if (resolved != null) {
ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (resolved.Type);
ctx.Module.Compiler.Report.Error (138, Location,
"`{0}' is a type not a namespace. A using namespace directive can only be applied to namespaces",
GetSignatureForError ());
}
} }
return resolved;
} }
} }
public class NamespaceUsingAlias public class UsingExternAlias : UsingAliasNamespace
{ {
public readonly string Alias; public UsingExternAlias (SimpleMemberName alias, Location loc)
public Location Location; : base (alias, null, loc)
public NamespaceUsingAlias (string alias, Location loc)
{ {
this.Alias = alias;
this.Location = loc;
} }
public virtual FullNamedExpression Resolve (IMemberContext rc, bool local) public override void Define (NamespaceContainer ctx)
{ {
FullNamedExpression fne = rc.Module.GetRootNamespace (Alias); resolved = ctx.Module.GetRootNamespace (Alias.Value);
if (fne == null) { if (resolved == null) {
rc.Module.Compiler.Report.Error (430, Location, ctx.Module.Compiler.Report.Error (430, Location,
"The extern alias `{0}' was not specified in -reference option", "The extern alias `{0}' was not specified in -reference option",
Alias); Alias.Value);
} }
return fne;
} }
} }
class LocalUsingAliasEntry : NamespaceUsingAlias public class UsingAliasNamespace : UsingNamespace
{ {
FullNamedExpression resolved; readonly SimpleMemberName alias;
MemberName value;
public LocalUsingAliasEntry (string alias, MemberName name, Location loc) struct AliasContext : IMemberContext
: base (alias, loc)
{ {
this.value = name; readonly NamespaceContainer ns;
}
public override FullNamedExpression Resolve (IMemberContext rc, bool local) public AliasContext (NamespaceContainer ns)
{ {
if (resolved != null || value == null) this.ns = ns;
return resolved; }
public TypeSpec CurrentType {
get {
return null;
}
}
public TypeParameters CurrentTypeParameters {
get {
return null;
}
}
public MemberCore CurrentMemberDefinition {
get {
return null;
}
}
public bool IsObsolete {
get {
return false;
}
}
public bool IsUnsafe {
get {
throw new NotImplementedException ();
}
}
public bool IsStatic {
get {
throw new NotImplementedException ();
}
}
public ModuleContainer Module {
get {
return ns.Module;
}
}
public string GetSignatureForError ()
{
throw new NotImplementedException ();
}
if (local) public ExtensionMethodCandidates LookupExtensionMethod (TypeSpec extensionType, string name, int arity)
{
return null; return null;
}
public FullNamedExpression LookupNamespaceOrType (string name, int arity, LookupMode mode, Location loc)
{
var fne = ns.NS.LookupTypeOrNamespace (ns, name, arity, mode, loc);
if (fne != null)
return fne;
//
// Only extern aliases are allowed in this context
//
fne = ns.LookupExternAlias (name);
if (fne != null)
return fne;
if (ns.ImplicitParent != null)
return ns.ImplicitParent.LookupNamespaceOrType (name, arity, mode, loc);
resolved = value.GetTypeExpression ().ResolveAsTypeOrNamespace (rc);
if (resolved == null) {
value = null;
return null; return null;
} }
return resolved; public FullNamedExpression LookupNamespaceAlias (string name)
{
return ns.LookupNamespaceAlias (name);
}
}
public UsingAliasNamespace (SimpleMemberName alias, ATypeNameExpression expr, Location loc)
: base (expr, loc)
{
this.alias = alias;
}
public override SimpleMemberName Alias {
get {
return alias;
}
}
public override void Define (NamespaceContainer ctx)
{
//
// The namespace-or-type-name of a using-alias-directive is resolved as if
// the immediately containing compilation unit or namespace body had no
// using-directives. A using-alias-directive may however be affected
// by extern-alias-directives in the immediately containing compilation
// unit or namespace body
//
// We achieve that by introducing alias-context which redirect any local
// namespace or type resolve calls to parent namespace
//
resolved = NamespaceExpression.ResolveAsTypeOrNamespace (new AliasContext (ctx));
} }
} }
} }

20
ICSharpCode.NRefactory.CSharp/Parser/mcs/nullable.cs

@ -1001,20 +1001,24 @@ namespace Mono.CSharp.Nullable
Expression left, right; Expression left, right;
Unwrap unwrap; Unwrap unwrap;
public Expression Left {
get { return this.left; }
}
public Expression Right {
get { return this.right; }
}
public NullCoalescingOperator (Expression left, Expression right, Location loc) public NullCoalescingOperator (Expression left, Expression right, Location loc)
{ {
this.left = left; this.left = left;
this.right = right; this.right = right;
this.loc = loc; this.loc = loc;
} }
public Expression LeftExpression {
get {
return left;
}
}
public Expression Right {
get {
return right;
}
}
public override Expression CreateExpressionTree (ResolveContext ec) public override Expression CreateExpressionTree (ResolveContext ec)
{ {

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

@ -234,10 +234,7 @@ namespace Mono.CSharp {
TemporaryVariableReference expr_tree_variable; TemporaryVariableReference expr_tree_variable;
HoistedVariable hoisted_variant; HoistedVariable hoisted_variant;
public Modifier ParameterModifier { get { return modFlags; }}
public Expression DefaultExpression { get { return default_expr; }}
public Parameter (FullNamedExpression type, string name, Modifier mod, Attributes attrs, Location loc) public Parameter (FullNamedExpression type, string name, Modifier mod, Attributes attrs, Location loc)
{ {
this.name = name; this.name = name;
@ -251,6 +248,12 @@ namespace Mono.CSharp {
#region Properties #region Properties
public Expression DefaultExpression {
get {
return default_expr;
}
}
public DefaultParameterValueExpression DefaultValue { public DefaultParameterValueExpression DefaultValue {
get { get {
return default_expr as DefaultParameterValueExpression; return default_expr as DefaultParameterValueExpression;
@ -279,6 +282,12 @@ namespace Mono.CSharp {
} }
} }
public Modifier ParameterModifier {
get {
return modFlags;
}
}
public TypeSpec Type { public TypeSpec Type {
get { get {
return parameter_type; return parameter_type;
@ -1212,7 +1221,7 @@ namespace Mono.CSharp {
// //
// Default parameter value expression. We need this wrapper to handle // Default parameter value expression. We need this wrapper to handle
// default parameter values of folded constants when for indexer parameters // default parameter values of folded constants (e.g. indexer parameters).
// The expression is resolved only once but applied to two methods which // The expression is resolved only once but applied to two methods which
// both share reference to this expression and we ensure that resolving // both share reference to this expression and we ensure that resolving
// this expression always returns same instance // this expression always returns same instance

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

@ -67,7 +67,7 @@ namespace Mono.CSharp {
} }
} }
public TypeParameter[] CurrentTypeParameters { public TypeParameters CurrentTypeParameters {
get { get {
throw new NotImplementedException (); throw new NotImplementedException ();
} }
@ -443,7 +443,7 @@ namespace Mono.CSharp {
optional = tm.optional; optional = tm.optional;
} }
if (op == Operation.Lookup && name.Left != null && ambiguousCandidate == null) { if (op == Operation.Lookup && name.ExplicitInterface != null && ambiguousCandidate == null) {
ambiguousCandidate = m; ambiguousCandidate = m;
continue; continue;
} }

97
ICSharpCode.NRefactory.CSharp/Parser/mcs/property.cs

@ -733,6 +733,12 @@ namespace Mono.CSharp
{ {
} }
public override void Accept (StructuralVisitor visitor)
{
visitor.Visit (this);
}
void CreateAutomaticProperty () void CreateAutomaticProperty ()
{ {
// Create backing field // Create backing field
@ -757,11 +763,6 @@ namespace Mono.CSharp
Set.Block.AddStatement (new StatementExpression (a)); Set.Block.AddStatement (new StatementExpression (a));
} }
public override void Accept (StructuralVisitor visitor)
{
visitor.Visit (this);
}
public override bool Define () public override bool Define ()
{ {
if (!base.Define ()) if (!base.Define ())
@ -857,6 +858,11 @@ namespace Mono.CSharp
{ {
} }
public override void Accept (StructuralVisitor visitor)
{
visitor.Visit (this);
}
public override bool Define() public override bool Define()
{ {
if (!base.Define ()) if (!base.Define ())
@ -871,12 +877,6 @@ namespace Mono.CSharp
return attribute_targets; return attribute_targets;
} }
} }
public override void Accept (StructuralVisitor visitor)
{
visitor.Visit (this);
}
} }
/// <summary> /// <summary>
@ -909,8 +909,8 @@ namespace Mono.CSharp
// Delegate obj1 = backing_field // Delegate obj1 = backing_field
// do { // do {
// Delegate obj2 = obj1; // Delegate obj2 = obj1;
// obj1 = Interlocked.CompareExchange (ref backing_field, Delegate.Combine|Remove(obj2, value), obj1); // obj1 = Interlocked.CompareExchange (ref backing_field, Delegate.Combine|Remove(obj2, value), obj1);
// } while (obj1 != obj2) // } while ((object)obj1 != (object)obj2)
// //
var field_info = ((EventField) method).backing_field; var field_info = ((EventField) method).backing_field;
@ -924,7 +924,9 @@ namespace Mono.CSharp
block.AddStatement (new StatementExpression (new SimpleAssign (new LocalVariableReference (obj1, Location), f_expr))); block.AddStatement (new StatementExpression (new SimpleAssign (new LocalVariableReference (obj1, Location), f_expr)));
var cond = new BooleanExpression (new Binary (Binary.Operator.Inequality, var cond = new BooleanExpression (new Binary (Binary.Operator.Inequality,
new LocalVariableReference (obj1, Location), new LocalVariableReference (obj2, Location), Location)); new Cast (new TypeExpression (Module.Compiler.BuiltinTypes.Object, Location), new LocalVariableReference (obj1, Location), Location),
new Cast (new TypeExpression (Module.Compiler.BuiltinTypes.Object, Location), new LocalVariableReference (obj2, Location), Location),
Location));
var body = new ExplicitBlock (block, Location, Location); var body = new ExplicitBlock (block, Location, Location);
block.AddStatement (new Do (body, cond, Location)); block.AddStatement (new Do (body, cond, Location));
@ -999,6 +1001,12 @@ namespace Mono.CSharp
#region Properties #region Properties
public List<FieldDeclarator> Declarators {
get {
return this.declarators;
}
}
bool HasBackingField { bool HasBackingField {
get { get {
return !IsInterface && (ModFlags & Modifiers.ABSTRACT) == 0; return !IsInterface && (ModFlags & Modifiers.ABSTRACT) == 0;
@ -1020,14 +1028,14 @@ namespace Mono.CSharp
} }
} }
public List<FieldDeclarator> Declarators {
get {
return this.declarators;
}
}
#endregion #endregion
public override void Accept (StructuralVisitor visitor)
{
visitor.Visit (this);
}
public void AddDeclarator (FieldDeclarator declarator) public void AddDeclarator (FieldDeclarator declarator)
{ {
if (declarators == null) if (declarators == null)
@ -1105,11 +1113,6 @@ namespace Mono.CSharp
return true; return true;
} }
public override void Accept (StructuralVisitor visitor)
{
visitor.Visit (this);
}
} }
public abstract class Event : PropertyBasedMember public abstract class Event : PropertyBasedMember
@ -1310,7 +1313,7 @@ namespace Mono.CSharp
spec = new EventSpec (Parent.Definition, this, MemberType, ModFlags, Add.Spec, remove.Spec); spec = new EventSpec (Parent.Definition, this, MemberType, ModFlags, Add.Spec, remove.Spec);
Parent.MemberCache.AddMember (this, Name, spec); Parent.MemberCache.AddMember (this, GetFullName (MemberName), spec);
Parent.MemberCache.AddMember (this, AddBuilder.Name, Add.Spec); Parent.MemberCache.AddMember (this, AddBuilder.Name, Add.Spec);
Parent.MemberCache.AddMember (this, RemoveBuilder.Name, remove.Spec); Parent.MemberCache.AddMember (this, RemoveBuilder.Name, remove.Spec);
@ -1513,15 +1516,15 @@ namespace Mono.CSharp
#endregion #endregion
public override void Accept (StructuralVisitor visitor)
{
visitor.Visit (this);
}
public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa) public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
{ {
if (a.Type == pa.IndexerName) { if (a.Type == pa.IndexerName) {
if (IsExplicitImpl) {
Report.Error (415, a.Location,
"The `{0}' attribute is valid only on an indexer that is not an explicit interface member declaration",
TypeManager.CSharpName (a.Type));
}
// Attribute was copied to container // Attribute was copied to container
return; return;
} }
@ -1534,11 +1537,6 @@ namespace Mono.CSharp
return Parent.MemberCache.CheckExistingMembersOverloads (this, parameters); return Parent.MemberCache.CheckExistingMembersOverloads (this, parameters);
} }
public override void Accept (StructuralVisitor visitor)
{
visitor.Visit (this);
}
public override bool Define () public override bool Define ()
{ {
if (!base.Define ()) if (!base.Define ())
@ -1554,21 +1552,28 @@ namespace Mono.CSharp
if (compiling != null) if (compiling != null)
compiling.Define (); compiling.Define ();
string name = indexer_attr.GetIndexerAttributeValue (); if (IsExplicitImpl) {
if ((ModFlags & Modifiers.OVERRIDE) != 0) { Report.Error (415, indexer_attr.Location,
"The `{0}' attribute is valid only on an indexer that is not an explicit interface member declaration",
indexer_attr.Type.GetSignatureForError ());
} else if ((ModFlags & Modifiers.OVERRIDE) != 0) {
Report.Error (609, indexer_attr.Location, Report.Error (609, indexer_attr.Location,
"Cannot set the `IndexerName' attribute on an indexer marked override"); "Cannot set the `IndexerName' attribute on an indexer marked override");
} } else {
string name = indexer_attr.GetIndexerAttributeValue ();
if (!string.IsNullOrEmpty (name)) if (!string.IsNullOrEmpty (name)) {
ShortName = name; SetMemberName (new MemberName (MemberName.Left, name, Location));
}
}
} }
} }
if (InterfaceType != null) { if (InterfaceType != null) {
string base_IndexerName = InterfaceType.MemberDefinition.GetAttributeDefaultMember (); string base_IndexerName = InterfaceType.MemberDefinition.GetAttributeDefaultMember ();
if (base_IndexerName != Name) if (base_IndexerName != ShortName) {
ShortName = base_IndexerName; SetMemberName (new MemberName (MemberName.Left, base_IndexerName, new TypeExpression (InterfaceType, Location), Location));
}
} }
if (!Parent.PartialContainer.AddMember (this)) if (!Parent.PartialContainer.AddMember (this))
@ -1606,9 +1611,9 @@ namespace Mono.CSharp
public override string GetSignatureForError () public override string GetSignatureForError ()
{ {
StringBuilder sb = new StringBuilder (Parent.GetSignatureForError ()); StringBuilder sb = new StringBuilder (Parent.GetSignatureForError ());
if (MemberName.Left != null) { if (MemberName.ExplicitInterface != null) {
sb.Append ("."); sb.Append (".");
sb.Append (MemberName.Left.GetSignatureForError ()); sb.Append (MemberName.ExplicitInterface.GetSignatureForError ());
} }
sb.Append (".this"); sb.Append (".this");

14
ICSharpCode.NRefactory.CSharp/Parser/mcs/reflection.cs

@ -442,12 +442,7 @@ namespace Mono.CSharp
return assembly.GetType (compiler.BuiltinTypes.Object.FullName) != null; return assembly.GetType (compiler.BuiltinTypes.Object.FullName) != null;
} }
public override Assembly LoadAssemblyFile (string fileName) public override Assembly LoadAssemblyFile (string assembly, bool isImplicitReference)
{
return LoadAssemblyFile (fileName, false);
}
Assembly LoadAssemblyFile (string assembly, bool soft)
{ {
Assembly a = null; Assembly a = null;
@ -464,7 +459,7 @@ namespace Mono.CSharp
a = Assembly.Load (ass); a = Assembly.Load (ass);
} }
} catch (FileNotFoundException) { } catch (FileNotFoundException) {
bool err = !soft; bool err = !isImplicitReference;
foreach (string dir in paths) { foreach (string dir in paths) {
string full_path = Path.Combine (dir, assembly); string full_path = Path.Combine (dir, assembly);
if (!assembly.EndsWith (".dll") && !assembly.EndsWith (".exe")) if (!assembly.EndsWith (".dll") && !assembly.EndsWith (".exe"))
@ -490,11 +485,6 @@ namespace Mono.CSharp
return a; return a;
} }
public override Assembly LoadAssemblyDefault (string fileName)
{
return LoadAssemblyFile (fileName, true);
}
Module LoadModuleFile (AssemblyDefinitionDynamic assembly, string module) Module LoadModuleFile (AssemblyDefinitionDynamic assembly, string module)
{ {
string total_log = ""; string total_log = "";

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

@ -351,6 +351,12 @@ namespace Mono.CSharp
tc.CloseType (); tc.CloseType ();
} }
if (anonymous_types != null) {
foreach (var atypes in anonymous_types)
foreach (var at in atypes.Value)
at.CloseType ();
}
if (compiler_generated != null) if (compiler_generated != null)
foreach (CompilerGeneratedClass c in compiler_generated) foreach (CompilerGeneratedClass c in compiler_generated)
c.CloseType (); c.CloseType ();
@ -367,7 +373,7 @@ namespace Mono.CSharp
public RootNamespace CreateRootNamespace (string alias) public RootNamespace CreateRootNamespace (string alias)
{ {
if (alias == global_ns.Alias) { if (alias == global_ns.Alias) {
NamespaceContainer.Error_GlobalNamespaceRedefined (Location.Null, Report); RootNamespace.Error_GlobalNamespaceRedefined (Report, Location.Null);
return global_ns; return global_ns;
} }
@ -445,6 +451,12 @@ namespace Mono.CSharp
foreach (TypeContainer tc in types) foreach (TypeContainer tc in types)
tc.VerifyMembers (); tc.VerifyMembers ();
if (anonymous_types != null) {
foreach (var atypes in anonymous_types)
foreach (var at in atypes.Value)
at.EmitType ();
}
if (compiler_generated != null) if (compiler_generated != null)
foreach (var c in compiler_generated) foreach (var c in compiler_generated)
c.EmitType (); c.EmitType ();
@ -540,7 +552,7 @@ namespace Mono.CSharp
} }
string ns = mn.Left != null ? mn.Left.GetSignatureForError () : Module.GlobalRootNamespace.GetSignatureForError (); string ns = mn.Left != null ? mn.Left.GetSignatureForError () : Module.GlobalRootNamespace.GetSignatureForError ();
mn = new MemberName (mn.Name, mn.TypeArguments, mn.Location); mn = new MemberName (mn.Name, mn.TypeParameters, mn.Location);
Report.SymbolRelatedToPreviousError (found.Location, ""); Report.SymbolRelatedToPreviousError (found.Location, "");
Report.Error (101, container.Location, Report.Error (101, container.Location,

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

@ -154,9 +154,11 @@ namespace Mono.CSharp {
FalseStatement = false_statement; FalseStatement = false_statement;
loc = l; loc = l;
} }
public Expression Expr { public Expression Expr {
get { return this.expr; } get {
return this.expr;
}
} }
public override bool Resolve (BlockContext ec) public override bool Resolve (BlockContext ec)
@ -639,9 +641,11 @@ namespace Mono.CSharp {
this.expr = expr; this.expr = expr;
loc = expr.Location; loc = expr.Location;
} }
public ExpressionStatement Expr { public ExpressionStatement Expr {
get { return this.expr; } get {
return this.expr;
}
} }
protected override void CloneTo (CloneContext clonectx, Statement t) protected override void CloneTo (CloneContext clonectx, Statement t)
@ -676,7 +680,7 @@ namespace Mono.CSharp {
this.expr = expr; this.expr = expr;
} }
public Expression Expression { public Expression Expr {
get { get {
return expr; return expr;
} }
@ -779,25 +783,30 @@ namespace Mono.CSharp {
/// </summary> /// </summary>
public class Return : ExitStatement public class Return : ExitStatement
{ {
public Expression Expr { get; protected set; } Expression expr;
public Return (Expression expr, Location l) public Return (Expression expr, Location l)
{ {
Expr = expr; this.expr = expr;
loc = l; loc = l;
} }
#region Properties #region Properties
public Expression Expression {
public Expression Expr {
get { get {
return Expr; return expr;
}
protected set {
expr = value;
} }
} }
#endregion #endregion
protected override bool DoResolve (BlockContext ec) protected override bool DoResolve (BlockContext ec)
{ {
if (Expr == null) { if (expr == null) {
if (ec.ReturnType.Kind == MemberKind.Void) if (ec.ReturnType.Kind == MemberKind.Void)
return true; return true;
@ -811,7 +820,7 @@ namespace Mono.CSharp {
// //
// Extra trick not to emit ret/leave inside awaiter body // Extra trick not to emit ret/leave inside awaiter body
// //
Expr = EmptyExpression.Null; expr = EmptyExpression.Null;
return true; return true;
} }
} }
@ -827,7 +836,7 @@ namespace Mono.CSharp {
return false; return false;
} }
Expr = Expr.Resolve (ec); expr = expr.Resolve (ec);
TypeSpec block_return_type = ec.ReturnType; TypeSpec block_return_type = ec.ReturnType;
AnonymousExpression am = ec.CurrentAnonymousMethod; AnonymousExpression am = ec.CurrentAnonymousMethod;
@ -845,12 +854,12 @@ namespace Mono.CSharp {
var async_block = am as AsyncInitializer; var async_block = am as AsyncInitializer;
if (async_block != null) { if (async_block != null) {
if (Expr != null) { if (expr != null) {
var storey = (AsyncTaskStorey) am.Storey; var storey = (AsyncTaskStorey) am.Storey;
var async_type = storey.ReturnType; var async_type = storey.ReturnType;
if (async_type == null && async_block.ReturnTypeInference != null) { if (async_type == null && async_block.ReturnTypeInference != null) {
async_block.ReturnTypeInference.AddCommonTypeBound (Expr.Type); async_block.ReturnTypeInference.AddCommonTypeBound (expr.Type);
return true; return true;
} }
@ -871,20 +880,20 @@ namespace Mono.CSharp {
} }
} else { } else {
var l = am as AnonymousMethodBody; var l = am as AnonymousMethodBody;
if (l != null && l.ReturnTypeInference != null && Expr != null) { if (l != null && l.ReturnTypeInference != null && expr != null) {
l.ReturnTypeInference.AddCommonTypeBound (Expr.Type); l.ReturnTypeInference.AddCommonTypeBound (expr.Type);
return true; return true;
} }
} }
} }
if (Expr == null) if (expr == null)
return false; return false;
if (Expr.Type != block_return_type) { if (expr.Type != block_return_type) {
Expr = Convert.ImplicitConversionRequired (ec, Expr, block_return_type, loc); expr = Convert.ImplicitConversionRequired (ec, expr, block_return_type, loc);
if (Expr == null) { if (expr == null) {
if (am != null && block_return_type == ec.ReturnType) { if (am != null && block_return_type == ec.ReturnType) {
ec.Report.Error (1662, loc, ec.Report.Error (1662, loc,
"Cannot convert `{0}' to delegate type `{1}' because some of the return types in the block are not implicitly convertible to the delegate return type", "Cannot convert `{0}' to delegate type `{1}' because some of the return types in the block are not implicitly convertible to the delegate return type",
@ -899,8 +908,8 @@ namespace Mono.CSharp {
protected override void DoEmit (EmitContext ec) protected override void DoEmit (EmitContext ec)
{ {
if (Expr != null) { if (expr != null) {
Expr.Emit (ec); expr.Emit (ec);
var async_body = ec.CurrentAnonymousMethod as AsyncInitializer; var async_body = ec.CurrentAnonymousMethod as AsyncInitializer;
if (async_body != null) { if (async_body != null) {
@ -936,9 +945,10 @@ namespace Mono.CSharp {
{ {
Return target = (Return) t; Return target = (Return) t;
// It's null for simple return; // It's null for simple return;
if (Expr != null) if (expr != null)
target.Expr = Expr.Clone (clonectx); target.expr = expr.Clone (clonectx);
} }
public override object Accept (StructuralVisitor visitor) public override object Accept (StructuralVisitor visitor)
{ {
return visitor.Visit (this); return visitor.Visit (this);
@ -1135,9 +1145,11 @@ namespace Mono.CSharp {
expr = e; expr = e;
loc = l; loc = l;
} }
public Expression Expr { public Expression Expr {
get { return this.expr; } get {
return this.expr;
}
} }
public override bool Resolve (BlockContext ec) public override bool Resolve (BlockContext ec)
@ -1207,11 +1219,13 @@ namespace Mono.CSharp {
this.expr = expr; this.expr = expr;
loc = l; loc = l;
} }
public Expression Expr { public Expression Expr {
get { return this.expr; } get {
return this.expr;
}
} }
public override bool Resolve (BlockContext ec) public override bool Resolve (BlockContext ec)
{ {
if (expr == null) { if (expr == null) {
@ -1872,6 +1886,7 @@ namespace Mono.CSharp {
public static string GetCompilerGeneratedName (Block block) public static string GetCompilerGeneratedName (Block block)
{ {
// HACK: Debugger depends on the name semantics
return "$locvar" + block.ParametersBlock.TemporaryLocalsCount++.ToString ("X"); return "$locvar" + block.ParametersBlock.TemporaryLocalsCount++.ToString ("X");
} }
@ -1988,7 +2003,7 @@ namespace Mono.CSharp {
int? resolving_init_idx; int? resolving_init_idx;
protected Block original; Block original;
#if DEBUG #if DEBUG
static int id; static int id;
@ -2035,6 +2050,9 @@ namespace Mono.CSharp {
get { get {
return original; return original;
} }
protected set {
original = value;
}
} }
public bool IsCompilerGenerated { public bool IsCompilerGenerated {
@ -2051,10 +2069,11 @@ namespace Mono.CSharp {
get { return (flags & Flags.Unsafe) != 0; } get { return (flags & Flags.Unsafe) != 0; }
set { flags |= Flags.Unsafe; } set { flags |= Flags.Unsafe; }
} }
public List<Statement> Statements { public List<Statement> Statements {
get { return this.statements; } get { return statements; }
} }
#endregion #endregion
public Block CreateSwitchBlock (Location start) public Block CreateSwitchBlock (Location start)
@ -2328,6 +2347,7 @@ namespace Mono.CSharp {
foreach (Statement s in statements) foreach (Statement s in statements)
target.statements.Add (s.Clone (clonectx)); target.statements.Add (s.Clone (clonectx));
} }
public override object Accept (StructuralVisitor visitor) public override object Accept (StructuralVisitor visitor)
{ {
return visitor.Visit (this); return visitor.Visit (this);
@ -2692,7 +2712,7 @@ namespace Mono.CSharp {
// Overwrite original for comparison purposes when linking cross references // Overwrite original for comparison purposes when linking cross references
// between anonymous methods // between anonymous methods
// //
original = source; Original = source;
} }
#region Properties #region Properties
@ -2906,7 +2926,7 @@ namespace Mono.CSharp {
ParametersBlock pb = new ParametersBlock (this, ParametersCompiled.EmptyReadOnlyParameters, StartLocation); ParametersBlock pb = new ParametersBlock (this, ParametersCompiled.EmptyReadOnlyParameters, StartLocation);
pb.EndLocation = EndLocation; pb.EndLocation = EndLocation;
pb.statements = statements; pb.statements = statements;
pb.original = this; pb.Original = this;
var iterator = new Iterator (pb, method, host, iterator_type, is_enumerable); var iterator = new Iterator (pb, method, host, iterator_type, is_enumerable);
am_storey = new IteratorStorey (iterator); am_storey = new IteratorStorey (iterator);
@ -2921,7 +2941,7 @@ namespace Mono.CSharp {
ParametersBlock pb = new ParametersBlock (this, ParametersCompiled.EmptyReadOnlyParameters, StartLocation); ParametersBlock pb = new ParametersBlock (this, ParametersCompiled.EmptyReadOnlyParameters, StartLocation);
pb.EndLocation = EndLocation; pb.EndLocation = EndLocation;
pb.statements = statements; pb.statements = statements;
pb.original = this; pb.Original = this;
var block_type = host.Module.Compiler.BuiltinTypes.Void; var block_type = host.Module.Compiler.BuiltinTypes.Void;
var initializer = new AsyncInitializer (pb, host, block_type); var initializer = new AsyncInitializer (pb, host, block_type);
@ -4468,11 +4488,13 @@ namespace Mono.CSharp {
{ {
this.expr = expr; this.expr = expr;
} }
public Expression Expr { public Expression Expr {
get { return this.expr; } get {
return this.expr;
}
} }
public override bool Resolve (BlockContext ec) public override bool Resolve (BlockContext ec)
{ {
expr = expr.Resolve (ec); expr = expr.Resolve (ec);
@ -5151,6 +5173,12 @@ namespace Mono.CSharp {
this.fini = fini; this.fini = fini;
} }
public Block Finallyblock {
get {
return fini;
}
}
public override bool Resolve (BlockContext ec) public override bool Resolve (BlockContext ec)
{ {
bool ok = true; bool ok = true;
@ -5202,23 +5230,20 @@ namespace Mono.CSharp {
public class TryCatch : ExceptionStatement public class TryCatch : ExceptionStatement
{ {
public Block Block; public Block Block;
public List<Catch> Specific; List<Catch> clauses;
public Catch General;
readonly bool inside_try_finally; readonly bool inside_try_finally;
public TryCatch (Block block, List<Catch> catch_clauses, Location l, bool inside_try_finally) public TryCatch (Block block, List<Catch> catch_clauses, Location l, bool inside_try_finally)
: base (l) : base (l)
{ {
this.Block = block; this.Block = block;
this.Specific = catch_clauses; this.clauses = catch_clauses;
this.inside_try_finally = inside_try_finally; this.inside_try_finally = inside_try_finally;
}
if (catch_clauses != null) {
Catch c = catch_clauses [0]; public List<Catch> Clauses {
if (c.IsGeneral) { get {
this.General = c; return clauses;
catch_clauses.RemoveAt (0);
}
} }
} }
@ -5237,9 +5262,8 @@ namespace Mono.CSharp {
if (!Block.Resolve (ec)) if (!Block.Resolve (ec))
ok = false; ok = false;
TypeSpec[] prev_catches = new TypeSpec [Specific.Count]; for (int i = 0; i < clauses.Count; ++i) {
int last_index = 0; var c = clauses[i];
foreach (Catch c in Specific){
ec.CurrentBranching.CreateSibling (c.Block, FlowBranching.SiblingType.Catch); ec.CurrentBranching.CreateSibling (c.Block, FlowBranching.SiblingType.Catch);
if (!c.Resolve (ec)) { if (!c.Resolve (ec)) {
@ -5248,37 +5272,40 @@ namespace Mono.CSharp {
} }
TypeSpec resolved_type = c.CatchType; TypeSpec resolved_type = c.CatchType;
for (int ii = 0; ii < last_index; ++ii) { for (int ii = 0; ii < clauses.Count; ++ii) {
if (resolved_type == prev_catches[ii] || TypeSpec.IsBaseClass (resolved_type, prev_catches[ii], true)) { if (ii == i)
ec.Report.Error (160, c.loc, continue;
"A previous catch clause already catches all exceptions of this or a super type `{0}'",
TypeManager.CSharpName (prev_catches [ii]));
ok = false;
}
}
prev_catches [last_index++] = resolved_type; if (clauses[ii].IsGeneral) {
} if (resolved_type.BuiltinType != BuiltinTypeSpec.Type.Exception)
continue;
if (!ec.Module.DeclaringAssembly.WrapNonExceptionThrows)
continue;
if (!ec.Module.PredefinedAttributes.RuntimeCompatibility.IsDefined)
continue;
ec.Report.Warning (1058, 1, c.loc,
"A previous catch clause already catches all exceptions. All non-exceptions thrown will be wrapped in a `System.Runtime.CompilerServices.RuntimeWrappedException'");
if (General != null) {
foreach (Catch c in Specific) {
if (c.CatchType.BuiltinType != BuiltinTypeSpec.Type.Exception)
continue; continue;
}
if (!ec.Module.DeclaringAssembly.WrapNonExceptionThrows) if (ii >= i)
continue; continue;
if (!ec.Module.PredefinedAttributes.RuntimeCompatibility.IsDefined) var ct = clauses[ii].CatchType;
if (ct == null)
continue; continue;
ec.Report.Warning (1058, 1, c.loc, if (resolved_type == ct || TypeSpec.IsBaseClass (resolved_type, ct, true)) {
"A previous catch clause already catches all exceptions. All non-exceptions thrown will be wrapped in a `System.Runtime.CompilerServices.RuntimeWrappedException'"); ec.Report.Error (160, c.loc,
"A previous catch clause already catches all exceptions of this or a super type `{0}'",
ct.GetSignatureForError ());
ok = false;
}
} }
ec.CurrentBranching.CreateSibling (General.Block, FlowBranching.SiblingType.Catch);
if (!General.Resolve (ec))
ok = false;
} }
ec.EndFlowBranching (); ec.EndFlowBranching ();
@ -5293,12 +5320,9 @@ namespace Mono.CSharp {
Block.Emit (ec); Block.Emit (ec);
foreach (Catch c in Specific) foreach (Catch c in clauses)
c.Emit (ec); c.Emit (ec);
if (General != null)
General.Emit (ec);
if (!inside_try_finally) if (!inside_try_finally)
ec.EndExceptionBlock (); ec.EndExceptionBlock ();
} }
@ -5308,14 +5332,13 @@ namespace Mono.CSharp {
TryCatch target = (TryCatch) t; TryCatch target = (TryCatch) t;
target.Block = clonectx.LookupBlock (Block); target.Block = clonectx.LookupBlock (Block);
if (General != null) if (clauses != null){
target.General = (Catch) General.Clone (clonectx); target.clauses = new List<Catch> ();
if (Specific != null){ foreach (Catch c in clauses)
target.Specific = new List<Catch> (); target.clauses.Add ((Catch) c.Clone (clonectx));
foreach (Catch c in Specific)
target.Specific.Add ((Catch) c.Clone (clonectx));
} }
} }
public override object Accept (StructuralVisitor visitor) public override object Accept (StructuralVisitor visitor)
{ {
return visitor.Visit (this); return visitor.Visit (this);
@ -5468,7 +5491,7 @@ namespace Mono.CSharp {
declarators = null; declarators = null;
return stmt; return stmt;
} }
public override object Accept (StructuralVisitor visitor) public override object Accept (StructuralVisitor visitor)
{ {
@ -5492,7 +5515,7 @@ namespace Mono.CSharp {
#region Properties #region Properties
public Expression Expression { public Expression Expr {
get { get {
return decl.Variable == null ? decl.Initializer : null; return decl.Variable == null ? decl.Initializer : null;
} }
@ -5571,6 +5594,7 @@ namespace Mono.CSharp {
target.decl = (VariableDeclaration) decl.Clone (clonectx); target.decl = (VariableDeclaration) decl.Clone (clonectx);
target.stmt = stmt.Clone (clonectx); target.stmt = stmt.Clone (clonectx);
} }
public override object Accept (StructuralVisitor visitor) public override object Accept (StructuralVisitor visitor)
{ {
return visitor.Visit (this); return visitor.Visit (this);
@ -6114,14 +6138,6 @@ namespace Mono.CSharp {
LocalVariable variable; LocalVariable variable;
Expression expr; Expression expr;
Statement statement; Statement statement;
public Expression TypeExpr {
get { return this.type; }
}
public LocalVariable Variable {
get { return this.variable; }
}
public Foreach (Expression type, LocalVariable var, Expression expr, Statement stmt, Location l) public Foreach (Expression type, LocalVariable var, Expression expr, Statement stmt, Location l)
{ {
@ -6132,14 +6148,23 @@ namespace Mono.CSharp {
loc = l; loc = l;
} }
public Expression Expr {
get { return expr; }
}
public Statement Statement { public Statement Statement {
get { return statement; } get { return statement; }
} }
public Expression Expr { public Expression TypeExpression {
get { return this.expr; } get { return type; }
} }
public LocalVariable Variable {
get { return variable; }
}
public override bool Resolve (BlockContext ec) public override bool Resolve (BlockContext ec)
{ {
expr = expr.Resolve (ec); expr = expr.Resolve (ec);

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

@ -37,7 +37,7 @@ namespace Mono.CSharp {
return System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode (obj); return System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode (obj);
} }
} }
#if !NET_4_0
public class Tuple<T1, T2> : IEquatable<Tuple<T1, T2>> public class Tuple<T1, T2> : IEquatable<Tuple<T1, T2>>
{ {
public Tuple (T1 item1, T2 item2) public Tuple (T1 item1, T2 item2)
@ -107,6 +107,7 @@ namespace Mono.CSharp {
return new Tuple<T1, T2, T3> (item1, item2, item3); return new Tuple<T1, T2, T3> (item1, item2, item3);
} }
} }
#endif
static class ArrayComparer static class ArrayComparer
{ {

Loading…
Cancel
Save