21#include "llvm/ADT/StringRef.h"
22#include "llvm/Support/FormatAdapters.h"
32 const std::string &
message, uint32_t loc,
34 : ErrorInfo(make_error_code(std::errc::invalid_argument)) {
36 FileSpec{}, 1,
static_cast<uint16_t
>(loc + 1),
37 err_len,
false,
true};
38 std::string rendered_msg =
39 llvm::formatv(
"<user expression 0>:1:{0}: {1}\n 1 | {2}\n | ^",
44 m_detail.rendered = std::move(rendered_msg);
47llvm::Expected<ASTNodeUP>
49 std::shared_ptr<StackFrame> frame_sp,
51 bool fragile_ivar,
bool check_ptr_vs_member) {
52 llvm::Error
error = llvm::Error::success();
53 DILParser parser(dil_input_expr, lexer, frame_sp, use_dynamic, use_synthetic,
54 fragile_ivar, check_ptr_vs_member,
error);
65 std::shared_ptr<StackFrame> frame_sp,
67 bool fragile_ivar,
bool check_ptr_vs_member,
107 uint32_t save_token_idx =
m_dil_lexer.GetCurrentTokenIdx();
119 if (!type_id.value().IsValid())
120 return std::make_unique<ErrorNode>();
126 return std::make_unique<CastNode>(loc, type_id.value(), std::move(rhs),
170 llvm_unreachable(
"invalid token kind");
196 llvm::formatv(
"failed to parse integer constant: {0}",
CurToken()),
198 return std::make_unique<ErrorNode>();
204 BailOut(llvm::formatv(
"failed to parse integer constant: {0}",
207 return std::make_unique<ErrorNode>();
209 lhs = std::make_unique<BitFieldExtractionNode>(
210 loc, std::move(lhs), std::move(*index), std::move(*last_index));
212 lhs = std::make_unique<ArraySubscriptNode>(loc, std::move(lhs),
224 lhs = std::make_unique<MemberOfNode>(
230 llvm_unreachable(
"invalid token");
256 if (!identifier.empty())
257 return std::make_unique<IdentifierNode>(loc, identifier);
270 return std::make_unique<ErrorNode>();
294 (
m_dil_lexer.LookAhead(1).GetSpelling() ==
"anonymous") &&
296 (
m_dil_lexer.LookAhead(2).GetSpelling() ==
"namespace") &&
304 BailOut(
"Expected an identifier or anonymous namespace, but not found.",
310 return "(anonymous namespace)::" + identifier2;
351 if (maybe_builtin_type) {
352 type = *maybe_builtin_type;
360 std::vector<Token> ptr_operators;
363 ptr_operators.push_back(std::move(tok));
382 std::string type_name =
"";
383 uint32_t save_token_idx =
m_dil_lexer.GetCurrentTokenIdx();
384 bool first_word =
true;
386 if (
CurToken().GetSpelling() ==
"const" ||
387 CurToken().GetSpelling() ==
"volatile")
390 type_name.push_back(
' ');
393 type_name.append(
CurToken().GetSpelling());
397 if (type_name.size() > 0) {
400 for (
auto type_system_sp : target_sp->GetScratchTypeSystems())
401 if (
auto compiler_type =
402 type_system_sp->GetBuiltinTypeByName(const_type_name))
403 return compiler_type;
425 bool global_scope =
false;
436 if (!nested_name_specifier.empty()) {
440 return llvm::formatv(
"{0}{1}{2}", global_scope ?
"::" :
"",
441 nested_name_specifier, unqualified_id);
453 return llvm::formatv(
"{0}{1}", global_scope ?
"::" :
"", identifier);
477 const std::vector<Token> &ptr_operators) {
479 for (
Token tk : ptr_operators) {
480 uint32_t loc = tk.GetLocation();
484 BailOut(llvm::formatv(
"'type name' declared as a pointer to a "
485 "reference of type {0}",
487 loc,
CurToken().GetSpelling().length());
497 BailOut(
"type name declared as a reference to a reference", loc,
520 return std::make_unique<BooleanLiteralNode>(loc, literal_value);
543 std::string number_spelling;
547 number_spelling =
"-";
550 number_spelling.append(
CurToken().GetSpelling());
551 llvm::StringRef spelling_ref = number_spelling;
553 if (!spelling_ref.getAsInteger<int64_t>(0, raw_value)) {
573 if (!numeric_constant) {
574 BailOut(llvm::formatv(
"Failed to parse token as numeric-constant: {0}",
577 return std::make_unique<ErrorNode>();
580 return numeric_constant;
586 llvm::StringRef spelling_ref = spelling;
588 auto radix = llvm::getAutoSenseRadix(spelling_ref);
590 bool is_unsigned =
false;
591 if (spelling_ref.consume_back_insensitive(
"u"))
593 if (spelling_ref.consume_back_insensitive(
"ll"))
595 else if (spelling_ref.consume_back_insensitive(
"l"))
598 if (!is_unsigned && spelling_ref.consume_back_insensitive(
"u"))
601 llvm::APInt raw_value;
602 if (!spelling_ref.getAsInteger(radix, raw_value))
603 return std::make_unique<IntegerLiteralNode>(token.
GetLocation(), raw_value,
604 radix, is_unsigned, type);
611 llvm::StringRef spelling_ref = spelling;
613 llvm::APFloat raw_float(llvm::APFloat::IEEEdouble());
614 if (spelling_ref.consume_back_insensitive(
"f"))
615 raw_float = llvm::APFloat(llvm::APFloat::IEEEsingle());
617 auto StatusOrErr = raw_float.convertFromString(
618 spelling_ref, llvm::APFloat::rmNearestTiesToEven);
619 if (!errorToBool(StatusOrErr.takeError()))
620 return std::make_unique<FloatLiteralNode>(token.
GetLocation(), raw_float);
632 if (!
CurToken().IsOneOf(kinds_vec)) {
633 BailOut(llvm::formatv(
"expected any of ({0}), got: {1}",
634 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.
Generic representation of a type in a programming language.
CompilerType GetPointerType() const
Return a new CompilerType that is a pointer to this type.
CompilerType GetLValueReferenceType() const
Return a new CompilerType that is a L value reference to this type if this type is valid and the type...
bool IsReferenceType(CompilerType *pointee_type=nullptr, bool *is_rvalue=nullptr) const
std::string TypeDescription()
A uniqued constant string class.
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)
std::optional< CompilerType > ParseTypeId()
void TentativeParsingRollback(uint32_t saved_idx)
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()
std::optional< CompilerType > ParseBuiltinType()
ASTNodeUP ParsePrimaryExpression()
std::shared_ptr< StackFrame > m_ctx_scope
void BailOut(const std::string &error, uint32_t loc, uint16_t err_len)
CompilerType ResolveTypeDeclarators(CompilerType type, const std::vector< Token > &ptr_operators)
ASTNodeUP ParsePostfixExpression()
std::string ParseIdExpression()
std::optional< int64_t > ParseIntegerConstant()
lldb::DynamicValueType m_use_dynamic
std::string ParseUnqualifiedId()
ASTNodeUP ParseCastExpression()
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
@ eNone
Type promotion casting.
std::unique_ptr< ASTNode > ASTNodeUP
std::shared_ptr< lldb_private::Target > TargetSP
A source location consisting of a file name and position.