From 0efca0f6449aaef67b54586b543106ab67c9aea5 Mon Sep 17 00:00:00 2001 From: Alexandre Duret-Lutz Date: Thu, 16 Dec 2004 12:33:37 +0000 Subject: [PATCH] * src/ltlparse/ltlscan.ll: Pass yyleng to the std::string constructor, so it doesn't have to compute it. * src/tgbaparse/tgbascan.ll: Likewise. (YY_USER_INIT, current_file): Remove, it is too costly to use yy::Location::filename in the current implementation of yy::Location (this attribute is duplicated for each token). Leaving it empty divides the parsing time by 3. * src/tgbaparse/fmterror.cc, src/tgbaparse/public.hh (format_tgba_parse_errors): Take the filename as argument. * src/tgbatest/explprod.cc, src/tgbatest/ltl2tgba.cc, src/tgbatest/mixprod.cc, src/tgbatest/powerset.cc, src/tgbatest/readsave.cc, src/tgbatest/reductgba.cc, src/tgbatest/tgbaread.cc, src/tgbatest/tripprod.cc, iface/gspn/dottyssp.cc, iface/gspn/ltlgspn.cc: Adjust calls to format_tgba_parse_errors. --- ChangeLog | 18 ++++++++++++++++++ iface/gspn/dottyssp.cc | 2 +- iface/gspn/ltlgspn.cc | 3 ++- src/ltlparse/ltlscan.ll | 2 +- src/tgbaparse/fmterror.cc | 6 ++++-- src/tgbaparse/public.hh | 1 + src/tgbaparse/tgbascan.ll | 18 ++++-------------- src/tgbatest/explprod.cc | 4 ++-- src/tgbatest/ltl2tgba.cc | 5 +++-- src/tgbatest/mixprod.cc | 2 +- src/tgbatest/powerset.cc | 2 +- src/tgbatest/readsave.cc | 2 +- src/tgbatest/reductgba.cc | 2 +- src/tgbatest/tgbaread.cc | 2 +- src/tgbatest/tripprod.cc | 6 +++--- 15 files changed, 44 insertions(+), 31 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9ca6969da..f8f808ec5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2004-12-16 Alexandre Duret-Lutz + + * src/ltlparse/ltlscan.ll: Pass yyleng to the std::string constructor, + so it doesn't have to compute it. + * src/tgbaparse/tgbascan.ll: Likewise. + (YY_USER_INIT, current_file): Remove, it is too costly to use + yy::Location::filename in the current implementation + of yy::Location (this attribute is duplicated for each token). + Leaving it empty divides the parsing time by 3. + * src/tgbaparse/fmterror.cc, src/tgbaparse/public.hh + (format_tgba_parse_errors): Take the filename as argument. + * src/tgbatest/explprod.cc, src/tgbatest/ltl2tgba.cc, + src/tgbatest/mixprod.cc, src/tgbatest/powerset.cc, + src/tgbatest/readsave.cc, src/tgbatest/reductgba.cc, + src/tgbatest/tgbaread.cc, src/tgbatest/tripprod.cc, + iface/gspn/dottyssp.cc, iface/gspn/ltlgspn.cc: Adjust calls + to format_tgba_parse_errors. + 2004-12-15 Alexandre Duret-Lutz * src/tgbaparse/tgbaparse.yy: Cache parsed formulae to speedup diff --git a/iface/gspn/dottyssp.cc b/iface/gspn/dottyssp.cc index 1d33619a0..d3ac69823 100644 --- a/iface/gspn/dottyssp.cc +++ b/iface/gspn/dottyssp.cc @@ -46,7 +46,7 @@ main(int argc, char **argv) spot::tgba_parse_error_list pel1; spot::tgba_explicit* control = spot::tgba_parse(argv[--argc], pel1, dict, env); - if (spot::format_tgba_parse_errors(std::cerr, pel1)) + if (spot::format_tgba_parse_errors(std::cerr, argv[argc], pel1)) return 2; spot::tgba* a = gspn.automaton(control); diff --git a/iface/gspn/ltlgspn.cc b/iface/gspn/ltlgspn.cc index 8cf826a89..2d96b2325 100644 --- a/iface/gspn/ltlgspn.cc +++ b/iface/gspn/ltlgspn.cc @@ -182,7 +182,8 @@ main(int argc, char **argv) spot::tgba_parse_error_list pel1; spot::tgba_explicit* control = spot::tgba_parse(argv[formula_index + 2], pel1, dict, env); - if (spot::format_tgba_parse_errors(std::cerr, pel1)) + if (spot::format_tgba_parse_errors(std::cerr, argv[formula_index + 2], + pel1)) return 2; #else spot::gspn_interface gspn(2, argv, dict, env, dead); diff --git a/src/ltlparse/ltlscan.ll b/src/ltlparse/ltlscan.ll index 906f2579c..97fb10a61 100644 --- a/src/ltlparse/ltlscan.ll +++ b/src/ltlparse/ltlscan.ll @@ -116,7 +116,7 @@ flex_set_buffer(const char* buf) */ [a-zA-EH-QSTWYZ_][a-zA-EH-WYZ0-9_]* | [a-zA-EH-QSTWYZ_][a-zA-EH-WYZ0-9_][a-zA-Z0-9_]* { - yylval->str = new std::string(yytext); + yylval->str = new std::string(yytext, yyleng); BEGIN(not_prop); return ATOMIC_PROP; } diff --git a/src/tgbaparse/fmterror.cc b/src/tgbaparse/fmterror.cc index 3d7690ae3..09ca5fb8f 100644 --- a/src/tgbaparse/fmterror.cc +++ b/src/tgbaparse/fmterror.cc @@ -26,14 +26,16 @@ namespace spot { bool format_tgba_parse_errors(std::ostream& os, + const std::string& filename, tgba_parse_error_list& error_list) { bool printed = false; spot::tgba_parse_error_list::iterator it; for (it = error_list.begin(); it != error_list.end(); ++it) { - if (it->first.begin.filename != "") - os << it->first << ": "; + if (filename != "-") + os << filename << ":"; + os << it->first << ": "; os << it->second << std::endl; printed = true; } diff --git a/src/tgbaparse/public.hh b/src/tgbaparse/public.hh index 1dc63aed6..b7f685dd1 100644 --- a/src/tgbaparse/public.hh +++ b/src/tgbaparse/public.hh @@ -69,6 +69,7 @@ namespace spot /// parsing \a ltl_string. /// \return \c true iff any diagnostic was output. bool format_tgba_parse_errors(std::ostream& os, + const std::string& filename, tgba_parse_error_list& error_list); /// @} diff --git a/src/tgbaparse/tgbascan.ll b/src/tgbaparse/tgbascan.ll index dfaee6b00..fac2a9466 100644 --- a/src/tgbaparse/tgbascan.ll +++ b/src/tgbaparse/tgbascan.ll @@ -1,4 +1,4 @@ -/* Copyright (C) 2003 Laboratoire d'Informatique de Paris 6 (LIP6), +/* Copyright (C) 2003, 2004 Laboratoire d'Informatique de Paris 6 (LIP6), ** département Systèmes Répartis Coopératifs (SRC), Université Pierre ** et Marie Curie. ** @@ -31,16 +31,8 @@ #define YY_USER_ACTION \ yylloc->columns(yyleng); -#define YY_USER_INIT \ - do { \ - yylloc->begin.filename = current_file; \ - yylloc->end.filename = current_file; \ - } while (0) - #define YY_NEVER_INTERACTIVE 1 -static std::string current_file; - %} eol \n|\r|\n\r|\r\n @@ -54,7 +46,7 @@ eol \n|\r|\n\r|\r\n acc[ \t]*= return ACC_DEF; [a-zA-Z][a-zA-Z0-9_]* { - yylval->str = new std::string(yytext); + yylval->str = new std::string(yytext, yyleng); return IDENT; } @@ -76,7 +68,7 @@ acc[ \t]*= return ACC_DEF; return STRING; } \\["\\] yylval->str->append(1, yytext[1]); - [^"\\]+ yylval->str->append (yytext, yyleng); + [^"\\]+ yylval->str->append(yytext, yyleng); <> { BEGIN(INITIAL); return UNTERMINATED_STRING; @@ -98,12 +90,10 @@ namespace spot if (name == "-") { yyin = stdin; - current_file = "standard input"; } else { - yyin = fopen (name.c_str (), "r"); - current_file = name; + yyin = fopen(name.c_str(), "r"); if (!yyin) return 1; } diff --git a/src/tgbatest/explprod.cc b/src/tgbatest/explprod.cc index 680db25d5..f4b39e385 100644 --- a/src/tgbatest/explprod.cc +++ b/src/tgbatest/explprod.cc @@ -47,11 +47,11 @@ main(int argc, char** argv) spot::ltl::environment& env(spot::ltl::default_environment::instance()); spot::tgba_parse_error_list pel1; spot::tgba_explicit* a1 = spot::tgba_parse(argv[1], pel1, dict, env); - if (spot::format_tgba_parse_errors(std::cerr, pel1)) + if (spot::format_tgba_parse_errors(std::cerr, argv[1], pel1)) return 2; spot::tgba_parse_error_list pel2; spot::tgba_explicit* a2 = spot::tgba_parse(argv[2], pel2, dict, env); - if (spot::format_tgba_parse_errors(std::cerr, pel2)) + if (spot::format_tgba_parse_errors(std::cerr, argv[2], pel2)) return 2; { diff --git a/src/tgbatest/ltl2tgba.cc b/src/tgbatest/ltl2tgba.cc index ea75245de..d51455f9d 100644 --- a/src/tgbatest/ltl2tgba.cc +++ b/src/tgbatest/ltl2tgba.cc @@ -280,7 +280,8 @@ main(int argc, char** argv) spot::tgba_parse_error_list pel; system = spot::tgba_parse(argv[formula_index] + 2, pel, dict, env, debug_opt); - if (spot::format_tgba_parse_errors(std::cerr, pel)) + if (spot::format_tgba_parse_errors(std::cerr, + argv[formula_index] + 2, pel)) return 2; system->merge_transitions(); std::clog << argv[formula_index] + 2 << " read" << std::endl; @@ -528,7 +529,7 @@ main(int argc, char** argv) spot::tgba_parse_error_list pel; spot::tgba_explicit* e; to_free = a = e = spot::tgba_parse(input, pel, dict, env, debug_opt); - if (spot::format_tgba_parse_errors(std::cerr, pel)) + if (spot::format_tgba_parse_errors(std::cerr, input, pel)) { delete to_free; delete dict; diff --git a/src/tgbatest/mixprod.cc b/src/tgbatest/mixprod.cc index 28cce7ac2..e70870e60 100644 --- a/src/tgbatest/mixprod.cc +++ b/src/tgbatest/mixprod.cc @@ -56,7 +56,7 @@ main(int argc, char** argv) spot::tgba_parse_error_list pel2; spot::tgba_explicit* a2 = spot::tgba_parse(argv[2], pel2, dict, env); - if (spot::format_tgba_parse_errors(std::cerr, pel2)) + if (spot::format_tgba_parse_errors(std::cerr, argv[2], pel2)) return 2; { diff --git a/src/tgbatest/powerset.cc b/src/tgbatest/powerset.cc index db7d75cff..a49e7ba13 100644 --- a/src/tgbatest/powerset.cc +++ b/src/tgbatest/powerset.cc @@ -48,7 +48,7 @@ main(int argc, char** argv) spot::ltl::environment& env(spot::ltl::default_environment::instance()); spot::tgba_parse_error_list pel; spot::tgba_explicit* a = spot::tgba_parse(argv[1], pel, dict, env); - if (spot::format_tgba_parse_errors(std::cerr, pel)) + if (spot::format_tgba_parse_errors(std::cerr, argv[1], pel)) return 2; diff --git a/src/tgbatest/readsave.cc b/src/tgbatest/readsave.cc index 9904380c7..aa8562faf 100644 --- a/src/tgbatest/readsave.cc +++ b/src/tgbatest/readsave.cc @@ -60,7 +60,7 @@ main(int argc, char** argv) pel, dict, env, debug); exit_code = - spot::format_tgba_parse_errors(std::cerr, pel); + spot::format_tgba_parse_errors(std::cerr, argv[filename_index], pel); if (a) { diff --git a/src/tgbatest/reductgba.cc b/src/tgbatest/reductgba.cc index 2a1b6be74..fc463e1ec 100644 --- a/src/tgbatest/reductgba.cc +++ b/src/tgbatest/reductgba.cc @@ -106,7 +106,7 @@ main(int argc, char** argv) #ifdef REDUCCMP spot::tgba_parse_error_list pel; automata = spot::tgba_parse(argv[2], pel, dict, env, false); - if (spot::format_tgba_parse_errors(std::cerr, pel)) + if (spot::format_tgba_parse_errors(std::cerr, argv[2], pel)) return 2; #else spot::ltl::parse_error_list p1; diff --git a/src/tgbatest/tgbaread.cc b/src/tgbatest/tgbaread.cc index d18bfab11..0fddc0816 100644 --- a/src/tgbatest/tgbaread.cc +++ b/src/tgbatest/tgbaread.cc @@ -57,7 +57,7 @@ main(int argc, char** argv) spot::tgba_explicit* a = spot::tgba_parse(argv[filename_index], pel, dict, env, debug); - if (spot::format_tgba_parse_errors(std::cerr, pel)) + if (spot::format_tgba_parse_errors(std::cerr, argv[filename_index], pel)) return 2; if (a) diff --git a/src/tgbatest/tripprod.cc b/src/tgbatest/tripprod.cc index a36ec0bf4..3911da452 100644 --- a/src/tgbatest/tripprod.cc +++ b/src/tgbatest/tripprod.cc @@ -47,15 +47,15 @@ main(int argc, char** argv) spot::ltl::environment& env(spot::ltl::default_environment::instance()); spot::tgba_parse_error_list pel1; spot::tgba_explicit* a1 = spot::tgba_parse(argv[1], pel1, dict, env); - if (spot::format_tgba_parse_errors(std::cerr, pel1)) + if (spot::format_tgba_parse_errors(std::cerr, argv[1], pel1)) return 2; spot::tgba_parse_error_list pel2; spot::tgba_explicit* a2 = spot::tgba_parse(argv[2], pel2, dict, env); - if (spot::format_tgba_parse_errors(std::cerr, pel2)) + if (spot::format_tgba_parse_errors(std::cerr, argv[2], pel2)) return 2; spot::tgba_parse_error_list pel3; spot::tgba_explicit* a3 = spot::tgba_parse(argv[3], pel3, dict, env); - if (spot::format_tgba_parse_errors(std::cerr, pel3)) + if (spot::format_tgba_parse_errors(std::cerr, argv[3], pel3)) return 2; {