From 10324ce772d45a59be9e25a1fdb30aa55357d0d1 Mon Sep 17 00:00:00 2001 From: Royce Mitchell III Date: Sun, 9 Jan 2005 01:58:53 +0000 Subject: [PATCH] replaced Backend Factory's vector with a map. added a map of the MingwModuleHandlers that's created at startup time svn path=/branches/xmlbuildsystem/; revision=12900 --- reactos/tools/rbuild/backend/backend.cpp | 22 +++--- reactos/tools/rbuild/backend/backend.h | 3 +- reactos/tools/rbuild/backend/mingw/mingw.cpp | 22 +----- reactos/tools/rbuild/backend/mingw/mingw.h | 21 ------ .../rbuild/backend/mingw/modulehandler.cpp | 74 ++++++++++++------- .../rbuild/backend/mingw/modulehandler.h | 21 +++--- reactos/tools/rbuild/exception.cpp | 6 ++ reactos/tools/rbuild/exception.h | 6 ++ reactos/tools/rbuild/pch.h | 1 + 9 files changed, 86 insertions(+), 90 deletions(-) diff --git a/reactos/tools/rbuild/backend/backend.cpp b/reactos/tools/rbuild/backend/backend.cpp index 3ebd389feba..566a18fe248 100644 --- a/reactos/tools/rbuild/backend/backend.cpp +++ b/reactos/tools/rbuild/backend/backend.cpp @@ -6,15 +6,17 @@ using std::string; using std::vector; +using std::map; -vector* Backend::Factory::factories = NULL; +map* Backend::Factory::factories = NULL; Backend::Factory::Factory ( const std::string& name_ ) - : name(name_) { + string name(name_); + strlwr ( &name[0] ); if ( !factories ) - factories = new vector; - factories->push_back ( this ); + factories = new map; + (*factories)[name.c_str()] = this; } /*static*/ Backend* @@ -24,15 +26,13 @@ Backend::Factory::Create ( const std::string& name, Project& project ) strlwr ( &sname[0] ); if ( !factories || !factories->size() ) throw Exception ( "internal tool error: no registered factories" ); - vector& fact = *factories; - for ( size_t i = 0; i < fact.size(); i++ ) + Backend::Factory* f = (*factories)[sname.c_str()]; + if ( !f ) { - //char* p = *fact[i]; - if ( sname == fact[i]->name ) - return (*fact[i]) ( project ); + throw UnknownBackendException ( sname ); + return NULL; } - throw UnknownBackendException ( sname ); - return NULL; + return (*f) ( project ); } Backend::Backend ( Project& project ) diff --git a/reactos/tools/rbuild/backend/backend.h b/reactos/tools/rbuild/backend/backend.h index 6cbe6f05a26..1b4fe9fa88e 100644 --- a/reactos/tools/rbuild/backend/backend.h +++ b/reactos/tools/rbuild/backend/backend.h @@ -12,8 +12,7 @@ class Backend public: class Factory { - static std::vector* factories; - std::string name; + static std::map* factories; protected: diff --git a/reactos/tools/rbuild/backend/mingw/mingw.cpp b/reactos/tools/rbuild/backend/mingw/mingw.cpp index c4777680c97..5ae9ea1d0d5 100644 --- a/reactos/tools/rbuild/backend/mingw/mingw.cpp +++ b/reactos/tools/rbuild/backend/mingw/mingw.cpp @@ -43,6 +43,7 @@ MingwBackend::CreateMakefile () fMakefile = fopen ( ProjectNode.makefile.c_str (), "w" ); if ( !fMakefile ) throw AccessDeniedException ( ProjectNode.makefile ); + MingwModuleHandler::SetMakefile ( fMakefile ); } void @@ -89,25 +90,8 @@ MingwBackend::GenerateAllTarget () void MingwBackend::ProcessModule ( Module& module ) { - MingwModuleHandlerList moduleHandlers; - GetModuleHandlers ( moduleHandlers ); - for (size_t i = 0; i < moduleHandlers.size (); i++) - { - MingwModuleHandler& moduleHandler = *moduleHandlers[i]; - if (moduleHandler.CanHandleModule ( module ) ) - { - moduleHandler.Process ( module ); - return; - } - } -} - -void -MingwBackend::GetModuleHandlers ( MingwModuleHandlerList& moduleHandlers ) const -{ - moduleHandlers.push_back ( new MingwBuildToolModuleHandler ( fMakefile ) ); - moduleHandlers.push_back ( new MingwKernelModuleHandler ( fMakefile ) ); - moduleHandlers.push_back ( new MingwStaticLibraryModuleHandler ( fMakefile ) ); + MingwModuleHandler* h = MingwModuleHandler::LookupHandler ( module.name ); + h->Process ( module ); } string diff --git a/reactos/tools/rbuild/backend/mingw/mingw.h b/reactos/tools/rbuild/backend/mingw/mingw.h index 28a3acf9bfc..e79e529b02f 100644 --- a/reactos/tools/rbuild/backend/mingw/mingw.h +++ b/reactos/tools/rbuild/backend/mingw/mingw.h @@ -4,26 +4,6 @@ #include "../backend.h" #include "modulehandler.h" -class MingwModuleHandlerList : public std::vector -{ -public: - MingwModuleHandlerList() - { - } - ~MingwModuleHandlerList() - { - for ( size_t i = 0; i < size(); i++ ) - { - delete (*this)[i]; - } - } -private: - // disable copy semantics - MingwModuleHandlerList ( const MingwModuleHandlerList& ); - MingwModuleHandlerList& operator = ( const MingwModuleHandlerList& ); -}; - - class MingwBackend : public Backend { public: @@ -31,7 +11,6 @@ public: virtual void Process (); private: void ProcessModule ( Module& module ); - void GetModuleHandlers ( MingwModuleHandlerList& moduleHandlers ) const; void CreateMakefile (); void CloseMakefile (); void GenerateHeader (); diff --git a/reactos/tools/rbuild/backend/mingw/modulehandler.cpp b/reactos/tools/rbuild/backend/mingw/modulehandler.cpp index 95638154ebb..02e25ad57e0 100644 --- a/reactos/tools/rbuild/backend/mingw/modulehandler.cpp +++ b/reactos/tools/rbuild/backend/mingw/modulehandler.cpp @@ -8,10 +8,43 @@ using std::string; using std::vector; +using std::map; -MingwModuleHandler::MingwModuleHandler ( FILE* fMakefile ) - : fMakefile ( fMakefile ) +map* +MingwModuleHandler::handler_map = NULL; + +FILE* +MingwModuleHandler::fMakefile = NULL; + +MingwModuleHandler::MingwModuleHandler ( const char* moduletype_ ) +{ + string moduletype ( moduletype_ ); + strlwr ( &moduletype[0] ); + if ( !handler_map ) + handler_map = new map; + (*handler_map)[moduletype.c_str()] = this; +} + +/*static*/ void +MingwModuleHandler::SetMakefile ( FILE* f ) { + fMakefile = f; +} + +/*static*/ MingwModuleHandler* +MingwModuleHandler::LookupHandler ( const string& moduletype_ ) +{ + string moduletype ( moduletype_ ); + strlwr ( &moduletype[0] ); + if ( !handler_map ) + throw Exception ( "internal tool error: no registered module handlers" ); + MingwModuleHandler* h = (*handler_map)[moduletype.c_str()]; + if ( !h ) + { + throw UnknownModuleTypeException ( moduletype ); + return NULL; + } + return h; } string @@ -352,7 +385,7 @@ MingwModuleHandler::GenerateInvocations ( const Module& module ) const string invokeTarget = module.GetInvocationTarget ( i ); fprintf ( fMakefile, "%s: %s\n\n", - invoke.GetTargets ().c_str (), + invoke.GetTargets ().c_str (), invokeTarget.c_str () ); fprintf ( fMakefile, "%s: %s\n", @@ -398,22 +431,17 @@ MingwModuleHandler::GeneratePreconditionDependencies ( const Module& module ) co sourceFilenames.c_str (), preconditionDependenciesName.c_str ()); fprintf ( fMakefile, - ".PNONY: %s\n\n", + ".PHONY: %s\n\n", preconditionDependenciesName.c_str () ); } +static MingwBuildToolModuleHandler buildtool_handler; -MingwBuildToolModuleHandler::MingwBuildToolModuleHandler ( FILE* fMakefile ) - : MingwModuleHandler ( fMakefile ) +MingwBuildToolModuleHandler::MingwBuildToolModuleHandler() + : MingwModuleHandler ( "buildtool" ) { } -bool -MingwBuildToolModuleHandler::CanHandleModule ( const Module& module ) const -{ - return module.type == BuildTool; -} - void MingwBuildToolModuleHandler::Process ( const Module& module ) { @@ -438,18 +466,13 @@ MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ( const Module& modul GenerateObjectFileTargetsHost ( module ); } +static MingwKernelModuleHandler kernelmodule_handler; -MingwKernelModuleHandler::MingwKernelModuleHandler ( FILE* fMakefile ) - : MingwModuleHandler ( fMakefile ) +MingwKernelModuleHandler::MingwKernelModuleHandler () + : MingwModuleHandler ( "kernelmodedll" ) { } -bool -MingwKernelModuleHandler::CanHandleModule ( const Module& module ) const -{ - return module.type == KernelModeDLL; -} - void MingwKernelModuleHandler::Process ( const Module& module ) { @@ -505,16 +528,11 @@ MingwKernelModuleHandler::GenerateKernelModuleTarget ( const Module& module ) GenerateObjectFileTargetsTarget ( module ); } +static MingwStaticLibraryModuleHandler staticlibrary_handler; -MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler ( FILE* fMakefile ) - : MingwModuleHandler ( fMakefile ) -{ -} - -bool -MingwStaticLibraryModuleHandler::CanHandleModule ( const Module& module ) const +MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler () + : MingwModuleHandler ( "staticlibrary" ) { - return module.type == StaticLibrary; } void diff --git a/reactos/tools/rbuild/backend/mingw/modulehandler.h b/reactos/tools/rbuild/backend/mingw/modulehandler.h index 2f3266c5b1e..4304a731a85 100644 --- a/reactos/tools/rbuild/backend/mingw/modulehandler.h +++ b/reactos/tools/rbuild/backend/mingw/modulehandler.h @@ -6,9 +6,15 @@ class MingwModuleHandler { public: - MingwModuleHandler ( FILE* fMakefile ); - virtual bool CanHandleModule ( const Module& module ) const = 0; + static std::map* handler_map; + + MingwModuleHandler ( const char* moduletype_ ); + virtual ~MingwModuleHandler() {} + + static void SetMakefile ( FILE* f ); + static MingwModuleHandler* LookupHandler ( const std::string& moduletype_ ); virtual void Process ( const Module& module ) = 0; + protected: std::string MingwModuleHandler::GetWorkingDirectory () const; std::string ReplaceExtension ( const std::string& filename, @@ -29,7 +35,7 @@ protected: std::string GetInvocationParameters ( const Invoke& invoke ) const; void GenerateInvocations ( const Module& module ) const; void GeneratePreconditionDependencies ( const Module& module ) const; - FILE* fMakefile; + static FILE* fMakefile; private: std::string ConcatenatePaths ( const std::string& path1, const std::string& path2 ) const; @@ -49,8 +55,7 @@ private: class MingwBuildToolModuleHandler : public MingwModuleHandler { public: - MingwBuildToolModuleHandler ( FILE* fMakefile ); - virtual bool CanHandleModule ( const Module& module ) const; + MingwBuildToolModuleHandler (); virtual void Process ( const Module& module ); private: void GenerateBuildToolModuleTarget ( const Module& module ); @@ -60,8 +65,7 @@ private: class MingwKernelModuleHandler : public MingwModuleHandler { public: - MingwKernelModuleHandler ( FILE* fMakefile ); - virtual bool CanHandleModule ( const Module& module ) const; + MingwKernelModuleHandler (); virtual void Process ( const Module& module ); private: void GenerateKernelModuleTarget ( const Module& module ); @@ -71,8 +75,7 @@ private: class MingwStaticLibraryModuleHandler : public MingwModuleHandler { public: - MingwStaticLibraryModuleHandler ( FILE* fMakefile ); - virtual bool CanHandleModule ( const Module& module ) const; + MingwStaticLibraryModuleHandler (); virtual void Process ( const Module& module ); private: void GenerateStaticLibraryModuleTarget ( const Module& module ); diff --git a/reactos/tools/rbuild/exception.cpp b/reactos/tools/rbuild/exception.cpp index f3b3d5bc586..798773aacf0 100644 --- a/reactos/tools/rbuild/exception.cpp +++ b/reactos/tools/rbuild/exception.cpp @@ -122,3 +122,9 @@ UnknownBackendException::UnknownBackendException ( const string& name ) name.c_str() ) { } + +UnknownModuleTypeException::UnknownModuleTypeException ( const string& moduletype ) + : Exception ( "module type requested: '%s'", + moduletype.c_str() ) +{ +} diff --git a/reactos/tools/rbuild/exception.h b/reactos/tools/rbuild/exception.h index 50a95100762..c3c84236415 100644 --- a/reactos/tools/rbuild/exception.h +++ b/reactos/tools/rbuild/exception.h @@ -92,4 +92,10 @@ public: UnknownBackendException ( const std::string& name ); }; +class UnknownModuleTypeException : public Exception +{ +public: + UnknownModuleTypeException ( const std::string& moduletype ); +}; + #endif /* __EXCEPTION_H */ diff --git a/reactos/tools/rbuild/pch.h b/reactos/tools/rbuild/pch.h index 1274c0687a0..c0881b7a3fb 100644 --- a/reactos/tools/rbuild/pch.h +++ b/reactos/tools/rbuild/pch.h @@ -9,6 +9,7 @@ #include #include +#include #include -- 2.17.1