diff --git a/Bin/clang-format-12.exe b/Bin/clang-format-12.exe new file mode 100644 index 000000000..f6ec92b62 Binary files /dev/null and b/Bin/clang-format-12.exe differ diff --git a/Source/.clang-format b/Source/.clang-format new file mode 100644 index 000000000..548e6d4fc --- /dev/null +++ b/Source/.clang-format @@ -0,0 +1,37 @@ +--- +BasedOnStyle: Microsoft +Language: Cpp +Standard: Cpp11 +AccessModifierOffset: -4 +AllowShortEnumsOnASingleLine: true +AllowShortCaseLabelsOnASingleLine: true +AllowShortIfStatementsOnASingleLine: WithoutElse +BraceWrapping: + AfterCaseLabel: true + AfterClass: true + AfterControlStatement: true + AfterEnum: true + AfterFunction: true + AfterNamespace: true + AfterStruct: true + AfterUnion: true + BeforeCatch: true + BeforeElse: true + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBraces: Custom +BreakInheritanceList: AfterColon +BreakConstructorInitializers: AfterColon +BreakStringLiterals: false +ColumnLimit: 0 +IndentCaseLabels: false +IndentWidth: 4 +PointerAlignment: Middle +SortIncludes: true +SpaceAfterTemplateKeyword: true +SpaceBeforeParens: ControlStatements +SpacesInSquareBrackets: false +TabWidth: 4 +UseTab: Never +... diff --git a/Source/Project64-core/N64System/Recompiler/x86/x86ops.h b/Source/Project64-core/N64System/Recompiler/x86/x86ops.h index 307497231..bc7b53369 100644 --- a/Source/Project64-core/N64System/Recompiler/x86/x86ops.h +++ b/Source/Project64-core/N64System/Recompiler/x86/x86ops.h @@ -17,7 +17,6 @@ class CX86Ops : public asmjit::Logger { public: - enum Multipler { Multip_x1 = 1, @@ -130,7 +129,7 @@ private: }; static x86Reg RegValue(const asmjit::x86::Gp & Reg); - asmjit::Error _log(const char* data, size_t size) noexcept; + asmjit::Error _log(const char * data, size_t size) noexcept; void AddSymbol(const char * SymbolKey, const char * SymbolValue); void RemoveSymbol(const char * SymbolKey); std::string VariableSymbol(void * Variable) const; @@ -138,7 +137,7 @@ private: static void BreakPointNotification(const char * FileName, int32_t LineNumber); typedef std::map SymbolMap; - + SymbolMap m_Symbols; CCodeBlock & m_CodeBlock; }; diff --git a/Source/Project64/Project64.vcxproj b/Source/Project64/Project64.vcxproj index 5efd15b2f..bdb6bf052 100644 --- a/Source/Project64/Project64.vcxproj +++ b/Source/Project64/Project64.vcxproj @@ -52,6 +52,9 @@ $(SolutionDir)Source\3rdParty\asmjit\src;%(AdditionalIncludeDirectories) + + "$(SolutionDir)\Source\Script\clang.cmd" check + diff --git a/Source/Script/clang.cmd b/Source/Script/clang.cmd new file mode 100644 index 000000000..dc33d6930 --- /dev/null +++ b/Source/Script/clang.cmd @@ -0,0 +1,82 @@ +@echo off +setlocal EnableDelayedExpansion + +set origdir=%cd% +cd /d %~dp0..\.. +set base_dir=%cd% +cd /d %origdir% + +set ScanDir[0]="%base_dir%\Source\Common" +set ScanDir[1]="%base_dir%\Source\Project64" +set ScanDir[2]="%base_dir%\Source\Project64-core" + +set ScanFiles[0]="*.cpp" +set ScanFiles[1]="*.h" + +set Exclude[0]="%base_dir%\Source\Project64-core\Version.h" +set Exclude[1]="%base_dir%\Source\Project64\UserInterface\resource.h" + +set ValidParam=0 +if "%1" == "check" set ValidParam=1 +if "%1" == "format" set ValidParam=1 +IF %ValidParam%==0 GOTO :Usage + +if "%1" == "check" echo Checking code formatting +if "%1" == "check" set ClangParm=-style=file -Werror --dry-run +if "%1" == "format" set ClangParm=-i -style=file + +set /a Result=0 + +set /a DirectoryIndex=0 +:DirectoryLoop +if defined ScanDir[%DirectoryIndex%] ( + CALL :ProcessDirectory %DirectoryIndex% + + set /a DirectoryIndex += 1 + GOTO :DirectoryLoop +) +exit /b %Result% + +:ProcessDirectory +call set Directory=%%ScanDir[%1]%% +set /a ScanFilesIndex=0 + +:ScanFilesLoop +if defined ScanFiles[%ScanFilesIndex%] ( + CALL :ProcessDirectoryFiles %ScanFilesIndex% + + set /a ScanFilesIndex += 1 + GOTO :ScanFilesLoop +) +goto :end + +:ProcessDirectoryFiles +call set Files=%%ScanFiles[%1]%% +For /R %Directory% %%A In (%Files%) Do ( + ::"%base_dir%\bin\clang-format-12.exe" -i -style=file "%%A" + CALL :ProcessFile "%%A" +) +goto :end + +:ProcessFile +set /a ExcludeIndex=0 +:ExcludeLoop +if defined Exclude[%ExcludeIndex%] ( + call set ExcludeFile=%%Exclude[%ExcludeIndex%]%% + if %1==!ExcludeFile! ( + goto :end + ) + set /a ExcludeIndex += 1 + GOTO :ExcludeLoop +) +"%base_dir%\bin\clang-format-12.exe" %ClangParm% %1 +IF %ERRORLEVEL% NEQ 0 set /a Result=1 +goto :end + +:Usage +echo clang.cmd [format/check] +echo check - checks to see if any code would have to change +echo format - change the code to meet clang formating + + +:end \ No newline at end of file