@@ -210,6 +210,30 @@ static struct xnode* _node_text_push(struct _yycontext *yy, const char *text) {
210210 return _push_and_register (yy , _node_text (yy , text ));
211211}
212212
213+ int node_bind (struct node * n ) {
214+ return _node_bind (n );
215+ }
216+
217+ struct node * node_clone_and_register (struct node * n_ ) {
218+ struct sctx * ctx = n_ -> ctx ;
219+ struct xnode * n = (struct xnode * ) n_ ;
220+ struct xnode * x = pool_calloc (g_env .pool , sizeof (* x ));
221+ * x = * n ;
222+ x -> base .flags = 0 ;
223+ x -> base .child = 0 ;
224+ x -> base .next = 0 ;
225+ x -> base .parent = 0 ;
226+ x -> base .impl = 0 ;
227+ x -> base .value_get = 0 ;
228+ x -> base .init = 0 ;
229+ x -> base .setup = 0 ;
230+ x -> base .build = 0 ;
231+ x -> base .post_build = 0 ;
232+ x -> base .dispose = 0 ;
233+ _node_register (ctx , x );
234+ return (struct node * ) x ;
235+ }
236+
213237static char * _text_escaped (char * wp , const char * rp ) {
214238 // Replace: \} \{ \n \r \t
215239 int esc = 0 ;
@@ -445,16 +469,17 @@ static void _script_destroy(struct sctx *s) {
445469
446470static int _node_bind (struct node * n ) {
447471 int rc = 0 ;
448- // Tree has been built since its safe to compute node name
449- if (n -> type != NODE_TYPE_SCRIPT ) {
450- n -> name = pool_printf (g_env .pool , "%s:%-3u %5s" , _node_file (n ), n -> lnum , n -> value );
451- } else {
452- n -> name = pool_printf (g_env .pool , "%s %5s" , _node_file (n ), "" );
453- }
454- n -> vfile = pool_printf (g_env .pool , ".%u" , n -> index );
455-
456472 if (!(n -> flags & NODE_FLG_BOUND )) {
457473 n -> flags |= NODE_FLG_BOUND ;
474+
475+ // Tree has been built since its safe to compute node name
476+ if (n -> type != NODE_TYPE_SCRIPT ) {
477+ n -> name = pool_printf (g_env .pool , "%s:%-3u %5s" , _node_file (n ), n -> lnum , n -> value );
478+ } else {
479+ n -> name = pool_printf (g_env .pool , "%s %5s" , _node_file (n ), "" );
480+ }
481+ n -> vfile = pool_printf (g_env .pool , ".%u" , n -> index );
482+
458483 switch (n -> type ) {
459484 case NODE_TYPE_SCRIPT :
460485 rc = node_script_setup (n );
@@ -575,7 +600,7 @@ const char* node_value(struct node *n) {
575600}
576601
577602void node_reset (struct node * n ) {
578- n -> flags &= ~(NODE_FLG_UPDATED | NODE_FLG_BUILT | NODE_FLG_SETUP | NODE_FLG_INIT );
603+ n -> flags &= ~(NODE_FLG_BUILT | NODE_FLG_SETUP | NODE_FLG_INIT );
579604}
580605
581606static void _init_subnodes (struct node * n ) {
@@ -609,30 +634,6 @@ static void _post_build_subnodes(struct node *n) {
609634 }
610635}
611636
612- static void _macro_call_init (struct node * n ) {
613- }
614-
615- static void _macros_init (struct sctx * s ) {
616- for (int i = 0 ; i < s -> nodes .num ; ++ i ) {
617- struct node * n = NODE_AT (& s -> nodes , i );
618- if (n -> type == NODE_TYPE_MACRO ) {
619- n -> flags |= NODE_FLG_SETUP ;
620- _node_context_push (n );
621- n -> init (n );
622- _node_context_pop (n );
623- }
624- }
625- for (int i = 0 ; i < s -> nodes .num ; ++ i ) {
626- struct node * n = NODE_AT (& s -> nodes , i );
627- if (n -> type == NODE_TYPE_CALL && !(n -> flags & NODE_FLG_CALLED )) {
628- n -> flags |= NODE_FLG_CALLED ;
629- _node_context_push (n );
630- _macro_call_init (n );
631- _node_context_pop (n );
632- }
633- }
634- }
635-
636637void node_init (struct node * n ) {
637638 if (!node_is_init (n )) {
638639 n -> flags |= NODE_FLG_INIT ;
@@ -641,6 +642,8 @@ void node_init(struct node *n) {
641642 case NODE_TYPE_INCLUDE :
642643 case NODE_TYPE_FOREACH :
643644 case NODE_TYPE_IN_SOURCES :
645+ case NODE_TYPE_MACRO :
646+ case NODE_TYPE_CALL :
644647 _node_context_push (n );
645648 n -> init (n );
646649 _init_subnodes (n );
@@ -790,7 +793,6 @@ int script_include(struct node *parent, const char *file, struct node **out) {
790793
791794void script_build (struct sctx * s ) {
792795 akassert (s -> root );
793- _macros_init (s );
794796 node_init (s -> root );
795797 node_setup (s -> root );
796798 node_build (s -> root );
0 commit comments