| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 #include "string-stream.h" | 56 #include "string-stream.h" |
| 57 | 57 |
| 58 namespace v8 { | 58 namespace v8 { |
| 59 namespace internal { | 59 namespace internal { |
| 60 | 60 |
| 61 class UnicodeCache; | 61 class UnicodeCache; |
| 62 | 62 |
| 63 template<typename YYCTYPE> | 63 template<typename YYCTYPE> |
| 64 class ExperimentalScanner { | 64 class ExperimentalScanner { |
| 65 public: | 65 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 |
| 66 explicit ExperimentalScanner( | 80 explicit ExperimentalScanner( |
| 67 YYCTYPE* source, | 81 YYCTYPE* source, |
| 68 YYCTYPE* source_end, | 82 YYCTYPE* source_end, |
| 69 Isolate* isolate); | 83 Isolate* isolate); |
| 70 | 84 |
| 71 ~ExperimentalScanner(); | 85 ~ExperimentalScanner(); |
| 72 | 86 |
| 73 Token::Value Next(int* beg_pos, int* end_pos); | 87 Token::Value Next() { |
| 88 current_ = next_; |
| 89 Scan(); // will fill in next_. |
| 90 return current_.token; |
| 91 } |
| 92 |
| 93 Location location() { |
| 94 return Location(current_.beg_pos, current_.end_pos); |
| 95 } |
| 74 | 96 |
| 75 void SetHarmonyNumericLiterals(bool numeric_literals) { | 97 void SetHarmonyNumericLiterals(bool numeric_literals) { |
| 76 harmony_numeric_literals_ = numeric_literals; | 98 harmony_numeric_literals_ = numeric_literals; |
| 77 } | 99 } |
| 78 | 100 |
| 79 void SetHarmonyModules(bool modules) { | 101 void SetHarmonyModules(bool modules) { |
| 80 harmony_modules_ = modules; | 102 harmony_modules_ = modules; |
| 81 } | 103 } |
| 82 | 104 |
| 83 void SetHarmonyScoping(bool scoping) { | 105 void SetHarmonyScoping(bool scoping) { |
| 84 harmony_scoping_ = scoping; | 106 harmony_scoping_ = scoping; |
| 85 } | 107 } |
| 86 | 108 |
| 87 private: | 109 private: |
| 110 struct TokenDesc { |
| 111 Token::Value token; |
| 112 int beg_pos; |
| 113 int end_pos; |
| 114 LiteralBuffer* literal_chars; |
| 115 }; |
| 116 |
| 117 void Scan(); |
| 118 |
| 88 bool ValidIdentifierStart(); | 119 bool ValidIdentifierStart(); |
| 89 bool ValidIdentifierPart(); | 120 bool ValidIdentifierPart(); |
| 90 uc32 ScanHexNumber(int length); | 121 uc32 ScanHexNumber(int length); |
| 91 | 122 |
| 92 UnicodeCache* unicode_cache_; | 123 UnicodeCache* unicode_cache_; |
| 93 | 124 |
| 94 YYCTYPE* buffer_; | 125 YYCTYPE* buffer_; |
| 95 YYCTYPE* buffer_end_; | 126 YYCTYPE* buffer_end_; |
| 96 YYCTYPE* start_; | 127 YYCTYPE* start_; |
| 97 YYCTYPE* cursor_; | 128 YYCTYPE* cursor_; |
| 98 YYCTYPE* marker_; | 129 YYCTYPE* marker_; |
| 99 bool just_seen_line_terminator_; | 130 bool just_seen_line_terminator_; |
| 100 | 131 |
| 101 YYCTYPE yych; | 132 YYCTYPE yych; |
| 102 | 133 |
| 134 TokenDesc current_; // desc for current token (as returned by Next()) |
| 135 TokenDesc next_; // desc for next token (one token look-ahead) |
| 136 |
| 103 bool harmony_numeric_literals_; | 137 bool harmony_numeric_literals_; |
| 104 bool harmony_modules_; | 138 bool harmony_modules_; |
| 105 bool harmony_scoping_; | 139 bool harmony_scoping_; |
| 106 }; | 140 }; |
| 107 | 141 |
| 108 const byte* ReadFile(const char* name, Isolate* isolate, int* size, int repeat); | 142 const byte* ReadFile(const char* name, Isolate* isolate, int* size, int repeat); |
| 109 | 143 |
| 110 template<typename YYCTYPE> | 144 template<typename YYCTYPE> |
| 111 ExperimentalScanner<YYCTYPE>::ExperimentalScanner( | 145 ExperimentalScanner<YYCTYPE>::ExperimentalScanner( |
| 112 YYCTYPE* source, | 146 YYCTYPE* source, |
| 113 YYCTYPE* source_end, | 147 YYCTYPE* source_end, |
| 114 Isolate* isolate) | 148 Isolate* isolate) |
| 115 : unicode_cache_(isolate->unicode_cache()), | 149 : unicode_cache_(isolate->unicode_cache()), |
| 116 just_seen_line_terminator_(true), | 150 just_seen_line_terminator_(true), |
| 117 harmony_numeric_literals_(false), | 151 harmony_numeric_literals_(false), |
| 118 harmony_modules_(false), | 152 harmony_modules_(false), |
| 119 harmony_scoping_(false) { | 153 harmony_scoping_(false) { |
| 120 buffer_ = source; | 154 buffer_ = source; |
| 121 buffer_end_ = source_end; | 155 buffer_end_ = source_end; |
| 122 start_ = buffer_; | 156 start_ = buffer_; |
| 123 cursor_ = buffer_; | 157 cursor_ = buffer_; |
| 124 marker_ = buffer_; | 158 marker_ = buffer_; |
| 159 Scan(); |
| 125 } | 160 } |
| 126 | 161 |
| 127 | 162 |
| 128 template<typename YYCTYPE> | 163 template<typename YYCTYPE> |
| 129 ExperimentalScanner<YYCTYPE>::~ExperimentalScanner() { | 164 ExperimentalScanner<YYCTYPE>::~ExperimentalScanner() { |
| 130 delete[] buffer_; | 165 delete[] buffer_; |
| 131 } | 166 } |
| 132 | 167 |
| 133 | 168 |
| 134 template<typename YYCTYPE> | 169 template<typename YYCTYPE> |
| (...skipping 20 matching lines...) Expand all Loading... |
| 155 | 190 |
| 156 | 191 |
| 157 template<typename YYCTYPE> | 192 template<typename YYCTYPE> |
| 158 bool ExperimentalScanner<YYCTYPE>::ValidIdentifierStart() { | 193 bool ExperimentalScanner<YYCTYPE>::ValidIdentifierStart() { |
| 159 return unicode_cache_->IsIdentifierStart(ScanHexNumber(4)); | 194 return unicode_cache_->IsIdentifierStart(ScanHexNumber(4)); |
| 160 } | 195 } |
| 161 | 196 |
| 162 } } | 197 } } |
| 163 | 198 |
| 164 #endif // V8_LEXER_EXPERIMENTAL_SCANNER_H | 199 #endif // V8_LEXER_EXPERIMENTAL_SCANNER_H |
| OLD | NEW |