**** Merged r38418-r38487 from MCS ****
authorMartin Baulig <martin@novell.com>
Tue, 25 Jan 2005 01:52:55 +0000 (01:52 -0000)
committerMartin Baulig <martin@novell.com>
Tue, 25 Jan 2005 01:52:55 +0000 (01:52 -0000)
svn path=/trunk/mcs/; revision=39453

mcs/gmcs/ChangeLog
mcs/gmcs/attribute.cs
mcs/gmcs/class.cs
mcs/gmcs/cs-parser.jay
mcs/gmcs/cs-tokenizer.cs
mcs/gmcs/decl.cs
mcs/gmcs/doc.cs
mcs/gmcs/enum.cs

index aa21c5a2fa4485f54942a4cac9063c46f0a169d1..a75c16134d42b2eea6cc7a2322a35de603654a69 100644 (file)
@@ -1,3 +1,65 @@
+2005-01-08  Miguel de Icaza  <miguel@ximian.com>
+
+       * attribute.cs: Check for null and empty strings.  
+
+       I have lost another battle to Paolo.
+
+2005-01-07  Marek Safar  <marek.safar@seznam.cz>
+
+       Fix #70942
+       * class.cs (PropertyMethod): Set Parent field in ctors.
+       (SetMethod.InternalParameters): Add unsafe switch hack.
+       Override MarkForDuplicationCheck where it is appropriate.
+
+       * decl.cs (MemberCore.MarkForDuplicationCheck): New method.
+       It says whether container allows members with the same name.
+       Base default is no.
+       (DeclSpace.AddToContainer): Use MarkForDuplicationCheck.
+       Removed is_method parameter.
+
+2005-01-06  Duncan Mak  <duncan@ximian.com>
+
+       * cs-tokenizer.cs (xtoken): Redo the work for signaling CS1040
+       because the previous change led to incorrect reporting of CS1032
+       ("Cannot define/undefine preprocessor symbols after first token in
+       file"). Instead of using `tokens_seen' as the only flag that
+       triggers CS1040, introduce `comments_seen'. This new flag is used
+       to signify having seen comments on the current line, so it is
+       unset after a newline.
+
+2005-01-06  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * doc.cs : When searching for a type, find nested type too.
+         This fixes bug #71040.
+
+2005-01-06  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * doc.cs :
+         - Warn missing member comment on those classes which also does not
+           have doc comments. Fixed bug #71041.
+         - Don't warn missing doc comment on default constructor.
+           Fixed bug #71042.
+
+2005-01-06  Duncan Mak  <duncan@ximian.com>
+
+       * cs-tokenizer.cs (xtoken): After handling traditional C-style
+       comments, set `tokens_seen' to true. This allows us to detect
+       misplaced preprocessor directives (i.e. not at the beginning of
+       the a line, nor after whitespaces). In that case, report error
+       CS1040. This fixes bug #56460.
+
+       * cs-parser.jay (interface_member_declaration): Add checks for
+       IsExplicitImpl, and report CS0541 error if an interface member is
+       defined as an explicit interface declaration.
+
+2005-01-06  Marek Safar  <marek.safar@seznam.cz>
+
+       Fix #70817
+       * class.cs (PropertyMethod): Set Parent field in ctors.
+       (SetMethod.InternalParameters): Add unsafe switch hack.
+       
+       * decl.cs (MemberCore.Parent): Cannot be readonly.
+
 2005-01-06  Raja R Harinath  <rharinath@novell.com>
 
        * decl.cs (DeclSpace.ResolveType): Remove.
index a007d89a5a4b3f663ca59580c07dffa901018414..00ecbb8b2ae4c296e84d6c8fb27ff8693c889052 100644 (file)
@@ -117,13 +117,18 @@ namespace Mono.CSharp {
                                      Name);
                }
 
-               static void Error_AttributeArgumentNotValid (Location loc)
+               static void Error_AttributeArgumentNotValid (string extra, Location loc)
                {
                        Report.Error (182, loc,
                                      "An attribute argument must be a constant expression, typeof " +
-                                     "expression or array creation expression");
+                                     "expression or array creation expression" + extra);
                }
 
+               static void Error_AttributeArgumentNotValid (Location loc)
+               {
+                       Error_AttributeArgumentNotValid ("", loc);
+               }
+               
                static void Error_TypeParameterInAttribute (Location loc)
                {
                        Report.Error (
@@ -1032,10 +1037,14 @@ namespace Mono.CSharp {
                        if (tmp.Expr is Constant)
                                dll_name = (string) ((Constant) tmp.Expr).GetValue ();
                        else { 
-                               Error_AttributeArgumentNotValid (Location);
+                               Error_AttributeArgumentNotValid ("", Location);
                                return null;
                        }
-
+                       if (dll_name == null || dll_name == ""){
+                               Error_AttributeArgumentNotValid (": DllImport requires a non-empty string", Location);
+                               return null;
+                       }
+                       
                        // Now we process the named arguments
                        CallingConvention cc = CallingConvention.Winapi;
                        CharSet charset = CharSet.Ansi;
index fc030464fd93f8cf3f16ea049740afdbb0cc08da..2e7c39217db19cf95f1b637e50bba7d8e99acad1 100644 (file)
@@ -469,19 +469,19 @@ namespace Mono.CSharp {
                        base_class_name = null;
                }
 
-               public bool AddToMemberContainer (MemberCore symbol, bool is_method)
+               public bool AddToMemberContainer (MemberCore symbol)
                {
-                       return AddToContainer (symbol, is_method, String.Concat (Name, '.', symbol.Name), symbol.Name);
+                       return AddToContainer (symbol, String.Concat (Name, '.', symbol.Name), symbol.Name);
                }
 
                bool AddToTypeContainer (DeclSpace ds)
                {
-                       return AddToContainer (ds, false, ds.Name, ds.Basename);
+                       return AddToContainer (ds, ds.Name, ds.Basename);
                }
 
                public void AddConstant (Const constant)
                {
-                       if (!AddToMemberContainer (constant, false))
+                       if (!AddToMemberContainer (constant))
                                return;
 
                        if (constants == null)
@@ -522,7 +522,7 @@ namespace Mono.CSharp {
 
                public void AddMethod (Method method)
                {
-                       if (!AddToMemberContainer (method, true))
+                       if (!AddToMemberContainer (method))
                                return;
 
                        if (methods == null)
@@ -583,7 +583,7 @@ namespace Mono.CSharp {
 
                public void AddField (Field field)
                {
-                       if (!AddToMemberContainer (field, false))
+                       if (!AddToMemberContainer (field))
                                return;
 
                        if (fields == null)
@@ -612,8 +612,8 @@ namespace Mono.CSharp {
 
                public void AddProperty (Property prop)
                {
-                       if (!AddToMemberContainer (prop, false) || 
-                           !AddToMemberContainer (prop.Get, true) || !AddToMemberContainer (prop.Set, true))
+                       if (!AddToMemberContainer (prop) || 
+                               !AddToMemberContainer (prop.Get) || !AddToMemberContainer (prop.Set))
                                return;
 
                        if (properties == null)
@@ -627,14 +627,14 @@ namespace Mono.CSharp {
 
                public void AddEvent (Event e)
                {
-                       if (!AddToMemberContainer (e, false))
+                       if (!AddToMemberContainer (e))
                                return;
 
                        if (e is EventProperty) {
-                               if (!AddToMemberContainer (e.Add, true))
+                               if (!AddToMemberContainer (e.Add))
                                        return;
 
-                               if (!AddToMemberContainer (e.Remove, true))
+                               if (!AddToMemberContainer (e.Remove))
                                        return;
                        }
 
@@ -660,7 +660,7 @@ namespace Mono.CSharp {
 
                public void AddOperator (Operator op)
                {
-                       if (!AddToMemberContainer (op, true))
+                       if (!AddToMemberContainer (op))
                                return;
 
                        if (operators == null)
@@ -4051,6 +4051,12 @@ namespace Mono.CSharp {
                        return mi;
                }
        
+               public override bool MarkForDuplicationCheck ()
+               {
+                       caching_flags |= Flags.TestMethodDuplication;
+                       return true;
+               }
+
                protected override bool VerifyClsCompliance(DeclSpace ds)
                {
                        if (!base.VerifyClsCompliance (ds))
@@ -6106,11 +6112,16 @@ namespace Mono.CSharp {
                                Parameter [] parms = new Parameter [1];
                                parms [0] = new Parameter (method.Type, "value", Parameter.Modifier.NONE, null);
                                Parameters parameters = new Parameters (parms, null, method.Location);
+
+                               bool old_unsafe = ec.InUnsafe;
+                               ec.InUnsafe = InUnsafe;
                                Type [] types = parameters.GetParameterInfo (ec);
+                               ec.InUnsafe = old_unsafe;
+
                                return new InternalParameters (types, parameters);
                        }
 
-                       public override MethodBuilder Define(TypeContainer container)
+                       public override MethodBuilder Define (TypeContainer container)
                        {
                                if (container.EmitContext == null)
                                        throw new InternalErrorException ("SetMethod.Define called too early");
@@ -6159,12 +6170,14 @@ namespace Mono.CSharp {
                                : base (method, prefix)
                        {
                                this.method = method;
+                               Parent = method.Parent;
                        }
 
                        public PropertyMethod (MethodCore method, Accessor accessor, string prefix)
                                : base (method, accessor, prefix)
                        {
                                this.method = method;
+                               Parent = method.Parent;
                                this.ModFlags = accessor.ModFlags;
 
                                if (accessor.ModFlags != 0 && RootContext.Version == LanguageVersion.ISO_1) {
@@ -6255,6 +6268,12 @@ namespace Mono.CSharp {
                                        Report.Error (273, Location, "{0}: accessibility modifier must be more restrictive than the property or indexer",
                                                GetSignatureForError (container));
                        }
+
+                       public override bool MarkForDuplicationCheck ()
+                       {
+                               caching_flags |= Flags.TestMethodDuplication;
+                               return true;
+                       }
                }
 
                public PropertyMethod Get, Set;
@@ -6338,7 +6357,6 @@ namespace Mono.CSharp {
                        return TypeManager.CSharpSignature (PropertyBuilder, false);
                }
 
-
                protected override bool CheckForDuplications ()
                {
                        ArrayList ar = Parent.Indexers;
@@ -7313,8 +7331,8 @@ namespace Mono.CSharp {
                                UpdateMemberName ();
                        }
 
-                       if (!Parent.AddToMemberContainer (this, true) ||
-                           !Parent.AddToMemberContainer (Get, true) || !Parent.AddToMemberContainer (Set, true))
+                       if (!Parent.AddToMemberContainer (this) ||
+                               !Parent.AddToMemberContainer (Get) || !Parent.AddToMemberContainer (Set))
                                return false;
 
                        if (!CheckBase ())
@@ -7393,6 +7411,13 @@ namespace Mono.CSharp {
                {
                        return String.Concat (tc.Name, ".this[", Parameters.FixedParameters [0].TypeName.ToString (), ']');
                }
+
+               public override bool MarkForDuplicationCheck ()
+               {
+                       caching_flags |= Flags.TestMethodDuplication;
+                       return true;
+               }
+
        }
 
        public class Operator : MethodCore, IIteratorContainer {
@@ -7736,6 +7761,12 @@ namespace Mono.CSharp {
                        return ToString ();
                }
                
+               public override bool MarkForDuplicationCheck ()
+               {
+                       caching_flags |= Flags.TestMethodDuplication;
+                       return true;
+               }
+
                public override string ToString ()
                {
                        if (OperatorMethod == null)
index 0a9358f12f5ea627a0e707d4d36552111eb1a863..cb0b929bd4490a183b3e939a4c8ea4bfc2593604 100644 (file)
@@ -91,9 +91,7 @@ namespace Mono.CSharp
                ///
                string tmpComment;
                string enumTypeComment;
-
-               
-               
+                       
                /// Current attribute target
                string current_attr_target;
                
@@ -1504,6 +1502,10 @@ interface_member_declaration
          { 
                Method m = (Method) $1;
 
+               if (m.IsExplicitImpl)
+                       Report.Error (541, lexer.Location, 
+                               "Explicit interface declaration can only be declared in a class or struct");
+
                current_container.AddMethod (m);
 
                if (RootContext.Documentation != null)
@@ -1513,6 +1515,10 @@ interface_member_declaration
          { 
                Property p = (Property) $1;
 
+               if (p.IsExplicitImpl)
+                       Report.Error (541, lexer.Location, 
+                               "Explicit interface declaration can only be declared in a class or struct");
+
                current_container.AddProperty (p);
 
                if (RootContext.Documentation != null)
@@ -1522,6 +1528,11 @@ interface_member_declaration
           { 
                if ($1 != null){
                        Event e = (Event) $1;
+
+                       if (e.IsExplicitImpl)
+                               Report.Error (541, lexer.Location, 
+                                   "Explicit interface declaration can only be declared in a class or struct");
+                       
                        current_container.AddEvent (e);
                }
 
@@ -1532,6 +1543,10 @@ interface_member_declaration
          { 
                Indexer i = (Indexer) $1;
 
+               if (i.IsExplicitImpl)
+                       Report.Error (541, lexer.Location, 
+                               "Explicit interface declaration can only be declared in a class or struct");
+
                current_container.AddIndexer (i);
 
                if (RootContext.Documentation != null)
index e34cdb5cfe2430a777074dfeb45af753235acbc0..61d11c3a9d2dffce4cb91632a28a776c9cf6b86b 100644 (file)
@@ -66,6 +66,7 @@ namespace Mono.CSharp
                // after a token has been seen.
                //
                bool any_token_seen = false;
+
                static Hashtable tokenValues;
                
                private static Hashtable TokenValueName
@@ -2014,6 +2015,9 @@ namespace Mono.CSharp
                        bool doread = false;
                        int c;
 
+                       // Whether we have seen comments on the current line
+                       bool comments_seen = false;
+                       
                        val = null;
                        // optimization: eliminate col and implement #directive semantic correctly.
                        for (;(c = getChar ()) != -1; col++) {
@@ -2092,6 +2096,7 @@ namespace Mono.CSharp
                                                        if (d == '*' && peekChar () == '/'){
                                                                getChar ();
                                                                col++;
+                                                               comments_seen = true;
                                                                break;
                                                        }
                                                        if (docAppend)
@@ -2120,15 +2125,25 @@ namespace Mono.CSharp
                                        col = 0;
                                        any_token_seen |= tokens_seen;
                                        tokens_seen = false;
+                                       comments_seen = false;
                                        continue;
                                }
 
                                /* For now, ignore pre-processor commands */
                                // FIXME: In C# the '#' is not limited to appear
                                // on the first column.
-                               if (c == '#' && !tokens_seen){
+                               if (c == '#'{
                                        bool cont = true;
                                        
+                                       if (tokens_seen || comments_seen) {
+                                               error_details = "Preprocessor directives must appear as the first non-whitespace " +
+                                                       "character on a line.";
+
+                                               Report.Error (1040, Location, error_details);
+
+                                               return Token.ERROR;
+                                       }
+                                       
                                start_again:
                                        
                                        cont = handle_preprocessing_directive (cont);
index 51cc74a2c864f845ec795c4d9ef979a92b1894a6..9d71ad01cdbc1618f2efaf2728305b4f721b29e9 100644 (file)
@@ -218,7 +218,7 @@ namespace Mono.CSharp {
                /// </summary>
                public int ModFlags;
 
-               public readonly TypeContainer Parent;
+               public /*readonly*/ TypeContainer Parent;
 
                /// <summary>
                ///   Location where this declaration happens
@@ -426,6 +426,14 @@ namespace Mono.CSharp {
                        }
                }
 
+               /// <summary>
+               /// It helps to handle error 102 & 111 detection
+               /// </summary>
+               public virtual bool MarkForDuplicationCheck ()
+               {
+                       return false;
+               }
+
                /// <summary>
                /// The main virtual method for CLS-Compliant verifications.
                /// The method returns true if member is CLS-Compliant and false if member is not
@@ -568,7 +576,7 @@ namespace Mono.CSharp {
                /// <summary>
                /// Adds the member to defined_names table. It tests for duplications and enclosing name conflicts
                /// </summary>
-               protected bool AddToContainer (MemberCore symbol, bool is_method, string fullname, string basename)
+               protected bool AddToContainer (MemberCore symbol, string fullname, string basename)
                {
                        if (basename == Basename && !(this is Interface)) {
                                if (symbol is TypeParameter)
@@ -584,26 +592,23 @@ namespace Mono.CSharp {
 
                        MemberCore mc = (MemberCore)defined_names [fullname];
 
-                       if (is_method && (mc is MethodCore || mc is IMethodData)) {
-                               symbol.caching_flags |= Flags.TestMethodDuplication;
-                               mc.caching_flags |= Flags.TestMethodDuplication;
+                       if (mc == null) {
+                               defined_names.Add (fullname, symbol);
                                return true;
                        }
 
-                       if (mc != null) {
-                               if (symbol is TypeParameter)
-                                       Report.Error (692, symbol.Location, "Duplicate type parameter `{0}'", basename);
-                               else {
-                                       Report.SymbolRelatedToPreviousError (mc);
-                                       Report.Error (102, symbol.Location,
-                                                     "The type '{0}' already contains a definition for '{1}'",
-                                                     GetSignatureForError (), basename);
-                               }
-                               return false;
-                       }
+                       if (symbol.MarkForDuplicationCheck () && mc.MarkForDuplicationCheck ())
+                               return true;
 
-                       defined_names.Add (fullname, symbol);
-                       return true;
+                       if (symbol is TypeParameter)
+                               Report.Error (692, symbol.Location, "Duplicate type parameter `{0}'", basename);
+                       else {
+                               Report.SymbolRelatedToPreviousError (mc);
+                               Report.Error (102, symbol.Location,
+                                             "The type '{0}' already contains a definition for '{1}'",
+                                             GetSignatureForError (), basename);
+                       }
+                       return false;
                }
 
                public void RecordDecl ()
@@ -1374,7 +1379,7 @@ namespace Mono.CSharp {
                                type_params [i] = new TypeParameter (Parent, name, constraints, Location);
 
                                string full_name = Name + "." + name;
-                               AddToContainer (type_params [i], false, full_name, name);
+                               AddToContainer (type_params [i], full_name, name);
                        }
                }
 
index 125eafbd433b336d0a33a80bd0db224467c8d2cd..990e1ee5d641ab93aac4747d11bc9938f20dbef2 100644 (file)
@@ -170,13 +170,11 @@ namespace Mono.CSharp {
 
                                n.WriteTo (RootContext.Documentation.XmlCommentOutput);
                        }
-                       else if (mc.IsExposedFromAssembly (ds) &&
-                               // There are no warnings when the container also
-                               // misses documentations.
-                               (ds == null || ds.DocComment != null))
-                       {
-                               Report.Warning (1591, 4, mc.Location,
-                                       "Missing XML comment for publicly visible type or member '{0}'", mc.GetSignatureForError ());
+                       else if (mc.IsExposedFromAssembly (ds)) {
+                               Constructor c = mc as Constructor;
+                               if (c == null || !c.IsDefault ())
+                                       Report.Warning (1591, 4, mc.Location,
+                                               "Missing XML comment for publicly visible type or member '{0}'", mc.GetSignatureForError ());
                        }
                }
 
@@ -264,7 +262,7 @@ namespace Mono.CSharp {
                // be C# specific type name.
                //
                private static Type FindDocumentedType (MemberCore mc,
-                       string name, DeclSpace ds, bool allowAlias)
+                       string name, DeclSpace ds, bool allowAlias, string cref)
                {
                        bool isArray = false;
                        string identifier = name;
@@ -276,14 +274,15 @@ namespace Mono.CSharp {
                                }
                        }
                        Type t = FindDocumentedTypeNonArray (mc, identifier,
-                               ds, allowAlias);
+                               ds, allowAlias, cref);
                        if (t != null && isArray)
                                t = Array.CreateInstance (t, 0).GetType ();
                        return t;
                }
 
                private static Type FindDocumentedTypeNonArray (MemberCore mc,
-                       string identifier, DeclSpace ds, bool allowAlias)
+                       string identifier, DeclSpace ds, bool allowAlias,
+                       string cref)
                {
                        switch (identifier) {
                        case "int":
@@ -326,7 +325,22 @@ namespace Mono.CSharp {
                        }
                        Type t = ds.FindType (mc.Location, identifier);
                        if (t == null)
-                               t = TypeManager.LookupTypeDirect (identifier);
+                               t = TypeManager.LookupType (identifier);
+                       if (t == null) {
+                               int index = identifier.LastIndexOf ('.');
+                               if (index < 0)
+                                       return null;
+                               int warn;
+                               Type parent = FindDocumentedType (mc,
+                                       identifier.Substring (0, index),
+                                       ds, allowAlias, cref);
+                               if (parent == null)
+                                       return null;
+                               t = FindDocumentedMember (mc, parent,
+                                       identifier.Substring (index + 1),
+                                       emptyParamList,
+                                       ds, out warn, cref) as Type;
+                       }
                        return t;
                }
 
@@ -451,7 +465,7 @@ namespace Mono.CSharp {
                                ((PropertyInfo) mi).PropertyType :
                                null;
                        if (returnTypeName != null) {
-                               Type returnType = FindDocumentedType (mc, returnTypeName, ds, true);
+                               Type returnType = FindDocumentedType (mc, returnTypeName, ds, true, cref);
                                if (returnType == null || returnType != expected) {
                                        warningType = 1581;
                                        Report.Warning (1581, 1, mc.Location, "Invalid return type in XML comment cref attribute '{0}'", cref);
@@ -532,7 +546,7 @@ namespace Mono.CSharp {
                                ArrayList plist = new ArrayList ();
                                for (int i = 0; i < paramList.Length; i++) {
                                        string paramTypeName = paramList [i].Trim (wsChars);
-                                       Type paramType = FindDocumentedType (mc, paramTypeName, ds, true);
+                                       Type paramType = FindDocumentedType (mc, paramTypeName, ds, true, cref);
                                        if (paramType == null) {
                                                Report.Warning (1580, 1, mc.Location, "Invalid type for parameter '{0}' in XML comment cref attribute '{1}'", i + 1, cref);
                                                return;
@@ -552,7 +566,7 @@ namespace Mono.CSharp {
                                parameters = sb.ToString ();
                        }
 
-                       Type type = FindDocumentedType (mc, name, ds, true);
+                       Type type = FindDocumentedType (mc, name, ds, true, cref);
                        if (type != null) {
                                xref.SetAttribute ("cref", "T:" + type.FullName.Replace ("+", "."));
                                return; // a type
@@ -568,7 +582,7 @@ namespace Mono.CSharp {
                        if (period > 0) {
                                string typeName = name.Substring (0, period);
                                string memberName = name.Substring (period + 1);
-                               type = FindDocumentedType (mc, typeName, ds, false);
+                               type = FindDocumentedType (mc, typeName, ds, false, cref);
                                int warnResult;
                                if (type != null) {
                                        MemberInfo mi = FindDocumentedMember (mc, type, memberName, parameterTypes, ds, out warnResult, cref);
index 1961216e01fc9ca38200bfcc0ecd2d282e5e84c7..c969a4a9bb5a1597f74c9335c79b3733b5144188 100644 (file)
@@ -166,7 +166,7 @@ namespace Mono.CSharp {
 
                        EnumMember em = new EnumMember (this, expr, name, loc, opt_attrs);
                        em.DocComment = documentation;
-                       if (!AddToContainer (em, false, name, ""))
+                       if (!AddToContainer (em, name, ""))
                                return;