Exemple #1
0
        public VirtualMethodTableCodeWriter(VirtualMethodTable typeTable, List <MethodInterpreter> closure)
        {
            _typeTable = typeTable;
            var methodNames = GetAllMethodNames(closure);

            _validVirtualMethods = CalculateValidVirtualMethods(typeTable, methodNames);
        }
        public static StringBuilder GenerateSourceStringBuilder(MethodInterpreter interpreter, List <Type> typeClosure,
                                                                List <MethodInterpreter> closure,
                                                                VirtualMethodTable typeTable, CrRuntimeLibrary crRuntime)
        {
            var sb = new StringBuilder();

            sb.AppendLine("#include \"sloth.h\"");

            var virtualMethodTableCodeWriter = new VirtualMethodTableCodeWriter(typeTable, closure);

            WriteClosureStructBodies(typeClosure.ToArray(), sb, crRuntime);
            WriteClosureDelegateBodies(closure, sb);
            WriteClosureHeaders(closure, sb, crRuntime);

            sb.AppendLine("#include \"runtime_base.hpp\"");

            sb.AppendLine(virtualMethodTableCodeWriter.GenerateTypeTableCode());
            WriteCppMethods(closure, sb);
            WriteClosureMethods(closure, sb, typeTable.TypeTable, crRuntime);

            WriteMainBody(interpreter, sb);
            sb.AppendLine(PlatformInvokeCodeWriter.LoadDllMethods());
            sb.AppendLine(ConstByteArrayList.BuildConstantTable());
            sb.AppendLine(LinkingData.Instance.Strings.BuildStringTable());

            return(sb);
        }
 private void BuildVirtualMethodTable(TypeDescriptionTable typeTable,
                                      Dictionary <MethodInterpreterKey, MethodInterpreter> methodClosure)
 {
     _virtualMethodTable = new VirtualMethodTable(typeTable);
     foreach (var type in _typeDictionary.Keys)
     {
         var methods = type.GetMethods();
         foreach (var method in methods)
         {
             _virtualMethodTable.RegisterMethod(method, methodClosure);
         }
     }
 }
Exemple #4
0
        public static List <VirtualMethodDescription> CalculateValidVirtualMethods(VirtualMethodTable typeTable,
                                                                                   HashSet <string> methodNames)
        {
            var validVirtMethods = new List <VirtualMethodDescription>();

            foreach (var virtualMethod in typeTable.VirtualMethods)
            {
                if (!methodNames.Contains(virtualMethod.Name))
                {
                    continue;
                }
                var implementations = virtualMethod.UsingImplementations
                                      .Where(type => typeTable.TypeTable.HasType(type))
                                      .ToList();
                if (implementations.Count != 0)
                {
                    validVirtMethods.Add(virtualMethod);
                }
            }
            return(validVirtMethods);
        }