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 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
|
/*-----------------------------------------------------------------------
File : ccl_clauseinfo.c
Author: Stephan Schulz (schulz@eprover.org)
Contents
Datatype and basic functions for storing and handling clause
information that few clauses carry (probably just input
clauses). This is not stored in the clause (or formula) data types,
because it would eat up to much memory (remember, there are
millions of clauses)
Copyright 2004 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> Fri Sep 3 12:21:57 CEST 2004
New
-----------------------------------------------------------------------*/
#include "ccl_clauseinfo.h"
/*---------------------------------------------------------------------*/
/* Global Variables */
/*---------------------------------------------------------------------*/
/*---------------------------------------------------------------------*/
/* Forward Declarations */
/*---------------------------------------------------------------------*/
/*---------------------------------------------------------------------*/
/* Internal Functions */
/*---------------------------------------------------------------------*/
/*---------------------------------------------------------------------*/
/* Exported Functions */
/*---------------------------------------------------------------------*/
/*-----------------------------------------------------------------------
//
// Function: ClauseInfoAlloc()
//
// Allocate an initialized clause info cell. Strings are copied and
// local to the cell!
//
// Global Variables: -
//
// Side Effects : Memory operations
//
/----------------------------------------------------------------------*/
ClauseInfo_p ClauseInfoAlloc(char* name, char* source,
long line, long column)
{
ClauseInfo_p handle = ClauseInfoCellAlloc();
handle->name = NULL;
handle->source = NULL;
if(name)
{
handle->name = SecureStrdup(name);
}
if(source)
{
handle->source= SecureStrdup(source);
}
handle->line = line;
handle->column = column;
return handle;
}
/*-----------------------------------------------------------------------
//
// Function: ClauseInfoFree()
//
// Free a clauseinfocell (and all stored information). This is
// explicitely designed to handle the NULL case silently and
// gracefully, so we can call it even for clauses which do not have
// an info field.
//
// Global Variables: -
//
// Side Effects : Memory operations
//
/----------------------------------------------------------------------*/
void ClauseInfoFree(ClauseInfo_p info)
{
if(info)
{
if(info->name)
{
FREE(info->name);
}
if(info->source)
{
FREE(info->source);
}
ClauseInfoCellFree(info);
}
}
/*-----------------------------------------------------------------------
//
// Function: ClauseSourceInfoPrint()
//
// Print the source part of a clause info cell in TSTP or PCL (or
// weird) format.
//
// Global Variables: -
//
// Side Effects : Output
//
/----------------------------------------------------------------------*/
void ClauseSourceInfoPrint(FILE* out, ClauseInfo_p info, char *inf_lit, char* delim)
{
DStr_p source_accu = DStrAlloc();
char *source = "unknown";
char *name;
char buffer[100]; /* At most 2 longs and some filler */
if(info->source)
{
DStrAppendStr(source_accu, delim);
DStrAppendStr(source_accu, info->source);
DStrAppendStr(source_accu, delim);
source = DStrView(source_accu);
}
name = info->name;
if(!name)
{
if(info->line < 0)
{
name = "unknown";
}
else
{
assert(info->column >= 0);
sprintf(buffer, "at_line_%ld_column_%ld", info->line, info->column);
name = buffer;
}
}
fprintf(out, "%s(%s, %s)", inf_lit, source, name);
DStrFree(source_accu);
}
/*-----------------------------------------------------------------------
//
// Function: ClauseInfoGetIdNameSpace()
//
// Identifiers for clauses and formulas generated by E are of the
// form c_<ns>_<id> or i_<ns>_<id>, where both <ns> and <id> are
// numbers. The idea is that <ns> selects a name space for
// identifiers, and <id> enumerates identifiers in this name
// space. This function extracts the name space (if any) from an
// identifier in a ClauseInfo struct. If there is no identifier, or
// if it does not use the general form of E-generated identifiers,
// the function returns -1.
//
// With this long a description, the function probably does
// something too complex ;-).
//
// Global Variables: -
//
// Side Effects : -
//
/----------------------------------------------------------------------*/
long ClauseInfoGetIdNameSpace(ClauseInfo_p info)
{
long res;
char *endptr;
if(!info)
{
return -1;
}
if(!info->name)
{
return -1;
}
if((strncmp(info->name, "i_", 2)==0) ||
(strncmp(info->name, "c_", 2)==0))
{
if((info->name[2]<'0') || (info->name[2]>'9'))
{
return -1;
}
res = strtol(info->name+3, &endptr, 10);
if(*endptr!='_')
{
return -1;
}
return res;
}
return -1;
}
/*-----------------------------------------------------------------------
//
// Function: ClauseInfoGetIdCounter()
//
// Identifiers for clauses and formulas generated by E are of the
// form c_<ns>_<id> or i_<ns>_<id>, where both <ns> and <id> are
// numbers. The idea is that <ns> selects a name space for
// identifiers, and <id> enumerates identifiers in this name
// space. This function extracts the <id> value. If there is no
// identifier, or if it does not use the general form of E-generated
// identifiers, the function returns -1.
//
// With this long a description, the function probably does
// something too complex ;-).
//
// Global Variables: -
//
// Side Effects : -
//
/----------------------------------------------------------------------*/
long ClauseInfoGetIdCounter(ClauseInfo_p info)
{
long res;
char *endptr;
if(!info)
{
return -1;
}
if(!info->name)
{
return -1;
}
if((strncmp(info->name, "i_", 2)==0) ||
(strncmp(info->name, "c_", 2)==0))
{
if((info->name[2]<'0') || (info->name[2]>'9'))
{
return -1;
}
res = strtol(info->name+3, &endptr, 10);
if(*endptr!='_')
{
return -1;
}
endptr++;
res = strtol(endptr, &endptr, 10);
if(*endptr)
{
return -1;
}
return res;
}
return -1;
}
/*---------------------------------------------------------------------*/
/* End of File */
/*---------------------------------------------------------------------*/
|