[go: up one dir, main page]

File: recipe.c

package info (click to toggle)
cook 2.10-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 6,856 kB
  • ctags: 3,842
  • sloc: ansic: 47,714; sh: 12,150; makefile: 4,317; yacc: 3,104; awk: 154
file content (325 lines) | stat: -rw-r--r-- 7,466 bytes parent folder | download | duplicates (4)
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
/*
 *	cook - file construction tool
 *	Copyright (C) 1997, 1998, 1999 Peter Miller;
 *	All rights reserved.
 *
 *	This program is free software; you can redistribute it and/or modify
 *	it under the terms of the GNU General Public License as published by
 *	the Free Software Foundation; either version 2 of the License, or
 *	(at your option) any later version.
 *
 *	This program is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU General Public License for more details.
 *
 *	You should have received a copy of the GNU General Public License
 *	along with this program; if not, write to the Free Software
 *	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
 *
 * MANIFEST: functions to manipulate recipes
 */

#include <ac/string.h>

#include <expr.h>
#include <error_intl.h>
#include <flag.h>
#include <match/new_by_recip.h>
#include <match/wl.h>
#include <mem.h>
#include <opcode/list.h>
#include <option.h>
#include <recipe.h>
#include <stmt.h>
#include <strip_dot.h>
#include <trace.h>


/*
 * NAME
 *	recipe_destructor
 *
 * SYNOPSIS
 *	void recipe_destructor(recipe_ty *);
 *
 * DESCRIPTION
 *	The recipe_destructor function is used to release the resources
 *	held by a recipe_ty structure.
 */

static void recipe_destructor _((recipe_ty *));

static void
recipe_destructor(rp)
	recipe_ty	*rp;
{
	trace(("recipe_destructor(rp = %08lX)\n{\n"/*}*/, (long)rp));
	if (rp->target)
		string_list_delete(rp->target);
	if (rp->need1)
		opcode_list_delete(rp->need1);
	if (rp->need2)
		opcode_list_delete(rp->need2);
	if (rp->flags)
		flag_delete(rp->flags);
	if (rp->precondition)
		opcode_list_delete(rp->precondition);
	if (rp->single_thread)
		opcode_list_delete(rp->single_thread);
	if (rp->host_binding)
		opcode_list_delete(rp->host_binding);
	if (rp->out_of_date)
		opcode_list_delete(rp->out_of_date);
	if (rp->up_to_date)
		opcode_list_delete(rp->up_to_date);
	expr_position_destructor(&rp->pos);
	trace((/*{*/"}\n"));
}


/*
 * NAME
 *	recipe_delete
 *
 * SYNOPSIS
 *	void recipe_delete(recipe_ty *);
 *
 * DESCRIPTION
 *	The recipe_delete function is used to release the resources
 *	held by a recipe_ty structure in dynamic memory.
 */

void
recipe_delete(rp)
	recipe_ty	*rp;
{
	trace(("recipe_delete(rp = %08lX)\n{\n"/*}*/, (long)rp));
	assert(rp->reference_count > 0);
	rp->reference_count--;
	if (rp->reference_count <= 0)
	{
		recipe_destructor(rp);
		mem_free(rp);
	}
	trace((/*{*/"}\n"));
}


/*
 * NAME
 *	recipe_copy
 *
 * SYNOPSIS
 *	recipe_ty *recipe_copy(recipe_ty *);
 *
 * DESCRIPTION
 *	The recipe_copy function is used to make a copy of a recipe in
 *	dynamic memory.
 *
 * RETURNS
 *	recipe_ty *; pointer to new copy.
 *
 * CAVEAT
 *	Actually uses reference counting.
 */

recipe_ty *
recipe_copy(rp)
	recipe_ty	*rp;
{
	trace(("recipe_copy(rp = %08lX)\n{\n"/*}*/, (long)rp));
	assert(rp);
	assert(rp->reference_count > 0);
	rp->reference_count++;
	trace((/*{*/"}\n"));
	return rp;
}


/*
 * NAME
 *	recipe_constructor
 *
 * SYNOPSIS
 *	void recipe_constructor(recipe_ty *, string_list_ty *,
 *		expr_list_ty *, expr_list_ty *, flag_ty *, int, expr_ty *,
 *		stmt_ty *, stmt_ty *, expr_position_ty *);
 *
 * DESCRIPTION
 *	The recipe_constructor function is used to intitialize a
 *	recipe_ty structure.
 */

static int recipe_constructor _((recipe_ty *, string_list_ty *,
	opcode_list_ty *, opcode_list_ty *, flag_ty *, int,
	opcode_list_ty *, opcode_list_ty *, opcode_list_ty *,
	opcode_list_ty *, opcode_list_ty *, const expr_position_ty *));

static int
recipe_constructor(rp, target, need1, need2, flags, multiple, precondition,
		single_thread, host_binding, out_of_date, up_to_date, pp)
	recipe_ty	*rp;
	string_list_ty	*target;
	opcode_list_ty	*need1;
	opcode_list_ty	*need2;
	flag_ty		*flags;
	int		multiple;
	opcode_list_ty	*precondition;
	opcode_list_ty	*single_thread;
	opcode_list_ty	*host_binding;
	opcode_list_ty	*out_of_date;
	opcode_list_ty	*up_to_date;
	const expr_position_ty *pp;
{
	size_t		j;
	match_ty	*mp;

	trace(("recipe_constructor(rp = %08lX)\n{\n"/*}*/, (long)rp));
	rp->target = string_list_new_copy(target);
	rp->need1 = need1 ? opcode_list_copy(need1) : 0;
	rp->need2 = need2 ? opcode_list_copy(need2) : 0;
	rp->precondition = precondition ? opcode_list_copy(precondition) : 0;
	rp->flags = flags ? flag_copy(flags) : 0;
	rp->multiple = multiple;
	rp->precondition = precondition ? opcode_list_copy(precondition) : 0;
	rp->single_thread = single_thread ? opcode_list_copy(single_thread) : 0;
	rp->host_binding = host_binding ? opcode_list_copy(host_binding) : 0;
	rp->out_of_date = out_of_date ? opcode_list_copy(out_of_date) : 0;
	rp->up_to_date = up_to_date ? opcode_list_copy(up_to_date) : 0;
	expr_position_copy_constructor(&rp->pos, pp);

	strip_dot_list(rp->target);
	rp->inhibit = 0;

	/*
	 * is it implicit or explicit?
	 */
	mp = match_new_by_recipe(rp);
	rp->implicit = match_wl_usage_mask(mp, rp->target, &rp->pos);
	if (rp->implicit)
	{
		string_ty	*s;
		int		all_used;

		/* make sure all the bits get used at least once */
		all_used = 0;
		for (j = 0; j < rp->target->nstrings; ++j)
		{
			s = rp->target->string[j];
			if (rp->implicit == match_usage_mask(mp, s, &rp->pos))
				++all_used;
		}
		if (!all_used)
		{
			error_with_position
			(
				&rp->pos,
				0,
i18n("at least one target of an implicit recipe must use all of the \
named pattern elements")
			);
			match_delete(mp);
			trace((/*{*/"}\n"));
			return -1;
		}
	}
	match_delete(mp);
	trace((/*{*/"}\n"));
	return 0;
}


/*
 * NAME
 *	recipe_new
 *
 * SYNOPSIS
 *	recipe_ty *recipe_new(string_list_ty *target, expr_list_ty *need,
 *		expr_list_ty *need2, unsigned long flags, int multiple,
 *		expr_ty *precondition, stmt_ty *action, stmt_ty *use_action,
 *		expr_position_ty *pp);
 *
 * DESCRIPTION
 *	The recipe_new function is used to allocate a new recipe_ty
 *	structure in dynamic memory and initialize it.
 *
 * RETURNS
 *	recipe_ty *
 */

recipe_ty *
recipe_new(target, need1, need2, flags, multiple, precondition, single_thread,
		host_binding, out_of_date, up_to_date, pp)
	string_list_ty	*target;
	opcode_list_ty	*need1;
	opcode_list_ty	*need2;
	flag_ty		*flags;
	int		multiple;
	opcode_list_ty	*precondition;
	opcode_list_ty	*single_thread;
	opcode_list_ty	*host_binding;
	opcode_list_ty	*out_of_date;
	opcode_list_ty	*up_to_date;
	const expr_position_ty *pp;
{
	recipe_ty	*rp;
	int		result;

	trace(("recipe_new()\n{\n"/*}*/));
	rp = mem_alloc(sizeof(recipe_ty));
	rp->reference_count = 1;
	result =
		recipe_constructor
		(
			rp,
			target,
			need1,
			need2,
			flags,
			multiple,
			precondition,
			single_thread,
			host_binding,
			out_of_date,
			up_to_date,
			pp
		);
	if (result < 0)
	{
		recipe_delete(rp);
		rp = 0;
	}
	trace(("return %08lX;\n", (long)rp));
	trace((/*{*/"}\n"));
	return rp;
}


/*
 * NAME
 *	recipe_flags_set - set them
 *
 * SYNOPSIS
 *	void recipe_flags_set(recipe_ty *);
 *
 * DESCRIPTION
 *	The recipe_flags_set function is used to take a flags variable
 *	and set the appropriate options at the given level.
 *
 * RETURNS
 *	void
 *
 * CAVEAT
 *	Use the option_undo_level function to remove the flag settings.
 */

void
recipe_flags_set(rp)
	recipe_ty	*rp;
{
	trace(("recipe_flags_set(rp = %8.8lX)\n{\n"/*}*/, (long)rp));
	if (rp->flags)
		flag_set_options(rp->flags, OPTION_LEVEL_RECIPE);
	trace((/*{*/"}\n"));
}