From 8b98a6b3fae40487ac529a7118865df6a71159ee Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sat, 22 Jul 2017 17:43:09 +0200 Subject: Implement detection of ignorable changes (whitespaces, comments) --- build2/cc/lexer.hxx | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'build2/cc/lexer.hxx') diff --git a/build2/cc/lexer.hxx b/build2/cc/lexer.hxx index 65e9012..1869344 100644 --- a/build2/cc/lexer.hxx +++ b/build2/cc/lexer.hxx @@ -5,6 +5,7 @@ #ifndef BUILD2_CC_LEXER_HXX #define BUILD2_CC_LEXER_HXX +#include #include #include @@ -27,6 +28,10 @@ namespace build2 // saved from literals. The #line directive (and its shorthand notation) // is recognized to provide the logical token location. // + // While at it we also calculate the checksum of the input ignoring + // comments, whitespaces, etc. This is used to detect changes that do not + // alter the resulting token stream. + // enum class token_type { // NOTE: remember to update operator<<() if changing anything here! @@ -82,6 +87,9 @@ namespace build2 const path& name () const {return name_;} + string + checksum () const {return cs_.string ();} + // Note that it is ok to call next() again after getting eos. // token @@ -137,13 +145,21 @@ namespace build2 using base = char_scanner; xchar + peek (bool escape = true); + + xchar get (bool escape = true); void get (const xchar& peeked); + // Hashing versions. + // xchar - peek (bool escape = true); + geth (bool escape = true); + + void + geth (const xchar& peeked); private: const path name_; @@ -154,6 +170,8 @@ namespace build2 // path log_file_; optional log_line_; + + sha256 cs_; }; // Diagnostics plumbing. -- cgit v1.1