Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions lldb/include/lldb/ValueObject/DILAST.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#ifndef LLDB_VALUEOBJECT_DILAST_H
#define LLDB_VALUEOBJECT_DILAST_H

#include "lldb/ValueObject/DILLexer.h"
#include "lldb/ValueObject/ValueObject.h"
#include "llvm/Support/Error.h"
#include <cstdint>
Expand All @@ -19,10 +20,12 @@ namespace lldb_private::dil {
/// The various types DIL AST nodes (used by the DIL parser).
enum class NodeKind {
eArraySubscriptNode,
eBinaryOpNode,
eBitExtractionNode,
eErrorNode,
eIdentifierNode,
eMemberOfNode,
eScalarLiteralNode,
eUnaryOpNode,
};

Expand All @@ -32,6 +35,14 @@ enum class UnaryOpKind {
Deref, // "*"
};

enum class BinaryOpKind {
Add, // "+"
Sub, // "-"
};

/// Translates DIL tokens to BinaryOpKind.
BinaryOpKind GetBinaryOpKindFromToken(Token::Kind token_kind);

/// Forward declaration, for use in DIL AST nodes. Definition is at the very
/// end of this file.
class Visitor;
Expand Down Expand Up @@ -178,6 +189,49 @@ class BitFieldExtractionNode : public ASTNode {
int64_t m_last_index;
};

class ScalarLiteralNode : public ASTNode {
public:
ScalarLiteralNode(uint32_t location, lldb::BasicType type, Scalar value)
: ASTNode(location, NodeKind::eScalarLiteralNode), m_type(type),
m_value(value) {}

llvm::Expected<lldb::ValueObjectSP> Accept(Visitor *v) const override;

lldb::BasicType GetType() const { return m_type; }
Scalar GetValue() const & { return m_value; }

static bool classof(const ASTNode *node) {
return node->GetKind() == NodeKind::eScalarLiteralNode;
}

private:
lldb::BasicType m_type;
Scalar m_value;
};

class BinaryOpNode : public ASTNode {
public:
BinaryOpNode(uint32_t location, BinaryOpKind kind, ASTNodeUP lhs,
ASTNodeUP rhs)
: ASTNode(location, NodeKind::eBinaryOpNode), m_kind(kind),
m_lhs(std::move(lhs)), m_rhs(std::move(rhs)) {}

llvm::Expected<lldb::ValueObjectSP> Accept(Visitor *v) const override;

BinaryOpKind GetKind() const { return m_kind; }
ASTNode *GetLHS() const { return m_lhs.get(); }
ASTNode *GetRHS() const { return m_rhs.get(); }

static bool classof(const ASTNode *node) {
return node->GetKind() == NodeKind::eBinaryOpNode;
}

private:
BinaryOpKind m_kind;
ASTNodeUP m_lhs;
ASTNodeUP m_rhs;
};

/// This class contains one Visit method for each specialized type of
/// DIL AST node. The Visit methods are used to dispatch a DIL AST node to
/// the correct function in the DIL expression evaluator for evaluating that
Expand All @@ -195,6 +249,10 @@ class Visitor {
Visit(const ArraySubscriptNode *node) = 0;
virtual llvm::Expected<lldb::ValueObjectSP>
Visit(const BitFieldExtractionNode *node) = 0;
virtual llvm::Expected<lldb::ValueObjectSP>
Visit(const ScalarLiteralNode *node) = 0;
virtual llvm::Expected<lldb::ValueObjectSP>
Visit(const BinaryOpNode *node) = 0;
};

} // namespace lldb_private::dil
Expand Down
11 changes: 11 additions & 0 deletions lldb/include/lldb/ValueObject/DILEval.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ class Interpreter : Visitor {
Visit(const ArraySubscriptNode *node) override;
llvm::Expected<lldb::ValueObjectSP>
Visit(const BitFieldExtractionNode *node) override;
llvm::Expected<lldb::ValueObjectSP>
Visit(const ScalarLiteralNode *node) override;
llvm::Expected<lldb::ValueObjectSP> Visit(const BinaryOpNode *node) override;

lldb::ValueObjectSP
ConvertValueObjectToTypeSystem(lldb::ValueObjectSP valobj,
lldb::TypeSystemSP type_system);

llvm::Expected<lldb::ValueObjectSP>
EvaluateBinaryAddition(lldb::ValueObjectSP lhs, lldb::ValueObjectSP rhs,
uint32_t location, std::shared_ptr<StackFrame> ctx);

// Used by the interpreter to create objects, perform casts, etc.
lldb::TargetSP m_target;
Expand Down
1 change: 1 addition & 0 deletions lldb/include/lldb/ValueObject/DILLexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Token {
minus,
numeric_constant,
period,
plus,
r_paren,
r_square,
star,
Expand Down
3 changes: 3 additions & 0 deletions lldb/include/lldb/ValueObject/DILParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class DILParser {
ASTNodeUP Run();

ASTNodeUP ParseExpression();
ASTNodeUP ParseAdditiveExpression();
ASTNodeUP ParseUnaryExpression();
ASTNodeUP ParsePostfixExpression();
ASTNodeUP ParsePrimaryExpression();
Expand All @@ -96,6 +97,8 @@ class DILParser {
std::string ParseIdExpression();
std::string ParseUnqualifiedId();
std::optional<int64_t> ParseIntegerConstant();
ASTNodeUP ParseNumericLiteral();
ASTNodeUP ParseNumericConstant();

void BailOut(const std::string &error, uint32_t loc, uint16_t err_len);

Expand Down
21 changes: 21 additions & 0 deletions lldb/source/ValueObject/DILAST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@

namespace lldb_private::dil {

BinaryOpKind GetBinaryOpKindFromToken(Token::Kind token_kind) {
switch (token_kind) {
case Token::minus:
return BinaryOpKind::Sub;
case Token::plus:
return BinaryOpKind::Add;
default:
break;
}
llvm_unreachable("Unknown binary operator kind.");
}

llvm::Expected<lldb::ValueObjectSP> ErrorNode::Accept(Visitor *v) const {
llvm_unreachable("Attempting to Visit a DIL ErrorNode.");
}
Expand All @@ -37,4 +49,13 @@ BitFieldExtractionNode::Accept(Visitor *v) const {
return v->Visit(this);
}

llvm::Expected<lldb::ValueObjectSP>
ScalarLiteralNode::Accept(Visitor *v) const {
return v->Visit(this);
}

llvm::Expected<lldb::ValueObjectSP> BinaryOpNode::Accept(Visitor *v) const {
return v->Visit(this);
}

} // namespace lldb_private::dil
Loading
Loading