LLDB mainline
DILParser.h
Go to the documentation of this file.
1//===-- DILParser.h ---------------------------------------------*- C++ -*-===//
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//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_VALUEOBJECT_DILPARSER_H
10#define LLDB_VALUEOBJECT_DILPARSER_H
11
14#include "lldb/Utility/Status.h"
17#include "llvm/Support/Error.h"
18#include <memory>
19#include <optional>
20#include <string>
21#include <system_error>
22#include <tuple>
23#include <vector>
24
25namespace lldb_private {
26class StackFrame;
27}
28
29namespace lldb_private::dil {
30
37
38CompilerType ResolveTypeByName(const std::string &name,
39 ExecutionContextScope &ctx_scope);
40
41// The following is modeled on class OptionParseError.
43 : public llvm::ErrorInfo<DILDiagnosticError, DiagnosticError> {
45
46public:
47 using llvm::ErrorInfo<DILDiagnosticError, DiagnosticError>::ErrorInfo;
49 : ErrorInfo(make_error_code(std::errc::invalid_argument)),
50 m_detail(std::move(detail)) {}
51
52 DILDiagnosticError(llvm::StringRef expr, const std::string &message,
53 uint32_t loc, uint16_t err_len = 1);
54
55 std::unique_ptr<CloneableError> Clone() const override {
56 return std::make_unique<DILDiagnosticError>(m_detail);
57 }
58
59 llvm::ArrayRef<DiagnosticDetail> GetDetails() const override {
60 return m_detail;
61 }
62
63 std::string message() const override { return m_detail.rendered; }
64};
65
66/// Pure recursive descent parser for C++ like expressions.
67/// EBNF grammar for the parser is described in lldb/docs/dil-expr-lang.ebnf
68class DILParser {
69public:
70 static llvm::Expected<ASTNodeUP>
71 Parse(llvm::StringRef dil_input_expr, DILLexer lexer, StackFrame &stack_frame,
72 lldb::DynamicValueType use_dynamic, lldb::DILMode mode);
73
74 ~DILParser() = default;
75
76private:
77 explicit DILParser(llvm::StringRef dil_input_expr, DILLexer lexer,
78 StackFrame &stack_frame,
79 lldb::DynamicValueType use_dynamic, llvm::Error &error,
80 lldb::DILMode mode);
81
82 ASTNodeUP Run();
83
85
93
94 std::string ParseNestedNameSpecifier();
95
96 std::string ParseIdExpression();
97 std::string ParseUnqualifiedId();
102
104 std::optional<CompilerType> ParseBuiltinType();
105 std::optional<CompilerType> ParseTypeId();
106 void ParseTypeSpecifierSeq(std::string &type_name);
107 std::optional<std::string> ParseTypeSpecifier();
108 std::optional<std::string> ParseTypeName();
110 const std::vector<Token> &ptr_operators);
111
112 void BailOut(const std::string &error, uint32_t loc, uint16_t err_len);
113
114 void Expect(Token::Kind kind);
115
116 void ExpectOneOf(std::vector<Token::Kind> kinds_vec);
117
118 void TentativeParsingRollback(uint32_t saved_idx) {
119 if (m_error)
120 llvm::consumeError(std::move(m_error));
121 m_dil_lexer.ResetTokenIdx(saved_idx);
122 }
123
124 Token CurToken() { return m_dil_lexer.GetCurrentToken(); }
125
126 // Parser doesn't own the evaluation context. The produced AST may depend on
127 // it (for example, for source locations), so it's expected that expression
128 // context will outlive the parser.
130
131 llvm::StringRef m_input_expr;
132
134
135 // Holds an error if it occures during parsing.
136 llvm::Error &m_error;
137
139
140 // DIL Mode requested by the caller.
142}; // class DILParser
143
144} // namespace lldb_private::dil
145
146#endif // LLDB_VALUEOBJECT_DILPARSER_H
static llvm::raw_ostream & error(Stream &strm)
Generic representation of a type in a programming language.
"lldb/Target/ExecutionContextScope.h" Inherit from this if your object can reconstruct its execution ...
This base class provides an interface to stack frames.
Definition StackFrame.h:44
DILDiagnosticError(DiagnosticDetail detail)
Definition DILParser.h:48
std::unique_ptr< CloneableError > Clone() const override
Definition DILParser.h:55
llvm::ArrayRef< DiagnosticDetail > GetDetails() const override
Definition DILParser.h:59
std::string message() const override
Definition DILParser.h:63
Class for doing the simple lexing required by DIL.
Definition DILLexer.h:81
void ParseTypeSpecifierSeq(std::string &type_name)
void Expect(Token::Kind kind)
std::optional< CompilerType > ParseTypeId()
static llvm::Expected< ASTNodeUP > Parse(llvm::StringRef dil_input_expr, DILLexer lexer, StackFrame &stack_frame, lldb::DynamicValueType use_dynamic, lldb::DILMode mode)
Definition DILParser.cpp:93
void TentativeParsingRollback(uint32_t saved_idx)
Definition DILParser.h:118
ASTNodeUP ParseFloatingPointLiteral()
void ExpectOneOf(std::vector< Token::Kind > kinds_vec)
std::optional< std::string > ParseTypeSpecifier()
ASTNodeUP ParseAssignmentExpression()
std::optional< CompilerType > ParseBuiltinType()
DILParser(llvm::StringRef dil_input_expr, DILLexer lexer, StackFrame &stack_frame, lldb::DynamicValueType use_dynamic, llvm::Error &error, lldb::DILMode mode)
void BailOut(const std::string &error, uint32_t loc, uint16_t err_len)
CompilerType ResolveTypeDeclarators(CompilerType type, const std::vector< Token > &ptr_operators)
ASTNodeUP ParseMultiplicativeExpression()
lldb::DynamicValueType m_use_dynamic
Definition DILParser.h:138
std::optional< std::string > ParseTypeName()
llvm::StringRef m_input_expr
Definition DILParser.h:131
std::string ParseNestedNameSpecifier()
Class defining the tokens generated by the DIL lexer and used by the DIL parser.
Definition DILLexer.h:25
std::unique_ptr< ASTNode > ASTNodeUP
Definition DILAST.h:98
CompilerType ResolveTypeByName(const std::string &name, ExecutionContextScope &ctx_scope)
Definition DILParser.cpp:62
A class that represents a running process on the host machine.
DILMode
Data Inspection Language (DIL) evaluation modes.
A compiler-independent representation of an lldb_private::Diagnostic.