Skip to content

Commit c2bc4f0

Browse files
committed
Simplify parsing of builtin type names.
Following a reviewer suggestion. This eliminates the need for the TypeSpecifier & TypeDeclaration classes which simplifies things a bit.
1 parent d13cda6 commit c2bc4f0

File tree

2 files changed

+58
-474
lines changed

2 files changed

+58
-474
lines changed

lldb/include/lldb/ValueObject/DILParser.h

Lines changed: 4 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -59,61 +59,6 @@ class DILDiagnosticError
5959

6060
std::string message() const override { return m_detail.rendered; }
6161
};
62-
/// TypeDeclaration builds information about the literal type definition as
63-
/// type is being parsed. It doesn't perform semantic analysis for non-basic
64-
/// types -- e.g. "char&&&" is a valid type declaration.
65-
/// NOTE: CV qualifiers are ignored.
66-
class TypeDeclaration {
67-
public:
68-
enum class TypeSpecifier {
69-
kBool,
70-
kChar,
71-
kDouble,
72-
kFloat,
73-
kInt,
74-
kLong,
75-
kLongDouble,
76-
kLongLong,
77-
kShort,
78-
kUnknown,
79-
kVoid,
80-
};
81-
82-
enum class SignSpecifier {
83-
kUnknown,
84-
kSigned,
85-
kUnsigned,
86-
};
87-
88-
bool IsEmpty() const { return !m_is_builtin && !m_is_user_type; }
89-
90-
lldb::BasicType GetBasicType() const;
91-
92-
public:
93-
// Indicates user-defined typename (e.g. "MyClass", "MyTmpl<int>").
94-
std::string m_user_typename;
95-
96-
// Basic type specifier ("void", "char", "intr", "float", "long long", etc.).
97-
TypeSpecifier m_type_specifier = TypeSpecifier::kUnknown;
98-
99-
// Signedness specifier ("signed", "unsigned").
100-
SignSpecifier m_sign_specifier = SignSpecifier::kUnknown;
101-
102-
// Does the type declaration includes "int" specifier?
103-
// This is different than `type_specifier_` and is used to detect "int"
104-
// duplication for types that can be combined with "int" specifier (e.g.
105-
// "short int", "long int").
106-
bool m_has_int_specifier = false;
107-
108-
// Indicates whether there was an error during parsing.
109-
bool m_has_error = false;
110-
111-
// Indicates whether this declaration describes a builtin type.
112-
bool m_is_builtin = false;
113-
114-
// Indicates whether this declaration describes a user type.
115-
bool m_is_user_type = false;
116-
}; // class TypeDeclaration
11762

11863
/// Pure recursive descent parser for C++ like expressions.
11964
/// EBNF grammar for the parser is described in lldb/docs/dil-expr-lang.ebnf
@@ -161,14 +106,13 @@ class DILParser {
161106
ASTNodeUP ParseBooleanLiteral();
162107

163108
ASTNodeUP ParseCastExpression();
164-
std::optional<CompilerType> ParseTypeId(bool must_be_type_id = false);
165-
void ParseTypeSpecifierSeq(TypeDeclaration *type_decl);
166-
bool ParseTypeSpecifier(TypeDeclaration *type_decl);
109+
std::optional<CompilerType> ParseBuiltinType();
110+
std::optional<CompilerType> ParseTypeId();
111+
void ParseTypeSpecifierSeq(std::string &type_name);
112+
bool ParseTypeSpecifier(std::string &user_type_name);
167113
std::string ParseTypeName();
168114
CompilerType ResolveTypeDeclarators(CompilerType type,
169115
const std::vector<Token> &ptr_operators);
170-
bool IsSimpleTypeSpecifierKeyword(Token token) const;
171-
bool HandleSimpleTypeSpecifier(TypeDeclaration *type_decl);
172116

173117
void BailOut(const std::string &error, uint32_t loc, uint16_t err_len);
174118

@@ -204,66 +148,4 @@ class DILParser {
204148

205149
} // namespace lldb_private::dil
206150

207-
namespace llvm {
208-
template <>
209-
struct format_provider<lldb_private::dil::TypeDeclaration::TypeSpecifier> {
210-
static void format(const lldb_private::dil::TypeDeclaration::TypeSpecifier &t,
211-
raw_ostream &OS, llvm::StringRef Options) {
212-
switch (t) {
213-
case lldb_private::dil::TypeDeclaration::TypeSpecifier::kVoid:
214-
OS << "void";
215-
break;
216-
case lldb_private::dil::TypeDeclaration::TypeSpecifier::kBool:
217-
OS << "bool";
218-
break;
219-
case lldb_private::dil::TypeDeclaration::TypeSpecifier::kChar:
220-
OS << "char";
221-
break;
222-
case lldb_private::dil::TypeDeclaration::TypeSpecifier::kInt:
223-
OS << "int";
224-
break;
225-
case lldb_private::dil::TypeDeclaration::TypeSpecifier::kFloat:
226-
OS << "float";
227-
break;
228-
case lldb_private::dil::TypeDeclaration::TypeSpecifier::kShort:
229-
OS << "short";
230-
break;
231-
case lldb_private::dil::TypeDeclaration::TypeSpecifier::kLong:
232-
OS << "long";
233-
break;
234-
case lldb_private::dil::TypeDeclaration::TypeSpecifier::kLongLong:
235-
OS << "long long";
236-
break;
237-
case lldb_private::dil::TypeDeclaration::TypeSpecifier::kDouble:
238-
OS << "double";
239-
break;
240-
case lldb_private::dil::TypeDeclaration::TypeSpecifier::kLongDouble:
241-
OS << "long double";
242-
break;
243-
default:
244-
OS << "invalid type specifier";
245-
break;
246-
}
247-
}
248-
};
249-
250-
template <>
251-
struct format_provider<lldb_private::dil::TypeDeclaration::SignSpecifier> {
252-
static void format(const lldb_private::dil::TypeDeclaration::SignSpecifier &t,
253-
raw_ostream &OS, llvm::StringRef Options) {
254-
switch (t) {
255-
case lldb_private::dil::TypeDeclaration::SignSpecifier::kSigned:
256-
OS << "signed";
257-
break;
258-
case lldb_private::dil::TypeDeclaration::SignSpecifier::kUnsigned:
259-
OS << "unsigned";
260-
break;
261-
default:
262-
OS << "invalid sign specifier";
263-
break;
264-
}
265-
}
266-
};
267-
} // namespace llvm
268-
269151
#endif // LLDB_VALUEOBJECT_DILPARSER_H

0 commit comments

Comments
 (0)