Skip to content

Commit

Permalink
(Support) Upgraded to latest Sawyer release
Browse files Browse the repository at this point in the history
* ASSERT_*2 macros can take most any type as the description
  string (2nd argument). It does not have to be an std::string or a
  `const char*`, but must be able to be passed as an argument to
  'boost::lexical_cast<std::string>'.

  For instance, instead of these:

    ASSERT_require2(list.empty(), "list size = " + Rose::StringUtility::toString(list.size()));
    ASSERT_require2(list.empty(), Rose::StringUtility::toString(list.size()));

  You can say:

    ASSERT_require2(list.empty(), boost::format("list size = %d") % list.size());
    ASSERT_require2(list.empty(), list.size());

* Sawyer::Tree is updated to allow both 1:1 edges and 1:N
  edges. Sawyer::Tree is a tree data structure that supports automatic
  parent pointers when adjusting child pointers, and traversals that
  don't require any code generation. Using only C++14.

* Added many more Sawyer::Tree unit tests. See
  tests/smoke/unit/Sawyer/treeUnitTests.C if you want to see how to
  write tree data structures without using generated code. This is a
  work in progress.

* Removed a ROSE dependency from Sawyer::Yaml by replacing
  rose_strtoull with Sawyer::parse. The latter is also easier to use
  correctly.

RPM-212
  • Loading branch information
matzke1 committed Apr 19, 2023
1 parent 144bd45 commit 1405052
Show file tree
Hide file tree
Showing 15 changed files with 1,741 additions and 1,111 deletions.
9 changes: 9 additions & 0 deletions src/util/Sawyer/AddressSegment.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ class AddressSegment {
const std::string &name="")
: buffer_(buffer), offset_(offset), accessibility_(accessBits), name_(name) {}

/** Assignment. */
AddressSegment& operator=(const AddressSegment &other) {
buffer_ = other.buffer_;
offset_ = other.offset_;
accessibility_ = other.accessibility_;
name_ = other.name_;
return *this;
}

//-------------------------------------------------------------------------------------------------------------------
// The following static methods are convenience wrappers around various buffer types.
//-------------------------------------------------------------------------------------------------------------------
Expand Down
16 changes: 9 additions & 7 deletions src/util/Sawyer/Assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <Sawyer/Sawyer.h>

#include <boost/config.hpp>
#include <boost/lexical_cast.hpp>
#include <string>
#ifdef __clang_analyzer__
#include <cassert>
Expand Down Expand Up @@ -124,10 +125,10 @@ SAWYER_EXPORT extern AssertFailureHandler assertFailureHandler;
#define ASSERT_always_forbid(expr) ASSERT_always_forbid2(expr, "")
#define ASSERT_always_not_null(expr) ASSERT_always_not_null2(expr, "")
#define ASSERT_always_not_reachable(note) \
Sawyer::Assert::fail("reached impossible state", NULL, (note), \
Sawyer::Assert::fail("reached impossible state", NULL, boost::lexical_cast<std::string>(note), \
__FILE__, __LINE__, SAWYER_PRETTY_FUNCTION)
#define ASSERT_always_not_implemented(note) \
Sawyer::Assert::fail("not implemented yet", NULL, (note), \
Sawyer::Assert::fail("not implemented yet", NULL, boost::lexical_cast<std::string>(note), \
__FILE__, __LINE__, SAWYER_PRETTY_FUNCTION)
#define ASSERT_always_this() /*void*/

Expand All @@ -140,20 +141,21 @@ SAWYER_EXPORT extern AssertFailureHandler assertFailureHandler;
#define ASSERT_always_require2(expr, note) \
((expr) ? \
static_cast<void>(0) : \
Sawyer::Assert::fail("assertion failed", "required: " #expr, (note), \
Sawyer::Assert::fail("assertion failed", "required: " #expr, boost::lexical_cast<std::string>(note), \
__FILE__, __LINE__, SAWYER_PRETTY_FUNCTION))

#define ASSERT_always_forbid2(expr, note) \
(!(expr) ? \
static_cast<void>(0) : \
Sawyer::Assert::fail("assertion failed", \
"forbidden: " #expr, (note), __FILE__, __LINE__, SAWYER_PRETTY_FUNCTION))
"forbidden: " #expr, boost::lexical_cast<std::string>(note), \
__FILE__, __LINE__, SAWYER_PRETTY_FUNCTION))

#define ASSERT_always_not_null2(expr, note) \
((expr)!=NULL ? \
static_cast<void>(0) : \
Sawyer::Assert::fail("null pointer", \
#expr, (note), __FILE__, __LINE__, SAWYER_PRETTY_FUNCTION))
#expr, boost::lexical_cast<std::string>(note), __FILE__, __LINE__, SAWYER_PRETTY_FUNCTION))
#endif

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -191,11 +193,11 @@ SAWYER_EXPORT extern AssertFailureHandler assertFailureHandler;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#define TODO(note) \
Sawyer::Assert::fail("not implemented yet", NULL, (note), \
Sawyer::Assert::fail("not implemented yet", NULL, boost::lexical_cast<std::string>(note), \
__FILE__, __LINE__, SAWYER_PRETTY_FUNCTION)

#define FIXME(note) \
Sawyer::Assert::fail("needs to be fixed", NULL, (note), \
Sawyer::Assert::fail("needs to be fixed", NULL, boost::lexical_cast<std::string>(note), \
__FILE__, __LINE__, SAWYER_PRETTY_FUNCTION)

#endif
4 changes: 4 additions & 0 deletions src/util/Sawyer/BitFlags.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ class BitFlags {
BitFlags(E e) /*implicit*/
: vector_(Vector(e)) {}

/** Copy constructor. */
BitFlags(const BitFlags &other)
: vector_(other.vector_) {}

/** Current value of the bit vector. */
Vector vector() const {
return vector_;
Expand Down
4 changes: 2 additions & 2 deletions src/util/Sawyer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ install(FILES
DocumentTextMarkup.h Exception.h FileSystem.h Graph.h GraphAlgorithm.h GraphBoost.h GraphIteratorBiMap.h GraphIteratorMap.h
GraphIteratorSet.h GraphTraversal.h IndexedList.h Interval.h IntervalMap.h IntervalSet.h IntervalSetMap.h HashMap.h Lexer.h
LineVector.h Map.h MappedBuffer.h Message.h NullBuffer.h Optional.h Parse.h PoolAllocator.h ProgressBar.h Sawyer.h Set.h SharedObject.h
Result.h SharedPointer.h SmallObject.h Stack.h StackAllocator.h StaticBuffer.h Stopwatch.h Synchronization.h ThreadWorkers.h Time.h Trace.h
Tracker.h Tree.h Type.h WarningsOff.h WarningsRestore.h WorkList.h Yaml.h
Result.h SharedPointer.h SmallObject.h Stack.h StackAllocator.h StaticBuffer.h Stopwatch.h Synchronization.h ThreadWorkers.h Time.h
Trace.h Tracker.h Tree.h Type.h WarningsOff.h WarningsRestore.h WorkList.h Yaml.h
DESTINATION include/Sawyer) # installed in $PREFIX/Sawyer, not $PREFIX/rose/Sawyer.
9 changes: 9 additions & 0 deletions src/util/Sawyer/Graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,7 @@ class Graph {
public:
/** Assignment. */
Derived& operator=(const Derived &other) { base_ = other.base_; return *derived(); }
VertexBaseIterator& operator=(const VertexBaseIterator &other) { base_ = other.base_; return *this; }

/** Increment.
*
Expand Down Expand Up @@ -926,6 +927,7 @@ class Graph {
typedef Edge* Pointer;
EdgeIterator() {}
EdgeIterator(const EdgeIterator &other): Super(other) {}
EdgeIterator& operator=(const EdgeIterator &other) { this->Super::operator=(other); return *this; }
Edge& operator*() const { return this->dereference(); }
Edge* operator->() const { return &this->dereference(); }
private:
Expand All @@ -952,6 +954,7 @@ class Graph {
ConstEdgeIterator() {}
ConstEdgeIterator(const ConstEdgeIterator &other): Super(other) {}
ConstEdgeIterator(const EdgeIterator &other): Super(other.phase_, other.iter_, other.vlist_) {}
ConstEdgeIterator& operator=(const ConstEdgeIterator &other) { this->Super::operator=(other); return *this; }
const Edge& operator*() const { return this->dereference(); }
const Edge* operator->() const { return &this->dereference(); }
private:
Expand All @@ -977,6 +980,7 @@ class Graph {
EdgeValueIterator() {}
EdgeValueIterator(const EdgeValueIterator &other): Super(other) {}
EdgeValueIterator(const EdgeIterator &other): Super(other.phase_, other.iter_, other.vlist_) {}
EdgeValueIterator& operator=(const EdgeValueIterator &other) { this->Super::operator=(other); return *this; }
EdgeValue& operator*() const { return this->dereference().value(); }
EdgeValue* operator->() const { return &this->dereference().value(); }
private:
Expand Down Expand Up @@ -1004,6 +1008,7 @@ class Graph {
ConstEdgeValueIterator(const EdgeValueIterator &other): Super(other.phase_, other.iter_, other.vlist_) {}
ConstEdgeValueIterator(const EdgeIterator &other): Super(other.phase_, other.iter_, other.vlist_) {}
ConstEdgeValueIterator(const ConstEdgeIterator &other): Super(other.phase_, other.iter_, other.vlist_) {}
ConstEdgeValueIterator& operator=(const EdgeValueIterator &other) { this->Super::operator=(other); return *this; }
const EdgeValue& operator*() const { return this->dereference().value(); }
const EdgeValue* operator->() const { return &this->dereference().value(); }
private:
Expand All @@ -1027,6 +1032,7 @@ class Graph {
typedef Vertex* Pointer;
VertexIterator() {}
VertexIterator(const VertexIterator &other): Super(other) {}
VertexIterator& operator=(const VertexIterator &other) { this->Super::operator=(other); return *this; }
Vertex& operator*() const { return this->dereference(); }
Vertex* operator->() const { return &this->dereference(); }
private:
Expand All @@ -1049,6 +1055,7 @@ class Graph {
ConstVertexIterator() {}
ConstVertexIterator(const ConstVertexIterator &other): Super(other) {}
ConstVertexIterator(const VertexIterator &other): Super(other.base_) {}
ConstVertexIterator& operator=(const ConstVertexIterator &other) { this->Super::operator=(other); return *this; }
const Vertex& operator*() const { return this->dereference(); }
const Vertex* operator->() const { return &this->dereference(); }
private:
Expand All @@ -1072,6 +1079,7 @@ class Graph {
VertexValueIterator() {}
VertexValueIterator(const VertexValueIterator &other): Super(other) {}
VertexValueIterator(const VertexIterator &other): Super(other.base_) {}
VertexValueIterator& operator=(const VertexValueIterator &other) { this->Super::operator=(other); return *this; }
VertexValue& operator*() const { return this->dereference().value(); }
VertexValue* operator->() const { return &this->dereference().value(); }
private:
Expand All @@ -1096,6 +1104,7 @@ class Graph {
ConstVertexValueIterator(const VertexValueIterator &other): Super(other.base_) {}
ConstVertexValueIterator(const VertexIterator &other): Super(other.base_) {}
ConstVertexValueIterator(const ConstVertexIterator &other): Super(other.base_) {}
ConstVertexValueIterator& operator=(const ConstVertexValueIterator &other) { this->Super::operator=(other); return *this; }
const VertexValue& operator*() const { return this->dereference().value(); }
const VertexValue* operator->() const { return &this->dereference().value(); }
private:
Expand Down
5 changes: 5 additions & 0 deletions src/util/Sawyer/IndexedList.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ class IndexedList {
IteratorBase(const IteratorBase &other): base_(other.base_) {}
IteratorBase(const BaseIterator &base): base_(base) {}
public:
IteratorBase& operator=(const IteratorBase &other) { base_ = other.base_; return *this; }
bool isAtEnd() const { return base_->isHead(); }
Derived& operator++() { base_ = base_->next; return *derived(); }
Derived operator++(int) { Derived old(this->base_); base_ = base_->next; return old; }
Expand Down Expand Up @@ -211,6 +212,7 @@ class IndexedList {
public:
NodeIterator() {}
NodeIterator(const NodeIterator &other): Super(other) {}
NodeIterator& operator=(const NodeIterator &other) { this->Super::operator=(other); return *this; }
Node& operator*() const { return this->base_->dereference(); }
Node* operator->() const { return &this->base_->dereference(); }
private:
Expand Down Expand Up @@ -239,6 +241,7 @@ class IndexedList {
ConstNodeIterator() {}
ConstNodeIterator(const ConstNodeIterator &other): Super(other) {}
ConstNodeIterator(const NodeIterator &other): Super(other.base()) {}
ConstNodeIterator& operator=(const ConstNodeIterator &other) { this->Super::operator=(other); return *this; }
const Node& operator*() const { return this->base_->dereference(); }
const Node* operator->() const { return &this->base_->dereference(); }
private:
Expand All @@ -263,6 +266,7 @@ class IndexedList {
ValueIterator() {}
ValueIterator(const ValueIterator &other): Super(other) {}
ValueIterator(const NodeIterator &other): Super(other.base()) {}
ValueIterator& operator=(const ValueIterator &other) { this->Super::operator=(other); return *this; }
Value& operator*() const { return this->base()->dereference().value(); }
Value* operator->() const { return &this->base()->dereference().value(); }
private:
Expand All @@ -289,6 +293,7 @@ class IndexedList {
ConstValueIterator(const NodeIterator &other): Super(other.base()) {}
ConstValueIterator(const ConstNodeIterator &other): Super(other.base()) {}
ConstValueIterator(const ValueIterator &other): Super(other.base()) {}
ConstValueIterator& operator=(const ConstValueIterator &other) { this->Super::operator=(other); return *this; }
const Value& operator*() const { return this->base()->dereference().value(); }
const Value* operator->() const { return &this->base()->dereference().value(); }
private:
Expand Down
25 changes: 25 additions & 0 deletions src/util/Sawyer/Map.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,11 @@ class Map {
BaseIterator base_;
BidirectionalIterator() {}
BidirectionalIterator(const BaseIterator &base): base_(base) {}
BidirectionalIterator(const BidirectionalIterator &other): base_(other.base_) {}

public:
Derived& operator=(const Derived &other) { base_ = other.base_; return *derived(); }
BidirectionalIterator& operator=(const BidirectionalIterator &other) { base_ = other.base; return *this; }

/** Pre-increment to next iterator position. */
Derived& operator++() { ++base_; return *derived(); }
Expand Down Expand Up @@ -171,6 +174,9 @@ class Map {
/** Copy constructor. */
NodeIterator(const NodeIterator &other): Super(other) {}

/** Assignment. */
NodeIterator& operator=(const NodeIterator &other) { this->Super::operator=(other); return *this; }

// std::map stores std::pair nodes, but we want to return Node, which must have the same layout.
/** Dereference iterator to return a storage node. */
Node& operator*() const { return *(Node*)&*this->base_; }
Expand All @@ -197,6 +203,9 @@ class Map {
/** Copy constructor. */
ConstNodeIterator(const NodeIterator &other): Super(typename StlMap::const_iterator(other.base())) {}

/** Assignment. */
ConstNodeIterator& operator=(const ConstNodeIterator &other) { this->Super::operator=(other); return *this; }

// std::map stores std::pair nodes, but we want to return Node, which must have the same layout.
/** Dereference iterator to return a storage node. */
const Node& operator*() const { return *(const Node*)&*this->base_; }
Expand Down Expand Up @@ -227,6 +236,9 @@ class Map {
/** Copy constructor. */
ConstKeyIterator(const ConstNodeIterator &other): Super(other.base()) {}

/** Assignment. */
ConstKeyIterator& operator=(const ConstKeyIterator &other) { this->Super::operator=(other); return *this; }

/** Dereference iterator to return the interval of the storage node. */
const Key& operator*() const { return this->base()->first; }

Expand All @@ -249,6 +261,9 @@ class Map {
/** Copy constructor. */
ValueIterator(const NodeIterator &other): Super(other.base()) {}

/** Assignment. */
ValueIterator& operator=(const ValueIterator &other) { this->Super::operator=(other); return *this; }

/** Dereference iterator to return the value of the storage node. */
Value& operator*() const { return this->base()->second; }

Expand Down Expand Up @@ -277,6 +292,9 @@ class Map {
/** Copy constructor. */
ConstValueIterator(const NodeIterator &other): Super(typename StlMap::const_iterator(other.base())) {}

/** Assignment. */
ConstValueIterator& operator=(const ConstValueIterator &other) { this->Super::operator=(other); return *this; }

/** Dereference iterator to return the value of the storage node. */
const Value& operator*() const { return this->base()->second; }

Expand Down Expand Up @@ -318,6 +336,13 @@ class Map {
map_.insert(map_.end(), std::make_pair(Key(otherIter->key()), Value(otherIter->value())));
}

Map& operator=(const Map &other) {
clear();
for (const auto &node: other.nodes())
map_.insert(map_.end(), std::make_pair(node.key(), node.value()));
return *this;
}

/** Make this map be a copy of another map.
*
* The keys and values of the @p other map must be convertible to the types used for this map. */
Expand Down
Loading

0 comments on commit 1405052

Please sign in to comment.