/* * Copyright (c) Meta Platforms, Inc. and affiliates. * * 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. */ #pragma once #include #include #include #include #include #include #include #include #include /** * Helper function to instantiate fake t_functions of the form: * f = create_fake_function("function_name") */ template std::unique_ptr create_fake_function( std::string name, t_program* program = nullptr) { using signature = func_signature; std::unique_ptr args(new t_paramlist(program)); std::size_t index = 0; for (auto& arg : signature::args_types()) { args->append(std::make_unique( arg.release(), fmt::format("arg_{}", index++))); } return std::make_unique( signature::return_type().release(), std::move(name), std::move(args)); } /** * Helper function to instantiate fake t_services */ inline std::unique_ptr create_fake_service( std::string name, t_program* program = nullptr) { return std::make_unique(program, std::move(name)); } /** * Helper function to instantiate fake t_enums */ inline std::unique_ptr create_fake_enum( std::string name, t_program* program = nullptr) { return std::make_unique(program, std::move(name)); } /** * Helper function to parse thrift content to t_program */ std::shared_ptr dedent_and_parse_to_program( source_manager& sm, std::string source);