Skip to content

Commit

Permalink
[tidy] Clean up scanCxFile() by renaming, extracting
Browse files Browse the repository at this point in the history
  • Loading branch information
thoni56 committed Jan 2, 2025
1 parent 6c41bf9 commit a11d8f3
Showing 1 changed file with 38 additions and 40 deletions.
78 changes: 38 additions & 40 deletions src/cxfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ static ScanFileFunctionStep secondPassMacroUsageFunctionSequence[];
static ScanFileFunctionStep globalUnusedDetectionFunctionSequence[];
static ScanFileFunctionStep symbolSearchFunctionSequence[];

static void scanCxFile(ScanFileFunctionStep *scanFunctionTable);
static void scanCxFileUsing(ScanFileFunctionStep *scanFunctionTable);


static void fPutDecimal(int num, FILE *file) {
Expand Down Expand Up @@ -519,7 +519,7 @@ static void writePartialReferenceFile(bool updateFlag,
mapOverFileTableWithIndex(mapfun);
if (mapfun2!=NULL)
mapOverFileTableWithIndex(mapfun2);
scanCxFile(fullScanFunctionSequence);
scanCxFileUsing(fullScanFunctionSequence);
closeCurrentReferenceFile();
}

Expand All @@ -538,17 +538,17 @@ static void writeReferencesFromMemoryIntoRefFileNo(int fileOrder) {
}
}

static void writeSingleReferenceFile(int updating, char *filename) {
static void writeSingleReferenceFile(bool updating, char *filename) {
openInOutReferenceFile(updating, filename);
writeCxFileHead();
mapOverFileTableWithIndex(writeFileNumberItem);
mapOverFileTableWithIndex(writeFileSourceIndexItem);
scanCxFile(fullScanFunctionSequence);
scanCxFileUsing(fullScanFunctionSequence);
mapOverReferenceTable(writeReferenceItem);
closeCurrentReferenceFile();
}

static void writeMultipeReferenceFiles(int updating, char *dirname) {
static void writeMultipeReferenceFiles(bool updating, char *dirname) {
char referenceFileName[MAX_FILE_NAME_SIZE];

createDirectory(dirname);
Expand All @@ -559,7 +559,7 @@ static void writeMultipeReferenceFiles(int updating, char *dirname) {
assert(strlen(referenceFileName) < MAX_FILE_NAME_SIZE - 1);
openInOutReferenceFile(updating, referenceFileName);
writeCxFileHead();
scanCxFile(fullScanFunctionSequence);
scanCxFileUsing(fullScanFunctionSequence);
writeReferencesFromMemoryIntoRefFileNo(i);
closeCurrentReferenceFile();
}
Expand Down Expand Up @@ -744,8 +744,8 @@ static int scanSymbolName(CharacterBuffer *cb, char *id, int size) {
}


static void getSymbolTypeAndClasses(Type *symbolType) {
*symbolType = lastIncomingData.data[CXFI_SYMBOL_TYPE];
static Type getSymbolType(void) {
return lastIncomingData.data[CXFI_SYMBOL_TYPE];
}


Expand All @@ -766,8 +766,7 @@ static void scanFunction_SymbolNameForFullUpdateSchedule(int size,
char *id = lastIncomingData.cachedSymbolName;
int len = scanSymbolName(cb, id, size);

Type symbolType;
getSymbolTypeAndClasses(&symbolType);
Type symbolType = getSymbolType();
if (symbolType!=TypeCppInclude || strcmp(id, LINK_NAME_INCLUDE_REFS)!=0) {
lastIncomingData.onLineReferencedSym = -1;
return;
Expand Down Expand Up @@ -848,8 +847,7 @@ static void scanFunction_SymbolName(int size,
char *id = lastIncomingData.cachedSymbolName;
scanSymbolName(cb, id, size);

Type symbolType;
getSymbolTypeAndClasses(&symbolType);
Type symbolType = getSymbolType();

ReferenceItem *referenceItem = &lastIncomingData.cachedReferenceItem;
lastIncomingData.referenceItem = referenceItem;
Expand Down Expand Up @@ -919,16 +917,14 @@ static void scanFunction_ReferenceForFullUpdateSchedule(int size,

Usage usage = lastIncomingData.data[CXFI_USAGE];

int file = lastIncomingData.data[CXFI_FILE_NUMBER];
file = fileNumberMapping[file];
int unmapped_file = lastIncomingData.data[CXFI_FILE_NUMBER];
int file = fileNumberMapping[unmapped_file];

int line = lastIncomingData.data[CXFI_LINE_INDEX];
int col = lastIncomingData.data[CXFI_COLUMN_INDEX];

Type symbolType;
getSymbolTypeAndClasses(&symbolType);

log_trace("%d %d->%d %d", usage, file, fileNumberMapping[file], line);
log_trace("Read reference with %s in file %d->%d at %d,%d", usageKindEnumName[usage],
unmapped_file, file, line, col);

Position pos = makePosition(file, line, col);
if (lastIncomingData.onLineReferencedSym == lastIncomingData.data[CXFI_SYMBOL_INDEX]) {
Expand Down Expand Up @@ -1060,40 +1056,42 @@ static int scanInteger(CharacterBuffer *cb, int *_ch) {
return scannedInt;
}

static void resetIncomingData() {
memset(&lastIncomingData, 0, sizeof(lastIncomingData));
lastIncomingData.onLineReferencedSym = -1;
lastIncomingData.symbolToCheckForDeadness = -1;
lastIncomingData.onLineRefMenuItem = NULL;
lastIncomingData.keyUsed[CXFI_INCLUDEFILENUMBER] = NO_FILE_NUMBER;
lastIncomingData.keyUsed[CXFI_SUPERCLASS] = NO_FILE_NUMBER;
fileNumberMapping[NO_FILE_NUMBER] = NO_FILE_NUMBER;
}

static void scanCxFile(ScanFileFunctionStep scanFunctionTable[]) {
int scannedInt = 0;
int ch;
static void setupRecordKeyHandlersFromTable(ScanFileFunctionStep scanFunctionTable[]) {
/* Set up the keys and handlers from the provided table */
for (int i = 0; scanFunctionTable[i].recordCode > 0; i++) {
assert(scanFunctionTable[i].recordCode < MAX_CHARS);
int ch = scanFunctionTable[i].recordCode;
lastIncomingData.handlerFunction[ch] = scanFunctionTable[i].handlerFunction;
lastIncomingData.argument[ch] = scanFunctionTable[i].argument;
}
}

static void scanCxFileUsing(ScanFileFunctionStep scanFunctionTable[]) {
ENTER();
if (currentReferenceFile == NULL) {
log_trace("No reference file opened");
LEAVE();
return;
}

/* Reset lastIncomingData */
memset(&lastIncomingData, 0, sizeof(lastIncomingData));
lastIncomingData.onLineReferencedSym = -1;
lastIncomingData.symbolToCheckForDeadness = -1;
lastIncomingData.onLineRefMenuItem = NULL;
lastIncomingData.keyUsed[CXFI_INCLUDEFILENUMBER] = NO_FILE_NUMBER;
lastIncomingData.keyUsed[CXFI_SUPERCLASS] = NO_FILE_NUMBER;
fileNumberMapping[NO_FILE_NUMBER] = NO_FILE_NUMBER;

/* Set up the keys and handlers from this table */
for (int i=0; scanFunctionTable[i].recordCode>0; i++) {
assert(scanFunctionTable[i].recordCode < MAX_CHARS);
ch = scanFunctionTable[i].recordCode;
lastIncomingData.handlerFunction[ch] = scanFunctionTable[i].handlerFunction;
lastIncomingData.argument[ch] = scanFunctionTable[i].argument;
}
resetIncomingData();

setupRecordKeyHandlersFromTable(scanFunctionTable);

initCharacterBufferFromFile(&cxFileCharacterBuffer, currentReferenceFile);
ch = ' ';
int ch = ' ';
while (!cxFileCharacterBuffer.isAtEOF) {
scannedInt = scanInteger(&cxFileCharacterBuffer, &ch);
int scannedInt = scanInteger(&cxFileCharacterBuffer, &ch);

if (cxFileCharacterBuffer.isAtEOF)
break;
Expand Down Expand Up @@ -1137,7 +1135,7 @@ static bool scanReferenceFile(char *cxrefLocation, char *element1, char *element
if (currentReferenceFile==NULL) {
return false;
} else {
scanCxFile(scanFunctionTable);
scanCxFileUsing(scanFunctionTable);
closeFile(currentReferenceFile);
currentReferenceFile = NULL;
return true;
Expand Down

0 comments on commit a11d8f3

Please sign in to comment.