dynamic array type expression changed: 0 -> _

This commit is contained in:
ProgramSnail 2023-07-08 13:23:52 +03:00
parent 3815f8259b
commit d6e6d5cc2c
4 changed files with 42 additions and 20 deletions

View file

@ -1481,32 +1481,52 @@ void BuildVisitor::Visit(TypeExpression* node) {
auto suffix_node1 = current_node_.NextSibling();
// TODO: better structure // TODO: check
// TODO: refactor ?? // TODO: check
if (!suffix_node1.IsNull()) {
auto suffix_node2 = suffix_node1.NextSibling();
if (!suffix_node2.IsNull()) {
auto suffix_node3 = suffix_node2.NextSibling();
if (!suffix_node3.IsNull()) {
current_node_ = suffix_node2;
if (suffix_node2.GetValue() == "_") {
node->array_size = 0; // dynamic array
} else {
current_node_ = suffix_node2;
NumberLiteral size_literal;
Visit(&size_literal);
node->array_size = size_literal.value;
NumberLiteral literal;
Visit(&literal);
node->array_size = literal.value;
++excluded_child_count;
if (size_literal.value == 0) {
error_handling::HandleParsingError("Can't have zero sized arrays with constant length",
node->base.start_position,
node->base.end_position);
}
++excluded_child_count; // literal is named child
}
node->is_optional = true;
} else {
if (suffix_node1.GetValue() == "`" && suffix_node2.GetValue() == "?") {
node->array_size = 0;
node->is_optional = true;
error_handling::HandleInternalError("Array suffix should have size parameter or _",
"BuildVisitor.TypeExpression",
std::nullopt);
} else if (suffix_node1.GetValue() == "`") {
current_node_ = suffix_node2;
if (suffix_node2.GetValue() == "_") {
node->array_size = 0; // dynamic array
} else {
current_node_ = suffix_node2;
NumberLiteral size_literal;
Visit(&size_literal);
node->array_size = size_literal.value;
NumberLiteral literal;
Visit(&literal);
node->array_size = literal.value;
++excluded_child_count;
if (size_literal.value == 0) {
error_handling::HandleParsingError("Can't have zero sized arrays with constant length",
node->base.start_position,
node->base.end_position);
}
++excluded_child_count; // literal is named child
}
} else {
error_handling::HandleInternalError("Undefined suffix (2 elements)",
"BuildVisitor.TypeExpression",
@ -1515,7 +1535,9 @@ void BuildVisitor::Visit(TypeExpression* node) {
}
} else {
if (suffix_node1.GetValue() == "`") {
node->array_size = 0;
error_handling::HandleInternalError("Array suffix should have size parameter or _",
"BuildVisitor.TypeExpression",
std::nullopt);
} else if (suffix_node1.GetValue() == "?") {
node->is_optional = true;
} else {