1/* 2 * Copyright (c) Facebook, Inc. and its affiliates. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17namespace cpp test_cpp1.cpp_reflection 18namespace cpp2 test_cpp2.cpp_reflection 19namespace d test_d.cpp_reflection 20namespace java test_java.cpp_reflection 21namespace java.swift test_swift.cpp_reflection 22namespace php test_php.cpp_reflection 23namespace py3 test_py.cpp_reflection 24 25include "thrift/test/reflection/reflection_dep_B.thrift" 26include "thrift/test/reflection/reflection_dep_C.thrift" 27 28cpp_include "thrift/test/reflection/fatal_custom_types.h" 29cpp_include "<deque>" 30cpp_include "<unordered_set>" 31cpp_include "<unordered_map>" 32 33enum enum1 { 34 field0 = 0, 35 field1 = 1, 36 field2 = 2, 37} 38 39enum enum2 { 40 field0_2 = 0, 41 field1_2 = 1, 42 field2_2 = 2, 43} 44 45enum enum3 { 46 field0_3 = 0, 47 field1_3 = 1 (field_annotation = "field annotated"), 48 field2_3 = 2 ( 49 field_structured_annotation = '{"a": "foo", "b": 567, "c": true}', 50 field_annotation = "some other text", 51 ), 52} ( 53 one.here = "with some value associated", 54 another.there = ".", 55 yet.another = "and yet more text - it's that easy", 56 duplicate_id_annotation_1 = "duplicate id annotation", 57 duplicate_id_annotation_2 = "duplicate.id.annotation", 58 _now.with.an.underscore = "_now.with.an.underscore", 59) 60 61enum enum_with_renamed_value { 62 fancy.idl.name = 7 (cpp.name = "boring_cxx_name"), 63} 64 65union union1 { 66 1: i32 ui; 67 2: double ud; 68 3: string us; 69 4: enum1 ue; 70} 71 72union union2 { 73 1: i32 ui_2; 74 2: double ud_2; 75 3: string us_2; 76 4: enum1 ue_2; 77} 78 79union union3 { 80 1: i32 ui_3; 81 2: double ud_3; 82 3: string us_3; 83 4: enum1 ue_3; 84} 85 86struct structA { 87 1: i32 a; 88 2: string b; 89} 90 91typedef structA (cpp.type = "test_cpp_reflection::custom_structA") my_structA 92 93union unionA { 94 1: i32 i; 95 2: double d; 96 3: string s; 97 4: enum1 e; 98 5: structA a; 99} (sample.annotation = "some text here", another.annotation = "some more text") 100 101struct structB { 102 1: double c; 103 2: bool d ( 104 some.annotation = "some value", 105 another.annotation = "another value", 106 ); 107} ( 108 some.annotation = "this is its value", 109 some.other.annotation = "this is its other value", 110 multi_line_annotation = "line one 111line two", 112) 113 114struct structC { 115 1: i32 a; 116 2: string b; 117 3: double c; 118 4: bool d; 119 5: enum1 e; 120 6: enum2 f; 121 7: union1 g; 122 8: unionA h; 123 9: unionA i; 124 10: list<i32> j; 125 11: list<i32> j1; 126 12: list<enum1> j2; 127 13: list<structA> j3; 128 14: set<i32> k; 129 15: set<i32> k1; 130 16: set<enum2> k2; 131 17: set<structB> k3; 132 18: map<i32, i32> l; 133 19: map<i32, i32> l1; 134 20: map<i32, enum1> l2; 135 21: map<i32, structB> l3; 136 22: map<enum1, i32> m1; 137 23: map<enum1, enum2> m2; 138 24: map<enum1, structB> m3; 139 25: map<string, i32> n1; 140 26: map<string, enum1> n2; 141 27: map<string, structB> n3; 142 28: map<structA, i32> o1; 143 29: map<structA, enum1> o2; 144 30: map<structA, structB> o3; 145} 146 147struct struct1 { 148 1: required i32 field0; 149 2: optional string field1; 150 4: enum1 field2; 151 8: required enum2 field3; 152 16: optional union1 field4; 153 32: union2 field5; 154} 155 156struct struct2 { 157 1: i32 fieldA; 158 2: string fieldB; 159 3: enum1 fieldC; 160 4: enum2 fieldD; 161 5: union1 fieldE; 162 6: union2 fieldF; 163 7: struct1 fieldG; 164} 165 166struct struct3 { 167 1: i32 fieldA; 168 2: string fieldB; 169 3: enum1 fieldC; 170 4: enum2 fieldD; 171 5: union1 fieldE; 172 6: union2 fieldF; 173 7: struct1 fieldG; 174 8: union2 fieldH; 175 9: list<i32> fieldI; 176 10: list<string> fieldJ; 177 11: list<string> fieldK; 178 12: list<structA> fieldL; 179 13: set<i32> fieldM; 180 14: set<string> fieldN; 181 15: set<string> fieldO; 182 16: set<structB> fieldP; 183 17: map<string, structA> fieldQ; 184 18: map<string, structB> (cpp.template = 'std::unordered_map') fieldR; 185 19: map<binary, binary> fieldS; 186} 187 188struct struct4 { 189 1: required i32 field0; 190 2: optional string field1; 191 3: enum1 field2; 192 6: structA field3 (cpp2.ref = "true"); 193} 194 195struct struct5 { 196 1: required i32 field0; 197 2: optional string field1; 198 3: enum1 field2; 199 4: structA field3 (annotate_here = "with text"); 200 5: structB field4; 201} 202 203struct struct_binary { 204 1: binary bi; 205} 206 207struct dep_A_struct { 208 1: reflection_dep_B.dep_B_struct b; 209 2: reflection_dep_C.dep_C_struct c; 210 3: i32 i_a; 211} 212 213struct annotated { 214 1: i32 a ( 215 m_b_false = 'false', 216 m_b_true = 'true', 217 m_int = '10', 218 m_string = '"hello"', 219 m_int_list = '[-1, 2, 3]', 220 m_str_list = '["a", "b", "c"]', 221 m_mixed_list = '["a", 1, "b", 2]', 222 m_int_map = '{"a": 1, "b": -2, "c": -3}', 223 m_str_map = '{"a": "A", "b": "B", "c": "C"}', 224 m_mixed_map = '{"a": -2, "b": "B", "c": 3}', 225 ); 226} ( 227 s_b_false = 'false', 228 s_b_true = 'true', 229 s_int = '10', 230 s_string = '"hello"', 231 s_int_list = '[-1, 2, 3]', 232 s_str_list = '["a", "b", "c"]', 233 s_mixed_list = '["a", 1, "b", 2]', 234 s_int_map = '{"a": 1, "b": -2, "c": -3}', 235 s_str_map = '{"a": "A", "b": "B", "c": "C"}', 236 s_mixed_map = '{"a": -2, "b": "B", "c": 3}', 237) 238 239service service1 { 240 void method1(); 241 void method2(1: i32 x, 2: struct1 y, 3: double z); 242 i32 method3(); 243 i32 method4(1: i32 i, 2: struct1 j, 3: double k); 244 struct2 method5(); 245 struct2 method6(1: i32 l, 2: struct1 m, 3: double n); 246} 247 248service service2 { 249 void methodA(); 250 void methodB(1: i32 x, 2: struct1 y, 3: double z); 251 i32 methodC(); 252 i32 methodD(1: i32 i, 2: struct1 j, 3: double k); 253 struct2 methodE(); 254 struct2 methodF(1: i32 l, 2: struct1 m, 3: double n); 255} 256 257service service3 { 258 void methodA(); 259 void methodB(1: i32 x, 2: struct1 y, 3: double z); 260 i32 methodC(); 261 i32 methodD(1: i32 i, 2: struct1 j, 3: double k); 262 struct2 methodE(); 263 struct3 methodF(1: i32 l, 2: struct1 m, 3: double n); 264} 265 266const i32 constant1 = 1357; 267const string constant2 = "hello"; 268const enum1 constant3 = enum1.field0; 269 270enum enum_with_special_names { 271 get = 0, 272 getter = 1, 273 lists = 2, 274 maps = 3, 275 name = 4 (py3.name = "name_"), 276 name_to_value = 5, 277 names = 6, 278 prefix_tree = 7, 279 sets = 8, 280 setter = 9, 281 str = 10, 282 strings = 11, 283 type = 12, 284 value = 13 (py3.name = "value_"), 285 value_to_name = 14, 286 values = 15, 287 id = 16, 288 ids = 17, 289 descriptor = 18, 290 descriptors = 19, 291 key = 20, 292 keys = 21, 293 annotation = 22, 294 annotations = 23, 295 member = 24, 296 members = 25, 297 field = 26, 298 fields = 27, 299} 300 301union union_with_special_names { 302 1: i32 get; 303 2: i32 getter; 304 3: i32 lists; 305 4: i32 maps; 306 5: i32 name; 307 6: i32 name_to_value; 308 7: i32 names; 309 8: i32 prefix_tree; 310 9: i32 sets; 311 10: i32 setter; 312 11: i32 str; 313 12: i32 strings; 314 13: i32 type; 315 14: i32 value; 316 15: i32 value_to_name; 317 16: i32 values; 318 17: i32 id; 319 18: i32 ids; 320 19: i32 descriptor; 321 20: i32 descriptors; 322 21: i32 key; 323 22: i32 keys; 324 23: i32 annotation; 325 24: i32 annotations; 326 25: i32 member; 327 26: i32 members; 328 27: i32 field; 329 28: i32 fields; 330} 331 332struct struct_with_special_names { 333 1: i32 get; 334 2: i32 getter; 335 3: i32 lists; 336 4: i32 maps; 337 5: i32 name; 338 6: i32 name_to_value; 339 7: i32 names; 340 8: i32 prefix_tree; 341 9: i32 sets; 342 10: i32 setter; 343 11: i32 str; 344 12: i32 strings; 345 13: i32 type; 346 14: i32 value; 347 15: i32 value_to_name; 348 16: i32 values; 349 17: i32 id; 350 18: i32 ids; 351 19: i32 descriptor; 352 20: i32 descriptors; 353 21: i32 key; 354 22: i32 keys; 355 23: i32 annotation; 356 24: i32 annotations; 357 25: i32 member; 358 26: i32 members; 359 27: i32 field; 360 28: i32 fields; 361} 362 363service service_with_special_names { 364 i32 get(); 365 i32 getter(); 366 i32 lists(); 367 i32 maps(); 368 i32 name(); 369 i32 name_to_value(); 370 i32 names(); 371 i32 prefix_tree(); 372 i32 sets(); 373 i32 setter(); 374 i32 str(); 375 i32 strings(); 376 i32 type(); 377 i32 value(); 378 i32 value_to_name(); 379 i32 values(); 380 i32 id(); 381 i32 ids(); 382 i32 descriptor(); 383 i32 descriptors(); 384 i32 key(); 385 i32 keys(); 386 i32 annotation(); 387 i32 annotations(); 388 i32 member(); 389 i32 members(); 390 i32 field(); 391 i32 fields(); 392} 393 394const i32 constant_with_special_name = 42; 395 396struct hasRefUnique { 397 1: structA aStruct (cpp2.ref_type = "unique"); 398 2: list<string> (cpp.template = "std::deque") aList ( 399 cpp2.ref_type = "unique", 400 ); 401 3: set<string> (cpp.template = "std::unordered_set") aSet ( 402 cpp2.ref_type = "unique", 403 ); 404 4: map<string, string> (cpp.template = "std::unordered_map") aMap ( 405 cpp2.ref_type = "unique", 406 ); 407 5: unionA aUnion (cpp2.ref_type = "unique"); 408 6: optional structA anOptionalStruct (cpp2.ref_type = "unique"); 409 7: optional list<string> (cpp.template = "std::deque") anOptionalList ( 410 cpp2.ref_type = "unique", 411 ); 412 8: optional set<string> (cpp.template = "std::unordered_set") anOptionalSet ( 413 cpp2.ref_type = "unique", 414 ); 415 9: optional map<string, string> ( 416 cpp.template = "std::unordered_map", 417 ) anOptionalMap (cpp2.ref_type = "unique"); 418 10: optional unionA anOptionalUnion (cpp2.ref_type = "unique"); 419} 420 421struct hasRefUniqueSimple { 422 // same as above, but no cpp.template annotations 423 1: structA aStruct (cpp2.ref_type = "unique"); 424 2: list<string> aList (cpp2.ref_type = "unique"); 425 3: set<string> aSet (cpp2.ref_type = "unique"); 426 4: map<string, string> aMap (cpp2.ref_type = "unique"); 427 5: unionA aUnion (cpp2.ref_type = "unique"); 428 6: optional structA anOptionalStruct (cpp2.ref_type = "unique"); 429 7: optional list<string> anOptionalList (cpp2.ref_type = "unique"); 430 8: optional set<string> anOptionalSet (cpp2.ref_type = "unique"); 431 9: optional map<string, string> anOptionalMap (cpp2.ref_type = "unique"); 432 10: optional unionA anOptionalUnion (cpp2.ref_type = "unique"); 433} 434 435union variantHasRefUnique { 436 1: structA aStruct (cpp2.ref_type = "unique"); 437 2: i32 anInt; 438} 439 440struct hasRefShared { 441 1: structA aStruct (cpp2.ref_type = "shared"); 442 2: list<string> (cpp.template = "std::deque") aList ( 443 cpp2.ref_type = "shared", 444 ); 445 3: set<string> (cpp.template = "std::unordered_set") aSet ( 446 cpp2.ref_type = "shared", 447 ); 448 4: map<string, string> (cpp.template = "std::unordered_map") aMap ( 449 cpp2.ref_type = "shared", 450 ); 451 5: unionA aUnion (cpp2.ref_type = "shared"); 452 6: optional structA anOptionalStruct (cpp2.ref_type = "shared"); 453 7: optional list<string> (cpp.template = "std::deque") anOptionalList ( 454 cpp2.ref_type = "shared", 455 ); 456 8: optional set<string> (cpp.template = "std::unordered_set") anOptionalSet ( 457 cpp2.ref_type = "shared", 458 ); 459 9: optional map<string, string> ( 460 cpp.template = "std::unordered_map", 461 ) anOptionalMap (cpp2.ref_type = "shared"); 462 10: optional unionA anOptionalUnion (cpp2.ref_type = "shared"); 463} 464 465struct hasRefSharedSimple { 466 // same as above, but no cpp.template annotations 467 1: structA aStruct (cpp2.ref_type = "shared"); 468 2: list<string> aList (cpp2.ref_type = "shared"); 469 3: set<string> aSet (cpp2.ref_type = "shared"); 470 4: map<string, string> aMap (cpp2.ref_type = "shared"); 471 5: unionA aUnion (cpp2.ref_type = "shared"); 472 6: optional structA anOptionalStruct (cpp2.ref_type = "shared"); 473 7: optional list<string> anOptionalList (cpp2.ref_type = "shared"); 474 8: optional set<string> anOptionalSet (cpp2.ref_type = "shared"); 475 9: optional map<string, string> anOptionalMap (cpp2.ref_type = "shared"); 476 10: optional unionA anOptionalUnion (cpp2.ref_type = "shared"); 477} 478 479struct hasRefSharedConst { 480 1: structA aStruct (cpp2.ref_type = "shared_const"); 481 2: list<string> (cpp.template = "std::deque") aList ( 482 cpp2.ref_type = "shared_const", 483 ); 484 3: set<string> (cpp.template = "std::unordered_set") aSet ( 485 cpp2.ref_type = "shared_const", 486 ); 487 4: map<string, string> (cpp.template = "std::unordered_map") aMap ( 488 cpp2.ref_type = "shared_const", 489 ); 490 5: unionA aUnion (cpp2.ref_type = "shared_const"); 491 6: optional structA anOptionalStruct (cpp2.ref_type = "shared_const"); 492 7: optional list<string> (cpp.template = "std::deque") anOptionalList ( 493 cpp2.ref_type = "shared_const", 494 ); 495 8: optional set<string> (cpp.template = "std::unordered_set") anOptionalSet ( 496 cpp2.ref_type = "shared_const", 497 ); 498 9: optional map<string, string> ( 499 cpp.template = "std::unordered_map", 500 ) anOptionalMap (cpp2.ref_type = "shared_const"); 501 10: optional unionA anOptionalUnion (cpp2.ref_type = "shared_const"); 502} 503 504struct hasRefSharedConstSimple { 505 // same as above, but no cpp.template annotations 506 1: structA aStruct (cpp2.ref_type = "shared_const"); 507 2: list<string> aList (cpp2.ref_type = "shared_const"); 508 3: set<string> aSet (cpp2.ref_type = "shared_const"); 509 4: map<string, string> aMap (cpp2.ref_type = "shared_const"); 510 5: unionA aUnion (cpp2.ref_type = "shared_const"); 511 6: optional structA anOptionalStruct (cpp2.ref_type = "shared_const"); 512 7: optional list<string> anOptionalList (cpp2.ref_type = "shared_const"); 513 8: optional set<string> anOptionalSet (cpp2.ref_type = "shared_const"); 514 9: optional map<string, string> anOptionalMap ( 515 cpp2.ref_type = "shared_const", 516 ); 517 10: optional unionA anOptionalUnion (cpp2.ref_type = "shared_const"); 518} 519 520struct hasBox { 521 6: optional structA anOptionalStruct (cpp.box); 522 7: optional list<string> (cpp.template = "std::deque") anOptionalList ( 523 cpp.box, 524 ); 525 8: optional set<string> (cpp.template = "std::unordered_set") anOptionalSet ( 526 cpp.box, 527 ); 528 9: optional map<string, string> ( 529 cpp.template = "std::unordered_map", 530 ) anOptionalMap (cpp.box); 531 10: optional unionA anOptionalUnion (cpp.box); 532} 533 534struct hasBoxSimple { 535 6: optional structA anOptionalStruct (cpp.box); 536 7: optional list<string> anOptionalList (cpp.box); 537 8: optional set<string> anOptionalSet (cpp.box); 538 9: optional map<string, string> anOptionalMap (cpp.box); 539 10: optional unionA anOptionalUnion (cpp.box); 540} 541 542struct StructWithIOBuf { 543 1: binary (cpp.type = "std::unique_ptr<folly::IOBuf>") buf; 544} 545 546struct struct_with_renamed_field { 547 1: string fancy.idl.name (cpp.name = "boring_cxx_name"); 548} 549 550union union_with_renamed_field { 551 1: string fancy.idl.name (cpp.name = "boring_cxx_name"); 552} 553