示例#1
0
        private static void CheckParameter([NotNull] ParameterDescriptionEntry parameter, Node node)
        {
            // TCRFUN_LEVEL_88_PARAMETERS
            if (parameter.LevelNumber?.Value != 1)
            {
                DiagnosticUtils.AddError(node,
                                         "Condition parameter \"" + parameter.Name + "\" must be subordinate to another parameter.");
            }
            if (parameter.DataConditions != null)
            {
                foreach (var condition in parameter.DataConditions)
                {
                    if (condition.LevelNumber?.Value != 88)
                    {
                        DiagnosticUtils.AddError(node,
                                                 "Condition parameter \"" + condition.Name + "\" must be level 88.");
                    }
                    if (condition.LevelNumber?.Value == 88 && parameter.DataType == DataType.Boolean)
                    {
                        DiagnosticUtils.AddError(node,
                                                 "The Level 88 symbol '" + parameter.Name + "' cannot be declared under a BOOL typed symbol");
                    }
                }
            }

            if (parameter.Picture != null)
            {
                CrossCompleteChecker.CheckPicture(node, parameter);
            }

            var            type = parameter.DataType;
            TypeDefinition foundedType;

            TypeDefinitionHelper.Check(node, type, out foundedType); //Check if the type exists and is not ambiguous
        }
示例#2
0
 public ParametersProfile()
 {
     InputParameters    = new List <ParameterDescriptionEntry>();
     InoutParameters    = new List <ParameterDescriptionEntry>();
     OutputParameters   = new List <ParameterDescriptionEntry>();
     ReturningParameter = null;
 }
示例#3
0
 public ParametersProfile() : base(CodeElementType.ParametersProfile)
 {
     InputParameters    = new List <ParameterDescriptionEntry>();
     InoutParameters    = new List <ParameterDescriptionEntry>();
     OutputParameters   = new List <ParameterDescriptionEntry>();
     ReturningParameter = null;
 }
示例#4
0
        private void CheckParameter([NotNull] ParameterDescriptionEntry parameter, CodeElement ce, ParserRuleContext context, Node node)
        {
            // TCRFUN_LEVEL_88_PARAMETERS
            if (parameter.LevelNumber.Value != 1)
            {
                DiagnosticUtils.AddError(ce, "Condition parameter \"" + parameter.Name + "\" must be subordinate to another parameter.", context);
            }
            if (parameter.DataConditions != null)
            {
                foreach (var condition in parameter.DataConditions)
                {
                    if (condition.LevelNumber.Value != 88)
                    {
                        DiagnosticUtils.AddError(ce, "Condition parameter \"" + condition.Name + "\" must be level 88.");
                    }
                }
            }

            if (parameter.Picture != null)
            {
                Cobol85CompleteASTChecker.CheckPicture(parameter);
            }

            var type = parameter.DataType;

            TypeDefinitionHelper.Check(node, type); //Check if the type exists and is not ambiguous
        }
示例#5
0
 private static ParameterDescriptionEntry Validate(ParameterDescriptionEntry parameter, string name)
 {
     if (parameter != null && parameter.Name.Equals(name))
     {
         return(parameter);
     }
     return(null);
 }
示例#6
0
 private static CallParameter Create(ParameterDescriptionEntry pAsDefined, CallParameter pAsUsed)
 {
     if (pAsUsed != null)
     {
         return(pAsUsed);
     }
     return(new EmptyCallParameter());
 }
        private ParameterDescriptionEntry CreateFunctionDataParameter(DataConditionEntry condition)
        {
            var data = new ParameterDescriptionEntry();

            data.LevelNumber = condition.LevelNumber;
            data.DataName    = condition.DataName;
            data.DataType    = DataType.Unknown;
            return(data);
        }
        private static CallTargetParameter CreateCallTargetParameter(ParameterDescriptionEntry param)
        {
            var symbolReference = new SymbolReference(param.DataName);
            var storageArea     = new DataOrConditionStorageArea(symbolReference);
            var callParameter   = new CallTargetParameter {
                StorageArea = storageArea
            };

            return(callParameter);
        }
        private ParameterEntry CreateParameterEntry(ParameterDescriptionEntry parameter, Compiler.CodeModel.SymbolTable table)
        {
            var generated = new ParameterEntry(parameter, table);

            if (parameter.DataConditions != null)
            {
                foreach (var child in parameter.DataConditions)
                {
                    generated.Add(new DataCondition(child));
                }
            }
            return(generated);
        }
示例#10
0
 private string encode(ParameterDescriptionEntry parameter)
 {
     if (parameter == null)
     {
         return("?");
     }
     if (parameter.Picture != null)
     {
         return(parameter.Picture.ToString());
     }
     if (parameter.DataType != null)
     {
         return("T(" + parameter.DataType.Name + ")");
     }
     return("??");
 }
示例#11
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);
        }
示例#13
0
 public ParameterDescription(ParameterDescriptionEntry entry) : base(entry)
 {
 }
示例#14
0
 /// <summary>Creates function.</summary>
 public Function(QualifiedName name, IList <ParameterDescriptionEntry> inputs, ParameterDescriptionEntry returning, AccessModifier visibility = AccessModifier.Private)
     : this(name, inputs, null, null, returning, visibility)
 {
 }
示例#15
0
 public virtual bool Visit(ParameterDescriptionEntry parameterDescriptionEntry)
 {
     return(true);
 }
示例#16
0
 public ParameterDescription(ParameterDescriptionEntry entry)
     : base(entry)
 {
 }
示例#17
0
 /// <summary>Creates functions or procedure</summary>
 public Function(QualifiedName name, IList <ParameterDescriptionEntry> inputs, IList <ParameterDescriptionEntry> outputs, IList <ParameterDescriptionEntry> inouts, ParameterDescriptionEntry returning, AccessModifier visibility = AccessModifier.Private)
 {
     QualifiedName              = name;
     Profile                    = new ParametersProfile();
     Profile.InputParameters    = inputs ?? new List <ParameterDescriptionEntry>();
     Profile.OutputParameters   = outputs ?? new List <ParameterDescriptionEntry>();
     Profile.InoutParameters    = inouts ?? new List <ParameterDescriptionEntry>();
     Profile.ReturningParameter = returning;
     Visibility                 = visibility;
 }