diff --git a/src/dump.c b/src/dump.c index 34eaf3773..e9d830f7a 100644 --- a/src/dump.c +++ b/src/dump.c @@ -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); @@ -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: @@ -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: diff --git a/src/names.c b/src/names.c index 796c1dade..2dd39d38b 100644 --- a/src/names.c +++ b/src/names.c @@ -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); diff --git a/src/parse.c b/src/parse.c index c62ffb7b3..9c3491558 100644 --- a/src/parse.c +++ b/src/parse.c @@ -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()); @@ -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 @@ -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); diff --git a/src/simp.c b/src/simp.c index eb5459e2d..706e356fe 100644 --- a/src/simp.c +++ b/src/simp.c @@ -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; @@ -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: diff --git a/test/lower/rectype.vhd b/test/lower/rectype.vhd deleted file mode 100644 index 8e15b2206..000000000 --- a/test/lower/rectype.vhd +++ /dev/null @@ -1,32 +0,0 @@ -package rectype is - - type r1 is record - x : integer; - end record; - -end package; - -entity e is -end entity; - -use work.rectype.all; - -architecture a of e is - type r2 is record - x : r1; - end record; - - signal s : r2; -begin - - p1: process is - type r3 is record - x : r2; - end record; - variable v : r3; - begin - v.x := s; - wait; - end process; - -end architecture; diff --git a/test/simp/use.vhd b/test/simp/use.vhd deleted file mode 100644 index 99844d664..000000000 --- a/test/simp/use.vhd +++ /dev/null @@ -1,11 +0,0 @@ --- Library somelib - -package pack is - constant N : natural := 42; -end package; - -use work.pack.all; -- Should get rewritten to somelib.pack - -package pack2 is - constant X : natural := N; -end package; diff --git a/test/test_lower.c b/test/test_lower.c index 5b3b256a7..3c5c45d4f 100644 --- a/test/test_lower.c +++ b/test/test_lower.c @@ -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 @
- 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"); @@ -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 }, @@ -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 }, @@ -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); diff --git a/test/test_parse.c b/test/test_parse.c index b0ea9aa08..c7abbb064 100644 --- a/test/test_parse.c +++ b/test/test_parse.c @@ -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"); @@ -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 } @@ -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); @@ -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); diff --git a/test/test_sem.c b/test/test_sem.c index 961c4abc7..b7650dd35 100644 --- a/test/test_sem.c +++ b/test/test_sem.c @@ -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 } }; diff --git a/test/test_simp.c b/test/test_simp.c index 8fb623586..a9101cedc 100644 --- a/test/test_simp.c +++ b/test/test_simp.c @@ -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"); @@ -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);