Пример #1
0
 public TypeIgnoreChecker(ITypeMapDatabase database,
                          GeneratorKind generatorKind = GeneratorKind.CSharp)
 {
     TypeMapDatabase = database;
     VisitOptions.ClearFlags(VisitFlags.ClassBases | VisitFlags.TemplateArguments);
     this.generatorKind = generatorKind;
 }
Пример #2
0
 public ParserGen(GeneratorKind kind, string triple,
                  bool isGnuCpp11Abi = false)
 {
     Kind          = kind;
     Triple        = triple;
     IsGnuCpp11Abi = isGnuCpp11Abi;
 }
        private TypePrinter GetTypePrinter(GeneratorKind kind, BindingContext context)
        {
            TypePrinter typePrinter;

            switch (kind)
            {
            case GeneratorKind.C:
                typePrinter = new CppTypePrinter(Context)
                {
                    PrintFlavorKind = CppTypePrintFlavorKind.C
                };
                break;

            case GeneratorKind.CPlusPlus:
            case GeneratorKind.QuickJS:
            case GeneratorKind.NAPI:
            case GeneratorKind.TypeScript:
                typePrinter = new CppTypePrinter(Context);
                break;

            case GeneratorKind.CLI:
                typePrinter = new CLITypePrinter(Context);
                break;

            case GeneratorKind.CSharp:
                typePrinter = new CSharpTypePrinter(Context);
                break;

            default:
                throw new System.NotImplementedException();
            }

            return(typePrinter);
        }
Пример #4
0
        Generator CreateGeneratorFromKind(GeneratorKind kind)
        {
            switch (kind)
            {
            case GeneratorKind.C:
                return(new CGenerator(Context));

            case GeneratorKind.CPlusPlus:
                return(new CppGenerator(Context));

            case GeneratorKind.CLI:
                return(new CLIGenerator(Context));

            case GeneratorKind.CSharp:
                return(new CSharpGenerator(Context));

            case GeneratorKind.QuickJS:
                return(new QuickJSGenerator(Context));

            case GeneratorKind.NAPI:
                return(new NAPIGenerator(Context));
            }

            throw new NotImplementedException();
        }
Пример #5
0
        public static Type GetMappedType(this Type type, TypeMapDatabase typeMaps,
                                         GeneratorKind generatorKind)
        {
            TypeMap typeMap;

            if (typeMaps.FindTypeMap(type, out typeMap))
            {
                var typePrinterContext = new TypePrinterContext
                {
                    Kind = TypePrinterContextKind.Managed,
                    Type = typeMap.Type
                };

                switch (generatorKind)
                {
                case GeneratorKind.CLI:
                    return(typeMap.CLISignatureType(typePrinterContext).Desugar());

                case GeneratorKind.CSharp:
                    return(typeMap.CSharpSignatureType(typePrinterContext).Desugar());
                }
            }

            return(type.Desugar());
        }
Пример #6
0
        public DriverOptions()
        {
            Headers = new List<string>();
            Libraries = new List<string>();

            Abi = IsUnixPlatform ? CppAbi.Itanium : CppAbi.Microsoft;
            MicrosoftMode = !IsUnixPlatform;

            OutputDir = Directory.GetCurrentDirectory();
            Libraries = new List<string>();
            CheckSymbols = false;

            GeneratorKind = GeneratorKind.CSharp;
            GenerateLibraryNamespace = true;
            GeneratePartialClasses = true;
            GenerateClassMarshals = false;
            OutputInteropIncludes = true;
            MaxIndent = 80;
            CommentPrefix = "///";

            Encoding = Encoding.ASCII;

            CodeFiles = new List<string>();

            Is32Bit = true;
            #if IS_64_BIT
            Is32Bit = false;
            #endif
        }
Пример #7
0
 public ParserGen(GeneratorKind kind, string triple, CppAbi abi,
     bool isGnuCpp11Abi = false)
 {
     Kind = kind;
     Triple = triple;
     Abi = abi;
     IsGnuCpp11Abi = isGnuCpp11Abi;
 }
Пример #8
0
 public TypeIgnoreChecker(ITypeMapDatabase database,
                          GeneratorKind generatorKind = GeneratorKind.CSharp)
 {
     TypeMapDatabase = database;
     VisitOptions.VisitClassBases        = false;
     VisitOptions.VisitTemplateArguments = false;
     this.generatorKind = generatorKind;
 }
Пример #9
0
        internal IteratorInstance GetIterator(Realm realm, GeneratorKind hint = GeneratorKind.Sync, ICallable method = null)
        {
            if (!TryGetIterator(realm, out var iterator, hint, method))
            {
                ExceptionHelper.ThrowTypeError(realm, "The value is not iterable");
            }

            return(iterator);
        }
Пример #10
0
        public void SetupTypeMaps(GeneratorKind generatorKind)
        {
            var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies();

            foreach (var assembly in loadedAssemblies)
            {
                var types = assembly.FindDerivedTypes(typeof(TypeMap));
                SetupTypeMaps(types, generatorKind);
            }
        }
Пример #11
0
        protected TestsGenerator(string name, GeneratorKind languageKind)
        {
            this.name = name;

            options          = new Options();
            options.Language = languageKind;
            driver           = new Driver(options);

            Setup();
        }
Пример #12
0
        public static CManagedToNativeTypePrinter GetCTypePrinter(GeneratorKind kind)
        {
            var typePrinter = new CManagedToNativeTypePrinter
            {
                PrintScopeKind  = TypePrintScopeKind.Qualified,
                PrintFlavorKind = GetTypePrinterFlavorKind(kind),
                PrintVariableArrayAsPointers = true
            };

            return(typePrinter);
        }
Пример #13
0
        protected TestsGenerator(string name, GeneratorKind languageKind)
        {
            this.name = name;

            options = new Options();
            options.GeneratorKind = languageKind;
            project = new Project();
            driver  = new Driver(project, options);

            Setup();
        }
Пример #14
0
        Generator CreateGeneratorFromKind(GeneratorKind kind)
        {
            switch (kind)
            {
                case GeneratorKind.CLI:
                    return new CLIGenerator(this);
                case GeneratorKind.CSharp:
                    return new CSharpGenerator(this);
            }

            return null;
        }
Пример #15
0
        Generator CreateGeneratorFromKind(GeneratorKind kind)
        {
            switch (kind)
            {
            case GeneratorKind.CLI:
                return(new CLIGenerator(Context));

            case GeneratorKind.CSharp:
                return(new CSharpGenerator(Context));
            }

            return(null);
        }
Пример #16
0
        private static string GetGeneratorKindName(GeneratorKind kind)
        {
            switch (kind)
            {
            case GeneratorKind.CLI:
                return("C++/CLI");

            case GeneratorKind.CSharp:
                return("C#");

            default:
                return(kind.ToString());
            }
        }
Пример #17
0
 private void SetupTypeMaps(IEnumerable <System.Type> types, GeneratorKind generatorKind)
 {
     foreach (var typeMap in types)
     {
         var attrs = typeMap.GetCustomAttributes(typeof(TypeMapAttribute), true);
         foreach (TypeMapAttribute attr in attrs)
         {
             if (attr.GeneratorKind == null || attr.GeneratorKind == generatorKind)
             {
                 TypeMaps[attr.Type] = typeMap;
             }
         }
     }
 }
Пример #18
0
        private static CppTypePrintFlavorKind GetTypePrinterFlavorKind(GeneratorKind kind)
        {
            switch (kind)
            {
            case GeneratorKind.C:
                return(CppTypePrintFlavorKind.C);

            case GeneratorKind.CPlusPlus:
                return(CppTypePrintFlavorKind.Cpp);

            case GeneratorKind.ObjectiveC:
                return(CppTypePrintFlavorKind.ObjC);
            }

            throw new NotImplementedException();
        }
Пример #19
0
        internal bool TryGetIterator(Realm realm, out IteratorInstance iterator, GeneratorKind hint = GeneratorKind.Sync, ICallable method = null)
        {
            var obj = TypeConverter.ToObject(realm, this);

            if (method is null)
            {
                if (hint == GeneratorKind.Async)
                {
                    method = obj.GetMethod(GlobalSymbolRegistry.AsyncIterator);
                    if (method is null)
                    {
                        var syncMethod         = obj.GetMethod(GlobalSymbolRegistry.Iterator);
                        var syncIteratorRecord = obj.GetIterator(realm, GeneratorKind.Sync, syncMethod);
                        // TODO async CreateAsyncFromSyncIterator(syncIteratorRecord);
                        ExceptionHelper.ThrowNotImplementedException("async");
                    }
                }
                else
                {
                    method = obj.GetMethod(GlobalSymbolRegistry.Iterator);
                }
            }

            if (method is null)
            {
                iterator = null;
                return(false);
            }

            var iteratorResult = method.Call(obj, Arguments.Empty) as ObjectInstance;

            if (iteratorResult is null)
            {
                ExceptionHelper.ThrowTypeError(realm, "Result of the Symbol.iterator method is not an object");
            }

            if (iteratorResult is IteratorInstance i)
            {
                iterator = i;
            }
            else
            {
                iterator = new IteratorInstance.ObjectIterator(iteratorResult);
            }

            return(true);
        }
Пример #20
0
        private void RunButton_Click(object sender, EventArgs e)
        {
            if (module != null)
            {
                GeneratorKind mode = GeneratorKind.CSharp;

                if (radioButton4.Checked)
                {
                    mode = GeneratorKind.CSharp;
                }
                if (radioButton5.Checked)
                {
                    mode = GeneratorKind.CLI;
                }
                if (radioButton6.Checked)
                {
                    mode = GeneratorKind.C;
                }
                if (radioButton7.Checked)
                {
                    mode = GeneratorKind.CPlusPlus;
                }
                if (radioButton8.Checked)
                {
                    mode = GeneratorKind.ObjectiveC;
                }
                if (radioButton9.Checked)
                {
                    mode = GeneratorKind.Java;
                }

                // std.cs生成
                File.Copy(Application.StartupPath + @"\Std.cs", bindPath + @"\Std.cs", true);
                // SymbolResolver.cs生成
                File.Copy(Application.StartupPath + @"\SymbolResolver.cs", bindPath + @"\SymbolResolver.cs", true);


                var builder = new BuildLib(module, mode);
                ConsoleDriver.Run(builder);
            }

            Process.Start(bindPath);

            module = null;

            Environment.Exit(0);
        }
Пример #21
0
 public TypeMapDatabase(ASTContext astContext, GeneratorKind generatorKind)
 {
     TypeMaps = new Dictionary <string, TypeMap>();
     foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
     {
         try
         {
             var types = assembly.FindDerivedTypes(typeof(TypeMap));
             SetupTypeMaps(types, generatorKind, astContext);
         }
         catch (System.Reflection.ReflectionTypeLoadException ex)
         {
             Diagnostics.Error("Error loading type maps from assembly '{0}': {1}",
                               assembly.GetName().Name, ex.Message);
         }
     }
 }
Пример #22
0
        public virtual Type SignatureType(GeneratorKind kind, TypePrinterContext ctx)
        {
            switch (kind)
            {
            case GeneratorKind.CPlusPlus:
                return(CppSignatureType(ctx));

            case GeneratorKind.CLI:
                return(CLISignatureType(ctx));

            case GeneratorKind.CSharp:
                return(CSharpSignatureType(ctx));

            default:
                throw new System.NotImplementedException();
            }
        }
Пример #23
0
        static bool GetGeneratorKindFromLang(string lang, out GeneratorKind kind)
        {
            kind = GeneratorKind.CSharp;

            switch (lang)
            {
            case "CSharp":
            case "C#":
                kind = GeneratorKind.CSharp;
                return(true);

            case "CLI":
                kind = GeneratorKind.CLI;
                return(true);
            }

            return(false);
        }
Пример #24
0
        public void SetupTypeMaps(GeneratorKind generatorKind)
        {
            var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies();

            foreach (var assembly in loadedAssemblies)
            {
                try
                {
                    var types = assembly.FindDerivedTypes(typeof(TypeMap));
                    SetupTypeMaps(types, generatorKind);
                }
                catch (System.Reflection.ReflectionTypeLoadException ex)
                {
                    Diagnostics.Error("Error loading type maps from assembly '{0}': {1}",
                                      assembly.GetName().Name, ex.Message);
                }
            }
        }
Пример #25
0
 private void SetupTypeMaps(IEnumerable <System.Type> types,
                            GeneratorKind generatorKind, ASTContext astContext)
 {
     foreach (var type in types)
     {
         var attrs = type.GetCustomAttributes(typeof(TypeMapAttribute), true);
         foreach (TypeMapAttribute attr in attrs)
         {
             if (attr.GeneratorKind == 0 || attr.GeneratorKind == generatorKind)
             {
                 var typeMap = (TypeMap)Activator.CreateInstance(type);
                 typeMap.ASTContext       = astContext;
                 typeMap.TypeMapDatabase  = this;
                 this.TypeMaps[attr.Type] = typeMap;
             }
         }
     }
 }
Пример #26
0
        public virtual void MarshalToNative(GeneratorKind kind, MarshalContext ctx)
        {
            switch (kind)
            {
            case GeneratorKind.CPlusPlus:
                CppMarshalToNative(ctx);
                return;

            case GeneratorKind.CLI:
                CLIMarshalToNative(ctx);
                return;

            case GeneratorKind.CSharp:
                CSharpMarshalToNative(ctx as CSharpMarshalContext);
                return;

            default:
                throw new System.NotImplementedException();
            }
        }
Пример #27
0
 private void SetupTypeMaps(IEnumerable<System.Type> types, GeneratorKind generatorKind)
 {
     foreach (var typeMap in types)
     {
         var attrs = typeMap.GetCustomAttributes(typeof(TypeMapAttribute), true);
         foreach (TypeMapAttribute attr in attrs)
         {
             if (attr.GeneratorKind == 0 || attr.GeneratorKind == generatorKind)
             {
                 TypeMaps[attr.Type] = typeMap;
             }
         }
     }
 }
Пример #28
0
 public TypeMapAttribute(string type, GeneratorKind generatorKind)
 {
     Type = type;
     GeneratorKind = generatorKind;
 }
Пример #29
0
 public NamespacesBaseTests(GeneratorKind kind)
     : base("NamespacesBase", kind)
 {
 }
Пример #30
0
 public ParserGen(GeneratorKind kind, string triple, CppAbi abi)
 {
     Kind   = kind;
     Triple = triple;
     Abi    = abi;
 }
Пример #31
0
 public NamespacesDerivedTests(GeneratorKind kind)
     : base("NamespacesDerived", kind)
 {
 }
Пример #32
0
 protected GeneratorTest(string name, GeneratorKind kind)
 {
     this.name = name;
     this.kind = kind;
 }
Пример #33
0
 public CommonTestsGenerator(GeneratorKind kind)
     : base("Common", kind)
 {
 }
Пример #34
0
        public DriverOptions()
        {
            Abi = IsUnixPlatform ? CppAbi.Itanium : CppAbi.Microsoft;
            MicrosoftMode = !IsUnixPlatform;

            OutputDir = Directory.GetCurrentDirectory();

            Modules = new List<Module>();

            GeneratorKind = GeneratorKind.CSharp;
            GeneratePartialClasses = true;
            GenerateClassMarshals = false;
            OutputInteropIncludes = true;
            MaxIndent = 80;
            CommentPrefix = "///";

            Encoding = Encoding.ASCII;

            StripLibPrefix = true;

            ExplicitlyPatchedVirtualFunctions = new HashSet<string>();
        }
Пример #35
0
 public EncodingsTestsGenerator(GeneratorKind kind)
     : base("Encodings", kind)
 {
 }
Пример #36
0
 public VTableTests(GeneratorKind kind)
     : base("VTables", kind)
 {
 }
Пример #37
0
 public STL(GeneratorKind kind)
     : base("STL", kind)
 {
 }
Пример #38
0
        public void SetupTypeMaps(GeneratorKind generatorKind)
        {
            var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies();

            foreach (var assembly in loadedAssemblies)
            {
                var types = assembly.FindDerivedTypes(typeof(TypeMap));
                SetupTypeMaps(types, generatorKind);
            }
        }
Пример #39
0
 public TypeMapAttribute(string type, GeneratorKind generatorKind)
 {
     Type          = type;
     GeneratorKind = generatorKind;
 }
Пример #40
0
        static bool GetGeneratorKindFromLang(string lang, out GeneratorKind kind)
        {
            kind = GeneratorKind.CSharp;

            switch(lang)
            {
            case "CSharp":
            case "C#":
                kind = GeneratorKind.CSharp;
                return true;
            case "CLI":
                kind = GeneratorKind.CLI;
                return true;
            }

            return false;
        }
Пример #41
0
 public CLITestsGenerator(GeneratorKind kind)
     : base("CLI", kind)
 {
 }
Пример #42
0
        public CommonTestsGenerator(GeneratorKind kind)
            : base("Common", kind)
        {

        }
Пример #43
0
 public CSharpTestsGenerator(GeneratorKind kind)
     : base("CSharp", kind)
 {
 }
Пример #44
0
 public CSharpTempTests(GeneratorKind kind)
     : base("CSharpTemp", kind)
 {
 }
Пример #45
0
 public CLITemp(GeneratorKind kind)
     : base("CLITemp", kind)
 {
 }
Пример #46
0
 public TypeMaps(GeneratorKind kind)
     : base("TypeMaps", kind)
 {
 }
Пример #47
0
 public VTableTests(GeneratorKind kind)
     : base("VTables", kind)
 {
 }
Пример #48
0
 public ParserGen(GeneratorKind kind, string triple, CppAbi abi)
 {
     Kind = kind;
     Triple = triple;
     Abi = abi;
 }
Пример #49
0
 public Basic(GeneratorKind kind)
     : base("Basic", kind)
 {
 }
Пример #50
0
 public StandardLibTestsGenerator(GeneratorKind kind)
     : base("StandardLib", kind)
 {
 }
Пример #51
0
 public NamespacesDerivedTests(GeneratorKind kind)
     : base("NamespacesDerived", kind)
 {
 }
Пример #52
0
 protected GeneratorTest(string name, GeneratorKind kind)
 {
     this.name = name;
     this.kind = kind;
 }
Пример #53
0
 public EmptyTestsGenerator(GeneratorKind kind)
     : base("Empty", kind)
 {
 }
Пример #54
0
 public UTF16Tests(GeneratorKind kind)
     : base("UTF16", kind)
 {
 }
Пример #55
0
 public ParserGen(GeneratorKind kind)
 {
     Kind = kind;
 }