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); }
/*/ * private static bool GenerateWsdlTest(int index) * { * string testDirectory = @"..\..\..\..\..\..\..\soal-cs\Src\Test\MetaDslx.Languages.Soal.Test\"; * bool result = false; * string inputFileName = string.Format(testDirectory + @"InputFiles\soal\Wsdl{0:00}.soal", index); * string expectedXsdFileName = string.Format(testDirectory + @"ExpectedFiles\xsd\Wsdl{0:00}.Hello.xsd", index); * string outputXsdFileName = string.Format(testDirectory + @"OutputFiles\xsd\Wsdl{0:00}.Hello.xsd", index); * string expectedWsdlFileName = string.Format(testDirectory + @"ExpectedFiles\wsdl\Wsdl{0:00}.Hello.wsdl", index); * string outputWsdlFileName = string.Format(testDirectory + @"OutputFiles\wsdl\Wsdl{0:00}.Hello.wsdl", index); * string outputDirectory = string.Format(testDirectory + @"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, concurrentBuild: false); * SoalCompilation compilation = SoalCompilation.Create("SoalTest").AddReferences(soalReference).AddSyntaxTrees(syntaxTree).WithOptions(options); * compilation.ForceComplete(); * ImmutableModel model = compilation.Model; * * Debug.Assert(!compilation.GetDiagnostics().Any(d => d.Severity == DiagnosticSeverity.Error)); * DiagnosticFormatter formatter = new DiagnosticFormatter(); * foreach (var diagnostic in compilation.GetDiagnostics()) * { * Console.WriteLine(formatter.Format(diagnostic)); * } * * DiagnosticBag generatorDiagnostics = new DiagnosticBag(); * SoalGenerator generator = new SoalGenerator(model, compilation.BuildModelObjectToSymbolMap(), outputDirectory, generatorDiagnostics, inputFileName); * generator.SeparateXsdWsdl = true; * generator.SingleFileWsdl = false; * generator.Generate(); * * var generatorDiagnosticList = generatorDiagnostics.ToReadOnly(); * Debug.Assert(!generatorDiagnosticList.Any(d => d.Severity == DiagnosticSeverity.Error)); * foreach (var diagnostic in generatorDiagnosticList) * { * Console.WriteLine(formatter.Format(diagnostic)); * } * * string expectedXsd = null; * using (StreamReader reader = new StreamReader(expectedXsdFileName)) * { * expectedXsd = reader.ReadToEnd(); * } * string outputXsd = null; * using (StreamReader reader = new StreamReader(outputXsdFileName)) * { * outputXsd = reader.ReadToEnd(); * } * Debug.Assert(expectedXsd == outputXsd); * string expectedWsdl = null; * using (StreamReader reader = new StreamReader(expectedWsdlFileName)) * { * expectedWsdl = reader.ReadToEnd(); * } * string outputWsdl = null; * using (StreamReader reader = new StreamReader(outputWsdlFileName)) * { * outputWsdl = reader.ReadToEnd(); * } * Debug.Assert(expectedWsdl == outputWsdl); * return result; * * } * * private static bool SoalImportTest(int index) * { * string testDirectory = @"..\..\..\..\..\..\..\soal-cs\Src\Test\MetaDslx.Languages.Soal.Test\"; * bool result = false; * string inputFileName = string.Format(testDirectory + @"InputFiles\wsdl\Wsdl{0:00}.Hello.wsdl", index); * string expectedFileName = string.Format(testDirectory + @"ExpectedFiles\soal\Wsdl{0:00}.soal", index); * string outputFileName = string.Format(testDirectory + @"OutputFiles\soal\Wsdl{0:00}.Hello.soal", index); * string outputLogFileName = string.Format(testDirectory + @"OutputFiles\soal\Wsdl{0:00}.Hello.log", index); * string outputDirectory = string.Format(testDirectory + @"OutputFiles\soal", index); * DiagnosticBag diagnostics = new DiagnosticBag(); * ImmutableModel model = SoalImporter.Import(inputFileName, diagnostics); * using (StreamWriter writer = new StreamWriter(outputLogFileName)) * { * foreach (var msg in diagnostics.AsEnumerable()) * { * writer.WriteLine(msg); * } * } * Debug.Assert(!diagnostics.HasAnyErrors()); * Directory.CreateDirectory(outputDirectory); * string outputSoal = null; * SoalPrinter printer = new SoalPrinter(model.Symbols); * using (StreamWriter writer = new StreamWriter(outputFileName)) * { * outputSoal = printer.Generate(); * writer.WriteLine(outputSoal); * } * string expectedSoal = null; * using (StreamReader reader = new StreamReader(expectedFileName)) * { * expectedSoal = reader.ReadToEnd(); * } * File.WriteAllText(@"..\..\..\expected.txt", expectedSoal); * File.WriteAllText(@"..\..\..\actual.txt", outputSoal); * Debug.Assert(expectedSoal == outputSoal); * return result; * } * //*/ /*/ * private static void WebSequenceDiagramsTest() * { * MetaDescriptor.Initialize(); * UmlDescriptor.Initialize(); * * string text = File.ReadAllText(@"..\..\..\test2.wsd"); * * SequenceLexer lexer = new SequenceLexer(new AntlrInputStream(text)); * while(!lexer._hitEOF) * { * var token = lexer.NextToken(); * var tokenType = SequenceLexer.DefaultVocabulary.GetDisplayName(token.Type); * Console.WriteLine(tokenType+": "+token.Text); * } * * SequenceSyntaxTree st = SequenceSyntaxTree.ParseText(text); * //Console.WriteLine(st); * DiagnosticFormatter df = new DiagnosticFormatter(); * foreach (var diag in st.GetDiagnostics()) * { * Console.WriteLine(df.Format(diag)); * } * * SequenceCompilationOptions options = new SequenceCompilationOptions(SequenceLanguage.Instance, OutputKind.DynamicallyLinkedLibrary, concurrentBuild: false, deterministic: true); * SequenceCompilation compilation = SequenceCompilation.Create("Sequence").WithOptions(options).AddSyntaxTrees(st); * compilation.ForceComplete(); * var model = compilation.Model; * Console.WriteLine(model); * } * //*/ /*/ * public static void MofXmiTest() * { * MofDescriptor.Initialize(); * * string fileName = "../../../Uml.xmi"; * * try * { * var xmi = new MofXmiSerializer(); * var modelGroup = xmi.ReadModelGroupFromFile(fileName); * Console.WriteLine(modelGroup); * var writeOptions = new MofXmiWriteOptions(); * int i = 0; * foreach (var model in modelGroup.Models) * { * writeOptions.ModelToFileMap.Add(model, "../../../file" + i + ".xmi"); ++i; * } * xmi.WriteModelGroupToFile(modelGroup, writeOptions); * //var xmiCode = xmi.WriteModelGroup(modelGroup); * MofModelToMetaModelGenerator mgen = new MofModelToMetaModelGenerator(modelGroup.Objects); * string metaCode = mgen.Generate("MetaDslx.Languages.Uml.Model", "Uml", "http://www.omg.org/spec/UML"); * File.WriteAllText("../../../Uml.txt", metaCode); * } * catch (ModelException mex) * { * Console.WriteLine(mex.Diagnostic.ToString()); * } * } * //*/ /*/ * public static void UmlXmiTest() * { * UmlDescriptor.Initialize(); * * string fileName = "../../../Uml.xmi"; * * try * { * var xmi = new UmlXmiSerializer(); * var readOptions = new UmlXmiReadOptions(); * readOptions.IgnoredNamespaces.Add("http://www.omg.org/spec/MOF/20131001"); * var modelGroup = xmi.ReadModelGroupFromFile(fileName, readOptions); * Console.WriteLine(modelGroup); * var writeOptions = new UmlXmiWriteOptions(); * int i = 0; * foreach (var model in modelGroup.Models) * { * writeOptions.ModelToFileMap.Add(model, "../../../file" + i + ".xmi"); ++i; * } * xmi.WriteModelGroupToFile(modelGroup, writeOptions); * //var xmiCode = xmi.WriteModelGroup(modelGroup); * UmlModelToMetaModelGenerator mgen = new UmlModelToMetaModelGenerator(modelGroup.Objects); * string metaCode = mgen.Generate("MetaDslx.Languages.Uml.Model", "Uml", "http://www.omg.org/spec/UML"); * File.WriteAllText("../../../Uml.txt", metaCode); * } * catch (ModelException mex) * { * Console.WriteLine(mex.Diagnostic.ToString()); * } * } * //*/ /*/ * public static void EcoreXmiTest() * { * EcoreDescriptor.Initialize(); * * string fileName = "../../../RailDsl.ecore"; * * try * { * var xmi = new EcoreXmiSerializer(); * var emodel = xmi.ReadModelFromFile(fileName); * Console.WriteLine(emodel); * xmi.WriteModelToFile("../../../RailDsl2.ecore", emodel); * var metaModel = EcoreModelConverter.ToMetaModel(emodel); * var gen = new MetaModelGenerator(metaModel.Objects); * string metaCode = gen.Generate(metaModel.Objects.OfType<MetaModel>().First()); * File.WriteAllText("../../../RailDsl.mm", metaCode); * //MofModelToMetaModelGenerator mgen = new MofModelToMetaModelGenerator(model.Objects); * //string metaCode = mgen.Generate("MetaDslx.Languages.Uml.Model", "Uml", "http://www.omg.org/spec/UML/20161101"); * //File.WriteAllText("../../../Uml.txt", metaCode); * } * catch (ModelException mex) * { * Console.WriteLine(mex.Diagnostic.ToString()); * } * } * //*/ //*/ public static void MetaDslxXmiTest() { MetaDescriptor.Initialize(); string fileName = "../../../RailDsl.ecore"; try { var xmi = new MetaXmiSerializer(); var model = xmi.ReadModelFromFile(fileName); Console.WriteLine(model); xmi.WriteModelToFile("../../../RailDsl2.ecore", model); //MofModelToMetaModelGenerator mgen = new MofModelToMetaModelGenerator(model.Objects); //string metaCode = mgen.Generate("MetaDslx.Languages.Uml.Model", "Uml", "http://www.omg.org/spec/UML/20161101"); //File.WriteAllText("../../../Uml.txt", metaCode); } catch (ModelException mex) { Console.WriteLine(mex.Diagnostic.ToString()); } }