Example #1
0
 public static void CheckPicture(CommonDataDescriptionAndDataRedefines codeElement)
 {
     if (codeElement.Picture != null)
     {
         foreach (Match match in Regex.Matches(codeElement.Picture.Value, @"\(([^)]*)\)"))
         {
             try //Try catch is here beacause of the risk to parse a non numerical value
             {
                 int value = int.Parse(match.Value, System.Globalization.NumberStyles.AllowParentheses);
             }
             catch (Exception)
             {
                 var m = "Given value is not correct : " + match.Value + " expected numerical value only";
                 DiagnosticUtils.AddError(codeElement, m);
             }
         }
     }
 }
Example #2
0
 /// <summary>
 /// Append in the given StringBuilder the name and any global attribute of the the given DataDefition object.
 /// </summary>
 /// <param name="buffer">The String Buffer</param>
 /// <param name="dataDef">The Data Definition object</param>
 /// <param name="globalSeen">Global token hass been already seen</param>
 internal static void AppendNameAndGlobalDataDef(StringBuilder buffer, DataDefinitionEntry dataDef, bool globalSeen)
 {
     if (dataDef.Name != null)
     {
         buffer.Append(' ').Append(dataDef.Name);
         if (!globalSeen)
         {
             if (dataDef is CommonDataDescriptionAndDataRedefines)
             {
                 CommonDataDescriptionAndDataRedefines cdadr = dataDef as CommonDataDescriptionAndDataRedefines;
                 if (cdadr.IsGlobal)
                 {
                     Token gtoken = GetToken(dataDef.ConsumedTokens, TokenType.GLOBAL);
                     buffer.Append(' ').Append(gtoken.Text);
                 }
             }
         }
     }
 }
Example #3
0
        public static void CheckPicture(Node node, CommonDataDescriptionAndDataRedefines customCodeElement = null)
        {
            var codeElement = customCodeElement ?? node.CodeElement as CommonDataDescriptionAndDataRedefines;

            if (codeElement?.Picture == null)
            {
                return;
            }


            // if there is not the same number of '(' than of ')'
            if ((codeElement.Picture.Value.Split('(').Length - 1) != (codeElement.Picture.Value.Split(')').Length - 1))
            {
                DiagnosticUtils.AddError(node, "missing '(' or ')'");
            }
            // if the first '(' is after first ')' OR last '(' is after last ')'
            else if (codeElement.Picture.Value.IndexOf("(", StringComparison.Ordinal) > codeElement.Picture.Value.IndexOf(")", StringComparison.Ordinal) ||
                     codeElement.Picture.Value.LastIndexOf("(", StringComparison.Ordinal) > codeElement.Picture.Value.LastIndexOf(")", StringComparison.Ordinal))
            {
                DiagnosticUtils.AddError(node, "missing '(' or ')'");
            }
            else
            {
                foreach (Match match in Regex.Matches(codeElement.Picture.Value, @"\(([^)]*)\)"))
                {
                    try //Try catch is here because of the risk to parse a non numerical value
                    {
                        int.Parse(match.Value, System.Globalization.NumberStyles.AllowParentheses);
                    }
                    catch (Exception)
                    {
                        var m = "Given value is not correct : " + match.Value + " expected numerical value only";
                        DiagnosticUtils.AddError(node, m, codeElement);
                    }
                }
            }
        }
Example #4
0
        public DataDefinition GetRedefinedVariable(DataRedefines redefinesNode, SymbolReference symbolReference)
        {
            var childrens = redefinesNode.Parent.Children;
            int index     = redefinesNode.Parent.IndexOf(redefinesNode);

            bool redefinedVariableFound = false;

            while (!redefinedVariableFound && index >= 0)
            {
                CommonDataDescriptionAndDataRedefines child = childrens[index].CodeElement as DataDescriptionEntry ??
                                                              (CommonDataDescriptionAndDataRedefines)
                                                              (childrens[index].CodeElement as DataRedefinesEntry);

                if (child != null && (child is DataDescriptionEntry || child is DataRedefinesEntry))
                {
                    if (child.DataName != null &&
                        string.Equals(child.DataName.Name, symbolReference.Name,
                                      StringComparison.InvariantCultureIgnoreCase))
                    {
                        return(childrens[index] as DataDefinition);
                    }
                    else if (child.DataName != null && child is DataDescriptionEntry &&
                             !string.Equals(child.DataName.Name, symbolReference.Name,
                                            StringComparison.InvariantCultureIgnoreCase))
                    {
                        return(null);
                    }
                }
                else
                {
                    return(null);
                }

                index--;
            }
            return(null);
        }
Example #5
0
        public override bool Visit(DataDefinition dataDefinition)
        {
            CommonDataDescriptionAndDataRedefines commonDataDataDefinitionCodeElement =
                dataDefinition.CodeElement as CommonDataDescriptionAndDataRedefines;

            if (commonDataDataDefinitionCodeElement != null)
            {
                CheckPicture(dataDefinition);
            }


            DataDefinitionEntry dataDefinitionEntry = dataDefinition.CodeElement as DataDefinitionEntry;

            if (dataDefinitionEntry == null)
            {
                return(true);
            }

            var levelNumber = dataDefinitionEntry.LevelNumber;

            if (levelNumber != null)
            {
                var dataDefinitionParent = (dataDefinition.Parent as DataDefinition);
                var levelNumberValue     = levelNumber.Value;
                if (dataDefinitionParent != null)
                {
                    //Check if DataDefinition is level 88 and declared under a Type BOOL variable
                    if (dataDefinitionParent.DataType == DataType.Boolean && levelNumberValue == 88)
                    {
                        DiagnosticUtils.AddError(dataDefinition.CodeElement,
                                                 "The Level 88 symbol '" + dataDefinition.Name + "' cannot be declared under a BOOL typed symbol");
                    }
                }
                else
                {
                    //Parent is not a DataDefinition so it's a top level data definition under a section (eg working-storage)
                    //These top level DataDefinition can only be level 01 or 77
                    if (!(levelNumberValue == 01 || levelNumberValue == 77))
                    {
                        DiagnosticUtils.AddError(dataDefinition.CodeElement,
                                                 "The variable '" + dataDefinition.Name + "' can only be of level 01 or 77", dataDefinitionEntry);
                    }
                }

                //Level 88 and 66 cannot have Children.
                if ((levelNumberValue == 88 || levelNumberValue == 66))
                {
                    if (dataDefinition.ChildrenCount != 0)
                    {
                        DiagnosticUtils.AddError(dataDefinition.CodeElement,
                                                 "The variable '" + dataDefinition.Name + "' with level 88 and 66 cannot be group item.", dataDefinitionEntry);
                    }

                    if (dataDefinition.Usage != null)
                    {
                        DiagnosticUtils.AddError(dataDefinition.CodeElement,
                                                 "The variable '" + dataDefinition.Name + "' with level 88 and 66 cannot have USAGE.", dataDefinitionEntry);
                    }
                }
            }


            if (HasChildrenThatDeclareData(dataDefinition))
            {
                if (dataDefinition.Picture != null)
                {
                    DiagnosticUtils.AddError(dataDefinition,
                                             "Group item " + dataDefinition.Name + " cannot have a \"PICTURE\"", dataDefinitionEntry);
                }

                if (commonDataDataDefinitionCodeElement?.UserDefinedDataType != null)
                {
                    DiagnosticUtils.AddError(dataDefinition,
                                             "Group item  " + dataDefinition.Name + " cannot have a \"TYPE\"", dataDefinitionEntry);
                }

                if (commonDataDataDefinitionCodeElement?.IsBlankWhenZero?.Value == true)
                {
                    DiagnosticUtils.AddError(dataDefinition,
                                             "Group itm " + dataDefinition.Name + " cannot have \"Blank when zero\" clause", dataDefinitionEntry);
                }

                return(true);
            }

            return(true);
        }