]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/build/src/engine/compile.c
2 * Copyright 1993, 2000 Christopher Seiwald.
4 * This file is part of Jam - see jam.c for Copyright information.
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)
14 * compile.c - compile parsed jam statements
17 * evaluate_rule() - execute a rule invocation
20 * debug_compile() - printf with indent to show rule expansion
28 #include "constants.h"
45 static void debug_compile( int which
, char const * s
, FRAME
* );
47 /* Internal functions from builtins.c */
48 void backtrace( FRAME
* );
49 void backtrace_line( FRAME
* );
50 void print_source_line( FRAME
* );
51 void unknown_rule( FRAME
*, char const * key
, module_t
*, OBJECT
* rule_name
);
55 * evaluate_rule() - execute a rule invocation
58 LIST
* evaluate_rule( RULE
* rule
, OBJECT
* rulename
, FRAME
* frame
)
61 profile_frame prof
[ 1 ];
62 module_t
* prev_module
= frame
->module
;
66 /* Try hard to indicate in which module the rule is going to execute. */
68 if ( rule
->module
->name
)
70 strncat( buf
, object_str( rule
->module
->name
), sizeof( buf
) -
72 strncat( buf
, ".", sizeof( buf
) - 1 );
73 if ( strncmp( buf
, object_str( rule
->name
), strlen( buf
) ) == 0 )
78 strncat( buf
, object_str( rule
->name
), sizeof( buf
) - 1 );
79 debug_compile( 1, buf
, frame
);
81 lol_print( frame
->args
);
85 if ( rule
->procedure
&& rule
->module
!= prev_module
)
87 /* Propagate current module to nested rule invocations. */
88 frame
->module
= rule
->module
;
91 /* Record current rule name in frame. */
92 if ( rule
->procedure
)
94 frame
->rulename
= object_str( rulename
);
95 /* And enter record profile info. */
97 profile_enter( function_rulename( rule
->procedure
), prof
);
100 /* Check traditional targets $(<) and sources $(>). */
101 if ( !rule
->actions
&& !rule
->procedure
)
102 unknown_rule( frame
, NULL
, frame
->module
, rule
->name
);
104 /* If this rule will be executed for updating the targets then construct the
111 /* The action is associated with this instance of this rule. */
112 ACTION
* const action
= (ACTION
*)BJAM_MALLOC( sizeof( ACTION
) );
113 memset( (char *)action
, '\0', sizeof( *action
) );
116 action
->targets
= targetlist( (TARGETS
*)0, lol_get( frame
->args
, 0 ) );
117 action
->sources
= targetlist( (TARGETS
*)0, 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
; t
; t
= t
->next
)
130 t
->target
->rebuilds
= targetentry( t
->target
->rebuilds
, t0
);
131 t0
->rebuilds
= targetentry( t0
->rebuilds
, t
->target
);
135 /* Append this action to the actions of each target. */
136 for ( t
= action
->targets
; t
; t
= t
->next
)
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 FUNCTION
* const function
= rule
->procedure
;
149 function_refer( function
);
150 result
= function_run( function
, frame
, stack_global() );
151 function_free( function
);
154 if ( DEBUG_PROFILE
&& rule
->procedure
)
155 profile_exit( prof
);
158 debug_compile( -1, 0, frame
);
165 * Call the given rule with the specified parameters. The parameters should be
166 * of type LIST* and end with a NULL pointer. This differs from 'evaluate_rule'
167 * in that frame for the called rule is prepared inside 'call_rule'.
169 * This function is useful when a builtin rule (in C) wants to call another rule
170 * which might be implemented in Jam.
173 LIST
* call_rule( OBJECT
* rulename
, FRAME
* caller_frame
, ... )
180 inner
->prev
= caller_frame
;
181 inner
->prev_user
= caller_frame
->module
->user_module
183 : caller_frame
->prev_user
;
184 inner
->module
= caller_frame
->module
;
186 va_start( va
, caller_frame
);
189 LIST
* const l
= va_arg( va
, LIST
* );
192 lol_add( inner
->args
, l
);
196 result
= evaluate_rule( bindrule( rulename
, inner
->module
), rulename
, inner
);
205 * debug_compile() - printf with indent to show rule expansion
208 static void debug_compile( int which
, char const * s
, FRAME
* frame
)
210 static int level
= 0;
211 static char indent
[ 36 ] = ">>>>|>>>>|>>>>|>>>>|>>>>|>>>>|>>>>|";
217 print_source_line( frame
);
219 i
= ( level
+ 1 ) * 2;
226 out_printf( "%*.*s ", i
, i
, indent
);
230 out_printf( "%s ", s
);