LLDB mainline
DILParser.cpp
Go to the documentation of this file.
1//===-- DILParser.cpp -----------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7// This implements the recursive descent parser for the Data Inspection
8// Language (DIL), and its helper functions, which will eventually underlie the
9// 'frame variable' command. The language that this parser recognizes is
10// described in lldb/docs/dil-expr-lang.ebnf
11//
12//===----------------------------------------------------------------------===//
13
22#include "llvm/ADT/StringRef.h"
23#include "llvm/Support/FormatAdapters.h"
24#include <cstdlib>
25#include <limits.h>
26#include <memory>
27#include <sstream>
28#include <string>
29
30namespace lldb_private::dil {
31
33 const std::string &message, uint32_t loc,
34 uint16_t err_len)
35 : ErrorInfo(make_error_code(std::errc::invalid_argument)) {
37 FileSpec{}, /*line=*/1, static_cast<uint16_t>(loc + 1),
38 err_len, false, /*in_user_input=*/true};
39 std::string rendered_msg =
40 llvm::formatv("<user expression 0>:1:{0}: {1}\n 1 | {2}\n | ^",
41 loc + 1, message, expr);
42 m_detail.source_location = sloc;
44 m_detail.message = message;
45 m_detail.rendered = std::move(rendered_msg);
46}
47
48llvm::Expected<lldb::TypeSystemSP>
49GetTypeSystemFromCU(std::shared_ptr<StackFrame> ctx) {
50 SymbolContext symbol_context =
51 ctx->GetSymbolContext(lldb::eSymbolContextCompUnit);
52 lldb::LanguageType language = symbol_context.comp_unit->GetLanguage();
53
54 symbol_context = ctx->GetSymbolContext(lldb::eSymbolContextModule);
55 return symbol_context.module_sp->GetTypeSystemForLanguage(language);
56}
57
58CompilerType ResolveTypeByName(const std::string &name,
59 ExecutionContextScope &ctx_scope) {
60 // Internally types don't have global scope qualifier in their names and
61 // LLDB doesn't support queries with it too.
62 llvm::StringRef name_ref(name);
63
64 if (name_ref.starts_with("::"))
65 name_ref = name_ref.drop_front(2);
66
67 std::vector<CompilerType> result_type_list;
68 lldb::TargetSP target_sp = ctx_scope.CalculateTarget();
69 if (!name_ref.empty() && target_sp) {
70 ModuleList &images = target_sp->GetImages();
71 TypeQuery query{ConstString(name_ref), TypeQueryOptions::e_exact_match |
72 TypeQueryOptions::e_find_one};
73 TypeResults results;
74 images.FindTypes(nullptr, query, results);
75 const lldb::TypeSP &type_sp = results.GetFirstType();
76 if (type_sp)
77 result_type_list.push_back(type_sp->GetFullCompilerType());
78 }
79
80 if (!result_type_list.empty()) {
81 CompilerType type = result_type_list[0];
82 if (type.IsValid() && type.GetTypeName().GetStringRef() == name_ref)
83 return type;
84 }
85
86 return {};
87}
88
89llvm::Expected<ASTNodeUP> DILParser::Parse(llvm::StringRef dil_input_expr,
90 DILLexer lexer,
91 std::shared_ptr<StackFrame> frame_sp,
92
93 lldb::DynamicValueType use_dynamic,
94 uint32_t options) {
95 const bool check_ptr_vs_member =
97 const bool no_fragile_ivar =
99 const bool no_synth_child =
101
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,
105 error);
106
107 ASTNodeUP node_up = parser.Run();
108 assert(node_up && "ASTNodeUP must not contain a nullptr");
109
110 if (error)
111 return error;
112
113 return node_up;
114}
115
116DILParser::DILParser(llvm::StringRef dil_input_expr, DILLexer lexer,
117 std::shared_ptr<StackFrame> frame_sp,
118 lldb::DynamicValueType use_dynamic, bool use_synthetic,
119 bool fragile_ivar, bool check_ptr_vs_member,
120 llvm::Error &error)
121 : m_ctx_scope(frame_sp), m_input_expr(dil_input_expr),
122 m_dil_lexer(std::move(lexer)), m_error(error), m_use_dynamic(use_dynamic),
123 m_use_synthetic(use_synthetic), m_fragile_ivar(fragile_ivar),
124 m_check_ptr_vs_member(check_ptr_vs_member) {}
125
127 ASTNodeUP expr = ParseExpression();
128
130
131 return expr;
132}
133
134// Parse an expression.
135//
136// expression:
137// cast_expression
138//
140
141// Parse an additive_expression.
142//
143// additive_expression:
144// cast_expression {"+" cast_expression}
145//
147 auto lhs = ParseCastExpression();
148 assert(lhs && "ASTNodeUP must not contain a nullptr");
149
150 while (CurToken().IsOneOf({Token::plus, Token::minus})) {
151 Token token = CurToken();
152 m_dil_lexer.Advance();
153 auto rhs = ParseCastExpression();
154 assert(rhs && "ASTNodeUP must not contain a nullptr");
155 lhs = std::make_unique<BinaryOpNode>(
157 std::move(lhs), std::move(rhs));
158 }
159
160 return lhs;
161}
162
163// Parse a cast_expression.
164//
165// cast_expression:
166// unary_expression
167// "(" type_id ")" cast_expression
168
170 if (!CurToken().Is(Token::l_paren))
171 return ParseUnaryExpression();
172
173 // This could be a type cast, try parsing the contents as a type declaration.
174 Token token = CurToken();
175 uint32_t loc = token.GetLocation();
176
177 // Enable lexer backtracking, so that we can rollback in case it's not
178 // actually a type declaration.
179
180 // Start tentative parsing (save token location/idx, for possible rollback).
181 uint32_t save_token_idx = m_dil_lexer.GetCurrentTokenIdx();
182
183 // Consume the token only after enabling the backtracking.
184 m_dil_lexer.Advance();
185
186 // Try parsing the type declaration. If the returned value is not valid,
187 // then we should rollback and try parsing the expression.
188 auto type_id = ParseTypeId();
189 if (type_id) {
190 // Successfully parsed the type declaration. Commit the backtracked
191 // tokens and parse the cast_expression.
192
193 if (!type_id.value().IsValid())
194 return std::make_unique<ErrorNode>();
195
197 m_dil_lexer.Advance();
198 auto rhs = ParseCastExpression();
199 assert(rhs && "ASTNodeUP must not contain a nullptr");
200 return std::make_unique<CastNode>(loc, type_id.value(), std::move(rhs),
202 }
203
204 // Failed to parse the contents of the parentheses as a type declaration.
205 // Rollback the lexer and try parsing it as unary_expression.
206 TentativeParsingRollback(save_token_idx);
207
208 return ParseUnaryExpression();
209}
210
211// Parse an unary_expression.
212//
213// unary_expression:
214// postfix_expression
215// unary_operator cast_expression
216//
217// unary_operator:
218// "&"
219// "*"
220// "+"
221// "-"
222//
224 if (CurToken().IsOneOf(
226 Token token = CurToken();
227 uint32_t loc = token.GetLocation();
228 m_dil_lexer.Advance();
229 auto rhs = ParseCastExpression();
230 assert(rhs && "ASTNodeUP must not contain a nullptr");
231 switch (token.GetKind()) {
232 case Token::star:
233 return std::make_unique<UnaryOpNode>(loc, UnaryOpKind::Deref,
234 std::move(rhs));
235 case Token::amp:
236 return std::make_unique<UnaryOpNode>(loc, UnaryOpKind::AddrOf,
237 std::move(rhs));
238 case Token::minus:
239 return std::make_unique<UnaryOpNode>(loc, UnaryOpKind::Minus,
240 std::move(rhs));
241 case Token::plus:
242 return std::make_unique<UnaryOpNode>(loc, UnaryOpKind::Plus,
243 std::move(rhs));
244 default:
245 llvm_unreachable("invalid token kind");
246 }
247 }
248 return ParsePostfixExpression();
249}
250
251// Parse a postfix_expression.
252//
253// postfix_expression:
254// primary_expression
255// postfix_expression "[" expression "]"
256// postfix_expression "[" expression ":" expression "]"
257// postfix_expression "." id_expression
258// postfix_expression "->" id_expression
259//
262 assert(lhs && "ASTNodeUP must not contain a nullptr");
263 while (CurToken().IsOneOf({Token::l_square, Token::period, Token::arrow})) {
264 uint32_t loc = CurToken().GetLocation();
265 Token token = CurToken();
266 switch (token.GetKind()) {
267 case Token::l_square: {
268 m_dil_lexer.Advance();
269 ASTNodeUP index = ParseExpression();
270 assert(index && "ASTNodeUP must not contain a nullptr");
271 if (CurToken().GetKind() == Token::colon) {
272 m_dil_lexer.Advance();
273 ASTNodeUP last_index = ParseExpression();
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));
277 } else if (CurToken().GetKind() == Token::minus) {
278 BailOut("use of '-' for bitfield range is deprecated; use ':' instead",
279 CurToken().GetLocation(), CurToken().GetSpelling().length());
280 return std::make_unique<ErrorNode>();
281 } else {
282 lhs = std::make_unique<ArraySubscriptNode>(loc, std::move(lhs),
283 std::move(index));
284 }
286 m_dil_lexer.Advance();
287 break;
288 }
289 case Token::period:
290 case Token::arrow: {
291 m_dil_lexer.Advance();
292 Token member_token = CurToken();
293 std::string member_id = ParseIdExpression();
294 lhs = std::make_unique<MemberOfNode>(
295 member_token.GetLocation(), std::move(lhs),
296 token.GetKind() == Token::arrow, member_id);
297 break;
298 }
299 default:
300 llvm_unreachable("invalid token");
301 }
302 }
303
304 return lhs;
305}
306
307// Parse a primary_expression.
308//
309// primary_expression:
310// numeric_literal
311// boolean_literal
312// id_expression
313// "(" expression ")"
314//
317 return ParseNumericLiteral();
318 if (CurToken().IsOneOf({Token::kw_true, Token::kw_false}))
319 return ParseBooleanLiteral();
320 if (CurToken().IsOneOf(
322 // Save the source location for the diagnostics message.
323 uint32_t loc = CurToken().GetLocation();
324 std::string identifier = ParseIdExpression();
325
326 if (!identifier.empty())
327 return std::make_unique<IdentifierNode>(loc, identifier);
328 }
329
330 if (CurToken().Is(Token::l_paren)) {
331 m_dil_lexer.Advance();
332 auto expr = ParseExpression();
334 m_dil_lexer.Advance();
335 return expr;
336 }
337
338 BailOut(llvm::formatv("Unexpected token: {0}", CurToken()),
339 CurToken().GetLocation(), CurToken().GetSpelling().length());
340 return std::make_unique<ErrorNode>();
341}
342
343// Parse nested_name_specifier.
344//
345// nested_name_specifier:
346// type_name "::"
347// namespace_name "::"
348// nested_name_specifier identifier "::"
349//
351 // The first token in nested_name_specifier is always an identifier, or
352 // '(anonymous namespace)'.
353 switch (CurToken().GetKind()) {
354 case Token::l_paren: {
355 // Anonymous namespaces need to be treated specially: They are
356 // represented the the string '(anonymous namespace)', which has a
357 // space in it (throwing off normal parsing) and is not actually
358 // proper C++> Check to see if we're looking at
359 // '(anonymous namespace)::...'
360
361 // Look for all the pieces, in order:
362 // l_paren 'anonymous' 'namespace' r_paren coloncolon
363 if (m_dil_lexer.LookAhead(1).Is(Token::identifier) &&
364 (m_dil_lexer.LookAhead(1).GetSpelling() == "anonymous") &&
365 m_dil_lexer.LookAhead(2).Is(Token::identifier) &&
366 (m_dil_lexer.LookAhead(2).GetSpelling() == "namespace") &&
367 m_dil_lexer.LookAhead(3).Is(Token::r_paren) &&
368 m_dil_lexer.LookAhead(4).Is(Token::coloncolon)) {
369 m_dil_lexer.Advance(4);
370
372 m_dil_lexer.Advance();
373 if (!CurToken().Is(Token::identifier) && !CurToken().Is(Token::l_paren)) {
374 BailOut("Expected an identifier or anonymous namespace, but not found.",
375 CurToken().GetLocation(), CurToken().GetSpelling().length());
376 }
377 // Continue parsing the nested_namespace_specifier.
378 std::string identifier2 = ParseNestedNameSpecifier();
379
380 return "(anonymous namespace)::" + identifier2;
381 }
382
383 return "";
384 } // end of special handling for '(anonymous namespace)'
385 case Token::identifier: {
386 // If the next token is scope ("::"), then this is indeed a
387 // nested_name_specifier
388 if (m_dil_lexer.LookAhead(1).Is(Token::coloncolon)) {
389 // This nested_name_specifier is a single identifier.
390 std::string identifier = CurToken().GetSpelling();
391 m_dil_lexer.Advance(1);
393 m_dil_lexer.Advance();
394 // Continue parsing the nested_name_specifier.
395 return identifier + "::" + ParseNestedNameSpecifier();
396 }
397
398 return "";
399 }
400 default:
401 return "";
402 }
403}
404
405// Parse a type_id.
406//
407// type_id:
408// type_specifier_seq [abstract_declarator]
409//
410// type_specifier_seq:
411// type_specifier [type_specifier]
412//
413// type_specifier:
414// ["::"] [nested_name_specifier] type_name // not handled for now!
415// builtin_typename
416//
417std::optional<CompilerType> DILParser::ParseTypeId() {
418 CompilerType type;
419 auto maybe_builtin_type = ParseBuiltinType();
420 if (maybe_builtin_type) {
421 type = *maybe_builtin_type;
422 } else {
423 // Check to see if we have a user-defined type here.
424 // First build up the user-defined type name.
425 std::string type_name;
426 ParseTypeSpecifierSeq(type_name);
427
428 if (type_name.empty())
429 return {};
430 type = ResolveTypeByName(type_name, *m_ctx_scope);
431 if (!type.IsValid())
432 return {};
433
434 // Same-name identifiers should be preferred over typenames.
436 // TODO: Make type accessible with 'class', 'struct' and 'union' keywords.
437 return {};
438
439 // Same-name identifiers should be preferred over typenames.
440 if (LookupGlobalIdentifier(type_name, m_ctx_scope,
441 m_ctx_scope->CalculateTarget(), m_use_dynamic))
442 // TODO: Make type accessible with 'class', 'struct' and 'union' keywords
443 return {};
444 }
445
446 //
447 // abstract_declarator:
448 // ptr_operator [abstract_declarator]
449 //
450 std::vector<Token> ptr_operators;
451 while (CurToken().IsOneOf({Token::star, Token::amp})) {
452 Token tok = CurToken();
453 ptr_operators.push_back(std::move(tok));
454 m_dil_lexer.Advance();
455 }
456 type = ResolveTypeDeclarators(type, ptr_operators);
457
458 return type;
459}
460
461// Parse a built-in type
462//
463// builtin_typename:
464// identifer_seq
465//
466// identifier_seq
467// identifer [identifier_seq]
468//
469// A built-in type can be a single identifier or a space-separated
470// list of identifiers (e.g. "short" or "long long").
471std::optional<CompilerType> DILParser::ParseBuiltinType() {
472 std::string type_name = "";
473 uint32_t save_token_idx = m_dil_lexer.GetCurrentTokenIdx();
474 bool first_word = true;
475 while (CurToken().GetKind() == Token::identifier) {
476 if (CurToken().GetSpelling() == "const" ||
477 CurToken().GetSpelling() == "volatile")
478 continue;
479 if (!first_word)
480 type_name.push_back(' ');
481 else
482 first_word = false;
483 type_name.append(CurToken().GetSpelling());
484 m_dil_lexer.Advance();
485 }
486
487 if (type_name.size() > 0) {
488 lldb::TargetSP target_sp = m_ctx_scope->CalculateTarget();
489 ConstString const_type_name(type_name.c_str());
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;
494 }
495
496 TentativeParsingRollback(save_token_idx);
497 return {};
498}
499
500// Parse a type_specifier_seq.
501//
502// type_specifier_seq:
503// type_specifier [type_specifier_seq]
504//
505void DILParser::ParseTypeSpecifierSeq(std::string &type_name) {
506 while (true) {
507 std::optional<std::string> err_or_string = ParseTypeSpecifier();
508 if (!err_or_string)
509 break;
510 type_name = *err_or_string;
511 }
512}
513
514// Parse a type_specifier.
515//
516// type_specifier:
517// ["::"] [nested_name_specifier] type_name
518//
519// Returns TRUE if a type_specifier was successfully parsed at this location.
520//
521std::optional<std::string> DILParser::ParseTypeSpecifier() {
522 // The type_specifier must be a user-defined type. Try parsing a
523 // simple_type_specifier.
524
525 // Try parsing optional global scope operator.
526 bool global_scope = false;
527 if (CurToken().Is(Token::coloncolon)) {
528 global_scope = true;
529 m_dil_lexer.Advance();
530 }
531
532 // Try parsing optional nested_name_specifier.
533 auto nested_name_specifier = ParseNestedNameSpecifier();
534
535 // Try parsing required type_name.
536 auto type_name_or_err = ParseTypeName();
537 if (!type_name_or_err)
538 return type_name_or_err;
539 std::string type_name = *type_name_or_err;
540
541 // If there is a type_name, then this is indeed a simple_type_specifier.
542 // Global and qualified (namespace/class) scopes can be empty, since they're
543 // optional. In this case type_name is type we're looking for.
544 if (!type_name.empty())
545 // User-defined typenames can't be combined with builtin keywords.
546 return llvm::formatv("{0}{1}{2}", global_scope ? "::" : "",
547 nested_name_specifier, type_name);
548
549 // No type_specifier was found here.
550 return {};
551}
552
553// Parse a type_name.
554//
555// type_name:
556// class_name
557// enum_name
558// typedef_name
559//
560// class_name
561// identifier
562//
563// enum_name
564// identifier
565//
566// typedef_name
567// identifier
568//
569std::optional<std::string> DILParser::ParseTypeName() {
570 // Typename always starts with an identifier.
571 if (CurToken().IsNot(Token::identifier)) {
572 return std::nullopt;
573 }
574
575 // Otherwise look for a class_name, enum_name or a typedef_name.
576 std::string identifier = CurToken().GetSpelling();
577 m_dil_lexer.Advance();
578
579 return identifier;
580}
581
582// Parse an id_expression.
583//
584// id_expression:
585// unqualified_id
586// qualified_id
587//
588// qualified_id:
589// ["::"] [nested_name_specifier] unqualified_id
590// ["::"] identifier
591//
592// identifier:
593// ? Token::identifier ?
594//
596 // Try parsing optional global scope operator.
597 bool global_scope = false;
598 if (CurToken().Is(Token::coloncolon)) {
599 global_scope = true;
600 m_dil_lexer.Advance();
601 }
602
603 // Try parsing optional nested_name_specifier.
604 std::string nested_name_specifier = ParseNestedNameSpecifier();
605
606 // If nested_name_specifier is present, then it's qualified_id production.
607 // Follow the first production rule.
608 if (!nested_name_specifier.empty()) {
609 // Parse unqualified_id and construct a fully qualified id expression.
610 auto unqualified_id = ParseUnqualifiedId();
611
612 return llvm::formatv("{0}{1}{2}", global_scope ? "::" : "",
613 nested_name_specifier, unqualified_id);
614 }
615
616 if (!CurToken().Is(Token::identifier))
617 return "";
618
619 // No nested_name_specifier, but with global scope -- this is also a
620 // qualified_id production. Follow the second production rule.
621 if (global_scope) {
623 std::string identifier = CurToken().GetSpelling();
624 m_dil_lexer.Advance();
625 return llvm::formatv("{0}{1}", global_scope ? "::" : "", identifier);
626 }
627
628 // This is unqualified_id production.
629 return ParseUnqualifiedId();
630}
631
632// Parse an unqualified_id.
633//
634// unqualified_id:
635// identifier
636//
637// identifier:
638// ? Token::identifier ?
639//
642 std::string identifier = CurToken().GetSpelling();
643 m_dil_lexer.Advance();
644 return identifier;
645}
646
649 const std::vector<Token> &ptr_operators) {
650 // Resolve pointers/references.
651 for (Token tk : ptr_operators) {
652 uint32_t loc = tk.GetLocation();
653 if (tk.GetKind() == Token::star) {
654 // Pointers to reference types are forbidden.
655 if (type.IsReferenceType()) {
656 BailOut(llvm::formatv("'type name' declared as a pointer to a "
657 "reference of type {0}",
658 type.TypeDescription()),
659 loc, CurToken().GetSpelling().length());
660 return {};
661 }
662 // Get pointer type for the base type: e.g. int* -> int**.
663 type = type.GetPointerType();
664
665 } else if (tk.GetKind() == Token::amp) {
666 // References to references are forbidden.
667 // FIXME: In future we may want to allow rvalue references (i.e. &&).
668 if (type.IsReferenceType()) {
669 BailOut("type name declared as a reference to a reference", loc,
670 CurToken().GetSpelling().length());
671 return {};
672 }
673 // Get reference type for the base type: e.g. int -> int&.
674 type = type.GetLValueReferenceType();
675 }
676 }
677
678 return type;
679}
680
681// Parse an boolean_literal.
682//
683// boolean_literal:
684// "true"
685// "false"
686//
688 ExpectOneOf(std::vector<Token::Kind>{Token::kw_true, Token::kw_false});
689 uint32_t loc = CurToken().GetLocation();
690 bool literal_value = CurToken().Is(Token::kw_true);
691 m_dil_lexer.Advance();
692 return std::make_unique<BooleanLiteralNode>(loc, literal_value);
693}
694
695void DILParser::BailOut(const std::string &error, uint32_t loc,
696 uint16_t err_len) {
697 if (m_error)
698 // If error is already set, then the parser is in the "bail-out" mode. Don't
699 // do anything and keep the original error.
700 return;
701
702 m_error =
703 llvm::make_error<DILDiagnosticError>(m_input_expr, error, loc, err_len);
704 // Advance the lexer token index to the end of the lexed tokens vector.
705 m_dil_lexer.ResetTokenIdx(m_dil_lexer.NumLexedTokens() - 1);
706}
707
708// Parse a numeric_literal.
709//
710// numeric_literal:
711// ? Token::integer_constant ?
712// ? Token::floating_constant ?
713//
715 ASTNodeUP numeric_constant;
717 numeric_constant = ParseIntegerLiteral();
718 else
719 numeric_constant = ParseFloatingPointLiteral();
720 if (numeric_constant->GetKind() == NodeKind::eErrorNode) {
721 BailOut(llvm::formatv("Failed to parse token as numeric-constant: {0}",
722 CurToken()),
723 CurToken().GetLocation(), CurToken().GetSpelling().length());
724 return numeric_constant;
725 }
726 m_dil_lexer.Advance();
727 return numeric_constant;
728}
729
731 Token token = CurToken();
732 auto spelling = token.GetSpelling();
733 llvm::StringRef spelling_ref = spelling;
734
735 auto radix = llvm::getAutoSenseRadix(spelling_ref);
737 bool is_unsigned = false;
738 if (spelling_ref.consume_back_insensitive("u"))
739 is_unsigned = true;
740 if (spelling_ref.consume_back_insensitive("ll"))
742 else if (spelling_ref.consume_back_insensitive("l"))
744 // Suffix 'u' can be only specified only once, before or after 'l'
745 if (!is_unsigned && spelling_ref.consume_back_insensitive("u"))
746 is_unsigned = true;
747
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>();
753}
754
756 Token token = CurToken();
757 auto spelling = token.GetSpelling();
758 llvm::StringRef spelling_ref = spelling;
759
760 llvm::APFloat raw_float(llvm::APFloat::IEEEdouble());
761 if (spelling_ref.consume_back_insensitive("f"))
762 raw_float = llvm::APFloat(llvm::APFloat::IEEEsingle());
763
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>();
769}
770
772 if (CurToken().IsNot(kind)) {
773 BailOut(llvm::formatv("expected {0}, got: {1}", kind, CurToken()),
774 CurToken().GetLocation(), CurToken().GetSpelling().length());
775 }
776}
777
778void DILParser::ExpectOneOf(std::vector<Token::Kind> kinds_vec) {
779 if (!CurToken().IsOneOf(kinds_vec)) {
780 BailOut(llvm::formatv("expected any of ({0}), got: {1}",
781 llvm::iterator_range(kinds_vec), CurToken()),
782 CurToken().GetLocation(), CurToken().GetSpelling().length());
783 }
784}
785
786} // namespace lldb_private::dil
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
A uniqued constant string class.
Definition ConstString.h:40
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 file utility class.
Definition FileSpec.h:57
A collection class for Module objects.
Definition ModuleList.h:125
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.
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.
Definition Type.h:104
This class tracks the state and results of a TypeQuery.
Definition Type.h:344
lldb::TypeSP GetFirstType() const
Definition Type.h:385
DILDiagnosticError(DiagnosticDetail detail)
Definition DILParser.h:48
std::string message() const override
Definition DILParser.h:63
Class for doing the simple lexing required by DIL.
Definition DILLexer.h:74
void ParseTypeSpecifierSeq(std::string &type_name)
void Expect(Token::Kind kind)
std::optional< CompilerType > ParseTypeId()
void TentativeParsingRollback(uint32_t saved_idx)
Definition DILParser.h:125
ASTNodeUP ParseFloatingPointLiteral()
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()
std::optional< CompilerType > ParseBuiltinType()
std::shared_ptr< StackFrame > m_ctx_scope
Definition DILParser.h:136
void BailOut(const std::string &error, uint32_t loc, uint16_t err_len)
CompilerType ResolveTypeDeclarators(CompilerType type, const std::vector< Token > &ptr_operators)
lldb::DynamicValueType m_use_dynamic
Definition DILParser.h:145
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)
Definition DILParser.cpp:89
llvm::StringRef m_input_expr
Definition DILParser.h:138
std::string ParseNestedNameSpecifier()
Class defining the tokens generated by the DIL lexer and used by the DIL parser.
Definition DILLexer.h:25
bool Is(Kind kind) const
Definition DILLexer.h:55
uint32_t GetLocation() const
Definition DILLexer.h:63
Kind GetKind() const
Definition DILLexer.h:51
std::string GetSpelling() const
Definition DILLexer.h:53
@ eNone
Invalid promotion type (results in error).
Definition DILAST.h:57
llvm::Expected< lldb::TypeSystemSP > GetTypeSystemFromCU(std::shared_ptr< StackFrame > ctx)
Definition DILParser.cpp:49
std::unique_ptr< ASTNode > ASTNodeUP
Definition DILAST.h:90
BinaryOpKind GetBinaryOpKindFromToken(Token::Kind token_kind)
Translates DIL tokens to BinaryOpKind.
Definition DILAST.cpp:14
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.
Definition DILEval.cpp:300
CompilerType ResolveTypeByName(const std::string &name, ExecutionContextScope &ctx_scope)
Definition DILParser.cpp:58
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...
Definition DILEval.cpp:341
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.