Skip to content

Commit

Permalink
Merge pull request #50 from jabacat/format-check
Browse files Browse the repository at this point in the history
Create format.yml
  • Loading branch information
JakeRoggenbuck authored Nov 26, 2023
2 parents 61e6904 + e944bd3 commit 0cd0ef5
Show file tree
Hide file tree
Showing 18 changed files with 351 additions and 104 deletions.
215 changes: 215 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
---
Language: Cpp
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignArrayOfStructures: None
AlignConsecutiveAssignments:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
PadOperators: true
AlignConsecutiveBitFields:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
PadOperators: false
AlignConsecutiveDeclarations:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
PadOperators: false
AlignConsecutiveMacros:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
PadOperators: false
AlignEscapedNewlines: Right
AlignOperands: Align
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortEnumsOnASingleLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
AttributeMacros:
- __capability
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeConceptDeclarations: Always
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
QualifierAlignment: Leave
CompactNamespaces: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: false
DisableFormat: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
ExperimentalAutoDetectBinPacking: false
PackConstructorInitializers: BinPack
BasedOnStyle: ''
ConstructorInitializerAllOnOneLineOrOnePerLine: false
AllowAllConstructorInitializersOnNextLine: true
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IfMacros:
- KJ_IF_MAYBE
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
SortPriority: 0
CaseSensitive: false
- Regex: '.*'
Priority: 1
SortPriority: 0
CaseSensitive: false
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentAccessModifiers: false
IndentCaseLabels: false
IndentCaseBlocks: false
IndentGotoLabels: true
IndentPPDirectives: None
IndentExternBlock: AfterExternBlock
IndentRequiresClause: true
IndentWidth: 4
IndentWrappedFunctionNames: false
InsertBraces: false
InsertTrailingCommas: None
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
LambdaBodyIndentation: Signature
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakOpenParenthesis: 0
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PenaltyIndentedWhitespace: 0
PointerAlignment: Right
PPIndentWidth: -1
ReferenceAlignment: Left
ReflowComments: true
RemoveBracesLLVM: false
RequiresClausePosition: OwnLine
SeparateDefinitionBlocks: Leave
ShortNamespaceLines: 1
SortIncludes: CaseSensitive
SortJavaStaticImport: Before
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeParensOptions:
AfterControlStatements: true
AfterForeachMacros: true
AfterFunctionDefinitionName: false
AfterFunctionDeclarationName: false
AfterIfMacros: true
AfterOverloadedOperator: false
AfterRequiresInClause: false
AfterRequiresInExpression: false
BeforeNonEmptyParentheses: false
SpaceAroundPointerQualifiers: Default
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: Never
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: -1
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
BitFieldColonSpacing: Both
Standard: Latest
StatementAttributeLikeMacros:
- Q_EMIT
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 8
UseCRLF: false
UseTab: Never
WhitespaceSensitiveMacros:
- STRINGIZE
- PP_STRINGIZE
- BOOST_PP_STRINGIZE
- NS_SWIFT_NAME
- CF_SWIFT_NAME
...

19 changes: 19 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: format

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: format
run: |
cd core
find . -iname "*.hpp" -o -iname "*.cpp" -o -iname "*.c" -o -iname "*.h" | xargs -I {} clang-format -i --dry-run --Werror -style='{IndentWidth: 4, ReferenceAlignment: Left}' {}
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,14 @@ meson test -C build # replace `build`
```

Unfortunately, meson doesn't provide good output when a test fails. Running the test executable manually is often more helpful. Look under `build/tests/` to find the right executable. The executable for testing the core library is `core_tests`.

## Format

We use [clang-format](https://www.kernel.org/doc/html/latest/process/clang-format.html) to check our formatting.
Before you push your code, you can run the following that finds all source code files, and then formats them all in place.

```
find . -iname "*.hpp" -o -iname "*.cpp" -o -iname "*.c" -o -iname "*.h" -o -iname "*.tpp" | xargs -I {} clang-format {}
```

You can also add this to your editors formatting system or some precommit step.
16 changes: 8 additions & 8 deletions core/capi/cjml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jml::Vector& vector_lookup_(unsigned vid) {
}

int jml_vector_add(unsigned v1, unsigned v2) {
jml::Vector& to = vector_lookup_(v1);
jml::Vector& to = vector_lookup_(v1);
jml::Vector& from = vector_lookup_(v2);
to.add(from);
return 0;
Expand All @@ -30,14 +30,14 @@ int jml_vector_add_entry(unsigned vid, int pos, double val) {

int jml_vector_apply(unsigned vid, JMLActivFunc val) {
jml::Vector& v = vector_lookup_(vid);
jml::ActivationFunction * a;
jml::ActivationFunction *a;
switch (val) {
case JACT_FSIG:
a = new jml::FastSigmoid();
case JACT_SIG:
a = new jml::Sigmoid();
case JACT_RELU:
a = new jml::ReLU();
case JACT_FSIG:
a = new jml::FastSigmoid();
case JACT_SIG:
a = new jml::Sigmoid();
case JACT_RELU:
a = new jml::ReLU();
}
v.apply(a);
delete a;
Expand Down
8 changes: 4 additions & 4 deletions core/include/jml/internal/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

#pragma once

#include <jml/jmldefs.h>
#include <iostream>
#include <jml/jmldefs.h>

namespace jml {

Expand All @@ -25,9 +25,9 @@ class JML_LOCAL Log {
std::string message;

public:
Log &operator<<(enum Severity s);
Log &operator<<(std::string m);
Log &operator<<(int m);
Log& operator<<(enum Severity s);
Log& operator<<(std::string m);
Log& operator<<(int m);

enum Severity get_severity();
std::string get_message();
Expand Down
50 changes: 26 additions & 24 deletions core/include/jml/jmldefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,37 @@
// stolen from https://gcc.gnu.org/wiki/Visibility
// Generic helper definitions for shared library support
#if defined _WIN32 || defined __CYGWIN__
#define JML_HELPER_DLL_IMPORT __declspec(dllimport)
#define JML_HELPER_DLL_EXPORT __declspec(dllexport)
#define JML_HELPER_DLL_LOCAL
#define JML_HELPER_DLL_IMPORT __declspec(dllimport)
#define JML_HELPER_DLL_EXPORT __declspec(dllexport)
#define JML_HELPER_DLL_LOCAL
#else
#if __GNUC__ >= 4
#define JML_HELPER_DLL_IMPORT __attribute__ ((visibility ("default")))
#define JML_HELPER_DLL_EXPORT __attribute__ ((visibility ("default")))
#define JML_HELPER_DLL_LOCAL __attribute__ ((visibility ("hidden")))
#else
#define JML_HELPER_DLL_IMPORT
#define JML_HELPER_DLL_EXPORT
#define JML_HELPER_DLL_LOCAL
#endif
#if __GNUC__ >= 4
#define JML_HELPER_DLL_IMPORT __attribute__((visibility("default")))
#define JML_HELPER_DLL_EXPORT __attribute__((visibility("default")))
#define JML_HELPER_DLL_LOCAL __attribute__((visibility("hidden")))
#else
#define JML_HELPER_DLL_IMPORT
#define JML_HELPER_DLL_EXPORT
#define JML_HELPER_DLL_LOCAL
#endif
#endif

// Now we use the generic helper definitions above to define JML_API and JML_LOCAL.
// JML_API is used for the public API symbols. It either DLL imports or DLL exports (or does nothing for static build)
// JML_LOCAL is used for non-api symbols.
// Now we use the generic helper definitions above to define JML_API and
// JML_LOCAL. JML_API is used for the public API symbols. It either DLL imports
// or DLL exports (or does nothing for static build) JML_LOCAL is used for
// non-api symbols.

#ifdef JML_DLL // defined if JML is compiled as a DLL
#ifdef JML_DLL_EXPORTS // defined if we are building the JML DLL (instead of using it)
#define JML_API JML_HELPER_DLL_EXPORT
#else
#define JML_API JML_HELPER_DLL_IMPORT
#endif // JML_DLL_EXPORTS
#define JML_LOCAL JML_HELPER_DLL_LOCAL
#ifdef JML_DLL // defined if JML is compiled as a DLL
#ifdef JML_DLL_EXPORTS // defined if we are building the JML DLL (instead of
// using it)
#define JML_API JML_HELPER_DLL_EXPORT
#else
#define JML_API JML_HELPER_DLL_IMPORT
#endif // JML_DLL_EXPORTS
#define JML_LOCAL JML_HELPER_DLL_LOCAL
#else // JML_DLL is not defined: this means JML is a static lib.
#define JML_API
#define JML_LOCAL
#define JML_API
#define JML_LOCAL
#endif // JML_DLL

#endif
4 changes: 2 additions & 2 deletions core/include/jml/math/matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

#include <memory>

#include <jml/math/vector.hpp>
#include <jml/jmldefs.h>
#include <jml/internal/logger.hpp>
#include <jml/jmldefs.h>
#include <jml/math/vector.hpp>

namespace jml {

Expand Down
Loading

0 comments on commit 0cd0ef5

Please sign in to comment.