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

Side by Side Diff: runtime/vm/object.cc

Issue 23452043: Introduce newline tokens into the token stream. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/object.h" 5 #include "vm/object.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/assembler.h" 9 #include "vm/assembler.h"
10 #include "vm/cpu.h" 10 #include "vm/cpu.h"
(...skipping 6034 matching lines...) Expand 10 before | Expand all | Expand 10 after
6045 const char* TokenStream::ToCString() const { 6045 const char* TokenStream::ToCString() const {
6046 return "TokenStream"; 6046 return "TokenStream";
6047 } 6047 }
6048 6048
6049 6049
6050 void TokenStream::PrintToJSONStream(JSONStream* stream, bool ref) const { 6050 void TokenStream::PrintToJSONStream(JSONStream* stream, bool ref) const {
6051 JSONObject jsobj(stream); 6051 JSONObject jsobj(stream);
6052 } 6052 }
6053 6053
6054 6054
6055 TokenStream::Iterator::Iterator(const TokenStream& tokens, intptr_t token_pos) 6055 TokenStream::Iterator::Iterator(const TokenStream& tokens,
6056 intptr_t token_pos,
6057 Iterator::StreamType stream_type)
6056 : tokens_(TokenStream::Handle(tokens.raw())), 6058 : tokens_(TokenStream::Handle(tokens.raw())),
6057 data_(ExternalTypedData::Handle(tokens.GetStream())), 6059 data_(ExternalTypedData::Handle(tokens.GetStream())),
6058 stream_(reinterpret_cast<uint8_t*>(data_.DataAddr(0)), data_.Length()), 6060 stream_(reinterpret_cast<uint8_t*>(data_.DataAddr(0)), data_.Length()),
6059 token_objects_(Array::Handle(tokens.TokenObjects())), 6061 token_objects_(Array::Handle(tokens.TokenObjects())),
6060 obj_(Object::Handle()), 6062 obj_(Object::Handle()),
6061 cur_token_pos_(token_pos), 6063 cur_token_pos_(token_pos),
6062 cur_token_kind_(Token::kILLEGAL), 6064 cur_token_kind_(Token::kILLEGAL),
6063 cur_token_obj_index_(-1) { 6065 cur_token_obj_index_(-1),
6066 stream_type_(stream_type) {
6064 SetCurrentPosition(token_pos); 6067 SetCurrentPosition(token_pos);
6065 } 6068 }
6066 6069
6067 6070
6068 void TokenStream::Iterator::SetStream(const TokenStream& tokens, 6071 void TokenStream::Iterator::SetStream(const TokenStream& tokens,
6069 intptr_t token_pos) { 6072 intptr_t token_pos) {
6070 tokens_ = tokens.raw(); 6073 tokens_ = tokens.raw();
6071 data_ = tokens.GetStream(); 6074 data_ = tokens.GetStream();
6072 stream_.SetStream(reinterpret_cast<uint8_t*>(data_.DataAddr(0)), 6075 stream_.SetStream(reinterpret_cast<uint8_t*>(data_.DataAddr(0)),
6073 data_.Length()); 6076 data_.Length());
(...skipping 11 matching lines...) Expand all
6085 } 6088 }
6086 6089
6087 6090
6088 Token::Kind TokenStream::Iterator::LookaheadTokenKind(intptr_t num_tokens) { 6091 Token::Kind TokenStream::Iterator::LookaheadTokenKind(intptr_t num_tokens) {
6089 intptr_t saved_position = stream_.Position(); 6092 intptr_t saved_position = stream_.Position();
6090 Token::Kind kind = Token::kILLEGAL; 6093 Token::Kind kind = Token::kILLEGAL;
6091 intptr_t value = -1; 6094 intptr_t value = -1;
6092 intptr_t count = 0; 6095 intptr_t count = 0;
6093 while (count < num_tokens && value != Token::kEOS) { 6096 while (count < num_tokens && value != Token::kEOS) {
6094 value = ReadToken(); 6097 value = ReadToken();
6095 count += 1; 6098 if ((stream_type_ == kAllTokens) ||
6099 (static_cast<Token::Kind>(value) != Token::kNEWLINE)) {
6100 count += 1;
6101 }
6096 } 6102 }
6097 if (value < Token::kNumTokens) { 6103 if (value < Token::kNumTokens) {
6098 kind = static_cast<Token::Kind>(value); 6104 kind = static_cast<Token::Kind>(value);
6099 } else { 6105 } else {
6100 value = value - Token::kNumTokens; 6106 value = value - Token::kNumTokens;
6101 obj_ = token_objects_.At(value); 6107 obj_ = token_objects_.At(value);
6102 if (obj_.IsLiteralToken()) { 6108 if (obj_.IsLiteralToken()) {
6103 const LiteralToken& literal_token = LiteralToken::Cast(obj_); 6109 const LiteralToken& literal_token = LiteralToken::Cast(obj_);
6104 kind = literal_token.kind(); 6110 kind = literal_token.kind();
6105 } else { 6111 } else {
(...skipping 12 matching lines...) Expand all
6118 6124
6119 6125
6120 void TokenStream::Iterator::SetCurrentPosition(intptr_t value) { 6126 void TokenStream::Iterator::SetCurrentPosition(intptr_t value) {
6121 stream_.SetPosition(value); 6127 stream_.SetPosition(value);
6122 Advance(); 6128 Advance();
6123 } 6129 }
6124 6130
6125 6131
6126 void TokenStream::Iterator::Advance() { 6132 void TokenStream::Iterator::Advance() {
6127 cur_token_pos_ = stream_.Position(); 6133 cur_token_pos_ = stream_.Position();
6128 intptr_t value = ReadToken(); 6134 intptr_t value;
6135 do {
6136 value = ReadToken();
6137 } while ((stream_type_ == kNoNewlines) &&
6138 (static_cast<Token::Kind>(value) == Token::kNEWLINE));
6129 if (value < Token::kNumTokens) { 6139 if (value < Token::kNumTokens) {
6130 cur_token_kind_ = static_cast<Token::Kind>(value); 6140 cur_token_kind_ = static_cast<Token::Kind>(value);
6131 cur_token_obj_index_ = -1; 6141 cur_token_obj_index_ = -1;
6132 return; 6142 return;
6133 } 6143 }
6134 cur_token_obj_index_ = value - Token::kNumTokens; 6144 cur_token_obj_index_ = value - Token::kNumTokens;
6135 obj_ = token_objects_.At(cur_token_obj_index_); 6145 obj_ = token_objects_.At(cur_token_obj_index_);
6136 if (obj_.IsLiteralToken()) { 6146 if (obj_.IsLiteralToken()) {
6137 const LiteralToken& literal_token = LiteralToken::Cast(obj_); 6147 const LiteralToken& literal_token = LiteralToken::Cast(obj_);
6138 cur_token_kind_ = literal_token.kind(); 6148 cur_token_kind_ = literal_token.kind();
(...skipping 8787 matching lines...) Expand 10 before | Expand all | Expand 10 after
14926 return "_MirrorReference"; 14936 return "_MirrorReference";
14927 } 14937 }
14928 14938
14929 14939
14930 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { 14940 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const {
14931 JSONObject jsobj(stream); 14941 JSONObject jsobj(stream);
14932 } 14942 }
14933 14943
14934 14944
14935 } // namespace dart 14945 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/object_test.cc » ('j') | runtime/vm/object_test.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698