yum-mirror/slang

Making it easier to work with shaders

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

Ellie Hermaszewskaformatf65d756bf

master
2.4 KiB84 linesraw
1#ifndef SLANG_INCLUDE_SYSTEM_H
2#define SLANG_INCLUDE_SYSTEM_H
3// slang-include-system.h
4
5#include "../compiler-core/slang-source-loc.h"
6
7namespace Slang
8{
9
10// A directory to be searched when looking for files (e.g., `#include`)
11struct SearchDirectory
12{
13    SearchDirectory() = default;
14    SearchDirectory(SearchDirectory const& other) = default;
15    SearchDirectory(String const& path)
16        : path(path)
17    {
18    }
19    SearchDirectory& operator=(SearchDirectory const& other) = default;
20
21    String path;
22};
23
24/// A list of directories to search for files (e.g., `#include`)
25struct SearchDirectoryList
26{
27    // A parent list that should also be searched
28    SearchDirectoryList* parent = nullptr;
29
30    // Directories to be searched
31    List<SearchDirectory> searchDirectories;
32};
33
34/* A helper class that builds basic include handling on top of searchDirectories/fileSystemExt and
35 * optionally a sourceManager */
36struct IncludeSystem
37{
38    SlangResult findFile(
39        const String& pathToInclude,
40        const String& pathIncludedFrom,
41        PathInfo& outPathInfo);
42    SlangResult findFile(
43        SlangPathType fromPathType,
44        const String& fromPath,
45        const String& path,
46        PathInfo& outPathInfo);
47    String simplifyPath(const String& path);
48    SlangResult loadFile(
49        const PathInfo& pathInfo,
50        ComPtr<ISlangBlob>& outBlob,
51        SourceFile*& outSourceFile);
52    inline SlangResult loadFile(const PathInfo& pathInfo, ComPtr<ISlangBlob>& outBlob)
53    {
54        SourceFile* sourceFile;
55        return loadFile(pathInfo, outBlob, sourceFile);
56    }
57
58    SlangResult findAndLoadFile(
59        const String& pathToInclude,
60        const String& pathIncludedFrom,
61        PathInfo& outPathInfo,
62        ComPtr<ISlangBlob>& outBlob);
63
64    SearchDirectoryList* getSearchDirectoryList() const { return m_searchDirectories; }
65    ISlangFileSystemExt* getFileSystem() const { return m_fileSystemExt; }
66    SourceManager* getSourceManager() const { return m_sourceManager; }
67
68    /// Ctor
69    IncludeSystem() = default;
70    IncludeSystem(
71        SearchDirectoryList* searchDirectories,
72        ISlangFileSystemExt* fileSystemExt,
73        SourceManager* sourceManager = nullptr);
74
75protected:
76    SearchDirectoryList* m_searchDirectories;
77    ISlangFileSystemExt* m_fileSystemExt;
78    SourceManager*
79        m_sourceManager; ///< If not set, will not look up the content in the source manager
80};
81
82} // namespace Slang
83
84#endif // SLANG_INCLUDE_HANDLER_H