+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.
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 (
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;
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)
public void AddMethod (Method method)
{
- if (!AddToMemberContainer (method, true))
+ if (!AddToMemberContainer (method))
return;
if (methods == null)
public void AddField (Field field)
{
- if (!AddToMemberContainer (field, false))
+ if (!AddToMemberContainer (field))
return;
if (fields == null)
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)
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;
}
public void AddOperator (Operator op)
{
- if (!AddToMemberContainer (op, true))
+ if (!AddToMemberContainer (op))
return;
if (operators == null)
return mi;
}
+ public override bool MarkForDuplicationCheck ()
+ {
+ caching_flags |= Flags.TestMethodDuplication;
+ return true;
+ }
+
protected override bool VerifyClsCompliance(DeclSpace ds)
{
if (!base.VerifyClsCompliance (ds))
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");
: 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) {
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;
return TypeManager.CSharpSignature (PropertyBuilder, false);
}
-
protected override bool CheckForDuplications ()
{
ArrayList ar = Parent.Indexers;
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 ())
{
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 {
return ToString ();
}
+ public override bool MarkForDuplicationCheck ()
+ {
+ caching_flags |= Flags.TestMethodDuplication;
+ return true;
+ }
+
public override string ToString ()
{
if (OperatorMethod == null)
///
string tmpComment;
string enumTypeComment;
-
-
-
+
/// Current attribute target
string current_attr_target;
{
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)
{
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)
{
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);
}
{
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)
// after a token has been seen.
//
bool any_token_seen = false;
+
static Hashtable tokenValues;
private static Hashtable TokenValueName
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++) {
if (d == '*' && peekChar () == '/'){
getChar ();
col++;
+ comments_seen = true;
break;
}
if (docAppend)
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);
/// </summary>
public int ModFlags;
- public readonly TypeContainer Parent;
+ public /*readonly*/ TypeContainer Parent;
/// <summary>
/// Location where this declaration happens
}
}
+ /// <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
/// <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)
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 ()
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);
}
}
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 ());
}
}
// 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;
}
}
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":
}
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;
}
((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);
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;
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
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);
EnumMember em = new EnumMember (this, expr, name, loc, opt_attrs);
em.DocComment = documentation;
- if (!AddToContainer (em, false, name, ""))
+ if (!AddToContainer (em, name, ""))
return;