Token::createMutualLinks(): introduce and use.
No functional change.
This commit is contained in:
parent
368bacff9a
commit
7ac6162947
|
@ -17,6 +17,7 @@
|
|||
*/
|
||||
|
||||
#include "token.h"
|
||||
#include <cassert>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
@ -610,6 +611,16 @@ Token *Token::link() const
|
|||
return _link;
|
||||
}
|
||||
|
||||
void Token::createMutualLinks(Token *begin, Token *end)
|
||||
{
|
||||
assert(begin != NULL);
|
||||
assert(end != NULL);
|
||||
assert(begin != end);
|
||||
|
||||
begin->link(end);
|
||||
end->link(begin);
|
||||
}
|
||||
|
||||
void Token::printOut(const char *title) const
|
||||
{
|
||||
std::cout << stringifyList(true, title) << std::endl;
|
||||
|
|
|
@ -213,6 +213,11 @@ public:
|
|||
*/
|
||||
Token *link() const;
|
||||
|
||||
/**
|
||||
* Links two elements against each other.
|
||||
**/
|
||||
static void createMutualLinks(Token *begin, Token *end);
|
||||
|
||||
private:
|
||||
void next(Token *next);
|
||||
void previous(Token *previous);
|
||||
|
|
|
@ -1097,8 +1097,7 @@ bool Tokenizer::createLinks()
|
|||
return false;
|
||||
}
|
||||
|
||||
token->link(links.back());
|
||||
links.back()->link(token);
|
||||
Token::createMutualLinks(links.back(), token);
|
||||
links.pop_back();
|
||||
}
|
||||
else if (token->str() == "(")
|
||||
|
@ -1114,8 +1113,7 @@ bool Tokenizer::createLinks()
|
|||
return false;
|
||||
}
|
||||
|
||||
token->link(links2.back());
|
||||
links2.back()->link(token);
|
||||
Token::createMutualLinks(links2.back(), token);
|
||||
links2.pop_back();
|
||||
}
|
||||
}
|
||||
|
@ -1338,8 +1336,7 @@ void Tokenizer::simplifyTokenList()
|
|||
// Ok, we should be clean. Add ) after tempToken
|
||||
tok->insertToken("(");
|
||||
tempToken->insertToken(")");
|
||||
tok->next()->link(tempToken->next());
|
||||
tempToken->next()->link(tok->next());
|
||||
Token::createMutualLinks(tok->next(), tempToken->next());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1891,11 +1888,7 @@ bool Tokenizer::simplifyDoWhileAddBraces()
|
|||
// insert "}" before "while"
|
||||
tok2->previous()->insertToken("}");
|
||||
|
||||
// allow link() works
|
||||
tok1 = tok1->next();
|
||||
tok2 = tok2->previous();
|
||||
tok1->link(tok2);
|
||||
tok2->link(tok1);
|
||||
Token::createMutualLinks(tok1->next(), tok2->previous());
|
||||
|
||||
ret = true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue