public Type Type;
+ bool resolve_error;
+
// Is non-null if type is AttributeUsageAttribute
AttributeUsageAttribute usage_attribute;
"Could not find attribute '" + Name
+ "' (are you missing a using directive or an assembly reference ?)");
+ resolve_error = true;
return null;
}
return false;
}
- public CustomAttributeBuilder Resolve (EmitContext ec)
+ public virtual CustomAttributeBuilder Resolve (EmitContext ec)
{
+ if (resolve_error)
+ return null;
+
+ resolve_error = true;
+
Type oldType = Type;
// Sanity check.
else
cb = new CustomAttributeBuilder (
(ConstructorInfo) constructor, pos_values);
- } catch (NullReferenceException) {
- //
- // Don't know what to do here
- //
- Report.Warning (
- -101, Location, "NullReferenceException while trying to create attribute." +
- "Something's wrong!");
} catch (Exception e) {
//
// Sample:
// [DefaultValue (CollectionChangeAction.Add)]
// class X { static void Main () {} }
//
- Report.Warning (
- -23, Location, "The compiler can not encode this attribute in .NET due to a bug in the .NET runtime. Try the Mono runtime. The exception was: " + e.Message);
+ Error_AttributeArgumentNotValid (Location);
+ return null;
}
+ resolve_error = false;
return cb;
}
/// </summary>
public string GetIndexerAttributeValue (EmitContext ec)
{
- if (pos_values == null) {
+ if (pos_values == null)
// TODO: It is not neccessary to call whole Resolve (ApplyAttribute does it now) we need only ctor args.
// But because a lot of attribute class code must be rewritten will be better to wait...
Resolve (ec);
- }
return pos_values [0] as string;
}
/// <summary>
/// Returns condition of ConditionalAttribute
/// </summary>
- public string GetConditionalAttributeValue (DeclSpace ds)
+ public string GetConditionalAttributeValue (EmitContext ec)
{
- if (pos_values == null) {
- EmitContext ec = new EmitContext (ds, ds, Location, null, null, 0, false);
-
+ if (pos_values == null)
// TODO: It is not neccessary to call whole Resolve (ApplyAttribute does it now) we need only ctor args.
// But because a lot of attribute class code must be rewritten will be better to wait...
Resolve (ec);
- }
// Some error occurred
if (pos_values [0] == null)
/// <summary>
/// Creates the instance of ObsoleteAttribute from this attribute instance
/// </summary>
- public ObsoleteAttribute GetObsoleteAttribute (DeclSpace ds)
+ public ObsoleteAttribute GetObsoleteAttribute (EmitContext ec)
{
- if (pos_values == null) {
- EmitContext ec = new EmitContext (ds, ds, Location, null, null, 0, false);
-
+ if (pos_values == null)
// TODO: It is not neccessary to call whole Resolve (ApplyAttribute does it now) we need only ctor args.
// But because a lot of attribute class code must be rewritten will be better to wait...
Resolve (ec);
- }
// Some error occurred
if (pos_values == null)
/// before ApplyAttribute. We need to resolve the arguments.
/// This situation occurs when class deps is differs from Emit order.
/// </summary>
- public bool GetClsCompliantAttributeValue (DeclSpace ds)
+ public bool GetClsCompliantAttributeValue (EmitContext ec)
{
- if (pos_values == null) {
- EmitContext ec = new EmitContext (ds, ds, Location, null, null, 0, false);
-
+ if (pos_values == null)
// TODO: It is not neccessary to call whole Resolve (ApplyAttribute does it now) we need only ctor args.
// But because a lot of attribute class code must be rewritten will be better to wait...
Resolve (ec);
- }
// Some error occurred
if (pos_values [0] == null)
// in effect where the attribute was used. Since code elsewhere cannot assume
// that the NamespaceEntry is right, just overwrite it.
//
- // FIXME: Check every place the NamespaceEntry of RootContext.Tree.Types is used
- // to ensure the right one is used.
+ // Precondition: RootContext.Tree.Types == null || RootContext.Tree.Types == ns.
+ // The second case happens when we are recursively invoked from inside Emit.
+
+ NamespaceEntry old = null;
+ if (ec.DeclSpace == RootContext.Tree.Types) {
+ old = ec.DeclSpace.NamespaceEntry;
+ ec.DeclSpace.NamespaceEntry = ns;
+ if (old != null && old != ns)
+ throw new InternalErrorException (Location + " non-null NamespaceEntry " + old);
+ }
+
+ Type retval = base.CheckAttributeType (ec);
+
if (ec.DeclSpace == RootContext.Tree.Types)
+ ec.DeclSpace.NamespaceEntry = old;
+
+ return retval;
+ }
+
+ public override CustomAttributeBuilder Resolve (EmitContext ec)
+ {
+ if (ec.DeclSpace == RootContext.Tree.Types) {
+ NamespaceEntry old = ec.DeclSpace.NamespaceEntry;
ec.DeclSpace.NamespaceEntry = ns;
+ if (old != null)
+ throw new InternalErrorException (Location + " non-null NamespaceEntry " + old);
+ }
+
+ CustomAttributeBuilder retval = base.Resolve (ec);
+
+ if (ec.DeclSpace == RootContext.Tree.Types)
+ ec.DeclSpace.NamespaceEntry = null;
- return base.CheckAttributeType (ec);
+ return retval;
}
}