22#include "llvm/ADT/StringRef.h"
23#include "llvm/Support/FormatAdapters.h"
33 const std::string &
message, uint32_t loc,
35 : ErrorInfo(make_error_code(std::errc::invalid_argument)) {
37 FileSpec{}, 1,
static_cast<uint16_t
>(loc + 1),
38 err_len,
false,
true};
46 auto msg = llvm::formatv(
"<user expression>:1:{0}: {1}\n 1 | {2}\n |",
48 std::string rendered_str;
49 llvm::raw_string_ostream rendered_os(rendered_str);
50 rendered_os << msg.str();
51 rendered_os << llvm::indent(loc + 1) <<
"^";
54 rendered_os << std::string(err_len - 1,
'~');
59 m_detail.rendered = std::move(rendered_str);
66 llvm::StringRef name_ref(name);
68 if (name_ref.starts_with(
"::"))
69 name_ref = name_ref.drop_front(2);
71 std::vector<CompilerType> result_type_list;
73 if (!name_ref.empty() && target_sp) {
76 TypeQueryOptions::e_find_one};
78 images.
FindTypes(
nullptr, query, results);
81 result_type_list.push_back(type_sp->GetFullCompilerType());
84 if (!result_type_list.empty()) {
95 std::shared_ptr<StackFrame> frame_sp,
98 llvm::Error
error = llvm::Error::success();
99 DILParser parser(dil_input_expr, lexer, frame_sp, use_dynamic,
error, mode);
102 assert(node_up &&
"ASTNodeUP must not contain a nullptr");
111 std::shared_ptr<StackFrame> frame_sp,
141 assert(lhs &&
"ASTNodeUP must not contain a nullptr");
147 assert(rhs &&
"ASTNodeUP must not contain a nullptr");
148 lhs = std::make_unique<BinaryOpNode>(
150 std::move(lhs), std::move(rhs));
164 assert(lhs &&
"ASTNodeUP must not contain a nullptr");
170 assert(rhs &&
"ASTNodeUP must not contain a nullptr");
171 lhs = std::make_unique<BinaryOpNode>(
173 std::move(lhs), std::move(rhs));
192 BailOut(
"binary multiplication (*) is allowed only in DIL full mode",
194 return std::make_unique<ErrorNode>();
198 assert(rhs &&
"ASTNodeUP must not contain a nullptr");
199 lhs = std::make_unique<BinaryOpNode>(
201 std::move(lhs), std::move(rhs));
225 uint32_t save_token_idx =
m_dil_lexer.GetCurrentTokenIdx();
237 if (!type_id.value().IsValid())
238 return std::make_unique<ErrorNode>();
243 assert(rhs &&
"ASTNodeUP must not contain a nullptr");
244 return std::make_unique<CastNode>(loc, type_id.value(), std::move(rhs),
274 assert(rhs &&
"ASTNodeUP must not contain a nullptr");
289 llvm_unreachable(
"invalid token kind");
306 assert(lhs &&
"ASTNodeUP must not contain a nullptr");
314 assert(index &&
"ASTNodeUP must not contain a nullptr");
318 assert(last_index &&
"ASTNodeUP must not contain a nullptr");
319 lhs = std::make_unique<BitFieldExtractionNode>(
320 loc, std::move(lhs), std::move(index), std::move(last_index));
322 BailOut(
"use of '-' for bitfield range is deprecated; use ':' instead",
324 return std::make_unique<ErrorNode>();
326 lhs = std::make_unique<ArraySubscriptNode>(loc, std::move(lhs),
338 lhs = std::make_unique<MemberOfNode>(
344 llvm_unreachable(
"invalid token");
370 if (!identifier.empty())
371 return std::make_unique<IdentifierNode>(loc, identifier);
384 return std::make_unique<ErrorNode>();
408 (
m_dil_lexer.LookAhead(1).GetSpelling() ==
"anonymous") &&
410 (
m_dil_lexer.LookAhead(2).GetSpelling() ==
"namespace") &&
418 BailOut(
"Expected an identifier or anonymous namespace, but not found.",
424 return "(anonymous namespace)::" + identifier2;
464 if (maybe_builtin_type) {
465 type = *maybe_builtin_type;
469 std::string type_name;
472 if (type_name.empty())
494 std::vector<Token> ptr_operators;
497 ptr_operators.push_back(std::move(tok));
516 std::string type_name =
"";
517 uint32_t save_token_idx =
m_dil_lexer.GetCurrentTokenIdx();
518 bool first_word =
true;
520 if (
CurToken().GetSpelling() ==
"const" ||
521 CurToken().GetSpelling() ==
"volatile")
524 type_name.push_back(
' ');
527 type_name.append(
CurToken().GetSpelling());
531 if (type_name.size() > 0) {
534 for (
auto type_system_sp : target_sp->GetScratchTypeSystems())
535 if (
auto compiler_type =
536 type_system_sp->GetBuiltinTypeByName(const_type_name))
537 return compiler_type;
554 type_name = *err_or_string;
570 bool global_scope =
false;
581 if (!type_name_or_err)
582 return type_name_or_err;
583 std::string type_name = *type_name_or_err;
588 if (!type_name.empty())
590 return llvm::formatv(
"{0}{1}{2}", global_scope ?
"::" :
"",
591 nested_name_specifier, type_name);
641 bool global_scope =
false;
652 if (!nested_name_specifier.empty()) {
656 return llvm::formatv(
"{0}{1}{2}", global_scope ?
"::" :
"",
657 nested_name_specifier, unqualified_id);
669 return llvm::formatv(
"{0}{1}", global_scope ?
"::" :
"", identifier);
693 const std::vector<Token> &ptr_operators) {
695 for (
Token tk : ptr_operators) {
696 uint32_t loc = tk.GetLocation();
700 BailOut(llvm::formatv(
"'type name' declared as a pointer to a "
701 "reference of type {0}",
703 loc,
CurToken().GetSpelling().length());
713 BailOut(
"type name declared as a reference to a reference", loc,
736 return std::make_unique<BooleanLiteralNode>(loc, literal_value);
765 BailOut(llvm::formatv(
"Failed to parse token as numeric-constant: {0}",
768 return numeric_constant;
771 return numeric_constant;
777 llvm::StringRef spelling_ref = spelling;
779 auto radix = llvm::getAutoSenseRadix(spelling_ref);
781 bool is_unsigned =
false;
782 if (spelling_ref.consume_back_insensitive(
"u"))
784 if (spelling_ref.consume_back_insensitive(
"ll"))
786 else if (spelling_ref.consume_back_insensitive(
"l"))
789 if (!is_unsigned && spelling_ref.consume_back_insensitive(
"u"))
792 llvm::APInt raw_value;
793 if (!spelling_ref.getAsInteger(radix, raw_value))
794 return std::make_unique<IntegerLiteralNode>(token.
GetLocation(), raw_value,
795 radix, is_unsigned, type);
796 return std::make_unique<ErrorNode>();
802 llvm::StringRef spelling_ref = spelling;
804 llvm::APFloat raw_float(llvm::APFloat::IEEEdouble());
805 if (spelling_ref.consume_back_insensitive(
"f"))
806 raw_float = llvm::APFloat(llvm::APFloat::IEEEsingle());
808 auto StatusOrErr = raw_float.convertFromString(
809 spelling_ref, llvm::APFloat::rmNearestTiesToEven);
810 if (!errorToBool(StatusOrErr.takeError()))
811 return std::make_unique<FloatLiteralNode>(token.
GetLocation(), raw_float);
812 return std::make_unique<ErrorNode>();
823 if (!
CurToken().IsOneOf(kinds_vec)) {
824 BailOut(llvm::formatv(
"expected any of ({0}), got: {1}",
825 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...
ConstString GetTypeName(bool BaseOnly=false) const
bool IsReferenceType(CompilerType *pointee_type=nullptr, bool *is_rvalue=nullptr) const
std::string TypeDescription()
A uniqued constant string class.
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
"lldb/Target/ExecutionContextScope.h" Inherit from this if your object can reconstruct its execution ...
virtual lldb::TargetSP CalculateTarget()=0
A collection class for Module objects.
void FindTypes(Module *search_first, const TypeQuery &query, lldb_private::TypeResults &results) const
Find types using a type-matching object that contains all search parameters.
A class that contains all state required for type lookups.
This class tracks the state and results of a TypeQuery.
lldb::TypeSP GetFirstType() const
DILDiagnosticError(DiagnosticDetail detail)
std::string message() const override
DiagnosticDetail m_detail
Class for doing the simple lexing required by DIL.
ASTNodeUP ParseAdditiveExpression()
ASTNodeUP ParseUnaryExpression()
void ParseTypeSpecifierSeq(std::string &type_name)
ASTNodeUP ParseIntegerLiteral()
void Expect(Token::Kind kind)
std::optional< CompilerType > ParseTypeId()
void TentativeParsingRollback(uint32_t saved_idx)
ASTNodeUP ParseFloatingPointLiteral()
ASTNodeUP ParseExpression()
void ExpectOneOf(std::vector< Token::Kind > kinds_vec)
std::optional< std::string > ParseTypeSpecifier()
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()
ASTNodeUP ParseMultiplicativeExpression()
lldb::DynamicValueType m_use_dynamic
std::string ParseUnqualifiedId()
DILParser(llvm::StringRef dil_input_expr, DILLexer lexer, std::shared_ptr< StackFrame > frame_sp, lldb::DynamicValueType use_dynamic, llvm::Error &error, lldb::DILMode mode)
static llvm::Expected< ASTNodeUP > Parse(llvm::StringRef dil_input_expr, DILLexer lexer, std::shared_ptr< StackFrame > frame_sp, lldb::DynamicValueType use_dynamic, lldb::DILMode mode)
ASTNodeUP ParseCastExpression()
ASTNodeUP ParseBooleanLiteral()
std::optional< std::string > ParseTypeName()
llvm::StringRef m_input_expr
std::string ParseNestedNameSpecifier()
ASTNodeUP ParseShiftExpression()
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
BinaryOpKind GetBinaryOpKindFromToken(Token::Kind token_kind)
Translates DIL tokens to BinaryOpKind.
lldb::ValueObjectSP LookupGlobalIdentifier(llvm::StringRef name_ref, std::shared_ptr< StackFrame > frame_sp, lldb::TargetSP target_sp, lldb::DynamicValueType use_dynamic)
Given the name of an identifier, check to see if it matches the name of a global variable.
CompilerType ResolveTypeByName(const std::string &name, ExecutionContextScope &ctx_scope)
lldb::ValueObjectSP LookupIdentifier(llvm::StringRef name_ref, std::shared_ptr< StackFrame > frame_sp, lldb::DynamicValueType use_dynamic)
Given the name of an identifier (variable name, member name, type name, etc.), find the ValueObject f...
std::shared_ptr< lldb_private::Type > TypeSP
std::shared_ptr< lldb_private::Target > TargetSP
DILMode
Data Inspection Language (DIL) evaluation modes.
@ eDILModeFull
Allowed: everything supported by DIL.
A source location consisting of a file name and position.