+2004-09-13 Marek Safar <marek.safar@seznam.cz>
+
+ * class.cs (MethodCore.CheckBase): Fix bug #65757.
+
+2004-09-12 Marek Safar <marek.safar@seznam.cz>
+
+ * attribute.cs (Attribute.Resolve): Add error 653 report.
+
+ * class.cs (Class.ApplyAttributeBuilder): Add error 641
+ report.
+ (Method.ApplyAttributeBuilder): Add error 685 report.
+ (Operator.Define): Add error 564 report.
+
+ * cs-tokenizer.cs (handle_hex): Add error 1013 report.
+
+ * expression.cs (Invocation.DoResolve): Add error
+ 245 and 250 report.
+
+ * parameter.cs (Parameter.ApplyAttributeBuilder): Add
+ error 674 report.
+
+2004-09-11 Marek Safar <marek.safar@seznam.cz>
+
+ * class.cs (ConstructorInitializer.Resolve):
+ Wrong error number (515->516).
+
+2004-09-11 Marek Safar <marek.safar@seznam.cz>
+
+ * class.cs (Indexer.Define): Add error 631 report.
+
+2004-09-11 Marek Safar <marek.safar@seznam.cz>
+
+ * ecore.cs (Error_NegativeArrayIndex): Fix 248 error.
+
+2004-09-11 Marek Safar <marek.safar@seznam.cz>
+
+ * expression.cs (Probe.DoResolve): Add error CS0241 report.
+
+2004-09-10 Marek Safar <marek.safar@seznam.cz>
+
+ * cs-parser.jay: Added error CS0241 report.
+
+2004-09-10 Raja R Harinath <rharinath@novell.com>
+
+ * cs-parser.jay (fixed_statement): Introduce a scope for the
+ declaration in the 'fixed' statement.
+
+2004-09-09 Marek Safar <marek.safar@seznam.cz>
+
+ * cs-parser.jay: Added CS0230 error report.
+
+2004-09-09 Marek Safar <marek.safar@seznam.cz>
+
+ * cs-parser.jay: Added errors CS0231 and CS0257 report.
+
+2004-09-09 Marek Safar <marek.safar@seznam.cz>
+
+ * expression.cs (Argument.Resolve): Added error CS0192 and
+ CS0199 report.
+
+2004-09-09 Marek Safar <marek.safar@seznam.cz>
+
+ C# 2.0 #pragma warning feature
+
+ * cs-tokenizer.cs (PreProcessPragma): New method;
+ Handles #pragma directive.
+
+ * report.cs (WarningRegions): New class; Support
+ class for #pragma warning directive. It tests whether
+ warning is enabled for a given line.
+
+2004-09-08 Miguel de Icaza <miguel@ximian.com>
+
+ * const.cs: Add more descriptive error report, tahnks to
+ Sebastien.
+
+2004-09-08 Marek Safar <marek.safar@seznam.cz>
+
+ * ecore.cs (FieldExpr.DoResolveLValue): Fixed CS0198 report.
+
+2004-09-07 Miguel de Icaza <miguel@ximian.com>
+
+ * expression.cs: Apply patch from Ben: Remove dead code from
+ ArrayCreation, and remove the TurnintoConstant call in const.cs,
+ as that code just threw an exception anwyays.
+
+ * const.cs: Remove the call to the turnintoconstant, for details
+ see bug: #63144
+
+ * literal.cs: The type of the null-literal is the null type; So
+ we use a placeholder type (literal.cs:System.Null, defined here)
+ for it.
+
+ * expression.cs (Conditional.DoResolve): Remove some old code that
+ is no longer needed, conversions have been fixed.
+
+ (ArrayCreationExpression.DoResolve): Return false if we fail to
+ resolve the inner expression.
+
+2004-09-07 Raja R Harinath <rharinath@novell.com>
+
+ Fix test-290.cs.
+ * cs-parser.jay (delegate_declaration): Record a delegate
+ declaration as a type declaration.
+ Reported by Jo Vermeulen <jo@lumumba.luc.ac.be>.
+
+2004-09-06 Miguel de Icaza <miguel@ximian.com>
+
+ * parameter.cs: Do not crash if the type can not be resolved.
+
+ * expression.cs: Report errors with unsafe pointers, fixes #64896
+
+2004-09-06 Ben Maurer <bmaurer@users.sourceforge.net>
+
+ * expression.cs: Pointer arith always needs to do a conv.i
+ if the operand is a long. fix 65320
+
+2004-09-04 Marek Safar <marek.safar@seznam.cz>
+
+ Fixed cs0619-37.cs, cs0619-38.cs
+
+ * enum.cs (GetObsoleteAttribute): Removed.
+
+ * expression.cs (MemberAccess.DoResolve): Test for [Obsolete]
+ on Enum member is double staged. The first is tested member
+ and then enum.
+
+2004-09-04 Marek Safar <marek.safar@seznam.cz>
+
+ Fixed #56986, #63631, #65231
+
+ * class.cs: (TypeContainer.AddToMemberContainer): New method,
+ adds member to name container.
+ (TypeContainer.AddToTypeContainer): New method, adds type to
+ name container.
+ (AddConstant, AddEnum, AddClassOrStruct, AddDelegate, AddMethod,
+ AddConstructor, AddInterface, AddField, AddProperty, AddEvent,
+ AddOperator): Simplified by reusing AddToMemberContainer.
+ (TypeContainer.UserDefinedStaticConstructor): Changed to property
+ instead of field.
+ (Method.CheckForDuplications): Fixed implementation to test all
+ possibilities.
+ (MemberBase): Detection whether member is explicit interface
+ implementation is now in constructor.
+ (MemberBase.UpdateMemberName): Handles IndexerName.
+ (Accessor): Changed to keep also location information.
+ (AbstractPropertyEventMethod): Is derived from MemberCore.
+ (AbstractPropertyEventMethod.IsDummy): Says whether accessor
+ will be emited or not.
+ (PropertyBase.AreAccessorsDuplicateImplementation):
+ Tests whether accessors are not in collision with some method.
+ (Operator): Is derived from MethodCore to simplify common
+ operations.
+
+ * decl.cs (Flags.TestMethodDuplication): Test for duplication
+ must be performed.
+ (DeclSpace.AddToContainer): Adds the member to defined_names
+ table. It tests for duplications and enclosing name conflicts.
+
+ * enum.cs (EnumMember): Clean up to reuse the base structures
+
+2004-09-03 Martin Baulig <martin@ximian.com>
+
+ Merged latest changes into gmcs. Please keep this comment in
+ here, it makes it easier for me to see what changed in MCS since
+ the last time I merged.
+
+2004-09-03 Martin Baulig <martin@ximian.com>
+
+ * class.cs (TypeContainer.DefineDefaultConstructor): Put this back
+ into TypeContainer, to make partial classes work again.
+
+2004-09-03 Martin Baulig <martin@ximian.com>
+
+ * rootcontext.cs (RootContext.V2): Removed.
+
+2004-03-23 Martin Baulig <martin@ximian.com>
+
+ * expression.cs (Invocation.OverloadResolve): Added `bool
+ may_fail' argument and use it instead of the Location.IsNull() hack.
+
2004-09-09 Martin Baulig <martin@ximian.com>
* cs-parser.jay (namespace_declaration): Fixed CS0134 reporting.
return null;
}
+ if (Type.IsAbstract) {
+ Report.Error (653, Location, "Cannot apply attribute class '{0}' because it is abstract", Name);
+ return null;
+ }
+
bool MethodImplAttr = false;
bool MarshalAsAttr = false;
bool GuidAttr = false;
seen_normal_indexers = true;
if (class_indexer_name == null) {
- class_indexer_name = i.IndexerName;
+ class_indexer_name = i.ShortName;
continue;
}
- if (i.IndexerName != class_indexer_name)
+ if (i.ShortName != class_indexer_name)
Report.Error (668, i.Location, "Two indexers have different names; the IndexerName attribute must be used with the same name on every indexer within a type");
}
"The operator `" + oe.op + "' requires a matching operator `" + s + "' to also be defined");
}
- if (has_equality_or_inequality && container.Methods != null && (RootContext.WarningLevel > 2)) {
- if (!container.Methods.HasEquals)
+ if (has_equality_or_inequality && (RootContext.WarningLevel > 2)) {
+ if (container.Methods == null || !container.Methods.HasEquals)
Report.Warning (660, container.Location, "'{0}' defines operator == or operator != but does not override Object.Equals(object o)", container.GetSignatureForError ());
- if (!container.Methods.HasGetHashCode)
+ if (container.Methods == null || !container.Methods.HasGetHashCode)
Report.Warning (661, container.Location, "'{0}' defines operator == or operator != but does not override Object.GetHashCode()", container.GetSignatureForError ());
}
}
protected Constructor default_constructor;
protected Constructor default_static_constructor;
- //
- // Whether we have seen a static constructor for this class or not
- //
- public bool UserDefinedStaticConstructor = false;
-
//
// Whether we have at least one non-static field
//
Type GenericType;
- public TypeContainer (NamespaceEntry ns, TypeContainer parent,
- MemberName name, Attributes attrs, Kind kind, Location l)
+ public TypeContainer (NamespaceEntry ns, TypeContainer parent, MemberName name,
+ Attributes attrs, Kind kind, Location l)
: base (ns, parent, name, attrs, l)
{
this.Kind = kind;
base_class_name = null;
}
- // <summary>
- // Used to report back to the user the result of a declaration
- // in the current declaration space
- // </summary>
- public void CheckDef (AdditionResult result, string name, Location loc)
+ public bool AddToMemberContainer (MemberCore symbol, bool is_method)
{
- if (result == AdditionResult.Success)
- return;
-
- switch (result){
- case AdditionResult.NameExists:
- Report.Error (102, loc, "The container `{0}' already " +
- "contains a definition for `{1}'",
- Name, name);
- break;
-
- //
- // This is handled only for static Constructors, because
- // in reality we handle these by the semantic analysis later
- //
- case AdditionResult.MethodExists:
- Report.Error (111, loc, "Class `{0}' already defines a " +
- "member called '{1}' with the same parameter " +
- "types (more than one default constructor)",
- Name, name);
- break;
-
- case AdditionResult.EnclosingClash:
- Report.Error (542, loc, "Member names cannot be the same " +
- "as their enclosing type");
- break;
-
- case AdditionResult.NotAConstructor:
- Report.Error (1520, loc, "Class, struct, or interface method " +
- "must have a return type");
- break;
+ return AddToContainer (symbol, is_method, String.Concat (Name, '.', symbol.Name), symbol.Name);
+ }
- case AdditionResult.Error:
- // Error has already been reported.
- break;
- }
+ bool AddToTypeContainer (DeclSpace ds)
+ {
+ return AddToContainer (ds, false, ds.Name, ds.Basename);
}
- public AdditionResult AddConstant (Const constant)
+ public void AddConstant (Const constant)
{
- AdditionResult res;
- string basename = constant.Name;
- string fullname = Name + "." + basename;
+ if (!AddToMemberContainer (constant, false))
+ return;
- if ((res = IsValid (basename, fullname)) != AdditionResult.Success)
- return res;
-
if (constants == null)
constants = new MemberCoreArrayList ();
constants.Add (constant);
- DefineName (fullname, constant);
-
- return AdditionResult.Success;
}
- public AdditionResult AddEnum (Mono.CSharp.Enum e)
+ public void AddEnum (Mono.CSharp.Enum e)
{
- AdditionResult res;
-
- if ((res = IsValid (e.Basename, e.Name)) != AdditionResult.Success)
- return res;
+ if (!AddToTypeContainer (e))
+ return;
if (enums == null)
enums = new MemberCoreArrayList ();
enums.Add (e);
- DefineName (e.Name, e);
-
- return AdditionResult.Success;
}
- public AdditionResult AddClass (TypeContainer c)
+ public void AddClassOrStruct (TypeContainer c)
{
- AdditionResult res;
- string name = c.Basename;
-
- if ((res = IsValid (name, c.Name)) != AdditionResult.Success)
- return res;
+ if (!AddToTypeContainer (c))
+ return;
- DefineName (c.Name, c);
types.Add (c);
-
- return AdditionResult.Success;
}
- public AdditionResult AddStruct (TypeContainer s)
+ public void AddDelegate (Delegate d)
{
- AdditionResult res;
- string name = s.Basename;
-
- if ((res = IsValid (name, s.Name)) != AdditionResult.Success)
- return res;
-
- DefineName (s.Name, s);
- types.Add (s);
-
- return AdditionResult.Success;
- }
-
- public AdditionResult AddDelegate (Delegate d)
- {
- AdditionResult res;
- string name = d.Basename;
-
- if ((res = IsValid (name, d.Name)) != AdditionResult.Success)
- return res;
+ if (!AddToTypeContainer (d))
+ return;
if (delegates == null)
delegates = new MemberCoreArrayList ();
- DefineName (d.Name, d);
delegates.Add (d);
-
- return AdditionResult.Success;
}
- public AdditionResult AddMethod (Method method)
+ public void AddMethod (Method method)
{
- string basename = method.Name;
- string fullname = Name + "." + basename;
-
- Object value = defined_names [fullname];
-
- if (value != null && (!(value is Method)))
- return AdditionResult.NameExists;
-
- if (basename == Basename)
- return AdditionResult.EnclosingClash;
+ if (!AddToMemberContainer (method, true))
+ return;
if (methods == null)
methods = new MethodArrayList (this);
methods.Insert (0, method);
else
methods.Add (method);
-
- if (value == null)
- DefineName (fullname, method);
-
- return AdditionResult.Success;
}
- public AdditionResult AddConstructor (Constructor c)
+ public void AddConstructor (Constructor c)
{
- if (c.Name != Basename)
- return AdditionResult.NotAConstructor;
+ if (c.Name != Basename) {
+ Report.Error (1520, Location, "Class, struct, or interface method must have a return type");
+ }
bool is_static = (c.ModFlags & Modifiers.STATIC) != 0;
if (is_static){
- UserDefinedStaticConstructor = true;
- if (default_static_constructor != null)
- return AdditionResult.MethodExists;
+ if (default_static_constructor != null) {
+ Report.SymbolRelatedToPreviousError (default_static_constructor);
+ Report.Error (111, c.Location, "Type '{0}' already defines a member " +
+ "called '{1}' with the same parameter types", Name, c.Name);
+ return;
+ }
default_static_constructor = c;
} else {
if (c.IsDefault ()){
- if (default_constructor != null)
- return AdditionResult.MethodExists;
+ if (default_constructor != null) {
+ Report.SymbolRelatedToPreviousError (default_constructor);
+ Report.Error (111, c.Location, "Type '{0}' already defines a member " +
+ "called '{1}' with the same parameter types", Name, c.Name);
+ return;
+ }
default_constructor = c;
}
instance_constructors.Add (c);
}
-
- return AdditionResult.Success;
}
- public AdditionResult AddInterface (TypeContainer iface)
+ public void AddInterface (TypeContainer iface)
{
- AdditionResult res;
- string name = iface.Basename;
-
- if ((res = IsValid (name, iface.Name)) != AdditionResult.Success)
- return res;
-
- if (interfaces == null)
+ if (!AddToTypeContainer (iface))
+ return;
+
+ if (interfaces == null) {
interfaces = new MemberCoreArrayList ();
+ }
+
interfaces.Add (iface);
- DefineName (iface.Name, iface);
-
- return AdditionResult.Success;
}
- public AdditionResult AddField (Field field)
+ public void AddField (Field field)
{
- AdditionResult res;
- string basename = field.Name;
- string fullname = Name + "." + basename;
+ if (!AddToMemberContainer (field, false))
+ return;
- if ((res = IsValid (basename, fullname)) != AdditionResult.Success)
- return res;
-
if (fields == null)
fields = new MemberCoreArrayList ();
if ((field.ModFlags & Modifiers.STATIC) == 0)
have_nonstatic_fields = true;
-
- DefineName (fullname, field);
- return AdditionResult.Success;
}
- public AdditionResult AddProperty (Property prop)
+ public void AddProperty (Property prop)
{
- AdditionResult res;
-
- if ((res = AddProperty (prop, prop.Name)) != AdditionResult.Success)
- return res;
-
- if (prop.Get != null) {
- if ((res = AddProperty (prop, "get_" + prop.Name)) != AdditionResult.Success)
- return res;
- }
-
- if (prop.Set != null) {
- if ((res = AddProperty (prop, "set_" + prop.Name)) != AdditionResult.Success)
- return res;
- }
+ if (!AddToMemberContainer (prop, false) ||
+ !AddToMemberContainer (prop.Get, true) || !AddToMemberContainer (prop.Set, true))
+ return;
if (properties == null)
properties = new MemberCoreArrayList ();
properties.Insert (0, prop);
else
properties.Add (prop);
-
- return AdditionResult.Success;
}
- AdditionResult AddProperty (Property prop, string basename)
+ public void AddEvent (Event e)
{
- AdditionResult res;
- string fullname = Name + "." + basename;
-
- if ((res = IsValid (basename, fullname)) != AdditionResult.Success)
- return res;
-
- DefineName (fullname, prop);
-
- return AdditionResult.Success;
- }
+ if (!AddToMemberContainer (e, false))
+ return;
- public AdditionResult AddEvent (Event e)
- {
- AdditionResult res;
- string basename = e.Name;
- string fullname = Name + "." + basename;
+ if (e is EventProperty) {
+ if (!AddToMemberContainer (e.Add, true))
+ return;
- if ((res = IsValid (basename, fullname)) != AdditionResult.Success)
- return res;
+ if (!AddToMemberContainer (e.Remove, true))
+ return;
+ }
if (events == null)
events = new MemberCoreArrayList ();
-
- events.Add (e);
- DefineName (fullname, e);
- return AdditionResult.Success;
+ events.Add (e);
}
+ /// <summary>
+ /// Indexer has special handling in constrast to other AddXXX because the name can be driven by IndexerNameAttribute
+ /// </summary>
public void AddIndexer (Indexer i)
{
if (indexers == null)
indexers = new IndexerArrayList (this);
- if (i.MemberName.Left != null)
+ if (i.IsExplicitImpl)
indexers.Insert (0, i);
else
indexers.Add (i);
}
- public AdditionResult AddOperator (Operator op)
+ public void AddOperator (Operator op)
{
+ if (!AddToMemberContainer (op, true))
+ return;
+
if (operators == null)
operators = new OperatorArrayList (this);
operators.Add (op);
-
- string basename = op.Name;
- string fullname = Name + "." + basename;
- if (!defined_names.Contains (fullname))
- {
- DefineName (fullname, op);
- }
- return AdditionResult.Success;
}
public void AddIterator (Iterator i)
DefineContainerMembers (constants);
DefineContainerMembers (fields);
- if ((Kind == Kind.Class) && !(this is ClassPart)){
+ if ((Kind == Kind.Class) && !(this is ClassPart) && !(this is StaticClass)){
if ((instance_constructors == null) &&
!(this is StaticClass)) {
if (default_constructor == null)
if (default_static_constructor != null)
default_static_constructor.Define ();
- DefineContainerMembers (methods);
DefineContainerMembers (properties);
DefineContainerMembers (events);
DefineContainerMembers (indexers);
+ DefineContainerMembers (methods);
DefineContainerMembers (operators);
DefineContainerMembers (enums);
DefineContainerMembers (delegates);
return ok;
}
- Hashtable builder_and_args;
-
- public bool RegisterMethod (MethodBuilder mb, InternalParameters ip, Type [] args)
- {
- if (builder_and_args == null)
- builder_and_args = new Hashtable ();
- return true;
+ public bool UserDefinedStaticConstructor {
+ get {
+ return default_static_constructor != null;
+ }
}
protected override bool VerifyClsCompliance (DeclSpace ds)
{
if (Kind == Kind.Interface)
Parent.AddInterface (this);
- else if (Kind == Kind.Class)
- Parent.AddClass (this);
- else if (Kind == Kind.Struct)
- Parent.AddStruct (this);
+ else if (Kind == Kind.Class || Kind == Kind.Struct)
+ Parent.AddClassOrStruct (this);
else
throw new InvalidOperationException ();
}
base.ApplyAttributeBuilder (a, cb);
}
+
+ public override void Register ()
+ {
+ Parent.AddClassOrStruct (this);
+ }
}
/// <summary>
/// Class handles static classes declaration
/// </summary>
public sealed class StaticClass: Class {
- public StaticClass (NamespaceEntry ns, TypeContainer parent, MemberName name,
- int mod, Attributes attrs, Location l)
+ public StaticClass (NamespaceEntry ns, TypeContainer parent, MemberName name, int mod,
+ Attributes attrs, Location l)
: base (ns, parent, name, mod & ~Modifiers.STATIC, attrs, l)
{
if (RootContext.Version == LanguageVersion.ISO_1) {
- Report.FeatureIsNotStandardized ("static classes");
+ Report.FeatureIsNotStandardized (l, "static classes");
Environment.Exit (1);
}
}
// Information in the case we are an attribute type
AttributeUsageAttribute attribute_usage;
- public Class (NamespaceEntry ns, TypeContainer parent, MemberName name,
- int mod, Attributes attrs, Location l)
+ public Class (NamespaceEntry ns, TypeContainer parent, MemberName name, int mod,
+ Attributes attrs, Location l)
: base (ns, parent, name, attrs, Kind.Class, l)
{
int accmods;
public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb)
{
- if (a.UsageAttribute != null)
+ if (a.UsageAttribute != null) {
+ if (ptype != TypeManager.attribute_type &&
+ !ptype.IsSubclassOf (TypeManager.attribute_type) &&
+ TypeBuilder.FullName != "System.Attribute") {
+ Report.Error (641, a.Location, "Attribute '{0}' is only valid on classes derived from System.Attribute", a.Name);
+ }
attribute_usage = a.UsageAttribute;
+ }
base.ApplyAttributeBuilder (a, cb);
}
}
}
- public override void Register ()
- {
- CheckDef (Parent.AddClass (this), Name, Location);
- }
-
public const TypeAttributes DefaultTypeAttributes =
TypeAttributes.AutoLayout | TypeAttributes.Class;
}
}
- public override void Register ()
- {
- CheckDef (Parent.AddStruct (this), Name, Location);
- }
-
public const TypeAttributes DefaultTypeAttributes =
TypeAttributes.SequentialLayout |
TypeAttributes.Sealed |
public override void Register ()
{
- CheckDef (Parent.AddInterface (this), Name, Location);
+ Parent.AddInterface (this);
}
public override PendingImplementation GetPendingImplementations ()
if (!DoDefineParameters ())
return false;
+ if ((caching_flags & Flags.TestMethodDuplication) != 0 && !CheckForDuplications ())
+ return false;
+
if (IsExplicitImpl)
return true;
- // TODO: Is it correct ?
- if (!IsOperator) {
- if (!CheckForDuplications ())
- return false;
- }
-
// Is null for System.Object while compiling corlib and base interfaces
if (Parent.ParentContainer == null) {
if ((RootContext.WarningLevel >= 4) && ((ModFlags & Modifiers.NEW) != 0)) {
if (RootContext.WarningLevel >= 2)
Report.Warning (114, Location, "'{0}' hides inherited member '{1}'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword", GetSignatureForError (Parent), parent_method);
} else
- Report.Warning (108, Location, "The keyword new is required on '{0}' because it hides inherited member `{1}'", GetSignatureForError (Parent), parent_method);
+ Report.Warning (108, Location, "The keyword new is required on '{0}' because it hides inherited member", GetSignatureForError (Parent));
}
return ok;
protected bool IsDuplicateImplementation (MethodCore method)
{
- if ((method == this) || (method.Name != Name))
+ if ((method == this) ||
+ (method.MemberName.GetTypeName () != MemberName.GetTypeName ()))
return false;
Type[] param_types = method.ParameterTypes;
}
for (int i = 0; i < param_types.Length; i++) {
- Type a = param_types [i];
- Type b = ParameterTypes [i];
+ if (param_types [i] != ParameterTypes [i])
+ equal = false;
+ }
- if (a != b)
+ // TODO: make operator compatible with MethodCore to avoid this
+ if (this is Operator && method is Operator) {
+ if (MemberType != method.MemberType)
equal = false;
}
public override string GetSignatureForError()
{
+ if (MethodBuilder == null) {
+ return GetSignatureForError (Parent);
+ }
return TypeManager.CSharpSignature (MethodBuilder);
}
/// </summary>
public override string GetSignatureForError (TypeContainer tc)
{
+ // TODO: get params from somewhere
+ if (parameter_info == null)
+ return base.GetSignatureForError (tc);
+
// TODO: move to parameters
System.Text.StringBuilder args = new System.Text.StringBuilder ();
if (parameter_info.Parameters.FixedParameters != null) {
Report.Error (629, Location, "Conditional member '{0}' cannot implement interface member", GetSignatureForError ());
return;
}
+
+ for (int i = 0; i < parameter_info.Count; ++i) {
+ if ((parameter_info.ParameterModifier (i) & Parameter.Modifier.OUT) != 0) {
+ Report.Error (685, Location, "Conditional method '{0}' cannot have an out parameter", GetSignatureForError ());
+ return;
+ }
+ }
}
MethodBuilder.SetCustomAttribute (cb);
protected override bool CheckForDuplications ()
{
ArrayList ar = Parent.Methods;
+ if (ar != null) {
+ int arLen = ar.Count;
+
+ for (int i = 0; i < arLen; i++) {
+ Method m = (Method) ar [i];
+ if (IsDuplicateImplementation (m))
+ return false;
+ }
+ }
+
+ ar = Parent.Properties;
if (ar != null) {
- int arLen = ar.Count;
+ for (int i = 0; i < ar.Count; ++i) {
+ PropertyBase pb = (PropertyBase) ar [i];
+ if (pb.AreAccessorsDuplicateImplementation (this))
+ return false;
+ }
+ }
- for (int i = 0; i < arLen; i++) {
- Method m = (Method) ar [i];
- if (IsDuplicateImplementation (m))
+ ar = Parent.Indexers;
+ if (ar != null) {
+ for (int i = 0; i < ar.Count; ++i) {
+ PropertyBase pb = (PropertyBase) ar [i];
+ if (pb.AreAccessorsDuplicateImplementation (this))
return false;
}
}
- if (MemberType.IsAbstract && MemberType.IsSealed) {
- Report.Error (722, Location, Error722, TypeManager.CSharpName (MemberType));
- return false;
+ ar = Parent.Events;
+ if (ar != null) {
+ for (int i = 0; i < ar.Count; ++i) {
+ Event ev = (Event) ar [i];
+ if (ev.AreAccessorsDuplicateImplementation (this))
+ return false;
+ }
}
return true;
}
}
+ if (MemberType.IsAbstract && MemberType.IsSealed) {
+ Report.Error (722, Location, Error722, TypeManager.CSharpName (MemberType));
+ return false;
+ }
+
return true;
}
}
}
- public string MethodName {
+ public Type ReturnType {
+ get {
+ return MemberType;
+ }
+ }
+
+ public MemberName MethodName {
get {
- return ShortName;
+ return MemberName;
}
}
}
}
- public Type ReturnType {
- get {
- return MemberType;
- }
- }
-
#endregion
}
}
if (parent_constructor == caller_builder){
- Report.Error (515, String.Format ("Constructor `{0}' can not call itself", TypeManager.CSharpSignature (caller_builder)));
+ Report.Error (516, String.Format ("Constructor `{0}' can not call itself", TypeManager.CSharpSignature (caller_builder)));
return false;
}
public override string GetSignatureForError()
{
+ if (ConstructorBuilder == null)
+ return GetSignatureForError (Parent);
+
return TypeManager.CSharpSignature (ConstructorBuilder);
}
}
}
- public string MethodName {
+ public MemberName MethodName {
get {
- return ShortName;
+ return MemberName;
}
}
{
CallingConventions CallingConventions { get; }
Location Location { get; }
- string MethodName { get; }
+ MemberName MethodName { get; }
Type[] ParameterTypes { get; }
Type ReturnType { get; }
GenericMethod GenericMethod { get; }
public bool Define (TypeContainer container)
{
MethodInfo implementing = null;
- string prefix;
+ string prefix;
if (member.IsExplicitImpl)
prefix = RemoveArity (member.InterfaceType.FullName) + ".";
else
prefix = "";
- string name = method.MethodName;
+ string name = method.MethodName.Name;
string method_name = prefix + name;
+
Type[] ParameterTypes = method.ParameterTypes;
if (container.Pending != null){
if ((modifiers & (Modifiers.VIRTUAL | Modifiers.ABSTRACT | Modifiers.OVERRIDE)) == 0)
flags |= MethodAttributes.Final;
- // Get the method name from the explicit interface.
- if (member.InterfaceType != null) {
- name = implementing.Name;
- method_name = prefix + name;
- }
-
IsImplementing = true;
}
}
- if (!TypeManager.RegisterMethod (builder, ParameterInfo, ParameterTypes)) {
- Report.Error (111, method.Location,
- "Class `" + container.Name +
- "' already contains a definition with the " +
- "same return value and parameter types as the " +
- "'get' method of property `" + member.Name + "'");
- return false;
- }
-
+ TypeManager.RegisterMethod (builder, ParameterInfo, ParameterTypes);
TypeManager.AddMethod (builder, method);
if (GenericMethod != null) {
//
// The name of the interface we are explicitly implementing
//
- public Expression ExplicitInterfaceName = null;
+ public MemberName ExplicitInterfaceName = null;
//
// Whether this is an interface member.
explicit_mod_flags = mod;
Type = type;
ModFlags = Modifiers.Check (allowed_mod, mod, def_mod, loc);
+
+ // Check for explicit interface implementation
+ if (MemberName.Left != null) {
+ ExplicitInterfaceName = MemberName.Left;
+ ShortName = MemberName.Name;
+ IsExplicitImpl = true;
+ } else
+ ShortName = Name;
}
protected virtual bool CheckBase ()
protected virtual bool DoDefineBase ()
{
if (Name == null)
- Name = "this";
+ throw new InternalErrorException ();
if (IsInterface) {
ModFlags = Modifiers.PUBLIC |
if (MemberType.IsPointer && !UnsafeOK (Parent))
return false;
- //
- // Check for explicit interface implementation
- //
- if (MemberName.Left != null) {
- ExplicitInterfaceName = MemberName.Left.GetTypeExpression (Location);
- ShortName = MemberName.Name;
- } else
- ShortName = Name;
-
- if (ExplicitInterfaceName != null) {
+ if (IsExplicitImpl) {
InterfaceType = Parent.ResolveType (
- ExplicitInterfaceName, false, Location);
+ ExplicitInterfaceName.GetTypeExpression (Location), false, Location);
if (InterfaceType == null)
return false;
return false;
}
- // Compute the full name that we need to export.
- Name = InterfaceType.FullName + "." + ShortName;
-
if (!Parent.VerifyImplements (InterfaceType, ShortName, Name, Location))
return false;
Modifiers.Check (Modifiers.AllowedExplicitImplFlags, explicit_mod_flags, 0, Location);
-
- IsExplicitImpl = true;
- } else
- IsExplicitImpl = false;
+ }
return true;
}
+ /// <summary>
+ /// The name of the member can be changed during definition (see IndexerName attribute)
+ /// </summary>
+ protected virtual void UpdateMemberName ()
+ {
+ MemberName.Name = ShortName;
+ }
+
public override string GetSignatureForError (TypeContainer tc)
{
return String.Concat (tc.Name, '.', base.GetSignatureForError (tc));
public override string GetSignatureForError ()
{
+ if (FieldBuilder == null) {
+ return base.GetSignatureForError (Parent);
+ }
return TypeManager.GetFullNameSignature (FieldBuilder);
}
//
public Block Block;
public Attributes Attributes;
+ public Location Location;
- public Accessor (Block b, Attributes attrs)
+ public Accessor (Block b, Attributes attrs, Location loc)
{
Block = b;
Attributes = attrs;
+ Location = loc;
}
}
// Ooouh Martin, templates are missing here.
// When it will be possible move here a lot of child code and template method type.
- public abstract class AbstractPropertyEventMethod: Attributable, IMethodData
- {
+ public abstract class AbstractPropertyEventMethod: MemberCore, IMethodData {
protected MethodData method_data;
protected Block block;
+ // The accessor are created event if they are not wanted.
+ // But we need them because their names are reserved.
+ // Field says whether accessor will be emited or not
+ public readonly bool IsDummy;
+
+ protected readonly string prefix;
+
ReturnParameter return_attributes;
- public AbstractPropertyEventMethod ():
- base (null)
+ public AbstractPropertyEventMethod (MemberBase member, string prefix)
+ : base (null, SetupName (prefix, member), null, member.Location)
{
+ this.prefix = prefix;
+ IsDummy = true;
}
- public AbstractPropertyEventMethod (Accessor accessor):
- base (accessor.Attributes)
+ public AbstractPropertyEventMethod (MemberBase member, Accessor accessor,
+ string prefix)
+ : base (null, SetupName (prefix, member),
+ accessor.Attributes, accessor.Location)
{
+ this.prefix = prefix;
this.block = accessor.Block;
}
+ static MemberName SetupName (string prefix, MemberBase member)
+ {
+ MemberName name = member.MemberName.Clone ();
+ name.Name = prefix + member.ShortName;
+ return name;
+ }
+
+ public void UpdateName (MemberBase member)
+ {
+ MemberName.Name = prefix + member.ShortName;
+ }
+
#region IMethodData Members
public Block Block {
}
}
+ public MemberName MethodName {
+ get {
+ return MemberName;
+ }
+ }
+
public abstract ObsoleteAttribute GetObsoleteAttribute ();
- public abstract string GetSignatureForError (TypeContainer tc);
- public abstract Location Location { get; }
- public abstract string MethodName { get; }
public abstract Type[] ParameterTypes { get; }
public abstract Type ReturnType { get; }
public abstract EmitContext CreateEmitContext(TypeContainer tc, ILGenerator ig);
System.Diagnostics.Debug.Fail ("You forgot to define special attribute target handling");
}
+ public override bool Define()
+ {
+ return false;
+ }
+
public virtual void Emit (TypeContainer container)
{
method_data.Emit (container, this);
block = null;
}
+
+ public override bool IsClsCompliaceRequired(DeclSpace ds)
+ {
+ return false;
+ }
+
+ public bool IsDuplicateImplementation (MethodCore method)
+ {
+ if (Name != method.Name)
+ return false;
+
+ Type[] param_types = method.ParameterTypes;
+
+ if (param_types.Length != ParameterTypes.Length)
+ return false;
+
+ for (int i = 0; i < param_types.Length; i++)
+ if (param_types [i] != ParameterTypes [i])
+ return false;
+
+ Report.SymbolRelatedToPreviousError (method);
+ Report.Error (111, Location, "Type '{0}' already defines a member called '{1}' with " +
+ "the same parameter types", Parent.Name, Name);
+ return true;
+ }
+
+ public new Location Location {
+ get {
+ return base.Location;
+ }
+ }
+
+ protected override void VerifyObsoleteAttribute()
+ {
+ }
+
}
//
{
static string[] attribute_targets = new string [] { "method", "return" };
+ public GetMethod (MethodCore method):
+ base (method, "get_")
+ {
+ }
+
public GetMethod (MethodCore method, Accessor accessor):
- base (method, accessor)
+ base (method, accessor, "get_")
{
}
return String.Concat (base.GetSignatureForError (tc), ".get");
}
- public override string MethodName
- {
- get {
- return "get_" + method.ShortName;
- }
- }
-
public override Type ReturnType {
get {
return method.MemberType;
static string[] attribute_targets = new string [] { "method", "param", "return" };
ImplicitParameter param_attr;
+ public SetMethod (MethodCore method):
+ base (method, "set_")
+ {
+ }
+
public SetMethod (MethodCore method, Accessor accessor):
- base (method, accessor)
+ base (method, accessor, "set_")
{
}
return String.Concat (base.GetSignatureForError (tc), ".set");
}
- public override string MethodName {
- get {
- return "set_" + method.ShortName;
- }
- }
-
public override Type[] ParameterTypes {
get {
return new Type[] { method.MemberType };
public abstract class PropertyMethod: AbstractPropertyEventMethod {
protected readonly MethodCore method;
- public PropertyMethod (MethodCore method, Accessor accessor):
- base (accessor)
+ public PropertyMethod (MethodCore method, string prefix)
+ : base (method, prefix)
+ {
+ this.method = method;
+ }
+
+ public PropertyMethod (MethodCore method, Accessor accessor, string prefix)
+ : base (method, accessor, prefix)
{
this.method = method;
}
}
}
- public override Location Location {
- get {
- return method.Location;
- }
- }
-
public override EmitContext CreateEmitContext (TypeContainer tc,
ILGenerator ig)
{
public override string GetSignatureForError()
{
+ if (PropertyBuilder == null)
+ return GetSignatureForError (Parent);
+
return TypeManager.CSharpSignature (PropertyBuilder, false);
}
protected override bool CheckForDuplications ()
{
- ArrayList ar = Parent.Properties;
+ ArrayList ar = Parent.Indexers;
if (ar != null) {
int arLen = ar.Count;
for (int i = 0; i < arLen; i++) {
- Property m = (Property) ar [i];
+ Indexer m = (Indexer) ar [i];
if (IsDuplicateImplementation (m))
return false;
}
}
- return true;
+
+ ar = Parent.Properties;
+ if (ar != null) {
+ int arLen = ar.Count;
+
+ for (int i = 0; i < arLen; i++) {
+ Property m = (Property) ar [i];
+ if (IsDuplicateImplementation (m))
+ return false;
+ }
}
+ return true;
+ }
+
protected override MethodInfo FindOutParentMethod (TypeContainer container, ref Type parent_ret_type)
{
PropertyInfo parent_property = container.ParentContainer.MemberCache.FindMemberToOverride (
if (PropertyBuilder != null && OptAttributes != null)
OptAttributes.Emit (ec, this);
- if (Get != null)
+ if (!Get.IsDummy)
Get.Emit (Parent);
- if (Set != null)
+ if (!Set.IsDummy)
Set.Emit (Parent);
base.Emit ();
}
+ /// <summary>
+ /// Tests whether accessors are not in collision with some method (CS0111)
+ /// </summary>
+ public bool AreAccessorsDuplicateImplementation (MethodCore mc)
+ {
+ return Get.IsDuplicateImplementation (mc) || Set.IsDuplicateImplementation (mc);
+ }
+
+ protected override void UpdateMemberName ()
+ {
+ base.UpdateMemberName ();
+
+ Get.UpdateName (this);
+ Set.UpdateName (this);
+ }
+
+
public override string[] ValidAttributeTargets {
get {
return attribute_targets;
is_iface, name, Parameters.EmptyReadOnlyParameters, attrs,
loc)
{
- if (get_block != null)
+ if (get_block == null)
+ Get = new GetMethod (this);
+ else
Get = new GetMethod (this, get_block);
- if (set_block != null)
+ if (set_block == null)
+ Set = new SetMethod (this);
+ else
Set = new SetMethod (this, set_block);
}
flags |= MethodAttributes.HideBySig | MethodAttributes.SpecialName;
- if (Get != null) {
+ if (!Get.IsDummy) {
GetBuilder = Get.Define (Parent);
if (GetBuilder == null)
}
}
- if (Set != null) {
+ if (!Set.IsDummy) {
SetBuilder = Set.Define (Parent);
if (SetBuilder == null)
return false;
PropertyBuilder = Parent.TypeBuilder.DefineProperty (
Name, prop_attr, MemberType, null);
- if (Get != null)
+ if (!Get.IsDummy)
PropertyBuilder.SetGetMethod (GetBuilder);
- if (Set != null)
+ if (!Set.IsDummy)
PropertyBuilder.SetSetMethod (SetBuilder);
- //
- // HACK for the reasons exposed above
- //
- if (!TypeManager.RegisterProperty (PropertyBuilder, GetBuilder, SetBuilder)) {
- Report.Error (
- 111, Location,
- "Class `" + Parent.Name +
- "' already contains a definition for the property `" +
- Name + "'");
- return false;
- }
+ TypeManager.RegisterProperty (PropertyBuilder, GetBuilder, SetBuilder);
}
return true;
}
protected sealed class AddDelegateMethod: DelegateMethod
{
+
public AddDelegateMethod (Event method):
- base (method)
+ base (method, "add_")
{
}
public AddDelegateMethod (Event method, Accessor accessor):
- base (method, accessor)
+ base (method, accessor, "add_")
{
}
- public override string MethodName {
- get {
- return "add_" + method.ShortName;
- }
- }
-
protected override MethodInfo DelegateMethodInfo {
get {
return TypeManager.delegate_combine_delegate_delegate;
protected sealed class RemoveDelegateMethod: DelegateMethod
{
public RemoveDelegateMethod (Event method):
- base (method)
+ base (method, "remove_")
{
}
public RemoveDelegateMethod (Event method, Accessor accessor):
- base (method, accessor)
+ base (method, accessor, "remove_")
{
}
- public override string MethodName {
- get {
- return "remove_" + method.ShortName;
- }
- }
-
protected override MethodInfo DelegateMethodInfo {
get {
return TypeManager.delegate_remove_delegate_delegate;
static string[] attribute_targets = new string [] { "method", "param", "return" };
- public DelegateMethod (Event method)
+ public DelegateMethod (Event method, string prefix)
+ : base (method, prefix)
{
this.method = method;
}
- public DelegateMethod (Event method, Accessor accessor):
- base (accessor)
+ public DelegateMethod (Event method, Accessor accessor, string prefix)
+ : base (method, accessor, prefix)
{
this.method = method;
}
}
}
- public override Location Location {
- get {
- return method.Location;
- }
- }
-
public override EmitContext CreateEmitContext (TypeContainer tc,
ILGenerator ig)
{
const int AllowedInterfaceModifiers =
Modifiers.NEW;
- protected DelegateMethod Add, Remove;
+ public DelegateMethod Add, Remove;
public MyEventBuilder EventBuilder;
public MethodBuilder AddBuilder, RemoveBuilder;
EventBuilder.SetCustomAttribute (cb);
}
+ public bool AreAccessorsDuplicateImplementation (MethodCore mc)
+ {
+ return Add.IsDuplicateImplementation (mc) || Remove.IsDuplicateImplementation (mc);
+ }
+
public override AttributeTargets AttributeTargets {
get {
return AttributeTargets.Event;
EventBuilder.SetAddOnMethod (AddBuilder);
EventBuilder.SetRemoveOnMethod (RemoveBuilder);
- if (!TypeManager.RegisterEvent (EventBuilder, AddBuilder, RemoveBuilder)) {
- Report.Error (111, Location,
- "Class `" + Parent.Name +
- "' already contains a definition for the event `" +
- Name + "'");
- return false;
- }
+ TypeManager.RegisterEvent (EventBuilder, AddBuilder, RemoveBuilder);
}
return true;
public override string GetSignatureForError ()
{
+ if (EventBuilder == null)
+ return base.GetSignatureForError (Parent);
+
return TypeManager.GetFullNameSignature (EventBuilder);
}
}
- //
- // FIXME: This does not handle:
- //
- // int INTERFACENAME [ args ]
- // Does not
- //
- // Only:
- //
- // int this [ args ]
public class Indexer : PropertyBase {
class GetIndexerMethod: GetMethod
{
+ public GetIndexerMethod (MethodCore method):
+ base (method)
+ {
+ }
+
public GetIndexerMethod (MethodCore method, Accessor accessor):
base (method, accessor)
{
{
readonly Parameters parameters;
+ public SetIndexerMethod (MethodCore method):
+ base (method)
+ {
+ }
+
public SetIndexerMethod (MethodCore method, Parameters parameters, Accessor accessor):
base (method, accessor)
{
const int AllowedInterfaceModifiers =
Modifiers.NEW;
- public string IndexerName = TypeContainer.DefaultIndexerName;
- public string InterfaceIndexerName;
-
//
// Are we implementing an interface ?
//
- public Indexer (TypeContainer parent, Expression type, int mod_flags,
- bool is_iface, MemberName name, Parameters parameters,
- Attributes attrs, Accessor get_block, Accessor set_block,
- Location loc)
- : base (parent, type, mod_flags,
+ public Indexer (TypeContainer parent, Expression type, MemberName name, int mod,
+ bool is_iface, Parameters parameters, Attributes attrs,
+ Accessor get_block, Accessor set_block, Location loc)
+ : base (parent, type, mod,
is_iface ? AllowedInterfaceModifiers : AllowedModifiers,
is_iface, name, parameters, attrs, loc)
{
- if (get_block != null)
+ if (get_block == null)
+ Get = new GetIndexerMethod (this);
+ else
Get = new GetIndexerMethod (this, get_block);
- if (set_block != null)
+ if (set_block == null)
+ Set = new SetIndexerMethod (this);
+ else
Set = new SetIndexerMethod (this, parameters, set_block);
}
if (OptAttributes != null) {
Attribute indexer_attr = OptAttributes.GetIndexerNameAttribute (ec);
if (indexer_attr != null) {
- IndexerName = indexer_attr.GetIndexerAttributeValue (ec);
+ ShortName = indexer_attr.GetIndexerAttributeValue (ec);
+
if (IsExplicitImpl) {
- // The 'IndexerName' attribute is valid only on an indexer that is not an explicit interface member declaration
Report.Error (415, indexer_attr.Location, "The 'IndexerName' attribute is valid only on an indexer that is not an explicit interface member declaration");
return false;
}
return false;
}
- if (!Tokenizer.IsValidIdentifier (IndexerName)) {
- // The argument to the 'IndexerName' attribute must be a valid identifier
+ if (!Tokenizer.IsValidIdentifier (ShortName)) {
Report.Error (633, indexer_attr.Location, "The argument to the 'IndexerName' attribute must be a valid identifier");
return false;
}
+
+ UpdateMemberName ();
}
}
- ShortName = IndexerName;
- if (IsExplicitImpl) {
- InterfaceIndexerName = TypeManager.IndexerPropertyName (InterfaceType);
- Name = InterfaceType.FullName + "." + IndexerName;
- } else {
- InterfaceIndexerName = IndexerName;
- Name = ShortName;
+ if (InterfaceType != null) {
+ string parent_IndexerName = TypeManager.IndexerPropertyName (InterfaceType);
+ if (parent_IndexerName != Name)
+ ShortName = parent_IndexerName;
+ UpdateMemberName ();
}
- if (!CheckNameCollision (Parent))
+ if (!Parent.AddToMemberContainer (this, true) ||
+ !Parent.AddToMemberContainer (Get, true) || !Parent.AddToMemberContainer (Set, true))
return false;
if (!CheckBase ())
return false;
flags |= MethodAttributes.HideBySig | MethodAttributes.SpecialName;
- if (Get != null){
+ if (!Get.IsDummy){
GetBuilder = Get.Define (Parent);
if (GetBuilder == null)
return false;
}
- if (Set != null){
+ if (!Set.IsDummy){
SetBuilder = Set.Define (Parent);
if (SetBuilder == null)
return false;
//
Parameter [] p = Parameters.FixedParameters;
if (p != null) {
+ if ((p [0].ModFlags & Parameter.Modifier.ISBYREF) != 0) {
+ Report.Error (631, Location, "ref and out are not valid in this context");
+ return false;
+ }
+
int i;
for (i = 0; i < p.Length; ++i) {
- if (Get != null)
+ if (!Get.IsDummy)
GetBuilder.DefineParameter (
i + 1, p [i].Attributes, p [i].Name);
- if (Set != null)
+ if (!Set.IsDummy)
SetBuilder.DefineParameter (
i + 1, p [i].Attributes, p [i].Name);
}
- if (Set != null)
+ if (!Set.IsDummy)
SetBuilder.DefineParameter (
i + 1, ParameterAttributes.None, "value");
//
if (!IsExplicitImpl) {
PropertyBuilder = Parent.TypeBuilder.DefineProperty (
- IndexerName, prop_attr, MemberType, ParameterTypes);
+ ShortName, prop_attr, MemberType, ParameterTypes);
- if (Get != null)
+ if (!Get.IsDummy)
PropertyBuilder.SetGetMethod (GetBuilder);
- if (Set != null)
+ if (!Set.IsDummy)
PropertyBuilder.SetSetMethod (SetBuilder);
TypeManager.RegisterIndexer (PropertyBuilder, GetBuilder, SetBuilder,
return true;
}
- bool CheckNameCollision (TypeContainer container) {
- switch (VerifyName (container)){
- case DeclSpace.AdditionResult.NameExists:
- Report.Error (102, Location, "The container '{0}' already contains a definition for '{1}'", container.GetSignatureForError (), Name);
- return false;
-
- case DeclSpace.AdditionResult.Success:
- return true;
- }
- throw new NotImplementedException ();
- }
-
- DeclSpace.AdditionResult VerifyName (TypeContainer container) {
- if (!AddIndexer (container, container.Name + "." + Name))
- return DeclSpace.AdditionResult.NameExists;
-
- if (Get != null) {
- if (!AddIndexer (container, container.Name + ".get_" + Name))
- return DeclSpace.AdditionResult.NameExists;
- }
-
- if (Set != null) {
- if (!AddIndexer (container, container.Name + ".set_" + Name))
- return DeclSpace.AdditionResult.NameExists;
- }
- return DeclSpace.AdditionResult.Success;
- }
-
- bool AddIndexer (TypeContainer container, string fullname)
- {
- object value = container.GetDefinition (fullname);
-
- if (value != null) {
- return value.GetType () != GetType () ? false : true;
- }
-
- container.DefineName (fullname, this);
- return true;
- }
-
public override string GetSignatureForError ()
{
+ if (PropertyBuilder == null)
+ return GetSignatureForError (Parent);
+
return TypeManager.CSharpSignature (PropertyBuilder, true);
}
}
}
- public class Operator : MemberBase, IIteratorContainer {
+ public class Operator : MethodCore, IIteratorContainer {
const int AllowedModifiers =
Modifiers.PUBLIC |
};
public readonly OpType OperatorType;
- public readonly Expression ReturnType;
- public readonly Expression FirstArgType, SecondArgType;
- public readonly string FirstArgName, SecondArgName;
- public Block Block;
public MethodBuilder OperatorMethodBuilder;
- public string MethodName;
public Method OperatorMethod;
static string[] attribute_targets = new string [] { "method", "return" };
public Operator (TypeContainer parent, OpType type, Expression ret_type,
- int mod_flags, Expression arg1type, string arg1name,
- Expression arg2type, string arg2name,
+ int mod_flags, Parameters parameters,
Block block, Attributes attrs, Location loc)
- : base (parent, ret_type, mod_flags, AllowedModifiers,
- Modifiers.PUBLIC, MemberName.Null, attrs, loc)
+ : base (parent, null, ret_type, mod_flags, AllowedModifiers, false,
+ new MemberName ("op_" + type), attrs, parameters, loc)
{
OperatorType = type;
- Name = "op_" + OperatorType;
- ReturnType = ret_type;
- FirstArgType = arg1type;
- FirstArgName = arg1name;
- SecondArgType = arg2type;
- SecondArgName = arg2name;
Block = block;
}
return true;
}
- public override bool Define ()
+ protected override bool CheckForDuplications()
{
- int length = 1;
- MethodName = "op_" + OperatorType;
-
- if (SecondArgType != null)
- length = 2;
-
- Parameter [] param_list = new Parameter [length];
+ ArrayList ar = Parent.Operators;
+ if (ar != null) {
+ int arLen = ar.Count;
+
+ for (int i = 0; i < arLen; i++) {
+ Operator o = (Operator) ar [i];
+ if (IsDuplicateImplementation (o))
+ return false;
+ }
+ }
+
+ ar = Parent.Methods;
+ if (ar != null) {
+ int arLen = ar.Count;
+
+ for (int i = 0; i < arLen; i++) {
+ Method m = (Method) ar [i];
+ if (IsDuplicateImplementation (m))
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public override bool Define ()
+ {
if ((ModFlags & RequiredModifiers) != RequiredModifiers){
Report.Error (
558, Location,
return false;
}
- param_list[0] = new Parameter (FirstArgType, FirstArgName,
- Parameter.Modifier.NONE, null);
- if (SecondArgType != null)
- param_list[1] = new Parameter (SecondArgType, SecondArgName,
- Parameter.Modifier.NONE, null);
-
+ if (!DoDefine (ds))
+ return false;
+
OperatorMethod = new Method (
- Parent, null, ReturnType, ModFlags, false,
- new MemberName (MethodName),
- new Parameters (param_list, null, Location),
- OptAttributes, Location);
+ Parent, null, Type, ModFlags, false, MemberName,
+ Parameters, OptAttributes, Location);
OperatorMethod.Block = Block;
OperatorMethod.IsOperator = true;
OperatorMethodBuilder = OperatorMethod.MethodBuilder;
- Type [] param_types = OperatorMethod.ParameterTypes;
+ parameter_types = OperatorMethod.ParameterTypes;
Type declaring_type = OperatorMethod.MethodData.DeclaringType;
Type return_type = OperatorMethod.ReturnType;
- Type first_arg_type = param_types [0];
+ Type first_arg_type = parameter_types [0];
+
+ if (!CheckBase ())
+ return false;
// Rules for conversion operators
Report.Error (554, Location, "'{0}' : user defined conversion to/from derived class", GetSignatureForError ());
return false;
}
- } else if (SecondArgType == null) {
+ } else if (OperatorType == OpType.LeftShift || OperatorType == OpType.RightShift) {
+ if (first_arg_type != declaring_type || parameter_types [1] != TypeManager.int32_type) {
+ Report.Error (564, Location, "Overloaded shift operator must have the type of the first operand be the containing type, and the type of the second operand must be int");
+ return false;
+ }
+ } else if (Parameters.FixedParameters.Length == 1) {
// Checks for Unary operators
if (first_arg_type != declaring_type){
// Checks for Binary operators
if (first_arg_type != declaring_type &&
- param_types [1] != declaring_type){
+ parameter_types [1] != declaring_type){
Report.Error (
563, Location,
"One of the parameters of a binary operator must " +
Block = null;
}
+ // Operator cannot be override
+ protected override MethodInfo FindOutParentMethod (TypeContainer container, ref Type parent_ret_type)
+ {
+ return null;
+ }
+
public static string GetName (OpType ot)
{
switch (ot){
public override string GetSignatureForError (TypeContainer tc)
{
StringBuilder sb = new StringBuilder ();
- sb.AppendFormat ("{0}.operator {1} {2}({3}", tc.Name, GetName (OperatorType), ReturnType.ToString (), TypeManager.CSharpName (FirstArgType.Type));
+ sb.AppendFormat ("{0}.operator {1} {2}({3}", tc.Name, GetName (OperatorType), Type.ToString (), Parameters.FixedParameters [0].GetSignatureForError ());
- if (SecondArgType != null) {
+ if (Parameters.FixedParameters.Length > 1) {
sb.Append (",");
- sb.Append (TypeManager.CSharpName (SecondArgType.Type));
+ sb.Append (Parameters.FixedParameters [1].GetSignatureForError ());
}
sb.Append (")");
return sb.ToString ();
public override string ToString ()
{
+ if (OperatorMethod == null)
+ return Name;
+
Type return_type = OperatorMethod.ReturnType;
Type [] param_types = OperatorMethod.ParameterTypes;
- if (SecondArgType == null)
+ if (Parameters.FixedParameters.Length == 1)
return String.Format (
"{0} operator {1}({2})",
TypeManager.CSharpName (return_type),
return false;
const_ec = new EmitContext (Parent, Location, null, type, ModFlags);
-
+
Type ttype = type;
while (ttype.IsArray)
ttype = TypeManager.GetElementType (ttype);
value = null;
return false;
}
-
+
Expr = Expr.Resolve (const_ec);
in_transit = false;
Expr = ch_expr.Expr;
else if ((ec_expr != null) && (ec_expr.Child is Constant))
Expr = ec_expr.Child;
- else if (Expr is ArrayCreation) {
- ArrayCreation ac = (ArrayCreation) Expr;
-
- Expr = ac.TurnIntoConstant ();
- if (Expr == null){
- Report.Error (150, Location, "A constant value is expected");
- value = null;
- return false;
- }
+ else if (Expr is ArrayCreation){
+ Report.Error (133, Location, "Arrays can not be constant");
} else {
if (errors == Report.Errors)
Report.Error (150, Location, "A constant value is expected");
if ($7 != null)
current_class.Bases = (ArrayList) $7;
- CheckDef (current_class.SetParameterInfo ((ArrayList) $8), current_class.Name,
- current_class.Location);
+ current_class.SetParameterInfo ((ArrayList) $8);
current_class.Register ();
}
(Expression) constant.expression_or_array_initializer, (int) $2,
(Attributes) $1, l);
- CheckDef (current_container.AddConstant (c), c.Name, l);
+ current_container.AddConstant (c);
}
}
;
var.expression_or_array_initializer,
(Attributes) $1, l);
- CheckDef (current_container.AddField (field), field.Name, l);
+ current_container.AddField (field);
}
}
| opt_attributes
}
method.Block = (Block) $3;
- CheckDef (current_container.AddMethod (method), method.Name, method.Location);
+ current_container.AddMethod (method);
current_local_parameters = null;
iterator_container = null;
generic = new GenericMethod (current_namespace, current_class,
name, lexer.Location);
- CheckDef (generic.SetParameterInfo ((ArrayList) $9), name.Name, lexer.Location);
+ generic.SetParameterInfo ((ArrayList) $9);
}
method = new Method (current_class, generic, (Expression) $3, (int) $2, false,
generic = new GenericMethod (current_namespace, current_class,
name, lexer.Location);
-
- CheckDef (generic.SetParameterInfo ((ArrayList) $9), name.Name, lexer.Location);
+ generic.SetParameterInfo ((ArrayList) $9);
}
method = new Method (current_class, generic, TypeManager.system_void_expr,
if (SimpleIteratorContainer.Simple.Yields)
prop.SetYields ();
- CheckDef (current_container.AddProperty (prop), prop.Name, loc);
+ current_container.AddProperty (prop);
implicit_value_parameter_type = null;
iterator_container = null;
}
}
accessor_body
{
- $$ = new Accessor ((Block) $4, (Attributes) $1);
+ $$ = new Accessor ((Block) $4, (Attributes) $1, lexer.Location);
current_local_parameters = null;
lexer.PropertyParsing = true;
}
}
accessor_body
{
- $$ = new Accessor ((Block) $4, (Attributes) $1);
+ $$ = new Accessor ((Block) $4, (Attributes) $1, lexer.Location);
current_local_parameters = null;
lexer.PropertyParsing = true;
}
if ($7 != null)
current_class.Bases = (ArrayList) $7;
- CheckDef (current_class.SetParameterInfo ((ArrayList) $8),
- current_class.Name, current_class.Location);
+ current_class.SetParameterInfo ((ArrayList) $8);
current_class.Register ();
}
{
Method m = (Method) $1;
- CheckDef (current_container.AddMethod (m), m.Name, m.Location);
+ current_container.AddMethod (m);
}
| interface_property_declaration
{
Property p = (Property) $1;
- CheckDef (current_container.AddProperty (p), p.Name, p.Location);
+ current_container.AddProperty (p);
}
| interface_event_declaration
{
if ($1 != null){
Event e = (Event) $1;
- CheckDef (current_container.AddEvent (e), e.Name, lexer.Location);
+ current_container.AddEvent (e);
}
}
| interface_indexer_declaration
generic = new GenericMethod (current_namespace, current_class,
name, lexer.Location);
- CheckDef (generic.SetParameterInfo ((ArrayList) $9), name.Name, lexer.Location);
+ generic.SetParameterInfo ((ArrayList) $9);
}
$$ = new Method (current_class, generic, (Expression) $3, (int) $2, true, name,
generic = new GenericMethod (current_namespace, current_class,
name, lexer.Location);
- CheckDef (generic.SetParameterInfo ((ArrayList) $9), name.Name, lexer.Location);
+ generic.SetParameterInfo ((ArrayList) $9);
}
$$ = new Method (current_class, generic, TypeManager.system_void_expr, (int) $2,
;
interface_accessors
- : opt_attributes GET SEMICOLON { $$ = new InterfaceAccessorInfo (true, false, (Attributes) $1, null); }
- | opt_attributes SET SEMICOLON { $$ = new InterfaceAccessorInfo (false, true, null, (Attributes) $1); }
+ : opt_attributes GET SEMICOLON { $$ = new InterfaceAccessorInfo (true, false, (Attributes) $1, null, lexer.Location, lexer.Location); }
+ | opt_attributes SET SEMICOLON { $$ = new InterfaceAccessorInfo (false, true, null, (Attributes) $1, lexer.Location, lexer.Location); }
| opt_attributes GET SEMICOLON opt_attributes SET SEMICOLON
- { $$ = new InterfaceAccessorInfo (true, true, (Attributes) $1, (Attributes) $3); }
+ { $$ = new InterfaceAccessorInfo (true, true, (Attributes) $1, (Attributes) $3, lexer.Location, lexer.Location); }
| opt_attributes SET SEMICOLON opt_attributes GET SEMICOLON
- { $$ = new InterfaceAccessorInfo (true, true, (Attributes) $3, (Attributes) $1); }
+ { $$ = new InterfaceAccessorInfo (true, true, (Attributes) $3, (Attributes) $1, lexer.Location, lexer.Location); }
;
interface_event_declaration
{
InterfaceAccessorInfo info = (InterfaceAccessorInfo) $10;
- $$ = new Indexer (current_class, (Expression) $3, (int) $2, true,
- MemberName.Null, (Parameters) $6, (Attributes) $1,
+ $$ = new Indexer (current_class, (Expression) $3,
+ new MemberName (TypeContainer.DefaultIndexerName),
+ (int) $2, true, (Parameters) $6, (Attributes) $1,
info.Get, info.Set, lexer.Location);
}
;
{
OperatorDeclaration decl = (OperatorDeclaration) $3;
+ Parameter [] param_list = new Parameter [decl.arg2type != null ? 2 : 1];
+
+ param_list[0] = new Parameter (decl.arg1type, decl.arg1name, Parameter.Modifier.NONE, null);
+ if (decl.arg2type != null)
+ param_list[1] = new Parameter (decl.arg2type, decl.arg2name, Parameter.Modifier.NONE, null);
+
Operator op = new Operator (
- current_class, decl.optype, decl.ret_type, (int) $2, decl.arg1type,
- decl.arg1name, decl.arg2type, decl.arg2name, (Block) $5,
- (Attributes) $1, decl.location);
+ current_class, decl.optype, decl.ret_type, (int) $2,
+ new Parameters (param_list, null, decl.location),
+ (Block) $5, (Attributes) $1, decl.location);
if (SimpleIteratorContainer.Simple.Yields)
op.SetYields ();
Console.WriteLine ("{0} and {1}", c.Name, current_container.Basename);
}
- CheckDef (current_container.AddConstructor (c), c.Name, c.Location);
+ current_container.AddConstructor (c);
current_local_parameters = null;
}
new Parameters (null, null, l), (Attributes) $1, l);
d.Block = (Block) $7;
- CheckDef (current_container.AddMethod (d), d.Name, d.Location);
+ current_container.AddMethod (d);
}
}
| opt_attributes opt_modifiers EVENT type member_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS block {
var.expression_or_array_initializer,
(Attributes) $1, lexer.Location);
- CheckDef (current_container.AddEvent (e), e.Name, e.Location);
+ current_container.AddEvent (e);
}
}
(Accessor) pair.First, (Accessor) pair.Second,
loc);
- CheckDef (current_container.AddEvent (e), e.Name, loc);
+ current_container.AddEvent (e);
implicit_value_parameter_type = null;
}
}
}
block
{
- $$ = new Accessor ((Block) $4, (Attributes) $1);
+ $$ = new Accessor ((Block) $4, (Attributes) $1, lexer.Location);
lexer.EventParsing = true;
}
| opt_attributes ADD error {
}
block
{
- $$ = new Accessor ((Block) $4, (Attributes) $1);
+ $$ = new Accessor ((Block) $4, (Attributes) $1, lexer.Location);
lexer.EventParsing = true;
}
| opt_attributes REMOVE error {
if (decl.interface_type != null)
name = new MemberName (decl.interface_type, "", null);
else
- name = MemberName.Null;
+ name = new MemberName (TypeContainer.DefaultIndexerName);
- indexer = new Indexer (current_class, decl.type, (int) $2, false,
- name, decl.param_list, (Attributes) $1,
+ indexer = new Indexer (current_class, decl.type, name,
+ (int) $2, false, decl.param_list, (Attributes) $1,
get_block, set_block, loc);
- // Note that there is no equivalent of CheckDef for this case
- // We shall handle this in semantic analysis
-
current_container.AddIndexer (indexer);
current_local_parameters = null;
foreach (VariableDeclaration ev in (ArrayList) $6) {
Location loc = (Location) ev.Location;
- CheckDef (e.AddEnumMember (ev.identifier,
- (Expression) ev.expression_or_array_initializer,
- loc, ev.OptAttributes),
- ev.identifier, loc);
+ e.AddEnumMember (ev.identifier,
+ (Expression) ev.expression_or_array_initializer,
+ loc, ev.OptAttributes);
}
string name = full_name.GetName (false);
- CheckDef (current_container.AddEnum (e), name, enum_location);
+ current_container.AddEnum (e);
RootContext.Tree.RecordDecl (name, e);
}
current_namespace, current_container, (Expression) $4, (int) $2,
MakeName ((MemberName) $5), (Parameters) $7, (Attributes) $1, l);
- CheckDef (current_container.AddDelegate (del), del.Name, l);
+ current_container.AddDelegate (del);
current_delegate = del;
}
SEMICOLON
{
- CheckDef (current_delegate.SetParameterInfo ((ArrayList) $9), current_delegate.Name, current_delegate.Location);
+ current_delegate.SetParameterInfo ((ArrayList) $9);
current_delegate = null;
}
TypeManager.system_void_expr, (int) $2, MakeName ((MemberName) $5),
(Parameters) $7, (Attributes) $1, l);
- CheckDef (current_container.AddDelegate (del), del.Name, l);
+ current_container.AddDelegate (del);
current_delegate = del;
}
SEMICOLON
{
- CheckDef (current_delegate.SetParameterInfo ((ArrayList) $9), current_delegate.Name, current_delegate.Location);
+ current_delegate.SetParameterInfo ((ArrayList) $9);
current_delegate = null;
}
} else {
create_toplevel_block = false;
if (RootContext.Version == LanguageVersion.ISO_1){
- Report.FeatureIsNotStandardized ("anonymous methods");
+ Report.FeatureIsNotStandardized (lexer.Location, "anonymous methods");
$$ = null;
} else
$$ = new AnonymousMethod ((Parameters) $2, (Block) $4, lexer.Location);
current_class.Bases = (ArrayList) $7;
}
- CheckDef (current_class.SetParameterInfo ((ArrayList) $8),
- current_class.Name, current_class.Location);
+ current_class.SetParameterInfo ((ArrayList) $8);
current_class.Register ();
}
$$ = null;
}
if (RootContext.Version == LanguageVersion.ISO_1){
- Report.FeatureIsNotStandardized ("yield statement");
+ Report.FeatureIsNotStandardized (lexer.Location, "yield statement");
$$ = null;
}
if (iterator_container == null){
$$ = null;
}
if (RootContext.Version == LanguageVersion.ISO_1){
- Report.FeatureIsNotStandardized ("yield statement");
+ Report.FeatureIsNotStandardized (lexer.Location, "yield statement");
$$ = null;
}
if (iterator_container == null){
public readonly Accessor Get, Set;
public InterfaceAccessorInfo (bool has_get, bool has_set,
- Attributes get_attrs, Attributes set_attrs)
+ Attributes get_attrs, Attributes set_attrs, Location get_loc, Location set_loc)
{
if (has_get)
- Get = new Accessor (null, get_attrs);
+ Get = new Accessor (null, get_attrs, get_loc);
if (has_set)
- Set = new Accessor (null, set_attrs);
+ Set = new Accessor (null, set_attrs, set_loc);
}
}
}
}
-// <summary>
-// Used to report back to the user the result of a declaration
-// in the current declaration space
-// </summary>
-void
-CheckDef (DeclSpace.AdditionResult result, string name, Location l)
-{
- current_container.CheckDef (result, name, l);
-}
-
-void
-CheckDef (bool result, string name, Location l)
-{
- if (result)
- return;
- CheckDef (DeclSpace.AdditionResult.NameExists, name, l);
-}
-
Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
{
Block implicit_block;
val = 0ul;\r
return Token.LITERAL_INTEGER;\r
}\r
+ catch (FormatException) {\r
+ Report.Error (1013, Location, "Invalid number");\r
+ val = 0ul;\r
+ return Token.LITERAL_INTEGER;\r
+ }\r
}\r
\r
int adjust_real (int t)\r
}\r
}\r
\r
+ /// <summary>\r
+ /// Handles #pragma directive\r
+ /// </summary>\r
+ void PreProcessPragma (string arg)\r
+ {\r
+ const string disable = "warning disable";\r
+ const string restore = "warning restore";\r
+\r
+ if (arg == disable) {\r
+ Report.RegisterWarningRegion (Location).WarningDisable (line);\r
+ return;\r
+ }\r
+\r
+ if (arg == restore) {\r
+ Report.RegisterWarningRegion (Location).WarningEnable (line);\r
+ return;\r
+ }\r
+\r
+ if (arg.StartsWith (disable)) {\r
+ int[] codes = ParseNumbers (arg.Substring (disable.Length));\r
+ foreach (int code in codes) {\r
+ if (code != 0)\r
+ Report.RegisterWarningRegion (Location).WarningDisable (Location, code);\r
+ }\r
+ return;\r
+ }\r
+\r
+ if (arg.StartsWith (restore)) {\r
+ int[] codes = ParseNumbers (arg.Substring (restore.Length));\r
+ foreach (int code in codes) {\r
+ Report.RegisterWarningRegion (Location).WarningEnable (Location, code);\r
+ }\r
+ return;\r
+ }\r
+\r
+ return;\r
+ }\r
+\r
+ int[] ParseNumbers (string text)\r
+ {\r
+ string[] string_array = text.Split (',');\r
+ int[] values = new int [string_array.Length];\r
+ int index = 0;\r
+ foreach (string string_code in string_array) {\r
+ try {\r
+ values[index++] = int.Parse (string_code, System.Globalization.CultureInfo.InvariantCulture);\r
+ }\r
+ catch (FormatException) {\r
+ Report.Warning (1692, Location, "Invalid number");\r
+ }\r
+ }\r
+ return values;\r
+ }\r
+\r
bool eval_val (string s)\r
{\r
if (s == "true")\r
//\r
switch (cmd){\r
case "pragma":\r
- if (RootContext.Version != LanguageVersion.ISO_1)\r
+ if (RootContext.Version == LanguageVersion.ISO_1) {\r
+ Report.FeatureIsNotStandardized (Location, "#pragma");\r
return caller_is_taking;\r
- break;\r
+ }\r
+\r
+ PreProcessPragma (arg);\r
+ return caller_is_taking;\r
\r
case "line":\r
if (!PreProcessLine (arg))\r
namespace Mono.CSharp {
public class MemberName {
- public readonly string Name;
+ public string Name;
public readonly TypeArguments TypeArguments;
public readonly MemberName Left;
}
}
+ public MemberName Clone ()
+ {
+ if (Left != null)
+ return new MemberName (Left.Clone (), Name, TypeArguments);
+ else
+ return new MemberName (Name, TypeArguments);
+ }
+
public string Basename {
get {
if (TypeArguments != null)
/// <summary>
/// Public name
/// </summary>
- public string Name;
+ public string Name {
+ get {
+ return MemberName.GetName (!(this is GenericMethod) && !(this is Method));
+ }
+ }
public readonly MemberName MemberName;
HasClsCompliantAttribute = 1 << 6, // Type has CLSCompliantAttribute
ClsCompliantAttributeTrue = 1 << 7, // Type has CLSCompliant (true)
Excluded_Undetected = 1 << 8, // Conditional attribute has not been detected yet
- Excluded = 1 << 9 // Method is conditional
-
+ Excluded = 1 << 9, // Method is conditional
+ TestMethodDuplication = 1 << 10 // Test for duplication must be performed
}
/// <summary>
/// MemberCore flags at first detected then cached
/// </summary>
- protected Flags caching_flags;
+ internal Flags caching_flags;
public MemberCore (TypeContainer parent, MemberName name, Attributes attrs,
Location loc)
: base (attrs)
{
Parent = parent;
- Name = name.GetName (!(this is GenericMethod) && !(this is Method));
MemberName = name;
Location = loc;
caching_flags = Flags.Obsolete_Undetected | Flags.ClsCompliance_Undetected | Flags.HasCompliantAttribute_Undetected | Flags.Excluded_Undetected;
public string Basename;
- /// <summary>
- /// defined_names is used for toplevel objects
- /// </summary>
protected Hashtable defined_names;
readonly bool is_generic;
count_type_params += parent.count_type_params;
}
- public void RecordDecl ()
- {
- if ((NamespaceEntry != null) && (Parent == RootContext.Tree.Types))
- NamespaceEntry.DefineName (MemberName.Basename, this);
- }
-
- /// <summary>
- /// The result value from adding an declaration into
- /// a struct or a class
- /// </summary>
- public enum AdditionResult {
- /// <summary>
- /// The declaration has been successfully
- /// added to the declation space.
- /// </summary>
- Success,
-
- /// <summary>
- /// The symbol has already been defined.
- /// </summary>
- NameExists,
-
- /// <summary>
- /// Returned if the declation being added to the
- /// name space clashes with its container name.
- ///
- /// The only exceptions for this are constructors
- /// and static constructors
- /// </summary>
- EnclosingClash,
-
- /// <summary>
- /// Returned if a constructor was created (because syntactically
- /// it looked like a constructor) but was not (because the name
- /// of the method is not the same as the container class
- /// </summary>
- NotAConstructor,
-
- /// <summary>
- /// This is only used by static constructors to emit the
- /// error 111, but this error for other things really
- /// happens at another level for other functions.
- /// </summary>
- MethodExists,
-
- /// <summary>
- /// Some other error.
- /// </summary>
- Error
- }
-
/// <summary>
- /// Returns a status code based purely on the name
- /// of the member being added
+ /// Adds the member to defined_names table. It tests for duplications and enclosing name conflicts
/// </summary>
- protected AdditionResult IsValid (string basename, string name)
+ protected bool AddToContainer (MemberCore symbol, bool is_method, string fullname, string basename)
{
- if (basename == Basename)
- return AdditionResult.EnclosingClash;
+ if (basename == Basename) {
+ Report.SymbolRelatedToPreviousError (this);
+ Report.Error (542, "'{0}': member names cannot be the same as their enclosing type", symbol.Location, symbol.GetSignatureForError ());
+ return false;
+ }
+
+ 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;
+ return true;
+ }
- if (defined_names.Contains (name))
- return AdditionResult.NameExists;
+ if (mc != null) {
+ Report.SymbolRelatedToPreviousError (mc);
+ Report.Error (102, symbol.Location, "The type '{0}' already contains a definition for '{1}'", GetSignatureForError (), basename);
+ return false;
+ }
- return AdditionResult.Success;
+ defined_names.Add (fullname, symbol);
+ return true;
}
- public static int length;
- public static int small;
-
- /// <summary>
- /// Introduce @name into this declaration space and
- /// associates it with the object @o. Note that for
- /// methods this will just point to the first method. o
- /// </summary>
- public void DefineName (string name, object o)
+ public void RecordDecl ()
{
- defined_names.Add (name, o);
-
-#if DEBUGME
- int p = name.LastIndexOf ('.');
- int l = name.Length;
- length += l;
- small += l -p;
-#endif
+ if ((NamespaceEntry != null) && (Parent == RootContext.Tree.Types))
+ NamespaceEntry.DefineName (MemberName.Basename, this);
}
/// <summary>
- /// Returns the object associated with a given name in the declaration
- /// space. This is the inverse operation of `DefineName'
+ /// Returns the MemberCore associated with a given name in the declaration
+ /// space. It doesn't return method based symbols !!
/// </summary>
- public object GetDefinition (string name)
+ ///
+ public MemberCore GetDefinition (string name)
{
- return defined_names [name];
+ return (MemberCore)defined_names [name];
}
-
+
bool in_transit = false;
/// <summary>
return type_param_list;
}
- public AdditionResult SetParameterInfo (ArrayList constraints_list)
+ public void SetParameterInfo (ArrayList constraints_list)
{
if (!is_generic) {
if (constraints_list != null) {
Report.Error (
80, Location, "Contraints are not allowed " +
"on non-generic declarations");
- return AdditionResult.Error;
}
- return AdditionResult.Success;
+ return;
}
string[] names = MemberName.TypeArguments.GetDeclarations ();
for (int i = 0; i < type_params.Length; i++) {
string name = names [i];
- AdditionResult res = IsValid (name, name);
-
- if (res != AdditionResult.Success)
- return res;
-
Constraints constraints = null;
if (constraints_list != null) {
foreach (Constraints constraint in constraints_list) {
}
}
- type_params [i] = new TypeParameter (name, constraints, Location);
+ type_params [i] = new TypeParameter (Parent, name, constraints, Location);
- DefineName (name, type_params [i]);
+ string full_name = Name + "." + name;
+ AddToContainer (type_params [i], false, full_name, name);
}
-
- return AdditionResult.Success;
}
public TypeParameter[] TypeParameters {
return 0;
}
- static void Error_NegativeArrayIndex (Location loc)
+ public static void Error_NegativeArrayIndex (Location loc)
{
- Report.Error (284, loc, "Can not create array with a negative size");
+ Report.Error (248, loc, "Cannot create an array with a negative size");
}
//
return this;
}
- Report_AssignToReadonly (true);
+ Report_AssignToReadonly (!IsStatic);
return null;
}
Enum parent_enum;
public FieldBuilder builder;
+ internal readonly Expression Type;
- public EnumMember (Enum parent_enum, string name, Location loc, Attributes attrs):
+ public EnumMember (Enum parent_enum, Expression expr, string name,
+ Location loc, Attributes attrs):
base (null, new MemberName (name), attrs, loc)
{
this.parent_enum = parent_enum;
this.ModFlags = parent_enum.ModFlags;
+ this.Type = expr;
}
public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb)
public void Emit (EmitContext ec)
{
+ base.Emit ();
+
if (OptAttributes != null)
OptAttributes.Emit (ec, this);
Emit ();
}
- // TODO: caching would be usefull
- public ObsoleteAttribute GetObsoleteAttribute (EmitContext ec)
- {
- if (OptAttributes == null)
- return null;
-
- Attribute obsolete_attr = OptAttributes.Search (TypeManager.obsolete_attribute_type, ec);
- if (obsolete_attr == null)
- return null;
-
- ObsoleteAttribute obsolete = obsolete_attr.GetObsoleteAttribute (ec.DeclSpace);
- if (obsolete == null)
- return null;
-
- return obsolete;
- }
-
public override string GetSignatureForError()
{
return String.Concat (parent_enum.GetSignatureForError (), '.', base.GetSignatureForError ());
public Type UnderlyingType;
Hashtable member_to_location;
- Hashtable member_to_attributes;
//
// This is for members that have been defined
ArrayList field_builders;
-
- Hashtable name_to_member;
-
public const int AllowedModifiers =
Modifiers.NEW |
Modifiers.PUBLIC |
member_to_value = new Hashtable ();
in_transit = new Hashtable ();
field_builders = new ArrayList ();
-
- name_to_member = new Hashtable ();
}
/// <summary>
/// Adds @name to the enumeration space, with @expr
/// being its definition.
/// </summary>
- public AdditionResult AddEnumMember (string name, Expression expr, Location loc,
- Attributes opt_attrs)
+ public void AddEnumMember (string name, Expression expr, Location loc, Attributes opt_attrs)
{
- if (defined_names.Contains (name))
- return AdditionResult.NameExists;
-
if (name == "value__") {
Report.Error (76, loc, "An item in an enumeration can't have an identifier `value__'");
- return AdditionResult.Error;
+ return;
}
- DefineName (name, expr);
+ EnumMember em = new EnumMember (this, expr, name, loc, opt_attrs);
+ if (!AddToContainer (em, false, name, ""))
+ return;
+
+ // TODO: can be almost deleted
ordered_enums.Add (name);
member_to_location.Add (name, loc);
-
- if (member_to_attributes == null)
- member_to_attributes = new Hashtable ();
-
- member_to_attributes.Add (name, opt_attrs);
-
- name_to_member.Add (name, new EnumMember (this, name, loc, opt_attrs));
-
- return AdditionResult.Success;
}
//
}
}
- EnumMember em = name_to_member [name] as EnumMember;
+ EnumMember em = (EnumMember) defined_names [name];
em.DefineMember (TypeBuilder);
bool fail;
//
if (TypeBuilder == null)
return false;
-
+
EmitContext ec = new EmitContext (this, this, Location, null,
UnderlyingType, ModFlags, false);
object default_value = 0;
-
+
foreach (string name in ordered_enums) {
//
// Have we already been defined, thanks to some cross-referencing ?
return false;
}
- EnumMember em = name_to_member [name] as EnumMember;
+ EnumMember em = (EnumMember) defined_names [name];
em.DefineMember (TypeBuilder);
FieldBuilder fb = em.builder;
return true;
}
-
+
public override void Emit ()
{
EmitContext ec = new EmitContext (
OptAttributes.Emit (ec, this);
}
- foreach (EnumMember em in name_to_member.Values) {
+ foreach (EnumMember em in defined_names.Values) {
em.Emit (ec);
}
}
void VerifyClsName ()
- {
+ {
Hashtable ht = new Hashtable ();
foreach (string name in ordered_enums) {
string locase = name.ToLower (System.Globalization.CultureInfo.InvariantCulture);
if (!ht.Contains (locase)) {
- ht.Add (locase, name_to_member [name]);
- continue;
- }
+ ht.Add (locase, defined_names [name]);
+ continue;
+ }
- EnumMember conflict = (EnumMember)ht [locase];
+ MemberCore conflict = (MemberCore)ht [locase];
Report.SymbolRelatedToPreviousError (conflict);
- conflict = (EnumMember)name_to_member [name];
+ conflict = GetDefinition (name);
Report.Error (3005, conflict.Location, "Identifier '{0}' differing only in case is not CLS-compliant", conflict.GetSignatureForError ());
- }
- }
+ }
+ }
protected override bool VerifyClsCompliance (DeclSpace ds)
{
// indexer
public Expression this [string name] {
get {
- return (Expression) defined_names [name];
+ return ((EnumMember) defined_names [name]).Type;
}
}
{
// UnderlyingType is never obsolete
}
-
- /// <summary>
- /// Returns ObsoleteAttribute for both enum type and enum member
- /// </summary>
- public ObsoleteAttribute GetObsoleteAttribute (EmitContext ec, string identifier)
- {
- if ((caching_flags & Flags.Obsolete_Undetected) == 0 && (caching_flags & Flags.Obsolete) == 0) {
- return null;
- }
-
- ObsoleteAttribute oa = GetObsoleteAttribute (ec.DeclSpace);
- if (oa != null)
- return oa;
-
- EnumMember em = (EnumMember)name_to_member [identifier];
- oa = em.GetObsoleteAttribute (ec);
-
- if (oa == null)
- return null;
-
- caching_flags |= Flags.Obsolete;
- return oa;
- }
}
}
if (expr == null)
return null;
+ if (expr.Type.IsPointer) {
+ Report.Error (244, loc, "\"is\" or \"as\" are not valid on pointer types");
+ return null;
+ }
return this;
}
}
else if (rtype == TypeManager.uint64_type)
ig.Emit (OpCodes.Conv_U8);
ig.Emit (OpCodes.Mul);
- ig.Emit (OpCodes.Conv_I);
}
+
+ if (rtype == TypeManager.int64_type || rtype == TypeManager.uint64_type)
+ ig.Emit (OpCodes.Conv_I);
+
if (is_add)
ig.Emit (OpCodes.Add);
else
Type true_type = trueExpr.Type;
Type false_type = falseExpr.Type;
- if (trueExpr is NullLiteral){
- type = false_type;
- return this;
- } else if (falseExpr is NullLiteral){
- type = true_type;
- return this;
- }
-
//
// First, if an implicit conversion exists from trueExpr
// to falseExpr, then the result type is of type falseExpr.Type
if (Expr == null)
return false;
+ if (!ec.IsConstructor) {
+ FieldExpr fe = Expr as FieldExpr;
+ if (fe != null && fe.FieldInfo.IsInitOnly) {
+ if (fe.FieldInfo.IsStatic)
+ Report.Error (199, loc, "A static readonly field cannot be passed ref or out (except in a static constructor)");
+ else
+ Report.Error (192, loc, "A readonly field cannot be passed ref or out (except in a constructor)");
+ return false;
+ }
+ }
Expr = Expr.ResolveLValue (ec, Expr);
} else if (ArgType == AType.Out)
Expr = Expr.ResolveLValue (ec, new EmptyExpression ());
return null;
}
+ if (method.Name == "Finalize" && Arguments == null) {
+ if (is_base)
+ Report.Error (250, loc, "Do not directly call your base class Finalize method. It is called automatically from your destructor");
+ else
+ Report.Error (245, loc, "Destructors and object.Finalize cannot be called directly. Consider calling IDisposable.Dispose if available");
+ return null;
+ }
+
if ((method.Attributes & MethodAttributes.SpecialName) != 0){
if (TypeManager.IsSpecialMethod (method))
Report.Error (571, loc, method.Name + ": can not call operator or accessor");
Expression tmp = (Expression) o;
tmp = tmp.Resolve (ec);
if (tmp == null)
- continue;
+ return false;
// Console.WriteLine ("I got: " + tmp);
// Handle initialization from vars, fields etc.
}
}
- void Error_NegativeArrayIndex ()
- {
- Error (284, "Can not create array with a negative size");
- }
-
//
// Converts `source' to an int, uint, long or ulong.
//
if (target is Constant){
if (target is IntConstant){
if (((IntConstant) target).Value < 0){
- Error_NegativeArrayIndex ();
+ Expression.Error_NegativeArrayIndex (loc);
return null;
}
}
if (target is LongConstant){
if (((LongConstant) target).Value < 0){
- Error_NegativeArrayIndex ();
+ Expression.Error_NegativeArrayIndex (loc);
return null;
}
}
}
return ret;
}
-
- public Expression TurnIntoConstant ()
- {
- //
- // Should use something like the above attribute thing.
- // It should return a subclass of Constant that just returns
- // the computed value of the array
- //
- throw new Exception ("Does not support yet Turning array into a Constant");
- }
}
/// <summary>
return null;
}
+ if (typearg.IsPointer && !ec.InUnsafe){
+ UnsafeError (loc);
+ return null;
+ }
CheckObsoleteAttribute (typearg);
type = TypeManager.type_type;
object value = en.LookupEnumValue (ec, Identifier, loc);
if (value != null){
- ObsoleteAttribute oa = en.GetObsoleteAttribute (ec, Identifier);
+ MemberCore mc = en.GetDefinition (Identifier);
+ ObsoleteAttribute oa = mc.GetObsoleteAttribute (en);
+ if (oa != null) {
+ AttributeTester.Report_ObsoleteMessage (oa, mc.GetSignatureForError (), Location);
+ }
+ oa = en.GetObsoleteAttribute (en);
if (oa != null) {
AttributeTester.Report_ObsoleteMessage (oa, en.GetSignatureForError (), Location);
}
//
// This type represents a generic type parameter
//
- public class TypeParameter : IMemberContainer {
+ public class TypeParameter : MemberCore, IMemberContainer {
string name;
Constraints constraints;
Location loc;
GenericTypeParameterBuilder type;
- public TypeParameter (string name, Constraints constraints, Location loc)
+ public TypeParameter (TypeContainer parent, string name,
+ Constraints constraints, Location loc)
+ : base (parent, new MemberName (name), null, loc)
{
this.name = name;
this.constraints = constraints;
this.loc = loc;
}
- public string Name {
- get {
- return name;
- }
- }
-
- public Location Location {
- get {
- return loc;
- }
- }
-
public Constraints Constraints {
get {
return constraints;
return true;
}
+ //
+ // MemberContainer
+ //
+
+ public override bool Define ()
+ {
+ return true;
+ }
+
+ protected override void VerifyObsoleteAttribute ()
+ { }
+
+ public override void ApplyAttributeBuilder (Attribute a,
+ CustomAttributeBuilder cb)
+ { }
+
+ public override AttributeTargets AttributeTargets {
+ get {
+ return (AttributeTargets) 0;
+ }
+ }
+
+ public override string[] ValidAttributeTargets {
+ get {
+ return new string [0];
+ }
+ }
+
//
// IMemberContainer
//
+ string IMemberContainer.Name {
+ get { return Name; }
+ }
+
IMemberContainer IMemberContainer.ParentContainer {
get { return null; }
}
new FieldExpression (current_field), Location),
Location));
- Accessor getter = new Accessor (get_block, null);
+ Accessor getter = new Accessor (get_block, null, Location);
Property current = new Property (
this, type, 0, false, name, null, getter, null, Location);
using System.Reflection;
using System.Reflection.Emit;
+//
+// I put System.Null just so we do not have to special case it on
+// TypeManager.CSharpName
+//
+namespace System {
+ //
+ // Represents the Null Type, just used as a placeholder for the type in NullLiteral
+ //
+ public class Null {
+ }
+}
+
namespace Mono.CSharp {
public class NullLiteral : Constant {
public override Expression DoResolve (EmitContext ec)
{
- type = TypeManager.object_type;
+ type = typeof (System.Null);
return this;
}
if (resolved != null)
return resolved;
- NamespaceEntry curr_ns = NamespaceEntry;
-
//
// GENERICS: Cope with the expression and not with the string
// this will fail with `using A = Stack<int>'
//
string alias = Alias.GetTypeName ();
+
+ // According to section 16.3.1, the namespace-or-type-name is resolved
+ // as if the immediately containing namespace body has no using-directives.
+ resolved = NamespaceEntry.Lookup (
+ null, alias, Alias.CountTypeArguments, true, false, Location);
+
+ NamespaceEntry curr_ns = NamespaceEntry.Parent;
+
while ((curr_ns != null) && (resolved == null)) {
resolved = curr_ns.Lookup (
null, alias, Alias.CountTypeArguments,
- false, Location);
+ false, false, Location);
if (resolved == null)
curr_ns = curr_ns.Parent;
}
public IAlias Lookup (DeclSpace ds, string name, int num_type_params,
- bool silent, Location loc)
+ bool ignore_using, bool silent, Location loc)
{
IAlias o;
Namespace ns;
string first = name.Substring (0, pos);
string last = name.Substring (pos + 1);
- o = Lookup (ds, first, 0, silent, loc);
+ o = Lookup (ds, first, 0, ignore_using, silent, loc);
if (o == null)
return null;
if (o != null)
return o;
+ if (ignore_using)
+ return null;
+
//
// Check aliases.
//
TypeName = type;
}
+ public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
+ {
+ if (a.Type == TypeManager.param_array_type) {
+ Report.Error (674, a.Location, "Do not use 'System.ParamArrayAttribute'. Use the 'params' keyword instead");
+ return;
+ }
+ base.ApplyAttributeBuilder (a, cb);
+ }
+
// <summary>
// Resolve is used in method definitions
// </summary>
//
static Hashtable warning_ignore_table;
+ static Hashtable warning_regions_table;
+
/// <summary>
/// List of symbols related to reported error/warning. You have to fill it before error/warning is reported.
/// </summary>
static StringCollection related_symbols = new StringCollection ();
-
- static void Check (int code)
- {
- if (code == expected_error){
+
+ abstract class AbstractMessage {
+
+ static void Check (int code)
+ {
+ if (code == expected_error) {
+ Environment.Exit (0);
+ }
+ }
+
+ public abstract string MessageType { get; }
+
+ public virtual void Print (int code, string location, string text)
+ {
+ if (code < 0)
+ code = 8000-code;
+
+ StringBuilder msg = new StringBuilder ();
+ if (location.Length != 0) {
+ msg.Append (location);
+ msg.Append (' ');
+ }
+ msg.AppendFormat ("{0} CS{1:0000}: {2}", MessageType, code, text);
+ Console.WriteLine (msg.ToString ());
+
+ foreach (string s in related_symbols) {
+ Console.WriteLine (String.Concat (s, MessageType, ')'));
+ }
+ related_symbols.Clear ();
+
+ if (Stacktrace)
+ Console.WriteLine (FriendlyStackTrace (new StackTrace (true)));
+
if (Fatal)
- throw new Exception ();
-
- Environment.Exit (0);
+ throw new Exception (text);
+
+ Check (code);
+ }
+
+ public virtual void Print (int code, Location location, string text)
+ {
+ if (location.Equals (Location.Null)) {
+ Print (code, "", text);
+ return;
+ }
+ Print (code, String.Format ("{0}({1})", location.Name, location.Row), text);
}
}
-
- public static void FeatureIsNotStandardized (string feature)
+
+ sealed class WarningMessage: AbstractMessage {
+ Location loc = Location.Null;
+ readonly int Level;
+
+ public WarningMessage ():
+ this (-1) {}
+
+ public WarningMessage (int level)
+ {
+ Level = level;
+ }
+
+ bool IsEnabled (int code)
+ {
+ if (RootContext.WarningLevel < Level)
+ return false;
+
+ if (warning_ignore_table != null) {
+ if (warning_ignore_table.Contains (code)) {
+ return false;
+ }
+ }
+
+ if (warning_regions_table == null || loc.Equals (Location.Null))
+ return true;
+
+ WarningRegions regions = (WarningRegions)warning_regions_table [loc.Name];
+ return regions.IsWarningEnabled (code, loc.Row);
+ }
+
+ public override void Print(int code, string location, string text)
+ {
+ if (!IsEnabled (code)) {
+ related_symbols.Clear ();
+ return;
+ }
+
+ if (WarningsAreErrors) {
+ new ErrorMessage ().Print (code, location, text);
+ return;
+ }
+
+ Warnings++;
+ base.Print (code, location, text);
+ }
+
+ public override void Print(int code, Location location, string text)
+ {
+ loc = location;
+ base.Print (code, location, text);
+ }
+
+ public override string MessageType {
+ get {
+ return "warning";
+ }
+ }
+ }
+
+ sealed class ErrorMessage: AbstractMessage {
+
+ public override void Print(int code, string location, string text)
+ {
+ Errors++;
+ base.Print (code, location, text);
+ }
+
+ public override string MessageType {
+ get {
+ return "error";
+ }
+ }
+
+ }
+
+ public static void FeatureIsNotStandardized (Location loc, string feature)
{
- Report.Error (1644, "Feature '{0}' cannot be used because it is not part of the standardized ISO C# language specification", feature);
+ Report.Error (1644, loc, "Feature '{0}' cannot be used because it is not part of the standardized ISO C# language specification", feature);
}
public static string FriendlyStackTrace (Exception e)
return sb.ToString ();
}
+
+ // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ // IF YOU ADD A NEW WARNING YOU HAVE TO DUPLICATE ITS ID HERE
+ public static bool IsValidWarning (int code)
+ {
+ int[] all_warnings = new int[] { 28, 67, 78, 105, 108, 109, 114, 192, 168, 169, 183, 184, 219, 251, 612, 618, 626, 628, 642, 649,
+ 659, 660, 661, 672, 1030, 1522, 1616, 1691, 1692, 1901, 2002, 2023, 3012, 3019, 8024, 8028
+ };
+ foreach (int i in all_warnings) {
+ if (i == code)
+ return true;
+ }
+ return false;
+ }
static public void LocationOfPreviousError (Location loc)
{
Console.WriteLine (String.Format ("{0}({1}) (Location of symbol related to previous error)", loc.Name, loc.Row));
- }
-
+ }
+
static public void RuntimeMissingSupport (string feature)
{
Report.Error (-88, "Your .NET Runtime does not support '{0}'. Please use the latest Mono runtime instead.");
}
/// <summary>
- /// In most error cases is very useful to have information about symbol that caused the error.
- /// Call this method before you call Report.Error when it makes sense.
+ /// In most error cases is very useful to have information about symbol that caused the error.
+ /// Call this method before you call Report.Error when it makes sense.
/// </summary>
static public void SymbolRelatedToPreviousError (Location loc, string symbol)
{
static public void SymbolRelatedToPreviousError (MemberInfo mi)
{
- Type decl = mi.DeclaringType;
- if (decl.IsGenericInstance)
- decl = decl.GetGenericTypeDefinition ();
-
- TypeContainer temp_ds = TypeManager.LookupTypeContainer (decl);
+ TypeContainer temp_ds = TypeManager.LookupTypeContainer (mi.DeclaringType);
if (temp_ds == null) {
- SymbolRelatedToPreviousError (decl.Assembly.Location, TypeManager.GetFullNameSignature (mi));
+ SymbolRelatedToPreviousError (mi.DeclaringType.Assembly.Location, TypeManager.GetFullNameSignature (mi));
} else {
if (mi is MethodBase) {
- MethodBase mb = (MethodBase) mi;
- if (mb.Mono_IsInflatedMethod)
- mb = mb.GetGenericMethodDefinition ();
-
- IMethodData md = TypeManager.GetMethod (mb);
+ IMethodData md = TypeManager.GetMethod ((MethodBase)mi);
SymbolRelatedToPreviousError (md.Location, md.GetSignatureForError (temp_ds));
return;
}
string name = String.Concat (temp_ds.Name, ".", mi.Name);
- MemberCore mc = temp_ds.GetDefinition (name) as MemberCore;
- SymbolRelatedToPreviousError (mc.Location, mc.GetSignatureForError ());
+ MemberCore mc = temp_ds.GetDefinition (name);
+ SymbolRelatedToPreviousError (mc);
}
}
{
DeclSpace temp_ds = TypeManager.LookupDeclSpace (type);
if (temp_ds == null)
- SymbolRelatedToPreviousError (type.Assembly.Location, TypeManager.CSharpName (type));
+ SymbolRelatedToPreviousError (type.Assembly.Location, TypeManager.CSharpName (type));
else
SymbolRelatedToPreviousError (temp_ds.Location, TypeManager.CSharpName (type));
}
related_symbols.Add (String.Format ("{0}: '{1}' (name of symbol related to previous ", loc, symbol));
}
- static public void RealError (string msg)
+ public static WarningRegions RegisterWarningRegion (Location location)
{
- Errors++;
- Console.WriteLine (msg);
+ if (warning_regions_table == null)
+ warning_regions_table = new Hashtable ();
- foreach (string s in related_symbols)
- Console.WriteLine (s + "error)");
- related_symbols.Clear ();
-
- if (Stacktrace)
- Console.WriteLine (FriendlyStackTrace (new StackTrace (true)));
-
- if (Fatal)
- throw new Exception (msg);
+ WarningRegions regions = (WarningRegions)warning_regions_table [location.Name];
+ if (regions == null) {
+ regions = new WarningRegions ();
+ warning_regions_table.Add (location.Name, regions);
+ }
+ return regions;
}
-
- static public void Error (int code, Location l, string text)
+ static public void Warning (int code, int level, Location loc, string format, params object[] args)
{
- if (code < 0)
- code = 8000-code;
-
- string msg = String.Format (
- "{0}({1}) error CS{2:0000}: {3}", l.Name, l.Row, code, text);
-// "{0}({1}) error CS{2}: {3}", l.Name, l.Row, code, text);
-
- RealError (msg);
- Check (code);
+ WarningMessage w = new WarningMessage (level);
+ w.Print (code, loc, String.Format (format, args));
}
- static public void Warning (int code, Location l, string text)
+ static public void Warning (int code, Location loc, string format, params object[] args)
{
- if (code < 0)
- code = 8000-code;
-
- if (warning_ignore_table != null){
- if (warning_ignore_table.Contains (code)) {
- related_symbols.Clear ();
- return;
- }
- }
-
- if (WarningsAreErrors)
- Error (code, l, text);
- else {
- string row;
-
- if (Location.IsNull (l))
- row = "";
- else
- row = l.Row.ToString ();
-
- Console.WriteLine (String.Format (
- "{0}({1}) warning CS{2:0000}: {3}",
-// "{0}({1}) warning CS{2}: {3}",
- l.Name, row, code, text));
- Warnings++;
-
- foreach (string s in related_symbols)
- Console.WriteLine (s + "warning)");
- related_symbols.Clear ();
-
- Check (code);
-
- if (Stacktrace)
- Console.WriteLine (new StackTrace ().ToString ());
- }
+ WarningMessage w = new WarningMessage ();
+ w.Print (code, loc, String.Format (format, args));
}
-
- static public void Warning (int code, string text)
+
+ static public void Warning (int code, string format, params object[] args)
{
- Warning (code, Location.Null, text);
+ Warning (code, Location.Null, String.Format (format, args));
}
- static public void Error (int code, string text)
+ /// <summary>
+ /// Did you test your WarningLevel, that you use this method
+ /// </summary>
+ static public void Warning (int code, string text)
{
- if (code < 0)
- code = 8000-code;
-
- string msg = String.Format ("error CS{0:0000}: {1}", code, text);
-
- RealError (msg);
- Check (code);
+ Warning (code, Location.Null, text);
}
static public void Error (int code, string format, params object[] args)
static public void Error (int code, Location loc, string format, params object[] args)
{
- Error (code, loc, String.Format (format, args));
- }
-
- static public void Warning (int code, string format, params object[] args)
- {
- Warning (code, Location.Null, String.Format (format, args));
- }
-
- static public void Warning (int code, Location loc, string format, params object[] args)
- {
- Warning (code, loc, String.Format (format, args));
+ ErrorMessage e = new ErrorMessage ();
+ e.Print (code, loc, String.Format (format, args));
}
static public void SetIgnoreWarning (int code)
warning_ignore_table [code] = true;
}
- static public int ExpectedError {
- set {
- expected_error = value;
- }
- get {
- return expected_error;
- }
- }
+ static public int ExpectedError {
+ set {
+ expected_error = value;
+ }
+ get {
+ return expected_error;
+ }
+ }
public static int DebugFlags = 0;
sb.Append ("null");
else if (arg is ICollection)
sb.Append (PrintCollection ((ICollection) arg));
- else if (arg is IntPtr)
- sb.Append (String.Format ("IntPtr(0x{0:x})", ((IntPtr) arg).ToInt32 ()));
else
sb.Append (arg);
}
: base (message)
{
}
+ }
+
+ /// <summary>
+ /// Handles #pragma warning
+ /// </summary>
+ public class WarningRegions {
+
+ abstract class PragmaCmd
+ {
+ public int Line;
+
+ protected PragmaCmd (int line)
+ {
+ Line = line;
+ }
+
+ public abstract bool IsEnabled (int code, bool previous);
+ }
+
+ class Disable: PragmaCmd
+ {
+ int code;
+ public Disable (int line, int code)
+ : base (line)
+ {
+ this.code = code;
+ }
+
+ public override bool IsEnabled (int code, bool previous)
+ {
+ return this.code == code ? false : previous;
+ }
+ }
+
+ class DisableAll: PragmaCmd
+ {
+ public DisableAll (int line)
+ : base (line) {}
+
+ public override bool IsEnabled(int code, bool previous)
+ {
+ return false;
+ }
+ }
+
+ class Enable: PragmaCmd
+ {
+ int code;
+ public Enable (int line, int code)
+ : base (line)
+ {
+ this.code = code;
+ }
+
+ public override bool IsEnabled(int code, bool previous)
+ {
+ return this.code == code ? true : previous;
+ }
+ }
+
+ class EnableAll: PragmaCmd
+ {
+ public EnableAll (int line)
+ : base (line) {}
+
+ public override bool IsEnabled(int code, bool previous)
+ {
+ return true;
+ }
+ }
+
+
+ ArrayList regions = new ArrayList ();
+
+ public void WarningDisable (int line)
+ {
+ regions.Add (new DisableAll (line));
+ }
- public InternalErrorException (string format, params object[] args)
- : this (String.Format (format, args))
- { }
+ public void WarningDisable (Location location, int code)
+ {
+ if (CheckWarningCode (code, location))
+ regions.Add (new Disable (location.Row, code));
+ }
+
+ public void WarningEnable (int line)
+ {
+ regions.Add (new EnableAll (line));
+ }
+
+ public void WarningEnable (Location location, int code)
+ {
+ if (CheckWarningCode (code, location))
+ regions.Add (new Enable (location.Row, code));
+ }
+
+ public bool IsWarningEnabled (int code, int src_line)
+ {
+ bool result = true;
+ foreach (PragmaCmd pragma in regions) {
+ if (src_line < pragma.Line)
+ break;
+
+ result = pragma.IsEnabled (code, result);
+ }
+ return result;
+ }
+
+ bool CheckWarningCode (int code, Location loc)
+ {
+ if (Report.IsValidWarning (code))
+ return true;
+
+ Report.Warning (1691, 1, loc, "'{0}' is not a valid warning number", code);
+ return false;
+ }
}
}
// Try in the current namespace and all its implicit parents
//
for (NamespaceEntry ns = ds.NamespaceEntry; ns != null; ns = ns.ImplicitParent) {
- IAlias result = ns.Lookup (ds, name, num_type_args, silent, loc);
+ IAlias result = ns.Lookup (ds, name, num_type_args, false, silent, loc);
if (result == null)
continue;
@"^System\." +
@"(Int32|UInt32|Int16|UInt16|Int64|UInt64|" +
@"Single|Double|Char|Decimal|Byte|SByte|Object|" +
- @"Boolean|String|Void)" +
+ @"Boolean|String|Void|Null)" +
@"(\W+|\b)",
new MatchEvaluator (CSharpNameMatch));
}
iparams = new ReflectionParameters (mb);
// Is property
- if (mb.IsSpecialName && iparams.Count == 0)
+ if (mb.IsSpecialName && iparams.Count == 0 && !mb.IsConstructor)
return GetFullNameSignature (mb);
for (int i = 0; i < iparams.Count; i++) {
/// for anything which is dynamic, and we need this in a number of places,
/// we register this information here, and use it afterwards.
/// </remarks>
- static public bool RegisterMethod (MethodBase mb, InternalParameters ip, Type [] args)
+ static public void RegisterMethod (MethodBase mb, InternalParameters ip, Type [] args)
{
if (args == null)
args = NoTypes;
method_arguments.Add (mb, args);
method_internal_params.Add (mb, ip);
-
- return true;
}
static public InternalParameters LookupParametersByBuilder (MethodBase mb)
static Hashtable events;
- static public bool RegisterEvent (MyEventBuilder eb, MethodBase add, MethodBase remove)
+ static public void RegisterEvent (MyEventBuilder eb, MethodBase add, MethodBase remove)
{
if (events == null)
events = new Hashtable ();
- if (events.Contains (eb))
- return false;
-
+ if (!events.Contains (eb)) {
events.Add (eb, new Pair (add, remove));
-
- return true;
+ }
}
static public MethodInfo GetAddMethod (EventInfo ei)