コード例 #1
0
ファイル: Compiler.cs プロジェクト: zihotki/Excess
        public ExpressionSyntax CompileExpression(string expr)
        {
            var document = new RoslynDocument(_scope, expr);
            var handler  = _lexical as IDocumentInjector <SyntaxToken, SyntaxNode, SemanticModel>;

            _scope.set <IDocument <SyntaxToken, SyntaxNode, SemanticModel> >(document);

            handler.apply(document);
            document.applyChanges(CompilerStage.Lexical);

            return(CSharp.ParseExpression(document.LexicalText));
        }
コード例 #2
0
ファイル: Compiler.cs プロジェクト: zihotki/Excess
        public SyntaxTree ApplySemanticalPass(RoslynDocument document, out string result)
        {
            var lHandler  = _lexical as IDocumentInjector <SyntaxToken, SyntaxNode, SemanticModel>;
            var sHandler  = _syntax as IDocumentInjector <SyntaxToken, SyntaxNode, SemanticModel>;
            var ssHandler = _semantics as IDocumentInjector <SyntaxToken, SyntaxNode, SemanticModel>;

            lHandler.apply(document);
            sHandler.apply(document);
            ssHandler.apply(document);

            document.applyChanges(CompilerStage.Syntactical);
            var tree = document.SyntaxRoot.SyntaxTree;

            var compilation = CSharpCompilation.Create("semantical-pass",
                                                       syntaxTrees: new[] { tree },
                                                       references: new[]
            {
                MetadataReference.CreateFromFile(typeof(object).Assembly.Location),
                MetadataReference.CreateFromFile(typeof(Enumerable).Assembly.Location),
                MetadataReference.CreateFromFile(typeof(Dictionary <int, int>).Assembly.Location),
            },
                                                       options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));

            while (true)
            {
                document.Model = compilation.GetSemanticModel(tree);
                if (document.applyChanges(CompilerStage.Semantical))
                {
                    break;
                }

                var oldTree = tree;
                tree        = document.SyntaxRoot.SyntaxTree;
                compilation = compilation.ReplaceSyntaxTree(oldTree, tree);
            }

            result = document.SyntaxRoot.NormalizeWhitespace().ToFullString();
            return(document.SyntaxRoot.SyntaxTree);
        }
コード例 #3
0
ファイル: Compiler.cs プロジェクト: zihotki/Excess
        public SyntaxNode ApplyLexicalPass(string text, out string newText)
        {
            var document = new RoslynDocument(_scope, text);
            var handler  = _lexical as IDocumentInjector <SyntaxToken, SyntaxNode, SemanticModel>;

            _scope.set <IDocument <SyntaxToken, SyntaxNode, SemanticModel> >(document);

            handler.apply(document);
            document.applyChanges(CompilerStage.Lexical);

            newText = document.LexicalText;
            return(document.SyntaxRoot);
        }
コード例 #4
0
ファイル: Compiler.cs プロジェクト: zihotki/Excess
        public SyntaxTree ApplySyntacticalPass(string text, out string result)
        {
            var document = new RoslynDocument(_scope, text); //we actually dont touch our own state during these calls
            var lHandler = _lexical as IDocumentInjector <SyntaxToken, SyntaxNode, SemanticModel>;
            var sHandler = _syntax as IDocumentInjector <SyntaxToken, SyntaxNode, SemanticModel>;

            lHandler.apply(document);
            sHandler.apply(document);

            document.applyChanges(CompilerStage.Syntactical);

            result = document.SyntaxRoot.NormalizeWhitespace().ToFullString();
            return(document.SyntaxRoot.SyntaxTree);
        }