1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
/*-----------------------------------------------------------------------
File : cte_termpos.c
Author: Stephan Schulz
Contents
Positions in terms
Copyright 1998, 1999 by the author.
This code is released under the GNU General Public Licence and
the GNU Lesser General Public License.
See the file COPYING in the main E directory for details..
Run "eprover -h" for contact information.
Changes
<1> Sun May 10 17:40:18 MET DST 1998
-----------------------------------------------------------------------*/
#include "cte_termpos.h"
/*---------------------------------------------------------------------*/
/* Global Variables */
/*---------------------------------------------------------------------*/
/*---------------------------------------------------------------------*/
/* Forward Declarations */
/*---------------------------------------------------------------------*/
/*---------------------------------------------------------------------*/
/* Internal Functions */
/*---------------------------------------------------------------------*/
/*---------------------------------------------------------------------*/
/* Exported Functions */
/*---------------------------------------------------------------------*/
/*-----------------------------------------------------------------------
//
// Function: TermPosNextLIPosition()
//
// Given an (implicit) term and a position, compute the next
// position (in leftmost-innermost order) and return the
// corresponding term.
//
// Global Variables: -
//
// Side Effects : Changes pos
//
/----------------------------------------------------------------------*/
Term_p TermPosNextLIPosition(TermPos_p pos)
{
Term_p super;
int idx;
if(PStackEmpty(pos))
{
return NULL;
}
idx = PStackPopInt(pos);
super = PStackPopP(pos);
if(idx<super->arity-1)
{
idx++;
while(super->arity)
{
PStackPushP(pos, super);
PStackPushInt(pos, idx);
super = super->args[idx];
idx = 0;
}
}
return super;
}
/*-----------------------------------------------------------------------
//
// Function: TermPosPrint()
//
// Print the position as a doted list.
//
// Global Variables: -
//
// Side Effects : Output
//
/----------------------------------------------------------------------*/
void TermPosPrint(FILE* out, TermPos_p pos)
{
PStackPointer i;
if(PStackEmpty(pos))
{
return;
}
fprintf(out, "%ld", PStackElementInt(pos, 1));
for(i=2; i<PStackGetSP(pos); i+=2)
{
fprintf(out, ".%ld\n", PStackElementInt(pos, i+1));
}
}
/*-----------------------------------------------------------------------
//
// Function: TermPosDebugPrint()
//
// Print a position in a term. If sig!=NULL, print terms, otherwise
// print adddresses
//
// Global Variables: -
//
// Side Effects : Output
//
/----------------------------------------------------------------------*/
void TermPosDebugPrint(FILE* out, Sig_p sig, TermPos_p pos)
{
PStackPointer i;
fprintf(out, "# TermPos--\n");
for(i=0; i<PStackGetSP(pos); i+=2)
{
fprintf(out, "# ");
if(sig)
{
TermPrint(out, PStackElementP(pos, i), sig, DEREF_NEVER);
fprintf(out, "...");
TermPrint(out, PStackElementP(pos, i), sig, DEREF_ALWAYS);
}
else
{
fprintf(out, "<%p>", PStackElementP(pos, i));
}
fprintf(out, " Subterm %ld\n", PStackElementInt(pos, i+1));
}
fprintf(out, "# --TermPos\n");
}
/*---------------------------------------------------------------------*/
/* End of File */
/*---------------------------------------------------------------------*/
|