Bug 1776444 [wpt PR 34582] - Revert "Add TimedHTMLParserBudget to fieldtrial_testing_...
[gecko.git] / build / clang-plugin / JSHandleRootedTypedefChecker.cpp
blob15862c9072804940622dce85f9e6ca4df9b63b11
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 *Warning = "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(), Warning, DiagnosticIDs::Warning)
35 << FixItHint::CreateReplacement(
36 Declarator->getTypeSourceInfo()->getTypeLoc().getSourceRange(),
37 Replacement);