Debian Codegraph @

link-grammar/prepare/build-disjuncts.c

raw symbols SCIP
1 /*************************************************************************/cxx . . $ `<file>/link-grammar/prepare/build-disjuncts.c`/
2 /* Copyright (c) 2004 */
3 /* Daniel Sleator, David Temperley, and John Lafferty */
4 /* Copyright (c) 2013 Linas Vepstas */
5 /* All rights reserved */
6 /* */
7 /* Use of the link grammar parsing system is subject to the terms of the */
8 /* license set forth in the LICENSE file included with this software. */
9 /* This license allows free redistribution and use in source and binary */
10 /* forms, with or without modification, subject to certain conditions. */
11 /* */
12 /*************************************************************************/
13
14 /* Code that transforms a dictionary entry into a disjunct list */
15
16 #include "build-disjuncts.h"cxx . . $ `<file>/link-grammar/prepare/build-disjuncts.h`/
17 #include "connectors.h"cxx . . $ `<file>/link-grammar/connectors.h`/
18 #include "dict-common/dict-structures.h"cxx . . $ `<file>/link-grammar/dict-common/dict-structures.h`/ // Exp_struct, exp_stringify
19 #include "dict-common/dict-common.h"cxx . . $ `<file>/link-grammar/dict-common/dict-common.h`/ // Dictionary
20 #include "disjunct-utils.h"cxx . . $ `<file>/link-grammar/disjunct-utils.h`/
21 #include "utilities.h"cxx . . $ `<file>/link-grammar/utilities.h`/
22
23 /* Temporary connectors used while converting expressions into disjunct lists */
24 typedef struct Tconnector_structcxx . . $ Tconnector_struct# Tconnectorcxx . . $ Tconnector#;
25 struct Tconnector_structcxx . . $ Tconnector_struct#
26 {
27 Tconnectorcxx . . $ Tconnector# * nextcxx . . $ Tconnector_struct#next.;
28 Expcxx . . $ Exp# *ecxx . . $ Tconnector_struct#e.; /* a CONNECTOR_type element from which to get the connector */
29 Connectorcxx . . $ Connector# *traconcxx . . $ Tconnector_struct#tracon.; /* the created tracon, set through memory sharing */
30 };
31
32 typedef struct clause_structcxx . . $ clause_struct# Clausecxx . . $ Clause#;
33 struct clause_structcxx . . $ clause_struct#
34 {
35 Clausecxx . . $ Clause# * nextcxx . . $ clause_struct#next.;
36 Tconnectorcxx . . $ Tconnector# * ccxx . . $ clause_struct#c.;
37 float totcostcxx . . $ clause_struct#totcost.; // Total cost of all connectors in the clause
38 };
39
40 typedef structcxx . . $ $anonymous_type_9cef6a05adbc8e66_0#
41 {
42 Pool_desccxx . . $ Pool_desc# *Tconnector_poolcxx . . $ $anonymous_type_9cef6a05adbc8e66_0#Tconnector_pool.;
43 Pool_desccxx . . $ Pool_desc# *Clause_poolcxx . . $ $anonymous_type_9cef6a05adbc8e66_0#Clause_pool.;
44 float cost_cutoffcxx . . $ $anonymous_type_9cef6a05adbc8e66_0#cost_cutoff.;
45 int exp_poscxx . . $ $anonymous_type_9cef6a05adbc8e66_0#exp_pos.;
46 } clause_contextcxx . . $ clause_context#;
47
48 #ifdef DEBUG
49 static void print_Tconnector_list(Tconnector * e);
50 static void print_clause_list(Clause * c);
51 #endif
52
53 #if BUILD_DISJUNCTS_FREE_INETERMEDIATE_MEMORY /* Undefined - CPU overhead. */
54 static void free_Tconnectors(Tconnector *e, Pool_desc *mp)
55 {
56 Tconnector * n;
57 for(;e != NULL; e=n)
58 {
59 n = e->next;
60 pool_free(mp, e);
61 }
62 }
63
64 static void free_clause_list(Clause *c, clause_context *ct)
65 {
66 Clause *c1;
67 while (c != NULL)
68 {
69 c1 = c->next;
70 free_Tconnectors(c->c, ct->Tconnector_pool);
71 pool_free(ct->Clause_pool, c);
72 c = c1;
73 }
74 }
75 #endif
76
77 /**
78 * Builds a new list of connectors that is the catenation of e1 with e2.
79 * does not effect lists e1 or e2. Order is maintained.
80 */
81 static Tconnectorcxx . . $ Tconnector# * catenatecxx . . $ catenate(b6e0a5bfc1f8f7b3).(Tconnectorcxx . . $ Tconnector# * e1, Tconnectorcxx . . $ Tconnector# * e2, Pool_desccxx . . $ Pool_desc# *tp)
82 {
83 Tconnectorcxx . . $ Tconnector# head;
84 Tconnectorcxx . . $ Tconnector# *preve = &head;
85
86 for (;e1 != NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; e1 = e1->nextcxx . . $ Tconnector_struct#next.)
87 {
88 Tconnectorcxx . . $ Tconnector# *newe = pool_alloccxx . . $ pool_alloc(6cde9c27c50a76a3).(tp);
89 *newe = *e1;
90
91 preve->nextcxx . . $ Tconnector_struct#next. = newe;
92 preve = newe;
93 }
94
95 preve->nextcxx . . $ Tconnector_struct#next. = e2; /* tracon memory sharing */
96 return head.nextcxx . . $ Tconnector_struct#next.;
97 }
98
99 /**
100 * build the connector for the terminal node n
101 */
102 static Tconnectorcxx . . $ Tconnector# * build_terminalcxx . . $ build_terminal(b8c9a6a65d973b61).(Expcxx . . $ Exp# *e, clause_contextcxx . . $ clause_context# *ct)
103 {
104 Tconnectorcxx . . $ Tconnector# *c = pool_alloccxx . . $ pool_alloc(6cde9c27c50a76a3).(ct->Tconnector_poolcxx . . $ $anonymous_type_9cef6a05adbc8e66_0#Tconnector_pool.);
105 c->ecxx . . $ Tconnector_struct#e. = e;
106 c->nextcxx . . $ Tconnector_struct#next. = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!;
107 c->ecxx . . $ Tconnector_struct#e.->poscxx . . $ Exp_struct#pos. = ct->exp_poscxx . . $ $anonymous_type_9cef6a05adbc8e66_0#exp_pos.++;
108 c->traconcxx . . $ Tconnector_struct#tracon. = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!;
109 return c;
110 }
111
112 static void debug_lastcxx . . $ debug_last(89b164d8eb7693ce).(Clausecxx . . $ Clause# *c, Clausecxx . . $ Clause# **c_last, const char *type)
113 {
114 #ifdef DEBUG
115 if ((c == NULL) || (c_last == NULL)) return;
116 do
117 {
118 if (c->next == NULL)
119 {
120 assert(c == *c_last, "%s", type);
121 return;
122 }
123 } while ((c = c->next));
124 #endif
125 }
126
127 #ifdef DEBUG
128 /**
129 * Return the number of clauses that would be generated by expanding
130 * the expression.
131 */
132 GNUC_UNUSED static unsigned long count_clauses(Exp *e)
133 {
134 if (e->type == AND_type)
135 {
136 unsigned long cnt = 1;
137 for (Exp *opd = e->operand_first; opd != NULL; opd = opd->operand_next)
138 cnt *= count_clauses(opd);
139 return cnt;
140 }
141
142 if (e->type == OR_type)
143 {
144 unsigned long cnt = 0;
145 for (Exp *opd = e->operand_first; opd != NULL; opd = opd->operand_next)
146 cnt += count_clauses(opd);
147 return cnt;
148 }
149 return 1;
150 }
151 #endif
152
153 /**
154 * Build the clause for the expression e. Does not change e
155 */
156 static Clausecxx . . $ Clause# * build_clausecxx . . $ build_clause(6597858a58c4260).(Expcxx . . $ Exp# *e, clause_contextcxx . . $ clause_context# *ct, Clausecxx . . $ Clause# **c_last)
157 {
158 assertcxx . . $ `link-grammar/error.h:107:9`!(e != NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!, "build_clause called with null parameter");
159 if (e->typecxx . . $ Exp_struct#type. == AND_typecxx . . $ AND_type.)
160 {
161 Clausecxx . . $ Clause# *c = pool_alloccxx . . $ pool_alloc(6cde9c27c50a76a3).(ct->Clause_poolcxx . . $ $anonymous_type_9cef6a05adbc8e66_0#Clause_pool.);
162 c->ccxx . . $ clause_struct#c. = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!;
163 c->nextcxx . . $ clause_struct#next. = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!;
164 c->totcostcxx . . $ clause_struct#totcost. = 0.0;
165 for (Expcxx . . $ Exp# *opd = e->operand_firstcxx . . $ Exp_struct#$anonymous_type_5#operand_first.; opd != NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; opd = opd->operand_nextcxx . . $ Exp_struct#operand_next.)
166 {
167 Clausecxx . . $ Clause# *c2 = build_clausecxx . . $ build_clause(6597858a58c4260).(opd, ct, NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!);
168 Clausecxx . . $ Clause# *c_head = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!;
169 for (Clausecxx . . $ Clause# *c3 = c; c3 != NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; c3 = c3->nextcxx . . $ clause_struct#next.)
170 {
171 for (Clausecxx . . $ Clause# *c4 = c2; c4 != NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; c4 = c4->nextcxx . . $ clause_struct#next.)
172 {
173 Clausecxx . . $ Clause# *c5 = pool_alloccxx . . $ pool_alloc(6cde9c27c50a76a3).(ct->Clause_poolcxx . . $ $anonymous_type_9cef6a05adbc8e66_0#Clause_pool.);
174 if ((c_head == NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!) && (c_last != NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!)) *c_last = c5;
175 c5->totcostcxx . . $ clause_struct#totcost. = c3->totcostcxx . . $ clause_struct#totcost. + c4->totcostcxx . . $ clause_struct#totcost.;
176 c5->ccxx . . $ clause_struct#c. = catenatecxx . . $ catenate(b6e0a5bfc1f8f7b3).(c4->ccxx . . $ clause_struct#c., c3->ccxx . . $ clause_struct#c., ct->Tconnector_poolcxx . . $ $anonymous_type_9cef6a05adbc8e66_0#Tconnector_pool.);
177 c5->nextcxx . . $ clause_struct#next. = c_head;
178 c_head = c5;
179 }
180 }
181 #if BUILD_DISJUNCTS_FREE_INETERMEDIATE_MEMORY /* Undefined - CPU overhead. */
182 free_clause_list(c, ct);
183 free_clause_list(c2, ct);
184 #endif
185 c = c_head;
186 }
187 if ((c != NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!) && (c->nextcxx . . $ clause_struct#next. == NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!) && (c_last != NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!)) *c_last = c;
188 debug_lastcxx . . $ debug_last(89b164d8eb7693ce).(c, c_last, "AND_type");
189
190 for (Clausecxx . . $ Clause# *c1 = c; c1 != NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; c1 = c1->nextcxx . . $ clause_struct#next.)
191 c1->totcostcxx . . $ clause_struct#totcost. += e->costcxx . . $ Exp_struct#cost.;
192 return c;
193 }
194
195 if (e->typecxx . . $ Exp_struct#type. == OR_typecxx . . $ OR_type.)
196 {
197 Clausecxx . . $ Clause# *or_last = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!;
198 Clausecxx . . $ Clause# *c = build_clausecxx . . $ build_clause(6597858a58c4260).(e->operand_firstcxx . . $ Exp_struct#$anonymous_type_5#operand_first., ct, &or_last);
199
200 /* We'll concatenate the lists of clauses. */
201 for (Expcxx . . $ Exp# *opd = e->operand_firstcxx . . $ Exp_struct#$anonymous_type_5#operand_first.->operand_nextcxx . . $ Exp_struct#operand_next.; opd != NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; opd = opd->operand_nextcxx . . $ Exp_struct#operand_next.)
202 {
203 Clausecxx . . $ Clause# *last;
204 or_last->nextcxx . . $ clause_struct#next. = build_clausecxx . . $ build_clause(6597858a58c4260).(opd, ct, &last);
205 or_last = last;
206 }
207
208 if (c_last != NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!) *c_last = or_last;
209 debug_lastcxx . . $ debug_last(89b164d8eb7693ce).(c, c_last, "OR_type");
210
211 for (Clausecxx . . $ Clause# *c1 = c; c1 != NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; c1 = c1->nextcxx . . $ clause_struct#next.)
212 c1->totcostcxx . . $ clause_struct#totcost. += e->costcxx . . $ Exp_struct#cost.;
213 return c;
214 }
215
216 if (e->typecxx . . $ Exp_struct#type. == CONNECTOR_typecxx . . $ CONNECTOR_type.)
217 {
218 Clausecxx . . $ Clause# *c = pool_alloccxx . . $ pool_alloc(6cde9c27c50a76a3).(ct->Clause_poolcxx . . $ $anonymous_type_9cef6a05adbc8e66_0#Clause_pool.);
219 c->ccxx . . $ clause_struct#c. = build_terminalcxx . . $ build_terminal(b8c9a6a65d973b61).(e, ct);
220 c->nextcxx . . $ clause_struct#next. = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!;
221 c->totcostcxx . . $ clause_struct#totcost. = e->costcxx . . $ Exp_struct#cost.;
222 if (c_last != NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!) *c_last = c;
223 return c;
224 }
225
226 assertcxx . . $ `link-grammar/error.h:107:9`!(falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!, "Unknown expression type %d", (int)e->type);
227 }
228
229 /**
230 * Build a disjunct list out of the clause list cl.
231 * wstring is the print name of word that generated this disjunct.
232 */
233 static Disjunctcxx . . $ Disjunct# *
234 build_disjunctcxx . . $ build_disjunct(fbe0d9ef6f5aae5b).(Sentencecxx . . $ Sentence# sent, Clausecxx . . $ Clause# * cl, const char * wstring,
235 const gword_setcxx . . $ gword_set# *gs, float cost_cutoff, Parse_Optionscxx . . $ Parse_Options# opts)
236 {
237 Pool_desccxx . . $ Pool_desc# *connector_pool = sent->Connector_poolcxx . . $ Sentence_s#Connector_pool.;
238 Pool_desccxx . . $ Pool_desc# *disjunct_pool = sent->Disjunct_poolcxx . . $ Sentence_s#Disjunct_pool.;
239 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! sat_solver = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
240
241 #if USE_SAT_SOLVER
242 sat_solver = (opts != NULL) && opts->use_sat_solver;
243 #endif /* USE_SAT_SOLVER */
244
245 Disjunctcxx . . $ Disjunct# *dis = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!;
246 for (; cl != NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; cl = cl->nextcxx . . $ clause_struct#next.)
247 {
248 if (unlikelycxx . . $ `link-grammar/utilities.h:276:9`!(NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`! == cl->c)) continue; /* no connectors */
249 if (cl->totcostcxx . . $ clause_struct#totcost. > cost_cutoff) continue;
250
251 Disjunctcxx . . $ Disjunct# *ndis;
252 #if USE_SAT_SOLVER
253 if (sat_solver) /* For the SAT-parser, until fixed. */
254 ndis = xalloc(sizeof(Disjunct));
255 else
256 ndis = pool_alloc(disjunct_pool);
257 #else
258 ndis = pool_alloccxx . . $ pool_alloc(6cde9c27c50a76a3).(disjunct_pool);
259 #endif
260
261 ndis->leftcxx . . $ Disjunct_struct#left. = ndis->rightcxx . . $ Disjunct_struct#right. = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!;
262
263 /* Build a list of connectors from the Tconnectors. */
264 Connectorcxx . . $ Connector# **jet[2] = { &ndis->leftcxx . . $ Disjunct_struct#left., &ndis->rightcxx . . $ Disjunct_struct#right. };
265 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! is_tracon[2] = { falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`! };
266 for (Tconnectorcxx . . $ Tconnector# *t = cl->ccxx . . $ clause_struct#c.; t != NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; t = t->nextcxx . . $ Tconnector_struct#next.)
267 {
268 int idir = ('+' == t->ecxx . . $ Tconnector_struct#e.->dircxx . . $ Exp_struct#$anonymous_type_2#$anonymous_type_4#dir.);
269
270 if (is_tracon[idir]) continue; /* this direction is complete */
271 if (NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`! != t->traconcxx . . $ Tconnector_struct#tracon.)
272 {
273 /* Use the cached tracon and mark this direction as complete. */
274 *(jet[idir]) = t->traconcxx . . $ Tconnector_struct#tracon.;
275 is_tracon[idir] = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
276 continue;
277 }
278
279 Connectorcxx . . $ Connector# *n = connector_newcxx . . $ connector_new(12f9aac2941b19a0).(connector_pool, t->ecxx . . $ Tconnector_struct#e.->condesccxx . . $ Exp_struct#$anonymous_type_5#condesc.);
280 t->traconcxx . . $ Tconnector_struct#tracon. = n; /* cache this tracon */
281
282 n->exp_poscxx . . $ Connector_struct#$anonymous_type_2#$anonymous_type_3#exp_pos. = t->ecxx . . $ Tconnector_struct#e.->poscxx . . $ Exp_struct#pos.;
283 n->multicxx . . $ Connector_struct#multi. = t->ecxx . . $ Tconnector_struct#e.->multicxx . . $ Exp_struct#$anonymous_type_2#$anonymous_type_4#multi.;
284 n->farthest_wordcxx . . $ Connector_struct#farthest_word. = t->ecxx . . $ Tconnector_struct#e.->farthest_wordcxx . . $ Exp_struct#$anonymous_type_2#$anonymous_type_4#farthest_word.;
285
286 *(jet[idir]) = n;
287 jet[idir] = &n->nextcxx . . $ Connector_struct#next.;
288 }
289
290 /* XXX add_category() starts category strings by ' '.
291 * FIXME Replace it by a better indication. */
292 if (sat_solver || (!IS_GENERATIONcxx . . $ `link-grammar/dict-common/dict-common.h:32:9`!(sent->dict) || (' ' != wstring[0])))
293 {
294 ndis->word_stringcxx . . $ Disjunct_struct#$anonymous_type_0#$anonymous_type_1#word_string. = wstring;
295 ndis->costcxx . . $ Disjunct_struct#$anonymous_type_0#$anonymous_type_1#cost. = cl->totcostcxx . . $ clause_struct#totcost.;
296 ndis->is_categorycxx . . $ Disjunct_struct#$anonymous_type_0#$anonymous_type_1#is_category. = 0;
297 }
298 else
299 {
300 ndis->num_categories_allocedcxx . . $ Disjunct_struct#$anonymous_type_0#$anonymous_type_2#num_categories_alloced. = 4;
301 ndis->categorycxx . . $ Disjunct_struct#$anonymous_type_0#$anonymous_type_2#category. =
302 malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(*ndis->categorycxx . . $ Disjunct_struct#$anonymous_type_0#$anonymous_type_2#category.) * ndis->num_categories_allocedcxx . . $ Disjunct_struct#$anonymous_type_0#$anonymous_type_2#num_categories_alloced.);
303 ndis->num_categoriescxx . . $ Disjunct_struct#$anonymous_type_0#$anonymous_type_2#num_categories. = 1;
304 ndis->categorycxx . . $ Disjunct_struct#$anonymous_type_0#$anonymous_type_2#category.[0].numcxx . . $ $anonymous_type_1fe34d592de6147a_7#num. = strtolcxx . . $ strtol(44bbb87609b212fc).(wstring, NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!, 16);
305 ndis->categorycxx . . $ Disjunct_struct#$anonymous_type_0#$anonymous_type_2#category.[1].numcxx . . $ $anonymous_type_1fe34d592de6147a_7#num. = 0; /* API array terminator */
306 assertcxx . . $ `link-grammar/error.h:107:9`!(sat_solver || ((ndis->category[0].num > 0) &&
307 (ndis->category[0].num < 64*1024)),
308 "Insane category %u", ndis->category[0].num);
309 ndis->categorycxx . . $ Disjunct_struct#$anonymous_type_0#$anonymous_type_2#category.[0].costcxx . . $ $anonymous_type_1fe34d592de6147a_7#cost. = cl->totcostcxx . . $ clause_struct#totcost.;
310 // ndis->cost = cl->totcost; No! clobbers memory!
311 }
312
313 ndis->originating_gwordcxx . . $ Disjunct_struct#originating_gword. = (gword_setcxx . . $ gword_set#*)gs; /* XXX remove constness */
314 ndis->nextcxx . . $ Disjunct_struct#next. = dis;
315 dis = ndis;
316 }
317 return dis;
318 }
319
320 Disjunctcxx . . $ Disjunct# *build_disjuncts_for_expcxx . . $ build_disjuncts_for_exp(51b32e8a7d083af7).(Sentencecxx . . $ Sentence# sent, Expcxx . . $ Exp#* exp, const char *word,
321 const gword_setcxx . . $ gword_set# *gs, float cost_cutoff,
322 Parse_Optionscxx . . $ Parse_Options# opts)
323 {
324 clause_contextcxx . . $ clause_context# ct = { 0 };
325 ct.cost_cutoffcxx . . $ $anonymous_type_9cef6a05adbc8e66_0#cost_cutoff. = cost_cutoff;
326
327 if (unlikelycxx . . $ `link-grammar/utilities.h:276:9`!(sent->Clause_pool == NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!))
328 {
329 ct.Clause_poolcxx . . $ $anonymous_type_9cef6a05adbc8e66_0#Clause_pool. = pool_newcxx . . $ pool_new(8ba40a212f70b706).(__func__, "Clause",
330 /*num_elements*/4096, sizeof(Clausecxx . . $ Clause#),
331 /*zero_out*/falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!, /*align*/falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!, /*exact*/falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!);
332 ct.Tconnector_poolcxx . . $ $anonymous_type_9cef6a05adbc8e66_0#Tconnector_pool. = pool_newcxx . . $ pool_new(8ba40a212f70b706).(__func__, "Tconnector",
333 /*num_elements*/32768, sizeof(Tconnectorcxx . . $ Tconnector#),
334 /*zero_out*/falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!, /*align*/falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!, /*exact*/falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!);
335 /* Keep for freeing at the caller. */
336 sent->Clause_poolcxx . . $ Sentence_s#Clause_pool. = ct.Clause_poolcxx . . $ $anonymous_type_9cef6a05adbc8e66_0#Clause_pool.;
337 sent->Tconnector_poolcxx . . $ Sentence_s#Tconnector_pool. = ct.Tconnector_poolcxx . . $ $anonymous_type_9cef6a05adbc8e66_0#Tconnector_pool.;
338 }
339 else
340 {
341 ct.Clause_poolcxx . . $ $anonymous_type_9cef6a05adbc8e66_0#Clause_pool. = sent->Clause_poolcxx . . $ Sentence_s#Clause_pool.;
342 ct.Tconnector_poolcxx . . $ $anonymous_type_9cef6a05adbc8e66_0#Tconnector_pool. = sent->Tconnector_poolcxx . . $ Sentence_s#Tconnector_pool.;
343 }
344
345 // printf("%s\n", lg_exp_stringify(exp));
346 Clausecxx . . $ Clause# *c = build_clausecxx . . $ build_clause(6597858a58c4260).(exp, &ct, NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!);
347 // print_clause_list(c);
348 Disjunctcxx . . $ Disjunct# *dis = build_disjunctcxx . . $ build_disjunct(fbe0d9ef6f5aae5b).(sent, c, word, gs, cost_cutoff, opts);
349 // print_disjunct_list(dis);
350 pool_reusecxx . . $ pool_reuse(92f32b8d0af4e0ba).(ct.Clause_poolcxx . . $ $anonymous_type_9cef6a05adbc8e66_0#Clause_pool.);
351 pool_reusecxx . . $ pool_reuse(92f32b8d0af4e0ba).(ct.Tconnector_poolcxx . . $ $anonymous_type_9cef6a05adbc8e66_0#Tconnector_pool.);
352
353 /* We are done, in the convectional case. */
354 if (NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`! == opts || 0 == opts->max_disjunctscxx . . $ Parse_Options_s#max_disjuncts.) return dis;
355
356 /* If there are more than the allowed number of disjuncts,
357 * then randomly discard some of them. The discard is done
358 * with uniform weighting; no attempt to look at the cost
359 * is made. A fancier algo might selectively choose those
360 * with lower cost.
361 * We don't care for now that this doesn't work if discnt > INT_MAX.
362 */
363 int maxdj = opts->max_disjunctscxx . . $ Parse_Options_s#max_disjuncts.;
364 int discnt = count_disjunctscxx . . $ count_disjuncts(aabaea8ee08bed3d).(dis);
365 if (discnt < maxdj) return dis;
366
367 /* If we are here, we need to trim down the list */
368 unsigned int rst = sent->rand_statecxx . . $ Sentence_s#rand_state.;
369 Disjunctcxx . . $ Disjunct# *kdis = dis;
370 Disjunctcxx . . $ Disjunct# *ktail = dis;
371 for (Disjunctcxx . . $ Disjunct# *d = dis->nextcxx . . $ Disjunct_struct#next.; d != NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; d=d->nextcxx . . $ Disjunct_struct#next.)
372 {
373 int pick = rand_rcxx . . $ rand_r(4ebf403dd87dd80).(&rst) % discnt;
374 if (pick < maxdj)
375 {
376 ktail->nextcxx . . $ Disjunct_struct#next. = d;
377 ktail = d;
378 }
379 }
380 ktail->nextcxx . . $ Disjunct_struct#next. = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!;
381 if (0 != sent->rand_statecxx . . $ Sentence_s#rand_state.) sent->rand_statecxx . . $ Sentence_s#rand_state. = rst;
382
383 return kdis;
384 }
385
386 #ifdef DEBUG
387 /* Misc printing functions, useful for debugging */
388
389 static void print_Tconnector_list(Tconnector *t)
390 {
391 for (; t != NULL; t = t->next)
392 {
393 if (t->e->multi) printf("@");
394 printf("%s", t->e->condesc->more->string);
395 printf("%c", t->e->dir);
396 if (t->next != NULL) printf(" ");
397 }
398 }
399
400 GNUC_UNUSED static void print_clause_list(Clause * c)
401 {
402 for (;c != NULL; c=c->next) {
403 printf(" Clause: ");
404 printf("(%4.2f) ", c->totcost);
405 print_Tconnector_list(c->c);
406 printf("\n");
407 }
408 }
409 #endif /* DEBUG */