| 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 "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 6215 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   6226     // Setup for next iteration. |   6226     // Setup for next iteration. | 
|   6227     prev = curr; |   6227     prev = curr; | 
|   6228     curr = next; |   6228     curr = next; | 
|   6229   } |   6229   } | 
|   6230   const Array& source = Array::Handle(Array::MakeArray(literals)); |   6230   const Array& source = Array::Handle(Array::MakeArray(literals)); | 
|   6231   return String::ConcatAll(source); |   6231   return String::ConcatAll(source); | 
|   6232 } |   6232 } | 
|   6233  |   6233  | 
|   6234  |   6234  | 
|   6235 intptr_t TokenStream::ComputeSourcePosition(intptr_t tok_pos) const { |   6235 intptr_t TokenStream::ComputeSourcePosition(intptr_t tok_pos) const { | 
|   6236   Iterator iterator(*this, 0); |   6236   Iterator iterator(*this, 0, Iterator::kAllTokens); | 
|   6237   intptr_t src_pos = 0; |   6237   intptr_t src_pos = 0; | 
|   6238   Token::Kind kind = iterator.CurrentTokenKind(); |   6238   Token::Kind kind = iterator.CurrentTokenKind(); | 
|   6239   while (iterator.CurrentPosition() < tok_pos && kind != Token::kEOS) { |   6239   while (iterator.CurrentPosition() < tok_pos && kind != Token::kEOS) { | 
|   6240     iterator.Advance(); |   6240     iterator.Advance(); | 
|   6241     kind = iterator.CurrentTokenKind(); |   6241     kind = iterator.CurrentTokenKind(); | 
|   6242     src_pos += 1; |   6242     src_pos += 1; | 
|   6243   } |   6243   } | 
|   6244   return src_pos; |   6244   return src_pos; | 
|   6245 } |   6245 } | 
|   6246  |   6246  | 
|   6247  |   6247  | 
|   6248 intptr_t TokenStream::ComputeTokenPosition(intptr_t src_pos) const { |  | 
|   6249   Iterator iterator(*this, 0); |  | 
|   6250   intptr_t index = 0; |  | 
|   6251   Token::Kind kind = iterator.CurrentTokenKind(); |  | 
|   6252   while (index < src_pos && kind != Token::kEOS) { |  | 
|   6253     iterator.Advance(); |  | 
|   6254     kind = iterator.CurrentTokenKind(); |  | 
|   6255     index += 1; |  | 
|   6256   } |  | 
|   6257   return iterator.CurrentPosition(); |  | 
|   6258 } |  | 
|   6259  |  | 
|   6260  |  | 
|   6261 RawTokenStream* TokenStream::New() { |   6248 RawTokenStream* TokenStream::New() { | 
|   6262   ASSERT(Object::token_stream_class() != Class::null()); |   6249   ASSERT(Object::token_stream_class() != Class::null()); | 
|   6263   RawObject* raw = Object::Allocate(TokenStream::kClassId, |   6250   RawObject* raw = Object::Allocate(TokenStream::kClassId, | 
|   6264                                     TokenStream::InstanceSize(), |   6251                                     TokenStream::InstanceSize(), | 
|   6265                                     Heap::kOld); |   6252                                     Heap::kOld); | 
|   6266   return reinterpret_cast<RawTokenStream*>(raw); |   6253   return reinterpret_cast<RawTokenStream*>(raw); | 
|   6267 } |   6254 } | 
|   6268  |   6255  | 
|   6269  |   6256  | 
|   6270 RawTokenStream* TokenStream::New(intptr_t len) { |   6257 RawTokenStream* TokenStream::New(intptr_t len) { | 
| (...skipping 24 matching lines...) Expand all  Loading... | 
|   6295           GrowableObjectArray::New(kInitialTokenCount, Heap::kOld))), |   6282           GrowableObjectArray::New(kInitialTokenCount, Heap::kOld))), | 
|   6296       token_obj_(Object::Handle()), |   6283       token_obj_(Object::Handle()), | 
|   6297       literal_token_(LiteralToken::Handle()), |   6284       literal_token_(LiteralToken::Handle()), | 
|   6298       literal_str_(String::Handle()) { |   6285       literal_str_(String::Handle()) { | 
|   6299     token_objects_.Add(Object::null_string()); |   6286     token_objects_.Add(Object::null_string()); | 
|   6300   } |   6287   } | 
|   6301   ~CompressedTokenStreamData() { |   6288   ~CompressedTokenStreamData() { | 
|   6302   } |   6289   } | 
|   6303  |   6290  | 
|   6304   // Add an IDENT token into the stream and the token objects array. |   6291   // Add an IDENT token into the stream and the token objects array. | 
|   6305   void AddIdentToken(String* ident) { |   6292   void AddIdentToken(const String* ident) { | 
|   6306     if (ident != NULL) { |   6293     if (ident != NULL) { | 
|   6307       // If the IDENT token is already in the tokens object array use the |   6294       // If the IDENT token is already in the tokens object array use the | 
|   6308       // same index instead of duplicating it. |   6295       // same index instead of duplicating it. | 
|   6309       intptr_t index = FindIdentIndex(ident); |   6296       intptr_t index = FindIdentIndex(ident); | 
|   6310       if (index == -1) { |   6297       if (index == -1) { | 
|   6311         WriteIndex(token_objects_.Length()); |   6298         WriteIndex(token_objects_.Length()); | 
|   6312         ASSERT(ident != NULL); |   6299         ASSERT(ident != NULL); | 
|   6313         token_objects_.Add(*ident); |   6300         token_objects_.Add(*ident); | 
|   6314       } else { |   6301       } else { | 
|   6315         WriteIndex(index); |   6302         WriteIndex(index); | 
|   6316       } |   6303       } | 
|   6317     } else { |   6304     } else { | 
|   6318       WriteIndex(0); |   6305       WriteIndex(0); | 
|   6319     } |   6306     } | 
|   6320   } |   6307   } | 
|   6321  |   6308  | 
|   6322   // Add a LITERAL token into the stream and the token objects array. |   6309   // Add a LITERAL token into the stream and the token objects array. | 
|   6323   void AddLiteralToken(Token::Kind kind, String* literal) { |   6310   void AddLiteralToken(Token::Kind kind, const String* literal) { | 
|   6324     if (literal != NULL) { |   6311     if (literal != NULL) { | 
|   6325       // If the literal token is already in the tokens object array use the |   6312       // If the literal token is already in the tokens object array use the | 
|   6326       // same index instead of duplicating it. |   6313       // same index instead of duplicating it. | 
|   6327       intptr_t index = FindLiteralIndex(kind, literal); |   6314       intptr_t index = FindLiteralIndex(kind, literal); | 
|   6328       if (index == -1) { |   6315       if (index == -1) { | 
|   6329         WriteIndex(token_objects_.Length()); |   6316         WriteIndex(token_objects_.Length()); | 
|   6330         ASSERT(literal != NULL); |   6317         ASSERT(literal != NULL); | 
|   6331         literal_token_ = LiteralToken::New(kind, *literal); |   6318         literal_token_ = LiteralToken::New(kind, *literal); | 
|   6332         token_objects_.Add(literal_token_); |   6319         token_objects_.Add(literal_token_); | 
|   6333       } else { |   6320       } else { | 
| (...skipping 14 matching lines...) Expand all  Loading... | 
|   6348  |   6335  | 
|   6349   // Return the compressed token stream length. |   6336   // Return the compressed token stream length. | 
|   6350   intptr_t Length() const { return stream_.bytes_written(); } |   6337   intptr_t Length() const { return stream_.bytes_written(); } | 
|   6351  |   6338  | 
|   6352   // Return the token objects array. |   6339   // Return the token objects array. | 
|   6353   const GrowableObjectArray& TokenObjects() const { |   6340   const GrowableObjectArray& TokenObjects() const { | 
|   6354     return token_objects_; |   6341     return token_objects_; | 
|   6355   } |   6342   } | 
|   6356  |   6343  | 
|   6357  private: |   6344  private: | 
|   6358   intptr_t FindIdentIndex(String* ident) { |   6345   intptr_t FindIdentIndex(const String* ident) { | 
|   6359     ASSERT(ident != NULL); |   6346     ASSERT(ident != NULL); | 
|   6360     intptr_t hash_value = ident->Hash() % kTableSize; |   6347     intptr_t hash_value = ident->Hash() % kTableSize; | 
|   6361     GrowableArray<intptr_t>& value = ident_table_[hash_value]; |   6348     GrowableArray<intptr_t>& value = ident_table_[hash_value]; | 
|   6362     for (intptr_t i = 0; i < value.length(); i++) { |   6349     for (intptr_t i = 0; i < value.length(); i++) { | 
|   6363       intptr_t index = value[i]; |   6350       intptr_t index = value[i]; | 
|   6364       token_obj_ = token_objects_.At(index); |   6351       token_obj_ = token_objects_.At(index); | 
|   6365       if (token_obj_.IsString()) { |   6352       if (token_obj_.IsString()) { | 
|   6366         const String& ident_str = String::Cast(token_obj_); |   6353         const String& ident_str = String::Cast(token_obj_); | 
|   6367         if (ident->Equals(ident_str)) { |   6354         if (ident->Equals(ident_str)) { | 
|   6368           return index; |   6355           return index; | 
|   6369         } |   6356         } | 
|   6370       } |   6357       } | 
|   6371     } |   6358     } | 
|   6372     value.Add(token_objects_.Length()); |   6359     value.Add(token_objects_.Length()); | 
|   6373     return -1; |   6360     return -1; | 
|   6374   } |   6361   } | 
|   6375  |   6362  | 
|   6376   intptr_t FindLiteralIndex(Token::Kind kind, String* literal) { |   6363   intptr_t FindLiteralIndex(Token::Kind kind, const String* literal) { | 
|   6377     ASSERT(literal != NULL); |   6364     ASSERT(literal != NULL); | 
|   6378     intptr_t hash_value = literal->Hash() % kTableSize; |   6365     intptr_t hash_value = literal->Hash() % kTableSize; | 
|   6379     GrowableArray<intptr_t>& value = literal_table_[hash_value]; |   6366     GrowableArray<intptr_t>& value = literal_table_[hash_value]; | 
|   6380     for (intptr_t i = 0; i < value.length(); i++) { |   6367     for (intptr_t i = 0; i < value.length(); i++) { | 
|   6381       intptr_t index = value[i]; |   6368       intptr_t index = value[i]; | 
|   6382       token_obj_ = token_objects_.At(index); |   6369       token_obj_ = token_objects_.At(index); | 
|   6383       if (token_obj_.IsLiteralToken()) { |   6370       if (token_obj_.IsLiteralToken()) { | 
|   6384         const LiteralToken& token = LiteralToken::Cast(token_obj_); |   6371         const LiteralToken& token = LiteralToken::Cast(token_obj_); | 
|   6385         literal_str_ = token.literal(); |   6372         literal_str_ = token.literal(); | 
|   6386         if (kind == token.kind() && literal->Equals(literal_str_)) { |   6373         if (kind == token.kind() && literal->Equals(literal_str_)) { | 
| (...skipping 9180 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  15567   return "_MirrorReference"; |  15554   return "_MirrorReference"; | 
|  15568 } |  15555 } | 
|  15569  |  15556  | 
|  15570  |  15557  | 
|  15571 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { |  15558 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { | 
|  15572   JSONObject jsobj(stream); |  15559   JSONObject jsobj(stream); | 
|  15573 } |  15560 } | 
|  15574  |  15561  | 
|  15575  |  15562  | 
|  15576 }  // namespace dart |  15563 }  // namespace dart | 
| OLD | NEW |