Exemple #1
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="source">The source Node to be expanded</param>
 /// <param name="destination">The destination node of the new expanded node, the new new node will added in
 /// Destination's parent node at the right index.</param>
 /// <param name="destinationURI">The dotted path of the destination, that willl be used to calculate the
 /// Destination parent's node index to which to insert the new expanded node as child.</param>
 public Remarks(Node source, Node destination, string destinationURI, CompilationDocument compilationDocument)
 {
     Source              = source;
     Destination         = destination;
     DestinationURI      = destinationURI;
     CompilationDocument = compilationDocument;
 }
Exemple #2
0
        public void addDocument(string id, string contents, ICompilerInjector <SyntaxToken, SyntaxNode, SemanticModel> injector)
        {
            if (_documents
                .Where(doc => doc.Id == id)
                .Any())
            {
                throw new InvalidOperationException();
            }

            var ext      = Path.GetExtension(id);
            var compiler = null as RoslynCompiler;
            var tool     = null as ICompilationTool;
            var hash     = 0;

            if (string.IsNullOrEmpty(ext))
            {
                compiler = new RoslynCompiler(_environment, _scope);
                injector.apply(compiler);
            }
            else if (ext == ".cs")
            {
                addCSharpFile(id, contents);
            }
            else
            {
                if (_tools.TryGetValue(ext, out tool))
                {
                    var storage = _environment.storage();
                    hash = storage == null ? hash : storage.cachedId(id);
                }
            }

            var newDoc = new CompilationDocument
            {
                Id       = id,
                Stage    = CompilerStage.Started,
                Compiler = compiler,
                Tool     = tool,
                Hash     = hash
            };

            if (compiler != null)
            {
                newDoc.Stage    = CompilerStage.Started;
                newDoc.Document = new RoslynDocument(compiler.Scope, contents, id);

                var documentInjector = newDoc.Compiler as IDocumentInjector <SyntaxToken, SyntaxNode, SemanticModel>;
                documentInjector.apply(newDoc.Document);
            }
            else
            {
                newDoc.Contents = contents;
            }

            _documents.Add(newDoc);
        }
Exemple #3
0
        public void addDocument(string id, IDocument <SyntaxToken, SyntaxNode, SemanticModel> document)
        {
            if (_documents
                .Where(doc => doc.Id == id)
                .Any())
            {
                throw new InvalidOperationException($"duplicate file: {id}");
            }

            var newDoc = new CompilationDocument
            {
                Id       = id,
                Stage    = CompilerStage.Started,
                Document = document,
            };

            _documents.Add(newDoc);
        }
Exemple #4
0
        public static void Check_CobolTokenSource_WithStartToken()
        {
            // Test file properties
            string         relativePath = @"Compiler\Parser\Samples";
            string         textName     = "MSVCOUT";
            Encoding       encoding     = Encoding.GetEncoding(1252);
            DocumentFormat docFormat    = DocumentFormat.RDZReferenceFormat;

            // Compile test file
            CompilationDocument compilationDocument = ParserUtils.ScanCobolFile(relativePath, textName, docFormat);

            // Search for first level 88 as a start token
            Token startToken = compilationDocument.TokensDocumentSnapshot.SourceTokens.First(t => (t.TokenType == TokenType.IntegerLiteral && ((IntegerLiteralTokenValue)t.LiteralValue).Number == 88));

            // Create a token iterator on top of tokens lines
            TokensLinesIterator tokensIterator = new TokensLinesIterator(
                compilationDocument.TokensDocumentSnapshot.TextSourceInfo.Name,
                compilationDocument.TokensDocumentSnapshot.Lines,
                startToken,
                Token.CHANNEL_SourceTokens);

            // Crate an Antlr compatible token source on top a the token iterator
            TokensLinesTokenSource tokenSource = new TokensLinesTokenSource(
                compilationDocument.TokensDocumentSnapshot.TextSourceInfo.Name,
                tokensIterator);

            IToken         token      = null;
            IList <IToken> tokensList = new List <IToken>();

            for (int i = 0; i < 9; i++)
            {
                token = tokenSource.NextToken();
                tokensList.Add(token);
            }
            if (tokensList[0].Text != "88" ||
                tokensList[1].Text != ":MSVCOUT:-RtnCod-OK" ||
                tokensList[7].Text != "VALUE" ||
                tokensList[8].Text != "'STUB'")
            {
                throw new Exception("Token source nextToken method with start token KO");
            }
        }
Exemple #5
0
        public void addDocument(string id, IDocument <SyntaxToken, SyntaxNode, SemanticModel> document, RoslynCompiler compiler)
        {
            if (_documents
                .Where(doc => doc.Id == id)
                .Any())
            {
                throw new InvalidOperationException($"duplicate file: {id}");
            }

            var newDoc = new CompilationDocument
            {
                Id       = id,
                Stage    = CompilerStage.Started,
                Document = document,
                Compiler = compiler,
            };

            //build the document
            var documentInjector = newDoc.Compiler as IDocumentInjector <SyntaxToken, SyntaxNode, SemanticModel>;

            documentInjector.apply(newDoc.Document);

            _documents.Add(newDoc);
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="Skeletons">Skeletons pattern for actions</param>
 public GeneratorActions(List <Skeleton> skeletons, CompilationDocument compilationDocument)
 {
     Skeletons           = skeletons ?? new List <Skeleton>();
     CompilationDocument = compilationDocument;
 }
Exemple #7
0
        public static void Check_CobolCharStream()
        {
            // Test file properties
            string         relativePath   = @"Compiler\Parser\Samples";
            string         textName       = "MSVCOUT";
            DocumentFormat documentFormat = DocumentFormat.RDZReferenceFormat;

            // Compile test file
            CompilationDocument compilationDocument = ParserUtils.ScanCobolFile(relativePath, textName, documentFormat);

            // Create a token iterator on top of tokens lines
            TokensLinesIterator tokensIterator = new TokensLinesIterator(
                compilationDocument.TokensDocumentSnapshot.TextSourceInfo.Name,
                compilationDocument.TokensDocumentSnapshot.Lines,
                null,
                Token.CHANNEL_SourceTokens);

            // Crate an Antlr compatible token source on top a the token iterator
            TokensLinesTokenSource tokenSource = new TokensLinesTokenSource(
                compilationDocument.TokensDocumentSnapshot.TextSourceInfo.Name,
                tokensIterator);

            tokenSource.NextToken();

            // Get underlying CharStream
            ICharStream charStream = tokenSource.InputStream;

            if (charStream.Index != 0)
            {
                throw new Exception("Char stream index should start at 0");
            }
            if (charStream.La(0) != 0)
            {
                throw new Exception("La(0) should be 0");
            }
            if (charStream.La(1) != '0')
            {
                throw new Exception("La(1) should be 0");
            }
            if (charStream.La(4) != '1')
            {
                throw new Exception("La(4) should be 1");
            }
            if (charStream.La(5) != '6')
            {
                throw new Exception("La(5) should be 6");
            }

            charStream.Consume();
            if (charStream.Index != 1)
            {
                throw new Exception("Char stream index should be 1 after consume");
            }
            if (charStream.La(4) != '6')
            {
                throw new Exception("La(4) should be 6 after consume");
            }
            if (charStream.La(80) != IntStreamConstants.Eof)
            {
                throw new Exception("La(80) should be Eof");
            }

            charStream.Seek(12);
            if (charStream.Index != 12)
            {
                throw new Exception("Char stream index should be 12 after seek");
            }
            if (charStream.La(-1) != ':')
            {
                throw new Exception("La(-1) should be : after seek");
            }
            if (charStream.La(1) != 'M')
            {
                throw new Exception("La(1) should be M after seek");
            }
            // should do nothing
            int marker = charStream.Mark();

            charStream.Release(marker);
            if (charStream.La(2) != 'S')
            {
                throw new Exception("La(2) should be S after release");
            }

            string text = charStream.GetText(new Interval(11, 18));

            if (text != ":MSVCOUT")
            {
                throw new Exception("Char stream GetText method KO");
            }

            if (charStream.Size != 80)
            {
                throw new Exception("Char stream size KO");
            }
        }
Exemple #8
0
        public static void Check_CobolTokenSource()
        {
            // Test file properties
            string         relativePath = @"Compiler\Parser\Samples";
            string         textName     = "MSVCOUT";
            DocumentFormat docFormat    = DocumentFormat.RDZReferenceFormat;

            // Compile test file
            CompilationDocument compilationDocument = ParserUtils.ScanCobolFile(relativePath, textName, docFormat);

            // Create a token iterator on top of tokens lines
            TokensLinesIterator tokensIterator = new TokensLinesIterator(
                compilationDocument.TokensDocumentSnapshot.TextSourceInfo.Name,
                compilationDocument.TokensDocumentSnapshot.Lines,
                null,
                Token.CHANNEL_SourceTokens);

            // Crate an Antlr compatible token source on top a the token iterator
            TokensLinesTokenSource tokenSource = new TokensLinesTokenSource(
                compilationDocument.TokensDocumentSnapshot.TextSourceInfo.Name,
                tokensIterator);

            if (tokenSource.SourceName != "MSVCOUT")
            {
                throw new Exception("Token source name KO");
            }

            var    source = new Tuple <ITokenSource, ICharStream>(tokenSource, tokenSource.InputStream);
            IToken token  = tokenSource.TokenFactory.Create(source, (int)TokenType.IntegerLiteral, "314", Token.CHANNEL_CompilerDirectives, 10, 20, 30, 17);

            if (token.Channel != Token.CHANNEL_CompilerDirectives || token.Column != 18 || token.Line != 1 ||
                token.StartIndex != 17 || token.StopIndex != 16 || token.Text != "314" ||
                token.TokenIndex != -1 || token.InputStream == null || token.TokenSource == null ||
                token.Type != (int)TokenType.IntegerLiteral || ((IntegerLiteralTokenValue)((Token)token).LiteralValue).Number != 314)
            {
                throw new Exception("TokenFactory second Create method KO");
            }

            if (tokenSource.Column != 0)
            {
                throw new Exception("Token source column should be 0 at start");
            }
            if (tokenSource.Line != 1)
            {
                throw new Exception("Token source line should be 1 at start");
            }

            IList <IToken> tokensList = new List <IToken>();

            for (int i = 0; token.Type != (int)TokenType.EndOfFile; i++)
            {
                token = tokenSource.NextToken();
                tokensList.Add(token);
            }
            if (tokensList.Count != 293 ||
                tokensList[0].Text != "01" ||
                tokensList[1].Text != ":MSVCOUT:" ||
                tokensList[290].Text != "'/MSVCOUT'" ||
                tokensList[292].Type != (int)TokenType.EndOfFile)
            {
                throw new Exception("Token source nextToken method KO");
            }
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="Skeletons">Skeletons pattern for actions</param>
 public GeneratorActions(Generator generator, List <Skeleton> skeletons, CompilationDocument compilationDocument)
 {
     Generator           = generator;
     Skeletons           = skeletons ?? new List <Skeleton>();
     CompilationDocument = compilationDocument;
 }
 public MixedTransformGenerator(CompilationDocument document, StringBuilder destination, List <Skeleton> skeletons, Generator generator)
     : base(document, destination, skeletons, null)
 {
     _usedGenerator = generator;
 }
Exemple #11
0
        public void addDocument(string id, string contents, ICompilerInjector<SyntaxToken, SyntaxNode, SemanticModel> injector)
        {
            if (_documents
                .Where(doc => doc.Id == id)
                .Any())
                throw new InvalidOperationException();

            var ext = Path.GetExtension(id);
            var compiler = null as RoslynCompiler;
            var tool = null as ICompilationTool;
            var hash = 0;
            if (string.IsNullOrEmpty(ext))
            {
                compiler = new RoslynCompiler(_environment, _scope);
                injector.apply(compiler);
            }
            else if (ext == ".cs")
            {
                addCSharpFile(id, contents);
            }
            else
            {
                if (_tools.TryGetValue(ext, out tool))
                {
                    var storage = _environment.storage();
                    hash = storage == null ? hash : storage.cachedId(id);
                }
            }

            var newDoc = new CompilationDocument
            {
                Id = id,
                Stage = CompilerStage.Started,
                Compiler = compiler,
                Tool = tool,
                Hash = hash
            };

            if (compiler != null)
            {
                newDoc.Stage = CompilerStage.Started;
                newDoc.Document = new RoslynDocument(compiler.Scope, contents, id);

                var documentInjector = newDoc.Compiler as IDocumentInjector<SyntaxToken, SyntaxNode, SemanticModel>;
                documentInjector.apply(newDoc.Document);
            }
            else
                newDoc.Contents = contents;

            _documents.Add(newDoc);
        }
Exemple #12
0
        public void addDocument(string id, IDocument<SyntaxToken, SyntaxNode, SemanticModel> document)
        {
            if (_documents
                .Where(doc => doc.Id == id)
                .Any())
                throw new InvalidOperationException();

            var newDoc = new CompilationDocument
            {
                Id = id,
                Stage = CompilerStage.Started,
                Document = document,
            };

            _documents.Add(newDoc);
        }