Check for duplicate fields in the declaration visitor

This commit is contained in:
2025-03-15 23:01:05 +01:00
parent fa73f14070
commit f6e0ead4fb
9 changed files with 88 additions and 151 deletions

View File

@ -52,12 +52,10 @@ namespace boot
{
type current_type;
std::shared_ptr<symbol_table> symbols;
std::unordered_map<std::string, std::shared_ptr<alias_type>> unresolved;
bool build_composite_type(const std::vector<field_declaration>& declarations,
std::vector<type_field>& fields);
public:
std::unordered_map<std::string, std::shared_ptr<alias_type>> unresolved;
explicit declaration_visitor(const char *path, std::shared_ptr<symbol_table> symbols);
void visit(primitive_type_expression *type_expression) override;
@ -65,9 +63,9 @@ namespace boot
void visit(pointer_type_expression *type_expression) override;
void visit(program *program) override;
void visit(type_definition *definition) override;
void visit(record_type_expression *type_expression) override;
void visit(union_type_expression *type_expression) override;
void visit(procedure_type_expression *type_expression) override;
void visit(record_type_expression *) override;
void visit(union_type_expression *) override;
void visit(procedure_type_expression *) override;
};
}
}

View File

@ -113,16 +113,12 @@ namespace boot
explicit primitive_type(const std::string& identifier);
};
using type_field = typename std::pair<std::string, type>;
struct record_type
{
std::vector<type_field> fields;
};
struct union_type
{
std::vector<type_field> fields;
};
class type_info;

View File

@ -15,16 +15,21 @@ 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 <memory>
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tree.h"
#include "tree-iterator.h"
#include "elna/gcc/elna-tree.h"
namespace elna
{
namespace gcc
{
void init_ttree();
std::shared_ptr<symbol_table> builtin_symbol_table();
}
}

View File

@ -35,7 +35,9 @@ namespace elna
namespace gcc
{
std::deque<std::unique_ptr<boot::error>> do_semantic_analysis(const char *path,
std::unique_ptr<boot::program>& ast, std::shared_ptr<symbol_table> symbols);
std::unique_ptr<boot::program>& ast, std::shared_ptr<boot::symbol_table> info_table,
std::shared_ptr<symbol_table> symbols);
tree handle_symbol(const std::string& symbol_name, const boot::type& type, std::shared_ptr<symbol_table> symbols);
class generic_visitor final : public boot::empty_visitor
{
@ -44,12 +46,12 @@ namespace gcc
tree build_label_decl(const char *name, location_t loc);
tree build_procedure_type(boot::procedure_type_expression& type);
void build_composite_type(const std::vector<boot::field_declaration>& fields,
tree composite_type_node);
void enter_scope();
tree leave_scope();
tree lookup(const std::string& name);
void make_if_branch(boot::conditional_statements& branch, tree goto_endif);
tree build_arithmetic_operation(boot::binary_expression *expression,