| 976 | return res; |
| 977 | } |
| 978 | id define_function(const location &loc, function &info) override |
| 979 | { |
| 980 | const id res = info.id = make_id(); |
| 981 | |
| 982 | // Name is used in other places like the entry point defines, so escape it here |
| 983 | info.unique_name = escape_name(info.unique_name); |
| 984 | |
| 985 | assert(!info.unique_name.empty() && (info.unique_name[0] == 'F' || info.unique_name[0] == 'E')); |
| 986 | const bool is_entry_point = info.unique_name[0] == 'E'; |
| 987 | if (!is_entry_point) |
| 988 | define_name<naming::unique>(res, info.unique_name); |
| 989 | else |
| 990 | define_name<naming::reserved>(res, "main"); |
| 991 | |
| 992 | assert(_current_block == 0 && (_current_function_declaration.empty() || is_entry_point)); |
| 993 | std::string &code = _current_function_declaration; |
| 994 | |
| 995 | write_location(code, loc); |
| 996 | |
| 997 | write_type(code, info.return_type); |
| 998 | code += ' ' + id_to_name(res) + '('; |
| 999 | |
| 1000 | assert(info.parameter_list.empty() || !is_entry_point); |
| 1001 | |
| 1002 | for (member_type ¶m : info.parameter_list) |
| 1003 | { |
| 1004 | param.id = make_id(); |
| 1005 | define_name<naming::unique>(param.id, param.name); |
| 1006 | |
| 1007 | code += '\n'; |
| 1008 | write_location(code, param.location); |
| 1009 | code += '\t'; |
| 1010 | write_type<true>(code, param.type); // GLSL does not allow interpolation attributes on function parameters |
| 1011 | code += ' ' + id_to_name(param.id); |
| 1012 | |
| 1013 | if (param.type.is_array()) |
| 1014 | code += '[' + std::to_string(param.type.array_length) + ']'; |
| 1015 | |
| 1016 | code += ','; |
| 1017 | } |
| 1018 | |
| 1019 | // Remove trailing comma |
| 1020 | if (!info.parameter_list.empty()) |
| 1021 | code.pop_back(); |
| 1022 | |
| 1023 | code += ")\n"; |
| 1024 | |
| 1025 | _functions.push_back(std::make_unique<function>(info)); |
| 1026 | _current_function = _functions.back().get(); |
| 1027 | |
| 1028 | return res; |
| 1029 | } |
| 1030 | |
| 1031 | void define_entry_point(function &func) override |
| 1032 | { |
no test coverage detected