]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/build/src/engine/parse.c
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / tools / build / src / engine / parse.c
1 /*
2 * Copyright 1993, 2000 Christopher Seiwald.
3 *
4 * This file is part of Jam - see jam.c for Copyright information.
5 */
6
7 /* This file is ALSO:
8 * Copyright 2001-2004 David Abrahams.
9 * Distributed under the Boost Software License, Version 1.0.
10 * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
11 */
12
13 #include "jam.h"
14 #include "lists.h"
15 #include "parse.h"
16 #include "scan.h"
17 #include "object.h"
18 #include "modules.h"
19 #include "frames.h"
20 #include "function.h"
21
22 /*
23 * parse.c - make and destroy parse trees as driven by the parser
24 *
25 * 09/07/00 (seiwald) - ref count on PARSE to avoid freeing when used,
26 * as per Matt Armstrong.
27 * 09/11/00 (seiwald) - structure reworked to reflect that (*func)()
28 * returns a LIST *.
29 */
30
31 static PARSE * yypsave;
32
33 void parse_file( OBJECT * f, FRAME * frame )
34 {
35 /* Suspend scan of current file and push this new file in the stream. */
36 yyfparse( f );
37
38 /* Now parse each block of rules and execute it. Execute it outside of the
39 * parser so that recursive calls to yyrun() work (no recursive yyparse's).
40 */
41
42 for ( ; ; )
43 {
44 PARSE * p;
45 FUNCTION * func;
46
47 /* Filled by yyparse() calling parse_save(). */
48 yypsave = 0;
49
50 /* If parse error or empty parse, outta here. */
51 if ( yyparse() || !( p = yypsave ) )
52 break;
53
54 /* Run the parse tree. */
55 func = function_compile( p );
56 parse_free( p );
57 list_free( function_run( func, frame, stack_global() ) );
58 function_free( func );
59 }
60
61 yyfdone();
62 }
63
64
65 void parse_save( PARSE * p )
66 {
67 yypsave = p;
68 }
69
70
71 PARSE * parse_make(
72 int type,
73 PARSE * left,
74 PARSE * right,
75 PARSE * third,
76 OBJECT * string,
77 OBJECT * string1,
78 int num )
79 {
80 PARSE * p = (PARSE *)BJAM_MALLOC( sizeof( PARSE ) );
81
82 p->type = type;
83 p->left = left;
84 p->right = right;
85 p->third = third;
86 p->string = string;
87 p->string1 = string1;
88 p->num = num;
89 p->refs = 1;
90 p->rulename = 0;
91
92 if ( left )
93 {
94 p->file = object_copy( left->file );
95 p->line = left->line;
96 }
97 else
98 {
99 yyinput_last_read_token( &p->file, &p->line );
100 p->file = object_copy( p->file );
101 }
102
103 return p;
104 }
105
106
107 void parse_refer( PARSE * p )
108 {
109 ++p->refs;
110 }
111
112
113 void parse_free( PARSE * p )
114 {
115 if ( --p->refs )
116 return;
117
118 if ( p->string )
119 object_free( p->string );
120 if ( p->string1 )
121 object_free( p->string1 );
122 if ( p->left )
123 parse_free( p->left );
124 if ( p->right )
125 parse_free( p->right );
126 if ( p->third )
127 parse_free( p->third );
128 if ( p->rulename )
129 object_free( p->rulename );
130 if ( p->file )
131 object_free( p->file );
132
133 BJAM_FREE( (char *)p );
134 }