Bug 1874684 - Part 17: Fix uninitialised variable warnings from clang-tidy. r=allstarschh
[gecko.git] / build / clang-plugin / JSHandleRootedTypedefChecker.cpp
blob3e3adf7906e24fc4749c729b8db5faa6c22bb0c0
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/. */
5 #include "JSHandleRootedTypedefChecker.h"
6 #include "CustomMatchers.h"
8 void JSHandleRootedTypedefChecker::registerMatchers(MatchFinder *AstMatcher) {
9 AstMatcher->addMatcher(
10 declaratorDecl(isUsingJSHandleRootedTypedef(), isNotSpiderMonkey())
11 .bind("declaratorDecl"),
12 this);
15 std::string getReplacement(std::string TypeName) {
16 for (auto &pair : JSHandleRootedTypedefMap) {
17 if (!TypeName.compare(pair[0])) {
18 return pair[1];
21 llvm_unreachable("Unexpected type name");
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.";
30 const DeclaratorDecl *Declarator =
31 Result.Nodes.getNodeAs<DeclaratorDecl>("declaratorDecl");
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);