| OLD | NEW |
| (Empty) |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "src/v8.h" | |
| 6 | |
| 7 #include "src/interface.h" | |
| 8 | |
| 9 #include "src/ast-value-factory.h" | |
| 10 | |
| 11 namespace v8 { | |
| 12 namespace internal { | |
| 13 | |
| 14 // --------------------------------------------------------------------------- | |
| 15 // Addition. | |
| 16 | |
| 17 #ifdef DEBUG | |
| 18 // Current nesting depth for debug output. | |
| 19 class Nesting { | |
| 20 public: | |
| 21 Nesting() { current_ += 2; } | |
| 22 ~Nesting() { current_ -= 2; } | |
| 23 static int current() { return current_; } | |
| 24 private: | |
| 25 static int current_; | |
| 26 }; | |
| 27 | |
| 28 int Nesting::current_ = 0; | |
| 29 #endif | |
| 30 | |
| 31 | |
| 32 void Interface::Add(const AstRawString* name, Zone* zone, bool* ok) { | |
| 33 void* key = const_cast<AstRawString*>(name); | |
| 34 | |
| 35 #ifdef DEBUG | |
| 36 if (FLAG_print_interface_details) { | |
| 37 PrintF("%*s# Adding...\n", Nesting::current(), ""); | |
| 38 PrintF("%*sthis = ", Nesting::current(), ""); | |
| 39 this->Print(Nesting::current()); | |
| 40 PrintF("%*s%.*s : ", Nesting::current(), "", name->length(), | |
| 41 name->raw_data()); | |
| 42 } | |
| 43 #endif | |
| 44 | |
| 45 ZoneHashMap** map = &exports_; | |
| 46 ZoneAllocationPolicy allocator(zone); | |
| 47 | |
| 48 if (*map == nullptr) { | |
| 49 *map = new(zone->New(sizeof(ZoneHashMap))) | |
| 50 ZoneHashMap(ZoneHashMap::PointersMatch, | |
| 51 ZoneHashMap::kDefaultHashMapCapacity, allocator); | |
| 52 } | |
| 53 | |
| 54 ZoneHashMap::Entry* p = | |
| 55 (*map)->Lookup(key, name->hash(), !IsFrozen(), allocator); | |
| 56 if (p == nullptr || p->value != nullptr) { | |
| 57 *ok = false; | |
| 58 } | |
| 59 | |
| 60 p->value = key; | |
| 61 | |
| 62 #ifdef DEBUG | |
| 63 if (FLAG_print_interface_details) { | |
| 64 PrintF("%*sthis' = ", Nesting::current(), ""); | |
| 65 this->Print(Nesting::current()); | |
| 66 PrintF("%*s# Added.\n", Nesting::current(), ""); | |
| 67 } | |
| 68 #endif | |
| 69 } | |
| 70 | |
| 71 | |
| 72 // --------------------------------------------------------------------------- | |
| 73 // Printing. | |
| 74 | |
| 75 #ifdef DEBUG | |
| 76 void Interface::Print(int n) { | |
| 77 int n0 = n > 0 ? n : 0; | |
| 78 | |
| 79 if (FLAG_print_interface_details) { | |
| 80 PrintF("%p ", static_cast<void*>(this)); | |
| 81 } | |
| 82 | |
| 83 PrintF("module %d %s{", Index(), IsFrozen() ? "" : "(unresolved) "); | |
| 84 ZoneHashMap* map = exports_; | |
| 85 if (map == nullptr || map->occupancy() == 0) { | |
| 86 PrintF("}\n"); | |
| 87 } else if (n < 0 || n0 >= 2 * FLAG_print_interface_depth) { | |
| 88 // Avoid infinite recursion on cyclic types. | |
| 89 PrintF("...}\n"); | |
| 90 } else { | |
| 91 PrintF("\n"); | |
| 92 for (ZoneHashMap::Entry* p = map->Start(); p != nullptr; p = map->Next(p)) { | |
| 93 String* name = *static_cast<String**>(p->key); | |
| 94 PrintF("%*s%s : ", n0 + 2, "", name->ToAsciiArray()); | |
| 95 } | |
| 96 PrintF("%*s}\n", n0, ""); | |
| 97 } | |
| 98 } | |
| 99 #endif | |
| 100 | |
| 101 } } // namespace v8::internal | |
| OLD | NEW |