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