//===--- InterpreterValuePrinter.cpp - Value printing utils -----*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file implements routines for in-process value printing in clang-repl. // //===----------------------------------------------------------------------===// #include "IncrementalParser.h" #include "InterpreterUtils.h" #include "clang/AST/ASTContext.h" #include "clang/AST/PrettyPrinter.h" #include "clang/AST/Type.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Interpreter/Interpreter.h" #include "clang/Interpreter/Value.h" #include "clang/Lex/Preprocessor.h" #include "clang/Sema/Lookup.h" #include "clang/Sema/Sema.h" #include "llvm/Support/Error.h" #include "llvm/Support/raw_ostream.h" #include <cassert> #include <string> #include <cstdarg> namespace clang { llvm::Expected<llvm::orc::ExecutorAddr> Interpreter::CompileDtorCall(CXXRecordDecl *CXXRD) { … } enum InterfaceKind { … }; class InterfaceKindVisitor : public TypeVisitor<InterfaceKindVisitor, InterfaceKind> { … }; // This synthesizes a call expression to a speciall // function that is responsible for generating the Value. // In general, we transform: // clang-repl> x // To: // // 1. If x is a built-in type like int, float. // __clang_Interpreter_SetValueNoAlloc(ThisInterp, OpaqueValue, xQualType, x); // // 2. If x is a struct, and a lvalue. // __clang_Interpreter_SetValueNoAlloc(ThisInterp, OpaqueValue, xQualType, // &x); // // 3. If x is a struct, but a rvalue. // new (__clang_Interpreter_SetValueWithAlloc(ThisInterp, OpaqueValue, // xQualType)) (x); llvm::Expected<Expr *> Interpreter::ExtractValueFromExpr(Expr *E) { … } } // namespace clang usingnamespaceclang; // Temporary rvalue struct that need special care. REPL_EXTERNAL_VISIBILITY void * __clang_Interpreter_SetValueWithAlloc(void *This, void *OutVal, void *OpaqueType) { … } extern "C" void REPL_EXTERNAL_VISIBILITY __clang_Interpreter_SetValueNoAlloc( void *This, void *OutVal, void *OpaqueType, ...) { … } // A trampoline to work around the fact that operator placement new cannot // really be forward declared due to libc++ and libstdc++ declaration mismatch. // FIXME: __clang_Interpreter_NewTag is ODR violation because we get the same // definition in the interpreter runtime. We should move it in a runtime header // which gets included by the interpreter and here. struct __clang_Interpreter_NewTag { … }; REPL_EXTERNAL_VISIBILITY void * operator new(size_t __sz, void *__p, __clang_Interpreter_NewTag) noexcept { … }