Skip to content

Commit

Permalink
add semantic check that ports are signal class
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchsm committed Oct 12, 2015
1 parent 7acc062 commit 976d86a
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/sem.c
Original file line number Diff line number Diff line change
Expand Up @@ -2681,8 +2681,15 @@ static bool sem_check_ports(tree_t t)
for (int n = 0; n < nports; n++) {
tree_t p = tree_port(t, n);

if (tree_class(p) == C_DEFAULT)
switch (tree_class(p)) {
case C_DEFAULT:
tree_set_class(p, C_SIGNAL);
break;
case C_SIGNAL:
break;
default:
sem_error(p, "invalid object class for port");
}

tree_add_attr_int(p, elab_copy_i, 1);

Expand Down
39 changes: 39 additions & 0 deletions test/sem/interfaces.vhd
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package interfaces is

component comp1 is
port (
signal p1 : integer; -- OK
p2 : integer -- OK
);
end component;

component comp2 is
port (variable p : integer); -- Error
end component;

component comp3 is
port (constant p : integer); -- Error
end component;

component comp4 is
port (file p : text); -- Error
end component;

component comp5 is
generic (constant p1 : integer; -- OK
p2 : integer);-- OK
end component;

component comp5 is
generic (signal p : integer); -- Error
end component;

component comp5 is
generic (variable p : integer); -- Error
end component;

component comp5 is
generic (file p : text); -- Error
end component;

end package interfaces;
22 changes: 22 additions & 0 deletions test/test_sem.c
Original file line number Diff line number Diff line change
Expand Up @@ -1445,6 +1445,27 @@ START_TEST(test_issue239)
}
END_TEST

START_TEST(test_interfaces)
{
input_from_file(TESTDIR "/sem/interfaces.vhd");

const error_t expect[] = {
{ 11, "invalid object class for port" },
{ 15, "invalid object class for port" },
{ 19, "invalid object class for port" },
{ 28, "invalid object class for generic" },
{ 32, "invalid object class for generic" },
{ 36, "invalid object class for generic" },
{ -1, NULL }
};
expect_errors(expect);

parse_and_check(T_PACKAGE);

fail_unless(sem_errors() == ARRAY_LEN(expect) - 1);
}
END_TEST

int main(void)
{
Suite *s = suite_create("sem");
Expand Down Expand Up @@ -1518,6 +1539,7 @@ int main(void)
tcase_add_test(tc_core, test_issue221);
tcase_add_test(tc_core, test_issue236);
tcase_add_test(tc_core, test_issue239);
tcase_add_test(tc_core, test_interfaces);
suite_add_tcase(s, tc_core);

return nvc_run_test(s);
Expand Down

0 comments on commit 976d86a

Please sign in to comment.