| 1070 | } |
| 1071 | |
| 1072 | bool reshadefx::parser::parse_struct() |
| 1073 | { |
| 1074 | const location struct_location = std::move(_token.location); |
| 1075 | |
| 1076 | struct_type info; |
| 1077 | // The structure name is optional |
| 1078 | if (accept(tokenid::identifier)) |
| 1079 | info.name = std::move(_token.literal_as_string); |
| 1080 | else |
| 1081 | info.name = "_anonymous_struct_" + std::to_string(struct_location.line) + '_' + std::to_string(struct_location.column); |
| 1082 | |
| 1083 | info.unique_name = 'S' + current_scope().name + info.name; |
| 1084 | std::replace(info.unique_name.begin(), info.unique_name.end(), ':', '_'); |
| 1085 | |
| 1086 | if (!expect('{')) |
| 1087 | return false; |
| 1088 | |
| 1089 | bool parse_success = true; |
| 1090 | |
| 1091 | while (!peek('}')) // Empty structures are possible |
| 1092 | { |
| 1093 | member_type member; |
| 1094 | |
| 1095 | if (!parse_type(member.type)) |
| 1096 | { |
| 1097 | error(_token_next.location, 3000, "syntax error: unexpected '" + token::id_to_name(_token_next.id) + "', expected struct member type"); |
| 1098 | consume_until('}'); |
| 1099 | accept(';'); |
| 1100 | return false; |
| 1101 | } |
| 1102 | |
| 1103 | unsigned int count = 0; |
| 1104 | do |
| 1105 | { |
| 1106 | if ((count++ > 0 && !expect(',')) || !expect(tokenid::identifier)) |
| 1107 | { |
| 1108 | consume_until('}'); |
| 1109 | accept(';'); |
| 1110 | return false; |
| 1111 | } |
| 1112 | |
| 1113 | member.name = std::move(_token.literal_as_string); |
| 1114 | member.location = std::move(_token.location); |
| 1115 | |
| 1116 | if (member.type.is_void()) |
| 1117 | { |
| 1118 | parse_success = false; |
| 1119 | error(member.location, 3038, '\'' + member.name + "': struct members cannot be void"); |
| 1120 | } |
| 1121 | if (member.type.is_struct()) // Nesting structures would make input/output argument flattening more complicated, so prevent it for now |
| 1122 | { |
| 1123 | parse_success = false; |
| 1124 | error(member.location, 3090, '\'' + member.name + "': nested struct members are not supported"); |
| 1125 | } |
| 1126 | |
| 1127 | if (member.type.has(type::q_in) || member.type.has(type::q_out)) |
| 1128 | { |
| 1129 | parse_success = false; |
nothing calls this directly
no test coverage detected