yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f65d756bf
master
1// parse-diagnostic-util.h 2 3#ifndef PARSE_DIAGNOSTIC_UTIL_H 4#define PARSE_DIAGNOSTIC_UTIL_H 5 6#include "../../source/compiler-core/slang-artifact-diagnostic-util.h" 7#include "../../source/compiler-core/slang-downstream-compiler.h" 8#include "../../source/core/slang-string-util.h" 9#include "../../source/core/slang-string.h" 10#include "slang-com-ptr.h" 11 12struct ParseDiagnosticUtil 13{ 14struct OutputInfo 15 { 16int resultCode ; 17Slang ::String stdError ; 18Slang ::String stdOut ; 19 }; 20 21/// We need a way to identify downstream compilers and others - specifically here Slang. 22/// Ideally we'd have an enum that included Slang. 23/// Just adding to SlangPassThrough doesn't seem right. If we had an enumeration with a 24/// more appropriate name, then including downstream and slang compilers wouldn't be a problem. 25/// So for now this is punted, and this type is used to represent possible compiler identities. 26struct CompilerIdentity 27 { 28typedef CompilerIdentity ThisType ; 29 30enum Type 31 { 32Unknown , 33Slang , 34DownstreamCompiler , 35 }; 36 37static CompilerIdentity make (Type type ,SlangPassThrough downstreamCompiler ) 38 { 39CompilerIdentity ident ; 40ident .m_type = type ; 41ident .m_downstreamCompiler = downstreamCompiler ; 42return ident ; 43 } 44static CompilerIdentity make (SlangPassThrough downstreamCompiler ) 45 { 46return make (Type ::DownstreamCompiler ,downstreamCompiler ); 47 } 48static CompilerIdentity makeSlang () {return make (Type ::Slang ,SLANG_PASS_THROUGH_NONE ); } 49 50bool operator == (const ThisType & rhs )const 51 { 52return m_type == rhs .m_type && m_downstreamCompiler == rhs .m_downstreamCompiler ; 53 } 54bool operator != (const ThisType & rhs )const {return !(* this == rhs ); } 55 56Type m_type = Type ::Unknown ; 57SlangPassThrough m_downstreamCompiler = SLANG_PASS_THROUGH_NONE ; 58 }; 59 60typedef uint32_t EqualityFlags ; 61struct EqualityFlag 62 { 63enum Enum :EqualityFlags 64 { 65IgnoreLineNos = 0x1 , 66 }; 67 }; 68 69typedef SlangResult (* LineParser )( 70Slang ::SliceAllocator & allocator , 71const Slang ::UnownedStringSlice & line , 72Slang ::List < Slang ::UnownedStringSlice >& lineSlices , 73Slang ::ArtifactDiagnostic & outDiagnostic ); 74 75/// Given a compiler identity returns a line parsing function. 76static LineParser getLineParser (const CompilerIdentity & compilerIdentity ); 77 78/// For a 'generic' (as in uses DownstreamCompiler mechanism) line parsing 79static SlangResult parseGenericLine ( 80Slang ::SliceAllocator & allocator , 81const Slang ::UnownedStringSlice & line , 82Slang ::List < Slang ::UnownedStringSlice >& lineSlices , 83Slang ::ArtifactDiagnostic & outDiagnostic ); 84 85/// For parsing diagnostics from Slang 86static SlangResult parseSlangLine ( 87Slang ::SliceAllocator & allocator , 88const Slang ::UnownedStringSlice & line , 89Slang ::List < Slang ::UnownedStringSlice >& lineSlices , 90Slang ::ArtifactDiagnostic & outDiagnostic ); 91 92/// Parse diagnostics into output text 93static SlangResult parseDiagnostics ( 94const Slang ::UnownedStringSlice & inText , 95Slang ::IArtifactDiagnostics * diagnostics ); 96 97/// Parse diagnostics with known compiler identity. 98/// If the prefix is empty, it is assumed there is no prefix and it won't be checked. 99static SlangResult parseDiagnostics ( 100const Slang ::UnownedStringSlice & inText , 101const CompilerIdentity & identity , 102const Slang ::UnownedStringSlice & prefix , 103Slang ::IArtifactDiagnostics * diagnostics ); 104 105/// Given the file output style used by tests, get components of the output into Diagnostic 106static SlangResult parseOutputInfo (const Slang ::UnownedStringSlice & in ,OutputInfo & out ); 107 108/// Given a line split it into slices - taking into account compiler output, path 109/// considerations, and potentially line prefixing 110static SlangResult splitDiagnosticLine ( 111const CompilerIdentity & compilerIdentity , 112const Slang ::UnownedStringSlice & line , 113const Slang ::UnownedStringSlice & linePrefix , 114Slang ::List < Slang ::UnownedStringSlice >& outSlices ); 115 116/// Give text of diagnostic determine which compiler the output is from 117static SlangResult identifyCompiler ( 118const Slang ::UnownedStringSlice & in , 119CompilerIdentity & outIdentity ); 120 121/// Determines if the diagnostics in a and b (they are parsed via parseDiagnostics) are equal, 122/// taking into account flags Note! If the parse of either a or b fails, then equality is 123/// returns as false. 124static bool areEqual ( 125const Slang ::UnownedStringSlice & a , 126const Slang ::UnownedStringSlice & b , 127EqualityFlags flags ); 128}; 129 130#endif // PARSE_DIAGNOSTIC_UTIL_H