================
@@ -101,30 +102,63 @@ std::string removePureVirtualSyntax(const std::string
&MethodDecl,
assert(!MethodDecl.empty());
TokenStream TS = lex(MethodDecl, LangOpts);
+ auto Tokens = TS.tokens();
- std::string DeclString;
- for (const clangd::Token &Tk : TS.tokens()) {
- if (Tk.Kind == clang::tok::raw_identifier && Tk.text() == "virtual")
+ // Find the pure-specifier (= 0) by searching backwards.
+ size_t PureEqualIndex = Tokens.size();
+ for (int J = static_cast<int>(Tokens.size()) - 1; J >= 1; --J) {
+ auto Kind = Tokens[J].Kind;
+ if (Kind == tok::eof || Kind == tok::semi || Kind == tok::comment)
continue;
- // If the ending two tokens are "= 0", we break here and we already have
the
- // method's string without the pure virtual syntax.
- const auto &Next = Tk.next();
- if (Next.next().Kind == tok::eof && Tk.Kind == clang::tok::equal &&
- Next.text() == "0")
+ if (Tokens[J].text() == "0" && Tokens[J - 1].Kind == tok::equal)
+ PureEqualIndex = J - 1;
+
+ break;
----------------
timon-ul wrote:
I think this `for` loop is a bit...odd. I understand you are filtering out the
end of the string, but the last `if` just feels wrong. Like what are you trying
to express by the case of "we did not find `=0` but we break out of the loop
anyway". I know it cannot happen but...then why do we have an `if`?
https://github.com/llvm/llvm-project/pull/184023
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits