diff --git a/lib/token.cpp b/lib/token.cpp index 12ab3f97b..3ed697c31 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -39,7 +39,6 @@ Token::Token(Token **t) : _link(0), _scope(0), _function(0), // Initialize whole union - _str(""), _varId(0), _fileIndex(0), _linenr(0), @@ -48,13 +47,14 @@ Token::Token(Token **t) : _flags(0), _astOperand1(nullptr), _astOperand2(nullptr), - _astParent(nullptr) + _astParent(nullptr), + _originalName(nullptr) { } Token::~Token() { - + delete _originalName; } void Token::update_property_info() @@ -174,7 +174,10 @@ void Token::deleteThis() _scope = _next->_scope; _function = _next->_function; _variable = _next->_variable; - _originalName = _next->_originalName; + if (_next->_originalName) { + _originalName = _next->_originalName; + _next->_originalName = nullptr; + } values = _next->values; if (_link) _link->link(this); @@ -191,7 +194,10 @@ void Token::deleteThis() _scope = _previous->_scope; _function = _previous->_function; _variable = _previous->_variable; - _originalName = _previous->_originalName; + if (_previous->_originalName) { + _originalName = _previous->_originalName; + _previous->_originalName = nullptr; + } values = _previous->values; if (_link) _link->link(this); @@ -931,7 +937,8 @@ void Token::insertToken(const std::string &tokenStr, const std::string &original else newToken = new Token(tokensBack); newToken->str(tokenStr); - newToken->_originalName = originalNameStr; + if (!originalNameStr.empty()) + newToken->originalName(originalNameStr); newToken->_linenr = _linenr; newToken->_fileIndex = _fileIndex; newToken->_progressValue = _progressValue; diff --git a/lib/token.h b/lib/token.h index 45666725a..5bb7a2d3d 100644 --- a/lib/token.h +++ b/lib/token.h @@ -620,7 +620,7 @@ public: * @return the original name. */ const std::string & originalName() const { - return _originalName; + return _originalName ? *_originalName : emptyString; } /** @@ -628,7 +628,10 @@ public: */ template void originalName(T&& name) { - _originalName = name; + if (!_originalName) + _originalName = new std::string(name); + else + *_originalName = name; } /** Values of token */ @@ -687,6 +690,7 @@ private: */ static int firstWordLen(const char *str); + std::string _str; Token *_next; Token *_previous; @@ -699,7 +703,6 @@ private: const Variable *_variable; }; - std::string _str; unsigned int _varId; unsigned int _fileIndex; unsigned int _linenr; @@ -761,7 +764,7 @@ private: Token *_astParent; // original name like size_t - std::string _originalName; + std::string* _originalName; public: void astOperand1(Token *tok); diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 668566cb1..2a4357724 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -165,7 +165,8 @@ void TokenList::addtoken(const Token * tok, const unsigned int lineno, const uns _front = new Token(&_back); _back = _front; _back->str(tok->str()); - _back->originalName(tok->originalName()); + if (!tok->originalName().empty()) + _back->originalName(tok->originalName()); } _back->linenr(lineno);