| OLD | NEW |
| 1 // Portions of this code based on re2c: | |
| 2 // (re2c/examples/push.re) | |
| 3 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 4 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 5 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 6 // met: | 4 // met: |
| 7 // | 5 // |
| 8 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 9 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 10 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 11 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 12 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| 13 // with the distribution. | 11 // with the distribution. |
| 14 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
| 15 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
| 16 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
| 17 // | 15 // |
| 18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | 27 |
| 30 #ifndef V8_LEXER_LEXER_H | 28 #ifndef V8_LEXER_EXPERIMENTAL_SCANNER_H |
| 31 #define V8_LEXER_LEXER_H | 29 #define V8_LEXER_EXPERIMENTAL_SCANNER_H |
| 32 | 30 |
| 33 #include <vector> | 31 #include <vector> |
| 34 | 32 |
| 33 #include "flags.h" |
| 35 #include "token.h" | 34 #include "token.h" |
| 36 #include "flags.h" | |
| 37 | 35 |
| 38 class ExperimentalScanner; | 36 namespace v8 { |
| 37 namespace internal { |
| 39 | 38 |
| 40 class PushScanner { | 39 class PushScanner; |
| 41 public: | |
| 42 explicit PushScanner(ExperimentalScanner* sink); | |
| 43 | |
| 44 ~PushScanner(); | |
| 45 | |
| 46 void send(v8::internal::Token::Value token); | |
| 47 uint32_t push(const void *input, int input_size); | |
| 48 | |
| 49 private: | |
| 50 bool eof_; | |
| 51 int32_t state_; | |
| 52 int32_t condition_; | |
| 53 | |
| 54 uint8_t* limit_; | |
| 55 uint8_t* start_; | |
| 56 uint8_t* cursor_; | |
| 57 uint8_t* marker_; | |
| 58 int real_start_; | |
| 59 | |
| 60 uint8_t* buffer_; | |
| 61 uint8_t* buffer_end_; | |
| 62 | |
| 63 uint8_t yych; | |
| 64 uint32_t yyaccept; | |
| 65 | |
| 66 ExperimentalScanner* sink_; | |
| 67 }; | |
| 68 | 40 |
| 69 class ExperimentalScanner { | 41 class ExperimentalScanner { |
| 70 public: | 42 public: |
| 43 struct Location { |
| 44 Location(int b, int e) : beg_pos(b), end_pos(e) { } |
| 45 Location() : beg_pos(0), end_pos(0) { } |
| 46 |
| 47 bool IsValid() const { |
| 48 return beg_pos >= 0 && end_pos >= beg_pos; |
| 49 } |
| 50 |
| 51 static Location invalid() { return Location(-1, -1); } |
| 52 |
| 53 int beg_pos; |
| 54 int end_pos; |
| 55 }; |
| 56 |
| 71 ExperimentalScanner(const char* fname, bool read_all_at_once); | 57 ExperimentalScanner(const char* fname, bool read_all_at_once); |
| 72 ~ExperimentalScanner(); | 58 ~ExperimentalScanner(); |
| 73 v8::internal::Token::Value Next(int* beg_pos, int* end_pos); | 59 |
| 60 Token::Value Next(); |
| 61 Token::Value current_token(); |
| 62 Location location(); |
| 63 |
| 74 void Record(v8::internal::Token::Value token, int beg_pos, int end_pos); | 64 void Record(v8::internal::Token::Value token, int beg_pos, int end_pos); |
| 75 | 65 |
| 76 private: | 66 private: |
| 77 void FillTokens(); | 67 void FillTokens(); |
| 78 static const int BUFFER_SIZE = 256; | 68 static const int BUFFER_SIZE = 256; |
| 79 std::vector<v8::internal::Token::Value> token_; | 69 std::vector<v8::internal::Token::Value> token_; |
| 80 std::vector<int> beg_; | 70 std::vector<int> beg_; |
| 81 std::vector<int> end_; | 71 std::vector<int> end_; |
| 82 size_t current_; | 72 size_t current_; |
| 83 size_t fetched_; | 73 size_t fetched_; |
| 84 FILE* file_; | 74 FILE* file_; |
| 85 PushScanner* scanner_; | 75 PushScanner* scanner_; |
| 86 bool read_all_at_once_; | 76 bool read_all_at_once_; |
| 87 const v8::internal::byte* source_; | 77 const v8::internal::byte* source_; |
| 88 int length_; | 78 int length_; |
| 89 }; | 79 }; |
| 90 | 80 |
| 91 #endif // V8_LEXER_LEXER_H | 81 } } // namespace v8::internal |
| 82 |
| 83 #endif |
| OLD | NEW |