Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| 11 // with the distribution. | 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
| 15 // | 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #include "types.h" | 28 #include "types.h" |
| 29 #include "string-stream.h" | |
| 29 | 30 |
| 30 namespace v8 { | 31 namespace v8 { |
| 31 namespace internal { | 32 namespace internal { |
| 32 | 33 |
| 33 int Type::NumClasses() { | 34 int Type::NumClasses() { |
| 34 if (is_class()) { | 35 if (is_class()) { |
| 35 return 1; | 36 return 1; |
| 36 } else if (is_union()) { | 37 } else if (is_union()) { |
| 37 Handle<Unioned> unioned = as_union(); | 38 Handle<Unioned> unioned = as_union(); |
| 38 int result = 0; | 39 int result = 0; |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 469 return from_handle(result); | 470 return from_handle(result); |
| 470 } | 471 } |
| 471 | 472 |
| 472 | 473 |
| 473 Type* Type::Optional(Handle<Type> type) { | 474 Type* Type::Optional(Handle<Type> type) { |
| 474 return type->is_bitset() | 475 return type->is_bitset() |
| 475 ? from_bitset(type->as_bitset() | kUndefined) | 476 ? from_bitset(type->as_bitset() | kUndefined) |
| 476 : Union(type, Undefined()->handle_via_isolate_of(*type)); | 477 : Union(type, Undefined()->handle_via_isolate_of(*type)); |
| 477 } | 478 } |
| 478 | 479 |
| 480 | |
| 481 SmartArrayPointer<const char> Type::GetName() { | |
| 482 char buffer[200]; | |
|
rossberg
2013/07/08 11:20:05
200 seems fragile. I'd drop this method altogether
| |
| 483 NoAllocationStringAllocator allocator(buffer, | |
| 484 static_cast<unsigned>(sizeof(buffer))); | |
| 485 StringStream stream(&allocator); | |
| 486 PrintName(&stream); | |
| 487 return stream.ToCString(); | |
| 488 } | |
| 489 | |
| 490 | |
| 491 void Type::PrintName(StringStream* stream) { | |
| 492 if (is_bitset()) { | |
| 493 int val = as_bitset(); | |
| 494 const char* composed_name = GetComposedName(val); | |
| 495 if (composed_name != NULL) { | |
| 496 stream->Add(composed_name); | |
| 497 return; | |
| 498 } | |
| 499 SimpleListPrinter printer(stream); | |
|
rossberg
2013/07/08 11:20:05
Can we put a "{...}" around the list?
| |
| 500 for (unsigned i = 0; i < sizeof(val)*8; ++i) { | |
| 501 int mask = (1<<i); | |
| 502 if ((val & mask) != 0) { | |
| 503 printer.Add(GetPrimitiveName(mask)); | |
| 504 } | |
| 505 } | |
| 506 } else if (is_constant()) { | |
| 507 stream->Add("Constant("); | |
| 508 stream->Add("0x%x", *as_constant()); | |
| 509 stream->Add(")"); | |
| 510 } else if (is_class()) { | |
| 511 stream->Add("Class("); | |
| 512 stream->Add("0x%x", *as_class()); | |
| 513 stream->Add(")"); | |
| 514 } else if (is_union()) { | |
| 515 Handle<Unioned> unioned = as_union(); | |
| 516 SimpleListPrinter printer(stream); | |
|
rossberg
2013/07/08 11:20:05
Can we put a "{...}" around the list?
| |
| 517 for (int i = 0; i < unioned->length(); ++i) { | |
| 518 Handle<Type> type_i = union_get(unioned, i); | |
| 519 printer.Add(*type_i->GetName()); | |
| 520 } | |
| 521 } | |
| 522 } | |
| 523 | |
| 524 | |
| 479 } } // namespace v8::internal | 525 } } // namespace v8::internal |
| OLD | NEW |