[PATCH] D18575: [clang-tidy] New checker to replace deprecated throw() specifications
Alexander Kornienko via cfe-commits
cfe-commits at lists.llvm.org
Wed May 11 09:55:17 PDT 2016
alexfh requested changes to this revision.
This revision now requires changes to proceed.
================
Comment at: clang-tidy/modernize/UseNoexceptCheck.cpp:39
@@ +38,3 @@
+
+ const FunctionDecl *FuncDecl =
+ Result.Nodes.getNodeAs<clang::FunctionDecl>("functionDecl");
----------------
s/FunctionDecl/auto/
================
Comment at: clang-tidy/modernize/UseNoexceptCheck.cpp:40
@@ +39,3 @@
+ const FunctionDecl *FuncDecl =
+ Result.Nodes.getNodeAs<clang::FunctionDecl>("functionDecl");
+ if (!FuncDecl)
----------------
s/clang:://
================
Comment at: clang-tidy/modernize/UseNoexceptCheck.cpp:49-50
@@ +48,4 @@
+ SourceLocation CurrentLoc = Range.getEnd();
+ SourceLocation ReplaceStart;
+ SourceLocation ReplaceEnd;
+ std::string Replacement = ReplacementStr;
----------------
These two seem to represent a `SourceRange`.
================
Comment at: clang-tidy/modernize/UseNoexceptCheck.cpp:51
@@ +50,3 @@
+ SourceLocation ReplaceEnd;
+ std::string Replacement = ReplacementStr;
+ unsigned TokenLength = 0;
----------------
s/std::string/StringRef/
================
Comment at: clang-tidy/modernize/UseNoexceptCheck.cpp:54-90
@@ +53,39 @@
+
+ SmallVector<Token, 16> Tokens =
+ utils::lexer::ParseTokens(Context, SM, CharSourceRange(Range, true));
+ auto TokensEnd = Tokens.rend();
+ for (auto I = Tokens.rbegin(); I != TokensEnd; ++I) {
+ SourceLocation Loc = I->getLocation();
+ TokenLength = I->getLength();
+
+ // Looking for throw(), throw(<exception>[,...]), or throw(...).
+ if (I->is(tok::r_paren)) {
+ if (++I == TokensEnd)
+ return;
+ bool Empty = true;
+ // Found ')', now loop till we find '('.
+ while (I->isNot(tok::l_paren)) {
+ Empty = false;
+ if (++I == TokensEnd)
+ return;
+ }
+ if (++I == TokensEnd)
+ return;
+ if (StringRef(SM.getCharacterData(I->getLocation()), I->getLength()) ==
+ "throw") {
+ if (!Empty) {
+ // We only support macro replacement for "throw()".
+ if (Replacement != "noexcept")
+ break;
+ Replacement = "noexcept(false)";
+ }
+ ReplaceEnd = Loc;
+ ReplaceStart = I->getLocation();
+ break;
+ }
+ } else if (++I == TokensEnd) {
+ return;
+ }
+ CurrentLoc = I->getLocation();
+ }
+
----------------
I'd pull this to a separate function to make the `check()` method easier to read.
================
Comment at: clang-tidy/modernize/UseNoexceptCheck.cpp:93
@@ +92,3 @@
+ if (ReplaceStart.isValid() && ReplaceEnd.isValid()) {
+ std::pair<FileID, unsigned> BeginInfo = SM.getDecomposedLoc(ReplaceStart);
+ std::pair<FileID, unsigned> EndInfo = SM.getDecomposedLoc(ReplaceEnd);
----------------
`Lexer::makeFileCharRange` is a convenient way to ensure a range is a contiguous range in the same file.
http://reviews.llvm.org/D18575
More information about the cfe-commits
mailing list