diff options
| author | ArielG-NV <159081215+ArielG-NV@users.noreply.github.com> | 2024-07-25 18:04:47 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-25 15:04:47 -0700 |
| commit | 2e7e2b568ce93697e36a7c0b50364dc78bd1bb97 (patch) | |
| tree | e18b2a29080adb70326ce2cf6984fbd84b8944ef /source/slang/slang-capability.cpp | |
| parent | 19657f8a3867b0ca266b06ef64d18d03f51cfbd2 (diff) | |
Add `_Internal`/`External` atom enforcement and validation. (#4702)
* Add `_Internal`/`External` atom validation and use enforcement.
Fixes: #4676
Changes:
* Added `validateInternalAtomExternalAtomPair` to the capability generator to ensure all `_Internal` atoms have a corresponding `External` atom.
* Validation of 'RequireCapabilityAttribute' warns if a user uses an '_Internal' atom.
* Added 'External' atoms to atoms with an already existing '_Internal' atom.
* Printing an atom removes '_'.
* Fixed some incorrect which were checking for the incorrect warning/error (capability4.slang, capability5.slang, capability6.slang).
* switch capability name to use `UnownedStringSlice` instead of `const char*`
switch capability name to use `UnownedStringSlice` instead of `const char*`, this includes using functions like `.startsWith`.
* grammer
---------
Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'source/slang/slang-capability.cpp')
| -rw-r--r-- | source/slang/slang-capability.cpp | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/source/slang/slang-capability.cpp b/source/slang/slang-capability.cpp index f06ccb663..00a3b6001 100644 --- a/source/slang/slang-capability.cpp +++ b/source/slang/slang-capability.cpp @@ -49,7 +49,7 @@ enum class CapabilityNameFlavor : int32_t struct CapabilityAtomInfo { /// The API-/language-exposed name of the capability. - char const* name; + UnownedStringSlice name; /// Flavor of atom: concrete, abstract, or alias CapabilityNameFlavor flavor; @@ -85,14 +85,14 @@ void getCapabilityNames(List<UnownedStringSlice>& ioNames) { if (_getInfo(CapabilityName(i)).flavor != CapabilityNameFlavor::Abstract) { - ioNames.add(UnownedStringSlice(_getInfo(CapabilityName(i)).name)); + ioNames.add(_getInfo(CapabilityName(i)).name); } } } UnownedStringSlice capabilityNameToString(CapabilityName name) { - return UnownedStringSlice(_getInfo(name).name); + return _getInfo(name).name; } bool isDirectChildOfAbstractAtom(CapabilityAtom name) @@ -111,7 +111,7 @@ bool isTargetVersionAtom(CapabilityAtom name) bool isSpirvExtensionAtom(CapabilityAtom name) { - return UnownedStringSlice(_getInfo(name).name).startsWith("SPV_"); + return _getInfo(name).name.startsWith("SPV_"); } bool lookupCapabilityName(const UnownedStringSlice& str, CapabilityName& value); @@ -124,6 +124,12 @@ CapabilityName findCapabilityName(UnownedStringSlice const& name) return result; } +bool isInternalCapabilityName(CapabilityName name) +{ + SLANG_ASSERT(_getInfo(name).name != nullptr); + return _getInfo(name).name.startsWith("_"); +} + CapabilityAtom getLatestSpirvAtom() { static CapabilityAtom result = CapabilityAtom::Invalid; @@ -964,7 +970,7 @@ void printDiagnosticArg(StringBuilder& sb, const CapabilityAtomSet atomSet) CapabilityName formattedAtom = (CapabilityName)atom; if (!isFirst) sb << " + "; - sb << capabilityNameToStringWithoutPrefix(formattedAtom); + printDiagnosticArg(sb, formattedAtom); isFirst = false; } } |
