From a729c15e9dce9f5116a38afc66329ab2ca4cea54 Mon Sep 17 00:00:00 2001 From: Ellie Hermaszewska Date: Tue, 29 Oct 2024 13:59:28 +0800 Subject: preparation for clang format (#5422) * Clang-format excludes * Add .clang-format * Don't clang-format in external * Missing includes and forward declarations * Replace wonky include-once macro name * neaten include naming * Add clang-format to formatting script * Add xargs and diff to required binaries * add clang-format to ci formatting check * Add max version check to formatting script * temporarily disable checking formatting for cpp files --- source/compiler-core/slang-artifact-desc-util.cpp | 2 + source/compiler-core/slang-dxc-compiler.cpp | 47 +++++++++++++---------- source/compiler-core/slang-nvrtc-compiler.cpp | 2 + 3 files changed, 31 insertions(+), 20 deletions(-) (limited to 'source/compiler-core') diff --git a/source/compiler-core/slang-artifact-desc-util.cpp b/source/compiler-core/slang-artifact-desc-util.cpp index 907a953ce..7c2622f70 100644 --- a/source/compiler-core/slang-artifact-desc-util.cpp +++ b/source/compiler-core/slang-artifact-desc-util.cpp @@ -154,6 +154,7 @@ bool isDerivedFrom(ENUM_TYPE kind, ENUM_TYPE base) { return g_table##ENUM_TYPE.i /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!! ArtifactKind !!!!!!!!!!!!!!!!!!!!!!! */ +// clang-format off #define SLANG_ARTIFACT_KIND(x) \ x(Invalid, Invalid) \ x(Base, Invalid) \ @@ -245,6 +246,7 @@ SLANG_HIERARCHICAL_ENUM(ArtifactPayload, SLANG_ARTIFACT_PAYLOAD, SLANG_ARTIFACT_ x(Kernel, CodeLike) \ x(Host, CodeLike) \ x(Obfuscated, Base) +// clang-format on #define SLANG_ARTIFACT_STYLE_ENTRY(TYPE, PARENT) { Index(ArtifactStyle::TYPE), Index(ArtifactStyle::PARENT), #TYPE }, diff --git a/source/compiler-core/slang-dxc-compiler.cpp b/source/compiler-core/slang-dxc-compiler.cpp index 3a949b3bd..30bf71968 100644 --- a/source/compiler-core/slang-dxc-compiler.cpp +++ b/source/compiler-core/slang-dxc-compiler.cpp @@ -37,26 +37,33 @@ // generate code on Windows. #if SLANG_ENABLE_DXIL_SUPPORT -# ifdef _WIN32 -# include -# include -# include "../../external/dxc/dxcapi.h" -# else -# include "../../external/dxc/dxcapi.h" - -# ifdef __uuidof - // DXC's WinAdapter.h defines __uuidof(T) over types, but the existing - // usage in this file is over values (both are accepted on MSVC.) - // We also need to decay through Slang::ComPtr, hence the helper struct - template - struct StripSlangComPtr { using type = T; }; - template - struct StripSlangComPtr> { using type = T; }; -# undef __uuidof -# define __uuidof(x) __emulated_uuidof>::type>() -# endif -# endif - +# ifdef _WIN32 +# include +# include +# endif + +# include "../../external/dxc/dxcapi.h" + +# ifndef _WIN32 +# ifdef __uuidof +// DXC's WinAdapter.h defines __uuidof(T) over types, but the existing +// usage in this file is over values (both are accepted on MSVC.) +// We also need to decay through Slang::ComPtr, hence the helper struct +template +struct StripSlangComPtr +{ + using type = T; +}; +template +struct StripSlangComPtr> +{ + using type = T; +}; +# undef __uuidof +# define __uuidof(x) \ + __emulated_uuidof>::type>() +# endif +# endif #endif namespace Slang diff --git a/source/compiler-core/slang-nvrtc-compiler.cpp b/source/compiler-core/slang-nvrtc-compiler.cpp index 80fde277b..8e234e634 100644 --- a/source/compiler-core/slang-nvrtc-compiler.cpp +++ b/source/compiler-core/slang-nvrtc-compiler.cpp @@ -41,6 +41,7 @@ typedef enum { typedef struct _nvrtcProgram *nvrtcProgram; +// clang-format off #define SLANG_NVRTC_FUNCS(x) \ x(const char*, nvrtcGetErrorString, (nvrtcResult result)) \ x(nvrtcResult, nvrtcVersion, (int *major, int *minor)) \ @@ -53,6 +54,7 @@ typedef struct _nvrtcProgram *nvrtcProgram; x(nvrtcResult, nvrtcGetProgramLog, (nvrtcProgram prog, char *log))\ x(nvrtcResult, nvrtcAddNameExpression, (nvrtcProgram prog, const char * const name_expression)) \ x(nvrtcResult, nvrtcGetLoweredName, (nvrtcProgram prog, const char *const name_expression, const char** lowered_name)) +// clang-format on } // namespace nvrtc -- cgit v1.2.3