Add boxed attribute arguments extraction
authorMarek Safar <marek.safar@gmail.com>
Thu, 26 Jul 2012 11:47:09 +0000 (12:47 +0100)
committerMarek Safar <marek.safar@gmail.com>
Thu, 26 Jul 2012 11:47:09 +0000 (12:47 +0100)
mcs/tools/corcompare/mono-api-info.cs
mcs/tools/corcompare/mono-api-info.csproj

index 4ace2b363f34286047c3d09a29faa8725a72b53e..72c6da574e7a8908a37c9545651bc81909b3593d 100644 (file)
@@ -57,8 +57,9 @@ namespace CorCompare
                                                        TypeHelper.Resolver.AddSearchDirectory (Path.Combine (windir, @"Microsoft.NET\Framework\v4.0.30319"));
                                                        TypeHelper.Resolver.AddSearchDirectory (Path.Combine (windir, @"Microsoft.NET\Framework\v4.0.30319\WPF"));
                                                }
+                                       } else {
+                                               TypeHelper.Resolver.AddSearchDirectory (Path.GetDirectoryName (arg));
                                        }
-
                                }
                        }
 
@@ -1047,6 +1048,7 @@ namespace CorCompare
                                                AddAttribute (n, "value", "null");
                                                continue;
                                        }
+                                       
                                        string value = o.ToString ();
                                        if (attName.EndsWith ("GuidAttribute"))
                                                value = value.ToUpper ();
@@ -1076,8 +1078,12 @@ namespace CorCompare
                {
                        foreach (var named_argument in attribute.Properties) {
                                var name = named_argument.Name;
+                               var arg = named_argument.Argument;
+
+                               if (arg.Value is CustomAttributeArgument)
+                                       arg = (CustomAttributeArgument) arg.Value;
 
-                               mapping.Add (name, GetArgumentValue (named_argument.Argument.Type, named_argument.Argument.Value));
+                               mapping.Add (name, GetArgumentValue (arg.Type, arg.Value));
                        }
                }
 
@@ -1153,6 +1159,29 @@ namespace CorCompare
                        if (!constructor.HasBody)
                                return;
 
+                       // Custom handling for attributes with arguments which cannot be easily extracted
+                       var ca = attribute.ConstructorArguments;
+                       switch (constructor.DeclaringType.FullName) {
+                       case "System.Runtime.CompilerServices.DecimalConstantAttribute":
+                               var dca = constructor.Parameters[2].ParameterType == constructor.Module.TypeSystem.Int32 ?
+                                       new DecimalConstantAttribute ((byte) ca[0].Value, (byte) ca[1].Value, (int) ca[2].Value, (int) ca[3].Value, (int) ca[4].Value) :
+                                       new DecimalConstantAttribute ((byte) ca[0].Value, (byte) ca[1].Value, (uint) ca[2].Value, (uint) ca[3].Value, (uint) ca[4].Value);
+
+                               mapping.Add ("Value", dca.Value);
+                               return;
+                       case "System.ComponentModel.BindableAttribute":
+                               if (ca.Count != 1)
+                                       break;
+
+                               if (constructor.Parameters[0].ParameterType == constructor.Module.TypeSystem.Boolean) {
+                                       mapping.Add ("Bindable", ca[0].Value);
+                               } else {
+                                       throw new NotImplementedException ();
+                               }
+
+                               return;
+                       }
+
                        var field_mapping = CreateArgumentFieldMapping (constructor);
                        var property_mapping = CreatePropertyFieldMapping ((TypeDefinition) constructor.DeclaringType);
 
@@ -1161,7 +1190,10 @@ namespace CorCompare
                                if (!field_mapping.TryGetValue (pair.Value, out argument))
                                        continue;
 
-                               var ca_arg = attribute.ConstructorArguments [argument];
+                               var ca_arg = ca [argument];
+                               if (ca_arg.Value is CustomAttributeArgument)
+                                       ca_arg = (CustomAttributeArgument) ca_arg.Value;
+
                                mapping.Add (pair.Key.Name, GetArgumentValue (ca_arg.Type, ca_arg.Value));
                        }
                }
index 87baeb22cf68a0ed3089c8b427f0c9a1a3d5d1d1..1596015470e1372724a2fc19575f28fdab1ee966 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>\r
-<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
   <PropertyGroup>\r
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>\r
     <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>\r
@@ -9,8 +9,29 @@
     <OutputType>Exe</OutputType>\r
     <RootNamespace>mono_api_info</RootNamespace>\r
     <AssemblyName>mono-api-info</AssemblyName>\r
-    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>\r
+    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>\r
     <FileAlignment>512</FileAlignment>\r
+    <FileUpgradeFlags>\r
+    </FileUpgradeFlags>\r
+    <UpgradeBackupLocation>\r
+    </UpgradeBackupLocation>\r
+    <OldToolsVersion>3.5</OldToolsVersion>\r
+    <PublishUrl>publish\</PublishUrl>\r
+    <Install>true</Install>\r
+    <InstallFrom>Disk</InstallFrom>\r
+    <UpdateEnabled>false</UpdateEnabled>\r
+    <UpdateMode>Foreground</UpdateMode>\r
+    <UpdateInterval>7</UpdateInterval>\r
+    <UpdateIntervalUnits>Days</UpdateIntervalUnits>\r
+    <UpdatePeriodically>false</UpdatePeriodically>\r
+    <UpdateRequired>false</UpdateRequired>\r
+    <MapFileExtensions>true</MapFileExtensions>\r
+    <ApplicationRevision>0</ApplicationRevision>\r
+    <ApplicationVersion>1.0.0.%2a</ApplicationVersion>\r
+    <IsWebBootstrapper>false</IsWebBootstrapper>\r
+    <UseApplicationTrust>false</UseApplicationTrust>\r
+    <BootstrapperEnabled>true</BootstrapperEnabled>\r
+    <TargetFrameworkProfile />\r
   </PropertyGroup>\r
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">\r
     <DebugSymbols>true</DebugSymbols>\r
     <Compile Include="WellFormedXmlWriter.cs" />\r
   </ItemGroup>\r
   <ItemGroup>\r
-    <ProjectReference Include="..\..\class\Mono.Cecil\Mono.Cecil.csproj">\r
-      <Project>{D8F63DFF-5230-43E4-9AB2-DA6E721A1FAE}</Project>\r
-      <Name>Mono.Cecil-2008</Name>\r
+    <BootstrapperPackage Include="Microsoft.Net.Client.3.5">\r
+      <Visible>False</Visible>\r
+      <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>\r
+      <Install>false</Install>\r
+    </BootstrapperPackage>\r
+    <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">\r
+      <Visible>False</Visible>\r
+      <ProductName>.NET Framework 3.5 SP1</ProductName>\r
+      <Install>true</Install>\r
+    </BootstrapperPackage>\r
+  </ItemGroup>\r
+  <ItemGroup>\r
+    <ProjectReference Include="..\..\..\external\cecil\Mono.Cecil.csproj">\r
+      <Project>{d68133bd-1e63-496e-9ede-4fbdbf77b486}</Project>\r
+      <Name>Mono.Cecil</Name>\r
     </ProjectReference>\r
   </ItemGroup>\r
+  <ItemGroup>\r
+    <None Include="app.config" />\r
+  </ItemGroup>\r
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />\r
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. \r
        Other similar extension points exist, see Microsoft.Common.targets.\r