Ejemplo n.º 1
0
        /// <summary>
        /// Create a Replace action
        /// </summary>
        /// <param name="token">The Replace token</param>
        private void ReplaceAction(TypeCobol.Compiler.Preprocessor.ReplacedPartialCobolWord token)
        {
            Position from = null;
            Position to   = null;

            ComputePositions(new List <Token>()
            {
                token
            }, out from, out to);

            TargetDocument.Source.AddPosition(from); //from position
            TargetDocument.Source.AddPosition(to);   //To Pos
            Compiler.Source.StringSourceText buffer = new Compiler.Source.StringSourceText();
            buffer.Insert(token.Text, 0, 0);         //First new line
            //So pad the replacement if necessary
            int nPadLen = token.SourceText.Length - token.Text.Length;

            if (nPadLen > 0)
            {
                buffer.Insert(new string(' ', nPadLen), buffer.Size, buffer.Size);
            }
            //Delete the copy Instruction
            Action action = new Action()
            {
                Kind = ActionKind.Replace, From = from, To = to, Text = buffer
            };

            Actions.Add(action);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Insert action to erase compiler directives
        /// </summary>
        /// <param name="tokens">The tokens to erase</param>
        private void EraseCompilerDirectiveToken(IList <Token> tokens)
        {
            Position from = null;
            Position to   = null;
            Tuple <int, int, int, List <int>, List <int> > positions = ComputePositions(tokens, out from, out to);

            TargetDocument.Source.AddPosition(from); //from position
            TargetDocument.Source.AddPosition(to);   //To Pos
            Compiler.Source.StringSourceText del_buffer = new Compiler.Source.StringSourceText(new string(' ', to.Pos - from.Pos));
            Action action = new Action()
            {
                Kind = ActionKind.Insert, From = from, To = to, Text = del_buffer
            };

            Actions.Add(action);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Try to determine what can be erased after a copy instruction
        /// </summary>
        public Position ComputeErasureAfterCopyInstructionAction(TypeCobol.Compiler.Scanner.Token copyToken, TypeCobol.Compiler.Scanner.Token lastToken, out bool bAddNewLine)
        {
            bAddNewLine = false;
            Position cfrom = null;
            Position cto   = null;
            Tuple <int, int, int, List <int>, List <int> > positions = ComputePositions(new List <TypeCobol.Compiler.Scanner.Token>()
            {
                copyToken, lastToken
            }, out cfrom, out cto);

            TargetDocument.Source.AddPosition(cfrom);//from position
            if (this.Layout == ColumnsLayout.FreeTextFormat)
            {
                return(cfrom);
            }

            SourceDocument.SourceLine sourceLine = TargetDocument[positions.Item4[positions.Item4.Count - 1] - 1];
            int lineLen         = -1;
            int lineStartOffset = -1;
            int lineEndOffset   = -1;
            int from            = sourceLine.From;
            int to = sourceLine.To;

            lineLen = TargetDocument.Source.GetLineInfo(from, out lineStartOffset, out lineEndOffset);
            if (lineLen > LEGAL_COBOL_LINE_LENGTH)
            {   //Delete all characters in column 72-80
                int      replace_len = lineLen - LEGAL_COBOL_LINE_LENGTH;
                Position efrom       = new Position(from + LEGAL_COBOL_LINE_LENGTH);
                Position eto         = new Position(from + lineLen);
                TargetDocument.Source.AddPosition(efrom);
                TargetDocument.Source.AddPosition(eto);
                Compiler.Source.StringSourceText del_buffer = new Compiler.Source.StringSourceText(new string(' ', replace_len));
                Action action = new Action()
                {
                    Kind = ActionKind.Insert, From = efrom, To = eto, Text = del_buffer
                };
                Actions.Add(action);
            }
            bAddNewLine = true;
            return(sourceLine.End);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Create the action of Inserting all Imported Tokens from the current iterator
        /// </summary>
        /// <param name="firstToken">The First Imported Token</param>
        /// <param name="tokensIterator"></param>
        private void InsertImportedTokensAction(TypeCobol.Compiler.Scanner.Token firstToken, Compiler.Scanner.ITokensLinesIterator tokensIterator)
        {
            TypeCobol.Compiler.Preprocessor.ImportedToken importedToken = (TypeCobol.Compiler.Preprocessor.ImportedToken)firstToken;
            TypeCobol.Compiler.Directives.CopyDirective   copyDirective = importedToken.CopyDirective;
            Token        copyToken     = copyDirective.COPYToken;
            Token        copyNameToken = copyDirective.TextNameSymbol;
            int          startLine     = copyToken.Line;
            int          endLine       = copyNameToken.Line;
            int          startColumn   = copyToken.Column;
            int          endColumn     = copyNameToken.EndColumn;
            List <Token> tokens        = new List <Token>()
            {
                copyToken, copyNameToken
            };
            Position from = null;
            Position to   = null;

            ComputePositions(tokens, out from, out to);
            TargetDocument.Source.AddPosition(from); //from position
            TargetDocument.Source.AddPosition(to);   //To Pos
            //Delete the copy Instruction
            bool     bAddNewLine = false;
            Position insertPos   = ComputeErasureAfterCopyInstructionAction(copyToken, copyNameToken, out bAddNewLine);

            Compiler.Source.StringSourceText buffer = new Compiler.Source.StringSourceText();
            if (bAddNewLine)
            {
                buffer.Insert(Environment.NewLine, 0, 0);//First new line
            }
            int currentLine   = firstToken.Line;
            int currentColumn = 1;

            TypeCobol.Compiler.Scanner.Token currentToken = firstToken;
            do
            {
                TypeCobol.Compiler.Preprocessor.ImportedToken impToken = currentToken as TypeCobol.Compiler.Preprocessor.ImportedToken;
                if (impToken.CopyDirective.COPYToken.Line != copyToken.Line ||
                    impToken.CopyDirective.COPYToken.Column != copyToken.Column)
                {
                    break;//This is from another COPY
                }
                int nInserPos = buffer.Size;
                int newLine   = currentToken.Line;
                if (newLine != currentLine)
                {
                    currentColumn = 1;
                    currentLine   = newLine;
                    buffer.Insert(Environment.NewLine, nInserPos, nInserPos);
                    nInserPos += Environment.NewLine.Length;
                }
                int nPadLength = currentToken.Column - currentColumn;
                if (nPadLength > 0)
                {
                    buffer.Insert(new string(' ', nPadLength), nInserPos, nInserPos);
                    nInserPos += nPadLength;
                }
                buffer.Insert(currentToken.Text, nInserPos, nInserPos);
                currentColumn = currentToken.EndColumn + 1;
                currentToken  = tokensIterator.NextToken();
            } while (currentToken.TokenType != TokenType.EndOfFile && currentToken is TypeCobol.Compiler.Preprocessor.ImportedToken);
            buffer.Insert(Environment.NewLine, buffer.Size, buffer.Size);
            Action action = new Action()
            {
                Kind = ActionKind.Insert, From = to, To = to, Text = buffer
            };

            Actions.Add(action);
        }