From 5587a93f98c158ab5e71c1f1c6b318690271d335 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Sun, 26 Jan 2014 13:53:26 -0800 Subject: [PATCH] CYPoolCode should simply take an std::istream &. --- Code.hpp | 52 +++++++++++++++++++++++++++++++++++++++++++ Execute.cpp | 5 ++--- Highlight.cpp | 1 + Library.cpp | 3 +-- ObjectiveC/Library.mm | 4 +++- Parser.hpp | 21 ----------------- cycript.hpp | 3 --- 7 files changed, 59 insertions(+), 30 deletions(-) create mode 100644 Code.hpp diff --git a/Code.hpp b/Code.hpp new file mode 100644 index 0000000..324c00f --- /dev/null +++ b/Code.hpp @@ -0,0 +1,52 @@ +/* Cycript - Optimizing JavaScript Compiler/Runtime + * Copyright (C) 2009-2013 Jay Freeman (saurik) +*/ + +/* GNU General Public License, Version 3 {{{ */ +/* + * Cycript is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * Cycript 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Cycript. If not, see . +**/ +/* }}} */ + +#ifndef CODE_HPP +#define CODE_HPP + +#include + +#include "String.hpp" + +class CYStream : + public std::istream +{ + private: + class CYBuffer : + public std::streambuf + { + public: + CYBuffer(const char *start, const char *end) { + setg(const_cast(start), const_cast(start), const_cast(end)); + } + } buffer_; + + public: + CYStream(const char *start, const char *end) : + std::istream(&buffer_), + buffer_(start, end) + { + } +}; + +CYUTF8String CYPoolCode(CYPool &pool, std::istream &stream); + +#endif//CODE_HPP diff --git a/Execute.cpp b/Execute.cpp index 1644bb1..82ef815 100644 --- a/Execute.cpp +++ b/Execute.cpp @@ -44,8 +44,7 @@ #include #include -#include "Parser.hpp" - +#include "Code.hpp" #include "Decode.hpp" #include "Error.hpp" #include "JavaScript.hpp" @@ -1736,7 +1735,7 @@ static JSValueRef require(JSContextRef context, JSObjectRef object, JSObjectRef std::stringstream wrap; wrap << "(function (exports, require, module) { " << code << "\n});"; - code = CYPoolCode(pool, wrap.str().c_str()); + code = CYPoolCode(pool, wrap); JSValueRef value(_jsccall(JSEvaluateScript, context, CYJSString(code), NULL, NULL, 0)); JSObjectRef function(CYCastJSObject(context, value)); diff --git a/Highlight.cpp b/Highlight.cpp index 4cfc8db..7cb96ee 100644 --- a/Highlight.cpp +++ b/Highlight.cpp @@ -24,6 +24,7 @@ #include "Cycript.tab.hh" #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) { while (current.line != target.line || current.column != target.column) { diff --git a/Library.cpp b/Library.cpp index 74df502..816dab6 100644 --- a/Library.cpp +++ b/Library.cpp @@ -191,9 +191,8 @@ double CYCastDouble(const char *value) { return CYCastDouble(value, strlen(value)); } -CYUTF8String CYPoolCode(CYPool &pool, CYUTF8String code) { +CYUTF8String CYPoolCode(CYPool &pool, std::istream &stream) { CYLocalPool local; - CYStream stream(code.data, code.data + code.size); CYDriver driver(stream); cy::parser parser(driver); diff --git a/ObjectiveC/Library.mm b/ObjectiveC/Library.mm index c4759a5..fe8933c 100644 --- a/ObjectiveC/Library.mm +++ b/ObjectiveC/Library.mm @@ -40,6 +40,7 @@ #include #endif +#include "Code.hpp" #include "Error.hpp" #include "JavaScript.hpp" #include "String.hpp" @@ -3116,7 +3117,8 @@ extern "C" void CydgetMemoryParse(const uint16_t **data, size_t *size) { try { CYPool pool; CYUTF8String utf8(CYPoolUTF8String(pool, CYUTF16String(*data, *size))); - utf8 = CYPoolCode(pool, utf8); + CYStream stream(utf8.data, utf8.data + utf8.size); + utf8 = CYPoolCode(pool, stream); CYUTF16String utf16(CYPoolUTF16String(pool, CYUTF8String(utf8.data, utf8.size))); size_t bytes(utf16.size * sizeof(uint16_t)); diff --git a/Parser.hpp b/Parser.hpp index e804e4a..fab18af 100644 --- a/Parser.hpp +++ b/Parser.hpp @@ -460,27 +460,6 @@ struct CYBlock : virtual void Output(CYOutput &out, CYFlags flags) const; }; -class CYStream : - public std::istream -{ - private: - class CYBuffer : - public std::streambuf - { - public: - CYBuffer(const char *start, const char *end) { - setg(const_cast(start), const_cast(start), const_cast(end)); - } - } buffer_; - - public: - CYStream(const char *start, const char *end) : - std::istream(&buffer_), - buffer_(start, end) - { - } -}; - struct CYForInitialiser { virtual ~CYForInitialiser() { } diff --git a/cycript.hpp b/cycript.hpp index e65721a..d0fcaf6 100644 --- a/cycript.hpp +++ b/cycript.hpp @@ -26,7 +26,6 @@ #include #include "Pooling.hpp" -#include "String.hpp" bool CYRecvAll_(int socket, uint8_t *data, size_t size); bool CYSendAll_(int socket, const uint8_t *data, size_t size); @@ -51,6 +50,4 @@ bool CYSendAll(int socket, const Type_ *data, size_t size) { CYPool &CYGetGlobalPool(); -CYUTF8String CYPoolCode(CYPool &pool, CYUTF8String code); - #endif/*CYCRIPT_HPP*/ -- 2.47.2