From: helly Date: Thu, 13 Mar 2008 17:43:07 +0000 (+0000) Subject: - Fix compiler warnings X-Git-Tag: 0.13.6~69 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1edc6c5f0db7ea5fe7d887b7eb47f6b6226b5880;p=re2c - Fix compiler warnings - Improve error message generation (allows to fix reported line numbers) --- diff --git a/re2c/scanner.h b/re2c/scanner.h index a90d403a..f03604f1 100644 --- a/re2c/scanner.h +++ b/re2c/scanner.h @@ -19,6 +19,7 @@ private: std::ostream& out; char *bot, *tok, *ptr, *cur, *pos, *lim, *top, *eof, *ctx; uint tchar, tline, cline, iscfg, buf_size; + bool in_parse; private: char *fill(char*, uint); @@ -29,15 +30,19 @@ public: Scanner(std::istream&, std::ostream&); ~Scanner(); - enum EchoState { + enum ParseMode { Stop, Parse, - Reuse, + Reuse }; - EchoState echo(); + ParseMode echo(); int scan(); - + + uint get_cline() const; + void set_in_parse(bool new_in_parse); + void fatal_at(uint line, uint ofs, const char *msg) const; + void fatalf_at(uint line, const char*, ...) const; void fatalf(const char*, ...) const; void fatal(const char*) const; void fatal(uint, const char*) const; @@ -65,6 +70,11 @@ public: RegExp * mkDot() const; }; +inline uint Scanner::get_cline() const +{ + return cline; +} + inline void Scanner::fatal(const char *msg) const { fatal(0, msg); diff --git a/re2c/scanner.re b/re2c/scanner.re index 24ae1a73..29fc9b03 100644 --- a/re2c/scanner.re +++ b/re2c/scanner.re @@ -34,6 +34,7 @@ Scanner::Scanner(std::istream& i, std::ostream& o) , out(o) , bot(NULL), tok(NULL), ptr(NULL), cur(NULL), pos(NULL), lim(NULL) , top(NULL), eof(NULL), ctx(NULL), tchar(0), tline(0), cline(1), iscfg(0) + , in_parse(false) { ; } @@ -53,7 +54,7 @@ char *Scanner::fill(char *cursor, uint need) lim -= cnt; } need = MAX(need, BSIZE); - if((top - lim) < need) + if(static_cast(top - lim) < need) { char *buf = new char[(lim - bot) + need]; if (!buf) @@ -102,7 +103,7 @@ config = "re2c" cname+ ("@" name)?; value = [^\r\n; \t]* | dstring | sstring; */ -Scanner::EchoState Scanner::echo() +Scanner::ParseMode Scanner::echo() { char *cursor = cur; bool ignore_eoc = false; @@ -112,7 +113,7 @@ Scanner::EchoState Scanner::echo() { return Stop; } - + tok = cursor; echo: /*!re2c @@ -260,7 +261,6 @@ echo: */ } - int Scanner::scan() { char *cursor = cur; @@ -624,15 +624,40 @@ value: */ } -void Scanner::fatal(uint ofs, const char *msg) const +void Scanner::set_in_parse(bool new_in_parse) +{ + in_parse = new_in_parse; +} + +void Scanner::fatal_at(uint line, uint ofs, const char *msg) const { out.flush(); std::cerr << "re2c: error: " - << "line " << tline << ", column " << (tchar + ofs + 1) << ": " + << "line " << line << ", column " << (tchar + ofs + 1) << ": " << msg << std::endl; exit(1); } +void Scanner::fatal(uint ofs, const char *msg) const +{ + fatal_at(in_parse ? tline : cline, ofs, msg); +} + +void Scanner::fatalf_at(uint line, const char* fmt, ...) const +{ + char szBuf[4096]; + + va_list args; + + va_start(args, fmt); + vsnprintf(szBuf, sizeof(szBuf), fmt, args); + va_end(args); + + szBuf[sizeof(szBuf)-1] = '0'; + + fatal_at(line, 0, szBuf); +} + void Scanner::fatalf(const char *fmt, ...) const { char szBuf[4096];