CppInterOp
C++ Language Interoperability Layer
Loading...
Searching...
No Matches
CXCppInterOp.h
Go to the documentation of this file.
1//===- CXCppInterOp.h - C API for the CppInterOp library --------*- C -*-===//
2//
3// Part of the compiler-research project, under the Apache License v2.0 with
4// LLVM Exceptions.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Public C API for CppInterOp. Wraps the tablegen-generated declarations
10// in CXCppInterOpDecl.inc and adds the hand-written extras that cannot
11// be emitted by the generator (NoCWrapper return types, mixed return +
12// out-param shapes).
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef CPPINTEROP_CXCPPINTEROP_H
17#define CPPINTEROP_CXCPPINTEROP_H
18
20
21#ifdef __cplusplus
22// The generated .inc spells C-API parameter and return types with the
23// prefixed C-side names (CppDeclRef etc.). For C++ TUs that opt into the
24// C API by including this header, alias each prefixed name to its
25// namespaced Cpp::* counterpart — they're layout-identical, so this
26// makes them the same C++ type and no conversion happens at call sites.
27// C++ TUs that include only CppInterOp.h (the C++ API header) never see
28// these aliases — the prefixed spelling stays out of their namespace.
29using CppDeclRef = Cpp::DeclRef;
30using CppTypeRef = Cpp::TypeRef;
31using CppFuncRef = Cpp::FuncRef;
32using CppObjectRef = Cpp::ObjectRef;
33using CppInterpRef = Cpp::InterpRef;
34using CppConstDeclRef = Cpp::ConstDeclRef;
35using CppConstTypeRef = Cpp::ConstTypeRef;
36using CppConstFuncRef = Cpp::ConstFuncRef;
37
38// The C-linkage functions return Cpp::*Ref types (one-word PODs with
39// inline constructors). Clang warns about returning a "user-defined
40// type" with C linkage even though the ABI is fine — the C-side
41// spelling is a layout-identical struct without constructors, and
42// HandleTypesTest::AbiCompatibleWithVoidPtr proves the call convention
43// matches. Silence the warning for downstream C++ consumers using -I.
44#pragma clang diagnostic push
45#pragma clang diagnostic ignored "-Wreturn-type-c-linkage"
46extern "C" {
47#endif
48
49#include "CppInterOp/CXCppInterOpDecl.inc"
50
51// --- Hand-written wrappers (see lib/CppInterOp/CXCppInterOp.cpp) ---
52
53/// C-ABI overload of Cpp::Evaluate. Returns the execution result as
54/// a raw \c intptr_t bit pattern; on parse error or no-value-after-
55/// success writes \c true to \c *HadError (if non-null) and returns
56/// \c ~0UL. The Box-returning C++ overload is marked NoCWrapper.
57CPPINTEROP_API intptr_t cppinterop_Evaluate(const char* code, bool* HadError);
58
59/// Returns the templated method scopes inside \c parent matching
60/// \c name. The bool-return-with-vector-outparam shape is not
61/// expressible by the tablegen wrapper emitter; callers check
62/// \c arr.size > 0 to detect "no matches".
65
66#ifdef __cplusplus
67} // extern "C"
68#pragma clang diagnostic pop
69#endif
70
71#endif // CPPINTEROP_CXCPPINTEROP_H
CPPINTEROP_API intptr_t cppinterop_Evaluate(const char *code, bool *HadError)
C-ABI overload of Cpp::Evaluate.
CPPINTEROP_API CppInterOpArray cppinterop_GetClassTemplatedMethods(const char *name, CppConstDeclRef parent)
Returns the templated method scopes inside parent matching name.
#define CPPINTEROP_API
Opaque handle types for the CppInterOp C and C++ API.
C-compatible array of opaque pointers, returned by generated C API wrappers for functions that produc...