clang: lib/Interpreter/InterpreterValuePrinter.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

24

25#include "llvm/Support/Error.h"

26#include "llvm/Support/raw_ostream.h"

27

28#include

29#include

30

31#include

32

34

36Interpreter::CompileDtorCall(CXXRecordDecl *CXXRD) {

37 assert(CXXRD && "Cannot compile a destructor for a nullptr");

38 if (auto Dtor = Dtors.find(CXXRD); Dtor != Dtors.end())

39 return Dtor->getSecond();

40

42 return llvm::orc::ExecutorAddr{};

43

46

47 llvm::StringRef Name =

50 if (!AddrOrErr)

51 return AddrOrErr.takeError();

52

53 Dtors[CXXRD] = *AddrOrErr;

54 return AddrOrErr;

55}

56

58

60 : public TypeVisitor<InterfaceKindVisitor, InterfaceKind> {

61

65

66public:

68 : S(S), E(E), Args(Args) {}

69

72 }

73

76 }

77

80 }

81

84 }

85

87 HandlePtrType(Ty);

89 }

90

92 HandlePtrType(Ty);

94 }

95

98 assert(!AddrOfE.isInvalid() && "Can not create unary expression");

99 Args.push_back(AddrOfE.get());

101 }

102

105 Args.push_back(E);

107 Args.push_back(E);

109 HandleIntegralOrEnumType(Ty);

111

112 }

113

115 }

116

118 HandleIntegralOrEnumType(Ty);

120 }

121

122private:

123

124

125 void HandleIntegralOrEnumType(const Type *Ty) {

132 assert(!CastedExpr.isInvalid() && "Cannot create cstyle cast expr");

133 Args.push_back(CastedExpr.get());

134 }

135

136 void HandlePtrType(const Type *Ty) {

141 assert(!CastedExpr.isInvalid() && "Can not create cstyle cast expression");

142 Args.push_back(CastedExpr.get());

143 }

144};

145

146

147

148

149

150

151

152

153

154

155

156

157

158

162

163

164 if (!ValuePrintingInfo[0]) {

165 assert(llvm::all_of(ValuePrintingInfo, [](Expr *E) { return E; }));

166

168 llvm::StringRef Name) -> llvm::Error {

171 RedeclarationKind::ForVisibleRedeclaration);

173 if (R.empty())

174 return llvm::make_errorllvm::StringError(

175 Name + " not found!", llvm::inconvertibleErrorCode());

176

179 return llvm::Error::success();

180 };

181 static constexpr llvm::StringRef Builtin[] = {

182 "__clang_Interpreter_SetValueNoAlloc",

183 "__clang_Interpreter_SetValueWithAlloc",

184 "__clang_Interpreter_SetValueCopyArr", "__ci_newtag"};

185 if (llvm::Error Err =

186 LookupInterface(ValuePrintingInfo[NoAlloc], Builtin[NoAlloc]))

187 return std::move(Err);

188

190 if (llvm::Error Err =

192 return std::move(Err);

193 if (llvm::Error Err =

195 return std::move(Err);

196 if (llvm::Error Err =

197 LookupInterface(ValuePrintingInfo[NewTag], Builtin[NewTag]))

198 return std::move(Err);

199 }

200 }

201

203

205

206

207 AdjustedArgs.push_back(

209

210

211

212

213 if (auto *EWC = llvm::dyn_cast_if_present(E))

214 E = EWC->getSubExpr();

215

218

219

223 }

224

225 Expr *TypeArg =

227

228 AdjustedArgs.push_back(TypeArg);

229

230

231

236 switch (Kind) {

238 LLVM_FALLTHROUGH;

240

244 assert(!AllocCall.isInvalid() && "Can't create runtime interface call!");

245

247

248

251 Dtor->addAttr(UsedAttr::CreateImplicit(Ctx));

254 }

255

256

258 const auto *ConstantArrTy =

259 cast(DesugaredTy.getTypePtr());

262 Expr *Args[] = {E, AllocCall.get(), ArrSizeExpr};

263 SetValueE =

266 }

270 true, SourceLocation(), Args,

274

275 assert(!CXXNewCall.isInvalid() &&

276 "Can't create runtime placement new call!");

277

279 false);

280 break;

281 }

282

284 SetValueE =

287 break;

288 }

289 default:

290 llvm_unreachable("Unhandled InterfaceKind");

291 }

292

293

295 return E;

296

297 return SetValueE.get();

298}

299

300}

301

302using namespace clang;

303

304

307 void *OpaqueType) {

310 return VRef.getPtr();

311}

312

314 void *This, void *OutVal, void *OpaqueType, ...) {

317 VRef = Value(I, OpaqueType);

319 return;

320

322 va_start(args, OpaqueType);

323

327 } else {

329 QT = ET->getDecl()->getIntegerType();

331 default:

332 llvm_unreachable("unknown type kind!");

333 break;

334

335 case BuiltinType::Bool:

336 VRef.setBool(va_arg(args, int));

337 break;

338 case BuiltinType::Char_S:

339 VRef.setChar_S(va_arg(args, int));

340 break;

341 case BuiltinType::SChar:

342 VRef.setSChar(va_arg(args, int));

343 break;

344 case BuiltinType::Char_U:

345 VRef.setChar_U(va_arg(args, unsigned));

346 break;

347 case BuiltinType::UChar:

348 VRef.setUChar(va_arg(args, unsigned));

349 break;

350 case BuiltinType::Short:

351 VRef.setShort(va_arg(args, int));

352 break;

353 case BuiltinType::UShort:

354 VRef.setUShort(va_arg(args, unsigned));

355 break;

356 case BuiltinType::Int:

357 VRef.setInt(va_arg(args, int));

358 break;

359 case BuiltinType::UInt:

360 VRef.setUInt(va_arg(args, unsigned));

361 break;

362 case BuiltinType::Long:

363 VRef.setLong(va_arg(args, long));

364 break;

365 case BuiltinType::ULong:

366 VRef.setULong(va_arg(args, unsigned long));

367 break;

368 case BuiltinType::LongLong:

369 VRef.setLongLong(va_arg(args, long long));

370 break;

371 case BuiltinType::ULongLong:

372 VRef.setULongLong(va_arg(args, unsigned long long));

373 break;

374

375 case BuiltinType::Float:

376 VRef.setFloat(va_arg(args, double));

377 break;

378 case BuiltinType::Double:

379 VRef.setDouble(va_arg(args, double));

380 break;

381 case BuiltinType::LongDouble:

382 VRef.setLongDouble(va_arg(args, long double));

383 break;

384

385 }

386 }

388}

389

390

391

392

393

394

398

399 return operator new(__sz, __p);

400}

Defines the clang::ASTContext interface.

REPL_EXTERNAL_VISIBILITY void * __clang_Interpreter_SetValueWithAlloc(void *This, void *OutVal, void *OpaqueType)

void REPL_EXTERNAL_VISIBILITY __clang_Interpreter_SetValueNoAlloc(void *This, void *OutVal, void *OpaqueType,...)

#define REPL_EXTERNAL_VISIBILITY

Defines the clang::Preprocessor interface.

C Language Family Type Representation.

#define va_start(ap, param)

__builtin_va_list va_list

static __inline__ uint32_t volatile uint32_t * __p

virtual bool HandleTopLevelDecl(DeclGroupRef D)

HandleTopLevelDecl - Handle the specified top-level declaration.

Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...

TranslationUnitDecl * getTranslationUnitDecl() const

QualType getLValueReferenceType(QualType T, bool SpelledAsLValue=true) const

Return the uniqued reference to the type for an lvalue reference to the specified type.

const LangOptions & getLangOpts() const

TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const

Allocate a TypeSourceInfo where all locations have been initialized to a given location,...

uint64_t getTypeSize(QualType T) const

Return the size of the specified (complete) type T, in bits.

uint64_t getConstantArrayElementCount(const ConstantArrayType *CA) const

Return number of constant array elements.

QualType getBitIntType(bool Unsigned, unsigned NumBits) const

Return a bit-precise integer type with the specified signedness and bit count.

This class is used for builtin types like 'int'.

Represents a C++ destructor within a class.

Represents a C++ struct/union/class.

bool hasIrrelevantDestructor() const

Determine whether this class has a destructor which has no semantic effect.

Represents a C++ nested-name-specifier or a global scope specifier.

llvm::StringRef GetMangledName(GlobalDecl GD)

Given a global declaration, return a mangled name for this declaration which has been added to this c...

ASTConsumer & getASTConsumer() const

Represents the canonical version of C arrays with a specified constant size.

A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.

This represents one expression.

bool isLValue() const

isLValue - True if this expression is an "l-value" according to the rules of the current language.

Represents a prototype with parameter type info, e.g.

GlobalDecl - represents a global declaration.

IdentifierInfo & get(StringRef Name)

Return the identifier token info for the specified named identifier.

InterfaceKind VisitConstantArrayType(const ConstantArrayType *Ty)

InterfaceKind VisitFunctionProtoType(const FunctionProtoType *Ty)

InterfaceKind computeInterfaceKind(QualType Ty)

InterfaceKind VisitReferenceType(const ReferenceType *Ty)

InterfaceKind VisitPointerType(const PointerType *Ty)

InterfaceKind VisitEnumType(const EnumType *Ty)

InterfaceKind VisitBuiltinType(const BuiltinType *Ty)

InterfaceKind VisitRecordType(const RecordType *Ty)

InterfaceKind VisitMemberPointerType(const MemberPointerType *Ty)

InterfaceKindVisitor(Sema &S, Expr *E, llvm::SmallVectorImpl< Expr * > &Args)

Provides top-level interfaces for incremental compilation and execution.

llvm::Expected< llvm::orc::ExecutorAddr > getSymbolAddress(GlobalDecl GD) const

const CompilerInstance * getCompilerInstance() const

Represents the results of name lookup.

A pointer to member type per C++ 8.3.3 - Pointers to members.

PointerType - C99 6.7.5.1 - Pointer Declarators.

A (possibly-)qualified type.

QualType getDesugaredType(const ASTContext &Context) const

Return the specified type with any "sugar" removed from the type.

const Type * getTypePtr() const

Retrieves a pointer to the underlying (unqualified) type.

void * getAsOpaquePtr() const

A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...

Base for LValueReferenceType and RValueReferenceType.

Scope - A scope is a transient data structure that is used while parsing the program.

Sema - This implements semantic analysis and AST building for C.

ExprResult CreateBuiltinUnaryOp(SourceLocation OpLoc, UnaryOperatorKind Opc, Expr *InputExpr, bool IsAfterAmp=false)

@ LookupOrdinaryName

Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc....

ASTContext & getASTContext() const

CXXDestructorDecl * LookupDestructor(CXXRecordDecl *Class)

Look for the destructor of the given class.

ExprResult BuildCXXNew(SourceRange Range, bool UseGlobal, SourceLocation PlacementLParen, MultiExprArg PlacementArgs, SourceLocation PlacementRParen, SourceRange TypeIdParens, QualType AllocType, TypeSourceInfo *AllocTypeInfo, std::optional< Expr * > ArraySize, SourceRange DirectInitRange, Expr *Initializer)

ExprResult BuildCStyleCastExpr(SourceLocation LParenLoc, TypeSourceInfo *Ty, SourceLocation RParenLoc, Expr *Op)

ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, LookupResult &R, bool NeedsADL, bool AcceptInvalidDecl=false)

bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, bool InUnqualifiedLookup=false)

Perform qualified name lookup into a given context.

ExprResult ActOnCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc, MultiExprArg ArgExprs, SourceLocation RParenLoc, Expr *ExecConfig=nullptr)

ActOnCallExpr - Handle a call to Fn with the specified array of arguments.

ExprResult ActOnFinishFullExpr(Expr *Expr, bool DiscardedValue)

Encodes a location in the source.

A trivial tuple used to represent a source range.

SourceLocation getEndLoc() const LLVM_READONLY

SourceRange getSourceRange() const LLVM_READONLY

SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...

SourceLocation getBeginLoc() const LLVM_READONLY

A container of type source information.

QualType getType() const

Return the type wrapped by this type source info.

InterfaceKind Visit(const Type *T)

Performs the operation associated with this visitor object.

The base class of the type hierarchy.

CXXRecordDecl * getAsCXXRecordDecl() const

Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...

const T * castAs() const

Member-template castAs.

bool isIntegralOrEnumerationType() const

Determine whether this type is an integral or enumeration type.

bool isFloatingType() const

const T * getAs() const

Member-template getAs'.

bool isNullPtrType() const

bool isRecordType() const

The JSON file list parser is used to communicate input to InstallAPI.

IntegerLiteral * IntegerLiteralExpr(ASTContext &C, uint64_t Val)

@ Dtor_Base

Base object dtor.

Expr * CStyleCastPtrExpr(Sema &S, QualType Ty, Expr *E)

@ Interface

The "__interface" keyword introduces the elaborated-type-specifier.

__UINTPTR_TYPE__ uintptr_t

An unsigned integer type with the property that any valid pointer to void can be converted to this ty...