Skip to content

Commit

Permalink
Update clang-format config and reformat code. (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
SharafMohamed authored Jul 26, 2024
1 parent 3af64f7 commit 6eda3b5
Show file tree
Hide file tree
Showing 21 changed files with 706 additions and 692 deletions.
137 changes: 72 additions & 65 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,37 +1,42 @@
# yamllint disable-line rule:document-start
---
ColumnLimit: 100
IndentWidth: 4
# yamllint disable-line rule:document-start
---
Language: Cpp
Language: "Cpp"
AccessModifierOffset: -4
AlignAfterOpenBracket: BlockIndent
AlignArrayOfStructures: None
AlignConsecutiveAssignments: None
AlignConsecutiveBitFields: None
AlignConsecutiveDeclarations: None
AlignConsecutiveMacros: None
AlignEscapedNewlines: DontAlign
AlignOperands: Align
AlignTrailingComments: Never
AlignAfterOpenBracket: "BlockIndent"
AlignArrayOfStructures: "None"
AlignConsecutiveAssignments: "None"
AlignConsecutiveBitFields: "None"
AlignConsecutiveDeclarations: "None"
AlignConsecutiveMacros: "None"
AlignEscapedNewlines: "DontAlign"
AlignOperands: "Align"
AlignTrailingComments:
Kind: "Never"
AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Always
AllowBreakBeforeNoexceptSpecifier: "OnlyWithParen"
AllowShortBlocksOnASingleLine: "Always"
AllowShortCaseLabelsOnASingleLine: false
AllowShortCompoundRequirementOnASingleLine: true
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: All
AllowShortFunctionsOnASingleLine: "Inline"
AllowShortIfStatementsOnASingleLine: "Never"
AllowShortLambdasOnASingleLine: "All"
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakAfterReturnType: "None"
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
AlwaysBreakTemplateDeclarations: "Yes"
BinPackArguments: false
BinPackParameters: false
BitFieldColonSpacing: Both
BitFieldColonSpacing: "Both"
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: MultiLine
AfterControlStatement: "MultiLine"
AfterEnum: false
AfterFunction: false
AfterNamespace: false
Expand All @@ -46,45 +51,46 @@ BraceWrapping:
SplitEmptyFunction: false
SplitEmptyNamespace: false
SplitEmptyRecord: false
BreakAfterAttributes: Never
BreakBeforeBinaryOperators: All
BreakBeforeBraces: Custom
BreakBeforeConceptDeclarations: Always
BreakBeforeInlineASMColon: OnlyMultiline
BreakAfterAttributes: "Never"
BreakBeforeBinaryOperators: "All"
BreakBeforeBraces: "Custom"
BreakBeforeConceptDeclarations: "Always"
BreakBeforeInlineASMColon: "OnlyMultiline"
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: BeforeColon
BreakConstructorInitializers: "BeforeColon"
BreakInheritanceList: "BeforeColon"
BreakStringLiterals: true
CompactNamespaces: true
ConstructorInitializerIndentWidth: 8
ContinuationIndentWidth: 8
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
EmptyLineAfterAccessModifier: "Never"
EmptyLineBeforeAccessModifier: "LogicalBlock"
FixNamespaceComments: true
IncludeBlocks: Regroup
IncludeBlocks: "Regroup"
IncludeCategories:
# NOTE: A header is grouped by first matching regex
# Library headers. Update when adding new libraries.
# NOTE: clang-format retains leading white-space on a line in violation of the YAML spec.
- Regex: "<Catch2"
Priority: 3
# Project headers
- Regex: '^<log_surgeon'
- Regex: "^<log_surgeon"
Priority: 4
# Third-party headers. Update when adding new third-party library
- Regex: '^<(Catch2)'
Priority: 3
# C headers
- Regex: '^<.*\.h>$'
# C system headers
- Regex: "^<.+\\.h>"
Priority: 1
# C++ standard libraries
- Regex: '^<.*>$'
- Regex: "^<.+>"
Priority: 2
IndentAccessModifiers: false
IndentCaseBlocks: false
IndentCaseLabels: true
IndentExternBlock: Indent
IndentExternBlock: "Indent"
IndentGotoLabels: false
IndentPPDirectives: BeforeHash
IndentPPDirectives: "BeforeHash"
IndentRequiresClause: false
IndentWrappedFunctionNames: false
InsertBraces: true
Expand All @@ -97,61 +103,62 @@ IntegerLiteralSeparator:
Hex: 4
HexMinDigits: 4
KeepEmptyLinesAtTheStartOfBlocks: false
LambdaBodyIndentation: Signature
LineEnding: LF
LambdaBodyIndentation: "Signature"
LineEnding: "LF"
MaxEmptyLinesToKeep: 1
NamespaceIndentation: Inner
NamespaceIndentation: "None"
PPIndentWidth: -1
PackConstructorInitializers: CurrentLine
PenaltyBreakAssignment: 50
PackConstructorInitializers: "CurrentLine"
PenaltyBreakOpenParenthesis: 25
PenaltyBreakBeforeFirstCallParameter: 25
PenaltyReturnTypeOnItsOwnLine: 100
PointerAlignment: Left
QualifierAlignment: Custom
PointerAlignment: "Left"
QualifierAlignment: "Custom"
QualifierOrder:
- static
- friend
- inline
- "static"
- "friend"
- "inline"
# constexpr west as explained in https://www.youtube.com/watch?v=z6s6bacI424
- constexpr
- type
- const
- volatile
ReferenceAlignment: Pointer
- "constexpr"
- "type"
- "const"
- "volatile"
ReferenceAlignment: "Pointer"
ReflowComments: true
RemoveBracesLLVM: false
RemoveSemicolon: true
RequiresClausePosition: OwnLine
RequiresExpressionIndentation: OuterScope
SeparateDefinitionBlocks: Always
RequiresClausePosition: "OwnLine"
RequiresExpressionIndentation: "OuterScope"
SeparateDefinitionBlocks: "Always"
ShortNamespaceLines: 0
SortIncludes: CaseInsensitive
SortUsingDeclarations: Lexicographic
SortIncludes: "CaseInsensitive"
SortUsingDeclarations: "Lexicographic"
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceAroundPointerQualifiers: Default
SpaceAroundPointerQualifiers: "Default"
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeParens: "ControlStatements"
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: false
SpacesInCStyleCastParentheses: false
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: -1
SpacesInParentheses: false
SpacesInParens: "Custom"
SpacesInParensOptions:
InConditionalStatements: false
InCStyleCasts: false
InEmptyParentheses: false
Other: false
SpacesInSquareBrackets: false
Standard: Latest
Standard: "Latest"
TabWidth: 4
UseTab: Never
UseTab: "Never"
4 changes: 2 additions & 2 deletions examples/common.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include "common.hpp"

#include <filesystem>
#include <fstream>
#include <iostream>
Expand All @@ -6,8 +8,6 @@

#include <log_surgeon/LogEvent.hpp>

#include "common.hpp"

using namespace std;
using namespace log_surgeon;

Expand Down
2 changes: 1 addition & 1 deletion examples/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ auto check_input(int argc, char* argv[]) -> int;

auto print_timestamp_loglevel(log_surgeon::LogEventView const& event, uint32_t loglevel_id) -> void;

#endif // COMMON_HPP
#endif // COMMON_HPP
4 changes: 2 additions & 2 deletions src/log_surgeon/Buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ class Buffer {
}

template <class T>
auto read(T& reader, uint32_t read_offset, uint32_t bytes_to_read, size_t& bytes_read)
-> ErrorCode {
auto
read(T& reader, uint32_t read_offset, uint32_t bytes_to_read, size_t& bytes_read) -> ErrorCode {
static_assert(std::is_same_v<T, Reader>, "T should be a Reader");
return reader.read(m_active_storage + read_offset, bytes_to_read, bytes_read);
}
Expand Down
9 changes: 6 additions & 3 deletions src/log_surgeon/BufferParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,12 @@ class BufferParser {
* internally before this method returns.
* @return ErrorCode from LogParser::parse.
*/
auto
parse_next_event(char* buf, size_t size, size_t& offset, bool finished_reading_input = false)
-> ErrorCode;
auto parse_next_event(
char* buf,
size_t size,
size_t& offset,
bool finished_reading_input = false
) -> ErrorCode;

/**
* @return The underlying LogParser.
Expand Down
10 changes: 5 additions & 5 deletions src/log_surgeon/Constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ constexpr char cTokenNewline[] = "newLine";
constexpr uint32_t cStaticByteBuffSize = 48'000;

namespace utf8 {
// 0xC0, 0xC1, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE,
// 0xFF are invalid UTF-8 code units
static unsigned char const cCharEOF = 0xFF;
static unsigned char const cCharErr = 0xFE;
static unsigned char const cCharStartOfFile = 0xFD;
// 0xC0, 0xC1, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE,
// 0xFF are invalid UTF-8 code units
static unsigned char const cCharEOF = 0xFF;
static unsigned char const cCharErr = 0xFE;
static unsigned char const cCharStartOfFile = 0xFD;
} // namespace utf8
} // namespace log_surgeon

Expand Down
11 changes: 6 additions & 5 deletions src/log_surgeon/LALR1Parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,10 @@ class LALR1Parser : public Parser<NFAStateType, DFAStateType> {
* @param name
* @param rule
*/
auto
add_rule(std::string const& name, std::unique_ptr<finite_automata::RegexAST<NFAStateType>> rule)
-> void override;
auto add_rule(
std::string const& name,
std::unique_ptr<finite_automata::RegexAST<NFAStateType>> rule
) -> void override;

/**
* Calls add_rule with the given RegexASTGroup
Expand Down Expand Up @@ -382,8 +383,8 @@ class LALR1Parser : public Parser<NFAStateType, DFAStateType> {
* @param parse_stack_matches
* @return std::string
*/
static auto get_input_after_last_newline(std::stack<MatchedSymbol>& parse_stack_matches)
-> std::string;
static auto get_input_after_last_newline(std::stack<MatchedSymbol>& parse_stack_matches
) -> std::string;

/**
* Get the current line after the error symbol
Expand Down
Loading

0 comments on commit 6eda3b5

Please sign in to comment.