# HG changeset patch # User Mario de Sousa # Date 1352898605 0 # Node ID db5881e6facda4f46f0a19dd27671c7f5f6aa412 # Parent 9b61eb4f00dc68ae77ba5fc2a92c1c394e3c1b7f Add method to determine the id (name) of a datatype. diff -r 9b61eb4f00dc -r db5881e6facd absyntax_utils/get_datatype_info.cc --- a/absyntax_utils/get_datatype_info.cc Tue Nov 13 18:03:17 2012 +0000 +++ b/absyntax_utils/get_datatype_info.cc Wed Nov 14 13:10:05 2012 +0000 @@ -50,13 +50,78 @@ #include // required for typeid - - - - - - - +/**********************************************************/ +/**********************************************************/ +/**********************************************************/ +/***** *****/ +/***** *****/ +/***** Some helper classes *****/ +/***** *****/ +/***** *****/ +/**********************************************************/ +/**********************************************************/ +/**********************************************************/ + +/* Return the identifier (name) of a datatype, typically declared in a TYPE .. END_TYPE declaration */ +class get_datatype_id_c: null_visitor_c { + private: + static get_datatype_id_c *singleton; + + public: + static symbol_c *get_id(symbol_c *symbol) { + if (NULL == singleton) singleton = new get_datatype_id_c(); + if (NULL == singleton) ERROR; + return (symbol_c *)symbol->accept(*singleton); + } + + protected: + /********************************/ + /* B 1.3.3 - Derived data types */ + /********************************/ + /* simple_type_name ':' simple_spec_init */ + void *visit(simple_type_declaration_c *symbol) {return symbol->simple_type_name;} + /* subrange_type_name ':' subrange_spec_init */ + void *visit(subrange_type_declaration_c *symbol) {return symbol->subrange_type_name;} + /* enumerated_type_name ':' enumerated_spec_init */ + void *visit(enumerated_type_declaration_c *symbol) {return symbol->enumerated_type_name;} + /* identifier ':' array_spec_init */ + void *visit(array_type_declaration_c *symbol) {return symbol->identifier;} + /* structure_type_name ':' structure_specification */ + void *visit(structure_type_declaration_c *symbol) {return symbol->structure_type_name;} + /* string_type_name ':' elementary_string_type_name string_type_declaration_size string_type_declaration_init */ + void *visit(string_type_declaration_c *symbol) {return symbol->string_type_name;} + + /*****************************/ + /* B 1.5.2 - Function Blocks */ + /*****************************/ + /* FUNCTION_BLOCK derived_function_block_name io_OR_other_var_declarations function_block_body END_FUNCTION_BLOCK */ + void *visit(function_block_declaration_c *symbol) {return symbol->fblock_name;} +}; // get_datatype_id_c + +get_datatype_id_c *get_datatype_id_c::singleton = NULL; + + + + + + +/**********************************************************/ +/**********************************************************/ +/**********************************************************/ +/***** *****/ +/***** *****/ +/***** GET_DATATYPE_INFO_C *****/ +/***** *****/ +/***** *****/ +/**********************************************************/ +/**********************************************************/ +/**********************************************************/ + + + +symbol_c *get_datatype_info_c::get_datatype_id(symbol_c *datatype) { + return get_datatype_id_c::get_id(datatype); +} bool get_datatype_info_c::is_type_equal(symbol_c *first_type, symbol_c *second_type) { diff -r 9b61eb4f00dc -r db5881e6facd absyntax_utils/get_datatype_info.hh --- a/absyntax_utils/get_datatype_info.hh Tue Nov 13 18:03:17 2012 +0000 +++ b/absyntax_utils/get_datatype_info.hh Wed Nov 14 13:10:05 2012 +0000 @@ -57,6 +57,8 @@ public: + static symbol_c *get_datatype_id(symbol_c *datatype); /* get the identifier (name) of the datatype); returns NULL if anonymous datatype! */ + static bool is_type_equal(symbol_c *first_type, symbol_c *second_type); static bool is_type_valid(symbol_c *type);