Skip to content
Snippets Groups Projects
Commit 5d3e5b3d authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Prepare complex type handling

Grammar allows constructions such as
``
let f : R*R -> R*R, x -> x;
``
This expression does not actually compiles since expression types are not
correctly defined, thus semantic analysis fails
parent 56028cb9
No related branches found
No related tags found
1 merge request!37Feature/language
......@@ -62,7 +62,7 @@ struct ASTBuilder::simplify_unary : parse_tree::apply<ASTBuilder::simplify_unary
transform(std::unique_ptr<ASTNode>& n, States&&... st)
{
if (n->children.size() == 1) {
if (n->is<unary_expression>()) {
if (n->is<unary_expression>() or n->is<type_expression>()) {
n->remove_content();
n = std::move(n->children.back());
transform(n, st...);
......@@ -201,8 +201,8 @@ struct ASTBuilder::simplify_stream_statement : parse_tree::apply<ASTBuilder::sim
};
template <typename Rule>
using selector = parse_tree::selector<
Rule,
using selector =
parse_tree::selector<Rule,
parse_tree::store_content::on<true_kw,
false_kw,
integer,
......@@ -219,7 +219,7 @@ using selector = parse_tree::selector<
clog_kw,
declaration,
let_declaration,
function_domain_mapping,
type_mapping,
function_definition,
if_statement,
do_while_statement,
......@@ -228,7 +228,8 @@ using selector = parse_tree::selector<
break_kw,
continue_kw>,
ASTBuilder::rearrange::on<product, affectation, expression>,
ASTBuilder::simplify_unary::on<unary_minus, unary_plus, unary_not, function_evaluation, unary_expression>,
ASTBuilder::simplify_unary::
on<unary_minus, unary_plus, unary_not, function_evaluation, type_expression, unary_expression>,
parse_tree::remove_content::on<plus_op,
minus_op,
multiply_op,
......
......@@ -108,7 +108,7 @@ ASTNodeDataTypeBuilder::_buildNodeDataTypes(ASTNode& n)
} else if (n.is<language::eq_op>() or n.is<language::multiplyeq_op>() or n.is<language::divideeq_op>() or
n.is<language::pluseq_op>() or n.is<language::minuseq_op>()) {
n.m_data_type = n.children[0]->m_data_type;
} else if (n.is<language::function_domain_mapping>() or n.is<language::function_definition>()) {
} else if (n.is<language::type_mapping>() or n.is<language::function_definition>()) {
n.m_data_type = ASTNodeDataType::void_t;
} else if (n.is<language::for_post>() or n.is<language::for_init>() or n.is<language::for_statement_block>()) {
n.m_data_type = ASTNodeDataType::void_t;
......
......@@ -203,10 +203,12 @@ struct affectation : seq< NAME , if_must< affect_op, expression > >{};
struct declaration : if_must< TYPESPECIFIER, NAME, opt< if_must< seq< one< '=' >, ignored >, expression > > >{};
struct function_domain_mapping : seq< TYPESPECIFIER, RIGHT_ARROW, TYPESPECIFIER >{};
struct type_expression : list_must< TYPESPECIFIER, one< '*' > >{};
struct type_mapping : seq< type_expression, RIGHT_ARROW, type_expression >{};
struct function_definition : seq< NAME, RIGHT_ARROW, expression >{};
struct let_declaration : if_must< LET, NAME, COLUMN, function_domain_mapping, COMMA, function_definition >{};
struct let_declaration : if_must< LET, NAME, COLUMN, type_mapping, COMMA, function_definition >{};
struct open_brace : seq< one< '{' >, ignored >{};
struct close_brace : seq< one< '}' >, ignored >{};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment