Skip to content

Commit

Permalink
parser lineNum cleanup; remove redundant vars
Browse files Browse the repository at this point in the history
  • Loading branch information
gewang committed Oct 4, 2024
1 parent 899d108 commit fb0ad41
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 27 deletions.
8 changes: 7 additions & 1 deletion src/core/chuck.lex
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ int yywrap( void )
// new line
void a_newline()
{
EM_newline( yylloc.last_column );
EM_newline( yylloc.last_column, yylloc.last_line );
}

// manually advance
Expand Down Expand Up @@ -200,6 +200,12 @@ long htol( c_str str )
return n;
}

// for debugging (string literals, especially multi-line strings)
void testLineNumPrint()
{
fprintf( stderr, "TEST: %ld %i\n", EM_lineNum, yylloc.last_line );
}


// block comment hack
#define block_comment_hack loop: \
Expand Down
35 changes: 14 additions & 21 deletions src/core/chuck_errmsg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,9 @@ using namespace std;
// global
t_CKINT EM_tokPos = 0;
t_CKINT EM_lineNum = 1;
t_CKINT EM_extLineNum = 1;

// current filename
static const char * the_filename = "";
// current line number
static t_CKINT the_lineNum = 1;
// current chuck
static ChucK * the_chuck = NULL;

Expand Down Expand Up @@ -108,7 +105,7 @@ static const char * g_str[] = {
"FINE!!", // 7
"FINER!", // 8
"FINEST", // 9
"ALL!!" // 10
"ALL!!!" // 10
};


Expand Down Expand Up @@ -145,15 +142,19 @@ static IntList intList( t_CKINT i, IntList rest )
// called by lexer on new line
// 1.5.0.5 (ge) updated to take a pos argument
//-----------------------------------------------------------------------------
void EM_newline( t_CKINT pos )
void EM_newline( t_CKINT pos, t_CKINT lineNum )
{
the_lineNum++;
// debug print
// cerr << "pos: " << pos << " lineNum: " << lineNum << " EM_lineNum: " << EM_lineNum << endl;

// HACK: this is specifically for multi-line strings
// for( int i = EM_lineNum; i < lineNum; i++ )
// the_linePos = intList( pos, the_linePos );

// set to new line num
EM_lineNum++;
EM_extLineNum++;
// add to linked list
the_linePos = intList( pos, the_linePos );

// debug print
// cerr << "line: " << EM_lineNum << " pos: " << pos << endl;
}


Expand Down Expand Up @@ -427,7 +428,7 @@ void EM_error( t_CKINT pos, const char * message, ... )
{
va_list ap;
IntList lines = the_linePos;
t_CKINT line = the_lineNum;
t_CKINT line = EM_lineNum;
t_CKINT actualPos = -1;
t_CKBOOL bold = TRUE;
// declare each time to pick up any TC state
Expand Down Expand Up @@ -493,7 +494,7 @@ void EM_error2( t_CKINT pos, const char * message, ... )
{
va_list ap;
IntList lines = the_linePos;
t_CKINT line = the_lineNum;
t_CKINT line = EM_lineNum;
t_CKINT actualPos = -1;
t_CKBOOL bold = TRUE;
// declare each time to pick up any TC state
Expand All @@ -512,8 +513,6 @@ void EM_error2( t_CKINT pos, const char * message, ... )
if( lines ) actualPos = pos - lines->i;
}

// save
EM_extLineNum = line;
// separate errmsgs with newlines
if( g_lasterror != "" ) lastErrorCat( "\n" );

Expand Down Expand Up @@ -577,8 +576,6 @@ void EM_error2b( t_CKINT line, const char * message, ... )
{
va_list ap;

EM_extLineNum = line;

// separate errmsgs with newlines
if( g_lasterror != "" ) lastErrorCat( "\n" );

Expand Down Expand Up @@ -621,7 +618,7 @@ const char * EM_error2str( t_CKINT pos, t_CKBOOL outputPrefix, const char * mess
{
va_list ap;
IntList lines = the_linePos;
t_CKINT line = the_lineNum;
t_CKINT line = EM_lineNum;
t_CKINT actualPos = -1;
t_CKBOOL bold = TRUE;
// declare each time to pick up any TC state
Expand Down Expand Up @@ -1025,9 +1022,7 @@ void EM_poplog()
void EM_start_filename( const char * fname )
{
the_filename = fname ? fname : (c_str)"";
the_lineNum = 1;
EM_lineNum = 1;
EM_extLineNum = 1;

// free the intList
IntList curr = NULL;
Expand Down Expand Up @@ -1055,9 +1050,7 @@ void EM_reset_filename()
// set
the_filename = (c_str)"";
// more set
the_lineNum = 0;
EM_lineNum = 0;
EM_extLineNum = 0;
}


Expand Down
6 changes: 1 addition & 5 deletions src/core/chuck_errmsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,8 @@ const char * mini_type( const char * str );
extern t_CKINT EM_tokPos;
extern t_CKINT EM_lineNum;

// EM_extLineNum is synced with EM_lineNum in lexer/parser phase, then synced
// with scanner/typechecker (EM_lineNum is not synced with scanner/typechecker)
extern t_CKINT EM_extLineNum;

// advance state when new line is encountered
void EM_newline( t_CKINT pos );
void EM_newline( t_CKINT pos, t_CKINT line );


//-----------------------------------------------------------------------------
Expand Down

0 comments on commit fb0ad41

Please sign in to comment.