LLDB mainline
DILEval.h
Go to the documentation of this file.
1//===-- DILEval.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_DILEVAL_H
10#define LLDB_VALUEOBJECT_DILEVAL_H
11
14#include "llvm/ADT/StringRef.h"
15#include "llvm/Support/Error.h"
16#include <memory>
17#include <vector>
18
19namespace lldb_private::dil {
20
21/// Given the name of an identifier (variable name, member name, type name,
22/// etc.), find the ValueObject for that name (if it exists), excluding global
23/// variables, and create and return an IdentifierInfo object containing all
24/// the relevant information about that object (for DIL parsing and
25/// evaluating).
26lldb::ValueObjectSP LookupIdentifier(llvm::StringRef name_ref,
27 std::shared_ptr<StackFrame> frame_sp,
28 lldb::DynamicValueType use_dynamic);
29
30/// Given the name of an identifier, check to see if it matches the name of a
31/// global variable. If so, find the ValueObject for that global variable, and
32/// create and return an IdentifierInfo object containing all the relevant
33/// informatin about it.
34lldb::ValueObjectSP LookupGlobalIdentifier(llvm::StringRef name_ref,
35 std::shared_ptr<StackFrame> frame_sp,
36 lldb::TargetSP target_sp,
37 lldb::DynamicValueType use_dynamic);
38
40public:
41 Interpreter(lldb::TargetSP target, llvm::StringRef expr,
42 std::shared_ptr<StackFrame> frame_sp,
43 lldb::DynamicValueType use_dynamic, uint32_t options);
44
45 /// Evaluate an ASTNode.
46 /// \returns A non-null lldb::ValueObjectSP or an Error.
47 llvm::Expected<lldb::ValueObjectSP> Evaluate(const ASTNode &node);
48
49private:
50 /// Evaluate an ASTNode. If the result is a reference, it is also
51 /// dereferenced using ValueObject::Dereference.
52 /// \returns A non-null lldb::ValueObjectSP or an Error.
53 llvm::Expected<lldb::ValueObjectSP>
55 llvm::Expected<lldb::ValueObjectSP>
56 Visit(const IdentifierNode &node) override;
57 llvm::Expected<lldb::ValueObjectSP> Visit(const MemberOfNode &node) override;
58 llvm::Expected<lldb::ValueObjectSP> Visit(const UnaryOpNode &node) override;
59 llvm::Expected<lldb::ValueObjectSP> Visit(const BinaryOpNode &node) override;
60 llvm::Expected<lldb::ValueObjectSP>
61 Visit(const ArraySubscriptNode &node) override;
62 llvm::Expected<lldb::ValueObjectSP>
63 Visit(const BitFieldExtractionNode &node) override;
64 llvm::Expected<lldb::ValueObjectSP>
65 Visit(const IntegerLiteralNode &node) override;
66 llvm::Expected<lldb::ValueObjectSP>
67 Visit(const FloatLiteralNode &node) override;
68 llvm::Expected<lldb::ValueObjectSP>
69 Visit(const BooleanLiteralNode &node) override;
70 llvm::Expected<lldb::ValueObjectSP> Visit(const CastNode &node) override;
71
72 /// Perform usual unary conversions on a value. At the moment this
73 /// includes array-to-pointer and integral promotion for eligible types.
74 llvm::Expected<lldb::ValueObjectSP>
75 UnaryConversion(lldb::ValueObjectSP valobj, uint32_t location);
76
77 /// If `lhs_type` is unsigned and `rhs_type` is signed, check whether it
78 /// can represent all of the values of `lhs_type`.
79 /// If not, then promote `rhs_type` to the unsigned version of its type.
80 /// This expects that Rank(lhs_type) < Rank(rhs_type).
81 /// \returns Unchanged `rhs_type` or promoted unsigned version.
82 llvm::Expected<CompilerType> PromoteSignedInteger(CompilerType &lhs_type,
83 CompilerType &rhs_type);
84
85 /// Perform an arithmetic conversion on two values from an arithmetic
86 /// operation.
87 /// \returns The result type of an arithmetic operation.
88 llvm::Expected<CompilerType> ArithmeticConversion(lldb::ValueObjectSP &lhs,
90 uint32_t location);
91 /// Add or subtract the offset to the pointer according to the pointee type
92 /// byte size.
93 /// \returns A new `ValueObject` with a new pointer value.
94 llvm::Expected<lldb::ValueObjectSP> PointerOffset(lldb::ValueObjectSP ptr,
96 BinaryOpKind operation,
97 uint32_t location);
98 llvm::Expected<lldb::ValueObjectSP> EvaluateScalarOp(BinaryOpKind kind,
101 CompilerType result_type,
102 uint32_t location);
103 llvm::Expected<lldb::ValueObjectSP>
105 uint32_t location);
106 llvm::Expected<lldb::ValueObjectSP>
108 uint32_t location);
109 llvm::Expected<CompilerType>
111 std::shared_ptr<ExecutionContextScope> ctx,
112 const IntegerLiteralNode &literal);
113
114 /// A helper function for VerifyCastType (below). This performs
115 /// arithmetic-specific checks. It should only be called if the target_type
116 /// is a scalar type.
117 llvm::Expected<CastKind> VerifyArithmeticCast(CompilerType source_type,
118 CompilerType target_type,
119 int location);
120
121 /// As a preparation for type casting, compare the requested 'target' type
122 /// of the cast with the type of the operand to be cast. If the cast is
123 /// allowed, return the appropriate CastKind for the cast; otherwise return
124 /// an error.
125 llvm::Expected<CastKind> VerifyCastType(lldb::ValueObjectSP operand,
126 CompilerType source_type,
127 CompilerType target_type,
128 int location);
129
130 // Used by the interpreter to create objects, perform casts, etc.
132 llvm::StringRef m_expr;
134 std::shared_ptr<StackFrame> m_exe_ctx_scope;
139 // TODO: Remove 'maybe_unused' when next PR, using this, gets submitted.
140 [[maybe_unused]] bool m_allow_var_updates;
141};
142
143} // namespace lldb_private::dil
144
145#endif // LLDB_VALUEOBJECT_DILEVAL_H
Generic representation of a type in a programming language.
The rest of the classes in this file, except for the Visitor class at the very end,...
Definition DILAST.h:74
std::shared_ptr< StackFrame > m_exe_ctx_scope
Definition DILEval.h:134
llvm::Expected< lldb::ValueObjectSP > Evaluate(const ASTNode &node)
Evaluate an ASTNode.
Definition DILEval.cpp:410
llvm::Expected< lldb::ValueObjectSP > EvaluateBinaryAddition(lldb::ValueObjectSP lhs, lldb::ValueObjectSP rhs, uint32_t location)
Definition DILEval.cpp:617
llvm::Expected< lldb::ValueObjectSP > EvaluateAndDereference(const ASTNode &node)
Evaluate an ASTNode.
Definition DILEval.cpp:423
llvm::Expected< lldb::ValueObjectSP > PointerOffset(lldb::ValueObjectSP ptr, lldb::ValueObjectSP offset, BinaryOpKind operation, uint32_t location)
Add or subtract the offset to the pointer according to the pointee type byte size.
Definition DILEval.cpp:554
llvm::Expected< lldb::ValueObjectSP > EvaluateScalarOp(BinaryOpKind kind, lldb::ValueObjectSP lhs, lldb::ValueObjectSP rhs, CompilerType result_type, uint32_t location)
Definition DILEval.cpp:591
llvm::Expected< CompilerType > PromoteSignedInteger(CompilerType &lhs_type, CompilerType &rhs_type)
If lhs_type is unsigned and rhs_type is signed, check whether it can represent all of the values of l...
Definition DILEval.cpp:190
llvm::Expected< lldb::ValueObjectSP > EvaluateBinarySubtraction(lldb::ValueObjectSP lhs, lldb::ValueObjectSP rhs, uint32_t location)
Definition DILEval.cpp:655
llvm::Expected< lldb::ValueObjectSP > UnaryConversion(lldb::ValueObjectSP valobj, uint32_t location)
Perform usual unary conversions on a value.
Definition DILEval.cpp:68
llvm::Expected< lldb::ValueObjectSP > Visit(const IdentifierNode &node) override
Definition DILEval.cpp:439
lldb::ValueObjectSP m_scope
Definition DILEval.h:133
llvm::Expected< CompilerType > PickIntegerType(lldb::TypeSystemSP type_system, std::shared_ptr< ExecutionContextScope > ctx, const IntegerLiteralNode &literal)
Definition DILEval.cpp:1075
Interpreter(lldb::TargetSP target, llvm::StringRef expr, std::shared_ptr< StackFrame > frame_sp, lldb::DynamicValueType use_dynamic, uint32_t options)
Definition DILEval.cpp:389
lldb::DynamicValueType m_use_dynamic
Definition DILEval.h:135
llvm::Expected< CompilerType > ArithmeticConversion(lldb::ValueObjectSP &lhs, lldb::ValueObjectSP &rhs, uint32_t location)
Perform an arithmetic conversion on two values from an arithmetic operation.
Definition DILEval.cpp:219
llvm::Expected< CastKind > VerifyCastType(lldb::ValueObjectSP operand, CompilerType source_type, CompilerType target_type, int location)
As a preparation for type casting, compare the requested 'target' type of the cast with the type of t...
Definition DILEval.cpp:1234
llvm::Expected< CastKind > VerifyArithmeticCast(CompilerType source_type, CompilerType target_type, int location)
A helper function for VerifyCastType (below).
Definition DILEval.cpp:1171
This class contains one Visit method for each specialized type of DIL AST node.
Definition DILAST.h:319
BinaryOpKind
The binary operators recognized by DIL.
Definition DILAST.h:44
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
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
std::shared_ptr< lldb_private::TypeSystem > TypeSystemSP
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
std::shared_ptr< lldb_private::Target > TargetSP