Exemple #1
0
 public GlobalDefinitions(Parser yyp, GlobalDefinitions gd, GlobalFunctionDefinition gfd) : base((yyp))
 {
     while (0 < gd.kids.Count) kids.Add(gd.kids.Pop());
     kids.Add(gfd);
 }
        /// <summary>
        ///     Generates the code for a GlobalFunctionDefinition node.
        /// </summary>
        /// <param name="gf">The GlobalFunctionDefinition node.</param>
        /// <returns>String containing C# code for GlobalFunctionDefinition gf.</returns>
        private string GenerateGlobalFunctionDefinition(GlobalFunctionDefinition gf)
        {
            MethodVariables.Clear();
            VariablesToRename.Clear();
            StringBuilder retstr = new StringBuilder();
            _currentGlobalFunctionDeclaration = gf;

            // we need to separate the argument declaration list from other kids
            List<SYMBOL> argumentDeclarationListKids = new List<SYMBOL>();
            List<SYMBOL> remainingKids = new List<SYMBOL>();

            foreach (SYMBOL kid in gf.kids)
                if (kid is ArgumentDeclarationList)
                    argumentDeclarationListKids.Add(kid);
                else
                    remainingKids.Add(kid);

            retstr.Append(
                GenerateIndented(String.Format("public System.Collections.IEnumerator {0}(", CheckName(gf.Name)), gf));

            IsParentEnumerable = true;

            // print the state arguments, if any
            List<ArgumentDeclarationList> args = new List<ArgumentDeclarationList>();
            foreach (SYMBOL kid in argumentDeclarationListKids)
            {
                ArgumentDeclarationList ADL = (ArgumentDeclarationList) kid;
                args.Add(ADL);
                retstr.Append(GenerateArgumentDeclarationList(ADL));
            }
            m_allMethods.Add(CheckName(gf.Name), args);

            retstr.Append(GenerateLine(")"));

            foreach (SYMBOL kid in remainingKids)
                retstr.Append(GenerateNode(kid));

            if (gf.ReturnType == "void")
            {
                int i;
                for (i = 1; i < 5; i++)
                {
                    if (retstr[retstr.Length - i] == '}')
                    {
                        retstr.Insert(retstr.Length - i, GenerateLine(" yield break;"));
                        break;
                    }
                }
            }

            IsParentEnumerable = false;
            _currentGlobalFunctionDeclaration = null;
            return retstr.ToString();
        }
Exemple #3
0
 public GlobalDefinitions(Parser yyp, GlobalFunctionDefinition gfd) : base((yyp))
 {
     kids.Add(gfd);
 }