Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.kdev4
build
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I usually use out-of-source builds (i.e. I make the build directory a sibling not a child of the project directory), but why not.

11 changes: 6 additions & 5 deletions src/CgStr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,31 @@
#include <cassert>
#include <ostream>
#include <string>
#include <utility>

namespace synth {

class CgStr {
class CgStr final {
public:
CgStr(CXString&& s)
: m_data(s)
: m_data(std::move(s))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since CXString comes from a C library, it is a POD. But nonetheless moving is OK as documentation. 👍

{ }

CgStr(CgStr&& other)
CgStr(CgStr&& other) noexcept
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good point! 👍

: m_data(std::move(other.m_data))
{
other.m_data.data = nullptr;
}

CgStr& operator=(CgStr&& other) {
CgStr& operator=(CgStr&& other) noexcept {
destroy();
m_data = std::move(other.m_data);
other.m_data.data = nullptr; // HACK Undocumented behavior.
assert(!other.valid());
return *this;
}

~CgStr() {
~CgStr() noexcept {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to rely on C++11's default noexcept for destructors, so that if I ever have a noexcept(false) dtor, it sticks out even more. So please remove that one.

destroy();
}

Expand Down
5 changes: 4 additions & 1 deletion src/FileIdSupport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include <clang-c/Index.h>
#include <algorithm>
#include <iterator>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

#include <functional>

namespace std {
template <>
Expand Down Expand Up @@ -30,7 +32,8 @@ namespace std {
return std::equal(
std::begin(lhs.data),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? Both are fixed size C arrays.

std::end(lhs.data),
std::begin(rhs.data));
std::begin(rhs.data),
std::end(rhs.data));
}
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/MultiTuProcessor.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef SYNTH_MULTI_TU_PROCESSOR_HPP_INCLUDED
#define SYNTH_MULTI_TU_PROCESSOR_HPP_INCLUDED

#include "fileidsupport.hpp"
#include "FileIdSupport.hpp"
#include "output.hpp"

#include <boost/filesystem/path.hpp>
Expand Down Expand Up @@ -84,7 +84,7 @@ class MultiTuProcessor {
// Common prefix of all keys in m_dirs
fs::path m_rootInDir;

std::mutex m_mut;
mutable std::mutex m_mut;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I never thought about that, good point! 👍

};

} // namespace synth
Expand Down
2 changes: 1 addition & 1 deletion src/annotate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "CgStr.hpp"
#include "MultiTuProcessor.hpp"
#include "cgWrappers.hpp"
#include "fileIdSupport.hpp"
#include "FileIdSupport.hpp"
#include "highlight.hpp"
#include "output.hpp"
#include "xref.hpp"
Expand Down
10 changes: 5 additions & 5 deletions src/cgWrappers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@

namespace synth {

class CgTokensHandle {
class CgTokensHandle final {
public:
CgTokensHandle(CXToken* data, unsigned ntokens, CXTranslationUnit tu_)
: m_data(data), m_ntokens(ntokens), m_tu(tu_)
{}

~CgTokensHandle() { destroy(); }
~CgTokensHandle() noexcept { destroy(); }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As before: I do not like explicit noexcept for destructors.


CgTokensHandle(CgTokensHandle&& other)
CgTokensHandle(CgTokensHandle&& other) noexcept
: m_data(other.m_data)
, m_ntokens(other.m_ntokens)
, m_tu(other.m_tu)
{
other.release();
}

CgTokensHandle& operator= (CgTokensHandle&& other)
CgTokensHandle& operator= (CgTokensHandle&& other) noexcept
{
destroy();
m_data = other.m_data;
Expand All @@ -40,7 +40,7 @@ class CgTokensHandle {

CXTranslationUnit tu() const { return m_tu; }
unsigned size() const { return m_ntokens; }
CXToken* tokens() { return m_data; }
CXToken* tokens() const { return m_data; }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving out const was intentional here: I don't want to provide a mutable handle to data in a const object.

But thinking about it, libclang provides no way to modify a CXToken so it is immutable anyway, thus 👍 on that.


private:
void destroy()
Expand Down
3 changes: 2 additions & 1 deletion src/cmdline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <cstring>
#include <stdexcept>
#include <thread>
#include <utility>

using namespace synth;

Expand Down Expand Up @@ -77,7 +78,7 @@ CmdLineArgs CmdLineArgs::parse(int argc, char const* const* argv)
throw std::runtime_error("Superfluous commandline arguments.");

if (r.nThreads == 0)
r.nThreads = std::thread::hardware_concurrency();
r.nThreads = std::max(std::thread::hardware_concurrency(), 1u);
for (auto& dir : r.inOutDirs) {
if (!dir.second)
dir.second = ".";
Expand Down
2 changes: 1 addition & 1 deletion src/highlight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using namespace synth;


unsigned const kMaxRefRecursion = 16;
static unsigned const kMaxRefRecursion = 16;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const at namespace level already implies static in C++. See http://stackoverflow.com/a/178259/2128694.


static bool isTypeKind(CXCursorKind k)
{
Expand Down