示例#1
0
        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());
                parameter.DataType = DataType.CreateCustom(parameter.UserDefinedDataType.Name);
            }
            //TODO#245: subphrases
            return(parameter);
        }
        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);
        }