Support variable declaration initializer
This commit is contained in:
@@ -135,7 +135,8 @@ along with GCC; see the file COPYING3. If not see
|
||||
%type <std::vector<elna::boot::switch_case>> switch_cases;
|
||||
%type <elna::boot::constant_declaration *> constant_declaration;
|
||||
%type <std::vector<elna::boot::constant_declaration *>> constant_part constant_declarations;
|
||||
%type <std::vector<elna::boot::variable_declaration *>> variable_declarations variable_part variable_declaration;
|
||||
%type <elna::boot::variable_declaration *> variable_declaration;
|
||||
%type <std::vector<elna::boot::variable_declaration *>> variable_declarations variable_part;
|
||||
%type <elna::boot::type_expression *> type_expression;
|
||||
%type <std::vector<elna::boot::type_expression *>> type_expressions;
|
||||
%type <elna::boot::traits_expression *> traits_expression;
|
||||
@@ -501,24 +502,23 @@ identifiers:
|
||||
$$.emplace($$.cbegin(), std::move($1));
|
||||
}
|
||||
| IDENTIFIER { $$.emplace_back(std::move($1)); }
|
||||
variable_declaration: identifier_definitions ":" type_expression ";"
|
||||
variable_declaration:
|
||||
identifier_definitions ":" type_expression ";"
|
||||
{
|
||||
std::shared_ptr<boot::type_expression> shared_type{ $3 };
|
||||
|
||||
for (boot::identifier_definition& identifier : $1)
|
||||
{
|
||||
boot::variable_declaration *declaration = new boot::variable_declaration(
|
||||
boot::make_position(@2), std::move(identifier), shared_type);
|
||||
$$.push_back(declaration);
|
||||
}
|
||||
$$ = new boot::variable_declaration( boot::make_position(@2), std::move($1), shared_type);
|
||||
}
|
||||
| identifier_definitions ":" type_expression ":=" expression ";"
|
||||
{
|
||||
std::shared_ptr<boot::type_expression> shared_type{ $3 };
|
||||
$$ = new boot::variable_declaration( boot::make_position(@2), std::move($1), shared_type, $5);
|
||||
}
|
||||
variable_declarations:
|
||||
/* no variable declarations */ {}
|
||||
| variable_declaration variable_declarations
|
||||
{
|
||||
std::swap($$, $1);
|
||||
$$.reserve($$.size() + $2.size());
|
||||
$$.insert(std::end($$), std::begin($2), std::end($2));
|
||||
std::swap($$, $2);
|
||||
$$.insert(std::cbegin($$), $1);
|
||||
}
|
||||
variable_part:
|
||||
/* no variable declarations */ {}
|
||||
@@ -531,7 +531,7 @@ constant_declarations:
|
||||
constant_declaration constant_declarations
|
||||
{
|
||||
std::swap($$, $2);
|
||||
$$.insert($$.cbegin(), $1);
|
||||
$$.insert(std::cbegin($$), $1);
|
||||
}
|
||||
| /* no constant definitions */ {}
|
||||
constant_part:
|
||||
|
Reference in New Issue
Block a user