From 58beabb9dcdfb0018be91d66443255bfd9474c36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jurko=20Gospodneti=C4=87?= Date: Wed, 18 Jul 2012 14:24:19 +0000 Subject: [PATCH] Boost Jam code cleanup - moved code for creating new internal include targets into a single location (rules.c module) instead of having it done in two (rules.c & builtins.c modules). [SVN r79584] --- src/engine/builtins.c | 19 +++---------- src/engine/rules.c | 63 +++++++++++++++++++++++++------------------ src/engine/rules.h | 7 ++--- 3 files changed, 45 insertions(+), 44 deletions(-) diff --git a/src/engine/builtins.c b/src/engine/builtins.c index 52bd56027..96d80a9fc 100644 --- a/src/engine/builtins.c +++ b/src/engine/builtins.c @@ -502,23 +502,12 @@ LIST * builtin_depends( FRAME * frame, int flags ) LISTITER end = list_end( targets ); for ( ; iter != end; iter = list_next( iter ) ) { - TARGET * t = bindtarget( list_item( iter ) ); + TARGET * const t = bindtarget( list_item( iter ) ); - /* If doing INCLUDES, switch to the TARGET's include TARGET, creating it - * if necessary. The internal include TARGET shares the name of its - * parent. - */ if ( flags ) - { - if ( !t->includes ) - { - t->includes = copytarget( t ); - t->includes->original_target = t; - } - t = t->includes; - } - - t->depends = targetlist( t->depends, sources ); + target_include_many( t, sources ); + else + t->depends = targetlist( t->depends, sources ); } /* Enter reverse links */ diff --git a/src/engine/rules.c b/src/engine/rules.c index aaf9649b9..2212140ad 100644 --- a/src/engine/rules.c +++ b/src/engine/rules.c @@ -46,23 +46,51 @@ static struct hash * targethash = 0; /* - * target_include() - adds the 'included' TARGET to the list of targets included - * by the 'including' TARGET. Such targets are modeled as dependencies of the - * internal include node belonging to the 'including' TARGET. + * get_target_includes() - lazy creates a target's internal includes node + * + * The newly created node is not entered into the hash table as there should + * never be a need to bind them directly from a target names. If you want to + * access an internal includes node by name, first access the actual target and + * then read the internal includes node from there. */ -void target_include( TARGET * including, TARGET * included ) +static TARGET * get_target_includes( TARGET * const t ) { - TARGET * internal; - if ( !including->includes ) + if ( !t->includes ) { - including->includes = copytarget( including ); - including->includes->original_target = including; + TARGET * const i = (TARGET *)BJAM_MALLOC( sizeof( *t ) ); + memset( (char *)i, '\0', sizeof( *i ) ); + i->name = object_copy( t->name ); + i->boundname = object_copy( i->name ); + i->flags |= T_FLAG_NOTFILE | T_FLAG_INTERNAL; + i->original_target = t; + t->includes = i; } - internal = including->includes; + return t->includes; +} + + +/* + * target_include() - adds a target to the given targe's 'included' list + * target_include_many() - adds targets to the given target's 'included' list + * + * Included targets are modeled as dependencies of the including target's + * internal include node. + */ + +void target_include( TARGET * const including, TARGET * const included ) +{ + TARGET * const internal = get_target_includes( including ); internal->depends = targetentry( internal->depends, included ); } +void target_include_many( TARGET * const including, LIST * const included_names + ) +{ + TARGET * const internal = get_target_includes( including ); + internal->depends = targetlist( internal->depends, included_names ); +} + /* * enter_rule() - return pointer to RULE, creating it if necessary in @@ -178,23 +206,6 @@ void bind_explicitly_located_targets() } -/* - * copytarget() - make a new target with the old target's name. - * - * Not entered into the hash table -- for internal nodes. - */ - -TARGET * copytarget( TARGET const * ot ) -{ - TARGET * const t = (TARGET *)BJAM_MALLOC( sizeof( *t ) ); - memset( (char *)t, '\0', sizeof( *t ) ); - t->name = object_copy( ot->name ); - t->boundname = object_copy( t->name ); - t->flags |= T_FLAG_NOTFILE | T_FLAG_INTERNAL; - return t; -} - - /* * touch_target() - mark a target to simulate being new. */ diff --git a/src/engine/rules.h b/src/engine/rules.h index 4230325bc..fe2792f43 100644 --- a/src/engine/rules.h +++ b/src/engine/rules.h @@ -252,12 +252,13 @@ void rule_free ( RULE * ); /* Target related functions. */ void bind_explicitly_located_targets(); TARGET * bindtarget ( OBJECT * const ); -TARGET * copytarget ( TARGET const * t ); void freetargets ( TARGETS * ); TARGETS * targetchain ( TARGETS *, TARGETS * ); TARGETS * targetentry ( TARGETS *, TARGET * ); -void target_include ( TARGET * including, - TARGET * included ); +void target_include ( TARGET * const including, + TARGET * const included ); +void target_include_many ( TARGET * const including, + LIST * const included_names ); TARGETS * targetlist ( TARGETS *, LIST * target_names ); void touch_target ( OBJECT * const ); void clear_includes ( TARGET * );