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 #ifdef OBJECT_PRINT | |
482 void Type::TypePrint() { | |
483 TypePrint(stdout); | |
484 PrintF(stdout, "\n"); | |
485 Flush(stdout); | |
486 } | |
487 | |
488 | |
489 void Type::TypePrint(FILE* out) { | |
490 if (is_bitset()) { | |
491 int val = as_bitset(); | |
492 const char* composed_name = GetComposedName(val); | |
493 if (composed_name != NULL) { | |
494 PrintF(out, "%s", composed_name); | |
495 return; | |
496 } | |
497 bool first_entry = true; | |
498 PrintF(out, "{"); | |
499 for (unsigned i = 0; i < sizeof(val)*8; ++i) { | |
500 int mask = (1<<i); | |
501 if ((val & mask) != 0) { | |
502 if (!first_entry) PrintF(out, ","); | |
503 first_entry = false; | |
504 PrintF(out, "%s", GetPrimitiveName(mask)); | |
505 } | |
506 } | |
507 PrintF(out, "}"); | |
508 } else if (is_constant()) { | |
509 PrintF(out, "Constant(0x%x)", (unsigned)(*as_constant())); | |
rossberg
2013/07/10 10:32:08
Is there a specific reason you are not using %p (h
oliv
2013/07/10 11:19:43
none except didn't remember the parameter
| |
510 } else if (is_class()) { | |
511 PrintF(out, "Class(0x%x)", (unsigned)(*as_class())); | |
512 } else if (is_union()) { | |
513 PrintF(out, "{"); | |
514 Handle<Unioned> unioned = as_union(); | |
515 for (int i = 0; i < unioned->length(); ++i) { | |
516 Handle<Type> type_i = union_get(unioned, i); | |
517 if (i>0) PrintF(out, ","); | |
rossberg
2013/07/10 10:32:08
Nit: spaces around >
| |
518 type_i->TypePrint(out); | |
519 } | |
520 PrintF(out, "}"); | |
521 } | |
522 } | |
523 #endif | |
524 | |
525 | |
479 } } // namespace v8::internal | 526 } } // namespace v8::internal |
OLD | NEW |