mirror of
https://github.com/boostorg/build.git
synced 2026-02-14 00:32:11 +00:00
Boost Jam/Build cleanup - minor stylistic changes (comment updates; line wrapping; removed some dead/unused function declarations, parameters & code; declared variables as const; reordered some #include directives alphabetically, removed some unnecessary ones and added several missing ones discovered by the reordering).
[SVN r79569]
This commit is contained in:
@@ -2,146 +2,157 @@
|
||||
/* Software License, Version 1.0. (See accompanying */
|
||||
/* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */
|
||||
|
||||
#include "../native.h"
|
||||
#include "../lists.h"
|
||||
#include "../strings.h"
|
||||
#include "../mem.h"
|
||||
#include "../native.h"
|
||||
#include "../object.h"
|
||||
#include "../strings.h"
|
||||
#include "../variable.h"
|
||||
|
||||
|
||||
/* Use quite klugy approach: when we add order dependency from 'a' to 'b',
|
||||
just append 'b' to of value of variable 'a'.
|
||||
*/
|
||||
LIST *add_pair( FRAME *frame, int flags )
|
||||
/* Use quite klugy approach: when we add order dependency from 'a' to 'b', just
|
||||
* append 'b' to of value of variable 'a'.
|
||||
*/
|
||||
LIST * add_pair( FRAME * frame, int flags )
|
||||
{
|
||||
LIST* arg = lol_get( frame->args, 0 );
|
||||
LISTITER iter = list_begin( arg ), end = list_end( arg );
|
||||
|
||||
var_set( frame->module, list_item( iter ), list_copy_range( arg, list_next( iter ), end ), VAR_APPEND );
|
||||
|
||||
LIST * arg = lol_get( frame->args, 0 );
|
||||
LISTITER iter = list_begin( arg );
|
||||
LISTITER const end = list_end( arg );
|
||||
var_set( frame->module, list_item( iter ), list_copy_range( arg, list_next(
|
||||
iter ), end ), VAR_APPEND );
|
||||
return L0;
|
||||
}
|
||||
|
||||
/** Given a list and a value, returns position of that value in
|
||||
the list, or -1 if not found.
|
||||
*/
|
||||
int list_index(LIST* list, OBJECT* value)
|
||||
|
||||
/* Given a list and a value, returns position of that value in the list, or -1
|
||||
* if not found.
|
||||
*/
|
||||
int list_index( LIST * list, OBJECT * value )
|
||||
{
|
||||
int result = 0;
|
||||
LISTITER iter = list_begin(list), end = list_end(list);
|
||||
for(; iter != end; iter = list_next(iter), ++result) {
|
||||
if (object_equal(list_item(iter), value))
|
||||
LISTITER iter = list_begin( list );
|
||||
LISTITER const end = list_end( list );
|
||||
for ( ; iter != end; iter = list_next( iter ), ++result )
|
||||
if ( object_equal( list_item( iter ), value ) )
|
||||
return result;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
enum colors { white, gray, black };
|
||||
|
||||
/* Main routite of topological sort. Calls itself recursively on all
|
||||
adjacent vertices which were not yet visited. After that, 'current_vertex'
|
||||
is added to '*result_ptr'.
|
||||
*/
|
||||
void do_ts(int** graph, int current_vertex, int* colors, int** result_ptr)
|
||||
|
||||
/* Main routine for topological sort. Calls itself recursively on all adjacent
|
||||
* vertices which were not yet visited. After that, 'current_vertex' is added to
|
||||
* '*result_ptr'.
|
||||
*/
|
||||
void do_ts( int * * graph, int current_vertex, int * colors, int * * result_ptr
|
||||
)
|
||||
{
|
||||
int i;
|
||||
|
||||
colors[current_vertex] = gray;
|
||||
for(i = 0; graph[current_vertex][i] != -1; ++i) {
|
||||
int adjacent_vertex = graph[current_vertex][i];
|
||||
|
||||
if (colors[adjacent_vertex] == white)
|
||||
do_ts(graph, adjacent_vertex, colors, result_ptr);
|
||||
/* The vertex is either black, in which case we don't have to do
|
||||
anything, a gray, in which case we have a loop. If we have a loop,
|
||||
it's not clear what useful diagnostic we can emit, so we emit
|
||||
nothing. */
|
||||
colors[ current_vertex ] = gray;
|
||||
for ( i = 0; graph[ current_vertex ][ i ] != -1; ++i )
|
||||
{
|
||||
int adjacent_vertex = graph[ current_vertex ][ i ];
|
||||
if ( colors[ adjacent_vertex ] == white )
|
||||
do_ts( graph, adjacent_vertex, colors, result_ptr );
|
||||
/* The vertex is either black, in which case we do not have to do
|
||||
* anything, or gray, in which case we have a loop. If we have a loop,
|
||||
* it is not clear what useful diagnostic we can emit, so we emit
|
||||
* nothing.
|
||||
*/
|
||||
}
|
||||
colors[current_vertex] = black;
|
||||
**result_ptr = current_vertex;
|
||||
(*result_ptr)++;
|
||||
colors[ current_vertex ] = black;
|
||||
**result_ptr = current_vertex;
|
||||
( *result_ptr )++;
|
||||
}
|
||||
|
||||
void topological_sort(int** graph, int num_vertices, int* result)
|
||||
|
||||
void topological_sort( int * * graph, int num_vertices, int * result )
|
||||
{
|
||||
int i;
|
||||
int* colors = (int*)BJAM_CALLOC(num_vertices, sizeof(int));
|
||||
for (i = 0; i < num_vertices; ++i)
|
||||
colors[i] = white;
|
||||
int * colors = ( int * )BJAM_CALLOC( num_vertices, sizeof( int ) );
|
||||
for ( i = 0; i < num_vertices; ++i )
|
||||
colors[ i ] = white;
|
||||
|
||||
for(i = 0; i < num_vertices; ++i)
|
||||
if (colors[i] == white)
|
||||
do_ts(graph, i, colors, &result);
|
||||
for ( i = 0; i < num_vertices; ++i )
|
||||
if ( colors[ i ] == white )
|
||||
do_ts( graph, i, colors, &result );
|
||||
|
||||
BJAM_FREE(colors);
|
||||
BJAM_FREE( colors );
|
||||
}
|
||||
|
||||
LIST *order( FRAME *frame, int flags )
|
||||
|
||||
LIST * order( FRAME * frame, int flags )
|
||||
{
|
||||
LIST* arg = lol_get( frame->args, 0 );
|
||||
LIST* result = L0;
|
||||
LIST * arg = lol_get( frame->args, 0 );
|
||||
LIST * result = L0;
|
||||
int src;
|
||||
LISTITER iter = list_begin(arg), end = list_end(arg);
|
||||
LISTITER iter = list_begin( arg );
|
||||
LISTITER const end = list_end( arg );
|
||||
|
||||
/* We need to create a graph of order dependencies between
|
||||
the passed objects. We assume that there are no duplicates
|
||||
passed to 'add_pair'.
|
||||
*/
|
||||
int length = list_length(arg);
|
||||
int** graph = (int**)BJAM_CALLOC(length, sizeof(int*));
|
||||
int* order = (int*)BJAM_MALLOC((length+1)*sizeof(int));
|
||||
|
||||
for(src = 0; iter != end; iter = list_next(iter), ++src) {
|
||||
/* For all object this one depend upon, add elements
|
||||
to 'graph' */
|
||||
LIST* dependencies = var_get(frame->module, list_item(iter));
|
||||
/* We need to create a graph of order dependencies between the passed
|
||||
* objects. We assume there are no duplicates passed to 'add_pair'.
|
||||
*/
|
||||
int length = list_length( arg );
|
||||
int * * graph = ( int * * )BJAM_CALLOC( length, sizeof( int * ) );
|
||||
int * order = ( int * )BJAM_MALLOC( ( length + 1 ) * sizeof( int ) );
|
||||
|
||||
for ( src = 0; iter != end; iter = list_next( iter ), ++src )
|
||||
{
|
||||
/* For all objects this one depends upon, add elements to 'graph'. */
|
||||
LIST * dependencies = var_get( frame->module, list_item( iter ) );
|
||||
int index = 0;
|
||||
LISTITER dep_iter = list_begin(dependencies), dep_end = list_end(dependencies);
|
||||
LISTITER dep_iter = list_begin( dependencies );
|
||||
LISTITER const dep_end = list_end( dependencies );
|
||||
|
||||
graph[src] = (int*)BJAM_CALLOC(list_length(dependencies)+1, sizeof(int));
|
||||
for(; dep_iter != dep_end; dep_iter = list_next(dep_iter)) {
|
||||
int dst = list_index(arg, list_item(dep_iter));
|
||||
if (dst != -1)
|
||||
graph[src][index++] = dst;
|
||||
graph[ src ] = ( int * )BJAM_CALLOC( list_length( dependencies ) + 1,
|
||||
sizeof( int ) );
|
||||
for ( ; dep_iter != dep_end; dep_iter = list_next( dep_iter ) )
|
||||
{
|
||||
int const dst = list_index( arg, list_item( dep_iter ) );
|
||||
if ( dst != -1 )
|
||||
graph[ src ][ index++ ] = dst;
|
||||
}
|
||||
graph[src][index] = -1;
|
||||
graph[ src ][ index ] = -1;
|
||||
}
|
||||
|
||||
topological_sort(graph, length, order);
|
||||
topological_sort( graph, length, order );
|
||||
|
||||
{
|
||||
int index = length-1;
|
||||
for(; index >= 0; --index) {
|
||||
int index = length - 1;
|
||||
for ( ; index >= 0; --index )
|
||||
{
|
||||
int i;
|
||||
iter = list_begin(arg), end = list_end(arg);
|
||||
for (i = 0; i < order[index]; ++i, iter = list_next(iter));
|
||||
result = list_push_back(result, object_copy(list_item(iter)));
|
||||
LISTITER iter = list_begin( arg );
|
||||
LISTITER const end = list_end( arg );
|
||||
for ( i = 0; i < order[ index ]; ++i, iter = list_next( iter ) );
|
||||
result = list_push_back( result, object_copy( list_item( iter ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
/* Clean up */
|
||||
{
|
||||
int i;
|
||||
for(i = 0; i < length; ++i)
|
||||
BJAM_FREE(graph[i]);
|
||||
BJAM_FREE(graph);
|
||||
BJAM_FREE(order);
|
||||
for ( i = 0; i < length; ++i )
|
||||
BJAM_FREE( graph[ i ] );
|
||||
BJAM_FREE( graph );
|
||||
BJAM_FREE( order );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void init_order()
|
||||
{
|
||||
{
|
||||
const char* args[] = { "first", "second", 0 };
|
||||
declare_native_rule("class@order", "add-pair", args, add_pair, 1);
|
||||
char const * args[] = { "first", "second", 0 };
|
||||
declare_native_rule( "class@order", "add-pair", args, add_pair, 1 );
|
||||
}
|
||||
|
||||
{
|
||||
const char* args[] = { "objects", "*", 0 };
|
||||
declare_native_rule("class@order", "order", args, order, 1);
|
||||
char const * args[] = { "objects", "*", 0 };
|
||||
declare_native_rule( "class@order", "order", args, order, 1 );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -2,29 +2,33 @@
|
||||
/* Software License, Version 1.0. (See accompanying */
|
||||
/* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */
|
||||
|
||||
#include "../compile.h"
|
||||
#include "../lists.h"
|
||||
#include "../native.h"
|
||||
#include "../timestamp.h"
|
||||
#include "../object.h"
|
||||
#include "../strings.h"
|
||||
#include "../lists.h"
|
||||
#include "../timestamp.h"
|
||||
#include "../variable.h"
|
||||
#include "../compile.h"
|
||||
|
||||
LIST* get_grist(char* f)
|
||||
#include <string.h>
|
||||
|
||||
|
||||
LIST * get_grist( char const * const f )
|
||||
{
|
||||
char* end = strchr(f, '>');
|
||||
string s[1];
|
||||
LIST* result;
|
||||
char const * const end = strchr( f, '>' );
|
||||
string s[ 1 ];
|
||||
LIST * result;
|
||||
|
||||
string_new(s);
|
||||
string_new( s );
|
||||
|
||||
string_append_range(s, f, end+1);
|
||||
result = list_new(object_new(s->value));
|
||||
string_append_range( s, f, end + 1 );
|
||||
result = list_new( object_new( s->value ) );
|
||||
|
||||
string_free(s);
|
||||
string_free( s );
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
rule create ( raw-properties * )
|
||||
{
|
||||
@@ -41,77 +45,57 @@ rule create ( raw-properties * )
|
||||
}
|
||||
*/
|
||||
|
||||
LIST *property_set_create( FRAME *frame, int flags )
|
||||
LIST * property_set_create( FRAME * frame, int flags )
|
||||
{
|
||||
LIST* properties = lol_get( frame->args, 0 );
|
||||
LIST* sorted = L0;
|
||||
#if 0
|
||||
LIST* order_sensitive = 0;
|
||||
#endif
|
||||
LIST* unique;
|
||||
LIST* val;
|
||||
string var[1];
|
||||
OBJECT* name;
|
||||
LISTITER iter, end;
|
||||
LIST * properties = lol_get( frame->args, 0 );
|
||||
LIST * sorted = L0;
|
||||
LIST * unique;
|
||||
LIST * val;
|
||||
string var[ 1 ];
|
||||
OBJECT * name;
|
||||
LISTITER iter;
|
||||
LISTITER end;
|
||||
|
||||
#if 0
|
||||
/* Sort all properties which are not order sensitive */
|
||||
for(tmp = properties; tmp; tmp = tmp->next) {
|
||||
LIST* g = get_grist(tmp->string);
|
||||
LIST* att = call_rule("feature.attributes", frame, g, 0);
|
||||
if (list_in(att, "order-sensitive")) {
|
||||
order_sensitive = list_new( order_sensitive, copystr(tmp->string));
|
||||
} else {
|
||||
sorted = list_new( sorted, copystr(tmp->string));
|
||||
}
|
||||
list_free(att);
|
||||
}
|
||||
sorted = list_sort( properties );
|
||||
unique = list_unique( sorted );
|
||||
|
||||
sorted = list_sort(sorted);
|
||||
sorted = list_append(sorted, order_sensitive);
|
||||
unique = list_unique(sorted);
|
||||
#endif
|
||||
sorted = list_sort(properties);
|
||||
unique = list_unique(sorted);
|
||||
string_new( var );
|
||||
string_append( var, ".ps." );
|
||||
|
||||
string_new(var);
|
||||
string_append(var, ".ps.");
|
||||
|
||||
iter = list_begin( unique ), end = list_end( unique );
|
||||
for( ; iter != end; iter = list_next( iter ) ) {
|
||||
string_append(var, object_str( list_item( iter ) ));
|
||||
string_push_back(var, '-');
|
||||
}
|
||||
name = object_new(var->value);
|
||||
val = var_get(frame->module, name);
|
||||
if (list_empty(val))
|
||||
iter = list_begin( unique );
|
||||
end = list_end( unique );
|
||||
for ( ; iter != end; iter = list_next( iter ) )
|
||||
{
|
||||
OBJECT* rulename = object_new("new");
|
||||
val = call_rule(rulename, frame,
|
||||
list_append(list_new(object_new("property-set")), unique), 0);
|
||||
object_free(rulename);
|
||||
|
||||
var_set(frame->module, name, list_copy(val), VAR_SET);
|
||||
string_append( var, object_str( list_item( iter ) ) );
|
||||
string_push_back( var, '-' );
|
||||
}
|
||||
name = object_new( var->value );
|
||||
val = var_get( frame->module, name );
|
||||
if ( list_empty( val ) )
|
||||
{
|
||||
OBJECT * const rulename = object_new( "new" );
|
||||
val = call_rule( rulename, frame, list_append( list_new( object_new(
|
||||
"property-set" ) ), unique ), 0 );
|
||||
/* The 'unique' variable is freed in 'call_rule'. */
|
||||
object_free( rulename );
|
||||
var_set( frame->module, name, list_copy( val ), VAR_SET );
|
||||
}
|
||||
else
|
||||
{
|
||||
list_free(unique);
|
||||
val = list_copy(val);
|
||||
list_free( unique );
|
||||
val = list_copy( val );
|
||||
}
|
||||
object_free(name);
|
||||
|
||||
string_free(var);
|
||||
/* The 'unique' variable is freed in 'call_rule'. */
|
||||
list_free(sorted);
|
||||
object_free( name );
|
||||
string_free( var );
|
||||
list_free( sorted );
|
||||
|
||||
return val;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void init_property_set()
|
||||
{
|
||||
{
|
||||
const char* args[] = { "raw-properties", "*", 0 };
|
||||
declare_native_rule("property-set", "create", args, property_set_create, 1);
|
||||
}
|
||||
char const * args[] = { "raw-properties", "*", 0 };
|
||||
declare_native_rule( "property-set", "create", args, property_set_create, 1
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,12 +2,13 @@
|
||||
/* Software License, Version 1.0. (See accompanying */
|
||||
/* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */
|
||||
|
||||
#include "../native.h"
|
||||
#include "../timestamp.h"
|
||||
#include "../object.h"
|
||||
#include "../strings.h"
|
||||
#include "../regexp.h"
|
||||
#include "../compile.h"
|
||||
#include "../mem.h"
|
||||
#include "../native.h"
|
||||
#include "../object.h"
|
||||
#include "../regexp.h"
|
||||
#include "../strings.h"
|
||||
|
||||
|
||||
/*
|
||||
rule transform ( list * : pattern : indices * )
|
||||
@@ -20,62 +21,65 @@ rule transform ( list * : pattern : indices * )
|
||||
if $(m)
|
||||
{
|
||||
result += $(m[$(indices)]) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $(result) ;
|
||||
}
|
||||
*/
|
||||
LIST *regex_transform( FRAME *frame, int flags )
|
||||
|
||||
LIST * regex_transform( FRAME * frame, int flags )
|
||||
{
|
||||
LIST* l = lol_get( frame->args, 0 );
|
||||
LIST* pattern = lol_get( frame->args, 1 );
|
||||
LIST* indices_list = lol_get(frame->args, 2);
|
||||
int* indices = 0;
|
||||
LIST * l = lol_get( frame->args, 0 );
|
||||
LIST * pattern = lol_get( frame->args, 1 );
|
||||
LIST * indices_list = lol_get( frame->args, 2 );
|
||||
int * indices = 0;
|
||||
int size;
|
||||
int* p;
|
||||
int * p;
|
||||
LIST* result = L0;
|
||||
|
||||
string buf[1];
|
||||
string_new(buf);
|
||||
string buf[ 1 ];
|
||||
string_new( buf );
|
||||
|
||||
if (!list_empty(indices_list))
|
||||
if ( !list_empty( indices_list ) )
|
||||
{
|
||||
LISTITER iter = list_begin(indices_list), end = list_end(indices_list);
|
||||
size = list_length(indices_list);
|
||||
indices = (int*)BJAM_MALLOC(size*sizeof(int));
|
||||
for(p = indices; iter != end; iter = list_next(iter))
|
||||
{
|
||||
*p++ = atoi(object_str(list_item(iter)));
|
||||
}
|
||||
LISTITER iter = list_begin( indices_list );
|
||||
LISTITER const end = list_end( indices_list );
|
||||
size = list_length( indices_list );
|
||||
indices = ( int * )BJAM_MALLOC( size * sizeof( int ) );
|
||||
for ( p = indices; iter != end; iter = list_next( iter ) )
|
||||
*p++ = atoi( object_str( list_item( iter ) ) );
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
size = 1;
|
||||
indices = (int*)BJAM_MALLOC(sizeof(int));
|
||||
indices = ( int * )BJAM_MALLOC( sizeof( int ) );
|
||||
*indices = 1;
|
||||
}
|
||||
|
||||
{
|
||||
/* Result is cached and intentionally never freed */
|
||||
regexp *re = regex_compile( list_front( pattern ) );
|
||||
regexp * re = regex_compile( list_front( pattern ) );
|
||||
|
||||
LISTITER iter = list_begin( l ), end = list_end( l );
|
||||
for( ; iter != end; iter = list_next( iter ) )
|
||||
LISTITER iter = list_begin( l );
|
||||
LISTITER const end = list_end( l );
|
||||
for ( ; iter != end; iter = list_next( iter ) )
|
||||
{
|
||||
if( regexec( re, object_str( list_item( iter ) ) ) )
|
||||
if ( regexec( re, object_str( list_item( iter ) ) ) )
|
||||
{
|
||||
int i = 0;
|
||||
for(; i < size; ++i)
|
||||
for ( ; i < size; ++i )
|
||||
{
|
||||
int index = indices[i];
|
||||
/* Skip empty submatches. Not sure it's right in all cases,
|
||||
but surely is right for the case for which this routine
|
||||
is optimized -- header scanning.
|
||||
*/
|
||||
if (re->startp[index] != re->endp[index])
|
||||
int index = indices[ i ];
|
||||
/* Skip empty submatches. Not sure it is right in all cases,
|
||||
* but surely is right for the case for which this routine
|
||||
* is optimized -- header scanning.
|
||||
*/
|
||||
if ( re->startp[ index ] != re->endp[ index ] )
|
||||
{
|
||||
string_append_range( buf, re->startp[index], re->endp[index] );
|
||||
result = list_push_back( result, object_new( buf->value ) );
|
||||
string_append_range( buf, re->startp[ index ],
|
||||
re->endp[ index ] );
|
||||
result = list_push_back( result, object_new( buf->value
|
||||
) );
|
||||
string_truncate( buf, 0 );
|
||||
}
|
||||
}
|
||||
@@ -84,15 +88,15 @@ LIST *regex_transform( FRAME *frame, int flags )
|
||||
string_free( buf );
|
||||
}
|
||||
|
||||
BJAM_FREE(indices);
|
||||
|
||||
BJAM_FREE( indices );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void init_regex()
|
||||
{
|
||||
{
|
||||
const char* args[] = { "list", "*", ":", "pattern", ":", "indices", "*", 0 };
|
||||
declare_native_rule("regex", "transform", args, regex_transform, 2);
|
||||
}
|
||||
char const * args[] = { "list", "*", ":", "pattern", ":", "indices", "*", 0
|
||||
};
|
||||
declare_native_rule( "regex", "transform", args, regex_transform, 2 );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user