13 #include "clang/AST/ASTTypeTraits.h" 14 #include "clang/AST/Type.h" 15 #include "llvm/Support/FormatVariadic.h" 16 #include "llvm/Support/ScopedPrinter.h" 17 #include "llvm/Support/raw_ostream.h" 31 class DumpAST :
public Tweak {
33 const char *id() const override final;
35 bool prepare(const Selection &Inputs)
override {
36 for (
auto N = Inputs.ASTSelection.commonAncestor(); N && !Node;
38 if (dumpable(N->ASTNode))
40 return Node.hasValue();
42 Expected<Effect> apply(
const Selection &Inputs)
override;
43 std::string title()
const override {
44 return llvm::formatv(
"Dump {0} AST", Node->getNodeKind().asStringRef());
46 Intent intent()
const override {
return Info; }
47 bool hidden()
const override {
return true; }
50 static bool dumpable(
const ast_type_traits::DynTypedNode &N) {
53 return N.get<Decl>() || N.get<Stmt>() || N.get<
Type>();
56 llvm::Optional<ast_type_traits::DynTypedNode> Node;
60 llvm::Expected<Tweak::Effect> DumpAST::apply(
const Selection &Inputs) {
62 llvm::raw_string_ostream OS(Str);
63 Node->dump(OS, Inputs.AST.getASTContext().getSourceManager());
64 return Effect::showMessage(std::move(OS.str()));
83 class ShowSelectionTree :
public Tweak {
85 const char *id() const override final;
87 bool prepare(const Selection &Inputs)
override {
88 return Inputs.ASTSelection.root() !=
nullptr;
90 Expected<Effect> apply(
const Selection &Inputs)
override {
91 return Effect::showMessage(llvm::to_string(Inputs.ASTSelection));
93 std::string title()
const override {
return "Show selection tree"; }
94 Intent intent()
const override {
return Info; }
95 bool hidden()
const override {
return true; }
108 class DumpRecordLayout :
public Tweak {
110 const char *id() const override final;
112 bool prepare(const Selection &Inputs)
override {
113 if (
auto *Node = Inputs.ASTSelection.commonAncestor())
114 if (
auto *
D = Node->ASTNode.get<Decl>())
115 Record = dyn_cast<RecordDecl>(
D);
116 return Record &&
Record->isThisDeclarationADefinition() &&
117 !
Record->isDependentType();
119 Expected<Effect> apply(
const Selection &Inputs)
override {
121 llvm::raw_string_ostream OS(Str);
122 Inputs.AST.getASTContext().DumpRecordLayout(Record, OS);
123 return Effect::showMessage(std::move(OS.str()));
125 std::string title()
const override {
126 return llvm::formatv(
128 TypeWithKeyword::getTagTypeKindName(
Record->getTagKind()));
130 Intent intent()
const override {
return Info; }
135 bool hidden()
const override {
return true; }
138 const RecordDecl *
Record =
nullptr;
llvm::SmallVector< uint64_t, 1024 > Record
#define REGISTER_TWEAK(Subclass)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//