| 9387 | } |
| 9388 | |
| 9389 | Capturer::Capturer( StringRef macroName, SourceLineInfo const& lineInfo, ResultWas::OfType resultType, StringRef names ) { |
| 9390 | auto trimmed = [&] (size_t start, size_t end) { |
| 9391 | while (names[start] == ',' || isspace(names[start])) { |
| 9392 | ++start; |
| 9393 | } |
| 9394 | while (names[end] == ',' || isspace(names[end])) { |
| 9395 | --end; |
| 9396 | } |
| 9397 | return names.substr(start, end - start + 1); |
| 9398 | }; |
| 9399 | |
| 9400 | size_t start = 0; |
| 9401 | std::stack<char> openings; |
| 9402 | for (size_t pos = 0; pos < names.size(); ++pos) { |
| 9403 | char c = names[pos]; |
| 9404 | switch (c) { |
| 9405 | case '[': |
| 9406 | case '{': |
| 9407 | case '(': |
| 9408 | // It is basically impossible to disambiguate between |
| 9409 | // comparison and start of template args in this context |
| 9410 | // case '<': |
| 9411 | openings.push(c); |
| 9412 | break; |
| 9413 | case ']': |
| 9414 | case '}': |
| 9415 | case ')': |
| 9416 | // case '>': |
| 9417 | openings.pop(); |
| 9418 | break; |
| 9419 | case ',': |
| 9420 | if (start != pos && openings.size() == 0) { |
| 9421 | m_messages.emplace_back(macroName, lineInfo, resultType); |
| 9422 | m_messages.back().message = trimmed(start, pos); |
| 9423 | m_messages.back().message += " := "; |
| 9424 | start = pos; |
| 9425 | } |
| 9426 | } |
| 9427 | } |
| 9428 | assert(openings.size() == 0 && "Mismatched openings"); |
| 9429 | m_messages.emplace_back(macroName, lineInfo, resultType); |
| 9430 | m_messages.back().message = trimmed(start, names.size() - 1); |
| 9431 | m_messages.back().message += " := "; |
| 9432 | } |
| 9433 | Capturer::~Capturer() { |
| 9434 | if ( !uncaught_exceptions() ){ |
| 9435 | assert( m_captured == m_messages.size() ); |