Skip to content

Commit

Permalink
add semantic check that file type is not of protected type
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchsm committed Oct 17, 2015
1 parent 5b33cd5 commit 0f028eb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
14 changes: 11 additions & 3 deletions src/sem.c
Expand Up @@ -1806,11 +1806,19 @@ static bool sem_check_type_decl(tree_t t)
return false;
type_set_file(base, f);

if (type_kind(f) == T_ACCESS)
switch (type_kind(f)) {
case T_ACCESS:
sem_error(t, "files may not be of access type");

if (type_kind(f) == T_FILE)
break;
case T_FILE:
sem_error(t, "files may not be of file type");
break;
case T_PROTECTED:
sem_error(t, "files may not be of protected type");
break;
default:
break;
}

sem_declare_predefined_ops(t);
return true;
Expand Down
8 changes: 8 additions & 0 deletions test/sem/file.vhd
Expand Up @@ -2,11 +2,16 @@ package p is

type ft is file of natural; -- OK

type t_prot is protected
end protected;

type int_ptr is access integer;
type bad1 is file of int_ptr; -- Error

type bad2 is file of ft; -- Error

type bad3 is file of t_prot; -- Error

file f1 : ft is "foo.txt" ; -- OK

file f2 : integer is "bar.txt"; -- Error
Expand Down Expand Up @@ -37,4 +42,7 @@ package body p is
assert endfile(f1); -- OK
end procedure;

type t_prot is protected body
end protected body;

end package body;
15 changes: 9 additions & 6 deletions test/test_sem.c
Expand Up @@ -672,15 +672,18 @@ END_TEST

START_TEST(test_file)
{
set_standard(STD_00);

input_from_file(TESTDIR "/sem/file.vhd");

const error_t expect[] = {
{ 6, "files may not be of access type" },
{ 8, "files may not be of file type" },
{ 12, "file declarations must have file type" },
{ 16, "open mode must have type FILE_OPEN_KIND" },
{ 20, "file name must have type STRING" },
{ 36, "no suitable overload for procedure READ" },
{ 9, "files may not be of access type" },
{ 11, "files may not be of file type" },
{ 13, "files may not be of protected type" },
{ 17, "file declarations must have file type" },
{ 21, "open mode must have type FILE_OPEN_KIND" },
{ 25, "file name must have type STRING" },
{ 41, "no suitable overload for procedure READ" },
{ -1, NULL }
};
expect_errors(expect);
Expand Down

0 comments on commit 0f028eb

Please sign in to comment.