|
29 | 29 | #include "cnglob.h" |
30 | 30 | #include "ancrec.h" |
31 | 31 | #include "cse.h" |
32 | | -#include "msghans.h" // MH_X0050 |
| 32 | +#include "msghans.h" |
33 | 33 | #include "messages.h" // msgIsHan |
34 | 34 | #include "exman.h" |
35 | 35 | #include "cvpak.h" |
@@ -124,83 +124,45 @@ int record::IsNameMatch( const char* _name) const |
124 | 124 | return !_stricmp( _name, Name()); |
125 | 125 | } // record::IsNameMatch |
126 | 126 | //----------------------------------------------------------------------------- |
127 | | -/*virtual*/ record& record::CopyFrom( |
128 | | - const record* src, |
129 | | - int copyName/*=1*/, |
130 | | - [[maybe_unused]] int dupPtrs/*=0*/) |
131 | | - |
132 | | -// copy user and ul data from another record or init data to already-constructed record |
133 | | - |
134 | | -// copies user language overhead, and ownTi, and, unless suppressed, name. |
135 | | -// Does not copy ancrec internal overhead except 'gud' |
136 | | - |
137 | | -/* "dupPtrs" is for poss future use duplicating heap pointers in derived classes |
138 | | - (in present uses (input to run rat copies) ptrs are not currenly being dup'd 2-92) |
139 | | - (7-92: converting to dup'd ptrs with explicit derived class CopyFrom's and destructors. |
140 | | - "dupPtrs" would shorten code; table bit or different field ty needed to say which ptrs to dup (some CHP's don't get dup'd). */ |
141 | | -{ |
142 | | -// error if not init (can't constr here: need b, ss). (if needed, do a "copyTo" or a "copy(b,i1,i2)" that constructs dest.) |
143 | | - if (!b) // (or gud? wd error here if init then destroyed) |
144 | | - err( PABT, (char *)MH_X0050); // error msg "record::CopyFrom: unconstructed destination (b is 0)" and abort program. |
145 | | -#ifdef DEBUG2 // message not occuring (1-95) so omit from release version. |
146 | | - b->validate("record::CopyFrom"); // abort if record 'this' not associated with valid anchor |
147 | | - ((record *)src)->Validate(); |
148 | | -#endif |
149 | | - |
150 | | -// use shorter record length |
151 | | - int eSz = b->eSz; // get dest derived class rec length from anchor |
152 | | - if ( src->b && src->b->rt==src->rt // if source has anchor (could be just init data) |
153 | | - && eSz != src->b->eSz ) // and source record length is different |
154 | | - eSz = min( b->sOff, src->b->sOff); // use the shorter length and do not copy status bytes (3-12-92). |
155 | | - // calls exist (ZNI->ZNR) where source is start of dest record (ug!) |
156 | | - // add logic to copy status bytes to correct place if need found |
157 | | - |
158 | | -// copy data after front (bitwise) |
159 | | - // copy start offset: do not copy base class except ownTi and optionally name |
160 | | - int offBeg = offsetof(record, ownTi); |
161 | | - memcpy( (char *)this + offBeg, (char *)src + offBeg, eSz - offBeg ); |
162 | | - |
163 | | - if (copyName) |
164 | | - name.Set(src->name); |
165 | | - |
166 | | -// copy user language front members. another arg option? |
167 | | - li = src->li; // if nz, is subscript of entry it is LIKE |
168 | | - ty = src->ty; // if nz, may be TYPE subscript (future) |
169 | | - fileIx = src->fileIx; // if nz, is index of object input fileName |
170 | | - line = src->line; // if nz, is object input file line |
171 | | - |
172 | | -// copy internal good-record flag with possible future user bits |
173 | | - gud = src->gud; // 0 = free, > 0 = in use, sign bit = bad (poss future use). |
174 | | - |
175 | | - FixUp(); // virtual: record can e.g. fix ptrs |
176 | | -#if defined( _DEBUG) |
177 | | - Validate(); // virtual |
178 | | -#endif |
179 | | - return *this; |
180 | | -} // record::CopyFrom |
181 | | -//--------------------------------------------------------------------------------------------------------------------------- |
182 | 127 | /*virtual*/ void record::Copy( // copy user and ul data and 'gud' from another record of same type |
183 | | - const record* pSrc, |
184 | | - int options/*=0*/) |
| 128 | + const record* pSrc, // source record |
| 129 | + int options/*=0*/) // rcoLEAVENAME: do NOT copy name |
185 | 130 | { |
186 | | - options; |
187 | | - |
188 | | - // this implementation requires records already constructed (can't construct here without knowning b, ss). |
189 | | - if (!b) // (or gud? wd error here if init then destroyed) |
190 | | - err( PABT, (char *)MH_X0051); // err msg "record::operator=(): unconstructed destination (b is 0)" and abort program |
191 | | - if (b->rt != pSrc->b->rt) // check for same rt (same derived class) |
192 | | - err( PABT, (char *)MH_X0052); // err msg "record::operator=(): records not same type" and abort program |
193 | | - b->validate("left arg to record::operator="); // abort if records not well anchored |
194 | | -#ifdef DEBUG2 |
195 | | - pSrc->b->validate("right arg to record::operator="); |
| 131 | + // records must already be constructed (can't construct here without knowning b, ss). |
| 132 | + if (!b || !pSrc) // (or gud? wd error here if init then destroyed) |
| 133 | + err( PABT, (char *)MH_X0051); // err msg "record::Copy(): unconstructed destination or !pSrc" |
| 134 | +#if defined( _DEBUG) |
| 135 | + b->validate("Copy() dest"); // abort if records not well anchored |
| 136 | + pSrc->b->validate("Copy() src"); |
196 | 137 | #endif |
197 | | - name.Release(); // memcpy will overwrite with pSrc.name |
198 | | - // copy start offset: don't copy internal members |
| 138 | + |
| 139 | + // bitwise copy members preceding name (not including internal members) |
199 | 140 | int offBeg = offsetof(record, gud); |
200 | | - memcpy((char *)this + offBeg, (char *)pSrc + offBeg, b->eSz - offBeg); |
201 | | - name.FixAfterCopy(); |
| 141 | + int offEnd = offsetof(record, name); |
| 142 | + memcpy((char*)this + offBeg, (const char*)pSrc + offBeg, offEnd - offBeg); |
| 143 | + |
| 144 | + // conditionally copy name |
| 145 | + if (!(options & rcoLEAVENAME)) |
| 146 | + name = pSrc->name; |
| 147 | + |
| 148 | + // bitwisecopy remainder (ownTi, record data, and status array) |
| 149 | + offBeg = offsetof(record, ownTi); |
| 150 | + if (b->rt == pSrc->b->rt) |
| 151 | + { // same type: single memcpy() |
| 152 | + memcpy((char*)this + offBeg, (const char*)pSrc + offBeg, b->eSz - offBeg); |
| 153 | + } |
| 154 | + else |
| 155 | + { // partial copy (e.g. ZNI->ZNR) |
| 156 | + if (pSrc->b->sOff > b->sOff) |
| 157 | + err(PABT, (char*)MH_X0052); |
| 158 | + else |
| 159 | + { memcpy((char*)this + offBeg, (const char*)pSrc + offBeg, pSrc->b->sOff - offBeg); |
| 160 | + memcpy((char*)this + b->sOff, (const char*)pSrc + pSrc->b->sOff, pSrc->b->nFlds); |
| 161 | + } |
| 162 | + } |
202 | 163 |
|
203 | 164 | FixUp(); // virtual: record can e.g. fix ptrs |
| 165 | + |
204 | 166 | #if defined( _DEBUG) |
205 | 167 | Validate(); // virtual |
206 | 168 | #endif |
@@ -349,7 +311,7 @@ o what ); |
349 | 311 | // else if it has file and line, optionally show them |
350 | 312 | if (op) |
351 | 313 | if (fileIx) |
352 | | - return strtprintf("%s [%s(%d)]", what, getFileName( fileIx), line); |
| 314 | + return strtprintf("%s [%s(%d)]", what, getFileName( fileIx), inputLineNo); |
353 | 315 |
|
354 | 316 | // else just class name |
355 | 317 | return what; |
@@ -1047,7 +1009,7 @@ RC FC basAnc::del( TI i, int erOp/*=ABT*/) // delete (squeeze out) ith record |
1047 | 1009 | { |
1048 | 1010 | if (!dest.gud) |
1049 | 1011 | conRec(i); // construct destination if nec to insure vftp, rt, b, ss set. |
1050 | | - dest.CopyFrom(&src); // copy record i+1 to i without dup'ing heap ptrs |
| 1012 | + dest.Copy( &src); // copy record i+1 to i without dup'ing heap ptrs |
1051 | 1013 | // tentatively no destroy: does nothing in base class, and deriv class might delete heap ptrs we did not dup. |
1052 | 1014 | #if defined( _DEBUG) |
1053 | 1015 | dest.Validate(); |
|
0 commit comments