1 //===-- FormatEntity.h ------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_FormatEntity_h_
11 #define liblldb_FormatEntity_h_
13 #include "lldb/Utility/CompletionRequest.h"
14 #include "lldb/Utility/FileSpec.h" // for FileSpec
15 #include "lldb/Utility/Status.h"
16 #include "lldb/lldb-enumerations.h" // for Format::eFormatDefault, Format
17 #include "lldb/lldb-types.h" // for addr_t
18 #include <algorithm> // for min
19 #include <stddef.h> // for size_t
20 #include <stdint.h> // for uint32_t, uint64_t
25 namespace lldb_private {
28 namespace lldb_private {
29 class ExecutionContext;
31 namespace lldb_private {
34 namespace lldb_private {
37 namespace lldb_private {
40 namespace lldb_private {
47 namespace lldb_private {
62 ScriptVariableSynthetic,
76 ThreadCompletedExpression,
94 FunctionInitialFunction,
99 FunctionAddrOffsetConcrete,
107 LineEntryStartAddress,
112 enum FormatType { None, UInt32, UInt64, CString };
116 const char *string; // Insert this exact string into the output
118 FormatType format_type; // uint32_t, uint64_t, cstr, or anything that can
119 // be formatted by printf or lldb::Format
121 uint32_t num_children;
122 Definition *children; // An array of "num_children" Definition entries,
126 Entry(Type t = Type::Invalid, const char *s = nullptr,
127 const char *f = nullptr)
128 : string(s ? s : ""), printf_format(f ? f : ""), children(),
129 definition(nullptr), type(t), fmt(lldb::eFormatDefault), number(0),
132 Entry(llvm::StringRef s);
135 void AppendChar(char ch);
137 void AppendText(const llvm::StringRef &s);
139 void AppendText(const char *cstr);
141 void AppendEntry(const Entry &&entry) { children.push_back(entry); }
145 printf_format.clear();
147 definition = nullptr;
148 type = Type::Invalid;
149 fmt = lldb::eFormatDefault;
154 static const char *TypeToCString(Type t);
156 void Dump(Stream &s, int depth = 0) const;
158 bool operator==(const Entry &rhs) const {
159 if (string != rhs.string)
161 if (printf_format != rhs.printf_format)
163 const size_t n = children.size();
164 const size_t m = rhs.children.size();
165 for (size_t i = 0; i < std::min<size_t>(n, m); ++i) {
166 if (!(children[i] == rhs.children[i]))
169 if (children != rhs.children)
171 if (definition != rhs.definition)
173 if (type != rhs.type)
177 if (deref != rhs.deref)
183 std::string printf_format;
184 std::vector<Entry> children;
185 Definition *definition;
192 static bool Format(const Entry &entry, Stream &s, const SymbolContext *sc,
193 const ExecutionContext *exe_ctx, const Address *addr,
194 ValueObject *valobj, bool function_changed,
195 bool initial_function);
197 static bool FormatStringRef(const llvm::StringRef &format, Stream &s,
198 const SymbolContext *sc,
199 const ExecutionContext *exe_ctx,
200 const Address *addr, ValueObject *valobj,
201 bool function_changed, bool initial_function);
203 static bool FormatCString(const char *format, Stream &s,
204 const SymbolContext *sc,
205 const ExecutionContext *exe_ctx,
206 const Address *addr, ValueObject *valobj,
207 bool function_changed, bool initial_function);
209 static Status Parse(const llvm::StringRef &format, Entry &entry);
211 static Status ExtractVariableInfo(llvm::StringRef &format_str,
212 llvm::StringRef &variable_name,
213 llvm::StringRef &variable_format);
215 static size_t AutoComplete(lldb_private::CompletionRequest &request);
217 //----------------------------------------------------------------------
218 // Format the current elements into the stream \a s.
220 // The root element will be stripped off and the format str passed in will be
221 // either an empty string (print a description of this object), or contain a
222 // `.`-separated series like a domain name that identifies further
223 // sub-elements to display.
224 //----------------------------------------------------------------------
225 static bool FormatFileSpec(const FileSpec &file, Stream &s,
226 llvm::StringRef elements,
227 llvm::StringRef element_format);
230 static Status ParseInternal(llvm::StringRef &format, Entry &parent_entry,
233 } // namespace lldb_private
235 #endif // liblldb_FormatEntity_h_