00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifdef DO_MEMORY_USAGE
00020
00021 #include "memoryInfo.h"
00022 #include "typedReferenceCount.h"
00023 #include "typeHandle.h"
00024
00025
00026
00027
00028
00029
00030 MemoryInfo::
00031 MemoryInfo() {
00032 _void_ptr = (void *)NULL;
00033 _ref_ptr = (ReferenceCount *)NULL;
00034 _typed_ptr = (TypedObject *)NULL;
00035 _size = 0;
00036 _static_type = TypeHandle::none();
00037 _dynamic_type = TypeHandle::none();
00038
00039 _flags = 0;
00040 }
00041
00042
00043
00044
00045
00046
00047
00048 TypeHandle MemoryInfo::
00049 get_type() {
00050
00051
00052 if ((_flags & F_reconsider_dynamic_type) == 0) {
00053 if (_dynamic_type == TypeHandle::none()) {
00054 return _static_type;
00055 }
00056 return _dynamic_type;
00057 }
00058
00059
00060
00061
00062
00063
00064
00065 determine_dynamic_type();
00066
00067
00068 TypeHandle type = _static_type;
00069 update_type_handle(type, _dynamic_type);
00070
00071 return type;
00072 }
00073
00074
00075
00076
00077
00078
00079
00080 void MemoryInfo::
00081 determine_dynamic_type() {
00082 if ((_flags & F_reconsider_dynamic_type) != 0 &&
00083 _static_type != TypeHandle::none()) {
00084
00085
00086
00087 if (_typed_ptr == (TypedObject *)NULL) {
00088
00089
00090
00091 if (_static_type.is_derived_from(TypedReferenceCount::get_class_type())) {
00092 _typed_ptr = (TypedReferenceCount *)_ref_ptr;
00093 }
00094 }
00095
00096 if (_typed_ptr != (TypedObject *)NULL) {
00097
00098
00099
00100
00101 TypeHandle got_type = _typed_ptr->get_type();
00102
00103 if (got_type == TypeHandle::none()) {
00104 express_cat.warning()
00105 << "Found an unregistered type in a " << _static_type
00106 << " pointer:\n"
00107 << "Check derived types of " << _static_type
00108 << " and make sure that all are being initialized.\n";
00109 _dynamic_type = _static_type;
00110 _flags &= ~F_reconsider_dynamic_type;
00111 return;
00112 }
00113
00114 update_type_handle(_dynamic_type, got_type);
00115 }
00116 }
00117 }
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127 void MemoryInfo::
00128 update_type_handle(TypeHandle &destination, TypeHandle refined) {
00129 if (refined == TypeHandle::none()) {
00130 express_cat.error()
00131 << "Attempt to update type of " << (void *)_ref_ptr
00132 << "(type is " << get_type()
00133 << ") to an undefined type!\n";
00134
00135 } else if (destination == refined) {
00136
00137
00138 } else if (destination.is_derived_from(refined)) {
00139
00140
00141 } else if (refined.is_derived_from(destination)) {
00142
00143 destination = refined;
00144
00145 } else {
00146 express_cat.error()
00147 << "Pointer " << (void *)_ref_ptr << " previously indicated as type "
00148 << destination << " is now type " << refined << "!\n";
00149 destination = refined;
00150 }
00151 }
00152
00153 #endif // DO_MEMORY_USAGE