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

Side by Side Diff: src/lexer/lexer-shell.cc

Issue 27034005: Add rule for generating lexer and implement lexer shell. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Fix comment Created 7 years, 2 months 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/lexer.gyp ('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
(Empty)
1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
27
28 #include <assert.h>
29 #include <fcntl.h>
30 #include <string.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include "v8.h"
34
35 #include "api.h"
36 #include "ast.h"
37 #include "char-predicates-inl.h"
38 #include "messages.h"
39 #include "platform.h"
40 #include "runtime.h"
41 #include "scanner-character-streams.h"
42 #include "scopeinfo.h"
43 #include "string-stream.h"
44 #include "scanner.h"
45
46 using namespace v8::internal;
47
48 Handle<String> ReadFile(const char* name, Isolate* isolate) {
49 FILE* file = fopen(name, "rb");
50 if (file == NULL) return Handle<String>();
51
52 fseek(file, 0, SEEK_END);
53 int size = ftell(file);
54 rewind(file);
55
56 uint8_t* chars = new uint8_t[size + 1];
57 chars[size] = '\0';
58 for (int i = 0; i < size;) {
59 int read = static_cast<int>(fread(&chars[i], 1, size - i, file));
60 i += read;
61 }
62 fclose(file);
63 Handle<String> result = isolate->factory()->NewStringFromOneByte(
64 Vector<const uint8_t>(chars, size));
65 delete[] chars;
66 return result;
67 }
68
69
70 class BaselineScanner {
71 public:
72 BaselineScanner(const char* fname, Isolate* isolate) {
73 Handle<String> source = ReadFile(fname, isolate);
74 unicode_cache_ = new UnicodeCache();
75 scanner_ = new Scanner(unicode_cache_);
76 stream_ = new GenericStringUtf16CharacterStream(
77 source, 0, source->length());
78 scanner_->Initialize(stream_);
79 }
80
81 ~BaselineScanner() {
82 delete scanner_;
83 delete stream_;
84 delete unicode_cache_;
85 }
86
87 Token::Value Next() {
88 return scanner_->Next();
89 }
90
91 Scanner::Location Location() {
92 return scanner_->location();
93 }
94
95 private:
96 UnicodeCache* unicode_cache_;
97 Scanner* scanner_;
98 GenericStringUtf16CharacterStream* stream_;
99 };
100
101
102 class ExperimentalScanner {
103 explicit ExperimentalScanner(const char* fname);
104 ~ExperimentalScanner();
105 Token::Value Next();
106 Scanner::Location Location();
107 };
108
109
110 int main(int argc, char* argv[]) {
111 v8::V8::InitializeICU();
112 v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
113 v8::Isolate* isolate = v8::Isolate::GetCurrent();
114 {
115 v8::HandleScope handle_scope(isolate);
116 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
117 v8::Local<v8::Context> context = v8::Context::New(isolate, NULL, global);
118 ASSERT(!context.IsEmpty());
119 {
120 v8::Context::Scope scope(context);
121 Isolate* isolate = Isolate::Current();
122 HandleScope handle_scope(isolate);
123 BaselineScanner baseline(argv[1], isolate);
124 Token::Value current;
125 while ((current = baseline.Next()) != Token::EOS) {
126 printf("%11s => (%d, %d)\n",
127 Token::Name(current),
128 baseline.Location().beg_pos,
129 baseline.Location().end_pos);
130 }
131 }
132 }
133 v8::V8::Dispose();
134 return 0;
135 }
OLDNEW
« no previous file with comments | « src/lexer/lexer.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698