]>
git.saurik.com Git - apple/javascriptcore.git/blob - bytecode/StructureSet.h
d7087b9dca3f6a07aebfba3faf8eec4cdc24b0f8
   2  * Copyright (C) 2011, 2013 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" 
  32 #include "DumpContext.h" 
  33 #include <wtf/CommaPrinter.h> 
  34 #include <wtf/Vector.h> 
  39 class StructureAbstractValue
; 
  46     StructureSet(Structure
* structure
) 
  49         m_structures
.append(structure
); 
  57     void add(Structure
* structure
) 
  60         ASSERT(!contains(structure
)); 
  61         m_structures
.append(structure
); 
  64     bool addAll(const StructureSet
& other
) 
  67         for (size_t i 
= 0; i 
< other
.size(); ++i
) { 
  68             if (contains(other
[i
])) 
  76     void remove(Structure
* structure
) 
  78         for (size_t i 
= 0; i 
< m_structures
.size(); ++i
) { 
  79             if (m_structures
[i
] != structure
) 
  82             m_structures
[i
] = m_structures
.last(); 
  83             m_structures
.removeLast(); 
  88     bool contains(Structure
* structure
) const 
  90         for (size_t i 
= 0; i 
< m_structures
.size(); ++i
) { 
  91             if (m_structures
[i
] == structure
) 
  97     bool containsOnly(Structure
* structure
) const 
 101         return singletonStructure() == structure
; 
 104     bool isSubsetOf(const StructureSet
& other
) const 
 106         for (size_t i 
= 0; i 
< m_structures
.size(); ++i
) { 
 107             if (!other
.contains(m_structures
[i
])) 
 113     bool isSupersetOf(const StructureSet
& other
) const 
 115         return other
.isSubsetOf(*this); 
 118     bool overlaps(const StructureSet
& other
) const 
 120         for (size_t i 
= 0; i 
< m_structures
.size(); ++i
) { 
 121             if (other
.contains(m_structures
[i
])) 
 127     size_t size() const { return m_structures
.size(); } 
 129     // Call this if you know that the structure set must consist of exactly 
 131     Structure
* singletonStructure() const 
 133         ASSERT(m_structures
.size() == 1); 
 134         return m_structures
[0]; 
 137     Structure
* at(size_t i
) const { return m_structures
.at(i
); } 
 139     Structure
* operator[](size_t i
) const { return at(i
); } 
 141     Structure
* last() const { return m_structures
.last(); } 
 143     SpeculatedType 
speculationFromStructures() const 
 145         SpeculatedType result 
= SpecNone
; 
 147         for (size_t i 
= 0; i 
< m_structures
.size(); ++i
) 
 148             mergeSpeculation(result
, speculationFromStructure(m_structures
[i
])); 
 153     ArrayModes 
arrayModesFromStructures() const 
 155         ArrayModes result 
= 0; 
 157         for (size_t i 
= 0; i 
< m_structures
.size(); ++i
) 
 158             mergeArrayModes(result
, asArrayModes(m_structures
[i
]->indexingType())); 
 163     bool operator==(const StructureSet
& other
) const 
 165         if (m_structures
.size() != other
.m_structures
.size()) 
 168         for (size_t i 
= 0; i 
< m_structures
.size(); ++i
) { 
 169             if (!other
.contains(m_structures
[i
])) 
 176     void dumpInContext(PrintStream
& out
, DumpContext
* context
) const 
 180         for (size_t i 
= 0; i 
< m_structures
.size(); ++i
) 
 181             out
.print(comma
, inContext(*m_structures
[i
], context
)); 
 185     void dump(PrintStream
& out
) const 
 187         dumpInContext(out
, 0); 
 191     friend class DFG::StructureAbstractValue
; 
 193     Vector
<Structure
*, 2> m_structures
; 
 198 #endif // StructureSet_h