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

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

Issue 39673002: Experimental scanner: save all token data into one vector. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 7 years, 1 month 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') | no next file » | 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 : current_(0), 68 : current_(0),
69 fetched_(0), 69 fetched_(0),
70 read_all_at_once_(read_all_at_once), 70 read_all_at_once_(read_all_at_once),
71 source_(0), 71 source_(0),
72 length_(0) { 72 length_(0) {
73 file_ = fopen(fname, "rb"); 73 file_ = fopen(fname, "rb");
74 scanner_ = new PushScanner(this, isolate->unicode_cache()); 74 scanner_ = new PushScanner(this, isolate->unicode_cache());
75 if (read_all_at_once_) { 75 if (read_all_at_once_) {
76 source_ = ReadFile(fname, isolate, &length_); 76 source_ = ReadFile(fname, isolate, &length_);
77 token_.resize(1500); 77 token_.resize(1500);
78 beg_.resize(1500);
79 end_.resize(1500);
80 } else { 78 } else {
81 token_.resize(BUFFER_SIZE); 79 token_.resize(BUFFER_SIZE);
82 beg_.resize(BUFFER_SIZE);
83 end_.resize(BUFFER_SIZE);
84 } 80 }
85 } 81 }
86 82
87 83
88 ExperimentalScanner::~ExperimentalScanner() { 84 ExperimentalScanner::~ExperimentalScanner() {
89 fclose(file_); 85 fclose(file_);
90 delete[] source_; 86 delete[] source_;
91 } 87 }
92 88
93 89
94 void ExperimentalScanner::FillTokens() { 90 void ExperimentalScanner::FillTokens() {
95 current_ = 0; 91 current_ = 0;
96 fetched_ = 0; 92 fetched_ = 0;
97 if (read_all_at_once_) { 93 if (read_all_at_once_) {
98 scanner_->push(source_, length_ + 1); 94 scanner_->push(source_, length_ + 1);
99 } else { 95 } else {
100 uint8_t chars[BUFFER_SIZE]; 96 uint8_t chars[BUFFER_SIZE];
101 int n = static_cast<int>(fread(&chars, 1, BUFFER_SIZE, file_)); 97 int n = static_cast<int>(fread(&chars, 1, BUFFER_SIZE, file_));
102 for (int i = n; i < BUFFER_SIZE; i++) chars[i] = 0; 98 for (int i = n; i < BUFFER_SIZE; i++) chars[i] = 0;
103 scanner_->push(chars, BUFFER_SIZE); 99 scanner_->push(chars, BUFFER_SIZE);
104 } 100 }
105 } 101 }
106 102
107 103
108 Token::Value ExperimentalScanner::Next() { 104 Token::Value ExperimentalScanner::Next() {
109 while (current_ == fetched_) 105 while (current_ == fetched_)
110 FillTokens(); 106 FillTokens();
111 return token_[current_++]; 107 return token_[current_++].value;
112 } 108 }
113 109
114 110
115 Token::Value ExperimentalScanner::current_token() { 111 Token::Value ExperimentalScanner::current_token() {
116 return token_[current_ - 1]; 112 return token_[current_ - 1].value;
117 } 113 }
118 114
119 115
120 ExperimentalScanner::Location ExperimentalScanner::location() { 116 ExperimentalScanner::Location ExperimentalScanner::location() {
121 return Location(beg_[current_ - 1], end_[current_ - 1]); 117 return Location(token_[current_ - 1].beg, token_[current_ - 1].end);
122 } 118 }
123 119
124 120
125 void ExperimentalScanner::Record(Token::Value token, int beg, int end) { 121 void ExperimentalScanner::Record(Token::Value token, int beg, int end) {
126 if (token == Token::EOS) end--; 122 if (token == Token::EOS) end--;
127 if (fetched_ >= token_.size()) { 123 if (fetched_ >= token_.size()) {
128 token_.resize(token_.size() * 2); 124 token_.resize(token_.size() * 2);
129 beg_.resize(beg_.size() * 2);
130 end_.resize(end_.size() * 2);
131 } 125 }
132 token_[fetched_] = token; 126 token_[fetched_].value = token;
133 beg_[fetched_] = beg; 127 token_[fetched_].beg = beg;
134 end_[fetched_] = end; 128 token_[fetched_].end = end;
135 fetched_++; 129 fetched_++;
136 } 130 }
137 131
138 } } // namespace v8::internal 132 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/lexer/experimental-scanner.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698