Пример #1
0
        private CompiledMethod ParseAndCompileSingleMethod(string source)
        {
            var sourceBytes = Encoding.UTF8.GetBytes(source);
            var diagnostics = new BenchmarkDiagnosticsSink();

            // Parse the source
            const string sourceFilename = "test.cle";
            var          syntaxTree     = SyntaxParser.Parse(sourceBytes.AsMemory(), sourceFilename, diagnostics);

            if (syntaxTree is null || syntaxTree.Functions.Count != 1)
            {
                throw new InvalidOperationException("Expected a single method");
            }

            // Compile the declaration
            var declarationProvider = new NullDeclarationProvider();
            var declaration         = MethodDeclarationCompiler.Compile(syntaxTree.Functions[0],
                                                                        syntaxTree.Namespace, sourceFilename,
                                                                        0, declarationProvider, diagnostics);

            // Compile the method body
            var result = new MethodCompiler(declarationProvider, diagnostics)
                         .CompileBody(syntaxTree.Functions[0], declaration !, syntaxTree.Namespace, sourceFilename);

            if (diagnostics.DiagnosticCount > 0)
            {
                throw new InvalidOperationException("Expected no diagnostics");
            }
            return(result !);
        }
Пример #2
0
        public int ParseSingleFileWithoutErrors()
        {
            var diagnostics = new BenchmarkDiagnosticsSink();

            SyntaxParser.Parse(_source, "filename.cle", diagnostics);

            return(diagnostics.DiagnosticCount);
        }