Example #1
0
        public static ITypeDefinition CheckAndAdd(ITypeDefinition t)
        {
            if (SuppressF(t))
            {
                return(null);
            }
            if (t is IGenericTypeInstance)
            {
                IGenericTypeInstance         gty     = t as IGenericTypeInstance;
                IEnumerable <ITypeReference> genArgs = gty.GenericArguments;
                foreach (ITypeReference garg in genArgs)
                {
                    CheckAndAdd(garg.ResolvedType);
                }
            }

            ITypeDefinition toAdd   = t;
            bool            matches = MatchesSuppressM(t);

            if (matches)
            {
                ITypeDefinition stubType = Stubs.GetStubType(t);
                if (stubType != null)
                {
                    toAdd = stubType;
                }
            }
            if (!rtaAnalyzer.visitedClasses.Contains(toAdd) && !rtaAnalyzer.classes.Contains(toAdd))
            {
                rtaAnalyzer.rtaLogSW.WriteLine("SRK_DBG: Adding class: {0}", toAdd.FullName());
                rtaAnalyzer.classes.Add(toAdd);
                rtaAnalyzer.classWorkList.Add(toAdd);
            }
            return(toAdd);
        }
Example #2
0
        private void ProcessGenericType(ITypeDefinition cl, StreamWriter classesSW,
                                        IModule mod, ISet <ITypeDefinition> processedTypes)
        {
            IGenericTypeInstance gcl = cl as IGenericTypeInstance;

            if (gcl != null && !processedTypes.Contains(gcl))
            {
                INamedTypeDefinition         templateType = gcl.GenericType.ResolvedType;
                IEnumerable <ITypeReference> genArgs      = gcl.GenericArguments;
                string argStr = "";
                foreach (ITypeReference ty in genArgs)
                {
                    ITypeDefinition tyDefn = ty.ResolvedType;
                    if (tyDefn is IGenericTypeInstance)
                    {
                        IModule mod1 = TypeHelper.GetDefiningUnit(tyDefn) as IModule;
                        ProcessGenericType(tyDefn, classesSW, mod1, processedTypes);
                    }
                    else
                    {
                        if (!processedTypes.Contains(tyDefn))
                        {
                            IModule mod1 = TypeHelper.GetDefiningUnit(tyDefn) as IModule;
                            classesSW.WriteLine("CLASS:" + tyDefn.FullName() + " ARGS:" + " MODULE:" + mod1.Name.Value);
                            processedTypes.Add(tyDefn);
                        }
                    }
                    argStr += tyDefn.FullName() + ";";
                }
                if (!argStr.Equals(""))
                {
                    argStr = argStr.TrimEnd(';');
                }

                IDictionary <string, ITypeDefinition> nestedTypeMap = new Dictionary <string, ITypeDefinition>();
                FillNestedTypeMap(gcl, nestedTypeMap, "", false);
                int nestedCnt = nestedTypeMap.Count;
                if (nestedCnt > 0)
                {
                    classesSW.WriteLine("CLASS:" + templateType.FullName() + " ARGS:" + argStr + " MODULE:" + mod.Name.Value +
                                        " NESTED_CNT:" + nestedCnt);
                }
                else
                {
                    classesSW.WriteLine("CLASS:" + templateType.FullName() + " ARGS:" + argStr + " MODULE:" + mod.Name.Value);
                }
                processedTypes.Add(gcl);
                foreach (KeyValuePair <string, ITypeDefinition> entry in nestedTypeMap)
                {
                    classesSW.WriteLine("CLASS:" + templateType.FullName() + " ARGS:" + argStr + " MODULE:" + mod.Name.Value +
                                        " NESTED_CLASS:" + entry.Key);
                    processedTypes.Add(entry.Value);
                }
            }
        }
Example #3
0
        static ITypeDefinition CreateGenericTypeInstance(IGenericTypeInstance gty, ITypeDefinition stubTemplate)
        {
            INamedTypeDefinition         nStubTemplate = stubTemplate as INamedTypeDefinition;
            IEnumerable <ITypeReference> genArgs       = gty.GenericArguments;
            GenericTypeInstanceReference stubbedGtyRef =
                new GenericTypeInstanceReference(stubTemplate as INamedTypeReference, genArgs, internFactory);
            ITypeDefinition stubbedGty = stubbedGtyRef.ResolvedType;

            NameToNameMap.Add(gty.FullName(), stubbedGty.FullName());
            NameToTypeDefMap.Add(stubbedGty.FullName(), stubbedGty);
            return(stubbedGty);
        }
Example #4
0
        private void NoteGenericParameterFlowForMethod(IMethodDefinition calledMethod)
        {
            // There are three ways generic parameters can flow
            //
            // 1) generic type parameters via a newobject constructor
            // 2) generic type parameters via a static call
            // 3) generic method parameters via a (non-constructor)method call

            // t-devinc:
            // I don't think this handles specialized types properly (i.e. a type some of whose parameters are instantiated
            // and some of whom are generic). This can happen with inner classes.


            // handle Foo<T>.DoSomething(); or new Foo<T>()
            if (calledMethod.ContainingTypeDefinition is IGenericTypeInstance && (calledMethod.IsStatic || calledMethod.IsConstructor))
            {
                IGenericTypeInstance instantiatedType = calledMethod.ContainingTypeDefinition as IGenericTypeInstance;

                ITypeDefinition genericType = instantiatedType.GenericType.ResolvedType;

                IEnumerable <ITypeReference> actuals = instantiatedType.GenericArguments;

                IEnumerable <IGenericParameter> formals = genericType.GenericParameters;

                NoteGenericParametersFlow(actuals, formals);
            }

            // handle Bar.DoSomething<T>();
            if (calledMethod is IGenericMethodInstance)
            {
                IGenericMethodInstance instantiatedMethod = calledMethod as IGenericMethodInstance;

                IMethodDefinition genericMethod = instantiatedMethod.GenericMethod.ResolvedMethod;

                IEnumerable <ITypeReference> actuals = instantiatedMethod.GenericArguments;

                IEnumerable <IGenericParameter> formals = genericMethod.GenericParameters;

                NoteGenericParametersFlow(actuals, formals);
            }
        }
Example #5
0
        public static ITypeDefinition GetStubType(ITypeDefinition ty)
        {
            ITypeDefinition stubTy = FindIfPresent(ty);

            if (stubTy != null)
            {
                return(stubTy);
            }

            if (ty is IGenericTypeInstance)
            {
                IGenericTypeInstance gty               = ty as IGenericTypeInstance;
                INamedTypeDefinition templateOfGty     = gty.GenericType.ResolvedType;
                ITypeDefinition      equivStubTemplate = FindIfPresent(templateOfGty);
                if (equivStubTemplate == null)
                {
                    return(null);
                }
                stubTy = CreateGenericTypeInstance(gty, equivStubTemplate);
                return(stubTy);
            }
            return(null);
        }
Example #6
0
 public static bool IsValueTuple(this IGenericTypeInstance genericType)
 {
     return(genericType.GenericType.FullName().StartsWith("System.ValueTuple"));
 }
Example #7
0
 private void AddTypeInstanceToFunction(ICommonFunctionNode func, IGenericTypeInstance gti)
 {
     List<IGenericTypeInstance> instances;
     bool found = instances_in_functions.TryGetValue(func, out instances);
     if (!found)
     {
         instances = new List<IGenericTypeInstance>();
         instances_in_functions.Add(func, instances);
     }
     if (!instances.Contains(gti))
     {
         instances.Add(gti);
     }
 }
Example #8
0
 private void ConvertGenericInstanceTypeMembers(IGenericTypeInstance value)
 {
     if (helper.GetTypeReference(value) == null)
     {
         return;
     }
     ICompiledGenericTypeInstance compiled_inst = value as ICompiledGenericTypeInstance;
     if (compiled_inst != null)
     {
         ConvertCompiledGenericInstanceTypeMembers(compiled_inst);
         return;
     }
     ICommonGenericTypeInstance common_inst = value as ICommonGenericTypeInstance;
     if (common_inst != null)
     {
         ConvertCommonGenericInstanceTypeMembers(common_inst);
         return;
     }
 }
Example #9
0
 private void AddTypeInstanceToFunction(ICommonFunctionNode func, IGenericTypeInstance gti)
 {
     List<IGenericTypeInstance> instances;
     //if (func == null) // SSM 3.07.16 Это решает проблему с оставшимся после перевода в сем. дерево узлом IEnumerable<UnknownType>, но очень грубо - пробую найти ошибку раньше
     //    return;
     bool found = instances_in_functions.TryGetValue(func, out instances);
     if (!found)
     {
         instances = new List<IGenericTypeInstance>();
         instances_in_functions.Add(func, instances);
     }
     if (!instances.Contains(gti))
     {
         instances.Add(gti);
     }
 }
Example #10
0
    public virtual IGenericTypeInstance VisitGenericTypeInstance(IGenericTypeInstance node)
    {
        if (node.Generic is TypeNode)
        {
            node.Generic = VisitTypeReference(node.Generic as TypeNode);
        }
        node.GenericArguments = VisitTypeNodeList(node.GenericArguments);

        return node;
    }