From fa15331793bf50583f9dd072d5fd40fe36a5c479 Mon Sep 17 00:00:00 2001 From: Jean-Paul Chaput Date: Tue, 11 Aug 2020 14:46:31 +0200 Subject: [PATCH] Simpler allocation of regex in CRL::Environment. * Change: In CRL::Environment, regex_t are now pointers instead of values, this way the "in initialization" flag can be removed (maybe still too complicated). --- crlcore/src/ccore/Environment.cpp | 74 +++++++++++++++---------- crlcore/src/ccore/crlcore/Environment.h | 23 +++----- 2 files changed, 53 insertions(+), 44 deletions(-) diff --git a/crlcore/src/ccore/Environment.cpp b/crlcore/src/ccore/Environment.cpp index 00e46d17..bab54097 100644 --- a/crlcore/src/ccore/Environment.cpp +++ b/crlcore/src/ccore/Environment.cpp @@ -64,92 +64,110 @@ namespace CRL { , _OUT_LO ("vst") , _OUT_PH ("ap") , _CATALOG ("CATAL") - , _inConstructor (true) + , _POWER ("vdd") + , _GROUND ("vss") + , _CLOCK ("^ck$") + , _BLOCKAGE ("^blockage$") + , _pad ("^.*_px$") + , _LIBRARIES () + , _PowerRegex (new regex_t) + , _GroundRegex (new regex_t) + , _ClockRegex (new regex_t) + , _BlockageRegex (new regex_t) + , _padRegex (new regex_t) { - setPOWER ( "vdd" ); - setGROUND ( "vss" ); - setCLOCK ( "^ck$" ); - setBLOCKAGE ( "^obs$" ); - setPad ( "^.*_px$" ); + setPOWER ( "vdd" ); + setGROUND ( "vss" ); + setCLOCK ( "^ck$" ); + setBLOCKAGE( "^blockage$" ); + setPad ( "^.*_px$" ); - _LIBRARIES.append ( ".", "working" ); - - _inConstructor = false; + _LIBRARIES.append( ".", "working" ); } Environment::~Environment () { - regfree ( &_PowerRegex ); - regfree ( &_GroundRegex ); - regfree ( &_ClockRegex ); - regfree ( &_BlockageRegex ); - regfree ( &_padRegex ); + regfree( _PowerRegex ); + regfree( _GroundRegex ); + regfree( _ClockRegex ); + regfree( _BlockageRegex ); + regfree( _padRegex ); + delete _PowerRegex; + delete _GroundRegex; + delete _ClockRegex; + delete _BlockageRegex; + delete _padRegex; } bool Environment::isPOWER ( const char* name ) const { - return regexec ( &_PowerRegex, name, 0, NULL, 0 ) == 0; + if (not _PowerRegex) return false; + return regexec( _PowerRegex, name, 0, NULL, 0 ) == 0; } bool Environment::isGROUND ( const char* name ) const { - return regexec ( &_GroundRegex, name, 0, NULL, 0 ) == 0; + if (not _GroundRegex) return false; + return regexec ( _GroundRegex, name, 0, NULL, 0 ) == 0; } bool Environment::isCLOCK ( const char* name ) const { - return regexec ( &_ClockRegex, name, 0, NULL, 0 ) == 0; + if (not _ClockRegex) return false; + return regexec( _ClockRegex, name, 0, NULL, 0 ) == 0; } bool Environment::isBLOCKAGE ( const char* name ) const { - return regexec ( &_BlockageRegex, name, 0, NULL, 0 ) == 0; + if (not _BlockageRegex) return false; + return regexec ( _BlockageRegex, name, 0, NULL, 0 ) == 0; } bool Environment::isPad ( const char* name ) const { - return regexec ( &_padRegex, name, 0, NULL, 0 ) == 0; + if (not _padRegex) return false; + return regexec ( _padRegex, name, 0, NULL, 0 ) == 0; } void Environment::setPOWER ( const char* value ) { _POWER = value; - _setRegex ( &_PowerRegex , _POWER , "Power" ); + _setRegex ( _PowerRegex , _POWER , "Power" ); } void Environment::setGROUND ( const char* value ) { _GROUND = value; - _setRegex ( &_GroundRegex , _GROUND , "Ground" ); + _setRegex ( _GroundRegex , _GROUND , "Ground" ); } void Environment::setCLOCK ( const char* value ) { _CLOCK = value; - _setRegex ( &_ClockRegex , _CLOCK , "Clock" ); + _setRegex ( _ClockRegex , _CLOCK , "Clock" ); } void Environment::setBLOCKAGE ( const char* value ) { _BLOCKAGE = value; - _setRegex ( &_BlockageRegex , _BLOCKAGE , "Blockage" ); + _setRegex ( _BlockageRegex , _BLOCKAGE , "Blockage" ); } void Environment::setPad ( const char* value ) { _pad = value; - _setRegex ( &_padRegex , _pad , "Pad" ); + _setRegex ( _padRegex , _pad , "Pad" ); } @@ -192,15 +210,13 @@ namespace CRL { } - void Environment::_setRegex ( regex_t* regex, const string& pattern, const char* name ) + void Environment::_setRegex ( regex_t*& regex, const string& pattern, const char* name ) { char regexError[1024]; int regexCode; - if ( !_inConstructor ) regfree ( regex ); - - if ( ( regexCode = regcomp(regex,getString(pattern).c_str(),REG_EXTENDED|REG_NOSUB) ) ) { - regerror ( regexCode, regex, regexError, 1024 ); + if ( (regexCode = regcomp(regex,getString(pattern).c_str(),REG_EXTENDED|REG_NOSUB)) ) { + regerror( regexCode, regex, regexError, 1024 ); throw Error ( badRegex, name, regexError ); } } diff --git a/crlcore/src/ccore/crlcore/Environment.h b/crlcore/src/ccore/crlcore/Environment.h index 063315a9..64185f8b 100644 --- a/crlcore/src/ccore/crlcore/Environment.h +++ b/crlcore/src/ccore/crlcore/Environment.h @@ -14,9 +14,7 @@ // +-----------------------------------------------------------------+ -#ifndef CRL_ENVIRONMENT_H -#define CRL_ENVIRONMENT_H - +#pragma once #include #include #include "hurricane/Commons.h" @@ -92,26 +90,24 @@ namespace CRL { std::string _CORIOLIS_TOP; std::string _displayStyle; long _SCALE_X; - std::string _DISPLAY; std::string _IN_LO; std::string _IN_PH; std::string _OUT_LO; std::string _OUT_PH; + std::string _CATALOG; std::string _POWER; std::string _GROUND; std::string _CLOCK; std::string _BLOCKAGE; std::string _pad; - std::string _CATALOG; SearchPath _LIBRARIES; - regex_t _PowerRegex; - regex_t _GroundRegex; - regex_t _ClockRegex; - regex_t _BlockageRegex; - regex_t _padRegex; - bool _inConstructor; + regex_t* _PowerRegex; + regex_t* _GroundRegex; + regex_t* _ClockRegex; + regex_t* _BlockageRegex; + regex_t* _padRegex; private: - void _setRegex ( regex_t* regex, const std::string& pattern, const char* name ); + void _setRegex ( regex_t*& regex, const std::string& pattern, const char* name ); }; @@ -158,6 +154,3 @@ namespace CRL { INSPECTOR_P_SUPPORT(CRL::Environment); - - -#endif // CRL_ENVIRONMENT_H