mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-25 17:11:59 +00:00
move code into src
This commit is contained in:
parent
ec3d522095
commit
695048baa7
184
bitfield.h
184
bitfield.h
@ -1,184 +0,0 @@
|
||||
//---------------------------------------------------------
|
||||
// For conditions of distribution and use, see
|
||||
// https://github.com/preshing/cpp11-on-multicore/blob/master/LICENSE
|
||||
//---------------------------------------------------------
|
||||
|
||||
#ifndef __CPP11OM_BITFIELD_H__
|
||||
#define __CPP11OM_BITFIELD_H__
|
||||
|
||||
#include <cassert>
|
||||
|
||||
|
||||
//---------------------------------------------------------
|
||||
// BitFieldMember<>: Used internally by ADD_BITFIELD_MEMBER macro.
|
||||
// All members are public to simplify compliance with sections 9.0.7 and
|
||||
// 9.5.1 of the C++11 standard, thereby avoiding undefined behavior.
|
||||
//---------------------------------------------------------
|
||||
template <typename T, int Offset, int Bits>
|
||||
struct BitFieldMember
|
||||
{
|
||||
T value;
|
||||
|
||||
static_assert(Offset + Bits <= (int) sizeof(T) * 8, "Member exceeds bitfield boundaries");
|
||||
static_assert(Bits < (int) sizeof(T) * 8, "Can't fill entire bitfield with one member");
|
||||
|
||||
static const T Maximum = (T(1) << Bits) - 1;
|
||||
static const T Mask = Maximum << Offset;
|
||||
T maximum() const { return Maximum; }
|
||||
T one() const { return T(1) << Offset; }
|
||||
|
||||
operator T() const
|
||||
{
|
||||
return (value >> Offset) & Maximum;
|
||||
}
|
||||
|
||||
BitFieldMember& operator=(T v)
|
||||
{
|
||||
assert(v <= Maximum); // v must fit inside the bitfield member
|
||||
value = (value & ~Mask) | (v << Offset);
|
||||
return *this;
|
||||
}
|
||||
|
||||
BitFieldMember& operator+=(T v)
|
||||
{
|
||||
assert(T(*this) + v <= Maximum); // result must fit inside the bitfield member
|
||||
value += v << Offset;
|
||||
return *this;
|
||||
}
|
||||
|
||||
BitFieldMember& operator-=(T v)
|
||||
{
|
||||
assert(T(*this) >= v); // result must not underflow
|
||||
value -= v << Offset;
|
||||
return *this;
|
||||
}
|
||||
|
||||
BitFieldMember& operator++() { return *this += 1; }
|
||||
BitFieldMember operator++(int) // postfix form
|
||||
{
|
||||
BitFieldMember tmp(*this);
|
||||
operator++();
|
||||
return tmp;
|
||||
}
|
||||
BitFieldMember& operator--() { return *this -= 1; }
|
||||
BitFieldMember operator--(int) // postfix form
|
||||
{
|
||||
BitFieldMember tmp(*this);
|
||||
operator--();
|
||||
return tmp;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//---------------------------------------------------------
|
||||
// BitFieldArray<>: Used internally by ADD_BITFIELD_ARRAY macro.
|
||||
// All members are public to simplify compliance with sections 9.0.7 and
|
||||
// 9.5.1 of the C++11 standard, thereby avoiding undefined behavior.
|
||||
//---------------------------------------------------------
|
||||
template <typename T, int BaseOffset, int BitsPerItem, int NumItems>
|
||||
struct BitFieldArray
|
||||
{
|
||||
T value;
|
||||
|
||||
static_assert(BaseOffset + BitsPerItem * NumItems <= (int) sizeof(T) * 8, "Array exceeds bitfield boundaries");
|
||||
static_assert(BitsPerItem < (int) sizeof(T) * 8, "Can't fill entire bitfield with one array element");
|
||||
|
||||
static const T Maximum = (T(1) << BitsPerItem) - 1;
|
||||
T maximum() const { return Maximum; }
|
||||
int numItems() const { return NumItems; }
|
||||
|
||||
class Element
|
||||
{
|
||||
private:
|
||||
T& value;
|
||||
int offset;
|
||||
|
||||
public:
|
||||
Element(T& value, int offset) : value(value), offset(offset) {}
|
||||
T mask() const { return Maximum << offset; }
|
||||
|
||||
operator T() const
|
||||
{
|
||||
return (value >> offset) & Maximum;
|
||||
}
|
||||
|
||||
Element& operator=(T v)
|
||||
{
|
||||
assert(v <= Maximum); // v must fit inside the bitfield member
|
||||
value = (value & ~mask()) | (v << offset);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Element& operator+=(T v)
|
||||
{
|
||||
assert(T(*this) + v <= Maximum); // result must fit inside the bitfield member
|
||||
value += v << offset;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Element& operator-=(T v)
|
||||
{
|
||||
assert(T(*this) >= v); // result must not underflow
|
||||
value -= v << offset;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Element& operator++() { return *this += 1; }
|
||||
Element operator++(int) // postfix form
|
||||
{
|
||||
Element tmp(*this);
|
||||
operator++();
|
||||
return tmp;
|
||||
}
|
||||
Element& operator--() { return *this -= 1; }
|
||||
Element operator--(int) // postfix form
|
||||
{
|
||||
Element tmp(*this);
|
||||
operator--();
|
||||
return tmp;
|
||||
}
|
||||
};
|
||||
|
||||
Element operator[](int i)
|
||||
{
|
||||
assert(i >= 0 && i < NumItems); // array index must be in range
|
||||
return Element(value, BaseOffset + BitsPerItem * i);
|
||||
}
|
||||
|
||||
const Element operator[](int i) const
|
||||
{
|
||||
assert(i >= 0 && i < NumItems); // array index must be in range
|
||||
return Element(value, BaseOffset + BitsPerItem * i);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//---------------------------------------------------------
|
||||
// Bitfield definition macros.
|
||||
// For usage examples, see RWLock and LockReducedDiningPhilosophers.
|
||||
// All members are public to simplify compliance with sections 9.0.7 and
|
||||
// 9.5.1 of the C++11 standard, thereby avoiding undefined behavior.
|
||||
//---------------------------------------------------------
|
||||
#define BEGIN_BITFIELD_TYPE(typeName, T) \
|
||||
union typeName \
|
||||
{ \
|
||||
struct Wrapper { T value; }; \
|
||||
Wrapper wrapper; \
|
||||
typeName(T v = 0) { wrapper.value = v; } \
|
||||
typeName& operator=(T v) { wrapper.value = v; return *this; } \
|
||||
operator T&() { return wrapper.value; } \
|
||||
operator T() const { return wrapper.value; } \
|
||||
typedef T StorageType;
|
||||
|
||||
#define ADD_BITFIELD_MEMBER(memberName, offset, bits) \
|
||||
BitFieldMember<StorageType, offset, bits> memberName;
|
||||
|
||||
#define ADD_BITFIELD_ARRAY(memberName, offset, bits, numItems) \
|
||||
BitFieldArray<StorageType, offset, bits, numItems> memberName;
|
||||
|
||||
#define END_BITFIELD_TYPE() \
|
||||
};
|
||||
|
||||
|
||||
#endif // __CPP11OM_BITFIELD_H__
|
||||
|
@ -1,2 +0,0 @@
|
||||
#define DOCTEST_CONFIG_IMPLEMENT
|
||||
#include "third_party/doctest/doctest/doctest.h"
|
@ -5,7 +5,7 @@
|
||||
#include <thread>
|
||||
|
||||
#include "platform.h"
|
||||
#include "../utils.h"
|
||||
#include "utils.h"
|
||||
#include "../third_party/doctest/doctest/doctest.h"
|
||||
|
||||
namespace {
|
||||
|
@ -4,17 +4,17 @@
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
// TODO: cleanup includes
|
||||
#include "compilation_database_loader.h"
|
||||
#include "indexer.h"
|
||||
#include "query.h"
|
||||
#include "language_server_api.h"
|
||||
#include "test.h"
|
||||
#include "timer.h"
|
||||
#include "threaded_queue.h"
|
||||
#include "typed_bidi_message_queue.h"
|
||||
|
||||
#include "src/timer.h"
|
||||
#include "src/threaded_queue.h"
|
||||
#include "src/typed_bidi_message_queue.h"
|
||||
|
||||
#include "third_party/doctest/doctest/doctest.h"
|
||||
#include "../third_party/doctest/doctest/doctest.h"
|
||||
|
||||
#include <rapidjson/istreamwrapper.h>
|
||||
#include <rapidjson/ostreamwrapper.h>
|
2
src/doctest_impl.cc
Normal file
2
src/doctest_impl.cc
Normal file
@ -0,0 +1,2 @@
|
||||
#define DOCTEST_CONFIG_IMPLEMENT
|
||||
#include "../third_party/doctest/doctest/doctest.h"
|
@ -10,7 +10,6 @@
|
||||
#include "libclangmm/clangmm.h"
|
||||
#include "libclangmm/Utility.h"
|
||||
|
||||
#include "bitfield.h"
|
||||
#include "utils.h"
|
||||
#include "optional.h"
|
||||
#include "serializer.h"
|
@ -7,7 +7,7 @@
|
||||
|
||||
#include "platform.h"
|
||||
#include "resizable_buffer.h"
|
||||
#include "../utils.h"
|
||||
#include "utils.h"
|
||||
#include "../third_party/doctest/doctest/doctest.h"
|
||||
|
||||
// TODO: figure out a logging solution
|
||||
|
@ -1,7 +1,7 @@
|
||||
#if defined(__linux__) || defined(__APPLE__)
|
||||
#include "platform.h"
|
||||
|
||||
#include "../utils.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <string>
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include <string>
|
||||
#include <Windows.h>
|
||||
|
||||
#include "../utils.h"
|
||||
#include "utils.h"
|
||||
|
||||
namespace {
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
#include "test.h"
|
||||
|
||||
#include "indexer.h"
|
||||
#include "platform.h"
|
||||
#include "serializer.h"
|
||||
#include "utils.h"
|
||||
#include "src/platform.h"
|
||||
|
||||
void Write(const std::vector<std::string>& strs) {
|
||||
for (const std::string& str : strs)
|
@ -6,7 +6,7 @@
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
|
||||
#include "../optional.h"
|
||||
#include "optional.h"
|
||||
|
||||
// A threadsafe-queue. http://stackoverflow.com/a/16075550
|
||||
template <class T>
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
#include "buffer.h"
|
||||
#include "message_queue.h"
|
||||
#include "../serializer.h"
|
||||
#include "serializer.h"
|
||||
|
||||
// TypedBidiMessageQueue provides a type-safe server/client implementation on
|
||||
// top of a couple MessageQueue instances.
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#include "tinydir.h"
|
||||
#include "../third_party/tinydir.h"
|
||||
|
||||
static std::vector<std::string> GetFilesInFolderHelper(std::string folder, bool recursive, std::string output_prefix) {
|
||||
std::vector<std::string> result;
|
Loading…
Reference in New Issue
Block a user