19#include "llvm/ADT/StringRef.h"
20#include "llvm/Support/FormatAdapters.h"
30 const std::string &
message, uint32_t loc,
32 : ErrorInfo(make_error_code(std::errc::invalid_argument)) {
34 FileSpec{}, 1,
static_cast<uint16_t
>(loc + 1),
35 err_len,
false,
true};
36 std::string rendered_msg =
37 llvm::formatv(
"<user expression 0>:1:{0}: {1}\n 1 | {2}\n | ^",
42 m_detail.rendered = std::move(rendered_msg);
45llvm::Expected<ASTNodeUP>
47 std::shared_ptr<StackFrame> frame_sp,
49 bool fragile_ivar,
bool check_ptr_vs_member) {
50 llvm::Error
error = llvm::Error::success();
51 DILParser parser(dil_input_expr, lexer, frame_sp, use_dynamic, use_synthetic,
52 fragile_ivar, check_ptr_vs_member,
error);
63 std::shared_ptr<StackFrame> frame_sp,
65 bool fragile_ivar,
bool check_ptr_vs_member,
112 llvm_unreachable(
"invalid token kind");
138 llvm::formatv(
"failed to parse integer constant: {0}",
CurToken()),
140 return std::make_unique<ErrorNode>();
146 BailOut(llvm::formatv(
"failed to parse integer constant: {0}",
149 return std::make_unique<ErrorNode>();
151 lhs = std::make_unique<BitFieldExtractionNode>(
152 loc, std::move(lhs), std::move(*index), std::move(*last_index));
154 lhs = std::make_unique<ArraySubscriptNode>(loc, std::move(lhs),
166 lhs = std::make_unique<MemberOfNode>(
172 llvm_unreachable(
"invalid token");
198 if (!identifier.empty())
199 return std::make_unique<IdentifierNode>(loc, identifier);
212 return std::make_unique<ErrorNode>();
236 (
m_dil_lexer.LookAhead(1).GetSpelling() ==
"anonymous") &&
238 (
m_dil_lexer.LookAhead(2).GetSpelling() ==
"namespace") &&
246 BailOut(
"Expected an identifier or anonymous namespace, but not found.",
252 return "(anonymous namespace)::" + identifier2;
292 bool global_scope =
false;
303 if (!nested_name_specifier.empty()) {
307 return llvm::formatv(
"{0}{1}{2}", global_scope ?
"::" :
"",
308 nested_name_specifier, unqualified_id);
320 return llvm::formatv(
"{0}{1}", global_scope ?
"::" :
"", identifier);
353 return std::make_unique<BooleanLiteralNode>(loc, literal_value);
376 std::string number_spelling;
380 number_spelling =
"-";
383 number_spelling.append(
CurToken().GetSpelling());
384 llvm::StringRef spelling_ref = number_spelling;
386 if (!spelling_ref.getAsInteger<int64_t>(0, raw_value)) {
406 if (!numeric_constant) {
407 BailOut(llvm::formatv(
"Failed to parse token as numeric-constant: {0}",
410 return std::make_unique<ErrorNode>();
413 return numeric_constant;
419 llvm::StringRef spelling_ref = spelling;
421 auto radix = llvm::getAutoSenseRadix(spelling_ref);
423 bool is_unsigned =
false;
424 if (spelling_ref.consume_back_insensitive(
"u"))
426 if (spelling_ref.consume_back_insensitive(
"ll"))
428 else if (spelling_ref.consume_back_insensitive(
"l"))
431 if (!is_unsigned && spelling_ref.consume_back_insensitive(
"u"))
434 llvm::APInt raw_value;
435 if (!spelling_ref.getAsInteger(radix, raw_value))
436 return std::make_unique<IntegerLiteralNode>(token.
GetLocation(), raw_value,
437 radix, is_unsigned, type);
444 llvm::StringRef spelling_ref = spelling;
446 llvm::APFloat raw_float(llvm::APFloat::IEEEdouble());
447 if (spelling_ref.consume_back_insensitive(
"f"))
448 raw_float = llvm::APFloat(llvm::APFloat::IEEEsingle());
450 auto StatusOrErr = raw_float.convertFromString(
451 spelling_ref, llvm::APFloat::rmNearestTiesToEven);
452 if (!errorToBool(StatusOrErr.takeError()))
453 return std::make_unique<FloatLiteralNode>(token.
GetLocation(), raw_float);
465 if (!
CurToken().IsOneOf(kinds_vec)) {
466 BailOut(llvm::formatv(
"expected any of ({0}), got: {1}",
467 llvm::iterator_range(kinds_vec),
CurToken()),
static llvm::raw_ostream & error(Stream &strm)
uint32_t GetKind(uint32_t data)
Return the type kind encoded in the given data.
DILDiagnosticError(DiagnosticDetail detail)
std::string message() const override
DiagnosticDetail m_detail
Class for doing the simple lexing required by DIL.
bool m_check_ptr_vs_member
ASTNodeUP ParseUnaryExpression()
ASTNodeUP ParseIntegerLiteral()
void Expect(Token::Kind kind)
static llvm::Expected< ASTNodeUP > Parse(llvm::StringRef dil_input_expr, DILLexer lexer, std::shared_ptr< StackFrame > frame_sp, lldb::DynamicValueType use_dynamic, bool use_synthetic, bool fragile_ivar, bool check_ptr_vs_member)
ASTNodeUP ParseFloatingPointLiteral()
ASTNodeUP ParseExpression()
DILParser(llvm::StringRef dil_input_expr, DILLexer lexer, std::shared_ptr< StackFrame > frame_sp, lldb::DynamicValueType use_dynamic, bool use_synthetic, bool fragile_ivar, bool check_ptr_vs_member, llvm::Error &error)
void ExpectOneOf(std::vector< Token::Kind > kinds_vec)
ASTNodeUP ParseNumericLiteral()
ASTNodeUP ParsePrimaryExpression()
std::shared_ptr< StackFrame > m_ctx_scope
void BailOut(const std::string &error, uint32_t loc, uint16_t err_len)
ASTNodeUP ParsePostfixExpression()
std::string ParseIdExpression()
std::optional< int64_t > ParseIntegerConstant()
lldb::DynamicValueType m_use_dynamic
std::string ParseUnqualifiedId()
ASTNodeUP ParseBooleanLiteral()
llvm::StringRef m_input_expr
std::string ParseNestedNameSpecifier()
Class defining the tokens generated by the DIL lexer and used by the DIL parser.
uint32_t GetLocation() const
std::string GetSpelling() const
std::unique_ptr< ASTNode > ASTNodeUP
A source location consisting of a file name and position.