Exemplo n.º 1
0
        private IRRule ASTRuleToIR(IRGoal goal, ASTRule astRule)
        {
            var rule = new IRRule
            {
                Goal            = goal,
                Type            = astRule.Type,
                Conditions      = new List <IRCondition>(astRule.Conditions.Count),
                Actions         = new List <IRStatement>(astRule.Actions.Count),
                Variables       = new List <IRRuleVariable>(),
                VariablesByName = new Dictionary <String, IRRuleVariable>(),
                Location        = astRule.Location
            };

            foreach (var condition in astRule.Conditions)
            {
                rule.Conditions.Add(ASTConditionToIR(rule, condition));
            }

            foreach (var action in astRule.Actions)
            {
                rule.Actions.Add(ASTActionToIR(rule, action));
            }

            return(rule);
        }
Exemplo n.º 2
0
        public bool RegisterGoal(IRGoal goal)
        {
            if (GoalsByName.ContainsKey(goal.Name))
            {
                Log.Error(null, DiagnosticCode.GoalAlreadyDefined,
                          String.Format("Goal already registered: {0}", goal.Name));
                return(false);
            }

            GoalsByName.Add(goal.Name, goal);
            return(true);
        }
Exemplo n.º 3
0
 public void AddGoal(IRGoal goal)
 {
     Context.RegisterGoal(goal);
     foreach (var rule in goal.KBSection)
     {
         if (rule.Type == RuleType.Query
             || rule.Type == RuleType.Proc)
         {
             AddQueryOrProc(rule);
         }
     }
 }
Exemplo n.º 4
0
        private IRFact ASTFactToIR(IRGoal goal, ASTBaseFact astFact)
        {
            if (astFact is ASTFact)
            {
                var f    = astFact as ASTFact;
                var fact = new IRFact
                {
                    Database = new IRSymbolRef(new FunctionNameAndArity(f.Database, f.Elements.Count)),
                    Not      = f.Not,
                    Elements = new List <IRConstant>(f.Elements.Count),
                    Goal     = null,
                    Location = f.Location
                };

                foreach (var element in f.Elements)
                {
                    fact.Elements.Add(ASTConstantToIR(element));
                }

                return(fact);
            }
            else if (astFact is ASTGoalCompletedFact)
            {
                var f = astFact as ASTGoalCompletedFact;
                return(new IRFact
                {
                    Database = null,
                    Not = false,
                    Elements = new List <IRConstant>(),
                    Goal = goal,
                    Location = f.Location
                });
            }
            else
            {
                throw new InvalidOperationException("Cannot convert unknown AST fact type to IR");
            }
        }
Exemplo n.º 5
0
        private IRGoal ASTGoalToIR(ASTGoal astGoal)
        {
            var goal = new IRGoal
            {
                InitSection       = new List <IRFact>(astGoal.InitSection.Count),
                KBSection         = new List <IRRule>(astGoal.KBSection.Count),
                ExitSection       = new List <IRFact>(astGoal.ExitSection.Count),
                ParentTargetEdges = new List <IRTargetEdge>(astGoal.ParentTargetEdges.Count),
                Location          = astGoal.Location
            };

            foreach (var fact in astGoal.InitSection)
            {
                goal.InitSection.Add(ASTFactToIR(fact));
            }

            foreach (var rule in astGoal.KBSection)
            {
                goal.KBSection.Add(ASTRuleToIR(goal, rule));
            }

            foreach (var fact in astGoal.ExitSection)
            {
                goal.ExitSection.Add(ASTFactToIR(fact));
            }

            foreach (var refGoal in astGoal.ParentTargetEdges)
            {
                var edge = new IRTargetEdge();
                edge.Goal     = new IRGoalRef(refGoal.Goal);
                edge.Location = refGoal.Location;
                goal.ParentTargetEdges.Add(edge);
            }

            return(goal);
        }