From ea17d3262924f95a4fa721b3de6d7fe499bdcf14 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 5 Apr 2012 22:52:54 +0000 Subject: Added unique function and a workaround for non-matching inputs to rules passing the rule input filter. --- docs/build.7 | 4 ++++ share/autoinclude/general-rules.bld | 3 +++ src/functionplugger.cpp | 2 ++ src/functionunique.cpp | 47 +++++++++++++++++++++++++++++++++++++ src/functionunique.h | 16 +++++++++++++ support/vim/syntax/build.vim | 2 +- 6 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 src/functionunique.cpp create mode 100644 src/functionunique.h diff --git a/docs/build.7 b/docs/build.7 index b9099de..77b9f85 100644 --- a/docs/build.7 +++ b/docs/build.7 @@ -93,6 +93,10 @@ Takes a file handle as it's input, and takes an integer as it's parameter. The .B close() Takes a file handle as it's input, and no parameters. Closes the file indicated by the handle provided as input. While it is reccomended to close all files as soon as you are done with them, any files left open will be closed automatically and safely before build exists. +.TP +.B +unique() +At the moment only works on lists of strings. It will return the input string in the same order, with all duplicate entries removed. It will also remove any non-strings in the list at the moment. .P Here, lets list functions we wish we had... .SH ENVIRONMENT diff --git a/share/autoinclude/general-rules.bld b/share/autoinclude/general-rules.bld index cdc2d40..6c0df30 100644 --- a/share/autoinclude/general-rules.bld +++ b/share/autoinclude/general-rules.bld @@ -60,6 +60,7 @@ rule "exe" input "*.o"; profile "build" { + INPUT = [INPUT].unique().matches("*.o"); execute("${CXX} -o ${OUTPUT} ${INPUT} ${LDFLAGS}"); } } @@ -69,6 +70,7 @@ rule "so" input "*.o"; profile "build" { + INPUT = [INPUT].unique().matches("*.o"); execute("${CXX} -shared -o ${OUTPUT} ${INPUT} ${LDFLAGS}"); } } @@ -78,6 +80,7 @@ rule "lib" input "*.o"; profile "build" { + INPUT = [INPUT].unique().matches("*.o"); execute("${AR} cr ${OUTPUT} ${INPUT}"); } } diff --git a/src/functionplugger.cpp b/src/functionplugger.cpp index 8bd2edd..1f2bcf5 100644 --- a/src/functionplugger.cpp +++ b/src/functionplugger.cpp @@ -21,6 +21,7 @@ extern Bu::PluginInfo pluginFunctionOpen; extern Bu::PluginInfo pluginFunctionClose; extern Bu::PluginInfo pluginFunctionRead; extern Bu::PluginInfo pluginFunctionWrite; +extern Bu::PluginInfo pluginFunctionUnique; FunctionPlugger::FunctionPlugger() { @@ -42,6 +43,7 @@ FunctionPlugger::FunctionPlugger() registerBuiltinPlugin( &pluginFunctionClose ); registerBuiltinPlugin( &pluginFunctionRead ); registerBuiltinPlugin( &pluginFunctionWrite ); + registerBuiltinPlugin( &pluginFunctionUnique ); DIR *dir = opendir("/usr/lib/build"); if( !dir ) diff --git a/src/functionunique.cpp b/src/functionunique.cpp new file mode 100644 index 0000000..ca2461f --- /dev/null +++ b/src/functionunique.cpp @@ -0,0 +1,47 @@ +#include "functionunique.h" + +#include +#include +PluginInterface3( pluginFunctionUnique, unique, FunctionUnique, Function, + "Mike Buland", 0, 1 ); + +FunctionUnique::FunctionUnique() +{ +} + +FunctionUnique::~FunctionUnique() +{ +} + +Bu::String FunctionUnique::getName() const +{ + return "unique"; +} + +Variable FunctionUnique::call( Variable &input, VarList lParams ) +{ + if( lParams.getSize() > 0 ) + throw Bu::ExceptionBase("Unique does not take any parameters."); + if( input.getType() != Variable::typeList ) + throw Bu::ExceptionBase("unique does not work on non-list types."); + + Bu::Hash hHas; + + Variable vOut( Variable::typeList ); + for( VarList::iterator i = input.begin(); i; i++ ) + { + if( (*i).getType() != Variable::typeString ) + continue; + + Bu::String s = (*i).getString(); + + if( hHas.has( s ) ) + continue; + + hHas.insert( s, true ); + vOut.append( *i ); + } + + return vOut; +} + diff --git a/src/functionunique.h b/src/functionunique.h new file mode 100644 index 0000000..6bc4225 --- /dev/null +++ b/src/functionunique.h @@ -0,0 +1,16 @@ +#ifndef FUNCTION_UNIQUE_H +#define FUNCTION_UNIQUE_H + +#include "function.h" + +class FunctionUnique : public Function +{ +public: + FunctionUnique(); + virtual ~FunctionUnique(); + + virtual Bu::String getName() const; + virtual Variable call( Variable &input, VarList lParams ); +}; + +#endif diff --git a/support/vim/syntax/build.vim b/support/vim/syntax/build.vim index 721cfd4..04d1f90 100644 --- a/support/vim/syntax/build.vim +++ b/support/vim/syntax/build.vim @@ -19,7 +19,7 @@ syn keyword Statement include set unset function target input condition requir syn keyword Todo TODO FIXME XXX syn keyword Type int string bool float version syn keyword Constant null true false file never always important normal hidden autogenerated filetime -syn keyword Builtins files dirs matches replace regex execute unlink exists getMakeDeps toString targets fileName dirName +syn keyword Builtins files dirs matches replace regex execute unlink exists getMakeDeps toString targets fileName dirName unique syn match TargetProcess /[a-zA-Z_][a-zA-Z0-9_]*:/he=e-1 -- cgit v1.2.3