Exemple #1
0
            public void AddPredefined(ClauseNode clause)
            {
                BaseTerm       head = clause.Head;
                string         key  = head.Key;
                PredicateDescr pd   = this[key];

                if (pd == null)
                {
                    predefineds[key] = true;                                 // any value != null will do
                    SetClauseList(head.FunctorToString, head.Arity, clause); // create a PredicateDescr
                }
                else if (prevIndex != null && key != prevIndex)
                {
                    IO.Error("Definition for predefined predicate '{0}' must be contiguous", head.Index);
                }
                else
                {
                    pd.AppendToClauseList(clause);
                }

                prevIndex = key;
            }
Exemple #2
0
            public void AddClause(ClauseNode clause)
            {
                BaseTerm head = clause.Head;

                string key   = head.Key;
                string index = head.Index;

                if (predefineds.Contains(key))
                {
                    IO.Error("Modification of predefined predicate {0} not allowed", index);
                }

                if (prevIndex == key) // previous clause was for the same predicate
                {
                    PredicateDescr pd = this[key];
                    pd.AppendToClauseList(clause);
                }
                else // first predicate or different predicate
                {
                    PredicateDescr pd = this[key];

                    if (!definedInCurrFile.Contains(key)) //  very first clause of this predicate in this file -- reset at start of consult
                    {
                        if (pd != null && pd.DefinitionFile != ConsultFileName)
                        {
                            IO.Error("Predicate '{0}' is already defined in {1}", index, pd.DefinitionFile);
                        }

                        definedInCurrFile[key] = true;
                        pd = SetClauseList(head.FunctorToString, head.Arity, clause); // implicitly erases all previous definitions
                        pd.IsDiscontiguous = (isDiscontiguous.Contains(key) || allDiscontiguous);
                        prevIndex          = key;
                    }
                    else // not the first clause. First may be from another definitionFile (which is an error).
                    {    // If from same, IsDiscontiguous must hold, unless DiscontiguousAllowed = "1" in .config
                        bool b = false;

                        if (pd.IsDiscontiguous || (b = ConfigSettings.DiscontiguousAllowed))
                        {
                            if (b)
                            {
                                IO.Warning("Predicate '{0}' is defined discontiguously but is not declared as such", index);
                            }

                            if (pd.DefinitionFile == ConsultFileName)
                            {
                                pd.AppendToClauseList(clause);
                            }
                            else // OK
                            {
                                IO.Error("Discontiguous predicate {0} must be in one file (also found in {1})", index, pd.DefinitionFile);
                            }
                        }
                        else if (pd.DefinitionFile == ConsultFileName) // Warning or Error?
                        {
                            IO.Error("Predicate '{0}' occurs discontiguously but is not declared as such", index);
                        }
                        else
                        {
                            IO.Error("Predicate '{0}' is already defined in {1}", index, pd.DefinitionFile);
                        }
                    }
                }
            }