From: Jay Freeman (saurik) Date: Wed, 2 Dec 2015 03:09:29 +0000 (-0800) Subject: Limit recompilation of files upon changed grammar. X-Git-Tag: v0.9.590~252 X-Git-Url: https://git.saurik.com/cycript.git/commitdiff_plain/8a392978b2d6e7db62cdf6d576e071d70fef9b94 Limit recompilation of files upon changed grammar. --- diff --git a/Complete.cpp b/Complete.cpp index 3d14193..c81f90e 100644 --- a/Complete.cpp +++ b/Complete.cpp @@ -22,7 +22,6 @@ #include "cycript.hpp" #include "Driver.hpp" -#include "Cycript.tab.hh" #include "Replace.hpp" #include "String.hpp" @@ -30,9 +29,7 @@ static CYExpression *ParseExpression(CYPool &pool, CYUTF8String code) { std::stringstream stream; stream << '(' << code << ')'; CYDriver driver(pool, stream); - - cy::parser parser(driver); - if (parser.parse() != 0 || !driver.errors_.empty()) + if (driver.Parse() || !driver.errors_.empty()) return NULL; CYOptions options; @@ -59,8 +56,7 @@ _visible char **CYComplete(const char *word, const std::string &line, CYUTF8Stri driver.auto_ = true; - cy::parser parser(driver); - if (parser.parse() != 0 || !driver.errors_.empty()) + if (driver.Parse() || !driver.errors_.empty()) return NULL; if (driver.mode_ == CYDriver::AutoNone) diff --git a/Console.cpp b/Console.cpp index a191fc0..57f4375 100644 --- a/Console.cpp +++ b/Console.cpp @@ -69,7 +69,7 @@ #include "Display.hpp" #include "Driver.hpp" #include "Highlight.hpp" -#include "Replace.hpp" +#include "Parser.hpp" static volatile enum { Working, diff --git a/Cycript.l.in b/Cycript.l.in index 03f82ce..55502d4 100644 --- a/Cycript.l.in +++ b/Cycript.l.in @@ -677,6 +677,14 @@ void CYDriver::PopCondition() { yy_pop_state(scanner_); } +bool CYLexerHighlight(hi::Value &highlight, CYLocation &location, void *scanner) { + YYSTYPE value; + if (cylex(&value, &location, scanner) == 0) + return false; + highlight = value.highlight_; + return true; +} + #if defined(__clang__) #pragma clang diagnostic pop #else diff --git a/Cycript.yy.in b/Cycript.yy.in index d8aee24..295fa81 100644 --- a/Cycript.yy.in +++ b/Cycript.yy.in @@ -297,7 +297,7 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %token _case_ "case" %token _catch_ "catch" %token _class_ "class" -%token _class__ "!class" +%token _class__ ";class" %token _const_ "const" %token _continue_ "continue" %token _debugger_ "debugger" @@ -692,7 +692,7 @@ Word | "case" { $$ = CYNew CYWord("case"); } | "catch" { $$ = CYNew CYWord("catch"); } | "class" { $$ = CYNew CYWord("class"); } - | "!class" { $$ = CYNew CYWord("class"); } + | ";class" { $$ = CYNew CYWord("class"); } | "const" { $$ = CYNew CYWord("const"); } | "continue" { $$ = CYNew CYWord("continue"); } | "debugger" { $$ = CYNew CYWord("debugger"); } @@ -962,7 +962,7 @@ TemplateSpans ; /* }}} */ -/* 12.3+ Left-Hand-Side Expressions {{{ */ +/* 12.3 Left-Hand-Side Expressions {{{ */ MemberAccess : "[" LexPushInOff Expression "]" LexPopIn { $$ = CYNew CYDirectMember(NULL, $3); } | "." IdentifierName { $$ = CYNew CYDirectMember(NULL, CYNew CYString($2)); } @@ -2334,3 +2334,32 @@ PostfixExpression /* }}} */ %% + +bool CYDriver::Parse(CYMark mark) { + mark_ = mark; + CYLocal local(&pool_); + cy::parser parser(*this); +#ifdef YYDEBUG + parser.set_debug_level(debug_); +#endif + return parser.parse() != 0; +} + +void CYDriver::Warning(const cy::parser::location_type &location, const char *message) { + if (!strict_) + return; + + CYDriver::Error error; + error.warning_ = true; + error.location_ = location; + error.message_ = message; + errors_.push_back(error); +} + +void cy::parser::error(const cy::parser::location_type &location, const std::string &message) { + CYDriver::Error error; + error.warning_ = false; + error.location_ = location; + error.message_ = message; + driver.errors_.push_back(error); +} diff --git a/Driver.cpp b/Driver.cpp index eab0bb9..4bac2c2 100644 --- a/Driver.cpp +++ b/Driver.cpp @@ -19,8 +19,10 @@ **/ /* }}} */ -#include "Cycript.tab.hh" #include "Driver.hpp" +#include "Parser.hpp" + +bool CYParser(CYPool &pool, bool debug); CYDriver::CYDriver(CYPool &pool, std::istream &data, const std::string &filename) : pool_(pool), @@ -49,37 +51,8 @@ CYDriver::~CYDriver() { ScannerDestroy(); } -bool CYDriver::Parse(CYMark mark) { - mark_ = mark; - CYLocal local(&pool_); - cy::parser parser(*this); -#ifdef YYDEBUG - parser.set_debug_level(debug_); -#endif - return parser.parse() != 0; -} - void CYDriver::Replace(CYOptions &options) { CYLocal local(&pool_); CYContext context(options); script_->Replace(context); } - -void CYDriver::Warning(const cy::parser::location_type &location, const char *message) { - if (!strict_) - return; - - CYDriver::Error error; - error.warning_ = true; - error.location_ = location; - error.message_ = message; - errors_.push_back(error); -} - -void cy::parser::error(const cy::parser::location_type &location, const std::string &message) { - CYDriver::Error error; - error.warning_ = false; - error.location_ = location; - error.message_ = message; - driver.errors_.push_back(error); -} diff --git a/Driver.hpp b/Driver.hpp index 0df39d7..fbc96d9 100644 --- a/Driver.hpp +++ b/Driver.hpp @@ -29,7 +29,13 @@ #include #include "Location.hpp" -#include "Parser.hpp" +#include "Options.hpp" +#include "Pooling.hpp" +#include "Standard.hpp" + +struct CYExpression; +struct CYScript; +struct CYWord; enum CYMark { CYMarkIgnore, diff --git a/Handler.cpp b/Handler.cpp index d048d83..2a17d61 100644 --- a/Handler.cpp +++ b/Handler.cpp @@ -36,13 +36,11 @@ #include "cycript.hpp" +#include "Driver.hpp" #include "JavaScript.hpp" #include "Parser.hpp" #include "Pooling.hpp" -#include "Cycript.tab.hh" -#include "Driver.hpp" - struct CYExecute_ { CYPool &pool_; const char * volatile data_; diff --git a/Highlight.cpp b/Highlight.cpp index 9c95728..addd757 100644 --- a/Highlight.cpp +++ b/Highlight.cpp @@ -19,12 +19,11 @@ **/ /* }}} */ +#include "Code.hpp" +#include "Driver.hpp" #include "Highlight.hpp" -#include "Parser.hpp" -#include "Cycript.tab.hh" -#include "Driver.hpp" -#include "Code.hpp" +bool CYLexerHighlight(hi::Value &highlight, CYLocation &location, void *scanner); static void Skip(const char *data, size_t size, std::ostream &output, size_t &offset, CYPosition ¤t, CYPosition target) { while (current.line != target.line || current.column != target.column) { @@ -65,13 +64,13 @@ _visible void CYLexerHighlight(const char *data, size_t size, std::ostream &outp size_t offset(0); CYPosition current; - YYSTYPE value; + hi::Value highlight; CYLocation location; - while (cylex(&value, &location, driver.scanner_) != 0) { + while (CYLexerHighlight(highlight, location, driver.scanner_)) { CYColor color; - switch (value.highlight_) { + switch (highlight) { case hi::Comment: color = CYColor(true, 30); break; case hi::Constant: color = CYColor(false, 31); break; case hi::Control: color = CYColor(false, 33); break; diff --git a/Library.cpp b/Library.cpp index 9ed238d..e8e70d6 100644 --- a/Library.cpp +++ b/Library.cpp @@ -34,14 +34,12 @@ #include #include +#include "Driver.hpp" #include "Error.hpp" #include "Execute.hpp" #include "Parser.hpp" #include "String.hpp" -#include "Cycript.tab.hh" -#include "Driver.hpp" - #include "ConvertUTF.h" template <> @@ -220,9 +218,7 @@ double CYCastDouble(const char *value) { CYUTF8String CYPoolCode(CYPool &pool, std::istream &stream) { CYLocalPool local; CYDriver driver(local, stream); - - cy::parser parser(driver); - _assert(parser.parse() == 0); + _assert(!driver.Parse()); _assert(driver.errors_.empty()); CYOptions options; diff --git a/Makefile.am b/Makefile.am index 09f002c..d89c83f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -109,7 +109,7 @@ lex.cy.cpp: Cycript.l grep -F 'No backing up.' lex.backup >/dev/null ! grep -F ': warning, ' lex.output || true -Console.$(OBJEXT) Cycript.tab.lo Driver.lo Handler.lo Highlight.lo Library.lo lex.cy.lo: Cycript.tab.hh +lex.cy.lo: Cycript.tab.hh CLEANFILES += Cycript.tab.cc Cycript.tab.hh stack.hh Cycript.output Cycript.tab.cc Cycript.tab.hh stack.hh Cycript.output: Cycript.yy diff --git a/Makefile.in b/Makefile.in index 7383506..ba8d8f5 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1335,7 +1335,7 @@ lex.cy.cpp: Cycript.l grep -F 'No backing up.' lex.backup >/dev/null ! grep -F ': warning, ' lex.output || true -Console.$(OBJEXT) Cycript.tab.lo Driver.lo Handler.lo Highlight.lo Library.lo lex.cy.lo: Cycript.tab.hh +lex.cy.lo: Cycript.tab.hh Cycript.tab.cc Cycript.tab.hh stack.hh Cycript.output: Cycript.yy $(BISON) -v --report=state -Werror $< ! grep -n '^State [0-9]* conflicts:' Cycript.output