Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
26 changes: 26 additions & 0 deletions .github/workflows/cpp_format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: cpp-linter
on:
pull_request:
branches: [main]
paths: ['**.c', '**.cpp', '**.h', '**.hpp', '**.cxx', '**.hxx', '**.cc', '**.hh', '*.mm', '**CMakeLists.txt', '**.cmake']
push:
branches: [main]
paths: ['**.c', '**.cpp', '**.h', '**.hpp', '**.cxx', '**.hxx', '**.cc', '**.hh', '*.mm', '**CMakeLists.txt', '**.cmake']
jobs:
cpp-linter:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: cpp-linter/cpp-linter-action@v2
id: linter
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
style: 'file' # Use .clang-format config file.
tidy-checks: '-*' # disable clang-tidy checks.
step-summary: true
format-review: true

- name: Fail fast?!
if: steps.linter.outputs.clang-format-checks-failed > 0
run: exit 1
20 changes: 10 additions & 10 deletions shadercompiler/ASTNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
#include "HLSLParser.h"
#include "ParserUtils.h"

ASTNode::ASTNode( ASTNodeType type, const FileLocation& location, ScopeSymbolTable* scope, const ScannerToken* token )
:m_nodeType( type ),
ASTNode::ASTNode( ASTNodeType type, const FileLocation& location, ScopeSymbolTable* scope, const ScannerToken* token ) :
m_nodeType( type ),
m_symbol( nullptr ),
m_location( location ),
m_scope( scope )
m_scope( scope )
{
m_type.FromTokenType( 0 );
if( token )
{
{
m_token = *token;
}
else
Expand Down Expand Up @@ -66,11 +66,11 @@ void ASTNode::ReplaceChild( size_t place, ASTNode* child )

void ASTNode::ReplaceChild( ASTNode* old, ASTNode* child )
{
auto found = find( begin( m_children ), end( m_children ), old );
if( found != end( m_children ) )
{
*found = child;
}
auto found = find( begin( m_children ), end( m_children ), old );
if( found != end( m_children ) )
{
*found = child;
}
}

void ASTNode::RemoveChild( size_t place )
Expand Down Expand Up @@ -150,7 +150,7 @@ const ScannerToken* ASTNode::GetToken() const
}
}

void ASTNode::SetToken(const ScannerToken& token)
void ASTNode::SetToken( const ScannerToken& token )
{
m_token = token;
}
Expand Down
6 changes: 3 additions & 3 deletions shadercompiler/ASTNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class ASTNode
void AddChild( ASTNode* child );
void InsertChild( size_t place, ASTNode* child );
void ReplaceChild( size_t place, ASTNode* child );
void ReplaceChild( ASTNode* old, ASTNode* child );
void ReplaceChild( ASTNode* old, ASTNode* child );
void RemoveChild( size_t place );
void RemoveChild( ASTNode* child );

Expand Down Expand Up @@ -147,7 +147,7 @@ class ASTNode
void FindNodes( ASTNodeType type, std::vector<ASTNode*>& nodes );

template <typename T>
ASTNode* Map( T callback )
ASTNode* Map( T callback )
{
ASTNode* newNode = callback( this );
for( size_t i = 0; i < newNode->m_children.size(); ++i )
Expand All @@ -161,7 +161,7 @@ class ASTNode
}

private:
ASTNodeType m_nodeType;
ASTNodeType m_nodeType;
ScannerToken m_token;
Symbol* m_symbol;
Type m_type;
Expand Down
10 changes: 5 additions & 5 deletions shadercompiler/CachingIncludeHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
// TODO MACOS: This function is just a stub. Make sure it covers all cases.
namespace
{
BOOL PathIsRelative( LPCSTR pszPath )
{
return pszPath[0] != '/';
}
BOOL PathIsRelative( LPCSTR pszPath )
{
return pszPath[0] != '/';
}
}
#endif

Expand Down Expand Up @@ -201,7 +201,7 @@ std::optional<CachingIncludeHandler::IncludedFile> CachingIncludeHandler::AddPre
return std::nullopt;
}

auto &info = fileFromPath->second;
auto& info = fileFromPath->second;
auto length = strlen( prefix );
auto data = malloc( info.size + length + 2 );
if( data == NULL )
Expand Down
7 changes: 4 additions & 3 deletions shadercompiler/CachingIncludeHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

// --------------------------------------------------------------------------------------
// Description:
// CachingIncludeHandler is an include handler for D3D effect compiler. It caches
// contents of included files, so the next time they are requested it returns cached
// contents. This object can be accessed from different threads.
// CachingIncludeHandler is an include handler for D3D effect compiler. It caches
// contents of included files, so the next time they are requested it returns cached
// contents. This object can be accessed from different threads.
// --------------------------------------------------------------------------------------
class CachingIncludeHandler
{
Expand All @@ -27,6 +27,7 @@ class CachingIncludeHandler
void SetRootPath( const char* shaderPath );

std::optional<IncludedFile> AddPrefix( const char* fileName, const char* prefix );

private:
typedef std::map<const void*, std::string> PathFromFile;
typedef std::map<std::string, IncludedFile> FileFromPath;
Expand Down
12 changes: 6 additions & 6 deletions shadercompiler/CompileMessageQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include "CompileMessageQueue.h"


CompileMessageQueue::CompileMessageQueue()
:m_stop( false )
CompileMessageQueue::CompileMessageQueue() :
m_stop( false )
{
m_thread = std::thread( [this] { this->Run(); } );
}
Expand Down Expand Up @@ -33,7 +33,7 @@ void CompileMessageQueue::AddMessages( IDxcBlobEncoding* blob )
if( size > 0 )
{
m_messagesMutex.lock();
m_messages.push( reinterpret_cast<char*>(blob->GetBufferPointer()) );
m_messages.push( reinterpret_cast<char*>( blob->GetBufferPointer() ) );
m_messagesMutex.unlock();
m_queueEvent.notify_one();
}
Expand All @@ -49,7 +49,7 @@ void CompileMessageQueue::AddMessage( const char* format, ... )
va_end( args );

std::string message;
message.resize(count);
message.resize( count );

va_start( args, format );
count = vsnprintf( &message[0], message.size(), format, args );
Expand Down Expand Up @@ -140,12 +140,12 @@ void CompileMessageQueue::OutputMessages( const char* messages, size_t length )
const char* end = messages + 1;
while( *start && start - messages < ptrdiff_t( length ) )
{
if( *end == 0 || end - messages >= ptrdiff_t( length ) || (end[0] == '\n' && (end - messages + 1 >= ptrdiff_t( length ) || !isspace( end[1] ))) )
if( *end == 0 || end - messages >= ptrdiff_t( length ) || ( end[0] == '\n' && ( end - messages + 1 >= ptrdiff_t( length ) || !isspace( end[1] ) ) ) )
{
std::string message( start, end );
if( m_printedMessages.insert( message ).second )
{
const char* memoryRefs[] = { "\\memory(", "/memory(", "/memory:", "memory:"};
const char* memoryRefs[] = { "\\memory(", "/memory(", "/memory:", "memory:" };
for( auto memoryRef : memoryRefs )
{
auto pos = message.find( memoryRef );
Expand Down
2 changes: 1 addition & 1 deletion shadercompiler/CompileMessageQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CompileMessageQueue
void AddMessages( IDxcBlobEncoding* buffer ); // windows only? or is it also for mac
#endif
void AddMessage( const char* format, ... );

void Flush();
void SetEntryFileName( const char* fileName );

Expand Down
66 changes: 33 additions & 33 deletions shadercompiler/DxReflection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,44 @@
namespace DxReflection
{

bool MakeEffectAnnotationFromSymbolAnnotation( const SymbolAnnotation& annotation, Annotation& result, bool& isSRGB, bool& isAutoregister )
bool MakeEffectAnnotationFromSymbolAnnotation( const SymbolAnnotation& annotation, Annotation& result, bool& isSRGB, bool& isAutoregister )
{
switch( annotation.type )
{
switch( annotation.type )
case OP_FLOAT:
case OP_HALF:
case OP_DOUBLE:
result.type = ANNOTATION_TYPE_FLOAT;
result.floatValue = float( ParseFloat( annotation.value.stringValue.start, annotation.value.stringValue.end ) );
return true;

case OP_UINT:
case OP_INT:
result.type = ANNOTATION_TYPE_INT;
result.intValue = ParseNumber( annotation.value.stringValue.start, annotation.value.stringValue.end );
return true;

case OP_BOOL:
result.type = ANNOTATION_TYPE_BOOL;
result.intValue = annotation.value.intValue ? 1 : 0;
if( ToString( annotation.name ) == "Tr2sRGB" )
{
isSRGB = result.intValue != 0;
}
else if( ToString( annotation.name ) == "AutoRegister" )
{
case OP_FLOAT:
case OP_HALF:
case OP_DOUBLE:
result.type = ANNOTATION_TYPE_FLOAT;
result.floatValue = float( ParseFloat( annotation.value.stringValue.start, annotation.value.stringValue.end ) );
return true;

case OP_UINT:
case OP_INT:
result.type = ANNOTATION_TYPE_INT;
result.intValue = ParseNumber( annotation.value.stringValue.start, annotation.value.stringValue.end );
return true;

case OP_BOOL:
result.type = ANNOTATION_TYPE_BOOL;
result.intValue = annotation.value.intValue ? 1 : 0;
if( ToString( annotation.name ) == "Tr2sRGB" )
{
isSRGB = result.intValue != 0;
}
else if( ToString( annotation.name ) == "AutoRegister" )
{
isAutoregister = result.intValue != 0;
}
return true;

case OP_STRING:
result.type = ANNOTATION_TYPE_STRING;
result.stringValue = g_stringTable.AddString( ParseString( annotation.value.stringValue ).c_str() );
return true;
isAutoregister = result.intValue != 0;
}
return true;

return false;
case OP_STRING:
result.type = ANNOTATION_TYPE_STRING;
result.stringValue = g_stringTable.AddString( ParseString( annotation.value.stringValue ).c_str() );
return true;
}

return false;
}

}
#endif
Loading
Loading