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};
39 std::string rendered_msg =
40 llvm::formatv(
"<user expression 0>:1:{0}: {1}\n 1 | {2}\n | ^",
45 m_detail.rendered = std::move(rendered_msg);
48llvm::Expected<lldb::TypeSystemSP>
51 ctx->GetSymbolContext(lldb::eSymbolContextCompUnit);
54 symbol_context = ctx->GetSymbolContext(lldb::eSymbolContextModule);
55 return symbol_context.
module_sp->GetTypeSystemForLanguage(language);
62 llvm::StringRef name_ref(name);
64 if (name_ref.starts_with(
"::"))
65 name_ref = name_ref.drop_front(2);
67 std::vector<CompilerType> result_type_list;
69 if (!name_ref.empty() && target_sp) {
72 TypeQueryOptions::e_find_one};
74 images.
FindTypes(
nullptr, query, results);
77 result_type_list.push_back(type_sp->GetFullCompilerType());
80 if (!result_type_list.empty()) {
91 std::shared_ptr<StackFrame> frame_sp,
95 const bool check_ptr_vs_member =
97 const bool no_fragile_ivar =
99 const bool no_synth_child =
102 llvm::Error
error = llvm::Error::success();
103 DILParser parser(dil_input_expr, lexer, frame_sp, use_dynamic,
104 !no_synth_child, !no_fragile_ivar, check_ptr_vs_member,
108 assert(node_up &&
"ASTNodeUP must not contain a nullptr");
117 std::shared_ptr<StackFrame> frame_sp,
119 bool fragile_ivar,
bool check_ptr_vs_member,
148 assert(lhs &&
"ASTNodeUP must not contain a nullptr");
154 assert(rhs &&
"ASTNodeUP must not contain a nullptr");
155 lhs = std::make_unique<BinaryOpNode>(
157 std::move(lhs), std::move(rhs));
181 uint32_t save_token_idx =
m_dil_lexer.GetCurrentTokenIdx();
193 if (!type_id.value().IsValid())
194 return std::make_unique<ErrorNode>();
199 assert(rhs &&
"ASTNodeUP must not contain a nullptr");
200 return std::make_unique<CastNode>(loc, type_id.value(), std::move(rhs),
230 assert(rhs &&
"ASTNodeUP must not contain a nullptr");
245 llvm_unreachable(
"invalid token kind");
262 assert(lhs &&
"ASTNodeUP must not contain a nullptr");
270 assert(index &&
"ASTNodeUP must not contain a nullptr");
274 assert(last_index &&
"ASTNodeUP must not contain a nullptr");
275 lhs = std::make_unique<BitFieldExtractionNode>(
276 loc, std::move(lhs), std::move(index), std::move(last_index));
278 BailOut(
"use of '-' for bitfield range is deprecated; use ':' instead",
280 return std::make_unique<ErrorNode>();
282 lhs = std::make_unique<ArraySubscriptNode>(loc, std::move(lhs),
294 lhs = std::make_unique<MemberOfNode>(
300 llvm_unreachable(
"invalid token");
326 if (!identifier.empty())
327 return std::make_unique<IdentifierNode>(loc, identifier);
340 return std::make_unique<ErrorNode>();
364 (
m_dil_lexer.LookAhead(1).GetSpelling() ==
"anonymous") &&
366 (
m_dil_lexer.LookAhead(2).GetSpelling() ==
"namespace") &&
374 BailOut(
"Expected an identifier or anonymous namespace, but not found.",
380 return "(anonymous namespace)::" + identifier2;
420 if (maybe_builtin_type) {
421 type = *maybe_builtin_type;
425 std::string type_name;
428 if (type_name.empty())
450 std::vector<Token> ptr_operators;
453 ptr_operators.push_back(std::move(tok));
472 std::string type_name =
"";
473 uint32_t save_token_idx =
m_dil_lexer.GetCurrentTokenIdx();
474 bool first_word =
true;
476 if (
CurToken().GetSpelling() ==
"const" ||
477 CurToken().GetSpelling() ==
"volatile")
480 type_name.push_back(
' ');
483 type_name.append(
CurToken().GetSpelling());
487 if (type_name.size() > 0) {
490 for (
auto type_system_sp : target_sp->GetScratchTypeSystems())
491 if (
auto compiler_type =
492 type_system_sp->GetBuiltinTypeByName(const_type_name))
493 return compiler_type;
510 type_name = *err_or_string;
526 bool global_scope =
false;
537 if (!type_name_or_err)
538 return type_name_or_err;
539 std::string type_name = *type_name_or_err;
544 if (!type_name.empty())
546 return llvm::formatv(
"{0}{1}{2}", global_scope ?
"::" :
"",
547 nested_name_specifier, type_name);
597 bool global_scope =
false;
608 if (!nested_name_specifier.empty()) {
612 return llvm::formatv(
"{0}{1}{2}", global_scope ?
"::" :
"",
613 nested_name_specifier, unqualified_id);
625 return llvm::formatv(
"{0}{1}", global_scope ?
"::" :
"", identifier);
649 const std::vector<Token> &ptr_operators) {
651 for (
Token tk : ptr_operators) {
652 uint32_t loc = tk.GetLocation();
656 BailOut(llvm::formatv(
"'type name' declared as a pointer to a "
657 "reference of type {0}",
659 loc,
CurToken().GetSpelling().length());
669 BailOut(
"type name declared as a reference to a reference", loc,
692 return std::make_unique<BooleanLiteralNode>(loc, literal_value);
721 BailOut(llvm::formatv(
"Failed to parse token as numeric-constant: {0}",
724 return numeric_constant;
727 return numeric_constant;
733 llvm::StringRef spelling_ref = spelling;
735 auto radix = llvm::getAutoSenseRadix(spelling_ref);
737 bool is_unsigned =
false;
738 if (spelling_ref.consume_back_insensitive(
"u"))
740 if (spelling_ref.consume_back_insensitive(
"ll"))
742 else if (spelling_ref.consume_back_insensitive(
"l"))
745 if (!is_unsigned && spelling_ref.consume_back_insensitive(
"u"))
748 llvm::APInt raw_value;
749 if (!spelling_ref.getAsInteger(radix, raw_value))
750 return std::make_unique<IntegerLiteralNode>(token.
GetLocation(), raw_value,
751 radix, is_unsigned, type);
752 return std::make_unique<ErrorNode>();
758 llvm::StringRef spelling_ref = spelling;
760 llvm::APFloat raw_float(llvm::APFloat::IEEEdouble());
761 if (spelling_ref.consume_back_insensitive(
"f"))
762 raw_float = llvm::APFloat(llvm::APFloat::IEEEsingle());
764 auto StatusOrErr = raw_float.convertFromString(
765 spelling_ref, llvm::APFloat::rmNearestTiesToEven);
766 if (!errorToBool(StatusOrErr.takeError()))
767 return std::make_unique<FloatLiteralNode>(token.
GetLocation(), raw_float);
768 return std::make_unique<ErrorNode>();
779 if (!
CurToken().IsOneOf(kinds_vec)) {
780 BailOut(llvm::formatv(
"expected any of ({0}), got: {1}",
781 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.
lldb::LanguageType GetLanguage()
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.
@ eExpressionPathOptionsNoFragileObjcIvar
@ eExpressionPathOptionCheckPtrVsMember
@ eExpressionPathOptionsNoSyntheticChildren
Defines a symbol context baton that can be handed other debug core functions.
lldb::ModuleSP module_sp
The Module for a given query.
CompileUnit * comp_unit
The CompileUnit for a given query.
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()
bool m_check_ptr_vs_member
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()
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)
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()
lldb::DynamicValueType m_use_dynamic
std::string ParseUnqualifiedId()
ASTNodeUP ParseCastExpression()
ASTNodeUP ParseBooleanLiteral()
std::optional< std::string > ParseTypeName()
static llvm::Expected< ASTNodeUP > Parse(llvm::StringRef dil_input_expr, DILLexer lexer, std::shared_ptr< StackFrame > frame_sp, lldb::DynamicValueType use_dynamic, uint32_t options)
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).
llvm::Expected< lldb::TypeSystemSP > GetTypeSystemFromCU(std::shared_ptr< StackFrame > ctx)
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...
LanguageType
Programming language type.
std::shared_ptr< lldb_private::Type > TypeSP
std::shared_ptr< lldb_private::Target > TargetSP
A source location consisting of a file name and position.