return false;
}
- public CustomAttributeBuilder Resolve (EmitContext ec)
+ public virtual CustomAttributeBuilder Resolve (EmitContext ec)
{
if (resolve_error)
return null;
/// </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;
}
}