Skip to content
Open
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
28 changes: 25 additions & 3 deletions lldb/docs/dil-expr-lang.ebnf
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
(* This is currently a subset of the final DIL Language, matching the current
DIL implementation. *)

expression = unary_expression ;
expression = cast_expression;

cast_expression = unary_expression
| "(" type_id ")" cast_expression;

unary_expression = postfix_expression
| unary_operator expression ;
| unary_operator cast_expression ;

unary_operator = "*" | "&" ;

Expand Down Expand Up @@ -44,10 +47,28 @@ nested_name_specifier = type_name "::"
| namespace_name '::'
| nested_name_specifier identifier "::" ;

type_id = type_specifier_seq [abstract_declarator] ;

type_specifier_seq = type_specifier [type_specifier];

type_specifier = ["::"] [nested_name_specifier] type_name
| builtin_typename ;

nested_name_specifier = type_name "::"
| namespace_name "::"
| nested_name_specifier identifier "::" ;

abstract_declarator = ptr_operator [abstract_declarator] ;

ptr_operator = "*"
| "&";

type_name = class_name
| enum_name
| typedef_name;

builtin_typename = identifier_seq;

class_name = identifier ;

enum_name = identifier ;
Expand All @@ -56,6 +77,7 @@ typedef_name = identifier ;

namespace_name = identifier ;


identifier_seq = identifier
| identifier identifier_seq;


41 changes: 41 additions & 0 deletions lldb/include/lldb/ValueObject/DILAST.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ enum class NodeKind {
eArraySubscriptNode,
eBitExtractionNode,
eBooleanLiteralNode,
eCStyleCastNode,
eErrorNode,
eFloatLiteralNode,
eIdentifierNode,
Expand All @@ -29,6 +30,21 @@ enum class NodeKind {
eUnaryOpNode,
};

/// The C-Style casts allowed by DIL.
enum class CStyleCastKind {
eEnumeration,
eNullptr,
eReference,
eNone,
};

/// Promotions for C-Style casts in DIL.
enum class CastPromoKind {
eArithmetic,
ePointer,
eNone,
};

/// The Unary operators recognized by DIL.
enum class UnaryOpKind {
AddrOf, // "&"
Expand Down Expand Up @@ -244,6 +260,29 @@ class BooleanLiteralNode : public ASTNode {
bool m_value;
};

class CStyleCastNode : public ASTNode {
public:
CStyleCastNode(uint32_t location, CompilerType type, ASTNodeUP operand,
CStyleCastKind kind)
: ASTNode(location, NodeKind::eCStyleCastNode), m_type(type),
m_operand(std::move(operand)), m_cast_kind(kind) {}

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

CompilerType GetType() const { return m_type; }
ASTNode *GetOperand() const { return m_operand.get(); }
CStyleCastKind GetCastKind() const { return m_cast_kind; }

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

private:
CompilerType m_type;
ASTNodeUP m_operand;
CStyleCastKind m_cast_kind;
};

/// 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 @@ -267,6 +306,8 @@ class Visitor {
Visit(const FloatLiteralNode *node) = 0;
virtual llvm::Expected<lldb::ValueObjectSP>
Visit(const BooleanLiteralNode *node) = 0;
virtual llvm::Expected<lldb::ValueObjectSP>
Visit(const CStyleCastNode *node) = 0;
};

} // namespace lldb_private::dil
Expand Down
7 changes: 7 additions & 0 deletions lldb/include/lldb/ValueObject/DILEval.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,19 @@ class Interpreter : Visitor {
Visit(const FloatLiteralNode *node) override;
llvm::Expected<lldb::ValueObjectSP>
Visit(const BooleanLiteralNode *node) override;
llvm::Expected<lldb::ValueObjectSP>
Visit(const CStyleCastNode *node) override;

llvm::Expected<CompilerType>
PickIntegerType(lldb::TypeSystemSP type_system,
std::shared_ptr<ExecutionContextScope> ctx,
const IntegerLiteralNode *literal);

llvm::Expected<CompilerType>
VerifyCStyleCastType(lldb::ValueObjectSP &operand, CompilerType &op_type,
CompilerType target_type, CastPromoKind &promo_kind,
CStyleCastKind &cast_kind, int location);

// Used by the interpreter to create objects, perform casts, etc.
lldb::TargetSP m_target;
llvm::StringRef m_expr;
Expand Down
13 changes: 13 additions & 0 deletions lldb/include/lldb/ValueObject/DILParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define LLDB_VALUEOBJECT_DILPARSER_H

#include "lldb/Target/ExecutionContextScope.h"
#include "lldb/Target/StackFrame.h"
#include "lldb/Utility/DiagnosticsRendering.h"
#include "lldb/Utility/Status.h"
#include "lldb/ValueObject/DILAST.h"
Expand All @@ -31,6 +32,9 @@ enum class ErrorCode : unsigned char {
kUnknown,
};

llvm::Expected<lldb::TypeSystemSP>
GetTypeSystemFromCU(std::shared_ptr<StackFrame> ctx);

// The following is modeled on class OptionParseError.
class DILDiagnosticError
: public llvm::ErrorInfo<DILDiagnosticError, DiagnosticError> {
Expand Down Expand Up @@ -101,6 +105,15 @@ class DILParser {
ASTNodeUP ParseFloatingPointLiteral();
ASTNodeUP ParseBooleanLiteral();

ASTNodeUP ParseCastExpression();
std::optional<CompilerType> ParseBuiltinType();
std::optional<CompilerType> ParseTypeId();
void ParseTypeSpecifierSeq(std::string &type_name);
bool ParseTypeSpecifier(std::string &user_type_name);
std::string ParseTypeName();
CompilerType ResolveTypeDeclarators(CompilerType type,
const std::vector<Token> &ptr_operators);

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

void Expect(Token::Kind kind);
Expand Down
4 changes: 4 additions & 0 deletions lldb/source/ValueObject/DILAST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,8 @@ BooleanLiteralNode::Accept(Visitor *v) const {
return v->Visit(this);
}

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

} // namespace lldb_private::dil
Loading
Loading