Example #1
0
        protected void ParseLibrary(params string[] files)
        {
            Options       = new DriverOptions();
            ParserOptions = new ParserOptions();

            var testsPath = GeneratorTest.GetTestsDirectory("Native");

            ParserOptions.AddIncludeDirs(testsPath);

            var module = Options.AddModule("Test");

            module.Headers.AddRange(files);

            Driver = new Driver(Options)
            {
                ParserOptions = this.ParserOptions
            };

            Driver.Setup();
            Driver.BuildParseOptions();
            if (!Driver.ParseCode())
            {
                throw new Exception("Error parsing the code");
            }

            AstContext = Driver.Context.ASTContext;
            new CleanUnitPass {
                Context = Driver.Context
            }.VisitASTContext(AstContext);
            new ResolveIncompleteDeclsPass {
                Context = Driver.Context
            }.VisitASTContext(AstContext);
        }
Example #2
0
        protected void ParseLibrary(params string[] files)
        {
            Options       = new DriverOptions();
            ParserOptions = new ParserOptions();

            var testsPath = GeneratorTest.GetTestsDirectory("Native");

            ParserOptions.AddIncludeDirs(testsPath);

            Options.Headers.AddRange(files);

            Driver = new Driver(Options)
            {
                ParserOptions = this.ParserOptions
            };

            foreach (var module in Driver.Options.Modules)
            {
                module.LibraryName = "Test";
            }
            Driver.Setup();
            Driver.BuildParseOptions();
            if (!Driver.ParseCode())
            {
                throw new Exception("Error parsing the code");
            }

            AstContext = Driver.Context.ASTContext;
        }
Example #3
0
        public async Task GeneratesEnableModuleAttributesForAllModules()
        {
            StringBuilder builder = new();

            foreach (DurianModule module in ModuleIdentity.GetAllModules().AsEnums())
            {
                builder
                .Append("[assembly: Durian.Generator.EnableModule(Durian.Info.")
                .Append(nameof(DurianModule))
                .Append('.')
                .Append(module.ToString())
                .AppendLine(")]");
            }

            CSharpSyntaxTree expected = (CSharpSyntaxTree)CSharpSyntaxTree.ParseText(builder.ToString());

            CSharpCompilation      compilation = RoslynUtilities.CreateBaseCompilation();
            DisabledModuleAnalyzer analyzer    = new();
            await analyzer.RunAnalyzer(compilation);

            SingletonGeneratorTestResult result = GeneratorTest.RunGenerator("", analyzer);

            Assert.True(result.IsGenerated);
            Assert.NotNull(result.SyntaxTree);
            Assert.True(result.SyntaxTree !.IsEquivalentTo(expected));
        }
Example #4
0
        private static IList <string> GetSymbols(string library)
        {
            var    driverOptions = new DriverOptions();
            Module module        = driverOptions.AddModule("Test");

            module.LibraryDirs.Add(GeneratorTest.GetTestsDirectory("Native"));
            module.Libraries.Add(library);
            using (var driver = new Driver(driverOptions))
            {
                driver.Setup();
                Assert.IsTrue(driver.ParseLibraries());
                return(driver.Context.Symbols.Libraries[0].Symbols);
            }
        }
Example #5
0
        public void TestReadDependenciesWindows()
        {
            var driverOptions = new DriverOptions();

            driverOptions.addLibraryDirs(GeneratorTest.GetTestsDirectory("Native"));
            driverOptions.Libraries.Add("ls-windows");
            var driver = new Driver(driverOptions, new TextDiagnosticPrinter());

            Assert.IsTrue(driver.ParseLibraries());
            var dependencies = driver.Symbols.Libraries[0].Dependencies;

            Assert.AreEqual("msys-intl-8.dll", dependencies[0]);
            Assert.AreEqual("msys-2.0.dll", dependencies[1]);
            Assert.AreEqual("KERNEL32.dll", dependencies[2]);
        }
Example #6
0
        public void TestReadDependenciesOSX()
        {
            var driverOptions = new DriverOptions();

            driverOptions.addLibraryDirs(GeneratorTest.GetTestsDirectory("Native"));
            driverOptions.Libraries.Add("ls-osx");
            var driver = new Driver(driverOptions, new TextDiagnosticPrinter());

            Assert.IsTrue(driver.ParseLibraries());
            var dependencies = driver.Symbols.Libraries[0].Dependencies;

            Assert.AreEqual("libutil.dylib", dependencies[0]);
            Assert.AreEqual("libncurses.5.4.dylib", dependencies[1]);
            Assert.AreEqual("libSystem.B.dylib", dependencies[2]);
        }
Example #7
0
        public void TestReadDependenciesLinux()
        {
            var driverOptions = new DriverOptions();

            driverOptions.addLibraryDirs(GeneratorTest.GetTestsDirectory("Native"));
            driverOptions.Libraries.Add("ls-linux");
            var driver = new Driver(driverOptions, new TextDiagnosticPrinter());

            Assert.IsTrue(driver.ParseLibraries());
            var dependencies = driver.Symbols.Libraries[0].Dependencies;

            Assert.AreEqual("libselinux.so.1", dependencies[0]);
            Assert.AreEqual("librt.so.1", dependencies[1]);
            Assert.AreEqual("libacl.so.1", dependencies[2]);
            Assert.AreEqual("libc.so.6", dependencies[3]);
        }
Example #8
0
        protected void ParseLibrary(params string[] files)
        {
            if (files.Length == 0)
            {
                return;
            }

            var options = new DriverOptions {
                GeneratorKind = GeneratorKind.CSharp
            };

            var module = options.AddModule("Test");

            module.IncludeDirs.Add(GeneratorTest.GetTestsDirectory("Native"));
            module.Headers.AddRange(files);

            Driver = new Driver(options)
            {
                ParserOptions = new ParserOptions {
                    SkipPrivateDeclarations = true
                }
            };

            Driver.Setup();
            if (!Driver.ParseCode())
            {
                throw new Exception("Error parsing the code");
            }

            Driver.SetupTypeMaps();
            AstContext = Driver.Context.ASTContext;
            new CleanUnitPass {
                Context = Driver.Context
            }.VisitASTContext(AstContext);
            new ResolveIncompleteDeclsPass {
                Context = Driver.Context
            }.VisitASTContext(AstContext);

            Context          = new BindingContext(options, Driver.ParserOptions);
            Context.TypeMaps = new Types.TypeMapDatabase(Context);

            CppSharp.AST.Type.TypePrinterDelegate = type =>
            {
                PrimitiveType primitiveType;
                return(type.IsPrimitiveType(out primitiveType) ? primitiveType.ToString() : string.Empty);
            };
        }
Example #9
0
        protected void ParseLibrary(params string[] files)
        {
            Options = new DriverOptions();

            var testsPath = GeneratorTest.GetTestsDirectory("Native");

            Options.addIncludeDirs(testsPath);

            Options.Headers.AddRange(files);

            Driver = new Driver(Options, new TextDiagnosticPrinter());
            Driver.BuildParseOptions();
            if (!Driver.ParseCode())
            {
                throw new Exception("Error parsing the code");
            }

            AstContext = Driver.ASTContext;
        }
Example #10
0
        private static IList <string> GetSymbols(string library)
        {
            var parserOptions = new ParserOptions();

            parserOptions.AddLibraryDirs(GeneratorTest.GetTestsDirectory("Native"));
            var driverOptions = new DriverOptions();
            var module        = driverOptions.AddModule("Test");

            module.Libraries.Add(library);
            var driver = new Driver(driverOptions)
            {
                ParserOptions = parserOptions
            };

            driver.Setup();
            Assert.IsTrue(driver.ParseLibraries());
            var symbols = driver.Context.Symbols.Libraries[0].Symbols;

            return(symbols);
        }
Example #11
0
        protected void ParseLibrary(string file)
        {
            Options = new DriverOptions();

            var testsPath = GeneratorTest.GetTestsDirectory("Native");

#if OLD_PARSER
            Options.IncludeDirs.Add(testsPath);
#else
            Options.addIncludeDirs(testsPath);
#endif

            Options.Headers.Add(file);

            Driver = new Driver(Options, new TextDiagnosticPrinter());
            if (!Driver.ParseCode())
            {
                throw new Exception("Error parsing the code");
            }

            AstContext = Driver.ASTContext;
        }
        private static IList <string> GetDependencies(string library)
        {
            var parserOptions = new ParserOptions();

            parserOptions.addLibraryDirs(GeneratorTest.GetTestsDirectory("Native"));
            var driverOptions = new DriverOptions();

            driverOptions.Libraries.Add(library);
            var driver = new Driver(driverOptions, new TextDiagnosticPrinter())
            {
                ParserOptions = parserOptions
            };

            foreach (var module in driver.Options.Modules)
            {
                module.LibraryName = "Test";
            }
            driver.Setup();
            Assert.IsTrue(driver.ParseLibraries());
            var dependencies = driver.Context.Symbols.Libraries[0].Dependencies;

            return(dependencies);
        }
Example #13
0
        protected void ParseLibrary(params string[] files)
        {
            var options = new DriverOptions {
                GeneratorKind = GeneratorKind.CSharp
            };
            var parserOptions = new ParserOptions();

            var testsPath = GeneratorTest.GetTestsDirectory("Native");

            parserOptions.AddIncludeDirs(testsPath);
            parserOptions.SkipPrivateDeclarations = true;

            var module = options.AddModule("Test");

            module.Headers.AddRange(files);

            Driver = new Driver(options)
            {
                ParserOptions = parserOptions
            };

            Driver.Setup();
            if (!Driver.ParseCode())
            {
                throw new Exception("Error parsing the code");
            }

            Driver.SetupTypeMaps();
            AstContext = Driver.Context.ASTContext;
            new CleanUnitPass {
                Context = Driver.Context
            }.VisitASTContext(AstContext);
            new ResolveIncompleteDeclsPass {
                Context = Driver.Context
            }.VisitASTContext(AstContext);
        }