Exemplo n.º 1
0
 public ContractExtractor(ContractNodes contractNodes, AssemblyNode assembly, bool verbose)
 {
     this.visited_methods = new Dictionary <Method, Method> ();
     this.contract_nodes  = contractNodes;
     this.assembly        = assembly;
     this.verbose         = verbose;
 }
Exemplo n.º 2
0
        public void Save()
        {
            foreach (NDOTreeNode trn in nodeCollection)
            {
                DatabaseNode dn = trn as DatabaseNode;
                if (dn != null)
                {
                    this.databaseNode = dn;
                }
                AssemblyNode an = trn as AssemblyNode;
                if (an != null)
                {
                    this.assemblyNode = an;
                }
            }
            new MappingGenerator(fileName, databaseNode, assemblyNode).GenerateCode();
            XmlDocument doc = new XmlDocument();

            doc.Load(fileName);
            XmlNode refNode = doc.SelectSingleNode("NDOMapping");
            XmlNode comment = doc.CreateComment("NDO Class Generator file - this is not a valid mapping file!");

            doc.InsertBefore(comment, refNode);
            assemblyNode.Assembly.ToXml(doc);
            XmlElement node = (XmlElement)doc.SelectSingleNode("NDOMapping/AssemblyElement");

            node.SetAttribute("DbOwner", this.databaseNode.Database.OwnerName);
            doc.Save(fileName);
        }
Exemplo n.º 3
0
        private static AssemblyNode GetRuntimeAssembly()
        {
            AssemblyNode result = RuntimeAssemblyLocation.ParsedAssembly;

            if (result != null)
            {
                return(result);
            }
            if (RuntimeAssemblyLocation.Location == null)
            {
                //This happens when there was no call to SetToXXX. Use the location of the assembly linked into the compiler.
                RuntimeAssemblyLocation.Location = typeof(dummy).Module.Assembly.Location;
                result = AssemblyNode.GetAssembly((RuntimeAssemblyLocation.Location));
            }
            else
            {
                result = AssemblyNode.GetAssembly(RuntimeAssemblyLocation.Location);
                if (result == null)
                {
                    //This happens when the location was set by a call to SetToXXX, but the runtime assembly is not actually deployed
                    //in the directory containing the target platform assemblies. This is really an error, but as a convenience during
                    //development of the compiler, the assembly linked into the compiler is used instead.
                    RuntimeAssemblyLocation.Location = typeof(dummy).Module.Assembly.Location;
                    result = AssemblyNode.GetAssembly((RuntimeAssemblyLocation.Location));
                }
            }
            if (result == null)
            {
                result         = new AssemblyNode();
                result.Name    = "Microsoft.SpecSharp.Runtime";
                result.Version = Cci.TargetPlatform.TargetVersion;
            }
            Cci.TargetPlatform.AssemblyReferenceFor[Identifier.For(result.Name).UniqueIdKey] = new AssemblyReference(result);
            return(result);
        }
        public void Test()
        {
             var gen = new XmlResultsGenerator(null,null,null, null, null);

            var muSession = new MutationTestingSession();
            
            var mutar = new MutationTarget(new MutationVariant());


            var ass = new AssemblyNode("Assembly");
            muSession.MutantsGrouped.Add(ass);
            var nodeNamespace = new TypeNamespaceNode(ass, "Namespace");
            ass.Children.Add(nodeNamespace);
            var nodeType = new TypeNode(nodeNamespace, "Type");
            nodeNamespace.Children.Add(nodeType);
            var nodeMethod = new MethodNode(nodeType, "Method", null, true);
            nodeType.Children.Add(nodeMethod);
            var nodeGroup = new MutantGroup("Gr1", nodeMethod);
            nodeMethod.Children.Add(nodeGroup);
            var nodeMutant = new Mutant("m1", nodeGroup, mutar);
            nodeGroup.Children.Add(nodeMutant);

            XDocument generateResults = gen.GenerateResults(muSession, false, false, ProgressCounter.Inactive(), CancellationToken.None).Result;

            Console.WriteLine(generateResults.ToString());
            //gen.
        }
Exemplo n.º 5
0
        private void mainTreeView_TreeNodePopulate(object sender, TreeViewEventArgs e)
        {
            TreeNode node = e.Node;
            object   obj  = e.Node.Tag;

            if (obj is AssemblyNode)
            {
                AssemblyNode asm = (AssemblyNode)obj;
                foreach (NamespaceNode space in asm.Namespaces)
                {
                    space.SortTypes();
                    TreeNode spaceNode = new TreeNode(space.Name);
                    spaceNode.ImageKey         = "namespace";
                    spaceNode.SelectedImageKey = spaceNode.ImageKey;
                    spaceNode.Tag = space;
                    spaceNode.Nodes.Add(String.Empty);
                    node.Nodes.Add(spaceNode);
                }
            }
            else if (obj is NamespaceNode)
            {
                NamespaceNode space = (NamespaceNode)obj;
                foreach (TypeNode type in space.Types)
                {
                    TreeNode typeNode = new TreeNode(type.Name);
                    typeNode.ImageKey         = GetImageKey(type);
                    typeNode.SelectedImageKey = typeNode.ImageKey;
                    typeNode.Tag = type;
                    node.Nodes.Add(typeNode);
                }
            }
        }
Exemplo n.º 6
0
        private void OnAssemblySelected(AssemblyNode assemblyNode, Action completeAction = null)
        {
            if (assemblyNode.Children.Count == 0)
            {
                Task loadingTask = assemblyNode.LoadItemsAsync(() => assemblyNode.IsExpanded = false);

                loadingTask.ContinueWith(t =>
                {
                    if (!t.IsCanceled && !t.IsFaulted)
                    {
                        if (completeAction != null)
                        {
                            completeAction();
                        }
                    }
                    else if (t.Exception.InnerExceptions.Count > 0)
                    {
                        // already shown an error window.
                        //this.ShowExceptionMessage(t.Exception.InnerExceptions);
                    }
                }, TaskScheduler.FromCurrentSynchronizationContext());
            }
            else
            {
                if (completeAction != null)
                {
                    completeAction();
                }
            }
        }
 private void CheckModule([NotNull] AssemblyNode module)
 {
     if (HasCheckOverloadAccepting(typeof(AssemblyNode)))
     {
         rule.Check(module);
     }
 }
Exemplo n.º 8
0
 public ClousotExtractor(ContractNodes contractNodes, AssemblyNode ultimateTargetAssembly,
                         AssemblyNode realAssembly, Action <System.CodeDom.Compiler.CompilerError> errorHandler)
     : base(contractNodes, ultimateTargetAssembly, realAssembly)
 {
     Contract.Requires(contractNodes != null);
     Contract.Requires(realAssembly != null);
 }
Exemplo n.º 9
0
        // Parsing logic

        public void LoadAssembly(string filePath)
        {
            //Console.WriteLine("loading {0}", filePath);
            //AssemblyNode assembly = AssemblyNode.GetAssembly(filePath);   // this causes mscorlib to be missing members
            //AssemblyNode assembly = AssemblyNode.GetAssembly(filePath, cache); // this causes compact framework non-classes to register as classes
            //AssemblyNode assembly = AssemblyNode.GetAssembly(filePath, cache, false, false, true, false); // this causes missing mscorlib members
            //AssemblyNode assembly = AssemblyNode.GetAssembly(filePath, cache, false, false, false, false); // this causes non-classes to register as classes
            //AssemblyNode assembly = AssemblyNode.GetAssembly(filePath, null, false, false, true, false); // this causes missing mscorlib members
            AssemblyNode assembly = AssemblyNode.GetAssembly(filePath, null, false, false, false, false); // this causes non-classes to register as classes

            if (assembly != null)
            {
                if (assembly.Name == "mscorlib")
                {
                    ResetMscorlib(assembly);
                }

                // Console.WriteLine("assembly = {0}", assembly.Name);
                resolver.Add(assembly);
                //assembly.AssemblyReferenceResolutionAfterProbingFailed += unresolvedModuleHandler;
                assemblies.Add(assembly);
                //Console.WriteLine("{0} has {1} types", assembly.Name, assembly.ExportedTypes.Count);
                //StoreTypes(assembly.Types);
            }
        }
Exemplo n.º 10
0
        public void WriteAssembly(AssemblyNode assemblyNode)
        {
            var controllers = assemblyNode.Controllers.OrderBy(x => x.Name).ToArray();

            foreach (var controllerNode in controllers)
            {
                WriteController(controllerNode);
            }

            WriteViews(assemblyNode);
            WriteEnums(assemblyNode);

            var output = new StringBuilder();

            foreach (var controllerNode in controllers)
            {
                output.AppendLine($"export * from \"./{StringHelpers.ToCamelCase(controllerNode.Name)}\";");
            }
            if (assemblyNode.Classes.Any(x => x.Value.Values != null))
            {
                output.AppendLine("export * from \"./enums\";");
            }
            output.AppendLine("export * from \"./views\";");

            OutputModules.Add("services", output.ToString());
        }
Exemplo n.º 11
0
        private void WriteViews(AssemblyNode assemblyNode)
        {
            StringBuilder body         = new StringBuilder();
            var           dependencies = new Dependencies
            {
                PrefixModules = PrefixModules.Enums
            };
            var any = false;

            foreach (var classNode in assemblyNode.Classes.Where(x => x.Value.Properties != null))
            {
                WriteTypeDefinition(classNode.Value, body, false, dependencies);
                any = true;
            }
            var result = new StringBuilder();

            if (dependencies.Enums)
            {
                result.AppendLine("import * as enums from \"./enums\";");
            }
            result.Append(body);
            if (any)
            {
                OutputModules.Add("views", result.ToString());
            }
        }
        public override void VisitAssemblyNode(AssemblyNode node)
        {
            if (node.DifferenceDecoration == DifferenceDecoration.NoDifferences)
            {
                return;
            }

            xmlWriter.WriteStartElement("Assembly");
            xmlWriter.WriteAttributeString("Name", node.Name);
            xmlWriter.WriteAttributeString("DiffType", node.DifferenceDecoration.ToString());

            foreach (var module in node.Modules)
            {
                module.Accept(this);
            }

            xmlWriter.WriteStartElement("Ressources");

            foreach (var resource in node.Resources)
            {
                resource.Accept(this);
            }

            xmlWriter.WriteEndElement();

            xmlWriter.WriteEndElement();
        }
 private void CheckTypes([NotNull] AssemblyNode module)
 {
     foreach (TypeNode type in module.Types)
     {
         CheckType(type);
     }
 }
Exemplo n.º 14
0
        private bool TryLoadContractNodes(ref AssemblyNode assembly)
        {
            ContractNodes nodes = null;

            foreach (Module module in assembly.Modules)
            {
                IAssemblyResolver assemblyResolver = module.Definition.AssemblyResolver;
                foreach (AssemblyNameReference reference in module.Definition.AssemblyReferences)
                {
                    AssemblyDefinition def = assemblyResolver.Resolve(reference);
                    nodes = ContractNodes.GetContractNodes(new AssemblyNode(def), (s) => { });
                    if (nodes != null)
                    {
                        break;
                    }
                }
            }

            if (nodes == null)
            {
                return(false);
            }

            var extractor = new ContractExtractor(nodes, assembly, true);

            assembly = (AssemblyNode)extractor.Visit(assembly);
            return(true);
        }
Exemplo n.º 15
0
        //=====================================================================

        /// <summary>
        /// This is overridden to resolve unknown assembly references
        /// </summary>
        /// <param name="reference">The reference to resolve</param>
        /// <param name="module">The module</param>
        /// <returns>The assembly node if resolved or null if not resolved</returns>
        public override AssemblyNode ResolveReference(
            AssemblyReference reference, System.Compiler.Module module)
        {
            AssemblyNode node = base.ResolveReference(reference, module);
            string       name;

            // Try the redirects if not found
            if (node == null)
            {
                name = reference.StrongName;

                foreach (BindingRedirectSettings brs in redirects)
                {
                    if (brs.IsRedirectFor(name) && cache.ContainsKey(brs.StrongName))
                    {
                        ConsoleApplication.WriteMessage(LogLevel.Info,
                                                        "Using redirect '{0}' in place of '{1}'",
                                                        brs.StrongName, name);

                        node = cache[brs.StrongName];
                        cache.Add(name, node);
                        break;
                    }
                }
            }

            return(node);
        }
Exemplo n.º 16
0
        public static void init( )
        {
            // if ( allNamespaces != null ) return;
            allNamespaces = new NamespaceList();

            nsCached = new Dictionary <string, TypeNodeList>();

            // Scan all assemblies referenced in parameters
            // and take all namespaces from them.
            // Put all these namespaces into the common list.
            System.Collections.Specialized.StringCollection assemblies = CONTEXT.options.ReferencedAssemblies;
            foreach (string assName in assemblies)
            {
                AssemblyNode assembly = AssemblyNode.GetAssembly(assName, true, false, true);
                if (assembly == null && !CONTEXT.AnalysisOnly)
                {
                    ERROR.UnresolvedReference(assName);
                    continue;
                }
                NamespaceList nss = assembly.GetNamespaceList();
                for (int i = 0, n = nss.Length; i < n; i++)
                {
                    allNamespaces.Add(nss[i]);
                }
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// This is used to load an assembly that will be parsed and documented
        /// </summary>
        /// <param name="filePath">The path of the documented assembly to load</param>
        public void LoadAssembly(string filePath)
        {
            // This causes non-classes to register as classes
            AssemblyNode assembly = AssemblyNode.GetAssembly(filePath, null, false,
                                                             (this.SourceCodeBasePath != null), false, false);

            if (assembly != null)
            {
                // If generating reflection data for a framework, reset the core library if seen
                if (assembly.Name == CoreSystemTypes.SystemAssembly.Name)
                {
                    ResetMscorlib(assembly);
                }

                resolver.Add(assembly);
                assemblies.Add(assembly);

                if (this.SourceCodeBasePath != null)
                {
                    if (!assembly.reader.PdbExists)
                    {
                        this.MessageLogger(LogLevel.Warn, "The program database (PDB) file associated with " +
                                           $"'{filePath}' does not exist or could not be loaded.  Source context information " +
                                           "is unavailable.");
                    }
                    else
                    {
                        this.MessageLogger(LogLevel.Info, $"Found a current program database (PDB) file for '{filePath}'.");
                    }
                }
            }
        }
Exemplo n.º 18
0
        public void Test()
        {
            var gen = new XmlResultsGenerator(null, null, null, null, null);

            var muSession = new MutationTestingSession();

            var mutar = new MutationTarget(new MutationVariant());


            var ass = new AssemblyNode("Assembly");

            muSession.MutantsGrouped.Add(ass);
            var nodeNamespace = new TypeNamespaceNode(ass, "Namespace");

            ass.Children.Add(nodeNamespace);
            var nodeType = new TypeNode(nodeNamespace, "Type");

            nodeNamespace.Children.Add(nodeType);
            var nodeMethod = new MethodNode(nodeType, "Method", null, true);

            nodeType.Children.Add(nodeMethod);
            var nodeGroup = new MutantGroup("Gr1", nodeMethod);

            nodeMethod.Children.Add(nodeGroup);
            var nodeMutant = new Mutant("m1", nodeGroup, mutar);

            nodeGroup.Children.Add(nodeMutant);

            XDocument generateResults = gen.GenerateResults(muSession, false, false, ProgressCounter.Inactive(), CancellationToken.None).Result;

            Console.WriteLine(generateResults.ToString());
            //gen.
        }
Exemplo n.º 19
0
 public MappingGenerator(string fileName, DatabaseNode databaseNode, AssemblyNode assemblyNode)
 {
     this.fileName     = fileName;
     this.databaseNode = databaseNode;
     this.ass          = assemblyNode.Assembly;
     database          = databaseNode.Database;
 }
Exemplo n.º 20
0
        public AssemblyNode CreateAssemblyNode(IOldToNewTupleMap <string> assemblyMap)
        {
            var generationProjectInfoMap = new OldToNewTupleMap <GeneratedProjectOutputInfo>
                                           (
                new GeneratedProjectOutputInfo(assemblyMap.OldType),
                new GeneratedProjectOutputInfo(assemblyMap.NewType)
                                           );

            Console.Write("Loading old assembly...");
            var assemblyDecompilationResultOld = GetAssemblyDecompilationResult(
                assemblyMap.OldType,
                generationProjectInfoMap.OldType.OutputPath,
                CancellationToken.None);

            GlobalDecompilationResultsRepository.Instance.AddDecompilationResult(assemblyMap.OldType, assemblyDecompilationResultOld);
            Console.WriteLine("done.");

            Console.Write("Loading new assembly...");
            var assemblyDecompilationResultNew = GetAssemblyDecompilationResult(
                assemblyMap.NewType,
                generationProjectInfoMap.NewType.OutputPath,
                CancellationToken.None);

            GlobalDecompilationResultsRepository.Instance.AddDecompilationResult(assemblyMap.NewType, assemblyDecompilationResultNew);
            Console.WriteLine("done.");

            return(AssemblyNode.Create(assemblyMap, generationProjectInfoMap));
        }
Exemplo n.º 21
0
        private static AssemblyNode GetTaskAssembly(TypeNode type)
        {
            AssemblyNode taskAssembly = null;

            // Check if the type's located in mscorlib
            TypeNode taskTypeNode = GetTypeNode(FrameworkAssemblies.Mscorlib, TaskNamespace, TaskGenericType);

            if (taskTypeNode != null)
            {
                taskAssembly = FrameworkAssemblies.Mscorlib;
            }
            else if (type.DeclaringModule.Name.Equals(TaskPortableAssembly))
            {
                // If the type is a type in the portable assembly, no need to loop through the assembly references
                taskAssembly = type.DeclaringModule.ContainingAssembly;
            }
            else
            {
                AssemblyReference assemblyReference = type.DeclaringModule
                                                      .AssemblyReferences
                                                      .FirstOrDefault(reference => reference.Name.Equals(TaskPortableAssembly, StringComparison.Ordinal));
                Contract.Assert(assemblyReference != null);
                taskAssembly = assemblyReference.Assembly;
            }

            Contract.Assert(taskAssembly != null);
            return(taskAssembly);
        }
Exemplo n.º 22
0
        public ActionsGroupNode ReadController(Type type, AssemblyNode assemblyNode)
        {
            var name = type.Name.Replace("Controller", string.Empty);

            name = NameCleaner.Replace(name, string.Empty);
            var controller = new ActionsGroupNode(assemblyNode, name);

            var    routePrefixAttribute = type.GetTypeInfo().GetCustomAttribute <RouteAttribute>(false) ?? type.GetTypeInfo().GetCustomAttribute <RouteAttribute>();
            string routePrefix          = routePrefixAttribute != null ? routePrefixAttribute.Template : "todo";

            controller.Documentation = documentation.GetDocumentation(type);

            foreach (var methodInfo in type.GetMethods().Where(x => x.IsPublic))
            {
                if (methodInfo.GetCustomAttribute <NonActionAttribute>() != null)
                {
                    continue;
                }
                if (methodInfo.IsSpecialName)
                {
                    continue;
                }

                var action = ReadAction(routePrefix, methodInfo, controller);
                if (action != null)
                {
                    controller.Actions.Add(action);
                }
            }
            return(controller);
        }
        public void Test1()
        {
            System.Action<CheckedNode, ICollection<MutationTarget>> typeNodeCreator = (parent, targets) =>
            {

            };

            Func<MutationTarget, string> namespaceExtractor = target => target.NamespaceName;

            var mt1 = new MutationTarget(null);
            mt1.NamespaceName = "Root.NamespaceName1";

            var mt2 = new MutationTarget(null);
            mt2.NamespaceName = "Root.NamespaceName2";

            var mt3 = new MutationTarget(null);
            mt3.NamespaceName = "Another.NamespaceName3";

            var mt4 = new MutationTarget(null);
            mt4.NamespaceName = "Another.NamespaceName3";

            var ass = new AssemblyNode("");
            NamespaceGrouper<MutationTarget, CheckedNode>.
                GroupTypes(ass, namespaceExtractor,
                (parent, name) => new TypeNamespaceNode(parent, name), typeNodeCreator,
                    new List<MutationTarget> { mt1, mt2, mt3 });

            ass.Children.Count.ShouldEqual(2);
            ass.Children.Single(c => c.Name == "Root").Children.Count.ShouldEqual(2);
            ass.Children.Single(c => c.Name == "Another.NamespaceName3").Children.Count.ShouldEqual(0);
        }
Exemplo n.º 24
0
 /// <summary>
 /// This is used to reset the target platform information if mscorlib is specified as one of the
 /// reference assemblies or documented assemblies.
 /// </summary>
 /// <param name="assembly">The system assembly for the target platform (mscorlib)</param>
 private static void ResetMscorlib(AssemblyNode assembly)
 {
     TargetPlatform.Clear();
     CoreSystemTypes.Clear();
     CoreSystemTypes.SystemAssembly = assembly;
     CoreSystemTypes.Initialize(true, false);
 }
 private void btnOpen_Click(object sender, System.EventArgs e)
 {
     try
     {
         if (dlgOpenAssembly.ShowDialog(this) == DialogResult.OK)
         {
             Assembly asm  = Assembly.LoadFrom(dlgOpenAssembly.FileName);
             TreeNode node = new AssemblyNode(asm);
             node.Nodes.Add(new TreeNode());
             tvBrowser.Nodes.Add(node);
         }
     }
     catch (Exception ex)
     {
         IUIService svc = (IUIService)this.GetService(typeof(IUIService));
         if (svc != null)
         {
             svc.ShowError(ex);
         }
         else
         {
             throw ex;
         }
     }
 }
Exemplo n.º 26
0
        private ClassNode ReadClass(Type parameterType, AssemblyNode assembly, ActionNode actionNode, Type[] parents)
        {
            var parameterTypeName = Regex.Replace(parameterType.Name, "`.*", "");

            ClassNode classNode;

            if (assembly.Classes.ContainsKey(parameterTypeName))
            {
                classNode = assembly.Classes[parameterTypeName];
            }
            else
            {
                classNode = new ClassNode
                {
                    Version       = actionNode.Version,
                    Documentation = documentation.GetDocumentation(parameterType),
                    KoName        = parameterTypeName,
                    Name          = Regex.Replace(parameterTypeName, @"View(Model)?$", string.Empty)
                };

                if (parameterType.GetTypeInfo().IsEnum)
                {
                    var enumNames  = parameterType.GetTypeInfo().GetEnumNames();
                    var enumValues = parameterType.GetTypeInfo().GetEnumValues();

                    classNode.Values = new List <EnumValueNode>();
                    for (var i = 0; i < enumValues.Length; i++)
                    {
                        var enumValue = new EnumValueNode
                        {
                            Name          = enumNames[i],
                            Value         = Convert.ToInt32(enumValues.GetValue(i)),
                            Documentation = documentation.GetDocumentation(parameterType, enumNames[i])
                        };
                        classNode.Values.Add(enumValue);
                    }
                }
                else
                {
                    if (parents.All(x => x != parameterType))
                    {
                        classNode.Properties = ReadProperties(parameterType, parents, assembly, actionNode);
                    }

                    if (parameterType.GetTypeInfo().IsGenericTypeDefinition)
                    {
                        classNode.GenericParameters = parameterType.GetGenericArguments().Select(x => x.Name).ToList();
                    }

                    var jsonAttribute = parameterType.GetTypeInfo().GetCustomAttribute <JsonAttribute>();
                    if (jsonAttribute != null)
                    {
                        classNode.HasObservable = jsonAttribute.Observable;
                    }
                }
                assembly.Classes[classNode.KoName] = classNode;
            }
            return(classNode);
        }
Exemplo n.º 27
0
 /// <summary>
 /// This is used to reset the target platform information if mscorlib is specified as one of the
 /// reference assemblies or documented assemblies.
 /// </summary>
 /// <param name="assembly">The system assembly for the target platform (mscorlib)</param>
 private static void ResetMscorlib(AssemblyNode assembly)
 {
     TargetPlatform.Clear();
     CoreSystemTypes.Clear();
     CoreSystemTypes.SystemAssembly            = assembly;
     TargetPlatform.PlatformAssembliesLocation = Path.GetDirectoryName(assembly.Location);
     CoreSystemTypes.Initialize(true, false);
 }
Exemplo n.º 28
0
 public static AssemblyNode GetAssembly()
 {
     if (_assemblyNode == null)
     {
         _assemblyNode = AssemblyNode.GetAssembly(Assembly.GetExecutingAssembly().Location, true, true, true);
     }
     return(_assemblyNode);
 }
Exemplo n.º 29
0
        private void AddJustAssemblyTab(AssemblyNode node)
        {
            var JustAssemblyTabItem = new AssemblyAttributeTabItem(node);

            JustAssemblyTabItem.LoadContent();

            this.AddNewTabItem(JustAssemblyTabItem);
        }
Exemplo n.º 30
0
        public virtual void VisitAssembly(AssemblyNode node)
        {
            if (node == null)
            {
                return;
            }

            VisitModuleList(node.Modules);
        }
Exemplo n.º 31
0
        public static bool IsSystemAssembly(this AssemblyNode assembly)
        {
            string assemblyFile = (assembly.Location ?? "").ToLower();

            return(assemblyFile.Contains(":\\Program Files (x86)\\Microsoft ASP.NET\\ASP.NET MVC 3\\Assemblies".ToLower()) ||
                   assemblyFile.Contains(":\\Program Files (x86)\\Microsoft ASP.NET\\ASP.NET MVC 4\\Assemblies".ToLower()) ||
                   assemblyFile.Contains(":\\Program Files (x86)\\Microsoft ASP.NET\\ASP.NET Web Pages\\v1.0\\Assemblies".ToLower()) ||
                   assemblyFile.Contains(":\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework".ToLower()));
        }
Exemplo n.º 32
0
        private ReturnNode ReadReturn(ContextualType responseType, AssemblyNode assembly, XElement?documentationNode, ActionNode actionNode)
        {
            var returnNode = new ReturnNode(ReadType(responseType, assembly, new Type[0], actionNode))
            {
                Documentation = documentation.ParseDocumentation(documentationNode),
            };

            return(returnNode);
        }
Exemplo n.º 33
0
		public void DrawTree(AssemblyNode module)
		{
			var leftCol = leftTree.Items.SourceCollection as INotifyCollectionChanged;
			leftCol.CollectionChanged += BuildLeftINodeList;
			
			var topCol = topTree.Items.SourceCollection as INotifyCollectionChanged;
			topCol.CollectionChanged += BuildTopINodeList;
			
			leftTree.MouseMove += LeftTree_MouseMove;
			topTree.MouseMove += TopTree_MouseMove;
			
			Helper.FillTree(leftTree, module);
			Helper.FillTree(topTree, module);
		}
Exemplo n.º 34
0
        public AssemblyNode CreateAssemblyNode(IModuleInfo module,
            CciMethodMatcher methodMatcher)
        {
            var matcher = methodMatcher.Join(new SolutionTypesManager.ProperlyNamedMatcher());
            var assemblyNode = new AssemblyNode(module.Name);
            assemblyNode.AssemblyPath = module.Module.Location.ToFilePathAbs();
            System.Action<CheckedNode, ICollection<INamedTypeDefinition>> typeNodeCreator = (parent, leafTypes) =>
            {
                foreach (INamedTypeDefinition typeDefinition in leafTypes)
                {
                    if (matcher.Matches(typeDefinition))
                    {
                        var type = new TypeNode(parent, typeDefinition.Name.Value);
                        foreach (var method in typeDefinition.Methods)
                        {
                            if (matcher.Matches(method))
                            {
                                type.Children.Add(new MethodNode(type, method.Name.Value, method, false));
                                return;
                            }
                        }
                        parent.Children.Add(type);
                    }
                }
            };
            Func<INamedTypeDefinition, string> namespaceExtractor = typeDef =>
                TypeHelper.GetDefiningNamespace(typeDef).Name.Value;


            NamespaceGrouper<INamespaceTypeDefinition, CheckedNode>.
                GroupTypes(assemblyNode,
                    namespaceExtractor,
                    (parent, name) => new TypeNamespaceNode(parent, name),
                    typeNodeCreator,
                        module.Module.GetAllTypes().ToList());


            //remove empty amespaces. 
            //TODO to refactor...
            List<TypeNamespaceNode> checkedNodes = assemblyNode.Children.OfType<TypeNamespaceNode>().ToList();
            foreach (TypeNamespaceNode node in checkedNodes)
            {
                RemoveFromParentIfEmpty(node);
            }
            return assemblyNode;
        }
Exemplo n.º 35
0
		public MetricsReader(string fileName)
		{
			loader = new CecilLoader(true) { IncludeInternalMembers = true };
			namespaceMappings = new Dictionary<string, NamespaceNode>();
			typeMappings = new Dictionary<ITypeDefinition, TypeNode>();
			methodMappings = new Dictionary<IMethod, MethodNode>();
			fieldMappings = new Dictionary<IField, FieldNode>();
			cecilMappings = new Dictionary<MemberReference, IEntity>();
			
			compilation = new SimpleCompilation(loader.LoadAssemblyFile(fileName));
			
			// TODO load referenced assemblies into compilation.
			
			Assembly = new AssemblyNode(compilation.MainAssembly.AssemblyName);
			assemblyDefinition = loader.GetCecilObject(compilation.MainAssembly.UnresolvedAssembly);
			
			foreach (var type in compilation.MainAssembly.GetAllTypeDefinitions()) {
				ReadType(type);
				
				foreach (IMethod method in type.Methods) {
					ReadMethod(method);
				}
				
				foreach (IProperty property in type.Properties) {
					if (property.CanGet)
						ReadMethod(property.Getter);
					if (property.CanSet)
						ReadMethod(property.Setter);
				}
				
				foreach (IField field in type.Fields) {
					ReadField(field);
				}
			}
			
			foreach (var method in methodMappings.Values) {
				ReadInstructions(method, method.Method, loader.GetCecilObject((IUnresolvedMethod)method.Method.UnresolvedMember));
			}
			
			Assembly.namespaces = namespaceMappings.Values;
		}
Exemplo n.º 36
0
 public Mutant CreateEquivalentMutant(out AssemblyNode assemblyNode)
 {
     
     assemblyNode = new AssemblyNode("All modules");
     var nsNode = new TypeNamespaceNode(assemblyNode, "");
     assemblyNode.Children.Add(nsNode);
     var typeNode = new TypeNode(nsNode, "");
     nsNode.Children.Add(typeNode);
     var methodNode = new MethodNode(typeNode, "", null, true);
     typeNode.Children.Add(methodNode);
     var group = new MutantGroup("Testing original program", methodNode);
     var target = new MutationTarget(new MutationVariant())
                  {
                      Name = "Original program",
                  };
     var mutant = new Mutant("0", group, target);
    
     group.Children.Add(mutant);
     methodNode.Children.Add(group);
     group.UpdateDisplayedText();
     return mutant;
 }
        /// <summary>
        /// Provide a hook for derived classes to modify the initial 
        /// list of types.
        /// </summary>
        /// 
        protected virtual void OnLoadNodes()
        {
            tvBrowser.Nodes.Clear();

            foreach(Assembly assembly in this.assemblies)
            {
                TreeNode node = new AssemblyNode(assembly);
                node.Nodes.Add(new TreeNode());
                tvBrowser.Nodes.Add(node);
            }
        }
Exemplo n.º 38
0
 public virtual AssemblyNode VisitAssembly(AssemblyNode assembly){
   if (assembly == null) return null;
   this.VisitModule(assembly);
   assembly.ModuleAttributes = this.VisitAttributeList(assembly.ModuleAttributes);
   assembly.SecurityAttributes = this.VisitSecurityAttributeList(assembly.SecurityAttributes);
   return assembly;
 }
 private void btnOpen_Click(object sender, System.EventArgs e)
 {
     try
     {
         if(dlgOpenAssembly.ShowDialog(this) == DialogResult.OK)
         {
             Assembly asm = Assembly.LoadFrom(dlgOpenAssembly.FileName);
             TreeNode node = new AssemblyNode(asm);
             node.Nodes.Add(new TreeNode());
             tvBrowser.Nodes.Add(node);
         }
     }
     catch(Exception ex)
     {
         IUIService svc = (IUIService)this.GetService(typeof(IUIService));
         if (svc != null)
         {
             svc.ShowError(ex);
         }
         else
         {
             throw ex;
         }
     }
 }
Exemplo n.º 40
0
		public virtual void VisitAssembly (AssemblyNode node)
		{
			if (node == null)
				return;

			VisitModuleList (node.Modules);
		}
Exemplo n.º 41
0
		public virtual AssemblyNode VisitAssembly (AssemblyNode node)
		{
			if (node == null)
				return null;

			VisitModuleList (node.Modules);


			return node;
		}
Exemplo n.º 42
0
        private AssemblyNode BuildMutantsTree(string moduleName,
            MultiDictionary<IMutationOperator, MutationTarget> mutationTargets)
        {

            var assemblyNode = new AssemblyNode(moduleName);

            System.Action<CheckedNode, ICollection<MutationTarget>> typeNodeCreator = (parent, targets) =>
            {
                var typeNodes =
                    from t in targets
                    orderby t.TypeName
                    group t by t.TypeName
                    into byTypeGrouping
                    select new TypeNode(parent, byTypeGrouping.Key,
                        from gr in byTypeGrouping
                        group gr by gr.MethodRaw.Name.Value
                        into byMethodGrouping
                        orderby byMethodGrouping.Key
                        let md = byMethodGrouping.First().MethodRaw
                        select new MethodNode(md.Name.Value, md,
                            from gr in byMethodGrouping
                            group gr by gr.GroupName
                            into byGroupGrouping
                            orderby byGroupGrouping.Key
                            select GroupOrMutant(byGroupGrouping)
                        )
                    );

                parent.Children.AddRange(typeNodes);
            };

            Func<MutationTarget, string> namespaceExtractor = target => target.NamespaceName;

            NamespaceGrouper<MutationTarget, CheckedNode>.GroupTypes(assemblyNode, 
                namespaceExtractor, 
                (parent, name) => new TypeNamespaceNode(parent, name), 
                typeNodeCreator,
                mutationTargets.Values.SelectMany(a => a).ToList());


            foreach (var node in assemblyNode.Children.Where(n=>n.Children.Count == 0).ToList())
            {
                assemblyNode.Children.Remove(node);
            }
            return assemblyNode;
        }
Exemplo n.º 43
0
 public override AssemblyNode VisitAssembly(AssemblyNode assembly) {
   if (assembly == null) return null;
   this.currentModule = this.currentAssembly = assembly;
   assembly.Attributes = this.VisitAttributeList(assembly.Attributes, assembly);
   assembly.ModuleAttributes = this.VisitModuleAttributes(assembly.ModuleAttributes);
   assembly.Types = this.VisitTypeNodeList(assembly.Types);
   return assembly;
 }
Exemplo n.º 44
0
 public override Module VisitModule(Module module){
   if (module == null) return null;
   this.currentModule = module;
   this.currentAssembly = module.ContainingAssembly;
   return base.VisitModule(module);
 }
Exemplo n.º 45
0
 public void Teardown()
 {
     MsCorLib = null;
     JSTypes = null;
 }
Exemplo n.º 46
0
 public override Module VisitModule(Module module) {
   if (module == null) return null;
   this.currentModule = module;
   this.currentAssembly = module.ContainingAssembly;
   module.Attributes = this.VisitModuleAttributes(module.Attributes);
   module.Types = this.VisitTypeNodeList(module.Types);
   return module;
 }
Exemplo n.º 47
0
 public override AssemblyNode VisitAssembly(AssemblyNode assembly){
   this.currentModule = this.currentAssembly = assembly;
   return base.VisitAssembly(assembly);
 }
Exemplo n.º 48
0
 public virtual AttributeNode VisitUnknownAssemblyAttribute(TypeNode attrType, AttributeNode attr, AssemblyNode target) {
   return attr;
 }
Exemplo n.º 49
0
 public override Compilation VisitCompilation(Compilation compilation) {
   if (compilation == null) return null;
   this.currentOptions = compilation.CompilerParameters as CompilerOptions;
   Module module = this.currentModule = compilation.TargetModule;
   if (module != null) {
     AssemblyNode assem = module as AssemblyNode;
     if (assem != null) {
       this.currentAssembly = assem;
       if (this.currentOptions.IsContractAssembly) { // handle compiler option /shadow:<assembly>
         this.shadowedAssembly = AssemblyNode.GetAssembly(this.currentOptions.ShadowedAssembly);
         if (this.shadowedAssembly == null) {
           this.HandleError(compilation, Error.CannotLoadShadowedAssembly, this.currentOptions.ShadowedAssembly);
           return compilation;
         }
         assem.Attributes.Add(ShadowedAssemblyAttribute());
         this.isCompilingAContractAssembly = true;
       }
       assem.Attributes = this.VisitAttributeList(assem.Attributes, assem);
       assem.ModuleAttributes = this.VisitModuleAttributes(assem.ModuleAttributes);
     } else {
       this.currentAssembly = module.ContainingAssembly;
       module.Attributes = this.VisitModuleAttributes(module.Attributes);
     }
   }
   return base.VisitCompilation(compilation);
 }
Exemplo n.º 50
0
 public virtual AttributeNode VisitAssemblyAttribute(AttributeNode attr, AssemblyNode target) {
   attr = this.VisitAttributeNode(attr);
   if (attr == null) return null;
   MemberBinding mb = attr.Constructor as MemberBinding;
   if (mb == null) return null;
   InstanceInitializer constr = mb.BoundMember as InstanceInitializer;
   if (constr == null) return null;
   TypeNode attrType = constr.DeclaringType;
   if (this.currentOptions != null) {
     if (attrType == SystemTypes.AssemblyCompanyAttribute)
       this.currentOptions.TargetInformation.Company = this.GetStringParameter(attr.Expressions);
     else if (attrType == SystemTypes.AssemblyConfigurationAttribute)
       this.currentOptions.TargetInformation.Configuration = this.GetStringParameter(attr.Expressions);
     else if (attrType == SystemTypes.AssemblyCopyrightAttribute)
       this.currentOptions.TargetInformation.Copyright = this.GetStringParameter(attr.Expressions);
     else if (attrType == SystemTypes.AssemblyCultureAttribute)
       this.currentOptions.TargetInformation.Culture = this.GetStringParameter(attr.Expressions);
     else if (attrType == SystemTypes.AssemblyDescriptionAttribute)
       this.currentOptions.TargetInformation.Description = this.GetStringParameter(attr.Expressions);
     else if (attrType == SystemTypes.AssemblyFileVersionAttribute)
       this.currentOptions.TargetInformation.Version = this.GetStringParameter(attr.Expressions);
     else if (attrType == SystemTypes.AssemblyInformationalVersionAttribute)
       this.currentOptions.TargetInformation.ProductVersion = this.GetStringParameter(attr.Expressions);
     else if (attrType == SystemTypes.AssemblyProductAttribute)
       this.currentOptions.TargetInformation.Product = this.GetStringParameter(attr.Expressions);
     else if (attrType == SystemTypes.AssemblyTitleAttribute)
       this.currentOptions.TargetInformation.Title = this.GetStringParameter(attr.Expressions);
     else if (attrType == SystemTypes.AssemblyTrademarkAttribute)
       this.currentOptions.TargetInformation.Trademark = this.GetStringParameter(attr.Expressions);
   }
   if (attrType == SystemTypes.AssemblyFlagsAttribute) {
     ExpressionList args = attr.Expressions;
     AssemblyFlags flags = AssemblyFlags.None;
     if (args != null && args.Count > 0) {
       Literal flagsLit = args[0] as Literal;
       if (flagsLit != null && this.currentAssembly != null) {
         if (flagsLit.Value is int)
           flags = (AssemblyFlags)(int)flagsLit.Value;
         else if (flagsLit.Value is uint)
           flags = (AssemblyFlags)(uint)flagsLit.Value;
       }
     }
     this.currentAssembly.Flags = flags;
     attr.IsPseudoAttribute = true;
     return attr;
   }
   if (attrType == SystemTypes.AssemblyKeyFileAttribute) {
     ExpressionList args = attr.Expressions;
     if (args != null && args.Count > 0) {
       Literal keyFilePathLit = args[0] as Literal;
       if (keyFilePathLit != null && this.currentAssembly != null) {
         string keyFilePath = keyFilePathLit.Value as string;
         Document doc = attr.SourceContext.Document;
         if (doc != null && doc.Name != null) {
           string dir = Path.GetDirectoryName(doc.Name);
           keyFilePath = PathWrapper.Combine(dir, keyFilePath);
         }
         if (keyFilePath != null && File.Exists(keyFilePath)) { //TODO: what about additional search paths
           if (this.currentOptions != null)
             this.currentOptions.AssemblyKeyFile = keyFilePath;
         } else {
           if (this.currentOptions != null)
             this.currentOptions.AssemblyKeyFile = keyFilePathLit.Value as string;
         }
         //this.HandleError(attr, Error.UseSwitchInsteadOfAttribute, "keyfile", "AssemblyKeyFileAttribute");
       }
     }
   }
   if (attrType == SystemTypes.AssemblyKeyNameAttribute) {
     ExpressionList args = attr.Expressions;
     if (args != null && args.Count > 0) {
       Literal keyNameLit = args[0] as Literal;
       if (keyNameLit != null && this.currentAssembly != null) {
         string keyName = keyNameLit.Value as string;
         if (keyName != null) {
           if (this.currentOptions != null)
             this.currentOptions.AssemblyKeyName = keyName;
           //this.HandleError(attr, Error.UseSwitchInsteadOfAttribute, "keyname", "AssemblyKeyNameAttribute");
         }
       }
     }
     return attr;
   }
   if (attrType == SystemTypes.AssemblyVersionAttribute || attrType == SystemTypes.SatelliteContractVersionAttribute) {
     ExpressionList args = attr.Expressions;
     string version = null;
     if (args != null && args.Count > 0) {
       Literal titleLit = args[0] as Literal;
       if (titleLit != null && this.currentAssembly != null) {
         version = titleLit.Value as String;
       }
     }
     Version v = null;
     if (version != null) v = this.ParseVersion(version, attrType != SystemTypes.SatelliteContractVersionAttribute);
     if (v == null)
       this.HandleError(mb, Error.CustomAttributeError, this.GetTypeName(attrType), version);
     else if (attrType == SystemTypes.AssemblyVersionAttribute) {
       target.Version = v;
       attr.IsPseudoAttribute = true;
       return attr;
     }
     return attr;
   }
   if (attrType == SystemTypes.AssemblyDelaySignAttribute) {
     ExpressionList args = attr.Expressions;
     if (args != null && args.Count > 0) {
       Literal valueLit = args[0] as Literal;
       if (valueLit != null && valueLit.Value is bool && this.currentAssembly != null && this.currentOptions != null && !this.currentOptions.DelaySign) {
         this.currentOptions.DelaySign = (bool)valueLit.Value;
       }
     }
     return attr;
   }
   if (attrType == SystemTypes.CLSCompliantAttribute) {
     //TODO: enable CLS checking
   }
   return this.VisitUnknownAssemblyAttribute(attrType, attr, target);
 }
Exemplo n.º 51
0
 public override AssemblyNode VisitAssembly(AssemblyNode assembly)
 {
     if (assembly == null) return null;
     this.FindTypesToBeDuplicated(assembly.Types);
     return base.VisitAssembly((AssemblyNode)assembly.Clone());
 }
Exemplo n.º 52
0
        public void Setup(AssemblyNode mscorlib, AssemblyNode jsTypes, AssemblyNode rewriteAssembly)
        {
            NumWarnings = 0;
            NumErrors = 0;

            MsCorLib = mscorlib;

            AssemblyDelaySignAttributeType = GetType(mscorlib, "System.Reflection", "AssemblyDelaySignAttribute");

            VoidType = GetType(mscorlib, "System", "Void");
            ObjectType = GetType(mscorlib, "System", "Object");
            StringType = GetType(mscorlib, "System", "String");
            IntType = GetType(mscorlib, "System", "Int32");
            BooleanType = GetType(mscorlib, "System", "Boolean");
            MethodBaseType = GetType(mscorlib, "System.Reflection", "MethodBase");
            RuntimeTypeHandleType = GetType(mscorlib, "System", "RuntimeTypeHandle");
            NullableTypeConstructor = GetType(mscorlib, "System", "Nullable`1");
            CompilerGeneratedAttributeType = GetType
                (mscorlib, "System.Runtime.CompilerServices", "CompilerGeneratedAttribute");
            DllImportAttributeType = GetType(mscorlib, "System.Runtime.InteropServices", "DllImportAttribute");

            TypeType = GetType(mscorlib, "System", "Type");
            Type_GetMethodMethod = GetMethod(TypeType, "GetMethod", StringType, TypeType.GetArrayType(1));
            Type_GetMemberMethod = GetMethod(TypeType, "GetMember", StringType);
            Type_GetConstructorMethod = GetMethod(TypeType, "GetConstructor", TypeType.GetArrayType(1));
            Type_GetTypeFromHandleMethod = GetMethod(TypeType, "GetTypeFromHandle", RuntimeTypeHandleType);
            Type_GetGenericArgumentsMethod = GetMethod(TypeType, "GetGenericArguments");
            Type_MakeArrayTypeMethod = GetMethod(TypeType, "MakeArrayType");
            Type_MakeGenericTypeMethod = GetMethod(TypeType, "MakeGenericType", TypeType.GetArrayType(1));

            InteropTypes = new InteropTypes(this);
            InteropManager = new InteropManager(this);

            IgnoreAttributeType = GetType(jsTypes, Constants.JSTypesIL2JSNS, "IgnoreAttribute");
            InteropAttributeType = GetType(jsTypes, Constants.JSTypesInteropNS, "InteropAttribute");
            NamingAttributeType = GetType(jsTypes, Constants.JSTypesInteropNS, "NamingAttribute");
            ImportAttributeType = GetType(jsTypes, Constants.JSTypesInteropNS, "ImportAttribute");
            ImportKeyAttributeType = GetType(jsTypes, Constants.JSTypesInteropNS, "ImportKeyAttribute");
            ExportAttributeType = GetType(jsTypes, Constants.JSTypesInteropNS, "ExportAttribute");
            NotExportedAttributeType = GetType(jsTypes, Constants.JSTypesInteropNS, "NotExportedAttribute");
            InteropGeneratedAttributeType = GetType(jsTypes, Constants.JSTypesIL2JSNS, "InteropGeneratedAttribute");

            JSTypes = jsTypes;

            JSContextType = GetType(jsTypes, Constants.JSTypesInteropNS, "JSContext");

            InteropContextManagerType = GetType(jsTypes, Constants.JSTypesManagedInteropNS, "InteropContextManager");
            InteropContextManager_GetDatabaseMethod = GetMethod(InteropContextManagerType, "get_Database");
            InteropContextManager_GetCurrentRuntimeMethod = GetMethod(InteropContextManagerType, "get_CurrentRuntime");
            InteropContextManager_GetRuntimeForObjectMethod = GetMethod
                (InteropContextManagerType, "GetRuntimeForObject", ObjectType);

            InteropDatabaseType = GetType(jsTypes, Constants.JSTypesManagedInteropNS, "InteropDatabase");
            InteropDatabase_RegisterRootExpression = GetMethod(InteropDatabaseType, "RegisterRootExpression", StringType);
            InteropDatabase_RegisterDelegateShimMethod = GetMethod
                (InteropDatabaseType, "RegisterDelegateShim", TypeType);
            InteropDatabase_RegisterTypeMethod = GetMethod
                (InteropDatabaseType,
                 "RegisterType",
                 TypeType,
                 IntType,
                 StringType,
                 StringType,
                 IntType,
                 BooleanType,
                 BooleanType,
                 BooleanType);
            InteropDatabase_RegisterExportMethod = GetMethod
                (InteropDatabaseType, "RegisterExport", MethodBaseType, BooleanType, StringType);

            SimpleMethodBaseType = GetType(jsTypes, Constants.JSTypesManagedInteropNS, "SimpleMethodBase");

            SimpleMethodInfoType = GetType(jsTypes, Constants.JSTypesManagedInteropNS, "SimpleMethodInfo");
            SimpleMethodInfo_Ctor = GetConstructor
                (SimpleMethodInfoType, BooleanType, StringType, TypeType, TypeType.GetArrayType(1), TypeType);

            SimpleConstructorInfoType = GetType(jsTypes, Constants.JSTypesManagedInteropNS, "SimpleConstructorInfo");
            SimpleConstructorInfo_Ctor = GetConstructor(SimpleConstructorInfoType, TypeType, TypeType.GetArrayType(1));

            RuntimeType = GetType(jsTypes, Constants.JSTypesManagedInteropNS, "Runtime");
            Runtime_CompleteConstructionMethod = GetMethod
                (RuntimeType, "CompleteConstruction", SimpleMethodBaseType, ObjectType, JSContextType);
            Runtime_CallImportedMethodMethod = GetMethod
                (RuntimeType, "CallImportedMethod", SimpleMethodBaseType, StringType, ObjectType.GetArrayType(1));

            UniversalDelegateType = GetType(jsTypes, Constants.JSTypesManagedInteropNS, "UniversalDelegate");
            UniversalDelegate_InvokeMethod = GetUniqueMethod(UniversalDelegateType, "Invoke");

            MethodBase_GetGenericArgumentsMethod = GetMethod(MethodBaseType, "GetGenericArguments");

            ModuleType = GetType(rewriteAssembly, "", "<Module>");
            foreach (var member in ModuleType.Members)
            {
                var cctor = member as StaticInitializer;
                if (cctor != null)
                    ModuleCCtorMethod = cctor;
            }
        }
Exemplo n.º 53
0
    public virtual Differences VisitAssembly(AssemblyNode/*!*/ assembly1, AssemblyNode assembly2) {
      Differences differences = new Differences(assembly1, assembly2);
      if (assembly1 == null || assembly2 == null){
        if (assembly1 != assembly2) differences.NumberOfDifferences++; else differences.NumberOfSimilarities++;
        return differences;
      }
      AssemblyNode changes = (AssemblyNode)assembly2.Clone();
      AssemblyNode deletions = (AssemblyNode)assembly2.Clone();
      AssemblyNode insertions = (AssemblyNode)assembly2.Clone();

      this.OriginalModule = assembly1;
      this.NewModule = assembly2;

      AssemblyReferenceList arChanges, arDeletions, arInsertions;
      Differences diff = this.VisitAssemblyReferenceList(assembly1.AssemblyReferences, assembly2.AssemblyReferences, out arChanges, out arDeletions, out arInsertions);
      if (diff == null){Debug.Assert(false); return differences;}
      changes.AssemblyReferences = arChanges;
      deletions.AssemblyReferences = arDeletions;
      insertions.AssemblyReferences = arInsertions;
      differences.NumberOfDifferences += diff.NumberOfDifferences;
      differences.NumberOfSimilarities += diff.NumberOfSimilarities;

      AttributeList attrChanges, attrDeletions, attrInsertions;
      diff = this.VisitAttributeList(assembly1.Attributes, assembly2.Attributes, out attrChanges, out attrDeletions, out attrInsertions);
      if (diff == null){Debug.Assert(false); return differences;}
      changes.Attributes = attrChanges;
      deletions.Attributes = attrDeletions;
      insertions.Attributes = attrInsertions;
      differences.NumberOfDifferences += diff.NumberOfDifferences;
      differences.NumberOfSimilarities += diff.NumberOfSimilarities;

      if (assembly1.Culture == assembly2.Culture) differences.NumberOfSimilarities++; else differences.NumberOfDifferences++;

      TypeNodeList typeChanges, typeDeletions, typeInsertions;
      diff = this.VisitTypeNodeList(assembly1.ExportedTypes, assembly2.ExportedTypes, out typeChanges, out typeDeletions, out typeInsertions);
      if (diff == null){Debug.Assert(false); return differences;}
      changes.Types = typeChanges;
      deletions.Types = typeDeletions;
      insertions.Types = typeInsertions;
      differences.NumberOfDifferences += diff.NumberOfDifferences;
      differences.NumberOfSimilarities += diff.NumberOfSimilarities;

      if (assembly1.Flags == assembly2.Flags) differences.NumberOfSimilarities++; else differences.NumberOfDifferences++;

      if (assembly1.Kind == assembly2.Kind) differences.NumberOfSimilarities++; else differences.NumberOfDifferences++;

      diff = this.VisitAttributeList(assembly1.ModuleAttributes, assembly2.ModuleAttributes, out attrChanges, out attrDeletions, out attrInsertions);
      if (diff == null){Debug.Assert(false); return differences;}
      changes.Attributes = attrChanges;
      deletions.Attributes = attrDeletions;
      insertions.Attributes = attrInsertions;
      differences.NumberOfDifferences += diff.NumberOfDifferences;
      differences.NumberOfSimilarities += diff.NumberOfSimilarities;

      ModuleReferenceList mrChanges, mrDeletions, mrInsertions;
      diff = this.VisitModuleReferenceList(assembly1.ModuleReferences, assembly2.ModuleReferences, out mrChanges, out mrDeletions, out mrInsertions);
      if (diff == null){Debug.Assert(false); return differences;}
      changes.ModuleReferences = mrChanges;
      deletions.ModuleReferences = mrDeletions;
      insertions.ModuleReferences = mrInsertions;
      differences.NumberOfDifferences += diff.NumberOfDifferences;
      differences.NumberOfSimilarities += diff.NumberOfSimilarities;

      if (assembly1.Name == assembly2.Name) differences.NumberOfSimilarities++; else differences.NumberOfDifferences++;

      SecurityAttributeList secChanges, secDeletions, secInsertions;
      diff = this.VisitSecurityAttributeList(assembly1.SecurityAttributes, assembly2.SecurityAttributes, out secChanges, out secDeletions, out secInsertions);
      if (diff == null){Debug.Assert(false); return differences;}
      changes.SecurityAttributes = secChanges;
      deletions.SecurityAttributes = secDeletions;
      insertions.SecurityAttributes = secInsertions;
      differences.NumberOfDifferences += diff.NumberOfDifferences;
      differences.NumberOfSimilarities += diff.NumberOfSimilarities;

      diff = this.VisitTypeNodeList(assembly1.Types, assembly2.Types, out typeChanges, out typeDeletions, out typeInsertions);
      if (diff == null){Debug.Assert(false); return differences;}
      changes.Types = typeChanges;
      deletions.Types = typeDeletions;
      insertions.Types = typeInsertions;
      differences.NumberOfDifferences += diff.NumberOfDifferences;
      differences.NumberOfSimilarities += diff.NumberOfSimilarities;

      if (assembly1.Version == assembly2.Version) differences.NumberOfSimilarities++; else differences.NumberOfDifferences++;

      if (differences.NumberOfDifferences == 0){
        differences.Changes = null;
        differences.Deletions = null;
        differences.Insertions = null;
      }else{
        differences.Changes = changes;
        differences.Deletions = deletions;
        differences.Insertions = insertions;
      }
      return differences;
    }
Exemplo n.º 54
0
 private TypeNode GetType(AssemblyNode assembly, string ns, string name)
 {
     var res = assembly.GetType(Identifier.For(ns), Identifier.For(name));
     if (res == null)
     {
         Log(new InvalidInteropMessage(null, "can't load required type: " + ns + "." + name));
         throw new ExitException();
     }
     return res;
 }
Exemplo n.º 55
0
 public override AssemblyNode VisitAssembly(AssemblyNode assembly)
 {
   throw new ApplicationException("unimplemented");
 }
Exemplo n.º 56
0
 public override Compilation VisitCompilation(Compilation compilation){
   if (compilation == null || compilation.TargetModule == null) return null;
   this.currentOptions = compilation.CompilerParameters as CompilerOptions;
   this.currentModule = compilation.TargetModule;
   this.currentAssembly = this.currentModule.ContainingAssembly;
   return base.VisitCompilation(compilation);
 }
Exemplo n.º 57
0
        private static TypeNode GetTypeNode(AssemblyNode assembly, string ns, string name)
        {
            Contract.Assert(assembly != null);

            return assembly.GetType(Identifier.For(ns), Identifier.For(name));
        }
Exemplo n.º 58
0
		public BaseQuery(AssemblyNode mainModule)
		{
			MainModule = mainModule;
		}
Exemplo n.º 59
0
 public virtual AssemblyNode VisitAssembly(AssemblyNode assembly, AssemblyNode changes, AssemblyNode deletions, AssemblyNode insertions){
   this.UpdateSourceContext(assembly, changes);
   if (assembly == null) return changes;
   if (changes != null){
     if (deletions == null || insertions == null)
       Debug.Assert(false);
     else{
       assembly.AssemblyReferences = this.VisitAssemblyReferenceList(assembly.AssemblyReferences, changes.AssemblyReferences, deletions.AssemblyReferences, insertions.AssemblyReferences);
       assembly.Attributes = this.VisitAttributeList(assembly.Attributes, changes.Attributes, deletions.Attributes, insertions.Attributes);
       assembly.Culture = changes.Culture;
       assembly.ExportedTypes = this.VisitTypeReferenceList(assembly.ExportedTypes, changes.ExportedTypes, deletions.ExportedTypes, insertions.ExportedTypes);
       assembly.Flags = changes.Flags;
       assembly.Kind = changes.Kind;
       assembly.ModuleAttributes = this.VisitAttributeList(assembly.ModuleAttributes, changes.ModuleAttributes, deletions.ModuleAttributes, insertions.ModuleAttributes);
       assembly.ModuleReferences = this.VisitModuleReferenceList(assembly.ModuleReferences, changes.ModuleReferences, deletions.ModuleReferences, insertions.ModuleReferences);
       assembly.Name = changes.Name;
       assembly.SecurityAttributes = this.VisitSecurityAttributeList(assembly.SecurityAttributes, changes.SecurityAttributes, deletions.SecurityAttributes, insertions.SecurityAttributes);
       assembly.Types = this.VisitTypeNodeList(assembly.Types, changes.Types, deletions.Types, insertions.Types);
       assembly.Version = changes.Version;
     }
   }else if (deletions != null)
     return null;
   return assembly;
 }
Exemplo n.º 60
0
 public virtual void VisitAssembly(AssemblyNode assembly)
 {
   if (assembly == null) return;
   this.VisitModule(assembly);
   this.VisitAttributeList(assembly.ModuleAttributes);
   this.VisitSecurityAttributeList(assembly.SecurityAttributes);
 }