コード例 #1
0
        protected MetaCompilation Compile(string filePath, bool assertEmptyDiagnostics = true, bool compileMetaModelCore = false)
        {
            MetaDescriptor.Initialize();
            string text = File.ReadAllText(filePath);
            var    st   = MetaSyntaxTree.ParseText(text);

            BinderFlags binderFlags = BinderFlags.IgnoreAccessibility;

            if (compileMetaModelCore)
            {
                BinderFlags binderFlags2 = BinderFlags.IgnoreMetaLibraryDuplicatedTypes;
                binderFlags = binderFlags.UnionWith(binderFlags2);
            }
            MetaCompilationOptions options = new MetaCompilationOptions(MetaLanguage.Instance, OutputKind.NetModule, deterministic: true, concurrentBuild: false,
                                                                        topLevelBinderFlags: binderFlags);
            var compilation = MetaCompilation.
                              Create("MetaModelCompilation").
                              AddSyntaxTrees(st).
                              AddReferences(
                ModelReference.CreateFromModel(MetaInstance.MModel)
                ).
                              WithOptions(options);

            compilation.ForceComplete();
            if (assertEmptyDiagnostics)
            {
                AssertEmptyDiagnostics(compilation);
            }
            return(compilation);
        }
コード例 #2
0
        public void Compile()
        {
            if (_compilation == null)
            {
                ImmutableModel coreModel = MetaInstance.MModel;
                string         text      = File.ReadAllText(_inputFilePath);
                var            tree      = MetaSyntaxTree.ParseText(text, path: _inputFilePath);

                BinderFlags binderFlags = BinderFlags.IgnoreAccessibility;
                if (_compileMetaModelCore)
                {
                    BinderFlags binderFlags2 = BinderFlags.IgnoreMetaLibraryDuplicatedTypes;
                    binderFlags = binderFlags.UnionWith(binderFlags2);
                }
                MetaCompilationOptions options = new MetaCompilationOptions(MetaLanguage.Instance, OutputKind.NetModule, deterministic: true, concurrentBuild: true,
                                                                            topLevelBinderFlags: binderFlags);
                //MetaCompilationOptions options = new MetaCompilationOptions(MetaLanguage.Instance, OutputKind.NetModule, deterministic: true, concurrentBuild: false);
                var compilation = MetaCompilation.
                                  Create("MetaModelCompilation").
                                  AddSyntaxTrees(tree).
                                  AddReferences(
                    ModelReference.CreateFromModel(coreModel)
                    ).
                                  WithOptions(options);
                Interlocked.CompareExchange(ref _compilation, compilation, null);
            }
            _compilation.ForceComplete();
        }
コード例 #3
0
        protected override ICompilation CreateCompilation(string filePath, string sourceText, CancellationToken cancellationToken)
        {
            var         metaModelReference = ModelReference.CreateFromModel(MetaInstance.MModel);
            var         tree         = MetaSyntaxTree.ParseText(sourceText, path: filePath, cancellationToken: cancellationToken);
            BinderFlags binderFlags  = BinderFlags.IgnoreAccessibility;
            BinderFlags binderFlags2 = BinderFlags.IgnoreMetaLibraryDuplicatedTypes;

            binderFlags = binderFlags.UnionWith(binderFlags2);
            MetaCompilationOptions options = new MetaCompilationOptions(MetaLanguage.Instance, OutputKind.NetModule,
                                                                        deterministic: true, concurrentBuild: true,
                                                                        topLevelBinderFlags: binderFlags);
            var compilation = MetaCompilation.Create("Tagger").AddReferences(metaModelReference).AddSyntaxTrees(tree).WithOptions(options);

            return(compilation);
        }
コード例 #4
0
        private bool Test(int index)
        {
            bool   result           = false;
            string inputFileName    = string.Format(@"..\..\InputFiles\soal\Xsd{0:00}.soal", index);
            string expectedFileName = string.Format(@"..\..\ExpectedFiles\xsd\Xsd{0:00}.Hello.xsd", index);
            string outputFileName   = string.Format(@"..\..\OutputFiles\xsd\Xsd{0:00}.Hello.xsd", index);
            string outputDirectory  = string.Format(@"..\..\OutputFiles");
            string inputSoal        = null;

            using (StreamReader reader = new StreamReader(inputFileName))
            {
                inputSoal = reader.ReadToEnd();
            }
            SoalSyntaxTree         syntaxTree    = SoalSyntaxTree.ParseText(inputSoal);
            ModelReference         soalReference = ModelReference.CreateFromModel(SoalInstance.Model);
            BinderFlags            binderFlags   = BinderFlags.IgnoreAccessibility;
            SoalCompilationOptions options       = new SoalCompilationOptions(SoalLanguage.Instance, OutputKind.NetModule, topLevelBinderFlags: binderFlags);
            SoalCompilation        compilation   = SoalCompilation.Create("SoalTest").AddReferences(soalReference).AddSyntaxTrees(syntaxTree).WithOptions(options);

            compilation.ForceComplete();
            ImmutableModel model = compilation.Model;

            Assert.IsFalse(compilation.GetDiagnostics().Any(d => d.Severity == DiagnosticSeverity.Error));

            DiagnosticBag generatorDiagnostics = new DiagnosticBag();
            SoalGenerator generator            = new SoalGenerator(model, compilation.BuildModelObjectToSymbolMap(), outputDirectory, generatorDiagnostics, inputFileName);

            generator.SeparateXsdWsdl = true;
            generator.SingleFileWsdl  = false;
            generator.Generate();

            Assert.IsFalse(generatorDiagnostics.AsEnumerable().Any(d => d.Severity == DiagnosticSeverity.Error));

            string expectedXsd = null;

            using (StreamReader reader = new StreamReader(expectedFileName))
            {
                expectedXsd = reader.ReadToEnd();
            }
            string outputXsd = null;

            using (StreamReader reader = new StreamReader(outputFileName))
            {
                outputXsd = reader.ReadToEnd();
            }
            Assert.AreEqual(expectedXsd, outputXsd);
            return(result);
        }
コード例 #5
0
        static void Main(string[] args)
        {
            string fileName        = null;
            string outputDirectory = null;
            bool   separateXsdWsdl = false;
            bool   singleFileWsdl  = false;

            for (int i = 0; i < args.Length; i++)
            {
                if (args[i].StartsWith("-"))
                {
                    if (args[i] == "-separateXsdWsdl")
                    {
                        separateXsdWsdl = true;
                    }
                    else if (args[i] == "-singleFileWsdl")
                    {
                        singleFileWsdl = true;
                    }
                    else if (i + 1 < args.Length)
                    {
                        if (args[i] == "-o")
                        {
                            outputDirectory = args[++i];
                        }
                        else
                        {
                            Console.WriteLine("Unknown option: '" + args[i] + "'");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Unknown option: '" + args[i] + "'");
                    }
                }
                else
                {
                    fileName = args[i];
                }
            }
            if (fileName == null)
            {
                Console.WriteLine("Usage:");
                Console.WriteLine("  Soal.exe [options] [input.soal]");
                Console.WriteLine("Options:");
                Console.WriteLine("  -o [dir]: output directory");
                Console.WriteLine("  -separateXsdWsdl: separate XSD and WSDL files into different directories");
                Console.WriteLine("  -singleFileWsdl: include XSD code into the WSDL");
                return;
            }
            if (outputDirectory == null)
            {
                outputDirectory = Directory.GetCurrentDirectory();
            }
            if (!File.Exists(fileName))
            {
                Console.WriteLine("Could not find file: " + fileName);
                return;
            }
            if (singleFileWsdl && separateXsdWsdl)
            {
                Console.WriteLine("Warning: conflicting options '-separateXsdWsdl' and '-singleFileWsdl'. '-singleFileWsdl' will be used.");
            }
            string source;

            using (StreamReader reader = new StreamReader(fileName))
            {
                source = reader.ReadToEnd();
            }
            SoalSyntaxTree         syntaxTree    = SoalSyntaxTree.ParseText(source);
            ModelReference         soalReference = ModelReference.CreateFromModel(SoalInstance.Model);
            BinderFlags            binderFlags   = BinderFlags.IgnoreAccessibility;
            SoalCompilationOptions options       = new SoalCompilationOptions(SoalLanguage.Instance, OutputKind.NetModule, topLevelBinderFlags: binderFlags, concurrentBuild: false);
            SoalCompilation        compilation   = SoalCompilation.Create("SoalTest").AddReferences(soalReference).AddSyntaxTrees(syntaxTree).WithOptions(options);

            compilation.ForceComplete();
            ImmutableModel model = compilation.Model;
            DiagnosticBag  generatorDiagnostics = new DiagnosticBag();

            if (!compilation.GetDiagnostics().Any(d => d.Severity == DiagnosticSeverity.Error))
            {
                SoalGenerator generator = new SoalGenerator(model, compilation.BuildModelObjectToSymbolMap(), outputDirectory, generatorDiagnostics, fileName);
                generator.SeparateXsdWsdl = separateXsdWsdl;
                generator.SingleFileWsdl  = singleFileWsdl;
                generator.Generate();
                SoalPrinter printer = new SoalPrinter(model.Symbols);
                using (StreamWriter writer = new StreamWriter(fileName + "0"))
                {
                    writer.WriteLine(printer.Generate());
                }
            }
            DiagnosticFormatter formatter = new DiagnosticFormatter();

            foreach (var diagnostic in compilation.GetDiagnostics())
            {
                string msg = formatter.Format(diagnostic);
                Console.WriteLine(msg);
            }
            foreach (var diagnostic in generatorDiagnostics.AsEnumerable())
            {
                string msg = formatter.Format(diagnostic);
                Console.WriteLine(msg);
            }
        }
コード例 #6
0
ファイル: SoalTestBase.cs プロジェクト: Anjireddy4246/meta-cs
        protected SoalCompilation Compile(string fileId, bool assertEmptyDiagnostics = true)
        {
            SoalDescriptor.Initialize();
            string text    = File.ReadAllText($@"..\..\..\InputFiles\Soal\{fileId}.soal");
            var    st      = SoalSyntaxTree.ParseText(text);
            var    options = new SoalCompilationOptions(SoalLanguage.Instance, Microsoft.CodeAnalysis.OutputKind.DynamicallyLinkedLibrary, topLevelBinderFlags: (BinderFlags)BinderFlags.IgnoreAccessibility, concurrentBuild: false);
            var    comp    = SoalCompilation.Create("Test").WithOptions(options).AddSyntaxTrees(st).AddReferences(ModelReference.CreateFromModel(SoalInstance.MModel));

            comp.ForceComplete();
            if (assertEmptyDiagnostics)
            {
                AssertEmptyDiagnostics(comp);
            }
            return(comp);
        }