2 // codegen.cs: The code generator
5 // Miguel de Icaza (miguel@ximian.com)
7 // (C) 2001 Ximian, Inc.
12 using System.Collections;
13 using System.Reflection;
14 using System.Reflection.Emit;
15 using System.Runtime.InteropServices;
16 using System.Security.Cryptography;
18 using Mono.Security.Cryptography;
20 namespace Mono.CSharp {
23 /// Code generator class.
25 public class CodeGen {
26 static AppDomain current_domain;
27 static public SymbolWriter SymbolWriter;
29 public static AssemblyClass Assembly;
30 public static ModuleClass Module;
34 Assembly = new AssemblyClass ();
35 Module = new ModuleClass (RootContext.Unsafe);
38 public static string Basename (string name)
40 int pos = name.LastIndexOf ('/');
43 return name.Substring (pos + 1);
45 pos = name.LastIndexOf ('\\');
47 return name.Substring (pos + 1);
52 public static string Dirname (string name)
54 int pos = name.LastIndexOf ('/');
57 return name.Substring (0, pos);
59 pos = name.LastIndexOf ('\\');
61 return name.Substring (0, pos);
66 static string TrimExt (string name)
68 int pos = name.LastIndexOf ('.');
70 return name.Substring (0, pos);
73 static public string FileName;
76 // Initializes the symbol writer
78 static void InitializeSymbolWriter (string filename)
80 SymbolWriter = SymbolWriter.GetSymbolWriter (Module.Builder, filename);
83 // If we got an ISymbolWriter instance, initialize it.
85 if (SymbolWriter == null) {
87 -18, "Could not find the symbol writer assembly (Mono.CSharp.Debugger.dll). This is normally an installation problem. Please make sure to compile and install the mcs/class/Mono.CSharp.Debugger directory.");
93 // Initializes the code generator variables
95 static public void Init (string name, string output, bool want_debugging_support)
98 AssemblyName an = Assembly.GetAssemblyName (name, output);
100 if (an.KeyPair != null) {
101 // If we are going to strong name our assembly make
102 // sure all its refs are strong named
103 foreach (Assembly a in TypeManager.GetAssemblies ()) {
104 AssemblyName ref_name = a.GetName ();
105 byte [] b = ref_name.GetPublicKeyToken ();
106 if (b == null || b.Length == 0) {
107 Report.Warning (1577, "Assembly generation failed " +
108 "-- Referenced assembly '" +
110 "' does not have a strong name.");
111 //Environment.Exit (1);
116 current_domain = AppDomain.CurrentDomain;
119 Assembly.Builder = current_domain.DefineDynamicAssembly (an,
120 AssemblyBuilderAccess.Save, Dirname (name));
122 catch (ArgumentException) {
123 // specified key may not be exportable outside it's container
124 if (RootContext.StrongNameKeyContainer != null) {
125 Report.Error (1548, "Could not access the key inside the container `" +
126 RootContext.StrongNameKeyContainer + "'.");
127 Environment.Exit (1);
131 catch (CryptographicException) {
132 if ((RootContext.StrongNameKeyContainer != null) || (RootContext.StrongNameKeyFile != null)) {
133 Report.Error (1548, "Could not use the specified key to strongname the assembly.");
134 Environment.Exit (1);
140 // Pass a path-less name to DefineDynamicModule. Wonder how
141 // this copes with output in different directories then.
142 // FIXME: figure out how this copes with --output /tmp/blah
144 // If the third argument is true, the ModuleBuilder will dynamically
145 // load the default symbol writer.
147 Module.Builder = Assembly.Builder.DefineDynamicModule (
148 Basename (name), Basename (output), false);
150 if (want_debugging_support)
151 InitializeSymbolWriter (output);
154 static public void Save (string name)
157 Assembly.Builder.Save (Basename (name));
159 catch (COMException) {
160 if ((RootContext.StrongNameKeyFile == null) || (!RootContext.StrongNameDelaySign))
163 // FIXME: it seems Microsoft AssemblyBuilder doesn't like to delay sign assemblies
164 Report.Error (1548, "Couldn't delay-sign the assembly with the '" +
165 RootContext.StrongNameKeyFile +
166 "', Use MCS with the Mono runtime or CSC to compile this assembly.");
168 catch (System.IO.IOException io) {
169 Report.Error (16, "Could not write to file `"+name+"', cause: " + io.Message);
172 if (SymbolWriter != null)
173 SymbolWriter.WriteSymbolFile ();
178 // Provides "local" store across code that can yield: locals
179 // or fields, notice that this should not be used by anonymous
180 // methods to create local storage, those only require
183 public class VariableStorage {
190 public VariableStorage (EmitContext ec, Type t)
194 fb = ec.CurrentIterator.MapVariable ("s_", count.ToString (), t);
196 local = ec.ig.DeclareLocal (t);
200 public void EmitThis ()
203 ig.Emit (OpCodes.Ldarg_0);
206 public void EmitStore ()
209 ig.Emit (OpCodes.Stloc, local);
211 ig.Emit (OpCodes.Stfld, fb);
214 public void EmitLoad ()
217 ig.Emit (OpCodes.Ldloc, local);
219 ig.Emit (OpCodes.Ldfld, fb);
222 public void EmitCall (MethodInfo mi)
224 // FIXME : we should handle a call like tostring
225 // here, where boxing is needed. However, we will
226 // never encounter that with the current usage.
228 bool value_type_call;
231 value_type_call = local.LocalType.IsValueType;
234 ig.Emit (OpCodes.Ldloca, local);
236 ig.Emit (OpCodes.Ldloc, local);
238 value_type_call = fb.FieldType.IsValueType;
241 ig.Emit (OpCodes.Ldflda, fb);
243 ig.Emit (OpCodes.Ldfld, fb);
246 ig.Emit (value_type_call ? OpCodes.Call : OpCodes.Callvirt, mi);
251 /// An Emit Context is created for each body of code (from methods,
252 /// properties bodies, indexer bodies or constructor bodies)
254 public class EmitContext {
255 public DeclSpace DeclSpace;
256 public DeclSpace TypeContainer;
257 public ILGenerator ig;
260 /// This variable tracks the `checked' state of the compilation,
261 /// it controls whether we should generate code that does overflow
262 /// checking, or if we generate code that ignores overflows.
264 /// The default setting comes from the command line option to generate
265 /// checked or unchecked code plus any source code changes using the
266 /// checked/unchecked statements or expressions. Contrast this with
267 /// the ConstantCheckState flag.
270 public bool CheckState;
273 /// The constant check state is always set to `true' and cant be changed
274 /// from the command line. The source code can change this setting with
275 /// the `checked' and `unchecked' statements and expressions.
277 public bool ConstantCheckState;
280 /// Whether we are emitting code inside a static or instance method
282 public bool IsStatic;
285 /// Whether we are emitting a field initializer
287 public bool IsFieldInitializer;
290 /// The value that is allowed to be returned or NULL if there is no
293 public Type ReturnType;
296 /// Points to the Type (extracted from the TypeContainer) that
297 /// declares this body of code
299 public Type ContainerType;
302 /// Whether this is generating code for a constructor
304 public bool IsConstructor;
307 /// Whether we're control flow analysis enabled
309 public bool DoFlowAnalysis;
312 /// Keeps track of the Type to LocalBuilder temporary storage created
313 /// to store structures (used to compute the address of the structure
314 /// value on structure method invocations)
316 public Hashtable temporary_storage;
318 public Block CurrentBlock;
320 public int CurrentFile;
323 /// The location where we store the return value.
325 LocalBuilder return_value;
328 /// The location where return has to jump to return the
331 public Label ReturnLabel;
334 /// If we already defined the ReturnLabel
336 public bool HasReturnLabel;
339 /// Whether we are inside an iterator block.
341 public bool InIterator;
343 public bool IsLastStatement;
346 /// Whether remapping of locals, parameters and fields is turned on.
347 /// Used by iterators and anonymous methods.
349 public bool RemapToProxy;
352 /// Whether we are inside an unsafe block
354 public bool InUnsafe;
357 /// Whether we are in a `fixed' initialization
359 public bool InFixedInitializer;
362 /// Whether we are inside an anonymous method.
364 public bool InAnonymousMethod;
367 /// Location for this EmitContext
372 /// Used to flag that it is ok to define types recursively, as the
373 /// expressions are being evaluated as part of the type lookup
374 /// during the type resolution process
376 public bool ResolvingTypeTree;
379 /// Inside an enum definition, we do not resolve enumeration values
380 /// to their enumerations, but rather to the underlying type/value
381 /// This is so EnumVal + EnumValB can be evaluated.
383 /// There is no "E operator + (E x, E y)", so during an enum evaluation
384 /// we relax the rules
386 public bool InEnumContext;
388 public Iterator CurrentIterator;
390 FlowBranching current_flow_branching;
392 public EmitContext (DeclSpace parent, DeclSpace ds, Location l, ILGenerator ig,
393 Type return_type, int code_flags, bool is_constructor)
397 TypeContainer = parent;
399 CheckState = RootContext.Checked;
400 ConstantCheckState = true;
402 IsStatic = (code_flags & Modifiers.STATIC) != 0;
403 InIterator = (code_flags & Modifiers.METHOD_YIELDS) != 0;
404 RemapToProxy = InIterator;
405 ReturnType = return_type;
406 IsConstructor = is_constructor;
411 // Can only be null for the ResolveType contexts.
412 ContainerType = parent.TypeBuilder;
413 if (parent.UnsafeContext)
416 InUnsafe = (code_flags & Modifiers.UNSAFE) != 0;
420 if (ReturnType == TypeManager.void_type)
424 public EmitContext (TypeContainer tc, Location l, ILGenerator ig,
425 Type return_type, int code_flags, bool is_constructor)
426 : this (tc, tc, l, ig, return_type, code_flags, is_constructor)
430 public EmitContext (TypeContainer tc, Location l, ILGenerator ig,
431 Type return_type, int code_flags)
432 : this (tc, tc, l, ig, return_type, code_flags, false)
436 public FlowBranching CurrentBranching {
438 return current_flow_branching;
443 // Starts a new code branching. This inherits the state of all local
444 // variables and parameters from the current branching.
446 public FlowBranching StartFlowBranching (FlowBranching.BranchingType type, Location loc)
448 current_flow_branching = FlowBranching.CreateBranching (CurrentBranching, type, null, loc);
449 return current_flow_branching;
453 // Starts a new code branching for block `block'.
455 public FlowBranching StartFlowBranching (Block block)
457 FlowBranching.BranchingType type;
459 if (CurrentBranching.Type == FlowBranching.BranchingType.Switch)
460 type = FlowBranching.BranchingType.SwitchSection;
462 type = FlowBranching.BranchingType.Block;
464 current_flow_branching = FlowBranching.CreateBranching (CurrentBranching, type, block, block.StartLocation);
465 return current_flow_branching;
468 public FlowBranchingException StartFlowBranching (ExceptionStatement stmt)
470 FlowBranchingException branching = new FlowBranchingException (
471 CurrentBranching, stmt);
472 current_flow_branching = branching;
477 // Ends a code branching. Merges the state of locals and parameters
478 // from all the children of the ending branching.
480 public FlowBranching.UsageVector DoEndFlowBranching ()
482 FlowBranching old = current_flow_branching;
483 current_flow_branching = current_flow_branching.Parent;
485 return current_flow_branching.MergeChild (old);
489 // Ends a code branching. Merges the state of locals and parameters
490 // from all the children of the ending branching.
492 public FlowBranching.Reachability EndFlowBranching ()
494 FlowBranching.UsageVector vector = DoEndFlowBranching ();
496 return vector.Reachability;
500 // Kills the current code branching. This throws away any changed state
501 // information and should only be used in case of an error.
503 public void KillFlowBranching ()
505 current_flow_branching = current_flow_branching.Parent;
508 public void EmitTopBlock (Block block, InternalParameters ip, Location loc)
510 bool unreachable = false;
512 if (!Location.IsNull (loc))
513 CurrentFile = loc.File;
517 int errors = Report.Errors;
519 block.EmitMeta (this, ip);
521 if (Report.Errors == errors){
522 bool old_do_flow_analysis = DoFlowAnalysis;
523 DoFlowAnalysis = true;
525 current_flow_branching = FlowBranching.CreateBranching (
526 null, FlowBranching.BranchingType.Block, block, loc);
528 if (!block.Resolve (this)) {
529 current_flow_branching = null;
530 DoFlowAnalysis = old_do_flow_analysis;
534 FlowBranching.Reachability reachability = current_flow_branching.MergeTopBlock ();
535 current_flow_branching = null;
537 DoFlowAnalysis = old_do_flow_analysis;
541 if (reachability.AlwaysReturns ||
542 reachability.AlwaysThrows ||
543 reachability.IsUnreachable)
546 } catch (Exception e) {
547 Console.WriteLine ("Exception caught by the compiler while compiling:");
548 Console.WriteLine (" Block that caused the problem begin at: " + loc);
550 if (CurrentBlock != null){
551 Console.WriteLine (" Block being compiled: [{0},{1}]",
552 CurrentBlock.StartLocation, CurrentBlock.EndLocation);
554 Console.WriteLine (e.GetType ().FullName + ": " + e.Message);
555 Console.WriteLine (Report.FriendlyStackTrace (e));
557 Environment.Exit (1);
561 if (ReturnType != null && !unreachable){
563 Report.Error (161, loc, "Not all code paths return a value");
569 ig.MarkLabel (ReturnLabel);
570 if (return_value != null){
571 ig.Emit (OpCodes.Ldloc, return_value);
572 ig.Emit (OpCodes.Ret);
575 // If `HasReturnLabel' is set, then we already emitted a
576 // jump to the end of the method, so we must emit a `ret'
579 // Unfortunately, System.Reflection.Emit automatically emits
580 // a leave to the end of a finally block. This is a problem
581 // if no code is following the try/finally block since we may
582 // jump to a point after the end of the method.
583 // As a workaround, we're always creating a return label in
587 if ((block != null) && block.IsDestructor) {
588 // Nothing to do; S.R.E automatically emits a leave.
589 } else if (HasReturnLabel || (!unreachable && !InIterator)) {
590 if (ReturnType != null)
591 ig.Emit (OpCodes.Ldloc, TemporaryReturn ());
592 ig.Emit (OpCodes.Ret);
598 /// This is called immediately before emitting an IL opcode to tell the symbol
599 /// writer to which source line this opcode belongs.
601 public void Mark (Location loc, bool check_file)
603 if ((CodeGen.SymbolWriter == null) || Location.IsNull (loc))
606 if (check_file && (CurrentFile != loc.File))
609 CodeGen.SymbolWriter.MarkSequencePoint (ig, loc.Row, 0);
612 public void DefineLocalVariable (string name, LocalBuilder builder)
614 if (CodeGen.SymbolWriter == null)
617 CodeGen.SymbolWriter.DefineLocalVariable (name, builder);
621 /// Returns a temporary storage for a variable of type t as
622 /// a local variable in the current body.
624 public LocalBuilder GetTemporaryLocal (Type t)
626 LocalBuilder location = null;
628 if (temporary_storage != null){
629 object o = temporary_storage [t];
632 ArrayList al = (ArrayList) o;
634 for (int i = 0; i < al.Count; i++){
636 location = (LocalBuilder) al [i];
642 location = (LocalBuilder) o;
643 if (location != null)
648 return ig.DeclareLocal (t);
651 public void FreeTemporaryLocal (LocalBuilder b, Type t)
653 if (temporary_storage == null){
654 temporary_storage = new Hashtable ();
655 temporary_storage [t] = b;
658 object o = temporary_storage [t];
660 temporary_storage [t] = b;
664 ArrayList al = (ArrayList) o;
665 for (int i = 0; i < al.Count; i++){
674 ArrayList replacement = new ArrayList ();
676 temporary_storage.Remove (t);
677 temporary_storage [t] = replacement;
681 /// Current loop begin and end labels.
683 public Label LoopBegin, LoopEnd;
686 /// Default target in a switch statement. Only valid if
689 public Label DefaultTarget;
692 /// If this is non-null, points to the current switch statement
694 public Switch Switch;
697 /// ReturnValue creates on demand the LocalBuilder for the
698 /// return value from the function. By default this is not
699 /// used. This is only required when returns are found inside
700 /// Try or Catch statements.
702 public LocalBuilder TemporaryReturn ()
704 if (return_value == null){
705 return_value = ig.DeclareLocal (ReturnType);
706 ReturnLabel = ig.DefineLabel ();
707 HasReturnLabel = true;
713 public void NeedReturnLabel ()
715 if (!InIterator && !HasReturnLabel) {
716 ReturnLabel = ig.DefineLabel ();
717 HasReturnLabel = true;
722 // Creates a field `name' with the type `t' on the proxy class
724 public FieldBuilder MapVariable (string name, Type t)
727 return CurrentIterator.MapVariable ("v_", name, t);
729 throw new Exception ("MapVariable for an unknown state");
733 // Invoke this routine to remap a VariableInfo into the
734 // proper MemberAccess expression
736 public Expression RemapLocal (LocalInfo local_info)
738 FieldExpr fe = new FieldExpr (local_info.FieldBuilder, loc);
739 fe.InstanceExpression = new ProxyInstance ();
740 return fe.DoResolve (this);
743 public Expression RemapLocalLValue (LocalInfo local_info, Expression right_side)
745 FieldExpr fe = new FieldExpr (local_info.FieldBuilder, loc);
746 fe.InstanceExpression = new ProxyInstance ();
747 return fe.DoResolveLValue (this, right_side);
750 public Expression RemapParameter (int idx)
752 FieldExpr fe = new FieldExprNoAddress (CurrentIterator.parameter_fields [idx].FieldBuilder, loc);
753 fe.InstanceExpression = new ProxyInstance ();
754 return fe.DoResolve (this);
757 public Expression RemapParameterLValue (int idx, Expression right_side)
759 FieldExpr fe = new FieldExprNoAddress (CurrentIterator.parameter_fields [idx].FieldBuilder, loc);
760 fe.InstanceExpression = new ProxyInstance ();
761 return fe.DoResolveLValue (this, right_side);
765 // Emits the proper object to address fields on a remapped
766 // variable/parameter to field in anonymous-method/iterator proxy classes.
768 public void EmitThis ()
770 ig.Emit (OpCodes.Ldarg_0);
771 if (InIterator && !IsStatic){
772 FieldBuilder this_field = CurrentIterator.this_field.FieldBuilder;
773 if (TypeManager.IsValueType (this_field.FieldType))
774 ig.Emit (OpCodes.Ldflda, this_field);
776 ig.Emit (OpCodes.Ldfld, this_field);
780 public Expression GetThis (Location loc)
783 if (CurrentBlock != null)
784 my_this = new This (CurrentBlock, loc);
786 my_this = new This (loc);
788 if (!my_this.ResolveBase (this))
796 public abstract class CommonAssemblyModulClass: Attributable {
797 protected CommonAssemblyModulClass ():
802 public void AddAttributes (ArrayList attrs)
804 if (OptAttributes == null) {
805 OptAttributes = new Attributes (attrs);
808 OptAttributes.AddAttributes (attrs);
809 OptAttributes.CheckTargets (this);
812 public virtual void Emit (TypeContainer tc)
814 if (OptAttributes == null)
817 EmitContext ec = new EmitContext (tc, Mono.CSharp.Location.Null, null, null, 0, false);
818 OptAttributes.Emit (ec, this);
821 protected Attribute GetClsCompliantAttribute ()
823 if (OptAttributes == null)
826 EmitContext temp_ec = new EmitContext (new RootTypes (), Mono.CSharp.Location.Null, null, null, 0, false);
827 Attribute a = OptAttributes.Search (TypeManager.cls_compliant_attribute_type, temp_ec);
835 public class AssemblyClass: CommonAssemblyModulClass {
836 // TODO: make it private and move all builder based methods here
837 public AssemblyBuilder Builder;
838 bool is_cls_compliant;
840 static string[] attribute_targets = new string [] { "assembly" };
842 public AssemblyClass (): base ()
844 is_cls_compliant = false;
847 public bool IsClsCompliant {
849 return is_cls_compliant;
853 public override AttributeTargets AttributeTargets {
855 return AttributeTargets.Assembly;
859 public override bool IsClsCompliaceRequired(DeclSpace ds)
861 return is_cls_compliant;
864 public void ResolveClsCompliance ()
866 Attribute a = GetClsCompliantAttribute ();
870 is_cls_compliant = a.GetClsCompliantAttributeValue (null);
873 public AssemblyName GetAssemblyName (string name, string output)
875 if (OptAttributes != null) {
876 foreach (Attribute a in OptAttributes.Attrs) {
877 if (a.Target != AttributeTargets.Assembly)
879 // TODO: This code is buggy: comparing Attribute name without resolving it is wrong.
880 // However, this is invoked by CodeGen.Init, at which time none of the namespaces
883 case "AssemblyKeyFile":
884 case "AssemblyKeyFileAttribute":
885 case "System.Reflection.AssemblyKeyFileAttribute":
886 if (RootContext.StrongNameKeyFile != null) {
887 Report.SymbolRelatedToPreviousError (a.Location, a.Name);
888 Report.Warning (Message.CS1616_Option_overrides_options_given_in_source, "keyfile", "System.Reflection.AssemblyKeyFileAttribute");
891 string value = a.GetString ();
892 if (value != String.Empty)
893 RootContext.StrongNameKeyFile = value;
896 case "AssemblyKeyName":
897 case "AssemblyKeyNameAttribute":
898 case "System.Reflection.AssemblyKeyNameAttribute":
899 if (RootContext.StrongNameKeyContainer != null) {
900 Report.SymbolRelatedToPreviousError (a.Location, a.Name);
901 Report.Warning (Message.CS1616_Option_overrides_options_given_in_source, "keycontainer", "System.Reflection.AssemblyKeyNameAttribute");
904 string value = a.GetString ();
905 if (value != String.Empty)
906 RootContext.StrongNameKeyContainer = value;
909 case "AssemblyDelaySign":
910 case "AssemblyDelaySignAttribute":
911 case "System.Reflection.AssemblyDelaySignAttribute":
912 RootContext.StrongNameDelaySign = a.GetBoolean ();
918 AssemblyName an = new AssemblyName ();
919 an.Name = Path.GetFileNameWithoutExtension (name);
921 // note: delay doesn't apply when using a key container
922 if (RootContext.StrongNameKeyContainer != null) {
923 an.KeyPair = new StrongNameKeyPair (RootContext.StrongNameKeyContainer);
927 // strongname is optional
928 if (RootContext.StrongNameKeyFile == null)
931 string AssemblyDir = Path.GetDirectoryName (output);
933 // the StrongName key file may be relative to (a) the compiled
934 // file or (b) to the output assembly. See bugzilla #55320
935 // http://bugzilla.ximian.com/show_bug.cgi?id=55320
937 // (a) relative to the compiled file
938 string filename = Path.GetFullPath (RootContext.StrongNameKeyFile);
939 bool exist = File.Exists (filename);
940 if ((!exist) && (AssemblyDir != null) && (AssemblyDir != String.Empty)) {
941 // (b) relative to the outputed assembly
942 filename = Path.GetFullPath (Path.Combine (AssemblyDir, RootContext.StrongNameKeyFile));
943 exist = File.Exists (filename);
947 using (FileStream fs = new FileStream (filename, FileMode.Open, FileAccess.Read)) {
948 byte[] snkeypair = new byte [fs.Length];
949 fs.Read (snkeypair, 0, snkeypair.Length);
951 if (RootContext.StrongNameDelaySign) {
952 // delayed signing - DO NOT include private key
954 // check for possible ECMA key
955 if (snkeypair.Length == 16) {
956 // will be rejected if not "the" ECMA key
957 an.KeyPair = new StrongNameKeyPair (snkeypair);
960 // take it, with or without, a private key
961 RSA rsa = CryptoConvert.FromCapiKeyBlob (snkeypair);
962 // and make sure we only feed the public part to Sys.Ref
963 byte[] publickey = CryptoConvert.ToCapiPublicKeyBlob (rsa);
964 an.KeyPair = new StrongNameKeyPair (publickey);
968 Report.Error (1548, "Could not strongname the assembly. File `" +
969 RootContext.StrongNameKeyFile + "' incorrectly encoded.");
970 Environment.Exit (1);
974 // no delay so we make sure we have the private key
976 CryptoConvert.FromCapiPrivateKeyBlob (snkeypair);
977 an.KeyPair = new StrongNameKeyPair (snkeypair);
979 catch (CryptographicException) {
980 if (snkeypair.Length == 16) {
981 // error # is different for ECMA key
982 Report.Error (1606, "Could not strongname the assembly. " +
983 "ECMA key can only be used to delay-sign assemblies");
986 Report.Error (1548, "Could not strongname the assembly. File `" +
987 RootContext.StrongNameKeyFile +
988 "' doesn't have a private key.");
990 Environment.Exit (1);
996 Report.Error (1548, "Could not strongname the assembly. File `" +
997 RootContext.StrongNameKeyFile + "' not found.");
998 Environment.Exit (1);
1003 public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder customBuilder)
1005 Builder.SetCustomAttribute (customBuilder);
1008 public override string[] ValidAttributeTargets {
1010 return attribute_targets;
1015 public class ModuleClass: CommonAssemblyModulClass {
1016 // TODO: make it private and move all builder based methods here
1017 public ModuleBuilder Builder;
1018 bool m_module_is_unsafe;
1020 static string[] attribute_targets = new string [] { "module" };
1022 public ModuleClass (bool is_unsafe)
1024 m_module_is_unsafe = is_unsafe;
1027 public override AttributeTargets AttributeTargets {
1029 return AttributeTargets.Module;
1033 public override bool IsClsCompliaceRequired(DeclSpace ds)
1035 return CodeGen.Assembly.IsClsCompliant;
1038 public override void Emit (TypeContainer tc)
1042 if (!m_module_is_unsafe)
1045 if (TypeManager.unverifiable_code_ctor == null) {
1046 Console.WriteLine ("Internal error ! Cannot set unverifiable code attribute.");
1050 ApplyAttributeBuilder (null, new CustomAttributeBuilder (TypeManager.unverifiable_code_ctor, new object [0]));
1053 public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder customBuilder)
1055 if (a != null && a.Type == TypeManager.cls_compliant_attribute_type) {
1056 Report.Warning (Message.CS3012_You_must_specify_the_CLSCompliant_attribute_on_the_assembly_not_the_module_to_enable_CLS_compliance_checking, a.Location);
1060 Builder.SetCustomAttribute (customBuilder);
1063 public override string[] ValidAttributeTargets {
1065 return attribute_targets;