@@ -277,6 +277,71 @@ 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,
308
+ arg_types.data (), arg_types.size (),
309
+ template_args.data (), template_args.size ());
310
+
311
+ if (function == (void *) -1 || function == 0 )
312
+ return std::string (" " );
313
+
314
+ return Cpp::GetFunctionSignature (function);
315
+ };
316
+
317
+ std::vector<Cpp::TCppType_t> arg_types;
318
+ std::vector<Cpp::TemplateArgInfo> template_args;
319
+
320
+ arg_types = {};
321
+ EXPECT_EQ (get_function_name_using_args (nullptr , " f1" , arg_types), " void f1()" );
322
+ arg_types = {Cpp::GetType (" int" )};
323
+ EXPECT_EQ (get_function_name_using_args (nullptr , " f1" , arg_types), " void f1(int a)" );
324
+
325
+ arg_types = {};
326
+ template_args = {{Cpp::GetType (" int" )}};
327
+ EXPECT_EQ (get_function_name_using_args (nullptr , " f2" , arg_types, template_args), " void f2()" );
328
+ arg_types = {};
329
+ template_args = {{Cpp::GetType (" double" )}};
330
+ EXPECT_EQ (get_function_name_using_args (nullptr , " f2" , arg_types, template_args), " void f2()" );
331
+
332
+ arg_types = {Cpp::GetType (" const std::string &" ), Cpp::GetType (" std::string *" )};
333
+ EXPECT_EQ (get_function_name_using_args (nullptr , " f3" , arg_types), " void f3(const std::string &t1, std::string *t2)" );
334
+ arg_types = {Cpp::GetType (" const int &" ), Cpp::GetType (" int *" )};
335
+ EXPECT_EQ (get_function_name_using_args (nullptr , " f3" , arg_types), " void f3(const int &t1, int *t2)" );
336
+
337
+ arg_types = {};
338
+ template_args = {{Cpp::GetType (" double" )}};
339
+ EXPECT_EQ (get_function_name_using_args (nullptr , " f4" , arg_types, template_args), " void f4()" );
340
+ arg_types = {};
341
+ template_args = {{Cpp::GetType (" double" )}, {Cpp::GetType (" int" )}};
342
+ EXPECT_EQ (get_function_name_using_args (nullptr , " f4" , arg_types, template_args), " void f4()" );
343
+ }
344
+
280
345
TEST (FunctionReflectionTest, GetFunctionReturnType) {
281
346
std::vector<Decl*> Decls, SubDecls, TemplateSubDecls;
282
347
std::string code = R"(
0 commit comments