99#ifndef LLDB_VALUEOBJECT_DILAST_H
1010#define LLDB_VALUEOBJECT_DILAST_H
1111
12+ #include " lldb/ValueObject/DILLexer.h"
1213#include " lldb/ValueObject/ValueObject.h"
1314#include " llvm/Support/Error.h"
1415#include < cstdint>
@@ -19,10 +20,12 @@ namespace lldb_private::dil {
1920// / The various types DIL AST nodes (used by the DIL parser).
2021enum class NodeKind {
2122 eArraySubscriptNode,
23+ eBinaryOpNode,
2224 eBitExtractionNode,
2325 eErrorNode,
2426 eIdentifierNode,
2527 eMemberOfNode,
28+ eScalarLiteralNode,
2629 eUnaryOpNode,
2730};
2831
@@ -32,6 +35,14 @@ enum class UnaryOpKind {
3235 Deref, // "*"
3336};
3437
38+ enum class BinaryOpKind {
39+ Add, // "+"
40+ Sub, // "-"
41+ };
42+
43+ // / Translates DIL tokens to BinaryOpKind.
44+ BinaryOpKind GetBinaryOpKindFromToken (Token::Kind token_kind);
45+
3546// / Forward declaration, for use in DIL AST nodes. Definition is at the very
3647// / end of this file.
3748class Visitor ;
@@ -178,6 +189,49 @@ class BitFieldExtractionNode : public ASTNode {
178189 int64_t m_last_index;
179190};
180191
192+ class ScalarLiteralNode : public ASTNode {
193+ public:
194+ ScalarLiteralNode (uint32_t location, lldb::BasicType type, Scalar value)
195+ : ASTNode(location, NodeKind::eScalarLiteralNode), m_type(type),
196+ m_value (value) {}
197+
198+ llvm::Expected<lldb::ValueObjectSP> Accept (Visitor *v) const override ;
199+
200+ lldb::BasicType GetType () const { return m_type; }
201+ Scalar GetValue () const & { return m_value; }
202+
203+ static bool classof (const ASTNode *node) {
204+ return node->GetKind () == NodeKind::eScalarLiteralNode;
205+ }
206+
207+ private:
208+ lldb::BasicType m_type;
209+ Scalar m_value;
210+ };
211+
212+ class BinaryOpNode : public ASTNode {
213+ public:
214+ BinaryOpNode (uint32_t location, BinaryOpKind kind, ASTNodeUP lhs,
215+ ASTNodeUP rhs)
216+ : ASTNode(location, NodeKind::eBinaryOpNode), m_kind(kind),
217+ m_lhs (std::move(lhs)), m_rhs(std::move(rhs)) {}
218+
219+ llvm::Expected<lldb::ValueObjectSP> Accept (Visitor *v) const override ;
220+
221+ BinaryOpKind GetKind () const { return m_kind; }
222+ ASTNode *GetLHS () const { return m_lhs.get (); }
223+ ASTNode *GetRHS () const { return m_rhs.get (); }
224+
225+ static bool classof (const ASTNode *node) {
226+ return node->GetKind () == NodeKind::eBinaryOpNode;
227+ }
228+
229+ private:
230+ BinaryOpKind m_kind;
231+ ASTNodeUP m_lhs;
232+ ASTNodeUP m_rhs;
233+ };
234+
181235// / This class contains one Visit method for each specialized type of
182236// / DIL AST node. The Visit methods are used to dispatch a DIL AST node to
183237// / the correct function in the DIL expression evaluator for evaluating that
@@ -195,6 +249,10 @@ class Visitor {
195249 Visit (const ArraySubscriptNode *node) = 0 ;
196250 virtual llvm::Expected<lldb::ValueObjectSP>
197251 Visit (const BitFieldExtractionNode *node) = 0 ;
252+ virtual llvm::Expected<lldb::ValueObjectSP>
253+ Visit (const ScalarLiteralNode *node) = 0 ;
254+ virtual llvm::Expected<lldb::ValueObjectSP>
255+ Visit (const BinaryOpNode *node) = 0 ;
198256};
199257
200258} // namespace lldb_private::dil
0 commit comments