Extend the matchers gathering API for types to record template parameters. The TypeLoc type hierarchy has some types which are templates used in CRTP such as PointerLikeTypeLoc. Record the inherited template and template arguments of types inheriting those CRTP types in the ClassInheritance map. Because the name inherited from is now computed, the value type in that map changes from StringRef to std::string. This also causes the toJSON override signature used to serialize that map to change. Remove the logic for skipping over empty ClassData instances. Several classes such as TypeOfExprTypeLoc inherit a CRTP class which provides interesting locations though the derived class does not. Record it as a class to make the locations it inherits available. Record the typeSourceInfo accessors too as they provide access to TypeLocs in many classes. The existing unit tests use UnorderedElementsAre to compare the introspection result with the expected result. Our current implementation of google mock (in gmock-generated-matchers.h) is limited to support for comparing a container of 10 elements. As we are now returning more than 10 results for one of the introspection tests, change it to instead compare against an ordered vector of pairs. Because a macro is used to generate API strings and API calls, disable clang-format in blocks of expected results. Otherwise clang-format would insert whitespaces which would then be compared against the introspected strings and fail the test. Introduce a recursion guard in the generated code. The TypeLoc class has IgnoreParens() API which by default returns itself, so it would otherwise recurse infinitely. Differential Revision: https://reviews.llvm.org/D100516
54 lines
1.5 KiB
C++
54 lines
1.5 KiB
C++
//===- ASTSrcLocProcessor.h ---------------------------------*- C++ -*-----===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLVM_CLANG_TOOLING_DUMPTOOL_ASTSRCLOCPROCESSOR_H
|
|
#define LLVM_CLANG_TOOLING_DUMPTOOL_ASTSRCLOCPROCESSOR_H
|
|
|
|
#include "APIData.h"
|
|
#include "clang/ASTMatchers/ASTMatchFinder.h"
|
|
#include "llvm/ADT/StringRef.h"
|
|
#include <memory>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace clang {
|
|
|
|
class CompilerInstance;
|
|
|
|
namespace tooling {
|
|
|
|
class ASTSrcLocProcessor : public ast_matchers::MatchFinder::MatchCallback {
|
|
public:
|
|
explicit ASTSrcLocProcessor(StringRef JsonPath);
|
|
|
|
std::unique_ptr<ASTConsumer> createASTConsumer(CompilerInstance &Compiler,
|
|
StringRef File);
|
|
|
|
void generate();
|
|
void generateEmpty();
|
|
|
|
private:
|
|
void run(const ast_matchers::MatchFinder::MatchResult &Result) override;
|
|
|
|
llvm::Optional<TraversalKind> getCheckTraversalKind() const override {
|
|
return TK_IgnoreUnlessSpelledInSource;
|
|
}
|
|
|
|
llvm::StringMap<std::string> ClassInheritance;
|
|
llvm::StringMap<std::vector<StringRef>> ClassesInClade;
|
|
llvm::StringMap<ClassData> ClassEntries;
|
|
|
|
std::string JsonPath;
|
|
std::unique_ptr<clang::ast_matchers::MatchFinder> Finder;
|
|
};
|
|
|
|
} // namespace tooling
|
|
} // namespace clang
|
|
|
|
#endif
|