From 764b38bb3b953588a020a516a1b52b3a25ed9b35 Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Sun, 15 Jan 2012 17:29:18 -0800 Subject: [PATCH] Use user defined types in the syntax. Given that the syntax is already parsed and elaborated, it is a simple matter to bind that typedef'ed type to the instances that use it. --- lexor.lex | 6 +++++- parse.y | 7 +++---- parse_misc.h | 2 +- pform.cc | 6 +++--- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lexor.lex b/lexor.lex index a6a683607..259a8fcd1 100644 --- a/lexor.lex +++ b/lexor.lex @@ -303,6 +303,7 @@ TU [munpf] perm_string tmp = lex_strings.make(yylval.text); map::iterator cur = disciplines.find(tmp); if (cur != disciplines.end()) { + delete[]yylval.text; yylval.discipline = (*cur).second; rc = DISCIPLINE_IDENTIFIER; } @@ -311,8 +312,11 @@ TU [munpf] /* If this identifer names a previously declared type, then return this as a TYPE_IDENTIFIER instead. */ if (rc == IDENTIFIER && gn_system_verilog()) { - if (pform_test_type_identifier(yylval.text)) + if (data_type_t*type = pform_test_type_identifier(yylval.text)) { + delete[]yylval.text; + yylval.data_type = type; rc = TYPE_IDENTIFIER; + } } return rc; diff --git a/parse.y b/parse.y index 08d9ba3cd..dbb46dd31 100644 --- a/parse.y +++ b/parse.y @@ -347,7 +347,8 @@ static void current_task_set_statement(vector*s) list *dimensions; }; -%token IDENTIFIER SYSTEM_IDENTIFIER TYPE_IDENTIFIER STRING TIME_LITERAL +%token IDENTIFIER SYSTEM_IDENTIFIER STRING TIME_LITERAL +%token TYPE_IDENTIFIER %token DISCIPLINE_IDENTIFIER %token PATHPULSE_IDENTIFIER %token BASED_NUMBER DEC_NUMBER @@ -786,9 +787,7 @@ data_type | enum_data_type { $$ = $1; } | TYPE_IDENTIFIER - { yyerror(@1, "sorry: Named types not supported here"); - $$ = 0; - } + { $$ = $1; } ; type_declaration diff --git a/parse_misc.h b/parse_misc.h index 0217a0cda..e9d642dfc 100644 --- a/parse_misc.h +++ b/parse_misc.h @@ -83,7 +83,7 @@ extern bool have_timeprec_decl; * parser detects typedefs and marks the typedef'ed identifiers as * type names. */ -extern bool pform_test_type_identifier(const char*txt); +extern data_type_t* pform_test_type_identifier(const char*txt); /* * Export these functions because we have to generate PENumber class diff --git a/pform.cc b/pform.cc index 97e7c8303..8ff97b60a 100644 --- a/pform.cc +++ b/pform.cc @@ -408,7 +408,7 @@ void pform_set_typedef(perm_string name, data_type_t*data_type) ref = data_type; } -bool pform_test_type_identifier(const char*txt) +data_type_t* pform_test_type_identifier(const char*txt) { // If there is no lexical_scope yet, then there is NO WAY the // identifier can be a type_identifier. @@ -418,9 +418,9 @@ bool pform_test_type_identifier(const char*txt) perm_string name = lex_strings.make(txt); map::iterator cur = lexical_scope->typedefs.find(name); if (cur != lexical_scope->typedefs.end()) - return true; + return cur->second; else - return false; + return 0; } static void pform_put_behavior_in_scope(PProcess*pp)