@@ -42,44 +42,44 @@ distribution.
4242using namespace DFHack ;
4343
4444
45- void *type_identity::do_allocate_pod () {
45+ void *type_identity::do_allocate_pod () const {
4646 size_t sz = byte_size ();
4747 void *p = malloc (sz);
4848 memset (p, 0 , sz);
4949 return p;
5050}
5151
52- void type_identity::do_copy_pod (void *tgt, const void *src) {
52+ void type_identity::do_copy_pod (void *tgt, const void *src) const {
5353 memmove (tgt, src, byte_size ());
5454};
5555
56- bool type_identity::do_destroy_pod (void *obj) {
56+ bool type_identity::do_destroy_pod (void *obj) const {
5757 free (obj);
5858 return true ;
5959}
6060
61- void *type_identity::allocate () {
61+ void *type_identity::allocate () const {
6262 if (can_allocate ())
6363 return do_allocate ();
6464 else
6565 return NULL ;
6666}
6767
68- bool type_identity::copy (void *tgt, const void *src) {
68+ bool type_identity::copy (void *tgt, const void *src) const {
6969 if (can_allocate () && tgt && src)
7070 return do_copy (tgt, src);
7171 else
7272 return false ;
7373}
7474
75- bool type_identity::destroy (void *obj) {
75+ bool type_identity::destroy (void *obj) const {
7676 if (can_allocate () && obj)
7777 return do_destroy (obj);
7878 else
7979 return false ;
8080}
8181
82- void *enum_identity::do_allocate () {
82+ void *enum_identity::do_allocate () const {
8383 size_t sz = byte_size ();
8484 void *p = malloc (sz);
8585 memcpy (p, &first_item_value, std::min (sz, sizeof (int64_t )));
@@ -92,11 +92,11 @@ void *enum_identity::do_allocate() {
9292 * initialized by the loader in the initial mmap.
9393 */
9494compound_identity *compound_identity::list = NULL ;
95- std::vector<compound_identity*> compound_identity::top_scope;
95+ std::vector<const compound_identity*> compound_identity::top_scope;
9696
9797compound_identity::compound_identity (size_t size, TAllocateFn alloc,
98- compound_identity *scope_parent, const char *dfhack_name)
99- : constructed_identity(size, alloc), dfhack_name(dfhack_name), scope_parent(scope_parent)
98+ const compound_identity *scope_parent, const char *dfhack_name)
99+ : constructed_identity(size, alloc), dfhack_name(dfhack_name), scope_parent(const_cast <compound_identity*>( scope_parent)) // fixme
100100{
101101 next = list; list = this ;
102102}
@@ -109,7 +109,7 @@ void compound_identity::doInit(Core *)
109109 top_scope.push_back (this );
110110}
111111
112- std::string compound_identity::getFullName ()
112+ const std::string compound_identity::getFullName () const
113113{
114114 if (scope_parent)
115115 return scope_parent->getFullName () + " ." + getName ();
@@ -131,19 +131,19 @@ void compound_identity::Init(Core *core)
131131}
132132
133133bitfield_identity::bitfield_identity (size_t size,
134- compound_identity *scope_parent, const char *dfhack_name,
134+ const compound_identity *scope_parent, const char *dfhack_name,
135135 int num_bits, const bitfield_item_info *bits)
136136 : compound_identity(size, NULL , scope_parent, dfhack_name), bits(bits), num_bits(num_bits)
137137{
138138}
139139
140140enum_identity::enum_identity (size_t size,
141- compound_identity *scope_parent, const char *dfhack_name,
142- type_identity *base_type,
141+ const compound_identity *scope_parent, const char *dfhack_name,
142+ const type_identity *base_type,
143143 int64_t first_item_value, int64_t last_item_value,
144144 const char *const *keys,
145145 const ComplexData *complex ,
146- const void *attrs, struct_identity *attr_type)
146+ const void *attrs, const struct_identity *attr_type)
147147 : compound_identity(size, NULL , scope_parent, dfhack_name),
148148 keys(keys), complex(complex ),
149149 first_item_value(first_item_value), last_item_value(last_item_value),
@@ -158,7 +158,7 @@ enum_identity::enum_identity(size_t size,
158158 }
159159}
160160
161- enum_identity::enum_identity (enum_identity *base_enum, type_identity *override_base_type)
161+ enum_identity::enum_identity (const enum_identity *base_enum, const type_identity *override_base_type)
162162 : enum_identity(override_base_type->byte_size (), base_enum->getScopeParent(),
163163 base_enum->getName(), override_base_type, base_enum->first_item_value,
164164 base_enum->last_item_value, base_enum->keys, base_enum->complex,
@@ -177,10 +177,10 @@ enum_identity::ComplexData::ComplexData(std::initializer_list<int64_t> values)
177177}
178178
179179struct_identity::struct_identity (size_t size, TAllocateFn alloc,
180- compound_identity *scope_parent, const char *dfhack_name,
181- struct_identity *parent, const struct_field_info *fields)
180+ const compound_identity *scope_parent, const char *dfhack_name,
181+ const struct_identity *parent, const struct_field_info *fields)
182182 : compound_identity(size, alloc, scope_parent, dfhack_name),
183- parent(parent), has_children(false ), fields(fields)
183+ parent(const_cast <struct_identity*>( parent) ), has_children(false ), fields(fields)
184184{
185185}
186186
@@ -194,7 +194,7 @@ void struct_identity::doInit(Core *core)
194194 }
195195}
196196
197- bool struct_identity::is_subclass (struct_identity *actual)
197+ bool struct_identity::is_subclass (const struct_identity *actual) const
198198{
199199 if (!has_children && actual != this )
200200 return false ;
@@ -205,42 +205,42 @@ bool struct_identity::is_subclass(struct_identity *actual)
205205 return false ;
206206}
207207
208- std::string pointer_identity::getFullName ()
208+ const std::string pointer_identity::getFullName () const
209209{
210210 return (target ? target->getFullName () : std::string (" void" )) + " *" ;
211211}
212212
213- std::string container_identity::getFullName (type_identity *item)
213+ const std::string container_identity::getFullName (const type_identity *item) const
214214{
215215 return ' <' + (item ? item->getFullName () : std::string (" void" )) + ' >' ;
216216}
217217
218- std::string ptr_container_identity::getFullName (type_identity *item)
218+ const std::string ptr_container_identity::getFullName (const type_identity *item) const
219219{
220220 return ' <' + (item ? item->getFullName () : std::string (" void" )) + std::string (" *>" );
221221}
222222
223- std::string bit_container_identity::getFullName (type_identity *)
223+ const std::string bit_container_identity::getFullName (const type_identity *) const
224224{
225225 return " <bool>" ;
226226}
227227
228- std::string df::buffer_container_identity::getFullName (type_identity *item)
228+ const std::string df::buffer_container_identity::getFullName (const type_identity *item) const
229229{
230230 return (item ? item->getFullName () : std::string (" void" )) +
231231 (size > 0 ? stl_sprintf (" [%d]" , size) : std::string (" []" ));
232232}
233233
234- union_identity::union_identity (size_t size, TAllocateFn alloc,
234+ union_identity::union_identity (size_t size, const TAllocateFn alloc,
235235 compound_identity *scope_parent, const char *dfhack_name,
236236 struct_identity *parent, const struct_field_info *fields)
237237 : struct_identity(size, alloc, scope_parent, dfhack_name, parent, fields)
238238{
239239}
240240
241- virtual_identity::virtual_identity (size_t size, TAllocateFn alloc,
241+ virtual_identity::virtual_identity (size_t size, const TAllocateFn alloc,
242242 const char *dfhack_name, const char *original_name,
243- virtual_identity *parent, const struct_field_info *fields,
243+ const virtual_identity *parent, const struct_field_info *fields,
244244 bool is_plugin)
245245 : struct_identity(size, alloc, NULL , dfhack_name, parent, fields), original_name(original_name),
246246 vtable_ptr(NULL ), is_plugin(is_plugin)
@@ -462,7 +462,7 @@ void DFHack::flagarrayToString(std::vector<std::string> *pvec, const void *p,
462462 }
463463}
464464
465- static const struct_field_info *find_union_tag_candidate (struct_identity *structure, const struct_field_info *union_field)
465+ static const struct_field_info *find_union_tag_candidate (const struct_identity *structure, const struct_field_info *union_field)
466466{
467467 if (union_field->extra && union_field->extra ->union_tag_field )
468468 {
@@ -502,7 +502,7 @@ static const struct_field_info *find_union_tag_candidate(struct_identity *struct
502502 return nullptr ;
503503}
504504
505- const struct_field_info *DFHack::find_union_tag (struct_identity *structure, const struct_field_info *union_field)
505+ const struct_field_info *DFHack::find_union_tag (const struct_identity *structure, const struct_field_info *union_field)
506506{
507507 CHECK_NULL_POINTER (structure);
508508 CHECK_NULL_POINTER (union_field);
@@ -538,7 +538,7 @@ const struct_field_info *DFHack::find_union_tag(struct_identity *structure, cons
538538 return nullptr ;
539539 }
540540
541- auto container_type = static_cast <container_identity *>(union_field->type );
541+ auto container_type = static_cast <const container_identity *>(union_field->type );
542542 if (container_type->getFullName (nullptr ) != " vector<void>" ||
543543 !container_type->getItemType () ||
544544 container_type->getItemType ()->type () != IDTYPE_UNION )
@@ -555,7 +555,7 @@ const struct_field_info *DFHack::find_union_tag(struct_identity *structure, cons
555555 return nullptr ;
556556 }
557557
558- auto tag_container_type = static_cast <container_identity *>(tag_candidate->type );
558+ auto tag_container_type = static_cast <const container_identity *>(tag_candidate->type );
559559 if (tag_container_type->getFullName (nullptr ) == " vector<void>" &&
560560 tag_container_type->getItemType () &&
561561 tag_container_type->getItemType ()->type () == IDTYPE_ENUM )
0 commit comments