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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/object.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/object.cc
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc
index 8ba182a30b55d34f06cab4fbc87dfe6df5d1c068..ac251452b19e38ee3daaffc6689360b7f793a690 100644
--- a/runtime/vm/object.cc
+++ b/runtime/vm/object.cc
@@ -5443,6 +5443,13 @@ RawString* Function::QualifiedUserVisibleName() const {
}
+RawString* Function::GenerateSource() {
hausner 2013/11/05 22:30:05 I suggest making this a bit more smart. If we do h
+ const Script& func_script = Script::Handle(script());
+ const TokenStream& token_stream = TokenStream::Handle(func_script.tokens());
+ return token_stream.GenerateSource(token_pos(), end_token_pos());
+}
+
+
// Construct fingerprint from token stream. The token stream contains also
// arguments.
int32_t Function::SourceFingerprint() const {
@@ -6250,8 +6257,9 @@ void TokenStream::SetPrivateKey(const String& value) const {
}
-RawString* TokenStream::GenerateSource() const {
- Iterator iterator(*this, 0, Iterator::kAllTokens);
+RawString* TokenStream::GenerateSource(intptr_t start_tok_pos,
+ intptr_t end_tok_pos) const {
+ Iterator iterator(*this, start_tok_pos, Iterator::kAllTokens);
const ExternalTypedData& data = ExternalTypedData::Handle(GetStream());
const GrowableObjectArray& literals =
GrowableObjectArray::Handle(GrowableObjectArray::New(data.Length()));
@@ -6267,6 +6275,10 @@ RawString* TokenStream::GenerateSource() const {
int indent = 0;
while (curr != Token::kEOS) {
+ 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
+ // We've reached the end of the token stream we want.
+ break;
+ }
// Remember current values for this token.
obj = iterator.CurrentToken();
literal = iterator.MakeLiteralToken(obj);
« 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