[Mono-dev] [PATCH] Warning and errors for InternalsVisibleAttr
Marek Safar
marek.safar at seznam.cz
Fri Oct 14 04:08:10 EDT 2005
Hello,
>The attached patch checks the validity of InternalsVisibleToAttribute,
>and reports and warnings depending on the contents.
>
>May I commit?
>
>
- no test for CS1700.
- please use syntax `blabla' for error/warning arguments.
+ if (a.Type == TypeManager.internals_visible_attr_type)
+ if (!CheckInternalsVisibleAttribute (a))
+ return;
+
Please use, &&.
But I am not sure whether we should commit this to mcs and then
integrate or to gmcs only.
Any ideas ?
Marek
>Carlos.
>
>PD - Attached are some tests.
>
>
>------------------------------------------------------------------------
>
>Index: typemanager.cs
>===================================================================
>--- typemanager.cs (revisión: 51640)
>+++ typemanager.cs (copia de trabajo)
>@@ -107,6 +107,7 @@
> static internal Type compiler_generated_attr_type;
> static internal Type fixed_buffer_attr_type;
> static internal Type default_charset_type;
>+ static internal Type internals_visible_attr_type;
>
> //
> // An empty array of types
>@@ -1143,6 +1144,7 @@
> compiler_generated_attr_type = CoreLookupType ("System.Runtime.CompilerServices", "CompilerGeneratedAttribute");
> fixed_buffer_attr_type = CoreLookupType ("System.Runtime.CompilerServices", "FixedBufferAttribute");
> default_charset_type = CoreLookupType ("System.Runtime.InteropServices", "DefaultCharSetAttribute");
>+ internals_visible_attr_type = CoreLookupType ("System.Runtime.CompilerServices", "InternalsVisibleToAttribute");
> //
> // When compiling corlib, store the "real" types here.
> //
>Index: codegen.cs
>===================================================================
>--- codegen.cs (revisión: 51690)
>+++ codegen.cs (copia de trabajo)
>@@ -144,6 +144,10 @@
> return false;
> }
>
>+ // Get the complete AssemblyName from the builder
>+ // (We need to get the public key and token)
>+ Assembly.Name = Assembly.Builder.GetName ();
>+
> //
> // Pass a path-less name to DefineDynamicModule. Wonder how
> // this copes with output in different directories then.
>@@ -1006,6 +1010,7 @@
> public class AssemblyClass: CommonAssemblyModulClass {
> // TODO: make it private and move all builder based methods here
> public AssemblyBuilder Builder;
>+ public AssemblyName Name;
>
> bool is_cls_compliant;
> public Attribute ClsCompliantAttribute;
>@@ -1196,6 +1201,35 @@
> Report.Error (1548, "Error during assembly signing. " + text);
> }
>
>+ bool CheckInternalsVisibleAttribute (Attribute a)
>+ {
>+ string assembly_name = a.GetString ();
>+ if (assembly_name.Length == 0)
>+ return false;
>+
>+ AssemblyName aname = null;
>+ try {
>+ aname = new AssemblyName (assembly_name);
>+ } catch (FileLoadException) {
>+ } catch (ArgumentException) {
>+ }
>+
>+ // Bad assembly name format
>+ if (aname == null)
>+ Report.Warning (1700, 3, a.Location, "Assembly reference '" + assembly_name + "' is invalid and cannot be resolved");
>+ // Report error if we have defined Version or Culture
>+ else if (aname.Version != null || aname.CultureInfo != null)
>+ throw new Exception ("Friend assembly '" + a.GetString () +
>+ "' is invalid. InternalsVisibleTo cannot have version or culture specified.");
>+ else if (aname.GetPublicKeyToken () == null && Name.GetPublicKeyToken () != null) {
>+ Report.Error (1726, a.Location, "Friend assembly reference '" + aname.Name + "' is invalid." +
>+ " Strong named assemblies must specify a public key token in their InternalsVisibleTo declarations");
>+ return false;
>+ }
>+
>+ return true;
>+ }
>+
> public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder customBuilder)
> {
> if (a.Type.IsSubclassOf (TypeManager.security_attr_type) && a.CheckSecurityActionValidity (true)) {
>@@ -1217,6 +1251,10 @@
> }
> }
>
>+ if (a.Type == TypeManager.internals_visible_attr_type)
>+ if (!CheckInternalsVisibleAttribute (a))
>+ return;
>+
> Builder.SetCustomAttribute (customBuilder);
> }
>
>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Mono-devel-list mailing list
>Mono-devel-list at lists.ximian.com
>http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
>
More information about the Mono-devel-list
mailing list