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_
18 // Other libraries and framework includes
20 #include "lldb/Core/Error.h"
21 #include "lldb/lldb-private.h"
27 namespace lldb_private {
42 ScriptVariableSynthetic,
56 ThreadCompletedExpression,
74 FunctionInitialFunction,
79 FunctionAddrOffsetConcrete,
87 LineEntryStartAddress,
92 enum FormatType { None, UInt32, UInt64, CString };
96 const char *string; // Insert this exact string into the output
98 FormatType format_type; // uint32_t, uint64_t, cstr, or anything that can
99 // be formatted by printf or lldb::Format
101 uint32_t num_children;
102 Definition *children; // An array of "num_children" Definition entries,
106 Entry(Type t = Type::Invalid, const char *s = nullptr,
107 const char *f = nullptr)
108 : string(s ? s : ""), printf_format(f ? f : ""), children(),
109 definition(nullptr), type(t), fmt(lldb::eFormatDefault), number(0),
112 Entry(llvm::StringRef s);
115 void AppendChar(char ch);
117 void AppendText(const llvm::StringRef &s);
119 void AppendText(const char *cstr);
121 void AppendEntry(const Entry &&entry) { children.push_back(entry); }
125 printf_format.clear();
127 definition = nullptr;
128 type = Type::Invalid;
129 fmt = lldb::eFormatDefault;
134 static const char *TypeToCString(Type t);
136 void Dump(Stream &s, int depth = 0) const;
138 bool operator==(const Entry &rhs) const {
139 if (string != rhs.string)
141 if (printf_format != rhs.printf_format)
143 const size_t n = children.size();
144 const size_t m = rhs.children.size();
145 for (size_t i = 0; i < std::min<size_t>(n, m); ++i) {
146 if (!(children[i] == rhs.children[i]))
149 if (children != rhs.children)
151 if (definition != rhs.definition)
153 if (type != rhs.type)
157 if (deref != rhs.deref)
163 std::string printf_format;
164 std::vector<Entry> children;
165 Definition *definition;
172 static bool Format(const Entry &entry, Stream &s, const SymbolContext *sc,
173 const ExecutionContext *exe_ctx, const Address *addr,
174 ValueObject *valobj, bool function_changed,
175 bool initial_function);
177 static bool FormatStringRef(const llvm::StringRef &format, Stream &s,
178 const SymbolContext *sc,
179 const ExecutionContext *exe_ctx,
180 const Address *addr, ValueObject *valobj,
181 bool function_changed, bool initial_function);
183 static bool FormatCString(const char *format, Stream &s,
184 const SymbolContext *sc,
185 const ExecutionContext *exe_ctx,
186 const Address *addr, ValueObject *valobj,
187 bool function_changed, bool initial_function);
189 static Error Parse(const llvm::StringRef &format, Entry &entry);
191 static Error ExtractVariableInfo(llvm::StringRef &format_str,
192 llvm::StringRef &variable_name,
193 llvm::StringRef &variable_format);
195 static size_t AutoComplete(llvm::StringRef s, int match_start_point,
196 int max_return_elements, bool &word_complete,
197 StringList &matches);
199 //----------------------------------------------------------------------
200 // Format the current elements into the stream \a s.
202 // The root element will be stripped off and the format str passed in
203 // will be either an empty string (print a description of this object),
204 // or contain a . separated series like a domain name that identifies
205 // further sub elements to display.
206 //----------------------------------------------------------------------
207 static bool FormatFileSpec(const FileSpec &file, Stream &s,
208 llvm::StringRef elements,
209 llvm::StringRef element_format);
212 static Error ParseInternal(llvm::StringRef &format, Entry &parent_entry,
215 } // namespace lldb_private
217 #endif // liblldb_FormatEntity_h_