]> git.saurik.com Git - cycript.git/commitdiff
Avoid dependency hell by overriding location type.
authorJay Freeman (saurik) <saurik@saurik.com>
Mon, 2 Nov 2015 13:15:18 +0000 (05:15 -0800)
committerJay Freeman (saurik) <saurik@saurik.com>
Mon, 2 Nov 2015 13:15:18 +0000 (05:15 -0800)
.gitignore
Console.cpp
Cycript.l.in
Cycript.yy.in
Driver.cpp
Driver.hpp
Highlight.cpp
Location.hpp [new file with mode: 0644]
Makefile.am
Makefile.in

index 142ae537e45fcc647798751bb08b0dae49ce1ac9..b144ebe25cdd01d499131521b6472f9b946a8688 100644 (file)
@@ -20,8 +20,6 @@ Cycript.l
 Cycript.tab.*
 Cycript.output
 Bridge.gperf
-location.hh
-position.hh
 stack.hh
 sysroot.ios
 sysroot.sim
index eeda0f9b36c2f6fca6a131ccc78a22a027124210..9ad12ee56737c105dcea2ca0e369dab1f5d66849 100644 (file)
@@ -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 << "  | ";
index ab5d0b3882dbf02e8a208de2ad63a197005b554b..d52a19b5c6864b29e180c822f653e88b64fb4078 100644 (file)
@@ -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 { \
index 17be07868572549f1cfb027c07d5d6fe66d2e1d4..9cf3b8ef358900e6a8538fcbcede1ce5beb95f31 100644 (file)
@@ -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
 
index 6501fbf14144142da38850134923f3fdbe738b09..46317c51b210b5289a64a66fee63e9b06f728194 100644 (file)
@@ -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;
 
index 769ba26d24d1483b7de0ee6d6e15626b4baac0ac..1297e14b8ba93ca183ca4e8cdb909ed655dfab97 100644 (file)
@@ -28,8 +28,7 @@
 #include <string>
 #include <vector>
 
-#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*/
index c05631566522ad17f7550ce0cadcdf39a59a48d5..ef3632fc9df3b9dc2336844c48cbecc66e74abd7 100644 (file)
@@ -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 &current, cy::position target) {
+static void Skip(const char *data, size_t size, std::ostream &output, size_t &offset, CYPosition &current, 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 (file)
index 0000000..2d52569
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+**/
+/* }}} */
+
+#ifndef CYCRIPT_LOCATION_HPP
+#define CYCRIPT_LOCATION_HPP
+
+#include <iostream>
+
+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*/
index 4c76c6d7c203dcf31a4681aa1bdb9c1e8afe8c96..aa8c70983919936eeb7daaf42fa2ccce4bd6d0ea 100644 (file)
@@ -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]*$$'
index d2c82b81354b7bdd110917d201e47c520507d322..5ba46b57ecf46410d92c438175f02447cfba511c 100644 (file)
@@ -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]*$$'