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 a persistent identifier (i.e., one that starts with a $),
22/// find the ValueObject for that name (if it exists).
23lldb::ValueObjectSP LookupPersistentIdentifier(llvm::StringRef name_ref,
24 StackFrame &stack_frame,
25 lldb::TargetSP target_sp,
26 lldb::LanguageType language);
27
28/// Given the name of an identifier (variable name, member name, type name,
29/// etc.), find the ValueObject for that name (if it exists), excluding global
30/// variables, and create and return an IdentifierInfo object containing all
31/// the relevant information about that object (for DIL parsing and
32/// evaluating).
33lldb::ValueObjectSP LookupIdentifier(llvm::StringRef name_ref,
34 StackFrame &stack_frame,
35 lldb::DynamicValueType use_dynamic);
36
37/// Given the name of an identifier, check to see if it matches the name of a
38/// global variable. If so, find the ValueObject for that global variable, and
39/// create and return an IdentifierInfo object containing all the relevant
40/// information about it.
41lldb::ValueObjectSP LookupGlobalIdentifier(llvm::StringRef name_ref,
42 StackFrame &stack_frame,
43 lldb::TargetSP target_sp,
44 lldb::DynamicValueType use_dynamic);
45
46/// Given the name of an identifier, attempt to find an enumeration value.
47/// If found, return a ValueObject with a const scalar value of the enum.
48lldb::ValueObjectSP LookupEnumValue(llvm::StringRef name_ref,
49 ExecutionContextScope &ctx_scope);
50
52public:
53 Interpreter(lldb::TargetSP target, llvm::StringRef expr,
54 StackFrame &stack_frame, lldb::DynamicValueType use_dynamic,
55 uint32_t options);
56
57 /// Evaluate an ASTNode tree.
58 /// \returns A non-null lldb::ValueObjectSP or an Error.
59 llvm::Expected<lldb::ValueObjectSP> EvaluateTree(const ASTNodeUP &tree);
60
61private:
62 /// Evaluate an ASTNode.
63 /// \returns A non-null lldb::ValueObjectSP or an Error.
64 llvm::Expected<lldb::ValueObjectSP> Evaluate(const ASTNode &node);
65 /// Evaluate an ASTNode. If the result is a reference, it is also
66 /// dereferenced using ValueObject::Dereference.
67 /// \returns A non-null lldb::ValueObjectSP or an Error.
68 llvm::Expected<lldb::ValueObjectSP>
70 llvm::Expected<lldb::ValueObjectSP>
71 Visit(const IdentifierNode &node) override;
72 llvm::Expected<lldb::ValueObjectSP> Visit(const MemberOfNode &node) override;
73 llvm::Expected<lldb::ValueObjectSP> Visit(const UnaryOpNode &node) override;
74 llvm::Expected<lldb::ValueObjectSP> Visit(const BinaryOpNode &node) override;
75 llvm::Expected<lldb::ValueObjectSP>
76 Visit(const ArraySubscriptNode &node) override;
77 llvm::Expected<lldb::ValueObjectSP>
78 Visit(const BitFieldExtractionNode &node) override;
79 llvm::Expected<lldb::ValueObjectSP>
80 Visit(const IntegerLiteralNode &node) override;
81 llvm::Expected<lldb::ValueObjectSP>
82 Visit(const FloatLiteralNode &node) override;
83 llvm::Expected<lldb::ValueObjectSP>
84 Visit(const BooleanLiteralNode &node) override;
85 llvm::Expected<lldb::ValueObjectSP> Visit(const CastNode &node) override;
86 llvm::Expected<lldb::ValueObjectSP>
87 Visit(const ConditionalNode &node) override;
88 llvm::Expected<lldb::ValueObjectSP> Visit(const SizeOfNode &node) override;
89
90 /// Perform usual unary conversions on a value. At the moment this
91 /// includes array-to-pointer and integral promotion for eligible types.
92 llvm::Expected<lldb::ValueObjectSP>
93 UnaryConversion(lldb::ValueObjectSP valobj, uint32_t location);
94
95 /// If `lhs_type` is unsigned and `rhs_type` is signed, check whether it
96 /// can represent all of the values of `lhs_type`.
97 /// If not, then promote `rhs_type` to the unsigned version of its type.
98 /// This expects that Rank(lhs_type) < Rank(rhs_type).
99 /// \returns Unchanged `rhs_type` or promoted unsigned version.
100 llvm::Expected<CompilerType> PromoteSignedInteger(CompilerType &lhs_type,
101 CompilerType &rhs_type);
102
103 /// Perform an arithmetic conversion on two values from an arithmetic
104 /// operation.
105 llvm::Expected<CompilerType> ArithmeticConversion(lldb::ValueObjectSP &lhs,
107 uint32_t location);
108
109 /// Add or subtract the offset to the pointer according to the pointee type
110 /// byte size.
111 /// \returns A new `ValueObject` with a new pointer value.
112 llvm::Expected<lldb::ValueObjectSP> PointerOffset(lldb::ValueObjectSP ptr,
113 lldb::ValueObjectSP offset,
114 BinaryOpKind operation,
115 uint32_t location);
116
117 llvm::Expected<lldb::ValueObjectSP> EvaluateScalarOp(BinaryOpKind kind,
120 CompilerType result_type,
121 uint32_t location);
123 lldb::ValueObjectSP &rhs, bool lhs_is_literal,
124 bool rhs_is_literal, uint32_t location);
125 llvm::Expected<lldb::ValueObjectSP>
127 lldb::ValueObjectSP rhs, bool lhs_is_literal,
128 bool rhs_is_literal, uint32_t location);
129 llvm::Expected<lldb::ValueObjectSP>
131 lldb::ValueObjectSP rhs, uint32_t location);
132 llvm::Expected<lldb::ValueObjectSP>
134 uint32_t location);
135
136 llvm::Expected<lldb::ValueObjectSP>
138 uint32_t location);
139
140 llvm::Expected<lldb::ValueObjectSP>
142 uint32_t location);
143 llvm::Expected<lldb::ValueObjectSP>
145 uint32_t location);
146 llvm::Expected<lldb::ValueObjectSP>
148 uint32_t location);
149 llvm::Expected<lldb::ValueObjectSP>
151 lldb::ValueObjectSP rhs, uint32_t location);
152 llvm::Expected<lldb::ValueObjectSP> EvaluateLogical(const BinaryOpNode &node);
153 llvm::Expected<CompilerType>
155 const IntegerLiteralNode &literal);
156
157 llvm::Expected<lldb::ValueObjectSP>
159 uint32_t location);
160
161 /// A helper function for VerifyCastType (below). This performs
162 /// arithmetic-specific checks. It should only be called if the target_type
163 /// is a scalar type.
164 llvm::Expected<CastKind> VerifyArithmeticCast(CompilerType source_type,
165 CompilerType target_type,
166 int location);
167
168 /// As a preparation for type casting, compare the requested 'target' type
169 /// of the cast with the type of the operand to be cast. If the cast is
170 /// allowed, return the appropriate CastKind for the cast; otherwise return
171 /// an error.
172 llvm::Expected<CastKind> VerifyCastType(lldb::ValueObjectSP operand,
173 CompilerType source_type,
174 CompilerType target_type,
175 int location);
176
177 // Used by the interpreter to create objects, perform casts, etc.
179 llvm::StringRef m_expr;
186 bool m_allow_globals = true;
187};
188
189} // namespace lldb_private::dil
190
191#endif // LLDB_VALUEOBJECT_DILEVAL_H
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
The rest of the classes in this file, except for the Visitor class at the very end,...
Definition DILAST.h:105
llvm::Expected< lldb::ValueObjectSP > EvaluateBinaryRemainder(lldb::ValueObjectSP lhs, lldb::ValueObjectSP rhs, uint32_t location)
Definition DILEval.cpp:970
llvm::Error ValidateComparison(BinaryOpKind kind, lldb::ValueObjectSP &lhs, lldb::ValueObjectSP &rhs, bool lhs_is_literal, bool rhs_is_literal, uint32_t location)
Definition DILEval.cpp:1062
llvm::Expected< lldb::ValueObjectSP > Evaluate(const ASTNode &node)
Evaluate an ASTNode.
Definition DILEval.cpp:478
llvm::Expected< lldb::ValueObjectSP > EvaluateBinaryAddition(lldb::ValueObjectSP lhs, lldb::ValueObjectSP rhs, uint32_t location)
Definition DILEval.cpp:805
llvm::Expected< lldb::ValueObjectSP > EvaluateAndDereference(const ASTNode &node)
Evaluate an ASTNode.
Definition DILEval.cpp:491
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:707
llvm::Expected< lldb::ValueObjectSP > EvaluateScalarOp(BinaryOpKind kind, lldb::ValueObjectSP lhs, lldb::ValueObjectSP rhs, CompilerType result_type, uint32_t location)
Definition DILEval.cpp:743
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:204
llvm::Expected< lldb::ValueObjectSP > EvaluateBinaryShift(BinaryOpKind kind, lldb::ValueObjectSP lhs, lldb::ValueObjectSP rhs, uint32_t location)
Definition DILEval.cpp:1253
llvm::Expected< lldb::ValueObjectSP > EvaluateLogical(const BinaryOpNode &node)
Definition DILEval.cpp:1293
llvm::Expected< lldb::ValueObjectSP > EvaluateTree(const ASTNodeUP &tree)
Evaluate an ASTNode tree.
Definition DILEval.cpp:463
llvm::Expected< lldb::ValueObjectSP > EvaluateBinarySubtraction(lldb::ValueObjectSP lhs, lldb::ValueObjectSP rhs, uint32_t location)
Definition DILEval.cpp:843
llvm::Expected< lldb::ValueObjectSP > UnaryConversion(lldb::ValueObjectSP valobj, uint32_t location)
Perform usual unary conversions on a value.
Definition DILEval.cpp:73
llvm::Expected< lldb::ValueObjectSP > EvaluateComparison(BinaryOpKind kind, lldb::ValueObjectSP lhs, lldb::ValueObjectSP rhs, bool lhs_is_literal, bool rhs_is_literal, uint32_t location)
Definition DILEval.cpp:1206
llvm::Expected< lldb::ValueObjectSP > Visit(const IdentifierNode &node) override
Definition DILEval.cpp:507
lldb::ValueObjectSP m_scope
Definition DILEval.h:180
llvm::Expected< lldb::ValueObjectSP > EvaluateBinaryDivision(lldb::ValueObjectSP lhs, lldb::ValueObjectSP rhs, uint32_t location)
Definition DILEval.cpp:942
lldb::DynamicValueType m_use_dynamic
Definition DILEval.h:182
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:231
llvm::Expected< lldb::ValueObjectSP > EvaluateBinaryMultiplication(lldb::ValueObjectSP lhs, lldb::ValueObjectSP rhs, uint32_t location)
Definition DILEval.cpp:920
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:1980
Interpreter(lldb::TargetSP target, llvm::StringRef expr, StackFrame &stack_frame, lldb::DynamicValueType use_dynamic, uint32_t options)
Definition DILEval.cpp:441
llvm::Expected< CompilerType > PickIntegerType(lldb::TypeSystemSP type_system, ExecutionContextScope &ctx, const IntegerLiteralNode &literal)
Definition DILEval.cpp:1814
llvm::Expected< lldb::ValueObjectSP > EvaluateAssignment(lldb::ValueObjectSP lhs, lldb::ValueObjectSP rhs, uint32_t location)
Definition DILEval.cpp:1037
llvm::Expected< CastKind > VerifyArithmeticCast(CompilerType source_type, CompilerType target_type, int location)
A helper function for VerifyCastType (below).
Definition DILEval.cpp:1913
llvm::Expected< lldb::ValueObjectSP > EvaluateBinaryBitwise(BinaryOpKind kind, lldb::ValueObjectSP lhs, lldb::ValueObjectSP rhs, uint32_t location)
Definition DILEval.cpp:1231
This class contains one Visit method for each specialized type of DIL AST node.
Definition DILAST.h:402
lldb::ValueObjectSP LookupPersistentIdentifier(llvm::StringRef name_ref, StackFrame &stack_frame, lldb::TargetSP target_sp, lldb::LanguageType language)
Given the name of a persistent identifier (i.e., one that starts with a $), find the ValueObject for ...
Definition DILEval.cpp:354
lldb::ValueObjectSP LookupIdentifier(llvm::StringRef name_ref, StackFrame &stack_frame, lldb::DynamicValueType use_dynamic)
Given the name of an identifier (variable name, member name, type name, etc.), find the ValueObject f...
Definition DILEval.cpp:368
std::unique_ptr< ASTNode > ASTNodeUP
Definition DILAST.h:123
BinaryOpKind
The binary operators recognized by DIL.
Definition DILAST.h:48
lldb::ValueObjectSP LookupGlobalIdentifier(llvm::StringRef name_ref, StackFrame &stack_frame, 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:312
lldb::ValueObjectSP LookupEnumValue(llvm::StringRef name_ref, ExecutionContextScope &ctx_scope)
Given the name of an identifier, attempt to find an enumeration value.
Definition DILEval.cpp:416
std::shared_ptr< lldb_private::TypeSystem > TypeSystemSP
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
LanguageType
Programming language type.
std::shared_ptr< lldb_private::Target > TargetSP