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/FileSpec.h" // for FileSpec
14 #include "lldb/Utility/Status.h"
15 #include "lldb/lldb-enumerations.h" // for Format::eFormatDefault, Format
16 #include "lldb/lldb-types.h" // for addr_t
17 #include <algorithm> // for min
18 #include <stddef.h> // for size_t
19 #include <stdint.h> // for uint32_t, uint64_t
24 namespace lldb_private {
27 namespace lldb_private {
28 class ExecutionContext;
30 namespace lldb_private {
33 namespace lldb_private {
36 namespace lldb_private {
39 namespace lldb_private {
46 namespace lldb_private {
61 ScriptVariableSynthetic,
75 ThreadCompletedExpression,
93 FunctionInitialFunction,
98 FunctionAddrOffsetConcrete,
106 LineEntryStartAddress,
111 enum FormatType { None, UInt32, UInt64, CString };
115 const char *string; // Insert this exact string into the output
117 FormatType format_type; // uint32_t, uint64_t, cstr, or anything that can
118 // be formatted by printf or lldb::Format
120 uint32_t num_children;
121 Definition *children; // An array of "num_children" Definition entries,
125 Entry(Type t = Type::Invalid, const char *s = nullptr,
126 const char *f = nullptr)
127 : string(s ? s : ""), printf_format(f ? f : ""), children(),
128 definition(nullptr), type(t), fmt(lldb::eFormatDefault), number(0),
131 Entry(llvm::StringRef s);
134 void AppendChar(char ch);
136 void AppendText(const llvm::StringRef &s);
138 void AppendText(const char *cstr);
140 void AppendEntry(const Entry &&entry) { children.push_back(entry); }
144 printf_format.clear();
146 definition = nullptr;
147 type = Type::Invalid;
148 fmt = lldb::eFormatDefault;
153 static const char *TypeToCString(Type t);
155 void Dump(Stream &s, int depth = 0) const;
157 bool operator==(const Entry &rhs) const {
158 if (string != rhs.string)
160 if (printf_format != rhs.printf_format)
162 const size_t n = children.size();
163 const size_t m = rhs.children.size();
164 for (size_t i = 0; i < std::min<size_t>(n, m); ++i) {
165 if (!(children[i] == rhs.children[i]))
168 if (children != rhs.children)
170 if (definition != rhs.definition)
172 if (type != rhs.type)
176 if (deref != rhs.deref)
182 std::string printf_format;
183 std::vector<Entry> children;
184 Definition *definition;
191 static bool Format(const Entry &entry, Stream &s, const SymbolContext *sc,
192 const ExecutionContext *exe_ctx, const Address *addr,
193 ValueObject *valobj, bool function_changed,
194 bool initial_function);
196 static bool FormatStringRef(const llvm::StringRef &format, Stream &s,
197 const SymbolContext *sc,
198 const ExecutionContext *exe_ctx,
199 const Address *addr, ValueObject *valobj,
200 bool function_changed, bool initial_function);
202 static bool FormatCString(const char *format, Stream &s,
203 const SymbolContext *sc,
204 const ExecutionContext *exe_ctx,
205 const Address *addr, ValueObject *valobj,
206 bool function_changed, bool initial_function);
208 static Status Parse(const llvm::StringRef &format, Entry &entry);
210 static Status ExtractVariableInfo(llvm::StringRef &format_str,
211 llvm::StringRef &variable_name,
212 llvm::StringRef &variable_format);
214 static size_t AutoComplete(llvm::StringRef s, int match_start_point,
215 int max_return_elements, bool &word_complete,
216 StringList &matches);
218 //----------------------------------------------------------------------
219 // Format the current elements into the stream \a s.
221 // The root element will be stripped off and the format str passed in
222 // will be either an empty string (print a description of this object),
223 // or contain a . separated series like a domain name that identifies
224 // further sub elements to display.
225 //----------------------------------------------------------------------
226 static bool FormatFileSpec(const FileSpec &file, Stream &s,
227 llvm::StringRef elements,
228 llvm::StringRef element_format);
231 static Status ParseInternal(llvm::StringRef &format, Entry &parent_entry,
234 } // namespace lldb_private
236 #endif // liblldb_FormatEntity_h_