private DataConditionEntry CreateFunctionConditionParameter(CodeElementsParser.FunctionConditionParameterContext context)
 {
     var parameter = new DataConditionEntry();
     parameter.LevelNumber = CobolWordsBuilder.CreateIntegerValue(context.levelNumber().integerValue());
     parameter.DataName = CobolWordsBuilder.CreateConditionNameDefinition(context.conditionNameDefinition());
     SetConditionValues(parameter, context.valueClauseForCondition());
     return parameter;
 }
 public override void EnterFunctionReturningPhrase(CodeElementsParser.FunctionReturningPhraseContext context)
 {
     var ce = (FunctionDeclarationHeader)CodeElement;
     ce.Returning = new SyntaxProperty<Passing.Mode>(Passing.Mode.Returning, ParseTreeUtils.GetTokenFromTerminalNode(context.RETURNING()));
     if (context.parameterDescription().functionDataParameter() != null) {
     var entry = CreateFunctionDataParameter(context.parameterDescription().functionDataParameter());
     ce.Profile.ReturningParameter = new ParameterDescription(entry);
     }
 }
 public override void EnterLibraryCopy(CodeElementsParser.LibraryCopyContext context)
 {
     var copy = new LibraryCopyCodeElement();
     if (context.UserDefinedWord() != null) { // TCRFUN_LIBRARY_COPY
     var value = CobolWordsBuilder.CreateAlphanumericValue(context.UserDefinedWord());
     copy.Name = new SymbolDefinition(value, SymbolType.FileName);//TODO#278 eww!
     }
     Context = context;
     CodeElement = copy;
 }
Ejemplo n.º 4
0
 // --- ACCEPT ---
 public override void EnterAcceptStatement(CodeElementsParser.AcceptStatementContext context)
 {
     Context = context;
     if (context.acceptDataTransfer() != null) {
         CodeElement = CobolStatementsBuilder.CreateAcceptDataTransferStatement(context.acceptDataTransfer());
     } else
     if(context.acceptSystemDateTime() != null) {
         CodeElement = CobolStatementsBuilder.CreateAcceptSystemDateTime(context.acceptSystemDateTime());
     }
 }
 public override void EnterFunctionDeclarationHeader(CodeElementsParser.FunctionDeclarationHeaderContext context)
 {
     var visibility = context.PUBLIC() != null ? AccessModifier.Public : AccessModifier.Private;
     QualifiedName name = null;
     if (context.UserDefinedWord() != null) {
     var token = ParseTreeUtils.GetTokenFromTerminalNode(context.UserDefinedWord());
     name = new URI(token.Text);
     }
     Context = context;
     CodeElement = new FunctionDeclarationHeader(name, visibility);
 }
Ejemplo n.º 6
0
 ////////////////
 // PARAGRAPHS //
 ////////////////
 // STATEMENTS
 ////////////////
 // --- ARITHMETIC STATEMENTS ---
 public override void EnterAddStatement(CodeElementsParser.AddStatementContext context)
 {
     Context = context;
     if(context.addSimple() != null) {
         CodeElement = CobolStatementsBuilder.CreateAddStatement(context.addSimple());
     } else
     if (context.addGiving() != null) {
         CodeElement = CobolStatementsBuilder.CreateAddGivingStatement(context.addGiving());
     } else
     if (context.addCorresponding() != null) {
         CodeElement = CobolStatementsBuilder.CreateAddCorrespondingStatement(context.addCorresponding());
     }
 }
 internal AlphanumericVariable CreateAlphanumericVariable(CodeElementsParser.AlphanumericVariable1Context context)
 {
     if (context.identifier() != null)
     {
         return new AlphanumericVariable(
             CreateIdentifier(context.identifier()));
     }
     else
     {
         return new AlphanumericVariable(
             CobolWordsBuilder.CreateAlphanumericValue(context.alphanumericValue3()));
     }
 }
 public ParameterDescriptionEntry CreateFunctionDataParameter(CodeElementsParser.FunctionDataParameterContext context)
 {
     var parameter = new ParameterDescriptionEntry();
     parameter.LevelNumber = new GeneratedIntegerValue(1);
     parameter.DataName = CobolWordsBuilder.CreateDataNameDefinition(context.dataNameDefinition());
     if (context.pictureClause() != null) {
     parameter.Picture = CobolWordsBuilder.CreateAlphanumericValue(context.pictureClause().pictureCharacterString);
     parameter.DataType = DataType.Create(parameter.Picture.Value);
     } else {
     parameter.CustomType = CobolWordsBuilder.CreateAlphanumericValue(context.cobol2002TypeClause());
     parameter.DataType = DataType.CreateCustom(parameter.CustomType.Value);
     }
     //TODO#245: subphrases
     return parameter;
 }
Ejemplo n.º 9
0
 internal StorageArea CreateAddressOfSpecialRegister(CodeElementsParser.AddressOfSpecialRegisterContext context)
 {
     var specialRegister = new StorageAreaPropertySpecialRegister(
         ParseTreeUtils.GetFirstToken(context.ADDRESS()),
         CreateStorageAreaReference(context.storageAreaReference()));
     if (specialRegister.DataDescriptionEntry != null)
     {
         var dataDescription = specialRegister.DataDescriptionEntry;
         CobolWordsBuilder.symbolInformationForTokens[specialRegister.DataDescriptionEntry.DataName.NameLiteral.Token] = specialRegister.DataDescriptionEntry.DataName;
     }
     if (specialRegister.SymbolReference != null)
     {
         CobolWordsBuilder.symbolInformationForTokens[specialRegister.SymbolReference.NameLiteral.Token] = specialRegister.SymbolReference;
     }
     return specialRegister;
 }
        public override void EnterFunctionDeclarationHeader(CodeElementsParser.FunctionDeclarationHeaderContext context)
        {
            var type = FunctionType.Undefined;
            if (context.PROCEDURE() != null) type = FunctionType.Procedure;
            if (context.FUNCTION()  != null) type = FunctionType.Function;

            // TCRFUN_NO_DEFAULT_ACCESS_MODIFIER
            // As the grammar enforces that there must be one least one of the PUBLIC or PRIVATE keywords,
            // there will be a syntax error if there is neither of these two keywords.
            // So, the fact of considering a function PRIVATE by default does not break this rule.
            var visibility = context.PUBLIC() != null ? AccessModifier.Public : AccessModifier.Private;

            SymbolDefinition name = null;
            if (context.functionNameDefinition() != null) {
            name = CobolWordsBuilder.CreateFunctionNameDefinition(context.functionNameDefinition());
            }
            Context = context;
            CodeElement = new FunctionDeclarationHeader(name, visibility, type);
        }
Ejemplo n.º 11
0
 public override void EnterAddStatementEnd(CodeElementsParser.AddStatementEndContext context)
 {
     Context = context;
     CodeElement = new AddStatementEnd();
 }
Ejemplo n.º 12
0
 // --- INVOKE ---
 public override void EnterInvokeStatement(CodeElementsParser.InvokeStatementContext context)
 {
     Context = context;
     CodeElement = CobolStatementsBuilder.CreateInvokeStatement(context);
 }
Ejemplo n.º 13
0
 // INPUT-OUTPUT SECTION
 //////////////////////////
 public override void EnterInputOutputSectionHeader(CodeElementsParser.InputOutputSectionHeaderContext context)
 {
     Context = context;
     CodeElement = new InputOutputSectionHeader();
 }
Ejemplo n.º 14
0
 // --- GOBACK ---
 public override void EnterGobackStatement(CodeElementsParser.GobackStatementContext context)
 {
     Context = context;
     CodeElement = new GobackStatement();
 }
Ejemplo n.º 15
0
 public override void EnterFileControlParagraphHeader(CodeElementsParser.FileControlParagraphHeaderContext context)
 {
     Context = context;
     CodeElement = new FileControlParagraphHeader();
 }
Ejemplo n.º 16
0
        public override void EnterFileControlEntry(CodeElementsParser.FileControlEntryContext context)
        {
            var entry = new FileControlEntry();

            if (context.selectClause() != null)
            {
                entry.FileName = CobolWordsBuilder.CreateFileNameDefinition(context.selectClause().fileNameDefinition());
                if (context.selectClause().OPTIONAL() != null)
                {
                    entry.IsOptional = new SyntaxProperty<bool>(true,
                        ParseTreeUtils.GetFirstToken(context.selectClause().OPTIONAL()));
                }
            }
            if (context.assignClause() != null && context.assignClause().Length > 0)
            {
                var assignClauseContext = context.assignClause()[0];
                entry.ExternalDataSet = CobolWordsBuilder.CreateAssignmentName(assignClauseContext.assignmentName()[0]);
            }
            if (context.reserveClause() != null && context.reserveClause().Length > 0)
            {
                var reserveClauseContext = context.reserveClause()[0];
                entry.ReserveIOBuffersCount = CobolWordsBuilder.CreateIntegerValue(reserveClauseContext.integerValue());
            }
            if (context.accessModeClause() != null && context.accessModeClause().Length > 0)
            {
                var accessModeClauseContext = context.accessModeClause()[0];
                if (accessModeClauseContext.SEQUENTIAL() != null)
                {
                    entry.AccessMode = new SyntaxProperty<FileAccessMode>(FileAccessMode.Sequential,
                        ParseTreeUtils.GetFirstToken(accessModeClauseContext.SEQUENTIAL()));
                }
                else if (accessModeClauseContext.RANDOM() != null)
                {
                    entry.AccessMode = new SyntaxProperty<FileAccessMode>(FileAccessMode.Random,
                        ParseTreeUtils.GetFirstToken(accessModeClauseContext.RANDOM()));
                }
                else if (accessModeClauseContext.DYNAMIC() != null)
                {
                    entry.AccessMode = new SyntaxProperty<FileAccessMode>(FileAccessMode.Dynamic,
                        ParseTreeUtils.GetFirstToken(accessModeClauseContext.DYNAMIC()));
                }
            }
            if (context.fileStatusClause() != null && context.fileStatusClause().Length > 0)
            {
                var fileStatusClauseContext = context.fileStatusClause()[0];
                entry.FileStatus = CobolExpressionsBuilder.CreateStorageArea(fileStatusClauseContext.fileStatus);
                if (fileStatusClauseContext.vsamReturnCode != null)
                {
                    entry.VSAMReturnCode = CobolExpressionsBuilder.CreateStorageArea(fileStatusClauseContext.vsamReturnCode);
                }
            }

            SyntaxProperty<FileRecordsOrganization> recordsOrganization = null;
            CharacterVariable paddingCharacter = null;
            Token recordDelimiter = null;
            SymbolReference recordKey = null;
            AlternateRecordKey[] alternateRecordKeys = null;
            SymbolReference relativeKey = null;
            SymbolReference password = null;
            if (context.organizationClause() != null && context.organizationClause().Length > 0)
            {
                var organizationClauseContext = context.organizationClause()[0];
                if (organizationClauseContext.SEQUENTIAL() != null)
                {
                    recordsOrganization = new SyntaxProperty<FileRecordsOrganization>(FileRecordsOrganization.Sequential,
                        ParseTreeUtils.GetFirstToken(organizationClauseContext.SEQUENTIAL()));
                }
                else if (organizationClauseContext.INDEXED() != null)
                {
                    recordsOrganization = new SyntaxProperty<FileRecordsOrganization>(FileRecordsOrganization.Indexed,
                        ParseTreeUtils.GetFirstToken(organizationClauseContext.INDEXED()));
                }
                else if (organizationClauseContext.RELATIVE() != null)
                {
                    recordsOrganization = new SyntaxProperty<FileRecordsOrganization>(FileRecordsOrganization.Relative,
                        ParseTreeUtils.GetFirstToken(organizationClauseContext.RELATIVE()));
                }
                if (organizationClauseContext.LINE() != null)
                {
                    recordsOrganization = new SyntaxProperty<FileRecordsOrganization>(FileRecordsOrganization.LineSequential,
                        ParseTreeUtils.GetFirstToken(organizationClauseContext.LINE()));
                }
            }
            if (context.paddingCharacterClause() != null && context.paddingCharacterClause().Length > 0)
            {
                var paddingCharacterClauseContext = context.paddingCharacterClause()[0];
                paddingCharacter = CobolExpressionsBuilder.CreateCharacterVariable(paddingCharacterClauseContext.characterVariable());
            }
            if (context.recordDelimiterClause() != null && context.recordDelimiterClause().Length > 0)
            {
                var recordDelimiterClauseContext = context.recordDelimiterClause()[0];
                if (recordDelimiterClauseContext.STANDARD_1() != null)
                {
                    recordDelimiter = ParseTreeUtils.GetFirstToken(recordDelimiterClauseContext.STANDARD_1());
                }
                else if (recordDelimiterClauseContext.literalOrUserDefinedWordOReservedWordExceptCopy() != null)
                {
                    recordDelimiter = ParseTreeUtils.GetFirstToken(recordDelimiterClauseContext.literalOrUserDefinedWordOReservedWordExceptCopy());
                }
            }
            if (context.recordKeyClause() != null && context.recordKeyClause().Length > 0)
            {
                var recordKeyClauseContext = context.recordKeyClause()[0];
                recordKey = CobolWordsBuilder.CreateDataNameReference(recordKeyClauseContext.dataNameReference());
            }
            if (context.alternateRecordKeyClause() != null && context.alternateRecordKeyClause().Length > 0)
            {
                alternateRecordKeys = new AlternateRecordKey[context.alternateRecordKeyClause().Length];
                for (int i = 0; i < context.alternateRecordKeyClause().Length; i++)
                {
                    var alternateRecordKeyClauseContext = context.alternateRecordKeyClause()[i];
                    alternateRecordKeys[i] = new AlternateRecordKey();
                    alternateRecordKeys[i].RecordKey = CobolWordsBuilder.CreateDataNameReference(alternateRecordKeyClauseContext.recordKey);
                    if (alternateRecordKeyClauseContext.DUPLICATES() != null)
                    {
                        alternateRecordKeys[i].AllowDuplicates = new SyntaxProperty<bool>(true,
                            ParseTreeUtils.GetFirstToken(alternateRecordKeyClauseContext.DUPLICATES()));
                    }
                    if (alternateRecordKeyClauseContext.password != null)
                    {
                        alternateRecordKeys[i].Password = CobolWordsBuilder.CreateDataNameReference(alternateRecordKeyClauseContext.password);
                    }
                }
            }
            if (context.relativeKeyClause() != null && context.relativeKeyClause().Length > 0)
            {
                var relativeKeyClauseContext = context.relativeKeyClause()[0];
                relativeKey = CobolWordsBuilder.CreateDataNameReference(relativeKeyClauseContext.dataNameReference());
            }
            if (context.passwordClause() != null && context.passwordClause().Length > 0)
            {
                var passwordClauseContext = context.passwordClause()[0];
                password = CobolWordsBuilder.CreateDataNameReference(passwordClauseContext.dataNameReference());
            }
            if (recordsOrganization != null)
            {
                switch (recordsOrganization.Value)
                {
                    case FileRecordsOrganization.Sequential:
                    case FileRecordsOrganization.LineSequential:
                        var sequentialFileStructure = new SequentialFileStructure();
                        sequentialFileStructure.RecordsOrganization = recordsOrganization;
                        sequentialFileStructure.PaddingCharacter = paddingCharacter;
                        sequentialFileStructure.RecordDelimiter = recordDelimiter;
                        sequentialFileStructure.Password = password;
                        entry.Structure = sequentialFileStructure;
                        break;
                    case FileRecordsOrganization.Indexed:
                        var indexedFileStructure = new IndexedFileStructure();
                        indexedFileStructure.RecordsOrganization = recordsOrganization;
                        indexedFileStructure.RecordKey = recordKey;
                        indexedFileStructure.Password = password;
                        indexedFileStructure.AlternateRecordKeys = alternateRecordKeys;
                        entry.Structure = indexedFileStructure;
                        break;
                    case FileRecordsOrganization.Relative:
                        var relativeFileStructure = new RelativeFileStructure();
                        relativeFileStructure.RecordsOrganization = recordsOrganization;
                        relativeFileStructure.RelativeKey = relativeKey;
                        relativeFileStructure.Password = password;
                        entry.Structure = relativeFileStructure;
                        break;
                }
            }

            Context = context;
            CodeElement = entry;
        }
Ejemplo n.º 17
0
 // FACTORY IDENTIFICATION
 ////////////////////////////
 public override void EnterFactoryIdentification(CodeElementsParser.FactoryIdentificationContext context)
 {
     Context = context;
     CodeElement = new FactoryIdentification();
 }
Ejemplo n.º 18
0
 public override void EnterDivideStatement(CodeElementsParser.DivideStatementContext context)
 {
     Context = context;
     if (context.divideSimple() != null) {
         CodeElement = CobolStatementsBuilder.CreateDivideStatement(context.divideSimple());
     } else
     if (context.divideGiving() != null) {
         CodeElement = CobolStatementsBuilder.CreateDivideGivingStatement(context.divideGiving());
     } else
     if (context.divideRemainder() != null) {
         CodeElement = CobolStatementsBuilder.CreateDivideRemainderStatement(context.divideRemainder());
     }
 }
Ejemplo n.º 19
0
 public override void EnterDivideStatementEnd(CodeElementsParser.DivideStatementEndContext context)
 {
     Context = context;
     CodeElement = new DivideStatementEnd();
 }
Ejemplo n.º 20
0
 public override void EnterElseCondition(CodeElementsParser.ElseConditionContext context)
 {
     Context = context;
     CodeElement = new ElseCondition();
 }
Ejemplo n.º 21
0
        // FILE DESCRIPTION ENTRY
        ////////////////////////////
        public override void EnterFileDescriptionEntry(CodeElementsParser.FileDescriptionEntryContext context)
        {
            var entry = new FileDescriptionEntry();

            if (context.FD() != null)
                entry.LevelIndicator = new SyntaxProperty<FileDescriptionType>(FileDescriptionType.File, ParseTreeUtils.GetFirstToken(context.FD()));
            else
            if (context.SD() != null)
                entry.LevelIndicator = new SyntaxProperty<FileDescriptionType>(FileDescriptionType.SortMergeFile, ParseTreeUtils.GetFirstToken(context.SD()));

            entry.FileName = CobolWordsBuilder.CreateFileNameReference(context.fileNameReference());

            if (context.externalClause() != null && context.externalClause().Length > 0) {
                var externalClauseContext = context.externalClause()[0];
                entry.IsExternal = new SyntaxProperty<bool>(true, ParseTreeUtils.GetFirstToken(externalClauseContext.EXTERNAL()));
            }
            if (context.globalClause() != null && context.globalClause().Length > 0) {
                var globalClauseContext = context.globalClause()[0];
                entry.IsGlobal = new SyntaxProperty<bool>(true, ParseTreeUtils.GetFirstToken(globalClauseContext.GLOBAL()));
            }
            if (context.blockContainsClause() != null && context.blockContainsClause().Length > 0) {
                var blockContainsClauseContext = context.blockContainsClause()[0];
                entry.MaxBlockSize = CobolWordsBuilder.CreateIntegerValue(blockContainsClauseContext.maxNumberOfBytes);
                if (blockContainsClauseContext.minNumberOfBytes != null) {
                    entry.MinBlockSize = CobolWordsBuilder.CreateIntegerValue(blockContainsClauseContext.minNumberOfBytes);
                }
                if (blockContainsClauseContext.CHARACTERS() != null) {
                    entry.BlockSizeUnit = new SyntaxProperty<BlockSizeUnit>(BlockSizeUnit.Characters,
                        ParseTreeUtils.GetFirstToken(blockContainsClauseContext.CHARACTERS()));
                } else
                if (blockContainsClauseContext.RECORDS() != null) {
                    entry.BlockSizeUnit = new SyntaxProperty<BlockSizeUnit>(BlockSizeUnit.Records, ParseTreeUtils.GetFirstToken(blockContainsClauseContext.RECORDS()));
                }
            }
            if (context.recordClause() != null && context.recordClause().Length > 0) {
                var recordClauseContext = context.recordClause()[0];
                if (recordClauseContext.numberOfBytes != null) {
                    entry.MinRecordSize = CobolWordsBuilder.CreateIntegerValue(recordClauseContext.numberOfBytes);
                    entry.MaxRecordSize = entry.MinRecordSize;
                } else
                if (recordClauseContext.minNumberOfBytes != null) {
                    entry.MinRecordSize = CobolWordsBuilder.CreateIntegerValue(recordClauseContext.minNumberOfBytes);
                    entry.MaxRecordSize = CobolWordsBuilder.CreateIntegerValue(recordClauseContext.maxNumberOfBytes);
                } else
                if (recordClauseContext.VARYING() != null) {
                    if (recordClauseContext.fromNumberOfBytes != null)
                        entry.MinRecordSize = CobolWordsBuilder.CreateIntegerValue(recordClauseContext.fromNumberOfBytes);
                    if (recordClauseContext.toNumberOfBytes != null)
                        entry.MaxRecordSize = CobolWordsBuilder.CreateIntegerValue(recordClauseContext.toNumberOfBytes);
                    if (recordClauseContext.dataNameReference() != null)
                        entry.RecordSizeDependingOn = CobolWordsBuilder.CreateDataNameReference(recordClauseContext.dataNameReference());
                }
            }
            if (context.labelRecordsClause() != null && context.labelRecordsClause().Length > 0) {
                var labelRecordClauseContext = context.labelRecordsClause()[0];
                if (labelRecordClauseContext.STANDARD() != null) {
                    entry.LabelRecordType = new SyntaxProperty<LabelRecordType>(LabelRecordType.StandardLabels, ParseTreeUtils.GetFirstToken(labelRecordClauseContext.STANDARD()));
                }
                if (labelRecordClauseContext.OMITTED() != null) {
                    entry.LabelRecordType = new SyntaxProperty<LabelRecordType>(LabelRecordType.Omitted, ParseTreeUtils.GetFirstToken(labelRecordClauseContext.OMITTED()));
                } else
                if (labelRecordClauseContext.dataNameReference() != null && labelRecordClauseContext.dataNameReference().Length > 0) {
                    entry.LabelRecords = new SymbolReference[labelRecordClauseContext.dataNameReference().Length];
                    for (int i = 0; i < labelRecordClauseContext.dataNameReference().Length; i++)
                        entry.LabelRecords[i] = CobolWordsBuilder.CreateDataNameReference(labelRecordClauseContext.dataNameReference()[i]);
                }
            }
            if (context.valueOfClause() != null && context.valueOfClause().Length > 0) {
                var valueOfClauseContext = context.valueOfClause()[0];
                entry.ValueOfLabelRecords = new Dictionary<SymbolReference, Variable>();
                for (int i = 0; i < valueOfClauseContext.qualifiedDataName().Length; i++) {
                    entry.ValueOfLabelRecords.Add(
                        CobolWordsBuilder.CreateQualifiedDataName(valueOfClauseContext.qualifiedDataName()[i]),
                        CobolExpressionsBuilder.CreateVariable(valueOfClauseContext.variable5()[i]));
                }
            }
            if (context.dataRecordsClause() != null && context.dataRecordsClause().Length > 0) {
                var dataRecordClauseContext = context.dataRecordsClause()[0];
                entry.DataRecords = new SymbolReference[dataRecordClauseContext.dataNameReference().Length];
                for (int i = 0; i < dataRecordClauseContext.dataNameReference().Length; i++)
                    entry.DataRecords[i] = CobolWordsBuilder.CreateDataNameReference(dataRecordClauseContext.dataNameReference()[i]);
            }
            if (context.linageClause() != null && context.linageClause().Length > 0) {
                var linageClauseContext = context.linageClause()[0];
                if (linageClauseContext.numberOfLinesInPage != null)
                    entry.LogicalPageBodyLineCount = CobolExpressionsBuilder.CreateIntegerVariable(linageClauseContext.numberOfLinesInPage);
                if (linageClauseContext.firstLineNumberOfFootingArea != null)
                    entry.LogicalPageFootingLineNumber = CobolExpressionsBuilder.CreateIntegerVariable(linageClauseContext.firstLineNumberOfFootingArea);
                if (linageClauseContext.numberOfLinesInTopMargin != null)
                    entry.LogicalPageTopMarginLineCount = CobolExpressionsBuilder.CreateIntegerVariable(linageClauseContext.numberOfLinesInTopMargin);
                if (linageClauseContext.numberOfLinesInBottomMargin != null)
                    entry.LogicalPageBottomMarginLineCount = CobolExpressionsBuilder.CreateIntegerVariable(linageClauseContext.numberOfLinesInBottomMargin);
            }
            if (context.recordingModeClause() != null && context.recordingModeClause().Length > 0) {
                var recordingModeClauseContext = context.recordingModeClause()[0];
                entry.RecordingMode = CobolWordsBuilder.CreateRecordingMode(recordingModeClauseContext.recordingMode());
            }

            Context = context;
            CodeElement = entry;
        }
Ejemplo n.º 22
0
 //////////////////////////
 // ENVIRONMENT DIVISION //
 //////////////////////////
 public override void EnterEnvironmentDivisionHeader(CodeElementsParser.EnvironmentDivisionHeaderContext context)
 {
     Context = context;
     CodeElement = new EnvironmentDivisionHeader();
 }
Ejemplo n.º 23
0
 public override void EnterFileSectionHeader(CodeElementsParser.FileSectionHeaderContext context)
 {
     Context = context;
     CodeElement = new FileSectionHeader();
 }
Ejemplo n.º 24
0
 // --- EVALUATE ---
 public override void EnterEvaluateStatement(CodeElementsParser.EvaluateStatementContext context)
 {
     Context = context;
     CodeElement = CobolStatementsBuilder.CreateEvaluateStatement(context); ;
 }
Ejemplo n.º 25
0
 // --- GOTO ---
 public override void EnterGotoStatement(CodeElementsParser.GotoStatementContext context)
 {
     Context = context;
     if (context.gotoSimple() != null) {
         CodeElement = CobolStatementsBuilder.CreateGotoStatement(context.gotoSimple());
     }
     if (context.gotoConditional() != null) {
         CodeElement = CobolStatementsBuilder.CreateGotoConditionalStatement(context.gotoConditional());
     }
 }
Ejemplo n.º 26
0
 public override void EnterEvaluateStatementEnd(CodeElementsParser.EvaluateStatementEndContext context)
 {
     Context = context;
     CodeElement = new EvaluateStatementEnd();
 }
Ejemplo n.º 27
0
 public override void EnterInvalidKeyCondition(CodeElementsParser.InvalidKeyConditionContext context)
 {
     Context = context;
     CodeElement = new InvalidKeyCondition();
 }
Ejemplo n.º 28
0
 // --- EXIT ---
 public override void EnterExitStatement(CodeElementsParser.ExitStatementContext context)
 {
     Context = context;
     CodeElement = new ExitStatement();
 }
Ejemplo n.º 29
0
        public override void EnterIoControlEntry(CodeElementsParser.IoControlEntryContext context)
        {
            IOControlEntry entry = null;
            if (context.rerunClause() != null)
            {
                var rerunClauseContext = context.rerunClause();
                var rerunEntry = new RerunIOControlEntry();
                rerunEntry.OnExternalDataSetOrFileName = CobolWordsBuilder.CreateAssignmentNameOrFileNameReference(
                    rerunClauseContext.assignmentNameOrFileNameReference());
                if (rerunClauseContext.RECORDS() != null)
                {
                    rerunEntry.CheckPointFrequency = new SyntaxProperty<CheckPointFrequency>(CheckPointFrequency.EveryRecordCount,
                        ParseTreeUtils.GetFirstToken(rerunClauseContext.RECORDS()));
                    rerunEntry.EveryRecordCount = CobolWordsBuilder.CreateIntegerValue(rerunClauseContext.integerValue());
                }
                else if (rerunClauseContext.REEL() != null)
                {
                    rerunEntry.CheckPointFrequency = new SyntaxProperty<CheckPointFrequency>(CheckPointFrequency.EveryEndOfReelUnit,
                        ParseTreeUtils.GetFirstToken(rerunClauseContext.REEL()));
                }
                else if (rerunClauseContext.UNIT() != null)
                {
                    rerunEntry.CheckPointFrequency = new SyntaxProperty<CheckPointFrequency>(CheckPointFrequency.EveryEndOfReelUnit,
                        ParseTreeUtils.GetFirstToken(rerunClauseContext.UNIT()));
                }
                if (rerunClauseContext.fileNameReference() != null)
                {
                    rerunEntry.OfFileName = CobolWordsBuilder.CreateFileNameReference(rerunClauseContext.fileNameReference());
                }
                entry = rerunEntry;
            }
            else if (context.sameAreaClause() != null)
            {
                var sameAreaClauseContext = context.sameAreaClause();
                var sameAreaEntry = new SameAreaIOControlEntry();
                if (sameAreaClauseContext.RECORD() != null)
                {
                    sameAreaEntry.SameAreaType = new SyntaxProperty<SameAreaType>(SameAreaType.SameRecordArea,
                        ParseTreeUtils.GetFirstToken(sameAreaClauseContext.RECORD()));
                }
                else if (sameAreaClauseContext.SORT_ARG() != null)
                {
                    sameAreaEntry.SameAreaType = new SyntaxProperty<SameAreaType>(SameAreaType.SameSortArea,
                        ParseTreeUtils.GetFirstToken(sameAreaClauseContext.SORT_ARG()));
                }
                else if (sameAreaClauseContext.SORT_MERGE() != null)
                {
                    sameAreaEntry.SameAreaType = new SyntaxProperty<SameAreaType>(SameAreaType.SameSortMergeArea,
                        ParseTreeUtils.GetFirstToken(sameAreaClauseContext.SORT_MERGE()));
                }
                sameAreaEntry.FileNames = new SymbolReference[sameAreaClauseContext.fileNameReference().Length];
                for (int i = 0; i < sameAreaClauseContext.fileNameReference().Length; i++)
                {
                    var fileNameReferenceContext = sameAreaClauseContext.fileNameReference()[i];
                    sameAreaEntry.FileNames[i] = CobolWordsBuilder.CreateFileNameReference(fileNameReferenceContext);
                }
                entry = sameAreaEntry;
            }
            else if (context.multipleFileTapeClause() != null)
            {
                var multipleFTClauseContext = context.multipleFileTapeClause();
                var multipleFileEntry = new MultipleFileTapeIOControlEntry();
                multipleFileEntry.PhysicalReelOfTape = new PhysicalReelOfTape[multipleFTClauseContext.physicalReelOfTape().Length];
                for (int i = 0; i < multipleFTClauseContext.physicalReelOfTape().Length; i++)
                {
                    var physicalReelOfTapeContext = multipleFTClauseContext.physicalReelOfTape()[i];
                    var physicalReelOfTape = new PhysicalReelOfTape();
                    physicalReelOfTape.FileName = CobolWordsBuilder.CreateFileNameReference(physicalReelOfTapeContext.fileNameReference());
                    if (physicalReelOfTapeContext.integerValue() != null)
                    {
                        physicalReelOfTape.FilePosition = CobolWordsBuilder.CreateIntegerValue(physicalReelOfTapeContext.integerValue());
                    }
                    multipleFileEntry.PhysicalReelOfTape[i] = physicalReelOfTape;
                }
                entry = multipleFileEntry;
            }
            else if (context.applyWriteOnlyClause() != null)
            {
                var applyWOClauseContext = context.applyWriteOnlyClause();
                var applyWOEntry = new ApplyWriteOnlyIOControlEntry();
                applyWOEntry.FileNames = new SymbolReference[applyWOClauseContext.fileNameReference().Length];
                for (int i = 0; i < applyWOClauseContext.fileNameReference().Length; i++)
                {
                    var fileNameReferenceContext = applyWOClauseContext.fileNameReference()[i];
                    applyWOEntry.FileNames[i] = CobolWordsBuilder.CreateFileNameReference(fileNameReferenceContext);
                }
                entry = applyWOEntry;
            }

            Context = context;
            CodeElement = entry;
        }
Ejemplo n.º 30
0
 public override void EnterFactoryEnd(CodeElementsParser.FactoryEndContext context)
 {
     Context = context;
     CodeElement = new FactoryEnd();
 }
Ejemplo n.º 31
0
        /// <summary>
        /// Incremental parsing of a set of processed tokens lines changes
        /// </summary>
        internal static IList <DocumentChange <ICodeElementsLine> > ParseProcessedTokensLinesChanges(TextSourceInfo textSourceInfo, ISearchableReadOnlyList <CodeElementsLine> documentLines, IList <DocumentChange <IProcessedTokensLine> > processedTokensLinesChanges, PrepareDocumentLineForUpdate prepareDocumentLineForUpdate, TypeCobolOptions compilerOptions, PerfStatsForParserInvocation perfStatsForParserInvocation)
        {
            // Collect all changes applied to the processed tokens lines during the incremental scan
            IList <DocumentChange <ICodeElementsLine> > codeElementsLinesChanges = new List <DocumentChange <ICodeElementsLine> >();

            // There are 2 reasons to re-parse a tokens line after a change :
            // 1. The tokens line changed : these lines were already reset during the previous steps
            // 2. If a tokens line that changed was involved in the parsing of a multiline code element, the whole group of lines must be parsed again

            // --- PREPARATION PHASE : identify all parse sections where code elements need to be refreshed ---

            IList <ParseSection> refreshParseSections       = null;
            ParseSection         largestRefreshParseSection = null;

            // Iterate over all processed tokens changes detected by the PreprocessorStep :
            // - refresh all the adjacent lines participating in a CodeElement
            // - register the start and stop token for all sections of the document which need to be parsed again
            if (processedTokensLinesChanges != null && processedTokensLinesChanges.Count > 0)
            {
                // If the document was cleared, everything must be parsed again
                if (processedTokensLinesChanges[0].Type != DocumentChangeType.DocumentCleared)
                {
                    refreshParseSections = new List <ParseSection>();

                    ParseSection lastParseSection = null;
                    foreach (DocumentChange <IProcessedTokensLine> tokensChange in processedTokensLinesChanges)
                    {
                        if (lastParseSection == null || tokensChange.LineIndex > lastParseSection.StopLineIndex)
                        {
                            lastParseSection = CheckIfAdjacentLinesNeedRefresh(tokensChange.Type, tokensChange.LineIndex, documentLines, prepareDocumentLineForUpdate, codeElementsLinesChanges, lastParseSection);
                            refreshParseSections.Add(lastParseSection);
                        }
                    }
                }
            }
            if (refreshParseSections != null)
            {
                //After getting all the parts refreshed, get the largest part that has been refreshed
                var minParseSection = refreshParseSections.OrderBy(p => p.StartLineIndex).First();
                var maxParseSection = refreshParseSections.OrderByDescending(p => p.StopLineIndex).First();
                largestRefreshParseSection = new ParseSection(minParseSection.StartLineIndex,
                                                              minParseSection.StartToken, maxParseSection.StopLineIndex, maxParseSection.StopToken,
                                                              maxParseSection.StopTokenIsFirstTokenOfTheLine);
            }


            // --- INITIALIZE ANTLR CodeElements parser ---

            // Create a token iterator on top of pre-processed tokens lines
            ITokensLinesIterator tokensIterator = ProcessedTokensDocument.GetProcessedTokensIterator(textSourceInfo, documentLines);

            // Create an Antlr compatible token source on top of the token iterator
            TokensLinesTokenSource tokenSource = new TokensLinesTokenSource(
                textSourceInfo.Name,
                tokensIterator);

            // Init parser
            TokensLinesTokenStream tokenStream = new TokensLinesTokenStream(tokenSource, Token.CHANNEL_SourceTokens);
            CodeElementsParser     cobolParser = new CodeElementsParser(tokenStream);

            // REVERT TO STD PARSER ==> TracingCobolParser cobolParser = new TracingCobolParser(tokenStream);

            // Optionnaly activate Antlr Parser performance profiling
            // WARNING : use this in a single-treaded context only (uses static field)
            if (AntlrPerformanceProfiler == null && perfStatsForParserInvocation.ActivateDetailedAntlrPofiling)
            {
                AntlrPerformanceProfiler = new AntlrPerformanceProfiler(cobolParser);
            }
            if (AntlrPerformanceProfiler != null)
            {
                // Replace the generated parser by a subclass which traces all rules invocations
                cobolParser = new CodeElementsTracingParser(tokenStream);

                var tokensCountIterator = ProcessedTokensDocument.GetProcessedTokensIterator(textSourceInfo, documentLines);
                AntlrPerformanceProfiler.BeginParsingFile(textSourceInfo, tokensCountIterator);
            }

            // Customize error recovery strategy
            IAntlrErrorStrategy cobolErrorStrategy = new CodeElementErrorStrategy();

            cobolParser.ErrorHandler = cobolErrorStrategy;

            // Register all parse errors in a list in memory
            ParserDiagnosticErrorListener errorListener = new ParserDiagnosticErrorListener();

            cobolParser.RemoveErrorListeners();
            cobolParser.AddErrorListener(errorListener);

            // Prepare to analyze the parse tree
            ParseTreeWalker    walker             = new ParseTreeWalker();
            CodeElementBuilder codeElementBuilder = new CodeElementBuilder();

            codeElementBuilder.Dispatcher = new CodeElementDispatcher();
            codeElementBuilder.Dispatcher.CreateListeners();

            // --- INCREMENTAL PARSING ---

            // In case of incremental parsing, parse only the code sections we need to refresh

            if (largestRefreshParseSection != null)
            {
                // Seek just before the next code element starting token
                tokenStream.SeekToToken(largestRefreshParseSection.StartToken);
                tokenStream.StartLookingForStopToken(largestRefreshParseSection.StopToken);

                //Remove all the code elements for the future line to parse.

                for (int i = largestRefreshParseSection.StartLineIndex;
                     i < (largestRefreshParseSection.StopLineIndex == documentLines.Count - 1 && largestRefreshParseSection.StopToken == null //If the last index is equals to number of line in document, make sure to also reset the last line, otherwise, reset lines normally.
                        ? largestRefreshParseSection.StopLineIndex + 1
                        : largestRefreshParseSection.StopLineIndex);
                     i++)
                {
                    if (documentLines[i].CodeElements != null)
                    {
                        documentLines[i].ResetCodeElements();
                    }
                }
            }



            // Reset parsing error diagnostics
            cobolErrorStrategy.Reset(cobolParser);

            // Try to parse code elements :
            // - starting with the current parse section Start token
            // - ending with the current parse section Stop token
            CodeElementsParser.CobolCodeElementsContext codeElementsParseTree = null;
            try
            {
                perfStatsForParserInvocation.OnStartAntlrParsing();
                if (AntlrPerformanceProfiler != null)
                {
                    AntlrPerformanceProfiler.BeginParsingSection();
                }
                codeElementsParseTree = cobolParser.cobolCodeElements();
                if (AntlrPerformanceProfiler != null)
                {
                    AntlrPerformanceProfiler.EndParsingSection(codeElementsParseTree.ChildCount);
                }
                perfStatsForParserInvocation.OnStopAntlrParsing(
                    AntlrPerformanceProfiler != null
                        ? (int)AntlrPerformanceProfiler.CurrentFileInfo.DecisionTimeMs
                        : 0,
                    AntlrPerformanceProfiler != null
                        ? AntlrPerformanceProfiler.CurrentFileInfo.RuleInvocations.Sum()
                        : 0);
            }
            catch (Exception e)
            {
                var currentToken = (Token)cobolParser.CurrentToken;
                CodeElementsLine codeElementsLine = GetCodeElementsLineForToken(currentToken);
                if (codeElementsLine != null)
                {
                    codeElementsLine.AddParserDiagnostic(new TokenDiagnostic(MessageCode.ImplementationError,
                                                                             currentToken, currentToken.Line, e));
                }
            }

            if (codeElementsParseTree != null)
            {
                // If the parse tree is not empty
                if (codeElementsParseTree.codeElement() != null && codeElementsParseTree.codeElement().Length > 0)
                {
                    // Analyze the parse tree for each code element
                    foreach (var codeElementParseTree in codeElementsParseTree.codeElement())
                    {
                        // Get the first line that was parsed
                        var tokenStart = (Token)codeElementParseTree.Start;
                        CodeElementsLine codeElementsLine = GetCodeElementsLineForToken(tokenStart);
                        if (codeElementsLine == null)
                        {
                            continue;
                        }

                        // Register that this line was updated
                        // COMMENTED FOR THE SAKE OF PERFORMANCE -- SEE ISSUE #160
                        //int updatedLineIndex = documentLines.IndexOf(codeElementsLine, codeElementsLine.LineIndex);
                        //codeElementsLinesChanges.Add(new DocumentChange<ICodeElementsLine>(DocumentChangeType.LineUpdated, updatedLineIndex, codeElementsLine));
                        codeElementsLinesChanges.Add(
                            new DocumentChange <ICodeElementsLine>(DocumentChangeType.LineUpdated,
                                                                   codeElementsLine.LineIndex, codeElementsLine));

                        perfStatsForParserInvocation.OnStartTreeBuilding();
                        // Visit the parse tree to build a first class object representing the code elements
                        try
                        {
                            walker.Walk(codeElementBuilder, codeElementParseTree);
                        }
                        catch (Exception ex)
                        {
                            var code  = MessageCode.ImplementationError;
                            int line  = 0;
                            int start = 0;
                            int stop  = 0;
                            if (codeElementsLine.SourceTokens != null && codeElementsLine.SourceTokens.Count > 0)
                            {
                                start = codeElementsLine.SourceTokens[0].StartIndex;
                                stop  =
                                    codeElementsLine.SourceTokens[codeElementsLine.SourceTokens.Count - 1].StopIndex;
                            }
                            codeElementsLine.AddParserDiagnostic(new ParserDiagnostic(ex.ToString(), start, stop,
                                                                                      line, null, code, ex));
                        }
                        CodeElement codeElement = codeElementBuilder.CodeElement;
                        if (codeElement != null)
                        {
                            // Attach consumed tokens and main document line numbers information to the code element
                            if (codeElement.ConsumedTokens.Count == 0)
                            {
// ISSUE #204:
                                var tempToken = tokenStream.Lt(1);
                                if (tempToken != null && tempToken != Token.END_OF_FILE)
                                {
// if not end of file,
                                    // add next token to ConsumedTokens to know where is the CodeElement in error
                                    codeElement.ConsumedTokens.Add((Token)tempToken);
                                    // this alter CodeElements semantics: in addition to matched tokens,
                                    // it includes the first token in error if no token has been matched
                                }
                            }

                            //TODO Issue #384 to discuss if this code should stay here:
                            //This should be in a Checker, but "codeElement.ConsumedTokens" is only set after all the checkers have been called
                            //Rule TCLIMITATION_NO_CE_ACROSS_SOURCES
                            if (codeElement.IsAcrossSourceFile())
                            {
                                DiagnosticUtils.AddError(codeElement,
                                                         "A Cobol statement cannot be across 2 sources files (eg. Main program and a COPY)",
                                                         MessageCode.TypeCobolParserLimitation);
                            }

                            // Add code element to the list
                            codeElementsLine.AddCodeElement(codeElement);
                        }
                    }
                }
                // If the parse tree contains errors
                if (codeElementsParseTree.Diagnostics != null)
                {
                    foreach (ParserDiagnostic d in codeElementsParseTree.Diagnostics)
                    {
                        if (d.OffendingSymbol != null)
                        {
                            CodeElementsLine codeElementsLine =
                                GetCodeElementsLineForToken((Token)d.OffendingSymbol);
                            if (codeElementsLine != null)
                            {
                                codeElementsLine.AddParserDiagnostic(d);
                            }
                        }
                    }
                }
                perfStatsForParserInvocation.OnStopTreeBuilding();
            }


            if (AntlrPerformanceProfiler != null)
            {
                AntlrPerformanceProfiler.EndParsingFile(cobolParser.ParseInfo.DecisionInfo, (int)(cobolParser.ParseInfo.GetTotalTimeInPrediction() / 1000000));
            }

            return(codeElementsLinesChanges);
        }
Ejemplo n.º 32
0
        /// <summary>
        /// Incremental parsing of a set of processed tokens lines changes
        /// </summary>
        internal static IList <DocumentChange <ICodeElementsLine> > ParseProcessedTokensLinesChanges(TextSourceInfo textSourceInfo, ISearchableReadOnlyList <CodeElementsLine> documentLines, IList <DocumentChange <IProcessedTokensLine> > processedTokensLinesChanges, PrepareDocumentLineForUpdate prepareDocumentLineForUpdate, TypeCobolOptions compilerOptions)
        {
            // Collect all changes applied to the processed tokens lines during the incremental scan
            IList <DocumentChange <ICodeElementsLine> > codeElementsLinesChanges = new List <DocumentChange <ICodeElementsLine> >();

            // There are 2 reasons to re-parse a tokens line after a change :
            // 1. The tokens line changed : these lines were already reset during the previous steps
            // 2. If a tokens line that changed was involved in the parsing of a multiline code element, the whole group of lines must be parsed again

            // --- PREPARATION PHASE : identify all parse sections where code elements need to be refreshed ---

            IList <ParseSection> refreshParseSections = null;

            // Iterate over all processed tokens changes detected by the PreprocessorStep :
            // - refresh all the adjacent lines participating in a CodeElement
            // - register the start and stop token for all sections of the document which need to be parsed again
            if (processedTokensLinesChanges != null)
            {
                // If the document was cleared, everything must be parsed again
                if (processedTokensLinesChanges[0].Type != DocumentChangeType.DocumentCleared)
                {
                    refreshParseSections = new List <ParseSection>();

                    ParseSection lastParseSection = null;
                    foreach (DocumentChange <IProcessedTokensLine> tokensChange in processedTokensLinesChanges)
                    {
                        if (lastParseSection == null || tokensChange.LineIndex > lastParseSection.StopLineIndex)
                        {
                            lastParseSection = CheckIfAdjacentLinesNeedRefresh(tokensChange.Type, tokensChange.LineIndex, documentLines, prepareDocumentLineForUpdate, codeElementsLinesChanges, lastParseSection);
                            refreshParseSections.Add(lastParseSection);
                        }
                    }
                }
            }

            // --- INITIALIZE ANTLR CodeElements parser ---

            // Create a token iterator on top of pre-processed tokens lines
            ITokensLinesIterator tokensIterator = ProcessedTokensDocument.GetProcessedTokensIterator(textSourceInfo, documentLines);

            // Create an Antlr compatible token source on top of the token iterator
            TokensLinesTokenSource tokenSource = new TokensLinesTokenSource(
                textSourceInfo.Name,
                tokensIterator);

            // Init parser
            TokensLinesTokenStream tokenStream = new TokensLinesTokenStream(tokenSource, Token.CHANNEL_SourceTokens);
            CodeElementsParser     cobolParser = new CodeElementsParser(tokenStream);
            // REVERT TO STD PARSER ==> TracingCobolParser cobolParser = new TracingCobolParser(tokenStream);

            // Customize error recovery strategy
            IAntlrErrorStrategy cobolErrorStrategy = new CodeElementErrorStrategy();

            cobolParser.ErrorHandler = cobolErrorStrategy;

            // Register all parse errors in a list in memory
            ParserDiagnosticErrorListener errorListener = new ParserDiagnosticErrorListener();

            cobolParser.RemoveErrorListeners();
            cobolParser.AddErrorListener(errorListener);

            // Prepare to analyze the parse tree
            ParseTreeWalker    walker             = new ParseTreeWalker();
            CodeElementBuilder codeElementBuilder = new CodeElementBuilder();

            codeElementBuilder.Dispatcher = new CodeElementDispatcher();
            codeElementBuilder.Dispatcher.CreateListeners();

            // --- INCREMENTAL PARSING ---

            // In case of incremental parsing, parse only the code sections we need to refresh
            IEnumerator <ParseSection> parseSectionsEnumerator = null;
            ParseSection currentParseSection = null;

            if (refreshParseSections != null)
            {
                // Get the first code section we need to refresh
                parseSectionsEnumerator = refreshParseSections.GetEnumerator();
                parseSectionsEnumerator.MoveNext();
                currentParseSection = parseSectionsEnumerator.Current;

                // Seek just before the next code element starting token
                tokenStream.SeekToToken(currentParseSection.StartToken);
                tokenStream.StartLookingForStopToken(currentParseSection.StopToken);
            }

            // Parse a list of code elements for each parse section while advancing in the underlying token stream
            do
            {
                // Reset parsing error diagnostics
                cobolErrorStrategy.Reset(cobolParser);

                // Try to parse code elements :
                // - starting with the current parse section Start token
                // - ending with the current parse section Stop token
                CodeElementsParser.CobolCodeElementsContext codeElementsParseTree = null;
                try {
                    codeElementsParseTree = cobolParser.cobolCodeElements();
                } catch (Exception e) {
                    var currentToken = (Token)cobolParser.CurrentToken;
                    CodeElementsLine codeElementsLine = GetCodeElementsLineForToken(currentToken);
                    codeElementsLine.AddParserDiagnostic(new TokenDiagnostic(MessageCode.ImplementationError, currentToken, currentToken.Line, e));
                }

                if (codeElementsParseTree != null)
                {
                    // If the parse tree is not empty
                    if (codeElementsParseTree.codeElement() != null && codeElementsParseTree.codeElement().Length > 0)
                    {
                        // Analyze the parse tree for each code element
                        foreach (var codeElementParseTree in codeElementsParseTree.codeElement())
                        {
                            // Get the first line that was parsed
                            var tokenStart = (Token)codeElementParseTree.Start;
                            CodeElementsLine codeElementsLine = GetCodeElementsLineForToken(tokenStart);

                            // Register that this line was updated
                            // COMMENTED FOR THE SAKE OF PERFORMANCE -- SEE ISSUE #160
                            //int updatedLineIndex = documentLines.IndexOf(codeElementsLine, codeElementsLine.InitialLineIndex);
                            //codeElementsLinesChanges.Add(new DocumentChange<ICodeElementsLine>(DocumentChangeType.LineUpdated, updatedLineIndex, codeElementsLine));
                            codeElementsLinesChanges.Add(new DocumentChange <ICodeElementsLine>(DocumentChangeType.LineUpdated, codeElementsLine.InitialLineIndex, codeElementsLine));

                            // Visit the parse tree to build a first class object representing the code elements
                            try { walker.Walk(codeElementBuilder, codeElementParseTree); }
                            catch (Exception ex)
                            {
                                var code = MessageCode.ImplementationError;
                                int line = 0; int start = 0; int stop = 0;
                                if (codeElementsLine.SourceTokens != null && codeElementsLine.SourceTokens.Count > 0)
                                {
                                    start = codeElementsLine.SourceTokens[0].StartIndex;
                                    stop  = codeElementsLine.SourceTokens[codeElementsLine.SourceTokens.Count - 1].StopIndex;
                                }
                                codeElementsLine.AddParserDiagnostic(new ParserDiagnostic(ex.ToString(), start, stop, line, null, code));
                            }
                            CodeElement codeElement = codeElementBuilder.CodeElement;
                            if (codeElement != null)
                            {
                                // Attach consumed tokens and main document line numbers information to the code element
                                if (codeElement.ConsumedTokens.Count == 0)
                                {     // ISSUE #204:
                                    if (tokenStream.Lt(1) != null)
                                    { // if not end of file,
                                        // add next token to ConsumedTokens to know where is the CodeElement in error
                                        codeElement.ConsumedTokens.Add((Token)tokenStream.Lt(1));
                                        // this alter CodeElements semantics: in addition to matched tokens,
                                        // it includes the first token in error if no token has been matched
                                    }
                                }

                                //TODO Issue #384 to discuss if this code should stay here:
                                //This should be in a Checker, but "codeElement.ConsumedTokens" is only set after all the checkers have been called
                                //Rule TCLIMITATION_NO_CE_ACROSS_SOURCES
                                if (codeElement.IsAcrossSourceFile())
                                {
                                    DiagnosticUtils.AddError(codeElement, "A Cobol statement cannot be across 2 sources files (eg. Main program and a COPY)", MessageCode.TypeCobolParserLimitation);
                                }

                                // Add code element to the list
                                codeElementsLine.AddCodeElement(codeElement);
                                if (codeElement.Diagnostics != null)
                                {
                                    foreach (Diagnostic d in codeElement.Diagnostics)
                                    {
                                        codeElementsLine.AddParserDiagnostic(d);
                                    }
                                }
                            }
                        }
                    }
                    // If the parse tree contains errors
                    if (codeElementsParseTree.Diagnostics != null)
                    {
                        foreach (ParserDiagnostic d in codeElementsParseTree.Diagnostics)
                        {
                            if (d.OffendingSymbol != null)
                            {
                                CodeElementsLine codeElementsLine = GetCodeElementsLineForToken((Token)d.OffendingSymbol);
                                codeElementsLine.AddParserDiagnostic(d);
                            }
                        }
                    }
                }

                // In case of incremental parsing, directly jump to next parse section in the token stream
                // Else, simply start parsing the next CodeElement beginning with the next token
                if (currentParseSection != null)
                {
                    // Adavance to the next ParseSection
                    if (parseSectionsEnumerator.MoveNext())
                    {
                        currentParseSection = parseSectionsEnumerator.Current;
                        tokenStream.SeekToToken(currentParseSection.StartToken);
                        tokenStream.StartLookingForStopToken(currentParseSection.StopToken);
                    }
                    // No more section to parse
                    else
                    {
                        break;
                    }
                }
            }while (tokenStream.La(1) >= 0);

            return(codeElementsLinesChanges);
        }