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.
58 /// \returns A non-null lldb::ValueObjectSP or an Error.
59 llvm::Expected<lldb::ValueObjectSP> Evaluate(const ASTNode &node);
60
61private:
62 /// Evaluate an ASTNode. If the result is a reference, it is also
63 /// dereferenced using ValueObject::Dereference.
64 /// \returns A non-null lldb::ValueObjectSP or an Error.
65 llvm::Expected<lldb::ValueObjectSP>
67 llvm::Expected<lldb::ValueObjectSP>
68 Visit(const IdentifierNode &node) override;
69 llvm::Expected<lldb::ValueObjectSP> Visit(const MemberOfNode &node) override;
70 llvm::Expected<lldb::ValueObjectSP> Visit(const UnaryOpNode &node) override;
71 llvm::Expected<lldb::ValueObjectSP> Visit(const BinaryOpNode &node) override;
72 llvm::Expected<lldb::ValueObjectSP>
73 Visit(const ArraySubscriptNode &node) override;
74 llvm::Expected<lldb::ValueObjectSP>
75 Visit(const BitFieldExtractionNode &node) override;
76 llvm::Expected<lldb::ValueObjectSP>
77 Visit(const IntegerLiteralNode &node) override;
78 llvm::Expected<lldb::ValueObjectSP>
79 Visit(const FloatLiteralNode &node) override;
80 llvm::Expected<lldb::ValueObjectSP>
81 Visit(const BooleanLiteralNode &node) override;
82 llvm::Expected<lldb::ValueObjectSP> Visit(const CastNode &node) override;
83 llvm::Expected<lldb::ValueObjectSP>
84 Visit(const ConditionalNode &node) override;
85 llvm::Expected<lldb::ValueObjectSP> Visit(const SizeOfNode &node) override;
86
87 /// Perform usual unary conversions on a value. At the moment this
88 /// includes array-to-pointer and integral promotion for eligible types.
89 llvm::Expected<lldb::ValueObjectSP>
90 UnaryConversion(lldb::ValueObjectSP valobj, uint32_t location);
91
92 /// If `lhs_type` is unsigned and `rhs_type` is signed, check whether it
93 /// can represent all of the values of `lhs_type`.
94 /// If not, then promote `rhs_type` to the unsigned version of its type.
95 /// This expects that Rank(lhs_type) < Rank(rhs_type).
96 /// \returns Unchanged `rhs_type` or promoted unsigned version.
97 llvm::Expected<CompilerType> PromoteSignedInteger(CompilerType &lhs_type,
98 CompilerType &rhs_type);
99
100 /// Perform an arithmetic conversion on two values from an arithmetic
101 /// operation.
102 llvm::Expected<CompilerType> ArithmeticConversion(lldb::ValueObjectSP &lhs,
104 uint32_t location);
105
106 /// Add or subtract the offset to the pointer according to the pointee type
107 /// byte size.
108 /// \returns A new `ValueObject` with a new pointer value.
109 llvm::Expected<lldb::ValueObjectSP> PointerOffset(lldb::ValueObjectSP ptr,
110 lldb::ValueObjectSP offset,
111 BinaryOpKind operation,
112 uint32_t location);
113
114 llvm::Expected<lldb::ValueObjectSP> EvaluateScalarOp(BinaryOpKind kind,
117 CompilerType result_type,
118 uint32_t location);
120 lldb::ValueObjectSP &rhs, bool lhs_is_literal,
121 bool rhs_is_literal, uint32_t location);
122 llvm::Expected<lldb::ValueObjectSP>
124 lldb::ValueObjectSP rhs, bool lhs_is_literal,
125 bool rhs_is_literal, uint32_t location);
126 llvm::Expected<lldb::ValueObjectSP>
128 lldb::ValueObjectSP rhs, uint32_t location);
129 llvm::Expected<lldb::ValueObjectSP>
131 uint32_t location);
132
133 llvm::Expected<lldb::ValueObjectSP>
135 uint32_t location);
136
137 llvm::Expected<lldb::ValueObjectSP>
139 uint32_t location);
140 llvm::Expected<lldb::ValueObjectSP>
142 uint32_t location);
143 llvm::Expected<lldb::ValueObjectSP>
145 uint32_t location);
146 llvm::Expected<lldb::ValueObjectSP>
148 lldb::ValueObjectSP rhs, uint32_t location);
149 llvm::Expected<lldb::ValueObjectSP> EvaluateLogical(const BinaryOpNode &node);
150 llvm::Expected<CompilerType>
152 const IntegerLiteralNode &literal);
153
154 llvm::Expected<lldb::ValueObjectSP>
156 uint32_t location);
157
158 /// A helper function for VerifyCastType (below). This performs
159 /// arithmetic-specific checks. It should only be called if the target_type
160 /// is a scalar type.
161 llvm::Expected<CastKind> VerifyArithmeticCast(CompilerType source_type,
162 CompilerType target_type,
163 int location);
164
165 /// As a preparation for type casting, compare the requested 'target' type
166 /// of the cast with the type of the operand to be cast. If the cast is
167 /// allowed, return the appropriate CastKind for the cast; otherwise return
168 /// an error.
169 llvm::Expected<CastKind> VerifyCastType(lldb::ValueObjectSP operand,
170 CompilerType source_type,
171 CompilerType target_type,
172 int location);
173
174 // Used by the interpreter to create objects, perform casts, etc.
176 llvm::StringRef m_expr;
183 bool m_allow_globals = true;
184};
185
186} // namespace lldb_private::dil
187
188#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:954
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:1046
llvm::Expected< lldb::ValueObjectSP > Evaluate(const ASTNode &node)
Evaluate an ASTNode.
Definition DILEval.cpp:462
llvm::Expected< lldb::ValueObjectSP > EvaluateBinaryAddition(lldb::ValueObjectSP lhs, lldb::ValueObjectSP rhs, uint32_t location)
Definition DILEval.cpp:789
llvm::Expected< lldb::ValueObjectSP > EvaluateAndDereference(const ASTNode &node)
Evaluate an ASTNode.
Definition DILEval.cpp:475
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:691
llvm::Expected< lldb::ValueObjectSP > EvaluateScalarOp(BinaryOpKind kind, lldb::ValueObjectSP lhs, lldb::ValueObjectSP rhs, CompilerType result_type, uint32_t location)
Definition DILEval.cpp:727
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:1237
llvm::Expected< lldb::ValueObjectSP > EvaluateLogical(const BinaryOpNode &node)
Definition DILEval.cpp:1277
llvm::Expected< lldb::ValueObjectSP > EvaluateBinarySubtraction(lldb::ValueObjectSP lhs, lldb::ValueObjectSP rhs, uint32_t location)
Definition DILEval.cpp:827
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:1190
llvm::Expected< lldb::ValueObjectSP > Visit(const IdentifierNode &node) override
Definition DILEval.cpp:491
lldb::ValueObjectSP m_scope
Definition DILEval.h:177
llvm::Expected< lldb::ValueObjectSP > EvaluateBinaryDivision(lldb::ValueObjectSP lhs, lldb::ValueObjectSP rhs, uint32_t location)
Definition DILEval.cpp:926
lldb::DynamicValueType m_use_dynamic
Definition DILEval.h:179
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:904
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:1964
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:1798
llvm::Expected< lldb::ValueObjectSP > EvaluateAssignment(lldb::ValueObjectSP lhs, lldb::ValueObjectSP rhs, uint32_t location)
Definition DILEval.cpp:1021
llvm::Expected< CastKind > VerifyArithmeticCast(CompilerType source_type, CompilerType target_type, int location)
A helper function for VerifyCastType (below).
Definition DILEval.cpp:1897
llvm::Expected< lldb::ValueObjectSP > EvaluateBinaryBitwise(BinaryOpKind kind, lldb::ValueObjectSP lhs, lldb::ValueObjectSP rhs, uint32_t location)
Definition DILEval.cpp:1215
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
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