47 */ |
47 */ |
48 #include "absyntax_utils.hh" |
48 #include "absyntax_utils.hh" |
49 #include "../main.hh" // required for ERROR() and ERROR_MSG() macros. |
49 #include "../main.hh" // required for ERROR() and ERROR_MSG() macros. |
50 |
50 |
51 |
51 |
|
52 /* pointer to singleton instance */ |
|
53 search_base_type_c *search_base_type_c::search_base_type_singleton = NULL; |
|
54 |
|
55 |
52 |
56 |
53 search_base_type_c::search_base_type_c(void) {current_type_name = NULL;} |
57 search_base_type_c::search_base_type_c(void) {current_type_name = NULL;} |
54 |
58 |
55 |
59 /* static method! */ |
56 |
60 void search_base_type_c::create_singleton(void) { |
57 |
61 if (NULL == search_base_type_singleton) search_base_type_singleton = new search_base_type_c(); |
|
62 if (NULL == search_base_type_singleton) ERROR; |
|
63 } |
|
64 |
|
65 /* static method! */ |
58 symbol_c *search_base_type_c::get_basetype_decl(symbol_c *symbol) { |
66 symbol_c *search_base_type_c::get_basetype_decl(symbol_c *symbol) { |
59 if (NULL == symbol) |
67 create_singleton(); |
60 return NULL; |
68 if (NULL == symbol) return NULL; |
|
69 return (symbol_c *)symbol->accept(*search_base_type_singleton); |
|
70 } |
|
71 |
|
72 /* static method! */ |
|
73 symbol_c *search_base_type_c::get_basetype_id (symbol_c *symbol) { |
|
74 create_singleton(); |
|
75 if (NULL == symbol) return NULL; |
61 |
76 |
62 return (symbol_c *)symbol->accept(*this); |
77 search_base_type_singleton->current_type_name = NULL; |
63 } |
78 symbol->accept(*search_base_type_singleton); |
64 |
79 return (symbol_c *)search_base_type_singleton->current_type_name; |
65 symbol_c *search_base_type_c::get_basetype_id (symbol_c *symbol) { |
|
66 if (NULL == symbol) |
|
67 return NULL; |
|
68 |
|
69 current_type_name = NULL; /* just to be on the safe side... */ |
|
70 symbol->accept(*this); |
|
71 return (symbol_c *)current_type_name; |
|
72 } |
80 } |
73 |
81 |
74 |
82 |
75 /* Note by MJS: The following two functions definately do not belong in this class!! Maybe create a new utility class? |
83 /* Note by MJS: The following two functions definately do not belong in this class!! Maybe create a new utility class? |
76 * I will need to clean this up when the opportunity arises! |
84 * I will need to clean this up when the opportunity arises! |
77 */ |
85 */ |
78 |
86 /* static method! */ |
79 bool search_base_type_c::type_is_subrange(symbol_c* type_decl) { |
87 bool search_base_type_c::type_is_subrange(symbol_c* type_decl) { |
80 this->is_subrange = false; |
88 create_singleton(); |
81 type_decl->accept(*this); |
89 search_base_type_singleton->is_subrange = false; |
82 return this->is_subrange; |
90 type_decl->accept(*search_base_type_singleton); |
83 } |
91 return search_base_type_singleton->is_subrange; |
84 |
92 } |
|
93 |
|
94 |
|
95 /* static method! */ |
85 bool search_base_type_c::type_is_enumerated(symbol_c* type_decl) { |
96 bool search_base_type_c::type_is_enumerated(symbol_c* type_decl) { |
86 this->is_enumerated = false; |
97 create_singleton(); |
87 type_decl->accept(*this); |
98 search_base_type_singleton->is_enumerated = false; |
88 return this->is_enumerated; |
99 type_decl->accept(*search_base_type_singleton); |
|
100 return search_base_type_singleton->is_enumerated; |
89 } |
101 } |
90 |
102 |
91 |
103 |
92 /*************************/ |
104 /*************************/ |
93 /* B.1 - Common elements */ |
105 /* B.1 - Common elements */ |