OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 the V8 project authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef V8_ASMJS_ASM_LEXER_H_ | |
6 #define V8_ASMJS_ASM_LEXER_H_ | |
7 | |
8 #include <unordered_map> | |
9 | |
10 #include "src/asmjs/asm-names.h" | |
11 #include "src/objects-inl.h" | |
12 #include "src/objects.h" | |
marja
2017/03/14 11:11:47
Nit: You shouldn't need objects.h and objects-inl.
bradn
2017/03/15 07:53:04
Done.
| |
13 #include "src/parsing/scanner.h" | |
marja
2017/03/14 11:11:47
Can you split out the stream from scanner.h so tha
vogelheim
2017/03/14 13:36:37
Forward declare v8::internal::Utf16CharacterStream
bradn
2017/03/15 07:53:03
Done.
bradn
2017/03/15 07:53:04
Done.
| |
14 | |
15 namespace v8 { | |
16 namespace internal { | |
17 | |
18 class AsmJsLexer { | |
19 public: | |
20 typedef intptr_t token_t; | |
vogelheim
2017/03/14 13:36:38
Why intptr_t? Is it intentional that the token ran
bradn
2017/03/15 07:53:04
Not particularly, other than that the string table
| |
21 | |
22 explicit AsmJsLexer(Isolate* isolate, Handle<Script> script, int start, | |
vogelheim
2017/03/14 13:36:38
nitpick: Drop explicit with multi-arg constructor.
bradn
2017/03/15 07:53:04
Done.
| |
23 int end); | |
24 token_t Token() const { return token_; } | |
25 const std::string& name() const { return name_; } | |
vogelheim
2017/03/14 13:36:37
name() / name_ appears to be the current token buf
vogelheim
2017/03/14 13:36:37
What is the intended use of name()?
I take it the
bradn
2017/03/15 07:53:04
Divided up its uses, renamed the public part to Id
bradn
2017/03/15 07:53:04
So the vast majority of places just the token id c
| |
26 void SetLocalScope(bool local) { local_ = local; } | |
vogelheim
2017/03/14 13:36:38
What does this do? (I mean, what's a local scope,
bradn
2017/03/15 07:53:04
Renamed, commented, and clarified.
| |
27 void Next(); | |
28 void Rewind(); | |
29 void ResetLocals(); | |
30 const char* Name(token_t token) const; | |
31 int position() const; | |
Karl
2017/03/14 18:00:47
Why is this method lower case when other methods s
bradn
2017/03/15 07:53:04
Changed.
| |
32 void Seek(int pos); | |
33 | |
34 bool IsLocal() const { return IsLocal(Token()); } | |
35 bool IsGlobal() const { return IsGlobal(Token()); } | |
36 static bool IsLocal(token_t token) { return token <= kLocalsStart; } | |
37 static bool IsGlobal(token_t token) { return token >= kGlobalsStart; } | |
38 static size_t LocalIndex(token_t token) { | |
39 DCHECK(IsLocal(token)); | |
40 return -(token - kLocalsStart); | |
41 } | |
42 static size_t GlobalIndex(token_t token) { | |
43 DCHECK(IsGlobal(token)); | |
44 return token - kGlobalsStart; | |
45 } | |
46 bool preceeded_by_newline() const { return preceeded_by_newline_; } | |
47 | |
48 bool IsUnsigned() const { return Token() == kUnsigned; } | |
49 bool IsDouble() const { return Token() == kDouble; } | |
50 | |
51 double AsDouble() const { return double_value_; } | |
52 uint64_t AsUnsigned() const { return unsigned_value_; } | |
53 | |
54 enum { | |
vogelheim
2017/03/14 13:36:37
This enum has a lot of implied structure which is
bradn
2017/03/15 07:53:04
Done.
| |
55 kLocalsStart = -10000, | |
56 #define V(name, _junk1, _junk2, _junk3) kToken_##name, | |
57 STDLIB_MATH_FUNCTION_LIST(V) STDLIB_ARRAY_TYPE_LIST(V) | |
58 #undef V | |
59 #define V(name) kToken_##name, | |
60 STDLIB_OTHER_LIST(V) STDLIB_MATH_VALUE_LIST(V) KEYWORD_NAME_LIST(V) | |
61 #undef V | |
62 #define V(rawname, name) kToken_##name, | |
63 LONG_SYMBOL_NAME_LIST(V) | |
vogelheim
2017/03/14 13:36:38
formatting nitpick: The indent is funky. Slightly
bradn
2017/03/15 07:53:04
Done.
| |
64 #undef V | |
65 | |
66 kEndOfInput = -1, | |
67 kParseError = -2, | |
68 kUnsigned = -3, | |
69 kDouble = -4, | |
70 kGlobalsStart = 256, | |
71 }; | |
72 | |
73 private: | |
74 Handle<Script> script_; | |
75 Handle<String> source_; | |
76 std::unique_ptr<Utf16CharacterStream> stream_; | |
77 token_t token_; | |
78 token_t last_token_; | |
vogelheim
2017/03/14 13:36:37
last_token_ -> preceding_token_?
(I take it it's
bradn
2017/03/15 07:53:04
Yes.
Renamed.
| |
79 token_t next_token_; | |
80 bool rewind_; | |
81 std::string name_; | |
82 bool local_; | |
83 std::unordered_map<std::string, token_t> local_names_; | |
84 std::unordered_map<std::string, token_t> global_names_; | |
85 std::unordered_map<std::string, token_t> property_names_; | |
86 int global_count_; | |
87 double double_value_; | |
88 uint64_t unsigned_value_; | |
89 bool preceeded_by_newline_; | |
90 }; | |
91 | |
92 } // namespace internal | |
93 } // namespace v8 | |
94 #endif | |
OLD | NEW |