// Add [module: DefaultCharSet] to all DllImport import attributes
//
var module = context.Module;
- // HACK: Needed for broken ModuleContainer::ResolveGlobalAttributes
- if (module.PredefinedAttributes == null)
- return ctor;
-
if (Type == module.PredefinedAttributes.DllImport && module.HasDefaultCharSet) {
AddModuleCharSet (rc);
}
public readonly PredefinedAttribute UnverifiableCode;
// New in .NET 2.0
- //public readonly PredefinedAttribute DefaultCharset;
+ public readonly PredefinedAttribute DefaultCharset;
public readonly PredefinedAttribute TypeForwarder;
public readonly PredefinedAttribute FixedBuffer;
public readonly PredefinedAttribute CompilerGenerated;
OptionalParameter = new PredefinedAttribute (module, "System.Runtime.InteropServices", "OptionalAttribute");
UnverifiableCode = new PredefinedAttribute (module, "System.Security", "UnverifiableCodeAttribute");
- //DefaultCharset = new PredefinedAttribute (module, "System.Runtime.InteropServices", "DefaultCharSetAttribute");
+ DefaultCharset = new PredefinedAttribute (module, "System.Runtime.InteropServices", "DefaultCharSetAttribute");
TypeForwarder = new PredefinedAttribute (module, "System.Runtime.CompilerServices", "TypeForwardedToAttribute");
FixedBuffer = new PredefinedAttribute (module, "System.Runtime.CompilerServices", "FixedBufferAttribute");
CompilerGenerated = new PredefinedAttribute (module, "System.Runtime.CompilerServices", "CompilerGeneratedAttribute");
protected override TypeAttributes TypeAttr {
get {
- return ModifiersExtensions.TypeAttr (ModFlags, IsTopLevel) | base.TypeAttr;
+ return ModifiersExtensions.TypeAttr (ModFlags, IsTopLevel);
}
}
if ((ModFlags & Modifiers.COMPILER_GENERATED) != 0 && !Parent.IsCompilerGenerated)
Module.PredefinedAttributes.CompilerGenerated.EmitAttribute (TypeBuilder);
+#if STATIC
+ if ((TypeBuilder.Attributes & TypeAttributes.StringFormatMask) == 0 && Module.HasDefaultCharSet)
+ TypeBuilder.__SetAttributes (TypeBuilder.Attributes | Module.DefaultCharSetType);
+#endif
+
base.Emit ();
}
return false;
}
- protected virtual TypeAttributes TypeAttr {
- get { return Module.DefaultCharSetType; }
- }
+ protected abstract TypeAttributes TypeAttr { get; }
/// <remarks>
/// Should be overriten by the appropriate declaration space
// Create nested fixed buffer container
string name = String.Format ("<{0}>__FixedBuffer{1}", Name, GlobalCounter++);
- fixed_buffer_type = Parent.TypeBuilder.DefineNestedType (name, Parent.Module.DefaultCharSetType |
+ fixed_buffer_type = Parent.TypeBuilder.DefineNestedType (name,
TypeAttributes.NestedPublic | TypeAttributes.Sealed | TypeAttributes.BeforeFieldInit, TypeManager.value_type.GetMetaInfo ());
fixed_buffer_type.DefineField (FixedElementName, MemberType.GetMetaInfo (), FieldAttributes.Public);
EmitFieldSize (buffer_size);
+#if STATIC
+ if (Module.HasDefaultCharSet)
+ fixed_buffer_type.__SetAttributes (fixed_buffer_type.Attributes | Module.DefaultCharSetType);
+#endif
+
Module.PredefinedAttributes.UnsafeValueType.EmitAttribute (fixed_buffer_type);
Module.PredefinedAttributes.CompilerGenerated.EmitAttribute (fixed_buffer_type);
fixed_buffer_type.CreateType ();
if (field_size == null || field_charset == null)
return;
- var char_set = CharSet ?? Module.DefaultCharSet;
+ var char_set = CharSet ?? Module.DefaultCharSet ?? 0;
encoder = new AttributeEncoder (false);
encoder.Encode ((short)LayoutKind.Sequential);
}
}
+ protected override TypeAttributes TypeAttr {
+ get {
+ throw new NotSupportedException ();
+ }
+ }
+
public override void DefineType ()
{
throw new Exception ();
}
}
- public CharSet DefaultCharSet = CharSet.Ansi;
+ public CharSet? DefaultCharSet;
public TypeAttributes DefaultCharSetType = TypeAttributes.AnsiClass;
Dictionary<int, List<AnonymousTypeClass>> anonymous_types;
ModuleBuilder builder;
- bool has_default_charset;
bool has_extenstion_method;
PredefinedAttributes predefined_attributes;
public bool HasDefaultCharSet {
get {
- return has_default_charset;
+ return DefaultCharSet.HasValue;
}
}
return;
}
- if (a.Type == pa.CLSCompliant) {
+ if (a.Type == pa.DefaultCharset) {
+ switch (a.GetCharSetValue ()) {
+ case CharSet.Ansi:
+ case CharSet.None:
+ break;
+ case CharSet.Auto:
+ DefaultCharSet = CharSet.Auto;
+ DefaultCharSetType = TypeAttributes.AutoClass;
+ break;
+ case CharSet.Unicode:
+ DefaultCharSet = CharSet.Unicode;
+ DefaultCharSetType = TypeAttributes.UnicodeClass;
+ break;
+ default:
+ Report.Error (1724, a.Location, "Value specified for the argument to `{0}' is not valid",
+ a.GetSignatureForError ());
+ break;
+ }
+ } else if (a.Type == pa.CLSCompliant) {
Attribute cls = DeclaringAssembly.CLSCompliantAttribute;
if (cls == null) {
Report.Warning (3012, 1, a.Location,
// FIXME: Temporary hack for repl to reset
static_data = null;
- // TODO: It should be done much later when the types are resolved
- // but that require DefineType clean-up
- ResolveGlobalAttributes ();
-
foreach (TypeContainer tc in types)
tc.CreateType ();
base.RemoveMemberType (ds);
}
- /// <summary>
- /// It is called very early therefore can resolve only predefined attributes
- /// </summary>
- void ResolveGlobalAttributes ()
- {
- if (OptAttributes == null)
- return;
-
- if (!OptAttributes.CheckTargets ())
- return;
-
- // FIXME: Define is wrong as the type may not exist yet
- var DefaultCharSet_attr = new PredefinedAttribute (this, "System.Runtime.InteropServices", "DefaultCharSetAttribute");
- DefaultCharSet_attr.Define ();
- Attribute a = ResolveModuleAttribute (DefaultCharSet_attr);
- if (a != null) {
- has_default_charset = true;
- DefaultCharSet = a.GetCharSetValue ();
- switch (DefaultCharSet) {
- case CharSet.Ansi:
- case CharSet.None:
- break;
- case CharSet.Auto:
- DefaultCharSetType = TypeAttributes.AutoClass;
- break;
- case CharSet.Unicode:
- DefaultCharSetType = TypeAttributes.UnicodeClass;
- break;
- default:
- Report.Error (1724, a.Location, "Value specified for the argument to `{0}' is not valid",
- DefaultCharSet_attr.GetSignatureForError ());
- break;
- }
- }
- }
-
public Attribute ResolveAssemblyAttribute (PredefinedAttribute a_type)
{
Attribute a = OptAttributes.Search ("assembly", a_type);
return a;
}
- Attribute ResolveModuleAttribute (PredefinedAttribute a_type)
- {
- Attribute a = OptAttributes.Search ("module", a_type);
- if (a != null) {
- a.Resolve ();
- }
- return a;
- }
-
public void SetDeclaringAssembly (AssemblyDefinition assembly)
{
// TODO: This setter is quite ugly but I have not found a way around it yet