]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/tools/build/src/engine/parse.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / tools / build / src / engine / parse.cpp
CommitLineData
7c673cae
FG
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.
1e59de90 10 * (See accompanying file LICENSE.txt or https://www.bfgroup.xyz/b2/LICENSE.txt)
7c673cae
FG
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"
1e59de90 21#include "mem.h"
7c673cae
FG
22
23/*
24 * parse.c - make and destroy parse trees as driven by the parser
25 *
26 * 09/07/00 (seiwald) - ref count on PARSE to avoid freeing when used,
27 * as per Matt Armstrong.
28 * 09/11/00 (seiwald) - structure reworked to reflect that (*func)()
29 * returns a LIST *.
30 */
31
32static PARSE * yypsave;
33
b32b8144 34static void parse_impl( FRAME * frame )
7c673cae 35{
7c673cae
FG
36
37 /* Now parse each block of rules and execute it. Execute it outside of the
38 * parser so that recursive calls to yyrun() work (no recursive yyparse's).
39 */
40
41 for ( ; ; )
42 {
43 PARSE * p;
7c673cae
FG
44
45 /* Filled by yyparse() calling parse_save(). */
46 yypsave = 0;
47
48 /* If parse error or empty parse, outta here. */
49 if ( yyparse() || !( p = yypsave ) )
50 break;
51
52 /* Run the parse tree. */
1e59de90 53 auto func = b2::jam::make_unique_bare_jptr( function_compile( p ), function_free );
7c673cae 54 parse_free( p );
1e59de90 55 list_free( function_run( func.get(), frame, stack_global() ) );
7c673cae
FG
56 }
57
58 yyfdone();
59}
60
61
b32b8144
FG
62void parse_file( OBJECT * f, FRAME * frame )
63{
64 /* Suspend scan of current file and push this new file in the stream. */
65 yyfparse( f );
66
67 parse_impl( frame );
68}
69
70
71void parse_string( OBJECT * name, const char * * lines, FRAME * frame )
72{
73 yysparse( name, lines );
74 parse_impl( frame );
75}
76
77
7c673cae
FG
78void parse_save( PARSE * p )
79{
80 yypsave = p;
81}
82
83
84PARSE * parse_make(
85 int type,
86 PARSE * left,
87 PARSE * right,
88 PARSE * third,
89 OBJECT * string,
90 OBJECT * string1,
91 int num )
92{
93 PARSE * p = (PARSE *)BJAM_MALLOC( sizeof( PARSE ) );
94
95 p->type = type;
96 p->left = left;
97 p->right = right;
98 p->third = third;
99 p->string = string;
100 p->string1 = string1;
101 p->num = num;
102 p->refs = 1;
103 p->rulename = 0;
104
105 if ( left )
106 {
107 p->file = object_copy( left->file );
108 p->line = left->line;
109 }
110 else
111 {
112 yyinput_last_read_token( &p->file, &p->line );
113 p->file = object_copy( p->file );
114 }
115
116 return p;
117}
118
119
120void parse_refer( PARSE * p )
121{
122 ++p->refs;
123}
124
125
126void parse_free( PARSE * p )
127{
128 if ( --p->refs )
129 return;
130
131 if ( p->string )
132 object_free( p->string );
133 if ( p->string1 )
134 object_free( p->string1 );
135 if ( p->left )
136 parse_free( p->left );
137 if ( p->right )
138 parse_free( p->right );
139 if ( p->third )
140 parse_free( p->third );
141 if ( p->rulename )
142 object_free( p->rulename );
143 if ( p->file )
144 object_free( p->file );
145
146 BJAM_FREE( (char *)p );
147}