| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #include "token.h" | 31 #include "token.h" |
| 32 #include "flags.h" | 32 #include "flags.h" |
| 33 #include "v8stdint.h" | 33 #include "v8stdint.h" |
| 34 | 34 |
| 35 // FIXME: some of this is probably not needed. | 35 // FIXME: some of this is probably not needed. |
| 36 #include "allocation.h" | 36 #include "allocation.h" |
| 37 #include "ast.h" | 37 #include "ast.h" |
| 38 #include "preparse-data-format.h" | 38 #include "preparse-data-format.h" |
| 39 #include "preparse-data.h" | 39 #include "preparse-data.h" |
| 40 #include "scopes.h" | 40 #include "scopes.h" |
| 41 #include "preparser.h" | |
| 42 #include "api.h" | 41 #include "api.h" |
| 43 #include "ast.h" | 42 #include "ast.h" |
| 44 #include "bootstrapper.h" | 43 #include "bootstrapper.h" |
| 45 #include "char-predicates-inl.h" | 44 #include "char-predicates-inl.h" |
| 46 #include "codegen.h" | |
| 47 #include "compiler.h" | 45 #include "compiler.h" |
| 48 #include "func-name-inferrer.h" | 46 #include "func-name-inferrer.h" |
| 49 #include "messages.h" | 47 #include "messages.h" |
| 50 #include "parser.h" | 48 #include "parser.h" |
| 51 #include "platform.h" | 49 #include "platform.h" |
| 52 #include "preparser.h" | |
| 53 #include "runtime.h" | 50 #include "runtime.h" |
| 54 #include "scanner-character-streams.h" | 51 #include "scanner-character-streams.h" |
| 55 #include "scopeinfo.h" | 52 #include "scopeinfo.h" |
| 56 #include "string-stream.h" | 53 #include "string-stream.h" |
| 57 | 54 |
| 58 namespace v8 { | 55 namespace v8 { |
| 59 namespace internal { | 56 namespace internal { |
| 60 | 57 |
| 61 class UnicodeCache; | 58 class UnicodeCache; |
| 62 | 59 |
| 60 struct ScannerLocation { |
| 61 ScannerLocation(int b, int e) : beg_pos(b), end_pos(e) { } |
| 62 ScannerLocation() : beg_pos(0), end_pos(0) { } |
| 63 |
| 64 bool IsValid() const { |
| 65 return beg_pos >= 0 && end_pos >= beg_pos; |
| 66 } |
| 67 |
| 68 static ScannerLocation invalid() { return ScannerLocation(-1, -1); } |
| 69 |
| 70 int beg_pos; |
| 71 int end_pos; |
| 72 }; |
| 73 |
| 63 template<typename YYCTYPE> | 74 template<typename YYCTYPE> |
| 64 class ExperimentalScanner { | 75 class ExperimentalScanner { |
| 65 public: | 76 public: |
| 66 struct Location { | |
| 67 Location(int b, int e) : beg_pos(b), end_pos(e) { } | |
| 68 Location() : beg_pos(0), end_pos(0) { } | |
| 69 | |
| 70 bool IsValid() const { | |
| 71 return beg_pos >= 0 && end_pos >= beg_pos; | |
| 72 } | |
| 73 | |
| 74 static Location invalid() { return Location(-1, -1); } | |
| 75 | |
| 76 int beg_pos; | |
| 77 int end_pos; | |
| 78 }; | |
| 79 | |
| 80 explicit ExperimentalScanner( | 77 explicit ExperimentalScanner( |
| 81 YYCTYPE* source, | 78 YYCTYPE* source, |
| 82 YYCTYPE* source_end, | 79 YYCTYPE* source_end, |
| 83 Isolate* isolate); | 80 Isolate* isolate); |
| 84 | 81 |
| 85 ~ExperimentalScanner(); | 82 ~ExperimentalScanner(); |
| 86 | 83 |
| 87 // Returns the next token and advances input. | 84 // Returns the next token and advances input. |
| 88 Token::Value Next() { | 85 Token::Value Next() { |
| 89 has_line_terminator_before_next_ = false; | 86 has_line_terminator_before_next_ = false; |
| 90 current_ = next_; | 87 current_ = next_; |
| 91 Scan(); // will fill in next_. | 88 Scan(); // will fill in next_. |
| 92 return current_.token; | 89 return current_.token; |
| 93 } | 90 } |
| 94 | 91 |
| 95 // Returns the current token again. | 92 // Returns the current token again. |
| 96 Token::Value current_token() { return current_.token; } | 93 Token::Value current_token() { return current_.token; } |
| 97 | 94 |
| 98 // Returns the location information for the current token | 95 // Returns the location information for the current token |
| 99 // (the token last returned by Next()). | 96 // (the token last returned by Next()). |
| 100 Location location() { | 97 ScannerLocation location() { |
| 101 return Location(current_.beg_pos, current_.end_pos); | 98 return ScannerLocation(current_.beg_pos, current_.end_pos); |
| 102 } | 99 } |
| 103 | 100 |
| 104 // One token look-ahead (past the token returned by Next()). | 101 // One token look-ahead (past the token returned by Next()). |
| 105 Token::Value peek() const { return next_.token; } | 102 Token::Value peek() const { return next_.token; } |
| 106 | 103 |
| 107 Location peek_location() const { return next_.location; } | 104 ScannerLocation peek_location() const { return next_.location; } |
| 108 | 105 |
| 109 UnicodeCache* unicode_cache() { return unicode_cache_; } | 106 UnicodeCache* unicode_cache() { return unicode_cache_; } |
| 110 | 107 |
| 111 bool HarmonyScoping() const { | 108 bool HarmonyScoping() const { |
| 112 return harmony_scoping_; | 109 return harmony_scoping_; |
| 113 } | 110 } |
| 114 void SetHarmonyScoping(bool scoping) { | 111 void SetHarmonyScoping(bool scoping) { |
| 115 harmony_scoping_ = scoping; | 112 harmony_scoping_ = scoping; |
| 116 } | 113 } |
| 117 bool HarmonyModules() const { | 114 bool HarmonyModules() const { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 128 } | 125 } |
| 129 | 126 |
| 130 // Returns true if there was a line terminator before the peek'ed token, | 127 // Returns true if there was a line terminator before the peek'ed token, |
| 131 // possibly inside a multi-line comment. | 128 // possibly inside a multi-line comment. |
| 132 bool HasAnyLineTerminatorBeforeNext() const { | 129 bool HasAnyLineTerminatorBeforeNext() const { |
| 133 return has_line_terminator_before_next_; | 130 return has_line_terminator_before_next_; |
| 134 // FIXME: do we need to distinguish between newlines inside and outside | 131 // FIXME: do we need to distinguish between newlines inside and outside |
| 135 // multiline comments? Atm doesn't look like we need to. | 132 // multiline comments? Atm doesn't look like we need to. |
| 136 } | 133 } |
| 137 | 134 |
| 135 // FIXME: implement these |
| 136 Vector<const char> literal_ascii_string() { |
| 137 return Vector<const char>(); // FIXME |
| 138 } |
| 139 Vector<const uc16> literal_utf16_string() { |
| 140 return Vector<const uc16>(); // FIXME |
| 141 } |
| 142 bool is_literal_ascii() { |
| 143 return true; // FIXME |
| 144 } |
| 145 bool is_literal_contextual_keyword(Vector<const char> keyword) { |
| 146 return false; // FIXME |
| 147 } |
| 148 int literal_length() const { |
| 149 return 0; // FIXME |
| 150 } |
| 151 bool literal_contains_escapes() const { |
| 152 return false; // FIXME |
| 153 } |
| 154 |
| 155 Vector<const char> next_literal_ascii_string() { |
| 156 return Vector<const char>(); // FIXME |
| 157 } |
| 158 Vector<const uc16> next_literal_utf16_string() { |
| 159 return Vector<const uc16>(); // FIXME |
| 160 } |
| 161 bool is_next_literal_ascii() { |
| 162 return true; // FIXME |
| 163 } |
| 164 bool is_next_contextual_keyword(Vector<const char> keyword) { |
| 165 return false; // FIXME |
| 166 } |
| 167 int next_literal_length() const { |
| 168 return 0; // FIXME |
| 169 } |
| 170 |
| 171 uc32 ScanOctalEscape(uc32 c, int length) { return 0; } // FIXME |
| 172 |
| 173 ScannerLocation octal_position() const { |
| 174 return ScannerLocation(0, 0); // FIXME |
| 175 } |
| 176 void clear_octal_position() { } // FIXME |
| 177 |
| 178 void SeekForward(int pos) { } // FIXME |
| 179 |
| 180 // Scans the input as a regular expression pattern, previous |
| 181 // character(s) must be /(=). Returns true if a pattern is scanned. |
| 182 bool ScanRegExpPattern(bool seen_equal) { return false; } // FIXME |
| 183 // Returns true if regexp flags are scanned (always since flags can |
| 184 // be empty). |
| 185 bool ScanRegExpFlags() { return false; } // FIXME |
| 186 |
| 138 private: | 187 private: |
| 139 struct TokenDesc { | 188 struct TokenDesc { |
| 140 Token::Value token; | 189 Token::Value token; |
| 141 int beg_pos; | 190 int beg_pos; |
| 142 int end_pos; | 191 int end_pos; |
| 143 LiteralBuffer* literal_chars; | |
| 144 }; | 192 }; |
| 145 | 193 |
| 146 void Scan(); | 194 void Scan(); |
| 147 | 195 |
| 148 bool ValidIdentifierStart(); | 196 bool ValidIdentifierStart(); |
| 149 bool ValidIdentifierPart(); | 197 bool ValidIdentifierPart(); |
| 150 uc32 ScanHexNumber(int length); | 198 uc32 ScanHexNumber(int length); |
| 151 | 199 |
| 152 UnicodeCache* unicode_cache_; | 200 UnicodeCache* unicode_cache_; |
| 153 | 201 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 | 267 |
| 220 | 268 |
| 221 template<typename YYCTYPE> | 269 template<typename YYCTYPE> |
| 222 bool ExperimentalScanner<YYCTYPE>::ValidIdentifierStart() { | 270 bool ExperimentalScanner<YYCTYPE>::ValidIdentifierStart() { |
| 223 return unicode_cache_->IsIdentifierStart(ScanHexNumber(4)); | 271 return unicode_cache_->IsIdentifierStart(ScanHexNumber(4)); |
| 224 } | 272 } |
| 225 | 273 |
| 226 } } | 274 } } |
| 227 | 275 |
| 228 #endif // V8_LEXER_EXPERIMENTAL_SCANNER_H | 276 #endif // V8_LEXER_EXPERIMENTAL_SCANNER_H |
| OLD | NEW |