|
|
@@ -240,6 +240,35 @@ const wgslMethods = {
|
|
|
floatunpack_float16_2x16: 'unpack2x16float'
|
|
|
};
|
|
|
|
|
|
+// See: https://www.w3.org/TR/WGSL/#keyword-summary and #reserved-words-section
|
|
|
+
|
|
|
+const wgslReservedKeywords = new Set( [
|
|
|
+ // keywords
|
|
|
+ 'alias', 'break', 'case', 'const', 'const_assert', 'continue', 'continuing', 'default', 'diagnostic',
|
|
|
+ 'discard', 'else', 'enable', 'false', 'fn', 'for', 'if', 'let', 'loop', 'override', 'requires',
|
|
|
+ 'return', 'struct', 'switch', 'true', 'var', 'while',
|
|
|
+ // reserved words
|
|
|
+ 'NULL', 'Self', 'abstract', 'active', 'alignas', 'alignof', 'as', 'asm', 'asm_fragment', 'async',
|
|
|
+ 'attribute', 'auto', 'await', 'become', 'binding_array', 'cast', 'catch', 'class', 'co_await',
|
|
|
+ 'co_return', 'co_yield', 'coherent', 'column_major', 'common', 'compile', 'compile_fragment',
|
|
|
+ 'concept', 'const_cast', 'consteval', 'constexpr', 'constinit', 'crate', 'debugger', 'decltype',
|
|
|
+ 'delete', 'demote', 'demote_to_helper', 'do', 'dynamic_cast', 'enum', 'explicit', 'export',
|
|
|
+ 'extends', 'extern', 'external', 'fallthrough', 'filter', 'final', 'finally', 'friend', 'from',
|
|
|
+ 'fxgroup', 'get', 'goto', 'groupshared', 'highp', 'impl', 'implements', 'import', 'inline',
|
|
|
+ 'instanceof', 'interface', 'layout', 'lowp', 'macro', 'macro_rules', 'match', 'mediump', 'meta',
|
|
|
+ 'mod', 'module', 'move', 'mut', 'mutable', 'namespace', 'new', 'nil', 'noexcept', 'noinline',
|
|
|
+ 'nointerpolation', 'non_coherent', 'noncoherent', 'noperspective', 'null', 'nullptr', 'of',
|
|
|
+ 'operator', 'package', 'packoffset', 'partition', 'pass', 'patch', 'pixelfragment', 'precise',
|
|
|
+ 'precision', 'premerge', 'priv', 'protected', 'pub', 'public', 'readonly', 'ref', 'regardless',
|
|
|
+ 'register', 'reinterpret_cast', 'require', 'resource', 'restrict', 'self', 'set', 'shared',
|
|
|
+ 'sizeof', 'smooth', 'snorm', 'static', 'static_assert', 'static_cast', 'std', 'subroutine',
|
|
|
+ 'super', 'target', 'template', 'this', 'thread_local', 'throw', 'trait', 'try', 'type', 'typedef',
|
|
|
+ 'typeid', 'typename', 'typeof', 'union', 'unless', 'unorm', 'unsafe', 'unsized', 'use', 'using',
|
|
|
+ 'varying', 'virtual', 'volatile', 'wgsl', 'where', 'with', 'writeonly', 'yield',
|
|
|
+ // generated entry points
|
|
|
+ 'main'
|
|
|
+] );
|
|
|
+
|
|
|
//
|
|
|
|
|
|
let diagnostics = '';
|
|
|
@@ -1148,6 +1177,18 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Returns whether the given name is a reserved keyword of WGSL.
|
|
|
+ *
|
|
|
+ * @param {string} name - The name to test.
|
|
|
+ * @return {boolean} Whether the name is a reserved keyword or not.
|
|
|
+ */
|
|
|
+ isReservedKeyword( name ) {
|
|
|
+
|
|
|
+ return wgslReservedKeywords.has( name );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Returns the output struct name.
|
|
|
*
|