11cb0ef41Sopenharmony_ci// Copyright 2019 the V8 project authors. All rights reserved. 21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be 31cb0ef41Sopenharmony_ci// found in the LICENSE file. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ci@abstract 61cb0ef41Sopenharmony_ciextern class Name extends PrimitiveHeapObject { 71cb0ef41Sopenharmony_ci raw_hash_field: NameHash; 81cb0ef41Sopenharmony_ci} 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_cibitfield struct NameHash extends uint32 { 111cb0ef41Sopenharmony_ci hash_field_type: HashFieldType: 2 bit; 121cb0ef41Sopenharmony_ci array_index_value: uint32: 24 bit; 131cb0ef41Sopenharmony_ci array_index_length: uint32: 6 bit; 141cb0ef41Sopenharmony_ci} 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ci// This is the same as Name, but with the information that there are no other 171cb0ef41Sopenharmony_ci// kinds of names. 181cb0ef41Sopenharmony_citype AnyName = PrivateSymbol|PublicSymbol|String; 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_cibitfield struct SymbolFlags extends uint32 { 211cb0ef41Sopenharmony_ci is_private: bool: 1 bit; 221cb0ef41Sopenharmony_ci is_well_known_symbol: bool: 1 bit; 231cb0ef41Sopenharmony_ci is_in_public_symbol_table: bool: 1 bit; 241cb0ef41Sopenharmony_ci is_interesting_symbol: bool: 1 bit; 251cb0ef41Sopenharmony_ci is_private_name: bool: 1 bit; 261cb0ef41Sopenharmony_ci is_private_brand: bool: 1 bit; 271cb0ef41Sopenharmony_ci} 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ciextern class Symbol extends Name { 301cb0ef41Sopenharmony_ci flags: SymbolFlags; 311cb0ef41Sopenharmony_ci description: String|Undefined; 321cb0ef41Sopenharmony_ci} 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_citype PublicSymbol extends Symbol; 351cb0ef41Sopenharmony_citype PrivateSymbol extends Symbol; 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ciconst kMaxCachedArrayIndexLength: constexpr uint32 381cb0ef41Sopenharmony_ci generates 'Name::kMaxCachedArrayIndexLength'; 391cb0ef41Sopenharmony_ciconst kMaxArrayIndexSize: constexpr uint32 401cb0ef41Sopenharmony_ci generates 'Name::kMaxArrayIndexSize'; 411cb0ef41Sopenharmony_ciconst kNofHashBitFields: constexpr int31 421cb0ef41Sopenharmony_ci generates 'Name::HashFieldTypeBits::kSize'; 431cb0ef41Sopenharmony_ciconst kArrayIndexValueBits: constexpr int31 441cb0ef41Sopenharmony_ci generates 'Name::kArrayIndexValueBits'; 451cb0ef41Sopenharmony_ciconst kDoesNotContainCachedArrayIndexMask: constexpr uint32 461cb0ef41Sopenharmony_ci generates 'Name::kDoesNotContainCachedArrayIndexMask'; 471cb0ef41Sopenharmony_ciconst kNameEmptyHashField: NameHash = NameHash{ 481cb0ef41Sopenharmony_ci hash_field_type: HashFieldType::kEmpty, 491cb0ef41Sopenharmony_ci array_index_value: 0, 501cb0ef41Sopenharmony_ci array_index_length: 0 511cb0ef41Sopenharmony_ci}; 521cb0ef41Sopenharmony_ci 531cb0ef41Sopenharmony_cimacro ContainsCachedArrayIndex(hash: uint32): bool { 541cb0ef41Sopenharmony_ci return (hash & kDoesNotContainCachedArrayIndexMask) == 0; 551cb0ef41Sopenharmony_ci} 561cb0ef41Sopenharmony_ci 571cb0ef41Sopenharmony_ciconst kArrayIndexValueBitsShift: uint32 = kNofHashBitFields; 581cb0ef41Sopenharmony_ciconst kArrayIndexLengthBitsShift: uint32 = 591cb0ef41Sopenharmony_ci kNofHashBitFields + kArrayIndexValueBits; 601cb0ef41Sopenharmony_ci 611cb0ef41Sopenharmony_cimacro TenToThe(exponent: uint32): uint32 { 621cb0ef41Sopenharmony_ci dcheck(exponent <= 9); 631cb0ef41Sopenharmony_ci let answer: int32 = 1; 641cb0ef41Sopenharmony_ci for (let i: int32 = 0; i < Signed(exponent); i++) { 651cb0ef41Sopenharmony_ci answer = answer * 10; 661cb0ef41Sopenharmony_ci } 671cb0ef41Sopenharmony_ci return Unsigned(answer); 681cb0ef41Sopenharmony_ci} 691cb0ef41Sopenharmony_ci 701cb0ef41Sopenharmony_cimacro IsIntegerIndex(hash: NameHash): bool { 711cb0ef41Sopenharmony_ci return hash.hash_field_type == HashFieldType::kIntegerIndex; 721cb0ef41Sopenharmony_ci} 731cb0ef41Sopenharmony_ci 741cb0ef41Sopenharmony_cimacro MakeArrayIndexHash(value: uint32, length: uint32): NameHash { 751cb0ef41Sopenharmony_ci // This is in sync with StringHasher::MakeArrayIndexHash. 761cb0ef41Sopenharmony_ci dcheck(length <= kMaxArrayIndexSize); 771cb0ef41Sopenharmony_ci const one: uint32 = 1; 781cb0ef41Sopenharmony_ci dcheck(TenToThe(kMaxCachedArrayIndexLength) < (one << kArrayIndexValueBits)); 791cb0ef41Sopenharmony_ci let rawHash: uint32 = value; 801cb0ef41Sopenharmony_ci rawHash = (rawHash << kArrayIndexValueBitsShift) | 811cb0ef41Sopenharmony_ci (length << kArrayIndexLengthBitsShift); 821cb0ef41Sopenharmony_ci dcheck( 831cb0ef41Sopenharmony_ci (length <= kMaxCachedArrayIndexLength) == 841cb0ef41Sopenharmony_ci ContainsCachedArrayIndex(rawHash)); 851cb0ef41Sopenharmony_ci const hash: NameHash = %RawDownCast<NameHash>(rawHash); 861cb0ef41Sopenharmony_ci dcheck(IsIntegerIndex(hash)); 871cb0ef41Sopenharmony_ci return hash; 881cb0ef41Sopenharmony_ci} 89