File: cpr_propsig.c

package info (click to toggle)
eprover 2.6%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 21,288 kB
  • sloc: ansic: 331,111; csh: 12,026; python: 10,178; awk: 5,825; makefile: 461; sh: 389
file content (207 lines) | stat: -rw-r--r-- 5,346 bytes parent folder | download | duplicates (2)
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*-----------------------------------------------------------------------

File  : cpr_propsig.c

Author: Stephan Schulz

Contents

  Code for "signatures" for propositional atoms (essentially just a
  bidirectional mapping external name <-> internal encoding).

  Copyright 2003 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> Thu Apr 24 16:28:42 CEST 2003
    New

-----------------------------------------------------------------------*/

#include "cpr_propsig.h"



/*---------------------------------------------------------------------*/
/*                        Global Variables                             */
/*---------------------------------------------------------------------*/


/*---------------------------------------------------------------------*/
/*                      Forward Declarations                           */
/*---------------------------------------------------------------------*/


/*---------------------------------------------------------------------*/
/*                         Internal Functions                          */
/*---------------------------------------------------------------------*/



/*---------------------------------------------------------------------*/
/*                         Exported Functions                          */
/*---------------------------------------------------------------------*/

/*-----------------------------------------------------------------------
//
// Function: PropSigAlloc()
//
//   Allocate an empty, initialized propositional signature.
//
// Global Variables: -
//
// Side Effects    : Memory operations
//
/----------------------------------------------------------------------*/

PropSig_p PropSigAlloc(void)
{
   PropSig_p handle = PropSigCellAlloc();

   handle->enc_to_name = PStackAlloc();
   PStackPushP(handle->enc_to_name, NULL); /* Don't use literal 0 */
   handle->name_to_enc = NULL;

   return handle;
}


/*-----------------------------------------------------------------------
//
// Function: PropSigFree()
//
//   Free a propositional signature and all associated memory.
//
// Global Variables: -
//
// Side Effects    : Memory operations
//
/----------------------------------------------------------------------*/

void PropSigFree(PropSig_p junk)
{
   PStackFree(junk->enc_to_name);
   StrTreeFree(junk->name_to_enc);
   PropSigCellFree(junk);
}


/*-----------------------------------------------------------------------
//
// Function: PropSigGetAtomEnc()
//
//   Given a name, return the encoding. Return PAtomNoAtom if name is
//   unknown.
//
// Global Variables: -
//
// Side Effects    : - (Reorganzizes name_to_enc)
//
/----------------------------------------------------------------------*/

PLiteralCode PropSigGetAtomEnc(PropSig_p psig, char* name)
{
   StrTree_p handle;

   handle = StrTreeFind(&(psig->name_to_enc),name);
   if(handle)
   {
      return handle->val1.i_val;
   }
   return PLiteralNoLit;
}


/*-----------------------------------------------------------------------
//
// Function: PropSigInsertAtom()
//
//   Insert a new atom into a psig. Return encoding. If atom already
//   exists, do nothing but returning the encoding.
//
// Global Variables: -
//
// Side Effects    : Changes psig.
//
/----------------------------------------------------------------------*/

PLiteralCode PropSigInsertAtom(PropSig_p psig, char* name)
{
   PLiteralCode enc;
   StrTree_p handle;

   enc = PropSigGetAtomEnc(psig,name);
   if(enc)
   {
      return enc;
   }
   handle = StrTreeCellAlloc();
   handle->key = SecureStrdup(name);
   enc = PropSigAtomNumber(psig);
   PStackPushP(psig->enc_to_name,handle->key);
   handle->val1.i_val = enc;
   handle = StrTreeInsert(&(psig->name_to_enc), handle);
   assert(!handle);

   return enc;
}

/*-----------------------------------------------------------------------
//
// Function: PropSigGetAtomName()
//
//   Return a pointer name of an atom. Fail on assertion if no valid
//   atom is passed.
//
// Global Variables: -
//
// Side Effects    : -
//
/----------------------------------------------------------------------*/


char* PropSigGetAtomName(PropSig_p psig, PLiteralCode atom)
{
   /* printf("Atom: %ld\n",atom); */
   assert(psig);
   assert(PAtomP(atom));
   assert(atom<PropSigAtomNumber(psig));
   return PStackElementP(psig->enc_to_name, atom);
}


/*-----------------------------------------------------------------------
//
// Function: PSigPrint()
//
//   Print a PSig (mainly for debugging)
//
// Global Variables: -
//
// Side Effects    : -
//
/----------------------------------------------------------------------*/

void PropSigPrint(FILE* out, PropSig_p psig)
{
   long i;

   fprintf(out, "# Propositional signature:\n");
   fprintf(out, "# ------------------------\n");
   for(i=1; i<PropSigAtomNumber(psig); i++)
   {
      fprintf(out, "# %6ld : %s\n", i, PropSigGetAtomName(psig,i));
   }
   fprintf(out, "\n");
}


/*---------------------------------------------------------------------*/
/*                        End of File                                  */
/*---------------------------------------------------------------------*/