Main Page   Modules   Alphabetical List   Data Structures   File List   Data Fields   Globals  

data.c

00001  /*
00002   * plint/prog/data.c : definitions of the program's variables
00003   * 
00004   * Time-stamp: <2003-01-08 22:06:00 gseba>
00005   * 
00006   * Copyright (C) Sebastian Glita, email: gseba@users.sourceforge.net
00007   * 
00008   * This file is part of plint.
00009   * 
00010   * plint is free software; you can  redistribute it and/or modify it under the
00011   * terms of the  GNU General Public License as published  by the Free Software
00012   * Foundation; either version 2, or (at your option) any later version.
00013   *
00014   * plint  is distributed  in the  hope  that it  will be  useful, but  WITHOUT
00015   * ANY  WARRANTY; without  even  the implied  warranty  of MERCHANTABILITY  or
00016   * FITNESS FOR A  PARTICULAR PURPOSE.  See the GNU  General Public License for
00017   * more details.
00018   * 
00019   * You should  have received a  copy of the  GNU General Public  License along
00020   * with  plint; see  the file  COPYING.  If  not, write  to the  Free Software
00021   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA USA.
00022   *
00023   */
00024 
00025 #pragma GCC dependency "Makefile" maybe some command line defines have changed
00026 
00027 #include "plint.h"
00028 #include "error.h"
00029 #include "share.h"
00030 
00031 #include "data.h"
00032 
00033 #include "share/hash.h"
00034 
00035 void plint_proc_log(FILE * out, plint_tree_t t)
00036 {
00037   fprintf(out, "> ");
00038   while (t)
00039     {
00040       char * s = hash_getstr(plint_hash.id, t->proc.name, 0);
00041 
00042       fprintf(out, "%s", s);
00043       free(s);
00044 
00045 #ifdef PLINT_TRACE_ARGS
00046       {
00047         size_t i;
00048         for (fputc('(', out), i = 0; i < t->proc.arrity;)
00049           {
00050             s = hash_getstr(plint_hash.id, t->proc.args[i], 0);
00051             fprintf(out, "%s", s);
00052             if (++i < t->proc.arrity)
00053               fputc(',', out);
00054             free(s);
00055           }
00056         fputc(')', out);
00057       }
00058 #else
00059       if (t->proc.arrity > 0)
00060         fprintf(out, "#%d", t->proc.arrity);
00061 #endif
00062 
00063       while ((t = t->prnt) && !PLINT_TREE_ISPRC(t));
00064 
00065       fprintf (out, (t) ? " ^ " : " <");
00066     }
00067 }
00068 
00069 
00070 inline int plint_tree_user_new(plint_tree_t r)
00071 {
00072   return slot_register(r->user, 0, 0);
00073 }
00074 
00075 inline int plint_tree_user_del(plint_tree_t r, int t)
00076 {
00077   return slot_unregister(r->user, t);
00078 }
00079 
00080 inline void plint_tree_user_set(plint_tree_t r, int t, void * d)
00081 {
00082   (void)slot_setdata(r->user, t, d);
00083 }
00084 
00085 inline void * plint_tree_user_get(plint_tree_t r, int t)
00086 {
00087   return slot_getdata(r->user, t);
00088 }
00089 
00090 typedef struct _plint_tree_user
00091 {
00092   plint_tree_t t;
00093   int i;
00094 } *plint_tree_user_t;
00095 
00096 int plint_tree_user_slot_add(slot_key_t s, plint_tree_t t, void * d)
00097 {
00098   plint_tree_user_t u;
00099   int i;
00100 
00101   i = slot_register(s, (void *)NEW(u), FREE);
00102   u->t = t;
00103   u->i = plint_tree_user_new(t);
00104   plint_tree_user_set(t, u->i, d);
00105   return i;
00106 }
00107 
00108 static int tree_user_find(plint_tree_user_t u, plint_tree_t t)
00109 {
00110   return u->t == t;
00111 }
00112 
00113 int plint_tree_user_slot_rem(slot_key_t s, plint_tree_t t)
00114 {
00115   plint_tree_user_t u;
00116   int i;
00117 
00118   i = slot_find(s, t, (slot_ffind_t)tree_user_find);
00119   if (!i)
00120     return 0;
00121 
00122   u = (plint_tree_user_t)slot_getdata(s, i);
00123   slot_unregister(s, i);
00124 
00125   return plint_tree_user_del(t, u->i);
00126 }
00127 
00128 void * plint_tree_user_slot_get(slot_key_t s, plint_tree_t t)
00129 {
00130   return plint_tree_user_get(t, ((plint_tree_user_t)slot_getdata(s, slot_find(s, t, (slot_ffind_t)tree_user_find)))->i);
00131 }
00132 
00133 
00134 inline plint_tree_t plint_tree_non_ins(plint_tree_t t)
00135 {
00136   while (PLINT_TREE_ISINS(t)) t = t->prnt;
00137   return t;
00138 }
00139 
00140 inline plint_tree_t plint_tree_non_ins_wrp(plint_tree_t t)
00141 {
00142   while (PLINT_TREE_ISINS(t) || PLINT_TREE_ISWRP(t)) t = t->prnt;
00143   return t;
00144 }
00145 
00146 inline plint_tree_t plint_tree_host(plint_tree_t t)
00147 {
00148   return t->host_id ? t->host.d : *t->host.i;
00149 }
00150 
00151 
00152 plint_tree_t plint_proc_lup_sig(plint_tree_t r)
00153 {
00154   int i;
00155   plint_tree_t p;
00156   for (i = r->nchlds; i; )
00157     if (!(p = r->chlds[--i]) ||
00158         PROC_SIG_EQU(plint_proc.lup.sig, p->proc) ||
00159         PLINT_TREE_ISINS(p) && (p = plint_proc_lup_sig(p)))
00160       return p;
00161 
00162   return 0;
00163 }
00164 
00165 int plint_proc_lup_ptr(plint_tree_t r)
00166 {
00167   int i;
00168   plint_tree_t p;
00169   for (i = r->nchlds; i; )
00170     if (!(p = r->chlds[--i]) ||
00171         p == plint_proc.lup.ptr ||
00172         PLINT_TREE_ISINS(p) && plint_proc_lup_ptr(p))
00173       return !0;
00174 
00175   return 0;
00176 }
00177 
00178 
00179 plint_stack_t plint_stack_block(int b)
00180 {
00181   plint_stack_t s = plint_stack.top;
00182 
00183   if (++b > 0)
00184     while (s && --b)
00185       {
00186         plint_tree_t r = s->block.src->prnt;
00187 
00188         if (r)
00189           r = plint_tree_non_ins_wrp(r);
00190 
00191         s = r ? r->top : 0;
00192       }
00193   else if ((b = - --b))
00194     while ((s = s->proc) && --b)
00195       s = s->down;
00196 
00197   if (!s)
00198     PLINT_ERROR(PLINT_ERR_BLK_NO);
00199 
00200   return s;
00201 }

Generated on Thu Jan 9 19:02:37 2003 for plint by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002