]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/build/src/engine/compile.cpp
2 * Copyright 1993, 2000 Christopher Seiwald.
4 * This file is part of Jam - see jam.c for Copyright information.
8 * Copyright 2022 René Ferdinand Rivera Morell
9 * Copyright 2001-2004 David Abrahams.
10 * Distributed under the Boost Software License, Version 1.0.
11 * (See accompanying file LICENSE.txt or https://www.bfgroup.xyz/b2/LICENSE.txt)
15 * compile.c - compile parsed jam statements
18 * evaluate_rule() - execute a rule invocation
21 * debug_compile() - printf with indent to show rule expansion
29 #include "constants.h"
37 #include "jam_strings.h"
46 static void debug_compile( int which
, char const * s
, FRAME
* );
48 /* Internal functions from builtins.c */
49 void backtrace( FRAME
* );
50 void backtrace_line( FRAME
* );
51 void print_source_line( FRAME
* );
52 void unknown_rule( FRAME
*, char const * key
, module_t
*, OBJECT
* rule_name
);
56 * evaluate_rule() - execute a rule invocation
59 LIST
* evaluate_rule( RULE
* rule
, OBJECT
* rulename
, FRAME
* frame
)
62 profile_frame prof
[ 1 ];
63 module_t
* prev_module
= frame
->module
;
67 /* Try hard to indicate in which module the rule is going to execute. */
69 if ( rule
->module
->name
)
71 strncat( buf
, object_str( rule
->module
->name
), sizeof( buf
) -
73 strncat( buf
, ".", sizeof( buf
) - 1 );
74 if ( strncmp( buf
, object_str( rule
->name
), strlen( buf
) ) == 0 )
79 strncat( buf
, object_str( rule
->name
), sizeof( buf
) - 1 );
80 debug_compile( 1, buf
, frame
);
82 lol_print( frame
->args
);
86 if ( rule
->procedure
&& rule
->module
!= prev_module
)
88 /* Propagate current module to nested rule invocations. */
89 frame
->module
= rule
->module
;
92 /* Record current rule name in frame. */
93 if ( rule
->procedure
)
95 frame
->rulename
= object_str( rulename
);
96 /* And enter record profile info. */
98 profile_enter( function_rulename( rule
->procedure
), prof
);
101 /* Check traditional targets $(<) and sources $(>). */
102 if ( !rule
->actions
&& !rule
->procedure
)
103 unknown_rule( frame
, NULL
, frame
->module
, rulename
);
105 /* If this rule will be executed for updating the targets then construct the
112 /* The action is associated with this instance of this rule. */
113 ACTION
* const action
= b2::jam::make_ptr
<ACTION
>();
116 action
->targets
.reset(); targetlist( action
->targets
, lol_get( frame
->args
, 0 ) );
117 action
->sources
.reset(); targetlist( action
->sources
, lol_get( frame
->args
, 1 ) );
120 /* If we have a group of targets all being built using the same action
121 * and any of these targets is updated, then we have to consider them
122 * all to be out-dated. We do this by adding a REBUILDS in both directions
123 * between the first target and all the other targets.
125 if ( action
->targets
)
127 TARGET
* const t0
= action
->targets
->target
;
128 for ( t
= action
->targets
->next
.get(); t
; t
= t
->next
.get() )
130 targetentry( t
->target
->rebuilds
, t0
);
131 targetentry( t0
->rebuilds
, t
->target
);
135 /* Append this action to the actions of each target. */
136 for ( t
= action
->targets
.get(); t
; t
= t
->next
.get() )
137 t
->target
->actions
= actionlist( t
->target
->actions
, action
);
139 action_free( action
);
142 /* Now recursively compile any parse tree associated with this rule.
143 * function_refer()/function_free() call pair added to ensure the rule does
144 * not get freed while in use.
146 if ( rule
->procedure
)
148 auto function
= b2::jam::make_unique_bare_jptr( rule
->procedure
, function_refer
, function_free
);
149 result
= function_run( function
.get(), frame
, stack_global() );
152 if ( DEBUG_PROFILE
&& rule
->procedure
)
153 profile_exit( prof
);
156 debug_compile( -1, 0, frame
);
163 * Call the given rule with the specified parameters. The parameters should be
164 * of type LIST* and end with a NULL pointer. This differs from 'evaluate_rule'
165 * in that frame for the called rule is prepared inside 'call_rule'.
167 * This function is useful when a builtin rule (in C) wants to call another rule
168 * which might be implemented in Jam.
171 LIST
* call_rule( OBJECT
* rulename
, FRAME
* caller_frame
, ... )
178 inner
->prev
= caller_frame
;
179 inner
->prev_user
= caller_frame
->module
->user_module
181 : caller_frame
->prev_user
;
182 inner
->module
= caller_frame
->module
;
184 va_start( va
, caller_frame
);
187 LIST
* const l
= va_arg( va
, LIST
* );
190 lol_add( inner
->args
, l
);
194 result
= evaluate_rule( bindrule( rulename
, inner
->module
), rulename
, inner
);
203 * debug_compile() - printf with indent to show rule expansion
206 static void debug_compile( int which
, char const * s
, FRAME
* frame
)
208 static int level
= 0;
209 static char indent
[ 36 ] = ">>>>|>>>>|>>>>|>>>>|>>>>|>>>>|>>>>|";
215 print_source_line( frame
);
217 i
= ( level
+ 1 ) * 2;
224 out_printf( "%*.*s ", i
, i
, indent
);
228 out_printf( "%s ", s
);