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

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

@ -36,15 +36,18 @@ namespace Mono.CSharp { @@ -36,15 +36,18 @@ namespace Mono.CSharp {
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);
TypeArguments args = null;
TypeParameters args = null;
if (tparams != null) {
args = new TypeArguments ();
foreach (TypeParameter tparam in tparams)
args.Add (new TypeParameterName (tparam.Name, null, loc));
args = new TypeParameters (tparams.Count);
// 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);
@ -81,15 +84,16 @@ namespace Mono.CSharp { @@ -81,15 +84,16 @@ namespace Mono.CSharp {
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)
{
if (tparams != null) {
type_params = new TypeParameter[tparams.Length];
var src = new TypeParameterSpec[tparams.Length];
var dst = new TypeParameterSpec[tparams.Length];
var type_params = name.TypeParameters;
var src = new TypeParameterSpec[tparams.Count];
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);
src[i] = tparams[i].Type;
@ -99,7 +103,7 @@ namespace Mono.CSharp { @@ -99,7 +103,7 @@ namespace Mono.CSharp {
// A copy is not enough, inflate any type parameter constraints
// using a new type parameters
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]);
}
@ -196,7 +200,7 @@ namespace Mono.CSharp { @@ -196,7 +200,7 @@ namespace Mono.CSharp {
// Local variable which holds this storey 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),
tparams, Modifiers.SEALED)
{
@ -323,8 +327,8 @@ namespace Mono.CSharp { @@ -323,8 +327,8 @@ namespace Mono.CSharp {
// Use current method type parameter (MVAR) for top level storey only. All
// nested storeys use class type parameter (VAR)
//
TypeParameter[] tparams = ec.CurrentAnonymousMethod != null && ec.CurrentAnonymousMethod.Storey != null ?
ec.CurrentAnonymousMethod.Storey.TypeParameters :
var tparams = ec.CurrentAnonymousMethod != null && ec.CurrentAnonymousMethod.Storey != null ?
ec.CurrentAnonymousMethod.Storey.CurrentTypeParameters :
ec.CurrentTypeParameters;
TypeArguments targs = new TypeArguments ();
@ -333,7 +337,7 @@ namespace Mono.CSharp { @@ -333,7 +337,7 @@ namespace Mono.CSharp {
// Use type parameter name instead of resolved type parameter
// 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));
storey_type_expr = new GenericTypeExpr (Definition, targs, Location);
@ -347,19 +351,18 @@ namespace Mono.CSharp { @@ -347,19 +351,18 @@ namespace Mono.CSharp {
public void SetNestedStoryParent (AnonymousMethodStorey parentStorey)
{
Parent = parentStorey;
type_params = null;
spec.IsGeneric = false;
spec.DeclaringType = parentStorey.CurrentType;
MemberName.TypeArguments = null;
MemberName.TypeParameters = null;
}
protected override bool DoResolveTypeParameters ()
{
// 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
if (type_params != null) {
for (int i = 0; i < type_params.Length; ++i) {
var spec = type_params[i].Type;
if (CurrentTypeParameters != null) {
for (int i = 0; i < CurrentTypeParameters.Count; ++i) {
var spec = CurrentTypeParameters[i].Type;
spec.BaseType = mutator.Mutate (spec.BaseType);
if (spec.InterfacesDefined != null) {
var mutated = new TypeSpec[spec.InterfacesDefined.Length];
@ -885,9 +888,8 @@ namespace Mono.CSharp { @@ -885,9 +888,8 @@ namespace Mono.CSharp {
public ParametersBlock Block;
public AnonymousMethodExpression (bool isAsync, Location loc)
public AnonymousMethodExpression (Location loc)
{
this.IsAsync = isAsync;
this.loc = loc;
this.compatibles = new Dictionary<TypeSpec, Expression> ();
}
@ -1588,16 +1590,17 @@ namespace Mono.CSharp { @@ -1588,16 +1590,17 @@ namespace Mono.CSharp {
MemberName member_name;
GenericMethod generic_method;
if (storey == null && mc.MemberName.TypeArguments != null) {
member_name = new MemberName (name, mc.MemberName.TypeArguments.Clone (), Location);
if (storey == null && ec.CurrentTypeParameters != null) {
var hoisted_tparams = ec.CurrentTypeParameters;
var type_params = new TypeParameter[hoisted_tparams.Length];
for (int i = 0; i < type_params.Length; ++i) {
type_params[i] = hoisted_tparams[i].CreateHoistedCopy (parent, null);
var type_params = new TypeParameters (hoisted_tparams.Count);
for (int i = 0; i < hoisted_tparams.Count; ++i) {
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);
} else {
member_name = new MemberName (name, Location);
@ -1782,16 +1785,15 @@ namespace Mono.CSharp { @@ -1782,16 +1785,15 @@ namespace Mono.CSharp {
string name = ClassNamePrefix + types_counter++;
ParametersCompiled all_parameters;
TypeParameterName[] t_params;
TypeParameters tparams = null;
SimpleName[] t_args;
if (parameters.Count == 0) {
all_parameters = ParametersCompiled.EmptyReadOnlyParameters;
t_params = new TypeParameterName[0];
t_args = null;
} else {
t_args = new SimpleName[parameters.Count];
t_params = new TypeParameterName[parameters.Count];
tparams = new TypeParameters ();
Parameter[] ctor_params = new Parameter[parameters.Count];
for (int i = 0; i < parameters.Count; ++i) {
AnonymousTypeParameter p = parameters[i];
@ -1808,7 +1810,7 @@ namespace Mono.CSharp { @@ -1808,7 +1810,7 @@ namespace Mono.CSharp {
}
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);
}
@ -1820,13 +1822,13 @@ namespace Mono.CSharp { @@ -1820,13 +1822,13 @@ namespace Mono.CSharp {
// named upon properties names
//
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)
a_type.SetParameterInfo (null);
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);
//
@ -1913,10 +1915,11 @@ namespace Mono.CSharp { @@ -1913,10 +1915,11 @@ namespace Mono.CSharp {
ToplevelBlock equals_block = new ToplevelBlock (Compiler, equals.ParameterInfo, loc);
TypeExpr current_type;
if (type_params != null) {
if (CurrentTypeParameters != null) {
var targs = new TypeArguments ();
foreach (var type_param in type_params)
targs.Add (new TypeParameterExpr (type_param, type_param.Location));
for (int i = 0; i < CurrentTypeParameters.Count; ++i) {
targs.Add (new TypeParameterExpr (CurrentTypeParameters[i], Location));
}
current_type = new GenericTypeExpr (Definition, targs, loc);
} else {

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

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

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

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

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

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

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

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

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

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

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

@ -37,7 +37,7 @@ namespace Mono.CSharp @@ -37,7 +37,7 @@ namespace Mono.CSharp
//
// 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
@ -393,7 +393,7 @@ namespace Mono.CSharp @@ -393,7 +393,7 @@ namespace Mono.CSharp
get { return MemberContext.CurrentType; }
}
public TypeParameter[] CurrentTypeParameters {
public TypeParameters 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 @@ -428,19 +428,26 @@ extern_alias_directive
{
var lt = (Tokenizer.LocatedToken) $2;
string s = lt.Value;
if (s != "alias"){
if (s != "alias") {
syntax_error (lt.Location, "`alias' expected");
} else if (lang_version == LanguageVersion.ISO_1) {
FeatureIsNotAvailable (lt.Location, "external alias");
} else {
lt = (Tokenizer.LocatedToken) $3;
current_namespace.AddUsingExternalAlias (lt.Value, lt.Location, report);
ubag.AddExternAlias (GetLocation ($1), GetLocation ($2), lt, GetLocation ($4));
if (lang_version == LanguageVersion.ISO_1)
FeatureIsNotAvailable (lt.Location, "external alias");
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
{
syntax_error (GetLocation ($1), "`alias' expected"); // TODO: better
Error_SyntaxError (yyToken);
}
;
@ -450,20 +457,23 @@ using_directives @@ -450,20 +457,23 @@ using_directives
;
using_directive
: using_alias_directive
{
if (doc_support)
Lexer.doc_state = XmlCommentState.Allowed;
}
| using_namespace_directive
: using_namespace
{
if (doc_support)
Lexer.doc_state = XmlCommentState.Allowed;
}
;
using_alias_directive
: USING IDENTIFIER ASSIGN namespace_or_type_name SEMICOLON
using_namespace
: 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;
if (lang_version != LanguageVersion.ISO_1 && lt.Value == "global") {
@ -471,22 +481,17 @@ using_alias_directive @@ -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");
}
current_namespace.AddUsingAlias (lt.Value, (MemberName) $4, GetLocation ($1));
ubag.AddUsingAlias (GetLocation ($1), lt, GetLocation ($3), (MemberName) $4, GetLocation ($5));
}
var un = new UsingAliasNamespace (new SimpleMemberName (lt.Value, lt.Location), (ATypeNameExpression) $4, GetLocation ($1));
current_namespace.AddUsing (un);
ubag.AddUsingAlias (GetLocation ($1), lt, GetLocation ($3), (ATypeNameExpression) $4, GetLocation ($5));
lbag.AddLocation (un, GetLocation ($3), GetLocation ($5));
}
| USING error
{
Error_SyntaxError (yyToken);
$$ = 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 @@ -495,10 +500,10 @@ using_namespace_directive
// detach them
//
namespace_declaration
: opt_attributes NAMESPACE qualified_identifier
: opt_attributes NAMESPACE namespace_name
{
Attributes attrs = (Attributes) $1;
MemberName name = (MemberName) $3;
var name = (MemberName) $3;
if (attrs != null) {
bool valid_global_attrs = true;
if ((current_namespace.DeclarationFound || current_namespace != file.NamespaceContainer)) {
@ -545,13 +550,13 @@ namespace_declaration @@ -545,13 +550,13 @@ namespace_declaration
}
;
qualified_identifier
namespace_name
: IDENTIFIER
{
var lt = (Tokenizer.LocatedToken) $1;
$$ = new MemberName (lt.Value, lt.Location);
}
| qualified_identifier DOT IDENTIFIER
| namespace_name DOT IDENTIFIER
{
var lt = (Tokenizer.LocatedToken) $3;
$$ = new MemberName ((MemberName) $1, lt.Value, lt.Location) {
@ -575,18 +580,6 @@ opt_comma @@ -575,18 +580,6 @@ opt_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
: /* empty */
| using_directives
@ -776,26 +769,18 @@ attribute @@ -776,26 +769,18 @@ attribute
opt_attribute_arguments
{
--lexer.parsing_block;
MemberName mname = (MemberName) $1;
if (mname.IsGeneric) {
report.Error (404, lexer.Location,
"'<' unexpected: attributes cannot be generic");
var tne = (ATypeNameExpression) $1;
if (tne.HasTypeArguments) {
report.Error (404, tne.Location, "Attributes cannot be generic");
}
Arguments [] arguments = (Arguments []) $3;
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 ();
}
$$ = new Attribute (current_attr_target, tne, (Arguments[]) $3, GetLocation ($1), lexer.IsEscapedIdentifier (tne));
}
;
attribute_name
: namespace_or_type_name
: namespace_or_type_expr
;
opt_attribute_arguments
@ -1293,7 +1278,7 @@ method_header @@ -1293,7 +1278,7 @@ method_header
current_local_parameters = (ParametersCompiled) $7;
GenericMethod generic = null;
if (name.TypeArguments != null) {
if (name.TypeParameters != null) {
generic = new GenericMethod (current_namespace, current_class, name,
(FullNamedExpression) $3, current_local_parameters);
@ -1337,12 +1322,12 @@ method_header @@ -1337,12 +1322,12 @@ method_header
MemberName name = (MemberName) $6;
current_local_parameters = (ParametersCompiled) $9;
if ($11 != null && name.TypeArguments == null)
if ($11 != null && name.TypeParameters == null)
report.Error (80, lexer.Location,
"Constraints are not allowed on non-generic declarations");
GenericMethod generic = null;
if (name.TypeArguments != null) {
if (name.TypeParameters != null) {
generic = new GenericMethod (current_namespace, current_class, name,
new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($4)),
current_local_parameters);
@ -2208,23 +2193,12 @@ constructor_declarator @@ -2208,23 +2193,12 @@ constructor_declarator
OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
{
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 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) {
report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
} else if ((mods & Modifiers.STATIC) != 0) {
@ -2233,16 +2207,32 @@ constructor_declarator @@ -2233,16 +2207,32 @@ constructor_declarator
"`{0}': static constructor cannot have an access modifier",
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,
"`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
c.GetSignatureForError ());
}
}
lbag.AddMember (c, GetModifierLocations (), GetLocation ($5), GetLocation ($7));
$$ = c;
$$ = $8;
}
;
@ -2324,7 +2314,7 @@ event_declaration @@ -2324,7 +2314,7 @@ event_declaration
current_event_field = new EventField (current_class, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
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",
current_event_field.GetSignatureForError ());
}
@ -2709,33 +2699,33 @@ opt_nullable @@ -2709,33 +2699,33 @@ opt_nullable
}
;
namespace_or_type_name
namespace_or_type_expr
: member_name
| qualified_alias_member IDENTIFIER opt_type_argument_list
{
var lt1 = (Tokenizer.LocatedToken) $1;
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
: type_name
| namespace_or_type_name DOT IDENTIFIER opt_type_argument_list
: simple_name_expr
| namespace_or_type_expr DOT IDENTIFIER opt_type_argument_list
{
var lt = (Tokenizer.LocatedToken) $3;
$$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $4, lt.Location) {
DotLocation = GetLocation ($2)
};
$$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
lbag.AddLocation ($$, GetLocation ($2));
}
;
type_name
simple_name_expr
: IDENTIFIER opt_type_argument_list
{
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 @@ -2791,7 +2781,7 @@ type_declaration_name
{
lexer.parsing_generic_declaration = false;
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 @@ -2799,7 +2789,7 @@ member_declaration_name
: method_declaration_name
{
MemberName mn = (MemberName)$1;
if (mn.TypeArguments != null)
if (mn.TypeParameters != null)
syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
mn.GetSignatureForError ()));
}
@ -2811,7 +2801,7 @@ method_declaration_name @@ -2811,7 +2801,7 @@ method_declaration_name
{
lexer.parsing_generic_declaration = false;
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 @@ -2824,7 +2814,7 @@ indexer_declaration_name
| explicit_interface THIS
{
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 @@ -2832,21 +2822,21 @@ explicit_interface
: IDENTIFIER opt_type_argument_list DOT
{
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));
}
| qualified_alias_member IDENTIFIER opt_type_argument_list DOT
{
var lt1 = (Tokenizer.LocatedToken) $1;
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));
}
| explicit_interface IDENTIFIER opt_type_argument_list DOT
{
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));
}
;
@ -2866,16 +2856,16 @@ opt_type_parameter_list @@ -2866,16 +2856,16 @@ opt_type_parameter_list
type_parameters
: type_parameter
{
TypeArguments type_args = new TypeArguments ();
type_args.Add ((FullNamedExpression)$1);
$$ = type_args;
var tparams = new TypeParameters ();
tparams.Add ((TypeParameter)$1);
$$ = tparams;
}
| type_parameters COMMA type_parameter
{
TypeArguments type_args = (TypeArguments) $1;
type_args.Add ((FullNamedExpression)$3);
$$ = type_args;
lbag.AppendTo (type_args, GetLocation ($2));
var tparams = (TypeParameters) $1;
tparams.Add ((TypeParameter)$3);
$$ = tparams;
lbag.AddLocation ($3, GetLocation ($3));
}
;
@ -2883,10 +2873,7 @@ type_parameter @@ -2883,10 +2873,7 @@ type_parameter
: opt_attributes opt_type_parameter_variance IDENTIFIER
{
var lt = (Tokenizer.LocatedToken)$3;
var variance = (Variance) $2;
$$ = new TypeParameterName (lt.Value, (Attributes)$1, variance, lt.Location);
if (variance != Variance.None)
lbag.AddLocation ($$, savedLocation);
$$ = new TypeParameter (new MemberName (lt.Value, lt.Location), (Attributes)$1, (Variance) $2);
}
| error
{
@ -2895,7 +2882,7 @@ type_parameter @@ -2895,7 +2882,7 @@ type_parameter
else
Error_SyntaxError (yyToken);
$$ = new TypeParameterName ("", null, lexer.Location);
$$ = new TypeParameter (MemberName.Null, null, Variance.None);
}
;
@ -2956,22 +2943,21 @@ type_expression_or_array @@ -2956,22 +2943,21 @@ type_expression_or_array
;
type_expression
: namespace_or_type_name opt_nullable
: namespace_or_type_expr opt_nullable
{
MemberName name = (MemberName) $1;
if ($2 != null) {
$$ = new ComposedCast (name.GetTypeExpression (), (ComposedTypeSpecifier) $2);
$$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
} else {
if (name.Left == null && name.Name == "var")
$$ = new VarExpr (name.Location);
var sn = $1 as SimpleName;
if (sn != null && sn.Name == "var")
$$ = new VarExpr (sn.Location);
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
{
@ -3736,16 +3722,16 @@ unbound_type_name @@ -3736,16 +3722,16 @@ unbound_type_name
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 ();
if (te.HasTypeArguments)
var tne = (ATypeNameExpression) $1;
if (tne.HasTypeArguments)
Error_TypeExpected (GetLocation ($4));
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)
};
};
}
;
@ -5103,7 +5089,7 @@ statement_expression @@ -5103,7 +5089,7 @@ statement_expression
ExpressionStatement s = $1 as ExpressionStatement;
if (s == null) {
Expression.Error_InvalidExpressionStatement (report, GetLocation ($1));
$$ = new InvalidStatementExpression ($1 as Expression);
$$ = new StatementErrorExpression ($1 as Expression);
} else {
$$ = new StatementExpression (s);
}
@ -5152,9 +5138,10 @@ if_statement @@ -5152,9 +5138,10 @@ if_statement
if ($7 is EmptyStatement)
Warning_EmptyStatement (GetLocation ($7));
}
| IF open_parens_any boolean_expression error {
var eloc = GetLocation ($3);
report.Error (1026, eloc, "Expected a ')'");
| IF open_parens_any boolean_expression error
{
Error_SyntaxError (yyToken);
$$ = new If ((BooleanExpression) $3, null, GetLocation ($1));
lbag.AddStatement ($$, GetLocation ($2));
}
@ -5171,6 +5158,13 @@ switch_statement @@ -5171,6 +5158,13 @@ switch_statement
end_block (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
@ -5199,7 +5193,7 @@ switch_sections @@ -5199,7 +5193,7 @@ switch_sections
}
| error
{
Error_SyntaxError (yyToken);
Error_SyntaxError (yyToken);
$$ = new List<SwitchSection> ();
}
;
@ -5260,24 +5254,30 @@ while_statement @@ -5260,24 +5254,30 @@ while_statement
$$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
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 embedded_statement
WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
: DO embedded_statement WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
{
$$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1));
lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
}
| DO embedded_statement error
{
var loc = GetLocation ($1);
report.Error (-100, loc, "Expected `while'");
$$ = new Do ((Statement) $2, null, loc);
Error_SyntaxError (yyToken);
$$ = new Do ((Statement) $2, null, GetLocation ($1));
}
| DO embedded_statement
WHILE open_parens_any boolean_expression error
| DO embedded_statement WHILE open_parens_any boolean_expression error
{
Error_SyntaxError (yyToken);
$$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1));
lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4));
}
@ -5383,10 +5383,35 @@ statement_expression_list @@ -5383,10 +5383,35 @@ statement_expression_list
;
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");
$$ = 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
{
@ -5544,9 +5569,9 @@ try_statement @@ -5544,9 +5569,9 @@ try_statement
$$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), true), (Block) $5, GetLocation ($1));
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);
}
;
@ -5564,15 +5589,11 @@ catch_clauses @@ -5564,15 +5589,11 @@ catch_clauses
var l = (List<Catch>) $1;
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");
} else {
if (c.IsGeneral)
l.Insert (0, c);
else
l.Add (c);
}
l.Add (c);
$$ = l;
}
;
@ -5652,6 +5673,13 @@ lock_statement @@ -5652,6 +5673,13 @@ lock_statement
$$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
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
@ -5713,9 +5741,15 @@ using_statement @@ -5713,9 +5741,15 @@ using_statement
if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
Warning_EmptyStatement (GetLocation ($5));
Using u = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
lbag.AddStatement (u, GetLocation ($2), GetLocation ($4));
$$ = u;
$$ = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
}
| 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 @@ -5959,7 +5993,7 @@ let_clause
var sn = new Linq.RangeVariable (lt.Value, lt.Location);
$$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
lbag.AddLocation ($$, GetLocation ($3));
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
@ -6332,7 +6366,7 @@ doc_cref @@ -6332,7 +6366,7 @@ doc_cref
}
| 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
{
@ -6341,7 +6375,7 @@ doc_cref @@ -6341,7 +6375,7 @@ doc_cref
opt_doc_parameters CLOSE_BRACKET
{
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
{
@ -6522,11 +6556,9 @@ DeclSpace pop_current_class () @@ -6522,11 +6556,9 @@ DeclSpace pop_current_class ()
MemberName
MakeName (MemberName class_name)
{
Namespace ns = current_namespace.NS;
if (current_container == module) {
if (ns.Name.Length != 0)
return new MemberName (ns.MemberName, class_name);
if (current_namespace.MemberName != MemberName.Null)
return new MemberName (current_namespace.NS.MemberName, class_name);
else
return class_name;
} else {
@ -6747,12 +6779,12 @@ void start_anonymous (bool isLambda, ParametersCompiled parameters, bool isAsync @@ -6747,12 +6779,12 @@ void start_anonymous (bool isLambda, ParametersCompiled parameters, bool isAsync
if (lang_version <= LanguageVersion.ISO_2)
FeatureIsNotAvailable (loc, "lambda expressions");
current_anonymous_method = new LambdaExpression (isAsync, loc);
current_anonymous_method = new LambdaExpression (loc);
} else {
if (lang_version == LanguageVersion.ISO_1)
FeatureIsNotAvailable (loc, "anonymous methods");
current_anonymous_method = new AnonymousMethodExpression (isAsync, loc);
current_anonymous_method = new AnonymousMethodExpression (loc);
}
async_block = isAsync;
@ -6784,7 +6816,12 @@ AnonymousMethodExpression end_anonymous (ParametersBlock anon_block) @@ -6784,7 +6816,12 @@ AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
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)

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

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

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

@ -36,18 +36,20 @@ namespace Mono.CSharp { @@ -36,18 +36,20 @@ namespace Mono.CSharp {
// Better name would be DottenName
//
[DebuggerDisplay ("{GetSignatureForError()}")]
public class MemberName {
public readonly string Name;
public TypeArguments TypeArguments;
public class MemberName
{
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 static readonly MemberName Null = new MemberName ("");
public readonly MemberName Left;
bool is_double_colon;
public bool IsDoubleColon { get { return is_double_colon; } }
public MemberName (string name)
: this (name, Location.Null)
{ }
#if FULL_AST
public Location DotLocation {
@ -55,61 +57,43 @@ namespace Mono.CSharp { @@ -55,61 +57,43 @@ namespace Mono.CSharp {
set;
}
#endif
private MemberName (MemberName left, string name, bool is_double_colon,
Location loc)
public MemberName (string name, Location loc)
: this (null, name, loc)
{ }
public MemberName (string name, TypeParameters tparams, Location loc)
{
this.Name = name;
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,
TypeArguments args, Location loc)
: this (left, name, is_double_colon, loc)
public MemberName (string name, TypeParameters tparams, FullNamedExpression explicitInterface, Location loc)
: this (name, tparams, loc)
{
if (args != null && args.Count > 0)
this.TypeArguments = args;
this.ExplicitInterface = explicitInterface;
}
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)
: this (left, name, false, loc)
{ }
public MemberName (MemberName left, string name, TypeArguments args, Location loc)
: this (left, name, false, args, loc)
{ }
{
this.Name = name;
this.Location = loc;
this.Left = left;
}
public MemberName (string alias, string name, TypeArguments args, Location loc)
: this (new MemberName (alias, loc), name, true, args, loc)
{ }
public MemberName (MemberName left, string name, FullNamedExpression explicitInterface, Location loc)
: this (left, name, loc)
{
this.ExplicitInterface = explicitInterface;
}
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)
throw new InternalErrorException ("Cannot append double_colon member name");
this.Left = (right.Left == null) ? left : new MemberName (left, right.Left);
this.Name = right.Name;
this.Location = right.Location;
this.TypeParameters = right.TypeParameters;
this.Left = left;
}
// TODO: Remove
@ -120,13 +104,13 @@ namespace Mono.CSharp { @@ -120,13 +104,13 @@ namespace Mono.CSharp {
public int Arity {
get {
return TypeArguments == null ? 0 : TypeArguments.Count;
return TypeParameters == null ? 0 : TypeParameters.Count;
}
}
public bool IsGeneric {
get {
if (TypeArguments != null)
if (TypeParameters != null)
return true;
else if (Left != null)
return Left.IsGeneric;
@ -139,55 +123,31 @@ namespace Mono.CSharp { @@ -139,55 +123,31 @@ namespace Mono.CSharp {
{
string name = is_generic ? Basename : Name;
if (Left != null)
return Left.GetName (is_generic) + (is_double_colon ? "::" : ".") + name;
return Left.GetName (is_generic) + "." + 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 {
get {
if (TypeArguments != null)
return MakeName (Name, TypeArguments);
if (TypeParameters != null)
return MakeName (Name, TypeParameters);
return Name;
}
}
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)
return Name + append;
string connect = is_double_colon ? "::" : ".";
return Left.GetSignatureForError () + connect + Name + append;
return s;
return Left.GetSignatureForError () + "." + s;
}
public override bool Equals (object other)
@ -201,14 +161,12 @@ namespace Mono.CSharp { @@ -201,14 +161,12 @@ namespace Mono.CSharp {
return true;
if (other == null || Name != other.Name)
return false;
if (is_double_colon != other.is_double_colon)
return false;
if ((TypeArguments != null) &&
(other.TypeArguments == null || TypeArguments.Count != other.TypeArguments.Count))
if ((TypeParameters != null) &&
(other.TypeParameters == null || TypeParameters.Count != other.TypeParameters.Count))
return false;
if ((TypeArguments == null) && (other.TypeArguments != null))
if ((TypeParameters == null) && (other.TypeParameters != null))
return false;
if (Left == null)
@ -222,27 +180,14 @@ namespace Mono.CSharp { @@ -222,27 +180,14 @@ namespace Mono.CSharp {
int hash = Name.GetHashCode ();
for (MemberName n = Left; n != null; n = n.Left)
hash ^= n.Name.GetHashCode ();
if (is_double_colon)
hash ^= 0xbadc01d;
if (TypeArguments != null)
hash ^= TypeArguments.Count << 5;
if (TypeParameters != null)
hash ^= TypeParameters.Count << 5;
return hash & 0x7FFFFFFF;
}
public int CountTypeArguments {
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)
public static string MakeName (string name, TypeParameters args)
{
if (args == null)
return name;
@ -871,7 +816,7 @@ namespace Mono.CSharp { @@ -871,7 +816,7 @@ namespace Mono.CSharp {
get { return this; }
}
public virtual TypeParameter[] CurrentTypeParameters {
public virtual TypeParameters CurrentTypeParameters {
get { return null; }
}
@ -1275,12 +1220,9 @@ namespace Mono.CSharp { @@ -1275,12 +1220,9 @@ namespace Mono.CSharp {
protected Dictionary<string, MemberCore> defined_names;
public TypeContainer PartialContainer;
public TypeContainer PartialContainer;
protected readonly bool is_generic;
readonly int count_type_params;
protected TypeParameter[] type_params;
TypeParameter[] type_param_list;
//
// Whether we are Generic
@ -1306,12 +1248,9 @@ namespace Mono.CSharp { @@ -1306,12 +1248,9 @@ namespace Mono.CSharp {
Basename = name.Basename;
defined_names = new Dictionary<string, MemberCore> ();
PartialContainer = null;
if (name.TypeArguments != null) {
if (name.TypeParameters != null) {
is_generic = true;
count_type_params = name.TypeArguments.Count;
}
if (parent != null)
count_type_params += parent.count_type_params;
}
/// <summary>
@ -1407,45 +1346,7 @@ namespace Mono.CSharp { @@ -1407,45 +1346,7 @@ namespace Mono.CSharp {
{
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
public List<Constraints> PlainConstraints {
get;
@ -1467,7 +1368,6 @@ namespace Mono.CSharp { @@ -1467,7 +1368,6 @@ namespace Mono.CSharp {
}
}
#endif
public List<Constraints> Constraints {
get;
private set;
@ -1493,27 +1393,24 @@ namespace Mono.CSharp { @@ -1493,27 +1393,24 @@ namespace Mono.CSharp {
return;
}
TypeParameterName[] names = MemberName.TypeArguments.GetDeclarations ();
type_params = new TypeParameter [names.Length];
//
// Register all the names
//
for (int i = 0; i < type_params.Length; i++) {
TypeParameterName name = names [i];
for (int i = 0; i < MemberName.TypeParameters.Count; i++) {
var name = MemberName.TypeParameters [i];
Constraints constraints = null;
if (constraints_list != null) {
int total = constraints_list.Count;
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
if (constraints_at == null) {
constraints_list.RemoveAt (ii);
--total;
continue;
}
if (constraints_at.TypeParameter.Value == name.Name) {
if (constraints_at.TypeParameter.Value == name.MemberName.Name) {
constraints = constraints_at;
constraints_list.RemoveAt(ii);
break;
@ -1521,16 +1418,13 @@ namespace Mono.CSharp { @@ -1521,16 +1418,13 @@ namespace Mono.CSharp {
}
}
Variance variance = name.Variance;
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");
variance = Variance.None;
}
type_params [i] = new TypeParameter (
Parent, i, new MemberName (name.Name, Location), constraints, name.OptAttributes, variance);
AddToContainer (type_params [i], name.Name);
MemberName.TypeParameters[i].Constraints = constraints;
if (name.MemberName != null)
AddToContainer (name, name.MemberName.Name);
}
if (constraints_list != null && constraints_list.Count > 0) {
@ -1541,25 +1435,6 @@ namespace Mono.CSharp { @@ -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 {
get { return attribute_targets; }
}
@ -1570,10 +1445,8 @@ namespace Mono.CSharp { @@ -1570,10 +1445,8 @@ namespace Mono.CSharp {
return false;
}
if (type_params != null) {
foreach (TypeParameter tp in type_params) {
tp.VerifyClsCompliance ();
}
if (CurrentTypeParameters != null) {
CurrentTypeParameters.VerifyClsCompliance ();
}
return true;

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

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

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

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

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

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

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

@ -253,7 +253,7 @@ namespace Mono.CSharp @@ -253,7 +253,7 @@ namespace Mono.CSharp
protected CSharpBinderFlags flags;
TypeSpec binder_type;
TypeParameter[] context_mvars;
TypeParameters context_mvars;
public DynamicExpressionStatement (IDynamicBinder binder, Arguments args, Location loc)
{
@ -349,7 +349,7 @@ namespace Mono.CSharp @@ -349,7 +349,7 @@ namespace Mono.CSharp
var site_container = ec.CreateDynamicSite ();
if (context_mvars != null) {
TypeParameter[] tparam;
TypeParameters tparam;
TypeContainer sc = site_container;
do {
tparam = sc.CurrentTypeParameters;
@ -466,7 +466,7 @@ namespace Mono.CSharp @@ -466,7 +466,7 @@ namespace Mono.CSharp
return;
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);
}
@ -482,7 +482,7 @@ namespace Mono.CSharp @@ -482,7 +482,7 @@ namespace Mono.CSharp
if (inflate_using_mvar || context_mvars == null) {
gt = site_container.CurrentType;
} 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
@ -957,7 +957,7 @@ namespace Mono.CSharp @@ -957,7 +957,7 @@ namespace Mono.CSharp
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)
{
parent.DynamicSitesCounter++;

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

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

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

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

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

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

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

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

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

@ -33,16 +33,16 @@ namespace Mono.CSharp @@ -33,16 +33,16 @@ namespace Mono.CSharp
protected T machine_initializer;
int resume_pc;
public Expression Expr {
get { return this.expr; }
}
protected YieldStatement (Expression expr, Location l)
{
this.expr = expr;
loc = l;
}
public Expression Expr {
get { return this.expr; }
}
protected override void CloneTo (CloneContext clonectx, Statement t)
{
var target = (YieldStatement<T>) t;
@ -160,7 +160,7 @@ namespace Mono.CSharp @@ -160,7 +160,7 @@ namespace Mono.CSharp
Field pc_field;
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)
{
}
@ -478,17 +478,14 @@ namespace Mono.CSharp @@ -478,17 +478,14 @@ namespace Mono.CSharp
Define_Reset ();
if (Iterator.IsEnumerable) {
MemberName name = new MemberName (QualifiedAliasMember.GlobalAlias, "System", null, Location);
name = new MemberName (name, "Collections", Location);
name = new MemberName (name, "IEnumerable", Location);
name = new MemberName (name, "GetEnumerator", Location);
FullNamedExpression explicit_iface = new TypeExpression (Compiler.BuiltinTypes.IEnumerable, Location);
var name = new MemberName ("GetEnumerator", null, explicit_iface, Location);
if (generic_enumerator_type != null) {
Method get_enumerator = new StateMachineMethod (this, null, enumerator_type, 0, name);
name = new MemberName (name.Left.Left, "Generic", Location);
name = new MemberName (name, "IEnumerable", generic_args, Location);
name = new MemberName (name, "GetEnumerator", Location);
explicit_iface = new GenericTypeExpr (Module.PredefinedTypes.IEnumerableGeneric.Resolve (), generic_args, Location);
name = new MemberName ("GetEnumerator", null, explicit_iface, Location);
Method gget_enumerator = new GetEnumeratorMethod (this, generic_enumerator_type, name);
//
@ -510,20 +507,17 @@ namespace Mono.CSharp @@ -510,20 +507,17 @@ namespace Mono.CSharp
void Define_Current (bool is_generic)
{
TypeExpr type;
MemberName name = new MemberName (QualifiedAliasMember.GlobalAlias, "System", null, Location);
name = new MemberName (name, "Collections", Location);
FullNamedExpression explicit_iface;
if (is_generic) {
name = new MemberName (name, "Generic", Location);
name = new MemberName (name, "IEnumerator", generic_args, Location);
explicit_iface = new GenericTypeExpr (Module.PredefinedTypes.IEnumeratorGeneric.Resolve (), generic_args, Location);
type = iterator_type_expr;
} else {
name = new MemberName (name, "IEnumerator");
explicit_iface = new TypeExpression (Module.Compiler.BuiltinTypes.IEnumerator, 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);
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 { @@ -24,13 +24,8 @@ namespace Mono.CSharp {
// A list of Parameters (explicitly typed parameters)
// An ImplicitLambdaParameter
//
public LambdaExpression (bool isAsync, Location loc)
: base (isAsync, 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 @@ -287,6 +287,12 @@ namespace Mono.CSharp.Linq
this.identifier = identifier;
}
public RangeVariable Identifier {
get {
return identifier;
}
}
public FullNamedExpression IdentifierType { get; set; }
protected Invocation CreateCastExpression (Expression lSide)
@ -476,6 +482,12 @@ namespace Mono.CSharp.Linq @@ -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)
{
base.CreateArguments (ec, parameter, ref args);
@ -519,6 +531,13 @@ namespace Mono.CSharp.Linq @@ -519,6 +531,13 @@ namespace Mono.CSharp.Linq
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 {
get {
return inner_selector;
@ -530,13 +549,6 @@ namespace Mono.CSharp.Linq @@ -530,13 +549,6 @@ namespace Mono.CSharp.Linq
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)
{

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

@ -95,8 +95,13 @@ namespace Mono.CSharp @@ -95,8 +95,13 @@ namespace Mono.CSharp
}
#if FULL_AST
char[] ILiteralConstant.ParsedValue { get; set; }
public char[] ParsedValue { get; set; }
#endif
public override object Accept (StructuralVisitor visitor)
{
return visitor.Visit (this);
}
}
public class CharLiteral : CharConstant, ILiteralConstant
@ -111,8 +116,13 @@ namespace Mono.CSharp @@ -111,8 +116,13 @@ namespace Mono.CSharp
}
#if FULL_AST
char[] ILiteralConstant.ParsedValue { get; set; }
public char[] ParsedValue { get; set; }
#endif
public override object Accept (StructuralVisitor visitor)
{
return visitor.Visit (this);
}
}
public class IntLiteral : IntConstant, ILiteralConstant
@ -143,8 +153,13 @@ namespace Mono.CSharp @@ -143,8 +153,13 @@ namespace Mono.CSharp
}
#if FULL_AST
char[] ILiteralConstant.ParsedValue { get; set; }
public char[] ParsedValue { get; set; }
#endif
public override object Accept (StructuralVisitor visitor)
{
return visitor.Visit (this);
}
}
public class UIntLiteral : UIntConstant, ILiteralConstant
@ -159,8 +174,13 @@ namespace Mono.CSharp @@ -159,8 +174,13 @@ namespace Mono.CSharp
}
#if FULL_AST
char[] ILiteralConstant.ParsedValue { get; set; }
public char[] ParsedValue { get; set; }
#endif
public override object Accept (StructuralVisitor visitor)
{
return visitor.Visit (this);
}
}
public class LongLiteral : LongConstant, ILiteralConstant
@ -175,8 +195,13 @@ namespace Mono.CSharp @@ -175,8 +195,13 @@ namespace Mono.CSharp
}
#if FULL_AST
char[] ILiteralConstant.ParsedValue { get; set; }
public char[] ParsedValue { get; set; }
#endif
public override object Accept (StructuralVisitor visitor)
{
return visitor.Visit (this);
}
}
public class ULongLiteral : ULongConstant, ILiteralConstant
@ -191,8 +216,13 @@ namespace Mono.CSharp @@ -191,8 +216,13 @@ namespace Mono.CSharp
}
#if FULL_AST
char[] ILiteralConstant.ParsedValue { get; set; }
public char[] ParsedValue { get; set; }
#endif
public override object Accept (StructuralVisitor visitor)
{
return visitor.Visit (this);
}
}
public class FloatLiteral : FloatConstant, ILiteralConstant
@ -207,8 +237,13 @@ namespace Mono.CSharp @@ -207,8 +237,13 @@ namespace Mono.CSharp
}
#if FULL_AST
char[] ILiteralConstant.ParsedValue { get; set; }
public char[] ParsedValue { get; set; }
#endif
public override object Accept (StructuralVisitor visitor)
{
return visitor.Visit (this);
}
}
public class DoubleLiteral : DoubleConstant, ILiteralConstant
@ -245,8 +280,13 @@ namespace Mono.CSharp @@ -245,8 +280,13 @@ namespace Mono.CSharp
}
#if FULL_AST
char[] ILiteralConstant.ParsedValue { get; set; }
public char[] ParsedValue { get; set; }
#endif
public override object Accept (StructuralVisitor visitor)
{
return visitor.Visit (this);
}
}
public class DecimalLiteral : DecimalConstant, ILiteralConstant
@ -261,8 +301,13 @@ namespace Mono.CSharp @@ -261,8 +301,13 @@ namespace Mono.CSharp
}
#if FULL_AST
char[] ILiteralConstant.ParsedValue { get; set; }
public char[] ParsedValue { get; set; }
#endif
public override object Accept (StructuralVisitor visitor)
{
return visitor.Visit (this);
}
}
public class StringLiteral : StringConstant, ILiteralConstant
@ -277,7 +322,12 @@ namespace Mono.CSharp @@ -277,7 +322,12 @@ namespace Mono.CSharp
}
#if FULL_AST
char[] ILiteralConstant.ParsedValue { get; set; }
public char[] ParsedValue { get; set; }
#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 (" @@ -796,10 +796,10 @@ if (checkpoints.Length <= CheckpointIndex) throw new Exception (String.Format ("
public readonly Location UsingLocation;
public readonly Tokenizer.LocatedToken Identifier;
public readonly Location AssignLocation;
public readonly MemberName Nspace;
public readonly ATypeNameExpression Nspace;
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.Identifier = identifier;
@ -817,10 +817,10 @@ if (checkpoints.Length <= CheckpointIndex) throw new Exception (String.Format (" @@ -817,10 +817,10 @@ if (checkpoints.Length <= CheckpointIndex) throw new Exception (String.Format ("
public class Using
{
public readonly Location UsingLocation;
public readonly MemberName NSpace;
public readonly ATypeNameExpression NSpace;
public readonly Location SemicolonLocation;
public Using (Location usingLocation, MemberName nSpace, Location semicolonLocation)
public Using (Location usingLocation, ATypeNameExpression nSpace, Location semicolonLocation)
{
this.UsingLocation = usingLocation;
this.NSpace = nSpace;
@ -869,13 +869,13 @@ if (checkpoints.Length <= CheckpointIndex) throw new Exception (String.Format (" @@ -869,13 +869,13 @@ if (checkpoints.Length <= CheckpointIndex) throw new Exception (String.Format ("
}
[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));
}
[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));
}

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

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

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

@ -35,6 +35,11 @@ namespace Mono.CSharp { @@ -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)
{
if (child != this)
@ -117,11 +122,11 @@ namespace Mono.CSharp { @@ -117,11 +122,11 @@ namespace Mono.CSharp {
throw new InternalErrorException ("Namespace has a null fullname");
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)
MemberName = MemberName.Null;
else
MemberName = new MemberName (name);
MemberName = new MemberName (name, Location.Null);
namespaces = new Dictionary<string, Namespace> ();
cached_types = new Dictionary<string, TypeExpr> ();
@ -578,37 +583,38 @@ namespace Mono.CSharp { @@ -578,37 +583,38 @@ namespace Mono.CSharp {
//
public class NamespaceContainer : IMemberContext, ITypesContainer
{
static readonly Namespace[] empty_namespaces = new Namespace[0];
static readonly string[] empty_using_list = new string[0];
Namespace ns;
readonly ModuleContainer module;
readonly NamespaceContainer parent;
readonly CompilationSourceFile file;
readonly Location loc;
readonly MemberName name;
NamespaceContainer implicit_parent;
int symfile_id;
// Namespace using import block
List<NamespaceUsingAlias> using_aliases;
List<NamespaceUsing> using_clauses;
List<UsingNamespace> clauses;
// Used by parsed to check for parser errors
public bool DeclarationFound;
// End
bool resolved;
public readonly bool IsImplicit;
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)
{
this.module = module;
this.parent = parent;
this.file = sourceFile;
this.loc = name == null ? Location.Null : name.Location;
this.name = name ?? MemberName.Null;
if (parent != null)
ns = parent.NS.GetNamespace (name.GetName (), true);
@ -634,105 +640,46 @@ namespace Mono.CSharp { @@ -634,105 +640,46 @@ namespace Mono.CSharp {
public Location Location {
get {
return loc;
return name.Location;
}
}
public MemberName MemberName {
get {
return ns.MemberName;
return name;
}
}
public CompilationSourceFile SourceFile {
public NamespaceContainer Parent {
get {
return file;
return parent;
}
}
public List<NamespaceUsing> Usings {
public CompilationSourceFile SourceFile {
get {
return using_clauses;
return file;
}
}
#endregion
//
// 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 {
public List<UsingNamespace> Usings {
get {
if (!IsImplicit && doppelganger == null) {
doppelganger = new NamespaceContainer (module, ImplicitParent, file, ns, true);
doppelganger.using_aliases = using_aliases;
}
return doppelganger;
return clauses;
}
}
#endregion
public Namespace NS {
get { return ns; }
}
public NamespaceContainer Parent {
get { return parent; }
}
public NamespaceContainer ImplicitParent {
get {
if (parent == null)
return null;
if (implicit_parent == null) {
implicit_parent = (parent.NS == ns.Parent)
implicit_parent = (parent.ns == ns.Parent)
? parent
: new NamespaceContainer (module, parent, file, ns.Parent, false);
}
@ -740,78 +687,47 @@ namespace Mono.CSharp { @@ -740,78 +687,47 @@ namespace Mono.CSharp {
}
}
/// <summary>
/// Records a new namespace for resolving name references
/// </summary>
public void AddUsing (MemberName name, Location loc)
public void AddUsing (UsingNamespace un)
{
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) {
using_clauses = new List<NamespaceUsing> ();
} 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));
}
if (clauses == null)
clauses = new List<UsingNamespace> ();
public void AddUsingAlias (string alias, MemberName name, Location loc)
{
if (DeclarationFound){
Compiler.Report.Error (1529, loc, "A using clause must precede all other namespace elements except extern alias declarations");
}
clauses.Add (un);
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 (using_aliases != null && !not_first) {
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;
if (DeclarationFound){
Compiler.Report.Error (1529, un.Location, "A using clause must precede all other namespace elements except extern alias declarations");
}
AddUsingAlias (new NamespaceUsingAlias (alias, loc));
AddAlias (un);
}
void AddUsingAlias (NamespaceUsingAlias uae)
void AddAlias (UsingAliasNamespace un)
{
if (using_aliases == null) {
using_aliases = new List<NamespaceUsingAlias> ();
if (clauses == null) {
clauses = new List<UsingNamespace> ();
} else {
foreach (NamespaceUsingAlias entry in using_aliases) {
if (uae.Alias == entry.Alias) {
Compiler.Report.SymbolRelatedToPreviousError (uae.Location, uae.Alias);
Compiler.Report.Error (1537, entry.Location, "The using alias `{0}' appeared previously in this namespace",
entry.Alias);
return;
foreach (var entry in clauses) {
var a = entry as UsingAliasNamespace;
if (a != null && a.Alias.Value == un.Alias.Value) {
Compiler.Report.SymbolRelatedToPreviousError (a.Location, "");
Compiler.Report.Error (1537, un.Location,
"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 { @@ -821,7 +737,7 @@ namespace Mono.CSharp {
public ExtensionMethodCandidates LookupExtensionMethod (TypeSpec extensionType, string name, int arity)
{
List<MethodSpec> candidates = null;
foreach (Namespace n in GetUsingTable ()) {
foreach (Namespace n in namespace_using_table) {
var a = n.LookupExtensionMethod (this, extensionType, name, arity);
if (a == null)
continue;
@ -866,7 +782,7 @@ namespace Mono.CSharp { @@ -866,7 +782,7 @@ namespace Mono.CSharp {
IEnumerable<string> all = Enumerable.Empty<string> ();
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)){
int ld = prefix.LastIndexOf ('.');
if (ld != -1){
@ -881,18 +797,35 @@ namespace Mono.CSharp { @@ -881,18 +797,35 @@ namespace Mono.CSharp {
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
//
public FullNamedExpression LookupNamespaceAlias (string name)
{
for (NamespaceContainer n = this; n != null; n = n.ImplicitParent) {
if (n.using_aliases == null)
if (n.aliases == null)
continue;
foreach (NamespaceUsingAlias ue in n.using_aliases) {
if (ue.Alias == name)
return ue.Resolve (Doppelganger ?? this, Doppelganger == null);
}
UsingAliasNamespace uan;
if (n.aliases.TryGetValue (name, out uan))
return uan.ResolvedExpression;
}
return null;
@ -908,26 +841,19 @@ namespace Mono.CSharp { @@ -908,26 +841,19 @@ namespace Mono.CSharp {
//
// Check aliases.
//
if (using_aliases != null && arity == 0) {
foreach (NamespaceUsingAlias ue in using_aliases) {
if (ue.Alias == name) {
if (fne != null) {
if (Doppelganger != null) {
if (mode == LookupMode.Normal) {
// TODO: Namespace has broken location
//Report.SymbolRelatedToPreviousError (fne.Location, null);
Compiler.Report.SymbolRelatedToPreviousError (ue.Location, null);
Compiler.Report.Error (576, loc,
"Namespace `{0}' contains a definition with same name as alias `{1}'",
GetSignatureForError (), name);
}
} else {
return fne;
}
}
return ue.Resolve (Doppelganger ?? this, Doppelganger == null);
if (aliases != null && arity == 0) {
UsingAliasNamespace uan;
if (aliases.TryGetValue (name, out uan)) {
if (fne != null) {
// TODO: Namespace has broken location
//Report.SymbolRelatedToPreviousError (fne.Location, null);
Compiler.Report.SymbolRelatedToPreviousError (uan.Location, null);
Compiler.Report.Error (576, loc,
"Namespace `{0}' contains a definition with same name as alias `{1}'",
GetSignatureForError (), name);
}
return uan.ResolvedExpression;
}
}
@ -941,9 +867,11 @@ namespace Mono.CSharp { @@ -941,9 +867,11 @@ namespace Mono.CSharp {
// Check using entries.
//
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
// does not import any nested namespaces
//
fne = using_ns.LookupType (this, name, arity, mode, loc);
if (fne == null)
continue;
@ -983,41 +911,20 @@ namespace Mono.CSharp { @@ -983,41 +911,20 @@ namespace Mono.CSharp {
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 {
get {
if (symfile_id == 0 && file.SourceFileEntry != null) {
int parent_id = parent == null ? 0 : parent.SymbolFileID;
string [] using_list = empty_using_list;
if (using_clauses != null) {
using_list = new string [using_clauses.Count];
for (int i = 0; i < using_clauses.Count; i++)
using_list [i] = ((NamespaceUsing) using_clauses [i]).MemberName.GetName ();
if (clauses != null) {
// TODO: Why is it needed, what to do with aliases
var ul = new List<string> ();
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);
@ -1036,11 +943,6 @@ namespace Mono.CSharp { @@ -1036,11 +943,6 @@ namespace Mono.CSharp {
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)
{
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 { @@ -1069,29 +971,76 @@ namespace Mono.CSharp {
}
}
/// <summary>
/// Used to validate that all the using clauses are correct
/// after we are finished parsing all the files.
/// </summary>
public void Resolve ()
public void Define ()
{
if (resolved)
return;
// FIXME: Because we call Define from bottom not top
if (parent != null)
parent.Define ();
namespace_using_table = empty_namespaces;
resolved = true;
if (using_aliases != null) {
foreach (NamespaceUsingAlias ue in using_aliases)
ue.Resolve (Doppelganger, Doppelganger == null);
}
if (clauses != null) {
var list = new List<Namespace> (clauses.Count);
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) {
foreach (NamespaceUsing ue in using_clauses)
ue.Resolve (Doppelganger);
}
continue;
}
if (parent != null)
parent.Resolve ();
entry.Define (this);
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 ()
@ -1113,12 +1062,12 @@ namespace Mono.CSharp { @@ -1113,12 +1062,12 @@ namespace Mono.CSharp {
get { return SlaveDeclSpace.CurrentMemberDefinition; }
}
public TypeParameter[] CurrentTypeParameters {
public TypeParameters CurrentTypeParameters {
get { return SlaveDeclSpace.CurrentTypeParameters; }
}
public bool IsObsolete {
get { return SlaveDeclSpace.IsObsolete; }
get { return false; }
}
public bool IsUnsafe {
@ -1136,106 +1085,199 @@ namespace Mono.CSharp { @@ -1136,106 +1085,199 @@ namespace Mono.CSharp {
#endregion
}
public class NamespaceUsing
public class UsingNamespace
{
readonly MemberName name;
Namespace resolved;
readonly ATypeNameExpression expr;
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 ()
{
return name.GetSignatureForError ();
}
#region Properties
public Location Location
{
get { return name.Location; }
public virtual SimpleMemberName Alias {
get {
return null;
}
}
public MemberName MemberName
{
get { return name; }
public Location Location {
get {
return loc;
}
}
public string Name
{
get { return GetSignatureForError (); }
public ATypeNameExpression NamespaceExpression {
get {
return expr;
}
}
public Namespace Resolve (IMemberContext rc)
{
if (resolved != null)
public FullNamedExpression ResolvedExpression {
get {
return resolved;
}
}
FullNamedExpression fne = name.GetTypeExpression ().ResolveAsTypeOrNamespace (rc);
if (fne == null)
return null;
#endregion
resolved = fne as Namespace;
if (resolved == null) {
rc.Module.Compiler.Report.SymbolRelatedToPreviousError (fne.Type);
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 string GetSignatureForError ()
{
return expr.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 Location Location;
public NamespaceUsingAlias (string alias, Location loc)
public UsingExternAlias (SimpleMemberName alias, Location loc)
: base (alias, null, 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);
if (fne == null) {
rc.Module.Compiler.Report.Error (430, Location,
resolved = ctx.Module.GetRootNamespace (Alias.Value);
if (resolved == null) {
ctx.Module.Compiler.Report.Error (430, Location,
"The extern alias `{0}' was not specified in -reference option",
Alias);
Alias.Value);
}
return fne;
}
}
class LocalUsingAliasEntry : NamespaceUsingAlias
public class UsingAliasNamespace : UsingNamespace
{
FullNamedExpression resolved;
MemberName value;
readonly SimpleMemberName alias;
public LocalUsingAliasEntry (string alias, MemberName name, Location loc)
: base (alias, loc)
struct AliasContext : IMemberContext
{
this.value = name;
}
readonly NamespaceContainer ns;
public override FullNamedExpression Resolve (IMemberContext rc, bool local)
{
if (resolved != null || value == null)
return resolved;
public AliasContext (NamespaceContainer ns)
{
this.ns = ns;
}
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;
}
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 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 @@ -1001,20 +1001,24 @@ namespace Mono.CSharp.Nullable
Expression left, right;
Unwrap unwrap;
public Expression Left {
get { return this.left; }
}
public Expression Right {
get { return this.right; }
}
public NullCoalescingOperator (Expression left, Expression right, Location loc)
{
this.left = left;
this.right = right;
this.loc = loc;
}
public Expression LeftExpression {
get {
return left;
}
}
public Expression Right {
get {
return right;
}
}
public override Expression CreateExpressionTree (ResolveContext ec)
{

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

@ -234,10 +234,7 @@ namespace Mono.CSharp { @@ -234,10 +234,7 @@ namespace Mono.CSharp {
TemporaryVariableReference expr_tree_variable;
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)
{
this.name = name;
@ -251,6 +248,12 @@ namespace Mono.CSharp { @@ -251,6 +248,12 @@ namespace Mono.CSharp {
#region Properties
public Expression DefaultExpression {
get {
return default_expr;
}
}
public DefaultParameterValueExpression DefaultValue {
get {
return default_expr as DefaultParameterValueExpression;
@ -279,6 +282,12 @@ namespace Mono.CSharp { @@ -279,6 +282,12 @@ namespace Mono.CSharp {
}
}
public Modifier ParameterModifier {
get {
return modFlags;
}
}
public TypeSpec Type {
get {
return parameter_type;
@ -1212,7 +1221,7 @@ namespace Mono.CSharp { @@ -1212,7 +1221,7 @@ namespace Mono.CSharp {
//
// 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
// both share reference to this expression and we ensure that resolving
// this expression always returns same instance

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

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

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

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

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

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

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

@ -351,6 +351,12 @@ namespace Mono.CSharp @@ -351,6 +351,12 @@ namespace Mono.CSharp
tc.CloseType ();
}
if (anonymous_types != null) {
foreach (var atypes in anonymous_types)
foreach (var at in atypes.Value)
at.CloseType ();
}
if (compiler_generated != null)
foreach (CompilerGeneratedClass c in compiler_generated)
c.CloseType ();
@ -367,7 +373,7 @@ namespace Mono.CSharp @@ -367,7 +373,7 @@ namespace Mono.CSharp
public RootNamespace CreateRootNamespace (string alias)
{
if (alias == global_ns.Alias) {
NamespaceContainer.Error_GlobalNamespaceRedefined (Location.Null, Report);
RootNamespace.Error_GlobalNamespaceRedefined (Report, Location.Null);
return global_ns;
}
@ -445,6 +451,12 @@ namespace Mono.CSharp @@ -445,6 +451,12 @@ namespace Mono.CSharp
foreach (TypeContainer tc in types)
tc.VerifyMembers ();
if (anonymous_types != null) {
foreach (var atypes in anonymous_types)
foreach (var at in atypes.Value)
at.EmitType ();
}
if (compiler_generated != null)
foreach (var c in compiler_generated)
c.EmitType ();
@ -540,7 +552,7 @@ namespace Mono.CSharp @@ -540,7 +552,7 @@ namespace Mono.CSharp
}
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.Error (101, container.Location,

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

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

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

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

Loading…
Cancel
Save