Check for duplicate fields in the declaration visitor
This commit is contained in:
@ -15,8 +15,6 @@ You should have received a copy of the GNU General Public License
|
||||
along with GCC; see the file COPYING3. If not see
|
||||
<http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <set>
|
||||
|
||||
#include "elna/boot/semantic.h"
|
||||
|
||||
namespace elna
|
||||
@ -110,57 +108,17 @@ namespace boot
|
||||
this->current_type = type(std::make_shared<array_type>(this->current_type, type_expression->size));
|
||||
}
|
||||
|
||||
bool declaration_visitor::build_composite_type(const std::vector<field_declaration>& declarations,
|
||||
std::vector<type_field>& fields)
|
||||
void declaration_visitor::visit(record_type_expression *)
|
||||
{
|
||||
std::set<std::string> field_names;
|
||||
|
||||
for (auto& field : declarations)
|
||||
{
|
||||
if (field_names.find(field.first) != field_names.cend())
|
||||
{
|
||||
add_error<already_declared_error>(field.first, this->input_file, field.second->position());
|
||||
this->current_type = type();
|
||||
return false;
|
||||
}
|
||||
field.second->accept(this);
|
||||
if (!this->current_type.empty())
|
||||
{
|
||||
fields.push_back({ field.first, type(this->current_type) });
|
||||
}
|
||||
}
|
||||
return true;
|
||||
this->current_type = type(std::make_shared<record_type>());
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(record_type_expression *type_expression)
|
||||
void declaration_visitor::visit(union_type_expression *)
|
||||
{
|
||||
auto type_definition = std::make_shared<record_type>();
|
||||
|
||||
if (build_composite_type(type_expression->fields, type_definition->fields))
|
||||
{
|
||||
this->current_type = type(type_definition);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->current_type = type();
|
||||
}
|
||||
this->current_type = type(std::make_shared<union_type>());
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(union_type_expression *type_expression)
|
||||
{
|
||||
auto type_definition = std::make_shared<union_type>();
|
||||
|
||||
if (build_composite_type(type_expression->fields, type_definition->fields))
|
||||
{
|
||||
this->current_type = type(type_definition);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->current_type = type();
|
||||
}
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(procedure_type_expression *type_expression)
|
||||
void declaration_visitor::visit(procedure_type_expression *)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,6 @@ namespace elna
|
||||
namespace boot
|
||||
{
|
||||
type::type()
|
||||
: tag(type_tag::alias)
|
||||
{
|
||||
}
|
||||
|
||||
@ -145,6 +144,7 @@ namespace boot
|
||||
case type_tag::empty:
|
||||
break;
|
||||
case type_tag::alias:
|
||||
this->alias.~weak_ptr<alias_type>();
|
||||
break;
|
||||
case type_tag::primitive:
|
||||
this->primitive.~shared_ptr<primitive_type>();
|
||||
|
Reference in New Issue
Block a user