yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Ellie Hermaszewskaformatf65d756bf

master
4.8 KiB130 linesraw
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{
14    struct OutputInfo
15    {
16        int resultCode;
17        Slang::String stdError;
18        Slang::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.
26    struct CompilerIdentity
27    {
28        typedef CompilerIdentity ThisType;
29
30        enum Type
31        {
32            Unknown,
33            Slang,
34            DownstreamCompiler,
35        };
36
37        static CompilerIdentity make(Type type, SlangPassThrough downstreamCompiler)
38        {
39            CompilerIdentity ident;
40            ident.m_type = type;
41            ident.m_downstreamCompiler = downstreamCompiler;
42            return ident;
43        }
44        static CompilerIdentity make(SlangPassThrough downstreamCompiler)
45        {
46            return make(Type::DownstreamCompiler, downstreamCompiler);
47        }
48        static CompilerIdentity makeSlang() { return make(Type::Slang, SLANG_PASS_THROUGH_NONE); }
49
50        bool operator==(const ThisType& rhs) const
51        {
52            return m_type == rhs.m_type && m_downstreamCompiler == rhs.m_downstreamCompiler;
53        }
54        bool operator!=(const ThisType& rhs) const { return !(*this == rhs); }
55
56        Type m_type = Type::Unknown;
57        SlangPassThrough m_downstreamCompiler = SLANG_PASS_THROUGH_NONE;
58    };
59
60    typedef uint32_t EqualityFlags;
61    struct EqualityFlag
62    {
63        enum Enum : EqualityFlags
64        {
65            IgnoreLineNos = 0x1,
66        };
67    };
68
69    typedef SlangResult (*LineParser)(
70        Slang::SliceAllocator& allocator,
71        const Slang::UnownedStringSlice& line,
72        Slang::List<Slang::UnownedStringSlice>& lineSlices,
73        Slang::ArtifactDiagnostic& outDiagnostic);
74
75    /// Given a compiler identity returns a line parsing function.
76    static LineParser getLineParser(const CompilerIdentity& compilerIdentity);
77
78    /// For a 'generic' (as in uses DownstreamCompiler mechanism) line parsing
79    static SlangResult parseGenericLine(
80        Slang::SliceAllocator& allocator,
81        const Slang::UnownedStringSlice& line,
82        Slang::List<Slang::UnownedStringSlice>& lineSlices,
83        Slang::ArtifactDiagnostic& outDiagnostic);
84
85    /// For parsing diagnostics from Slang
86    static SlangResult parseSlangLine(
87        Slang::SliceAllocator& allocator,
88        const Slang::UnownedStringSlice& line,
89        Slang::List<Slang::UnownedStringSlice>& lineSlices,
90        Slang::ArtifactDiagnostic& outDiagnostic);
91
92    /// Parse diagnostics into output text
93    static SlangResult parseDiagnostics(
94        const Slang::UnownedStringSlice& inText,
95        Slang::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.
99    static SlangResult parseDiagnostics(
100        const Slang::UnownedStringSlice& inText,
101        const CompilerIdentity& identity,
102        const Slang::UnownedStringSlice& prefix,
103        Slang::IArtifactDiagnostics* diagnostics);
104
105    /// Given the file output style used by tests, get components of the output into Diagnostic
106    static 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
110    static SlangResult splitDiagnosticLine(
111        const CompilerIdentity& compilerIdentity,
112        const Slang::UnownedStringSlice& line,
113        const Slang::UnownedStringSlice& linePrefix,
114        Slang::List<Slang::UnownedStringSlice>& outSlices);
115
116    /// Give text of diagnostic determine which compiler the output is from
117    static SlangResult identifyCompiler(
118        const Slang::UnownedStringSlice& in,
119        CompilerIdentity& 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.
124    static bool areEqual(
125        const Slang::UnownedStringSlice& a,
126        const Slang::UnownedStringSlice& b,
127        EqualityFlags flags);
128};
129
130#endif // PARSE_DIAGNOSTIC_UTIL_H