Browse Source

Updated mcs.

pull/45/merge
Mike Krüger 12 years ago
parent
commit
0ca084bb07
  1. 29
      ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs
  2. 29
      ICSharpCode.NRefactory.CSharp/Parser/mcs/anonymous.cs
  3. 4
      ICSharpCode.NRefactory.CSharp/Parser/mcs/argument.cs
  4. 32
      ICSharpCode.NRefactory.CSharp/Parser/mcs/assembly.cs
  5. 4
      ICSharpCode.NRefactory.CSharp/Parser/mcs/async.cs
  6. 24
      ICSharpCode.NRefactory.CSharp/Parser/mcs/attribute.cs
  7. 65
      ICSharpCode.NRefactory.CSharp/Parser/mcs/class.cs
  8. 4
      ICSharpCode.NRefactory.CSharp/Parser/mcs/const.cs
  9. 6
      ICSharpCode.NRefactory.CSharp/Parser/mcs/constant.cs
  10. 2
      ICSharpCode.NRefactory.CSharp/Parser/mcs/context.cs
  11. 4697
      ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.cs
  12. 289
      ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.jay
  13. 74
      ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-tokenizer.cs
  14. 11
      ICSharpCode.NRefactory.CSharp/Parser/mcs/decl.cs
  15. 18
      ICSharpCode.NRefactory.CSharp/Parser/mcs/delegate.cs
  16. 2
      ICSharpCode.NRefactory.CSharp/Parser/mcs/driver.cs
  17. 1
      ICSharpCode.NRefactory.CSharp/Parser/mcs/dynamic.cs
  18. 50
      ICSharpCode.NRefactory.CSharp/Parser/mcs/ecore.cs
  19. 2
      ICSharpCode.NRefactory.CSharp/Parser/mcs/enum.cs
  20. 3
      ICSharpCode.NRefactory.CSharp/Parser/mcs/eval.cs
  21. 65
      ICSharpCode.NRefactory.CSharp/Parser/mcs/expression.cs
  22. 15
      ICSharpCode.NRefactory.CSharp/Parser/mcs/field.cs
  23. 73
      ICSharpCode.NRefactory.CSharp/Parser/mcs/generic.cs
  24. 39
      ICSharpCode.NRefactory.CSharp/Parser/mcs/import.cs
  25. 31
      ICSharpCode.NRefactory.CSharp/Parser/mcs/iterators.cs
  26. 2
      ICSharpCode.NRefactory.CSharp/Parser/mcs/linq.cs
  27. 2
      ICSharpCode.NRefactory.CSharp/Parser/mcs/literal.cs
  28. 16
      ICSharpCode.NRefactory.CSharp/Parser/mcs/membercache.cs
  29. 280
      ICSharpCode.NRefactory.CSharp/Parser/mcs/method.cs
  30. 2
      ICSharpCode.NRefactory.CSharp/Parser/mcs/modifiers.cs
  31. 11
      ICSharpCode.NRefactory.CSharp/Parser/mcs/namespace.cs
  32. 6
      ICSharpCode.NRefactory.CSharp/Parser/mcs/nullable.cs
  33. 8
      ICSharpCode.NRefactory.CSharp/Parser/mcs/parameter.cs
  34. 34
      ICSharpCode.NRefactory.CSharp/Parser/mcs/pending.cs
  35. 16
      ICSharpCode.NRefactory.CSharp/Parser/mcs/property.cs
  36. 23
      ICSharpCode.NRefactory.CSharp/Parser/mcs/report.cs
  37. 26
      ICSharpCode.NRefactory.CSharp/Parser/mcs/settings.cs
  38. 146
      ICSharpCode.NRefactory.CSharp/Parser/mcs/statement.cs
  39. 24
      ICSharpCode.NRefactory.CSharp/Parser/mcs/typemanager.cs
  40. 4
      ICSharpCode.NRefactory.CSharp/Parser/mcs/visit.cs
  41. 2
      ICSharpCode.NRefactory.Tests/CSharp/CodeActions/IterateViaForeachTests.cs
  42. 2
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/InvalidStatementsTests.cs

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

@ -213,9 +213,10 @@ namespace ICSharpCode.NRefactory.CSharp
var memberType = new MemberType (); var memberType = new MemberType ();
memberType.AddChild (ConvertToType (ma.LeftExpression), MemberType.TargetRole); memberType.AddChild (ConvertToType (ma.LeftExpression), MemberType.TargetRole);
if (!ma.DotLocation.IsNull) var loc = LocationsBag.GetLocations (memberType);
memberType.AddChild (new CSharpTokenNode (Convert (ma.DotLocation), Roles.Dot), Roles.Dot); if (loc != null)
memberType.AddChild (new CSharpTokenNode (Convert (loc[0]), Roles.Dot), Roles.Dot);
memberType.MemberNameToken = Identifier.Create (ma.Name, Convert (ma.Location)); memberType.MemberNameToken = Identifier.Create (ma.Name, Convert (ma.Location));
AddTypeArguments (ma, memberType); AddTypeArguments (ma, memberType);
@ -424,9 +425,9 @@ namespace ICSharpCode.NRefactory.CSharp
if (newIdent.Name != "<invalid>") { if (newIdent.Name != "<invalid>") {
namespaceDecl.InsertChildBefore (insertPos, newIdent, Roles.Identifier); namespaceDecl.InsertChildBefore (insertPos, newIdent, Roles.Identifier);
insertPos = newIdent; insertPos = newIdent;
var loc = LocationsBag.GetLocations (memberName);
if (!memberName.DotLocation.IsNull) { if (loc != null) {
var dotToken = new CSharpTokenNode (Convert (memberName.DotLocation), Roles.Dot); var dotToken = new CSharpTokenNode (Convert (loc[0]), Roles.Dot);
namespaceDecl.InsertChildBefore (insertPos, dotToken, Roles.Dot); namespaceDecl.InsertChildBefore (insertPos, dotToken, Roles.Dot);
insertPos = dotToken; insertPos = dotToken;
} }
@ -483,9 +484,9 @@ namespace ICSharpCode.NRefactory.CSharp
var t = new MemberType (); var t = new MemberType ();
// t.IsDoubleColon = memberName.IsDoubleColon; // t.IsDoubleColon = memberName.IsDoubleColon;
t.AddChild (ConvertImport (memberName.Left), MemberType.TargetRole); t.AddChild (ConvertImport (memberName.Left), MemberType.TargetRole);
var loc = LocationsBag.GetLocations (memberName);
if (!memberName.DotLocation.IsNull) if (loc != null)
t.AddChild (new CSharpTokenNode (Convert (memberName.DotLocation), Roles.Dot), Roles.Dot); t.AddChild (new CSharpTokenNode (Convert (loc[0]), Roles.Dot), Roles.Dot);
t.AddChild (Identifier.Create (memberName.Name, Convert (memberName.Location)), Roles.Identifier); t.AddChild (Identifier.Create (memberName.Name, Convert (memberName.Location)), Roles.Identifier);
AddTypeArguments (t, memberName); AddTypeArguments (t, memberName);
@ -1368,7 +1369,7 @@ namespace ICSharpCode.NRefactory.CSharp
return null; return null;
} }
public override object Visit (BlockVariableDeclaration blockVariableDeclaration) public override object Visit (BlockVariable blockVariableDeclaration)
{ {
var result = new VariableDeclarationStatement (); var result = new VariableDeclarationStatement ();
result.AddChild (ConvertToType (blockVariableDeclaration.TypeExpression), Roles.Type); result.AddChild (ConvertToType (blockVariableDeclaration.TypeExpression), Roles.Type);
@ -1405,7 +1406,7 @@ namespace ICSharpCode.NRefactory.CSharp
return result; return result;
} }
public override object Visit (BlockConstantDeclaration blockVariableDeclaration) public override object Visit (BlockConstant blockVariableDeclaration)
{ {
var result = new VariableDeclarationStatement (); var result = new VariableDeclarationStatement ();
@ -2155,8 +2156,10 @@ namespace ICSharpCode.NRefactory.CSharp
var leftExpr = memberAccess.LeftExpression.Accept (this); var leftExpr = memberAccess.LeftExpression.Accept (this);
result.AddChild ((Expression)leftExpr, Roles.TargetExpression); result.AddChild ((Expression)leftExpr, Roles.TargetExpression);
} }
if (!memberAccess.DotLocation.IsNull) { var loc = LocationsBag.GetLocations (memberAccess);
result.AddChild (new CSharpTokenNode (Convert (memberAccess.DotLocation), Roles.Dot), Roles.Dot);
if (loc != null) {
result.AddChild (new CSharpTokenNode (Convert (loc[0]), Roles.Dot), Roles.Dot);
} }
} }

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

@ -570,6 +570,9 @@ namespace Mono.CSharp {
protected virtual void EmitHoistedParameters (EmitContext ec, List<HoistedParameter> hoisted) protected virtual void EmitHoistedParameters (EmitContext ec, List<HoistedParameter> hoisted)
{ {
foreach (HoistedParameter hp in hoisted) { foreach (HoistedParameter hp in hoisted) {
if (hp == null)
continue;
// //
// Parameters could be proxied via local fields for value type storey // Parameters could be proxied via local fields for value type storey
// //
@ -852,6 +855,8 @@ namespace Mono.CSharp {
} }
} }
public bool IsAssigned { get; set; }
public ParameterReference Parameter { public ParameterReference Parameter {
get { get {
return parameter; return parameter;
@ -1002,12 +1007,12 @@ namespace Mono.CSharp {
return delegate_type; return delegate_type;
ec.Report.Error (835, loc, "Cannot convert `{0}' to an expression tree of non-delegate type `{1}'", ec.Report.Error (835, loc, "Cannot convert `{0}' to an expression tree of non-delegate type `{1}'",
GetSignatureForError (), TypeManager.CSharpName (delegate_type)); GetSignatureForError (), delegate_type.GetSignatureForError ());
return null; return null;
} }
ec.Report.Error (1660, loc, "Cannot convert `{0}' to non-delegate type `{1}'", ec.Report.Error (1660, loc, "Cannot convert `{0}' to non-delegate type `{1}'",
GetSignatureForError (), TypeManager.CSharpName (delegate_type)); GetSignatureForError (), delegate_type.GetSignatureForError ());
return null; return null;
} }
@ -1019,7 +1024,7 @@ namespace Mono.CSharp {
if (!ec.IsInProbingMode) if (!ec.IsInProbingMode)
ec.Report.Error (1661, loc, ec.Report.Error (1661, loc,
"Cannot convert `{0}' to delegate type `{1}' since there is a parameter mismatch", "Cannot convert `{0}' to delegate type `{1}' since there is a parameter mismatch",
GetSignatureForError (), TypeManager.CSharpName (delegate_type)); GetSignatureForError (), delegate_type.GetSignatureForError ());
return false; return false;
} }
@ -1031,7 +1036,7 @@ namespace Mono.CSharp {
return false; return false;
ec.Report.Error (1593, loc, "Delegate `{0}' does not take `{1}' arguments", ec.Report.Error (1593, loc, "Delegate `{0}' does not take `{1}' arguments",
TypeManager.CSharpName (delegate_type), Parameters.Count.ToString ()); delegate_type.GetSignatureForError (), Parameters.Count.ToString ());
return false; return false;
} }
@ -1071,8 +1076,8 @@ namespace Mono.CSharp {
ec.Report.Error (1678, loc, "Parameter `{0}' is declared as type `{1}' but should be `{2}'", ec.Report.Error (1678, loc, "Parameter `{0}' is declared as type `{1}' but should be `{2}'",
(i+1).ToString (), (i+1).ToString (),
TypeManager.CSharpName (Parameters.Types [i]), Parameters.Types [i].GetSignatureForError (),
TypeManager.CSharpName (invoke_pd.Types [i])); invoke_pd.Types [i].GetSignatureForError ());
error = true; error = true;
} }
} }
@ -1376,7 +1381,7 @@ namespace Mono.CSharp {
return null; return null;
} }
b = b.ConvertToAsyncTask (ec, ec.CurrentMemberDefinition.Parent.PartialContainer, p, return_type, loc); b = b.ConvertToAsyncTask (ec, ec.CurrentMemberDefinition.Parent.PartialContainer, p, return_type, delegate_type, loc);
} }
return CompatibleMethodFactory (return_type ?? InternalType.ErrorType, delegate_type, p, b); return CompatibleMethodFactory (return_type ?? InternalType.ErrorType, delegate_type, p, b);
@ -1739,6 +1744,7 @@ namespace Mono.CSharp {
// //
method = DoCreateMethodHost (ec); method = DoCreateMethodHost (ec);
method.Define (); method.Define ();
method.PrepareEmit ();
} }
bool is_static = (method.ModFlags & Modifiers.STATIC) != 0; bool is_static = (method.ModFlags & Modifiers.STATIC) != 0;
@ -1865,7 +1871,7 @@ namespace Mono.CSharp {
public override string GetSignatureForError () public override string GetSignatureForError ()
{ {
return TypeManager.CSharpName (type); return type.GetSignatureForError ();
} }
} }
@ -2004,7 +2010,7 @@ namespace Mono.CSharp {
} }
var li_other = LocalVariable.CreateCompilerGenerated (CurrentType, equals_block, loc); var li_other = LocalVariable.CreateCompilerGenerated (CurrentType, equals_block, loc);
equals_block.AddStatement (new BlockVariableDeclaration (new TypeExpression (li_other.Type, loc), li_other)); equals_block.AddStatement (new BlockVariable (new TypeExpression (li_other.Type, loc), li_other));
var other_variable = new LocalVariableReference (li_other, loc); var other_variable = new LocalVariableReference (li_other, loc);
MemberAccess system_collections_generic = new MemberAccess (new MemberAccess ( MemberAccess system_collections_generic = new MemberAccess (new MemberAccess (
@ -2087,6 +2093,7 @@ namespace Mono.CSharp {
equals.Block = equals_block; equals.Block = equals_block;
equals.Define (); equals.Define ();
equals.PrepareEmit ();
Members.Add (equals); Members.Add (equals);
// //
@ -2116,7 +2123,7 @@ namespace Mono.CSharp {
hashcode_top.AddStatement (new Unchecked (hashcode_block, loc)); hashcode_top.AddStatement (new Unchecked (hashcode_block, loc));
var li_hash = LocalVariable.CreateCompilerGenerated (Compiler.BuiltinTypes.Int, hashcode_top, loc); var li_hash = LocalVariable.CreateCompilerGenerated (Compiler.BuiltinTypes.Int, hashcode_top, loc);
hashcode_block.AddStatement (new BlockVariableDeclaration (new TypeExpression (li_hash.Type, loc), li_hash)); hashcode_block.AddStatement (new BlockVariable (new TypeExpression (li_hash.Type, loc), li_hash));
LocalVariableReference hash_variable_assign = new LocalVariableReference (li_hash, loc); LocalVariableReference hash_variable_assign = new LocalVariableReference (li_hash, loc);
hashcode_block.AddStatement (new StatementExpression ( hashcode_block.AddStatement (new StatementExpression (
new SimpleAssign (hash_variable_assign, rs_hashcode))); new SimpleAssign (hash_variable_assign, rs_hashcode)));
@ -2141,6 +2148,7 @@ namespace Mono.CSharp {
hashcode_block.AddStatement (new Return (hash_variable, loc)); hashcode_block.AddStatement (new Return (hash_variable, loc));
hashcode.Block = hashcode_top; hashcode.Block = hashcode_top;
hashcode.Define (); hashcode.Define ();
hashcode.PrepareEmit ();
Members.Add (hashcode); Members.Add (hashcode);
// //
@ -2151,6 +2159,7 @@ namespace Mono.CSharp {
tostring_block.AddStatement (new Return (string_concat, loc)); tostring_block.AddStatement (new Return (string_concat, loc));
tostring.Block = tostring_block; tostring.Block = tostring_block;
tostring.Define (); tostring.Define ();
tostring.PrepareEmit ();
Members.Add (tostring); Members.Add (tostring);
return true; return true;

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

@ -132,7 +132,7 @@ namespace Mono.CSharp
if (Expr.eclass == ExprClass.MethodGroup) if (Expr.eclass == ExprClass.MethodGroup)
return Expr.ExprClassName; return Expr.ExprClassName;
return TypeManager.CSharpName (Expr.Type); return Expr.Type.GetSignatureForError ();
} }
public bool ResolveMethodGroup (ResolveContext ec) public bool ResolveMethodGroup (ResolveContext ec)
@ -347,7 +347,7 @@ namespace Mono.CSharp
} else if (arg_type.Kind == MemberKind.Void || arg_type == InternalType.Arglist || arg_type.IsPointer) { } else if (arg_type.Kind == MemberKind.Void || arg_type == InternalType.Arglist || arg_type.IsPointer) {
rc.Report.Error (1978, a.Expr.Location, rc.Report.Error (1978, a.Expr.Location,
"An expression of type `{0}' cannot be used as an argument of dynamic operation", "An expression of type `{0}' cannot be used as an argument of dynamic operation",
TypeManager.CSharpName (arg_type)); arg_type.GetSignatureForError ());
} }
info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags, info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,

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

@ -7,7 +7,7 @@
// //
// Copyright 2001, 2002, 2003 Ximian, Inc. // Copyright 2001, 2002, 2003 Ximian, Inc.
// Copyright 2004-2011 Novell, Inc. // Copyright 2004-2011 Novell, Inc.
// Copyright 2011 Xamarin Inc // Copyright 2011-2013 Xamarin Inc
// //
@ -74,6 +74,9 @@ namespace Mono.CSharp
Dictionary<ITypeDefinition, Attribute> emitted_forwarders; Dictionary<ITypeDefinition, Attribute> emitted_forwarders;
AssemblyAttributesPlaceholder module_target_attrs; AssemblyAttributesPlaceholder module_target_attrs;
// Win32 version info values
string vi_product, vi_product_version, vi_company, vi_copyright, vi_trademark;
protected AssemblyDefinition (ModuleContainer module, string name) protected AssemblyDefinition (ModuleContainer module, string name)
{ {
this.module = module; this.module = module;
@ -288,7 +291,7 @@ namespace Mono.CSharp
} else if (emitted_forwarders.ContainsKey (t.MemberDefinition)) { } else if (emitted_forwarders.ContainsKey (t.MemberDefinition)) {
Report.SymbolRelatedToPreviousError (emitted_forwarders[t.MemberDefinition].Location, null); Report.SymbolRelatedToPreviousError (emitted_forwarders[t.MemberDefinition].Location, null);
Report.Error (739, a.Location, "A duplicate type forward of type `{0}'", Report.Error (739, a.Location, "A duplicate type forward of type `{0}'",
TypeManager.CSharpName (t)); t.GetSignatureForError ());
return; return;
} }
@ -297,13 +300,13 @@ namespace Mono.CSharp
if (t.MemberDefinition.DeclaringAssembly == this) { if (t.MemberDefinition.DeclaringAssembly == this) {
Report.SymbolRelatedToPreviousError (t); Report.SymbolRelatedToPreviousError (t);
Report.Error (729, a.Location, "Cannot forward type `{0}' because it is defined in this assembly", Report.Error (729, a.Location, "Cannot forward type `{0}' because it is defined in this assembly",
TypeManager.CSharpName (t)); t.GetSignatureForError ());
return; return;
} }
if (t.IsNested) { if (t.IsNested) {
Report.Error (730, a.Location, "Cannot forward type `{0}' because it is a nested type", Report.Error (730, a.Location, "Cannot forward type `{0}' because it is a nested type",
TypeManager.CSharpName (t)); t.GetSignatureForError ());
return; return;
} }
@ -347,15 +350,24 @@ namespace Mono.CSharp
} else if (a.Type == pa.RuntimeCompatibility) { } else if (a.Type == pa.RuntimeCompatibility) {
wrap_non_exception_throws_custom = true; wrap_non_exception_throws_custom = true;
} else if (a.Type == pa.AssemblyFileVersion) { } else if (a.Type == pa.AssemblyFileVersion) {
string value = a.GetString (); vi_product_version = a.GetString ();
if (string.IsNullOrEmpty (value) || IsValidAssemblyVersion (value, false) == null) { if (string.IsNullOrEmpty (vi_product_version) || IsValidAssemblyVersion (vi_product_version, false) == null) {
Report.Warning (1607, 1, a.Location, "The version number `{0}' specified for `{1}' is invalid", Report.Warning (1607, 1, a.Location, "The version number `{0}' specified for `{1}' is invalid",
value, a.Name); vi_product_version, a.Name);
return; return;
} }
} else if (a.Type == pa.AssemblyProduct) {
vi_product = a.GetString ();
} else if (a.Type == pa.AssemblyCompany) {
vi_company = a.GetString ();
} else if (a.Type == pa.AssemblyDescription) {
// TODO: Needs extra api
} else if (a.Type == pa.AssemblyCopyright) {
vi_copyright = a.GetString ();
} else if (a.Type == pa.AssemblyTrademark) {
vi_trademark = a.GetString ();
} }
SetCustomAttribute (ctor, cdata); SetCustomAttribute (ctor, cdata);
} }
@ -370,7 +382,7 @@ namespace Mono.CSharp
// no working SRE API // no working SRE API
foreach (var entry in Importer.Assemblies) { foreach (var entry in Importer.Assemblies) {
var a = entry as ImportedAssemblyDefinition; var a = entry as ImportedAssemblyDefinition;
if (a == null) if (a == null || a.IsMissing)
continue; continue;
if (public_key != null && !a.HasStrongName) { if (public_key != null && !a.HasStrongName) {
@ -749,7 +761,7 @@ namespace Mono.CSharp
if (Compiler.Settings.Win32ResourceFile != null) { if (Compiler.Settings.Win32ResourceFile != null) {
Builder.DefineUnmanagedResource (Compiler.Settings.Win32ResourceFile); Builder.DefineUnmanagedResource (Compiler.Settings.Win32ResourceFile);
} else { } else {
Builder.DefineVersionInfoResource (); Builder.DefineVersionInfoResource (vi_product, vi_product_version, vi_company, vi_copyright, vi_trademark);
} }
if (Compiler.Settings.Win32IconFile != null) { if (Compiler.Settings.Win32IconFile != null) {

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

@ -384,6 +384,10 @@ namespace Mono.CSharp
} }
} }
public TypeSpec DelegateType {
get; set;
}
public override bool IsIterator { public override bool IsIterator {
get { get {
return false; return false;

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

@ -1,14 +1,14 @@
// //
// attribute.cs: Attribute Handler // attribute.cs: Attributes handling
// //
// Author: Ravi Pratap (ravi@ximian.com) // Author: Ravi Pratap (ravi@ximian.com)
// Marek Safar (marek.safar@seznam.cz) // Marek Safar (marek.safar@gmail.com)
// //
// Dual licensed under the terms of the MIT X11 or GNU GPL // Dual licensed under the terms of the MIT X11 or GNU GPL
// //
// Copyright 2001-2003 Ximian, Inc (http://www.ximian.com) // Copyright 2001-2003 Ximian, Inc (http://www.ximian.com)
// Copyright 2003-2008 Novell, Inc. // Copyright 2003-2008 Novell, Inc.
// Copyright 2011 Xamarin Inc // Copyright 2011-2013 Xamarin Inc
// //
using System; using System;
@ -264,7 +264,7 @@ namespace Mono.CSharp {
public void Error_AttributeEmitError (string inner) public void Error_AttributeEmitError (string inner)
{ {
Report.Error (647, Location, "Error during emitting `{0}' attribute. The reason is `{1}'", Report.Error (647, Location, "Error during emitting `{0}' attribute. The reason is `{1}'",
TypeManager.CSharpName (Type), inner); Type.GetSignatureForError (), inner);
} }
public void Error_InvalidSecurityParent () public void Error_InvalidSecurityParent ()
@ -367,7 +367,7 @@ namespace Mono.CSharp {
public string GetSignatureForError () public string GetSignatureForError ()
{ {
if (Type != null) if (Type != null)
return TypeManager.CSharpName (Type); return Type.GetSignatureForError ();
return expression.GetSignatureForError (); return expression.GetSignatureForError ();
} }
@ -454,7 +454,7 @@ namespace Mono.CSharp {
ObsoleteAttribute obsolete_attr = Type.GetAttributeObsolete (); ObsoleteAttribute obsolete_attr = Type.GetAttributeObsolete ();
if (obsolete_attr != null) { if (obsolete_attr != null) {
AttributeTester.Report_ObsoleteMessage (obsolete_attr, TypeManager.CSharpName (Type), Location, Report); AttributeTester.Report_ObsoleteMessage (obsolete_attr, Type.GetSignatureForError (), Location, Report);
} }
ResolveContext rc = null; ResolveContext rc = null;
@ -1669,6 +1669,11 @@ namespace Mono.CSharp {
public readonly PredefinedDecimalAttribute DecimalConstant; public readonly PredefinedDecimalAttribute DecimalConstant;
public readonly PredefinedAttribute StructLayout; public readonly PredefinedAttribute StructLayout;
public readonly PredefinedAttribute FieldOffset; public readonly PredefinedAttribute FieldOffset;
public readonly PredefinedAttribute AssemblyProduct;
public readonly PredefinedAttribute AssemblyCompany;
public readonly PredefinedAttribute AssemblyDescription;
public readonly PredefinedAttribute AssemblyCopyright;
public readonly PredefinedAttribute AssemblyTrademark;
public readonly PredefinedAttribute CallerMemberNameAttribute; public readonly PredefinedAttribute CallerMemberNameAttribute;
public readonly PredefinedAttribute CallerLineNumberAttribute; public readonly PredefinedAttribute CallerLineNumberAttribute;
public readonly PredefinedAttribute CallerFilePathAttribute; public readonly PredefinedAttribute CallerFilePathAttribute;
@ -1722,6 +1727,11 @@ namespace Mono.CSharp {
DecimalConstant = new PredefinedDecimalAttribute (module, "System.Runtime.CompilerServices", "DecimalConstantAttribute"); DecimalConstant = new PredefinedDecimalAttribute (module, "System.Runtime.CompilerServices", "DecimalConstantAttribute");
StructLayout = new PredefinedAttribute (module, "System.Runtime.InteropServices", "StructLayoutAttribute"); StructLayout = new PredefinedAttribute (module, "System.Runtime.InteropServices", "StructLayoutAttribute");
FieldOffset = new PredefinedAttribute (module, "System.Runtime.InteropServices", "FieldOffsetAttribute"); FieldOffset = new PredefinedAttribute (module, "System.Runtime.InteropServices", "FieldOffsetAttribute");
AssemblyProduct = new PredefinedAttribute (module, "System.Reflection", "AssemblyProductAttribute");
AssemblyCompany = new PredefinedAttribute (module, "System.Reflection", "AssemblyCompanyAttribute");
AssemblyDescription = new PredefinedAttribute (module, "System.Reflection", "AssemblyDescriptionAttribute");
AssemblyCopyright = new PredefinedAttribute (module, "System.Reflection", "AssemblyCopyrightAttribute");
AssemblyTrademark = new PredefinedAttribute (module, "System.Reflection", "AssemblyTrademarkAttribute");
AsyncStateMachine = new PredefinedStateMachineAttribute (module, "System.Runtime.CompilerServices", "AsyncStateMachineAttribute"); AsyncStateMachine = new PredefinedStateMachineAttribute (module, "System.Runtime.CompilerServices", "AsyncStateMachineAttribute");
@ -1839,7 +1849,7 @@ namespace Mono.CSharp {
// //
// Handle all parameter-less attributes as optional // Handle all parameter-less attributes as optional
// //
if (!IsDefined) if (!Define ())
return false; return false;
ctor = (MethodSpec) MemberCache.FindMember (type, MemberFilter.Constructor (ParametersCompiled.EmptyReadOnlyParameters), BindingRestriction.DeclaredOnly); ctor = (MethodSpec) MemberCache.FindMember (type, MemberFilter.Constructor (ParametersCompiled.EmptyReadOnlyParameters), BindingRestriction.DeclaredOnly);

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

@ -17,7 +17,6 @@ using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Security; using System.Security;
using System.Security.Permissions; using System.Security.Permissions;
using System.Linq;
using System.Text; using System.Text;
using System.Diagnostics; using System.Diagnostics;
using Mono.CompilerServices.SymbolWriter; using Mono.CompilerServices.SymbolWriter;
@ -1090,9 +1089,9 @@ namespace Mono.CSharp
} }
} }
public virtual void AddBasesForPart (List<FullNamedExpression> bases) public virtual void SetBaseTypes (List<FullNamedExpression> baseTypes)
{ {
type_bases = bases; type_bases = baseTypes;
} }
/// <summary> /// <summary>
@ -1283,8 +1282,10 @@ namespace Mono.CSharp
all_tp_builders = TypeBuilder.DefineGenericParameters (tparam_names); all_tp_builders = TypeBuilder.DefineGenericParameters (tparam_names);
if (CurrentTypeParameters != null) if (CurrentTypeParameters != null) {
CurrentTypeParameters.Define (all_tp_builders, spec, CurrentTypeParametersStartIndex, this); CurrentTypeParameters.Create (spec, CurrentTypeParametersStartIndex, this);
CurrentTypeParameters.Define (all_tp_builders);
}
} }
return true; return true;
@ -1445,6 +1446,7 @@ namespace Mono.CSharp
members.Add (proxy_method); members.Add (proxy_method);
proxy_method.Define (); proxy_method.Define ();
proxy_method.PrepareEmit ();
hoisted_base_call_proxies.Add (method, proxy_method); hoisted_base_call_proxies.Add (method, proxy_method);
} }
@ -1627,6 +1629,10 @@ namespace Mono.CSharp
foreach (var member in members) { foreach (var member in members) {
var pm = member as IParametersMember; var pm = member as IParametersMember;
if (pm != null) { if (pm != null) {
var mc = member as MethodOrOperator;
if (mc != null) {
mc.PrepareEmit ();
}
var p = pm.Parameters; var p = pm.Parameters;
if (p.IsEmpty) if (p.IsEmpty)
@ -1698,19 +1704,6 @@ namespace Mono.CSharp
current_type = null; current_type = null;
} }
void UpdateTypeParameterConstraints (TypeDefinition part)
{
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 (), CurrentTypeParameters[i].GetSignatureForError ());
}
}
public override void RemoveContainer (TypeContainer cont) public override void RemoveContainer (TypeContainer cont)
{ {
base.RemoveContainer (cont); base.RemoveContainer (cont);
@ -1735,7 +1728,7 @@ namespace Mono.CSharp
} }
if (IsPartialPart) { if (IsPartialPart) {
PartialContainer.UpdateTypeParameterConstraints (this); PartialContainer.CurrentTypeParameters.UpdateConstraints (this);
} }
return true; return true;
@ -2296,7 +2289,7 @@ namespace Mono.CSharp
Report.SymbolRelatedToPreviousError (mb.InterfaceType); Report.SymbolRelatedToPreviousError (mb.InterfaceType);
Report.Error (540, mb.Location, "`{0}': containing type does not implement interface `{1}'", Report.Error (540, mb.Location, "`{0}': containing type does not implement interface `{1}'",
mb.GetSignatureForError (), TypeManager.CSharpName (mb.InterfaceType)); mb.GetSignatureForError (), mb.InterfaceType.GetSignatureForError ());
return false; return false;
} }
@ -2526,7 +2519,7 @@ namespace Mono.CSharp
/// <summary> /// <summary>
/// Defines the default constructors /// Defines the default constructors
/// </summary> /// </summary>
protected Constructor DefineDefaultConstructor (bool is_static) protected virtual Constructor DefineDefaultConstructor (bool is_static)
{ {
// The default instance constructor is public // The default instance constructor is public
// If the class is abstract, the default constructor is protected // If the class is abstract, the default constructor is protected
@ -2607,14 +2600,14 @@ namespace Mono.CSharp
visitor.Visit (this); visitor.Visit (this);
} }
public override void AddBasesForPart (List<FullNamedExpression> bases) public override void SetBaseTypes (List<FullNamedExpression> baseTypes)
{ {
var pmn = MemberName; var pmn = MemberName;
if (pmn.Name == "Object" && !pmn.IsGeneric && Parent.MemberName.Name == "System" && Parent.MemberName.Left == null) if (pmn.Name == "Object" && !pmn.IsGeneric && Parent.MemberName.Name == "System" && Parent.MemberName.Left == null)
Report.Error (537, Location, Report.Error (537, Location,
"The class System.Object cannot have a base class or implement an interface."); "The class System.Object cannot have a base class or implement an interface.");
base.AddBasesForPart (bases); base.SetBaseTypes (baseTypes);
} }
public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa) public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
@ -3047,7 +3040,7 @@ namespace Mono.CSharp
Report.SymbolRelatedToPreviousError (iface); Report.SymbolRelatedToPreviousError (iface);
Report.Warning (3027, 1, Location, "`{0}' is not CLS-compliant because base interface `{1}' is not CLS-compliant", Report.Warning (3027, 1, Location, "`{0}' is not CLS-compliant because base interface `{1}' is not CLS-compliant",
GetSignatureForError (), TypeManager.CSharpName (iface)); GetSignatureForError (), iface.GetSignatureForError ());
} }
} }
@ -3282,10 +3275,10 @@ namespace Mono.CSharp
Report.SymbolRelatedToPreviousError (base_member); Report.SymbolRelatedToPreviousError (base_member);
if (this is PropertyBasedMember) { if (this is PropertyBasedMember) {
Report.Error (1715, Location, "`{0}': type must be `{1}' to match overridden member `{2}'", Report.Error (1715, Location, "`{0}': type must be `{1}' to match overridden member `{2}'",
GetSignatureForError (), TypeManager.CSharpName (base_member_type), TypeManager.CSharpSignature (base_member)); GetSignatureForError (), base_member_type.GetSignatureForError (), base_member.GetSignatureForError ());
} else { } else {
Report.Error (508, Location, "`{0}': return type must be `{1}' to match overridden member `{2}'", Report.Error (508, Location, "`{0}': return type must be `{1}' to match overridden member `{2}'",
GetSignatureForError (), TypeManager.CSharpName (base_member_type), TypeManager.CSharpSignature (base_member)); GetSignatureForError (), base_member_type.GetSignatureForError (), base_member.GetSignatureForError ());
} }
ok = false; ok = false;
} }
@ -3359,7 +3352,7 @@ namespace Mono.CSharp
if (!InterfaceType.IsInterface) { if (!InterfaceType.IsInterface) {
Report.SymbolRelatedToPreviousError (InterfaceType); Report.SymbolRelatedToPreviousError (InterfaceType);
Report.Error (538, Location, "The type `{0}' in explicit interface declaration is not an interface", Report.Error (538, Location, "The type `{0}' in explicit interface declaration is not an interface",
TypeManager.CSharpName (InterfaceType)); InterfaceType.GetSignatureForError ());
} else { } else {
Parent.PartialContainer.VerifyImplements (this); Parent.PartialContainer.VerifyImplements (this);
} }
@ -3390,15 +3383,15 @@ namespace Mono.CSharp
if (this is Indexer) if (this is Indexer)
Report.Error (55, Location, Report.Error (55, Location,
"Inconsistent accessibility: parameter type `{0}' is less accessible than indexer `{1}'", "Inconsistent accessibility: parameter type `{0}' is less accessible than indexer `{1}'",
TypeManager.CSharpName (t), GetSignatureForError ()); t.GetSignatureForError (), GetSignatureForError ());
else if (this is Operator) else if (this is Operator)
Report.Error (57, Location, Report.Error (57, Location,
"Inconsistent accessibility: parameter type `{0}' is less accessible than operator `{1}'", "Inconsistent accessibility: parameter type `{0}' is less accessible than operator `{1}'",
TypeManager.CSharpName (t), GetSignatureForError ()); t.GetSignatureForError (), GetSignatureForError ());
else else
Report.Error (51, Location, Report.Error (51, Location,
"Inconsistent accessibility: parameter type `{0}' is less accessible than method `{1}'", "Inconsistent accessibility: parameter type `{0}' is less accessible than method `{1}'",
TypeManager.CSharpName (t), GetSignatureForError ()); t.GetSignatureForError (), GetSignatureForError ());
error = true; error = true;
} }
return !error; return !error;
@ -3507,7 +3500,7 @@ namespace Mono.CSharp
// replacing predefined names which saves some space and name // replacing predefined names which saves some space and name
// is still unique // is still unique
// //
return TypeManager.CSharpName (InterfaceType) + "." + name; return InterfaceType.GetSignatureForError () + "." + name;
} }
public override string GetSignatureForDocumentation () public override string GetSignatureForDocumentation ()
@ -3607,28 +3600,28 @@ namespace Mono.CSharp
if (this is Property) if (this is Property)
Report.Error (53, Location, Report.Error (53, Location,
"Inconsistent accessibility: property type `" + "Inconsistent accessibility: property type `" +
TypeManager.CSharpName (MemberType) + "' is less " + MemberType.GetSignatureForError () + "' is less " +
"accessible than property `" + GetSignatureForError () + "'"); "accessible than property `" + GetSignatureForError () + "'");
else if (this is Indexer) else if (this is Indexer)
Report.Error (54, Location, Report.Error (54, Location,
"Inconsistent accessibility: indexer return type `" + "Inconsistent accessibility: indexer return type `" +
TypeManager.CSharpName (MemberType) + "' is less " + MemberType.GetSignatureForError () + "' is less " +
"accessible than indexer `" + GetSignatureForError () + "'"); "accessible than indexer `" + GetSignatureForError () + "'");
else if (this is MethodCore) { else if (this is MethodCore) {
if (this is Operator) if (this is Operator)
Report.Error (56, Location, Report.Error (56, Location,
"Inconsistent accessibility: return type `" + "Inconsistent accessibility: return type `" +
TypeManager.CSharpName (MemberType) + "' is less " + MemberType.GetSignatureForError () + "' is less " +
"accessible than operator `" + GetSignatureForError () + "'"); "accessible than operator `" + GetSignatureForError () + "'");
else else
Report.Error (50, Location, Report.Error (50, Location,
"Inconsistent accessibility: return type `" + "Inconsistent accessibility: return type `" +
TypeManager.CSharpName (MemberType) + "' is less " + MemberType.GetSignatureForError () + "' is less " +
"accessible than method `" + GetSignatureForError () + "'"); "accessible than method `" + GetSignatureForError () + "'");
} else { } else {
Report.Error (52, Location, Report.Error (52, Location,
"Inconsistent accessibility: field type `" + "Inconsistent accessibility: field type `" +
TypeManager.CSharpName (MemberType) + "' is less " + MemberType.GetSignatureForError () + "' is less " +
"accessible than field `" + GetSignatureForError () + "'"); "accessible than field `" + GetSignatureForError () + "'");
} }
} }

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

@ -100,10 +100,10 @@ namespace Mono.CSharp {
{ {
if (t.IsGenericParameter) { if (t.IsGenericParameter) {
Report.Error (1959, loc, Report.Error (1959, loc,
"Type parameter `{0}' cannot be declared const", TypeManager.CSharpName (t)); "Type parameter `{0}' cannot be declared const", t.GetSignatureForError ());
} else { } else {
Report.Error (283, loc, Report.Error (283, loc,
"The type `{0}' cannot be declared const", TypeManager.CSharpName (t)); "The type `{0}' cannot be declared const", t.GetSignatureForError ());
} }
} }

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

@ -64,7 +64,7 @@ namespace Mono.CSharp {
BuiltinTypeSpec.IsPrimitiveTypeOrDecimal (target) && BuiltinTypeSpec.IsPrimitiveTypeOrDecimal (target) &&
BuiltinTypeSpec.IsPrimitiveTypeOrDecimal (type)) { BuiltinTypeSpec.IsPrimitiveTypeOrDecimal (type)) {
ec.Report.Error (31, loc, "Constant value `{0}' cannot be converted to a `{1}'", ec.Report.Error (31, loc, "Constant value `{0}' cannot be converted to a `{1}'",
GetValueAsLiteral (), TypeManager.CSharpName (target)); GetValueAsLiteral (), target.GetSignatureForError ());
} else { } else {
base.Error_ValueCannotBeConverted (ec, target, expl); base.Error_ValueCannotBeConverted (ec, target, expl);
} }
@ -100,7 +100,7 @@ namespace Mono.CSharp {
// reached, by calling Convert.ImplicitStandardConversionExists // reached, by calling Convert.ImplicitStandardConversionExists
// //
throw new InternalErrorException ("Missing constant conversion between `{0}' and `{1}'", throw new InternalErrorException ("Missing constant conversion between `{0}' and `{1}'",
TypeManager.CSharpName (Type), TypeManager.CSharpName (type)); Type.GetSignatureForError (), type.GetSignatureForError ());
} }
return CreateConstantFromValue (type, constant_value, loc); return CreateConstantFromValue (type, constant_value, loc);
@ -402,7 +402,7 @@ namespace Mono.CSharp {
catch catch
{ {
ec.Report.Error (31, loc, "Constant value `{0}' cannot be converted to a `{1}'", ec.Report.Error (31, loc, "Constant value `{0}' cannot be converted to a `{1}'",
GetValue ().ToString (), TypeManager.CSharpName (target)); GetValue ().ToString (), target.GetSignatureForError ());
} }
} }

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

@ -782,7 +782,7 @@ namespace Mono.CSharp
public LocationsBag LocationsBag { get; set; } public LocationsBag LocationsBag { get; set; }
public bool UseJayGlobalArrays { get; set; } public bool UseJayGlobalArrays { get; set; }
public Tokenizer.LocatedToken[] LocatedTokens { get; set; } public LocatedToken[] LocatedTokens { get; set; }
public MD5 GetChecksumAlgorithm () public MD5 GetChecksumAlgorithm ()
{ {

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

File diff suppressed because it is too large Load Diff

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

@ -54,7 +54,7 @@ namespace Mono.CSharp
/// </summary> /// </summary>
Block current_block; Block current_block;
BlockVariableDeclaration current_variable; BlockVariable current_variable;
Delegate current_delegate; Delegate current_delegate;
@ -426,7 +426,7 @@ extern_alias_directives
extern_alias_directive extern_alias_directive
: EXTERN_ALIAS IDENTIFIER IDENTIFIER SEMICOLON : EXTERN_ALIAS IDENTIFIER IDENTIFIER SEMICOLON
{ {
var lt = (Tokenizer.LocatedToken) $2; var lt = (LocatedToken) $2;
string s = lt.Value; string s = lt.Value;
if (s != "alias") { if (s != "alias") {
syntax_error (lt.Location, "`alias' expected"); syntax_error (lt.Location, "`alias' expected");
@ -434,7 +434,7 @@ extern_alias_directive
if (lang_version == LanguageVersion.ISO_1) if (lang_version == LanguageVersion.ISO_1)
FeatureIsNotAvailable (lt.Location, "external alias"); FeatureIsNotAvailable (lt.Location, "external alias");
lt = (Tokenizer.LocatedToken) $3; lt = (LocatedToken) $3;
if (lt.Value == QualifiedAliasMember.GlobalAlias) { if (lt.Value == QualifiedAliasMember.GlobalAlias) {
RootNamespace.Error_GlobalNamespaceRedefined (report, lt.Location); RootNamespace.Error_GlobalNamespaceRedefined (report, lt.Location);
} }
@ -474,7 +474,7 @@ using_namespace
} }
| USING IDENTIFIER ASSIGN namespace_or_type_expr SEMICOLON | USING IDENTIFIER ASSIGN namespace_or_type_expr SEMICOLON
{ {
var lt = (Tokenizer.LocatedToken) $2; var lt = (LocatedToken) $2;
if (lang_version != LanguageVersion.ISO_1 && lt.Value == "global") { if (lang_version != LanguageVersion.ISO_1 && lt.Value == "global") {
report.Warning (440, 2, lt.Location, report.Warning (440, 2, lt.Location,
"An alias named `global' will not be used when resolving `global::'. The global namespace will be used instead"); "An alias named `global' will not be used when resolving `global::'. The global namespace will be used instead");
@ -563,15 +563,14 @@ opt_semicolon_error
namespace_name namespace_name
: IDENTIFIER : IDENTIFIER
{ {
var lt = (Tokenizer.LocatedToken) $1; var lt = (LocatedToken) $1;
$$ = new MemberName (lt.Value, lt.Location); $$ = new MemberName (lt.Value, lt.Location);
} }
| namespace_name DOT IDENTIFIER | namespace_name DOT IDENTIFIER
{ {
var lt = (Tokenizer.LocatedToken) $3; var lt = (LocatedToken) $3;
$$ = new MemberName ((MemberName) $1, lt.Value, lt.Location) { $$ = new MemberName ((MemberName) $1, lt.Value, lt.Location);
DotLocation = GetLocation ($2) lbag.AddLocation ($$, GetLocation ($2));
};
} }
| error | error
{ {
@ -747,7 +746,7 @@ attribute_section_cont
{ {
Error_SyntaxError (yyToken); Error_SyntaxError (yyToken);
var lt = (Tokenizer.LocatedToken) $1; var lt = (LocatedToken) $1;
var tne = new SimpleName (lt.Value, null, lt.Location); var tne = new SimpleName (lt.Value, null, lt.Location);
$$ = new List<Attribute> () { $$ = new List<Attribute> () {
@ -764,7 +763,7 @@ attribute_section_cont
attribute_target attribute_target
: IDENTIFIER : IDENTIFIER
{ {
var lt = (Tokenizer.LocatedToken) $1; var lt = (LocatedToken) $1;
$$ = CheckAttributeTarget (lt.Value, lt.Location); $$ = CheckAttributeTarget (lt.Value, lt.Location);
savedCloseLocation = GetLocation ($1); savedCloseLocation = GetLocation ($1);
} }
@ -894,14 +893,14 @@ named_attribute_argument
expression expression
{ {
--lexer.parsing_block; --lexer.parsing_block;
var lt = (Tokenizer.LocatedToken) $1; var lt = (LocatedToken) $1;
$$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4); $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4);
lbag.AddLocation ($$, GetLocation($2)); lbag.AddLocation ($$, GetLocation($2));
} }
; ;
named_argument named_argument
: identifier_inside_body COLON opt_named_modifier expression : identifier_inside_body COLON opt_named_modifier expression_or_error
{ {
if (lang_version <= LanguageVersion.V_3) if (lang_version <= LanguageVersion.V_3)
FeatureIsNotAvailable (GetLocation ($1), "named argument"); FeatureIsNotAvailable (GetLocation ($1), "named argument");
@ -909,7 +908,7 @@ named_argument
// Avoid boxing in common case (no modifier) // Avoid boxing in common case (no modifier)
var arg_mod = $3 == null ? Argument.AType.None : (Argument.AType) $3; var arg_mod = $3 == null ? Argument.AType.None : (Argument.AType) $3;
var lt = (Tokenizer.LocatedToken) $1; var lt = (LocatedToken) $1;
$$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4, arg_mod); $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4, arg_mod);
lbag.AddLocation ($$, GetLocation($2)); lbag.AddLocation ($$, GetLocation($2));
} }
@ -1023,7 +1022,7 @@ constant_declaration
opt_modifiers opt_modifiers
CONST type IDENTIFIER CONST type IDENTIFIER
{ {
var lt = (Tokenizer.LocatedToken) $5; var lt = (LocatedToken) $5;
var mod = (Modifiers) $2; var mod = (Modifiers) $2;
current_field = new Const (current_type, (FullNamedExpression) $4, mod, new MemberName (lt.Value, lt.Location), (Attributes) $1); current_field = new Const (current_type, (FullNamedExpression) $4, mod, new MemberName (lt.Value, lt.Location), (Attributes) $1);
current_type.AddMember (current_field); current_type.AddMember (current_field);
@ -1074,7 +1073,7 @@ constant_declarators
constant_declarator constant_declarator
: COMMA IDENTIFIER constant_initializer : COMMA IDENTIFIER constant_initializer
{ {
var lt = (Tokenizer.LocatedToken) $2; var lt = (LocatedToken) $2;
$$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3); $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
lbag.AddLocation ($$, GetLocation ($1)); lbag.AddLocation ($$, GetLocation ($1));
} }
@ -1114,7 +1113,7 @@ field_declaration
if (type.Type != null && type.Type.Kind == MemberKind.Void) if (type.Type != null && type.Type.Kind == MemberKind.Void)
report.Error (670, GetLocation ($3), "Fields cannot have void type"); report.Error (670, GetLocation ($3), "Fields cannot have void type");
var lt = (Tokenizer.LocatedToken) $4; var lt = (LocatedToken) $4;
current_field = new Field (current_type, type, (Modifiers) $2, new MemberName (lt.Value, lt.Location), (Attributes) $1); current_field = new Field (current_type, type, (Modifiers) $2, new MemberName (lt.Value, lt.Location), (Attributes) $1);
current_type.AddField (current_field); current_type.AddField (current_field);
$$ = current_field; $$ = current_field;
@ -1139,7 +1138,7 @@ field_declaration
if (lang_version < LanguageVersion.ISO_2) if (lang_version < LanguageVersion.ISO_2)
FeatureIsNotAvailable (GetLocation ($3), "fixed size buffers"); FeatureIsNotAvailable (GetLocation ($3), "fixed size buffers");
var lt = (Tokenizer.LocatedToken) $5; var lt = (LocatedToken) $5;
current_field = new FixedField (current_type, (FullNamedExpression) $4, (Modifiers) $2, current_field = new FixedField (current_type, (FullNamedExpression) $4, (Modifiers) $2,
new MemberName (lt.Value, lt.Location), (Attributes) $1); new MemberName (lt.Value, lt.Location), (Attributes) $1);
@ -1203,7 +1202,7 @@ field_declarators
field_declarator field_declarator
: COMMA IDENTIFIER : COMMA IDENTIFIER
{ {
var lt = (Tokenizer.LocatedToken) $2; var lt = (LocatedToken) $2;
$$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null); $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
lbag.AddLocation ($$, GetLocation ($1)); lbag.AddLocation ($$, GetLocation ($1));
} }
@ -1214,7 +1213,7 @@ field_declarator
variable_initializer variable_initializer
{ {
--lexer.parsing_block; --lexer.parsing_block;
var lt = (Tokenizer.LocatedToken) $2; var lt = (LocatedToken) $2;
$$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5); $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3)); lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
} }
@ -1239,7 +1238,7 @@ fixed_field_declarators
fixed_field_declarator fixed_field_declarator
: COMMA IDENTIFIER fixed_field_size : COMMA IDENTIFIER fixed_field_size
{ {
var lt = (Tokenizer.LocatedToken) $2; var lt = (LocatedToken) $2;
$$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3); $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
lbag.AddLocation ($$, GetLocation ($1)); lbag.AddLocation ($$, GetLocation ($1));
} }
@ -1383,8 +1382,10 @@ method_header
current_type.AddMember (method); current_type.AddMember (method);
if ($11 != null) async_block = (method.ModFlags & Modifiers.ASYNC) != 0;
method.SetConstraints ((List<Constraints>) $11);
if ($12 != null)
method.SetConstraints ((List<Constraints>) $12);
if (doc_support) if (doc_support)
method.DocComment = Lexer.consume_doc_comment (); method.DocComment = Lexer.consume_doc_comment ();
@ -1561,7 +1562,7 @@ fixed_parameter
parameter_type parameter_type
identifier_inside_body identifier_inside_body
{ {
var lt = (Tokenizer.LocatedToken) $4; var lt = (LocatedToken) $4;
$$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location); $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
lbag.AddLocation ($$, parameterModifierLocation); lbag.AddLocation ($$, parameterModifierLocation);
} }
@ -1570,7 +1571,7 @@ fixed_parameter
parameter_type parameter_type
identifier_inside_body OPEN_BRACKET CLOSE_BRACKET identifier_inside_body OPEN_BRACKET CLOSE_BRACKET
{ {
var lt = (Tokenizer.LocatedToken) $4; var lt = (LocatedToken) $4;
report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name"); report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
$$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location); $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
lbag.AddLocation ($$, parameterModifierLocation); lbag.AddLocation ($$, parameterModifierLocation);
@ -1629,7 +1630,7 @@ fixed_parameter
if ((valid_param_mod & ParameterModifierType.DefaultValue) == 0) if ((valid_param_mod & ParameterModifierType.DefaultValue) == 0)
report.Error (1065, GetLocation ($5), "Optional parameter is not valid in this context"); report.Error (1065, GetLocation ($5), "Optional parameter is not valid in this context");
var lt = (Tokenizer.LocatedToken) $4; var lt = (LocatedToken) $4;
$$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, lt.Location); $$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, lt.Location);
lbag.AddLocation ($$, parameterModifierLocation, GetLocation ($5)); // parameterModifierLocation should be ignored when mod == NONE lbag.AddLocation ($$, parameterModifierLocation, GetLocation ($5)); // parameterModifierLocation should be ignored when mod == NONE
@ -1701,7 +1702,7 @@ parameter_modifier
parameter_array parameter_array
: opt_attributes params_modifier type IDENTIFIER : opt_attributes params_modifier type IDENTIFIER
{ {
var lt = (Tokenizer.LocatedToken) $4; var lt = (LocatedToken) $4;
$$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location); $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
lbag.AddLocation ($$, savedLocation); lbag.AddLocation ($$, savedLocation);
} }
@ -1709,7 +1710,7 @@ parameter_array
{ {
report.Error (1751, GetLocation ($2), "Cannot specify a default value for a parameter array"); report.Error (1751, GetLocation ($2), "Cannot specify a default value for a parameter array");
var lt = (Tokenizer.LocatedToken) $4; var lt = (LocatedToken) $4;
$$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location); $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
lbag.AddLocation ($$, savedLocation); lbag.AddLocation ($$, savedLocation);
} }
@ -2135,11 +2136,11 @@ operator_declarator
Operator.GetName (op)); Operator.GetName (op));
} }
} else { } else {
if (p_count > 2) { if (p_count == 1) {
report.Error (1019, loc, "Overloadable unary operator expected");
} else if (p_count != 2) {
report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters", report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
Operator.GetName (op)); Operator.GetName (op));
} else if (p_count != 2) {
report.Error (1019, loc, "Overloadable unary operator expected");
} }
} }
@ -2276,7 +2277,7 @@ constructor_declarator
valid_param_mod = 0; valid_param_mod = 0;
current_local_parameters = (ParametersCompiled) $6; current_local_parameters = (ParametersCompiled) $6;
var lt = (Tokenizer.LocatedToken) $3; var lt = (LocatedToken) $3;
var mods = (Modifiers) $2; var mods = (Modifiers) $2;
var c = new Constructor (current_type, lt.Value, mods, (Attributes) $1, current_local_parameters, lt.Location); var c = new Constructor (current_type, lt.Value, mods, (Attributes) $1, current_local_parameters, lt.Location);
@ -2373,7 +2374,7 @@ destructor_declaration
} }
IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body
{ {
var lt = (Tokenizer.LocatedToken) $5; var lt = (LocatedToken) $5;
if (lt.Value != current_container.MemberName.Name){ if (lt.Value != current_container.MemberName.Name){
report.Error (574, lt.Location, "Name of destructor must match name of class"); report.Error (574, lt.Location, "Name of destructor must match name of class");
} else if (current_container.Kind != MemberKind.Class){ } else if (current_container.Kind != MemberKind.Class){
@ -2496,7 +2497,7 @@ event_declarators
event_declarator event_declarator
: COMMA IDENTIFIER : COMMA IDENTIFIER
{ {
var lt = (Tokenizer.LocatedToken) $2; var lt = (LocatedToken) $2;
$$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null); $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
lbag.AddLocation ($$, GetLocation ($1)); lbag.AddLocation ($$, GetLocation ($1));
} }
@ -2507,7 +2508,7 @@ event_declarator
event_variable_initializer event_variable_initializer
{ {
--lexer.parsing_block; --lexer.parsing_block;
var lt = (Tokenizer.LocatedToken) $2; var lt = (LocatedToken) $2;
$$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5); $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3)); lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
} }
@ -2729,7 +2730,7 @@ enum_member_declarations
enum_member_declaration enum_member_declaration
: opt_attributes IDENTIFIER : opt_attributes IDENTIFIER
{ {
var lt = (Tokenizer.LocatedToken) $2; var lt = (LocatedToken) $2;
var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1); var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
((Enum) current_type).AddEnumMember (em); ((Enum) current_type).AddEnumMember (em);
@ -2752,7 +2753,7 @@ enum_member_declaration
{ {
--lexer.parsing_block; --lexer.parsing_block;
var lt = (Tokenizer.LocatedToken) $2; var lt = (LocatedToken) $2;
var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1); var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4)); em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
((Enum) current_type).AddEnumMember (em); ((Enum) current_type).AddEnumMember (em);
@ -2766,7 +2767,7 @@ enum_member_declaration
{ {
Error_SyntaxError (yyToken); Error_SyntaxError (yyToken);
var lt = (Tokenizer.LocatedToken) $2; var lt = (LocatedToken) $2;
var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1); var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
((Enum) current_type).AddEnumMember (em); ((Enum) current_type).AddEnumMember (em);
@ -2840,8 +2841,8 @@ namespace_or_type_expr
: member_name : member_name
| qualified_alias_member IDENTIFIER opt_type_argument_list | qualified_alias_member IDENTIFIER opt_type_argument_list
{ {
var lt1 = (Tokenizer.LocatedToken) $1; var lt1 = (LocatedToken) $1;
var lt2 = (Tokenizer.LocatedToken) $2; var lt2 = (LocatedToken) $2;
$$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location); $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
lbag.AddLocation ($$, savedLocation, GetLocation ($2)); lbag.AddLocation ($$, savedLocation, GetLocation ($2));
@ -2852,17 +2853,16 @@ member_name
: simple_name_expr : simple_name_expr
| namespace_or_type_expr DOT IDENTIFIER opt_type_argument_list | namespace_or_type_expr DOT IDENTIFIER opt_type_argument_list
{ {
var lt = (Tokenizer.LocatedToken) $3; var lt = (LocatedToken) $3;
$$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location) { $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
DotLocation = GetLocation ($2) lbag.AddLocation ($$, GetLocation ($2));
};
} }
; ;
simple_name_expr simple_name_expr
: IDENTIFIER opt_type_argument_list : IDENTIFIER opt_type_argument_list
{ {
var lt = (Tokenizer.LocatedToken) $1; var lt = (LocatedToken) $1;
$$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location); $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
} }
; ;
@ -2918,7 +2918,7 @@ type_declaration_name
opt_type_parameter_list opt_type_parameter_list
{ {
lexer.parsing_generic_declaration = false; lexer.parsing_generic_declaration = false;
var lt = (Tokenizer.LocatedToken) $1; var lt = (LocatedToken) $1;
$$ = new MemberName (lt.Value, (TypeParameters)$3, lt.Location); $$ = new MemberName (lt.Value, (TypeParameters)$3, lt.Location);
} }
; ;
@ -2938,7 +2938,7 @@ method_declaration_name
| explicit_interface IDENTIFIER opt_type_parameter_list | explicit_interface IDENTIFIER opt_type_parameter_list
{ {
lexer.parsing_generic_declaration = false; lexer.parsing_generic_declaration = false;
var lt = (Tokenizer.LocatedToken) $2; var lt = (LocatedToken) $2;
$$ = new MemberName (lt.Value, (TypeParameters) $3, (ATypeNameExpression) $1, lt.Location); $$ = new MemberName (lt.Value, (TypeParameters) $3, (ATypeNameExpression) $1, lt.Location);
} }
; ;
@ -2959,21 +2959,21 @@ indexer_declaration_name
explicit_interface explicit_interface
: IDENTIFIER opt_type_argument_list DOT : IDENTIFIER opt_type_argument_list DOT
{ {
var lt = (Tokenizer.LocatedToken) $1; var lt = (LocatedToken) $1;
$$ = new SimpleName (lt.Value, (TypeArguments) $2, lt.Location); $$ = new SimpleName (lt.Value, (TypeArguments) $2, lt.Location);
lbag.AddLocation ($$, GetLocation ($3)); lbag.AddLocation ($$, GetLocation ($3));
} }
| qualified_alias_member IDENTIFIER opt_type_argument_list DOT | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
{ {
var lt1 = (Tokenizer.LocatedToken) $1; var lt1 = (LocatedToken) $1;
var lt2 = (Tokenizer.LocatedToken) $2; var lt2 = (LocatedToken) $2;
$$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location); $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
lbag.AddLocation ($$, savedLocation, GetLocation ($4)); lbag.AddLocation ($$, savedLocation, GetLocation ($4));
} }
| explicit_interface IDENTIFIER opt_type_argument_list DOT | explicit_interface IDENTIFIER opt_type_argument_list DOT
{ {
var lt = (Tokenizer.LocatedToken) $2; var lt = (LocatedToken) $2;
$$ = new MemberAccess ((ATypeNameExpression) $1, lt.Value, (TypeArguments) $3, lt.Location); $$ = new MemberAccess ((ATypeNameExpression) $1, lt.Value, (TypeArguments) $3, lt.Location);
lbag.AddLocation ($$, GetLocation ($4)); lbag.AddLocation ($$, GetLocation ($4));
} }
@ -3014,7 +3014,7 @@ type_parameters
type_parameter type_parameter
: opt_attributes opt_type_parameter_variance IDENTIFIER : opt_attributes opt_type_parameter_variance IDENTIFIER
{ {
var lt = (Tokenizer.LocatedToken)$3; var lt = (LocatedToken)$3;
var variance = (Variance) $2; var variance = (Variance) $2;
$$ = new TypeParameter (new MemberName (lt.Value, lt.Location), (Attributes)$1, variance); $$ = new TypeParameter (new MemberName (lt.Value, lt.Location), (Attributes)$1, variance);
if (variance != Variance.None) if (variance != Variance.None)
@ -3202,11 +3202,11 @@ primary_expression
primary_expression_or_type primary_expression_or_type
: IDENTIFIER opt_type_argument_list : IDENTIFIER opt_type_argument_list
{ {
var lt = (Tokenizer.LocatedToken) $1; var lt = (LocatedToken) $1;
$$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location); $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
} }
| IDENTIFIER GENERATE_COMPLETION { | IDENTIFIER GENERATE_COMPLETION {
var lt = (Tokenizer.LocatedToken) $1; var lt = (LocatedToken) $1;
$$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location); $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
} }
| member_access | member_access
@ -3259,29 +3259,26 @@ parenthesized_expression
member_access member_access
: primary_expression DOT identifier_inside_body opt_type_argument_list : primary_expression DOT identifier_inside_body opt_type_argument_list
{ {
var lt = (Tokenizer.LocatedToken) $3; var lt = (LocatedToken) $3;
$$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location) { $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
DotLocation = GetLocation ($2) lbag.AddLocation ($$, GetLocation ($2));
};
} }
| builtin_types DOT identifier_inside_body opt_type_argument_list | builtin_types DOT identifier_inside_body opt_type_argument_list
{ {
var lt = (Tokenizer.LocatedToken) $3; var lt = (LocatedToken) $3;
$$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location) { $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
DotLocation = GetLocation ($2) lbag.AddLocation ($$, GetLocation ($2));
};
} }
| BASE DOT identifier_inside_body opt_type_argument_list | BASE DOT identifier_inside_body opt_type_argument_list
{ {
var lt = (Tokenizer.LocatedToken) $3; var lt = (LocatedToken) $3;
$$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location) { $$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location);
DotLocation = GetLocation ($2) lbag.AddLocation ($$, GetLocation ($2));
};
} }
| qualified_alias_member identifier_inside_body opt_type_argument_list | qualified_alias_member identifier_inside_body opt_type_argument_list
{ {
var lt1 = (Tokenizer.LocatedToken) $1; var lt1 = (LocatedToken) $1;
var lt2 = (Tokenizer.LocatedToken) $2; var lt2 = (LocatedToken) $2;
$$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location); $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
lbag.AddLocation ($$, savedLocation, GetLocation ($2)); lbag.AddLocation ($$, savedLocation, GetLocation ($2));
@ -3290,7 +3287,7 @@ member_access
$$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3)); $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
} }
| primary_expression DOT IDENTIFIER GENERATE_COMPLETION { | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
var lt = (Tokenizer.LocatedToken) $3; var lt = (LocatedToken) $3;
$$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location); $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
} }
| builtin_types DOT GENERATE_COMPLETION | builtin_types DOT GENERATE_COMPLETION
@ -3298,7 +3295,7 @@ member_access
$$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location); $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
} }
| builtin_types DOT IDENTIFIER GENERATE_COMPLETION { | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
var lt = (Tokenizer.LocatedToken) $3; var lt = (LocatedToken) $3;
$$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location); $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
} }
; ;
@ -3378,13 +3375,13 @@ member_initializer_list
member_initializer member_initializer
: IDENTIFIER ASSIGN initializer_value : IDENTIFIER ASSIGN initializer_value
{ {
var lt = (Tokenizer.LocatedToken) $1; var lt = (LocatedToken) $1;
$$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location); $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
lbag.AddLocation ($$, GetLocation ($2)); lbag.AddLocation ($$, GetLocation ($2));
} }
| AWAIT ASSIGN initializer_value | AWAIT ASSIGN initializer_value
{ {
var lt = (Tokenizer.LocatedToken) Error_AwaitAsIdentifier ($1); var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
$$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location); $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
lbag.AddLocation ($$, GetLocation ($2)); lbag.AddLocation ($$, GetLocation ($2));
} }
@ -3722,13 +3719,13 @@ anonymous_type_parameters
anonymous_type_parameter anonymous_type_parameter
: identifier_inside_body ASSIGN variable_initializer : identifier_inside_body ASSIGN variable_initializer
{ {
var lt = (Tokenizer.LocatedToken)$1; var lt = (LocatedToken)$1;
$$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location); $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
lbag.AddLocation ($$, GetLocation ($2)); lbag.AddLocation ($$, GetLocation ($2));
} }
| identifier_inside_body | identifier_inside_body
{ {
var lt = (Tokenizer.LocatedToken)$1; var lt = (LocatedToken)$1;
$$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location), $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
lt.Value, lt.Location); lt.Value, lt.Location);
} }
@ -3857,15 +3854,17 @@ typeof_type_expression
unbound_type_name unbound_type_name
: identifier_inside_body generic_dimension : identifier_inside_body generic_dimension
{ {
var lt = (Tokenizer.LocatedToken) $1; var lt = (LocatedToken) $1;
var sn = new SimpleName (lt.Value, (int) $2, lt.Location); var sn = new SimpleName (lt.Value, (int) $2, lt.Location);
$$ = sn; $$ = sn;
lbag.AddLocation (sn.TypeArguments, Lexer.GetGenericDimensionLocations ()); lbag.AddLocation (sn.TypeArguments, Lexer.GetGenericDimensionLocations ());
} }
| qualified_alias_member identifier_inside_body generic_dimension | qualified_alias_member identifier_inside_body generic_dimension
{ {
var lt1 = (Tokenizer.LocatedToken) $1; var lt1 = (LocatedToken) $1;
var lt2 = (Tokenizer.LocatedToken) $2; var lt2 = (LocatedToken) $2;
var qam = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location); var qam = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
$$ = qam; $$ = qam;
lbag.AddLocation (qam.TypeArguments, Lexer.GetGenericDimensionLocations ()); lbag.AddLocation (qam.TypeArguments, Lexer.GetGenericDimensionLocations ());
@ -3873,20 +3872,18 @@ unbound_type_name
} }
| unbound_type_name DOT identifier_inside_body | unbound_type_name DOT identifier_inside_body
{ {
var lt = (Tokenizer.LocatedToken) $3; var lt = (LocatedToken) $3;
$$ = new MemberAccess ((Expression) $1, lt.Value, lt.Location) { $$ = new MemberAccess ((Expression) $1, lt.Value, lt.Location);
DotLocation = GetLocation ($2) lbag.AddLocation ($$, savedLocation, GetLocation ($2));
};
} }
| unbound_type_name DOT identifier_inside_body generic_dimension | unbound_type_name DOT identifier_inside_body generic_dimension
{ {
var lt = (Tokenizer.LocatedToken) $3; var lt = (LocatedToken) $3;
var ma = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location) { var ma = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
DotLocation = GetLocation ($2)
};
$$ = ma; $$ = ma;
lbag.AddLocation ($$, savedLocation, GetLocation ($2));
lbag.AddLocation (ma.TypeArguments, Lexer.GetGenericDimensionLocations ()); lbag.AddLocation (ma.TypeArguments, Lexer.GetGenericDimensionLocations ());
} }
| namespace_or_type_expr DOT identifier_inside_body generic_dimension | namespace_or_type_expr DOT identifier_inside_body generic_dimension
@ -3895,10 +3892,8 @@ unbound_type_name
if (tne.HasTypeArguments) if (tne.HasTypeArguments)
Error_TypeExpected (GetLocation ($4)); Error_TypeExpected (GetLocation ($4));
var lt = (Tokenizer.LocatedToken) $3; var lt = (LocatedToken) $3;
var ma = new MemberAccess (tne, lt.Value, (int) $4, lt.Location) { var ma = new MemberAccess (tne, lt.Value, (int) $4, lt.Location);
DotLocation = GetLocation ($2)
};
$$ = ma; $$ = ma;
lbag.AddLocation (ma.TypeArguments, Lexer.GetGenericDimensionLocations ()); lbag.AddLocation (ma.TypeArguments, Lexer.GetGenericDimensionLocations ());
} }
@ -3917,7 +3912,7 @@ generic_dimension
qualified_alias_member qualified_alias_member
: IDENTIFIER DOUBLE_COLON : IDENTIFIER DOUBLE_COLON
{ {
var lt = (Tokenizer.LocatedToken) $1; var lt = (LocatedToken) $1;
if (lang_version == LanguageVersion.ISO_1) if (lang_version == LanguageVersion.ISO_1)
FeatureIsNotAvailable (lt.Location, "namespace alias qualifier"); FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
savedLocation = GetLocation ($2); savedLocation = GetLocation ($2);
@ -3971,7 +3966,7 @@ unchecked_expression
pointer_member_access pointer_member_access
: primary_expression OP_PTR IDENTIFIER opt_type_argument_list : primary_expression OP_PTR IDENTIFIER opt_type_argument_list
{ {
var lt = (Tokenizer.LocatedToken) $3; var lt = (LocatedToken) $3;
$$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, (TypeArguments) $4, lt.Location); $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, (TypeArguments) $4, lt.Location);
} }
; ;
@ -4570,24 +4565,24 @@ lambda_parameter_list
lambda_parameter lambda_parameter
: parameter_modifier parameter_type identifier_inside_body : parameter_modifier parameter_type identifier_inside_body
{ {
var lt = (Tokenizer.LocatedToken) $3; var lt = (LocatedToken) $3;
$$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location); $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
} }
| parameter_type identifier_inside_body | parameter_type identifier_inside_body
{ {
var lt = (Tokenizer.LocatedToken) $2; var lt = (LocatedToken) $2;
$$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location); $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
} }
| IDENTIFIER | IDENTIFIER
{ {
var lt = (Tokenizer.LocatedToken) $1; var lt = (LocatedToken) $1;
$$ = new ImplicitLambdaParameter (lt.Value, lt.Location); $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
} }
| AWAIT | AWAIT
{ {
var lt = (Tokenizer.LocatedToken) Error_AwaitAsIdentifier ($1); var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
$$ = new ImplicitLambdaParameter (lt.Value, lt.Location); $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
} }
; ;
@ -4637,7 +4632,7 @@ expression_or_error
lambda_expression lambda_expression
: IDENTIFIER ARROW : IDENTIFIER ARROW
{ {
var lt = (Tokenizer.LocatedToken) $1; var lt = (LocatedToken) $1;
Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location); Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
start_anonymous (true, new ParametersCompiled (p), false, lt.Location); start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
} }
@ -4648,7 +4643,7 @@ lambda_expression
} }
| AWAIT ARROW | AWAIT ARROW
{ {
var lt = (Tokenizer.LocatedToken) Error_AwaitAsIdentifier ($1); var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location); Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
start_anonymous (true, new ParametersCompiled (p), false, lt.Location); start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
} }
@ -4659,7 +4654,7 @@ lambda_expression
} }
| ASYNC identifier_inside_body ARROW | ASYNC identifier_inside_body ARROW
{ {
var lt = (Tokenizer.LocatedToken) $2; var lt = (LocatedToken) $2;
Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location); Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
start_anonymous (true, new ParametersCompiled (p), true, lt.Location); start_anonymous (true, new ParametersCompiled (p), true, lt.Location);
} }
@ -4923,14 +4918,14 @@ opt_class_base
: /* empty */ : /* empty */
| COLON type_list | COLON type_list
{ {
current_type.AddBasesForPart ((List<FullNamedExpression>) $2); current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
lbag.AppendToMember (current_type, GetLocation ($1)); lbag.AppendToMember (current_type, GetLocation ($1));
} }
| COLON type_list error | COLON type_list error
{ {
Error_SyntaxError (yyToken); Error_SyntaxError (yyToken);
current_type.AddBasesForPart ((List<FullNamedExpression>) $2); current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
} }
; ;
@ -4970,7 +4965,7 @@ type_parameter_constraints_clauses
type_parameter_constraints_clause type_parameter_constraints_clause
: WHERE IDENTIFIER COLON type_parameter_constraints : WHERE IDENTIFIER COLON type_parameter_constraints
{ {
var lt = (Tokenizer.LocatedToken) $2; var lt = (LocatedToken) $2;
$$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1)); $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
lbag.AddLocation ($$, GetLocation ($3)); lbag.AddLocation ($$, GetLocation ($3));
} }
@ -4978,7 +4973,7 @@ type_parameter_constraints_clause
{ {
Error_SyntaxError (yyToken); Error_SyntaxError (yyToken);
var lt = (Tokenizer.LocatedToken) $2; var lt = (LocatedToken) $2;
$$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), null, GetLocation ($1)); $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), null, GetLocation ($1));
} }
; ;
@ -5160,7 +5155,7 @@ statement
| IDENTIFIER error | IDENTIFIER error
{ {
Error_SyntaxError (yyToken); Error_SyntaxError (yyToken);
var lt =(Tokenizer.LocatedToken) $1; var lt =(LocatedToken) $1;
var sn = new SimpleName (lt.Value, lt.Location); var sn = new SimpleName (lt.Value, lt.Location);
current_block.AddStatement(new StatementErrorExpression (sn)); current_block.AddStatement(new StatementErrorExpression (sn));
$$ = null; $$ = null;
@ -5258,7 +5253,7 @@ empty_statement
labeled_statement labeled_statement
: identifier_inside_body COLON : identifier_inside_body COLON
{ {
var lt = (Tokenizer.LocatedToken) $1; var lt = (LocatedToken) $1;
LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location); LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location);
lbag.AddLocation (labeled, GetLocation ($2)); lbag.AddLocation (labeled, GetLocation ($2));
current_block.AddLabel (labeled); current_block.AddLabel (labeled);
@ -5375,10 +5370,10 @@ identifier_inside_body
block_variable_declaration block_variable_declaration
: variable_type identifier_inside_body : variable_type identifier_inside_body
{ {
var lt = (Tokenizer.LocatedToken) $2; var lt = (LocatedToken) $2;
var li = new LocalVariable (current_block, lt.Value, lt.Location); var li = new LocalVariable (current_block, lt.Value, lt.Location);
current_block.AddLocalName (li); current_block.AddLocalName (li);
current_variable = new BlockVariableDeclaration ((FullNamedExpression) $1, li); current_variable = new BlockVariable ((FullNamedExpression) $1, li);
} }
opt_local_variable_initializer opt_variable_declarators semicolon_or_handle_error_close_brace opt_local_variable_initializer opt_variable_declarators semicolon_or_handle_error_close_brace
{ {
@ -5391,10 +5386,10 @@ block_variable_declaration
} }
| CONST variable_type identifier_inside_body | CONST variable_type identifier_inside_body
{ {
var lt = (Tokenizer.LocatedToken) $3; var lt = (LocatedToken) $3;
var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location); var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
current_block.AddLocalName (li); current_block.AddLocalName (li);
current_variable = new BlockConstantDeclaration ((FullNamedExpression) $2, li); current_variable = new BlockConstant ((FullNamedExpression) $2, li);
} }
const_variable_initializer opt_const_declarators SEMICOLON const_variable_initializer opt_const_declarators SEMICOLON
{ {
@ -5461,18 +5456,18 @@ variable_declarators
variable_declarator variable_declarator
: COMMA identifier_inside_body : COMMA identifier_inside_body
{ {
var lt = (Tokenizer.LocatedToken) $2; var lt = (LocatedToken) $2;
var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location); var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
var d = new BlockVariableDeclaration.Declarator (li, null); var d = new BlockVariableDeclarator (li, null);
current_variable.AddDeclarator (d); current_variable.AddDeclarator (d);
current_block.AddLocalName (li); current_block.AddLocalName (li);
lbag.AddLocation (d, GetLocation ($1)); lbag.AddLocation (d, GetLocation ($1));
} }
| COMMA identifier_inside_body ASSIGN block_variable_initializer | COMMA identifier_inside_body ASSIGN block_variable_initializer
{ {
var lt = (Tokenizer.LocatedToken) $2; var lt = (LocatedToken) $2;
var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location); var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
var d = new BlockVariableDeclaration.Declarator (li, (Expression) $4); var d = new BlockVariableDeclarator (li, (Expression) $4);
current_variable.AddDeclarator (d); current_variable.AddDeclarator (d);
current_block.AddLocalName (li); current_block.AddLocalName (li);
lbag.AddLocation (d, GetLocation ($1), GetLocation ($3)); lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
@ -5504,9 +5499,9 @@ const_declarators
const_declarator const_declarator
: COMMA identifier_inside_body ASSIGN constant_initializer_expr : COMMA identifier_inside_body ASSIGN constant_initializer_expr
{ {
var lt = (Tokenizer.LocatedToken) $2; var lt = (LocatedToken) $2;
var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location); var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
var d = new BlockVariableDeclaration.Declarator (li, (Expression) $4); var d = new BlockVariableDeclarator (li, (Expression) $4);
current_variable.AddDeclarator (d); current_variable.AddDeclarator (d);
current_block.AddLocalName (li); current_block.AddLocalName (li);
lbag.AddLocation (d, GetLocation ($1), GetLocation ($3)); lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
@ -5557,7 +5552,6 @@ statement_expression
ExpressionStatement s = $1 as ExpressionStatement; ExpressionStatement s = $1 as ExpressionStatement;
if (s == null) { if (s == null) {
var expr = $1 as Expression; var expr = $1 as Expression;
expr.Error_InvalidExpressionStatement (report);
$$ = new StatementErrorExpression (expr); $$ = new StatementErrorExpression (expr);
} else { } else {
$$ = new StatementExpression (s); $$ = new StatementExpression (s);
@ -5822,10 +5816,10 @@ opt_for_initializer
for_initializer for_initializer
: variable_type identifier_inside_body : variable_type identifier_inside_body
{ {
var lt = (Tokenizer.LocatedToken) $2; var lt = (LocatedToken) $2;
var li = new LocalVariable (current_block, lt.Value, lt.Location); var li = new LocalVariable (current_block, lt.Value, lt.Location);
current_block.AddLocalName (li); current_block.AddLocalName (li);
current_variable = new BlockVariableDeclaration ((FullNamedExpression) $1, li); current_variable = new BlockVariable ((FullNamedExpression) $1, li);
} }
opt_local_variable_initializer opt_variable_declarators opt_local_variable_initializer opt_variable_declarators
{ {
@ -5891,7 +5885,7 @@ foreach_statement
start_block (GetLocation ($2)); start_block (GetLocation ($2));
current_block.IsCompilerGenerated = true; current_block.IsCompilerGenerated = true;
var lt = (Tokenizer.LocatedToken) $4; var lt = (LocatedToken) $4;
var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location); var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
current_block.AddLocalName (li); current_block.AddLocalName (li);
@ -5905,7 +5899,8 @@ foreach_statement
{ {
start_block (GetLocation ($2)); start_block (GetLocation ($2));
current_block.IsCompilerGenerated = true; current_block.IsCompilerGenerated = true;
var lt = (Tokenizer.LocatedToken) $4;
var lt = (LocatedToken) $4;
var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location); var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
current_block.AddLocalName (li); current_block.AddLocalName (li);
$$ = li; $$ = li;
@ -5925,7 +5920,7 @@ foreach_statement
{ {
start_block (GetLocation ($2)); start_block (GetLocation ($2));
current_block.IsCompilerGenerated = true; current_block.IsCompilerGenerated = true;
var lt = $4 as Tokenizer.LocatedToken; var lt = $4 as LocatedToken;
var li = lt != null ? new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location) : null; var li = lt != null ? new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location) : null;
Foreach f = new Foreach ((Expression) $3, li, null, null, null, GetLocation ($1)); Foreach f = new Foreach ((Expression) $3, li, null, null, null, GetLocation ($1));
@ -5977,7 +5972,7 @@ continue_statement
goto_statement goto_statement
: GOTO identifier_inside_body SEMICOLON : GOTO identifier_inside_body SEMICOLON
{ {
var lt = (Tokenizer.LocatedToken) $2; var lt = (LocatedToken) $2;
$$ = new Goto (lt.Value, GetLocation ($1)); $$ = new Goto (lt.Value, GetLocation ($1));
lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3)); lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
} }
@ -6027,7 +6022,7 @@ throw_statement
yield_statement yield_statement
: identifier_inside_body RETURN opt_expression SEMICOLON : identifier_inside_body RETURN opt_expression SEMICOLON
{ {
var lt = (Tokenizer.LocatedToken) $1; var lt = (LocatedToken) $1;
string s = lt.Value; string s = lt.Value;
if (s != "yield"){ if (s != "yield"){
report.Error (1003, lt.Location, "; expected"); report.Error (1003, lt.Location, "; expected");
@ -6045,7 +6040,7 @@ yield_statement
{ {
Error_SyntaxError (yyToken); Error_SyntaxError (yyToken);
var lt = (Tokenizer.LocatedToken) $1; var lt = (LocatedToken) $1;
string s = lt.Value; string s = lt.Value;
if (s != "yield"){ if (s != "yield"){
report.Error (1003, lt.Location, "; expected"); report.Error (1003, lt.Location, "; expected");
@ -6061,7 +6056,7 @@ yield_statement
} }
| identifier_inside_body BREAK SEMICOLON | identifier_inside_body BREAK SEMICOLON
{ {
var lt = (Tokenizer.LocatedToken) $1; var lt = (LocatedToken) $1;
string s = lt.Value; string s = lt.Value;
if (s != "yield"){ if (s != "yield"){
report.Error (1003, lt.Location, "; expected"); report.Error (1003, lt.Location, "; expected");
@ -6069,7 +6064,7 @@ yield_statement
FeatureIsNotAvailable (lt.Location, "iterators"); FeatureIsNotAvailable (lt.Location, "iterators");
} }
current_block.Explicit.RegisterIteratorYield (); current_block.ParametersBlock.TopBlock.IsIterator = true;
$$ = new YieldBreak (lt.Location); $$ = new YieldBreak (lt.Location);
lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3)); lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
} }
@ -6141,7 +6136,7 @@ catch_clause
c.TypeExpression = (FullNamedExpression) $3; c.TypeExpression = (FullNamedExpression) $3;
if ($4 != null) { if ($4 != null) {
var lt = (Tokenizer.LocatedToken) $4; var lt = (LocatedToken) $4;
c.Variable = new LocalVariable (current_block, lt.Value, lt.Location); c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
current_block.AddLocalName (c.Variable); current_block.AddLocalName (c.Variable);
} }
@ -6174,12 +6169,12 @@ catch_clause
c.TypeExpression = (FullNamedExpression) $3; c.TypeExpression = (FullNamedExpression) $3;
if ($4 != null) { if ($4 != null) {
var lt = (Tokenizer.LocatedToken) $4; var lt = (LocatedToken) $4;
c.Variable = new LocalVariable (current_block, lt.Value, lt.Location); c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
} }
if ($4 != null) { if ($4 != null) {
var lt = (Tokenizer.LocatedToken) $4; var lt = (LocatedToken) $4;
c.Variable = new LocalVariable (current_block, lt.Value, lt.Location); c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
} }
@ -6237,7 +6232,7 @@ fixed_statement
start_block (GetLocation ($2)); start_block (GetLocation ($2));
current_block.IsCompilerGenerated = true; current_block.IsCompilerGenerated = true;
var lt = (Tokenizer.LocatedToken) $4; var lt = (LocatedToken) $4;
var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location); var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
current_block.AddLocalName (li); current_block.AddLocalName (li);
current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li); current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li);
@ -6265,7 +6260,7 @@ using_statement
start_block (GetLocation ($2)); start_block (GetLocation ($2));
current_block.IsCompilerGenerated = true; current_block.IsCompilerGenerated = true;
var lt = (Tokenizer.LocatedToken) $4; var lt = (LocatedToken) $4;
var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location); var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
current_block.AddLocalName (li); current_block.AddLocalName (li);
current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li); current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li);
@ -6371,7 +6366,7 @@ first_from_clause
{ {
current_block = new Linq.QueryBlock (current_block, lexer.Location); current_block = new Linq.QueryBlock (current_block, lexer.Location);
var lt = (Tokenizer.LocatedToken) $2; var lt = (LocatedToken) $2;
var rv = new Linq.RangeVariable (lt.Value, lt.Location); var rv = new Linq.RangeVariable (lt.Value, lt.Location);
var start = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1)); var start = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
lbag.AddLocation (start, GetLocation ($3)); lbag.AddLocation (start, GetLocation ($3));
@ -6381,7 +6376,7 @@ first_from_clause
{ {
current_block = new Linq.QueryBlock (current_block, lexer.Location); current_block = new Linq.QueryBlock (current_block, lexer.Location);
var lt = (Tokenizer.LocatedToken) $3; var lt = (LocatedToken) $3;
var rv = new Linq.RangeVariable (lt.Value, lt.Location); var rv = new Linq.RangeVariable (lt.Value, lt.Location);
var start = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) { var start = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
IdentifierType = (FullNamedExpression)$2 IdentifierType = (FullNamedExpression)$2
@ -6396,7 +6391,7 @@ nested_from_clause
{ {
current_block = new Linq.QueryBlock (current_block, lexer.Location); current_block = new Linq.QueryBlock (current_block, lexer.Location);
var lt = (Tokenizer.LocatedToken) $2; var lt = (LocatedToken) $2;
var rv = new Linq.RangeVariable (lt.Value, lt.Location); var rv = new Linq.RangeVariable (lt.Value, lt.Location);
var start = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1)); var start = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
lbag.AddLocation (start, GetLocation ($3)); lbag.AddLocation (start, GetLocation ($3));
@ -6406,7 +6401,7 @@ nested_from_clause
{ {
current_block = new Linq.QueryBlock (current_block, lexer.Location); current_block = new Linq.QueryBlock (current_block, lexer.Location);
var lt = (Tokenizer.LocatedToken) $3; var lt = (LocatedToken) $3;
var rv = new Linq.RangeVariable (lt.Value, lt.Location); var rv = new Linq.RangeVariable (lt.Value, lt.Location);
var start = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) { var start = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
IdentifierType = (FullNamedExpression)$2 IdentifierType = (FullNamedExpression)$2
@ -6423,7 +6418,7 @@ from_clause
} }
expression_or_error expression_or_error
{ {
var lt = (Tokenizer.LocatedToken) $2; var lt = (LocatedToken) $2;
var sn = new Linq.RangeVariable (lt.Value, lt.Location); var sn = new Linq.RangeVariable (lt.Value, lt.Location);
$$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1)); $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
@ -6439,7 +6434,7 @@ from_clause
} }
expression_or_error expression_or_error
{ {
var lt = (Tokenizer.LocatedToken) $3; var lt = (LocatedToken) $3;
var sn = new Linq.RangeVariable (lt.Value, lt.Location); var sn = new Linq.RangeVariable (lt.Value, lt.Location);
$$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) { $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
@ -6571,7 +6566,7 @@ let_clause
} }
expression_or_error expression_or_error
{ {
var lt = (Tokenizer.LocatedToken) $2; var lt = (LocatedToken) $2;
var sn = new Linq.RangeVariable (lt.Value, lt.Location); var sn = new Linq.RangeVariable (lt.Value, lt.Location);
$$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1)); $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
lbag.AddLocation ($$, GetLocation ($3)); lbag.AddLocation ($$, GetLocation ($3));
@ -6630,7 +6625,7 @@ join_clause
var outer_selector = linq_clause_blocks.Pop (); var outer_selector = linq_clause_blocks.Pop ();
var block = linq_clause_blocks.Pop (); var block = linq_clause_blocks.Pop ();
var lt = (Tokenizer.LocatedToken) $2; var lt = (LocatedToken) $2;
var sn = new Linq.RangeVariable (lt.Value, lt.Location); var sn = new Linq.RangeVariable (lt.Value, lt.Location);
Linq.RangeVariable into; Linq.RangeVariable into;
@ -6650,7 +6645,7 @@ join_clause
((Linq.QueryBlock)current_block).AddRangeVariable (sn); ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
lt = (Tokenizer.LocatedToken) $12; lt = (LocatedToken) $12;
into = new Linq.RangeVariable (lt.Value, lt.Location); into = new Linq.RangeVariable (lt.Value, lt.Location);
$$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)); $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1));
@ -6692,7 +6687,7 @@ join_clause
var outer_selector = linq_clause_blocks.Pop (); var outer_selector = linq_clause_blocks.Pop ();
var block = linq_clause_blocks.Pop (); var block = linq_clause_blocks.Pop ();
var lt = (Tokenizer.LocatedToken) $3; var lt = (LocatedToken) $3;
var sn = new Linq.RangeVariable (lt.Value, lt.Location); var sn = new Linq.RangeVariable (lt.Value, lt.Location);
Linq.RangeVariable into; Linq.RangeVariable into;
@ -6714,7 +6709,7 @@ join_clause
((Linq.QueryBlock)current_block).AddRangeVariable (sn); ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
lt = (Tokenizer.LocatedToken) $13; lt = (LocatedToken) $13;
into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO: into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO:
$$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) { $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) {
@ -6840,7 +6835,7 @@ opt_query_continuation
query_body query_body
{ {
var current_block = linq_clause_blocks.Pop (); var current_block = linq_clause_blocks.Pop ();
var lt = (Tokenizer.LocatedToken) $2; var lt = (LocatedToken) $2;
var rv = new Linq.RangeVariable (lt.Value, lt.Location); var rv = new Linq.RangeVariable (lt.Value, lt.Location);
$$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) { $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) {
next = (Linq.AQueryClause)$4 next = (Linq.AQueryClause)$4
@ -6945,7 +6940,7 @@ doc_cref
{ {
module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1; module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$4; module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$4;
var lt = (Tokenizer.LocatedToken) $3; var lt = (LocatedToken) $3;
$$ = new MemberName (lt.Value); $$ = new MemberName (lt.Value);
} }
| doc_type_declaration_name DOT THIS | doc_type_declaration_name DOT THIS
@ -7107,7 +7102,7 @@ object Error_AwaitAsIdentifier (object token)
{ {
if (async_block) { if (async_block) {
report.Error (4003, GetLocation (token), "`await' cannot be used as an identifier within an async method or lambda expression"); report.Error (4003, GetLocation (token), "`await' cannot be used as an identifier within an async method or lambda expression");
return new Tokenizer.LocatedToken ("await", GetLocation (token)); return new LocatedToken ("await", GetLocation (token));
} }
return token; return token;
@ -7301,7 +7296,7 @@ void FeatureIsNotAvailable (Location loc, string feature)
Location GetLocation (object obj) Location GetLocation (object obj)
{ {
var lt = obj as Tokenizer.LocatedToken; var lt = obj as LocatedToken;
if (lt != null) if (lt != null)
return lt.Location; return lt.Location;
@ -7379,7 +7374,7 @@ AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
retval = current_anonymous_method; retval = current_anonymous_method;
async_block = (bool) oob_stack.Pop (); async_block = (bool) oob_stack.Pop ();
current_variable = (BlockVariableDeclaration) oob_stack.Pop (); current_variable = (BlockVariable) oob_stack.Pop ();
current_local_parameters = (ParametersCompiled) oob_stack.Pop (); current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop (); current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
@ -7488,7 +7483,7 @@ string GetSymbolName (int token)
case Token.LITERAL: case Token.LITERAL:
return ((Constant)lexer.Value).GetValue ().ToString (); return ((Constant)lexer.Value).GetValue ().ToString ();
case Token.IDENTIFIER: case Token.IDENTIFIER:
return ((Tokenizer.LocatedToken)lexer.Value).Value; return ((LocatedToken)lexer.Value).Value;
case Token.BOOL: case Token.BOOL:
return "bool"; return "bool";

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

@ -20,6 +20,44 @@ using System.Collections;
namespace Mono.CSharp namespace Mono.CSharp
{ {
//
// This class has to be used by parser only, it reuses token
// details once a file is parsed
//
public class LocatedToken
{
public int row, column;
public string value;
public SourceFile file;
public LocatedToken ()
{
}
public LocatedToken (string value, Location loc)
{
this.value = value;
file = loc.SourceFile;
row = loc.Row;
column = loc.Column;
}
public override string ToString ()
{
return string.Format ("Token '{0}' at {1},{2}", Value, row, column);
}
public Location Location
{
get { return new Location (file, row, column); }
}
public string Value
{
get { return value; }
}
}
/// <summary> /// <summary>
/// Tokenizer for C# source code. /// Tokenizer for C# source code.
/// </summary> /// </summary>
@ -66,42 +104,6 @@ namespace Mono.CSharp
} }
} }
//
// This class has to be used by parser only, it reuses token
// details after each file parse completion
//
public class LocatedToken
{
public int row, column;
public string value;
public SourceFile file;
public LocatedToken ()
{
}
public LocatedToken (string value, Location loc)
{
this.value = value;
file = loc.SourceFile;
row = loc.Row;
column = loc.Column;
}
public override string ToString ()
{
return string.Format ("Token '{0}' at {1},{2}", Value, row, column);
}
public Location Location {
get { return new Location (file, row, column); }
}
public string Value {
get { return value; }
}
}
public class LocatedTokenBuffer public class LocatedTokenBuffer
{ {
readonly LocatedToken[] buffer; readonly LocatedToken[] buffer;

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

@ -53,12 +53,6 @@ namespace Mono.CSharp {
: this (name, Location.Null) : this (name, Location.Null)
{ } { }
#if FULL_AST
public Location DotLocation {
get;
set;
}
#endif
public MemberName (string name, Location loc) public MemberName (string name, Location loc)
: this (null, name, loc) : this (null, name, loc)
{ } { }
@ -1281,6 +1275,11 @@ namespace Mono.CSharp {
void SetIsUsed (); void SetIsUsed ();
} }
public interface IMethodDefinition : IMemberDefinition
{
MethodBase Metadata { get; }
}
public interface IParametersMember : IInterfaceMemberSpec public interface IParametersMember : IInterfaceMemberSpec
{ {
AParametersCollection Parameters { get; } AParametersCollection Parameters { get; }

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

@ -153,7 +153,7 @@ namespace Mono.CSharp {
Report.SymbolRelatedToPreviousError (partype); Report.SymbolRelatedToPreviousError (partype);
Report.Error (59, Location, Report.Error (59, Location,
"Inconsistent accessibility: parameter type `{0}' is less accessible than delegate `{1}'", "Inconsistent accessibility: parameter type `{0}' is less accessible than delegate `{1}'",
TypeManager.CSharpName (partype), GetSignatureForError ()); partype.GetSignatureForError (), GetSignatureForError ());
} }
} }
@ -169,7 +169,7 @@ namespace Mono.CSharp {
Report.SymbolRelatedToPreviousError (ret_type); Report.SymbolRelatedToPreviousError (ret_type);
Report.Error (58, Location, Report.Error (58, Location,
"Inconsistent accessibility: return type `" + "Inconsistent accessibility: return type `" +
TypeManager.CSharpName (ret_type) + "' is less " + ret_type.GetSignatureForError () + "' is less " +
"accessible than delegate `" + GetSignatureForError () + "'"); "accessible than delegate `" + GetSignatureForError () + "'");
return false; return false;
} }
@ -297,6 +297,12 @@ namespace Mono.CSharp {
if (!Parameters.IsEmpty) { if (!Parameters.IsEmpty) {
parameters.ResolveDefaultValues (this); parameters.ResolveDefaultValues (this);
} }
InvokeBuilder.PrepareEmit ();
if (BeginInvokeBuilder != null) {
BeginInvokeBuilder.PrepareEmit ();
EndInvokeBuilder.PrepareEmit ();
}
} }
public override void Emit () public override void Emit ()
@ -522,7 +528,7 @@ namespace Mono.CSharp {
TypeSpec e_type = emg.ExtensionExpression.Type; TypeSpec e_type = emg.ExtensionExpression.Type;
if (TypeSpec.IsValueType (e_type)) { if (TypeSpec.IsValueType (e_type)) {
ec.Report.Error (1113, loc, "Extension method `{0}' of value type `{1}' cannot be used to create delegates", ec.Report.Error (1113, loc, "Extension method `{0}' of value type `{1}' cannot be used to create delegates",
delegate_method.GetSignatureForError (), TypeManager.CSharpName (e_type)); delegate_method.GetSignatureForError (), e_type.GetSignatureForError ());
} }
} }
@ -586,8 +592,8 @@ namespace Mono.CSharp {
ec.Report.SymbolRelatedToPreviousError (method); ec.Report.SymbolRelatedToPreviousError (method);
if (ec.Module.Compiler.Settings.Version == LanguageVersion.ISO_1) { if (ec.Module.Compiler.Settings.Version == LanguageVersion.ISO_1) {
ec.Report.Error (410, loc, "A method or delegate `{0} {1}' parameters and return type must be same as delegate `{2} {3}' parameters and return type", ec.Report.Error (410, loc, "A method or delegate `{0} {1}' parameters and return type must be same as delegate `{2} {3}' parameters and return type",
TypeManager.CSharpName (method.ReturnType), member_name, method.ReturnType.GetSignatureForError (), member_name,
TypeManager.CSharpName (invoke_method.ReturnType), Delegate.FullDelegateDesc (invoke_method)); invoke_method.ReturnType.GetSignatureForError (), Delegate.FullDelegateDesc (invoke_method));
return; return;
} }
@ -599,7 +605,7 @@ namespace Mono.CSharp {
ec.Report.Error (407, loc, "A method or delegate `{0} {1}' return type does not match delegate `{2} {3}' return type", ec.Report.Error (407, loc, "A method or delegate `{0} {1}' return type does not match delegate `{2} {3}' return type",
return_type.GetSignatureForError (), member_name, return_type.GetSignatureForError (), member_name,
TypeManager.CSharpName (invoke_method.ReturnType), Delegate.FullDelegateDesc (invoke_method)); invoke_method.ReturnType.GetSignatureForError (), Delegate.FullDelegateDesc (invoke_method));
} }
public static bool ImplicitStandardConversionExists (ResolveContext ec, MethodGroupExpr mg, TypeSpec target_type) public static bool ImplicitStandardConversionExists (ResolveContext ec, MethodGroupExpr mg, TypeSpec target_type)

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

@ -80,7 +80,7 @@ namespace Mono.CSharp
var session = new ParserSession () { var session = new ParserSession () {
UseJayGlobalArrays = true, UseJayGlobalArrays = true,
LocatedTokens = new Tokenizer.LocatedToken[15000] LocatedTokens = new LocatedToken[15000]
}; };
for (int i = 0; i < sources.Count; ++i) { for (int i = 0; i < sources.Count; ++i) {

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

@ -447,6 +447,7 @@ namespace Mono.CSharp
d.CreateContainer (); d.CreateContainer ();
d.DefineContainer (); d.DefineContainer ();
d.Define (); d.Define ();
d.PrepareEmit ();
site.AddTypeContainer (d); site.AddTypeContainer (d);
del_type = new TypeExpression (d.CurrentType, loc); del_type = new TypeExpression (d.CurrentType, loc);

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

@ -251,7 +251,7 @@ namespace Mono.CSharp {
public void Error_ConstantCanBeInitializedWithNullOnly (ResolveContext rc, TypeSpec type, Location loc, string name) public void Error_ConstantCanBeInitializedWithNullOnly (ResolveContext rc, TypeSpec type, Location loc, string name)
{ {
rc.Report.Error (134, loc, "A constant `{0}' of reference type `{1}' can only be initialized with null", rc.Report.Error (134, loc, "A constant `{0}' of reference type `{1}' can only be initialized with null",
name, TypeManager.CSharpName (type)); name, type.GetSignatureForError ());
} }
protected virtual void Error_InvalidExpressionStatement (Report report, Location loc) protected virtual void Error_InvalidExpressionStatement (Report report, Location loc)
@ -282,7 +282,10 @@ namespace Mono.CSharp {
protected void Error_ValueCannotBeConvertedCore (ResolveContext ec, Location loc, TypeSpec target, bool expl) protected void Error_ValueCannotBeConvertedCore (ResolveContext ec, Location loc, TypeSpec target, bool expl)
{ {
// The error was already reported as CS1660 // The error was already reported as CS1660
if (type == InternalType.AnonymousMethod || type == InternalType.ErrorType) if (type == InternalType.AnonymousMethod)
return;
if (type == InternalType.ErrorType || target == InternalType.ErrorType)
return; return;
string from_type = type.GetSignatureForError (); string from_type = type.GetSignatureForError ();
@ -351,13 +354,15 @@ namespace Mono.CSharp {
{ {
ec.Report.SymbolRelatedToPreviousError (type); ec.Report.SymbolRelatedToPreviousError (type);
ec.Report.Error (117, loc, "`{0}' does not contain a definition for `{1}'", ec.Report.Error (117, loc, "`{0}' does not contain a definition for `{1}'",
TypeManager.CSharpName (type), name); type.GetSignatureForError (), name);
} }
public virtual void Error_ValueAssignment (ResolveContext rc, Expression rhs) public virtual void Error_ValueAssignment (ResolveContext rc, Expression rhs)
{ {
if (rhs == EmptyExpression.LValueMemberAccess || rhs == EmptyExpression.LValueMemberOutAccess) { if (rhs == EmptyExpression.LValueMemberAccess || rhs == EmptyExpression.LValueMemberOutAccess) {
// Already reported as CS1612 // Already reported as CS1612
} else if (rhs == EmptyExpression.OutAccess) {
rc.Report.Error (1510, loc, "A ref or out argument must be an assignable variable");
} else { } else {
rc.Report.Error (131, loc, "The left-hand side of an assignment must be a variable, a property or an indexer"); rc.Report.Error (131, loc, "The left-hand side of an assignment must be a variable, a property or an indexer");
} }
@ -492,10 +497,7 @@ namespace Mono.CSharp {
if (e == null) { if (e == null) {
if (errors == ec.Report.Errors) { if (errors == ec.Report.Errors) {
if (out_access) Error_ValueAssignment (ec, right_side);
ec.Report.Error (1510, loc, "A ref or out argument must be an assignable variable");
else
Error_ValueAssignment (ec, right_side);
} }
return null; return null;
} }
@ -1475,7 +1477,7 @@ namespace Mono.CSharp {
public override string GetSignatureForError() public override string GetSignatureForError()
{ {
return TypeManager.CSharpName (Type); return Type.GetSignatureForError ();
} }
public override object GetValue () public override object GetValue ()
@ -1534,7 +1536,7 @@ namespace Mono.CSharp {
} }
} }
public override Constant ConvertExplicitly(bool in_checked_context, TypeSpec target_type) public override Constant ConvertExplicitly (bool in_checked_context, TypeSpec target_type)
{ {
if (Child.Type == target_type) if (Child.Type == target_type)
return Child; return Child;
@ -2418,15 +2420,15 @@ namespace Mono.CSharp {
} }
} }
public override FullNamedExpression ResolveAsTypeOrNamespace (IMemberContext ec) public override FullNamedExpression ResolveAsTypeOrNamespace (IMemberContext mc)
{ {
FullNamedExpression fne = ec.LookupNamespaceOrType (Name, Arity, LookupMode.Normal, loc); FullNamedExpression fne = mc.LookupNamespaceOrType (Name, Arity, LookupMode.Normal, loc);
if (fne != null) { if (fne != null) {
if (fne.Type != null && Arity > 0) { if (fne.Type != null && Arity > 0) {
if (HasTypeArguments) { if (HasTypeArguments) {
GenericTypeExpr ct = new GenericTypeExpr (fne.Type, targs, loc); GenericTypeExpr ct = new GenericTypeExpr (fne.Type, targs, loc);
if (ct.ResolveAsType (ec) == null) if (ct.ResolveAsType (mc) == null)
return null; return null;
return ct; return ct;
@ -2442,21 +2444,21 @@ namespace Mono.CSharp {
return fne; return fne;
} }
if (Arity == 0 && Name == "dynamic" && ec.Module.Compiler.Settings.Version > LanguageVersion.V_3) { if (Arity == 0 && Name == "dynamic" && mc.Module.Compiler.Settings.Version > LanguageVersion.V_3) {
if (!ec.Module.PredefinedAttributes.Dynamic.IsDefined) { if (!mc.Module.PredefinedAttributes.Dynamic.IsDefined) {
ec.Module.Compiler.Report.Error (1980, Location, mc.Module.Compiler.Report.Error (1980, Location,
"Dynamic keyword requires `{0}' to be defined. Are you missing System.Core.dll assembly reference?", "Dynamic keyword requires `{0}' to be defined. Are you missing System.Core.dll assembly reference?",
ec.Module.PredefinedAttributes.Dynamic.GetSignatureForError ()); mc.Module.PredefinedAttributes.Dynamic.GetSignatureForError ());
} }
fne = new DynamicTypeExpr (loc); fne = new DynamicTypeExpr (loc);
fne.ResolveAsType (ec); fne.ResolveAsType (mc);
} }
if (fne != null) if (fne != null)
return fne; return fne;
Error_TypeOrNamespaceNotFound (ec); Error_TypeOrNamespaceNotFound (mc);
return null; return null;
} }
@ -3297,8 +3299,12 @@ namespace Mono.CSharp {
if (ExtensionExpression == null) if (ExtensionExpression == null)
return null; return null;
var cand = candidates;
arguments.Insert (0, new Argument (ExtensionExpression, Argument.AType.ExtensionType)); arguments.Insert (0, new Argument (ExtensionExpression, Argument.AType.ExtensionType));
var res = base.OverloadResolve (ec, ref arguments, ehandler ?? this, restr); var res = base.OverloadResolve (ec, ref arguments, ehandler ?? this, restr);
// Restore candidates in case we are running in probing mode
candidates = cand;
// Store resolved argument and restore original arguments // Store resolved argument and restore original arguments
if (res == null) { if (res == null) {
@ -3508,7 +3514,7 @@ namespace Mono.CSharp {
public override void Error_ValueCannotBeConverted (ResolveContext ec, TypeSpec target, bool expl) public override void Error_ValueCannotBeConverted (ResolveContext ec, TypeSpec target, bool expl)
{ {
ec.Report.Error (428, loc, "Cannot convert method group `{0}' to non-delegate type `{1}'. Consider using parentheses to invoke the method", ec.Report.Error (428, loc, "Cannot convert method group `{0}' to non-delegate type `{1}'. Consider using parentheses to invoke the method",
Name, TypeManager.CSharpName (target)); Name, target.GetSignatureForError ());
} }
public static bool IsExtensionMethodArgument (Expression expr) public static bool IsExtensionMethodArgument (Expression expr)
@ -5050,14 +5056,14 @@ namespace Mono.CSharp {
string index = (idx + 1).ToString (); string index = (idx + 1).ToString ();
if (((mod & Parameter.Modifier.RefOutMask) ^ (a.Modifier & Parameter.Modifier.RefOutMask)) != 0) { if (((mod & Parameter.Modifier.RefOutMask) ^ (a.Modifier & Parameter.Modifier.RefOutMask)) != 0) {
if ((mod & Parameter.Modifier.RefOutMask) == 0) if ((mod & Parameter.Modifier.RefOutMask) == 0)
ec.Report.Error (1615, loc, "Argument `#{0}' does not require `{1}' modifier. Consider removing `{1}' modifier", ec.Report.Error (1615, a.Expr.Location, "Argument `#{0}' does not require `{1}' modifier. Consider removing `{1}' modifier",
index, Parameter.GetModifierSignature (a.Modifier)); index, Parameter.GetModifierSignature (a.Modifier));
else else
ec.Report.Error (1620, loc, "Argument `#{0}' is missing `{1}' modifier", ec.Report.Error (1620, a.Expr.Location, "Argument `#{0}' is missing `{1}' modifier",
index, Parameter.GetModifierSignature (mod)); index, Parameter.GetModifierSignature (mod));
} else { } else {
string p1 = a.GetSignatureForError (); string p1 = a.GetSignatureForError ();
string p2 = TypeManager.CSharpName (paramType); string p2 = paramType.GetSignatureForError ();
if (p1 == p2) { if (p1 == p2) {
p1 = a.Type.GetSignatureForErrorIncludingAssemblyName (); p1 = a.Type.GetSignatureForErrorIncludingAssemblyName ();

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

@ -269,7 +269,7 @@ namespace Mono.CSharp {
case BuiltinTypeSpec.Type.ULong: case BuiltinTypeSpec.Type.ULong:
case BuiltinTypeSpec.Type.UShort: case BuiltinTypeSpec.Type.UShort:
Report.Warning (3009, 1, Location, "`{0}': base type `{1}' is not CLS-compliant", Report.Warning (3009, 1, Location, "`{0}': base type `{1}' is not CLS-compliant",
GetSignatureForError (), TypeManager.CSharpName (UnderlyingType)); GetSignatureForError (), UnderlyingType.GetSignatureForError ());
break; break;
} }

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

@ -652,7 +652,7 @@ namespace Mono.CSharp
new TypeExpression (base_class_imported, host.Location) new TypeExpression (base_class_imported, host.Location)
}; };
host.AddBasesForPart (baseclass_list); host.SetBaseTypes (baseclass_list);
host.CreateContainer (); host.CreateContainer ();
host.DefineContainer (); host.DefineContainer ();
@ -679,6 +679,7 @@ namespace Mono.CSharp
} }
if (host != null){ if (host != null){
host.PrepareEmit ();
host.EmitContainer (); host.EmitContainer ();
} }

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

@ -1437,10 +1437,10 @@ namespace Mono.CSharp
{ {
if (result) if (result)
ec.Report.Warning (183, 1, loc, "The given expression is always of the provided (`{0}') type", ec.Report.Warning (183, 1, loc, "The given expression is always of the provided (`{0}') type",
TypeManager.CSharpName (probe_type_expr)); probe_type_expr.GetSignatureForError ());
else else
ec.Report.Warning (184, 1, loc, "The given expression is never of the provided (`{0}') type", ec.Report.Warning (184, 1, loc, "The given expression is never of the provided (`{0}') type",
TypeManager.CSharpName (probe_type_expr)); probe_type_expr.GetSignatureForError ());
return ReducedExpression.Create (new BoolConstant (ec.BuiltinTypes, result, loc), this); return ReducedExpression.Create (new BoolConstant (ec.BuiltinTypes, result, loc), this);
} }
@ -1630,7 +1630,7 @@ namespace Mono.CSharp
} else { } else {
ec.Report.Error (77, loc, ec.Report.Error (77, loc,
"The `as' operator cannot be used with a non-nullable value type `{0}'", "The `as' operator cannot be used with a non-nullable value type `{0}'",
TypeManager.CSharpName (type)); type.GetSignatureForError ());
} }
return null; return null;
} }
@ -1663,7 +1663,7 @@ namespace Mono.CSharp
} }
ec.Report.Error (39, loc, "Cannot convert type `{0}' to `{1}' via a built-in conversion", ec.Report.Error (39, loc, "Cannot convert type `{0}' to `{1}' via a built-in conversion",
TypeManager.CSharpName (etype), TypeManager.CSharpName (type)); etype.GetSignatureForError (), type.GetSignatureForError ());
return null; return null;
} }
@ -1702,7 +1702,7 @@ namespace Mono.CSharp
return null; return null;
if (type.IsStatic) { if (type.IsStatic) {
ec.Report.Error (716, loc, "Cannot convert to static type `{0}'", TypeManager.CSharpName (type)); ec.Report.Error (716, loc, "Cannot convert to static type `{0}'", type.GetSignatureForError ());
return null; return null;
} }
@ -2255,6 +2255,12 @@ namespace Mono.CSharp
} }
} }
public override Location StartLocation {
get {
return left.StartLocation;
}
}
#endregion #endregion
/// <summary> /// <summary>
@ -2340,8 +2346,8 @@ namespace Mono.CSharp
return; return;
string l, r; string l, r;
l = TypeManager.CSharpName (left.Type); l = left.Type.GetSignatureForError ();
r = TypeManager.CSharpName (right.Type); r = right.Type.GetSignatureForError ();
ec.Report.Error (19, loc, "Operator `{0}' cannot be applied to operands of type `{1}' and `{2}'", ec.Report.Error (19, loc, "Operator `{0}' cannot be applied to operands of type `{1}' and `{2}'",
oper, l, r); oper, l, r);
@ -2716,9 +2722,10 @@ namespace Mono.CSharp
// FIXME: consider constants // FIXME: consider constants
var ltype = lcast != null ? lcast.UnderlyingType : rcast.UnderlyingType;
ec.Report.Warning (675, 3, loc, ec.Report.Warning (675, 3, loc,
"The operator `|' used on the sign-extended type `{0}'. Consider casting to a smaller unsigned type first", "The operator `|' used on the sign-extended type `{0}'. Consider casting to a smaller unsigned type first",
TypeManager.CSharpName (lcast != null ? lcast.UnderlyingType : rcast.UnderlyingType)); ltype.GetSignatureForError ());
} }
public static PredefinedOperator[] CreatePointerOperatorsTable (BuiltinTypes types) public static PredefinedOperator[] CreatePointerOperatorsTable (BuiltinTypes types)
@ -2931,7 +2938,7 @@ namespace Mono.CSharp
// FIXME: resolve right expression as unreachable // FIXME: resolve right expression as unreachable
// right.Resolve (ec); // right.Resolve (ec);
ec.Report.Warning (429, 4, loc, "Unreachable expression code detected"); ec.Report.Warning (429, 4, right.StartLocation, "Unreachable expression code detected");
return left; return left;
} }
@ -3557,7 +3564,7 @@ namespace Mono.CSharp
if (best_operator == null) { if (best_operator == null) {
ec.Report.Error (34, loc, "Operator `{0}' is ambiguous on operands of type `{1}' and `{2}'", ec.Report.Error (34, loc, "Operator `{0}' is ambiguous on operands of type `{1}' and `{2}'",
OperName (oper), TypeManager.CSharpName (l), TypeManager.CSharpName (r)); OperName (oper), l.GetSignatureForError (), r.GetSignatureForError ());
best_operator = po; best_operator = po;
break; break;
@ -3713,7 +3720,7 @@ namespace Mono.CSharp
} catch (OverflowException) { } catch (OverflowException) {
ec.Report.Warning (652, 2, loc, ec.Report.Warning (652, 2, loc,
"A comparison between a constant and a variable is useless. The constant is out of the range of the variable type `{0}'", "A comparison between a constant and a variable is useless. The constant is out of the range of the variable type `{0}'",
TypeManager.CSharpName (type)); type.GetSignatureForError ());
} }
} }
} }
@ -4273,7 +4280,7 @@ namespace Mono.CSharp
if (op_true == null || op_false == null) { if (op_true == null || op_false == null) {
ec.Report.Error (218, loc, ec.Report.Error (218, loc,
"The type `{0}' must have operator `true' and operator `false' defined when `{1}' is used as a short circuit operator", "The type `{0}' must have operator `true' and operator `false' defined when `{1}' is used as a short circuit operator",
TypeManager.CSharpName (type), oper.GetSignatureForError ()); type.GetSignatureForError (), oper.GetSignatureForError ());
return null; return null;
} }
@ -4684,7 +4691,7 @@ namespace Mono.CSharp
} else { } else {
ec.Report.Error (173, true_expr.Location, ec.Report.Error (173, true_expr.Location,
"Type of conditional expression cannot be determined because there is no implicit conversion between `{0}' and `{1}'", "Type of conditional expression cannot be determined because there is no implicit conversion between `{0}' and `{1}'",
TypeManager.CSharpName (true_type), TypeManager.CSharpName (false_type)); true_type.GetSignatureForError (), false_type.GetSignatureForError ());
return null; return null;
} }
} }
@ -5194,6 +5201,9 @@ namespace Mono.CSharp
void SetAssigned (ResolveContext ec) void SetAssigned (ResolveContext ec)
{ {
if (Parameter.HoistedVariant != null)
Parameter.HoistedVariant.IsAssigned = true;
if (HasOutModifier && ec.DoFlowAnalysis) if (HasOutModifier && ec.DoFlowAnalysis)
ec.CurrentBranching.SetAssigned (VariableInfo); ec.CurrentBranching.SetAssigned (VariableInfo);
} }
@ -5777,7 +5787,7 @@ namespace Mono.CSharp
if (type.IsPointer) { if (type.IsPointer) {
ec.Report.Error (1919, loc, "Unsafe type `{0}' cannot be used in an object creation expression", ec.Report.Error (1919, loc, "Unsafe type `{0}' cannot be used in an object creation expression",
TypeManager.CSharpName (type)); type.GetSignatureForError ());
return null; return null;
} }
@ -5800,13 +5810,13 @@ namespace Mono.CSharp
if ((tparam.SpecialConstraint & (SpecialConstraint.Struct | SpecialConstraint.Constructor)) == 0 && !TypeSpec.IsValueType (tparam)) { if ((tparam.SpecialConstraint & (SpecialConstraint.Struct | SpecialConstraint.Constructor)) == 0 && !TypeSpec.IsValueType (tparam)) {
ec.Report.Error (304, loc, ec.Report.Error (304, loc,
"Cannot create an instance of the variable type `{0}' because it does not have the new() constraint", "Cannot create an instance of the variable type `{0}' because it does not have the new() constraint",
TypeManager.CSharpName (type)); type.GetSignatureForError ());
} }
if ((arguments != null) && (arguments.Count != 0)) { if ((arguments != null) && (arguments.Count != 0)) {
ec.Report.Error (417, loc, ec.Report.Error (417, loc,
"`{0}': cannot provide arguments when creating an instance of a variable type", "`{0}': cannot provide arguments when creating an instance of a variable type",
TypeManager.CSharpName (type)); type.GetSignatureForError ());
} }
return this; return this;
@ -5814,7 +5824,7 @@ namespace Mono.CSharp
if (type.IsStatic) { if (type.IsStatic) {
ec.Report.SymbolRelatedToPreviousError (type); ec.Report.SymbolRelatedToPreviousError (type);
ec.Report.Error (712, loc, "Cannot create an instance of the static class `{0}'", TypeManager.CSharpName (type)); ec.Report.Error (712, loc, "Cannot create an instance of the static class `{0}'", type.GetSignatureForError ());
return null; return null;
} }
@ -5826,7 +5836,7 @@ namespace Mono.CSharp
} }
ec.Report.SymbolRelatedToPreviousError (type); ec.Report.SymbolRelatedToPreviousError (type);
ec.Report.Error (144, loc, "Cannot create an instance of the abstract class or interface `{0}'", TypeManager.CSharpName (type)); ec.Report.Error (144, loc, "Cannot create an instance of the abstract class or interface `{0}'", type.GetSignatureForError ());
return null; return null;
} }
@ -6048,7 +6058,7 @@ namespace Mono.CSharp
public class ArrayInitializer : Expression public class ArrayInitializer : Expression
{ {
List<Expression> elements; List<Expression> elements;
BlockVariableDeclaration variable; BlockVariable variable;
public ArrayInitializer (List<Expression> init, Location loc) public ArrayInitializer (List<Expression> init, Location loc)
{ {
@ -6084,7 +6094,7 @@ namespace Mono.CSharp
} }
} }
public BlockVariableDeclaration VariableDeclaration { public BlockVariable VariableDeclaration {
get { get {
return variable; return variable;
} }
@ -7823,7 +7833,7 @@ namespace Mono.CSharp
if (!ec.IsUnsafe) { if (!ec.IsUnsafe) {
ec.Report.Error (233, loc, ec.Report.Error (233, loc,
"`{0}' does not have a predefined size, therefore sizeof can only be used in an unsafe context (consider using System.Runtime.InteropServices.Marshal.SizeOf)", "`{0}' does not have a predefined size, therefore sizeof can only be used in an unsafe context (consider using System.Runtime.InteropServices.Marshal.SizeOf)",
TypeManager.CSharpName (type_queried)); type_queried.GetSignatureForError ());
} }
type = ec.BuiltinTypes.Int; type = ec.BuiltinTypes.Int;
@ -7941,13 +7951,6 @@ namespace Mono.CSharp
public class MemberAccess : ATypeNameExpression public class MemberAccess : ATypeNameExpression
{ {
protected Expression expr; protected Expression expr;
#if FULL_AST
public Location DotLocation {
get;
set;
}
#endif
public MemberAccess (Expression expr, string id) public MemberAccess (Expression expr, string id)
: base (id, expr.Location) : base (id, expr.Location)
@ -10139,8 +10142,8 @@ namespace Mono.CSharp
ec.Report.Error (1922, loc, "A field or property `{0}' cannot be initialized with a collection " + ec.Report.Error (1922, loc, "A field or property `{0}' cannot be initialized with a collection " +
"object initializer because type `{1}' does not implement `{2}' interface", "object initializer because type `{1}' does not implement `{2}' interface",
ec.CurrentInitializerVariable.GetSignatureForError (), ec.CurrentInitializerVariable.GetSignatureForError (),
TypeManager.CSharpName (ec.CurrentInitializerVariable.Type), ec.CurrentInitializerVariable.Type.GetSignatureForError (),
TypeManager.CSharpName (ec.BuiltinTypes.IEnumerable)); ec.BuiltinTypes.IEnumerable.GetSignatureForError ());
return null; return null;
} }
is_collection_initialization = true; is_collection_initialization = true;
@ -10174,7 +10177,7 @@ namespace Mono.CSharp
if (is_collection_initialization) { if (is_collection_initialization) {
if (TypeManager.HasElementType (type)) { if (TypeManager.HasElementType (type)) {
ec.Report.Error (1925, loc, "Cannot initialize object of type `{0}' with a collection initializer", ec.Report.Error (1925, loc, "Cannot initialize object of type `{0}' with a collection initializer",
TypeManager.CSharpName (type)); type.GetSignatureForError ());
} }
} }

15
ICSharpCode.NRefactory.CSharp/Parser/mcs/field.cs

@ -42,6 +42,11 @@ namespace Mono.CSharp
public Expression Initializer { get; private set; } public Expression Initializer { get; private set; }
#endregion #endregion
public virtual FullNamedExpression GetFieldTypeExpression (FieldBase field)
{
return new TypeExpression (field.MemberType, Name.Location);
}
} }
// //
@ -407,9 +412,8 @@ namespace Mono.CSharp
"`{0}': Fixed size buffers type must be one of the following: bool, byte, short, int, long, char, sbyte, ushort, uint, ulong, float or double", "`{0}': Fixed size buffers type must be one of the following: bool, byte, short, int, long, char, sbyte, ushort, uint, ulong, float or double",
GetSignatureForError ()); GetSignatureForError ());
} else if (declarators != null) { } else if (declarators != null) {
var t = new TypeExpression (MemberType, TypeExpression.Location);
foreach (var d in declarators) { foreach (var d in declarators) {
var f = new FixedField (Parent, t, ModFlags, new MemberName (d.Name.Value, d.Name.Location), OptAttributes); var f = new FixedField (Parent, d.GetFieldTypeExpression (this), ModFlags, new MemberName (d.Name.Value, d.Name.Location), OptAttributes);
f.initializer = d.Initializer; f.initializer = d.Initializer;
((ConstInitializer) f.initializer).Name = d.Name.Value; ((ConstInitializer) f.initializer).Name = d.Name.Value;
f.Define (); f.Define ();
@ -486,7 +490,7 @@ namespace Mono.CSharp
if (buffer_size > int.MaxValue / type_size) { if (buffer_size > int.MaxValue / type_size) {
Report.Error (1664, Location, "Fixed size buffer `{0}' of length `{1}' and type `{2}' exceeded 2^31 limit", Report.Error (1664, Location, "Fixed size buffer `{0}' of length `{1}' and type `{2}' exceeded 2^31 limit",
GetSignatureForError (), buffer_size.ToString (), TypeManager.CSharpName (MemberType)); GetSignatureForError (), buffer_size.ToString (), MemberType.GetSignatureForError ());
return; return;
} }
@ -645,8 +649,7 @@ namespace Mono.CSharp
if (declarators != null) { if (declarators != null) {
foreach (var d in declarators) { foreach (var d in declarators) {
var t = new TypeExpression (MemberType, d.Name.Location); var f = new Field (Parent, d.GetFieldTypeExpression (this), ModFlags, new MemberName (d.Name.Value, d.Name.Location), OptAttributes);
var f = new Field (Parent, t, ModFlags, new MemberName (d.Name.Value, d.Name.Location), OptAttributes);
if (d.Initializer != null) if (d.Initializer != null)
f.initializer = d.Initializer; f.initializer = d.Initializer;
@ -668,7 +671,7 @@ namespace Mono.CSharp
if ((ModFlags & Modifiers.VOLATILE) != 0) { if ((ModFlags & Modifiers.VOLATILE) != 0) {
if (!CanBeVolatile ()) { if (!CanBeVolatile ()) {
Report.Error (677, Location, "`{0}': A volatile field cannot be of the type `{1}'", Report.Error (677, Location, "`{0}': A volatile field cannot be of the type `{1}'",
GetSignatureForError (), TypeManager.CSharpName (MemberType)); GetSignatureForError (), MemberType.GetSignatureForError ());
} }
if ((ModFlags & Modifiers.READONLY) != 0) { if ((ModFlags & Modifiers.READONLY) != 0) {

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

@ -318,7 +318,7 @@ namespace Mono.CSharp {
if (type.IsSealed || !type.IsClass) { if (type.IsSealed || !type.IsClass) {
context.Module.Compiler.Report.Error (701, loc, context.Module.Compiler.Report.Error (701, loc,
"`{0}' is not a valid constraint. A constraint must be an interface, a non-sealed class or a type parameter", "`{0}' is not a valid constraint. A constraint must be an interface, a non-sealed class or a type parameter",
TypeManager.CSharpName (type)); type.GetSignatureForError ());
continue; continue;
} }
@ -495,7 +495,7 @@ namespace Mono.CSharp {
// //
// If partial type parameters constraints are not null and we don't // If partial type parameters constraints are not null and we don't
// already have constraints they become our constraints. If we already // already have constraints they become our constraints. If we already
// have constraints, we must check that they're the same. // have constraints, we must check that they're same.
// //
public bool AddPartialConstraints (TypeDefinition part, TypeParameter tp) public bool AddPartialConstraints (TypeDefinition part, TypeParameter tp)
{ {
@ -551,15 +551,19 @@ namespace Mono.CSharp {
// with SRE (by calling `DefineGenericParameters()' on the TypeBuilder / // with SRE (by calling `DefineGenericParameters()' on the TypeBuilder /
// MethodBuilder). // MethodBuilder).
// //
public void Define (GenericTypeParameterBuilder type, TypeSpec declaringType, TypeContainer parent) public void Create (TypeSpec declaringType, TypeContainer parent)
{ {
if (builder != null) if (builder != null)
throw new InternalErrorException (); throw new InternalErrorException ();
// Needed to get compiler reference // Needed to get compiler reference
this.Parent = parent; this.Parent = parent;
this.builder = type;
spec.DeclaringType = declaringType; spec.DeclaringType = declaringType;
}
public void Define (GenericTypeParameterBuilder type)
{
this.builder = type;
spec.SetMetaInfo (type); spec.SetMetaInfo (type);
} }
@ -1382,6 +1386,9 @@ namespace Mono.CSharp {
return ac; return ac;
} }
if (type.Kind == MemberKind.MissingType)
return type;
// //
// When inflating a nested type, inflate its parent first // When inflating a nested type, inflate its parent first
// in case it's using same type parameters (was inflated within the type) // in case it's using same type parameters (was inflated within the type)
@ -2185,13 +2192,13 @@ namespace Mono.CSharp {
names.AddRange (tparams.names); names.AddRange (tparams.names);
} }
public void Define (GenericTypeParameterBuilder[] buiders, TypeSpec declaringType, int parentOffset, TypeContainer parent) public void Create (TypeSpec declaringType, int parentOffset, TypeContainer parent)
{ {
types = new TypeParameterSpec[Count]; types = new TypeParameterSpec[Count];
for (int i = 0; i < types.Length; ++i) { for (int i = 0; i < types.Length; ++i) {
var tp = names[i]; var tp = names[i];
tp.Define (buiders[i + parentOffset], declaringType, parent); tp.Create (declaringType, parent);
types[i] = tp.Type; types[i] = tp.Type;
types[i].DeclaredPosition = i + parentOffset; types[i].DeclaredPosition = i + parentOffset;
@ -2201,6 +2208,14 @@ namespace Mono.CSharp {
} }
} }
public void Define (GenericTypeParameterBuilder[] builders)
{
for (int i = 0; i < types.Length; ++i) {
var tp = names[i];
tp.Define (builders [types [i].DeclaredPosition]);
}
}
public TypeParameter this[int index] { public TypeParameter this[int index] {
get { get {
return names [index]; return names [index];
@ -2240,6 +2255,44 @@ namespace Mono.CSharp {
return sb.ToString (); return sb.ToString ();
} }
public void CheckPartialConstraints (Method part)
{
var partTypeParameters = part.CurrentTypeParameters;
for (int i = 0; i < Count; i++) {
var tp_a = names[i];
var tp_b = partTypeParameters [i];
if (tp_a.Constraints == null) {
if (tp_b.Constraints == null)
continue;
} else if (tp_b.Constraints != null && tp_a.Type.HasSameConstraintsDefinition (tp_b.Type)) {
continue;
}
part.Compiler.Report.SymbolRelatedToPreviousError (this[i].CurrentMemberDefinition.Location, "");
part.Compiler.Report.Error (761, part.Location,
"Partial method declarations of `{0}' have inconsistent constraints for type parameter `{1}'",
part.GetSignatureForError (), partTypeParameters[i].GetSignatureForError ());
}
}
public void UpdateConstraints (TypeDefinition part)
{
var partTypeParameters = part.MemberName.TypeParameters;
for (int i = 0; i < Count; i++) {
var tp = names [i];
if (tp.AddPartialConstraints (part, partTypeParameters [i]))
continue;
part.Compiler.Report.SymbolRelatedToPreviousError (this[i].CurrentMemberDefinition);
part.Compiler.Report.Error (265, part.Location,
"Partial declarations of `{0}' have inconsistent constraints for type parameter `{1}'",
part.GetSignatureForError (), tp.GetSignatureForError ());
}
}
public void VerifyClsCompliance () public void VerifyClsCompliance ()
{ {
foreach (var tp in names) { foreach (var tp in names) {
@ -2270,7 +2323,7 @@ namespace Mono.CSharp {
public override string GetSignatureForError () public override string GetSignatureForError ()
{ {
return TypeManager.CSharpName (type); return type.GetSignatureForError ();
} }
public override TypeSpec ResolveAsType (IMemberContext mc) public override TypeSpec ResolveAsType (IMemberContext mc)
@ -2418,7 +2471,7 @@ namespace Mono.CSharp {
if (mc != null) { if (mc != null) {
mc.Module.Compiler.Report.Error (452, loc, mc.Module.Compiler.Report.Error (452, loc,
"The type `{0}' must be a reference type in order to use it as type parameter `{1}' in the generic type or method `{2}'", "The type `{0}' must be a reference type in order to use it as type parameter `{1}' in the generic type or method `{2}'",
TypeManager.CSharpName (atype), tparam.GetSignatureForError (), context.GetSignatureForError ()); atype.GetSignatureForError (), tparam.GetSignatureForError (), context.GetSignatureForError ());
} }
return false; return false;
@ -2428,7 +2481,7 @@ namespace Mono.CSharp {
if (mc != null) { if (mc != null) {
mc.Module.Compiler.Report.Error (453, loc, mc.Module.Compiler.Report.Error (453, loc,
"The type `{0}' must be a non-nullable value type in order to use it as type parameter `{1}' in the generic type or method `{2}'", "The type `{0}' must be a non-nullable value type in order to use it as type parameter `{1}' in the generic type or method `{2}'",
TypeManager.CSharpName (atype), tparam.GetSignatureForError (), context.GetSignatureForError ()); atype.GetSignatureForError (), tparam.GetSignatureForError (), context.GetSignatureForError ());
} }
return false; return false;
@ -2489,7 +2542,7 @@ namespace Mono.CSharp {
mc.Module.Compiler.Report.SymbolRelatedToPreviousError (atype); mc.Module.Compiler.Report.SymbolRelatedToPreviousError (atype);
mc.Module.Compiler.Report.Error (310, loc, mc.Module.Compiler.Report.Error (310, loc,
"The type `{0}' must have a public parameterless constructor in order to use it as parameter `{1}' in the generic type or method `{2}'", "The type `{0}' must have a public parameterless constructor in order to use it as parameter `{1}' in the generic type or method `{2}'",
TypeManager.CSharpName (atype), tparam.GetSignatureForError (), context.GetSignatureForError ()); atype.GetSignatureForError (), tparam.GetSignatureForError (), context.GetSignatureForError ());
} }
return false; return false;
} }

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

@ -420,7 +420,7 @@ namespace Mono.CSharp
} }
} }
IMemberDefinition definition; IMethodDefinition definition;
if (tparams != null) { if (tparams != null) {
var gmd = new ImportedGenericMethodDefinition ((MethodInfo) mb, returnType, parameters, tparams, this); var gmd = new ImportedGenericMethodDefinition ((MethodInfo) mb, returnType, parameters, tparams, this);
foreach (var tp in gmd.TypeParameters) { foreach (var tp in gmd.TypeParameters) {
@ -429,10 +429,10 @@ namespace Mono.CSharp
definition = gmd; definition = gmd;
} else { } else {
definition = new ImportedParameterMemberDefinition (mb, returnType, parameters, this); definition = new ImportedMethodDefinition (mb, returnType, parameters, this);
} }
MethodSpec ms = new MethodSpec (kind, declaringType, definition, returnType, mb, parameters, mod); MethodSpec ms = new MethodSpec (kind, declaringType, definition, returnType, parameters, mod);
if (tparams != null) if (tparams != null)
ms.IsGeneric = true; ms.IsGeneric = true;
@ -1683,7 +1683,7 @@ namespace Mono.CSharp
{ {
readonly AParametersCollection parameters; readonly AParametersCollection parameters;
public ImportedParameterMemberDefinition (MethodBase provider, TypeSpec type, AParametersCollection parameters, MetadataImporter importer) protected ImportedParameterMemberDefinition (MethodBase provider, TypeSpec type, AParametersCollection parameters, MetadataImporter importer)
: base (provider, type, importer) : base (provider, type, importer)
{ {
this.parameters = parameters; this.parameters = parameters;
@ -1706,7 +1706,21 @@ namespace Mono.CSharp
#endregion #endregion
} }
class ImportedGenericMethodDefinition : ImportedParameterMemberDefinition, IGenericMethodDefinition class ImportedMethodDefinition : ImportedParameterMemberDefinition, IMethodDefinition
{
public ImportedMethodDefinition (MethodBase provider, TypeSpec type, AParametersCollection parameters, MetadataImporter importer)
: base (provider, type, parameters, importer)
{
}
MethodBase IMethodDefinition.Metadata {
get {
return (MethodBase) provider;
}
}
}
class ImportedGenericMethodDefinition : ImportedMethodDefinition, IGenericMethodDefinition
{ {
readonly TypeParameterSpec[] tparams; readonly TypeParameterSpec[] tparams;
@ -1877,33 +1891,36 @@ namespace Mono.CSharp
// or referenced from the user core in which case compilation error has to // or referenced from the user core in which case compilation error has to
// be reported because compiler cannot continue anyway // be reported because compiler cannot continue anyway
// //
var report = ctx.Module.Compiler.Report;
for (int i = 0; i < types.Count; ++i) { for (int i = 0; i < types.Count; ++i) {
var t = types [i]; var t = types [i];
// //
// Report missing types only once per type // Report missing types only once
// //
if (i > 0 && types.IndexOf (t) < i) if (report.Printer.MissingTypeReported (t.MemberDefinition))
continue; continue;
string name = t.GetSignatureForError (); string name = t.GetSignatureForError ();
if (t.MemberDefinition.DeclaringAssembly == ctx.Module.DeclaringAssembly) { if (t.MemberDefinition.DeclaringAssembly == ctx.Module.DeclaringAssembly) {
ctx.Module.Compiler.Report.Error (1683, loc, report.Error (1683, loc,
"Reference to type `{0}' claims it is defined in this assembly, but it is not defined in source or any added modules", "Reference to type `{0}' claims it is defined in this assembly, but it is not defined in source or any added modules",
name); name);
} else if (t.MemberDefinition.DeclaringAssembly.IsMissing) { } else if (t.MemberDefinition.DeclaringAssembly.IsMissing) {
if (t.MemberDefinition.IsTypeForwarder) { if (t.MemberDefinition.IsTypeForwarder) {
ctx.Module.Compiler.Report.Error (1070, loc, report.Error (1070, loc,
"The type `{0}' has been forwarded to an assembly that is not referenced. Consider adding a reference to assembly `{1}'", "The type `{0}' has been forwarded to an assembly that is not referenced. Consider adding a reference to assembly `{1}'",
name, t.MemberDefinition.DeclaringAssembly.FullName); name, t.MemberDefinition.DeclaringAssembly.FullName);
} else { } else {
ctx.Module.Compiler.Report.Error (12, loc, report.Error (12, loc,
"The type `{0}' is defined in an assembly that is not referenced. Consider adding a reference to assembly `{1}'", "The type `{0}' is defined in an assembly that is not referenced. Consider adding a reference to assembly `{1}'",
name, t.MemberDefinition.DeclaringAssembly.FullName); name, t.MemberDefinition.DeclaringAssembly.FullName);
} }
} else { } else {
ctx.Module.Compiler.Report.Error (1684, loc, report.Error (1684, loc,
"Reference to type `{0}' claims it is defined assembly `{1}', but it could not be found", "Reference to type `{0}' claims it is defined assembly `{1}', but it could not be found",
name, t.MemberDefinition.DeclaringAssembly.FullName); name, t.MemberDefinition.DeclaringAssembly.FullName);
} }

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

@ -245,7 +245,7 @@ namespace Mono.CSharp
for (int i = 0; i < host.hoisted_params.Count; ++i) { for (int i = 0; i < host.hoisted_params.Count; ++i) {
HoistedParameter hp = host.hoisted_params [i]; HoistedParameter hp = host.hoisted_params [i];
HoistedParameter hp_cp = host.hoisted_params_copy [i]; HoistedParameter hp_cp = host.hoisted_params_copy [i] ?? hp;
FieldExpr from = new FieldExpr (hp_cp.Field, loc); FieldExpr from = new FieldExpr (hp_cp.Field, loc);
from.InstanceExpression = new CompilerGeneratedThis (ec.CurrentType, loc); from.InstanceExpression = new CompilerGeneratedThis (ec.CurrentType, loc);
@ -431,6 +431,13 @@ namespace Mono.CSharp
get { return hoisted_params; } get { return hoisted_params; }
} }
protected override Constructor DefineDefaultConstructor (bool is_static)
{
var ctor = base.DefineDefaultConstructor (is_static);
ctor.ModFlags |= Modifiers.DEBUGGER_HIDDEN;
return ctor;
}
protected override TypeSpec[] ResolveBaseTypes (out FullNamedExpression base_class) protected override TypeSpec[] ResolveBaseTypes (out FullNamedExpression base_class)
{ {
var mtype = Iterator.OriginalIteratorType; var mtype = Iterator.OriginalIteratorType;
@ -469,17 +476,26 @@ namespace Mono.CSharp
current_field = AddCompilerGeneratedField ("$current", iterator_type_expr); current_field = AddCompilerGeneratedField ("$current", iterator_type_expr);
disposing_field = AddCompilerGeneratedField ("$disposing", new TypeExpression (Compiler.BuiltinTypes.Bool, Location)); disposing_field = AddCompilerGeneratedField ("$disposing", new TypeExpression (Compiler.BuiltinTypes.Bool, Location));
if (hoisted_params != null) { if (Iterator.IsEnumerable && hoisted_params != null) {
// //
// Iterators are independent, each GetEnumerator call has to // Iterators are independent, each GetEnumerator call has to
// create same enumerator therefore we have to keep original values // create same enumerator therefore we have to keep original values
// around for re-initialization // around for re-initialization
// //
// TODO: Do it for assigned/modified parameters only
//
hoisted_params_copy = new List<HoistedParameter> (hoisted_params.Count); hoisted_params_copy = new List<HoistedParameter> (hoisted_params.Count);
foreach (HoistedParameter hp in hoisted_params) { foreach (HoistedParameter hp in hoisted_params) {
hoisted_params_copy.Add (new HoistedParameter (hp, "<$>" + hp.Field.Name));
//
// Don't create field copy for unmodified captured parameters
//
HoistedParameter hp_copy;
if (hp.IsAssigned) {
hp_copy = new HoistedParameter (hp, "<$>" + hp.Field.Name);
} else {
hp_copy = null;
}
hoisted_params_copy.Add (hp_copy);
} }
} }
@ -565,7 +581,8 @@ namespace Mono.CSharp
protected override void EmitHoistedParameters (EmitContext ec, List<HoistedParameter> hoisted) protected override void EmitHoistedParameters (EmitContext ec, List<HoistedParameter> hoisted)
{ {
base.EmitHoistedParameters (ec, hoisted); base.EmitHoistedParameters (ec, hoisted);
base.EmitHoistedParameters (ec, hoisted_params_copy); if (hoisted_params_copy != null)
base.EmitHoistedParameters (ec, hoisted_params_copy);
} }
} }
@ -1101,7 +1118,7 @@ namespace Mono.CSharp
"The body of `{0}' cannot be an iterator block " + "The body of `{0}' cannot be an iterator block " +
"because `{1}' is not an iterator interface type", "because `{1}' is not an iterator interface type",
method.GetSignatureForError (), method.GetSignatureForError (),
TypeManager.CSharpName (ret)); ret.GetSignatureForError ());
return; return;
} }

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

@ -135,7 +135,7 @@ namespace Mono.CSharp.Linq
if (!Convert.ImplicitConversionExists (rc, a.Expr, source_type)) { if (!Convert.ImplicitConversionExists (rc, a.Expr, source_type)) {
rc.Report.Error (1936, loc, "An implementation of `{0}' query expression pattern for source type `{1}' could not be found", rc.Report.Error (1936, loc, "An implementation of `{0}' query expression pattern for source type `{1}' could not be found",
best.Name, TypeManager.CSharpName (a.Type)); best.Name, a.Type.GetSignatureForError ());
return true; return true;
} }
} }

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

@ -61,7 +61,7 @@ namespace Mono.CSharp
if (TypeSpec.IsValueType (t)) { if (TypeSpec.IsValueType (t)) {
ec.Report.Error(37, loc, "Cannot convert null to `{0}' because it is a value type", ec.Report.Error(37, loc, "Cannot convert null to `{0}' because it is a value type",
TypeManager.CSharpName(t)); t.GetSignatureForError ());
return; return;
} }

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

@ -795,13 +795,14 @@ namespace Mono.CSharp {
while (true) { while (true) {
foreach (var entry in abstract_type.MemberCache.member_hash) { foreach (var entry in abstract_type.MemberCache.member_hash) {
foreach (var name_entry in entry.Value) { foreach (var name_entry in entry.Value) {
if ((name_entry.Modifiers & (Modifiers.ABSTRACT | Modifiers.OVERRIDE)) != Modifiers.ABSTRACT) if ((name_entry.Modifiers & Modifiers.ABSTRACT) == 0)
continue; continue;
if (name_entry.Kind != MemberKind.Method) var ms = name_entry as MethodSpec;
if (ms == null)
continue; continue;
abstract_methods.Add ((MethodSpec) name_entry); abstract_methods.Add (ms);
} }
} }
@ -1445,9 +1446,12 @@ namespace Mono.CSharp {
"A partial method declaration and partial method implementation must be both `static' or neither"); "A partial method declaration and partial method implementation must be both `static' or neither");
} }
Report.SymbolRelatedToPreviousError (ce); if ((method_a.ModFlags & Modifiers.UNSAFE) != (method_b.ModFlags & Modifiers.UNSAFE)) {
Report.Error (764, member.Location, Report.SymbolRelatedToPreviousError (ce);
"A partial method declaration and partial method implementation must be both `unsafe' or neither"); Report.Error (764, member.Location,
"A partial method declaration and partial method implementation must be both `unsafe' or neither");
}
return false; return false;
} }

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

@ -188,7 +188,7 @@ namespace Mono.CSharp {
} }
} }
public interface IGenericMethodDefinition : IMemberDefinition public interface IGenericMethodDefinition : IMethodDefinition
{ {
TypeParameterSpec[] TypeParameters { get; } TypeParameterSpec[] TypeParameters { get; }
int TypeParametersCount { get; } int TypeParametersCount { get; }
@ -198,18 +198,17 @@ namespace Mono.CSharp {
public sealed class MethodSpec : MemberSpec, IParametersMember public sealed class MethodSpec : MemberSpec, IParametersMember
{ {
MethodBase metaInfo, inflatedMetaInfo; MethodBase inflatedMetaInfo;
AParametersCollection parameters; AParametersCollection parameters;
TypeSpec returnType; TypeSpec returnType;
TypeSpec[] targs; TypeSpec[] targs;
TypeParameterSpec[] constraints; TypeParameterSpec[] constraints;
public MethodSpec (MemberKind kind, TypeSpec declaringType, IMemberDefinition details, TypeSpec returnType, public MethodSpec (MemberKind kind, TypeSpec declaringType, IMethodDefinition details, TypeSpec returnType,
MethodBase info, AParametersCollection parameters, Modifiers modifiers) AParametersCollection parameters, Modifiers modifiers)
: base (kind, declaringType, details, modifiers) : base (kind, declaringType, details, modifiers)
{ {
this.metaInfo = info;
this.parameters = parameters; this.parameters = parameters;
this.returnType = returnType; this.returnType = returnType;
} }
@ -237,6 +236,12 @@ namespace Mono.CSharp {
} }
} }
public new IMethodDefinition MemberDefinition {
get {
return (IMethodDefinition) definition;
}
}
public IGenericMethodDefinition GenericDefinition { public IGenericMethodDefinition GenericDefinition {
get { get {
return (IGenericMethodDefinition) definition; return (IGenericMethodDefinition) definition;
@ -322,21 +327,21 @@ namespace Mono.CSharp {
if (DeclaringType.IsTypeBuilder) { if (DeclaringType.IsTypeBuilder) {
if (IsConstructor) if (IsConstructor)
inflatedMetaInfo = TypeBuilder.GetConstructor (dt_meta, (ConstructorInfo) metaInfo); inflatedMetaInfo = TypeBuilder.GetConstructor (dt_meta, (ConstructorInfo) MemberDefinition.Metadata);
else else
inflatedMetaInfo = TypeBuilder.GetMethod (dt_meta, (MethodInfo) metaInfo); inflatedMetaInfo = TypeBuilder.GetMethod (dt_meta, (MethodInfo) MemberDefinition.Metadata);
} else { } else {
#if STATIC #if STATIC
// it should not be reached // it should not be reached
throw new NotImplementedException (); throw new NotImplementedException ();
#else #else
inflatedMetaInfo = MethodInfo.GetMethodFromHandle (metaInfo.MethodHandle, dt_meta.TypeHandle); inflatedMetaInfo = MethodInfo.GetMethodFromHandle (MemberDefinition.Metadata.MethodHandle, dt_meta.TypeHandle);
#endif #endif
} }
state &= ~StateFlags.PendingMetaInflate; state &= ~StateFlags.PendingMetaInflate;
} else { } else {
inflatedMetaInfo = metaInfo; inflatedMetaInfo = MemberDefinition.Metadata;
} }
} }
@ -518,19 +523,10 @@ namespace Mono.CSharp {
return missing; return missing;
} }
public void SetMetaInfo (MethodInfo info)
{
if (this.metaInfo != null)
throw new InternalErrorException ("MetaInfo reset");
this.metaInfo = info;
}
} }
public abstract class MethodOrOperator : MethodCore, IMethodData public abstract class MethodOrOperator : MethodCore, IMethodData, IMethodDefinition
{ {
public MethodBuilder MethodBuilder;
ReturnParameter return_attributes; ReturnParameter return_attributes;
SecurityType declarative_security; SecurityType declarative_security;
protected MethodData MethodData; protected MethodData MethodData;
@ -583,6 +579,19 @@ namespace Mono.CSharp {
} }
} }
MethodBase IMethodDefinition.Metadata {
get {
return MethodData.MethodBuilder;
}
}
// TODO: Remove and use MethodData abstraction
public MethodBuilder MethodBuilder {
get {
return MethodData.MethodBuilder;
}
}
protected override bool CheckForDuplications () protected override bool CheckForDuplications ()
{ {
return Parent.MemberCache.CheckExistingMembersOverloads (this, parameters); return Parent.MemberCache.CheckExistingMembersOverloads (this, parameters);
@ -609,41 +618,34 @@ namespace Mono.CSharp {
else else
kind = MemberKind.Method; kind = MemberKind.Method;
string explicit_name;
if (IsPartialDefinition) { if (IsPartialDefinition) {
caching_flags &= ~Flags.Excluded_Undetected; caching_flags &= ~Flags.Excluded_Undetected;
caching_flags |= Flags.Excluded; caching_flags |= Flags.Excluded;
// Add to member cache only when a partial method implementation has not been found yet // Add to member cache only when a partial method implementation has not been found yet
if ((caching_flags & Flags.PartialDefinitionExists) == 0) { if ((caching_flags & Flags.PartialDefinitionExists) != 0)
// MethodBase mb = new PartialMethodDefinitionInfo (this); return true;
spec = new MethodSpec (kind, Parent.Definition, this, ReturnType, null, parameters, ModFlags); if (IsExplicitImpl)
if (MemberName.Arity > 0) { return true;
spec.IsGeneric = true;
// TODO: Have to move DefineMethod after Define (ideally to Emit) explicit_name = null;
throw new NotImplementedException ("Generic partial methods"); } else {
} MethodData = new MethodData (this, ModFlags, flags, this, base_method);
Parent.MemberCache.AddMember (spec); if (!MethodData.Define (Parent.PartialContainer, GetFullName (MemberName)))
} return false;
return true; explicit_name = MethodData.MetadataName;
} }
MethodData = new MethodData ( spec = new MethodSpec (kind, Parent.Definition, this, ReturnType, parameters, ModFlags);
this, ModFlags, flags, this, MethodBuilder, base_method);
if (!MethodData.Define (Parent.PartialContainer, GetFullName (MemberName)))
return false;
MethodBuilder = MethodData.MethodBuilder;
spec = new MethodSpec (kind, Parent.Definition, this, ReturnType, MethodBuilder, parameters, ModFlags);
if (MemberName.Arity > 0) if (MemberName.Arity > 0)
spec.IsGeneric = true; spec.IsGeneric = true;
Parent.MemberCache.AddMember (this, MethodBuilder.Name, spec); Parent.MemberCache.AddMember (this, explicit_name, spec);
return true; return true;
} }
@ -713,7 +715,8 @@ namespace Mono.CSharp {
if (MethodData != null) if (MethodData != null)
MethodData.Emit (Parent); MethodData.Emit (Parent);
Block = null; if ((ModFlags & Modifiers.PARTIAL) == 0)
Block = null;
} }
protected void Error_ConditionalAttributeIsNotValid () protected void Error_ConditionalAttributeIsNotValid ()
@ -798,9 +801,36 @@ namespace Mono.CSharp {
#endregion #endregion
public virtual void PrepareEmit ()
{
var mb = MethodData.DefineMethodBuilder (Parent);
if (CurrentTypeParameters != null) {
string[] gnames = new string[CurrentTypeParameters.Count];
for (int i = 0; i < gnames.Length; ++i) {
gnames[i] = CurrentTypeParameters[i].Name;
}
var gen_params = MethodBuilder.DefineGenericParameters (gnames);
for (int i = 0; i < CurrentTypeParameters.Count; ++i) {
var tp = CurrentTypeParameters[i];
tp.Define (gen_params[i]);
}
}
//
// Generic method has been already defined to resolve method parameters
// correctly when they use type parameters
//
mb.SetParameters (parameters.GetMetaInfo ());
mb.SetReturnType (ReturnType.GetMetaInfo ());
}
public override void WriteDebugSymbol (MonoSymbolFile file) public override void WriteDebugSymbol (MonoSymbolFile file)
{ {
if (MethodData != null) if (MethodData != null && !IsPartialDefinition)
MethodData.WriteDebugSymbol (file); MethodData.WriteDebugSymbol (file);
} }
} }
@ -844,7 +874,7 @@ namespace Mono.CSharp {
} }
} }
#endregion #endregion
public override void Accept (StructuralVisitor visitor) public override void Accept (StructuralVisitor visitor)
{ {
@ -972,10 +1002,9 @@ namespace Mono.CSharp {
void CreateTypeParameters () void CreateTypeParameters ()
{ {
var tparams = MemberName.TypeParameters; var tparams = MemberName.TypeParameters;
string[] snames = new string[MemberName.Arity];
var parent_tparams = Parent.TypeParametersAll; var parent_tparams = Parent.TypeParametersAll;
for (int i = 0; i < snames.Length; i++) { for (int i = 0; i < MemberName.Arity; i++) {
string type_argument_name = tparams[i].MemberName.Name; string type_argument_name = tparams[i].MemberName.Name;
if (block == null) { if (block == null) {
@ -1000,12 +1029,9 @@ namespace Mono.CSharp {
tparams[i].WarningParentNameConflict (tp); tparams[i].WarningParentNameConflict (tp);
} }
} }
snames[i] = type_argument_name;
} }
GenericTypeParameterBuilder[] gen_params = MethodBuilder.DefineGenericParameters (snames); tparams.Create (null, 0, Parent);
tparams.Define (gen_params, null, 0, Parent);
} }
protected virtual void DefineTypeParameters () protected virtual void DefineTypeParameters ()
@ -1171,9 +1197,6 @@ namespace Mono.CSharp {
"Introducing `Finalize' method can interfere with destructor invocation. Did you intend to declare a destructor?"); "Introducing `Finalize' method can interfere with destructor invocation. Did you intend to declare a destructor?");
} }
if (partialMethodImplementation != null && IsPartialDefinition)
MethodBuilder = partialMethodImplementation.MethodBuilder;
if (Compiler.Settings.StdLib && ReturnType.IsSpecialRuntimeType) { if (Compiler.Settings.StdLib && ReturnType.IsSpecialRuntimeType) {
Error1599 (Location, ReturnType, Report); Error1599 (Location, ReturnType, Report);
return false; return false;
@ -1208,7 +1231,7 @@ namespace Mono.CSharp {
Report.Error (1983, Location, "The return type of an async method must be void, Task, or Task<T>"); Report.Error (1983, Location, "The return type of an async method must be void, Task, or Task<T>");
} }
block = (ToplevelBlock) block.ConvertToAsyncTask (this, Parent.PartialContainer, parameters, ReturnType, Location); block = (ToplevelBlock) block.ConvertToAsyncTask (this, Parent.PartialContainer, parameters, ReturnType, null, Location);
ModFlags |= Modifiers.DEBUGGER_HIDDEN; ModFlags |= Modifiers.DEBUGGER_HIDDEN;
} }
@ -1272,6 +1295,22 @@ namespace Mono.CSharp {
return true; return true;
} }
public override void PrepareEmit ()
{
if (IsPartialDefinition) {
//
// Use partial method implementation builder for partial method declaration attributes
//
if (partialMethodImplementation != null) {
MethodData = partialMethodImplementation.MethodData;
}
return;
}
base.PrepareEmit ();
}
// //
// Emits the code // Emits the code
// //
@ -1279,11 +1318,8 @@ namespace Mono.CSharp {
{ {
try { try {
if (IsPartialDefinition) { if (IsPartialDefinition) {
// if (partialMethodImplementation != null && CurrentTypeParameters != null) {
// Use partial method implementation builder for partial method declaration attributes CurrentTypeParameters.CheckPartialConstraints (partialMethodImplementation);
//
if (partialMethodImplementation != null) {
MethodBuilder = partialMethodImplementation.MethodBuilder;
} }
return; return;
@ -1297,6 +1333,7 @@ namespace Mono.CSharp {
if (CurrentTypeParameters != null) { if (CurrentTypeParameters != null) {
for (int i = 0; i < CurrentTypeParameters.Count; ++i) { for (int i = 0; i < CurrentTypeParameters.Count; ++i) {
var tp = CurrentTypeParameters [i]; var tp = CurrentTypeParameters [i];
tp.CheckGenericConstraints (false); tp.CheckGenericConstraints (false);
tp.Emit (); tp.Emit ();
} }
@ -1312,10 +1349,8 @@ namespace Mono.CSharp {
Module.PredefinedAttributes.Extension.EmitAttribute (MethodBuilder); Module.PredefinedAttributes.Extension.EmitAttribute (MethodBuilder);
base.Emit (); base.Emit ();
} catch { } catch (Exception e) {
Console.WriteLine ("Internal compiler error at {0}: exception caught while emitting {1}", throw new InternalErrorException (this, e);
Location, MethodBuilder);
throw;
} }
} }
@ -1329,13 +1364,12 @@ namespace Mono.CSharp {
public static void Error1599 (Location loc, TypeSpec t, Report Report) public static void Error1599 (Location loc, TypeSpec t, Report Report)
{ {
Report.Error (1599, loc, "Method or delegate cannot return type `{0}'", TypeManager.CSharpName (t)); Report.Error (1599, loc, "Method or delegate cannot return type `{0}'", t.GetSignatureForError ());
} }
protected override bool ResolveMemberType () protected override bool ResolveMemberType ()
{ {
if (CurrentTypeParameters != null) { if (CurrentTypeParameters != null) {
MethodBuilder = Parent.TypeBuilder.DefineMethod (GetFullName (MemberName), flags);
CreateTypeParameters (); CreateTypeParameters ();
} }
@ -1485,7 +1519,7 @@ namespace Mono.CSharp {
} }
} }
public class Constructor : MethodCore, IMethodData public class Constructor : MethodCore, IMethodData, IMethodDefinition
{ {
public ConstructorBuilder ConstructorBuilder; public ConstructorBuilder ConstructorBuilder;
public ConstructorInitializer Initializer; public ConstructorInitializer Initializer;
@ -1533,6 +1567,13 @@ namespace Mono.CSharp {
} }
} }
MethodBase IMethodDefinition.Metadata {
get {
return ConstructorBuilder;
}
}
// //
// Returns true if this is a default constructor // Returns true if this is a default constructor
// //
@ -1620,7 +1661,7 @@ namespace Mono.CSharp {
ca, CallingConventions, ca, CallingConventions,
parameters.GetMetaInfo ()); parameters.GetMetaInfo ());
spec = new MethodSpec (MemberKind.Constructor, Parent.Definition, this, Compiler.BuiltinTypes.Void, ConstructorBuilder, parameters, ModFlags); spec = new MethodSpec (MemberKind.Constructor, Parent.Definition, this, Compiler.BuiltinTypes.Void, parameters, ModFlags);
Parent.MemberCache.AddMember (spec); Parent.MemberCache.AddMember (spec);
@ -1828,10 +1869,6 @@ namespace Mono.CSharp {
// //
public class MethodData public class MethodData
{ {
#if !STATIC
static FieldInfo methodbuilder_attrs_field;
#endif
public readonly IMethodData method; public readonly IMethodData method;
// //
@ -1848,6 +1885,7 @@ namespace Mono.CSharp {
protected TypeSpec declaring_type; protected TypeSpec declaring_type;
protected MethodSpec parent_method; protected MethodSpec parent_method;
SourceMethodBuilder debug_builder; SourceMethodBuilder debug_builder;
string full_name;
MethodBuilder builder; MethodBuilder builder;
public MethodBuilder MethodBuilder { public MethodBuilder MethodBuilder {
@ -1862,6 +1900,12 @@ namespace Mono.CSharp {
} }
} }
public string MetadataName {
get {
return full_name;
}
}
public MethodData (InterfaceMemberBase member, public MethodData (InterfaceMemberBase member,
Modifiers modifiers, MethodAttributes flags, IMethodData method) Modifiers modifiers, MethodAttributes flags, IMethodData method)
{ {
@ -1874,11 +1918,10 @@ namespace Mono.CSharp {
public MethodData (InterfaceMemberBase member, public MethodData (InterfaceMemberBase member,
Modifiers modifiers, MethodAttributes flags, Modifiers modifiers, MethodAttributes flags,
IMethodData method, MethodBuilder builder, IMethodData method,
MethodSpec parent_method) MethodSpec parent_method)
: this (member, modifiers, flags, method) : this (member, modifiers, flags, method)
{ {
this.builder = builder;
this.parent_method = parent_method; this.parent_method = parent_method;
} }
@ -1896,13 +1939,13 @@ namespace Mono.CSharp {
if (member is PropertyBase) { if (member is PropertyBase) {
container.Compiler.Report.Error (550, method.Location, container.Compiler.Report.Error (550, method.Location,
"`{0}' is an accessor not found in interface member `{1}{2}'", "`{0}' is an accessor not found in interface member `{1}{2}'",
method.GetSignatureForError (), TypeManager.CSharpName (member.InterfaceType), method.GetSignatureForError (), member.InterfaceType.GetSignatureForError (),
member.GetSignatureForError ().Substring (member.GetSignatureForError ().LastIndexOf ('.'))); member.GetSignatureForError ().Substring (member.GetSignatureForError ().LastIndexOf ('.')));
} else { } else {
container.Compiler.Report.Error (539, method.Location, container.Compiler.Report.Error (539, method.Location,
"`{0}.{1}' in explicit interface declaration is not a member of interface", "`{0}.{1}' in explicit interface declaration is not a member of interface",
TypeManager.CSharpName (member.InterfaceType), member.ShortName); member.InterfaceType.GetSignatureForError (), member.ShortName);
} }
return false; return false;
} }
@ -1910,7 +1953,7 @@ namespace Mono.CSharp {
container.Compiler.Report.SymbolRelatedToPreviousError (implementing); container.Compiler.Report.SymbolRelatedToPreviousError (implementing);
container.Compiler.Report.Error (683, method.Location, container.Compiler.Report.Error (683, method.Location,
"`{0}' explicit method implementation cannot implement `{1}' because it is an accessor", "`{0}' explicit method implementation cannot implement `{1}' because it is an accessor",
member.GetSignatureForError (), TypeManager.CSharpSignature (implementing)); member.GetSignatureForError (), implementing.GetSignatureForError ());
return false; return false;
} }
} else { } else {
@ -2033,58 +2076,45 @@ namespace Mono.CSharp {
method_full_name = implementing.MemberDefinition.Name; method_full_name = implementing.MemberDefinition.Name;
} }
DefineMethodBuilder (container, method_full_name, method.ParameterInfo); full_name = method_full_name;
declaring_type = container.Definition;
if (builder == null) return true;
return false; }
// if (container.CurrentType != null) void DefineOverride (TypeDefinition container)
// declaring_type = container.CurrentType; {
// else if (implementing == null)
declaring_type = container.Definition; return;
if (implementing != null && member.IsExplicitImpl) { if (!member.IsExplicitImpl)
container.TypeBuilder.DefineMethodOverride (builder, (MethodInfo) implementing.GetMetaInfo ()); return;
}
return true; container.TypeBuilder.DefineMethodOverride (builder, (MethodInfo) implementing.GetMetaInfo ());
} }
//
/// <summary> // Creates partial MethodBuilder for the method when has generic parameters used
/// Create the MethodBuilder for the method // as arguments or return type
/// </summary> //
void DefineMethodBuilder (TypeDefinition container, string method_name, ParametersCompiled param) public MethodBuilder DefineMethodBuilder (TypeDefinition container)
{ {
var return_type = method.ReturnType.GetMetaInfo (); if (builder != null)
var p_types = param.GetMetaInfo (); throw new InternalErrorException ();
if (builder == null) { builder = container.TypeBuilder.DefineMethod (full_name, flags, method.CallingConventions);
builder = container.TypeBuilder.DefineMethod ( return builder;
method_name, flags, method.CallingConventions, }
return_type, p_types);
return;
}
// //
// Generic method has been already defined to resolve method parameters // Creates full MethodBuilder for the method
// correctly when they use type parameters //
// public MethodBuilder DefineMethodBuilder (TypeDefinition container, ParametersCompiled param)
builder.SetParameters (p_types); {
builder.SetReturnType (return_type); DefineMethodBuilder (container);
if (builder.Attributes != flags) { builder.SetReturnType (method.ReturnType.GetMetaInfo ());
#if STATIC builder.SetParameters (param.GetMetaInfo ());
builder.__SetAttributes (flags); return builder;
#else
try {
if (methodbuilder_attrs_field == null)
methodbuilder_attrs_field = typeof (MethodBuilder).GetField ("attrs", BindingFlags.NonPublic | BindingFlags.Instance);
methodbuilder_attrs_field.SetValue (builder, flags);
} catch {
container.Compiler.Report.RuntimeMissingSupport (method.Location, "Generic method MethodAttributes");
}
#endif
}
} }
// //
@ -2092,6 +2122,8 @@ namespace Mono.CSharp {
// //
public void Emit (TypeDefinition parent) public void Emit (TypeDefinition parent)
{ {
DefineOverride (parent);
var mc = (IMemberContext) method; var mc = (IMemberContext) method;
method.ParameterInfo.ApplyAttributes (mc, MethodBuilder); method.ParameterInfo.ApplyAttributes (mc, MethodBuilder);
@ -2231,7 +2263,7 @@ namespace Mono.CSharp {
// Ooouh Martin, templates are missing here. // Ooouh Martin, templates are missing here.
// When it will be possible move here a lot of child code and template method type. // When it will be possible move here a lot of child code and template method type.
public abstract class AbstractPropertyEventMethod : MemberCore, IMethodData { public abstract class AbstractPropertyEventMethod : MemberCore, IMethodData, IMethodDefinition {
protected MethodData method_data; protected MethodData method_data;
protected ToplevelBlock block; protected ToplevelBlock block;
protected SecurityType declarative_security; protected SecurityType declarative_security;
@ -2297,6 +2329,12 @@ namespace Mono.CSharp {
} }
} }
MethodBase IMethodDefinition.Metadata {
get {
return method_data.MethodBuilder;
}
}
public abstract ParametersCompiled ParameterInfo { get ; } public abstract ParametersCompiled ParameterInfo { get ; }
public abstract TypeSpec ReturnType { get; } public abstract TypeSpec ReturnType { get; }
@ -2307,7 +2345,7 @@ namespace Mono.CSharp {
if (a.Type == pa.CLSCompliant || a.Type == pa.Obsolete || a.Type == pa.Conditional) { if (a.Type == pa.CLSCompliant || a.Type == pa.Obsolete || a.Type == pa.Conditional) {
Report.Error (1667, a.Location, Report.Error (1667, a.Location,
"Attribute `{0}' is not valid on property or event accessors. It is valid on `{1}' declarations only", "Attribute `{0}' is not valid on property or event accessors. It is valid on `{1}' declarations only",
TypeManager.CSharpName (a.Type), a.GetValidTargets ()); a.Type.GetSignatureForError (), a.GetValidTargets ());
return; return;
} }

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

@ -262,7 +262,7 @@ namespace Mono.CSharp
return mod; return mod;
} }
for (i = 1; i <= (int) Modifiers.TOP; i <<= 1) { for (i = 1; i < (int) Modifiers.TOP; i <<= 1) {
if ((i & invalid_flags) == 0) if ((i & invalid_flags) == 0)
continue; continue;

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

@ -276,16 +276,7 @@ namespace Mono.CSharp {
public Namespace AddNamespace (MemberName name) public Namespace AddNamespace (MemberName name)
{ {
Namespace ns_parent; var ns_parent = name.Left == null ? this : AddNamespace (name.Left);
if (name.Left != null) {
if (parent != null)
ns_parent = parent.AddNamespace (name.Left);
else
ns_parent = AddNamespace (name.Left);
} else {
ns_parent = this;
}
return ns_parent.TryAddNamespace (name.Basename); return ns_parent.TryAddNamespace (name.Basename);
} }

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

@ -320,7 +320,7 @@ namespace Mono.CSharp.Nullable
public static Constant CreateFromExpression (ResolveContext ec, Expression e) public static Constant CreateFromExpression (ResolveContext ec, Expression e)
{ {
ec.Report.Warning (458, 2, e.Location, "The result of the expression is always `null' of type `{0}'", ec.Report.Warning (458, 2, e.Location, "The result of the expression is always `null' of type `{0}'",
TypeManager.CSharpName (e.Type)); e.Type.GetSignatureForError ());
return ReducedExpression.Create (Create (e.Type, e.Location), e); return ReducedExpression.Create (Create (e.Type, e.Location), e);
} }
@ -592,10 +592,10 @@ namespace Mono.CSharp.Nullable
if ((Oper & Operator.EqualityMask) != 0) { if ((Oper & Operator.EqualityMask) != 0) {
ec.Report.Warning (472, 2, loc, "The result of comparing value type `{0}' with null is always `{1}'", ec.Report.Warning (472, 2, loc, "The result of comparing value type `{0}' with null is always `{1}'",
TypeManager.CSharpName (expr.Type), c.GetValueAsLiteral ()); expr.Type.GetSignatureForError (), c.GetValueAsLiteral ());
} else { } else {
ec.Report.Warning (464, 2, loc, "The result of comparing type `{0}' with null is always `{1}'", ec.Report.Warning (464, 2, loc, "The result of comparing type `{0}' with null is always `{1}'",
TypeManager.CSharpName (expr.Type), c.GetValueAsLiteral ()); expr.Type.GetSignatureForError (), c.GetValueAsLiteral ());
} }
return ReducedExpression.Create (c, this); return ReducedExpression.Create (c, this);

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

@ -338,7 +338,7 @@ namespace Mono.CSharp {
if (HasOptionalExpression) { if (HasOptionalExpression) {
a.Report.Error (1745, a.Location, a.Report.Error (1745, a.Location,
"Cannot specify `{0}' attribute on optional parameter `{1}'", "Cannot specify `{0}' attribute on optional parameter `{1}'",
TypeManager.CSharpName (a.Type).Replace ("Attribute", ""), Name); a.Type.GetSignatureForError ().Replace ("Attribute", ""), Name);
} }
if (a.Type == pa.DefaultParameterValue) if (a.Type == pa.DefaultParameterValue)
@ -406,7 +406,7 @@ namespace Mono.CSharp {
if ((modFlags & Modifier.This) != 0 && (parameter_type.IsPointer || parameter_type.BuiltinType == BuiltinTypeSpec.Type.Dynamic)) { if ((modFlags & Modifier.This) != 0 && (parameter_type.IsPointer || parameter_type.BuiltinType == BuiltinTypeSpec.Type.Dynamic)) {
rc.Module.Compiler.Report.Error (1103, Location, "The extension method cannot be of type `{0}'", rc.Module.Compiler.Report.Error (1103, Location, "The extension method cannot be of type `{0}'",
TypeManager.CSharpName (parameter_type)); parameter_type.GetSignatureForError ());
} }
return parameter_type; return parameter_type;
@ -582,7 +582,7 @@ namespace Mono.CSharp {
{ {
string type_name; string type_name;
if (parameter_type != null) if (parameter_type != null)
type_name = TypeManager.CSharpName (parameter_type); type_name = parameter_type.GetSignatureForError ();
else else
type_name = texpr.GetSignatureForError (); type_name = texpr.GetSignatureForError ();
@ -989,7 +989,7 @@ namespace Mono.CSharp {
if (types == null || types [pos] == null) if (types == null || types [pos] == null)
return ((Parameter)FixedParameters [pos]).GetSignatureForError (); return ((Parameter)FixedParameters [pos]).GetSignatureForError ();
string type = TypeManager.CSharpName (types [pos]); string type = types [pos].GetSignatureForError ();
if (FixedParameters [pos].HasExtensionMethodModifier) if (FixedParameters [pos].HasExtensionMethodModifier)
return "this " + type; return "this " + type;

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

@ -534,10 +534,14 @@ namespace Mono.CSharp {
// about mismatch at return type when the check bellow rejects them // about mismatch at return type when the check bellow rejects them
// //
var parameters = mi.Parameters; var parameters = mi.Parameters;
MethodSpec close_match = null;
while (true) { while (true) {
var candidates = MemberCache.FindMembers (base_type, mi.Name, false); var candidates = MemberCache.FindMembers (base_type, mi.Name, false);
if (candidates == null) if (candidates == null) {
base_method = close_match;
return false; return false;
}
MethodSpec similar_candidate = null; MethodSpec similar_candidate = null;
foreach (var candidate in candidates) { foreach (var candidate in candidates) {
@ -590,19 +594,29 @@ namespace Mono.CSharp {
// From this point the candidate is used for detailed error reporting // From this point the candidate is used for detailed error reporting
// because it's very close match to what we are looking for // because it's very close match to what we are looking for
// //
base_method = (MethodSpec) candidate; var m = (MethodSpec) candidate;
if (!m.IsPublic) {
if (close_match == null)
close_match = m;
if (!candidate.IsPublic) continue;
return false; }
if (!TypeSpecComparer.Override.IsEqual (mi.ReturnType, base_method.ReturnType)) if (!TypeSpecComparer.Override.IsEqual (mi.ReturnType, m.ReturnType)) {
return false; if (close_match == null)
close_match = m;
if (mi.IsGeneric && !Method.CheckImplementingMethodConstraints (container, base_method, mi)) { continue;
}
base_method = m;
if (mi.IsGeneric && !Method.CheckImplementingMethodConstraints (container, m, mi)) {
return true; return true;
} }
} }
if (base_method != null) { if (base_method != null) {
if (similar_candidate != null) { if (similar_candidate != null) {
Report.SymbolRelatedToPreviousError (similar_candidate); Report.SymbolRelatedToPreviousError (similar_candidate);
@ -617,8 +631,10 @@ namespace Mono.CSharp {
} }
base_type = candidates[0].DeclaringType.BaseType; base_type = candidates[0].DeclaringType.BaseType;
if (base_type == null) if (base_type == null) {
base_method = close_match;
return false; return false;
}
} }
if (!base_method.IsVirtual) { if (!base_method.IsVirtual) {

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

@ -201,14 +201,14 @@ namespace Mono.CSharp
{ {
base.Define (parent); base.Define (parent);
Spec = new MethodSpec (MemberKind.Method, parent.PartialContainer.Definition, this, ReturnType, null, ParameterInfo, ModFlags); Spec = new MethodSpec (MemberKind.Method, parent.PartialContainer.Definition, this, ReturnType, ParameterInfo, ModFlags);
method_data = new MethodData (method, ModFlags, flags, this); method_data = new MethodData (method, ModFlags, flags, this);
if (!method_data.Define (parent.PartialContainer, method.GetFullName (MemberName))) if (!method_data.Define (parent.PartialContainer, method.GetFullName (MemberName)))
return null; return null;
Spec.SetMetaInfo (method_data.MethodBuilder); method_data.DefineMethodBuilder (parent.PartialContainer, ParameterInfo);
return method_data.MethodBuilder; return method_data.MethodBuilder;
} }
@ -268,14 +268,14 @@ namespace Mono.CSharp
base.Define (parent); base.Define (parent);
Spec = new MethodSpec (MemberKind.Method, parent.PartialContainer.Definition, this, ReturnType, null, ParameterInfo, ModFlags); Spec = new MethodSpec (MemberKind.Method, parent.PartialContainer.Definition, this, ReturnType, ParameterInfo, ModFlags);
method_data = new MethodData (method, ModFlags, flags, this); method_data = new MethodData (method, ModFlags, flags, this);
if (!method_data.Define (parent.PartialContainer, method.GetFullName (MemberName))) if (!method_data.Define (parent.PartialContainer, method.GetFullName (MemberName)))
return null; return null;
Spec.SetMetaInfo (method_data.MethodBuilder); method_data.DefineMethodBuilder (parent.PartialContainer, ParameterInfo);
return method_data.MethodBuilder; return method_data.MethodBuilder;
} }
@ -1198,15 +1198,15 @@ namespace Mono.CSharp
if (!method_data.Define (parent.PartialContainer, method.GetFullName (MemberName))) if (!method_data.Define (parent.PartialContainer, method.GetFullName (MemberName)))
return null; return null;
method_data.DefineMethodBuilder (parent.PartialContainer, ParameterInfo);
if (Compiler.Settings.WriteMetadataOnly) if (Compiler.Settings.WriteMetadataOnly)
block = null; block = null;
MethodBuilder mb = method_data.MethodBuilder; Spec = new MethodSpec (MemberKind.Method, parent.PartialContainer.Definition, this, ReturnType, ParameterInfo, method.ModFlags);
Spec = new MethodSpec (MemberKind.Method, parent.PartialContainer.Definition, this, ReturnType, mb, ParameterInfo, method.ModFlags);
Spec.IsAccessor = true; Spec.IsAccessor = true;
return mb; return method_data.MethodBuilder;
} }
public override TypeSpec ReturnType { public override TypeSpec ReturnType {

23
ICSharpCode.NRefactory.CSharp/Parser/mcs/report.cs

@ -550,6 +550,8 @@ namespace Mono.CSharp {
// //
public abstract class ReportPrinter public abstract class ReportPrinter
{ {
protected HashSet<ITypeDefinition> reported_missing_definitions;
#region Properties #region Properties
public int ErrorsCount { get; protected set; } public int ErrorsCount { get; protected set; }
@ -605,6 +607,22 @@ namespace Mono.CSharp {
} }
} }
//
// Tracks reported missing types. It needs to be session specific
// because we can run in probing mode
//
public bool MissingTypeReported (ITypeDefinition typeDefinition)
{
if (reported_missing_definitions == null)
reported_missing_definitions = new HashSet<ITypeDefinition> ();
if (reported_missing_definitions.Contains (typeDefinition))
return true;
reported_missing_definitions.Add (typeDefinition);
return false;
}
public void Reset () public void Reset ()
{ {
// HACK: Temporary hack for broken repl flow // HACK: Temporary hack for broken repl flow
@ -735,6 +753,11 @@ namespace Mono.CSharp {
error_msg |= !msg.IsWarning; error_msg |= !msg.IsWarning;
} }
if (reported_missing_definitions != null) {
foreach (var missing in reported_missing_definitions)
dest.MissingTypeReported (missing);
}
return error_msg; return error_msg;
} }
} }

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

@ -350,6 +350,17 @@ namespace Mono.CSharp {
public CompilerSettings ParseArguments (string[] args) public CompilerSettings ParseArguments (string[] args)
{ {
CompilerSettings settings = new CompilerSettings (); CompilerSettings settings = new CompilerSettings ();
if (!ParseArguments (settings, args))
return null;
return settings;
}
public bool ParseArguments (CompilerSettings settings, string[] args)
{
if (settings == null)
throw new ArgumentNullException ("settings");
List<string> response_file_list = null; List<string> response_file_list = null;
bool parsing_options = true; bool parsing_options = true;
stop_argument = false; stop_argument = false;
@ -369,7 +380,7 @@ namespace Mono.CSharp {
if (response_file_list.Contains (response_file)) { if (response_file_list.Contains (response_file)) {
report.Error (1515, "Response file `{0}' specified multiple times", response_file); report.Error (1515, "Response file `{0}' specified multiple times", response_file);
return null; return false;
} }
response_file_list.Add (response_file); response_file_list.Add (response_file);
@ -377,7 +388,7 @@ namespace Mono.CSharp {
extra_args = LoadArgs (response_file); extra_args = LoadArgs (response_file);
if (extra_args == null) { if (extra_args == null) {
report.Error (2011, "Unable to open response file: " + response_file); report.Error (2011, "Unable to open response file: " + response_file);
return null; return false;
} }
args = AddArgs (args, extra_args); args = AddArgs (args, extra_args);
@ -399,7 +410,7 @@ namespace Mono.CSharp {
continue; continue;
case ParseResult.Stop: case ParseResult.Stop:
stop_argument = true; stop_argument = true;
return settings; return true;
case ParseResult.UnknownOption: case ParseResult.UnknownOption:
if (UnknownOptionHandler != null) { if (UnknownOptionHandler != null) {
var ret = UnknownOptionHandler (args, i); var ret = UnknownOptionHandler (args, i);
@ -433,11 +444,11 @@ namespace Mono.CSharp {
} }
Error_WrongOption (arg); Error_WrongOption (arg);
return null; return false;
case ParseResult.Stop: case ParseResult.Stop:
stop_argument = true; stop_argument = true;
return settings; return true;
} }
} }
} }
@ -445,10 +456,7 @@ namespace Mono.CSharp {
ProcessSourceFiles (arg, false, settings.SourceFiles); ProcessSourceFiles (arg, false, settings.SourceFiles);
} }
if (report.Errors > 0) return report.Errors == 0;
return null;
return settings;
} }
void ProcessSourceFiles (string spec, bool recurse, List<SourceFile> sourceFiles) void ProcessSourceFiles (string spec, bool recurse, List<SourceFile> sourceFiles)

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

@ -706,6 +706,7 @@ namespace Mono.CSharp {
public StatementErrorExpression (Expression expr) public StatementErrorExpression (Expression expr)
{ {
this.expr = expr; this.expr = expr;
this.loc = expr.StartLocation;
} }
public Expression Expr { public Expression Expr {
@ -714,6 +715,12 @@ namespace Mono.CSharp {
} }
} }
public override bool Resolve (BlockContext bc)
{
expr.Error_InvalidExpressionStatement (bc);
return true;
}
protected override void DoEmit (EmitContext ec) protected override void DoEmit (EmitContext ec)
{ {
throw new NotSupportedException (); throw new NotSupportedException ();
@ -903,9 +910,18 @@ namespace Mono.CSharp {
if (this is ContextualReturn) if (this is ContextualReturn)
return true; return true;
ec.Report.Error (1997, loc, // Same error code as .NET but better error message
"`{0}': A return keyword must not be followed by an expression when async method returns `Task'. Consider using `Task<T>' return type", if (async_block.DelegateType != null) {
ec.GetSignatureForError ()); ec.Report.Error (1997, loc,
"`{0}': A return keyword must not be followed by an expression when async delegate returns `Task'. Consider using `Task<T>' return type",
async_block.DelegateType.GetSignatureForError ());
} else {
ec.Report.Error (1997, loc,
"`{0}': A return keyword must not be followed by an expression when async method returns `Task'. Consider using `Task<T>' return type",
ec.GetSignatureForError ());
}
return false; return false;
} }
@ -1252,7 +1268,7 @@ namespace Mono.CSharp {
if (!Convert.ImplicitStandardConversionExists (c, type)) if (!Convert.ImplicitStandardConversionExists (c, type))
ec.Report.Warning (469, 2, loc, ec.Report.Warning (469, 2, loc,
"The `goto case' value is not implicitly convertible to type `{0}'", "The `goto case' value is not implicitly convertible to type `{0}'",
TypeManager.CSharpName (type)); type.GetSignatureForError ());
} }
@ -1420,69 +1436,72 @@ namespace Mono.CSharp {
Location Location { get; } Location Location { get; }
} }
public class BlockVariableDeclaration : Statement public class BlockVariableDeclarator
{ {
public class Declarator LocalVariable li;
Expression initializer;
public BlockVariableDeclarator (LocalVariable li, Expression initializer)
{ {
LocalVariable li; if (li.Type != null)
Expression initializer; throw new ArgumentException ("Expected null variable type");
public Declarator (LocalVariable li, Expression initializer) this.li = li;
{ this.initializer = initializer;
if (li.Type != null) }
throw new ArgumentException ("Expected null variable type");
this.li = li; #region Properties
this.initializer = initializer;
}
public Declarator (Declarator clone, Expression initializer) public LocalVariable Variable {
{ get {
this.li = clone.li; return li;
this.initializer = initializer;
} }
}
#region Properties public Expression Initializer {
get {
public LocalVariable Variable { return initializer;
get {
return li;
}
} }
set {
public Expression Initializer { initializer = value;
get {
return initializer;
}
set {
initializer = value;
}
} }
}
#endregion #endregion
public virtual BlockVariableDeclarator Clone (CloneContext cloneCtx)
{
var t = (BlockVariableDeclarator) MemberwiseClone ();
if (initializer != null)
t.initializer = initializer.Clone (cloneCtx);
return t;
} }
}
public class BlockVariable : Statement
{
Expression initializer; Expression initializer;
protected FullNamedExpression type_expr; protected FullNamedExpression type_expr;
protected LocalVariable li; protected LocalVariable li;
protected List<Declarator> declarators; protected List<BlockVariableDeclarator> declarators;
TypeSpec type; TypeSpec type;
public BlockVariableDeclaration (FullNamedExpression type, LocalVariable li) public BlockVariable (FullNamedExpression type, LocalVariable li)
{ {
this.type_expr = type; this.type_expr = type;
this.li = li; this.li = li;
this.loc = type_expr.Location; this.loc = type_expr.Location;
} }
protected BlockVariableDeclaration (LocalVariable li) protected BlockVariable (LocalVariable li)
{ {
this.li = li; this.li = li;
} }
#region Properties #region Properties
public List<Declarator> Declarators { public List<BlockVariableDeclarator> Declarators {
get { get {
return declarators; return declarators;
} }
@ -1511,10 +1530,10 @@ namespace Mono.CSharp {
#endregion #endregion
public void AddDeclarator (Declarator decl) public void AddDeclarator (BlockVariableDeclarator decl)
{ {
if (declarators == null) if (declarators == null)
declarators = new List<Declarator> (); declarators = new List<BlockVariableDeclarator> ();
declarators.Add (decl); declarators.Add (decl);
} }
@ -1607,7 +1626,7 @@ namespace Mono.CSharp {
bool eval_global = bc.Module.Compiler.Settings.StatementMode && bc.CurrentBlock is ToplevelBlock; bool eval_global = bc.Module.Compiler.Settings.StatementMode && bc.CurrentBlock is ToplevelBlock;
if (eval_global) { if (eval_global) {
CreateEvaluatorVariable (bc, li); CreateEvaluatorVariable (bc, li);
} else { } else if (type != InternalType.ErrorType) {
li.PrepareForFlowAnalysis (bc); li.PrepareForFlowAnalysis (bc);
} }
@ -1621,7 +1640,7 @@ namespace Mono.CSharp {
d.Variable.Type = li.Type; d.Variable.Type = li.Type;
if (eval_global) { if (eval_global) {
CreateEvaluatorVariable (bc, d.Variable); CreateEvaluatorVariable (bc, d.Variable);
} else { } else if (type != InternalType.ErrorType) {
d.Variable.PrepareForFlowAnalysis (bc); d.Variable.PrepareForFlowAnalysis (bc);
} }
@ -1661,7 +1680,7 @@ namespace Mono.CSharp {
protected override void CloneTo (CloneContext clonectx, Statement target) protected override void CloneTo (CloneContext clonectx, Statement target)
{ {
BlockVariableDeclaration t = (BlockVariableDeclaration) target; BlockVariable t = (BlockVariable) target;
if (type_expr != null) if (type_expr != null)
t.type_expr = (FullNamedExpression) type_expr.Clone (clonectx); t.type_expr = (FullNamedExpression) type_expr.Clone (clonectx);
@ -1672,7 +1691,7 @@ namespace Mono.CSharp {
if (declarators != null) { if (declarators != null) {
t.declarators = null; t.declarators = null;
foreach (var d in declarators) foreach (var d in declarators)
t.AddDeclarator (new Declarator (d, d.Initializer == null ? null : d.Initializer.Clone (clonectx))); t.AddDeclarator (d.Clone (clonectx));
} }
} }
@ -1682,9 +1701,9 @@ namespace Mono.CSharp {
} }
} }
public class BlockConstantDeclaration : BlockVariableDeclaration public class BlockConstant : BlockVariable
{ {
public BlockConstantDeclaration (FullNamedExpression type, LocalVariable li) public BlockConstant (FullNamedExpression type, LocalVariable li)
: base (type, li) : base (type, li)
{ {
} }
@ -2059,7 +2078,8 @@ namespace Mono.CSharp {
HasAsyncModifier = 1 << 10, HasAsyncModifier = 1 << 10,
Resolved = 1 << 11, Resolved = 1 << 11,
YieldBlock = 1 << 12, YieldBlock = 1 << 12,
AwaitBlock = 1 << 13 AwaitBlock = 1 << 13,
Iterator = 1 << 14
} }
public Block Parent; public Block Parent;
@ -2646,6 +2666,7 @@ namespace Mono.CSharp {
} }
storey.Define (); storey.Define ();
storey.PrepareEmit ();
storey.Parent.PartialContainer.AddCompilerGeneratedClass (storey); storey.Parent.PartialContainer.AddCompilerGeneratedClass (storey);
} }
@ -2664,6 +2685,8 @@ namespace Mono.CSharp {
public void RegisterIteratorYield () public void RegisterIteratorYield ()
{ {
ParametersBlock.TopBlock.IsIterator = true;
var block = this; var block = this;
while ((block.flags & Flags.YieldBlock) == 0) { while ((block.flags & Flags.YieldBlock) == 0) {
block.flags |= Flags.YieldBlock; block.flags |= Flags.YieldBlock;
@ -3112,7 +3135,7 @@ namespace Mono.CSharp {
return tlb; return tlb;
} }
public ParametersBlock ConvertToAsyncTask (IMemberContext context, TypeDefinition host, ParametersCompiled parameters, TypeSpec returnType, Location loc) public ParametersBlock ConvertToAsyncTask (IMemberContext context, TypeDefinition host, ParametersCompiled parameters, TypeSpec returnType, TypeSpec delegateType, Location loc)
{ {
for (int i = 0; i < parameters.Count; i++) { for (int i = 0; i < parameters.Count; i++) {
Parameter p = parameters[i]; Parameter p = parameters[i];
@ -3144,6 +3167,7 @@ namespace Mono.CSharp {
var block_type = host.Module.Compiler.BuiltinTypes.Void; var block_type = host.Module.Compiler.BuiltinTypes.Void;
var initializer = new AsyncInitializer (this, host, block_type); var initializer = new AsyncInitializer (this, host, block_type);
initializer.Type = block_type; initializer.Type = block_type;
initializer.DelegateType = delegateType;
var stateMachine = new AsyncTaskStorey (this, context, initializer, returnType); var stateMachine = new AsyncTaskStorey (this, context, initializer, returnType);
@ -3207,7 +3231,10 @@ namespace Mono.CSharp {
public bool IsIterator { public bool IsIterator {
get { get {
return HasYield; return (flags & Flags.Iterator) != 0;
}
set {
flags = value ? flags | Flags.Iterator : flags & ~Flags.Iterator;
} }
} }
@ -4110,10 +4137,13 @@ namespace Mono.CSharp {
new_expr = SwitchGoverningType (ec, unwrap); new_expr = SwitchGoverningType (ec, unwrap);
} }
if (new_expr == null){ if (new_expr == null) {
ec.Report.Error (151, loc, if (Expr.Type != InternalType.ErrorType) {
"A switch expression of type `{0}' cannot be converted to an integral type, bool, char, string, enum or nullable type", ec.Report.Error (151, loc,
TypeManager.CSharpName (Expr.Type)); "A switch expression of type `{0}' cannot be converted to an integral type, bool, char, string, enum or nullable type",
Expr.Type.GetSignatureForError ());
}
return false; return false;
} }
@ -4512,6 +4542,7 @@ namespace Mono.CSharp {
if (finally_host != null) { if (finally_host != null) {
finally_host.Define (); finally_host.Define ();
finally_host.PrepareEmit ();
finally_host.Emit (); finally_host.Emit ();
// Now it's safe to add, to close it properly and emit sequence points // Now it's safe to add, to close it properly and emit sequence points
@ -5049,8 +5080,7 @@ namespace Mono.CSharp {
} }
} }
public class VariableDeclaration : BlockVariable
public class VariableDeclaration : BlockVariableDeclaration
{ {
public VariableDeclaration (FullNamedExpression type, LocalVariable li) public VariableDeclaration (FullNamedExpression type, LocalVariable li)
: base (type, li) : base (type, li)
@ -5175,7 +5205,7 @@ namespace Mono.CSharp {
} }
} }
public BlockVariableDeclaration Variables { public BlockVariable Variables {
get { get {
return decl; return decl;
} }
@ -5557,7 +5587,7 @@ namespace Mono.CSharp {
public class Using : TryFinallyBlock public class Using : TryFinallyBlock
{ {
public class VariableDeclaration : BlockVariableDeclaration public class VariableDeclaration : BlockVariable
{ {
Statement dispose_call; Statement dispose_call;
@ -5734,7 +5764,7 @@ namespace Mono.CSharp {
} }
} }
public BlockVariableDeclaration Variables { public BlockVariable Variables {
get { get {
return decl; return decl;
} }

24
ICSharpCode.NRefactory.CSharp/Parser/mcs/typemanager.cs

@ -691,6 +691,7 @@ namespace Mono.CSharp
readonly MemberKind kind; readonly MemberKind kind;
protected readonly ModuleContainer module; protected readonly ModuleContainer module;
protected TypeSpec type; protected TypeSpec type;
bool defined;
public PredefinedType (ModuleContainer module, MemberKind kind, string ns, string name, int arity) public PredefinedType (ModuleContainer module, MemberKind kind, string ns, string name, int arity)
: this (module, kind, ns, name) : this (module, kind, ns, name)
@ -753,7 +754,11 @@ namespace Mono.CSharp
if (type != null) if (type != null)
return true; return true;
type = Resolve (module, kind, ns, name, arity, false, false); if (!defined) {
defined = true;
type = Resolve (module, kind, ns, name, arity, false, false);
}
return type != null; return type != null;
} }
@ -771,12 +776,13 @@ namespace Mono.CSharp
// fake namespaces when type is optional and does not exist (e.g. System.Linq). // fake namespaces when type is optional and does not exist (e.g. System.Linq).
// //
Namespace type_ns = module.GlobalRootNamespace.GetNamespace (ns, required); Namespace type_ns = module.GlobalRootNamespace.GetNamespace (ns, required);
IList<TypeSpec> found = null; IList<TypeSpec> found = null;
if (type_ns != null) if (type_ns != null)
found = type_ns.GetAllTypes (name); found = type_ns.GetAllTypes (name);
if (found == null) { if (found == null) {
if (reportErrors ) if (reportErrors)
module.Compiler.Report.Error (518, "The predefined type `{0}.{1}' is not defined or imported", ns, name); module.Compiler.Report.Error (518, "The predefined type `{0}.{1}' is not defined or imported", ns, name);
return null; return null;
@ -984,15 +990,7 @@ namespace Mono.CSharp
partial class TypeManager { partial class TypeManager {
/// <summary> static public string CSharpName(IList<TypeSpec> types)
/// Returns the C# name of a type if possible, or the full type name otherwise
/// </summary>
static public string CSharpName (TypeSpec t)
{
return t.GetSignatureForError ();
}
static public string CSharpName (IList<TypeSpec> types)
{ {
if (types.Count == 0) if (types.Count == 0)
return string.Empty; return string.Empty;
@ -1002,7 +1000,7 @@ namespace Mono.CSharp
if (i > 0) if (i > 0)
sb.Append (","); sb.Append (",");
sb.Append (CSharpName (types [i])); sb.Append (types [i].GetSignatureForError ());
} }
return sb.ToString (); return sb.ToString ();
} }
@ -1090,7 +1088,7 @@ namespace Mono.CSharp
rc.Compiler.Report.SymbolRelatedToPreviousError (t); rc.Compiler.Report.SymbolRelatedToPreviousError (t);
rc.Compiler.Report.Error (208, loc, rc.Compiler.Report.Error (208, loc,
"Cannot take the address of, get the size of, or declare a pointer to a managed type `{0}'", "Cannot take the address of, get the size of, or declare a pointer to a managed type `{0}'",
CSharpName (t)); t.GetSignatureForError ());
return false; return false;
} }

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

@ -130,12 +130,12 @@ namespace Mono.CSharp
return null; return null;
} }
public virtual object Visit (BlockVariableDeclaration blockVariableDeclaration) public virtual object Visit (BlockVariable blockVariableDeclaration)
{ {
return null; return null;
} }
public virtual object Visit (BlockConstantDeclaration blockConstantDeclaration) public virtual object Visit (BlockConstant blockConstantDeclaration)
{ {
return null; return null;
} }

2
ICSharpCode.NRefactory.Tests/CSharp/CodeActions/IterateViaForeachTests.cs

@ -147,7 +147,7 @@ class TestClass
foreach (var c in s as IEnumerable<char>) { foreach (var c in s as IEnumerable<char>) {
} }
} }
}", 0, true); }", 0, false);
} }
[Test] [Test]

2
ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/InvalidStatementsTests.cs

@ -36,7 +36,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Statements
[Test] [Test]
public void AsExpressionStatementPositions() public void AsExpressionStatementPositions()
{ {
ExpressionStatement expr = ParseUtilCSharp.ParseStatement<ExpressionStatement>("\t\t\"\" as IEnumerable<char>;", true); ExpressionStatement expr = ParseUtilCSharp.ParseStatement<ExpressionStatement>("\t\t\"\" as IEnumerable<char>;", false);
Assert.AreEqual(new TextLocation(1, 3), expr.StartLocation); Assert.AreEqual(new TextLocation(1, 3), expr.StartLocation);
Assert.AreEqual(new TextLocation(1, 27), expr.EndLocation); Assert.AreEqual(new TextLocation(1, 27), expr.EndLocation);
} }

Loading…
Cancel
Save