Ejemplo n.º 1
0
 public IReadOnlyList <List <HandleAction> > Recipes(TokenPlan tp) => _data[tp].Recipes;
Ejemplo n.º 2
0
        private static void GenerateLexBranch(SwitchCaseStmt swLex, string hpk, IReadOnlyList <string> guardFlags,
                                              IReadOnlyList <List <HandleAction> > recipes, TokenPlan reactOn, bool matchChar)
        {
            var branchLex = new List <C.CsStmt>();

            Console.WriteLine($"[IR] in '{hpk}', handle {reactOn.Value}");
            bool onlyWraps = true;
            var  ite       = new C.IfThenElse();

            for (int i = 0; i < guardFlags.Count; i++)
            {
                if (!String.IsNullOrEmpty(guardFlags[i]))
                {
                    ite.AddBranch(guardFlags[i]);
                }
                var target
                    = String.IsNullOrEmpty(guardFlags[i])
                        ? branchLex
                        : ite.GetThenBranch(guardFlags[i]);
                foreach (var action in recipes[i])
                {
                    if (!(action is WrapOne))
                    {
                        onlyWraps = false;
                    }
                    if (action != null)
                    {
                        if (action is WrapOne)
                        {
                            var fake = new List <CsStmt>();
                            action.GenerateAbstractCode(fake);
                            if (fake.Count == 1 && fake[0] is IfThenElse ite2)
                            {
                                var newcond = guardFlags[i] + " && " + ite2.FirstThenBranchKey();
                                ite.RenameBranch(guardFlags[i], newcond);
                                foreach (CsStmt stmt in ite2.FirstThenBranchValue())
                                {
                                    ite.AddToBranch(newcond, stmt);
                                }
                            }
                            else
                            {
                                Console.WriteLine("[ERR] This particular usage of WRAP is not supported yet");
                            }
                        }
                        else
                        {
                            action.GenerateAbstractCode(target);
                        }
                    }
                    else
                    {
                        Console.WriteLine($"[B2C] Warning: no action to handle '{hpk}'/{reactOn.Value}");
                    }
                }
            }

            string flags;

            if (guardFlags.Count == 1)
            {
                flags = "flag " + guardFlags[0] + " is not";
            }
            else
            {
                flags = "neither of the flags " + String.Join(", ", guardFlags) + " are";
            }
            branchLex.Add(ite);
            if (!onlyWraps)
            {
                if (guardFlags.Any(f => !String.IsNullOrEmpty(f)))
                {
                    ite.AddElse($"ERROR = \"{flags} lifted when expected\"");
                }
            }
            if (matchChar)
            {
                swLex.Branches["'" + reactOn.Value + "'"] = branchLex;
            }
            else
            {
                swLex.Branches['"' + reactOn.Value + '"'] = branchLex;
            }
        }
Ejemplo n.º 3
0
 public IReadOnlyList <string> GuardFlags(TokenPlan tp) => _data[tp].GuardFlags;