deref.h

00001 /* File:      deref.h
00002 ** Author(s): Jiyang Xu, Terrance Swift, Kostis Sagonas
00003 ** Contact:   xsb-contact@cs.sunysb.edu
00004 ** 
00005 ** Copyright (C) The Research Foundation of SUNY, 1986, 1993-1998
00006 ** Copyright (C) ECRC, Germany, 1990
00007 ** 
00008 ** XSB is free software; you can redistribute it and/or modify it under the
00009 ** terms of the GNU Library General Public License as published by the Free
00010 ** Software Foundation; either version 2 of the License, or (at your option)
00011 ** any later version.
00012 ** 
00013 ** XSB is distributed in the hope that it will be useful, but WITHOUT ANY
00014 ** WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00015 ** FOR A PARTICULAR PURPOSE.  See the GNU Library General Public License for
00016 ** more details.
00017 ** 
00018 ** You should have received a copy of the GNU Library General Public License
00019 ** along with XSB; if not, write to the Free Software Foundation,
00020 ** Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00021 **
00022 ** $Id: deref.h,v 1.8 2005/10/21 17:47:52 tswift Exp $
00023 ** 
00024 */
00025 
00026 #ifndef __DEREF_H__
00027 #define __DEREF_H__
00028 
00029 /* TLS: Bao changed these derefs to handle attributed variables, since
00030  *  a reference chain can, in principle, have a chain of var pointers
00031  *  followed by a chain of attv pointers, ending in a free variable.
00032  *  Actually, the code here is somewhat more general, and allows more
00033  *  intermixture of attv and var pointers.  So I may be wrong or the
00034  *  code may be a little more general than it needs to be.
00035  * 
00036  *  XSB_Deref(op) is the same as XSB_CptrDeref(op) except that
00037  *  XSB_CptrDeref(op) performs an explicit cast of op to a CPtr.  */
00038 
00039 #define XSB_Deref(op) XSB_Deref2(op,break)
00040 
00041 /* XSB_Deref2 is changed to consider attributed variables */
00042 #define XSB_Deref2(op, stat) {                          \
00043   while (isref(op)) {                                   \
00044     if (op == follow(op))                               \
00045       stat;                                             \
00046     op = follow(op);                                    \
00047   }                                                     \
00048   while (isattv(op)) {                                  \
00049     if (cell((CPtr) dec_addr(op)) == dec_addr(op))      \
00050       break; /* end of an attv */                       \
00051     else {                                              \
00052       op = cell((CPtr) dec_addr(op));                   \
00053       while (isref(op)) {                               \
00054         if (op == follow(op))                           \
00055           stat;                                         \
00056         op = follow(op);                                \
00057       }                                                 \
00058     }                                                   \
00059   }                                                     \
00060 }
00061 
00062 #define XSB_CptrDeref(op) {                             \
00063   while (isref(op)) {                                   \
00064     if (op == (CPtr) cell(op)) break;                   \
00065     op = (CPtr) cell(op);                               \
00066   }                                                     \
00067   while (isattv(op)) {                                  \
00068     if (cell((CPtr) dec_addr(op)) == dec_addr(op))      \
00069       break;                                            \
00070     else {                                              \
00071       op = (CPtr) cell((CPtr) dec_addr(op));            \
00072       while (isref(op)) {                               \
00073         if (op == (CPtr) cell(op)) break;               \
00074         op = (CPtr) cell(op);                           \
00075       }                                                 \
00076     }                                                   \
00077   }                                                     \
00078 }
00079 
00080 #define printderef(op) while (isref(op) && op > 0) { \
00081                          if (op==follow(op)) \
00082                             break; \
00083                          op=follow(op); }
00084 #endif /* __DEREF_H__ */

Generated on Wed Jul 26 13:30:40 2006 for XSB by  doxygen 1.4.5