diff --git a/lexor.lex b/lexor.lex index f94c68f5f..4e93cb87b 100644 --- a/lexor.lex +++ b/lexor.lex @@ -26,6 +26,7 @@ //# define YYSTYPE lexval +# include # include # include # include "compiler.h" @@ -40,7 +41,7 @@ using namespace std; -# define YY_USER_INIT reset_lexor(); +# define YY_USER_INIT do { reset_lexor(); yylloc.lexical_pos = 0; } while (0); # define yylval VLlval # define YY_NO_INPUT @@ -338,6 +339,8 @@ TU [munpf] int rc = lexor_keyword_code(yytext, yyleng); switch (rc) { case IDENTIFIER: + assert(yylloc.lexical_pos != UINT_MAX); + yylloc.lexical_pos += 1; yylval.text = strdupnew(yytext); if (strncmp(yylval.text,"PATHPULSE$", 10) == 0) rc = PATHPULSE_IDENTIFIER; @@ -429,6 +432,8 @@ TU [munpf] \\[^ \t\b\f\r\n]+ { + assert(yylloc.lexical_pos != UINT_MAX); + yylloc.lexical_pos += 1; yylval.text = strdupnew(yytext+1); if (gn_system_verilog()) { if (PPackage*pkg = pform_test_package_identifier(yylval.text)) { diff --git a/parse.y b/parse.y index 61ea8aa81..9d06fa16e 100644 --- a/parse.y +++ b/parse.y @@ -115,12 +115,14 @@ static std::list*attributes_in_context = 0; (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ + (Current).lexical_pos = YYRHSLOC (Rhs, 1).lexical_pos; \ (Current).text = YYRHSLOC (Rhs, 1).text; \ } else { \ (Current).first_line = YYRHSLOC (Rhs, 0).last_line; \ (Current).first_column = YYRHSLOC (Rhs, 0).last_column; \ (Current).last_line = YYRHSLOC (Rhs, 0).last_line; \ (Current).last_column = YYRHSLOC (Rhs, 0).last_column; \ + (Current).lexical_pos = YYRHSLOC (Rhs, 0).lexical_pos; \ (Current).text = YYRHSLOC (Rhs, 0).text; \ } \ } while (0) diff --git a/parse_misc.h b/parse_misc.h index 86e86314b..23547e85c 100644 --- a/parse_misc.h +++ b/parse_misc.h @@ -1,7 +1,7 @@ #ifndef IVL_parse_misc_H #define IVL_parse_misc_H /* - * Copyright (c) 1998-2022 Stephen Williams (steve@icarus.com) + * Copyright (c) 1998-2024 Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -34,6 +34,7 @@ struct vlltype { int first_column; int last_line; int last_column; + unsigned lexical_pos; const char*text; std::string get_fileline() const; };