Skip to content

Commit

Permalink
Use clause tree_t should point at container rather than library
Browse files Browse the repository at this point in the history
  • Loading branch information
nickg committed Aug 11, 2023
1 parent 53c83e2 commit e0b8bff
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 127 deletions.
18 changes: 10 additions & 8 deletions src/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,14 @@ static void dump_component(tree_t t, int indent)
print_syntax("#end #component;\n");
}

static void dump_use(tree_t t)
{
print_syntax("#use %s", istr(tree_ident(t)));
if (tree_has_ident2(t))
print_syntax(".%s", istr(tree_ident2(t)));
print_syntax(";\n");
}

static void dump_decl(tree_t t, int indent)
{
tab(indent);
Expand Down Expand Up @@ -927,10 +935,7 @@ static void dump_decl(tree_t t, int indent)
return;

case T_USE:
print_syntax("#use %s", istr(tree_ident(t)));
if (tree_has_ident2(t))
print_syntax(".%s", istr(tree_ident2(t)));
print_syntax(";\n");
dump_use(t);
return;

case T_PACKAGE:
Expand Down Expand Up @@ -1443,10 +1448,7 @@ static void dump_context(tree_t t, int indent)
break;

case T_USE:
print_syntax("#use %s", istr(tree_ident(c)));
if (tree_has_ident2(c))
print_syntax(".%s", istr(tree_ident2(c)));
print_syntax(";\n");
dump_use(c);
break;

case T_CONTEXT_REF:
Expand Down
18 changes: 12 additions & 6 deletions src/names.c
Original file line number Diff line number Diff line change
Expand Up @@ -1933,12 +1933,18 @@ void insert_names_for_psl(nametab_t *tab)
tree_set_ident2(nvc, nvc_i);
insert_name(tab, nvc, nvc_i);

tree_t psl_support = tree_new(T_USE);
tree_set_ident(psl_support, well_known(W_NVC_PSL_SUPPORT));
tree_set_ident2(psl_support, well_known(W_ALL));
tree_set_ref(psl_support, nvc);

tab->psl = psl_support;
ident_t psl_support_i = well_known(W_NVC_PSL_SUPPORT);
lib_t lnvc = lib_require(nvc_i);
tree_t psl_support = lib_get(lnvc, psl_support_i);
if (psl_support == NULL)
fatal("cannot find %s package", istr(psl_support_i));

tree_t u = tree_new(T_USE);
tree_set_ident(u, psl_support_i);
tree_set_ident2(u, well_known(W_ALL));
tree_set_ref(u, psl_support);

tab->psl = u;
}

insert_names_from_use(tab, tab->psl);
Expand Down
18 changes: 15 additions & 3 deletions src/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -2514,9 +2514,13 @@ static void p_use_clause(tree_t unit, add_func_t addf)

switch (peek()) {
case tID:
tree_set_ident(u, ident_prefix(i1, p_identifier(), '.'));
i1 = ident_prefix(i1, p_identifier(), '.');
tree_set_ident(u, i1);

if (optional(tDOT)) {
if (head != NULL)
head = resolve_name(nametab, CURRENT_LOC, i1);

switch (peek()) {
case tID:
tree_set_ident2(u, p_identifier());
Expand Down Expand Up @@ -2556,6 +2560,8 @@ static void p_use_clause(tree_t unit, add_func_t addf)
if (kind == T_LIBRARY && !tree_has_ident2(head)) {
// Library declaration had an error
}
else if (is_uninstantiated_package(head))
parse_error(CURRENT_LOC, "cannot use an uninstantiated package");
else if (kind == T_LIBRARY || kind == T_PACKAGE
|| kind == T_PACK_INST
|| (kind == T_GENERIC_DECL
Expand Down Expand Up @@ -12525,10 +12531,16 @@ static tree_t p_design_unit(void)

// The std.standard package is implicit unless we are bootstrapping
if (!bootstrapping) {
lib_t lstd = lib_require(std_i);
ident_t standard_i = well_known(W_STD_STANDARD);
tree_t standard = lib_get(lstd, standard_i);
if (standard == NULL)
fatal("cannot find %s package", istr(standard_i));

tree_t u = tree_new(T_USE);
tree_set_ident(u, well_known(W_STD_STANDARD));
tree_set_ident(u, standard_i);
tree_set_ident2(u, well_known(W_ALL));
tree_set_ref(u, std);
tree_set_ref(u, standard);

tree_add_context(unit, u);
insert_names_from_use(nametab, u);
Expand Down
20 changes: 0 additions & 20 deletions src/simp.c
Original file line number Diff line number Diff line change
Expand Up @@ -869,24 +869,6 @@ static tree_t simp_context_ref(tree_t t, simp_ctx_t *ctx)
return NULL;
}

static tree_t simp_use(tree_t t)
{
tree_t lib_decl = tree_ref(t);
if (tree_kind(lib_decl) != T_LIBRARY)
return t;

ident_t qual = tree_ident(t);
ident_t lalias = ident_until(qual, '.');
ident_t lname = tree_ident2(lib_decl);

if (lalias != lname) {
ident_t rest = ident_from(qual, '.');
tree_set_ident(t, ident_prefix(lname, rest, '.'));
}

return t;
}

static tree_t simp_assert(tree_t t)
{
bool value_b;
Expand Down Expand Up @@ -1310,8 +1292,6 @@ static tree_t simp_tree(tree_t t, void *_ctx)
return simp_record_ref(t, ctx);
case T_CONTEXT_REF:
return simp_context_ref(t, ctx);
case T_USE:
return simp_use(t);
case T_ASSERT:
return simp_assert(t);
case T_IF_GENERATE:
Expand Down
32 changes: 0 additions & 32 deletions test/lower/rectype.vhd

This file was deleted.

11 changes: 0 additions & 11 deletions test/simp/use.vhd

This file was deleted.

24 changes: 2 additions & 22 deletions test/test_lower.c
Original file line number Diff line number Diff line change
Expand Up @@ -2180,27 +2180,6 @@ START_TEST(test_access_bug)
}
END_TEST

START_TEST(test_rectype)
{
input_from_file(TESTDIR "/lower/rectype.vhd");

run_elab();

vcode_unit_t v0 = find_unit("WORK.E.P1");
vcode_select_unit(v0);

fail_unless(vtype_kind(2) == VCODE_TYPE_RECORD);
fail_unless(vtype_kind(3) == VCODE_TYPE_RECORD);

// We used to mangle this with @<address>
ident_t r2_name = vtype_name(0);
fail_unless(strncmp(istr(r2_name), "WORK.E(A).R2", 3) == 0);

ident_t r1_name = vtype_name(3);
fail_unless(icmp(r1_name, "WORK.RECTYPE.R1$"));
}
END_TEST

START_TEST(test_issue149)
{
input_from_file(TESTDIR "/lower/issue149.vhd");
Expand Down Expand Up @@ -2539,6 +2518,7 @@ START_TEST(test_tag)

EXPECT_BB(0) = {
{ VCODE_OP_PACKAGE_INIT, .name = "STD.STANDARD" },
{ VCODE_OP_PACKAGE_INIT, .name = "WORK.P" },
{ VCODE_OP_CONST, .value = 1 },
{ VCODE_OP_DEBUG_LOCUS },
{ VCODE_OP_CONST, .value = 0 },
Expand Down Expand Up @@ -3740,6 +3720,7 @@ START_TEST(test_issue426)
vcode_select_unit(vu);

EXPECT_BB(0) = {
{ VCODE_OP_PACKAGE_INIT, .name = "STD.STANDARD" },
{ VCODE_OP_INDEX, .name = "EXP_STATUS" },
{ VCODE_OP_VAR_UPREF, .hops = 1, .name = "EXP_STATUS" },
{ VCODE_OP_COPY },
Expand Down Expand Up @@ -5307,7 +5288,6 @@ Suite *get_lower_tests(void)
tcase_add_test(tc, test_issue136);
tcase_add_test(tc, test_issue125);
tcase_add_test(tc, test_access_bug);
tcase_add_test(tc, test_rectype);
tcase_add_test(tc, test_issue149);
tcase_add_test(tc, test_issue158);
tcase_add_test(tc, test_issue167);
Expand Down
14 changes: 9 additions & 5 deletions test/test_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -3114,7 +3114,11 @@ START_TEST(test_context)
fail_unless(tree_kind(c1) == T_CONTEXT);
fail_unless(tree_ident(c1) == ident_new("WIDGET_LIB.WIDGET_CONTEXT"));
fail_unless(tree_contexts(c1) == 5);
fail_unless(tree_kind(tree_context(c1, 3)) == T_USE);
tree_t u3 = tree_context(c1, 3);
fail_unless(tree_kind(u3) == T_USE);
fail_unless(tree_ident(u3) == ident_new("WIDGET_LIB.WIDGET_DEFS"));
fail_unless(tree_ident2(u3) == well_known(W_ALL));
fail_unless(tree_ref(u3) == p1);
lib_put(lib_work(), c1);

lib_t project = lib_tmp("project");
Expand Down Expand Up @@ -4251,9 +4255,8 @@ START_TEST(test_error5)
input_from_file(TESTDIR "/parse/error5.vhd");

const error_t expect[] = {
{ 2, "unit WORK.NOTHERE not found in library WORK" },
{ 2, "design unit NOTHERE not found in library WORK" },
// It would be better to avoid the following errors
{ 2, "unit WORK.NOTHERE not found in library WORK" },
{ 8, "no visible declaration for MYTYPE" },
{ 8, "no visible declaration for MYFUNC" },
{ -1, NULL }
Expand Down Expand Up @@ -4353,7 +4356,8 @@ START_TEST(test_issue457)
lib_set_work(test_context_lib);

const error_t expect[] = {
{ 7, "design unit TEST_CONTEXT.TEST_CONTEXT is not a package" },
{ 7, "TEST_CONTEXT.TEST_CONTEXT is not a library or instantiated "
"package" },
{ -1, NULL }
};
expect_errors(expect);
Expand Down Expand Up @@ -4469,7 +4473,7 @@ START_TEST(test_error7)
const error_t expect[] = {
{ 4, "FOO already declared in this region" },
{ 7, "depends on WORK.ERROR7 which was analysed with errors" },
{ 11, "design unit WORK.ERROR7 was analysed with errors" },
{ 11, " depends on WORK.ERROR7 which was analysed with errors" },
{ -1, NULL }
};
expect_errors(expect);
Expand Down
2 changes: 1 addition & 1 deletion test/test_sem.c
Original file line number Diff line number Diff line change
Expand Up @@ -2740,7 +2740,7 @@ START_TEST(test_issue465)
input_from_file(TESTDIR "/sem/issue465.vhd");

const error_t expect[] = {
{ 1, "unit WORK.TESTTEST_PKG not found in library WORK" },
{ 1, "design unit TESTTEST_PKG not found in library WORK" },
{ 8, "design unit depends on WORK.TEST2_PKG which was analysed with" },
{ -1, NULL }
};
Expand Down
19 changes: 0 additions & 19 deletions test/test_simp.c
Original file line number Diff line number Diff line change
Expand Up @@ -923,24 +923,6 @@ START_TEST(test_static1)
}
END_TEST

START_TEST(test_use)
{
lib_t somelib = lib_tmp("somelib");
lib_set_work(somelib);

input_from_file(TESTDIR "/simp/use.vhd");

tree_t p = parse_check_and_simplify(T_PACKAGE, T_PACKAGE);
fail_if(p == NULL);

fail_unless(tree_contexts(p) == 4);

tree_t u = tree_context(p, 3);
fail_unless(tree_kind(u) == T_USE);
fail_unless(tree_ident(u) == ident_new("SOMELIB.PACK"));
}
END_TEST

START_TEST(test_predef)
{
input_from_file(TESTDIR "/simp/predef.vhd");
Expand Down Expand Up @@ -1570,7 +1552,6 @@ Suite *get_simp_tests(void)
tcase_add_test(tc_core, test_allsens);
tcase_add_test(tc_core, test_issue425);
tcase_add_test(tc_core, test_static1);
tcase_add_test(tc_core, test_use);
tcase_add_test(tc_core, test_predef);
tcase_add_test(tc_core, test_guard);
tcase_add_test(tc_core, test_copysub);
Expand Down

0 comments on commit e0b8bff

Please sign in to comment.