@@ -220,6 +220,7 @@ void Token::deleteThis()
220220 _variable = _next->_variable ;
221221 _type = _next->_type ;
222222 if (_next->_originalName ) {
223+ delete _originalName;
223224 _originalName = _next->_originalName ;
224225 _next->_originalName = nullptr ;
225226 }
@@ -241,6 +242,7 @@ void Token::deleteThis()
241242 _variable = _previous->_variable ;
242243 _type = _previous->_type ;
243244 if (_previous->_originalName ) {
245+ delete _originalName;
244246 _originalName = _previous->_originalName ;
245247 _previous->_originalName = nullptr ;
246248 }
@@ -296,13 +298,13 @@ void Token::replace(Token *replaceThis, Token *start, Token *end)
296298const Token *Token::tokAt (int index) const
297299{
298300 const Token *tok = this ;
299- int num = std::abs (index);
300- while (num > 0 && tok) {
301- if ( index > 0 )
302- tok = tok-> next ();
303- else
304- tok = tok->previous ();
305- --num ;
301+ while (index > 0 && tok) {
302+ tok = tok-> next ();
303+ -- index;
304+ }
305+ while (index < 0 && tok) {
306+ tok = tok->previous ();
307+ ++index ;
306308 }
307309 return tok;
308310}
@@ -867,44 +869,6 @@ const Token *Token::findmatch(const Token *startTok, const char pattern[], const
867869 return nullptr ;
868870}
869871
870- void Token::insertToken (const std::string &tokenStr, bool prepend)
871- {
872- // TODO: Find a solution for the first token on the list
873- if (prepend && !this ->previous ())
874- return ;
875- Token *newToken;
876- if (_str.empty ())
877- newToken = this ;
878- else
879- newToken = new Token (tokensBack);
880- newToken->str (tokenStr);
881- newToken->_linenr = _linenr;
882- newToken->_fileIndex = _fileIndex;
883- newToken->_progressValue = _progressValue;
884-
885- if (newToken != this ) {
886- if (prepend) {
887- /* if (this->previous())*/ {
888- newToken->previous (this ->previous ());
889- newToken->previous ()->next (newToken);
890- } /* else if (tokensFront?) {
891- *tokensFront? = newToken;
892- }*/
893- this ->previous (newToken);
894- newToken->next (this );
895- } else {
896- if (this ->next ()) {
897- newToken->next (this ->next ());
898- newToken->next ()->previous (newToken);
899- } else if (tokensBack) {
900- *tokensBack = newToken;
901- }
902- this ->next (newToken);
903- newToken->previous (this );
904- }
905- }
906- }
907-
908872void Token::insertToken (const std::string &tokenStr, const std::string &originalNameStr, bool prepend)
909873{
910874 // TODO: Find a solution for the first token on the list
0 commit comments