55#include " parser/declaration_parser.h"
66
77#include < cstddef>
8- #include < string>
98
109#include " ast/ast.h"
1110#include " ast/type.h"
@@ -158,7 +157,7 @@ Ast::Variable* Parser::DeclarationParser::ParseVariableDeclaration(
158157 if (name == nullptr ) INTERNAL_ERROR (" name is nullptr." );
159158
160159 // Checks if the variable is an array declaration.
161- if (*name == Ast::Statement::StatementType ::kArray )
160+ if (type-> GetTypeCategory () == Ast::Type::TypeCategory ::kArray )
162161 return ParseArrayDeclaration (type, name, token, length, index);
163162
164163 // Declaration with initialization value.
@@ -276,24 +275,19 @@ bool Parser::DeclarationParser::HasCustomTypeBeforeExpression(
276275Ast::ArrayDeclaration* Parser::DeclarationParser::ParseArrayDeclaration (
277276 Ast::Type* type, Ast::Expression* name, Token* token, std::size_t length,
278277 std::size_t & index) {
279-
280-
281278 if (token == nullptr ) INTERNAL_ERROR (" token is nullptr." );
282279 if (index >= length) INTERNAL_ERROR (" index is out of range." );
283- Ast::Array* array = Ast::Cast<Ast::Array>(name);
284- if (array == nullptr ) INTERNAL_ERROR (" name is not an array." );
285280
286281 if (token[index].value .oper == Token::OperatorType::equal) {
287282 index++;
288283 if (token[index].type == Token::Type::OPERATOR &&
289- token[index].value .oper == Token::OperatorType::l_brace ) {
284+ token[index].value .oper == Token::OperatorType::l_square ) {
290285 std::vector<Ast::Expression*> values;
291286 while (true ) {
292-
293- // Skip the l_brace or comma.
287+ // Skip the l_square or comma.
294288 values.push_back (ExpressionParser::ParseExpressionWithoutComma (
295289 token, length, ++index));
296- if (token[index] == Token::OperatorType::r_brace ) {
290+ if (token[index] == Token::OperatorType::r_square ) {
297291 index++;
298292 break ;
299293 }
@@ -303,15 +297,13 @@ Ast::ArrayDeclaration* Parser::DeclarationParser::ParseArrayDeclaration(
303297 " found." );
304298 }
305299 }
306- return new Ast::ArrayDeclaration (type, array->GetExpression (),
307- array->GetIndexExpression (), values);
300+ return new Ast::ArrayDeclaration (type, name, std::move (values));
308301 } else {
309302 LOGGING_ERROR (
310303 " Expected '{' or ',' after '=' in array declaration, but not found." );
311304 }
312305 }
313- return new Ast::ArrayDeclaration (type, array->GetExpression (),
314- array->GetIndexExpression ());
306+ return new Ast::ArrayDeclaration (type, name);
315307}
316308
317309} // namespace Aq
0 commit comments