diff options
Diffstat (limited to 'src/ExternalLexer.cxx')
| -rw-r--r-- | src/ExternalLexer.cxx | 91 | 
1 files changed, 18 insertions, 73 deletions
| diff --git a/src/ExternalLexer.cxx b/src/ExternalLexer.cxx index 8710e0cdd..4a2811c18 100644 --- a/src/ExternalLexer.cxx +++ b/src/ExternalLexer.cxx @@ -11,6 +11,8 @@  #include <stdexcept>  #include <string> +#include <vector> +#include <memory>  #include "Platform.h" @@ -26,7 +28,7 @@  using namespace Scintilla;  #endif -LexerManager *LexerManager::theInstance = NULL; +std::unique_ptr<LexerManager> LexerManager::theInstance;  //------------------------------------------  // @@ -45,22 +47,15 @@ void ExternalLexerModule::SetExternal(GetLexerFactoryFunction fFactory, int inde  //  //------------------------------------------ -LexerLibrary::LexerLibrary(const char *ModuleName) { -	// Initialise some members... -	first = NULL; -	last = NULL; - +LexerLibrary::LexerLibrary(const char *moduleName_) {  	// Load the DLL -	lib = DynamicLibrary::Load(ModuleName); +	lib.reset(DynamicLibrary::Load(moduleName_));  	if (lib->IsValid()) { -		m_sModuleName = ModuleName; +		moduleName = moduleName_;  		//Cannot use reinterpret_cast because: ANSI C++ forbids casting between pointers to functions and objects  		GetLexerCountFn GetLexerCount = (GetLexerCountFn)(sptr_t)lib->FindFunction("GetLexerCount");  		if (GetLexerCount) { -			ExternalLexerModule *lex; -			LexerMinder *lm; -  			// Find functions in the DLL  			GetLexerNameFn GetLexerName = (GetLexerNameFn)(sptr_t)lib->FindFunction("GetLexerName");  			GetLexerFactoryFunction fnFactory = (GetLexerFactoryFunction)(sptr_t)lib->FindFunction("GetLexerFactory"); @@ -71,20 +66,11 @@ LexerLibrary::LexerLibrary(const char *ModuleName) {  				// Assign a buffer for the lexer name.  				char lexname[100] = "";  				GetLexerName(i, lexname, sizeof(lexname)); -				lex = new ExternalLexerModule(SCLEX_AUTOMATIC, NULL, lexname, NULL); +				ExternalLexerModule *lex = new ExternalLexerModule(SCLEX_AUTOMATIC, NULL, lexname, NULL);  				Catalogue::AddLexerModule(lex); -				// Create a LexerMinder so we don't leak the ExternalLexerModule... -				lm = new LexerMinder; -				lm->self = lex; -				lm->next = NULL; -				if (first != NULL) { -					last->next = lm; -					last = lm; -				} else { -					first = lm; -					last = lm; -				} +				// Remember ExternalLexerModule so we don't leak it +				modules.push_back(std::unique_ptr<ExternalLexerModule>(lex));  				// The external lexer needs to know how to call into its DLL to  				// do its lexing and folding, we tell it here. @@ -92,27 +78,9 @@ LexerLibrary::LexerLibrary(const char *ModuleName) {  			}  		}  	} -	next = NULL;  }  LexerLibrary::~LexerLibrary() { -	Release(); -	delete lib; -} - -void LexerLibrary::Release() { -	LexerMinder *lm; -	LexerMinder *lmNext; -	lm = first; -	while (NULL != lm) { -		lmNext = lm->next; -		delete lm->self; -		delete lm; -		lm = lmNext; -	} - -	first = NULL; -	last = NULL;  }  //------------------------------------------ @@ -124,20 +92,17 @@ void LexerLibrary::Release() {  /// Return the single LexerManager instance...  LexerManager *LexerManager::GetInstance() {  	if (!theInstance) -		theInstance = new LexerManager; -	return theInstance; +		theInstance.reset(new LexerManager); +	return theInstance.get();  }  /// Delete any LexerManager instance...  void LexerManager::DeleteInstance() { -	delete theInstance; -	theInstance = NULL; +	theInstance.reset();  }  /// protected constructor - this is a singleton...  LexerManager::LexerManager() { -	first = NULL; -	last = NULL;  }  LexerManager::~LexerManager() { @@ -145,41 +110,21 @@ LexerManager::~LexerManager() {  }  void LexerManager::Load(const char *path) { -	LoadLexerLibrary(path); -} - -void LexerManager::LoadLexerLibrary(const char *module) { -	for (LexerLibrary *ll = first; ll; ll= ll->next) { -		if (strcmp(ll->m_sModuleName.c_str(), module) == 0) +	for (const std::unique_ptr<LexerLibrary> &ll : libraries) { +		if (ll->moduleName == path)  			return;  	} -	LexerLibrary *lib = new LexerLibrary(module); -	if (NULL != first) { -		last->next = lib; -		last = lib; -	} else { -		first = lib; -		last = lib; -	} +	LexerLibrary *lib = new LexerLibrary(path); +	libraries.push_back(std::unique_ptr<LexerLibrary>(lib));  }  void LexerManager::Clear() { -	if (NULL != first) { -		LexerLibrary *cur = first; -		LexerLibrary *next; -		while (cur) { -			next = cur->next; -			delete cur; -			cur = next; -		} -		first = NULL; -		last = NULL; -	} +	libraries.clear();  }  //------------------------------------------  // -// LexerManager +// LMMinder	-- trigger to clean up at exit.  //  //------------------------------------------ | 
