]>
git.saurik.com Git - apple/javascriptcore.git/blob - bytecode/StructureSet.h
2 * Copyright (C) 2011 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #ifndef StructureSet_h
27 #define StructureSet_h
29 #include "ArrayProfile.h"
30 #include "SpeculatedType.h"
31 #include "Structure.h"
33 #include <wtf/Vector.h>
38 class StructureAbstractValue
;
45 StructureSet(Structure
* structure
)
47 m_structures
.append(structure
);
55 void add(Structure
* structure
)
57 ASSERT(!contains(structure
));
58 m_structures
.append(structure
);
61 bool addAll(const StructureSet
& other
)
64 for (size_t i
= 0; i
< other
.size(); ++i
) {
65 if (contains(other
[i
]))
73 void remove(Structure
* structure
)
75 for (size_t i
= 0; i
< m_structures
.size(); ++i
) {
76 if (m_structures
[i
] != structure
)
79 m_structures
[i
] = m_structures
.last();
80 m_structures
.removeLast();
85 bool contains(Structure
* structure
) const
87 for (size_t i
= 0; i
< m_structures
.size(); ++i
) {
88 if (m_structures
[i
] == structure
)
94 bool containsOnly(Structure
* structure
) const
98 return singletonStructure() == structure
;
101 bool isSubsetOf(const StructureSet
& other
) const
103 for (size_t i
= 0; i
< m_structures
.size(); ++i
) {
104 if (!other
.contains(m_structures
[i
]))
110 bool isSupersetOf(const StructureSet
& other
) const
112 return other
.isSubsetOf(*this);
115 size_t size() const { return m_structures
.size(); }
117 // Call this if you know that the structure set must consist of exactly
119 Structure
* singletonStructure() const
121 ASSERT(m_structures
.size() == 1);
122 return m_structures
[0];
125 Structure
* at(size_t i
) const { return m_structures
.at(i
); }
127 Structure
* operator[](size_t i
) const { return at(i
); }
129 Structure
* last() const { return m_structures
.last(); }
131 SpeculatedType
speculationFromStructures() const
133 SpeculatedType result
= SpecNone
;
135 for (size_t i
= 0; i
< m_structures
.size(); ++i
)
136 mergeSpeculation(result
, speculationFromStructure(m_structures
[i
]));
141 ArrayModes
arrayModesFromStructures() const
143 ArrayModes result
= 0;
145 for (size_t i
= 0; i
< m_structures
.size(); ++i
)
146 mergeArrayModes(result
, asArrayModes(m_structures
[i
]->indexingType()));
151 bool operator==(const StructureSet
& other
) const
153 if (m_structures
.size() != other
.m_structures
.size())
156 for (size_t i
= 0; i
< m_structures
.size(); ++i
) {
157 if (!other
.contains(m_structures
[i
]))
167 for (size_t i
= 0; i
< m_structures
.size(); ++i
) {
170 fprintf(out
, "%p", m_structures
[i
]);
176 friend class DFG::StructureAbstractValue
;
178 Vector
<Structure
*, 2> m_structures
;
183 #endif // StructureSet_h