| OLD | NEW |
| 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 "platform/assert.h" | 7 #include "platform/assert.h" |
| 8 #include "vm/assembler.h" | 8 #include "vm/assembler.h" |
| 9 #include "vm/bigint_operations.h" | 9 #include "vm/bigint_operations.h" |
| 10 #include "vm/bootstrap.h" | 10 #include "vm/bootstrap.h" |
| (...skipping 4319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4330 } | 4330 } |
| 4331 return String::NewSymbol(Token::Str(kind)); | 4331 return String::NewSymbol(Token::Str(kind)); |
| 4332 } else { | 4332 } else { |
| 4333 LiteralToken& token = LiteralToken::Handle(); | 4333 LiteralToken& token = LiteralToken::Handle(); |
| 4334 token ^= obj.raw(); // Must be a literal token. | 4334 token ^= obj.raw(); // Must be a literal token. |
| 4335 return token.literal(); | 4335 return token.literal(); |
| 4336 } | 4336 } |
| 4337 } | 4337 } |
| 4338 | 4338 |
| 4339 | 4339 |
| 4340 RawString* TokenStream::GenerateSource() const { |
| 4341 GrowableObjectArray& literals = |
| 4342 GrowableObjectArray::Handle(GrowableObjectArray::New(Length())); |
| 4343 String& literal = String::Handle(); |
| 4344 String& blank = String::Handle(String::New(" ")); |
| 4345 String& newline = String::Handle(String::New("\n")); |
| 4346 for (intptr_t i = 0; i < Length(); i++) { |
| 4347 Token::Kind kind = KindAt(i); |
| 4348 literal = LiteralAt(i); |
| 4349 literals.Add(literal); |
| 4350 if (kind == Token::kLBRACE) { |
| 4351 literals.Add(newline); |
| 4352 } else { |
| 4353 literals.Add(blank); |
| 4354 } |
| 4355 } |
| 4356 const Array& source = Array::Handle(Array::MakeArray(literals)); |
| 4357 return String::ConcatAll(source); |
| 4358 } |
| 4359 |
| 4360 |
| 4340 RawTokenStream* TokenStream::New(intptr_t len) { | 4361 RawTokenStream* TokenStream::New(intptr_t len) { |
| 4341 const Class& token_stream_class = Class::Handle(Object::token_stream_class()); | 4362 const Class& token_stream_class = Class::Handle(Object::token_stream_class()); |
| 4342 TokenStream& result = TokenStream::Handle(); | 4363 TokenStream& result = TokenStream::Handle(); |
| 4343 { | 4364 { |
| 4344 RawObject* raw = Object::Allocate(token_stream_class, | 4365 RawObject* raw = Object::Allocate(token_stream_class, |
| 4345 TokenStream::InstanceSize(len), | 4366 TokenStream::InstanceSize(len), |
| 4346 Heap::kOld); | 4367 Heap::kOld); |
| 4347 NoGCScope no_gc; | 4368 NoGCScope no_gc; |
| 4348 result ^= raw; | 4369 result ^= raw; |
| 4349 result.SetLength(len); | 4370 result.SetLength(len); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 4368 } | 4389 } |
| 4369 return result.raw(); | 4390 return result.raw(); |
| 4370 } | 4391 } |
| 4371 | 4392 |
| 4372 | 4393 |
| 4373 const char* TokenStream::ToCString() const { | 4394 const char* TokenStream::ToCString() const { |
| 4374 return "TokenStream"; | 4395 return "TokenStream"; |
| 4375 } | 4396 } |
| 4376 | 4397 |
| 4377 | 4398 |
| 4399 RawString* Script::source() const { |
| 4400 String& source = String::Handle(raw_ptr()->source_); |
| 4401 if (source.IsNull()) { |
| 4402 const TokenStream& token_stream = TokenStream::Handle(tokens()); |
| 4403 return token_stream.GenerateSource(); |
| 4404 } else { |
| 4405 return raw_ptr()->source_; |
| 4406 } |
| 4407 } |
| 4408 |
| 4409 |
| 4378 void Script::set_url(const String& value) const { | 4410 void Script::set_url(const String& value) const { |
| 4379 StorePointer(&raw_ptr()->url_, value.raw()); | 4411 StorePointer(&raw_ptr()->url_, value.raw()); |
| 4380 } | 4412 } |
| 4381 | 4413 |
| 4382 | 4414 |
| 4383 void Script::set_source(const String& value) const { | 4415 void Script::set_source(const String& value) const { |
| 4384 StorePointer(&raw_ptr()->source_, value.raw()); | 4416 StorePointer(&raw_ptr()->source_, value.raw()); |
| 4385 } | 4417 } |
| 4386 | 4418 |
| 4387 | 4419 |
| (...skipping 5611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9999 const String& str = String::Handle(pattern()); | 10031 const String& str = String::Handle(pattern()); |
| 10000 const char* format = "JSRegExp: pattern=%s flags=%s"; | 10032 const char* format = "JSRegExp: pattern=%s flags=%s"; |
| 10001 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); | 10033 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); |
| 10002 char* chars = reinterpret_cast<char*>( | 10034 char* chars = reinterpret_cast<char*>( |
| 10003 Isolate::Current()->current_zone()->Allocate(len + 1)); | 10035 Isolate::Current()->current_zone()->Allocate(len + 1)); |
| 10004 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); | 10036 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); |
| 10005 return chars; | 10037 return chars; |
| 10006 } | 10038 } |
| 10007 | 10039 |
| 10008 } // namespace dart | 10040 } // namespace dart |
| OLD | NEW |