| 2135 | } |
| 2136 | |
| 2137 | const Token *expandToken(TokenList &output, const Location &loc, const Token *tok, const MacroMap ¯os, const std::set<TokenString> &expandedmacros, const std::vector<const Token*> ¶metertokens) const { |
| 2138 | // Not name.. |
| 2139 | if (!tok->name) { |
| 2140 | output.push_back(newMacroToken(tok->str(), loc, true, tok)); |
| 2141 | return tok->next; |
| 2142 | } |
| 2143 | |
| 2144 | // Macro parameter.. |
| 2145 | { |
| 2146 | TokenList temp(files); |
| 2147 | if (expandArg(temp, tok, loc, macros, expandedmacros, parametertokens)) { |
| 2148 | if (tok->str() == "__VA_ARGS__" && temp.empty() && output.cback() && output.cback()->str() == "," && |
| 2149 | tok->nextSkipComments() && tok->nextSkipComments()->str() == ")") |
| 2150 | output.deleteToken(output.back()); |
| 2151 | return recursiveExpandToken(output, temp, loc, tok, macros, expandedmacros, parametertokens); |
| 2152 | } |
| 2153 | } |
| 2154 | |
| 2155 | // Macro.. |
| 2156 | const MacroMap::const_iterator it = macros.find(tok->str()); |
| 2157 | if (it != macros.end() && expandedmacros.find(tok->str()) == expandedmacros.end()) { |
| 2158 | std::set<std::string> expandedmacros2(expandedmacros); |
| 2159 | expandedmacros2.insert(tok->str()); |
| 2160 | |
| 2161 | const Macro &calledMacro = it->second; |
| 2162 | if (!calledMacro.functionLike()) { |
| 2163 | TokenList temp(files); |
| 2164 | calledMacro.expand(temp, loc, tok, macros, expandedmacros); |
| 2165 | return recursiveExpandToken(output, temp, loc, tok, macros, expandedmacros2, parametertokens); |
| 2166 | } |
| 2167 | if (!sameline(tok, tok->next)) { |
| 2168 | output.push_back(newMacroToken(tok->str(), loc, true, tok)); |
| 2169 | return tok->next; |
| 2170 | } |
| 2171 | TokenList tokens(files); |
| 2172 | tokens.push_back(new Token(*tok)); |
| 2173 | const Token * tok2 = nullptr; |
| 2174 | if (tok->next->op == '(') { |
| 2175 | tok2 = appendTokens(tokens, loc, tok->next, macros, expandedmacros, parametertokens); |
| 2176 | } |
| 2177 | else if (expandArg(tokens, tok->next, loc, macros, expandedmacros, parametertokens)) { |
| 2178 | tokens.front()->location = loc; |
| 2179 | if (tokens.cfront()->next && tokens.cfront()->next->op == '(') |
| 2180 | tok2 = tok->next; |
| 2181 | } |
| 2182 | if (!tok2) { |
| 2183 | output.push_back(newMacroToken(tok->str(), loc, true, tok)); |
| 2184 | return tok->next; |
| 2185 | } |
| 2186 | TokenList temp(files); |
| 2187 | calledMacro.expand(temp, loc, tokens.cfront(), macros, expandedmacros); |
| 2188 | return recursiveExpandToken(output, temp, loc, tok2, macros, expandedmacros, parametertokens); |
| 2189 | } |
| 2190 | |
| 2191 | if (tok->str() == DEFINED) { |
| 2192 | const Token * const tok2 = tok->next; |
| 2193 | const Token * const tok3 = tok2 ? tok2->next : nullptr; |
| 2194 | const Token * const tok4 = tok3 ? tok3->next : nullptr; |
nothing calls this directly
no test coverage detected