Record the lexical order of identifiers whilst scanning the source files.

This is needed for detecting use before declaration. The lexical scanner
is the only place where we process the source text in strict lexical
order, so do it there.

As Verilog allows modules to span multiple source files, don't reset
the counter when we reset the lexor.
This commit is contained in:
Martin Whitaker 2024-02-18 15:46:56 +00:00
parent ccf925a4f7
commit 8b3f0d63b4
3 changed files with 10 additions and 2 deletions

View File

@ -26,6 +26,7 @@
//# define YYSTYPE lexval
# include <climits>
# include <cstdarg>
# include <iostream>
# 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)) {

View File

@ -115,12 +115,14 @@ static std::list<named_pexpr_t>*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)

View File

@ -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;
};