rename _astOperand1, _astOperand2, _astParent

This commit is contained in:
Daniel Marjamäki 2018-06-16 16:18:50 +02:00
parent 435aa70c3d
commit 26d58ddbb9
2 changed files with 39 additions and 39 deletions

View File

@ -50,9 +50,9 @@ Token::Token(TokensFrontBack *tokensFrontBack) :
_tokType(eNone), _tokType(eNone),
mFlags(0), mFlags(0),
_bits(0), _bits(0),
_astOperand1(nullptr), mAstOperand1(nullptr),
_astOperand2(nullptr), mAstOperand2(nullptr),
_astParent(nullptr), mAstParent(nullptr),
_originalName(nullptr), _originalName(nullptr),
_valuetype(nullptr), _valuetype(nullptr),
_values(nullptr) _values(nullptr)
@ -1101,37 +1101,37 @@ std::string Token::stringifyList(bool varid) const
void Token::astOperand1(Token *tok) void Token::astOperand1(Token *tok)
{ {
if (_astOperand1) if (mAstOperand1)
_astOperand1->_astParent = nullptr; mAstOperand1->mAstParent = nullptr;
// goto parent operator // goto parent operator
if (tok) { if (tok) {
std::set<Token*> visitedParents; std::set<Token*> visitedParents;
while (tok->_astParent) { while (tok->mAstParent) {
if (!visitedParents.insert(tok->_astParent).second) // #6838/#6726/#8352 avoid hang on garbage code if (!visitedParents.insert(tok->mAstParent).second) // #6838/#6726/#8352 avoid hang on garbage code
throw InternalError(this, "Internal error. Token::astOperand1() cyclic dependency."); throw InternalError(this, "Internal error. Token::astOperand1() cyclic dependency.");
tok = tok->_astParent; tok = tok->mAstParent;
} }
tok->_astParent = this; tok->mAstParent = this;
} }
_astOperand1 = tok; mAstOperand1 = tok;
} }
void Token::astOperand2(Token *tok) void Token::astOperand2(Token *tok)
{ {
if (_astOperand2) if (mAstOperand2)
_astOperand2->_astParent = nullptr; mAstOperand2->mAstParent = nullptr;
// goto parent operator // goto parent operator
if (tok) { if (tok) {
std::set<Token*> visitedParents; std::set<Token*> visitedParents;
while (tok->_astParent) { while (tok->mAstParent) {
//std::cout << tok << " -> " << tok->_astParent ; //std::cout << tok << " -> " << tok->mAstParent ;
if (!visitedParents.insert(tok->_astParent).second) // #6838/#6726 avoid hang on garbage code if (!visitedParents.insert(tok->mAstParent).second) // #6838/#6726 avoid hang on garbage code
throw InternalError(this, "Internal error. Token::astOperand2() cyclic dependency."); throw InternalError(this, "Internal error. Token::astOperand2() cyclic dependency.");
tok = tok->_astParent; tok = tok->mAstParent;
} }
tok->_astParent = this; tok->mAstParent = this;
} }
_astOperand2 = tok; mAstOperand2 = tok;
} }
bool Token::isCalculation() const bool Token::isCalculation() const
@ -1179,9 +1179,9 @@ bool Token::isUnaryPreOp() const
const Token *tokbefore = mPrevious; const Token *tokbefore = mPrevious;
const Token *tokafter = mNext; const Token *tokafter = mNext;
for (int distance = 1; distance < 10 && tokbefore; distance++) { for (int distance = 1; distance < 10 && tokbefore; distance++) {
if (tokbefore == _astOperand1) if (tokbefore == mAstOperand1)
return false; return false;
if (tokafter == _astOperand1) if (tokafter == mAstOperand1)
return true; return true;
tokbefore = tokbefore->mPrevious; tokbefore = tokbefore->mPrevious;
tokafter = tokafter->mPrevious; tokafter = tokafter->mPrevious;
@ -1298,7 +1298,7 @@ void Token::printAst(bool verbose, bool xml, std::ostream &out) const
{ {
std::set<const Token *> printed; std::set<const Token *> printed;
for (const Token *tok = this; tok; tok = tok->next()) { for (const Token *tok = this; tok; tok = tok->next()) {
if (!tok->_astParent && tok->_astOperand1) { if (!tok->mAstParent && tok->mAstOperand1) {
if (printed.empty() && !xml) if (printed.empty() && !xml)
out << "\n\n##AST" << std::endl; out << "\n\n##AST" << std::endl;
else if (printed.find(tok) != printed.end()) else if (printed.find(tok) != printed.end())
@ -1338,17 +1338,17 @@ std::string Token::astStringVerbose(const unsigned int indent1, const unsigned i
ret += " \'" + _valuetype->str() + '\''; ret += " \'" + _valuetype->str() + '\'';
ret += '\n'; ret += '\n';
if (_astOperand1) { if (mAstOperand1) {
unsigned int i1 = indent1, i2 = indent2 + 2; unsigned int i1 = indent1, i2 = indent2 + 2;
if (indent1==indent2 && !_astOperand2) if (indent1==indent2 && !mAstOperand2)
i1 += 2; i1 += 2;
ret += indent(indent1,indent2) + (_astOperand2 ? "|-" : "`-") + _astOperand1->astStringVerbose(i1,i2); ret += indent(indent1,indent2) + (mAstOperand2 ? "|-" : "`-") + mAstOperand1->astStringVerbose(i1,i2);
} }
if (_astOperand2) { if (mAstOperand2) {
unsigned int i1 = indent1, i2 = indent2 + 2; unsigned int i1 = indent1, i2 = indent2 + 2;
if (indent1==indent2) if (indent1==indent2)
i1 += 2; i1 += 2;
ret += indent(indent1,indent2) + "`-" + _astOperand2->astStringVerbose(i1,i2); ret += indent(indent1,indent2) + "`-" + mAstOperand2->astStringVerbose(i1,i2);
} }
return ret; return ret;
} }

View File

@ -989,9 +989,9 @@ private:
unsigned char _bits; unsigned char _bits;
// AST.. // AST..
Token *_astOperand1; Token *mAstOperand1;
Token *_astOperand2; Token *mAstOperand2;
Token *_astParent; Token *mAstParent;
// original name like size_t // original name like size_t
std::string* _originalName; std::string* _originalName;
@ -1008,18 +1008,18 @@ public:
void astOperand2(Token *tok); void astOperand2(Token *tok);
const Token * astOperand1() const { const Token * astOperand1() const {
return _astOperand1; return mAstOperand1;
} }
const Token * astOperand2() const { const Token * astOperand2() const {
return _astOperand2; return mAstOperand2;
} }
const Token * astParent() const { const Token * astParent() const {
return _astParent; return mAstParent;
} }
const Token *astTop() const { const Token *astTop() const {
const Token *ret = this; const Token *ret = this;
while (ret->_astParent) while (ret->mAstParent)
ret = ret->_astParent; ret = ret->mAstParent;
return ret; return ret;
} }
@ -1033,7 +1033,7 @@ public:
bool isCalculation() const; bool isCalculation() const;
void clearAst() { void clearAst() {
_astOperand1 = _astOperand2 = _astParent = nullptr; mAstOperand1 = mAstOperand2 = mAstParent = nullptr;
} }
void clearValueFlow() { void clearValueFlow() {
@ -1043,10 +1043,10 @@ public:
std::string astString(const char *sep = "") const { std::string astString(const char *sep = "") const {
std::string ret; std::string ret;
if (_astOperand1) if (mAstOperand1)
ret = _astOperand1->astString(sep); ret = mAstOperand1->astString(sep);
if (_astOperand2) if (mAstOperand2)
ret += _astOperand2->astString(sep); ret += mAstOperand2->astString(sep);
return ret + sep + _str; return ret + sep + _str;
} }