name.tq 2.76 KB
Newer Older
Tobias Tebbi's avatar
Tobias Tebbi committed
1 2 3 4 5 6 7
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

@abstract
@generateCppClass
extern class Name extends PrimitiveHeapObject {
8
  hash_field: NameHash;
Tobias Tebbi's avatar
Tobias Tebbi committed
9
}
10 11

bitfield struct NameHash extends uint32 {
12
  hash_not_computed: bool: 1 bit;
13 14 15 16 17
  is_not_integer_index_mask: bool: 1 bit;
  array_index_value: uint32: 24 bit;
  array_index_length: uint32: 6 bit;
}

Tobias Tebbi's avatar
Tobias Tebbi committed
18 19 20 21
// This is the same as Name, but with the information that there are no other
// kinds of names.
type AnyName = PrivateSymbol|PublicSymbol|String;

22 23 24 25 26 27 28 29 30
bitfield struct SymbolFlags extends uint32 {
  is_private: bool: 1 bit;
  is_well_known_symbol: bool: 1 bit;
  is_in_public_symbol_table: bool: 1 bit;
  is_interesting_symbol: bool: 1 bit;
  is_private_name: bool: 1 bit;
  is_private_brand: bool: 1 bit;
}

Tobias Tebbi's avatar
Tobias Tebbi committed
31 32
@generateCppClass
extern class Symbol extends Name {
33
  flags: SymbolFlags;
Tobias Tebbi's avatar
Tobias Tebbi committed
34 35 36 37 38
  description: String|Undefined;
}

type PublicSymbol extends Symbol;
type PrivateSymbol extends Symbol;
39

40
const kNameEmptyHashField: NameHash = NameHash{
41
  hash_not_computed: true,
42 43 44 45 46 47 48
  is_not_integer_index_mask: true,
  array_index_value: 0,
  array_index_length: 0
};

const kMaxCachedArrayIndexLength: constexpr uint32
    generates 'Name::kMaxCachedArrayIndexLength';
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
const kMaxArrayIndexSize: constexpr uint32
    generates 'Name::kMaxArrayIndexSize';
const kNofHashBitFields: constexpr int31
    generates 'Name::kNofHashBitFields';
const kArrayIndexValueBits: constexpr int31
    generates 'Name::kArrayIndexValueBits';
const kDoesNotContainCachedArrayIndexMask: constexpr uint32
    generates 'Name::kDoesNotContainCachedArrayIndexMask';
const kIsNotIntegerIndexMask: constexpr uint32
    generates 'Name::kIsNotIntegerIndexMask';

macro ContainsCachedArrayIndex(hash: uint32): bool {
  return (hash & kDoesNotContainCachedArrayIndexMask) == 0;
}

const kArrayIndexValueBitsShift: uint32 = kNofHashBitFields;
const kArrayIndexLengthBitsShift: uint32 =
    kNofHashBitFields + kArrayIndexValueBits;

macro TenToThe(exponent: uint32): uint32 {
  assert(exponent <= 9);
  let answer: int32 = 1;
  for (let i: int32 = 0; i < Signed(exponent); i++) {
    answer = answer * 10;
  }
  return Unsigned(answer);
}

macro MakeArrayIndexHash(value: uint32, length: uint32): NameHash {
  // This is in sync with StringHasher::MakeArrayIndexHash.
  assert(length <= kMaxArrayIndexSize);
  const one: uint32 = 1;
  assert(TenToThe(kMaxCachedArrayIndexLength) < (one << kArrayIndexValueBits));
  let hash: uint32 = value;
  hash = (hash << kArrayIndexValueBitsShift) |
      (length << kArrayIndexLengthBitsShift);
  assert((hash & kIsNotIntegerIndexMask) == 0);
  assert(
      (length <= kMaxCachedArrayIndexLength) == ContainsCachedArrayIndex(hash));
  return %RawDownCast<NameHash>(hash);
}