Esempio n. 1
0
        // Called when the first new T() is detected.
        // This method is where we add worst-case-scenario
        // constructed types for those stategies.

        // t-devinc: Now that we don't do construct reachable types
        // this maybe doesn't make sense.
        private void NoteFirstTypeVariableConstructed()
        {
            IEnumerable <ITypeDefinition> potentialUniverse;

            switch (createInstanceStrategy)
            {
            case TypeVariableCreateInstanceStrategy.ConstructAll:
                potentialUniverse = wholeProgram.AllDefinedTypes();
                break;

            default:
                // do nothing
                potentialUniverse = new HashSet <ITypeDefinition>();
                break;
            }

            foreach (ITypeDefinition t in potentialUniverse)
            {
                if (GarbageCollectHelper.TypeIsConstructable(t))
                {
                    ConstructionFound(t);
                    // t-devinc: We should associate a reason with this!
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Finds all the com objects in a given namespace and marks the methods of their subclasses as reachable.
        ///
        /// Perhaps too blunt.
        /// </summary>
        /// <param name="wholeProgram"></param>
        /// <param name="namespacePrefix"></param>
        /// <returns></returns>
        internal static ReachabilitySummary COMSummary(WholeProgram wholeProgram, String namespacePrefix)
        {
            // The ToString() here is probably not the best idea.
            IEnumerable <ITypeDefinition> comInterfaces = wholeProgram.AllDefinedTypes().Where(type => type.IsComObject &&
                                                                                               type.IsInterface &&
                                                                                               type.ToString().StartsWith("Microsoft.Cci"));

            ReachabilitySummary summary = new ReachabilitySummary();

            foreach (ITypeDefinition comInterface in comInterfaces)
            {
                summary.ReachableTypes.Add(comInterface);

                foreach (ITypeDefinition subtype in wholeProgram.ClassHierarchy().AllSubClassesOfClass(comInterface))
                {
                    summary.ConstructedTypes.Add(subtype);

                    foreach (IMethodDefinition method in subtype.Methods)
                    {
                        summary.NonvirtuallyCalledMethods.Add(method);
                    }
                }
            }

            return(summary);
        }
    static void ConstructClassHierarchyForSources(string[] sources, ClassHierarchyResultDelegate resultDelegate) {
      // Each source is assumed to refer to all the sources before it

      CompileSourcesAndRun(sources, ".dll", compilerResult => {
        WholeProgram wholeProgram = new WholeProgram(new IAssembly[] { compilerResult.MainAssembly }, compilerResult.Host);

        ClassHierarchy classHierarchy = new ClassHierarchy(wholeProgram.AllDefinedTypes(), compilerResult.Host);

        resultDelegate(compilerResult, classHierarchy);
      });
    }
    /// <summary>
    /// Finds all the com objects in a given namespace and marks the methods of their subclasses as reachable.
    /// 
    /// Perhaps too blunt.
    /// </summary>
    /// <param name="wholeProgram"></param>
    /// <param name="namespacePrefix"></param>
    /// <returns></returns>
    internal static ReachabilitySummary COMSummary(WholeProgram wholeProgram, String namespacePrefix) {

      // The ToString() here is probably not the best idea.
      IEnumerable<ITypeDefinition> comInterfaces = wholeProgram.AllDefinedTypes().Where(type => type.IsComObject &&
                                                                                          type.IsInterface &&
                                                                                          type.ToString().StartsWith("Microsoft.Cci"));

      ReachabilitySummary summary = new ReachabilitySummary();

      foreach (ITypeDefinition comInterface in comInterfaces) {
        summary.ReachableTypes.Add(comInterface);

        foreach (ITypeDefinition subtype in wholeProgram.ClassHierarchy().AllSubClassesOfClass(comInterface)) {
          summary.ConstructedTypes.Add(subtype);

          foreach (IMethodDefinition method in subtype.Methods) {
            summary.NonvirtuallyCalledMethods.Add(method);
          }
        }
      }

      return summary;
    }