Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and activate by default NDEBUG feature #62

Merged
merged 1 commit into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ YYTRACKMAXSTACKDEPTH = []
YYNOERRORRECOVERY = []
YYCOVERAGE = []
NDEBUG = []
default = ["YYNOERRORRECOVERY"]
default = ["YYNOERRORRECOVERY", "NDEBUG"]

[dependencies]
phf = { version = "0.11", features = ["uncased"] }
Expand Down
5 changes: 4 additions & 1 deletion sqlparser_bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ authors = ["Dandandan <[email protected]>"]
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]
Expand Down
2 changes: 1 addition & 1 deletion src/parser/parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions third_party/lemon/lemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ){
Expand All @@ -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
*/
Expand Down Expand Up @@ -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++;
Expand Down
45 changes: 23 additions & 22 deletions third_party/lemon/lempar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,12 @@ impl IndexMut<i8> 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.
Expand Down Expand Up @@ -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]
);
}
}
Expand Down Expand Up @@ -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)
);
}
}
}
Expand Down