Skip to content

Commit

Permalink
Run clang-format.
Browse files Browse the repository at this point in the history
  • Loading branch information
rnburn committed Jul 13, 2018
1 parent f4a4316 commit 3ef4f29
Show file tree
Hide file tree
Showing 12 changed files with 161 additions and 66 deletions.
96 changes: 96 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
---
Language: Cpp
# BasedOnStyle: Google
AccessModifierOffset: -1
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: true
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: true
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
IncludeCategories:
- Regex: '^<.*\.h>'
Priority: 1
- Regex: '^<.*'
Priority: 2
- Regex: '.*'
Priority: 3
IncludeIsMainRegex: '([-_](test|unittest))?$'
IndentCaseLabels: true
IndentWidth: 2
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: false
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
TabWidth: 8
UseTab: Never
...

3 changes: 3 additions & 0 deletions scripts/run_clang_format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
find . -path ./3rd_party -prune -o \( -name '*.h' -or -name '*.cpp' \) \
-exec clang-format -i {} \;
1 change: 0 additions & 1 deletion src/carrier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ opentracing::expected<void> LuaCarrierWriter::Set(
LuaCarrierReader::LuaCarrierReader(lua_State* lua_state) noexcept
: lua_state_{lua_state} {}


//------------------------------------------------------------------------------
// ForeachKey
//------------------------------------------------------------------------------
Expand Down
27 changes: 13 additions & 14 deletions src/carrier.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,32 @@
#include <opentracing/propagation.h>

extern "C" {
#include <lua.h>
#include <lauxlib.h>
} // extern "C"
#include <lua.h>
} // extern "C"

namespace lua_bridge_tracer {
class LuaCarrierWriter : public opentracing::HTTPHeadersWriter {
public:
explicit LuaCarrierWriter(lua_State* lua_state) noexcept;
explicit LuaCarrierWriter(lua_State* lua_state) noexcept;

opentracing::expected<void> Set(
opentracing::string_view key,
opentracing::string_view value) const final;
opentracing::expected<void> Set(opentracing::string_view key,
opentracing::string_view value) const final;

private:
lua_State* lua_state_;
};

class LuaCarrierReader : public opentracing::HTTPHeadersReader {
public:
explicit LuaCarrierReader(lua_State* lua_state) noexcept;
public:
explicit LuaCarrierReader(lua_State* lua_state) noexcept;

opentracing::expected<void> ForeachKey(
std::function<opentracing::expected<void>(opentracing::string_view key,
opentracing::string_view value)>
f) const final;
opentracing::expected<void> ForeachKey(
std::function<opentracing::expected<void>(opentracing::string_view key,
opentracing::string_view value)>
f) const final;

private:
lua_State* lua_state_;
private:
lua_State* lua_state_;
};
} // namespace lua_bridge_tracer
20 changes: 9 additions & 11 deletions src/dynamic_tracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ namespace {
class DynamicSpan : public opentracing::Span {
public:
DynamicSpan(std::shared_ptr<opentracing::Tracer> tracer,
std::unique_ptr<opentracing::Span>&& span) noexcept
std::unique_ptr<opentracing::Span>&& span) noexcept
: tracer_{tracer}, span_{std::move(span)} {}

private:
std::shared_ptr<opentracing::Tracer> tracer_;
std::unique_ptr<opentracing::Span> span_;

void FinishWithOptions(const opentracing::FinishSpanOptions&
finish_span_options) noexcept final {
finish_span_options) noexcept final {
span_->FinishWithOptions(finish_span_options);
}

Expand All @@ -29,12 +29,12 @@ class DynamicSpan : public opentracing::Span {
}

void SetTag(opentracing::string_view key,
const opentracing::Value& value) noexcept final {
const opentracing::Value& value) noexcept final {
span_->SetTag(key, value);
}

void SetBaggageItem(opentracing::string_view restricted_key,
opentracing::string_view value) noexcept final {
opentracing::string_view value) noexcept final {
span_->SetBaggageItem(restricted_key, value);
}

Expand All @@ -44,8 +44,8 @@ class DynamicSpan : public opentracing::Span {
}

void Log(std::initializer_list<
std::pair<opentracing::string_view, opentracing::Value>>
fields) noexcept final {
std::pair<opentracing::string_view, opentracing::Value>>
fields) noexcept final {
span_->Log(fields);
}

Expand Down Expand Up @@ -124,17 +124,15 @@ class DynamicTracer : public opentracing::Tracer,
return reader.Extract(*tracer_);
}

void Close() noexcept final {
tracer_->Close();
}
void Close() noexcept final { tracer_->Close(); }
};
} // namespace

//------------------------------------------------------------------------------
// make_dynamic_tracer
//------------------------------------------------------------------------------
std::shared_ptr<opentracing::Tracer> load_tracer(const char* library_name,
const char* config) {
const char* config) {
std::string error_message;
auto handle_maybe =
opentracing::DynamicallyLoadTracingLibrary(library_name, error_message);
Expand All @@ -147,6 +145,6 @@ std::shared_ptr<opentracing::Tracer> load_tracer(const char* library_name,
throw std::runtime_error{error_message};
}
return std::make_shared<DynamicTracer>(std::move(handle),
std::move(*tracer_maybe));
std::move(*tracer_maybe));
}
} // namespace lua_bridge_tracer
4 changes: 2 additions & 2 deletions src/dynamic_tracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
#include <opentracing/tracer.h>

namespace lua_bridge_tracer {
std::shared_ptr<opentracing::Tracer> load_tracer(
const char* tracer_library, const char* config);
std::shared_ptr<opentracing::Tracer> load_tracer(const char* tracer_library,
const char* config);
} // namespace lua_bridge_tracer
4 changes: 2 additions & 2 deletions src/lua_class_description.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#include <initializer_list>

extern "C" {
#include <lua.h>
#include <lauxlib.h>
} // extern "C"
#include <lua.h>
} // extern "C"

namespace lua_bridge_tracer {
struct LuaClassDescription {
Expand Down
4 changes: 2 additions & 2 deletions src/lua_span.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ int LuaSpan::set_baggage_item(lua_State* L) noexcept {
auto value_data = luaL_checklstring(L, 3, &key_len);
try {
span->span_->SetBaggageItem({key_data, key_len}, {value_data, value_len});
} catch(const std::exception& e) {
} catch (const std::exception& e) {
lua_pushstring(L, e.what());
}
return lua_error(L);
Expand All @@ -144,7 +144,7 @@ int LuaSpan::get_baggage_item(lua_State* L) noexcept {
auto baggage_item = span->span_->BaggageItem({key_data, key_len});
lua_pushstring(L, baggage_item.c_str());
return 1;
} catch(const std::exception& e) {
} catch (const std::exception& e) {
lua_pushstring(L, e.what());
}
return lua_error(L);
Expand Down
11 changes: 5 additions & 6 deletions src/lua_tracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,22 @@
#include <memory>

extern "C" {
#include <lua.h>
#include <lauxlib.h>
} // extern "C"
#include <lua.h>
} // extern "C"

namespace lua_bridge_tracer {
class LuaTracer {
public:
explicit LuaTracer(const std::shared_ptr<opentracing::Tracer>& tracer)
: tracer_{tracer}
{}
explicit LuaTracer(const std::shared_ptr<opentracing::Tracer>& tracer)
: tracer_{tracer} {}

static const LuaClassDescription description;
static int new_lua_tracer(lua_State* L) noexcept;

private:
std::shared_ptr<opentracing::Tracer> tracer_;


static int free(lua_State* L) noexcept;

static int start_span(lua_State* L) noexcept;
Expand Down
2 changes: 1 addition & 1 deletion src/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#include <iterator>

extern "C" {
#include <lua.h>
#include <lauxlib.h>
#include <lua.h>
} // extern "C"

static void setfuncs(lua_State* L, const luaL_Reg* l, int nup) {
Expand Down
48 changes: 24 additions & 24 deletions src/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ size_t get_table_len(lua_State* L, int index) {
//------------------------------------------------------------------------------
// convert_timestamp
//------------------------------------------------------------------------------
std::chrono::system_clock::time_point convert_timestamp(lua_State* L, int index) {
std::chrono::system_clock::time_point convert_timestamp(lua_State* L,
int index) {
using SystemClock = std::chrono::system_clock;
switch (lua_type(L, index)) {
case LUA_TNUMBER:
Expand All @@ -40,30 +41,29 @@ std::chrono::system_clock::time_point convert_timestamp(lua_State* L, int index)
static opentracing::Value to_dictionary_value(lua_State* L, int index);

opentracing::Value to_value(lua_State* L, int index) {
switch (lua_type(L, index)) {
case LUA_TNUMBER: {
return static_cast<double>(lua_tonumber(L, index));
}
case LUA_TSTRING: {
size_t value_len;
auto value_data = lua_tolstring(L, index, &value_len);
std::string value{value_data, value_len};
return std::move(value);
}
case LUA_TBOOLEAN: {
return static_cast<bool>(lua_toboolean(L, index));
}
case LUA_TTABLE: {
return to_dictionary_value(L, index);
}
case LUA_TNIL:
case LUA_TNONE: {
return nullptr;
}
default:
throw std::runtime_error{"invalid value type"};
switch (lua_type(L, index)) {
case LUA_TNUMBER: {
return static_cast<double>(lua_tonumber(L, index));
}

case LUA_TSTRING: {
size_t value_len;
auto value_data = lua_tolstring(L, index, &value_len);
std::string value{value_data, value_len};
return std::move(value);
}
case LUA_TBOOLEAN: {
return static_cast<bool>(lua_toboolean(L, index));
}
case LUA_TTABLE: {
return to_dictionary_value(L, index);
}
case LUA_TNIL:
case LUA_TNONE: {
return nullptr;
}
default:
throw std::runtime_error{"invalid value type"};
}
}

//------------------------------------------------------------------------------
Expand Down
7 changes: 4 additions & 3 deletions src/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
#include <chrono>

extern "C" {
#include <lua.h>
#include <lauxlib.h>
} // extern "C"
#include <lua.h>
} // extern "C"

namespace lua_bridge_tracer {
size_t get_table_len(lua_State* L, int index);

std::chrono::system_clock::time_point convert_timestamp(lua_State* L, int index);
std::chrono::system_clock::time_point convert_timestamp(lua_State* L,
int index);

opentracing::Value to_value(lua_State* L, int index);

Expand Down

0 comments on commit 3ef4f29

Please sign in to comment.