Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow declaring multiple members in one expression in shader structs #55903

Merged
merged 1 commit into from
Dec 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 53 additions & 39 deletions servers/rendering/shader_language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7648,57 +7648,71 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct
_set_error("void datatype not allowed here");
return ERR_PARSE_ERROR;
}
tk = _get_token();

if (tk.type != TK_IDENTIFIER && tk.type != TK_BRACKET_OPEN) {
_set_error("Expected identifier or '['.");
return ERR_PARSE_ERROR;
}

bool first = true;
bool fixed_array_size = false;
int array_size = 0;

if (tk.type == TK_BRACKET_OPEN) {
Error error = _parse_global_array_size(array_size, constants);
if (error != OK) {
return error;
}
do {
tk = _get_token();
}

if (tk.type != TK_IDENTIFIER) {
_set_error("Expected identifier!");
return ERR_PARSE_ERROR;
}
if (first) {
first = false;

MemberNode *member = alloc_node<MemberNode>();
member->precision = precision;
member->datatype = type;
member->struct_name = struct_name;
member->name = tk.text;
member->array_size = array_size;
if (tk.type != TK_IDENTIFIER && tk.type != TK_BRACKET_OPEN) {
_set_error("Expected identifier or '['.");
return ERR_PARSE_ERROR;
}

if (member_names.has(member->name)) {
_set_error("Redefinition of '" + String(member->name) + "'");
return ERR_PARSE_ERROR;
}
member_names.insert(member->name);
tk = _get_token();
if (tk.type == TK_BRACKET_OPEN) {
Error error = _parse_global_array_size(array_size, constants);
if (error != OK) {
return error;
}
fixed_array_size = true;
tk = _get_token();
}
}

if (tk.type == TK_BRACKET_OPEN) {
Error error = _parse_global_array_size(member->array_size, constants);
if (error != OK) {
return error;
if (tk.type != TK_IDENTIFIER) {
_set_error("Expected identifier!");
return ERR_PARSE_ERROR;
}

MemberNode *member = alloc_node<MemberNode>();
member->precision = precision;
member->datatype = type;
member->struct_name = struct_name;
member->name = tk.text;
member->array_size = array_size;

if (member_names.has(member->name)) {
_set_error("Redefinition of '" + String(member->name) + "'");
return ERR_PARSE_ERROR;
}
member_names.insert(member->name);
tk = _get_token();
}

if (tk.type != TK_SEMICOLON) {
_set_error("Expected ';'");
return ERR_PARSE_ERROR;
}
if (tk.type == TK_BRACKET_OPEN) {
Error error = _parse_global_array_size(member->array_size, constants);
if (error != OK) {
return error;
}
tk = _get_token();
}

if (!fixed_array_size) {
array_size = 0;
}

if (tk.type != TK_SEMICOLON && tk.type != TK_COMMA) {
_set_error("Expected ',' or ';' after struct member.");
return ERR_PARSE_ERROR;
}

st_node->members.push_back(member);
member_count++;
st_node->members.push_back(member);
member_count++;
} while (tk.type == TK_COMMA); // another member
}
}
if (member_count == 0) {
Expand Down