OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
11 // with the distribution. | 11 // with the distribution. |
12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
15 // | 15 // |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (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 |
26 // 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. |
27 | 27 |
28 // Features shared by parsing and pre-parsing scanners. | 28 // Features shared by parsing and pre-parsing scanners. |
29 | 29 |
30 #include "v8.h" | |
31 | |
32 /* | |
33 TODO(isolates): I incldue v8.h instead of these because we need Isolate and | |
34 some classes (NativeAllocationChecker) are moved into isolate.h | |
35 #include "../include/v8stdint.h" | 30 #include "../include/v8stdint.h" |
36 */ | |
37 #include "scanner-base.h" | 31 #include "scanner-base.h" |
38 #include "char-predicates-inl.h" | 32 #include "char-predicates-inl.h" |
39 | 33 |
40 namespace v8 { | 34 namespace v8 { |
41 namespace internal { | 35 namespace internal { |
42 | 36 |
43 // ---------------------------------------------------------------------------- | 37 // ---------------------------------------------------------------------------- |
44 // Compound predicates. | 38 // Compound predicates. |
45 | 39 |
46 bool ScannerConstants::IsIdentifier(unibrow::CharacterStream* buffer) { | 40 bool ScannerConstants::IsIdentifier(unibrow::CharacterStream* buffer) { |
47 // Checks whether the buffer contains an identifier (no escape). | 41 // Checks whether the buffer contains an identifier (no escape). |
48 if (!buffer->has_more()) return false; | 42 if (!buffer->has_more()) return false; |
49 if (!kIsIdentifierStart.get(buffer->GetNext())) { | 43 if (!kIsIdentifierStart.get(buffer->GetNext())) { |
50 return false; | 44 return false; |
51 } | 45 } |
52 while (buffer->has_more()) { | 46 while (buffer->has_more()) { |
53 if (!kIsIdentifierPart.get(buffer->GetNext())) { | 47 if (!kIsIdentifierPart.get(buffer->GetNext())) { |
54 return false; | 48 return false; |
55 } | 49 } |
56 } | 50 } |
57 return true; | 51 return true; |
58 } | 52 } |
59 | 53 |
60 // ---------------------------------------------------------------------------- | 54 // ---------------------------------------------------------------------------- |
61 // Scanner | 55 // Scanner |
62 | 56 |
63 Scanner::Scanner(Isolate* isolate) | 57 Scanner::Scanner(ScannerConstants* scanner_constants) |
64 : scanner_constants_(isolate->scanner_constants()), | 58 : scanner_constants_(scanner_constants), |
65 octal_pos_(kNoOctalLocation) { | 59 octal_pos_(kNoOctalLocation) { |
66 } | 60 } |
67 | 61 |
68 | 62 |
69 uc32 Scanner::ScanHexEscape(uc32 c, int length) { | 63 uc32 Scanner::ScanHexEscape(uc32 c, int length) { |
70 ASSERT(length <= 4); // prevent overflow | 64 ASSERT(length <= 4); // prevent overflow |
71 | 65 |
72 uc32 digits[4]; | 66 uc32 digits[4]; |
73 uc32 x = 0; | 67 uc32 x = 0; |
74 for (int i = 0; i < length; i++) { | 68 for (int i = 0; i < length; i++) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 if (c != '0' || i > 0) { | 107 if (c != '0' || i > 0) { |
114 octal_pos_ = source_pos() - i - 1; // Already advanced | 108 octal_pos_ = source_pos() - i - 1; // Already advanced |
115 } | 109 } |
116 return x; | 110 return x; |
117 } | 111 } |
118 | 112 |
119 | 113 |
120 // ---------------------------------------------------------------------------- | 114 // ---------------------------------------------------------------------------- |
121 // JavaScriptScanner | 115 // JavaScriptScanner |
122 | 116 |
123 JavaScriptScanner::JavaScriptScanner(Isolate* isolate) : Scanner(isolate) {} | 117 JavaScriptScanner::JavaScriptScanner(ScannerConstants* scanner_contants) |
| 118 : Scanner(scanner_contants) { } |
124 | 119 |
125 | 120 |
126 Token::Value JavaScriptScanner::Next() { | 121 Token::Value JavaScriptScanner::Next() { |
127 current_ = next_; | 122 current_ = next_; |
128 has_line_terminator_before_next_ = false; | 123 has_line_terminator_before_next_ = false; |
129 Scan(); | 124 Scan(); |
130 return current_.token; | 125 return current_.token; |
131 } | 126 } |
132 | 127 |
133 | 128 |
(...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
960 if (MatchKeywordStart(input, "with", 1, Token::WITH)) return; | 955 if (MatchKeywordStart(input, "with", 1, Token::WITH)) return; |
961 break; | 956 break; |
962 case UNMATCHABLE: | 957 case UNMATCHABLE: |
963 break; | 958 break; |
964 } | 959 } |
965 // On fallthrough, it's a failure. | 960 // On fallthrough, it's a failure. |
966 state_ = UNMATCHABLE; | 961 state_ = UNMATCHABLE; |
967 } | 962 } |
968 | 963 |
969 } } // namespace v8::internal | 964 } } // namespace v8::internal |
OLD | NEW |