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);
57 assert(node_up &&
"ASTNodeUP must not contain a nullptr");
66 std::shared_ptr<StackFrame> frame_sp,
68 bool fragile_ivar,
bool check_ptr_vs_member,
108 uint32_t save_token_idx =
m_dil_lexer.GetCurrentTokenIdx();
120 if (!type_id.value().IsValid())
121 return std::make_unique<ErrorNode>();
126 assert(rhs &&
"ASTNodeUP must not contain a nullptr");
127 return std::make_unique<CastNode>(loc, type_id.value(), std::move(rhs),
157 assert(rhs &&
"ASTNodeUP must not contain a nullptr");
172 llvm_unreachable(
"invalid token kind");
189 assert(lhs &&
"ASTNodeUP must not contain a nullptr");
197 assert(index &&
"ASTNodeUP must not contain a nullptr");
201 assert(last_index &&
"ASTNodeUP must not contain a nullptr");
202 lhs = std::make_unique<BitFieldExtractionNode>(
203 loc, std::move(lhs), std::move(index), std::move(last_index));
205 lhs = std::make_unique<ArraySubscriptNode>(loc, std::move(lhs),
217 lhs = std::make_unique<MemberOfNode>(
223 llvm_unreachable(
"invalid token");
249 if (!identifier.empty())
250 return std::make_unique<IdentifierNode>(loc, identifier);
263 return std::make_unique<ErrorNode>();
287 (
m_dil_lexer.LookAhead(1).GetSpelling() ==
"anonymous") &&
289 (
m_dil_lexer.LookAhead(2).GetSpelling() ==
"namespace") &&
297 BailOut(
"Expected an identifier or anonymous namespace, but not found.",
303 return "(anonymous namespace)::" + identifier2;
344 if (maybe_builtin_type) {
345 type = *maybe_builtin_type;
353 std::vector<Token> ptr_operators;
356 ptr_operators.push_back(std::move(tok));
375 std::string type_name =
"";
376 uint32_t save_token_idx =
m_dil_lexer.GetCurrentTokenIdx();
377 bool first_word =
true;
379 if (
CurToken().GetSpelling() ==
"const" ||
380 CurToken().GetSpelling() ==
"volatile")
383 type_name.push_back(
' ');
386 type_name.append(
CurToken().GetSpelling());
390 if (type_name.size() > 0) {
393 for (
auto type_system_sp : target_sp->GetScratchTypeSystems())
394 if (
auto compiler_type =
395 type_system_sp->GetBuiltinTypeByName(const_type_name))
396 return compiler_type;
418 bool global_scope =
false;
429 if (!nested_name_specifier.empty()) {
433 return llvm::formatv(
"{0}{1}{2}", global_scope ?
"::" :
"",
434 nested_name_specifier, unqualified_id);
446 return llvm::formatv(
"{0}{1}", global_scope ?
"::" :
"", identifier);
470 const std::vector<Token> &ptr_operators) {
472 for (
Token tk : ptr_operators) {
473 uint32_t loc = tk.GetLocation();
477 BailOut(llvm::formatv(
"'type name' declared as a pointer to a "
478 "reference of type {0}",
480 loc,
CurToken().GetSpelling().length());
490 BailOut(
"type name declared as a reference to a reference", loc,
513 return std::make_unique<BooleanLiteralNode>(loc, literal_value);
542 BailOut(llvm::formatv(
"Failed to parse token as numeric-constant: {0}",
545 return numeric_constant;
548 return numeric_constant;
554 llvm::StringRef spelling_ref = spelling;
556 auto radix = llvm::getAutoSenseRadix(spelling_ref);
558 bool is_unsigned =
false;
559 if (spelling_ref.consume_back_insensitive(
"u"))
561 if (spelling_ref.consume_back_insensitive(
"ll"))
563 else if (spelling_ref.consume_back_insensitive(
"l"))
566 if (!is_unsigned && spelling_ref.consume_back_insensitive(
"u"))
569 llvm::APInt raw_value;
570 if (!spelling_ref.getAsInteger(radix, raw_value))
571 return std::make_unique<IntegerLiteralNode>(token.
GetLocation(), raw_value,
572 radix, is_unsigned, type);
573 return std::make_unique<ErrorNode>();
579 llvm::StringRef spelling_ref = spelling;
581 llvm::APFloat raw_float(llvm::APFloat::IEEEdouble());
582 if (spelling_ref.consume_back_insensitive(
"f"))
583 raw_float = llvm::APFloat(llvm::APFloat::IEEEsingle());
585 auto StatusOrErr = raw_float.convertFromString(
586 spelling_ref, llvm::APFloat::rmNearestTiesToEven);
587 if (!errorToBool(StatusOrErr.takeError()))
588 return std::make_unique<FloatLiteralNode>(token.
GetLocation(), raw_float);
589 return std::make_unique<ErrorNode>();
600 if (!
CurToken().IsOneOf(kinds_vec)) {
601 BailOut(llvm::formatv(
"expected any of ({0}), got: {1}",
602 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()
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
Invalid promotion type (results in error).
std::unique_ptr< ASTNode > ASTNodeUP
std::shared_ptr< lldb_private::Target > TargetSP
A source location consisting of a file name and position.