* tuner/Mono.Tuner/InjectSecurityAttributes.cs: Make an enum
authorAndrés G. Aragoneses <knocte@gmail.com>
Fri, 7 Aug 2009 20:05:52 +0000 (20:05 -0000)
committerAndrés G. Aragoneses <knocte@gmail.com>
Fri, 7 Aug 2009 20:05:52 +0000 (20:05 -0000)
protected.

* tuner/Mono.Tuner/MoonlightA11yProcessor.cs: Prevent Type*Exceptions
because of badly placed SC attrib on methods.

* tuner/Mono.Tuner/MoonlightA11yDescriptorGenerator.cs: Typo in
comment.

svn path=/trunk/mcs/; revision=139589

mcs/tools/tuner/ChangeLog
mcs/tools/tuner/Mono.Tuner/InjectSecurityAttributes.cs
mcs/tools/tuner/Mono.Tuner/MoonlightA11yDescriptorGenerator.cs
mcs/tools/tuner/Mono.Tuner/MoonlightA11yProcessor.cs

index 8b84f3cc6045d480283b27e57c40009bd2d1c841..feada9de0cb591338586918cfd71d0e9a83827c4 100644 (file)
@@ -1,3 +1,15 @@
+2009-08-07  Andrés G. Aragoneses  <aaragoneses@novell.com>
+
+       * Mono.Tuner/InjectSecurityAttributes.cs: Make an enum
+         protected.
+
+       * Mono.Tuner/MoonlightA11yProcessor.cs: Prevent
+         Type*Exceptions because of badly placed SC attrib on
+         methods.
+
+       * Mono.Tuner/MoonlightA11yDescriptorGenerator.cs: Typo in
+         comment.
+
 2009-07-02  Jb Evain  <jbevain@novell.com>
 
        * Makefile: fix cecil's location.
index 215d450a3412c2cb8a0013a450ecb1df486c4b68..0d4bac44e1e88b4103c2e87bf1592fe7c8b5ad95 100644 (file)
@@ -45,7 +45,7 @@ namespace Mono.Tuner {
                        Method,
                }
 
-               enum AttributeType {
+               protected enum AttributeType {
                        Critical,
                        SafeCritical,
                }
@@ -242,7 +242,7 @@ namespace Mono.Tuner {
                        }
                }
 
-               static bool HasSecurityAttribute (ICustomAttributeProvider provider, AttributeType type)
+               protected static bool HasSecurityAttribute (ICustomAttributeProvider provider, AttributeType type)
                {
                        if (!provider.HasCustomAttributes)
                                return false;
index c0f92a91d4b77371b0a7c58294bb8055bf60031d..e50125cc9320af18e3fb79990ec2ebcbf473a7fb 100644 (file)
@@ -112,7 +112,7 @@ namespace Mono.Tuner {
                        return @params;
                }
 
-               Hashtable /*Dictionary<TypeDefinition,List<IAnnotationProvider>>*/ ScanAssembly (AssemblyDefinition assembly)
+               Hashtable /*Dictionary<TypeDefinition,List<IAnnotationProvider>*/ ScanAssembly (AssemblyDefinition assembly)
                {
                        if (Annotations.GetAction (assembly) != AssemblyAction.Link)
                                return null;
index d01a9dc965a98f6870620b2847cfc420ccdb6a78..4904671a4f03ec043a0127951c0ed823c0cc4140 100644 (file)
@@ -87,10 +87,66 @@ namespace Mono.Tuner {
                                                AddCriticalAttribute (ctor);
 
                                if (type.HasMethods)
-                                       foreach (MethodDefinition method in type.Methods)
-                                               AddCriticalAttribute (method);
+                                       foreach (MethodDefinition method in type.Methods) {
+                                               MethodDefinition parent = GetOverridenMethod (type, method);
+                                               //to prevent Type*Exceptions because of having SC attribs in overriden methods of non-SC base methods
+                                               if (parent == null || HasSecurityAttribute (parent, AttributeType.Critical))
+                                                       AddCriticalAttribute (method);
+                               }
+                               
                        }
                }
-
+               
+//             bool HasSecurityAttribute (ICustomAttributeProvider provider)
+//             {
+//                     CustomAttributeCollection attributes = provider.CustomAttributes;
+//                     for (int i = 0; i < attributes.Count; i++) {
+//                             CustomAttribute attribute = attributes [i];
+//                             if (attribute.Constructor.DeclaringType.FullName == _critical)
+//                                     return true;
+//                     }
+//                     return false;
+//             }
+               
+               //note: will not return abstract methods
+               MethodDefinition GetOverridenMethod (TypeDefinition finalType, MethodDefinition final)
+               {
+                       Console.WriteLine ("__GetOverridenMethod " + finalType.FullName + ":" + final.ToString ());
+                       var baseType = finalType.BaseType;
+                       while (baseType != null && baseType.Resolve () != null) {
+                               
+                               foreach (MethodDefinition method in baseType.Resolve ().Methods) {
+                                       if (!method.IsVirtual || method.Name != final.Name)
+                                               continue;
+                                       
+                                       //TODO: should we discard them?
+                                       if (method.IsAbstract)
+                                               continue;
+                                       
+                                       if (HasSameSignature (method, final))
+                                               return method;
+                               }
+                               baseType = baseType.Resolve().BaseType;
+                       }
+                       return null;
+               }
+               
+               //FIXME: take in account generic params
+               bool HasSameSignature (MethodDefinition method1, MethodDefinition method2)
+               {
+                       if (method1.ReturnType.ReturnType.FullName != method2.ReturnType.ReturnType.FullName)
+                               return false;
+                       
+                       if (method1.Parameters.Count != method2.Parameters.Count)
+                               return false;
+                       
+                       for (int i = 0; i < method1.Parameters.Count; i++) {
+                               if (method1.Parameters [i].ParameterType.DeclaringType.FullName !=
+                                   method2.Parameters [i].ParameterType.DeclaringType.FullName)
+                                       return false;
+                       }
+                       
+                       return true;
+               }
        }
 }