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

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

Issue 60993002: Add ability for Function to generate source (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
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 | « runtime/vm/object.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 (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 5425 matching lines...) Expand 10 before | Expand all | Expand 10 after
5436 } else { 5436 } else {
5437 tmp = cls.UserVisibleName(); 5437 tmp = cls.UserVisibleName();
5438 } 5438 }
5439 } 5439 }
5440 tmp = String::Concat(tmp, Symbols::Dot()); 5440 tmp = String::Concat(tmp, Symbols::Dot());
5441 const String& suffix = String::Handle(UserVisibleName()); 5441 const String& suffix = String::Handle(UserVisibleName());
5442 return String::Concat(tmp, suffix); 5442 return String::Concat(tmp, suffix);
5443 } 5443 }
5444 5444
5445 5445
5446 RawString* Function::GenerateSource() {
hausner 2013/11/05 22:30:05 I suggest making this a bit more smart. If we do h
5447 const Script& func_script = Script::Handle(script());
5448 const TokenStream& token_stream = TokenStream::Handle(func_script.tokens());
5449 return token_stream.GenerateSource(token_pos(), end_token_pos());
5450 }
5451
5452
5446 // Construct fingerprint from token stream. The token stream contains also 5453 // Construct fingerprint from token stream. The token stream contains also
5447 // arguments. 5454 // arguments.
5448 int32_t Function::SourceFingerprint() const { 5455 int32_t Function::SourceFingerprint() const {
5449 uint32_t result = String::Handle(Signature()).Hash(); 5456 uint32_t result = String::Handle(Signature()).Hash();
5450 TokenStream::Iterator tokens_iterator(TokenStream::Handle( 5457 TokenStream::Iterator tokens_iterator(TokenStream::Handle(
5451 Script::Handle(script()).tokens()), token_pos()); 5458 Script::Handle(script()).tokens()), token_pos());
5452 Object& obj = Object::Handle(); 5459 Object& obj = Object::Handle();
5453 String& literal = String::Handle(); 5460 String& literal = String::Handle();
5454 while (tokens_iterator.CurrentPosition() < end_token_pos()) { 5461 while (tokens_iterator.CurrentPosition() < end_token_pos()) {
5455 uint32_t val = 0; 5462 uint32_t val = 0;
(...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after
6243 RawString* TokenStream::PrivateKey() const { 6250 RawString* TokenStream::PrivateKey() const {
6244 return raw_ptr()->private_key_; 6251 return raw_ptr()->private_key_;
6245 } 6252 }
6246 6253
6247 6254
6248 void TokenStream::SetPrivateKey(const String& value) const { 6255 void TokenStream::SetPrivateKey(const String& value) const {
6249 StorePointer(&raw_ptr()->private_key_, value.raw()); 6256 StorePointer(&raw_ptr()->private_key_, value.raw());
6250 } 6257 }
6251 6258
6252 6259
6253 RawString* TokenStream::GenerateSource() const { 6260 RawString* TokenStream::GenerateSource(intptr_t start_tok_pos,
6254 Iterator iterator(*this, 0, Iterator::kAllTokens); 6261 intptr_t end_tok_pos) const {
6262 Iterator iterator(*this, start_tok_pos, Iterator::kAllTokens);
6255 const ExternalTypedData& data = ExternalTypedData::Handle(GetStream()); 6263 const ExternalTypedData& data = ExternalTypedData::Handle(GetStream());
6256 const GrowableObjectArray& literals = 6264 const GrowableObjectArray& literals =
6257 GrowableObjectArray::Handle(GrowableObjectArray::New(data.Length())); 6265 GrowableObjectArray::Handle(GrowableObjectArray::New(data.Length()));
6258 const String& private_key = String::Handle(PrivateKey()); 6266 const String& private_key = String::Handle(PrivateKey());
6259 intptr_t private_len = private_key.Length(); 6267 intptr_t private_len = private_key.Length();
6260 6268
6261 Token::Kind curr = iterator.CurrentTokenKind(); 6269 Token::Kind curr = iterator.CurrentTokenKind();
6262 Token::Kind prev = Token::kILLEGAL; 6270 Token::Kind prev = Token::kILLEGAL;
6263 // Handles used in the loop. 6271 // Handles used in the loop.
6264 Object& obj = Object::Handle(); 6272 Object& obj = Object::Handle();
6265 String& literal = String::Handle(); 6273 String& literal = String::Handle();
6266 // Current indentation level. 6274 // Current indentation level.
6267 int indent = 0; 6275 int indent = 0;
6268 6276
6269 while (curr != Token::kEOS) { 6277 while (curr != Token::kEOS) {
6278 if ((end_tok_pos > 0) && (iterator.CurrentPosition() > end_tok_pos)) {
hausner 2013/11/05 22:30:05 Is end_token_pos inclusive or exclusive? Typically
6279 // We've reached the end of the token stream we want.
6280 break;
6281 }
6270 // Remember current values for this token. 6282 // Remember current values for this token.
6271 obj = iterator.CurrentToken(); 6283 obj = iterator.CurrentToken();
6272 literal = iterator.MakeLiteralToken(obj); 6284 literal = iterator.MakeLiteralToken(obj);
6273 // Advance to be able to use next token kind. 6285 // Advance to be able to use next token kind.
6274 iterator.Advance(); 6286 iterator.Advance();
6275 Token::Kind next = iterator.CurrentTokenKind(); 6287 Token::Kind next = iterator.CurrentTokenKind();
6276 6288
6277 // Handle the current token. 6289 // Handle the current token.
6278 if (curr == Token::kSTRING) { 6290 if (curr == Token::kSTRING) {
6279 bool escape_characters = false; 6291 bool escape_characters = false;
(...skipping 9464 matching lines...) Expand 10 before | Expand all | Expand 10 after
15744 return "_MirrorReference"; 15756 return "_MirrorReference";
15745 } 15757 }
15746 15758
15747 15759
15748 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { 15760 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const {
15749 JSONObject jsobj(stream); 15761 JSONObject jsobj(stream);
15750 } 15762 }
15751 15763
15752 15764
15753 } // namespace dart 15765 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698