-
- public class ModuleClass : CommonAssemblyModulClass {
- // TODO: make it private and move all builder based methods here
- public ModuleBuilder Builder;
- bool m_module_is_unsafe;
-
- public CharSet DefaultCharSet = CharSet.Ansi;
- public TypeAttributes DefaultCharSetType = TypeAttributes.AnsiClass;
-
- static string[] attribute_targets = new string [] { "module" };
-
- public ModuleClass (bool is_unsafe)
- {
- m_module_is_unsafe = is_unsafe;
- }
-
- public override AttributeTargets AttributeTargets {
- get {
- return AttributeTargets.Module;
- }
- }
-
- public override bool IsClsComplianceRequired ()
- {
- return CodeGen.Assembly.IsClsCompliant;
- }
-
- public override void Emit (TypeContainer tc)
- {
- base.Emit (tc);
-
- if (!m_module_is_unsafe)
- return;
-
- if (TypeManager.unverifiable_code_ctor == null) {
- Console.WriteLine ("Internal error ! Cannot set unverifiable code attribute.");
- return;
- }
-
- Builder.SetCustomAttribute (new CustomAttributeBuilder (TypeManager.unverifiable_code_ctor, new object [0]));
- }
-
- public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder customBuilder)
- {
- if (a.Type == TypeManager.cls_compliant_attribute_type) {
- if (CodeGen.Assembly.ClsCompliantAttribute == null) {
- Report.Warning (3012, 1, a.Location, "You must specify the CLSCompliant attribute on the assembly, not the module, to enable CLS compliance checking");
- }
- else if (CodeGen.Assembly.IsClsCompliant != a.GetBoolean ()) {
- Report.SymbolRelatedToPreviousError (CodeGen.Assembly.ClsCompliantAttribute.Location, CodeGen.Assembly.ClsCompliantAttribute.GetSignatureForError ());
- Report.Error (3017, a.Location, "You cannot specify the CLSCompliant attribute on a module that differs from the CLSCompliant attribute on the assembly");
- return;
- }
- }
-
- Builder.SetCustomAttribute (customBuilder);
- }
-
- /// <summary>
- /// It is called very early therefore can resolve only predefined attributes
- /// </summary>
- public void Resolve ()
- {
-#if GMCS_SOURCE
- if (OptAttributes == null)
- return;
-
- if (!OptAttributes.CheckTargets())
- return;
-
- Attribute a = ResolveAttribute (TypeManager.default_charset_type);
- if (a != null) {
- 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 'System.Runtime.InteropServices.DefaultCharSetAttribute' is not valid");
- break;
- }
- }
-#endif
- }
-
- public override string[] ValidAttributeTargets {
- get {
- return attribute_targets;
- }
- }
- }