Browse Source

Updated mcs/fixed pointer reference expression bug.

newNRvisualizers
Mike Krüger 15 years ago
parent
commit
a4ce5aa555
  1. 2
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/PointerReferenceExpressionTests.cs
  2. 24
      ICSharpCode.NRefactory/CSharp/Parser/mcs/anonymous.cs
  3. 30
      ICSharpCode.NRefactory/CSharp/Parser/mcs/assembly.cs
  4. 59
      ICSharpCode.NRefactory/CSharp/Parser/mcs/attribute.cs
  5. 45
      ICSharpCode.NRefactory/CSharp/Parser/mcs/class.cs
  6. 27
      ICSharpCode.NRefactory/CSharp/Parser/mcs/constant.cs
  7. 4
      ICSharpCode.NRefactory/CSharp/Parser/mcs/context.cs
  8. 9762
      ICSharpCode.NRefactory/CSharp/Parser/mcs/cs-parser.cs
  9. 431
      ICSharpCode.NRefactory/CSharp/Parser/mcs/cs-parser.jay
  10. 21
      ICSharpCode.NRefactory/CSharp/Parser/mcs/cs-tokenizer.cs
  11. 40
      ICSharpCode.NRefactory/CSharp/Parser/mcs/decl.cs
  12. 2
      ICSharpCode.NRefactory/CSharp/Parser/mcs/delegate.cs
  13. 817
      ICSharpCode.NRefactory/CSharp/Parser/mcs/doc.cs
  14. 4
      ICSharpCode.NRefactory/CSharp/Parser/mcs/driver.cs
  15. 10
      ICSharpCode.NRefactory/CSharp/Parser/mcs/dynamic.cs
  16. 152
      ICSharpCode.NRefactory/CSharp/Parser/mcs/ecore.cs
  17. 2
      ICSharpCode.NRefactory/CSharp/Parser/mcs/enum.cs
  18. 7
      ICSharpCode.NRefactory/CSharp/Parser/mcs/eval.cs
  19. 27
      ICSharpCode.NRefactory/CSharp/Parser/mcs/expression.cs
  20. 2
      ICSharpCode.NRefactory/CSharp/Parser/mcs/field.cs
  21. 25
      ICSharpCode.NRefactory/CSharp/Parser/mcs/generic.cs
  22. 50
      ICSharpCode.NRefactory/CSharp/Parser/mcs/import.cs
  23. 2
      ICSharpCode.NRefactory/CSharp/Parser/mcs/iterators.cs
  24. 4
      ICSharpCode.NRefactory/CSharp/Parser/mcs/location.cs
  25. 81
      ICSharpCode.NRefactory/CSharp/Parser/mcs/method.cs
  26. 399
      ICSharpCode.NRefactory/CSharp/Parser/mcs/namespace.cs
  27. 2
      ICSharpCode.NRefactory/CSharp/Parser/mcs/nullable.cs
  28. 28
      ICSharpCode.NRefactory/CSharp/Parser/mcs/parameter.cs
  29. 19
      ICSharpCode.NRefactory/CSharp/Parser/mcs/pending.cs
  30. 31
      ICSharpCode.NRefactory/CSharp/Parser/mcs/property.cs
  31. 4
      ICSharpCode.NRefactory/CSharp/Parser/mcs/report.cs
  32. 69
      ICSharpCode.NRefactory/CSharp/Parser/mcs/roottypes.cs
  33. 14
      ICSharpCode.NRefactory/CSharp/Parser/mcs/statement.cs
  34. 101
      ICSharpCode.NRefactory/CSharp/Parser/mcs/typemanager.cs
  35. 98
      ICSharpCode.NRefactory/CSharp/Parser/mcs/typespec.cs

2
ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/PointerReferenceExpressionTests.cs

@ -17,7 +17,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression @@ -17,7 +17,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
Assert.AreEqual("b", pre.MemberName);
}
[Test, Ignore ("compiler error - reported upstream")]
[Test]
public void PointerReferenceGenericMethodTest()
{
ParseUtilCSharp.AssertExpression(

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

@ -591,7 +591,7 @@ namespace Mono.CSharp { @@ -591,7 +591,7 @@ namespace Mono.CSharp {
protected override Expression DoResolve (ResolveContext ec)
{
eclass = ExprClass.Value;
type = ec.Module.PredefinedTypes.Expression.Resolve (Location);
type = ec.Module.PredefinedTypes.Expression.Resolve ();
return this;
}
@ -1662,15 +1662,6 @@ namespace Mono.CSharp { @@ -1662,15 +1662,6 @@ namespace Mono.CSharp {
//
public class AnonymousTypeClass : CompilerGeneratedClass
{
// TODO: Merge with AnonymousTypeParameter
public class GeneratedParameter : Parameter
{
public GeneratedParameter (FullNamedExpression type, AnonymousTypeParameter p)
: base (type, p.Name, Modifier.NONE, null, p.Location)
{
}
}
static int types_counter;
public const string ClassNamePrefix = "<>__AnonType";
public const string SignatureForError = "anonymous type";
@ -1701,10 +1692,21 @@ namespace Mono.CSharp { @@ -1701,10 +1692,21 @@ namespace Mono.CSharp {
Parameter[] ctor_params = new Parameter[parameters.Count];
for (int i = 0; i < parameters.Count; ++i) {
AnonymousTypeParameter p = parameters[i];
for (int ii = 0; ii < i; ++ii) {
if (parameters[ii].Name == p.Name) {
parent.Compiler.Report.Error (833, parameters[ii].Location,
"`{0}': An anonymous type cannot have multiple properties with the same name",
p.Name);
p = new AnonymousTypeParameter (null, "$" + i.ToString (), p.Location);
parameters[i] = p;
break;
}
}
t_args[i] = new SimpleName ("<" + p.Name + ">__T", p.Location);
t_params[i] = new TypeParameterName (t_args[i].Name, null, p.Location);
ctor_params[i] = new GeneratedParameter (t_args[i], p);
ctor_params[i] = new Parameter (t_args[i], p.Name, Parameter.Modifier.NONE, null, p.Location);
}
all_parameters = new ParametersCompiled (ctor_params);

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

@ -376,6 +376,12 @@ namespace Mono.CSharp @@ -376,6 +376,12 @@ namespace Mono.CSharp
a.FullName);
}
var ci = a.Assembly.GetName ().CultureInfo;
if (!ci.Equals (System.Globalization.CultureInfo.InvariantCulture)) {
Report.Warning (1607, 1, "Referenced assembly `{0}' has different culture setting of `{1}'",
a.Name, ci.Name);
}
if (!a.IsFriendAssemblyTo (this))
continue;
@ -866,26 +872,24 @@ namespace Mono.CSharp @@ -866,26 +872,24 @@ namespace Mono.CSharp
}
if (entry_point == null) {
if (Compiler.Settings.MainClass != null) {
// TODO: Should use MemberCache
DeclSpace main_cont = module.GetDefinition (Compiler.Settings.MainClass) as DeclSpace;
if (main_cont == null) {
Report.Error (1555, "Could not find `{0}' specified for Main method", Compiler.Settings.MainClass);
string main_class = Compiler.Settings.MainClass;
if (main_class != null) {
// TODO: Handle dotted names
var texpr = module.GlobalRootNamespace.LookupType (module, main_class, 0, Location.Null);
if (texpr == null) {
Report.Error (1555, "Could not find `{0}' specified for Main method", main_class);
return;
}
if (!(main_cont is ClassOrStruct)) {
Report.Error (1556, "`{0}' specified for Main method must be a valid class or struct", Compiler.Settings.MainClass);
var mtype = texpr.Type.MemberDefinition as ClassOrStruct;
if (mtype == null) {
Report.Error (1556, "`{0}' specified for Main method must be a valid class or struct", main_class);
return;
}
Report.Error (1558, main_cont.Location, "`{0}' does not have a suitable static Main method", main_cont.GetSignatureForError ());
return;
}
if (Report.Errors == 0) {
Report.Error (1558, mtype.Location, "`{0}' does not have a suitable static Main method", mtype.GetSignatureForError ());
} else {
string pname = file_name == null ? name : Path.GetFileName (file_name);
Report.Error (5001, "Program `{0}' does not contain a static `Main' method suitable for an entry point",
pname);
}

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

@ -165,7 +165,7 @@ namespace Mono.CSharp { @@ -165,7 +165,7 @@ namespace Mono.CSharp {
}
// When re-attaching global attributes
if (context is NamespaceEntry) {
if (context is NamespaceContainer) {
this.targets[0] = target;
this.context = context;
return;
@ -245,20 +245,13 @@ namespace Mono.CSharp { @@ -245,20 +245,13 @@ namespace Mono.CSharp {
}
}
TypeSpec ResolvePossibleAttributeType (ATypeNameExpression expr, ref bool is_attr)
TypeSpec ResolvePossibleAttributeType (ATypeNameExpression expr)
{
TypeExpr te = expr.ResolveAsTypeTerminal (context, false);
if (te == null)
return null;
TypeSpec t = te.Type;
if (t.IsAttribute) {
is_attr = true;
} else {
Report.SymbolRelatedToPreviousError (t);
Report.Error (616, Location, "`{0}': is not an attribute class", TypeManager.CSharpName (t));
}
return t;
return te.Type;
}
/// <summary>
@ -274,8 +267,15 @@ namespace Mono.CSharp { @@ -274,8 +267,15 @@ namespace Mono.CSharp {
TypeSpec t1, t2;
ATypeNameExpression expanded = null;
// TODO: Additional warnings such as CS0436 are swallowed because we don't
// print on success
try {
t1 = ResolvePossibleAttributeType (expression, ref t1_is_attr);
t1 = ResolvePossibleAttributeType (expression);
if (t1 != null)
t1_is_attr = t1.IsAttribute;
resolve_printer.EndSession ();
if (nameEscaped) {
t2 = null;
@ -283,15 +283,15 @@ namespace Mono.CSharp { @@ -283,15 +283,15 @@ namespace Mono.CSharp {
expanded = (ATypeNameExpression) expression.Clone (null);
expanded.Name += "Attribute";
t2 = ResolvePossibleAttributeType (expanded, ref t2_is_attr);
t2 = ResolvePossibleAttributeType (expanded);
if (t2 != null)
t2_is_attr = t2.IsAttribute;
}
resolve_printer.EndSession ();
} finally {
context.Module.Compiler.Report.SetPrinter (prev_recorder);
}
if (t1_is_attr && t2_is_attr) {
if (t1_is_attr && t2_is_attr && t1 != t2) {
Report.Error (1614, Location, "`{0}' is ambiguous between `{1}' and `{2}'. Use either `@{0}' or `{0}Attribute'",
GetSignatureForError (), expression.GetSignatureForError (), expanded.GetSignatureForError ());
resolve_error = true;
@ -308,8 +308,23 @@ namespace Mono.CSharp { @@ -308,8 +308,23 @@ namespace Mono.CSharp {
return;
}
resolve_printer.Merge (prev_recorder);
resolve_error = true;
if (t1 != null) {
resolve_printer.Merge (prev_recorder);
Report.SymbolRelatedToPreviousError (t1);
Report.Error (616, Location, "`{0}': is not an attribute class", t1.GetSignatureForError ());
return;
}
if (t2 != null) {
Report.SymbolRelatedToPreviousError (t2);
Report.Error (616, Location, "`{0}': is not an attribute class", t2.GetSignatureForError ());
return;
}
resolve_printer.Merge (prev_recorder);
}
public TypeSpec ResolveType ()
@ -431,7 +446,7 @@ namespace Mono.CSharp { @@ -431,7 +446,7 @@ namespace Mono.CSharp {
// Add [module: DefaultCharSet] to all DllImport import attributes
//
var module = context.Module;
if (Type == module.PredefinedAttributes.DllImport && module.HasDefaultCharSet) {
if ((Type == module.PredefinedAttributes.DllImport || Type == module.PredefinedAttributes.UnmanagedFunctionPointer) && module.HasDefaultCharSet) {
if (rc == null)
rc = CreateResolveContext ();
@ -1146,7 +1161,7 @@ namespace Mono.CSharp { @@ -1146,7 +1161,7 @@ namespace Mono.CSharp {
return true;
}
public void ConvertGlobalAttributes (TypeContainer member, NamespaceEntry currentNamespace, bool isGlobal)
public void ConvertGlobalAttributes (TypeContainer member, NamespaceContainer currentNamespace, bool isGlobal)
{
var member_explicit_targets = member.ValidAttributeTargets;
for (int i = 0; i < Attrs.Count; ++i) {
@ -1621,8 +1636,6 @@ namespace Mono.CSharp { @@ -1621,8 +1636,6 @@ namespace Mono.CSharp {
public readonly PredefinedAttribute DefaultParameterValue;
public readonly PredefinedAttribute OptionalParameter;
public readonly PredefinedAttribute UnverifiableCode;
// New in .NET 2.0
public readonly PredefinedAttribute DefaultCharset;
public readonly PredefinedAttribute TypeForwarder;
public readonly PredefinedAttribute FixedBuffer;
@ -1631,6 +1644,7 @@ namespace Mono.CSharp { @@ -1631,6 +1644,7 @@ namespace Mono.CSharp {
public readonly PredefinedAttribute RuntimeCompatibility;
public readonly PredefinedAttribute DebuggerHidden;
public readonly PredefinedAttribute UnsafeValueType;
public readonly PredefinedAttribute UnmanagedFunctionPointer;
// New in .NET 3.5
public readonly PredefinedAttribute Extension;
@ -1650,8 +1664,8 @@ namespace Mono.CSharp { @@ -1650,8 +1664,8 @@ namespace Mono.CSharp {
{
ParamArray = new PredefinedAttribute (module, "System", "ParamArrayAttribute");
Out = new PredefinedAttribute (module, "System.Runtime.InteropServices", "OutAttribute");
ParamArray.Resolve (Location.Null);
Out.Resolve (Location.Null);
ParamArray.Resolve ();
Out.Resolve ();
Obsolete = new PredefinedAttribute (module, "System", "ObsoleteAttribute");
DllImport = new PredefinedAttribute (module, "System.Runtime.InteropServices", "DllImportAttribute");
@ -1684,6 +1698,7 @@ namespace Mono.CSharp { @@ -1684,6 +1698,7 @@ namespace Mono.CSharp {
RuntimeCompatibility = new PredefinedAttribute (module, "System.Runtime.CompilerServices", "RuntimeCompatibilityAttribute");
DebuggerHidden = new PredefinedAttribute (module, "System.Diagnostics", "DebuggerHiddenAttribute");
UnsafeValueType = new PredefinedAttribute (module, "System.Runtime.CompilerServices", "UnsafeValueTypeAttribute");
UnmanagedFunctionPointer = new PredefinedAttribute (module, "System.Runtime.InteropServices", "UnmanagedFunctionPointerAttribute");
Extension = new PredefinedAttribute (module, "System.Runtime.CompilerServices", "ExtensionAttribute");

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

@ -32,12 +32,19 @@ using System.Reflection; @@ -32,12 +32,19 @@ using System.Reflection;
using System.Reflection.Emit;
#endif
namespace Mono.CSharp {
namespace Mono.CSharp
{
public interface ITypesContainer
{
Location Location { get; }
MemberName MemberName { get; }
}
/// <summary>
/// This is the base class for structs and classes.
/// </summary>
public abstract class TypeContainer : DeclSpace, ITypeDefinition
public abstract class TypeContainer : DeclSpace, ITypeDefinition, ITypesContainer
{
//
// Different context is needed when resolving type container base
@ -96,7 +103,7 @@ namespace Mono.CSharp { @@ -96,7 +103,7 @@ namespace Mono.CSharp {
return tc.GetSignatureForError ();
}
public IList<MethodSpec> LookupExtensionMethod (TypeSpec extensionType, string name, int arity, ref NamespaceEntry scope)
public IList<MethodSpec> LookupExtensionMethod (TypeSpec extensionType, string name, int arity, ref NamespaceContainer scope)
{
return null;
}
@ -232,7 +239,7 @@ namespace Mono.CSharp { @@ -232,7 +239,7 @@ namespace Mono.CSharp {
/// </remarks>
PendingImplementation pending;
public TypeContainer (NamespaceEntry ns, DeclSpace parent, MemberName name,
public TypeContainer (NamespaceContainer ns, DeclSpace parent, MemberName name,
Attributes attrs, MemberKind kind)
: base (ns, parent, name, attrs)
{
@ -1079,11 +1086,6 @@ namespace Mono.CSharp { @@ -1079,11 +1086,6 @@ namespace Mono.CSharp {
int type_size = Kind == MemberKind.Struct && first_nonstatic_field == null ? 1 : 0;
if (IsTopLevel) {
// TODO: Completely wrong
if (Module.GlobalRootNamespace.IsNamespace (Name)) {
Report.Error (519, Location, "`{0}' clashes with a predefined namespace", Name);
}
TypeBuilder = Module.CreateBuilder (Name, TypeAttr, type_size);
} else {
TypeBuilder = Parent.TypeBuilder.DefineNestedType (Basename, TypeAttr, null, type_size);
@ -1145,7 +1147,7 @@ namespace Mono.CSharp { @@ -1145,7 +1147,7 @@ namespace Mono.CSharp {
var cloned_params = ParametersCompiled.CreateFullyResolved (base_parameters, method.Parameters.Types);
if (method.Parameters.HasArglist) {
cloned_params.FixedParameters[0] = new Parameter (null, "__arglist", Parameter.Modifier.NONE, null, Location);
cloned_params.Types[0] = Module.PredefinedTypes.RuntimeArgumentHandle.Resolve (Location);
cloned_params.Types[0] = Module.PredefinedTypes.RuntimeArgumentHandle.Resolve ();
}
GenericMethod generic_method;
@ -2298,7 +2300,7 @@ namespace Mono.CSharp { @@ -2298,7 +2300,7 @@ namespace Mono.CSharp {
{
SecurityType declarative_security;
public ClassOrStruct (NamespaceEntry ns, DeclSpace parent,
public ClassOrStruct (NamespaceContainer ns, DeclSpace parent,
MemberName name, Attributes attrs, MemberKind kind)
: base (ns, parent, name, attrs, kind)
{
@ -2423,7 +2425,7 @@ namespace Mono.CSharp { @@ -2423,7 +2425,7 @@ namespace Mono.CSharp {
}
}
public override IList<MethodSpec> LookupExtensionMethod (TypeSpec extensionType, string name, int arity, ref NamespaceEntry scope)
public override IList<MethodSpec> LookupExtensionMethod (TypeSpec extensionType, string name, int arity, ref NamespaceContainer scope)
{
DeclSpace top_level = Parent;
if (top_level != null) {
@ -2463,7 +2465,7 @@ namespace Mono.CSharp { @@ -2463,7 +2465,7 @@ namespace Mono.CSharp {
public const TypeAttributes StaticClassAttribute = TypeAttributes.Abstract | TypeAttributes.Sealed;
public Class (NamespaceEntry ns, DeclSpace parent, MemberName name, Modifiers mod,
public Class (NamespaceContainer ns, DeclSpace parent, MemberName name, Modifiers mod,
Attributes attrs)
: base (ns, parent, name, attrs, MemberKind.Class)
{
@ -2707,7 +2709,7 @@ namespace Mono.CSharp { @@ -2707,7 +2709,7 @@ namespace Mono.CSharp {
Modifiers.UNSAFE |
Modifiers.PRIVATE;
public Struct (NamespaceEntry ns, DeclSpace parent, MemberName name,
public Struct (NamespaceContainer ns, DeclSpace parent, MemberName name,
Modifiers mod, Attributes attrs)
: base (ns, parent, name, attrs, MemberKind.Struct)
{
@ -2898,7 +2900,7 @@ namespace Mono.CSharp { @@ -2898,7 +2900,7 @@ namespace Mono.CSharp {
Modifiers.UNSAFE |
Modifiers.PRIVATE;
public Interface (NamespaceEntry ns, DeclSpace parent, MemberName name, Modifiers mod,
public Interface (NamespaceContainer ns, DeclSpace parent, MemberName name, Modifiers mod,
Attributes attrs)
: base (ns, parent, name, attrs, MemberKind.Interface)
{
@ -3408,6 +3410,14 @@ namespace Mono.CSharp { @@ -3408,6 +3410,14 @@ namespace Mono.CSharp {
return TypeManager.CSharpName (InterfaceType) + "." + name;
}
public override string GetSignatureForDocumentation ()
{
if (IsExplicitImpl)
return Parent.GetSignatureForDocumentation () + "." + InterfaceType.GetExplicitNameSignatureForDocumentation () + "#" + ShortName;
return Parent.GetSignatureForDocumentation () + "." + ShortName;
}
protected override bool VerifyClsCompliance ()
{
if (!base.VerifyClsCompliance ()) {
@ -3553,6 +3563,11 @@ namespace Mono.CSharp { @@ -3553,6 +3563,11 @@ namespace Mono.CSharp {
return true;
}
public override string GetSignatureForDocumentation ()
{
return Parent.Name + "." + Name;
}
protected virtual bool ResolveMemberType ()
{
if (member_type != null)

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

@ -2026,19 +2026,26 @@ namespace Mono.CSharp { @@ -2026,19 +2026,26 @@ namespace Mono.CSharp {
public override void EncodeAttributeValue (IMemberContext rc, AttributeEncoder enc, TypeSpec targetType)
{
// Type it as string cast
if (targetType.BuiltinType == BuiltinTypeSpec.Type.Object)
switch (targetType.BuiltinType) {
case BuiltinTypeSpec.Type.Object:
// Type it as string cast
enc.Encode (rc.Module.Compiler.BuiltinTypes.String);
var ac = targetType as ArrayContainer;
if (ac != null) {
if (ac.Rank != 1 || ac.Element.IsArray)
base.EncodeAttributeValue (rc, enc, targetType);
else
enc.Encode (uint.MaxValue);
} else {
goto case BuiltinTypeSpec.Type.String;
case BuiltinTypeSpec.Type.String:
case BuiltinTypeSpec.Type.Type:
enc.Encode (byte.MaxValue);
return;
default:
var ac = targetType as ArrayContainer;
if (ac != null && ac.Rank == 1 && !ac.Element.IsArray) {
enc.Encode (uint.MaxValue);
return;
}
break;
}
base.EncodeAttributeValue (rc, enc, targetType);
}
public override void Emit (EmitContext ec)

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

@ -52,7 +52,7 @@ namespace Mono.CSharp @@ -52,7 +52,7 @@ namespace Mono.CSharp
string GetSignatureForError ();
IList<MethodSpec> LookupExtensionMethod (TypeSpec extensionType, string name, int arity, ref NamespaceEntry scope);
IList<MethodSpec> LookupExtensionMethod (TypeSpec extensionType, string name, int arity, ref NamespaceContainer scope);
FullNamedExpression LookupNamespaceOrType (string name, int arity, Location loc, bool ignore_cs0104);
FullNamedExpression LookupNamespaceAlias (string name);
}
@ -515,7 +515,7 @@ namespace Mono.CSharp @@ -515,7 +515,7 @@ namespace Mono.CSharp
return MemberContext.GetSignatureForError ();
}
public IList<MethodSpec> LookupExtensionMethod (TypeSpec extensionType, string name, int arity, ref NamespaceEntry scope)
public IList<MethodSpec> LookupExtensionMethod (TypeSpec extensionType, string name, int arity, ref NamespaceContainer scope)
{
return MemberContext.LookupExtensionMethod (extensionType, name, arity, ref scope);
}

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

File diff suppressed because it is too large Load Diff

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

File diff suppressed because it is too large Load Diff

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

@ -196,6 +196,7 @@ namespace Mono.CSharp @@ -196,6 +196,7 @@ namespace Mono.CSharp
// Set when parsing generic declaration (type or method header)
//
public bool parsing_generic_declaration;
public bool parsing_generic_declaration_doc;
//
// The value indicates that we have not reach any declaration or
@ -205,18 +206,19 @@ namespace Mono.CSharp @@ -205,18 +206,19 @@ namespace Mono.CSharp
public bool parsing_attribute_section;
//
// The special character to inject on streams to trigger the EXPRESSION_PARSE
// token to be returned. It just happens to be a Unicode character that
// would never be part of a program (can not be an identifier).
// The special characters to inject on streams to run the unit parser
// in the special expression mode. Using private characters from
// Plane Sixteen (U+100000 to U+10FFFD)
//
// This character is only tested just before the tokenizer is about to report
// an error; So on the regular operation mode, this addition will have no
// impact on the tokenizer's performance.
//
public const int EvalStatementParserCharacter = 0x2190; // Unicode Left Arrow
public const int EvalCompilationUnitParserCharacter = 0x2191; // Unicode Arrow
public const int EvalUsingDeclarationsParserCharacter = 0x2192; // Unicode Arrow
public const int EvalStatementParserCharacter = 0x100000;
public const int EvalCompilationUnitParserCharacter = 0x100001;
public const int EvalUsingDeclarationsParserCharacter = 0x100002;
public const int DocumentationXref = 0x100003;
//
// XML documentation buffer. The save point is used to divide
@ -3116,7 +3118,8 @@ namespace Mono.CSharp @@ -3116,7 +3118,8 @@ namespace Mono.CSharp
WarningMisplacedComment (Location - 3);
}
} else {
check_incorrect_doc_comment ();
if (xml_comment_buffer.Length > 0)
doc_state = XmlCommentState.NotAllowed;
}
} else {
bool isDoc = peek_char () == '/';
@ -3310,6 +3313,8 @@ namespace Mono.CSharp @@ -3310,6 +3313,8 @@ namespace Mono.CSharp
return Token.EVAL_COMPILATION_UNIT_PARSER;
case EvalUsingDeclarationsParserCharacter:
return Token.EVAL_USING_DECLARATIONS_UNIT_PARSER;
case DocumentationXref:
return Token.DOC_SEE;
}
if (is_identifier_start_character (c)) {
@ -3389,7 +3394,7 @@ namespace Mono.CSharp @@ -3389,7 +3394,7 @@ namespace Mono.CSharp
// Save current position and parse next token.
PushPosition ();
if (parse_less_than ()) {
if (parsing_generic_declaration && token () != Token.DOT) {
if (parsing_generic_declaration && (parsing_generic_declaration_doc || token () != Token.DOT)) {
d = Token.OP_GENERICS_LT_DECL;
} else {
d = Token.OP_GENERICS_LT;

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

@ -13,6 +13,7 @@ @@ -13,6 +13,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
#if NET_2_1
using XmlElement = System.Object;
@ -33,6 +34,7 @@ namespace Mono.CSharp { @@ -33,6 +34,7 @@ namespace Mono.CSharp {
//
// Better name would be DottenName
//
[DebuggerDisplay ("{GetSignatureForError()}")]
public class MemberName {
public readonly string Name;
public TypeArguments TypeArguments;
@ -691,7 +693,7 @@ namespace Mono.CSharp { @@ -691,7 +693,7 @@ namespace Mono.CSharp {
return true;
}
public virtual IList<MethodSpec> LookupExtensionMethod (TypeSpec extensionType, string name, int arity, ref NamespaceEntry scope)
public virtual IList<MethodSpec> LookupExtensionMethod (TypeSpec extensionType, string name, int arity, ref NamespaceContainer scope)
{
return Parent.LookupExtensionMethod (extensionType, name, arity, ref scope);
}
@ -814,22 +816,11 @@ namespace Mono.CSharp { @@ -814,22 +816,11 @@ namespace Mono.CSharp {
return true;
}
//
// Raised (and passed an XmlElement that contains the comment)
// when GenerateDocComment is writing documentation expectedly.
//
internal virtual void OnGenerateDocComment (XmlElement intermediateNode)
{
}
//
// Returns a string that represents the signature for this
// member which should be used in XML documentation.
//
public virtual string GetDocCommentName ()
{
return DocCommentHeader + Parent.Name + "." + Name;
}
public abstract string GetSignatureForDocumentation ();
//
// Generates xml doc comments (if any), and if required,
@ -1089,6 +1080,11 @@ namespace Mono.CSharp { @@ -1089,6 +1080,11 @@ namespace Mono.CSharp {
return cls == false;
}
public virtual string GetSignatureForDocumentation ()
{
return DeclaringType.GetSignatureForDocumentation () + "." + Name;
}
public virtual string GetSignatureForError ()
{
var bf = MemberDefinition as Property.BackingField;
@ -1252,7 +1248,7 @@ namespace Mono.CSharp { @@ -1252,7 +1248,7 @@ namespace Mono.CSharp {
// This is the namespace in which this typecontainer
// was declared. We use this to resolve names.
//
public NamespaceEntry NamespaceEntry;
public NamespaceContainer NamespaceEntry;
public readonly string Basename;
@ -1281,7 +1277,7 @@ namespace Mono.CSharp { @@ -1281,7 +1277,7 @@ namespace Mono.CSharp {
static readonly string[] attribute_targets = new string [] { "type" };
public DeclSpace (NamespaceEntry ns, DeclSpace parent, MemberName name,
public DeclSpace (NamespaceContainer ns, DeclSpace parent, MemberName name,
Attributes attrs)
: base (parent, name, attrs)
{
@ -1324,17 +1320,13 @@ namespace Mono.CSharp { @@ -1324,17 +1320,13 @@ namespace Mono.CSharp {
return false;
}
if (this is ModuleContainer) {
Report.Error (101, symbol.Location,
"The namespace `{0}' already contains a definition for `{1}'",
((DeclSpace)symbol).NamespaceEntry.GetSignatureForError (), symbol.MemberName.Name);
} else if (symbol is TypeParameter) {
if (symbol is TypeParameter) {
Report.Error (692, symbol.Location,
"Duplicate type parameter `{0}'", symbol.GetSignatureForError ());
} else {
Report.Error (102, symbol.Location,
"The type `{0}' already contains a definition for `{1}'",
GetSignatureForError (), symbol.MemberName.Name);
"The type `{0}' already contains a definition for `{1}'",
GetSignatureForError (), symbol.MemberName.Name);
}
return false;
@ -1385,9 +1377,9 @@ namespace Mono.CSharp { @@ -1385,9 +1377,9 @@ namespace Mono.CSharp {
type.GetSignatureForError ());
}
public override string GetDocCommentName ()
public override string GetSignatureForDocumentation ()
{
return DocCommentHeader + Name;
return Name;
}
public override string GetSignatureForError ()

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

@ -54,7 +54,7 @@ namespace Mono.CSharp { @@ -54,7 +54,7 @@ namespace Mono.CSharp {
Modifiers.UNSAFE |
Modifiers.PRIVATE;
public Delegate (NamespaceEntry ns, DeclSpace parent, FullNamedExpression type,
public Delegate (NamespaceContainer ns, DeclSpace parent, FullNamedExpression type,
Modifiers mod_flags, MemberName name, ParametersCompiled param_list,
Attributes attrs)
: base (ns, parent, name, attrs, MemberKind.Delegate)

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

@ -1,8 +1,9 @@ @@ -1,8 +1,9 @@
//
// doc.cs: Support for XML documentation comment.
//
// Author:
// Authors:
// Atsushi Enomoto <atsushi@ximian.com>
// Marek Safar (marek.safar@gmail.com>
//
// Dual licensed under the terms of the MIT X11 or GNU GPL
//
@ -17,7 +18,6 @@ using System.Text; @@ -17,7 +18,6 @@ using System.Text;
using System.Xml;
using System.Linq;
namespace Mono.CSharp
{
//
@ -35,10 +35,9 @@ namespace Mono.CSharp @@ -35,10 +35,9 @@ namespace Mono.CSharp
//
// The output for XML documentation.
//
public XmlWriter XmlCommentOutput;
XmlWriter XmlCommentOutput;
static readonly string line_head = Environment.NewLine + " ";
static readonly char[] wsChars = new char[] { ' ', '\t', '\n', '\r' };
//
// Stores XmlDocuments that are included in XML documentation.
@ -59,6 +58,22 @@ namespace Mono.CSharp @@ -59,6 +58,22 @@ namespace Mono.CSharp
}
}
public MemberName ParsedName {
get; set;
}
public List<DocumentationParameter> ParsedParameters {
get; set;
}
public TypeExpression ParsedBuiltinType {
get; set;
}
public Operator.OpType? ParsedOperator {
get; set;
}
XmlNode GetDocCommentNode (MemberCore mc, string name)
{
// FIXME: It could be even optimizable as not
@ -101,13 +116,16 @@ namespace Mono.CSharp @@ -101,13 +116,16 @@ namespace Mono.CSharp
//
internal void GenerateDocumentationForMember (MemberCore mc)
{
string name = mc.GetDocCommentName ();
string name = mc.DocCommentHeader + mc.GetSignatureForDocumentation ();
XmlNode n = GetDocCommentNode (mc, name);
XmlElement el = n as XmlElement;
if (el != null) {
mc.OnGenerateDocComment (el);
var pm = mc as IParametersMember;
if (pm != null) {
CheckParametersComments (mc, pm, el);
}
// FIXME: it could be done with XmlReader
XmlNodeList nl = n.SelectNodes (".//include");
@ -211,435 +229,233 @@ namespace Mono.CSharp @@ -211,435 +229,233 @@ namespace Mono.CSharp
HandleXrefCommon (mc, ds, seealso);
}
//
// returns a full runtime type name from a name which might
// be C# specific type name.
//
TypeSpec FindDocumentedType (MemberCore mc, string name, DeclSpace ds, string cref)
{
bool is_array = false;
string identifier = name;
if (name [name.Length - 1] == ']') {
string tmp = name.Substring (0, name.Length - 1).Trim (wsChars);
if (tmp [tmp.Length - 1] == '[') {
identifier = tmp.Substring (0, tmp.Length - 1).Trim (wsChars);
is_array = true;
}
}
TypeSpec t = FindDocumentedTypeNonArray (mc, identifier, ds, cref);
if (t != null && is_array)
t = ArrayContainer.MakeType (mc.Module, t);
return t;
}
TypeSpec FindDocumentedTypeNonArray (MemberCore mc, string identifier, DeclSpace ds, string cref)
FullNamedExpression ResolveMemberName (IMemberContext context, MemberName mn)
{
var types = module.Compiler.BuiltinTypes;
switch (identifier) {
case "int":
return types.Int;
case "uint":
return types.UInt;
case "short":
return types.Short;
case "ushort":
return types.UShort;
case "long":
return types.Long;
case "ulong":
return types.ULong;
case "float":
return types.Float;
case "double":
return types.Double;
case "char":
return types.Char;
case "decimal":
return types.Decimal;
case "byte":
return types.Byte;
case "sbyte":
return types.SByte;
case "object":
return types.Object;
case "bool":
return types.Bool;
case "string":
return types.String;
case "void":
return types.Void;
}
FullNamedExpression e = ds.LookupNamespaceOrType (identifier, 0, mc.Location, false);
if (e != null) {
if (!(e is TypeExpr))
return null;
return e.Type;
}
int index = identifier.LastIndexOf ('.');
if (index < 0)
return null;
if (mn.Left == null)
return context.LookupNamespaceOrType (mn.Name, mn.Arity, Location.Null, /*ignore_cs0104=*/ false);
var nsName = identifier.Substring (0, index);
var typeName = identifier.Substring (index + 1);
Namespace ns = ds.NamespaceEntry.NS.GetNamespace (nsName, false);
ns = ns ?? mc.Module.GlobalRootNamespace.GetNamespace(nsName, false);
if (ns != null) {
var te = ns.LookupType(mc, typeName, 0, true, mc.Location);
if(te != null)
return te.Type;
}
var left = ResolveMemberName (context, mn.Left);
var ns = left as Namespace;
if (ns != null)
return ns.Lookup (context, mn.Name, mn.Arity, Location.Null);
int warn;
TypeSpec parent = FindDocumentedType (mc, identifier.Substring (0, index), ds, cref);
if (parent == null)
return null;
// no need to detect warning 419 here
var ts = FindDocumentedMember (mc, parent,
identifier.Substring (index + 1),
null, ds, out warn, cref, false, null) as TypeSpec;
if (ts != null)
return ts;
return null;
}
TypeExpr texpr = left as TypeExpr;
if (texpr != null) {
var found = MemberCache.FindNestedType (texpr.Type, ParsedName.Name, ParsedName.Arity);
if (found != null)
return new TypeExpression (found, Location.Null);
//
// Returns a MemberInfo that is referenced in XML documentation
// (by "see" or "seealso" elements).
//
MemberSpec FindDocumentedMember (MemberCore mc,
TypeSpec type, string member_name, AParametersCollection param_list,
DeclSpace ds, out int warning_type, string cref,
bool warn419, string name_for_error)
{
// for (; type != null; type = type.DeclaringType) {
var mi = FindDocumentedMemberNoNest (
mc, type, member_name, param_list, ds,
out warning_type, cref, warn419,
name_for_error);
if (mi != null)
return mi; // new FoundMember (type, mi);
// }
warning_type = 0;
return null;
}
MemberSpec FindDocumentedMemberNoNest (
MemberCore mc, TypeSpec type, string member_name,
AParametersCollection param_list, DeclSpace ds, out int warning_type,
string cref, bool warn419, string name_for_error)
{
warning_type = 0;
// var filter = new MemberFilter (member_name, 0, MemberKind.All, param_list, null);
IList<MemberSpec> found = null;
while (type != null && found == null) {
found = MemberCache.FindMembers (type, member_name, false);
type = type.DeclaringType;
}
if (found == null)
return null;
if (warn419 && found.Count > 1) {
Report419 (mc, name_for_error, found.ToArray ());
}
return found [0];
/*
if (param_list == null) {
// search for fields/events etc.
mis = TypeManager.MemberLookup (type, null,
type, MemberKind.All,
BindingRestriction.None,
member_name, null);
mis = FilterOverridenMembersOut (mis);
if (mis == null || mis.Length == 0)
return null;
if (warn419 && IsAmbiguous (mis))
Report419 (mc, name_for_error, mis, Report);
return mis [0];
}
MethodSignature msig = new MethodSignature (member_name, null, param_list);
mis = FindMethodBase (type,
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance,
msig);
if (warn419 && mis.Length > 0) {
if (IsAmbiguous (mis))
Report419 (mc, name_for_error, mis, Report);
return mis [0];
}
// search for operators (whose parameters exactly
// matches with the list) and possibly report CS1581.
string oper = null;
string return_type_name = null;
if (member_name.StartsWith ("implicit operator ")) {
Operator.GetMetadataName (Operator.OpType.Implicit);
return_type_name = member_name.Substring (18).Trim (wsChars);
}
else if (member_name.StartsWith ("explicit operator ")) {
oper = Operator.GetMetadataName (Operator.OpType.Explicit);
return_type_name = member_name.Substring (18).Trim (wsChars);
}
else if (member_name.StartsWith ("operator ")) {
oper = member_name.Substring (9).Trim (wsChars);
switch (oper) {
// either unary or binary
case "+":
oper = param_list.Length == 2 ?
Operator.GetMetadataName (Operator.OpType.Addition) :
Operator.GetMetadataName (Operator.OpType.UnaryPlus);
break;
case "-":
oper = param_list.Length == 2 ?
Operator.GetMetadataName (Operator.OpType.Subtraction) :
Operator.GetMetadataName (Operator.OpType.UnaryNegation);
break;
default:
oper = Operator.GetMetadataName (oper);
if (oper != null)
break;
warning_type = 1584;
Report.Warning (1020, 1, mc.Location, "Overloadable {0} operator is expected", param_list.Length == 2 ? "binary" : "unary");
Report.Warning (1584, 1, mc.Location, "XML comment on `{0}' has syntactically incorrect cref attribute `{1}'",
mc.GetSignatureForError (), cref);
return null;
}
}
// here we still don't consider return type (to
// detect CS1581 or CS1002+CS1584).
msig = new MethodSignature (oper, null, param_list);
mis = FindMethodBase (type,
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance,
msig);
if (mis.Length == 0)
return null; // CS1574
var mi = mis [0];
TypeSpec expected = mi is MethodSpec ?
((MethodSpec) mi).ReturnType :
mi is PropertySpec ?
((PropertySpec) mi).PropertyType :
null;
if (return_type_name != null) {
TypeSpec returnType = FindDocumentedType (mc, return_type_name, ds, cref, Report);
if (returnType == null || returnType != expected) {
warning_type = 1581;
Report.Warning (1581, 1, mc.Location, "Invalid return type in XML comment cref attribute `{0}'", cref);
return null;
}
}
return mis [0];
*/
return left;
}
//
// Processes "see" or "seealso" elements.
// Checks cref attribute.
// Processes "see" or "seealso" elements from cref attribute.
//
void HandleXrefCommon (MemberCore mc, DeclSpace ds, XmlElement xref)
{
string cref = xref.GetAttribute ("cref").Trim (wsChars);
string cref = xref.GetAttribute ("cref");
// when, XmlReader, "if (cref == null)"
if (!xref.HasAttribute ("cref"))
return;
if (cref.Length == 0)
Report.Warning (1001, 1, mc.Location, "Identifier expected");
// ... and continue until CS1584.
string signature; // "x:" are stripped
string name; // method invokation "(...)" are removed
string parameters; // method parameter list
// When it found '?:' ('T:' 'M:' 'F:' 'P:' 'E:' etc.),
// MS ignores not only its member kind, but also
// the entire syntax correctness. Nor it also does
// type fullname resolution i.e. "T:List(int)" is kept
// as T:List(int), not
// T:System.Collections.Generic.List&lt;System.Int32&gt;
// Nothing to be resolved the reference is marked explicitly
if (cref.Length > 2 && cref [1] == ':')
return;
else
signature = cref;
// Also note that without "T:" any generic type
// indication fails.
int parens_pos = signature.IndexOf ('(');
int brace_pos = parens_pos >= 0 ? -1 :
signature.IndexOf ('[');
if (parens_pos > 0 && signature [signature.Length - 1] == ')') {
name = signature.Substring (0, parens_pos).Trim (wsChars);
parameters = signature.Substring (parens_pos + 1, signature.Length - parens_pos - 2).Trim (wsChars);
}
else if (brace_pos > 0 && signature [signature.Length - 1] == ']') {
name = signature.Substring (0, brace_pos).Trim (wsChars);
parameters = signature.Substring (brace_pos + 1, signature.Length - brace_pos - 2).Trim (wsChars);
}
else {
name = signature;
parameters = null;
}
Normalize (mc, ref name);
string identifier = GetBodyIdentifierFromName (name);
// Check if identifier is valid.
// This check is not necessary to mark as error, but
// csc specially reports CS1584 for wrong identifiers.
string [] name_elems = identifier.Split ('.');
for (int i = 0; i < name_elems.Length; i++) {
string nameElem = GetBodyIdentifierFromName (name_elems [i]);
if (i > 0)
Normalize (mc, ref nameElem);
if (!Tokenizer.IsValidIdentifier (nameElem)
&& nameElem.IndexOf ("operator") < 0) {
Report.Warning (1584, 1, mc.Location, "XML comment on `{0}' has syntactically incorrect cref attribute `{1}'",
mc.GetSignatureForError (), cref);
xref.SetAttribute ("cref", "!:" + signature);
return;
}
// Additional symbols for < and > are allowed for easier XML typing
cref = cref.Replace ('{', '<').Replace ('}', '>');
var encoding = module.Compiler.Settings.Encoding;
var s = new MemoryStream (encoding.GetBytes (cref));
SeekableStreamReader seekable = new SeekableStreamReader (s, encoding);
var source_file = new CompilationSourceFile ("{documentation}", "", 1);
var doc_module = new ModuleContainer (module.Compiler);
doc_module.DocumentationBuilder = this;
source_file.NamespaceContainer = new NamespaceContainer (null, doc_module, null, source_file);
Report parse_report = new Report (new NullReportPrinter ());
var parser = new CSharpParser (seekable, source_file, parse_report);
ParsedParameters = null;
ParsedName = null;
ParsedBuiltinType = null;
ParsedOperator = null;
parser.Lexer.putback_char = Tokenizer.DocumentationXref;
parser.Lexer.parsing_generic_declaration_doc = true;
parser.parse ();
if (parse_report.Errors > 0) {
Report.Warning (1584, 1, mc.Location, "XML comment on `{0}' has syntactically incorrect cref attribute `{1}'",
mc.GetSignatureForError (), cref);
xref.SetAttribute ("cref", "!:" + cref);
return;
}
// check if parameters are valid
AParametersCollection parameter_types;
if (parameters == null)
parameter_types = null;
else if (parameters.Length == 0)
parameter_types = ParametersCompiled.EmptyReadOnlyParameters;
else {
string [] param_list = parameters.Split (',');
var plist = new List<TypeSpec> ();
for (int i = 0; i < param_list.Length; i++) {
string param_type_name = param_list [i].Trim (wsChars);
Normalize (mc, ref param_type_name);
TypeSpec param_type = FindDocumentedType (mc, param_type_name, ds, cref);
if (param_type == null) {
Report.Warning (1580, 1, mc.Location, "Invalid type for parameter `{0}' in XML comment cref attribute `{1}'",
(i + 1).ToString (), cref);
return;
MemberSpec member;
string prefix = null;
FullNamedExpression fne = null;
//
// Try built-in type first because we are using ParsedName as identifier of
// member names on built-in types
//
if (ParsedBuiltinType != null && (ParsedParameters == null || ParsedName != null)) {
member = ParsedBuiltinType.Type;
} else {
member = null;
}
if (ParsedName != null || ParsedOperator.HasValue) {
TypeSpec type = null;
string member_name = null;
if (member == null) {
if (ParsedOperator.HasValue) {
type = mc.CurrentType;
} else if (ParsedName.Left != null) {
fne = ResolveMemberName (mc, ParsedName.Left);
if (fne != null) {
var ns = fne as Namespace;
if (ns != null) {
fne = ns.Lookup (mc, ParsedName.Name, ParsedName.Arity, Location.Null);
if (fne != null) {
member = fne.Type;
}
} else {
type = fne.Type;
}
}
} else {
fne = ResolveMemberName (mc, ParsedName);
if (fne == null) {
type = mc.CurrentType;
} else if (ParsedParameters == null) {
member = fne.Type;
} else if (fne.Type.MemberDefinition == mc.CurrentType.MemberDefinition) {
member_name = Constructor.ConstructorName;
type = fne.Type;
}
}
plist.Add (param_type);
} else {
type = (TypeSpec) member;
member = null;
}
parameter_types = ParametersCompiled.CreateFullyResolved (plist.ToArray ());
}
TypeSpec type = FindDocumentedType (mc, name, ds, cref);
if (type != null
// delegate must not be referenced with args
&& (!type.IsDelegate
|| parameter_types == null)) {
string result = GetSignatureForDoc (type)
+ (brace_pos < 0 ? String.Empty : signature.Substring (brace_pos));
xref.SetAttribute ("cref", "T:" + result);
return; // a type
}
if (ParsedParameters != null) {
foreach (var pp in ParsedParameters) {
pp.Resolve (mc);
}
}
int period = name.LastIndexOf ('.');
if (period > 0) {
string typeName = name.Substring (0, period);
string member_name = name.Substring (period + 1);
string lookup_name = member_name == "this" ? MemberCache.IndexerNameAlias : member_name;
Normalize (mc, ref lookup_name);
Normalize (mc, ref member_name);
type = FindDocumentedType (mc, typeName, ds, cref);
int warn_result;
if (type != null) {
var mi = FindDocumentedMember (mc, type, lookup_name, parameter_types, ds, out warn_result, cref, true, name);
if (warn_result > 0)
return;
if (mi != null) {
// we cannot use 'type' directly
// to get its name, since mi
// could be from DeclaringType
// for nested types.
xref.SetAttribute ("cref", GetMemberDocHead (mi) + GetSignatureForDoc (mi.DeclaringType) + "." + member_name + GetParametersFormatted (mi));
return; // a member of a type
if (member_name == null)
member_name = ParsedOperator.HasValue ?
Operator.GetMetadataName (ParsedOperator.Value) : ParsedName.Name;
int parsed_param_count;
if (ParsedOperator == Operator.OpType.Explicit || ParsedOperator == Operator.OpType.Implicit) {
parsed_param_count = ParsedParameters.Count - 1;
} else if (ParsedParameters != null) {
parsed_param_count = ParsedParameters.Count;
} else {
parsed_param_count = 0;
}
}
} else {
int warn_result;
var mi = FindDocumentedMember (mc, ds.PartialContainer.Definition, name, parameter_types, ds, out warn_result, cref, true, name);
if (warn_result > 0)
return;
if (mi != null) {
// we cannot use 'type' directly
// to get its name, since mi
// could be from DeclaringType
// for nested types.
xref.SetAttribute ("cref", GetMemberDocHead (mi) + GetSignatureForDoc (mi.DeclaringType) + "." + name + GetParametersFormatted (mi));
return; // local member name
}
}
// It still might be part of namespace name.
Namespace ns = ds.NamespaceEntry.NS.GetNamespace (name, false);
if (ns != null) {
xref.SetAttribute ("cref", "N:" + ns.GetSignatureForError ());
return; // a namespace
}
if (mc.Module.GlobalRootNamespace.IsNamespace (name)) {
xref.SetAttribute ("cref", "N:" + name);
return; // a namespace
}
int parameters_match = -1;
do {
var members = MemberCache.FindMembers (type, member_name, true);
if (members != null) {
foreach (var m in members) {
if (ParsedName != null && m.Arity != ParsedName.Arity)
continue;
if (ParsedParameters != null) {
IParametersMember pm = m as IParametersMember;
if (pm == null)
continue;
if (m.Kind == MemberKind.Operator && !ParsedOperator.HasValue)
continue;
int i;
for (i = 0; i < parsed_param_count; ++i) {
var pparam = ParsedParameters[i];
if (i >= pm.Parameters.Count || pparam == null ||
pparam.TypeSpec != pm.Parameters.Types[i] ||
(pparam.Modifier & Parameter.Modifier.SignatureMask) != (pm.Parameters.FixedParameters[i].ModFlags & Parameter.Modifier.SignatureMask)) {
if (i > parameters_match) {
parameters_match = i;
}
i = -1;
break;
}
}
if (i < 0)
continue;
if (ParsedOperator == Operator.OpType.Explicit || ParsedOperator == Operator.OpType.Implicit) {
if (pm.MemberType != ParsedParameters[parsed_param_count].TypeSpec) {
parameters_match = parsed_param_count + 1;
continue;
}
} else {
if (parsed_param_count != pm.Parameters.Count)
continue;
}
}
if (member != null) {
Report.Warning (419, 3, mc.Location,
"Ambiguous reference in cref attribute `{0}'. Assuming `{1}' but other overloads including `{2}' have also matched",
cref, member.GetSignatureForError (), m.GetSignatureForError ());
break;
}
member = m;
}
}
Report.Warning (1574, 1, mc.Location, "XML comment on `{0}' has cref attribute `{1}' that could not be resolved",
mc.GetSignatureForError (), cref);
// Continue with parent type for nested types
if (member == null) {
type = type.DeclaringType;
} else {
type = null;
}
} while (type != null);
xref.SetAttribute ("cref", "!:" + name);
}
if (member == null && parameters_match >= 0) {
for (int i = parameters_match; i < parsed_param_count; ++i) {
Report.Warning (1580, 1, mc.Location, "Invalid type for parameter `{0}' in XML comment cref attribute `{1}'",
(i + 1).ToString (), cref);
}
static string GetParametersFormatted (MemberSpec mi)
{
var pm = mi as IParametersMember;
if (pm == null || pm.Parameters.IsEmpty)
return string.Empty;
AParametersCollection parameters = pm.Parameters;
/*
if (parameters == null || parameters.Count == 0)
return String.Empty;
*/
StringBuilder sb = new StringBuilder ();
sb.Append ('(');
for (int i = 0; i < parameters.Count; i++) {
// if (is_setter && i + 1 == parameters.Count)
// break; // skip "value".
if (i > 0)
sb.Append (',');
TypeSpec t = parameters.Types [i];
sb.Append (GetSignatureForDoc (t));
if (parameters_match == parsed_param_count + 1) {
Report.Warning (1581, 1, mc.Location, "Invalid return type in XML comment cref attribute `{0}'", cref);
}
}
}
}
sb.Append (')');
return sb.ToString ();
}
static string GetBodyIdentifierFromName (string name)
{
string identifier = name;
if (name.Length > 0 && name [name.Length - 1] == ']') {
string tmp = name.Substring (0, name.Length - 1).Trim (wsChars);
int last = tmp.LastIndexOf ('[');
if (last > 0)
identifier = tmp.Substring (0, last).Trim (wsChars);
if (member == null) {
Report.Warning (1574, 1, mc.Location, "XML comment on `{0}' has cref attribute `{1}' that could not be resolved",
mc.GetSignatureForError (), cref);
cref = "!:" + cref;
} else if (member == InternalType.Namespace) {
cref = "N:" + fne.GetSignatureForError ();
} else {
prefix = GetMemberDocHead (member);
cref = prefix + member.GetSignatureForDocumentation ();
}
return identifier;
}
void Report419 (MemberCore mc, string member_name, MemberSpec [] mis)
{
Report.Warning (419, 3, mc.Location,
"Ambiguous reference in cref attribute `{0}'. Assuming `{1}' but other overloads including `{2}' have also matched",
member_name,
TypeManager.GetFullNameSignature (mis [0]),
TypeManager.GetFullNameSignature (mis [1]));
xref.SetAttribute ("cref", cref);
}
//
@ -659,97 +475,7 @@ namespace Mono.CSharp @@ -659,97 +475,7 @@ namespace Mono.CSharp
if (type is TypeSpec)
return "T:";
return "!:";
}
// MethodCore
//
// Returns a string that represents the signature for this
// member which should be used in XML documentation.
//
public static string GetMethodDocCommentName (MemberCore mc, ParametersCompiled parameters)
{
IParameterData [] plist = parameters.FixedParameters;
string paramSpec = String.Empty;
if (plist != null) {
StringBuilder psb = new StringBuilder ();
int i = 0;
foreach (Parameter p in plist) {
psb.Append (psb.Length != 0 ? "," : "(");
psb.Append (GetSignatureForDoc (parameters.Types [i++]));
if ((p.ModFlags & Parameter.Modifier.ISBYREF) != 0)
psb.Append ('@');
}
paramSpec = psb.ToString ();
}
if (paramSpec.Length > 0)
paramSpec += ")";
string name = mc.Name;
if (mc is Constructor)
name = "#ctor";
else if (mc is InterfaceMemberBase) {
var imb = (InterfaceMemberBase) mc;
name = imb.GetFullName (imb.ShortName);
}
name = name.Replace ('.', '#');
if (mc.MemberName.TypeArguments != null && mc.MemberName.TypeArguments.Count > 0)
name += "``" + mc.MemberName.CountTypeArguments;
string suffix = String.Empty;
Operator op = mc as Operator;
if (op != null) {
switch (op.OperatorType) {
case Operator.OpType.Implicit:
case Operator.OpType.Explicit:
suffix = "~" + GetSignatureForDoc (op.ReturnType);
break;
}
}
return String.Concat (mc.DocCommentHeader, mc.Parent.Name, ".", name, paramSpec, suffix);
}
static string GetSignatureForDoc (TypeSpec type)
{
var tp = type as TypeParameterSpec;
if (tp != null) {
int c = 0;
type = type.DeclaringType;
while (type != null && type.DeclaringType != null) {
type = type.DeclaringType;
c += type.MemberDefinition.TypeParametersCount;
}
var prefix = tp.IsMethodOwned ? "``" : "`";
return prefix + (c + tp.DeclaredPosition);
}
var pp = type as PointerContainer;
if (pp != null)
return GetSignatureForDoc (pp.Element) + "*";
ArrayContainer ap = type as ArrayContainer;
if (ap != null)
return GetSignatureForDoc (ap.Element) +
ArrayContainer.GetPostfixSignature (ap.Rank);
if (TypeManager.IsGenericType (type)) {
string g = type.MemberDefinition.Namespace;
if (g != null && g.Length > 0)
g += '.';
int idx = type.Name.LastIndexOf ('`');
g += (idx < 0 ? type.Name : type.Name.Substring (0, idx)) + '{';
int argpos = 0;
foreach (TypeSpec t in TypeManager.GetTypeArguments (type))
g += (argpos++ > 0 ? "," : String.Empty) + GetSignatureForDoc (t);
g += '}';
return g;
}
string name = type.GetMetaInfo ().FullName != null ? type.GetMetaInfo ().FullName : type.Name;
return name.Replace ("+", ".").Replace ('&', '@');
throw new NotImplementedException (type.GetType ().ToString ());
}
//
@ -759,62 +485,43 @@ namespace Mono.CSharp @@ -759,62 +485,43 @@ namespace Mono.CSharp
// FIXME: with a few effort, it could be done with XmlReader,
// that means removal of DOM use.
//
internal static void OnMethodGenerateDocComment (
MethodCore mc, XmlElement el, Report Report)
void CheckParametersComments (MemberCore member, IParametersMember paramMember, XmlElement el)
{
var paramTags = new Dictionary<string, string> ();
HashSet<string> found_tags = null;
foreach (XmlElement pelem in el.SelectNodes ("param")) {
string xname = pelem.GetAttribute ("name");
if (xname.Length == 0)
continue; // really? but MS looks doing so
if (xname != "" && mc.ParameterInfo.GetParameterIndexByName (xname) < 0)
Report.Warning (1572, 2, mc.Location, "XML comment on `{0}' has a param tag for `{1}', but there is no parameter by that name",
mc.GetSignatureForError (), xname);
else if (paramTags.ContainsKey (xname))
Report.Warning (1571, 2, mc.Location, "XML comment on `{0}' has a duplicate param tag for `{1}'",
mc.GetSignatureForError (), xname);
paramTags [xname] = xname;
}
IParameterData [] plist = mc.ParameterInfo.FixedParameters;
foreach (Parameter p in plist) {
if (paramTags.Count > 0 && !paramTags.ContainsKey (p.Name))
Report.Warning (1573, 4, mc.Location, "Parameter `{0}' has no matching param tag in the XML comment for `{1}'",
p.Name, mc.GetSignatureForError ());
}
}
void Normalize (MemberCore mc, ref string name)
{
if (name.Length > 0 && name [0] == '@')
name = name.Substring (1);
else if (name == "this")
name = "Item";
else if (Tokenizer.IsKeyword (name) && !IsTypeName (name))
Report.Warning (1041, 1, mc.Location, "Identifier expected. `{0}' is a keyword", name);
}
if (found_tags == null) {
found_tags = new HashSet<string> ();
}
private static bool IsTypeName (string name)
{
switch (name) {
case "bool":
case "byte":
case "char":
case "decimal":
case "double":
case "float":
case "int":
case "long":
case "object":
case "sbyte":
case "short":
case "string":
case "uint":
case "ulong":
case "ushort":
case "void":
return true;
if (xname != "" && paramMember.Parameters.GetParameterIndexByName (xname) < 0) {
Report.Warning (1572, 2, member.Location,
"XML comment on `{0}' has a param tag for `{1}', but there is no parameter by that name",
member.GetSignatureForError (), xname);
continue;
}
if (found_tags.Contains (xname)) {
Report.Warning (1571, 2, member.Location,
"XML comment on `{0}' has a duplicate param tag for `{1}'",
member.GetSignatureForError (), xname);
continue;
}
found_tags.Add (xname);
}
if (found_tags != null) {
foreach (Parameter p in paramMember.Parameters.FixedParameters) {
if (!found_tags.Contains (p.Name) && !(p is ArglistParameter))
Report.Warning (1573, 4, member.Location,
"Parameter `{0}' has no matching param tag in the XML comment for `{1}'",
p.Name, member.GetSignatureForError ());
}
}
return false;
}
//
@ -843,7 +550,7 @@ namespace Mono.CSharp @@ -843,7 +550,7 @@ namespace Mono.CSharp
w.WriteEndDocument ();
return true;
} catch (Exception ex) {
module.Compiler.Report.Error (1569, "Error generating XML documentation file `{0}' (`{1}')", xmlFileName, ex.Message);
Report.Error (1569, "Error generating XML documentation file `{0}' (`{1}')", xmlFileName, ex.Message);
return false;
} finally {
if (w != null)
@ -851,4 +558,32 @@ namespace Mono.CSharp @@ -851,4 +558,32 @@ namespace Mono.CSharp
}
}
}
class DocumentationParameter
{
public readonly Parameter.Modifier Modifier;
public FullNamedExpression Type;
public DocumentationParameter (Parameter.Modifier modifier, FullNamedExpression type)
: this (type)
{
this.Modifier = modifier;
}
public DocumentationParameter (FullNamedExpression type)
{
this.Type = type;
}
public TypeSpec TypeSpec {
get {
return Type == null ? null : Type.Type;
}
}
public void Resolve (IMemberContext context)
{
Type = Type.ResolveAsTypeTerminal (context, true);
}
}
}

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

@ -110,7 +110,7 @@ namespace Mono.CSharp @@ -110,7 +110,7 @@ namespace Mono.CSharp
public void Parse (SeekableStreamReader reader, CompilationSourceFile file, ModuleContainer module)
{
file.NamespaceContainer = new NamespaceEntry (module, null, file, null);
file.NamespaceContainer = new NamespaceContainer (null, module, null, file);
CSharpParser parser = new CSharpParser (reader, file);
parser.parse ();
@ -439,7 +439,7 @@ namespace Mono.CSharp @@ -439,7 +439,7 @@ namespace Mono.CSharp
var files = new List<CompilationSourceFile> ();
var unit = new CompilationSourceFile (inputFile, inputFile, 0);
var module = new ModuleContainer (ctx);
unit.NamespaceContainer = new NamespaceEntry (module, null, unit, null);
unit.NamespaceContainer = new NamespaceContainer (null, module, null, unit);
files.Add (unit);
Location.Initialize (files);

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

@ -232,7 +232,7 @@ namespace Mono.CSharp @@ -232,7 +232,7 @@ namespace Mono.CSharp
{
Child = new IntConstant (ec.BuiltinTypes, (int) (flags | statement.flags), statement.loc);
type = ec.Module.PredefinedTypes.BinderFlags.Resolve (loc);
type = ec.Module.PredefinedTypes.BinderFlags.Resolve ();
eclass = Child.eclass;
return this;
}
@ -283,9 +283,9 @@ namespace Mono.CSharp @@ -283,9 +283,9 @@ namespace Mono.CSharp
int errors = rc.Report.Errors;
var pt = rc.Module.PredefinedTypes;
binder_type = pt.Binder.Resolve (loc);
pt.CallSite.Resolve (loc);
pt.CallSiteGeneric.Resolve (loc);
binder_type = pt.Binder.Resolve ();
pt.CallSite.Resolve ();
pt.CallSiteGeneric.Resolve ();
eclass = ExprClass.Value;
@ -382,7 +382,7 @@ namespace Mono.CSharp @@ -382,7 +382,7 @@ namespace Mono.CSharp
TypeExpr te = null;
Namespace type_ns = module.GlobalRootNamespace.GetNamespace ("System", true);
if (type_ns != null) {
te = type_ns.LookupType (module, d_name, dyn_args_count + default_args, true, Location.Null);
te = type_ns.LookupType (module, d_name, dyn_args_count + default_args, Location.Null);
}
if (te != null) {

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

@ -316,10 +316,11 @@ namespace Mono.CSharp { @@ -316,10 +316,11 @@ namespace Mono.CSharp {
}
}
public void Error_TypeArgumentsCannotBeUsed (Report report, Location loc, MemberSpec member, int arity)
public void Error_TypeArgumentsCannotBeUsed (IMemberContext context, MemberSpec member, int arity, Location loc)
{
// Better message for possible generic expressions
if (member != null && (member.Kind & MemberKind.GenericMask) != 0) {
var report = context.Module.Compiler.Report;
report.SymbolRelatedToPreviousError (member);
if (member is TypeSpec)
member = ((TypeSpec) member).GetDefinition ();
@ -335,13 +336,13 @@ namespace Mono.CSharp { @@ -335,13 +336,13 @@ namespace Mono.CSharp {
name, member.GetSignatureForError ());
}
} else {
Error_TypeArgumentsCannotBeUsed (report, ExprClassName, GetSignatureForError (), loc);
Error_TypeArgumentsCannotBeUsed (context, ExprClassName, GetSignatureForError (), loc);
}
}
public void Error_TypeArgumentsCannotBeUsed (Report report, string exprType, string name, Location loc)
public void Error_TypeArgumentsCannotBeUsed (IMemberContext context, string exprType, string name, Location loc)
{
report.Error (307, loc, "The {0} `{1}' cannot be used with type arguments",
context.Module.Compiler.Report.Error (307, loc, "The {0} `{1}' cannot be used with type arguments",
exprType, name);
}
@ -564,7 +565,15 @@ namespace Mono.CSharp { @@ -564,7 +565,15 @@ namespace Mono.CSharp {
}
var r = new OverloadResolver (ctors, OverloadResolver.Restrictions.NoBaseMembers, loc);
return r.ResolveMember<MethodSpec> (rc, ref args);
var ctor = r.ResolveMember<MethodSpec> (rc, ref args);
if (ctor == null)
return null;
if ((ctor.Modifiers & Modifiers.PROTECTED) != 0 && !rc.HasSet (ResolveContext.Options.BaseInitializer)) {
MemberExpr.CheckProtectedMemberAccess (rc, ctor, ctor.DeclaringType, loc);
}
return ctor;
}
[Flags]
@ -913,7 +922,7 @@ namespace Mono.CSharp { @@ -913,7 +922,7 @@ namespace Mono.CSharp {
protected static TypeExpr CreateExpressionTypeExpression (ResolveContext ec, Location loc)
{
var t = ec.Module.PredefinedTypes.Expression.Resolve (loc);
var t = ec.Module.PredefinedTypes.Expression.Resolve ();
if (t == null)
return null;
@ -2143,7 +2152,7 @@ namespace Mono.CSharp { @@ -2143,7 +2152,7 @@ namespace Mono.CSharp {
FullNamedExpression retval = ec.LookupNamespaceOrType (Name, -System.Math.Max (1, Arity), loc, true);
if (retval != null) {
Error_TypeArgumentsCannotBeUsed (ec.Module.Compiler.Report, loc, retval.Type, Arity);
Error_TypeArgumentsCannotBeUsed (ec, retval.Type, Arity, loc);
/*
var te = retval as TypeExpr;
if (HasTypeArguments && te != null && !te.Type.IsGeneric)
@ -2154,7 +2163,7 @@ namespace Mono.CSharp { @@ -2154,7 +2163,7 @@ namespace Mono.CSharp {
return;
}
NamespaceEntry.Error_NamespaceNotFound (loc, Name, ec.Module.Compiler.Report);
NamespaceContainer.Error_NamespaceNotFound (loc, Name, ec.Module.Compiler.Report);
}
protected override Expression DoResolve (ResolveContext ec)
@ -2235,7 +2244,7 @@ namespace Mono.CSharp { @@ -2235,7 +2244,7 @@ namespace Mono.CSharp {
e = variable.CreateReferenceExpression (rc, loc);
if (e != null) {
if (Arity > 0)
Error_TypeArgumentsCannotBeUsed (rc.Report, "variable", Name, loc);
Error_TypeArgumentsCannotBeUsed (rc, "variable", Name, loc);
return e;
}
@ -2335,6 +2344,32 @@ namespace Mono.CSharp { @@ -2335,6 +2344,32 @@ namespace Mono.CSharp {
if (variable_found) {
rc.Report.Error (841, loc, "A local variable `{0}' cannot be used before it is declared", Name);
} else {
if (Arity > 0) {
TypeParameter[] tparams = rc.CurrentTypeParameters;
if (tparams != null) {
foreach (var ctp in tparams) {
if (ctp.Name == Name) {
Error_TypeArgumentsCannotBeUsed (rc, "type parameter", Name, loc);
return null;
}
}
}
var ct = rc.CurrentType;
do {
if (ct.MemberDefinition.TypeParametersCount > 0) {
foreach (var ctp in ct.MemberDefinition.TypeParameters) {
if (ctp.Name == Name) {
Error_TypeArgumentsCannotBeUsed (rc, "type parameter", Name, loc);
return null;
}
}
}
ct = ct.DeclaringType;
} while (ct != null);
}
rc.Report.Error (103, loc, "The name `{0}' does not exist in the current context", Name);
}
@ -2588,21 +2623,25 @@ namespace Mono.CSharp { @@ -2588,21 +2623,25 @@ namespace Mono.CSharp {
return;
if ((member.Modifiers & Modifiers.PROTECTED) != 0 && !(InstanceExpression is This)) {
var ct = rc.CurrentType;
var expr_type = InstanceExpression.Type;
if (ct == expr_type)
return;
CheckProtectedMemberAccess (rc, member, InstanceExpression.Type, loc);
}
}
if ((member.Modifiers & Modifiers.INTERNAL) != 0 && member.DeclaringType.MemberDefinition.IsInternalAsPublic (ct.MemberDefinition.DeclaringAssembly))
return;
public static void CheckProtectedMemberAccess<T> (ResolveContext rc, T member, TypeSpec qualifier, Location loc) where T : MemberSpec
{
var ct = rc.CurrentType;
if (ct == qualifier)
return;
expr_type = expr_type.GetDefinition ();
if (ct != expr_type && !IsSameOrBaseQualifier (ct, expr_type)) {
rc.Report.SymbolRelatedToPreviousError (member);
rc.Report.Error (1540, loc,
"Cannot access protected member `{0}' via a qualifier of type `{1}'. The qualifier must be of type `{2}' or derived from it",
member.GetSignatureForError (), expr_type.GetSignatureForError (), ct.GetSignatureForError ());
}
if ((member.Modifiers & Modifiers.INTERNAL) != 0 && member.DeclaringType.MemberDefinition.IsInternalAsPublic (ct.MemberDefinition.DeclaringAssembly))
return;
qualifier = qualifier.GetDefinition ();
if (ct != qualifier && !IsSameOrBaseQualifier (ct, qualifier)) {
rc.Report.SymbolRelatedToPreviousError (member);
rc.Report.Error (1540, loc,
"Cannot access protected member `{0}' via a qualifier of type `{1}'. The qualifier must be of type `{2}' or derived from it",
member.GetSignatureForError (), qualifier.GetSignatureForError (), ct.GetSignatureForError ());
}
}
@ -2817,10 +2856,10 @@ namespace Mono.CSharp { @@ -2817,10 +2856,10 @@ namespace Mono.CSharp {
//
class ExtensionMethodGroupExpr : MethodGroupExpr, OverloadResolver.IErrorHandler
{
NamespaceEntry namespace_entry;
NamespaceContainer namespace_entry;
public readonly Expression ExtensionExpression;
public ExtensionMethodGroupExpr (IList<MethodSpec> list, NamespaceEntry n, Expression extensionExpr, Location l)
public ExtensionMethodGroupExpr (IList<MethodSpec> list, NamespaceContainer n, Expression extensionExpr, Location l)
: base (list.Cast<MemberSpec>().ToList (), extensionExpr.Type, l)
{
this.namespace_entry = n;
@ -2956,6 +2995,12 @@ namespace Mono.CSharp { @@ -2956,6 +2995,12 @@ namespace Mono.CSharp {
}
}
public IList<MemberSpec> Candidates {
get {
return Methods;
}
}
protected override TypeSpec DeclaringType {
get {
return queried_type;
@ -3173,7 +3218,7 @@ namespace Mono.CSharp { @@ -3173,7 +3218,7 @@ namespace Mono.CSharp {
return null;
int arity = type_arguments == null ? 0 : type_arguments.Count;
NamespaceEntry methods_scope = null;
NamespaceContainer methods_scope = null;
var methods = rc.LookupExtensionMethod (InstanceExpression.Type, Methods[0].Name, arity, ref methods_scope);
if (methods == null)
return null;
@ -4293,6 +4338,13 @@ namespace Mono.CSharp { @@ -4293,6 +4338,13 @@ namespace Mono.CSharp {
return null;
}
//
// These flags indicates we are running delegate probing conversion. No need to
// do more expensive checks
//
if ((restrictions & (Restrictions.ProbingOnly | Restrictions.CovariantDelegate)) == (Restrictions.CovariantDelegate | Restrictions.ProbingOnly))
return (T) best_candidate;
if (ambiguous_candidates != null) {
//
// Now check that there are no ambiguities i.e the selected method
@ -4416,7 +4468,7 @@ namespace Mono.CSharp { @@ -4416,7 +4468,7 @@ namespace Mono.CSharp {
if (ta_count != best_candidate.Arity && (ta_count > 0 || ((IParametersMember) best_candidate).Parameters.IsEmpty)) {
var mg = new MethodGroupExpr (new [] { best_candidate }, best_candidate.DeclaringType, loc);
mg.Error_TypeArgumentsCannotBeUsed (rc.Report, loc, best_candidate, ta_count);
mg.Error_TypeArgumentsCannotBeUsed (rc, best_candidate, ta_count, loc);
return;
}
@ -4643,7 +4695,7 @@ namespace Mono.CSharp { @@ -4643,7 +4695,7 @@ namespace Mono.CSharp {
public class ConstantExpr : MemberExpr
{
ConstSpec constant;
readonly ConstSpec constant;
public ConstantExpr (ConstSpec constant, Location loc)
{
@ -4695,7 +4747,7 @@ namespace Mono.CSharp { @@ -4695,7 +4747,7 @@ namespace Mono.CSharp {
public override void SetTypeArguments (ResolveContext ec, TypeArguments ta)
{
Error_TypeArgumentsCannotBeUsed (ec.Report, "constant", GetSignatureForError (), loc);
Error_TypeArgumentsCannotBeUsed (ec, "constant", GetSignatureForError (), loc);
}
}
@ -4824,32 +4876,34 @@ namespace Mono.CSharp { @@ -4824,32 +4876,34 @@ namespace Mono.CSharp {
{
bool lvalue_instance = rhs != null && IsInstance && spec.DeclaringType.IsStruct;
if (ResolveInstanceExpression (ec, rhs)) {
// Resolve the field's instance expression while flow analysis is turned
// off: when accessing a field "a.b", we must check whether the field
// "a.b" is initialized, not whether the whole struct "a" is initialized.
if (rhs != this) {
if (ResolveInstanceExpression (ec, rhs)) {
// Resolve the field's instance expression while flow analysis is turned
// off: when accessing a field "a.b", we must check whether the field
// "a.b" is initialized, not whether the whole struct "a" is initialized.
if (lvalue_instance) {
using (ec.With (ResolveContext.Options.DoFlowAnalysis, false)) {
bool out_access = rhs == EmptyExpression.OutAccess || rhs == EmptyExpression.LValueMemberOutAccess;
if (lvalue_instance) {
using (ec.With (ResolveContext.Options.DoFlowAnalysis, false)) {
bool out_access = rhs == EmptyExpression.OutAccess || rhs == EmptyExpression.LValueMemberOutAccess;
Expression right_side =
out_access ? EmptyExpression.LValueMemberOutAccess : EmptyExpression.LValueMemberAccess;
Expression right_side =
out_access ? EmptyExpression.LValueMemberOutAccess : EmptyExpression.LValueMemberAccess;
InstanceExpression = InstanceExpression.ResolveLValue (ec, right_side);
}
} else {
using (ec.With (ResolveContext.Options.DoFlowAnalysis, false)) {
InstanceExpression = InstanceExpression.Resolve (ec, ResolveFlags.VariableOrValue);
InstanceExpression = InstanceExpression.ResolveLValue (ec, right_side);
}
} else {
using (ec.With (ResolveContext.Options.DoFlowAnalysis, false)) {
InstanceExpression = InstanceExpression.Resolve (ec, ResolveFlags.VariableOrValue);
}
}
if (InstanceExpression == null)
return null;
}
if (InstanceExpression == null)
return null;
DoBestMemberChecks (ec, spec);
}
DoBestMemberChecks (ec, spec);
var fb = spec as FixedFieldSpec;
IVariableReference var = InstanceExpression as IVariableReference;
@ -5155,7 +5209,7 @@ namespace Mono.CSharp { @@ -5155,7 +5209,7 @@ namespace Mono.CSharp {
public override void SetTypeArguments (ResolveContext ec, TypeArguments ta)
{
Error_TypeArgumentsCannotBeUsed (ec.Report, "field", GetSignatureForError (), loc);
Error_TypeArgumentsCannotBeUsed (ec, "field", GetSignatureForError (), loc);
}
}
@ -5357,7 +5411,7 @@ namespace Mono.CSharp { @@ -5357,7 +5411,7 @@ namespace Mono.CSharp {
public override void SetTypeArguments (ResolveContext ec, TypeArguments ta)
{
Error_TypeArgumentsCannotBeUsed (ec.Report, "property", GetSignatureForError (), loc);
Error_TypeArgumentsCannotBeUsed (ec, "property", GetSignatureForError (), loc);
}
}
@ -5685,7 +5739,7 @@ namespace Mono.CSharp { @@ -5685,7 +5739,7 @@ namespace Mono.CSharp {
public override void SetTypeArguments (ResolveContext ec, TypeArguments ta)
{
Error_TypeArgumentsCannotBeUsed (ec.Report, "event", GetSignatureForError (), loc);
Error_TypeArgumentsCannotBeUsed (ec, "event", GetSignatureForError (), loc);
}
}

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

@ -160,7 +160,7 @@ namespace Mono.CSharp { @@ -160,7 +160,7 @@ namespace Mono.CSharp {
Modifiers.INTERNAL |
Modifiers.PRIVATE;
public Enum (NamespaceEntry ns, DeclSpace parent, TypeExpression type,
public Enum (NamespaceContainer ns, DeclSpace parent, TypeExpression type,
Modifiers mod_flags, MemberName name, Attributes attrs)
: base (ns, parent, name, attrs, MemberKind.Enum)
{

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

@ -76,7 +76,7 @@ namespace Mono.CSharp @@ -76,7 +76,7 @@ namespace Mono.CSharp
module.Evaluator = this;
source_file = new CompilationSourceFile ("{interactive}", "", 1);
source_file.NamespaceContainer = new NamespaceEntry (module, null, source_file, null);
source_file.NamespaceContainer = new NamespaceContainer (null, module, null, source_file);
ctx.SourceFiles.Add (source_file);
@ -528,8 +528,9 @@ namespace Mono.CSharp @@ -528,8 +528,9 @@ namespace Mono.CSharp
Reset ();
Tokenizer.LocatedToken.Initialize ();
Stream s = new MemoryStream (Encoding.Default.GetBytes (input));
SeekableStreamReader seekable = new SeekableStreamReader (s, Encoding.Default);
var enc = ctx.Settings.Encoding;
var s = new MemoryStream (enc.GetBytes (input));
SeekableStreamReader seekable = new SeekableStreamReader (s, enc);
InputKind kind = ToplevelOrStatement (seekable);
if (kind == InputKind.Error){

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

@ -2606,7 +2606,7 @@ namespace Mono.CSharp @@ -2606,7 +2606,7 @@ namespace Mono.CSharp
break;
return left;
}
Error_OperatorCannotBeApplied (ec, this.left, this.right);
return null;
}
@ -3878,7 +3878,7 @@ namespace Mono.CSharp @@ -3878,7 +3878,7 @@ namespace Mono.CSharp
if ((oper & Operator.LogicalMask) != 0)
flags |= CSharpBinderFlags.BinaryOperationLogical;
binder_args.Add (new Argument (new EnumConstant (new IntLiteral (ec.BuiltinTypes, (int) flags, loc), ec.Module.PredefinedTypes.BinderFlags.Resolve (loc))));
binder_args.Add (new Argument (new EnumConstant (new IntLiteral (ec.BuiltinTypes, (int) flags, loc), ec.Module.PredefinedTypes.BinderFlags.Resolve ())));
binder_args.Add (new Argument (new MemberAccess (new MemberAccess (sle, "ExpressionType", loc), GetOperatorExpressionTypeName (), loc)));
binder_args.Add (new Argument (new TypeOf (new TypeExpression (ec.CurrentType, loc), loc)));
binder_args.Add (new Argument (new ImplicitlyTypedArrayCreation (args.CreateDynamicBinderArguments (ec), loc)));
@ -4954,6 +4954,9 @@ namespace Mono.CSharp @@ -4954,6 +4954,9 @@ namespace Mono.CSharp
bool DoResolveBase (ResolveContext ec)
{
if (eclass != ExprClass.Unresolved)
return true;
type = pi.ParameterType;
eclass = ExprClass.Variable;
@ -7027,7 +7030,7 @@ namespace Mono.CSharp @@ -7027,7 +7030,7 @@ namespace Mono.CSharp
protected override Expression DoResolve (ResolveContext ec)
{
eclass = ExprClass.Variable;
type = ec.Module.PredefinedTypes.RuntimeArgumentHandle.Resolve (loc);
type = ec.Module.PredefinedTypes.RuntimeArgumentHandle.Resolve ();
if (ec.HasSet (ResolveContext.Options.FieldInitializerScope) || !ec.CurrentBlock.ParametersBlock.Parameters.HasArglist) {
ec.Report.Error (190, loc,
@ -7139,7 +7142,7 @@ namespace Mono.CSharp @@ -7139,7 +7142,7 @@ namespace Mono.CSharp
return null;
type = texpr.Type;
expr = Convert.ImplicitConversionRequired (rc, expr, rc.Module.PredefinedTypes.TypedReference.Resolve (loc), loc);
expr = Convert.ImplicitConversionRequired (rc, expr, rc.Module.PredefinedTypes.TypedReference.Resolve (), loc);
eclass = ExprClass.Value;
return this;
}
@ -7166,7 +7169,7 @@ namespace Mono.CSharp @@ -7166,7 +7169,7 @@ namespace Mono.CSharp
if (expr == null)
return null;
expr = Convert.ImplicitConversionRequired (rc, expr, rc.Module.PredefinedTypes.TypedReference.Resolve (loc), loc);
expr = Convert.ImplicitConversionRequired (rc, expr, rc.Module.PredefinedTypes.TypedReference.Resolve (), loc);
if (expr == null)
return null;
@ -7196,7 +7199,7 @@ namespace Mono.CSharp @@ -7196,7 +7199,7 @@ namespace Mono.CSharp
protected override Expression DoResolve (ResolveContext rc)
{
expr = expr.ResolveLValue (rc, EmptyExpression.LValueMemberAccess);
type = rc.Module.PredefinedTypes.TypedReference.Resolve (loc);
type = rc.Module.PredefinedTypes.TypedReference.Resolve ();
eclass = ExprClass.Value;
return this;
}
@ -7353,9 +7356,9 @@ namespace Mono.CSharp @@ -7353,9 +7356,9 @@ namespace Mono.CSharp
protected override Expression DoResolve (ResolveContext ec)
{
if (member.IsConstructor) {
type = ec.Module.PredefinedTypes.ConstructorInfo.Resolve (loc);
type = ec.Module.PredefinedTypes.ConstructorInfo.Resolve ();
} else {
type = ec.Module.PredefinedTypes.MethodInfo.Resolve (loc);
type = ec.Module.PredefinedTypes.MethodInfo.Resolve ();
}
if (type == null)
@ -7436,7 +7439,7 @@ namespace Mono.CSharp @@ -7436,7 +7439,7 @@ namespace Mono.CSharp
protected override Expression DoResolve (ResolveContext ec)
{
type = ec.Module.PredefinedTypes.FieldInfo.Resolve (loc);
type = ec.Module.PredefinedTypes.FieldInfo.Resolve ();
if (type == null)
return null;
@ -7761,7 +7764,7 @@ namespace Mono.CSharp @@ -7761,7 +7764,7 @@ namespace Mono.CSharp
// Try to look for extension method when member lookup failed
//
if (MethodGroupExpr.IsExtensionMethodArgument (expr)) {
NamespaceEntry scope = null;
NamespaceContainer scope = null;
var methods = rc.LookupExtensionMethod (expr_type, Name, lookup_arity, ref scope);
if (methods != null) {
var emg = new ExtensionMethodGroupExpr (methods, scope, expr, loc);
@ -7935,7 +7938,7 @@ namespace Mono.CSharp @@ -7935,7 +7938,7 @@ namespace Mono.CSharp
var nested = MemberCache.FindNestedType (expr_type, Name, -System.Math.Max (1, Arity));
if (nested != null) {
Error_TypeArgumentsCannotBeUsed (rc.Module.Compiler.Report, expr.Location, nested, Arity);
Error_TypeArgumentsCannotBeUsed (rc, nested, Arity, expr.Location);
return;
}
@ -8634,7 +8637,7 @@ namespace Mono.CSharp @@ -8634,7 +8637,7 @@ namespace Mono.CSharp
public override void SetTypeArguments (ResolveContext ec, TypeArguments ta)
{
Error_TypeArgumentsCannotBeUsed (ec.Report, "indexer", GetSignatureForError (), loc);
Error_TypeArgumentsCannotBeUsed (ec, "indexer", GetSignatureForError (), loc);
}
#region IBaseMembersProvider Members

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

@ -613,7 +613,7 @@ namespace Mono.CSharp @@ -613,7 +613,7 @@ namespace Mono.CSharp
MetaType[] required_modifier = null;
if ((ModFlags & Modifiers.VOLATILE) != 0) {
var mod = Module.PredefinedTypes.IsVolatile.Resolve (Location);
var mod = Module.PredefinedTypes.IsVolatile.Resolve ();
if (mod != null)
required_modifier = new MetaType[] { mod.GetMetaInfo () };
}

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

@ -571,6 +571,11 @@ namespace Mono.CSharp { @@ -571,6 +571,11 @@ namespace Mono.CSharp {
throw new NotSupportedException ();
}
public override string GetSignatureForDocumentation ()
{
throw new NotImplementedException ();
}
public override string GetSignatureForError ()
{
return MemberName.Name;
@ -847,6 +852,19 @@ namespace Mono.CSharp { @@ -847,6 +852,19 @@ namespace Mono.CSharp {
return BaseType;
}
public override string GetSignatureForDocumentation ()
{
int c = 0;
var type = DeclaringType;
while (type != null && type.DeclaringType != null) {
type = type.DeclaringType;
c += type.MemberDefinition.TypeParametersCount;
}
var prefix = IsMethodOwned ? "``" : "`";
return prefix + (c + DeclaredPosition);
}
public override string GetSignatureForError ()
{
return Name;
@ -1943,6 +1961,9 @@ namespace Mono.CSharp { @@ -1943,6 +1961,9 @@ namespace Mono.CSharp {
constraints_checked = true;
if ((type.Modifiers & Modifiers.COMPILER_GENERATED) != 0)
return true;
var gtype = (InflatedTypeSpec) type;
var constraints = gtype.Constraints;
if (constraints == null)
@ -2286,14 +2307,14 @@ namespace Mono.CSharp { @@ -2286,14 +2307,14 @@ namespace Mono.CSharp {
{
ParametersCompiled parameters;
public GenericMethod (NamespaceEntry ns, DeclSpace parent, MemberName name,
public GenericMethod (NamespaceContainer ns, DeclSpace parent, MemberName name,
FullNamedExpression return_type, ParametersCompiled parameters)
: base (ns, parent, name, null)
{
this.parameters = parameters;
}
public GenericMethod (NamespaceEntry ns, DeclSpace parent, MemberName name, TypeParameter[] tparams,
public GenericMethod (NamespaceContainer ns, DeclSpace parent, MemberName name, TypeParameter[] tparams,
FullNamedExpression return_type, ParametersCompiled parameters)
: this (ns, parent, name, return_type, parameters)
{

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

@ -387,20 +387,30 @@ namespace Mono.CSharp @@ -387,20 +387,30 @@ namespace Mono.CSharp
// Cannot set to OVERRIDE without full hierarchy checks
// this flag indicates that the method could be override
// but further validation is needed
if ((mod & Modifiers.OVERRIDE) != 0 && kind == MemberKind.Method && declaringType.BaseType != null) {
var filter = MemberFilter.Method (name, tparams != null ? tparams.Length : 0, parameters, null);
var candidate = MemberCache.FindMember (declaringType.BaseType, filter, BindingRestriction.None);
if ((mod & Modifiers.OVERRIDE) != 0) {
bool is_real_override = false;
if (kind == MemberKind.Method && declaringType.BaseType != null) {
var filter = MemberFilter.Method (name, tparams != null ? tparams.Length : 0, parameters, null);
var candidate = MemberCache.FindMember (declaringType.BaseType, filter, BindingRestriction.None);
//
// For imported class method do additional validation to be sure that metadata
// override flag was correct
//
// Difference between protected internal and protected is ok
//
const Modifiers conflict_mask = Modifiers.AccessibilityMask & ~Modifiers.INTERNAL;
if (candidate == null || (candidate.Modifiers & conflict_mask) != (mod & conflict_mask) || candidate.IsStatic) {
//
// For imported class method do additional validation to be sure that metadata
// override flag was correct
//
// Difference between protected internal and protected is ok
//
const Modifiers conflict_mask = Modifiers.AccessibilityMask & ~Modifiers.INTERNAL;
if (candidate != null && (candidate.Modifiers & conflict_mask) == (mod & conflict_mask) && !candidate.IsStatic) {
is_real_override = true;
}
}
if (!is_real_override) {
mod &= ~Modifiers.OVERRIDE;
mod |= Modifiers.VIRTUAL;
if ((mod & Modifiers.SEALED) != 0)
mod &= ~Modifiers.SEALED;
else
mod |= Modifiers.VIRTUAL;
}
}
}
@ -1168,15 +1178,21 @@ namespace Mono.CSharp @@ -1168,15 +1178,21 @@ namespace Mono.CSharp
return mod;
}
// It can be sealed and override
if ((ma & MethodAttributes.Final) != 0)
mod |= Modifiers.SEALED;
// It can be sealed and override
if ((ma & MethodAttributes.Virtual) != 0) {
if ((ma & MethodAttributes.NewSlot) != 0 || !declaringType.IsClass) {
// No private virtual or sealed virtual
if ((mod & (Modifiers.PRIVATE | Modifiers.SEALED)) == 0)
if ((ma & MethodAttributes.Virtual) != 0 && !declaringType.IsSealed) {
// Not every member can be detected based on MethodAttribute, we
// set virtual or non-virtual only when we are certain. Further checks
// to really find out what `virtual' means for this member are done
// later
if ((ma & MethodAttributes.NewSlot) != 0) {
if ((mod & Modifiers.SEALED) != 0) {
mod &= ~Modifiers.SEALED;
} else {
mod |= Modifiers.VIRTUAL;
}
} else {
mod |= Modifiers.OVERRIDE;
}

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

@ -488,7 +488,7 @@ namespace Mono.CSharp { @@ -488,7 +488,7 @@ namespace Mono.CSharp {
reset.Block = new ToplevelBlock (Compiler, Location);
TypeSpec ex_type = Module.PredefinedTypes.NotSupportedException.Resolve (Location);
TypeSpec ex_type = Module.PredefinedTypes.NotSupportedException.Resolve ();
if (ex_type == null)
return;

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

@ -84,7 +84,7 @@ namespace Mono.CSharp { @@ -84,7 +84,7 @@ namespace Mono.CSharp {
CompileUnitEntry comp_unit;
Dictionary<string, SourceFile> include_files;
Dictionary<string, bool> conditionals;
NamespaceEntry ns_container;
NamespaceContainer ns_container;
public CompilationSourceFile (string name, string fullPathName, int index)
: base (name, fullPathName, index)
@ -99,7 +99,7 @@ namespace Mono.CSharp { @@ -99,7 +99,7 @@ namespace Mono.CSharp {
get { return comp_unit; }
}
public NamespaceEntry NamespaceContainer {
public NamespaceContainer NamespaceContainer {
get {
return ns_container;
}

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

@ -126,27 +126,6 @@ namespace Mono.CSharp { @@ -126,27 +126,6 @@ namespace Mono.CSharp {
return base.CheckBase ();
}
//
// Returns a string that represents the signature for this
// member which should be used in XML documentation.
//
public override string GetDocCommentName ()
{
return DocumentationBuilder.GetMethodDocCommentName (this, parameters);
}
//
// Raised (and passed an XmlElement that contains the comment)
// when GenerateDocComment is writing documentation expectedly.
//
// FIXME: with a few effort, it could be done with XmlReader,
// that means removal of DOM use.
//
internal override void OnGenerateDocComment (XmlElement el)
{
DocumentationBuilder.OnMethodGenerateDocComment (this, el, Report);
}
//
// Represents header string for documentation comment.
//
@ -168,6 +147,15 @@ namespace Mono.CSharp { @@ -168,6 +147,15 @@ namespace Mono.CSharp {
return base.EnableOverloadChecks (overload);
}
public override string GetSignatureForDocumentation ()
{
string s = base.GetSignatureForDocumentation ();
if (MemberName.Arity > 0)
s += "``" + MemberName.Arity.ToString ();
return s + parameters.GetSignatureForDocumentation ();
}
public MethodSpec Spec {
get { return spec; }
}
@ -349,6 +337,36 @@ namespace Mono.CSharp { @@ -349,6 +337,36 @@ namespace Mono.CSharp {
return inflatedMetaInfo;
}
public override string GetSignatureForDocumentation ()
{
string name;
switch (Kind) {
case MemberKind.Constructor:
name = "#ctor";
break;
case MemberKind.Method:
if (Arity > 0)
name = Name + "``" + Arity.ToString ();
else
name = Name;
break;
default:
name = Name;
break;
}
name = DeclaringType.GetSignatureForDocumentation () + "." + name + parameters.GetSignatureForDocumentation ();
if (Kind == MemberKind.Operator) {
var op = Operator.GetType (Name).Value;
if (op == Operator.OpType.Explicit || op == Operator.OpType.Implicit) {
name += "~" + ReturnType.GetSignatureForDocumentation ();
}
}
return name;
}
public override string GetSignatureForError ()
{
string name;
@ -1636,6 +1654,11 @@ namespace Mono.CSharp { @@ -1636,6 +1654,11 @@ namespace Mono.CSharp {
return null;
}
public override string GetSignatureForDocumentation ()
{
return Parent.GetSignatureForDocumentation () + ".#ctor" + parameters.GetSignatureForDocumentation ();
}
public override string GetSignatureForError()
{
return base.GetSignatureForError () + parameters.GetSignatureForError ();
@ -2259,6 +2282,12 @@ namespace Mono.CSharp { @@ -2259,6 +2282,12 @@ namespace Mono.CSharp {
return false;
}
public override string GetSignatureForDocumentation ()
{
// should not be called
throw new NotSupportedException ();
}
public override bool IsClsComplianceRequired()
{
return false;
@ -2603,6 +2632,16 @@ namespace Mono.CSharp { @@ -2603,6 +2632,16 @@ namespace Mono.CSharp {
}
}
public override string GetSignatureForDocumentation ()
{
string s = base.GetSignatureForDocumentation ();
if (OperatorType == OpType.Implicit || OperatorType == OpType.Explicit) {
s = s + "~" + ReturnType.GetSignatureForDocumentation ();
}
return s;
}
public override string GetSignatureForError ()
{
StringBuilder sb = new StringBuilder ();

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

@ -72,14 +72,14 @@ namespace Mono.CSharp { @@ -72,14 +72,14 @@ namespace Mono.CSharp {
}
}
/// <summary>
/// Keeps track of the namespaces defined in the C# code.
///
/// This is an Expression to allow it to be referenced in the
/// compiler parse/intermediate tree during name resolution.
/// </summary>
public class Namespace : FullNamedExpression {
//
// Namespace cache for imported and compiler namespaces
//
// This is an Expression to allow it to be referenced in the
// compiler parse/intermediate tree during name resolution.
//
public class Namespace : FullNamedExpression
{
Namespace parent;
string fullname;
protected Dictionary<string, Namespace> namespaces;
@ -99,7 +99,7 @@ namespace Mono.CSharp { @@ -99,7 +99,7 @@ namespace Mono.CSharp {
{
// Expression members.
this.eclass = ExprClass.Namespace;
this.Type = InternalType.FakeInternalType;
this.Type = InternalType.Namespace;
this.loc = Location.Null;
this.parent = parent;
@ -163,13 +163,13 @@ namespace Mono.CSharp { @@ -163,13 +163,13 @@ namespace Mono.CSharp {
{
FullNamedExpression retval = Lookup (ctx, name, -System.Math.Max (1, arity), loc);
if (retval != null) {
Error_TypeArgumentsCannotBeUsed (ctx.Module.Compiler.Report, loc, retval.Type, arity);
Error_TypeArgumentsCannotBeUsed (ctx, retval.Type, arity, loc);
return;
}
Namespace ns;
if (arity > 0 && namespaces.TryGetValue (name, out ns)) {
ns.Error_TypeArgumentsCannotBeUsed (ctx.Module.Compiler.Report, loc, null, arity);
ns.Error_TypeArgumentsCannotBeUsed (ctx, null, arity, loc);
return;
}
@ -208,7 +208,16 @@ namespace Mono.CSharp { @@ -208,7 +208,16 @@ namespace Mono.CSharp {
return ns;
}
public TypeExpr LookupType (IMemberContext ctx, string name, int arity, bool silent, Location loc)
public IList<TypeSpec> GetAllTypes (string name)
{
IList<TypeSpec> found;
if (types == null || !types.TryGetValue (name, out found))
return null;
return found;
}
public TypeExpr LookupType (IMemberContext ctx, string name, int arity, Location loc)
{
if (types == null)
return null;
@ -229,33 +238,10 @@ namespace Mono.CSharp { @@ -229,33 +238,10 @@ namespace Mono.CSharp {
continue;
}
var pts = best as BuiltinTypeSpec;
if (pts == null)
pts = ts as BuiltinTypeSpec;
if (pts != null) {
ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (best);
ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (ts);
// TODO: This should use different warning number but we want to be csc compatible
ctx.Module.Compiler.Report.Warning (1685, 1, loc,
"The predefined type `{0}.{1}' is redefined in the source code. Ignoring the local type definition",
pts.Namespace, pts.Name);
best = pts;
continue;
}
if (best.MemberDefinition.IsImported && ts.MemberDefinition.IsImported) {
ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (best);
ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (ts);
if (silent) {
ctx.Module.Compiler.Report.Warning (1685, 1, loc,
"The predefined type `{0}' is defined in multiple assemblies. Using definition from `{1}'",
ts.GetSignatureForError (), best.MemberDefinition.DeclaringAssembly.Name);
} else {
ctx.Module.Compiler.Report.Error (433, loc, "The imported type `{0}' is defined multiple times", ts.GetSignatureForError ());
}
ctx.Module.Compiler.Report.Error (433, loc, "The imported type `{0}' is defined multiple times", ts.GetSignatureForError ());
break;
}
@ -265,9 +251,6 @@ namespace Mono.CSharp { @@ -265,9 +251,6 @@ namespace Mono.CSharp {
if ((best.Modifiers & Modifiers.INTERNAL) != 0 && !best.MemberDefinition.IsInternalAsPublic (ctx.Module.DeclaringAssembly))
continue;
if (silent)
continue;
if (ts.MemberDefinition.IsImported)
ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (ts);
@ -297,7 +280,7 @@ namespace Mono.CSharp { @@ -297,7 +280,7 @@ namespace Mono.CSharp {
te = new TypeExpression (best, Location.Null);
// TODO MemberCache: Cache more
if (arity == 0 && !silent)
if (arity == 0)
cached_types.Add (name, te);
return te;
@ -339,7 +322,7 @@ namespace Mono.CSharp { @@ -339,7 +322,7 @@ namespace Mono.CSharp {
if (arity == 0 && namespaces.ContainsKey (name))
return namespaces [name];
return LookupType (ctx, name, arity, false, loc);
return LookupType (ctx, name, arity, loc);
}
//
@ -469,12 +452,12 @@ namespace Mono.CSharp { @@ -469,12 +452,12 @@ namespace Mono.CSharp {
cached_types.Remove (name);
}
public void ReplaceTypeWithPredefined (TypeSpec ts, BuiltinTypeSpec pts)
public void SetBuiltinType (BuiltinTypeSpec pts)
{
var found = types [ts.Name];
cached_types.Remove (ts.Name);
var found = types[pts.Name];
cached_types.Remove (pts.Name);
if (found.Count == 1) {
types[ts.Name][0] = pts;
types[pts.Name][0] = pts;
} else {
throw new NotImplementedException ();
}
@ -538,138 +521,23 @@ namespace Mono.CSharp { @@ -538,138 +521,23 @@ namespace Mono.CSharp {
}
//
// Namespace container as created by the parser
// Namespace block as created by the parser
//
public class NamespaceEntry : IMemberContext {
public class UsingEntry {
readonly MemberName name;
Namespace resolved;
public UsingEntry (MemberName name)
{
this.name = name;
}
public string GetSignatureForError ()
{
return name.GetSignatureForError ();
}
public Location Location {
get { return name.Location; }
}
public MemberName MemberName {
get { return name; }
}
public string Name {
get { return GetSignatureForError (); }
}
public Namespace Resolve (IMemberContext rc)
{
if (resolved != null)
return resolved;
FullNamedExpression fne = name.GetTypeExpression ().ResolveAsTypeStep (rc, false);
if (fne == null)
return null;
resolved = fne as Namespace;
if (resolved == null) {
rc.Module.Compiler.Report.SymbolRelatedToPreviousError (fne.Type);
rc.Module.Compiler.Report.Error (138, Location,
"`{0}' is a type not a namespace. A using namespace directive can only be applied to namespaces",
GetSignatureForError ());
}
return resolved;
}
public override string ToString ()
{
return Name;
}
}
public class UsingAliasEntry {
public readonly string Alias;
public Location Location;
public UsingAliasEntry (string alias, Location loc)
{
this.Alias = alias;
this.Location = loc;
}
public virtual FullNamedExpression Resolve (IMemberContext rc, bool local)
{
FullNamedExpression fne = rc.Module.GetRootNamespace (Alias);
if (fne == null) {
rc.Module.Compiler.Report.Error (430, Location,
"The extern alias `{0}' was not specified in -reference option",
Alias);
}
return fne;
}
public override string ToString ()
{
return Alias;
}
}
class LocalUsingAliasEntry : UsingAliasEntry {
FullNamedExpression resolved;
MemberName value;
public LocalUsingAliasEntry (string alias, MemberName name, Location loc)
: base (alias, loc)
{
this.value = name;
}
public override FullNamedExpression Resolve (IMemberContext rc, bool local)
{
if (resolved != null || value == null)
return resolved;
if (local)
return null;
resolved = value.GetTypeExpression ().ResolveAsTypeStep (rc, false);
if (resolved == null) {
value = null;
return null;
}
if (resolved is TypeExpr)
resolved = resolved.ResolveAsTypeTerminal (rc, false);
return resolved;
}
public override string ToString ()
{
return String.Format ("{0} = {1}", Alias, value.GetSignatureForError ());
}
}
public class NamespaceContainer : IMemberContext, ITypesContainer
{
Namespace ns;
readonly ModuleContainer module;
readonly NamespaceEntry parent;
readonly NamespaceContainer parent;
readonly CompilationSourceFile file;
readonly Location loc;
NamespaceEntry implicit_parent;
NamespaceContainer implicit_parent;
int symfile_id;
// Namespace using import block
List<UsingAliasEntry> using_aliases;
List<UsingEntry> using_clauses;
List<NamespaceUsingAlias> using_aliases;
List<NamespaceUsing> using_clauses;
public bool DeclarationFound;
// End
@ -682,23 +550,24 @@ namespace Mono.CSharp { @@ -682,23 +550,24 @@ namespace Mono.CSharp {
Namespace [] namespace_using_table;
public NamespaceEntry (ModuleContainer module, NamespaceEntry parent, CompilationSourceFile sourceFile, string name)
public NamespaceContainer (MemberName name, ModuleContainer module, NamespaceContainer parent, CompilationSourceFile sourceFile)
{
this.module = module;
this.parent = parent;
this.file = sourceFile;
this.loc = name == null ? Location.Null : name.Location;
if (parent != null)
ns = parent.NS.GetNamespace (name, true);
ns = parent.NS.GetNamespace (name.GetName (), true);
else if (name != null)
ns = module.GlobalRootNamespace.GetNamespace (name, true);
ns = module.GlobalRootNamespace.GetNamespace (name.GetName (), true);
else
ns = module.GlobalRootNamespace;
SlaveDeclSpace = new RootDeclSpace (module, this);
}
private NamespaceEntry (ModuleContainer module, NamespaceEntry parent, CompilationSourceFile file, Namespace ns, bool slave)
private NamespaceContainer (ModuleContainer module, NamespaceContainer parent, CompilationSourceFile file, Namespace ns, bool slave)
{
this.module = module;
this.parent = parent;
@ -708,31 +577,47 @@ namespace Mono.CSharp { @@ -708,31 +577,47 @@ namespace Mono.CSharp {
this.SlaveDeclSpace = slave ? new RootDeclSpace (module, this) : null;
}
#region Properties
public Location Location {
get {
return loc;
}
}
public MemberName MemberName {
get {
return ns.MemberName;
}
}
public CompilationSourceFile SourceFile {
get {
return file;
}
}
public List<UsingEntry> Usings {
public List<NamespaceUsing> Usings {
get {
return using_clauses;
}
}
#endregion
//
// Extracts the using alises and using clauses into a couple of
// arrays that might already have the same information; Used by the
// C# Eval mode.
//
public void Extract (List<UsingAliasEntry> out_using_aliases, List<UsingEntry> out_using_clauses)
public void Extract (List<NamespaceUsingAlias> out_using_aliases, List<NamespaceUsing> out_using_clauses)
{
if (using_aliases != null){
foreach (UsingAliasEntry uae in using_aliases){
foreach (NamespaceUsingAlias uae in using_aliases){
bool replaced = false;
for (int i = 0; i < out_using_aliases.Count; i++){
UsingAliasEntry out_uea = (UsingAliasEntry) out_using_aliases [i];
NamespaceUsingAlias out_uea = (NamespaceUsingAlias) out_using_aliases [i];
if (out_uea.Alias == uae.Alias){
out_using_aliases [i] = uae;
@ -746,10 +631,10 @@ namespace Mono.CSharp { @@ -746,10 +631,10 @@ namespace Mono.CSharp {
}
if (using_clauses != null){
foreach (UsingEntry ue in using_clauses){
foreach (NamespaceUsing ue in using_clauses){
bool found = false;
foreach (UsingEntry out_ue in out_using_clauses)
foreach (NamespaceUsing out_ue in out_using_clauses)
if (out_ue.Name == ue.Name){
found = true;
break;
@ -770,11 +655,11 @@ namespace Mono.CSharp { @@ -770,11 +655,11 @@ namespace Mono.CSharp {
// To implement these rules, the expressions in the using directives are resolved using
// the "doppelganger" (ghostly bodiless duplicate).
//
NamespaceEntry doppelganger;
NamespaceEntry Doppelganger {
NamespaceContainer doppelganger;
NamespaceContainer Doppelganger {
get {
if (!IsImplicit && doppelganger == null) {
doppelganger = new NamespaceEntry (module, ImplicitParent, file, ns, true);
doppelganger = new NamespaceContainer (module, ImplicitParent, file, ns, true);
doppelganger.using_aliases = using_aliases;
}
return doppelganger;
@ -785,18 +670,18 @@ namespace Mono.CSharp { @@ -785,18 +670,18 @@ namespace Mono.CSharp {
get { return ns; }
}
public NamespaceEntry Parent {
public NamespaceContainer Parent {
get { return parent; }
}
public NamespaceEntry ImplicitParent {
public NamespaceContainer ImplicitParent {
get {
if (parent == null)
return null;
if (implicit_parent == null) {
implicit_parent = (parent.NS == ns.Parent)
? parent
: new NamespaceEntry (module, parent, file, ns.Parent, false);
: new NamespaceContainer (module, parent, file, ns.Parent, false);
}
return implicit_parent;
}
@ -812,9 +697,9 @@ namespace Mono.CSharp { @@ -812,9 +697,9 @@ namespace Mono.CSharp {
}
if (using_clauses == null) {
using_clauses = new List<UsingEntry> ();
using_clauses = new List<NamespaceUsing> ();
} else {
foreach (UsingEntry old_entry in using_clauses) {
foreach (NamespaceUsing old_entry in using_clauses) {
if (name.Equals (old_entry.MemberName)) {
Compiler.Report.SymbolRelatedToPreviousError (old_entry.Location, old_entry.GetSignatureForError ());
Compiler.Report.Warning (105, 3, loc, "The using directive for `{0}' appeared previously in this namespace", name.GetSignatureForError ());
@ -823,12 +708,11 @@ namespace Mono.CSharp { @@ -823,12 +708,11 @@ namespace Mono.CSharp {
}
}
using_clauses.Add (new UsingEntry (name));
using_clauses.Add (new NamespaceUsing (name));
}
public void AddUsingAlias (string alias, MemberName name, Location loc)
{
// TODO: This is parser bussines
if (DeclarationFound){
Compiler.Report.Error (1529, loc, "A using clause must precede all other namespace elements except extern alias declarations");
}
@ -838,10 +722,9 @@ namespace Mono.CSharp { @@ -838,10 +722,9 @@ namespace Mono.CSharp {
public void AddUsingExternalAlias (string alias, Location loc, Report Report)
{
// TODO: Do this in parser
bool not_first = using_clauses != null || DeclarationFound;
if (using_aliases != null && !not_first) {
foreach (UsingAliasEntry uae in using_aliases) {
foreach (NamespaceUsingAlias uae in using_aliases) {
if (uae is LocalUsingAliasEntry) {
not_first = true;
break;
@ -857,15 +740,15 @@ namespace Mono.CSharp { @@ -857,15 +740,15 @@ namespace Mono.CSharp {
return;
}
AddUsingAlias (new UsingAliasEntry (alias, loc));
AddUsingAlias (new NamespaceUsingAlias (alias, loc));
}
void AddUsingAlias (UsingAliasEntry uae)
void AddUsingAlias (NamespaceUsingAlias uae)
{
if (using_aliases == null) {
using_aliases = new List<UsingAliasEntry> ();
using_aliases = new List<NamespaceUsingAlias> ();
} else {
foreach (UsingAliasEntry entry in using_aliases) {
foreach (NamespaceUsingAlias entry in using_aliases) {
if (uae.Alias == entry.Alias) {
Compiler.Report.SymbolRelatedToPreviousError (uae.Location, uae.Alias);
Compiler.Report.Error (1537, entry.Location, "The using alias `{0}' appeared previously in this namespace",
@ -882,7 +765,7 @@ namespace Mono.CSharp { @@ -882,7 +765,7 @@ namespace Mono.CSharp {
// Does extension methods look up to find a method which matches name and extensionType.
// Search starts from this namespace and continues hierarchically up to top level.
//
public IList<MethodSpec> LookupExtensionMethod (TypeSpec extensionType, string name, int arity, ref NamespaceEntry scope)
public IList<MethodSpec> LookupExtensionMethod (TypeSpec extensionType, string name, int arity, ref NamespaceContainer scope)
{
List<MethodSpec> candidates = null;
foreach (Namespace n in GetUsingTable ()) {
@ -925,7 +808,7 @@ namespace Mono.CSharp { @@ -925,7 +808,7 @@ namespace Mono.CSharp {
{
// Precondition: Only simple names (no dots) will be looked up with this function.
FullNamedExpression resolved = null;
for (NamespaceEntry curr_ns = this; curr_ns != null; curr_ns = curr_ns.ImplicitParent) {
for (NamespaceContainer curr_ns = this; curr_ns != null; curr_ns = curr_ns.ImplicitParent) {
if ((resolved = curr_ns.Lookup (name, arity, loc, ignore_cs0104)) != null)
break;
}
@ -937,7 +820,7 @@ namespace Mono.CSharp { @@ -937,7 +820,7 @@ namespace Mono.CSharp {
{
IEnumerable<string> all = Enumerable.Empty<string> ();
for (NamespaceEntry curr_ns = this; curr_ns != null; curr_ns = curr_ns.ImplicitParent){
for (NamespaceContainer curr_ns = this; curr_ns != null; curr_ns = curr_ns.ImplicitParent){
foreach (Namespace using_ns in GetUsingTable ()){
if (prefix.StartsWith (using_ns.Name)){
int ld = prefix.LastIndexOf ('.');
@ -957,11 +840,11 @@ namespace Mono.CSharp { @@ -957,11 +840,11 @@ namespace Mono.CSharp {
// Looks-up a alias named @name in this and surrounding namespace declarations
public FullNamedExpression LookupNamespaceAlias (string name)
{
for (NamespaceEntry n = this; n != null; n = n.ImplicitParent) {
for (NamespaceContainer n = this; n != null; n = n.ImplicitParent) {
if (n.using_aliases == null)
continue;
foreach (UsingAliasEntry ue in n.using_aliases) {
foreach (NamespaceUsingAlias ue in n.using_aliases) {
if (ue.Alias == name)
return ue.Resolve (Doppelganger ?? this, Doppelganger == null);
}
@ -981,7 +864,7 @@ namespace Mono.CSharp { @@ -981,7 +864,7 @@ namespace Mono.CSharp {
// Check aliases.
//
if (using_aliases != null && arity == 0) {
foreach (UsingAliasEntry ue in using_aliases) {
foreach (NamespaceUsingAlias ue in using_aliases) {
if (ue.Alias == name) {
if (fne != null) {
if (Doppelganger != null) {
@ -1016,7 +899,7 @@ namespace Mono.CSharp { @@ -1016,7 +899,7 @@ namespace Mono.CSharp {
foreach (Namespace using_ns in GetUsingTable ()) {
// A using directive imports only types contained in the namespace, it
// does not import any nested namespaces
fne = using_ns.LookupType (this, name, arity, false, loc);
fne = using_ns.LookupType (this, name, arity, loc);
if (fne == null)
continue;
@ -1067,7 +950,7 @@ namespace Mono.CSharp { @@ -1067,7 +950,7 @@ namespace Mono.CSharp {
var list = new List<Namespace> (using_clauses.Count);
foreach (UsingEntry ue in using_clauses) {
foreach (NamespaceUsing ue in using_clauses) {
Namespace using_ns = ue.Resolve (Doppelganger);
if (using_ns == null)
continue;
@ -1088,7 +971,7 @@ namespace Mono.CSharp { @@ -1088,7 +971,7 @@ namespace Mono.CSharp {
if (using_clauses != null) {
using_list = new string [using_clauses.Count];
for (int i = 0; i < using_clauses.Count; i++)
using_list [i] = ((UsingEntry) using_clauses [i]).MemberName.GetName ();
using_list [i] = ((NamespaceUsing) using_clauses [i]).MemberName.GetName ();
}
symfile_id = SymbolWriter.DefineNamespace (ns.Name, file.CompileUnitEntry, using_list, parent_id);
@ -1152,12 +1035,12 @@ namespace Mono.CSharp { @@ -1152,12 +1035,12 @@ namespace Mono.CSharp {
resolved = true;
if (using_aliases != null) {
foreach (UsingAliasEntry ue in using_aliases)
foreach (NamespaceUsingAlias ue in using_aliases)
ue.Resolve (Doppelganger, Doppelganger == null);
}
if (using_clauses != null) {
foreach (UsingEntry ue in using_clauses)
foreach (NamespaceUsing ue in using_clauses)
ue.Resolve (Doppelganger);
}
@ -1211,4 +1094,110 @@ namespace Mono.CSharp { @@ -1211,4 +1094,110 @@ namespace Mono.CSharp {
#endregion
}
public class NamespaceUsing
{
readonly MemberName name;
Namespace resolved;
public NamespaceUsing (MemberName name)
{
this.name = name;
}
public string GetSignatureForError ()
{
return name.GetSignatureForError ();
}
public Location Location
{
get { return name.Location; }
}
public MemberName MemberName
{
get { return name; }
}
public string Name
{
get { return GetSignatureForError (); }
}
public Namespace Resolve (IMemberContext rc)
{
if (resolved != null)
return resolved;
FullNamedExpression fne = name.GetTypeExpression ().ResolveAsTypeStep (rc, false);
if (fne == null)
return null;
resolved = fne as Namespace;
if (resolved == null) {
rc.Module.Compiler.Report.SymbolRelatedToPreviousError (fne.Type);
rc.Module.Compiler.Report.Error (138, Location,
"`{0}' is a type not a namespace. A using namespace directive can only be applied to namespaces",
GetSignatureForError ());
}
return resolved;
}
}
public class NamespaceUsingAlias
{
public readonly string Alias;
public Location Location;
public NamespaceUsingAlias (string alias, Location loc)
{
this.Alias = alias;
this.Location = loc;
}
public virtual FullNamedExpression Resolve (IMemberContext rc, bool local)
{
FullNamedExpression fne = rc.Module.GetRootNamespace (Alias);
if (fne == null) {
rc.Module.Compiler.Report.Error (430, Location,
"The extern alias `{0}' was not specified in -reference option",
Alias);
}
return fne;
}
}
class LocalUsingAliasEntry : NamespaceUsingAlias
{
FullNamedExpression resolved;
MemberName value;
public LocalUsingAliasEntry (string alias, MemberName name, Location loc)
: base (alias, loc)
{
this.value = name;
}
public override FullNamedExpression Resolve (IMemberContext rc, bool local)
{
if (resolved != null || value == null)
return resolved;
if (local)
return null;
resolved = value.GetTypeExpression ().ResolveAsTypeStep (rc, false);
if (resolved == null) {
value = null;
return null;
}
if (resolved is TypeExpr)
resolved = resolved.ResolveAsTypeTerminal (rc, false);
return resolved;
}
}
}

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

@ -39,7 +39,7 @@ namespace Mono.CSharp.Nullable @@ -39,7 +39,7 @@ namespace Mono.CSharp.Nullable
protected override TypeExpr DoResolveAsTypeStep (IMemberContext ec)
{
var type = ec.Module.PredefinedTypes.Nullable.Resolve (loc);
var type = ec.Module.PredefinedTypes.Nullable.Resolve ();
if (type == null)
return null;

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

@ -215,6 +215,7 @@ namespace Mono.CSharp { @@ -215,6 +215,7 @@ namespace Mono.CSharp {
ISBYREF = 8,
REFMASK = 32,
OUTMASK = 64,
SignatureMask = REFMASK | OUTMASK,
This = 128
}
@ -281,6 +282,9 @@ namespace Mono.CSharp { @@ -281,6 +282,9 @@ namespace Mono.CSharp {
get {
return parameter_type;
}
set {
parameter_type = value;
}
}
public FullNamedExpression TypeExpression {
@ -559,7 +563,7 @@ namespace Mono.CSharp { @@ -559,7 +563,7 @@ namespace Mono.CSharp {
var def_value = DefaultValue;
Constant c = def_value != null ? def_value.Child as Constant : default_expr as Constant;
if (c != null) {
if (default_expr.Type.BuiltinType == BuiltinTypeSpec.Type.Decimal) {
if (c.Type.BuiltinType == BuiltinTypeSpec.Type.Decimal) {
pa.DecimalConstant.EmitAttribute (builder, (decimal) c.GetValue (), c.Location);
} else {
builder.SetConstant (c.GetValue ());
@ -657,7 +661,7 @@ namespace Mono.CSharp { @@ -657,7 +661,7 @@ namespace Mono.CSharp {
//
public static TypeExpr ResolveParameterExpressionType (IMemberContext ec, Location location)
{
TypeSpec p_type = ec.Module.PredefinedTypes.ParameterExpression.Resolve (location);
TypeSpec p_type = ec.Module.PredefinedTypes.ParameterExpression.Resolve ();
return new TypeExpression (p_type, location);
}
@ -800,6 +804,26 @@ namespace Mono.CSharp { @@ -800,6 +804,26 @@ namespace Mono.CSharp {
return -1;
}
public string GetSignatureForDocumentation ()
{
if (IsEmpty)
return string.Empty;
StringBuilder sb = new StringBuilder ("(");
for (int i = 0; i < Count; ++i) {
if (i != 0)
sb.Append (",");
sb.Append (types [i].GetSignatureForDocumentation ());
if ((parameters[i].ModFlags & Parameter.Modifier.ISBYREF) != 0)
sb.Append ("@");
}
sb.Append (")");
return sb.ToString ();
}
public string GetSignatureForError ()
{
return GetSignatureForError ("(", ")", Count);

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

@ -327,10 +327,11 @@ namespace Mono.CSharp { @@ -327,10 +327,11 @@ namespace Mono.CSharp {
MethodBuilder proxy = container.TypeBuilder.DefineMethod (
proxy_name,
MethodAttributes.Private |
MethodAttributes.HideBySig |
MethodAttributes.NewSlot |
MethodAttributes.CheckAccessOnOverride |
MethodAttributes.Virtual,
MethodAttributes.Virtual | MethodAttributes.Final,
CallingConventions.Standard | CallingConventions.HasThis,
base_method.ReturnType.GetMetaInfo (), param.GetMetaInfo ());
@ -383,10 +384,20 @@ namespace Mono.CSharp { @@ -383,10 +384,20 @@ namespace Mono.CSharp {
if (!TypeSpecComparer.Override.IsEqual (mi.ReturnType, base_method.ReturnType))
return false;
if (!base_method.IsAbstract && !base_method.IsVirtual)
// FIXME: We can avoid creating a proxy if base_method can be marked 'final virtual' instead.
// However, it's too late now, the MethodBuilder has already been created (see bug 377519)
if (!base_method.IsVirtual) {
#if STATIC
var base_builder = base_method.GetMetaInfo () as MethodBuilder;
if (base_builder != null) {
//
// We can avoid creating a proxy if base_method can be marked 'final virtual'. This can
// be done for all methods from compiled assembly
//
base_builder.__SetAttributes (base_builder.Attributes | MethodAttributes.Virtual | MethodAttributes.Final | MethodAttributes.NewSlot);
return true;
}
#endif
DefineProxy (iface_type, base_method, mi);
}
return true;
}

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

@ -805,11 +805,6 @@ namespace Mono.CSharp @@ -805,11 +805,6 @@ namespace Mono.CSharp
base.Emit ();
}
public override string GetDocCommentName ()
{
return String.Concat (DocCommentHeader, Parent.Name, ".", GetFullName (ShortName).Replace ('.', '#'));
}
}
/// <summary>
@ -1118,7 +1113,7 @@ namespace Mono.CSharp @@ -1118,7 +1113,7 @@ namespace Mono.CSharp
public abstract class AEventAccessor : AbstractPropertyEventMethod
{
protected readonly Event method;
ParametersCompiled parameters;
readonly ParametersCompiled parameters;
static readonly string[] attribute_targets = new string [] { "method", "param", "return" };
@ -1169,7 +1164,10 @@ namespace Mono.CSharp @@ -1169,7 +1164,10 @@ namespace Mono.CSharp
public virtual MethodBuilder Define (DeclSpace parent)
{
parameters.Resolve (this);
// Fill in already resolved event type to speed things up and
// avoid confusing duplicate errors
((Parameter) parameters.FixedParameters[0]).Type = method.member_type;
parameters.Types = new TypeSpec[] { method.member_type };
method_data = new MethodData (method, method.ModFlags,
method.flags | MethodAttributes.HideBySig | MethodAttributes.SpecialName, this);
@ -1576,24 +1574,24 @@ namespace Mono.CSharp @@ -1576,24 +1574,24 @@ namespace Mono.CSharp
return base.EnableOverloadChecks (overload);
}
public override string GetDocCommentName ()
{
return DocumentationBuilder.GetMethodDocCommentName (this, parameters);
}
public override string GetSignatureForError ()
{
StringBuilder sb = new StringBuilder (Parent.GetSignatureForError ());
if (MemberName.Left != null) {
sb.Append ('.');
sb.Append (".");
sb.Append (MemberName.Left.GetSignatureForError ());
}
sb.Append (".this");
sb.Append (parameters.GetSignatureForError ().Replace ('(', '[').Replace (')', ']'));
sb.Append (parameters.GetSignatureForError ("[", "]", parameters.Count));
return sb.ToString ();
}
public override string GetSignatureForDocumentation ()
{
return base.GetSignatureForDocumentation () + parameters.GetSignatureForDocumentation ();
}
public AParametersCollection Parameters {
get {
return parameters;
@ -1634,6 +1632,11 @@ namespace Mono.CSharp @@ -1634,6 +1632,11 @@ namespace Mono.CSharp
}
#endregion
public override string GetSignatureForDocumentation ()
{
return base.GetSignatureForDocumentation () + parameters.GetSignatureForDocumentation ();
}
public override string GetSignatureForError ()
{
return DeclaringType.GetSignatureForError () + ".this" + parameters.GetSignatureForError ("[", "]", parameters.Count);

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

@ -677,6 +677,10 @@ namespace Mono.CSharp { @@ -677,6 +677,10 @@ namespace Mono.CSharp {
}
}
sealed class NullReportPrinter : ReportPrinter
{
}
//
// Default message recorder, it uses two types of message groups.
// Common messages: messages reported in all sessions.

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

@ -124,6 +124,9 @@ namespace Mono.CSharp @@ -124,6 +124,9 @@ namespace Mono.CSharp
readonly Dictionary<TypeSpec, ReferenceContainer> reference_types;
readonly Dictionary<TypeSpec, MethodSpec> attrs_cache;
// Used for unique namespaces/types during parsing
Dictionary<MemberName, ITypesContainer> defined_type_containers;
AssemblyDefinition assembly;
readonly CompilerContext context;
readonly RootNamespace global_ns;
@ -154,6 +157,8 @@ namespace Mono.CSharp @@ -154,6 +157,8 @@ namespace Mono.CSharp
pointer_types = new Dictionary<TypeSpec, PointerContainer> ();
reference_types = new Dictionary<TypeSpec, ReferenceContainer> ();
attrs_cache = new Dictionary<TypeSpec, MethodSpec> ();
defined_type_containers = new Dictionary<MemberName, ITypesContainer> ();
}
#region Properties
@ -197,6 +202,10 @@ namespace Mono.CSharp @@ -197,6 +202,10 @@ namespace Mono.CSharp
}
}
internal DocumentationBuilder DocumentationBuilder {
get; set;
}
public Evaluator Evaluator {
get; set;
}
@ -366,7 +375,7 @@ namespace Mono.CSharp @@ -366,7 +375,7 @@ namespace Mono.CSharp
public RootNamespace CreateRootNamespace (string alias)
{
if (alias == global_ns.Alias) {
NamespaceEntry.Error_GlobalNamespaceRedefined (Location.Null, Report);
NamespaceContainer.Error_GlobalNamespaceRedefined (Location.Null, Report);
return global_ns;
}
@ -387,6 +396,9 @@ namespace Mono.CSharp @@ -387,6 +396,9 @@ namespace Mono.CSharp
public new void CreateType ()
{
// Release cache used by parser only
defined_type_containers = null;
foreach (TypeContainer tc in types)
tc.CreateType ();
}
@ -486,12 +498,53 @@ namespace Mono.CSharp @@ -486,12 +498,53 @@ namespace Mono.CSharp
return DeclaringAssembly.IsCLSCompliant;
}
protected override bool AddMemberType (TypeContainer ds)
protected override bool AddMemberType (TypeContainer tc)
{
if (!AddToContainer (ds, ds.Name))
return false;
ds.NamespaceEntry.NS.AddType (this, ds.Definition);
return true;
if (AddTypesContainer (tc)) {
if ((tc.ModFlags & Modifiers.PARTIAL) != 0)
defined_names.Add (tc.Name, tc);
tc.NamespaceEntry.NS.AddType (this, tc.Definition);
return true;
}
return false;
}
public bool AddTypesContainer (ITypesContainer container)
{
var mn = container.MemberName;
ITypesContainer found;
if (!defined_type_containers.TryGetValue (mn, out found)) {
defined_type_containers.Add (mn, container);
return true;
}
if (container is NamespaceContainer && found is NamespaceContainer)
return true;
var container_tc = container as TypeContainer;
var found_tc = found as TypeContainer;
if (container_tc != null && found_tc != null && container_tc.Kind == found_tc.Kind) {
if ((found_tc.ModFlags & container_tc.ModFlags & Modifiers.PARTIAL) != 0) {
return false;
}
if (((found_tc.ModFlags | container_tc.ModFlags) & Modifiers.PARTIAL) != 0) {
Report.SymbolRelatedToPreviousError (found_tc);
Error_MissingPartialModifier (container_tc);
return false;
}
}
string ns = mn.Left != null ? mn.Left.GetSignatureForError () : Module.GlobalRootNamespace.GetSignatureForError ();
mn = new MemberName (mn.Name, mn.TypeArguments, mn.Location);
Report.SymbolRelatedToPreviousError (found.Location, "");
Report.Error (101, container.Location,
"The namespace `{0}' already contains a definition for `{1}'",
ns, mn.GetSignatureForError ());
return false;
}
protected override void RemoveMemberType (TypeContainer ds)
@ -517,7 +570,7 @@ namespace Mono.CSharp @@ -517,7 +570,7 @@ namespace Mono.CSharp
}
sealed class RootDeclSpace : TypeContainer {
public RootDeclSpace (ModuleContainer module, NamespaceEntry ns)
public RootDeclSpace (ModuleContainer module, NamespaceContainer ns)
: base (ns, null, MemberName.Null, null, 0)
{
PartialContainer = module;
@ -558,7 +611,7 @@ namespace Mono.CSharp @@ -558,7 +611,7 @@ namespace Mono.CSharp
return PartialContainer.IsClsComplianceRequired ();
}
public override IList<MethodSpec> LookupExtensionMethod (TypeSpec extensionType, string name, int arity, ref NamespaceEntry scope)
public override IList<MethodSpec> LookupExtensionMethod (TypeSpec extensionType, string name, int arity, ref NamespaceContainer scope)
{
return null;
}

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

@ -1982,14 +1982,7 @@ namespace Mono.CSharp { @@ -1982,14 +1982,7 @@ namespace Mono.CSharp {
var pi = variable as ParametersBlock.ParameterInfo;
if (pi != null) {
var p = pi.Parameter;
if (p is AnonymousTypeClass.GeneratedParameter) {
ParametersBlock.TopBlock.Report.Error (833, p.Location, "`{0}': An anonymous type cannot have multiple properties with the same name",
p.Name);
} else {
ParametersBlock.TopBlock.Report.Error (100, p.Location, "The parameter name `{0}' is a duplicate", p.Name);
}
return;
ParametersBlock.TopBlock.Report.Error (100, p.Location, "The parameter name `{0}' is a duplicate", p.Name);
}
ParametersBlock.TopBlock.Report.Error (128, variable.Location,
@ -2621,7 +2614,8 @@ namespace Mono.CSharp { @@ -2621,7 +2614,8 @@ namespace Mono.CSharp {
// TODO: Should use Parameter only and more block there
parameter_info[i] = new ParameterInfo (this, i);
AddLocalName (p.Name, parameter_info[i]);
if (p.Name != null)
AddLocalName (p.Name, parameter_info[i]);
}
}
@ -3760,7 +3754,7 @@ namespace Mono.CSharp { @@ -3760,7 +3754,7 @@ namespace Mono.CSharp {
} else if (ec.Module.PredefinedTypes.Hashtable.Define ()) {
string_dictionary_type = new TypeExpression (ec.Module.PredefinedTypes.Hashtable.TypeSpec, loc);
} else {
ec.Module.PredefinedTypes.Dictionary.Resolve (loc);
ec.Module.PredefinedTypes.Dictionary.Resolve ();
return;
}

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

@ -15,6 +15,7 @@ using System; @@ -15,6 +15,7 @@ using System;
using System.Globalization;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace Mono.CSharp
{
@ -142,14 +143,14 @@ namespace Mono.CSharp @@ -142,14 +143,14 @@ namespace Mono.CSharp
{
var ctx = module.Compiler;
foreach (var p in types) {
var found = PredefinedType.Resolve (module, p.Kind, p.Namespace, p.Name, p.Arity, Location.Null);
var found = PredefinedType.Resolve (module, p.Kind, p.Namespace, p.Name, p.Arity);
if (found == null || found == p)
continue;
var tc = found.MemberDefinition as TypeContainer;
if (tc != null) {
var ns = module.GlobalRootNamespace.GetNamespace (p.Namespace, false);
ns.ReplaceTypeWithPredefined (found, p);
ns.SetBuiltinType (p);
tc.SetPredefinedSpec (p);
p.SetDefinition (found);
@ -529,14 +530,8 @@ namespace Mono.CSharp @@ -529,14 +530,8 @@ namespace Mono.CSharp
if (type != null)
return true;
Namespace type_ns = module.GlobalRootNamespace.GetNamespace (ns, true);
var te = type_ns.LookupType (module, name, arity, true, Location.Null);
if (te == null || te.Type.Kind != kind) {
return false;
}
type = te.Type;
return true;
type = Resolve (module, kind, ns, name, arity, false);
return type != null;
}
public string GetSignatureForError ()
@ -544,33 +539,87 @@ namespace Mono.CSharp @@ -544,33 +539,87 @@ namespace Mono.CSharp
return ns + "." + name;
}
public static TypeSpec Resolve (ModuleContainer module, MemberKind kind, string ns, string name, int arity, Location loc)
public static TypeSpec Resolve (ModuleContainer module, MemberKind kind, string ns, string name, int arity)
{
return Resolve (module, kind, ns, name, arity, true);
}
public static TypeSpec Resolve (ModuleContainer module, MemberKind kind, string ns, string name, int arity, bool reportErrors)
{
Namespace type_ns = module.GlobalRootNamespace.GetNamespace (ns, true);
var te = type_ns.LookupType (module, name, arity, false, Location.Null);
if (te == null) {
module.Compiler.Report.Error (518, loc, "The predefined type `{0}.{1}' is not defined or imported", ns, name);
var found = type_ns.GetAllTypes (name);
if (found == null) {
if (reportErrors)
module.Compiler.Report.Error (518, "The predefined type `{0}.{1}' is not defined or imported", ns, name);
return null;
}
var type = te.Type;
if (type.Kind != kind) {
if (type.Kind == MemberKind.Struct && kind == MemberKind.Void && type.MemberDefinition is TypeContainer) {
// Void is declared as struct but we keep it internally as
// special kind, the swap will be done by caller
TypeSpec best_match = null;
foreach (var candidate in found) {
if (candidate.Kind != kind) {
if (candidate.Kind == MemberKind.Struct && kind == MemberKind.Void && candidate.MemberDefinition is TypeContainer) {
// Void is declared as struct but we keep it internally as
// special kind, the swap will be done by caller
} else {
continue;
}
}
if (candidate.Arity != arity)
continue;
if ((candidate.Modifiers & Modifiers.INTERNAL) != 0 && !candidate.MemberDefinition.IsInternalAsPublic (module.DeclaringAssembly))
continue;
if (best_match == null) {
best_match = candidate;
continue;
}
var other_match = best_match;
if (!best_match.MemberDefinition.IsImported &&
module.Compiler.BuiltinTypes.Object.MemberDefinition.DeclaringAssembly == candidate.MemberDefinition.DeclaringAssembly) {
best_match = candidate;
}
string location;
if (best_match.MemberDefinition is MemberCore) {
location = ((MemberCore) best_match.MemberDefinition).Location.Name;
} else {
var assembly = (ImportedAssemblyDefinition) best_match.MemberDefinition.DeclaringAssembly;
location = Path.GetFileName (assembly.Location);
}
module.Compiler.Report.SymbolRelatedToPreviousError (other_match);
module.Compiler.Report.SymbolRelatedToPreviousError (candidate);
module.Compiler.Report.Warning (1685, 1,
"The predefined type `{0}.{1}' is defined multiple times. Using definition from `{2}'",
ns, name, location);
break;
}
if (best_match == null && reportErrors) {
Location loc;
if (found[0].MemberDefinition is MemberCore) {
loc = ((MemberCore) found[0].MemberDefinition).Location;
} else {
module.Compiler.Report.Error (520, loc, "The predefined type `{0}.{1}' is not declared correctly", ns, name);
return null;
loc = Location.Null;
module.Compiler.Report.SymbolRelatedToPreviousError (found[0]);
}
module.Compiler.Report.Error (520, loc, "The predefined type `{0}.{1}' is not declared correctly", ns, name);
}
return type;
return best_match;
}
public TypeSpec Resolve (Location loc)
public TypeSpec Resolve ()
{
if (type == null)
type = Resolve (module, kind, ns, name, arity, loc);
type = Resolve (module, kind, ns, name, arity);
return type;
}
@ -662,7 +711,7 @@ namespace Mono.CSharp @@ -662,7 +711,7 @@ namespace Mono.CSharp
return member;
if (declaring_type == null) {
if (declaring_type_predefined.Resolve (loc) == null)
if (declaring_type_predefined.Resolve () == null)
return null;
}
@ -670,7 +719,7 @@ namespace Mono.CSharp @@ -670,7 +719,7 @@ namespace Mono.CSharp
TypeSpec[] types = new TypeSpec[parameters_predefined.Length];
for (int i = 0; i < types.Length; ++i) {
var p = parameters_predefined[i];
types[i] = p.Resolve (loc);
types[i] = p.Resolve ();
if (types[i] == null)
return null;
}

98
ICSharpCode.NRefactory/CSharp/Parser/mcs/typespec.cs

@ -109,11 +109,11 @@ namespace Mono.CSharp @@ -109,11 +109,11 @@ namespace Mono.CSharp
var type = this;
do {
if (type.IsGeneric)
return false;
if (type.BuiltinType == BuiltinTypeSpec.Type.Attribute)
return true;
if (type.IsGeneric)
return false;
type = type.base_type;
} while (type != null);
@ -358,6 +358,65 @@ namespace Mono.CSharp @@ -358,6 +358,65 @@ namespace Mono.CSharp
return this;
}
public override string GetSignatureForDocumentation ()
{
StringBuilder sb = new StringBuilder ();
if (IsNested) {
sb.Append (DeclaringType.GetSignatureForDocumentation ());
} else {
sb.Append (MemberDefinition.Namespace);
}
if (sb.Length != 0)
sb.Append (".");
sb.Append (Name);
if (Arity > 0) {
if (this is InflatedTypeSpec) {
sb.Append ("{");
for (int i = 0; i < Arity; ++i) {
if (i > 0)
sb.Append (",");
sb.Append (TypeArguments[i].GetSignatureForDocumentation ());
}
sb.Append ("}");
} else {
sb.Append ("`");
sb.Append (Arity.ToString ());
}
}
return sb.ToString ();
}
public string GetExplicitNameSignatureForDocumentation ()
{
StringBuilder sb = new StringBuilder ();
if (IsNested) {
sb.Append (DeclaringType.GetExplicitNameSignatureForDocumentation ());
} else if (MemberDefinition.Namespace != null) {
sb.Append (MemberDefinition.Namespace.Replace ('.', '#'));
}
if (sb.Length != 0)
sb.Append ("#");
sb.Append (Name);
if (Arity > 0) {
sb.Append ("{");
for (int i = 0; i < Arity; ++i) {
if (i > 0)
sb.Append (",");
sb.Append (TypeArguments[i].GetExplicitNameSignatureForDocumentation ());
}
sb.Append ("}");
}
return sb.ToString ();
}
public override string GetSignatureForError ()
{
string s;
@ -1133,6 +1192,7 @@ namespace Mono.CSharp @@ -1133,6 +1192,7 @@ namespace Mono.CSharp
public static readonly InternalType MethodGroup = new InternalType ("method group");
public static readonly InternalType NullLiteral = new InternalType ("null");
public static readonly InternalType FakeInternalType = new InternalType ("<fake$type>");
public static readonly InternalType Namespace = new InternalType ("<namespace>");
readonly string name;
@ -1303,6 +1363,11 @@ namespace Mono.CSharp @@ -1303,6 +1363,11 @@ namespace Mono.CSharp
return null;
}
public override string GetSignatureForDocumentation ()
{
return Element.GetSignatureForDocumentation () + GetPostfixSignature ();
}
public override string GetSignatureForError ()
{
return Element.GetSignatureForError () + GetPostfixSignature ();
@ -1533,6 +1598,33 @@ namespace Mono.CSharp @@ -1533,6 +1598,33 @@ namespace Mono.CSharp
return sb.ToString ();
}
public override string GetSignatureForDocumentation ()
{
var e = Element;
List<int> ranks = new List<int> (2);
ranks.Add (rank);
while (e is ArrayContainer) {
var ac = (ArrayContainer) e;
ranks.Add (ac.rank);
e = ac.Element;
}
StringBuilder sb = new StringBuilder (e.GetSignatureForDocumentation ());
for (int r = 0; r < ranks.Count; ++r) {
sb.Append ("[");
for (int i = 1; i < ranks[r]; i++) {
if (i == 1)
sb.Append ("0:");
sb.Append (",0:");
}
sb.Append ("]");
}
return sb.ToString ();
}
public static ArrayContainer MakeType (ModuleContainer module, TypeSpec element)
{
return MakeType (module, element, 1);

Loading…
Cancel
Save