From d317ed53f766206d91b30146aac6623adb8b93fc Mon Sep 17 00:00:00 2001 From: gwenn Date: Thu, 1 Aug 2024 20:54:19 +0200 Subject: [PATCH] Fix and activate by default NDEBUG feature --- Cargo.toml | 2 +- sqlparser_bench/Cargo.toml | 5 ++++- src/parser/parse.y | 2 +- third_party/lemon/lemon.c | 6 +++-- third_party/lemon/lempar.rs | 45 +++++++++++++++++++------------------ 5 files changed, 33 insertions(+), 27 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6bc69f9..12a6390 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ YYTRACKMAXSTACKDEPTH = [] YYNOERRORRECOVERY = [] YYCOVERAGE = [] NDEBUG = [] -default = ["YYNOERRORRECOVERY"] +default = ["YYNOERRORRECOVERY", "NDEBUG"] [dependencies] phf = { version = "0.11", features = ["uncased"] } diff --git a/sqlparser_bench/Cargo.toml b/sqlparser_bench/Cargo.toml index 6c7b361..1ec87cb 100644 --- a/sqlparser_bench/Cargo.toml +++ b/sqlparser_bench/Cargo.toml @@ -5,7 +5,10 @@ authors = ["Dandandan "] edition = "2018" [dependencies] -sqlite3-parser = { path = "..", default-features = false, features = ["YYNOERRORRECOVERY"] } +sqlite3-parser = { path = "..", default-features = false, features = [ + "YYNOERRORRECOVERY", + "NDEBUG", +] } fallible-iterator = "0.3" [dev-dependencies] diff --git a/src/parser/parse.y b/src/parser/parse.y index 93bdcaa..577db69 100644 --- a/src/parser/parse.y +++ b/src/parser/parse.y @@ -62,7 +62,7 @@ use crate::parser::ast::*; use crate::parser::{Context, ParserError}; use crate::dialect::{from_token, Token, TokenType}; use indexmap::IndexMap; -use log::{debug, error, log_enabled}; +use log::error; #[allow(non_camel_case_types)] type sqlite3ParserError = crate::parser::ParserError; diff --git a/third_party/lemon/lemon.c b/third_party/lemon/lemon.c index 8ead377..301577d 100644 --- a/third_party/lemon/lemon.c +++ b/third_party/lemon/lemon.c @@ -4451,7 +4451,7 @@ void ReportTable( } lineno = 1; - fprintf(out, + fprintf(out, "/* This file is automatically generated by Lemon from input grammar\n" "** source file \"%s\"", lemp->filename); lineno++; if( nDefineUsed==0 ){ @@ -4464,7 +4464,7 @@ void ReportTable( } fprintf(out, "*/\n"); lineno++; } - + /* The first %include directive begins with a C-language comment, ** then skip over the header comment of the template file */ @@ -4611,8 +4611,10 @@ void ReportTable( /* Finish rendering the constants now that the action table has ** been computed */ + fprintf(out,"#[cfg(any(feature = \"YYCOVERAGE\", not(feature = \"NDEBUG\")))]\n"); lineno++; fprintf(out,"const YYNSTATE: YYACTIONTYPE = %d;\n",lemp->nxstate); lineno++; fprintf(out,"const YYNRULE: usize = %d;\n",lemp->nrule); lineno++; + fprintf(out,"#[cfg(not(feature = \"NDEBUG\"))]\n"); lineno++; fprintf(out,"const YYNRULE_WITH_ACTION: YYACTIONTYPE = %d;\n",lemp->nruleWithAction); lineno++; fprintf(out,"const YYNTOKEN: YYACTIONTYPE = %d;\n",lemp->nterminal); lineno++; diff --git a/third_party/lemon/lempar.rs b/third_party/lemon/lempar.rs index 28695fe..7b6a6af 100644 --- a/third_party/lemon/lempar.rs +++ b/third_party/lemon/lempar.rs @@ -239,13 +239,12 @@ impl IndexMut for yyParser<'_> { } #[cfg(not(feature = "NDEBUG"))] -use log::Level::Debug; -#[cfg(not(feature = "NDEBUG"))] +use log::{debug, log_enabled, Level::Debug}; static TARGET: &str = "Parse"; /* For tracing shifts, the names of all terminals and nonterminals ** are required. The following table supplies these names */ -#[cfg(any(feature = "YYCOVERAGE", not(feature = "NDEBUG")))] +//#[cfg(any(feature = "YYCOVERAGE", not(feature = "NDEBUG")))] %% /* For tracing reduce actions, the names of all rules are required. @@ -302,14 +301,14 @@ impl yyParser<'_> { impl yyParser<'_> { fn yy_pop_parser_stack(&mut self) { use std::mem::take; - let yytos = take(&mut self.yystack[self.yyidx]); + let _yytos = take(&mut self.yystack[self.yyidx]); self.yyidx = self.yyidx.checked_sub(1).unwrap(); //assert_eq!(self.yyidx+1, self.yystack.len()); #[cfg(not(feature = "NDEBUG"))] { debug!( target: TARGET, - "Popping {}", yyTokenName[yytos.major as usize] + "Popping {}", yyTokenName[_yytos.major as usize] ); } } @@ -488,24 +487,26 @@ fn yy_find_reduce_action( */ impl yyParser<'_> { #[allow(non_snake_case)] + #[cfg(feature = "NDEBUG")] + fn yyTraceShift(&self, _: YYACTIONTYPE, _: &str) { + } + #[allow(non_snake_case)] + #[cfg(not(feature = "NDEBUG"))] fn yyTraceShift(&self, yyNewState: YYACTIONTYPE, zTag: &str) { - #[cfg(not(feature = "NDEBUG"))] - { - let yytos = &self[0]; - if yyNewState < YYNSTATE { - debug!( - target: TARGET, - "{} '{}', go to state {}", zTag, yyTokenName[yytos.major as usize], yyNewState - ); - } else { - debug!( - target: TARGET, - "{} '{}', pending reduce {:?}", - zTag, - yyTokenName[yytos.major as usize], - yyNewState.checked_sub(YY_MIN_REDUCE) - ); - } + let yytos = &self[0]; + if yyNewState < YYNSTATE { + debug!( + target: TARGET, + "{} '{}', go to state {}", zTag, yyTokenName[yytos.major as usize], yyNewState + ); + } else { + debug!( + target: TARGET, + "{} '{}', pending reduce {:?}", + zTag, + yyTokenName[yytos.major as usize], + yyNewState.checked_sub(YY_MIN_REDUCE) + ); } } }