14 #include "clang/AST/ASTTypeTraits.h" 15 #include "clang/AST/Type.h" 16 #include "llvm/Support/FormatVariadic.h" 17 #include "llvm/Support/ScopedPrinter.h" 18 #include "llvm/Support/raw_ostream.h" 32 class DumpAST :
public Tweak {
34 const char *id() const override final;
36 bool prepare(const Selection &Inputs)
override {
37 for (
auto N = Inputs.ASTSelection.commonAncestor(); N && !Node;
39 if (dumpable(N->ASTNode))
41 return Node.hasValue();
43 Expected<Effect> apply(
const Selection &Inputs)
override;
44 std::string title()
const override {
45 return llvm::formatv(
"Dump {0} AST", Node->getNodeKind().asStringRef());
47 Intent intent()
const override {
return Info; }
48 bool hidden()
const override {
return true; }
51 static bool dumpable(
const ast_type_traits::DynTypedNode &N) {
54 return N.get<
Decl>() || N.get<Stmt>() || N.get<
Type>();
57 llvm::Optional<ast_type_traits::DynTypedNode> Node;
61 llvm::Expected<Tweak::Effect> DumpAST::apply(
const Selection &Inputs) {
63 llvm::raw_string_ostream OS(Str);
64 Node->dump(OS, Inputs.AST->getSourceManager());
65 return Effect::showMessage(std::move(OS.str()));
84 class ShowSelectionTree :
public Tweak {
86 const char *id() const override final;
88 bool prepare(const Selection &Inputs)
override {
return true; }
89 Expected<Effect> apply(
const Selection &Inputs)
override {
90 return Effect::showMessage(llvm::to_string(Inputs.ASTSelection));
92 std::string title()
const override {
return "Show selection tree"; }
93 Intent intent()
const override {
return Info; }
94 bool hidden()
const override {
return true; }
105 class DumpSymbol :
public Tweak {
106 const char *id() const override final;
107 bool prepare(const Selection &Inputs)
override {
return true; }
108 Expected<Effect> apply(
const Selection &Inputs)
override {
110 llvm::raw_string_ostream Out(Storage);
116 return Effect::showMessage(Out.str());
118 std::string title()
const override {
return "Dump symbol under the cursor"; }
119 Intent intent()
const override {
return Info; }
120 bool hidden()
const override {
return true; }
133 class DumpRecordLayout :
public Tweak {
135 const char *id() const override final;
137 bool prepare(const Selection &Inputs)
override {
138 if (
auto *Node = Inputs.ASTSelection.commonAncestor())
139 if (
auto *D = Node->ASTNode.get<
Decl>())
140 Record = dyn_cast<RecordDecl>(D);
141 return Record &&
Record->isThisDeclarationADefinition() &&
142 !
Record->isDependentType();
144 Expected<Effect> apply(
const Selection &Inputs)
override {
146 llvm::raw_string_ostream OS(Str);
147 Inputs.AST->getASTContext().DumpRecordLayout(Record, OS);
148 return Effect::showMessage(std::move(OS.str()));
150 std::string title()
const override {
151 return llvm::formatv(
153 TypeWithKeyword::getTagTypeKindName(
Record->getTagKind()));
155 Intent intent()
const override {
return Info; }
160 bool hidden()
const override {
return true; }
163 const RecordDecl *
Record =
nullptr;
const FunctionDecl * Decl
llvm::SmallVector< uint64_t, 1024 > Record
#define REGISTER_TWEAK(Subclass)
std::vector< SymbolDetails > getSymbolInfo(ParsedAST &AST, Position Pos)
Get info about symbols at Pos.
Position sourceLocToPosition(const SourceManager &SM, SourceLocation Loc)
Turn a SourceLocation into a [line, column] pair.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//