示例#1
0
文件: dbintlog.cpp 项目: CapelliC/IL
//////////////////////////////////////
// initialize matching terms iterator
//
int DbIntlog::Search(Term t, DbEntryIter &iter, DbIntlog *dbs)
{
#ifdef _DEBUG
    CCP tstring = t.get_funct();
#endif

    DbEntry e = DbEntry(t.get_funct(), t.get_arity()),
            *dbe = isin(e);

    if (!dbe)
    {
        if (dbs == 0 ||
                (dbe = dbs->isin(e)) == 0 ||
                dbe->vProp != DbEntry::dynamic)
        {
            iter.pcc = 0;
            iter.own = iter.mod = 0;
            return 0;
        }
        iter.mod =
		iter.own = dbs;
    }
    else
    {
        iter.mod = this;
        iter.own = dbs;
    }

    // initialize for later search
    iter.pcc = (e_DbList*)dbe->get_first()->fix_clause(dbs);
    iter.pcp = 0;

    return 1;
}
示例#2
0
文件: dbintlog.cpp 项目: CapelliC/IL
////////////////////////////////////
// resync clauses list
//	this invalidate all DbEntryIter
//
void DbIntlog::ClearStatus(DbIntlog *owner)
{
    slist_scan ld(m_deleted);
    e_DbList *edbd;

    while ((edbd = (e_DbList*)ld.next()) != 0)
    {
        Term tk = edbd->clause->get_head();
#ifdef _DEBUG
        CCP tstring = tk.get_funct();
#endif

        DbEntry x(tk.get_funct(), tk.get_arity());
        DbEntry *dbe = isin(x);
        ASSERT(dbe);

        slist_scan tla(dbe->entries);
        e_DbList *edbl;

        while ((edbl = (e_DbList*)tla.next()) != 0)
            if (edbl->clause == 0)
            {
                tla.delitem();
                break;
            }

        if (!owner || edbd->type != e_DbList::tLocData ||
                edbd->clause->get_db() == owner)
            ld.delitem();
    }

    // clear all inherited DBs
    DbInherIter it(this);
    DbIntlog *db;
    while ((db = (DbIntlog *)it.next()) != 0)
        db->ClearStatus(this);
}
示例#3
0
文件: dbintlog.cpp 项目: CapelliC/IL
///////////////////////////////////
// storage entry point to database
//
void DbIntlog::Add(Clause *c, int first, DbIntlog *owner)
{
    Term h = c->get_head();
    ASSERT(!h.type(f_NOTERM));
#ifdef _DEBUG
    CCP tstring = h.get_funct();
#endif

    e_DbList *edbl = new e_DbList(c);

    // retrieve or create the entry
    kstring funct = h.get_funct();
    int arity = h.get_arity();
    DbEntry e(funct, arity), *dbe = isin(e);

    // verify location on create
    if (dbe == 0 && owner && owner != this)
        dbe = owner->isin(e);
    if (!dbe)
    {
        dbe = new DbEntry(funct, arity);
        insert(dbe);
    }
    if (dbe->arity == -1)
        dbe->arity = arity;

    DbIntlog *dbwork = this;
    if (dbe->vProp == DbEntry::dynamic)
    {
        if (!owner)
            owner = this;
        dbe = owner->isin(dbe);
        ASSERT(dbe);
        c->set_db(dbwork = owner);
    }
    else if (owner && owner != this)
    {
        edbl->type = e_DbList::tLocData;
        c->set_db(owner);
    }

    if (first)
        dbe->entries.insert(edbl, 0);
    else
    {
        DbListSeek eref(e_DbList::tExtRef);
        DbListSeek vtbl(e_DbList::tVTable);
        unsigned iref = dbe->entries.seek(&eref);
        unsigned itbl = dbe->entries.seek(&vtbl);

        if (iref != SLIST_INVPOS)
            dbe->entries.insert(edbl, iref);
        else
            if (itbl != SLIST_INVPOS)
                dbe->entries.insert(edbl, itbl);
            else
                dbe->entries.append(edbl);
    }

    // close inheritance chainings
    dbwork->check_inherited_entries(dbe);
}