Author: martin
Date: 2005-04-13 07:42:42 -0400 (Wed, 13 Apr 2005)
New Revision: 42908
Modified:
trunk/mcs/gmcs/ChangeLog
trunk/mcs/gmcs/class.cs
trunk/mcs/gmcs/cs-parser.jay
trunk/mcs/gmcs/cs-tokenizer.cs
trunk/mcs/gmcs/ecore.cs
trunk/mcs/gmcs/pending.cs
trunk/mcs/gmcs/typemanager.cs
Log:
**** Merged r41276 from MCS ****
Modified: trunk/mcs/gmcs/ChangeLog
===================================================================
--- trunk/mcs/gmcs/ChangeLog 2005-04-13 11:42:15 UTC (rev 42907)
+++ trunk/mcs/gmcs/ChangeLog 2005-04-13 11:42:42 UTC (rev 42908)
@@ -1,3 +1,20 @@
+2005-02-28 Marek Safar <[EMAIL PROTECTED]>
+
+ * cs-parser.jay: Add errors 1617, 650, 1007, 531, 547, 548
+
+ * class.cs (MethodCore.IsDuplicateImplementation): Special error
+ for operators.
+ (Method.CheckBase): Catch wrong destructor here.
+ (MethodData.Define): Add errors 550, 668.
+
+ * cs-tokenizer.cs (PreProcessPragma): Add warning 1634.
+
+ * ecore.cs (PropertyExpr.DoResolveLValue): Fixed wrong error code.
+
+ * pending.cs (VerifyPendingMethods): Add error 551.
+
+ * typemanager.cs (CSharpName): Next error report helper.
+
2005-02-25 Marek Safar <[EMAIL PROTECTED]>
* attribute.cs (Atttribute.Resolve): Add cache for parameter-less
Modified: trunk/mcs/gmcs/class.cs
===================================================================
--- trunk/mcs/gmcs/class.cs 2005-04-13 11:42:15 UTC (rev 42907)
+++ trunk/mcs/gmcs/class.cs 2005-04-13 11:42:42 UTC (rev 42908)
@@ -3710,7 +3710,14 @@
}
Report.SymbolRelatedToPreviousError (method);
- Report.Error (111, Location, "Type '{0}'
already defines a member called '{1}' with the same parameter types",
Parent.Name, Name);
+ if (this is Operator && method is Operator)
+ Report.Error (557, Location,
+ "Duplicate user-defined
conversion in type '{0}'",
+ Parent.Name);
+ else
+ Report.Error (111, Location,
+ "Type '{0}' already
defines a member called '{1}' " +
+ "with the same parameter
types", Parent.Name, Name);
return true;
} else if (may_unify) {
Report.Error (408, Location,
@@ -3719,7 +3726,6 @@
Parent.MemberName);
return true;
}
-
return false;
}
@@ -4231,6 +4237,20 @@
}
}
+ protected override bool CheckBase() {
+ if (!base.CheckBase ())
+ return false;
+
+ // TODO: Destructor should derive from MethodCore
+ if (base_method != null && (ModFlags &
Modifiers.OVERRIDE) != 0 && Name == "Finalize" &&
+ base_method.DeclaringType ==
TypeManager.object_type && !(this is Destructor)) {
+ Report.Error (249, Location, "Do not override
object.Finalize. Instead, provide a destructor");
+ return false;
+ }
+
+ return true;
+ }
+
public EmitContext CreateEmitContext (TypeContainer tc,
ILGenerator ig)
{
return new EmitContext (
@@ -4977,7 +4997,7 @@
Type[] ParameterTypes = method.ParameterTypes;
if (container.Pending != null){
- if (member is Indexer)
+ if (member is Indexer) // TODO: test it, but it
should work without this IF
implementing =
container.Pending.IsInterfaceIndexer (
member.InterfaceType,
method.ReturnType, ParameterTypes);
else
@@ -4986,10 +5006,23 @@
if (member.InterfaceType != null){
if (implementing == null){
- Report.Error (539,
method.Location,
- "'{0}' in
explicit interface declaration is not a member of interface",
member.GetSignatureForError () );
+ if (member is PropertyBase) {
+ Report.Error (550,
method.Location, "'{0}' is an accessor not found in interface member '{1}'",
+
method.GetSignatureForError (container), member.ExplicitInterfaceName);
+
+ } else {
+ Report.Error (539,
method.Location,
+ "'{0}' in
explicit interface declaration is not a member of interface",
member.GetSignatureForError () );
+ }
return false;
}
+ } else {
+ if (implementing != null && method is
AbstractPropertyEventMethod && !implementing.IsSpecialName) {
+
Report.SymbolRelatedToPreviousError (implementing);
+ Report.Error (688,
method.Location, "Accessor '{0}' cannot implement interface member '{1}' for
type '{2}'. Use an explicit interface implementation",
+
method.GetSignatureForError (container), TypeManager.CSharpSignature
(implementing), container.GetSignatureForError ());
+ return false;
+ }
}
}
@@ -5265,6 +5298,7 @@
}
}
+ // Should derive from MethodCore
public class Destructor : Method {
public Destructor (TypeContainer ds, Expression return_type,
int mod, string name,
@@ -7441,6 +7475,14 @@
{
}
+ // TODO: one GetSignatureForError is enough (reuse
Parent member)
+ public override string GetSignatureForError
(TypeContainer tc)
+ {
+ string core = base.GetSignatureForError (tc);
+ return core.Replace
(TypeContainer.DefaultIndexerName,
+ String.Format ("this[{0}]",
TypeManager.CSharpName (ParameterTypes)));
+ }
+
public override Type[] ParameterTypes {
get {
return method.ParameterTypes;
@@ -7570,7 +7612,7 @@
if (IsExplicitImpl) {
Report.Error (415,
indexer_attr.Location,
- "The
'IndexerName' attribute is valid only on an" +
+ "The
'IndexerName' attribute is valid only on an " +
"indexer that is
not an explicit interface member declaration");
return false;
}
Modified: trunk/mcs/gmcs/cs-parser.jay
===================================================================
--- trunk/mcs/gmcs/cs-parser.jay 2005-04-13 11:42:15 UTC (rev 42907)
+++ trunk/mcs/gmcs/cs-parser.jay 2005-04-13 11:42:42 UTC (rev 42908)
@@ -97,6 +97,8 @@
/// assembly and module attribute definition is enabled
bool global_attrs_enabled = true;
+ bool has_get, has_set;
+
%}
%token EOF
@@ -363,8 +365,7 @@
: opt_attributes NAMESPACE namespace_or_type_name
{
if ($1 != null) {
- Report.Error(1518, Lexer.Location, "Attributes cannot
be applied to namespaces."
- + " Expected class, delegate, enum,
interface, or struct");
+ Report.Error(1671, Lexer.Location, "A namespace
declaration cannot have modifiers or attributes");
}
MemberName name = (MemberName) $3;
@@ -1024,6 +1025,11 @@
{
$$ = new VariableDeclaration ((string) $1, null,
lexer.Location);
}
+ | IDENTIFIER OPEN_BRACKET opt_expression CLOSE_BRACKET
+ {
+ Report.Error (650, lexer.Location, "Syntax error, bad array
declarator. To declare a managed array the rank specifier precedes the
variable's identifier. " +
+ "To declare a fixed buffer field, use the fixed keyword
before the field type");
+ }
;
variable_initializer
@@ -1329,9 +1335,13 @@
accessor_declarations
{
lexer.PropertyParsing = false;
+ has_get = has_set = false;
}
CLOSE_BRACE
{
+ if ($8 == null)
+ break;
+
Property prop;
Pair pair = (Pair) $8;
Accessor get_block = (Accessor) pair.First;
@@ -1359,26 +1369,33 @@
;
accessor_declarations
- : get_accessor_declaration opt_set_accessor_declaration
- {
- $$ = new Pair ($1, $2);
- }
- | set_accessor_declaration opt_get_accessor_declaration
+ : get_accessor_declaration
+ {
+ $$ = new Pair ($1, null);
+ }
+ | get_accessor_declaration accessor_declarations
+ {
+ Pair pair = (Pair) $2;
+ pair.First = $1;
+ $$ = pair;
+ }
+ | set_accessor_declaration
+ {
+ $$ = new Pair (null, $1);
+ }
+ | set_accessor_declaration accessor_declarations
+ {
+ Pair pair = (Pair) $2;
+ pair.Second = $1;
+ $$ = pair;
+ }
+ | error
{
- $$ = new Pair ($2, $1);
+ Report.Error (1014, lexer.Location, "A get or set accessor
expected");
+ $$ = null;
}
;
-opt_get_accessor_declaration
- : /* empty */ { $$ = null; }
- | get_accessor_declaration
- ;
-
-opt_set_accessor_declaration
- : /* empty */ { $$ = null; }
- | set_accessor_declaration
- ;
-
get_accessor_declaration
: opt_attributes opt_modifiers GET
{
@@ -1392,7 +1409,12 @@
}
accessor_body
{
+ if (has_get) {
+ Report.Error (1007, lexer.Location, "Property accessor
already defined");
+ break;
+ }
$$ = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes)
$1, lexer.Location);
+ has_get = true;
current_local_parameters = null;
lexer.PropertyParsing = true;
@@ -1433,7 +1455,12 @@
}
accessor_body
{
+ if (has_set) {
+ Report.Error (1007, lexer.Location, "Property accessor
already defined");
+ break;
+ }
$$ = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes)
$1, lexer.Location);
+ has_set = true;
current_local_parameters = null;
lexer.PropertyParsing = true;
@@ -1528,6 +1555,9 @@
interface_member_declaration
: interface_method_declaration
{
+ if ($1 == null)
+ break;
+
Method m = (Method) $1;
if (m.IsExplicitImpl)
@@ -1541,6 +1571,9 @@
}
| interface_property_declaration
{
+ if ($1 == null)
+ break;
+
Property p = (Property) $1;
if (p.IsExplicitImpl)
@@ -1569,6 +1602,9 @@
}
| interface_indexer_declaration
{
+ if ($1 == null)
+ break;
+
Indexer i = (Indexer) $1;
if (i.IsExplicitImpl)
@@ -1600,6 +1636,10 @@
{
Report.Error (524, lexer.Location, "Interfaces can not declare
interfaces");
}
+ | constant_declaration
+ {
+ Report.Error (525, lexer.Location, "Interfaces cannot contain
constants");
+ }
;
opt_new
@@ -1670,6 +1710,19 @@
if (RootContext.Documentation != null)
((Method) $$).DocComment = Lexer.consume_doc_comment ();
}
+ | opt_attributes opt_new type namespace_or_type_name
+ OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
+ {
+ lexer.ConstraintsParsing = true;
+ }
+ opt_type_parameter_constraints_clauses
+ OPEN_BRACE opt_statement_list CLOSE_BRACE
+ {
+ lexer.ConstraintsParsing = false;
+ Report.Error (531, lexer.Location, "'{0}': interface members
cannot have a definition", $4);
+ $$ = null;
+ }
+
;
interface_property_declaration
@@ -1682,6 +1735,14 @@
{ lexer.PropertyParsing = false; }
CLOSE_BRACE
{
+ if ($3 == TypeManager.system_void_expr) {
+ Report.Error (547, lexer.Location, "'{0}': property
cannot have void type", $4);
+ break;
+ }
+
+ if ($7 == null)
+ break;
+
InterfaceAccessorInfo pinfo = (InterfaceAccessorInfo) $7;
$$ = new Property (current_class, (Expression) $3, (int) $2,
true,
@@ -1701,12 +1762,21 @@
interface_accessors
: opt_attributes opt_modifiers GET SEMICOLON
{ $$ = new InterfaceAccessorInfo (true, false, (Attributes) $1, null,
(int) $2, 0, lexer.Location, lexer.Location); }
+ | opt_attributes opt_modifiers GET OPEN_BRACE
+ {
+ Report.Error (531, lexer.Location, "'{0}': interface members
cannot have a definition", ".get");
+ $$ = null;
+ }
| opt_attributes opt_modifiers SET SEMICOLON
{ $$ = new InterfaceAccessorInfo (false, true, null, (Attributes) $1,
0, (int) $2, lexer.Location, lexer.Location); }
| opt_attributes opt_modifiers GET SEMICOLON opt_attributes
opt_modifiers SET SEMICOLON
{ $$ = new InterfaceAccessorInfo (true, true, (Attributes) $1,
(Attributes) $5, (int) $2, (int) $6, lexer.Location, lexer.Location); }
| opt_attributes opt_modifiers SET SEMICOLON opt_attributes
opt_modifiers GET SEMICOLON
{ $$ = new InterfaceAccessorInfo (true, true, (Attributes) $5,
(Attributes) $1, (int) $6, (int) $2, lexer.Location, lexer.Location); }
+ |
+ {
+ Report.Error (548, lexer.Location, "'{0}' : property or indexer
must have at least one accessor", "");
+ }
;
interface_event_declaration
@@ -1726,8 +1796,16 @@
Report.Error (68, lexer.Location, "Event declarations on
interfaces can not be initialized.");
$$ = null;
}
- | opt_attributes opt_new EVENT type IDENTIFIER OPEN_BRACE
event_accessor_declarations CLOSE_BRACE {
- Report.Error (69, lexer.Location, "Event accessors not valid on
interfaces");
+ | opt_attributes opt_new EVENT type IDENTIFIER OPEN_BRACE
+ {
+ lexer.EventParsing = true;
+ }
+ event_accessor_declarations
+ {
+ lexer.EventParsing = false;
+ }
+ CLOSE_BRACE {
+ Report.Error (69, lexer.Location, "Event in interface cannot
have add or remove accessors");
$$ = null;
}
;
@@ -1741,6 +1819,9 @@
{ lexer.PropertyParsing = false; }
CLOSE_BRACE
{
+ if ($10 == null)
+ break;
+
InterfaceAccessorInfo info = (InterfaceAccessorInfo) $10;
$$ = new Indexer (current_class, (Expression) $3,
@@ -2232,10 +2313,14 @@
accessor_declarations
{
lexer.PropertyParsing = false;
+ has_get = has_set = false;
parsing_indexer = false;
}
CLOSE_BRACE
{
+ if ($7 == null)
+ break;
+
// The signature is computed from the signature of the indexer.
Look
// at section 3.6 on the spec
Location loc = (Location) $5;
@@ -2449,40 +2534,6 @@
current_delegate = null;
}
- | opt_attributes
- opt_modifiers
- DELEGATE VOID member_name
- OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
- {
- Location l = lexer.Location;
- MemberName name = MakeName ((MemberName) $5);
- Delegate del = new Delegate (
- current_namespace, current_container,
- TypeManager.system_void_expr, (int) $2, name,
- (Parameters) $7, (Attributes) $1, l);
-
- if (RootContext.Documentation != null) {
- del.DocComment = Lexer.consume_doc_comment ();
- Lexer.doc_state = XmlCommentState.Allowed;
- }
-
- current_container.AddDelegate (del);
- RootContext.Tree.RecordDecl (name.GetName (true), del);
-
- current_delegate = del;
-
- lexer.ConstraintsParsing = true;
- }
- opt_type_parameter_constraints_clauses
- {
- lexer.ConstraintsParsing = false;
- }
- SEMICOLON
- {
- current_delegate.SetParameterInfo ((ArrayList) $9);
-
- current_delegate = null;
- }
;
opt_nullable
Modified: trunk/mcs/gmcs/cs-tokenizer.cs
===================================================================
--- trunk/mcs/gmcs/cs-tokenizer.cs 2005-04-13 11:42:15 UTC (rev 42907)
+++ trunk/mcs/gmcs/cs-tokenizer.cs 2005-04-13 11:42:42 UTC (rev 42908)
@@ -1470,21 +1470,22 @@
/// </summary>
void PreProcessPragma (string arg)
{
- const string disable = "warning disable";
- const string restore = "warning restore";
+ const string warning = "warning";
+ const string w_disable = warning + " disable";
+ const string w_restore = warning + " restore";
- if (arg == disable) {
+ if (arg == w_disable) {
Report.RegisterWarningRegion
(Location).WarningDisable (line);
return;
}
- if (arg == restore) {
+ if (arg == w_restore) {
Report.RegisterWarningRegion
(Location).WarningEnable (line);
return;
}
- if (arg.StartsWith (disable)) {
- int[] codes = ParseNumbers (arg.Substring
(disable.Length));
+ if (arg.StartsWith (w_disable)) {
+ int[] codes = ParseNumbers (arg.Substring
(w_disable.Length));
foreach (int code in codes) {
if (code != 0)
Report.RegisterWarningRegion
(Location).WarningDisable (Location, code);
@@ -1492,15 +1493,18 @@
return;
}
- if (arg.StartsWith (restore)) {
- int[] codes = ParseNumbers (arg.Substring
(restore.Length));
+ if (arg.StartsWith (w_restore)) {
+ int[] codes = ParseNumbers (arg.Substring
(w_restore.Length));
foreach (int code in codes) {
Report.RegisterWarningRegion
(Location).WarningEnable (Location, code);
}
return;
}
- return;
+ if (arg.StartsWith (warning)) {
+ Report.Warning (1634, 1, Location , "Expected
disable or restore");
+ return;
+ }
}
int[] ParseNumbers (string text)
Modified: trunk/mcs/gmcs/ecore.cs
===================================================================
--- trunk/mcs/gmcs/ecore.cs 2005-04-13 11:42:15 UTC (rev 42907)
+++ trunk/mcs/gmcs/ecore.cs 2005-04-13 11:42:42 UTC (rev 42908)
@@ -3431,10 +3431,9 @@
if (getter == null)
return null;
- Report.Error (154, loc,
- "The property `" +
PropertyInfo.Name +
- "' can not be used in " +
- "this context because it lacks a
set accessor");
+ // TODO: Print better property name
+ Report.Error (200, loc, "Property or indexer
'{0}' cannot be assigned to -- it is read only",
+ PropertyInfo.Name);
return null;
}
Modified: trunk/mcs/gmcs/pending.cs
===================================================================
--- trunk/mcs/gmcs/pending.cs 2005-04-13 11:42:15 UTC (rev 42907)
+++ trunk/mcs/gmcs/pending.cs 2005-04-13 11:42:42 UTC (rev 42908)
@@ -551,16 +551,23 @@
if (pending_implementations
[i].optional)
continue;
-
+
+
Report.SymbolRelatedToPreviousError (mi);
if (pending_implementations
[i].found [j]) {
- string[] methodLabel =
TypeManager.CSharpSignature (mi).Split ('.');
- Report.Error (536,
container.Location,
- "'{0}'
does not implement interface member '{1}'. '{2}.{3}' " +
- "is
either static, not public, or has the wrong return type",
-
container.Name, TypeManager.CSharpSignature (mi),
-
container.Name, methodLabel[methodLabel.Length - 1]);
+ if (mi.IsSpecialName) {
+ string name =
TypeManager.CSharpName (mi.DeclaringType) + '.' + mi.Name.Substring (4);
+ Report.Error
(551, container.Location, "Explicit interface implementation '{0}.{1}' is
missing accessor '{1}'",
+
container.Name, name);
+ } else {
+ string[]
methodLabel = TypeManager.CSharpSignature (mi).Split ('.');
+ Report.Error
(536, container.Location,
+ "'{0}'
does not implement interface member '{1}'. '{2}.{3}' " +
+ "is
either static, not public, or has the wrong return type",
+
container.Name, TypeManager.CSharpSignature (mi),
+
container.Name, methodLabel[methodLabel.Length - 1]);
+ }
}
- else {
+ else {
Report.Error (535,
container.Location, "'{0}' does not implement interface member '{1}'",
container.Name,
TypeManager.CSharpSignature (mi));
}
Modified: trunk/mcs/gmcs/typemanager.cs
===================================================================
--- trunk/mcs/gmcs/typemanager.cs 2005-04-13 11:42:15 UTC (rev 42907)
+++ trunk/mcs/gmcs/typemanager.cs 2005-04-13 11:42:42 UTC (rev 42908)
@@ -855,6 +855,17 @@
@"(\W+|\b)",
new MatchEvaluator (CSharpNameMatch)).Replace ('+',
'.');
}
+
+ static public string CSharpName (Type[] types)
+ {
+ StringBuilder sb = new StringBuilder ();
+ foreach (Type t in types) {
+ sb.Append (CSharpName (t));
+ sb.Append (',');
+ }
+ sb.Remove (sb.Length - 1, 1);
+ return sb.ToString ();
+ }
static String CSharpNameMatch (Match match)
{
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches