@@ -277,6 +277,83 @@ TEST(FunctionReflectionTest, GetClassDecls) {
277
277
EXPECT_EQ (Cpp::GetName (methods[3 ]) , Cpp::GetName (SubDecls[8 ]));
278
278
}
279
279
280
+ TEST (FunctionReflectionTest, GetFunctionUsingArgs) {
281
+ std::vector<Decl*> Decls;
282
+ std::string code = R"(
283
+ // Overloaded functions
284
+ void f1(int a) {}
285
+ void f1() {}
286
+
287
+ // Templated functions
288
+ template <typename T>
289
+ void f2() { T t; }
290
+
291
+ // Templated functions deducible from args
292
+ template <typename T>
293
+ void f3(const T& t1, T* t2) {}
294
+
295
+ // Overloaded templated functions
296
+ template <typename T>
297
+ void f4() { T t; }
298
+ template <typename T1, typename T2>
299
+ void f4() { T1 t1; T2 t2; }
300
+ )" ;
301
+
302
+ auto get_function_name_using_args =
303
+ [&](Cpp::TCppScope_t scope, const std::string& name,
304
+ std::vector<Cpp::TCppType_t> arg_types,
305
+ std::vector<Cpp::TemplateArgInfo> template_args = {}) {
306
+ Cpp::TCppFunction_t function = Cpp::GetFunctionUsingArgs (
307
+ scope, name, arg_types.data (), arg_types.size (),
308
+ template_args.data (), template_args.size ());
309
+
310
+ if (function == (void *)-1 || function == 0 )
311
+ return std::string (" " );
312
+
313
+ return Cpp::GetFunctionSignature (function);
314
+ };
315
+
316
+ std::vector<Cpp::TCppType_t> arg_types;
317
+ std::vector<Cpp::TemplateArgInfo> template_args;
318
+
319
+ arg_types = {};
320
+ EXPECT_EQ (get_function_name_using_args (nullptr , " f1" , arg_types),
321
+ " void f1()" );
322
+ arg_types = {Cpp::GetType (" int" )};
323
+ EXPECT_EQ (get_function_name_using_args (nullptr , " f1" , arg_types),
324
+ " void f1(int a)" );
325
+
326
+ arg_types = {};
327
+ template_args = {{Cpp::GetType (" int" )}};
328
+ EXPECT_EQ (
329
+ get_function_name_using_args (nullptr , " f2" , arg_types, template_args),
330
+ " void f2()" );
331
+ arg_types = {};
332
+ template_args = {{Cpp::GetType (" double" )}};
333
+ EXPECT_EQ (
334
+ get_function_name_using_args (nullptr , " f2" , arg_types, template_args),
335
+ " void f2()" );
336
+
337
+ arg_types = {Cpp::GetType (" const std::string &" ),
338
+ Cpp::GetType (" std::string *" )};
339
+ EXPECT_EQ (get_function_name_using_args (nullptr , " f3" , arg_types),
340
+ " void f3(const std::string &t1, std::string *t2)" );
341
+ arg_types = {Cpp::GetType (" const int &" ), Cpp::GetType (" int *" )};
342
+ EXPECT_EQ (get_function_name_using_args (nullptr , " f3" , arg_types),
343
+ " void f3(const int &t1, int *t2)" );
344
+
345
+ arg_types = {};
346
+ template_args = {{Cpp::GetType (" double" )}};
347
+ EXPECT_EQ (
348
+ get_function_name_using_args (nullptr , " f4" , arg_types, template_args),
349
+ " void f4()" );
350
+ arg_types = {};
351
+ template_args = {{Cpp::GetType (" double" )}, {Cpp::GetType (" int" )}};
352
+ EXPECT_EQ (
353
+ get_function_name_using_args (nullptr , " f4" , arg_types, template_args),
354
+ " void f4()" );
355
+ }
356
+
280
357
TEST (FunctionReflectionTest, GetFunctionReturnType) {
281
358
std::vector<Decl*> Decls, SubDecls, TemplateSubDecls;
282
359
std::string code = R"(
0 commit comments