public static RootSingleDeclaration ForTree(
            SoalSyntaxTree syntaxTree,
            string scriptClassName,
            bool isSubmission)
        {
            var builder = new SoalDeclarationTreeBuilderVisitor(syntaxTree, scriptClassName, isSubmission);

            return(builder.CreateRoot(syntaxTree.GetRoot(), typeof(Symbols.Namespace)));
        }
Exemplo n.º 2
0
        private bool Test(int index)
        {
            bool   result               = false;
            string inputFileName        = string.Format(@"..\..\InputFiles\soal\Wsdl{0:00}.soal", index);
            string expectedXsdFileName  = string.Format(@"..\..\ExpectedFiles\xsd\Wsdl{0:00}.Hello.xsd", index);
            string outputXsdFileName    = string.Format(@"..\..\OutputFiles\xsd\Wsdl{0:00}.Hello.xsd", index);
            string expectedWsdlFileName = string.Format(@"..\..\ExpectedFiles\wsdl\Wsdl{0:00}.Hello.wsdl", index);
            string outputWsdlFileName   = string.Format(@"..\..\OutputFiles\wsdl\Wsdl{0:00}.Hello.wsdl", index);
            string outputDirectory      = string.Format(@"..\..\OutputFiles");
            string inputSoal            = null;

            using (StreamReader reader = new StreamReader(inputFileName))
            {
                inputSoal = reader.ReadToEnd();
            }
            SoalSyntaxTree    syntaxTree    = SoalSyntaxTree.ParseText(inputSoal);
            MetadataReference soalReference = MetadataReference.CreateFromModel(SoalInstance.Model);
            SoalCompilation   compilation   = SoalCompilation.Create("SoalTest").AddReferences(soalReference).AddSyntaxTrees(syntaxTree);
            ImmutableModel    model         = compilation.Model;

            Assert.IsFalse(compilation.GetDiagnostics().Any(d => d.Severity == Compiler.Diagnostics.DiagnosticSeverity.Error));
            DiagnosticBag generatorDiagnostics = new DiagnosticBag();
            SoalGenerator generator            = new SoalGenerator(model, outputDirectory, generatorDiagnostics, inputFileName);

            generator.SeparateXsdWsdl = true;
            generator.SingleFileWsdl  = false;
            generator.Generate();
            string expectedXsd = null;

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

            using (StreamReader reader = new StreamReader(outputXsdFileName))
            {
                outputXsd = reader.ReadToEnd();
            }
            Assert.AreEqual(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();
            }
            Assert.AreEqual(expectedWsdl, outputWsdl);
            return(result);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates a new compilation that can be used in scripting.
        /// </summary>
        public static SoalCompilation CreateScriptCompilation(
            string name,
            SoalSyntaxTree syntaxTree = null,
            IEnumerable <MetadataReference> references = null,
            SoalCompilationOptions options             = null,
            SoalCompilation previousScriptCompilation  = null,
            Type returnType  = null,
            Type globalsType = null)
        {
            ValidateScriptCompilationParameters(previousScriptCompilation, returnType, ref globalsType);

            return(Create(
                       name,
                       options?.WithReferencesSupersedeLowerVersions(true) ?? s_defaultSubmissionOptions,
                       (syntaxTree != null) ? new[] { syntaxTree } : EmptyCollections.Enumerable <SoalSyntaxTree>(),
                       references,
                       previousScriptCompilation,
                       returnType,
                       globalsType,
                       isSubmission: true));
        }
 protected SoalDeclarationTreeBuilderVisitor(SoalSyntaxTree syntaxTree, string scriptClassName, bool isSubmission)
     : base(syntaxTree, scriptClassName, isSubmission)
 {
 }
Exemplo n.º 7
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);
            }
        }