yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f65d756bf
master
1// slang-artifact-util.h 2#ifndef SLANG_ARTIFACT_UTIL_H 3#define SLANG_ARTIFACT_UTIL_H 4 5#include "slang-artifact-associated.h" 6#include "slang-artifact-representation.h" 7#include "slang-artifact.h" 8#include "slang-com-ptr.h" 9 10namespace Slang 11{ 12 13struct ArtifactUtil 14{ 15typedef bool (* FindFunc )(IArtifact * artifact ,void * data ); 16 17enum class FindStyle :uint8_t 18 { 19Self ,///< Just on self 20SelfOrChildren ,///< Self, or if container just the children 21Recursive ,///< On self plus any children recursively 22Children ,///< Only on children 23ChildrenRecursive ,///< Only on children recursively 24 }; 25 26/// Find an artifact that matches desc allowing derivations. Flags is ignored 27static IArtifact * findArtifactByDerivedDesc ( 28IArtifact * artifact , 29FindStyle findStyle , 30const ArtifactDesc & desc ); 31/// Find an artifact that predicate matches 32static IArtifact * findArtifactByPredicate ( 33IArtifact * artifact , 34FindStyle findStyle , 35FindFunc func , 36void * data ); 37/// Find by name 38static IArtifact * findArtifactByName ( 39IArtifact * artifact , 40FindStyle findStyle , 41const char * name ); 42/// Find by desc exactly 43static IArtifact * findArtifactByDesc ( 44IArtifact * artifact , 45FindStyle findStyle , 46const ArtifactDesc & desc ); 47 48/// Creates an empty artifact for a type 49static ComPtr < IArtifact > createArtifactForCompileTarget (SlangCompileTarget target ); 50 51/// Create an artifact 52static ComPtr < IArtifact > createArtifact (const ArtifactDesc & desc ,const char * name ); 53static ComPtr < IArtifact > createArtifact (const ArtifactDesc & desc ); 54 55/// True if is significant 56static bool isSignificant (IArtifact * artifact ); 57/// True if is significant 58static bool isSignificant (const ArtifactDesc & desc ); 59 60/// Returns true if an artifact is 'significant'. 61/// The data parameter is unused and just used to make work as FindFunc 62static bool isSignificant (IArtifact * artifact ,void * data ); 63 64/// Find a significant artifact 65static IArtifact * findSignificant (IArtifact * artifact ); 66 67/// Find the path/name associated with the artifact. 68/// The path is *not* necessarily the path on the file system. The order of search is 69/// * If the artifact has a name return that 70/// * If the artifact has a IPathFileArtifactRepresentation (that isn't temporary) return it's 71/// path 72/// * If not found return an empty slice 73static UnownedStringSlice findPath (IArtifact * artifact ); 74/// Find a name 75static UnownedStringSlice findName (IArtifact * artifact ); 76 77/// Sometimes we have artifacts that don't specify a payload type - perhaps because they can be 78/// interpretted in different ways This function uses the associated name and file 79/// representations to infer a extension. If none is found returns an empty slice. 80static UnownedStringSlice inferExtension (IArtifact * artifact ); 81 82/// Given a desc and a basePath returns a suitable path for a entity of specified desc 83static SlangResult calcPath ( 84IArtifact * artifact , 85const UnownedStringSlice & basePath , 86StringBuilder & outPath ); 87 88/// Given a desc and a baseName works out the the output file name 89static SlangResult calcName ( 90IArtifact * artifact , 91const UnownedStringSlice & baseName , 92StringBuilder & outName ); 93 94/// Convenience function that adds metadata to artifact. If metadata is nullptr nothing is 95/// added. 96static void addAssociated (IArtifact * artifact ,IArtifactPostEmitMetadata * metadata ); 97/// Convenience function that adds diagnostics to artifact. If diagnostics is nullptr nothing is 98/// added. 99static void addAssociated (IArtifact * artifact ,IArtifactDiagnostics * diagnostics ); 100}; 101 102}// namespace Slang 103 104#endif