Fix handling of wildcard-imported types.

Don't add them to the explicit imports until they are referenced legally.
Stop searching when a matching name is found, even if it isn't a type name.
This commit is contained in:
Martin Whitaker 2019-09-29 19:16:35 +01:00
parent b0142a6406
commit 12fe4f2bf3
3 changed files with 29 additions and 14 deletions

18
parse.y
View File

@ -819,12 +819,14 @@ class_declaration_endlabel_opt
class_declaration_extends_opt /* IEEE1800-2005: A.1.2 */
: K_extends TYPE_IDENTIFIER
{ $$.type = $2.type;
{ pform_set_type_referenced(@2, $2.text);
$$.type = $2.type;
$$.exprs= 0;
delete[]$2.text;
}
| K_extends TYPE_IDENTIFIER '(' expression_list_with_nuls ')'
{ $$.type = $2.type;
{ pform_set_type_referenced(@2, $2.text);
$$.type = $2.type;
$$.exprs = $4;
delete[]$2.text;
}
@ -1106,7 +1108,8 @@ data_type /* IEEE1800-2005: A.2.2.1 */
$$ = tmp;
}
| TYPE_IDENTIFIER dimensions_opt
{ if ($2) {
{ pform_set_type_referenced(@1, $1.text);
if ($2) {
parray_type_t*tmp = new parray_type_t($1.type, $2);
FILE_NAME(tmp, @1);
$$ = tmp;
@ -1990,7 +1993,8 @@ simple_type_or_string /* IEEE1800-2005: A.2.2.1 */
$$ = tmp;
}
| TYPE_IDENTIFIER
{ $$ = $1.type;
{ pform_set_type_referenced(@1, $1.text);
$$ = $1.type;
delete[]$1.text;
}
| PACKAGE_IDENTIFIER K_SCOPE_RES
@ -3561,7 +3565,8 @@ expr_primary_or_typename
/* There are a few special cases (notably $bits argument) where the
expression may be a type name. Let the elaborator sort this out. */
| TYPE_IDENTIFIER
{ PETypename*tmp = new PETypename($1.type);
{ pform_set_type_referenced(@1, $1.text);
PETypename*tmp = new PETypename($1.type);
FILE_NAME(tmp,@1);
$$ = tmp;
delete[]$1.text;
@ -5320,7 +5325,8 @@ param_type
param_active_type = IVL_VT_BOOL;
}
| TYPE_IDENTIFIER
{ pform_set_param_from_type(@1, $1.type, $1.text, param_active_range,
{ pform_set_type_referenced(@1, $1.text);
pform_set_param_from_type(@1, $1.type, $1.text, param_active_range,
param_active_signed, param_active_type);
delete[]$1.text;
}

View File

@ -464,7 +464,7 @@ static void add_local_symbol(LexicalScope*scope, perm_string name, PNamedItem*it
}
static PPackage*find_potential_import(const struct vlltype&loc, LexicalScope*scope,
perm_string name, PNamedItem::SymbolType st)
perm_string name, bool make_explicit)
{
assert(scope);
@ -475,10 +475,7 @@ static PPackage*find_potential_import(const struct vlltype&loc, LexicalScope*sco
map<perm_string,PNamedItem*>::const_iterator cur_sym
= search_pkg->local_symbols.find(name);
if (cur_sym != search_pkg->local_symbols.end()) {
if (st != PNamedItem::ANY && st != cur_sym->second->symbol_type())
continue;
if (found_pkg) {
if (found_pkg && make_explicit) {
cerr << loc.get_fileline() << ": error: "
"Ambiguous use of '" << name << "'. "
"It is exported by both '"
@ -489,7 +486,8 @@ static PPackage*find_potential_import(const struct vlltype&loc, LexicalScope*sco
error_count += 1;
} else {
found_pkg = search_pkg;
scope->explicit_imports[name] = found_pkg;
if (make_explicit)
scope->explicit_imports[name] = found_pkg;
}
}
}
@ -504,7 +502,7 @@ static void check_potential_imports(const struct vlltype&loc, perm_string name)
return;
if (scope->explicit_imports.find(name) != scope->explicit_imports.end())
return;
if (find_potential_import(loc, scope, name, PNamedItem::ANY))
if (find_potential_import(loc, scope, name, true))
return;
scope = scope->parent_scope();
@ -858,6 +856,12 @@ void pform_set_typedef(perm_string name, data_type_t*data_type, std::list<pform_
pform_put_enum_type_in_scope(enum_type);
}
void pform_set_type_referenced(const struct vlltype&loc, const char*name)
{
perm_string lex_name = lex_strings.make(name);
check_potential_imports(loc, lex_name);
}
data_type_t* pform_test_type_identifier(const struct vlltype&loc, const char*txt)
{
perm_string name = lex_strings.make(txt);
@ -888,11 +892,14 @@ data_type_t* pform_test_type_identifier(const struct vlltype&loc, const char*txt
if (cur != cur_scope->typedefs.end())
return cur->second;
PPackage*pkg = find_potential_import(loc, cur_scope, name, PNamedItem::TYPE);
PPackage*pkg = find_potential_import(loc, cur_scope, name, false);
if (pkg) {
cur = pkg->typedefs.find(name);
if (cur != cur_scope->typedefs.end())
return cur->second;
// Not a type. Give up.
return 0;
}
cur_scope = cur_scope->parent_scope();

View File

@ -314,6 +314,8 @@ extern PGenerate* pform_parent_generate(void);
extern void pform_set_typedef(perm_string name, data_type_t*data_type,
std::list<pform_range_t>*unp_ranges);
extern void pform_set_type_referenced(const struct vlltype&loc, const char*name);
/*
* This function makes a PECallFunction of the named function.
*/