Skip to content

Commit 8487997

Browse files
authored
Merge pull request #404 from cse-sim/srd-enhance
Record info internals: add struct SFIR member to identify fields requiring special case (non-bitwise) copy
2 parents b65543b + eaa150d commit 8487997

File tree

8 files changed

+181
-158
lines changed

8 files changed

+181
-158
lines changed

src/RCDEF/rcdef.cpp

Lines changed: 75 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@
162162
#include "srd.h"
163163

164164
#include "xiopak.h" // xffilcomp
165-
// #include "envpak.h" // hello byebye
166165
#include "cuevf.h" // EVFHR EVFMH
167166
#include "cvpak.h"
168167
#include "lookup.h"
@@ -2049,7 +2048,13 @@ x { printf( "\nRecord trap!");}
20492048

20502049
// standard type-specific members: Copy() and operator=()
20512050
fprintf( frc, " %s& Copy( const %s& _d) { Copy( static_cast< const record*>(&_d)); return *this; }\n", rcNam, rcNam);
2051+
#if 0
2052+
0 experiment re elimination of duplicate Copy / CopyFrom
2053+
0 retain pending finalization of Copy / CopyFrom merge 6-2023
2054+
0 fprintf(frc, " %s& operator=( const %s& _d) = delete;\n", rcNam, rcNam);
2055+
#else
20522056
fprintf( frc, " %s& operator=( const %s& _d) { Copy( static_cast< const record*>(&_d)); return *this; }\n", rcNam, rcNam);
2057+
#endif
20532058

20542059
// virtual Copy(): override or not
20552060
fprintf( frc, " virtual void Copy( const record* pSrc, int options=0)%s;\n",
@@ -2230,7 +2235,7 @@ x { printf( "\nRecord trap!");}
22302235

22312236
if (fSrfd) // if doing it and opened ok
22322237
{
2233-
wSrfd4( fSrfd); // write part after per-record stuff, below
2238+
// wSrfd4( fSrfd); write part after per-record stuff, below DROPPED 6-2023
22342239
fprintf( fSrfd, "\n\n/* end of srfd.cpp */\n" );
22352240
fclose(fSrfd);
22362241
printf(" \n");
@@ -2932,7 +2937,7 @@ LOCAL void wRcTd( FILE *f) // write record and anchor class declara
29322937
//======================================================================
29332938
LOCAL void wSrfd1( FILE *f)
29342939

2935-
// write "Small record and field descriptor" C source file for compilation and linking into applications
2940+
// write "Small record and field descriptor" C++ file for compilation and linking into applications
29362941

29372942
// PART 1 of 4 parts: field types table, and stuff above portion repeated for each record type.
29382943

@@ -2945,15 +2950,15 @@ LOCAL void wSrfd1( FILE *f)
29452950
"// srfd.cpp\n"
29462951
"\n"
29472952
"/* This is a Record and Field Descriptor Tables source file generated generated by rcdef.exe.\n"
2948-
" This file is compiled and linked into an application, such as CN. */\n" );
2953+
" This file is compiled and linked into CSE.*/\n" );
29492954
fprintf( f, "\n"
29502955
"/* DO NOT EDIT: This file is overwritten when rcdef is run.\n"
29512956
" To change, change rcdef.exe input as desired and re-run rcdef.exe via the appropropriate batch file. */\n\n"
29522957
"\n"
29532958
"#include \"cnglob.h\" // includes <dtypes.h> for DTxxxx symbols\n"
29542959
"#include \"srd.h\" // defines structures and declares variables. Plus comments. Manually generated file.\n"
2955-
"#include <ancrec.h> // defines base class for record classes in rc____.h files. Manually generated file.\n"
2956-
"// also <rc___.h> file(s) are included below.\n"
2960+
"#include \"ancrec.h\" // defines base class for record classes. Manually generated file.\n"
2961+
"// also rccn.h is included below.\n"
29572962
"\n"
29582963
"#undef o // in case an .h file defines o\n"// 1-95
29592964
);
@@ -2973,9 +2978,8 @@ LOCAL void wSrfd1( FILE *f)
29732978
for (int i = 0; i < nfdtypes; i++)
29742979
{
29752980
// write data type 0 as "0", not "DTSI" or whatever is first, for clearer entry 0 (FDNONE)
2976-
char* dtTx = (Fdtab[i].dtype==0 ? const_cast<char*>("0")
2977-
: strtcat( "DT", dtnames[ dtnmi[ DTBMASK&(Fdtab[i].dtype) ] ],
2978-
NULL ) );
2981+
const char* dtTx = (Fdtab[i].dtype==0 ? "0"
2982+
: strtcat( "DT", dtnames[ dtnmi[ DTBMASK&(Fdtab[i].dtype) ] ], NULL ) );
29792983
/* write line: DTXXXX, LMXXXX, UNXXXX, // number NAME */
29802984
fprintf( f, " {%15s, %10s, %13s },\t//%3d %s\n",
29812985
dtTx,
@@ -2990,23 +2994,24 @@ LOCAL void wSrfd1( FILE *f)
29902994

29912995
// Write stuff above "fir" tables for record types
29922996

2993-
fprintf( f,
2997+
fprintf(f,
29942998
"\n\n/*========== small FIELDS-IN-RECORDS tables for each record type */\n"
29952999
"\n"
2996-
" /* COLUMNS ARE\n"
2997-
" .fdTy .evf .ff .off .mName \n"
2998-
" (sFdtab (vari- (fld \n"
2999-
" index) ation) flgs) (member offset) (member name) field type name\n"
3000-
" ------- ------ ----- ----------------- ------------------ --------------- */\n"
3001-
"\n"
3002-
"/*lint -e619 suppress msg for putting \"text\" in pointer */\n\n");
3000+
"// COLUMNS ARE\n"
3001+
"// ff field flags\n"
3002+
"// fdTy field type (sFdtab idx)\n"
3003+
"// evf variability (evaluation interval)\n"
3004+
"// nxsc fn of next field requiring special case copy\n"
3005+
"// off member offset\n"
3006+
"// mName member name\n"
3007+
"// data type (as comment)\n\n");
30033008

30043009
// wSrfd3, called for each record type, continues the file
30053010
} // wSrfd1
30063011
//======================================================================
30073012
LOCAL void wSrfd2( FILE *f)
30083013

3009-
// write "Small record and field descriptor" C source file for compilation and linking into applications
3014+
// write "Small record and field descriptor" c++ source file for compilation and linking into applications
30103015

30113016
// PART 2 of 4 parts: portion repeated at each *file statement
30123017

@@ -3019,7 +3024,7 @@ LOCAL void wSrfd2( FILE *f)
30193024
//======================================================================
30203025
LOCAL void wSrfd3( FILE *f)
30213026

3022-
// write "Small record and field descriptor" C source file for compilation and linking into applications
3027+
// write "Small record and field descriptor" C++ source file for compilation and linking into applications
30233028

30243029
// PART 3 of 4 parts: portion repeated for each record type: fields-in-record table for current record.
30253030

@@ -3032,61 +3037,77 @@ LOCAL void wSrfd3( FILE *f)
30323037

30333038
// for file format see comments in srd.h, or in srfd.cpp as output.
30343039
{
3040+
// identify fields that cannot be copied bit-wise
3041+
// chain them together for use in e.g. record::Copy
3042+
std::vector< int> nxsc(rcdesc->rcdnfds, -1);
3043+
int iNxscPrior = 0;
3044+
for (int j = 0; j < rcdesc->rcdnfds; j++)
3045+
{
3046+
int fdi = rcdesc->rcdfdd[j].rcfdnm; // field type
3047+
if (strcmp( rcfdnms[fdi], "CHP")==0)
3048+
{ nxsc[iNxscPrior] = j;
3049+
iNxscPrior = j;
3050+
}
3051+
}
3052+
30353053
fprintf( f, "struct SFIR sfir%s[] =\t// fields info for RT%s\n"
30363054
"{\n #define o(m) offsetof(%s,m)\n"
3037-
// {dddd, dddd, dddd,ssssssssssssssssssss,sssssssssssssssssss },
3038-
" // .ff .fdTy .evf .off .mName\n",
3055+
"// ff fdTy evf nxsc off mName\n",
30393056
rcNam, rcNam, rcNam );
30403057
for (int j = 0; j < rcdesc->rcdnfds; j++) // fields loop
30413058
{
30423059
int fdi = rcdesc->rcdfdd[j].rcfdnm; // get field type
3043-
fprintf( f, " {%4d, %4d, %4d,%20s,%19s },\t// %s\n",
3060+
fprintf( f, " {%4d, %4d, %4d, %4d,%20s,%19s },\t// %s\n",
30443061
rcdesc->rcdfdd[j].ff, // field flags (attributes)
30453062
fdi, // field type
30463063
rcdesc->rcdfdd[j].evf, // field variation
3064+
nxsc[ j], // next special copy field
30473065
strtprintf("o(%s)", fldFullNm2[rcseq][j].c_str()), // full member name, in macro call to make compiler supply offset
30483066
enquote( fldNm2[ rcseq][j].c_str()), // user member name in quotes (for probes, error messages)
30493067
rcfdnms[fdi] ); // name of field type, in comment
30503068
#define WARNAT (30-1) // extra -1 got lots of messages
30513069
if (strlen(fldNm2[ rcseq][j].c_str()) > WARNAT) // report overlong ones
30523070
rcderr( "Warning: member name over %d long: %s", WARNAT, fldNm2[ rcseq][j].c_str());
30533071
}
3054-
fprintf( f, " { 0, 0, 0, 0, 0 }\t// terminator\n"
3072+
fprintf( f, " { 0, 0, 0, 0, 0, 0 }\t// terminator\n"
30553073
" #undef o\n"
30563074
"}; // sfir%s\n\n", rcNam );
30573075
} // wSrfd3
30583076
//======================================================================
3059-
LOCAL void wSrfd4( FILE *f)
3060-
3061-
// write "Small record and field descriptor" C source file for compilation and linking into applications
3062-
3063-
// PART 4 of 4 parts: stuff after portion repeated for each record type; small record descriptor table.
3064-
{
3065-
3066-
// Write small record descriptor table
3067-
3068-
fprintf( f, "\n\n/*========== small RECORD DESCRIPTOR table */\n"
3069-
"\n"
3070-
" // find desired entry by searching for .rt \n"
3071-
"\n"
3072-
"SRD sRd[] =\n"
3073-
"{ // recTy, #fds, fields-in-record pointer\n"
3074-
" // .rt .nFlds .fir\n" );
3075-
for (int i = 1; i < nrcnms; i++) // loop records types
3076-
// note start at 1 to skip RTNONE
3077-
{
3078-
RCD* rd = (RCD *)( (char *)Rcdtab + (ULI)Rcdtab[ rctypes[i] & RCTMASK]);
3079-
// use offset stored in pointer array
3080-
// write line " RTXXXX, nFields, sfirXXXX,"
3081-
fprintf( f, " {%15s, %3d, sfir%s },\n",
3082-
strtcat( "RT", rcnms[i], NULL),
3083-
rd->rcdnfds, rcnms[i] );
3084-
}
3085-
fprintf( f, " { 0, 0, 0 }\t// terminate table for searching\n"
3086-
"}; // sRd[]\n");
3087-
3088-
// caller recs() finishes file and closes.
3089-
} // wSrfd4
3077+
#if 0
3078+
0 DROPPED 6-2023 (unused)
3079+
0 LOCAL void wSrfd4( FILE *f)
3080+
0
3081+
0 // write "Small record and field descriptor" C++ file for compilation and linking into applications
3082+
0
3083+
0 // PART 4 of 4 parts: stuff after portion repeated for each record type; small record descriptor table.
3084+
0 {
3085+
0
3086+
0 // Write small record descriptor table
3087+
0
3088+
0 fprintf( f, "\n\n/*========== small RECORD DESCRIPTOR table */\n"
3089+
0 "\n"
3090+
0 " // find desired entry by searching for .rt \n"
3091+
0 "\n"
3092+
0 "SRD sRd[] =\n"
3093+
0 "{ // recTy, #fds, fields-in-record pointer\n"
3094+
0 " // .rt .nFlds .fir\n" );
3095+
0 for (int i = 1; i < nrcnms; i++) // loop records types
3096+
0 // note start at 1 to skip RTNONE
3097+
0 {
3098+
0 RCD* rd = (RCD *)( (char *)Rcdtab + (ULI)Rcdtab[ rctypes[i] & RCTMASK]);
3099+
0 // use offset stored in pointer array
3100+
0 // write line " RTXXXX, nFields, sfirXXXX,"
3101+
0 fprintf( f, " {%15s, %3d, sfir%s },\n",
3102+
0 strtcat( "RT", rcnms[i], NULL),
3103+
0 rd->rcdnfds, rcnms[i] );
3104+
0 }
3105+
0 fprintf( f, " { 0, 0, 0 }\t// terminate table for searching\n"
3106+
0 "}; // sRd[]\n");
3107+
0
3108+
0 // caller recs() finishes file and closes.
3109+
0 } // wSrfd4
3110+
#endif
30903111

30913112
//======================================================================
30923113
LOCAL void sumry() // write rcdef summary to screen and file

src/ancrec.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ record::record(BP _b, TI i, SI noZ/*=0*/) // construct record i of basAnc b, z
6060
} // record::record
6161
//---------------------------------------------------------------------------------------------------------------------------
6262
void* record::field( int fn) // point to member in record by FIELD #
63-
{ return (void *)((char *)this + b->fir[fn].off); }
63+
{ return (void *)((char *)this + b->fir[fn].fi_off); }
6464
//-----------------------------------------------------------------------------
6565
const void* record::field( int fn) const
66-
{ return (const void *)((const char *)this + b->fir[fn].off); }
66+
{ return (const void *)((const char *)this + b->fir[fn].fi_off); }
6767
//-----------------------------------------------------------------------------
6868
void record::RRFldCopy( // record-to-record field copy
6969
const record* r, // source record (same type as this)
@@ -100,7 +100,7 @@ void record::FldCopy( // field-to-field copy (within record)
100100
} // record::FldCopy
101101
//-----------------------------------------------------------------------------
102102
int record::DType( int fn) const
103-
{ int fdTy = b->fir[ fn].fdTy; // get field type (sFdtab subscript) from rat's "Fields In Record" table
103+
{ int fdTy = b->fir[ fn].fi_fdTy; // get field type (sFdtab subscript) from rat's "Fields In Record" table
104104
int dt = sFdtab[ fdTy].dtype; // get data type from small Fields info Table
105105
return dt;
106106
} // record::DType
@@ -638,7 +638,7 @@ void CDEC record::chafSelf( // say increment change flag IN SAME RECORD on cha
638638
{
639639
va_list ap;
640640
va_start(ap, chafFn);
641-
chafNV(this->b, ss, b->fir[chafFn].off, ap);
641+
chafNV(this->b, ss, b->fir[chafFn].fi_off, ap);
642642
} // record::chafSelf
643643
//============================================================================================================================
644644
void CDEC record::chafN( // say increment specified flag during run on change in list of fields in curr record
@@ -884,7 +884,7 @@ void * FC basAnc::recFld( TI i, SI fn) // point record i member by FIELD #
884884
/* note: this is not in ancrec.h to avoid needing to include srd.h first for sFIRstr;
885885
it is not virtual to avoid multiple copies. delete later (3-92) if not used. */
886886
{
887-
return (void *)((char *)&rec(i) + fir[fn].off); // get field offset from basAnc's fields-in-record table
887+
return (void *)((char *)&rec(i) + fir[fn].fi_off); // get field offset from basAnc's fields-in-record table
888888
}
889889
//---------------------------------------------------------------------------------------------------------------------------
890890
RC FC basAnc::al( // destroy any existing records and allocate space for n (0=default) records
@@ -1251,7 +1251,7 @@ const char* basAnc::getChoiTx( // return text of given value for a choice data
12511251

12521252
// add more checks to this code if errors tend to happen...
12531253

1254-
USI fdTy = fir[fn].fdTy; // get field type (sFdtab subscript) from rat's "Fields In Record" table
1254+
USI fdTy = fir[fn].fi_fdTy; // get field type (sFdtab subscript) from rat's "Fields In Record" table
12551255
USI dt = sFdtab[fdTy].dtype; // get data type from small Fields info Table
12561256

12571257
chan &= ~NCNAN; // clear special bits in nchoice value to make checks work

0 commit comments

Comments
 (0)