From 99515212120e7c7accd615d9550a06ec4416c41c Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 30 Sep 2014 11:24:43 +0200 Subject: [PATCH] vhdlpp: Subprogram parameters are taken into account when distinguishing between function calls and vector elements. --- vhdlpp/parse.y | 14 ++++++++++++-- vhdlpp/subprogram.cc | 14 ++++++++++++++ vhdlpp/subprogram.h | 2 ++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/vhdlpp/parse.y b/vhdlpp/parse.y index 0c2314b84..26bfb0c86 100644 --- a/vhdlpp/parse.y +++ b/vhdlpp/parse.y @@ -83,6 +83,7 @@ extern int yylex(union YYSTYPE*yylvalp,YYLTYPE*yyllocp,yyscan_t yyscanner); */ static ActiveScope*active_scope = new ActiveScope; static stack scope_stack; +static Subprogram*active_sub = NULL; /* * When a scope boundary starts, call the push_scope function to push @@ -106,6 +107,13 @@ static void pop_scope(void) scope_stack.pop(); } +static bool is_subprogram_param(perm_string name) +{ + if(!active_sub) + return false; + + return (active_sub->find_param(name) != NULL); +} void preload_global_types(void) { @@ -1543,7 +1551,7 @@ name /* IEEE 1076-2008 P8.1 */ | IDENTIFIER '(' expression_list ')' { perm_string name = lex_strings.make($1); delete[]$1; - if (active_scope->is_vector_name(name)) { + if (active_scope->is_vector_name(name) || is_subprogram_param(name)) { ExpName*tmp = new ExpName(name, $3); $$ = tmp; } else { @@ -2166,6 +2174,7 @@ signal_assignment_statement subprogram_body /* IEEE 1076-2008 P4.3 */ : subprogram_specification K_is + { active_sub = $1; } subprogram_declarative_part K_begin subprogram_statement_part K_end subprogram_kind_opt identifier_opt ';' @@ -2178,8 +2187,9 @@ subprogram_body /* IEEE 1076-2008 P4.3 */ errormsg(@1, "Subprogram specification for %s doesn't match specification in package header.\n", prog->name().str()); } prog->transfer_from(*active_scope); - prog->set_program_body($5); + prog->set_program_body($6); active_scope->bind_name(prog->name(), prog); + active_sub = NULL; } | subprogram_specification K_is diff --git a/vhdlpp/subprogram.cc b/vhdlpp/subprogram.cc index 8f071fd25..0e3f22ab6 100644 --- a/vhdlpp/subprogram.cc +++ b/vhdlpp/subprogram.cc @@ -80,6 +80,20 @@ bool Subprogram::compare_specification(Subprogram*that) const return true; } +InterfacePort*Subprogram::find_param(perm_string nam) +{ + if(!ports_) + return NULL; + + for (std::list::const_iterator it = ports_->begin() + ; it != ports_->end(); ++it) { + if((*it)->name == nam) + return *it; + } + + return NULL; +} + void Subprogram::fix_return_type(void) { if(!statements_) diff --git a/vhdlpp/subprogram.h b/vhdlpp/subprogram.h index 68d924d00..68f62f8c3 100644 --- a/vhdlpp/subprogram.h +++ b/vhdlpp/subprogram.h @@ -48,6 +48,8 @@ class Subprogram : public LineInfo, public ScopeBase { // matches this subprogram and that subprogram. bool compare_specification(Subprogram*that) const; + InterfacePort*find_param(perm_string nam); + int emit(ostream&out, Entity*ent, Architecture*arc); // Emit a definition as it would show up in a package.