48 |
48 |
49 |
49 |
50 #include <typeinfo> // required for typeid |
50 #include <typeinfo> // required for typeid |
51 |
51 |
52 |
52 |
53 |
53 /**********************************************************/ |
54 |
54 /**********************************************************/ |
55 |
55 /**********************************************************/ |
56 |
56 /***** *****/ |
57 |
57 /***** *****/ |
58 |
58 /***** Some helper classes *****/ |
59 |
59 /***** *****/ |
|
60 /***** *****/ |
|
61 /**********************************************************/ |
|
62 /**********************************************************/ |
|
63 /**********************************************************/ |
|
64 |
|
65 /* Return the identifier (name) of a datatype, typically declared in a TYPE .. END_TYPE declaration */ |
|
66 class get_datatype_id_c: null_visitor_c { |
|
67 private: |
|
68 static get_datatype_id_c *singleton; |
|
69 |
|
70 public: |
|
71 static symbol_c *get_id(symbol_c *symbol) { |
|
72 if (NULL == singleton) singleton = new get_datatype_id_c(); |
|
73 if (NULL == singleton) ERROR; |
|
74 return (symbol_c *)symbol->accept(*singleton); |
|
75 } |
|
76 |
|
77 protected: |
|
78 /********************************/ |
|
79 /* B 1.3.3 - Derived data types */ |
|
80 /********************************/ |
|
81 /* simple_type_name ':' simple_spec_init */ |
|
82 void *visit(simple_type_declaration_c *symbol) {return symbol->simple_type_name;} |
|
83 /* subrange_type_name ':' subrange_spec_init */ |
|
84 void *visit(subrange_type_declaration_c *symbol) {return symbol->subrange_type_name;} |
|
85 /* enumerated_type_name ':' enumerated_spec_init */ |
|
86 void *visit(enumerated_type_declaration_c *symbol) {return symbol->enumerated_type_name;} |
|
87 /* identifier ':' array_spec_init */ |
|
88 void *visit(array_type_declaration_c *symbol) {return symbol->identifier;} |
|
89 /* structure_type_name ':' structure_specification */ |
|
90 void *visit(structure_type_declaration_c *symbol) {return symbol->structure_type_name;} |
|
91 /* string_type_name ':' elementary_string_type_name string_type_declaration_size string_type_declaration_init */ |
|
92 void *visit(string_type_declaration_c *symbol) {return symbol->string_type_name;} |
|
93 |
|
94 /*****************************/ |
|
95 /* B 1.5.2 - Function Blocks */ |
|
96 /*****************************/ |
|
97 /* FUNCTION_BLOCK derived_function_block_name io_OR_other_var_declarations function_block_body END_FUNCTION_BLOCK */ |
|
98 void *visit(function_block_declaration_c *symbol) {return symbol->fblock_name;} |
|
99 }; // get_datatype_id_c |
|
100 |
|
101 get_datatype_id_c *get_datatype_id_c::singleton = NULL; |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 /**********************************************************/ |
|
109 /**********************************************************/ |
|
110 /**********************************************************/ |
|
111 /***** *****/ |
|
112 /***** *****/ |
|
113 /***** GET_DATATYPE_INFO_C *****/ |
|
114 /***** *****/ |
|
115 /***** *****/ |
|
116 /**********************************************************/ |
|
117 /**********************************************************/ |
|
118 /**********************************************************/ |
|
119 |
|
120 |
|
121 |
|
122 symbol_c *get_datatype_info_c::get_datatype_id(symbol_c *datatype) { |
|
123 return get_datatype_id_c::get_id(datatype); |
|
124 } |
60 |
125 |
61 |
126 |
62 bool get_datatype_info_c::is_type_equal(symbol_c *first_type, symbol_c *second_type) { |
127 bool get_datatype_info_c::is_type_equal(symbol_c *first_type, symbol_c *second_type) { |
63 if ((NULL == first_type) || (NULL == second_type)) {return false;} |
128 if ((NULL == first_type) || (NULL == second_type)) {return false;} |
64 if (typeid(* first_type) == typeid(invalid_type_name_c)) {return false;} |
129 if (typeid(* first_type) == typeid(invalid_type_name_c)) {return false;} |