namespace expr {
namespace attr {
+
+void AttributeManager::debugHook(int debugFlag) {
+ /* DO NOT CHECK IN ANY CODE INTO THE DEBUG HOOKS!
+ * debugHook() is an empty function for the purpose of debugging
+ * the AttributeManager without recompiling all of CVC4.
+ * Formally this is a nop.
+ */
+}
+
void AttributeManager::deleteAllAttributes(NodeValue* nv) {
d_bools.erase(nv);
deleteFromTable(d_ints, nv);
d_cdptrs.clear();
}
+void AttributeManager::deleteAttributes(const AttrIdVec& atids){
+ typedef std::map<uint64_t, std::vector< uint64_t> > AttrToVecMap;
+ AttrToVecMap perTableIds;
+
+ for(AttrIdVec::const_iterator it = atids.begin(), it_end = atids.end(); it != it_end; ++it){
+ const AttributeUniqueId& pair = *(*it);
+ std::vector< uint64_t>& inTable = perTableIds[pair.getTableId()];
+ inTable.push_back(pair.getWithinTypeId());
+ }
+ AttrToVecMap::iterator it = perTableIds.begin(), it_end = perTableIds.end();
+ for(; it != it_end; ++it){
+ Assert(((*it).first) <= LastAttrTable);
+ AttrTableId tableId = (AttrTableId) ((*it).first);
+ std::vector< uint64_t>& ids = (*it).second;
+ std::sort(ids.begin(), ids.end());
+
+ switch(tableId){
+ case AttrTableBool:
+ Unimplemented("delete attributes is unimplemented for bools");
+ break;
+ case AttrTableUInt64:
+ deleteAttributesFromTable(d_ints, ids);
+ break;
+ case AttrTableTNode:
+ deleteAttributesFromTable(d_tnodes, ids);
+ break;
+ case AttrTableNode:
+ deleteAttributesFromTable(d_nodes, ids);
+ break;
+ case AttrTableTypeNode:
+ deleteAttributesFromTable(d_types, ids);
+ break;
+ case AttrTableString:
+ deleteAttributesFromTable(d_strings, ids);
+ break;
+ case AttrTablePointer:
+ deleteAttributesFromTable(d_ptrs, ids);
+ break;
+
+ case AttrTableCDBool:
+ case AttrTableCDUInt64:
+ case AttrTableCDTNode:
+ case AttrTableCDNode:
+ case AttrTableCDString:
+ case AttrTableCDPointer:
+ Unimplemented("CDAttributes cannot be deleted. Contact Tim/Morgan if this behaviour is desired.");
+ break;
+ case LastAttrTable:
+ default:
+ Unreachable();
+ }
+ }
+}
+
}/* CVC4::expr::attr namespace */
}/* CVC4::expr namespace */
}/* CVC4 namespace */
#include <string>
#include <stdint.h>
+#include "expr/attribute_unique_id.h"
// include supporting templates
#define CVC4_ATTRIBUTE_H__INCLUDING__ATTRIBUTE_INTERNALS_H
template <class T>
void deleteAllFromTable(AttrHash<T>& table);
+ template <class T>
+ void deleteAttributesFromTable(AttrHash<T>& table, const std::vector<uint64_t>& ids);
+
+ template <class T>
+ void reconstructTable(AttrHash<T>& table);
+
/**
* getTable<> is a helper template that gets the right table from an
* AttributeManager given its type.
* Remove all attributes from the tables.
*/
void deleteAllAttributes();
+
+
+ /**
+ * Determines the AttrTableId of an attribute.
+ *
+ * @param attr the attribute
+ * @return the id of the attribute table.
+ */
+ template <class AttrKind>
+ static AttributeUniqueId getAttributeId(const AttrKind& attr);
+
+ /** A list of attributes. */
+ typedef std::vector< const AttributeUniqueId* > AttrIdVec;
+
+ /** Deletes a list of attributes. */
+ void deleteAttributes(const AttrIdVec& attributeIds);
+
+ /**
+ * debugHook() is an empty function for the purpose of debugging
+ * the AttributeManager without recompiling all of CVC4.
+ * Formally this is a nop.
+ */
+ void debugHook(int debugFlag);
};
}/* CVC4::expr::attr namespace */
/** Access the "d_bools" member of AttributeManager. */
template <>
struct getTable<bool, false> {
+ static const AttrTableId id = AttrTableBool;
typedef AttrHash<bool> table_type;
static inline table_type& get(AttributeManager& am) {
return am.d_bools;
/** Access the "d_ints" member of AttributeManager. */
template <>
struct getTable<uint64_t, false> {
+ static const AttrTableId id = AttrTableUInt64;
typedef AttrHash<uint64_t> table_type;
static inline table_type& get(AttributeManager& am) {
return am.d_ints;
/** Access the "d_tnodes" member of AttributeManager. */
template <>
struct getTable<TNode, false> {
+ static const AttrTableId id = AttrTableTNode;
typedef AttrHash<TNode> table_type;
static inline table_type& get(AttributeManager& am) {
return am.d_tnodes;
/** Access the "d_nodes" member of AttributeManager. */
template <>
struct getTable<Node, false> {
+ static const AttrTableId id = AttrTableNode;
typedef AttrHash<Node> table_type;
static inline table_type& get(AttributeManager& am) {
return am.d_nodes;
/** Access the "d_types" member of AttributeManager. */
template <>
struct getTable<TypeNode, false> {
+ static const AttrTableId id = AttrTableTypeNode;
typedef AttrHash<TypeNode> table_type;
static inline table_type& get(AttributeManager& am) {
return am.d_types;
/** Access the "d_strings" member of AttributeManager. */
template <>
struct getTable<std::string, false> {
+ static const AttrTableId id = AttrTableString;
typedef AttrHash<std::string> table_type;
static inline table_type& get(AttributeManager& am) {
return am.d_strings;
/** Access the "d_ptrs" member of AttributeManager. */
template <class T>
struct getTable<T*, false> {
+ static const AttrTableId id = AttrTablePointer;
typedef AttrHash<void*> table_type;
static inline table_type& get(AttributeManager& am) {
return am.d_ptrs;
/** Access the "d_ptrs" member of AttributeManager. */
template <class T>
struct getTable<const T*, false> {
+ static const AttrTableId id = AttrTablePointer;
typedef AttrHash<void*> table_type;
static inline table_type& get(AttributeManager& am) {
return am.d_ptrs;
/** Access the "d_cdbools" member of AttributeManager. */
template <>
struct getTable<bool, true> {
+ static const AttrTableId id = AttrTableCDBool;
typedef CDAttrHash<bool> table_type;
static inline table_type& get(AttributeManager& am) {
return am.d_cdbools;
/** Access the "d_cdints" member of AttributeManager. */
template <>
struct getTable<uint64_t, true> {
+ static const AttrTableId id = AttrTableCDUInt64;
typedef CDAttrHash<uint64_t> table_type;
static inline table_type& get(AttributeManager& am) {
return am.d_cdints;
/** Access the "d_tnodes" member of AttributeManager. */
template <>
struct getTable<TNode, true> {
+ static const AttrTableId id = AttrTableCDTNode;
typedef CDAttrHash<TNode> table_type;
static inline table_type& get(AttributeManager& am) {
return am.d_cdtnodes;
/** Access the "d_cdnodes" member of AttributeManager. */
template <>
struct getTable<Node, true> {
+ static const AttrTableId id = AttrTableCDNode;
typedef CDAttrHash<Node> table_type;
static inline table_type& get(AttributeManager& am) {
return am.d_cdnodes;
/** Access the "d_cdstrings" member of AttributeManager. */
template <>
struct getTable<std::string, true> {
+ static const AttrTableId id = AttrTableCDString;
typedef CDAttrHash<std::string> table_type;
static inline table_type& get(AttributeManager& am) {
return am.d_cdstrings;
/** Access the "d_cdptrs" member of AttributeManager. */
template <class T>
struct getTable<T*, true> {
+ static const AttrTableId id = AttrTableCDPointer;
typedef CDAttrHash<void*> table_type;
static inline table_type& get(AttributeManager& am) {
return am.d_cdptrs;
/** Access the "d_cdptrs" member of AttributeManager. */
template <class T>
struct getTable<const T*, true> {
+ static const AttrTableId id = AttrTableCDPointer;
typedef CDAttrHash<void*> table_type;
static inline table_type& get(AttributeManager& am) {
return am.d_cdptrs;
table.clear();
}
+template <class AttrKind>
+AttributeUniqueId AttributeManager::getAttributeId(const AttrKind& attr){
+ typedef typename AttrKind::value_type value_type;
+ AttrTableId tableId = getTable<value_type,
+ AttrKind::context_dependent>::id;
+ return AttributeUniqueId(tableId, attr.getId());
+}
+
+template <class T>
+void AttributeManager::deleteAttributesFromTable(AttrHash<T>& table, const std::vector<uint64_t>& ids){
+ typedef AttributeTraits<T, false> traits_t;
+ typedef AttrHash<T> hash_t;
+
+ typename hash_t::iterator it = table.begin();
+ typename hash_t::iterator tmp;
+ typename hash_t::iterator it_end = table.end();
+
+ std::vector<uint64_t>::const_iterator begin_ids = ids.begin();
+ std::vector<uint64_t>::const_iterator end_ids = ids.end();
+
+ size_t initialSize = table.size();
+ while (it != it_end){
+ uint64_t id = (*it).first.first;
+
+ if(std::binary_search(begin_ids, end_ids, id)){
+ tmp = it;
+ ++it;
+ if(traits_t::getCleanup()[id] != NULL) {
+ traits_t::getCleanup()[id]((*tmp).second);
+ }
+ table.erase(tmp);
+ }else{
+ ++it;
+ }
+ }
+ static const size_t ReconstructShrinkRatio = 8;
+ if(initialSize/ReconstructShrinkRatio > table.size()){
+ reconstructTable(table);
+ }
+}
+
+template <class T>
+void AttributeManager::reconstructTable(AttrHash<T>& table){
+ typedef AttrHash<T> hash_t;
+ hash_t cpy;
+ cpy.insert(table.begin(), table.end());
+ cpy.swap(table);
+}
+
}/* CVC4::expr::attr namespace */
}/* CVC4::expr namespace */