From 58afc6aaca119c6b7b9ac5d91e3c6ee28dbd6fda Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Mon, 2 Nov 2015 05:15:18 -0800 Subject: [PATCH] Avoid dependency hell by overriding location type. --- .gitignore | 2 -- Console.cpp | 4 +-- Cycript.l.in | 4 +-- Cycript.yy.in | 4 ++- Driver.cpp | 2 +- Driver.hpp | 7 ++--- Highlight.cpp | 6 ++-- Location.hpp | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++ Makefile.am | 4 +-- Makefile.in | 5 ++-- 10 files changed, 99 insertions(+), 20 deletions(-) create mode 100644 Location.hpp diff --git a/.gitignore b/.gitignore index 142ae53..b144ebe 100644 --- a/.gitignore +++ b/.gitignore @@ -20,8 +20,6 @@ Cycript.l Cycript.tab.* Cycript.output Bridge.gperf -location.hh -position.hh stack.hh sysroot.ios sysroot.sim diff --git a/Console.cpp b/Console.cpp index eeda0f9..9ad12ee 100644 --- a/Console.cpp +++ b/Console.cpp @@ -553,9 +553,9 @@ static void Console(CYOptions &options) { if (parser.parse() != 0 || !driver.errors_.empty()) { for (CYDriver::Errors::const_iterator error(driver.errors_.begin()); error != driver.errors_.end(); ++error) { - cy::position begin(error->location_.begin); + CYPosition begin(error->location_.begin); if (begin.line != lines.size() || begin.column < lines.back().size() || error->warning_) { - cy::position end(error->location_.end); + CYPosition end(error->location_.end); if (begin.line != lines.size()) { std::cerr << " | "; diff --git a/Cycript.l.in b/Cycript.l.in index ab5d0b3..d52a19b 100644 --- a/Cycript.l.in +++ b/Cycript.l.in @@ -29,7 +29,7 @@ #pragma clang diagnostic ignored "-Wdeprecated-register" #endif -#define YYLTYPE cy::location +#define YYLTYPE CYLocation #include "Cycript.tab.hh" typedef cy::parser::token tk; @@ -89,7 +89,7 @@ typedef cy::parser::token tk; #define L { \ yylloc->step(); \ - yylloc->columns(yyleng); \ + yylloc->end.columns(yyleng); \ } #define M { \ diff --git a/Cycript.yy.in b/Cycript.yy.in index 17be078..9cf3b8e 100644 --- a/Cycript.yy.in +++ b/Cycript.yy.in @@ -110,7 +110,7 @@ typedef struct { } %code provides { -int cylex(YYSTYPE *, cy::location *, void *); +int cylex(YYSTYPE *, CYLocation *, void *); } %name-prefix "cy" @@ -124,6 +124,8 @@ int cylex(YYSTYPE *, cy::location *, void *); %locations %defines +%define api.location.type { CYLocation } + //%glr-parser //%expect 1 diff --git a/Driver.cpp b/Driver.cpp index 6501fbf..46317c5 100644 --- a/Driver.cpp +++ b/Driver.cpp @@ -42,7 +42,7 @@ CYDriver::~CYDriver() { ScannerDestroy(); } -void CYDriver::Warning(const cy::location &location, const char *message) { +void CYDriver::Warning(const cy::parser::location_type &location, const char *message) { if (!strict_) return; diff --git a/Driver.hpp b/Driver.hpp index 769ba26..1297e14 100644 --- a/Driver.hpp +++ b/Driver.hpp @@ -28,8 +28,7 @@ #include #include -#include "location.hh" - +#include "Location.hpp" #include "Parser.hpp" enum CYState { @@ -66,7 +65,7 @@ class CYDriver { struct Error { bool warning_; - cy::location location_; + CYLocation location_; std::string message_; }; @@ -116,7 +115,7 @@ class CYDriver { void PushCondition(Condition condition); void PopCondition(); - void Warning(const cy::location &location, const char *message); + void Warning(const CYLocation &location, const char *message); }; #endif/*CYCRIPT_DRIVER_HPP*/ diff --git a/Highlight.cpp b/Highlight.cpp index c056315..ef3632f 100644 --- a/Highlight.cpp +++ b/Highlight.cpp @@ -26,7 +26,7 @@ #include "Driver.hpp" #include "Code.hpp" -static void Skip(const char *data, size_t size, std::ostream &output, size_t &offset, cy::position ¤t, cy::position target) { +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) { _assert(offset != size); char next(data[offset++]); @@ -61,12 +61,12 @@ void CYLexerHighlight(const char *data, size_t size, std::ostream &output, bool driver.commented_ = true; size_t offset(0); - cy::position current; + CYPosition current; CYLocalPool pool; YYSTYPE value; - cy::location location; + CYLocation location; while (cylex(&value, &location, driver.scanner_) != 0) { CYColor color; diff --git a/Location.hpp b/Location.hpp new file mode 100644 index 0000000..2d52569 --- /dev/null +++ b/Location.hpp @@ -0,0 +1,81 @@ +/* Cycript - Optimizing JavaScript Compiler/Runtime + * Copyright (C) 2009-2014 Jay Freeman (saurik) +*/ + +/* GNU Affero General Public License, Version 3 {{{ */ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . +**/ +/* }}} */ + +#ifndef CYCRIPT_LOCATION_HPP +#define CYCRIPT_LOCATION_HPP + +#include + +class CYPosition { + public: + std::string *filename; + unsigned int line; + unsigned int column; + + CYPosition() : + filename(NULL), + line(1), + column(0) + { + } + + void lines(unsigned count = 1) { + column = 0; + line += count; + } + + void columns(unsigned count = 1) { + column += count; + } +}; + +inline std::ostream &operator <<(std::ostream &out, const CYPosition &position) { + if (position.filename != NULL) + out << *position.filename << ":"; + out << position.line << "." << position.column; + return out; +} + +class CYLocation { + public: + CYPosition begin; + CYPosition end; + + void step() { + begin = end; + } +}; + +inline std::ostream &operator <<(std::ostream &out, const CYLocation &location) { + const CYPosition &begin(location.begin); + const CYPosition &end(location.end); + + out << begin; + if (end.filename != NULL && (begin.filename == NULL || *begin.filename != *end.filename)) + out << '-' << *end.filename << ':' << end.line << '.' << end.column; + else if (begin.line != end.line) + out << '-' << end.line << '.' << end.column; + else if (begin.column != end.column) + out << '-' << end.column; + return out; +} + +#endif/*CYCRIPT_LOCATION_HPP*/ diff --git a/Makefile.am b/Makefile.am index 4c76c6d..aa8c709 100644 --- a/Makefile.am +++ b/Makefile.am @@ -104,8 +104,8 @@ lex.cy.cpp: Cycript.l Console.$(OBJEXT) Cycript.tab.lo Driver.lo Handler.lo Highlight.lo Library.lo lex.cy.lo: Cycript.tab.hh -CLEANFILES += Cycript.tab.cc Cycript.tab.hh location.hh position.hh stack.hh Cycript.output -Cycript.tab.cc Cycript.tab.hh location.hh position.hh stack.hh Cycript.output: Cycript.yy +CLEANFILES += Cycript.tab.cc Cycript.tab.hh stack.hh Cycript.output +Cycript.tab.cc Cycript.tab.hh stack.hh Cycript.output: Cycript.yy $(BISON) -v --report=state $< ! grep -n '^State [0-9]* conflicts:' Cycript.output ! grep -n '^ *$$default reduce using rule [0-9]* (Lex[A-Z][^)]*)$$' Cycript.output -B 2 | grep 'shift, and go to state [0-9]*$$' diff --git a/Makefile.in b/Makefile.in index d2c82b8..5ba46b5 100644 --- a/Makefile.in +++ b/Makefile.in @@ -528,8 +528,7 @@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ AUTOMAKE_OPTIONS = subdir-objects CLEANFILES = $(am__append_5) Cycript.yy Cycript.l lex.cy.cpp \ - Cycript.tab.cc Cycript.tab.hh location.hh position.hh stack.hh \ - Cycript.output + Cycript.tab.cc Cycript.tab.hh stack.hh Cycript.output SUBDIRS = ACLOCAL_AMFLAGS = -I m4 AM_CPPFLAGS = -I$(srcdir)/include -DYYDEBUG=1 -include config.h \ @@ -1332,7 +1331,7 @@ lex.cy.cpp: Cycript.l $(FLEX) -t $< | $(SED) -e 's/int yyl;/yy_size_t yyl;/;s/int yyleng_r;/yy_size_t yyleng_r;/' >$@ Console.$(OBJEXT) Cycript.tab.lo Driver.lo Handler.lo Highlight.lo Library.lo lex.cy.lo: Cycript.tab.hh -Cycript.tab.cc Cycript.tab.hh location.hh position.hh stack.hh Cycript.output: Cycript.yy +Cycript.tab.cc Cycript.tab.hh stack.hh Cycript.output: Cycript.yy $(BISON) -v --report=state $< ! grep -n '^State [0-9]* conflicts:' Cycript.output ! grep -n '^ *$$default reduce using rule [0-9]* (Lex[A-Z][^)]*)$$' Cycript.output -B 2 | grep 'shift, and go to state [0-9]*$$' -- 2.45.2