source: webkit/trunk/JavaScriptCore/kjs/SymbolTable.h@ 34907

Last change on this file since 34907 was 34610, checked in by [email protected], 17 years ago

2008-06-16 Geoffrey Garen <[email protected]>

Reviewed by Oliver Hunt.


Slight cleanup to the SymbolTableEntry class.


Renamed isEmpty to isNull, since we usually use "empty" to mean "holds
the valid, empty value", and "null" to mean "holds no value".


Changed an "== 0" to a "!", to match our style guidelines.


Added some ASSERTs to verify the (possibly questionable) assumption that
all register indexes will have their high two bits set. Also clarified a
comment to make that assumption clear.

  • Property svn:eol-style set to native
File size: 4.2 KB
Line 
1/*
2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifndef SymbolTable_h
30#define SymbolTable_h
31
32#include "JSObject.h"
33#include "ustring.h"
34#include <wtf/AlwaysInline.h>
35
36namespace KJS {
37
38 struct IdentifierRepHash : PtrHash<RefPtr<UString::Rep> > {
39 static unsigned hash(const RefPtr<UString::Rep>& key) { return key->computedHash(); }
40 static unsigned hash(UString::Rep* key) { return key->computedHash(); }
41 };
42
43 static ALWAYS_INLINE int missingSymbolMarker() { return std::numeric_limits<int>::max(); }
44
45 // The bit twiddling in this class assumes that every register index is a
46 // reasonably small negative number, and therefore has its high two bits set.
47
48 struct SymbolTableEntry {
49 SymbolTableEntry()
50 : rawValue(0)
51 {
52 }
53
54 SymbolTableEntry(int index)
55 {
56 ASSERT(index & 0x80000000);
57 ASSERT(index & 0x40000000);
58
59 rawValue = index & ~0x80000000 & ~0x40000000;
60 }
61
62 SymbolTableEntry(int index, unsigned attributes)
63 {
64 ASSERT(index & 0x80000000);
65 ASSERT(index & 0x40000000);
66
67 rawValue = index;
68
69 if (!(attributes & ReadOnly))
70 rawValue &= ~0x80000000;
71
72 if (!(attributes & DontEnum))
73 rawValue &= ~0x40000000;
74 }
75
76 bool isNull() const
77 {
78 return !rawValue;
79 }
80
81 int getIndex() const
82 {
83 ASSERT(!isNull());
84 return rawValue | 0x80000000 | 0x40000000;
85 }
86
87 unsigned getAttributes() const
88 {
89 unsigned attributes = 0;
90
91 if (rawValue & 0x80000000)
92 attributes |= ReadOnly;
93
94 if (rawValue & 0x40000000)
95 attributes |= DontEnum;
96
97 return attributes;
98 }
99
100 void setAttributes(unsigned attributes)
101 {
102 rawValue = getIndex();
103
104 if (!(attributes & ReadOnly))
105 rawValue &= ~0x80000000;
106
107 if (!(attributes & DontEnum))
108 rawValue &= ~0x40000000;
109 }
110
111 bool isReadOnly() const
112 {
113 return rawValue & 0x80000000;
114 }
115
116 int rawValue;
117 };
118
119 struct SymbolTableIndexHashTraits {
120 typedef SymbolTableEntry TraitType;
121 static SymbolTableEntry emptyValue() { return SymbolTableEntry(); }
122 static const bool emptyValueIsZero = false;
123 static const bool needsDestruction = false;
124 };
125
126 typedef HashMap<RefPtr<UString::Rep>, SymbolTableEntry, IdentifierRepHash, HashTraits<RefPtr<UString::Rep> >, SymbolTableIndexHashTraits> SymbolTable;
127
128} // namespace KJS
129
130#endif // SymbolTable_h
Note: See TracBrowser for help on using the repository browser.