コード例 #1
0
        /// <summary>
        /// Build the Dictionary that associate a token of an index-name-1 to its hash + name.
        /// </summary>
        /// <param name="indexes">The Array of Index Symbol Definition</param>
        /// <param name="ownerDefinition">The Owner of the definition that contains the INDEXED BY clause</param>
        /// <returns>The Dictionary</returns>
        private static Dictionary <Compiler.Scanner.Token, string> BuiltIndexMap(List <string> rootProcedures, List <Tuple <string, string> > rootVariableName, SymbolDefinition[] indexes, TypeCobol.Compiler.Nodes.DataDefinition ownerDefinition)
        {
            Dictionary <Compiler.Scanner.Token, string> map = new Dictionary <Compiler.Scanner.Token, string>(indexes.Length);
            List <string> pathProcedures;
            List <string> pathVariables;

            GeneratorHelper.ComputeProperPaths(ownerDefinition, out pathProcedures, out pathVariables);
            List <string> list_items = new List <string>();

            //list_items.AddRange(pathProcedures);

            //Add root procedures

            for (int j = rootProcedures.Count - 1; j >= 0; j--)
            {
                list_items.Add(rootProcedures[j]);
            }

            //Add Root variables
            for (int j = rootVariableName.Count - 1; j >= 0; j--)
            {
                list_items.Add(rootVariableName[j].Item1);
                if (j != 0 && rootVariableName[j].Item2 != null && rootVariableName[j].Item2.Trim().Length > 0)
                {
                    list_items.Add(rootVariableName[j].Item2);
                }
            }

            list_items.AddRange(pathVariables);
            string qn = string.Join(".", list_items.ToArray());

            foreach (Node child in ownerDefinition.Children)
            {
                if (child is IndexDefinition)
                {
                    IndexDefinition index = child as IndexDefinition;
                    foreach (SymbolDefinition sym in indexes)
                    {
                        if (sym.Name.Equals(index.Name))
                        {
                            string qualified_name = qn + '.' + index.Name;
                            string hash_name      = GeneratorHelper.ComputeIndexHashName(qualified_name, ownerDefinition);
                            map[sym.NameLiteral.Token] = hash_name;
                        }
                    }
                }
            }
            return(map);
        }
コード例 #2
0
ファイル: TypedDataNode.cs プロジェクト: telkomops/TypeCobol
 /// <summary>
 /// Add In the Index Map all indices that match an IndexDefinition children node of a parent node.
 /// </summary>
 /// <param name="parentNode">The parent Node</param>
 /// <param name="qn">Root qualified name of the indes</param>
 /// <param name="indexes">SymbolDefinition[] indexes</param>
 /// <param name="map">Map of token indexes to their hashname</param>
 private static void AddIndexMap(Node parentNode, string qn, SymbolDefinition[] indexes, Dictionary <Compiler.Scanner.Token, string> map)
 {
     foreach (Node child in parentNode.Children)
     {
         if (child is IndexDefinition)
         {
             IndexDefinition index = child as IndexDefinition;
             foreach (SymbolDefinition sym in indexes)
             {
                 if (sym.Name.Equals(index.Name))
                 {
                     string qualified_name = qn + '.' + index.Name;
                     string hash_name      = GeneratorHelper.ComputeIndexHashName(qualified_name, parentNode);
                     map[sym.NameLiteral.Token] = hash_name;
                 }
             }
         }
     }
 }
コード例 #3
0
ファイル: Qualifier.cs プロジェクト: fjsnogueiraCx/TypeCobol
 /// <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);
 }
コード例 #4
0
ファイル: Qualifier.cs プロジェクト: fjsnogueiraCx/TypeCobol
 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);
     }
 }
コード例 #5
0
ファイル: Qualifier.cs プロジェクト: fjsnogueiraCx/TypeCobol
            /// <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;
                }
            }