Rename AST types to type expressions
This commit is contained in:
@ -46,6 +46,8 @@ elna_OBJS = \
|
||||
elna/driver.o \
|
||||
elna/lexer.o \
|
||||
elna/parser.o \
|
||||
elna/semantic.o \
|
||||
elna/symbol.o \
|
||||
elna/result.o \
|
||||
$(END)
|
||||
|
||||
@ -134,7 +136,7 @@ elna.stagefeedback: stagefeedback-start
|
||||
-mv elna/*$(objext) stagefeedback/elna
|
||||
|
||||
ELNA_INCLUDES = -I $(srcdir)/elna/include -I elna/generated
|
||||
ELNA_CXXFLAGS = -std=c++11
|
||||
ELNA_CXXFLAGS = -std=c++14
|
||||
|
||||
elna/%.o: elna/boot/%.cc elna/generated/parser.hh elna/generated/location.hh
|
||||
$(COMPILE) $(ELNA_CXXFLAGS) $(ELNA_INCLUDES) $<
|
||||
|
@ -180,6 +180,23 @@ namespace gcc
|
||||
constant->accept(this);
|
||||
}
|
||||
for (boot::type_definition *const type : program->types)
|
||||
{
|
||||
tree type_node = NULL_TREE;
|
||||
|
||||
if (type->body().is_record())
|
||||
{
|
||||
type_node = make_node(RECORD_TYPE);
|
||||
}
|
||||
else if (type->body().is_union())
|
||||
{
|
||||
type_node = make_node(UNION_TYPE);
|
||||
}
|
||||
if (type_node != NULL_TREE)
|
||||
{
|
||||
this->symbol_map->enter(type->identifier, type_node);
|
||||
}
|
||||
}
|
||||
for (boot::type_definition *const type : program->types)
|
||||
{
|
||||
type->accept(this);
|
||||
}
|
||||
@ -731,33 +748,34 @@ namespace gcc
|
||||
void generic_visitor::visit(boot::type_definition *definition)
|
||||
{
|
||||
location_t definition_location = get_location(&definition->position());
|
||||
this->current_expression = this->symbol_map->lookup(definition->identifier);
|
||||
definition->body().accept(this);
|
||||
|
||||
tree definition_tree = build_decl(definition_location, TYPE_DECL,
|
||||
get_identifier(definition->identifier.c_str()), this->current_expression);
|
||||
auto result = this->symbol_map->enter(definition->identifier, this->current_expression);
|
||||
|
||||
if (result)
|
||||
{
|
||||
/* if (result)
|
||||
{ */
|
||||
TREE_PUBLIC(definition_tree) = definition->exported;
|
||||
TYPE_NAME(this->current_expression) = get_identifier(definition->identifier.c_str());
|
||||
}
|
||||
else
|
||||
// }
|
||||
/* else
|
||||
{
|
||||
error_at(get_location(&definition->position()),
|
||||
"type '%s' already declared in this scope",
|
||||
definition->identifier.c_str());
|
||||
}
|
||||
} */
|
||||
this->current_expression = NULL_TREE;
|
||||
}
|
||||
|
||||
tree generic_visitor::build_procedure_type(boot::procedure_type& type)
|
||||
tree generic_visitor::build_procedure_type(boot::procedure_type_expression& type)
|
||||
{
|
||||
std::vector<tree> parameter_types(type.parameters.size());
|
||||
|
||||
for (std::size_t i = 0; i < type.parameters.size(); ++i)
|
||||
{
|
||||
boot::top_type& parameter_type = type.parameters.at(i)->variable_type();
|
||||
boot::type_expression& parameter_type = type.parameters.at(i)->variable_type();
|
||||
parameter_type.accept(this);
|
||||
parameter_types[i] = this->current_expression;
|
||||
}
|
||||
@ -1102,14 +1120,14 @@ namespace gcc
|
||||
this->current_expression = NULL_TREE;
|
||||
}
|
||||
|
||||
void generic_visitor::visit(boot::basic_type *type)
|
||||
void generic_visitor::visit(boot::primitive_type_expression *type)
|
||||
{
|
||||
tree symbol = this->lookup(type->base_name());
|
||||
tree symbol = this->lookup(type->name);
|
||||
|
||||
if (symbol == NULL_TREE && TYPE_P(symbol))
|
||||
{
|
||||
error_at(get_location(&type->position()),
|
||||
"type '%s' not declared", type->base_name().c_str());
|
||||
"type '%s' not declared", type->name.c_str());
|
||||
|
||||
this->current_expression = error_mark_node;
|
||||
}
|
||||
@ -1119,7 +1137,7 @@ namespace gcc
|
||||
}
|
||||
}
|
||||
|
||||
void generic_visitor::visit(boot::array_type *type)
|
||||
void generic_visitor::visit(boot::array_type_expression *type)
|
||||
{
|
||||
tree lower_bound = build_int_cst_type(integer_type_node, 0);
|
||||
tree upper_bound = build_int_cst_type(integer_type_node, type->size);
|
||||
@ -1133,7 +1151,7 @@ namespace gcc
|
||||
}
|
||||
}
|
||||
|
||||
void generic_visitor::visit(boot::pointer_type *type)
|
||||
void generic_visitor::visit(boot::pointer_type_expression *type)
|
||||
{
|
||||
type->base().accept(this);
|
||||
|
||||
@ -1143,10 +1161,12 @@ namespace gcc
|
||||
}
|
||||
}
|
||||
|
||||
void generic_visitor::visit(boot::record_type *type)
|
||||
void generic_visitor::visit(boot::record_type_expression *type)
|
||||
{
|
||||
std::set<std::string> field_names;
|
||||
tree record_type_node = make_node(RECORD_TYPE);
|
||||
tree record_type_node = this->current_expression == NULL_TREE
|
||||
? make_node(RECORD_TYPE)
|
||||
: this->current_expression;
|
||||
|
||||
for (auto& field : type->fields)
|
||||
{
|
||||
@ -1166,16 +1186,19 @@ namespace gcc
|
||||
tree field_declaration = build_field(get_location(&field.second->position()),
|
||||
record_type_node, field.first, this->current_expression);
|
||||
TYPE_FIELDS(record_type_node) = chainon(TYPE_FIELDS(record_type_node), field_declaration);
|
||||
this->current_expression = NULL_TREE;
|
||||
}
|
||||
layout_type(record_type_node);
|
||||
|
||||
this->current_expression = record_type_node;
|
||||
}
|
||||
|
||||
void generic_visitor::visit(boot::union_type *type)
|
||||
void generic_visitor::visit(boot::union_type_expression *type)
|
||||
{
|
||||
std::set<std::string> field_names;
|
||||
tree union_type_node = make_node(UNION_TYPE);
|
||||
tree union_type_node = this->current_expression == NULL_TREE
|
||||
? make_node(UNION_TYPE)
|
||||
: this->current_expression;
|
||||
|
||||
for (auto& field : type->fields)
|
||||
{
|
||||
@ -1195,13 +1218,14 @@ namespace gcc
|
||||
tree field_declaration = build_field(get_location(&field.second->position()),
|
||||
union_type_node, field.first, this->current_expression);
|
||||
TYPE_FIELDS(union_type_node) = chainon(TYPE_FIELDS(union_type_node), field_declaration);
|
||||
this->current_expression = NULL_TREE;
|
||||
}
|
||||
layout_type(union_type_node);
|
||||
|
||||
this->current_expression = union_type_node;
|
||||
}
|
||||
|
||||
void generic_visitor::visit(boot::procedure_type *type)
|
||||
void generic_visitor::visit(boot::procedure_type_expression *type)
|
||||
{
|
||||
tree procedure_type_node = build_procedure_type(*type);
|
||||
this->current_expression = build_pointer_type_for_mode(procedure_type_node, VOIDmode, true);
|
||||
|
@ -30,6 +30,7 @@ along with GCC; see the file COPYING3. If not see
|
||||
|
||||
#include <fstream>
|
||||
#include "elna/boot/driver.h"
|
||||
#include "elna/boot/semantic.h"
|
||||
#include "elna/gcc/elna-tree.h"
|
||||
#include "elna/gcc/elna-generic.h"
|
||||
#include "elna/gcc/elna-diagnostic.h"
|
||||
@ -88,8 +89,10 @@ static void elna_parse_file(const char *filename)
|
||||
}
|
||||
else
|
||||
{
|
||||
elna::boot::declaration_visitor declaration_visitor{ std::make_shared<elna::boot::symbol_table>() };
|
||||
elna::gcc::generic_visitor generic_visitor{ std::make_shared<elna::gcc::symbol_table>() };
|
||||
|
||||
declaration_visitor.visit(driver.tree.get());
|
||||
generic_visitor.visit(driver.tree.get());
|
||||
}
|
||||
linemap_add(line_table, LC_LEAVE, 0, NULL, 0);
|
||||
|
Reference in New Issue
Block a user