25#include "llvm/Support/Error.h"
26#include "llvm/Support/raw_ostream.h"
37 assert(CXXRD &&
"Cannot compile a destructor for a nullptr");
38 if (
auto Dtor = Dtors.find(CXXRD); Dtor != Dtors.end())
39 return Dtor->getSecond();
42 return llvm::orc::ExecutorAddr{};
47 llvm::StringRef Name =
51 return AddrOrErr.takeError();
53 Dtors[CXXRD] = *AddrOrErr;
60 :
public TypeVisitor<InterfaceKindVisitor, InterfaceKind> {
68 : S(S),
E(
E), Args(Args) {}
98 assert(!AddrOfE.
isInvalid() &&
"Can not create unary expression");
99 Args.push_back(AddrOfE.
get());
109 HandleIntegralOrEnumType(Ty);
118 HandleIntegralOrEnumType(Ty);
125 void HandleIntegralOrEnumType(
const Type *Ty) {
132 assert(!CastedExpr.
isInvalid() &&
"Cannot create cstyle cast expr");
133 Args.push_back(CastedExpr.
get());
136 void HandlePtrType(
const Type *Ty) {
141 assert(!CastedExpr.
isInvalid() &&
"Can not create cstyle cast expression");
142 Args.push_back(CastedExpr.
get());
164 if (!ValuePrintingInfo[0]) {
165 assert(llvm::all_of(ValuePrintingInfo, [](
Expr *
E) {
return !
E; }));
168 llvm::StringRef Name) -> llvm::Error {
171 RedeclarationKind::ForVisibleRedeclaration);
174 return llvm::make_error<llvm::StringError>(
175 Name +
" not found!", llvm::inconvertibleErrorCode());
179 return llvm::Error::success();
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 =
187 return std::move(Err);
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);
207 AdjustedArgs.push_back(
213 if (
auto *EWC = llvm::dyn_cast_if_present<ExprWithCleanups>(
E))
214 E = EWC->getSubExpr();
228 AdjustedArgs.push_back(TypeArg);
244 assert(!AllocCall.
isInvalid() &&
"Can't create runtime interface call!");
251 Dtor->
addAttr(UsedAttr::CreateImplicit(Ctx));
258 const auto *ConstantArrTy =
259 cast<ConstantArrayType>(DesugaredTy.
getTypePtr());
262 Expr *Args[] = {
E, AllocCall.
get(), ArrSizeExpr};
276 "Can't create runtime placement new call!");
290 llvm_unreachable(
"Unhandled InterfaceKind");
297 return SetValueE.
get();
302using namespace clang;
314 void *This,
void *OutVal,
void *OpaqueType, ...) {
317 VRef =
Value(I, OpaqueType);
329 QT = ET->getDecl()->getIntegerType();
332 llvm_unreachable(
"unknown type kind!");
335 case BuiltinType::Bool:
336 VRef.setBool(
va_arg(args,
int));
338 case BuiltinType::Char_S:
339 VRef.setChar_S(
va_arg(args,
int));
341 case BuiltinType::SChar:
342 VRef.setSChar(
va_arg(args,
int));
344 case BuiltinType::Char_U:
345 VRef.setChar_U(
va_arg(args,
unsigned));
347 case BuiltinType::UChar:
348 VRef.setUChar(
va_arg(args,
unsigned));
350 case BuiltinType::Short:
351 VRef.setShort(
va_arg(args,
int));
353 case BuiltinType::UShort:
354 VRef.setUShort(
va_arg(args,
unsigned));
356 case BuiltinType::Int:
357 VRef.setInt(
va_arg(args,
int));
359 case BuiltinType::UInt:
360 VRef.setUInt(
va_arg(args,
unsigned));
362 case BuiltinType::Long:
363 VRef.setLong(
va_arg(args,
long));
365 case BuiltinType::ULong:
366 VRef.setULong(
va_arg(args,
unsigned long));
368 case BuiltinType::LongLong:
369 VRef.setLongLong(
va_arg(args,
long long));
371 case BuiltinType::ULongLong:
372 VRef.setULongLong(
va_arg(args,
unsigned long long));
375 case BuiltinType::Float:
376 VRef.setFloat(
va_arg(args,
double));
378 case BuiltinType::Double:
379 VRef.setDouble(
va_arg(args,
double));
381 case BuiltinType::LongDouble:
382 VRef.setLongDouble(
va_arg(args,
long double));
399 return operator new(__sz,
__p);
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<specific type>.
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
bool isFloatingType() const
const T * getAs() const
Member-template getAs<specific type>'.
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...