| 1062 | } |
| 1063 | |
| 1064 | Token* Token::insertToken(const std::string& tokenStr, bool prepend) |
| 1065 | { |
| 1066 | Token *newToken; |
| 1067 | if (mStr.empty()) |
| 1068 | newToken = this; |
| 1069 | else |
| 1070 | newToken = new Token(mList, mTokensFrontBack); |
| 1071 | newToken->str(tokenStr); |
| 1072 | |
| 1073 | if (newToken != this) { |
| 1074 | newToken->mImpl->mLineNumber = mImpl->mLineNumber; |
| 1075 | newToken->mImpl->mFileIndex = mImpl->mFileIndex; |
| 1076 | newToken->mImpl->mProgressValue = mImpl->mProgressValue; |
| 1077 | |
| 1078 | if (prepend) { |
| 1079 | if (this->previous()) { |
| 1080 | newToken->previous(this->previous()); |
| 1081 | newToken->previous()->next(newToken); |
| 1082 | } else { |
| 1083 | mTokensFrontBack->front = newToken; |
| 1084 | } |
| 1085 | this->previous(newToken); |
| 1086 | newToken->next(this); |
| 1087 | } else { |
| 1088 | if (this->next()) { |
| 1089 | newToken->next(this->next()); |
| 1090 | newToken->next()->previous(newToken); |
| 1091 | } else { |
| 1092 | mTokensFrontBack->back = newToken; |
| 1093 | } |
| 1094 | this->next(newToken); |
| 1095 | newToken->previous(this); |
| 1096 | } |
| 1097 | |
| 1098 | if (mImpl->mScopeInfo) { |
| 1099 | // If the brace is immediately closed there is no point opening a new scope for it |
| 1100 | if (newToken->str() == "{") { |
| 1101 | std::string nextScopeNameAddition; |
| 1102 | // This might be the opening of a member function |
| 1103 | Token *tok1 = newToken; |
| 1104 | while (Token::Match(tok1->previous(), "const|volatile|final|override|&|&&|noexcept")) |
| 1105 | tok1 = tok1->previous(); |
| 1106 | if (tok1->previous() && tok1->strAt(-1) == ")") { |
| 1107 | tok1 = tok1->linkAt(-1); |
| 1108 | if (Token::Match(tok1->previous(), "throw|noexcept")) { |
| 1109 | tok1 = tok1->previous(); |
| 1110 | while (Token::Match(tok1->previous(), "const|volatile|final|override|&|&&|noexcept")) |
| 1111 | tok1 = tok1->previous(); |
| 1112 | if (tok1->strAt(-1) != ")") |
| 1113 | return newToken; |
| 1114 | } else if (Token::Match(newToken->tokAt(-2), ":|, %name%")) { |
| 1115 | tok1 = tok1->tokAt(-2); |
| 1116 | if (tok1->strAt(-1) != ")") |
| 1117 | return newToken; |
| 1118 | } |
| 1119 | if (tok1->strAt(-1) == ">") |
| 1120 | tok1 = tok1->previous()->findOpeningBracket(); |
| 1121 | if (tok1 && Token::Match(tok1->tokAt(-3), "%name% :: %name%")) { |