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

Unified Diff: runtime/vm/scanner.h

Issue 1969563002: Eliminate GrowableTokenStream (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: runtime/vm/scanner.h
diff --git a/runtime/vm/scanner.h b/runtime/vm/scanner.h
index 8d5c6d55d3230b6cbbbae553345f0fb16b0002b0..2f9bddbd02ba0e74a705563d5878dcb716fe2a73 100644
--- a/runtime/vm/scanner.h
+++ b/runtime/vm/scanner.h
@@ -23,7 +23,7 @@ class ScanContext;
class String;
// A call to Scan() scans the source one token at at time.
-// The scanned token is returned by cur_token().
+// The scanned token is returned by current_token().
// GetStream() scans the entire source text and returns a stream of tokens.
class Scanner : ValueObject {
public:
@@ -45,7 +45,14 @@ class Scanner : ValueObject {
const String* literal; // Identifier, number or string literal.
};
- typedef ZoneGrowableArray<TokenDescriptor> GrowableTokenStream;
+ class TokenCollector : public ValueObject {
+ public:
+ TokenCollector() { }
+ virtual ~TokenCollector() { }
+ virtual void AddToken(const TokenDescriptor& token);
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TokenCollector);
+ };
// Initializes scanner to scan string source.
Scanner(const String& source, const String& private_key);
@@ -54,14 +61,13 @@ class Scanner : ValueObject {
// Scans one token at a time.
void Scan();
+ // Scans the entire source and collects tokens in the provided collector.
+ void ScanAll(TokenCollector* collector);
+
// Scans to specified token position.
// Use CurrentPosition() to extract position.
void ScanTo(TokenPosition token_index);
- // Scans entire source and returns a stream of tokens.
- // Should be called only once.
- const GrowableTokenStream& GetStream();
-
// Info about most recently recognized token.
const TokenDescriptor& current_token() const { return current_token_; }
@@ -78,10 +84,8 @@ class Scanner : ValueObject {
// Return true if str is an identifier.
bool IsIdent(const String& str);
- // Does the token stream contain a valid literal. This is used to implement
- // the Dart methods int.parse and double.parse.
- static bool IsValidLiteral(const Scanner::GrowableTokenStream& tokens,
- Token::Kind literal_kind,
+ // Does the token stream contain a valid integer literal.
+ static bool IsValidInteger(const String& str,
bool* is_positive,
const String** value);
@@ -116,9 +120,6 @@ class Scanner : ValueObject {
void ErrorMsg(const char* msg);
- // Scans entire source into a given stream of tokens.
- void ScanAll(GrowableTokenStream* token_stream);
-
// These functions return true if the given character is a letter,
// a decimal digit, a hexadecimal digit, etc.
static bool IsLetter(int32_t c);
@@ -183,8 +184,6 @@ class Scanner : ValueObject {
Thread* thread() const { return thread_; }
Zone* zone() const { return zone_; }
- static void PrintTokens(const GrowableTokenStream& ts);
-
TokenDescriptor current_token_; // Current token.
TokenDescriptor newline_token_; // Newline token.
TokenDescriptor empty_string_token_; // Token for "".

Powered by Google App Engine
This is Rietveld 408576698