Example #1
0
 public QualifierTokenCodeElement(TypeCobol.Compiler.Scanner.Token token) : base((CodeElementType)0)
 {
     base.ConsumedTokens = new List <TypeCobol.Compiler.Scanner.Token>();
     base.ConsumedTokens.Add(token);
 }
Example #2
0
 /// <summary>
 /// Token constructor
 /// </summary>
 /// <param name="token">The consumed token corresponding to this Picture</param>
 /// <param name="separateSign">a boolean value indicating whether the sign is separate character</param>
 public PictureType(TypeCobol.Compiler.Scanner.Token token, bool separateSign) : this()
 {
     ConsumedToken  = token;
     IsSeparateSign = separateSign;
 }
Example #3
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
                                GenerateQualifierToken item = new GenerateQualifierToken(
                                    new QualifierTokenCodeElement(sr.NameLiteral.Token), Items[j].ToString(),
                                    sourcePositions);
                                item.SetFlag(Node.Flag.HasBeenTypeCobolQualifierVisited, true);
                                sourceNode.Add(item);
                                if (tokenColonColon != null)
                                {
                                    item = new GenerateQualifierToken(new QualifierTokenCodeElement(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;
                }
            }
Example #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;
                }
                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;
                }
            }