Esempio n. 1
0
            private void QualifiedStorageAreaSelecterForBoolean(StorageArea storage_area, Tuple <int, int, int, List <int>, List <int> > sourcePositions)
            {
                if (UsedStorageArea != null && UsedStorageArea.Contains(storage_area))
                {
                    return;
                }
                string        name = storage_area?.SymbolReference?.Name;
                GenerateToken item = null;

                item = new GenerateToken(
                    new TokenCodeElement(storage_area?.SymbolReference?.NameLiteral?.Token), name + "-value", sourcePositions);
                item.SetFlag(Node.Flag.HasBeenTypeCobolQualifierVisited, true);
                this.CurrentNode.Add(item);
                if (UsedStorageArea == null)
                {
                    UsedStorageArea = new HashSet <StorageArea>();
                }
                UsedStorageArea.Add(storage_area);
            }
Esempio n. 2
0
 /// <summary>
 /// The Goal of this override is to generate hash names for pure Cobol85 Indices used as Qualified Names.
 /// </summary>
 /// <param name="indexDefinition">The Index Definition instance</param>
 /// <returns>true do to keep on visiting, false otherwise.</returns>
 public override bool Visit(IndexDefinition indexDefinition)
 {
     if (indexDefinition.IsFlagSet(Node.Flag.HasBeenTypeCobolQualifierVisited))
     {
         return(true);
     }
     if (!indexDefinition.IsPartOfATypeDef && indexDefinition.Parent != null && indexDefinition.IsFlagSet(Node.Flag.IndexUsedWithQualifiedName))
     {//Check if the parent is a data definition with a type which is not a TypeDef
         var dataDef = indexDefinition.Parent as DataDefinition;
         if (dataDef != null)
         {
             var dde = dataDef.CodeElement as DataDescriptionEntry;
             if (dde != null)
             {
                 if (dde.Indexes != null)
                 {
                     foreach (var index in dde.Indexes)
                     {
                         if (index.Name.Equals(indexDefinition.Name))
                         {
                             Tuple <int, int, int, List <int>, List <int> > sourcePositions = this.Generator.FromToPositions(indexDefinition.Parent);
                             string        name           = index.Name;
                             string        qualified_name = indexDefinition.QualifiedName.ToString();
                             GenerateToken item           = null;
                             string        hashName       = GeneratorHelper.ComputeIndexHashName(qualified_name, indexDefinition.Parent);
                             item = new GenerateToken(
                                 new TokenCodeElement(index.NameLiteral.Token), hashName,
                                 sourcePositions);
                             item.SetFlag(Node.Flag.HasBeenTypeCobolQualifierVisited, true);
                             indexDefinition.Parent.Add(item);
                             break;
                         }
                     }
                 }
             }
         }
     }
     indexDefinition.SetFlag(Node.Flag.HasBeenTypeCobolQualifierVisited, true);
     return(true);
 }
Esempio n. 3
0
 private void QualifiedStorageAreaSelecterForIndexes(StorageArea storageArea, Tuple <int, int, int, List <int>, List <int> > sourcePositions)
 {
     if (storageArea.SymbolReference != null && !storageArea.SymbolReference.IsQualifiedReference)
     {
         if (UsedStorageArea != null && UsedStorageArea.Contains(storageArea))
         {
             return;
         }
         string        name           = storageArea.SymbolReference.Name;
         string        qualified_name = this.CurrentNode.QualifiedStorageAreas[storageArea];
         GenerateToken item           = null;
         string        hashName       = GeneratorHelper.ComputeIndexHashName(qualified_name, this.CurrentNode);
         item = new GenerateToken(
             new TokenCodeElement(storageArea.SymbolReference.NameLiteral.Token), hashName, sourcePositions);
         item.SetFlag(Node.Flag.HasBeenTypeCobolQualifierVisited, true);
         this.CurrentNode.Add(item);
         if (UsedStorageArea == null)
         {
             UsedStorageArea = new HashSet <StorageArea>();
         }
         UsedStorageArea.Add(storageArea);
     }
 }
Esempio n. 4
0
            /// <summary>
            /// Perform the qualification action
            /// </summary>
            /// <param name="sourceNode">The source Node on which to perform teh action</param>
            /// <param name="visitor">The Visitor which as locate teh Source Node</param>
            internal void Perform(Node sourceNode)
            {
                if (sourceNode.IsFlagSet(Node.Flag.HasBeenTypeCobolQualifierVisited))
                {
                    return;
                }
                //Now this Node Is Visited
                sourceNode.SetFlag(Node.Flag.HasBeenTypeCobolQualifierVisited, true);
                Tuple <int, int, int, List <int>, List <int> > sourcePositions = this.Generator.FromToPositions(sourceNode);
                IList <TypeCobol.Compiler.Scanner.Token>       nodeTokens      = sourceNode.CodeElement.ConsumedTokens;
                List <Tuple <int, int> > boundaries = ItemsListIndexBoundary(nodeTokens);
                int  b            = 0;
                bool bWasProcCall = false;

                foreach (var items in AllItemsList)
                {
                    string           hashFunction;
                    bool             bProcCall = IsProcedureStyleCallItems(items, out hashFunction);
                    Tuple <int, int> range     = boundaries[b++];
                    Items = items;
                    int i = range.Item1;
                    if (bProcCall)
                    {   //----------------------------------------------------------------------------------------------
                        // This is for a procedure call.
                        // The Code below is commented. This code was used to test that in normal situation
                        // The TypeCobolQualifierReference for the function name can be replaced by a the hash code name.
                        //----------------------------------------------------------------------------------------------
                        //SymbolReference sr1 = Items[Items.Count - 1];
                        //SymbolReference sr2 = Items[0];
                        //List<TypeCobol.Compiler.Scanner.Token> consumedTokens = new List<TypeCobol.Compiler.Scanner.Token>();
                        //for (; i <= range.Item2; i++)
                        //{
                        //    if (nodeTokens[i] == sr1.NameLiteral.Token)
                        //    {
                        //        consumedTokens.Add(nodeTokens[i]);
                        //    }
                        //    else if (nodeTokens[i] == sr2.NameLiteral.Token)
                        //    {
                        //        consumedTokens.Add(nodeTokens[i]);
                        //        break;
                        //    }
                        //}
                        //GenerateQualifierToken item = new GenerateQualifierToken(new QualifierTokenCodeElement(consumedTokens), "'" + hashFunction + "'",
                        //    sourcePositions);
                        //item.SetFlag(Node.Flag.HasBeenTypeCobolQualifierVisited, true);
                        //sourceNode.Add(item);
                        //------------------------------------------------------------------------------------------------------------------------

                        bWasProcCall = true; //Remember that we have a Procedure Style Call Node.
                        continue;            //Continue
                    }
                    for (int j = 0; j < Items.Count; j++)
                    {
                        SymbolReference sr = Items[Items.Count - j - 1];
                        for (; i <= range.Item2; i++)
                        {
                            if (nodeTokens[i] == sr.NameLiteral.Token)
                            {
                                TypeCobol.Compiler.Scanner.Token tokenColonColon = null;
                                //Look for the corresponding ::
                                for (++i; i <= range.Item2; i++)
                                {
                                    if (!(nodeTokens[i] is TypeCobol.Compiler.Preprocessor.ImportedToken))
                                    {
                                        if (nodeTokens[i].TokenType == TypeCobol.Compiler.Scanner.TokenType.QualifiedNameSeparator)
                                        {
                                            tokenColonColon = nodeTokens[i];
                                            i++;
                                            break;
                                        }
                                    }
                                }
                                //We got It ==> Create our Generate Nodes
                                GenerateToken item = new GenerateToken(
                                    new TokenCodeElement(sr.NameLiteral.Token), Items[j].ToString(),
                                    sourcePositions);
                                item.SetFlag(Node.Flag.HasBeenTypeCobolQualifierVisited, true);
                                sourceNode.Add(item);
                                if (tokenColonColon != null)
                                {
                                    item = new GenerateToken(new TokenCodeElement(tokenColonColon), string.Intern(" OF "),
                                                             sourcePositions);
                                    item.SetFlag(Node.Flag.HasBeenTypeCobolQualifierVisited, true);
                                    sourceNode.Add(item);
                                }
                                break;//We got it
                            }
                        }
                    }
                }
                //Now Comment the Source Node, only and only if it was not a Procedure Style Call,
                //Because the Qualifier action is the first action performed, before any Expand action.
                //Expand Action does not expand Commented Nodes, it will comment theses nodes itself.
                if (!bWasProcCall)
                {
                    sourceNode.Comment = true;
                }
            }
Esempio n. 5
0
            /// <summary>
            /// Perform the qualification action
            /// </summary>
            /// <param name="sourceNode">The source Node on which to perform teh action</param>
            /// <param name="visitor">The Visitor which as locate teh Source Node</param>
            internal void Perform(Node sourceNode)
            {
                if (sourceNode.IsFlagSet(Node.Flag.HasBeenTypeCobolQualifierVisited))
                {
                    return;
                }
                TypeCobol.Compiler.Nodes.DataDescription dataDescription = null;
                if (sourceNode is TypeCobol.Compiler.Nodes.DataDescription && IsTypeDefinition(sourceNode as TypeCobol.Compiler.Nodes.DataDescription))
                {
                    dataDescription = sourceNode as TypeCobol.Compiler.Nodes.DataDescription;
                    if (dataDescription.QualifiedTokenSubsitutionMap == null)
                    {
                        dataDescription.QualifiedTokenSubsitutionMap = new Dictionary <Compiler.Scanner.Token, string>();
                    }
                }

                //Now this Node Is Visited
                sourceNode.SetFlag(Node.Flag.HasBeenTypeCobolQualifierVisited, true);
                Tuple <int, int, int, List <int>, List <int> > sourcePositions = this.Generator.FromToPositions(sourceNode);
                IList <TypeCobol.Compiler.Scanner.Token>       nodeTokens      = sourceNode.CodeElement.ConsumedTokens;
                List <Tuple <int, int> > boundaries = ItemsListIndexBoundary(nodeTokens);
                int  b            = 0;
                bool bWasProcCall = false;

                foreach (var items in AllItemsList)
                {
                    string           hashFunction;
                    bool             bProcCall = IsProcedureStyleCallItems(items, out hashFunction);
                    Tuple <int, int> range     = boundaries[b++];
                    Items = items;
                    int i = range.Item1;
                    if (bProcCall)
                    {   //----------------------------------------------------------------------------------------------
                        // This is for a procedure call.
                        // The Code below is commented. This code was used to test that in normal situation
                        // The TypeCobolQualifierReference for the function name can be replaced by a the hash code name.
                        //----------------------------------------------------------------------------------------------
                        //SymbolReference sr1 = Items[Items.Count - 1];
                        //SymbolReference sr2 = Items[0];
                        //List<TypeCobol.Compiler.Scanner.Token> consumedTokens = new List<TypeCobol.Compiler.Scanner.Token>();
                        //for (; i <= range.Item2; i++)
                        //{
                        //    if (nodeTokens[i] == sr1.NameLiteral.Token)
                        //    {
                        //        consumedTokens.Add(nodeTokens[i]);
                        //    }
                        //    else if (nodeTokens[i] == sr2.NameLiteral.Token)
                        //    {
                        //        consumedTokens.Add(nodeTokens[i]);
                        //        break;
                        //    }
                        //}
                        //GenerateQualifierToken item = new GenerateQualifierToken(new QualifierTokenCodeElement(consumedTokens), "'" + hashFunction + "'",
                        //    sourcePositions);
                        //item.SetFlag(Node.Flag.HasBeenTypeCobolQualifierVisited, true);
                        //sourceNode.Add(item);
                        //------------------------------------------------------------------------------------------------------------------------

                        bWasProcCall = true; //Remember that we have a Procedure Style Call Node.
                        continue;            //Continue
                    }
                    if (sourceNode.IsFlagSet(Node.Flag.NodeContainsIndex))
                    {
                        //So we must know if this qualified name is for an Index Name
                        string qualified_name;
                        bool   bAreIn = AreItemsInNodeQualifiedStorageAreas(items, sourceNode, out qualified_name);
                        if (bAreIn)
                        {
                            GenerateToken item     = null;
                            string        hashName = GeneratorHelper.ComputeIndexHashName(qualified_name, sourceNode);
                            //Now all items in the qualified name must be replaced with the hash name by the Generator.
                            //So all items except the last one are replaced by a blank, the last item will be the HashName
                            for (int r = i; r <= range.Item2 - 1; r++)
                            {
                                item = new GenerateToken(
                                    new TokenCodeElement(nodeTokens[r]), "",
                                    sourcePositions);
                                item.SetFlag(Node.Flag.HasBeenTypeCobolQualifierVisited, true);
                                sourceNode.Add(item);
                            }
                            item = new GenerateToken(
                                new TokenCodeElement(nodeTokens[range.Item2]), hashName,
                                sourcePositions);
                            item.SetFlag(Node.Flag.HasBeenTypeCobolQualifierVisited, true);
                            sourceNode.Add(item);
                            continue;
                        }
                    }

                    for (int j = 0; j < Items.Count; j++)
                    {
                        SymbolReference sr = Items[Items.Count - j - 1];
                        for (; i <= range.Item2; i++)
                        {
                            if (nodeTokens[i] == sr.NameLiteral.Token)
                            {
                                TypeCobol.Compiler.Scanner.Token tokenColonColon = null;
                                //Look for the corresponding ::
                                for (++i; i <= range.Item2; i++)
                                {
                                    if (!(nodeTokens[i] is TypeCobol.Compiler.Preprocessor.ImportedToken))
                                    {
                                        if (nodeTokens[i].TokenType == TypeCobol.Compiler.Scanner.TokenType.QualifiedNameSeparator)
                                        {
                                            tokenColonColon = nodeTokens[i];
                                            i++;
                                            break;
                                        }
                                    }
                                }
                                //We got It ==> Create our Generate Nodes
                                if (dataDescription != null)
                                {
                                    dataDescription.QualifiedTokenSubsitutionMap[sr.NameLiteral.Token] = Items[j].ToString();
                                    if (tokenColonColon != null)
                                    {
                                        dataDescription.QualifiedTokenSubsitutionMap[tokenColonColon] = "OF";
                                    }
                                }
                                else
                                {
                                    GenerateToken item          = null;
                                    string        replace_value = Items[j].ToString();

                                    if (this.CurrentNode.IsFlagSet(Node.Flag.NodeContainsBoolean))
                                    {
                                        if (this.CurrentNode.QualifiedStorageAreas.Keys.Any(flaggedStorageArea => flaggedStorageArea?.SymbolReference?.NameLiteral.Value == replace_value))
                                        {
                                            replace_value = replace_value + "-value";
                                        }
                                    }

                                    item = new GenerateToken(new TokenCodeElement(sr.NameLiteral.Token), replace_value, sourcePositions);
                                    item.SetFlag(Node.Flag.HasBeenTypeCobolQualifierVisited, true);
                                    sourceNode.Add(item);
                                    if (tokenColonColon != null)
                                    {
                                        item = new GenerateToken(new TokenCodeElement(tokenColonColon), string.Intern(" OF "),
                                                                 sourcePositions);
                                        item.SetFlag(Node.Flag.HasBeenTypeCobolQualifierVisited, true);
                                        sourceNode.Add(item);
                                    }
                                }
                                break;//We got it
                            }
                        }
                    }
                }
                //Now Comment the Source Node, only and only if it was not a Procedure Style Call,
                //Because the Qualifier action is the first action performed, before any Expand action.
                //Expand Action does not expand Commented Nodes, it will comment theses nodes itself.
                if (!bWasProcCall)
                {
                    sourceNode.Comment = true;
                }
            }
Esempio n. 6
0
            /// <summary>
            /// Generate TypeCobol Qualified Symbol Reference node for a given StorageArea.
            /// </summary>
            /// <param name="storageArea">The Storage Area to generate the node</param>
            /// <param name="codeElement">The underlying code element</param>
            /// <returns>true if some nodes have been generated, false otherwise</returns>
            private bool GenQualifiedStorage(StorageArea storageArea, CodeElement codeElement)
            {
                if (storageArea.SymbolReference != null && !storageArea.SymbolReference.IsTypeCobolQualifiedReference)
                {
                    return(false);
                }
                if (CurrentNode == null)
                {
                    return(false);
                }
                TypeCobolQualifiedSymbolReference tcqsr = storageArea.SymbolReference as TypeCobolQualifiedSymbolReference;
                int start = -1;

                for (int i = 0; i < codeElement.ConsumedTokens.Count; i++)
                {
                    if (codeElement.ConsumedTokens[i] == tcqsr?.Head.NameLiteral.Token)
                    {
                        start = i;
                        break;
                    }
                }
                int end = -1;

                for (int i = 0; i < codeElement.ConsumedTokens.Count; i++)
                {
                    if (codeElement.ConsumedTokens[i] == tcqsr?.Tail.NameLiteral.Token)
                    {
                        end = i;
                        break;
                    }
                }
                List <GenerateToken> items = new List <GenerateToken>();
                List <string>        names = new List <string>();

                for (int i = end; i <= start; i++)
                {
                    if (codeElement.ConsumedTokens[i].TokenType == Compiler.Scanner.TokenType.QualifiedNameSeparator)
                    {
                        GenerateToken qns = new GenerateToken(new TokenCodeElement(codeElement.ConsumedTokens[i]), string.Intern(" OF "),
                                                              null);
                        qns.SetFlag(Node.Flag.HasBeenTypeCobolQualifierVisited, true);
                        CurrentNode.Add(qns);
                    }
                    else
                    {
                        GenerateToken item = new GenerateToken(
                            new TokenCodeElement(codeElement.ConsumedTokens[i]), codeElement.ConsumedTokens[i].Text,
                            null);
                        item.SetFlag(Node.Flag.HasBeenTypeCobolQualifierVisited, true);
                        CurrentNode.Add(item);
                        items.Add(item);
                        names.Add(codeElement.ConsumedTokens[i].Text);
                    }
                }
                names.Reverse();
                for (int i = 0; i < names.Count; i++)
                {
                    items[i].ReplaceCode = names[i];
                }
                return(items.Count > 0);
            }