Skip to content

Commit d8cc2a1

Browse files
committed
More clang fixes; rework anc<T> special copy c'tor
1 parent 07a9360 commit d8cc2a1

File tree

9 files changed

+115
-154
lines changed

9 files changed

+115
-154
lines changed

src/ancrec.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ basAnc::basAnc() // default c'tor (for derived copy c'tor
845845
memset( (char *)this+SZVFTP, 0, sizeof(*this)-SZVFTP); // SZVFTP: virtFcnTblPtr: cnglob.h.
846846
} // basAnc::basAnc
847847
//---------------------------------------------------------------------------------------------------------------------------
848-
basAnc::basAnc( int flags, SFIR * _fir, USI _nFlds, const char * _what, USI _eSz, RCT _rt, USI _sOff, const CULT* pCULT, int dontRegister/*=0*/ )
848+
basAnc::basAnc( int flags, SFIR * _fir, USI _nFlds, const char * _what, USI _eSz, RCT _rt, USI _sOff, const CULT* pCULT, bool dontRegister/*=false*/ )
849849
{
850850
memset( (char *)this+SZVFTP, 0, sizeof(basAnc)-SZVFTP); // zero all basAnc members but virtFcnTblPtr at front
851851
ba_flags = flags;
@@ -858,6 +858,7 @@ basAnc::basAnc( int flags, SFIR * _fir, USI _nFlds, const char * _what, USI _eSz
858858
mn = 1; // min record subscript 1 (overwritten with 0 if static)
859859
// ptr() = 0; // is done in derived class constructor (deriv vf not avail here; ptr is pure!)
860860
ba_pCULT = pCULT; // pointer to associated input CULT table, nullptr = unknown
861+
// ba_probeModernizeTable = nullptr; // done by memset
861862
if (!dontRegister)
862863
regis(); // conditionally include anchor for nextAnc() iteration
863864
} // basAnc::basAnc

src/ancrec.h

Lines changed: 22 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,6 @@
44

55
// ancrec.h: record and record anchor base class definitions for cse
66

7-
8-
// before #include, #define NEEDLIKECTOR if including file calls the anc<T> like-another constructor
9-
10-
11-
//************************
12-
// unsuccessful OPTIONS
13-
//************************
14-
15-
16-
//---------------------------------------------------------------------------------------------------------------------------
17-
18-
197
#ifndef ANCREC_H // endif at end file
208
#define ANCREC_H
219

@@ -91,7 +79,7 @@ class basAnc // base class for record anchors: basAnc<recordName>
9179
// nullptr if none; see cuprobe.cpp
9280

9381
basAnc();
94-
basAnc( int flags, SFIR * fir, USI nFlds, const char * what, USI eSz, RCT rt, USI sOff, const CULT* pCult, int dontRegister=0 );
82+
basAnc( int flags, SFIR * fir, USI nFlds, const char * what, USI eSz, RCT rt, USI sOff, const CULT* pCult, bool dontRegister=false );
9583
void FC regis();
9684
virtual ~basAnc(); // destroyed in deriv classes, to use vf
9785
virtual record* ptr() = 0; // access block ptr (in drv class: typed)
@@ -101,6 +89,7 @@ class basAnc // base class for record anchors: basAnc<recordName>
10189
virtual const record& rec(TI i) const = 0; // ditto const
10290
virtual record* GetAtSafe( int i) const = 0; // typed pointer to ith record or NULL
10391
virtual void* recMbr(TI i, USI off) = 0; // point record i member by offset
92+
virtual basAnc* CloneForType(const char* what, int _flags, BP _ownB) const = 0;
10493
void * FC recFld(TI i, SI fn); // point record i member by FIELD # 3-92
10594
RC FC al( TI n, int erOp=ABT, BP _ownB=NULL); // allocate records block. destroys old recs.
10695
RC FC reAl( TI n, int erOp=ABT); // (re)allocate records block. keeps old recs <= n.
@@ -340,12 +329,11 @@ class record // base class for records
340329

341330
template <class T> class anc : public basAnc
342331
{ public:
343-
anc( const char *what, SFIR *sFir, USI nFlds, RCT rt, CULT* pCULT=nullptr) // cpp'tor used for static instances
344-
: basAnc( 0, sFir, nFlds, what, sizeof(T), rt, offsetof( T, sstat), pCULT)
332+
anc( const char *what, SFIR *sFir, USI nFlds, RCT rt, const CULT* pCULT=nullptr, bool dontregister=false) // cpp'tor used for static instances
333+
: basAnc( 0, sFir, nFlds, what, sizeof(T), rt, offsetof( T, sstat), pCULT, dontregister)
345334
{ p = 0; }
346-
anc( const BP src, int flags, char *_what, // like-another constructor,
347-
BP _ownB, int dontRegister=0 ); // code included only ifdef NEEDLIKECTOR.
348335
virtual ~anc(); // destroys records, and types anchor & its recs.
336+
virtual anc<T>* CloneForType(const char* _what, int _flags, BP _ownB) const;
349337

350338
T* p; // typed pointer to record array storage block
351339
virtual T* GetAtSafe( int i) const // typed pointer to ith record or NULL
@@ -428,27 +416,24 @@ template <class T> class anc : public basAnc
428416
rp <= (record *)( (char *)ptr() + eSz*n ); \
429417
IncP( DMPP( rp), eSz) ) \
430418
if (((record *)rp)->r_status > 0)
419+
431420
//=============================================================================
432-
#ifdef NEEDLIKECTOR // define where this constructor is USED: avoids generating for classes where not used.
433-
434-
template <class T> anc<T>::anc( const BP src, int flags, char *_what, BP _ownB, int dontRegister/*=0*/)
435-
436-
// like-another-with-records-deleted constructor.
437-
438-
// Generates the same derived class as src, using generic code; assumes size of all anc<T>'s is the same.
439-
440-
{ // for subsidiary types anchor, cul.cpp::ratTyR, 2-92; only used for one (arbitrary) T.
441-
// must copy: virt fcns, fir,nFlds,eSz,sOff,rt.
442-
memcpy( this, src, sizeof(anc<T>) ); // bitwise copy ALL, to incude virt fcn table ptr.
443-
ancN= nAl= n= 0; p= 0; tyB= 0; // clear what don't want: anchor #, records, ul stuff.
444-
mn = 1; // mn = 1 when no records allocated even if will be static
445-
ba_flags = flags; what = _what; ownB = _ownB; // store members given by caller
446-
if (!dontRegister)
447-
regis(); // conditionally include in nextAnc iteration.
448-
// CAUTION: don't regis() tyB's or any dm anc<T>'s without
449-
// adding unregister logic to destructor, 10-93.
450-
} // anc<T>::anc
451-
#endif // NEEDLIKECTOR
421+
template <class T> anc<T>* anc<T>::CloneForType( // copy c-tor-ish re creating anc<T> for DEFTYPE
422+
const char*_what, // new 'what' -- generally "<source what> type" (in DM)
423+
int _flags, // flags
424+
BP _ownB) const // owner
425+
{
426+
427+
// make new anc<T> with data from *this
428+
// combined with defaults from anc<T>::anc<T> and basAnc::basAnc
429+
anc<T>* pC = new anc<T>(_what, fir, nFlds, rt, ba_pCULT, true);
430+
431+
pC->ba_flags = _flags; // caller specific values
432+
pC->ownB = _ownB;
433+
434+
return pC;
435+
436+
} // anc<T>::CloneForType
452437
//-------------------------------------------------------------------------------------------------------------------------
453438
template <class T> anc<T>::~anc() // destroy anchor: destroy its records and types.
454439

src/cnguts.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2176,9 +2176,8 @@ void LOCAL accumulatorsAccum(
21762176
} // accumulatorsAccum
21772177
//-----------------------------------------------------------------------------
21782178
RC ACCUMULATOR::acm_CkF(
2179-
int options)
2179+
[[maybe_unused]] int options)
21802180
{
2181-
options;
21822181
return RCOK;
21832182

21842183
} // ACCUMULATOR::acm_CkF

src/cul.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@
5050
/*------------------------------- INCLUDES --------------------------------*/
5151

5252
#include "srd.h" // SFIR; sFdtab; GetDttab
53-
#define NEEDLIKECTOR // say this .cpp file needs anc<T> like-another constructor: prevents generation for classes where not used.
5453
#include "ancrec.h" // record: base class for rccn.h classes; anc<T> template definition.
55-
#undef NEEDLIKECTOR
5654
#include "rccn.h" // SFI_ [VALNDT_]
5755
#include "msghans.h" // MH_S0201 MH_S0202
5856

@@ -3624,7 +3622,7 @@ LOCAL void FC adjOwTi(
36243622
BP b;
36253623
for (CULT *cc = c-1; nxOwRat( ownB, c, &cc, &b, 0); ) // loop over basAncs owned by ownB
36263624
{
3627-
for (SI i = 1; i <= b->n; i++) // loop records in basAnc b
3625+
for (TI i = 1; i <= b->n; i++) // loop records in basAnc b
36283626
{
36293627
record *e = &b->rec(i); // point to record i (ancpak.cpp)
36303628
if (e->ownTi < minI) // if owner out of range of interest
@@ -3645,8 +3643,6 @@ LOCAL RC FC ratTyR( BP b) // if basAnc does not have secondary basAnc for types
36453643

36463644
if (b->tyB==0) // if this anc does not already have secondary anc for types, make one
36473645
{
3648-
RC rc;
3649-
36503646
// generate constructor arguments: flags, what, ownB
36513647

36523648
int flags = RFTYS | RFNOEX; // say is "types" anchor, disable expression expansion
@@ -3657,14 +3653,15 @@ LOCAL RC FC ratTyR( BP b) // if basAnc does not have secondary basAnc for types
36573653
BP _ownB = 0;
36583654
if (b->ownB) // if basAnc is owned, then tyB's owner will be owners tyB
36593655
{
3656+
RC rc;
36603657
CSE_E( ratTyR(b->ownB) ) // CALL SELF now to be sure owner already has tyB: if added later, ptr wd not get here
36613658
_ownB = b->ownB->tyB;
36623659
}
36633660

3664-
// make anc<T> of main anc's <T> (ie same derived class): use special constructor (of an arbitrary T)
3665-
// that COPIES given anc INCLUDING VIRTUAL FCNS. Copies rt, eSz, sOff, etc; drops records, tyB.
3661+
// make anc<T> of main anc's <T> (ie same derived class): Copies rt, eSz, sOff, etc; drops records, tyB.
36663662
// CAUTION: must not register w/o adding unregister to d'tor.
3667-
b->tyB = (BP)new anc<ZNR>( b, flags, _what, _ownB, 1 ); // construct copy w/ no records; do not register. ancrec.h.
3663+
b->tyB = b->CloneForType( _what, flags, _ownB); // construct copy w/ no records; do not register
3664+
36683665
if (!b->tyB)
36693666
{
36703667
// (known inconsistency: out of memory messages from

src/cuprobe.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -359,16 +359,18 @@ RC PROBEOBJECT::po_FindMember() // parse and look up probe member name in po_inB
359359
// if not found, issue error message. syntax ok if here.
360360

361361
if (!po_inB && !po_runB) // if found in neither input nor run records basAnc
362+
{
362363
if (!m) // if first token of name
363-
return perNx( MH_U0011, po_what, cuToktx); // "U0011: %s member '%s' not found"
364+
return perNx(MH_U0011, po_what, cuToktx); // "U0011: %s member '%s' not found"
364365
else
365366
{ // fancier error message for partial match
366-
const char* foundPart = strncpy0( NULL, f1->fi_GetMName(), m+1); // truncate to Tmpstr
367-
return perNx( MH_U0012,
367+
const char* foundPart = strncpy0(NULL, f1->fi_GetMName(), m+1); // truncate to Tmpstr
368+
return perNx(MH_U0012,
368369
//"U0012: %s member '%s%s' not found: \n"
369370
//" matched \"%s\" but could not match \"%s\"."
370-
po_what, foundPart, cuToktx, foundPart, cuToktx );
371+
po_what, foundPart, cuToktx, foundPart, cuToktx);
371372
}
373+
}
372374

373375
// match found for current token. Done if end fir table member text; error if tables continue differently.
374376

0 commit comments

Comments
 (0)