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());
        }
        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;
            }
        }
示例#3
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
                }
            }
        }
示例#4
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);
                }
            }
        }
        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);
        }