예제 #1
0
        public static bool RunTest()
        {
            var obj     = new VirtualMethods();
            var objBase = (VirtualMethods_Base)obj;

            return(obj.VirtualFoo(true) && obj.AbstractFoo(true) && objBase.VirtualFoo(true) && objBase.AbstractFoo(true));
        }
예제 #2
0
 public void RegisterVirtualMethod(CheckedFunctionDeclStatement method)
 {
     if (VirtualMethods == null)
     {
         VirtualMethods = new();
     }
     method.IndexInVirtualMethodTable = VirtualMethods.Count;
     VirtualMethods.Add(method);
 }
예제 #3
0
 public void testDegenerifyMethodName()
 {
     Assert.AreEqual(
         "TestData.IExplicitGenInterface`1.identity",
         VirtualMethods.degenerifyMethodName("TestData.IExplicitGenInterface<A>.identity")
         );
     Assert.AreEqual(
         "TestData.IExplicitGenInterface`2.identity",
         VirtualMethods.degenerifyMethodName("TestData.IExplicitGenInterface<A,B>.identity")
         );
     Assert.AreEqual(
         "TestData.IExplicitGenInterface`2.identity",
         VirtualMethods.degenerifyMethodName("TestData.IExplicitGenInterface<A, B>.identity")
         );
     Assert.AreEqual(
         "TestData.IExplicitGenInterface`3.identity",
         VirtualMethods.degenerifyMethodName("TestData.IExplicitGenInterface<A, B, C>.identity")
         );
     Assert.AreEqual(
         "TestData.IExplicitInterface.identity",
         VirtualMethods.degenerifyMethodName("TestData.IExplicitInterface.identity")
         );
 }
예제 #4
0
        static int Main(string[] args)
        {
            // print args
            Console.WriteLine("Printing args...");
            foreach (string arg in args)
            {
                Console.WriteLine("Arg: " + arg);
            }
            Console.WriteLine();

            // run basic tests
            Console.WriteLine("Running tests...");
            Log(ClassNesting.RunTest(), "ClassNesting");
            Log(ClassVsStruct.RunTest(), "ClassVsStruct");
            Log(Enums.RunTest(), "Enums");
            Log(RefOutParameters.RunTest(), "RefOutParameters");
            Log(FieldsAndProperties.RunTest(), "FieldsAndProperties");
            Log(FlowControlAndEnumerators.RunTest(), "FlowControlAndEnumerators");
            Log(ExtensionMethods.RunTest(), "ExtensionMethods");
            Log(Destructors.RunTest(), "Destructors");
            Log(TryCatch.RunTest(), "TryCatch");
            Log(Interop.RunTest(), "Interop");
            Log(VirtualMethods.RunTest(), "VirtualMethods");
            Log(Generics.RunTest(), "Generics");
            Log(Delegates.RunTest(), "Delegates");
            Log(Indexers.RunTest(), "Indexers");
            Log(Operators.RunTest(), "Operators");
            Log(StringEncoding.RunTest(), "StringEncoding");
            Log(CoreGenericCollections.RunTest(), "CoreGenericCollections");
            Log(NewOverrides.RunTest(), "NewOverrides");
            Log(NumbersToStrings.RunTest(), "NumbersToStrings");
            Console.WriteLine("TESTS DONE!");

            // return result code
            return(99);
        }
예제 #5
0
        public static AnalyzerData analyze(
            IEnumerable <MethodDefinition> entryPoints,
            AnalyserLogger log
            )
        {
            var data = new AnalyzerData(
                ImmutableHashSet <ExpandedType> .Empty, ImmutableHashSet <ExpandedMethod> .Empty,
                ImmutableHashSet <VirtualMethod> .Empty, ImmutableHashSet <VirtualMethod> .Empty
                );

            foreach (var entryMethod in entryPoints)
            {
                var exEntryMethod = ExpandedMethod.create(
                    entryMethod, ExpandedType.EMPTY_GENERIC_LOOKUP
                    );
                data = data.addType(exEntryMethod.declaringType);
                if (!data.hasMethod(exEntryMethod))
                {
                    log.log("Entry", exEntryMethod);
                    data = analyze(data, exEntryMethod, log);
                }
            }

            // Once we know all used types, resolve the called virtual methods.
            // Iterate in a loop because expanding virtual method bodies might invoke additional
            // virtual methods.
            while (!data.virtualMethodsToAnalyze.IsEmpty)
            {
                foreach (var virtualMethod in data.virtualMethodsToAnalyze)
                {
                    var declaring = virtualMethod.method.declaringType;
                    foreach (var _usedType in data.usedTypes.Where(et => et.implements(declaring)))
                    {
                        var usedType = _usedType;
                        MethodDefinition matching = null;
                        while (matching == null)
                        {
                            matching = VirtualMethods.GetMethod(
                                usedType.definition.Methods, virtualMethod.method.definition
                                );
                            if (matching == null)
                            {
                                if (usedType.definition.BaseType == null)
                                {
                                    throw new Exception(
                                              "Can't find implementation for [" + virtualMethod + "] in [" + _usedType + "]!"
                                              );
                                }
                                usedType = ExpandedType.create(
                                    usedType.definition.BaseType,
                                    usedType.genericParametersToArguments
                                    );
                            }
                        }

                        var generics = usedType.genericParametersToArguments.AddRange(
                            ExpandedMethod.genericArgumentsDict(
                                virtualMethod.method.genericArguments.Select(t => (TypeReference)t.definition).ToList(),
                                matching.GenericParameters,
                                usedType.genericParametersToArguments
                                )
                            );
                        var exMatching = new ExpandedMethod(
                            virtualMethod.method.returnType, usedType, matching,
                            virtualMethod.method.genericArguments,
                            virtualMethod.method.parameters, generics
                            );
                        data = analyze(data, exMatching, log);
                    }
                    data = data.analyzedVirtualMethod(virtualMethod);
                }
            }
            return(data);
        }