Skip to content

Commit

Permalink
[tidy] Make lexembuffer position and fileOffset be single values iso.…
Browse files Browse the repository at this point in the history
… rings
  • Loading branch information
thoni56 committed Aug 16, 2023
1 parent 499224d commit 29ae7c9
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 29 deletions.
12 changes: 4 additions & 8 deletions src/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,13 @@
#define LEXEM_BUFFER_SIZE (1024 + MAX_LEXEM_SIZE) /* must be bigger than MAX_LEXEM_SIZE */

#define MAX_UNGET_CHARS 20 /* reserve for ungetChar in char buffer */
#define MAX_LEXEM_SIZE MAX_FUN_NAME_SIZE /* max size of 1 lexem (string, ident) */
/* should be bigger, than MAX_FUN_NAME_SIZE */
#define MAX_LEXEM_SIZE MAX_FUN_NAME_SIZE /* max size of 1 lexem
(string, ident) should be
bigger than
MAX_FUN_NAME_SIZE */

#define YYIDBUFFER_SIZE 128 /* number of buffered tokens */
/* for C++ has to be larger because of backtracking parser */
/* it should be around 2048, but then workmemory will overflow */
/* when loading lot of sourcepath jsl modules */
/* NO, it will overflow due to the whole parsing stack which is */
/* stored there */

#define LEX_POSITIONS_RING_SIZE 16 /* for now, just for block markers */

/* ***************************** caching ******************************** */

Expand Down
1 change: 0 additions & 1 deletion src/lexembuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ void initLexemBuffer(LexemBuffer *buffer) {
buffer->read = buffer->lexemStream;
buffer->begin = buffer->lexemStream;
buffer->write = buffer->lexemStream;
buffer->ringIndex = 0;
}

void *getLexemStreamWrite(LexemBuffer *lb) {
Expand Down
9 changes: 4 additions & 5 deletions src/lexembuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ typedef struct {
char *read; /* next to read */
char *write; /* where to write next */
char lexemStream[LEXEM_BUFFER_SIZE];
Position positionRing[LEX_POSITIONS_RING_SIZE];
unsigned fileOffsetRing[LEX_POSITIONS_RING_SIZE];
int ringIndex; /* ...Ring[ringIndex%LEX_POSITIONS_RING_SIZE] */
Position position;
unsigned fileOffset;
char *backpatchPointer; /* Pointer into lexemStream can be saved
* and later backpatched without explicit
* knowledge of buffers and indices... */
* and later backpatched without explicit
* knowledge of buffers and indices... */
} LexemBuffer;


Expand Down
22 changes: 8 additions & 14 deletions src/lexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,10 @@ static LexemCode scanFloatingPointConstant(CharacterBuffer *cb, int *chPointer)


static void noteNewLexemPosition(LexemBuffer *lb, CharacterBuffer *cb) {
int index = 0; // lb->ringIndex % LEX_POSITIONS_RING_SIZE;
lb->fileOffsetRing[index] = fileOffsetFor(cb);
lb->positionRing[index].file = cb->fileNumber;
lb->positionRing[index].line = cb->lineNumber;
lb->positionRing[index].col = columnPosition(cb);
lb->ringIndex++;
lb->fileOffset = fileOffsetFor(cb);
lb->position.file = cb->fileNumber;
lb->position.line = cb->lineNumber;
lb->position.col = columnPosition(cb);
}

static LexemCode preprocessorLexemFromString(const char *preprocessorWord) {
Expand Down Expand Up @@ -764,18 +762,14 @@ bool buildLexemFromCharacters(CharacterBuffer *cb, LexemBuffer *lb) {
assert(0);
nextLexem:
if (options.mode == ServerMode) {
int pi, parChar;
int parChar;
Position position;
int currentLexemFileOffset;

/* Since lb->ringIndex is incremented *after* adding, we need to subtract 1 to get current */
pi = 0; // (lb->ringIndex-1) % LEX_POSITIONS_RING_SIZE;
currentLexemFileOffset = lb->fileOffsetRing[pi];
position = lb->positionRing[pi];
int currentLexemFileOffset = lb->fileOffset;
position = lb->position;

if (fileNumberFrom(cb) == olOriginalFileNumber && fileNumberFrom(cb) != NO_FILE_NUMBER
&& fileNumberFrom(cb) != -1 && s_jsl == NULL) {
if (options.serverOperation == OLO_EXTRACT && lb->ringIndex>=2) { /* TODO: WTF does "lb->index >= 2" mean? */
if (options.serverOperation == OLO_EXTRACT) {
ch = skipBlanks(cb, ch);
int apos = fileOffsetFor(cb);
log_trace(":pos1==%d, olCursorPos==%d, olMarkPos==%d",apos,options.olCursorOffset,options.olMarkPos);
Expand Down
1 change: 0 additions & 1 deletion src/yylex_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ static void setup_lexBuffer_for_reading_identifier(void *data) {
*strchr(&currentFile.lexemBuffer.lexemStream[2], ' ') = '\0';
currentFile.lexemBuffer.read = currentFile.lexemBuffer.lexemStream;
currentFile.lexemBuffer.write = strchr(currentFile.lexemBuffer.lexemStream, '\0');
currentFile.lexemBuffer.ringIndex = 2;
}

Ensure(Yylex, add_a_cpp_definition_to_the_symbol_table) {
Expand Down

0 comments on commit 29ae7c9

Please sign in to comment.