Skip to content

Commit 812ddfe

Browse files
committed
Another take on const
1 parent 25e2ff3 commit 812ddfe

File tree

4 files changed

+10
-20
lines changed

4 files changed

+10
-20
lines changed

clang/include/clang/Interpreter/Interpreter.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ class Interpreter {
187187

188188
// A cache for the compiled destructors used to for de-allocation of managed
189189
// clang::Values.
190-
llvm::DenseMap<CXXRecordDecl *, llvm::orc::ExecutorAddr> Dtors;
190+
mutable llvm::DenseMap<CXXRecordDecl *, llvm::orc::ExecutorAddr> Dtors;
191191

192192
std::array<Expr *, 4> ValuePrintingInfo;
193193

@@ -204,7 +204,8 @@ class Interpreter {
204204

205205
// When we deallocate clang::Value we need to run the destructor of the type.
206206
// This function forces emission of the needed dtor.
207-
llvm::Expected<llvm::orc::ExecutorAddr> CompileDtorCall(CXXRecordDecl *CXXRD);
207+
llvm::Expected<llvm::orc::ExecutorAddr>
208+
CompileDtorCall(CXXRecordDecl *CXXRD) const;
208209

209210
/// @}
210211
/// @name Code generation

clang/include/clang/Interpreter/Value.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class REPL_EXTERNAL_VISIBILITY Value {
111111
};
112112

113113
Value() = default;
114-
Value(Interpreter *In, void *Ty);
114+
Value(const Interpreter *In, void *Ty);
115115
Value(const Value &RHS);
116116
Value(Value &&RHS) noexcept;
117117
Value &operator=(const Value &RHS);
@@ -124,9 +124,7 @@ class REPL_EXTERNAL_VISIBILITY Value {
124124
void dump() const;
125125
void clear();
126126

127-
ASTContext &getASTContext();
128127
const ASTContext &getASTContext() const;
129-
Interpreter &getInterpreter();
130128
const Interpreter &getInterpreter() const;
131129
QualType getType() const;
132130

@@ -193,7 +191,7 @@ class REPL_EXTERNAL_VISIBILITY Value {
193191
}
194192
};
195193

196-
Interpreter *Interp = nullptr;
194+
const Interpreter *Interp = nullptr;
197195
void *OpaqueType = nullptr;
198196
Storage Data;
199197
Kind ValueKind = K_Unspecified;

clang/lib/Interpreter/InterpreterValuePrinter.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,7 @@ static std::string CharPtrToString(const char *Ptr) {
180180
namespace clang {
181181

182182
struct ValueRef : public Value {
183-
ValueRef(const Interpreter *In, void *Ty)
184-
: Value(const_cast<Interpreter *>(In), Ty) {
183+
ValueRef(const Interpreter *In, void *Ty) : Value(In, Ty) {
185184
// Tell the base class to not try to deallocate if it manages the value.
186185
IsManuallyAlloc = false;
187186
}
@@ -356,7 +355,7 @@ std::string Interpreter::ValueTypeToString(const Value &V) const {
356355
}
357356

358357
llvm::Expected<llvm::orc::ExecutorAddr>
359-
Interpreter::CompileDtorCall(CXXRecordDecl *CXXRD) {
358+
Interpreter::CompileDtorCall(CXXRecordDecl *CXXRD) const {
360359
assert(CXXRD && "Cannot compile a destructor for a nullptr");
361360
if (auto Dtor = Dtors.find(CXXRD); Dtor != Dtors.end())
362361
return Dtor->getSecond();

clang/lib/Interpreter/Value.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ static Value::Kind ConvertQualTypeToKind(const ASTContext &Ctx, QualType QT) {
120120
}
121121
}
122122

123-
Value::Value(Interpreter *In, void *Ty) : Interp(In), OpaqueType(Ty) {
124-
ASTContext &C = getASTContext();
123+
Value::Value(const Interpreter *In, void *Ty) : Interp(In), OpaqueType(Ty) {
124+
const ASTContext &C = getASTContext();
125125
setKind(ConvertQualTypeToKind(C, getType()));
126126
if (ValueKind == K_PtrOrObj) {
127127
QualType Canon = getType().getCanonicalType();
@@ -131,7 +131,7 @@ Value::Value(Interpreter *In, void *Ty) : Interp(In), OpaqueType(Ty) {
131131
Canon->isMemberPointerType())) {
132132
IsManuallyAlloc = true;
133133
// Compile dtor function.
134-
Interpreter &Interp = getInterpreter();
134+
const Interpreter &Interp = getInterpreter();
135135
void *DtorF = nullptr;
136136
size_t ElementsSize = 1;
137137
QualType DtorTy = getType();
@@ -236,20 +236,12 @@ QualType Value::getType() const {
236236
return QualType::getFromOpaquePtr(OpaqueType);
237237
}
238238

239-
Interpreter &Value::getInterpreter() {
240-
assert(Interp != nullptr &&
241-
"Can't get interpreter from a default constructed value");
242-
return *Interp;
243-
}
244-
245239
const Interpreter &Value::getInterpreter() const {
246240
assert(Interp != nullptr &&
247241
"Can't get interpreter from a default constructed value");
248242
return *Interp;
249243
}
250244

251-
ASTContext &Value::getASTContext() { return getInterpreter().getASTContext(); }
252-
253245
const ASTContext &Value::getASTContext() const {
254246
return getInterpreter().getASTContext();
255247
}

0 commit comments

Comments
 (0)