use std::{collections::HashMap, sync::LazyLock};
use wgsl_parse::syntax::Ident;
pub const BUILTIN_NAMES: &[&str] = &[
"bool",
"f16",
"f32",
"i32",
"sampler",
"sampler_comparison",
"texture_depth_2d",
"texture_depth_2d_array",
"texture_depth_cube",
"texture_depth_cube_array",
"texture_depth_multisampled_2d",
"texture_external",
"u32",
"array",
"atomic",
"mat2x2",
"mat2x3",
"mat2x4",
"mat3x2",
"mat3x3",
"mat3x4",
"mat4x2",
"mat4x3",
"mat4x4",
"ptr",
"texture_1d",
"texture_2d",
"texture_2d_array",
"texture_3d",
"texture_cube",
"texture_cube_array",
"texture_multisampled_2d",
"texture_storage_1d",
"texture_storage_2d",
"texture_storage_2d_array",
"texture_storage_3d",
"vec2",
"vec3",
"vec4",
"vec2i",
"vec3i",
"vec4i",
"vec2u",
"vec3u",
"vec4u",
"vec2f",
"vec3f",
"vec4f",
"vec2h",
"vec3h",
"vec4h",
"mat2x2f",
"mat2x3f",
"mat2x4f",
"mat3x2f",
"mat3x3f",
"mat3x4f",
"mat4x2f",
"mat4x3f",
"mat4x4f",
"mat2x2h",
"mat2x3h",
"mat2x4h",
"mat3x2h",
"mat3x3h",
"mat3x4h",
"mat4x2h",
"mat4x3h",
"mat4x4h",
"bitcast",
"all",
"any",
"select",
"arrayLength",
"abs",
"acos",
"acosh",
"asin",
"asinh",
"atan",
"atanh",
"atan2",
"ceil",
"clamp",
"cos",
"cosh",
"countLeadingZeros",
"countOneBits",
"countTrailingZeros",
"cross",
"degrees",
"determinant",
"distance",
"dot",
"dot4U8Packed",
"exp",
"exp2",
"extractBits",
"faceForward",
"firstLeadingBit",
"firstTrailingBit",
"floor",
"fma",
"fract",
"frexp",
"insertBits",
"inverseSqrt",
"ldexp",
"length",
"log",
"log2",
"max",
"min",
"mix",
"modf",
"normalize",
"pow",
"quantizeToF16",
"radians",
"reflect",
"refract",
"reverseBits",
"round",
"saturate",
"sign",
"sin",
"sinh",
"smoothstep",
"sqrt",
"step",
"tan",
"tanh",
"transpose",
"trunc",
"dpdx",
"dpdxCoarse",
"dpdxFine",
"dpdy",
"dpdyCoarse",
"dpdyFine",
"fwidth",
"fwidthCoarse",
"fwidthFine",
"textureDimensions",
"textureGather",
"textureGatherCompare",
"textureLoad",
"textureNumLayers",
"textureNumLevels",
"textureNumSamples",
"textureSample",
"textureSampleBias",
"textureSampleCompare",
"textureSampleCompareLevel",
"textureSampleGrad",
"textureSampleLevel",
"textureSampleBaseClampToEdge",
"textureStore",
"atomicLoad",
"atomicStore",
"atomicAdd",
"atomicSub",
"atomicMax",
"atomicMin",
"atomicAnd",
"atomicOr",
"atomicXor",
"atomicExchange",
"atomicCompareExchangeWeak",
"pack4x8snorm",
"pack4x8unorm",
"pack4xI8",
"pack4xU8",
"pack4xI8Clamp",
"pack4xU8Clamp",
"pack2x16snorm",
"pack2x16unorm",
"pack2x16float",
"unpack4x8snorm",
"unpack4x8unorm",
"unpack4xI8",
"unpack4xU8",
"unpack2x16snorm",
"unpack2x16unorm",
"unpack2x16float",
"storageBarrier",
"textureBarrier",
"workgroupBarrier",
"workgroupUniformLoad",
"subgroupAdd",
"subgroupExclusiveAdd",
"subgroupInclusiveAdd",
"subgroupAll",
"subgroupAnd",
"subgroupAny",
"subgroupBallot",
"subgroupBroadcast",
"subgroupBroadcastFirst",
"subgroupElect",
"subgroupMax",
"subgroupMin",
"subgroupMul",
"subgroupExclusiveMul",
"subgroupInclusiveMul",
"subgroupOr",
"subgroupShuffle",
"subgroupShuffleDown",
"subgroupShuffleUp",
"subgroupShuffleXor",
"subgroupXor",
"quadBroadcast",
"quadSwapDiagonal",
"quadSwapX",
"quadSwapY",
"read",
"write",
"read_write",
"function",
"private",
"workgroup",
"uniform",
"storage",
"rgba8unorm",
"rgba8snorm",
"rgba8uint",
"rgba8sint",
"rgba16uint",
"rgba16sint",
"rgba16float",
"r32uint",
"r32sint",
"r32float",
"rg32uint",
"rg32sint",
"rg32float",
"rgba32uint",
"rgba32sint",
"rgba32float",
"bgra8unorm",
];
pub const BUILTIN_FUNCTIONS: &[&str] = &[
"bool",
"f16",
"f32",
"i32",
"u32",
"array",
"mat2x2",
"mat2x3",
"mat2x4",
"mat3x2",
"mat3x3",
"mat3x4",
"mat4x2",
"mat4x3",
"mat4x4",
"vec2",
"vec3",
"vec4",
"vec2i",
"vec3i",
"vec4i",
"vec2u",
"vec3u",
"vec4u",
"vec2f",
"vec3f",
"vec4f",
"vec2h",
"vec3h",
"vec4h",
"mat2x2f",
"mat2x3f",
"mat2x4f",
"mat3x2f",
"mat3x3f",
"mat3x4f",
"mat4x2f",
"mat4x3f",
"mat4x4f",
"mat2x2h",
"mat2x3h",
"mat2x4h",
"mat3x2h",
"mat3x3h",
"mat3x4h",
"mat4x2h",
"mat4x3h",
"mat4x4h",
"bitcast",
"all",
"any",
"select",
"arrayLength",
"abs",
"acos",
"acosh",
"asin",
"asinh",
"atan",
"atanh",
"atan2",
"ceil",
"clamp",
"cos",
"cosh",
"countLeadingZeros",
"countOneBits",
"countTrailingZeros",
"cross",
"degrees",
"determinant",
"distance",
"dot",
"dot4U8Packed",
"exp",
"exp2",
"extractBits",
"faceForward",
"firstLeadingBit",
"firstTrailingBit",
"floor",
"fma",
"fract",
"frexp",
"insertBits",
"inverseSqrt",
"ldexp",
"length",
"log",
"log2",
"max",
"min",
"mix",
"modf",
"normalize",
"pow",
"quantizeToF16",
"radians",
"reflect",
"refract",
"reverseBits",
"round",
"saturate",
"sign",
"sin",
"sinh",
"smoothstep",
"sqrt",
"step",
"tan",
"tanh",
"transpose",
"trunc",
"dpdx",
"dpdxCoarse",
"dpdxFine",
"dpdy",
"dpdyCoarse",
"dpdyFine",
"fwidth",
"fwidthCoarse",
"fwidthFine",
"textureDimensions",
"textureGather",
"textureGatherCompare",
"textureLoad",
"textureNumLayers",
"textureNumLevels",
"textureNumSamples",
"textureSample",
"textureSampleBias",
"textureSampleCompare",
"textureSampleCompareLevel",
"textureSampleGrad",
"textureSampleLevel",
"textureSampleBaseClampToEdge",
"textureStore",
"atomicLoad",
"atomicStore",
"atomicAdd",
"atomicSub",
"atomicMax",
"atomicMin",
"atomicAnd",
"atomicOr",
"atomicXor",
"atomicExchange",
"atomicCompareExchangeWeak",
"pack4x8snorm",
"pack4x8unorm",
"pack4xI8",
"pack4xU8",
"pack4xI8Clamp",
"pack4xU8Clamp",
"pack2x16snorm",
"pack2x16unorm",
"pack2x16float",
"unpack4x8snorm",
"unpack4x8unorm",
"unpack4xI8",
"unpack4xU8",
"unpack2x16snorm",
"unpack2x16unorm",
"unpack2x16float",
"storageBarrier",
"textureBarrier",
"workgroupBarrier",
"workgroupUniformLoad",
"subgroupAdd",
"subgroupExclusiveAdd",
"subgroupInclusiveAdd",
"subgroupAll",
"subgroupAnd",
"subgroupAny",
"subgroupBallot",
"subgroupBroadcast",
"subgroupBroadcastFirst",
"subgroupElect",
"subgroupMax",
"subgroupMin",
"subgroupMul",
"subgroupExclusiveMul",
"subgroupInclusiveMul",
"subgroupOr",
"subgroupShuffle",
"subgroupShuffleDown",
"subgroupShuffleUp",
"subgroupShuffleXor",
"subgroupXor",
"quadBroadcast",
"quadSwapDiagonal",
"quadSwapX",
"quadSwapY",
];
pub const RESERVED_WORDS: &[&str] = &[
"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",
];
pub fn builtin_ident(name: &str) -> Option<&'static Ident> {
macro_rules! ident {
($name:literal) => {
($name, Ident::new($name.to_string()))
};
}
static IDENTS: LazyLock<HashMap<&str, Ident>> = LazyLock::new(|| {
HashMap::from_iter([
ident!("bool"),
ident!("__AbstractInt"),
ident!("__AbstractFloat"),
ident!("i32"),
ident!("u32"),
ident!("f32"),
ident!("f32"),
ident!("f16"),
ident!("array"),
ident!("atomic"),
ident!("ptr"),
ident!("vec2"),
ident!("vec3"),
ident!("vec4"),
ident!("mat2x2"),
ident!("mat3x2"),
ident!("mat4x2"),
ident!("mat2x3"),
ident!("mat3x3"),
ident!("mat4x3"),
ident!("mat2x4"),
ident!("mat3x4"),
ident!("mat4x4"),
ident!("texture_1d"),
ident!("texture_2d"),
ident!("texture_2d_array"),
ident!("texture_3d"),
ident!("texture_cube"),
ident!("texture_cube_array"),
ident!("texture_multisampled_2d"),
ident!("texture_depth_multisampled_2d"),
ident!("texture_external"),
ident!("texture_storage_1d"),
ident!("texture_storage_2d"),
ident!("texture_storage_2d_array"),
ident!("texture_storage_3d"),
ident!("texture_depth_2d"),
ident!("texture_depth_2d_array"),
ident!("texture_depth_cube"),
ident!("texture_depth_cube_array"),
ident!("sampler"),
ident!("sampler_comparison"),
ident!("read"),
ident!("write"),
ident!("read_write"),
ident!("function"),
ident!("private"),
ident!("workgroup"),
ident!("uniform"),
ident!("storage"),
ident!("rgba8unorm"),
ident!("rgba8snorm"),
ident!("rgba8uint"),
ident!("rgba8sint"),
ident!("rgba16uint"),
ident!("rgba16sint"),
ident!("rgba16float"),
ident!("r32uint"),
ident!("r32sint"),
ident!("r32float"),
ident!("rg32uint"),
ident!("rg32sint"),
ident!("rg32float"),
ident!("rgba32uint"),
ident!("rgba32sint"),
ident!("rgba32float"),
ident!("bgra8unorm"),
])
});
IDENTS.get(name)
}