Skip to content

Commit

Permalink
[cpp] semal - add struct definitions (even though its NYI
Browse files Browse the repository at this point in the history
  • Loading branch information
harrand committed May 13, 2024
1 parent 97e8c21 commit b52908c
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion cpp/src/semal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ namespace semal
{
structdata.ctx.semal_error("redeclaration of struct \"{}\". previously defined in same file at: {}", structdata.ty.name, this->struct_decls.at(structdata.ty.name).ctx.location().to_string());
}
this->struct_decls[structdata.ty.name] = structdata;
}

output analyse_predecl(const ast& tree)
Expand Down Expand Up @@ -296,7 +297,25 @@ namespace semal
{
output ret = predecl;
// todo: analyse all code (mainly implementations).

for(std::size_t i = 0; i < tree.root.children.size(); i++)
{
const ast::node& node = tree.root.children[i];
const ast::path_t path{i};
if(std::holds_alternative<ast::function_definition>(node.payload))
{
auto func = std::get<ast::function_definition>(node.payload);
diag::assert_that(predecl.functions.contains(func.func_name), error_code::ice, "function \"{}\" was not found in the predecl semal output, when this should always be the case.", func.func_name);

function_t fn = predecl.functions[func.func_name];
if(!func.is_extern)
{
fn.ctx.semal_assert(node.children.size() == 1, "non-extern functions must have an implementation.");
fn.ctx.semal_assert(std::holds_alternative<ast::block>(node.children.front().payload), "function implementation should consist of a block of code surrounded by braces");

// todo:semantically analyse the block...
}
}
}
return ret;
}
}

0 comments on commit b52908c

Please sign in to comment.