1 //===-- FormatEntity.h ------------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef liblldb_FormatEntity_h_
10 #define liblldb_FormatEntity_h_
12 #include "lldb/Utility/CompletionRequest.h"
13 #include "lldb/Utility/FileSpec.h"
14 #include "lldb/Utility/Status.h"
15 #include "lldb/lldb-enumerations.h"
16 #include "lldb/lldb-types.h"
24 namespace lldb_private {
26 class ExecutionContext;
36 namespace lldb_private {
51 ScriptVariableSynthetic,
65 ThreadCompletedExpression,
84 FunctionInitialFunction,
89 FunctionAddrOffsetConcrete,
98 LineEntryStartAddress,
105 const char *string; // Insert this exact string into the output
108 uint32_t num_children;
109 Definition *children; // An array of "num_children" Definition entries,
113 Entry(Type t = Type::Invalid, const char *s = nullptr,
114 const char *f = nullptr)
115 : string(s ? s : ""), printf_format(f ? f : ""), children(),
116 definition(nullptr), type(t), fmt(lldb::eFormatDefault), number(0),
119 Entry(llvm::StringRef s);
122 void AppendChar(char ch);
124 void AppendText(const llvm::StringRef &s);
126 void AppendText(const char *cstr);
128 void AppendEntry(const Entry &&entry) { children.push_back(entry); }
132 printf_format.clear();
134 definition = nullptr;
135 type = Type::Invalid;
136 fmt = lldb::eFormatDefault;
141 static const char *TypeToCString(Type t);
143 void Dump(Stream &s, int depth = 0) const;
145 bool operator==(const Entry &rhs) const {
146 if (string != rhs.string)
148 if (printf_format != rhs.printf_format)
150 const size_t n = children.size();
151 const size_t m = rhs.children.size();
152 for (size_t i = 0; i < std::min<size_t>(n, m); ++i) {
153 if (!(children[i] == rhs.children[i]))
156 if (children != rhs.children)
158 if (definition != rhs.definition)
160 if (type != rhs.type)
164 if (deref != rhs.deref)
170 std::string printf_format;
171 std::vector<Entry> children;
172 Definition *definition;
179 static bool Format(const Entry &entry, Stream &s, const SymbolContext *sc,
180 const ExecutionContext *exe_ctx, const Address *addr,
181 ValueObject *valobj, bool function_changed,
182 bool initial_function);
184 static bool FormatStringRef(const llvm::StringRef &format, Stream &s,
185 const SymbolContext *sc,
186 const ExecutionContext *exe_ctx,
187 const Address *addr, ValueObject *valobj,
188 bool function_changed, bool initial_function);
190 static bool FormatCString(const char *format, Stream &s,
191 const SymbolContext *sc,
192 const ExecutionContext *exe_ctx,
193 const Address *addr, ValueObject *valobj,
194 bool function_changed, bool initial_function);
196 static Status Parse(const llvm::StringRef &format, Entry &entry);
198 static Status ExtractVariableInfo(llvm::StringRef &format_str,
199 llvm::StringRef &variable_name,
200 llvm::StringRef &variable_format);
202 static void AutoComplete(lldb_private::CompletionRequest &request);
204 // Format the current elements into the stream \a s.
206 // The root element will be stripped off and the format str passed in will be
207 // either an empty string (print a description of this object), or contain a
208 // `.`-separated series like a domain name that identifies further
209 // sub-elements to display.
210 static bool FormatFileSpec(const FileSpec &file, Stream &s,
211 llvm::StringRef elements,
212 llvm::StringRef element_format);
215 static Status ParseInternal(llvm::StringRef &format, Entry &parent_entry,
218 } // namespace lldb_private
220 #endif // liblldb_FormatEntity_h_