Skip to content

Commit a38a66e

Browse files
authored
Merge branch 'main' into Update-to-llvm-20
2 parents 8a4c0af + 33bfa39 commit a38a66e

File tree

6 files changed

+437
-120
lines changed

6 files changed

+437
-120
lines changed

CMakeLists.txt

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ set(CMAKE_MODULE_PATH
66
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
77
)
88

9+
enable_language(CXX)
10+
set(CMAKE_CXX_EXTENSIONS NO)
11+
12+
option(CPPINTEROP_USE_CLING "Use Cling as backend" OFF)
13+
option(CPPINTEROP_USE_REPL "Use clang-repl as backend" ON)
14+
option(CPPINTEROP_ENABLE_TESTING "Enable the CppInterOp testing infrastructure." ON)
15+
16+
if (CPPINTEROP_USE_CLING AND CPPINTEROP_USE_REPL)
17+
message(FATAL_ERROR "We can only use Cling (${CPPINTEROP_USE_CLING}=On) or Repl (CPPINTEROP_USE_REPL=On), but not both of them.")
18+
endif()
919
# If we are not building as a part of LLVM, build CppInterOp as a standalone
1020
# project, using LLVM as an external library:
1121
if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
@@ -54,17 +64,7 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
5464
endif()
5565
endif()
5666

57-
enable_language(CXX)
58-
set(CMAKE_CXX_EXTENSIONS NO)
5967
include(GNUInstallDirs)
60-
option(CPPINTEROP_USE_CLING "Use Cling as backend" OFF)
61-
option(CPPINTEROP_USE_REPL "Use clang-repl as backend" ON)
62-
option(CPPINTEROP_ENABLE_TESTING "Enable the CppInterOp testing infrastructure." ON)
63-
64-
if (CPPINTEROP_USE_CLING AND CPPINTEROP_USE_REPL)
65-
message(FATAL_ERROR "We can only use Cling (CPPINTEROP_USE_CLING=On) or Repl (CPPINTEROP_USE_REPL=On), but not both of them.")
66-
endif()
67-
6868
## Define supported version of clang and llvm
6969

7070
set(CLANG_MIN_SUPPORTED 13.0)
@@ -293,16 +293,15 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
293293
# In rare cases we might want to have clang installed in a different place
294294
# than llvm and the header files should be found first (even though the
295295
# LLVM_INCLUDE_DIRS) contain clang headers, too.
296-
if (CPPINTEROP_USE_CLING)
296+
if(CPPINTEROP_USE_CLING)
297297
add_definitions(-DCPPINTEROP_USE_CLING)
298298
include_directories(SYSTEM ${CLING_INCLUDE_DIRS})
299-
else()
300-
if (NOT CPPINTEROP_USE_REPL)
301-
message(FATAL_ERROR "We need either CPPINTEROP_USE_CLING or CPPINTEROP_USE_REPL")
302-
endif()
299+
elseif(CPPINTEROP_USE_REPL)
303300
add_definitions(-DCPPINTEROP_USE_REPL)
301+
else()
302+
message(FATAL_ERROR "We need either CPPINTEROP_USE_CLING or CPPINTEROP_USE_REPL")
303+
endif()
304304

305-
endif(CPPINTEROP_USE_CLING)
306305
include_directories(SYSTEM ${CLANG_INCLUDE_DIRS})
307306
include_directories(SYSTEM ${LLVM_INCLUDE_DIRS})
308307
separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS})

include/clang-c/CXCppInterOp.h

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ typedef struct CXInterpreterImpl* CXInterpreter;
3434
*
3535
* \returns a \c CXInterpreter.
3636
*/
37-
CXInterpreter clang_createInterpreter(const char* const* argv, int argc);
37+
CINDEX_LINKAGE CXInterpreter clang_createInterpreter(const char* const* argv,
38+
int argc);
3839

3940
typedef void* TInterp_t;
4041

@@ -43,27 +44,29 @@ typedef void* TInterp_t;
4344
*
4445
* \returns a \c CXInterpreter.
4546
*/
46-
CXInterpreter clang_createInterpreterFromRawPtr(TInterp_t I);
47+
CINDEX_LINKAGE CXInterpreter clang_createInterpreterFromRawPtr(TInterp_t I);
4748

4849
/**
4950
* Returns a pointer to the underlying interpreter.
5051
*/
51-
void* clang_Interpreter_getClangInterpreter(CXInterpreter I);
52+
CINDEX_LINKAGE void* clang_Interpreter_getClangInterpreter(CXInterpreter I);
5253

5354
/**
5455
* Returns a \c TInterp_t and takes the ownership.
5556
*/
56-
TInterp_t clang_Interpreter_takeInterpreterAsPtr(CXInterpreter I);
57+
CINDEX_LINKAGE TInterp_t
58+
clang_Interpreter_takeInterpreterAsPtr(CXInterpreter I);
5759

5860
/**
5961
* Undo N previous incremental inputs.
6062
*/
61-
enum CXErrorCode clang_Interpreter_undo(CXInterpreter I, unsigned int N);
63+
CINDEX_LINKAGE enum CXErrorCode clang_Interpreter_undo(CXInterpreter I,
64+
unsigned int N);
6265

6366
/**
6467
* Dispose of the given interpreter context.
6568
*/
66-
void clang_Interpreter_dispose(CXInterpreter I);
69+
CINDEX_LINKAGE void clang_Interpreter_dispose(CXInterpreter I);
6770

6871
/**
6972
* Describes the return result of the different routines that do the incremental
@@ -95,8 +98,9 @@ typedef enum {
9598
*
9699
* \param prepend Whether to prepend the directory to the search path.
97100
*/
98-
void clang_Interpreter_addSearchPath(CXInterpreter I, const char* dir,
99-
bool isUser, bool prepend);
101+
CINDEX_LINKAGE void clang_Interpreter_addSearchPath(CXInterpreter I,
102+
const char* dir,
103+
bool isUser, bool prepend);
100104

101105
/**
102106
* Add an include path.
@@ -105,7 +109,8 @@ void clang_Interpreter_addSearchPath(CXInterpreter I, const char* dir,
105109
*
106110
* \param dir The directory to add.
107111
*/
108-
void clang_Interpreter_addIncludePath(CXInterpreter I, const char* dir);
112+
CINDEX_LINKAGE void clang_Interpreter_addIncludePath(CXInterpreter I,
113+
const char* dir);
109114

110115
/**
111116
* Declares a code snippet in \c code and does not execute it.
@@ -118,8 +123,8 @@ void clang_Interpreter_addIncludePath(CXInterpreter I, const char* dir);
118123
*
119124
* \returns a \c CXErrorCode.
120125
*/
121-
enum CXErrorCode clang_Interpreter_declare(CXInterpreter I, const char* code,
122-
bool silent);
126+
CINDEX_LINKAGE enum CXErrorCode
127+
clang_Interpreter_declare(CXInterpreter I, const char* code, bool silent);
123128

124129
/**
125130
* Declares and executes a code snippet in \c code.
@@ -130,7 +135,8 @@ enum CXErrorCode clang_Interpreter_declare(CXInterpreter I, const char* code,
130135
*
131136
* \returns a \c CXErrorCode.
132137
*/
133-
enum CXErrorCode clang_Interpreter_process(CXInterpreter I, const char* code);
138+
CINDEX_LINKAGE enum CXErrorCode clang_Interpreter_process(CXInterpreter I,
139+
const char* code);
134140

135141
/**
136142
* An opaque pointer representing a lightweight struct that is used for carrying
@@ -143,14 +149,14 @@ typedef void* CXValue;
143149
*
144150
* \returns a \c CXValue.
145151
*/
146-
CXValue clang_createValue(void);
152+
CINDEX_LINKAGE CXValue clang_createValue(void);
147153

148154
/**
149155
* Dispose of the given CXValue.
150156
*
151157
* \param V The CXValue to dispose.
152158
*/
153-
void clang_Value_dispose(CXValue V);
159+
CINDEX_LINKAGE void clang_Value_dispose(CXValue V);
154160

155161
/**
156162
* Declares, executes and stores the execution result to \c V.
@@ -163,8 +169,8 @@ void clang_Value_dispose(CXValue V);
163169
*
164170
* \returns a \c CXErrorCode.
165171
*/
166-
enum CXErrorCode clang_Interpreter_evaluate(CXInterpreter I, const char* code,
167-
CXValue V);
172+
CINDEX_LINKAGE enum CXErrorCode
173+
clang_Interpreter_evaluate(CXInterpreter I, const char* code, CXValue V);
168174

169175
/**
170176
* Looks up the library if access is enabled.
@@ -175,7 +181,8 @@ enum CXErrorCode clang_Interpreter_evaluate(CXInterpreter I, const char* code,
175181
*
176182
* \returns the path to the library.
177183
*/
178-
CXString clang_Interpreter_lookupLibrary(CXInterpreter I, const char* lib_name);
184+
CINDEX_LINKAGE CXString clang_Interpreter_lookupLibrary(CXInterpreter I,
185+
const char* lib_name);
179186

180187
/**
181188
* Finds \c lib_stem considering the list of search paths and loads it by
@@ -189,9 +196,8 @@ CXString clang_Interpreter_lookupLibrary(CXInterpreter I, const char* lib_name);
189196
*
190197
* \returns a \c CXInterpreter_CompilationResult.
191198
*/
192-
CXInterpreter_CompilationResult
193-
clang_Interpreter_loadLibrary(CXInterpreter I, const char* lib_stem,
194-
bool lookup);
199+
CINDEX_LINKAGE CXInterpreter_CompilationResult clang_Interpreter_loadLibrary(
200+
CXInterpreter I, const char* lib_stem, bool lookup);
195201

196202
/**
197203
* Finds \c lib_stem considering the list of search paths and unloads it by
@@ -201,7 +207,8 @@ clang_Interpreter_loadLibrary(CXInterpreter I, const char* lib_stem,
201207
*
202208
* \param lib_stem The stem of the library to unload.
203209
*/
204-
void clang_Interpreter_unloadLibrary(CXInterpreter I, const char* lib_stem);
210+
CINDEX_LINKAGE void clang_Interpreter_unloadLibrary(CXInterpreter I,
211+
const char* lib_stem);
205212

206213
/**
207214
* @}
@@ -226,40 +233,41 @@ typedef struct {
226233
} CXScope;
227234

228235
// for debugging purposes
229-
void clang_scope_dump(CXScope S);
236+
CINDEX_LINKAGE void clang_scope_dump(CXScope S);
230237

231238
/**
232239
* Checks if a class has a default constructor.
233240
*/
234-
bool clang_hasDefaultConstructor(CXScope S);
241+
CINDEX_LINKAGE bool clang_hasDefaultConstructor(CXScope S);
235242

236243
/**
237244
* Returns the default constructor of a class, if any.
238245
*/
239-
CXScope clang_getDefaultConstructor(CXScope S);
246+
CINDEX_LINKAGE CXScope clang_getDefaultConstructor(CXScope S);
240247

241248
/**
242249
* Returns the class destructor, if any.
243250
*/
244-
CXScope clang_getDestructor(CXScope S);
251+
CINDEX_LINKAGE CXScope clang_getDestructor(CXScope S);
245252

246253
/**
247254
* Returns a stringified version of a given function signature in the form:
248255
* void N::f(int i, double d, long l = 0, char ch = 'a').
249256
*/
250-
CXString clang_getFunctionSignature(CXScope func);
257+
CINDEX_LINKAGE CXString clang_getFunctionSignature(CXScope func);
251258

252259
/**
253260
* Checks if a function is a templated function.
254261
*/
255-
bool clang_isTemplatedFunction(CXScope func);
262+
CINDEX_LINKAGE bool clang_isTemplatedFunction(CXScope func);
256263

257264
/**
258265
* This function performs a lookup to check if there is a templated function of
259266
* that type. \c parent is mandatory, the global scope should be used as the
260267
* default value.
261268
*/
262-
bool clang_existsFunctionTemplate(const char* name, CXScope parent);
269+
CINDEX_LINKAGE bool clang_existsFunctionTemplate(const char* name,
270+
CXScope parent);
263271

264272
typedef struct {
265273
void* Type;
@@ -282,9 +290,8 @@ typedef struct {
282290
* \returns a \c CXScope representing the instantiated templated
283291
* class/function/variable.
284292
*/
285-
CXScope clang_instantiateTemplate(CXScope tmpl,
286-
CXTemplateArgInfo* template_args,
287-
size_t template_args_size);
293+
CINDEX_LINKAGE CXScope clang_instantiateTemplate(
294+
CXScope tmpl, CXTemplateArgInfo* template_args, size_t template_args_size);
288295

289296
/**
290297
* A fake CXType for working with the interpreter.
@@ -299,12 +306,12 @@ typedef struct {
299306
/**
300307
* Gets the string of the type that is passed as a parameter.
301308
*/
302-
CXString clang_getTypeAsString(CXQualType type);
309+
CINDEX_LINKAGE CXString clang_getTypeAsString(CXQualType type);
303310

304311
/**
305312
* Returns the complex of the provided type.
306313
*/
307-
CXQualType clang_getComplexType(CXQualType eltype);
314+
CINDEX_LINKAGE CXQualType clang_getComplexType(CXQualType eltype);
308315

309316
/**
310317
* An opaque pointer representing the object of a given type (\c CXScope).
@@ -314,18 +321,18 @@ typedef void* CXObject;
314321
/**
315322
* Allocates memory for the given type.
316323
*/
317-
CXObject clang_allocate(unsigned int n);
324+
CINDEX_LINKAGE CXObject clang_allocate(unsigned int n);
318325

319326
/**
320327
* Deallocates memory for a given class.
321328
*/
322-
void clang_deallocate(CXObject address);
329+
CINDEX_LINKAGE void clang_deallocate(CXObject address);
323330

324331
/**
325332
* Creates an object of class \c scope and calls its default constructor. If \c
326333
* arena is set it uses placement new.
327334
*/
328-
CXObject clang_construct(CXScope scope, void* arena);
335+
CINDEX_LINKAGE CXObject clang_construct(CXScope scope, void* arena);
329336

330337
/**
331338
* Creates a trampoline function and makes a call to a generic function or
@@ -341,8 +348,8 @@ CXObject clang_construct(CXScope scope, void* arena);
341348
*
342349
* \param self The 'this pointer' of the object.
343350
*/
344-
void clang_invoke(CXScope func, void* result, void** args, size_t n,
345-
void* self);
351+
CINDEX_LINKAGE void clang_invoke(CXScope func, void* result, void** args,
352+
size_t n, void* self);
346353

347354
/**
348355
* Calls the destructor of object of type \c type. When withFree is true it
@@ -354,7 +361,7 @@ void clang_invoke(CXScope func, void* result, void** args, size_t n,
354361
*
355362
* \param withFree Whether to call operator delete/free or not.
356363
*/
357-
void clang_destruct(CXObject This, CXScope S, bool withFree);
364+
CINDEX_LINKAGE void clang_destruct(CXObject This, CXScope S, bool withFree);
358365

359366
/**
360367
* @}

include/clang/Interpreter/CppInterOp.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ namespace Cpp {
210210
/// Checks if the scope is a class or not.
211211
CPPINTEROP_API bool IsClass(TCppScope_t scope);
212212

213+
/// Checks if the scope is a function.
214+
CPPINTEROP_API bool IsFunction(TCppScope_t scope);
215+
213216
/// Checks if the type is a function pointer.
214217
CPPINTEROP_API bool IsFunctionPointerType(TCppType_t type);
215218

@@ -706,17 +709,16 @@ namespace Cpp {
706709
CPPINTEROP_API TCppFunction_t
707710
InstantiateTemplateFunctionFromString(const char* function_template);
708711

709-
/// Finds best template match based on explicit template parameters and
710-
/// argument types
712+
/// Finds best overload match based on explicit template parameters (if any)
713+
/// and argument types.
711714
///
712-
///\param[in] candidates - Vector of suitable candidates that come under the
713-
/// parent scope and have the same name (obtained using
714-
/// GetClassTemplatedMethods)
715+
///\param[in] candidates - vector of overloads that come under the
716+
/// parent scope and have the same name
715717
///\param[in] explicit_types - set of expicitly instantiated template types
716718
///\param[in] arg_types - set of argument types
717719
///\returns Instantiated function pointer
718720
CPPINTEROP_API TCppFunction_t
719-
BestTemplateFunctionMatch(const std::vector<TCppFunction_t>& candidates,
721+
BestOverloadFunctionMatch(const std::vector<TCppFunction_t>& candidates,
720722
const std::vector<TemplateArgInfo>& explicit_types,
721723
const std::vector<TemplateArgInfo>& arg_types);
722724

lib/Interpreter/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ else()
133133
LINK_LIBS
134134
${link_libs}
135135
)
136+
137+
target_compile_definitions(clangCppInterOp PUBLIC "_CINDEX_LIB_") # workaround for the use of `CINDEX_LINKAGE`
136138
endif()
137139

138140
string(REPLACE ";" "\;" _VER CPPINTEROP_VERSION)

0 commit comments

Comments
 (0)