Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: src/lexer/experimental-scanner.cc

Issue 88653003: Add literal handling to experimental scanner. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Landing Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/lexer/experimental-scanner.h ('k') | src/lexer/lexer-shell.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 return content.ToUC16Vector().start(); 55 return content.ToUC16Vector().start();
56 } 56 }
57 57
58 58
59 template<> 59 template<>
60 const int8_t* ExperimentalScanner<int8_t>::GetNewBufferBasedOnHandle() const { 60 const int8_t* ExperimentalScanner<int8_t>::GetNewBufferBasedOnHandle() const {
61 String::FlatContent content = source_handle_->GetFlatContent(); 61 String::FlatContent content = source_handle_->GetFlatContent();
62 return reinterpret_cast<const int8_t*>(content.ToOneByteVector().start()); 62 return reinterpret_cast<const int8_t*>(content.ToOneByteVector().start());
63 } 63 }
64 64
65
66 template<>
67 bool ExperimentalScanner<uint8_t>::FillLiteral(
68 const TokenDesc& token, LiteralDesc* literal) {
69 literal->beg_pos = token.beg_pos;
70 const uint8_t* start = buffer_ + token.beg_pos;
71 const uint8_t* end = buffer_ + token.end_pos;
72 if (token.token == Token::STRING) {
73 ++start;
74 --end;
75 }
76 if (!token.has_escapes) {
77 literal->is_ascii = true;
78 literal->length = end - start;
79 literal->ascii_string = Vector<const char>(
80 reinterpret_cast<const char*>(start), literal->length);
81 return true;
82 }
83 literal->buffer.Reset();
84 for (const uint8_t* cursor = start; cursor != end;) {
85 if (*cursor != '\\') {
86 literal->buffer.AddChar(*cursor++);
87 } else if (token.token == Token::IDENTIFIER) {
88 uc32 c;
89 cursor = ScanIdentifierUnicodeEscape(cursor, end, &c);
90 ASSERT(cursor != NULL);
91 if (cursor == NULL) return false;
92 literal->buffer.AddChar(c);
93 } else {
94 cursor = ScanEscape(cursor, end, &literal->buffer);
95 ASSERT(cursor != NULL);
96 if (cursor == NULL) return false;
97 }
98 }
99 literal->is_ascii = literal->buffer.is_ascii();
100 literal->length = literal->buffer.length();
101 if (literal->is_ascii) {
102 literal->ascii_string = literal->buffer.ascii_literal();
103 } else {
104 literal->utf16_string = literal->buffer.utf16_literal();
105 }
106 return true;
107 }
108
109
110 template<>
111 bool ExperimentalScanner<uint16_t>::FillLiteral(
112 const TokenDesc& token, LiteralDesc* literal) {
113 literal->beg_pos = token.beg_pos;
114 const uint16_t* start = buffer_ + token.beg_pos;
115 const uint16_t* end = buffer_ + token.end_pos;
116 if (token.token == Token::STRING) {
117 ++start;
118 --end;
119 }
120 if (!token.has_escapes) {
121 literal->is_ascii = false; // FIXME: utf16 can contain only ascii chars.
122 literal->length = end - start;
123 literal->utf16_string = Vector<const uint16_t>(start, literal->length);
124 return true;
125 }
126 literal->buffer.Reset();
127 for (const uint16_t* cursor = start; cursor != end;) {
128 if (*cursor != '\\') {
129 literal->buffer.AddChar(*cursor++);
130 } else if (token.token == Token::IDENTIFIER) {
131 uc32 c;
132 cursor = ScanIdentifierUnicodeEscape(cursor, end, &c);
133 ASSERT(cursor != NULL);
134 if (cursor == NULL) return false;
135 literal->buffer.AddChar(c);
136 } else {
137 cursor = ScanEscape(cursor, end, &literal->buffer);
138 ASSERT(cursor != NULL);
139 if (cursor == NULL) return false;
140 }
141 }
142 literal->is_ascii = literal->buffer.is_ascii();
143 literal->length = literal->buffer.length();
144 if (literal->is_ascii) {
145 literal->ascii_string = literal->buffer.ascii_literal();
146 } else {
147 literal->utf16_string = literal->buffer.utf16_literal();
148 }
149 return true;
150 }
151
152 template<>
153 bool ExperimentalScanner<int8_t>::FillLiteral(
154 const TokenDesc& token, LiteralDesc* literal) {
155 // FIXME: implement.
156 return false;
157 }
158
159
65 } 160 }
66 } 161 }
OLDNEW
« no previous file with comments | « src/lexer/experimental-scanner.h ('k') | src/lexer/lexer-shell.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698