diff --git a/BUILD b/BUILD index f62f70651b1..dca5c8cdee0 100644 --- a/BUILD +++ b/BUILD @@ -878,6 +878,15 @@ grpc_cc_library( deps = ["gpr_platform"], ) +grpc_cc_library( + name = "switch", + language = "c++", + public_hdrs = [ + "src/core/lib/promise/detail/switch.h", + ], + deps = ["gpr_platform"], +) + grpc_cc_library( name = "ref_counted", language = "c++", diff --git a/src/core/lib/promise/detail/switch.h b/src/core/lib/promise/detail/switch.h new file mode 100644 index 00000000000..f164e23c4da --- /dev/null +++ b/src/core/lib/promise/detail/switch.h @@ -0,0 +1,1455 @@ +/* + * Copyright 2021 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Automatically generated by tools/codegen/core/gen_switch.py + */ + +#ifndef GRPC_CORE_LIB_PROMISE_DETAIL_SWITCH_H +#define GRPC_CORE_LIB_PROMISE_DETAIL_SWITCH_H + +#include + +#include + +namespace grpc_core { + +template +R Switch(char idx, F0 f0) { + switch (idx) { + case 0: + return f0(); + } + abort(); +} + +template +R Switch(char idx, F0 f0, F1 f1) { + switch (idx) { + case 0: + return f0(); + case 1: + return f1(); + } + abort(); +} + +template +R Switch(char idx, F0 f0, F1 f1, F2 f2) { + switch (idx) { + case 0: + return f0(); + case 1: + return f1(); + case 2: + return f2(); + } + abort(); +} + +template +R Switch(char idx, F0 f0, F1 f1, F2 f2, F3 f3) { + switch (idx) { + case 0: + return f0(); + case 1: + return f1(); + case 2: + return f2(); + case 3: + return f3(); + } + abort(); +} + +template +R Switch(char idx, F0 f0, F1 f1, F2 f2, F3 f3, F4 f4) { + switch (idx) { + case 0: + return f0(); + case 1: + return f1(); + case 2: + return f2(); + case 3: + return f3(); + case 4: + return f4(); + } + abort(); +} + +template +R Switch(char idx, F0 f0, F1 f1, F2 f2, F3 f3, F4 f4, F5 f5) { + switch (idx) { + case 0: + return f0(); + case 1: + return f1(); + case 2: + return f2(); + case 3: + return f3(); + case 4: + return f4(); + case 5: + return f5(); + } + abort(); +} + +template +R Switch(char idx, F0 f0, F1 f1, F2 f2, F3 f3, F4 f4, F5 f5, F6 f6) { + switch (idx) { + case 0: + return f0(); + case 1: + return f1(); + case 2: + return f2(); + case 3: + return f3(); + case 4: + return f4(); + case 5: + return f5(); + case 6: + return f6(); + } + abort(); +} + +template +R Switch(char idx, F0 f0, F1 f1, F2 f2, F3 f3, F4 f4, F5 f5, F6 f6, F7 f7) { + switch (idx) { + case 0: + return f0(); + case 1: + return f1(); + case 2: + return f2(); + case 3: + return f3(); + case 4: + return f4(); + case 5: + return f5(); + case 6: + return f6(); + case 7: + return f7(); + } + abort(); +} + +template +R Switch(char idx, F0 f0, F1 f1, F2 f2, F3 f3, F4 f4, F5 f5, F6 f6, F7 f7, + F8 f8) { + switch (idx) { + case 0: + return f0(); + case 1: + return f1(); + case 2: + return f2(); + case 3: + return f3(); + case 4: + return f4(); + case 5: + return f5(); + case 6: + return f6(); + case 7: + return f7(); + case 8: + return f8(); + } + abort(); +} + +template +R Switch(char idx, F0 f0, F1 f1, F2 f2, F3 f3, F4 f4, F5 f5, F6 f6, F7 f7, + F8 f8, F9 f9) { + switch (idx) { + case 0: + return f0(); + case 1: + return f1(); + case 2: + return f2(); + case 3: + return f3(); + case 4: + return f4(); + case 5: + return f5(); + case 6: + return f6(); + case 7: + return f7(); + case 8: + return f8(); + case 9: + return f9(); + } + abort(); +} + +template +R Switch(char idx, F0 f0, F1 f1, F2 f2, F3 f3, F4 f4, F5 f5, F6 f6, F7 f7, + F8 f8, F9 f9, F10 f10) { + switch (idx) { + case 0: + return f0(); + case 1: + return f1(); + case 2: + return f2(); + case 3: + return f3(); + case 4: + return f4(); + case 5: + return f5(); + case 6: + return f6(); + case 7: + return f7(); + case 8: + return f8(); + case 9: + return f9(); + case 10: + return f10(); + } + abort(); +} + +template +R Switch(char idx, F0 f0, F1 f1, F2 f2, F3 f3, F4 f4, F5 f5, F6 f6, F7 f7, + F8 f8, F9 f9, F10 f10, F11 f11) { + switch (idx) { + case 0: + return f0(); + case 1: + return f1(); + case 2: + return f2(); + case 3: + return f3(); + case 4: + return f4(); + case 5: + return f5(); + case 6: + return f6(); + case 7: + return f7(); + case 8: + return f8(); + case 9: + return f9(); + case 10: + return f10(); + case 11: + return f11(); + } + abort(); +} + +template +R Switch(char idx, F0 f0, F1 f1, F2 f2, F3 f3, F4 f4, F5 f5, F6 f6, F7 f7, + F8 f8, F9 f9, F10 f10, F11 f11, F12 f12) { + switch (idx) { + case 0: + return f0(); + case 1: + return f1(); + case 2: + return f2(); + case 3: + return f3(); + case 4: + return f4(); + case 5: + return f5(); + case 6: + return f6(); + case 7: + return f7(); + case 8: + return f8(); + case 9: + return f9(); + case 10: + return f10(); + case 11: + return f11(); + case 12: + return f12(); + } + abort(); +} + +template +R Switch(char idx, F0 f0, F1 f1, F2 f2, F3 f3, F4 f4, F5 f5, F6 f6, F7 f7, + F8 f8, F9 f9, F10 f10, F11 f11, F12 f12, F13 f13) { + switch (idx) { + case 0: + return f0(); + case 1: + return f1(); + case 2: + return f2(); + case 3: + return f3(); + case 4: + return f4(); + case 5: + return f5(); + case 6: + return f6(); + case 7: + return f7(); + case 8: + return f8(); + case 9: + return f9(); + case 10: + return f10(); + case 11: + return f11(); + case 12: + return f12(); + case 13: + return f13(); + } + abort(); +} + +template +R Switch(char idx, F0 f0, F1 f1, F2 f2, F3 f3, F4 f4, F5 f5, F6 f6, F7 f7, + F8 f8, F9 f9, F10 f10, F11 f11, F12 f12, F13 f13, F14 f14) { + switch (idx) { + case 0: + return f0(); + case 1: + return f1(); + case 2: + return f2(); + case 3: + return f3(); + case 4: + return f4(); + case 5: + return f5(); + case 6: + return f6(); + case 7: + return f7(); + case 8: + return f8(); + case 9: + return f9(); + case 10: + return f10(); + case 11: + return f11(); + case 12: + return f12(); + case 13: + return f13(); + case 14: + return f14(); + } + abort(); +} + +template +R Switch(char idx, F0 f0, F1 f1, F2 f2, F3 f3, F4 f4, F5 f5, F6 f6, F7 f7, + F8 f8, F9 f9, F10 f10, F11 f11, F12 f12, F13 f13, F14 f14, F15 f15) { + switch (idx) { + case 0: + return f0(); + case 1: + return f1(); + case 2: + return f2(); + case 3: + return f3(); + case 4: + return f4(); + case 5: + return f5(); + case 6: + return f6(); + case 7: + return f7(); + case 8: + return f8(); + case 9: + return f9(); + case 10: + return f10(); + case 11: + return f11(); + case 12: + return f12(); + case 13: + return f13(); + case 14: + return f14(); + case 15: + return f15(); + } + abort(); +} + +template +R Switch(char idx, F0 f0, F1 f1, F2 f2, F3 f3, F4 f4, F5 f5, F6 f6, F7 f7, + F8 f8, F9 f9, F10 f10, F11 f11, F12 f12, F13 f13, F14 f14, F15 f15, + F16 f16) { + switch (idx) { + case 0: + return f0(); + case 1: + return f1(); + case 2: + return f2(); + case 3: + return f3(); + case 4: + return f4(); + case 5: + return f5(); + case 6: + return f6(); + case 7: + return f7(); + case 8: + return f8(); + case 9: + return f9(); + case 10: + return f10(); + case 11: + return f11(); + case 12: + return f12(); + case 13: + return f13(); + case 14: + return f14(); + case 15: + return f15(); + case 16: + return f16(); + } + abort(); +} + +template +R Switch(char idx, F0 f0, F1 f1, F2 f2, F3 f3, F4 f4, F5 f5, F6 f6, F7 f7, + F8 f8, F9 f9, F10 f10, F11 f11, F12 f12, F13 f13, F14 f14, F15 f15, + F16 f16, F17 f17) { + switch (idx) { + case 0: + return f0(); + case 1: + return f1(); + case 2: + return f2(); + case 3: + return f3(); + case 4: + return f4(); + case 5: + return f5(); + case 6: + return f6(); + case 7: + return f7(); + case 8: + return f8(); + case 9: + return f9(); + case 10: + return f10(); + case 11: + return f11(); + case 12: + return f12(); + case 13: + return f13(); + case 14: + return f14(); + case 15: + return f15(); + case 16: + return f16(); + case 17: + return f17(); + } + abort(); +} + +template +R Switch(char idx, F0 f0, F1 f1, F2 f2, F3 f3, F4 f4, F5 f5, F6 f6, F7 f7, + F8 f8, F9 f9, F10 f10, F11 f11, F12 f12, F13 f13, F14 f14, F15 f15, + F16 f16, F17 f17, F18 f18) { + switch (idx) { + case 0: + return f0(); + case 1: + return f1(); + case 2: + return f2(); + case 3: + return f3(); + case 4: + return f4(); + case 5: + return f5(); + case 6: + return f6(); + case 7: + return f7(); + case 8: + return f8(); + case 9: + return f9(); + case 10: + return f10(); + case 11: + return f11(); + case 12: + return f12(); + case 13: + return f13(); + case 14: + return f14(); + case 15: + return f15(); + case 16: + return f16(); + case 17: + return f17(); + case 18: + return f18(); + } + abort(); +} + +template +R Switch(char idx, F0 f0, F1 f1, F2 f2, F3 f3, F4 f4, F5 f5, F6 f6, F7 f7, + F8 f8, F9 f9, F10 f10, F11 f11, F12 f12, F13 f13, F14 f14, F15 f15, + F16 f16, F17 f17, F18 f18, F19 f19) { + switch (idx) { + case 0: + return f0(); + case 1: + return f1(); + case 2: + return f2(); + case 3: + return f3(); + case 4: + return f4(); + case 5: + return f5(); + case 6: + return f6(); + case 7: + return f7(); + case 8: + return f8(); + case 9: + return f9(); + case 10: + return f10(); + case 11: + return f11(); + case 12: + return f12(); + case 13: + return f13(); + case 14: + return f14(); + case 15: + return f15(); + case 16: + return f16(); + case 17: + return f17(); + case 18: + return f18(); + case 19: + return f19(); + } + abort(); +} + +template +R Switch(char idx, F0 f0, F1 f1, F2 f2, F3 f3, F4 f4, F5 f5, F6 f6, F7 f7, + F8 f8, F9 f9, F10 f10, F11 f11, F12 f12, F13 f13, F14 f14, F15 f15, + F16 f16, F17 f17, F18 f18, F19 f19, F20 f20) { + switch (idx) { + case 0: + return f0(); + case 1: + return f1(); + case 2: + return f2(); + case 3: + return f3(); + case 4: + return f4(); + case 5: + return f5(); + case 6: + return f6(); + case 7: + return f7(); + case 8: + return f8(); + case 9: + return f9(); + case 10: + return f10(); + case 11: + return f11(); + case 12: + return f12(); + case 13: + return f13(); + case 14: + return f14(); + case 15: + return f15(); + case 16: + return f16(); + case 17: + return f17(); + case 18: + return f18(); + case 19: + return f19(); + case 20: + return f20(); + } + abort(); +} + +template +R Switch(char idx, F0 f0, F1 f1, F2 f2, F3 f3, F4 f4, F5 f5, F6 f6, F7 f7, + F8 f8, F9 f9, F10 f10, F11 f11, F12 f12, F13 f13, F14 f14, F15 f15, + F16 f16, F17 f17, F18 f18, F19 f19, F20 f20, F21 f21) { + switch (idx) { + case 0: + return f0(); + case 1: + return f1(); + case 2: + return f2(); + case 3: + return f3(); + case 4: + return f4(); + case 5: + return f5(); + case 6: + return f6(); + case 7: + return f7(); + case 8: + return f8(); + case 9: + return f9(); + case 10: + return f10(); + case 11: + return f11(); + case 12: + return f12(); + case 13: + return f13(); + case 14: + return f14(); + case 15: + return f15(); + case 16: + return f16(); + case 17: + return f17(); + case 18: + return f18(); + case 19: + return f19(); + case 20: + return f20(); + case 21: + return f21(); + } + abort(); +} + +template +R Switch(char idx, F0 f0, F1 f1, F2 f2, F3 f3, F4 f4, F5 f5, F6 f6, F7 f7, + F8 f8, F9 f9, F10 f10, F11 f11, F12 f12, F13 f13, F14 f14, F15 f15, + F16 f16, F17 f17, F18 f18, F19 f19, F20 f20, F21 f21, F22 f22) { + switch (idx) { + case 0: + return f0(); + case 1: + return f1(); + case 2: + return f2(); + case 3: + return f3(); + case 4: + return f4(); + case 5: + return f5(); + case 6: + return f6(); + case 7: + return f7(); + case 8: + return f8(); + case 9: + return f9(); + case 10: + return f10(); + case 11: + return f11(); + case 12: + return f12(); + case 13: + return f13(); + case 14: + return f14(); + case 15: + return f15(); + case 16: + return f16(); + case 17: + return f17(); + case 18: + return f18(); + case 19: + return f19(); + case 20: + return f20(); + case 21: + return f21(); + case 22: + return f22(); + } + abort(); +} + +template +R Switch(char idx, F0 f0, F1 f1, F2 f2, F3 f3, F4 f4, F5 f5, F6 f6, F7 f7, + F8 f8, F9 f9, F10 f10, F11 f11, F12 f12, F13 f13, F14 f14, F15 f15, + F16 f16, F17 f17, F18 f18, F19 f19, F20 f20, F21 f21, F22 f22, + F23 f23) { + switch (idx) { + case 0: + return f0(); + case 1: + return f1(); + case 2: + return f2(); + case 3: + return f3(); + case 4: + return f4(); + case 5: + return f5(); + case 6: + return f6(); + case 7: + return f7(); + case 8: + return f8(); + case 9: + return f9(); + case 10: + return f10(); + case 11: + return f11(); + case 12: + return f12(); + case 13: + return f13(); + case 14: + return f14(); + case 15: + return f15(); + case 16: + return f16(); + case 17: + return f17(); + case 18: + return f18(); + case 19: + return f19(); + case 20: + return f20(); + case 21: + return f21(); + case 22: + return f22(); + case 23: + return f23(); + } + abort(); +} + +template +R Switch(char idx, F0 f0, F1 f1, F2 f2, F3 f3, F4 f4, F5 f5, F6 f6, F7 f7, + F8 f8, F9 f9, F10 f10, F11 f11, F12 f12, F13 f13, F14 f14, F15 f15, + F16 f16, F17 f17, F18 f18, F19 f19, F20 f20, F21 f21, F22 f22, F23 f23, + F24 f24) { + switch (idx) { + case 0: + return f0(); + case 1: + return f1(); + case 2: + return f2(); + case 3: + return f3(); + case 4: + return f4(); + case 5: + return f5(); + case 6: + return f6(); + case 7: + return f7(); + case 8: + return f8(); + case 9: + return f9(); + case 10: + return f10(); + case 11: + return f11(); + case 12: + return f12(); + case 13: + return f13(); + case 14: + return f14(); + case 15: + return f15(); + case 16: + return f16(); + case 17: + return f17(); + case 18: + return f18(); + case 19: + return f19(); + case 20: + return f20(); + case 21: + return f21(); + case 22: + return f22(); + case 23: + return f23(); + case 24: + return f24(); + } + abort(); +} + +template +R Switch(char idx, F0 f0, F1 f1, F2 f2, F3 f3, F4 f4, F5 f5, F6 f6, F7 f7, + F8 f8, F9 f9, F10 f10, F11 f11, F12 f12, F13 f13, F14 f14, F15 f15, + F16 f16, F17 f17, F18 f18, F19 f19, F20 f20, F21 f21, F22 f22, F23 f23, + F24 f24, F25 f25) { + switch (idx) { + case 0: + return f0(); + case 1: + return f1(); + case 2: + return f2(); + case 3: + return f3(); + case 4: + return f4(); + case 5: + return f5(); + case 6: + return f6(); + case 7: + return f7(); + case 8: + return f8(); + case 9: + return f9(); + case 10: + return f10(); + case 11: + return f11(); + case 12: + return f12(); + case 13: + return f13(); + case 14: + return f14(); + case 15: + return f15(); + case 16: + return f16(); + case 17: + return f17(); + case 18: + return f18(); + case 19: + return f19(); + case 20: + return f20(); + case 21: + return f21(); + case 22: + return f22(); + case 23: + return f23(); + case 24: + return f24(); + case 25: + return f25(); + } + abort(); +} + +template +R Switch(char idx, F0 f0, F1 f1, F2 f2, F3 f3, F4 f4, F5 f5, F6 f6, F7 f7, + F8 f8, F9 f9, F10 f10, F11 f11, F12 f12, F13 f13, F14 f14, F15 f15, + F16 f16, F17 f17, F18 f18, F19 f19, F20 f20, F21 f21, F22 f22, F23 f23, + F24 f24, F25 f25, F26 f26) { + switch (idx) { + case 0: + return f0(); + case 1: + return f1(); + case 2: + return f2(); + case 3: + return f3(); + case 4: + return f4(); + case 5: + return f5(); + case 6: + return f6(); + case 7: + return f7(); + case 8: + return f8(); + case 9: + return f9(); + case 10: + return f10(); + case 11: + return f11(); + case 12: + return f12(); + case 13: + return f13(); + case 14: + return f14(); + case 15: + return f15(); + case 16: + return f16(); + case 17: + return f17(); + case 18: + return f18(); + case 19: + return f19(); + case 20: + return f20(); + case 21: + return f21(); + case 22: + return f22(); + case 23: + return f23(); + case 24: + return f24(); + case 25: + return f25(); + case 26: + return f26(); + } + abort(); +} + +template +R Switch(char idx, F0 f0, F1 f1, F2 f2, F3 f3, F4 f4, F5 f5, F6 f6, F7 f7, + F8 f8, F9 f9, F10 f10, F11 f11, F12 f12, F13 f13, F14 f14, F15 f15, + F16 f16, F17 f17, F18 f18, F19 f19, F20 f20, F21 f21, F22 f22, F23 f23, + F24 f24, F25 f25, F26 f26, F27 f27) { + switch (idx) { + case 0: + return f0(); + case 1: + return f1(); + case 2: + return f2(); + case 3: + return f3(); + case 4: + return f4(); + case 5: + return f5(); + case 6: + return f6(); + case 7: + return f7(); + case 8: + return f8(); + case 9: + return f9(); + case 10: + return f10(); + case 11: + return f11(); + case 12: + return f12(); + case 13: + return f13(); + case 14: + return f14(); + case 15: + return f15(); + case 16: + return f16(); + case 17: + return f17(); + case 18: + return f18(); + case 19: + return f19(); + case 20: + return f20(); + case 21: + return f21(); + case 22: + return f22(); + case 23: + return f23(); + case 24: + return f24(); + case 25: + return f25(); + case 26: + return f26(); + case 27: + return f27(); + } + abort(); +} + +template +R Switch(char idx, F0 f0, F1 f1, F2 f2, F3 f3, F4 f4, F5 f5, F6 f6, F7 f7, + F8 f8, F9 f9, F10 f10, F11 f11, F12 f12, F13 f13, F14 f14, F15 f15, + F16 f16, F17 f17, F18 f18, F19 f19, F20 f20, F21 f21, F22 f22, F23 f23, + F24 f24, F25 f25, F26 f26, F27 f27, F28 f28) { + switch (idx) { + case 0: + return f0(); + case 1: + return f1(); + case 2: + return f2(); + case 3: + return f3(); + case 4: + return f4(); + case 5: + return f5(); + case 6: + return f6(); + case 7: + return f7(); + case 8: + return f8(); + case 9: + return f9(); + case 10: + return f10(); + case 11: + return f11(); + case 12: + return f12(); + case 13: + return f13(); + case 14: + return f14(); + case 15: + return f15(); + case 16: + return f16(); + case 17: + return f17(); + case 18: + return f18(); + case 19: + return f19(); + case 20: + return f20(); + case 21: + return f21(); + case 22: + return f22(); + case 23: + return f23(); + case 24: + return f24(); + case 25: + return f25(); + case 26: + return f26(); + case 27: + return f27(); + case 28: + return f28(); + } + abort(); +} + +template +R Switch(char idx, F0 f0, F1 f1, F2 f2, F3 f3, F4 f4, F5 f5, F6 f6, F7 f7, + F8 f8, F9 f9, F10 f10, F11 f11, F12 f12, F13 f13, F14 f14, F15 f15, + F16 f16, F17 f17, F18 f18, F19 f19, F20 f20, F21 f21, F22 f22, F23 f23, + F24 f24, F25 f25, F26 f26, F27 f27, F28 f28, F29 f29) { + switch (idx) { + case 0: + return f0(); + case 1: + return f1(); + case 2: + return f2(); + case 3: + return f3(); + case 4: + return f4(); + case 5: + return f5(); + case 6: + return f6(); + case 7: + return f7(); + case 8: + return f8(); + case 9: + return f9(); + case 10: + return f10(); + case 11: + return f11(); + case 12: + return f12(); + case 13: + return f13(); + case 14: + return f14(); + case 15: + return f15(); + case 16: + return f16(); + case 17: + return f17(); + case 18: + return f18(); + case 19: + return f19(); + case 20: + return f20(); + case 21: + return f21(); + case 22: + return f22(); + case 23: + return f23(); + case 24: + return f24(); + case 25: + return f25(); + case 26: + return f26(); + case 27: + return f27(); + case 28: + return f28(); + case 29: + return f29(); + } + abort(); +} + +template +R Switch(char idx, F0 f0, F1 f1, F2 f2, F3 f3, F4 f4, F5 f5, F6 f6, F7 f7, + F8 f8, F9 f9, F10 f10, F11 f11, F12 f12, F13 f13, F14 f14, F15 f15, + F16 f16, F17 f17, F18 f18, F19 f19, F20 f20, F21 f21, F22 f22, F23 f23, + F24 f24, F25 f25, F26 f26, F27 f27, F28 f28, F29 f29, F30 f30) { + switch (idx) { + case 0: + return f0(); + case 1: + return f1(); + case 2: + return f2(); + case 3: + return f3(); + case 4: + return f4(); + case 5: + return f5(); + case 6: + return f6(); + case 7: + return f7(); + case 8: + return f8(); + case 9: + return f9(); + case 10: + return f10(); + case 11: + return f11(); + case 12: + return f12(); + case 13: + return f13(); + case 14: + return f14(); + case 15: + return f15(); + case 16: + return f16(); + case 17: + return f17(); + case 18: + return f18(); + case 19: + return f19(); + case 20: + return f20(); + case 21: + return f21(); + case 22: + return f22(); + case 23: + return f23(); + case 24: + return f24(); + case 25: + return f25(); + case 26: + return f26(); + case 27: + return f27(); + case 28: + return f28(); + case 29: + return f29(); + case 30: + return f30(); + } + abort(); +} + +template +R Switch(char idx, F0 f0, F1 f1, F2 f2, F3 f3, F4 f4, F5 f5, F6 f6, F7 f7, + F8 f8, F9 f9, F10 f10, F11 f11, F12 f12, F13 f13, F14 f14, F15 f15, + F16 f16, F17 f17, F18 f18, F19 f19, F20 f20, F21 f21, F22 f22, F23 f23, + F24 f24, F25 f25, F26 f26, F27 f27, F28 f28, F29 f29, F30 f30, + F31 f31) { + switch (idx) { + case 0: + return f0(); + case 1: + return f1(); + case 2: + return f2(); + case 3: + return f3(); + case 4: + return f4(); + case 5: + return f5(); + case 6: + return f6(); + case 7: + return f7(); + case 8: + return f8(); + case 9: + return f9(); + case 10: + return f10(); + case 11: + return f11(); + case 12: + return f12(); + case 13: + return f13(); + case 14: + return f14(); + case 15: + return f15(); + case 16: + return f16(); + case 17: + return f17(); + case 18: + return f18(); + case 19: + return f19(); + case 20: + return f20(); + case 21: + return f21(); + case 22: + return f22(); + case 23: + return f23(); + case 24: + return f24(); + case 25: + return f25(); + case 26: + return f26(); + case 27: + return f27(); + case 28: + return f28(); + case 29: + return f29(); + case 30: + return f30(); + case 31: + return f31(); + } + abort(); +} + +} // namespace grpc_core + +#endif // GRPC_CORE_LIB_PROMISE_DETAIL_SWITCH_H diff --git a/tools/codegen/core/gen_switch.py b/tools/codegen/core/gen_switch.py new file mode 100755 index 00000000000..6667959aec3 --- /dev/null +++ b/tools/codegen/core/gen_switch.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python3 + +# Copyright 2021 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys + + +# utility: print a big comment block into a set of files +def put_banner(files, banner): + for f in files: + print('/*', file=f) + for line in banner: + print(' * %s' % line, file=f) + print(' */', file=f) + print('', file=f) + + +with open('src/core/lib/promise/detail/switch.h', 'w') as H: + # copy-paste copyright notice from this file + with open(sys.argv[0]) as my_source: + copyright = [] + for line in my_source: + if line[0] != '#': + break + for line in my_source: + if line[0] == '#': + copyright.append(line) + break + for line in my_source: + if line[0] != '#': + break + copyright.append(line) + put_banner([H], [line[2:].rstrip() for line in copyright]) + + put_banner([H], ["Automatically generated by %s" % sys.argv[0]]) + + print("#ifndef GRPC_CORE_LIB_PROMISE_DETAIL_SWITCH_H", file=H) + print("#define GRPC_CORE_LIB_PROMISE_DETAIL_SWITCH_H", file=H) + print('', file=H) + print('#include ', file=H) + print('', file=H) + print("#include ", file=H) + print('', file=H) + print("namespace grpc_core {", file=H) + + for n in range(1, 33): + print('', file=H) + print("template R Switch(char idx, %s) {" % ( + ", ".join("typename F%d" % i for i in range(0, n)), + ", ".join("F%d f%d" % (i, i) for i in range(0, n)), + ), + file=H) + print(" switch (idx) {", file=H) + for i in range(0, n): + print(" case %d: return f%d();" % (i, i), file=H) + print(" }", file=H) + print(" abort();", file=H) + print("}", file=H) + + print('', file=H) + print("}", file=H) + print('', file=H) + print("#endif // GRPC_CORE_LIB_PROMISE_DETAIL_SWITCH_H", file=H)