| Index: vm/class_table.cc
|
| ===================================================================
|
| --- vm/class_table.cc (revision 0)
|
| +++ vm/class_table.cc (revision 0)
|
| @@ -0,0 +1,55 @@
|
| +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
| +// for details. All rights reserved. Use of this source code is governed by a
|
| +// BSD-style license that can be found in the LICENSE file.
|
| +
|
| +#include "vm/class_table.h"
|
| +#include "vm/flags.h"
|
| +#include "vm/object.h"
|
| +#include "vm/raw_object.h"
|
| +
|
| +namespace dart {
|
| +
|
| +DEFINE_FLAG(bool, print_class_table, false, "Print initial class table.");
|
| +
|
| +ClassTable::ClassTable()
|
| + : top_(kNumPredefinedKinds), capacity_(initial_capacity_), table_(NULL) {
|
| + table_ = reinterpret_cast<RawClass**>(calloc(capacity_,
|
| + sizeof(RawClass*))); // NOLINT
|
| +}
|
| +
|
| +
|
| +ClassTable::~ClassTable() {
|
| + free(table_);
|
| +}
|
| +
|
| +
|
| +void ClassTable::Register(const Class& cls) {
|
| + intptr_t index = cls.index();
|
| + if (index != kIllegalObjectKind) {
|
| + ASSERT(index > 0);
|
| + ASSERT(index < kNumPredefinedKinds);
|
| + ASSERT(table_[index] == 0);
|
| + table_[index] = cls.raw();
|
| + } else {
|
| + cls.set_index(top_);
|
| + table_[top_] = cls.raw();
|
| + top_++; // Increment next index.
|
| + ASSERT(top_ < capacity_);
|
| + }
|
| +}
|
| +
|
| +
|
| +void ClassTable::Print() {
|
| + Class& cls = Class::Handle();
|
| + String& name = String::Handle();
|
| +
|
| + for (intptr_t i = 1; i < top_; i++) {
|
| + cls = At(i);
|
| + if (cls.raw() != reinterpret_cast<RawClass*>(0)) {
|
| + name = cls.Name();
|
| + OS::Print("%d: %s\n", i, name.ToCString());
|
| + }
|
| + }
|
| +}
|
| +
|
| +} // namespace dart
|
|
|