示例#1
0
        private void CheckTypedef(DataTypeDescriptionEntry typedef,
                                  CodeElementsParser.DataDescriptionEntryContext context)
        {
            if (typedef == null)
            {
                return;
            }

            if (typedef.LevelNumber?.Value != 1)
            {
                string message = "TYPEDEF clause can only be specified for level 01 entries";
                DiagnosticUtils.AddError(typedef, message, context.cobol2002TypedefClause());
            }

            if (typedef.IsExternal)
            {
                string message = "EXTERNAL clause cannot be specified with TYPEDEF clause";
                foreach (var external in context.externalClause())
                {
                    DiagnosticUtils.AddError(typedef, message, external);
                }
            }

#if EUROINFO_LEGACY_TYPEDEF
            if (typedef.RestrictionLevel != RestrictionLevel.STRICT)
            {
                string message = "Custom EI rule : Only TYPEDEF STRICT is allowed.";
                DiagnosticUtils.AddError(typedef, message, context.cobol2002TypedefClause());
                return;
            }
#endif

            if (typedef.RestrictionLevel == RestrictionLevel.STRICT) //Manage as a STRICT TYPEDEF
            {
                if (typedef.IsSynchronized != null && typedef.IsSynchronized.Value == true)
                {
                    DiagnosticUtils.AddError(typedef, "SYNC clause cannot be used with a STRICT type definition", context.cobol2002TypedefClause());
                }
            }

            if (typedef.RestrictionLevel == RestrictionLevel.STRONG) //Manage as a STRONG TYPEDEF
            {
                if (typedef.InitialValue != null)
                {
                    string message = "STRONG TYPEDEF cannot contain VALUE clause:";
                    foreach (var valeuClause in context.valueClause())
                    {
                        DiagnosticUtils.AddError(typedef, message, valeuClause);
                    }
                }

                if (typedef.Picture != null)
                {
                    string message   = "Elementary TYPEDEF cannot be STRONG";
                    string rulestack = RuleStackBuilder.GetRuleStack(context.cobol2002TypedefClause());
                    DiagnosticUtils.AddError(typedef, message,
                                             ParseTreeUtils.GetFirstToken(context.cobol2002TypedefClause().STRONG()), rulestack);
                }
            }
        }
        public override void EnterInoutPhrase(CodeElementsParser.InoutPhraseContext context)
        {
            var ce = (FunctionDeclarationHeader)CodeElement;

            ce.Inout = new SyntaxProperty <ParameterPassingDirection>(ParameterPassingDirection.InOut,
                                                                      ParseTreeUtils.GetTokenFromTerminalNode(context.IN_OUT()));
            ce.Profile.InoutParameters = CreateParameters(context.parameterDescription());
        }
示例#3
0
        public override void EnterTitleCompilerStatement(CobolCompilerDirectivesParser.TitleCompilerStatementContext context)
        {
            TitleDirective titleDirective = new TitleDirective();

            CompilerDirective = titleDirective;

            string title = ParseTreeUtils.GetAlphanumericLiteral(context.alphanumericValue2());

            titleDirective.Title = title;
        }
        public override void EnterFunctionReturningPhrase(CodeElementsParser.FunctionReturningPhraseContext context)
        {
            var ce = (FunctionDeclarationHeader)CodeElement;

            ce.Returning = new SyntaxProperty <ParameterPassingDirection>(ParameterPassingDirection.Returning,
                                                                          ParseTreeUtils.GetTokenFromTerminalNode(context.RETURNING()));
            if (context.parameterDescription().functionDataParameter() != null)
            {
                var entry = CreateFunctionDataParameter(context.parameterDescription().functionDataParameter());
                ce.Profile.ReturningParameter = entry;
            }
        }
示例#5
0
        public override void EnterBasisCompilerStatement(CobolCompilerDirectivesParser.BasisCompilerStatementContext context)
        {
            var basisDirective = new BasisDirective();

            CompilerDirective = basisDirective;

            if (context.textName() != null)
            {
                basisDirective.BasisName      = GetTextName(context.textName());
                basisDirective.TextNameSymbol = ParseTreeUtils.GetFirstToken(context.textName());
            }
        }
示例#6
0
        public override void EnterInsertCompilerStatement(CobolCompilerDirectivesParser.InsertCompilerStatementContext context)
        {
            InsertDirective insertDirective = new InsertDirective();

            CompilerDirective = insertDirective;

            if (context.sequenceNumber() != null && context.sequenceNumber().IntegerLiteral() != null)
            {
                insertDirective.SequenceNumber = (int)ParseTreeUtils.GetIntegerLiteral(context.sequenceNumber().IntegerLiteral());
                if (insertDirective.SequenceNumber < 0)
                {
                    Token      errorToken = ParseTreeUtils.GetTokenFromTerminalNode(context.sequenceNumber().IntegerLiteral());
                    Diagnostic error      = new Diagnostic(
                        MessageCode.InvalidNumericLiteralFormat,
                        errorToken.Column, errorToken.EndColumn,
                        errorToken.Line, "TODO");
                    CompilerDirective.AddDiagnostic(error);//TODO proper diagnostic error
                }
            }
        }
示例#7
0
        public override void EnterSequenceNumberField(CobolCompilerDirectivesParser.SequenceNumberFieldContext context)
        {
            DeleteDirective deleteDirective = (DeleteDirective)CompilerDirective;

            bool isFirst  = true;
            int  previous = -42;

            foreach (ITerminalNode node in context.IntegerLiteral())
            {
                int current = (int)ParseTreeUtils.GetIntegerLiteral(node);
                if (isFirst)
                {
                    previous = current;
                    isFirst  = false;
                }
                else
                {
                    DeleteDirective.SequenceNumberRange range = new DeleteDirective.SequenceNumberRange();
                    range.From = previous;
                    if (current < 0)
                    {
                        range.To = -current;
                        isFirst  = true;
                    }
                    else
                    {
                        range.To = previous;
                        previous = current;
                    }
                    deleteDirective.SequenceNumberRangesList.Add(range);
                }
            }
            if (!isFirst && previous >= 0)
            {
                DeleteDirective.SequenceNumberRange range = new DeleteDirective.SequenceNumberRange();
                range.From = previous;
                range.To   = previous;
                deleteDirective.SequenceNumberRangesList.Add(range);
            }
        }
示例#8
0
        public override void EnterControlCblOption(CobolCompilerDirectivesParser.ControlCblOptionContext context)
        {
            string option = null;

            TryGetUserDefinedWord(context.enumeratedValue1().UserDefinedWord(), ref option);
            if (option != null)
            {
                ControlCblDirective.ControlCblOption optionValue;
                if (Enum.TryParse <ControlCblDirective.ControlCblOption>(option, out optionValue))
                {
                    ((ControlCblDirective)CompilerDirective).OptionsList.Add(optionValue);
                }
                else
                {
                    Token      errorToken = ParseTreeUtils.GetTokenFromTerminalNode(context.enumeratedValue1().UserDefinedWord());
                    Diagnostic diag       = new Diagnostic(
                        MessageCode.InvalidControlCblCompilerStatementOption,
                        errorToken.Column, errorToken.EndColumn,
                        errorToken.Line, option);
                    CompilerDirective.AddDiagnostic(diag);
                }
            }
        }
示例#9
0
        public override void EnterExecSqlIncludeStatement(CobolCompilerDirectivesParser.ExecSqlIncludeStatementContext context)
        {
            var copyDirective = new CopyDirective(CompilerDirectiveType.EXEC_SQL_INCLUDE, ParseTreeUtils.GetFirstToken(context.EXEC()));

            CompilerDirective = copyDirective;

            if (context.copyCompilerStatementBody() != null)
            {
                var textNameContext = context.copyCompilerStatementBody().qualifiedTextName().textName();
                if (textNameContext != null)
                {
                    string textName = GetTextName(textNameContext);
                    copyDirective.TextName       = textName;
                    copyDirective.TextNameSymbol = ParseTreeUtils.GetFirstToken(textNameContext);
                }

                var libraryNameContext = context.copyCompilerStatementBody().qualifiedTextName().libraryName();
                if (libraryNameContext != null)
                {
                    copyDirective.LibraryName       = GetLibraryName(libraryNameContext);
                    copyDirective.LibraryNameSymbol = ParseTreeUtils.GetFirstToken(libraryNameContext);
                }
            }
        }
        ////////////////////
        // PROCEDURE CALL //
        ////////////////////

        public override void EnterTcCallStatement(CodeElementsParser.TcCallStatementContext context)
        {
            var cbCallProc = context.procedurePointerOrFunctionPointerVariableOrfunctionNameReference;

            // Register call parameters (shared storage areas) information at the CodeElement level
            CallSite callSite = null;
            ProcedureStyleCallStatement statement = null;

            Context = context;

            //Incomplete CallStatement, create an empty CodeElement and return + Error due to issue #774
            if (cbCallProc == null)
            {
                CodeElement = new ProcedureStyleCallStatement
                {
                    Diagnostics = new List <Diagnostic>
                    {
                        new Diagnostic(MessageCode.SyntaxErrorInParser, context.Start.Column,
                                       context.Stop.Column, context.Start.Line, "Empty CALL is not authorized")
                    }
                };
                return;
            }


            //Here ambiguousSymbolReference with either CandidatesType:
            // - ProgramNameOrProgramEntry
            // - data, condition, UPSISwitch, TCFunctionName
            var ambiguousSymbolReference = CobolExpressionsBuilder.CreateProcedurePointerOrFunctionPointerVariableOrTCFunctionProcedure(cbCallProc);


            //If (inputs, inouts ou outputs).Count > 0, then it's a procedure call
            if (context.callOutputParameter().Length > 0 || context.callInputParameter().Length > 0 || context.callInoutParameter().Length > 0)
            {
                callSite = new CallSite();
                #region Setup Input Output Inout CallSitesParameters

                var inputs  = new List <CallSiteParameter>();
                var inouts  = new List <CallSiteParameter>();
                var outputs = new List <CallSiteParameter>();

                SyntaxProperty <ParameterSharingMode> mode = null;
                foreach (var p in context.callInputParameter())
                {
                    CreateSharingMode(p, ref mode); // TCRFUN_INPUT_BY
                    var callSiteParameter = new CallSiteParameter
                    {
                        SharingMode = mode,
                    };


                    if (p.sharedVariableOrFileName() != null)
                    {
                        callSiteParameter.StorageAreaOrValue = CobolExpressionsBuilder.CreateSharedVariableOrFileName(p.sharedVariableOrFileName());
                    }
                    else if (p.OMITTED() != null)
                    {
                        callSiteParameter.Omitted = new SyntaxProperty <bool>(true, ParseTreeUtils.GetFirstToken(p.OMITTED()));
                    }

                    if (p.sharedVariableOrFileName() != null || p.OMITTED() != null)
                    {
                        inputs.Add(callSiteParameter);
                    }
                }

                foreach (var p in context.callInoutParameter())
                {
                    var callSiteParameter = new CallSiteParameter
                    {
                        // TCRFUN_CALL_INOUT_AND_OUTPUT_BY_REFERENCE
                        SharingMode =
                            new SyntaxProperty <ParameterSharingMode>(ParameterSharingMode.ByReference, null),
                    };

                    if (p.sharedStorageArea1() != null)
                    {
                        callSiteParameter.StorageAreaOrValue = new Variable(CobolExpressionsBuilder.CreateSharedStorageArea(p.sharedStorageArea1()));
                    }
                    else if (p.OMITTED() != null)
                    {
                        callSiteParameter.Omitted = new SyntaxProperty <bool>(true, ParseTreeUtils.GetFirstToken(p.OMITTED()));
                    }

                    if (p.sharedStorageArea1() != null || p.OMITTED() != null)
                    {
                        inouts.Add(callSiteParameter);
                    }
                }

                foreach (var p in context.callOutputParameter())
                {
                    var callSiteParameter = new CallSiteParameter
                    {
                        // TCRFUN_CALL_INOUT_AND_OUTPUT_BY_REFERENCE
                        SharingMode =
                            new SyntaxProperty <ParameterSharingMode>(ParameterSharingMode.ByReference, null),
                    };

                    if (p.sharedStorageArea1() != null)
                    {
                        callSiteParameter.StorageAreaOrValue = new Variable(CobolExpressionsBuilder.CreateSharedStorageArea(p.sharedStorageArea1()));
                    }
                    else if (p.OMITTED() != null)
                    {
                        callSiteParameter.Omitted = new SyntaxProperty <bool>(true, ParseTreeUtils.GetFirstToken(p.OMITTED()));
                    }

                    if (p.sharedStorageArea1() != null || p.OMITTED() != null)
                    {
                        outputs.Add(callSiteParameter);
                    }
                }

                int parametersCount = inputs.Count + outputs.Count + inouts.Count;
                callSite.Parameters = new CallSiteParameter[parametersCount];
                int i = 0;

                //Add inputs to global callsites parameters
                if (inputs.Count > 0)
                {
                    foreach (var param in inputs)
                    {
                        callSite.Parameters[i] = param;
                        i++;
                    }
                }

                //Add outputs to global callsites parameters
                if (outputs.Count > 0)
                {
                    foreach (var param in outputs)
                    {
                        callSite.Parameters[i] = param;
                        i++;
                    }
                }

                //Add inouts to global callsites parameters
                if (inouts.Count > 0)
                {
                    foreach (var param in inouts)
                    {
                        callSite.Parameters[i] = param;
                        i++;
                    }
                }

                #endregion

                //Check Type or CandidatesTypes to see if a TCFunctionName is possible
                if (ambiguousSymbolReference.MainSymbolReference != null &&
                    ambiguousSymbolReference.MainSymbolReference.IsOrCanBeOfType(SymbolType.TCFunctionName))
                {
                    SymbolReferenceVariable TCFunctionNameRefVariable;

                    if (ambiguousSymbolReference.MainSymbolReference.IsQualifiedReference)
                    {
                        var nonAmbiguousHead =
                            new SymbolReference(
                                (ambiguousSymbolReference.MainSymbolReference as TypeCobolQualifiedSymbolReference)?.Head
                                .NameLiteral, SymbolType.TCFunctionName);
                        var nonAmbiguousTail =
                            new SymbolReference(
                                (ambiguousSymbolReference.MainSymbolReference as TypeCobolQualifiedSymbolReference)?.Tail
                                .NameLiteral, SymbolType.ProgramName);

                        TypeCobolQualifiedSymbolReference newQualifiedSymbolReferece =
                            new TypeCobolQualifiedSymbolReference(nonAmbiguousHead, nonAmbiguousTail);
                        TCFunctionNameRefVariable = new SymbolReferenceVariable(StorageDataType.MethodName,
                                                                                newQualifiedSymbolReferece);
                    }
                    else
                    {
                        //If so, create ProcedureStyleCallStatement with a ProcedureCall and fix SymbolReference so it's not ambiguous
                        var nonAmbiguousSymbolRef =
                            new SymbolReference(ambiguousSymbolReference.MainSymbolReference.NameLiteral,
                                                SymbolType.TCFunctionName);
                        TCFunctionNameRefVariable = new SymbolReferenceVariable(StorageDataType.MethodName,
                                                                                nonAmbiguousSymbolRef);
                    }

                    //CobolExpressionsBuilder store every StorageArea created into storageAreaReads and then after
                    //storageAreaReads is set to the CodeElement
                    //We must remove it as TCFunctionNameRefVariable doesn't contains a StorageArea
                    if (ambiguousSymbolReference.StorageArea != null)
                    {
                        CobolExpressionsBuilder.storageAreaReads.Remove(ambiguousSymbolReference.StorageArea);
                    }

                    statement =
                        new ProcedureStyleCallStatement(new ProcedureCall(TCFunctionNameRefVariable.MainSymbolReference,
                                                                          inputs, inouts, outputs))
                    {
                        ProgramOrProgramEntryOrProcedureOrFunctionOrTCProcedureFunction =
                            TCFunctionNameRefVariable.MainSymbolReference
                    };

                    callSite.CallTarget = TCFunctionNameRefVariable.MainSymbolReference;
                }
                else
                {
                    //else it's an error
                    statement =
                        new ProcedureStyleCallStatement(new ProcedureCall(ambiguousSymbolReference.MainSymbolReference,
                                                                          inputs, inouts, outputs))
                    {
                        ProgramOrProgramEntryOrProcedureOrFunctionOrTCProcedureFunction = ambiguousSymbolReference.MainSymbolReference,
                        Diagnostics = new List <Diagnostic>
                        {
                            new Diagnostic(MessageCode.ImplementationError, context.Start.Column,
                                           context.Stop.Column, context.Start.Line,
                                           "A call with arguments is not a TCFunctionName")
                        },
                    };

                    callSite.CallTarget = ambiguousSymbolReference.MainSymbolReference;
                }
            }
            else
            {
                if (ambiguousSymbolReference.MainSymbolReference != null &&
                    ambiguousSymbolReference.MainSymbolReference.IsOrCanBeOfType(SymbolType.DataName, SymbolType.TCFunctionName))
                {
                    //TODO think about uniformity of CandidateTypes inside QualifiedReference.
                    //Maybe just define CandidatesTypes for the Head...
                    if (ambiguousSymbolReference.MainSymbolReference.IsQualifiedReference)
                    {
                        var qualifiedSymbolReference = (QualifiedSymbolReference)ambiguousSymbolReference.MainSymbolReference;


                        AmbiguousSymbolReference.ApplyCandidatesTypes(qualifiedSymbolReference, new[] { SymbolType.DataName, SymbolType.ProgramName });
                        //Adjust candidate types only for the first element
                        if (qualifiedSymbolReference.First.IsAmbiguous)
                        {
                            ((AmbiguousSymbolReference)qualifiedSymbolReference.First).CandidateTypes = new[] { SymbolType.DataName, SymbolType.TCFunctionName };
                        }
                    }
                    else
                    {
                        ((AmbiguousSymbolReference)ambiguousSymbolReference.MainSymbolReference).CandidateTypes = new[] { SymbolType.DataName, SymbolType.TCFunctionName };
                    }

                    statement = new ProcedureStyleCallStatement(new ProcedureCall(ambiguousSymbolReference.MainSymbolReference,
                                                                                  null, null, null))
                    {
                        ProcdurePointerOrTCProcedureFunction = ambiguousSymbolReference.MainSymbolReference
                    };
                    callSite            = new CallSite();
                    callSite.CallTarget = statement.ProcdurePointerOrTCProcedureFunction;
                }
                else     //else, it's an error
                {
                    statement =
                        new ProcedureStyleCallStatement(new ProcedureCall(ambiguousSymbolReference.MainSymbolReference,
                                                                          null, null, null))
                    {
                        ProgramOrProgramEntryOrProcedureOrFunctionOrTCProcedureFunction =
                            ambiguousSymbolReference.MainSymbolReference,
                    };
                    statement.Diagnostics.Add(new Diagnostic(MessageCode.SyntaxErrorInParser, context.Start.Column,
                                                             context.Stop.Column, context.Start.Line, "Error in detecting Procedure Call type"));
                    callSite            = new CallSite();
                    callSite.CallTarget = statement.ProgramOrProgramEntryOrProcedureOrFunctionOrTCProcedureFunction;
                }
            }


            if (callSite != null)
            {
                if (statement.CallSites == null)
                {
                    statement.CallSites = new List <CallSite>();
                }
                statement.CallSites.Add(callSite);
            }

            CodeElement = statement;
        }
        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 if (context.cobol2002TypeClause() != null)
            {
                parameter.UserDefinedDataType =
                    CobolWordsBuilder.CreateQualifiedDataTypeReference(context.cobol2002TypeClause());
                if (parameter.UserDefinedDataType != null)
                {
                    parameter.DataType = DataType.CreateCustom(parameter.UserDefinedDataType.Name);
                }
            }
            else if (context.POINTER() != null)
            {
                parameter.Usage = CreateDataUsageProperty(DataUsage.Pointer, context.POINTER());
            }

            if (context.blankWhenZeroClause() != null)
            {
                var   blankClauseContext = context.blankWhenZeroClause();
                Token zeroToken;
                if (blankClauseContext.ZERO() != null)
                {
                    zeroToken = ParseTreeUtils.GetFirstToken(blankClauseContext.ZERO());
                }
                else if (blankClauseContext.ZEROS() != null)
                {
                    zeroToken = ParseTreeUtils.GetFirstToken(blankClauseContext.ZEROS());
                }
                else
                {
                    zeroToken = ParseTreeUtils.GetFirstToken(blankClauseContext.ZEROES());
                }
                parameter.IsBlankWhenZero = new SyntaxProperty <bool>(true, zeroToken);
            }

            if (context.justifiedClause() != null)
            {
                var   justifiedClauseContext = context.justifiedClause();
                Token justifiedToken         = null;
                if (justifiedClauseContext.JUSTIFIED() != null)
                {
                    justifiedToken = ParseTreeUtils.GetFirstToken(justifiedClauseContext.JUSTIFIED());
                }
                else
                {
                    justifiedToken = ParseTreeUtils.GetFirstToken(justifiedClauseContext.JUST());
                }
                parameter.IsJustified = new SyntaxProperty <bool>(true, justifiedToken);
            }

            if (context.synchronizedClause() != null)
            {
                var synchronizedClauseContext = context.synchronizedClause();
                if (synchronizedClauseContext.SYNCHRONIZED() != null)
                {
                    parameter.IsSynchronized = new SyntaxProperty <bool>(true,
                                                                         ParseTreeUtils.GetFirstToken(synchronizedClauseContext.SYNCHRONIZED()));
                }
                else
                {
                    parameter.IsSynchronized = new SyntaxProperty <bool>(true,
                                                                         ParseTreeUtils.GetFirstToken(synchronizedClauseContext.SYNC()));
                }
            }

            if (context.groupUsageClause() != null)
            {
                var groupUsageClauseContext = context.groupUsageClause();
                parameter.IsJustified = new SyntaxProperty <bool>(true,
                                                                  ParseTreeUtils.GetFirstToken(groupUsageClauseContext.NATIONAL()));
            }

            //No occurs clause because we only allow level 01

//            if (context.occursClause() != null && context.occursClause().Length > 0)
//            {
//                var occursClauseContext = context.occursClause()[0];
//                if (occursClauseContext.minNumberOfOccurences != null)
//                {
//                    parameter.MinOccurencesCount = CobolWordsBuilder.CreateIntegerValue(occursClauseContext.minNumberOfOccurences);
//                }
//                if (occursClauseContext.maxNumberOfOccurences != null)
//                {
//                    parameter.MaxOccurencesCount = CobolWordsBuilder.CreateIntegerValue(occursClauseContext.maxNumberOfOccurences);
//                }
//                if (parameter.MinOccurencesCount == null && parameter.MaxOccurencesCount != null)
//                {
//                    parameter.MinOccurencesCount = parameter.MaxOccurencesCount;
//                }
//                if (occursClauseContext.UNBOUNDED() != null)
//                {
//                    parameter.HasUnboundedNumberOfOccurences = new SyntaxProperty<bool>(true,
//                        ParseTreeUtils.GetFirstToken(occursClauseContext.UNBOUNDED()));
//                }
//                if (occursClauseContext.varNumberOfOccurences != null)
//                {
//                    parameter.OccursDependingOn = CobolExpressionsBuilder.CreateNumericVariable(occursClauseContext.varNumberOfOccurences);
//                }
//                if (occursClauseContext.tableSortingKeys() != null && occursClauseContext.tableSortingKeys().Length > 0)
//                {
//                    int keysCount = 0;
//                    foreach (var tableSortingKeysContext in occursClauseContext.tableSortingKeys())
//                    {
//                        keysCount += tableSortingKeysContext.dataNameReference().Length;
//                    }
//                    parameter.TableSortingKeys = new TableSortingKey[keysCount];
//                    int keyIndex = 0;
//                    foreach (var tableSortingKeysContext in occursClauseContext.tableSortingKeys())
//                    {
//                        SyntaxProperty<SortDirection> sortDirection = null;
//                        if (tableSortingKeysContext.ASCENDING() != null)
//                        {
//                            sortDirection = new SyntaxProperty<SortDirection>(SortDirection.Ascending,
//                                ParseTreeUtils.GetFirstToken(tableSortingKeysContext.ASCENDING()));
//                        }
//                        else
//                        {
//                            sortDirection = new SyntaxProperty<SortDirection>(SortDirection.Descending,
//                                ParseTreeUtils.GetFirstToken(tableSortingKeysContext.DESCENDING()));
//                        }
//                        foreach (var dataNameReference in tableSortingKeysContext.dataNameReference())
//                        {
//                            SymbolReference sortKey = CobolWordsBuilder.CreateDataNameReference(dataNameReference);
//                            parameter.TableSortingKeys[keyIndex] = new TableSortingKey(sortKey, sortDirection);
//                            keyIndex++;
//                        }
//                    }
//                }
//                if (occursClauseContext.indexNameDefinition() != null && occursClauseContext.indexNameDefinition().Length > 0)
//                {
//                    parameter.Indexes = new SymbolDefinition[occursClauseContext.indexNameDefinition().Length];
//                    for (int i = 0; i < occursClauseContext.indexNameDefinition().Length; i++)
//                    {
//                        var indexNameDefinition = occursClauseContext.indexNameDefinition()[i];
//                        parameter.Indexes[i] = CobolWordsBuilder.CreateIndexNameDefinition(indexNameDefinition);
//                    }
//                }
//            }

            if (context.signClause() != null)
            {
                var signClauseContext = context.signClause();
                if (signClauseContext.LEADING() != null)
                {
                    parameter.SignPosition = new SyntaxProperty <SignPosition>(SignPosition.Leading,
                                                                               ParseTreeUtils.GetFirstToken(signClauseContext.LEADING()));
                }
                else
                {
                    parameter.SignPosition = new SyntaxProperty <SignPosition>(SignPosition.Trailing,
                                                                               ParseTreeUtils.GetFirstToken(signClauseContext.TRAILING()));
                }
                if (signClauseContext.SEPARATE() != null)
                {
                    parameter.SignIsSeparate = new SyntaxProperty <bool>(true,
                                                                         ParseTreeUtils.GetFirstToken(signClauseContext.SEPARATE()));
                }
            }

            //As POINTER can already be defined in Usage property, we don't want to overwrite it
            if (parameter.Usage == null)
            {
                if (context.FUNCTION_POINTER() != null)
                {
                    parameter.Usage = CreateDataUsageProperty(DataUsage.FunctionPointer, context.FUNCTION_POINTER());
                }
                else if (context.PROCEDURE_POINTER() != null)
                {
                    parameter.Usage = CreateDataUsageProperty(DataUsage.ProcedurePointer, context.PROCEDURE_POINTER());
                }
                else if (context.tcfuncParameterUsageClause() != null)
                {
                    parameter.Usage = CreateTCFuncParameterUsageClause(context.tcfuncParameterUsageClause());
                }
            }

            if (context.valueClause() != null)
            {
                var valueClauseContext = context.valueClause();
                parameter.InitialValue = CobolWordsBuilder.CreateValue(valueClauseContext.value2());
            }

            if (context.QuestionMark() != null)
            {
                parameter.Omittable = new SyntaxProperty <bool>(true, ParseTreeUtils.GetTokenFromTerminalNode(context.QuestionMark()));
            }

            return(parameter);
        }
示例#12
0
 internal static void AddError(Node node, string message, Antlr4.Runtime.RuleContext context, MessageCode code = MessageCode.SyntaxErrorInParser)
 {
     AddError(node, message, ParseTreeUtils.GetFirstToken(context), RuleStackBuilder.GetRuleStack(context), code);
 }
示例#13
0
        public override void EnterCopyCompilerStatementBody(CobolCompilerDirectivesParser.CopyCompilerStatementBodyContext context)
        {
            var copy = (CopyDirective)CompilerDirective;

            if (context.qualifiedTextName() != null)
            {
                var ctxt = context.qualifiedTextName();
                copy.TextName       = GetTextName(ctxt.textName());
                copy.TextNameSymbol = ParseTreeUtils.GetFirstToken(ctxt.textName());
#if EUROINFO_LEGACY_REPLACING_SYNTAX
                if (copy.TextName != null)
                {
                    // Find the list of copy text names variations declared by previous REMARKS compiler directives
                    var variations = CopyTextNameVariations;
                    if (TypeCobolOptions.AutoRemarksEnable && (variations == null || !variations.Any(v => string.Equals(v.TextNameWithSuffix, copy.TextName, StringComparison.InvariantCultureIgnoreCase)))) //If it does not exists, create the text variation (AutoRemarks mechanism Issue #440)
                    {
                        variations = new List <RemarksDirective.TextNameVariation>
                        {
                            new RemarksDirective.TextNameVariation(copy.TextName)
                        };

                        CopyTextNameVariations.AddRange(variations);
                    }

                    if (variations != null)
                    {
                        var declaration = variations.Find(d => String.Equals(d.TextNameWithSuffix, copy.TextName, StringComparison.InvariantCultureIgnoreCase));
                        if (declaration != null)
                        {
                            // Declaration found => apply the legacy REPLACING semantics to the copy directive
                            copy.RemoveFirst01Level = true;
                            if (declaration.HasSuffix)
                            {
                                copy.TextName         = declaration.TextName;
                                copy.InsertSuffixChar = true;
                                copy.Suffix           = declaration.Suffix;
                                copy.PreSuffix        = declaration.PreSuffix;
                            }
                        }
                    }
                }
#endif
                copy.LibraryName       = GetLibraryName(ctxt.libraryName());
                copy.LibraryNameSymbol = ParseTreeUtils.GetFirstToken(ctxt.libraryName());
            }
            copy.Suppress = (context.SUPPRESS() != null);

            // REPLACING
            if (context.copyReplacingOperand() != null)
            {
                // Data used to build the current replace operation
                Token   comparisonToken           = null;
                Token[] followingComparisonTokens = null;
                Token   replacementToken          = null;
                Token[] replacementTokens         = null;

                // Used to distinguish pseudo-text1 and pseudo-text2
                int pseudoTextIndex = 0;

                foreach (CobolCompilerDirectivesParser.CopyReplacingOperandContext replacingOperandContext in context.copyReplacingOperand())
                {
                    // Get relevant tokens
                    IList <IToken> operandTokens = null;
                    if (replacingOperandContext.pseudoText() != null)                       // Pseudo-text => List of tokens
                    {
                        if (replacingOperandContext.pseudoText()._pseudoTextTokens != null)
                        {
                            operandTokens = replacingOperandContext.pseudoText()._pseudoTextTokens;
                        }
                    }
                    else                         // Single token
                    {
                        if (replacingOperandContext.literalOrUserDefinedWordOReservedWordExceptCopy() != null)
                        {
                            var terminalNode = ParseTreeUtils.GetFirstTerminalNode(replacingOperandContext.literalOrUserDefinedWordOReservedWordExceptCopy());
                            operandTokens = new List <IToken>(1);
                            operandTokens.Add(terminalNode.Symbol);
                        }
                    }
                    BuildReplaceOperation(copy.ReplaceOperations, ref comparisonToken, ref followingComparisonTokens, ref replacementToken, ref replacementTokens, ref pseudoTextIndex, operandTokens);
                }
            }
        }
示例#14
0
 public override void EnterCopyCompilerStatement(CobolCompilerDirectivesParser.CopyCompilerStatementContext context)
 {
     CompilerDirective = new CopyDirective(CompilerDirectiveType.COPY, ParseTreeUtils.GetFirstToken(context.COPY()));
 }