astyle formatting

This commit is contained in:
Daniel Marjamäki 2021-06-14 07:39:41 +02:00
parent c27c513b60
commit a7707a457d
2 changed files with 40 additions and 22 deletions

View File

@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
#ifndef tokenrangeH
#define tokenrangeH
//---------------------------------------------------------------------------
@ -24,16 +24,14 @@
#include "config.h"
template<typename T, REQUIRES("T must be a Token class", std::is_convertible<T*, const Token*>)>
class TokenRangeBase
{
class TokenRangeBase {
T* mFront;
T* mBack;
public:
TokenRangeBase(T* front, T* back) : mFront(front), mBack(back) {}
struct TokenIterator
{
struct TokenIterator {
using iterator_category = std::forward_iterator_tag;
using value_type = T*;
using difference_type = std::ptrdiff_t;
@ -43,14 +41,27 @@ public:
T* mt;
TokenIterator() : mt(nullptr) {}
explicit TokenIterator(T* t) : mt(t) {}
TokenIterator& operator++() { mt = mt->next(); return *this; }
bool operator==(const TokenIterator& b) const { return mt == b.mt; }
bool operator!=(const TokenIterator& b) const { return mt != b.mt; }
T* operator*() const { return mt; }
TokenIterator& operator++() {
mt = mt->next();
return *this;
}
bool operator==(const TokenIterator& b) const {
return mt == b.mt;
}
bool operator!=(const TokenIterator& b) const {
return mt != b.mt;
}
T* operator*() const {
return mt;
}
};
TokenIterator begin() const { return TokenIterator(mFront); }
TokenIterator end() const { return TokenIterator(mBack); }
TokenIterator begin() const {
return TokenIterator(mFront);
}
TokenIterator end() const {
return TokenIterator(mBack);
}
};
class TokenRange : public TokenRangeBase<Token> {

View File

@ -46,13 +46,13 @@ private:
TEST_CASE(exampleAlgorithms);
}
std::string testTokenRange(ConstTokenRange range, const Token* start, const Token* end) const
{
auto tokenToString = [](const Token* t) { return t ? t->str() : "<null>"; };
std::string testTokenRange(ConstTokenRange range, const Token* start, const Token* end) const {
auto tokenToString = [](const Token* t) {
return t ? t->str() : "<null>";
};
int index = 0;
const Token* expected = start;
for (const Token* t : range)
{
for (const Token* t : range) {
if (expected != t) {
std::ostringstream message;
message << "Failed to match token " << tokenToString(expected) << " at position " << index << ". Got " << tokenToString(t) << " instead";
@ -111,8 +111,7 @@ private:
const Scope& scope = *std::next(sd->scopeList.begin(), 3); //The scope of the if block
std::ostringstream contents;
for (const Token* t : ConstTokenRange{ scope.bodyStart->next(), scope.bodyEnd })
{
for (const Token* t : ConstTokenRange{ scope.bodyStart->next(), scope.bodyEnd }) {
contents << t->str();
}
ASSERT_EQUALS("a();", contents.str());
@ -123,10 +122,18 @@ private:
TokenList tokenList(nullptr);
tokenList.createTokens(istr, "test.cpp");
ConstTokenRange range{ tokenList.front(), nullptr };
ASSERT_EQUALS(true, std::all_of(range.begin(), range.end(), [](const Token*) {return true;}));
ASSERT_EQUALS(true, std::any_of(range.begin(), range.end(), [](const Token* t) {return t->str() == "true";}));
ASSERT_EQUALS("true", (*std::find_if(range.begin(), range.end(), [](const Token* t) {return t->str() == "true";}))->str());
ASSERT_EQUALS(3, std::count_if(range.begin(), range.end(), [](const Token* t) {return t->str() == "{";}));
ASSERT_EQUALS(true, std::all_of(range.begin(), range.end(), [](const Token*) {
return true;
}));
ASSERT_EQUALS(true, std::any_of(range.begin(), range.end(), [](const Token* t) {
return t->str() == "true";
}));
ASSERT_EQUALS("true", (*std::find_if(range.begin(), range.end(), [](const Token* t) {
return t->str() == "true";
}))->str());
ASSERT_EQUALS(3, std::count_if(range.begin(), range.end(), [](const Token* t) {
return t->str() == "{";
}));
}
};