JSHandleRootedTypedefChecker.cpp (1404B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 #include "JSHandleRootedTypedefChecker.h" 6 #include "CustomMatchers.h" 7 8 void JSHandleRootedTypedefChecker::registerMatchers(MatchFinder *AstMatcher) { 9 AstMatcher->addMatcher( 10 declaratorDecl(isUsingJSHandleRootedTypedef(), isNotSpiderMonkey()) 11 .bind("declaratorDecl"), 12 this); 13 } 14 15 std::string getReplacement(std::string TypeName) { 16 for (auto &pair : JSHandleRootedTypedefMap) { 17 if (!TypeName.compare(pair[0])) { 18 return pair[1]; 19 } 20 } 21 llvm_unreachable("Unexpected type name"); 22 } 23 24 void JSHandleRootedTypedefChecker::check( 25 const MatchFinder::MatchResult &Result) { 26 const char *Error = "The fully qualified types are preferred over the " 27 "shorthand typedefs for JS::Handle/JS::Rooted types " 28 "outside SpiderMonkey."; 29 30 const DeclaratorDecl *Declarator = 31 Result.Nodes.getNodeAs<DeclaratorDecl>("declaratorDecl"); 32 33 std::string Replacement = getReplacement(Declarator->getType().getAsString()); 34 diag(Declarator->getBeginLoc(), Error, DiagnosticIDs::Error) 35 << FixItHint::CreateReplacement( 36 Declarator->getTypeSourceInfo()->getTypeLoc().getSourceRange(), 37 Replacement); 38 }