diff --git a/vhdlpp/parse.y b/vhdlpp/parse.y index 49af5b57c..ad6b57c44 100644 --- a/vhdlpp/parse.y +++ b/vhdlpp/parse.y @@ -254,11 +254,12 @@ const VType*parse_type_by_name(perm_string name) %type association_element %type association_list port_map_aspect port_map_aspect_opt -%type subtype_indication +%type subtype_indication type_definition %type architecture_body_start package_declaration_start %type identifier_opt identifier_colon_opt logical_name suffix %type logical_name_list identifier_list +%type enumeration_literal_list enumeration_literal %type prefix selected_name %type selected_names use_clause @@ -404,6 +405,8 @@ block_declarative_item | constant_declaration + | type_declaration + | use_clause_lib /* Various error handling rules for block_declarative_item... */ @@ -780,6 +783,31 @@ entity_header { $$ = $1; } ; +enumeration_literal + : IDENTIFIER + { list*tmp = new list; + tmp->push_back(lex_strings.make($1)); + delete[]$1; + $$ = tmp; + } + ; + +enumeration_literal_list + : enumeration_literal_list ',' enumeration_literal + { list*tmp = $1; + list*tmp3 = $3; + if (tmp3) { + tmp->splice(tmp->end(), *tmp3); + delete tmp3; + } + $$ = tmp; + } + | enumeration_literal + { list*tmp = $1; + $$ = tmp; + } + ; + expression_list : expression_list ',' expression { list*tmp = $1; @@ -1762,6 +1790,19 @@ term } ; +type_declaration + : K_type IDENTIFIER K_is type_definition ';' + { sorrymsg(@1, "type_declaration not supported.\n"); } + ; + +type_definition + : '(' enumeration_literal_list ')' + { VTypeEnum*tmp = new VTypeEnum($2); + delete $2; + $$ = tmp; + } + ; + use_clause : K_use selected_names ';' { diff --git a/vhdlpp/vtype.cc b/vhdlpp/vtype.cc index 1065e2592..4be70e401 100644 --- a/vhdlpp/vtype.cc +++ b/vhdlpp/vtype.cc @@ -105,3 +105,18 @@ VTypeRange::VTypeRange(const VType*base, int64_t max_val, int64_t min_val) VTypeRange::~VTypeRange() { } + +VTypeEnum::VTypeEnum(const std::list*names) +: names_(names->size()) +{ + size_t idx = 0; + + for (list::const_iterator cur = names->begin() + ; cur != names->end() ; ++cur, ++idx) { + names_[idx] = *cur; + } +} + +VTypeEnum::~VTypeEnum() +{ +} diff --git a/vhdlpp/vtype.h b/vhdlpp/vtype.h index fbe89a7a0..812f4bc22 100644 --- a/vhdlpp/vtype.h +++ b/vhdlpp/vtype.h @@ -20,6 +20,7 @@ */ # include +# include # include # include # include @@ -41,6 +42,9 @@ class VType { // writing parsed types to library files. virtual void write_to_stream(std::ostream&fd) const; + // This virtual method writes a human-readable version of the + // type to a given file for debug purposes. (Question: is this + // really necessary given the write_to_stream method?) virtual void show(std::ostream&) const; public: @@ -154,4 +158,16 @@ class VTypeRange : public VType { int64_t max_, min_; }; +class VTypeEnum : public VType { + + public: + VTypeEnum(const std::list*names); + ~VTypeEnum(); + + virtual void elaborate(decl_t&decl) const; + + private: + std::vectornames_; +}; + #endif diff --git a/vhdlpp/vtype_elaborate.cc b/vhdlpp/vtype_elaborate.cc index b608e8e1a..99d8d461f 100644 --- a/vhdlpp/vtype_elaborate.cc +++ b/vhdlpp/vtype_elaborate.cc @@ -63,3 +63,7 @@ void VTypeRange::elaborate(VType::decl_t&decl) const { base_->elaborate(decl); } + +void VTypeEnum::elaborate(decl_t&) const +{ +}