use lang_util::SmolStr;
use crate::{lexer, util::Unescaped};
use super::{
keywords::KeywordAtom,
type_names::{TypeNameAtom, TypeNameState},
};
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, derive_more::Display)]
#[allow(non_camel_case_types)]
pub enum TypeName {
#[display("void")]
VOID,
#[display("int")]
INT,
#[display("bool")]
BOOL,
#[display("float")]
FLOAT,
#[display("double")]
DOUBLE,
#[display("vec2")]
VEC2,
#[display("vec3")]
VEC3,
#[display("vec4")]
VEC4,
#[display("ivec2")]
IVEC2,
#[display("ivec3")]
IVEC3,
#[display("ivec4")]
IVEC4,
#[display("bvec2")]
BVEC2,
#[display("bvec3")]
BVEC3,
#[display("bvec4")]
BVEC4,
#[display("uint")]
UINT,
#[display("atomic_uint")]
ATOMIC_UINT,
#[display("uvec2")]
UVEC2,
#[display("uvec3")]
UVEC3,
#[display("uvec4")]
UVEC4,
#[display("dvec2")]
DVEC2,
#[display("dvec3")]
DVEC3,
#[display("dvec4")]
DVEC4,
#[display("mat2")]
MAT2,
#[display("mat3")]
MAT3,
#[display("mat4")]
MAT4,
#[display("mat2x2")]
MAT2X2,
#[display("mat2x3")]
MAT2X3,
#[display("mat2x4")]
MAT2X4,
#[display("mat3x2")]
MAT3X2,
#[display("mat3x3")]
MAT3X3,
#[display("mat3x4")]
MAT3X4,
#[display("mat4x2")]
MAT4X2,
#[display("mat4x3")]
MAT4X3,
#[display("mat4x4")]
MAT4X4,
#[display("dmat2")]
DMAT2,
#[display("dmat3")]
DMAT3,
#[display("dmat4")]
DMAT4,
#[display("dmat2x2")]
DMAT2X2,
#[display("dmat2x3")]
DMAT2X3,
#[display("dmat2x4")]
DMAT2X4,
#[display("dmat3x2")]
DMAT3X2,
#[display("dmat3x3")]
DMAT3X3,
#[display("dmat3x4")]
DMAT3X4,
#[display("dmat4x2")]
DMAT4X2,
#[display("dmat4x3")]
DMAT4X3,
#[display("dmat4x4")]
DMAT4X4,
#[display("sampler1D")]
SAMPLER1D,
#[display("sampler1DShadow")]
SAMPLER1DSHADOW,
#[display("sampler1DArray")]
SAMPLER1DARRAY,
#[display("sampler1DArrayShadow")]
SAMPLER1DARRAYSHADOW,
#[display("isampler1D")]
ISAMPLER1D,
#[display("isampler1DArray")]
ISAMPLER1DARRAY,
#[display("usampler1D")]
USAMPLER1D,
#[display("usampler1DArray")]
USAMPLER1DARRAY,
#[display("sampler2D")]
SAMPLER2D,
#[display("sampler2DShadow")]
SAMPLER2DSHADOW,
#[display("sampler2DArray")]
SAMPLER2DARRAY,
#[display("sampler2DArrayShadow")]
SAMPLER2DARRAYSHADOW,
#[display("isampler2D")]
ISAMPLER2D,
#[display("isampler2DArray")]
ISAMPLER2DARRAY,
#[display("usampler2D")]
USAMPLER2D,
#[display("usampler2DArray")]
USAMPLER2DARRAY,
#[display("sampler2DRect")]
SAMPLER2DRECT,
#[display("sampler2DRectShadow")]
SAMPLER2DRECTSHADOW,
#[display("isampler2DRect")]
ISAMPLER2DRECT,
#[display("usampler2DRect")]
USAMPLER2DRECT,
#[display("sampler2DMS")]
SAMPLER2DMS,
#[display("isampler2DMS")]
ISAMPLER2DMS,
#[display("usampler2DMS")]
USAMPLER2DMS,
#[display("sampler2DMSArray")]
SAMPLER2DMSARRAY,
#[display("isampler2DMSArray")]
ISAMPLER2DMSARRAY,
#[display("usampler2DMSArray")]
USAMPLER2DMSARRAY,
#[display("sampler3D")]
SAMPLER3D,
#[display("isampler3D")]
ISAMPLER3D,
#[display("usampler3D")]
USAMPLER3D,
#[display("samplerCube")]
SAMPLERCUBE,
#[display("samplerCubeShadow")]
SAMPLERCUBESHADOW,
#[display("isamplerCube")]
ISAMPLERCUBE,
#[display("usamplerCube")]
USAMPLERCUBE,
#[display("samplerCubeArray")]
SAMPLERCUBEARRAY,
#[display("samplerCubeArrayShadow")]
SAMPLERCUBEARRAYSHADOW,
#[display("isamplerCubeArray")]
ISAMPLERCUBEARRAY,
#[display("usamplerCubeArray")]
USAMPLERCUBEARRAY,
#[display("samplerBuffer")]
SAMPLERBUFFER,
#[display("isamplerBuffer")]
ISAMPLERBUFFER,
#[display("usamplerBuffer")]
USAMPLERBUFFER,
#[display("image1D")]
IMAGE1D,
#[display("iimage1D")]
IIMAGE1D,
#[display("uimage1D")]
UIMAGE1D,
#[display("image1DArray")]
IMAGE1DARRAY,
#[display("iimage1DArray")]
IIMAGE1DARRAY,
#[display("uimage1DArray")]
UIMAGE1DARRAY,
#[display("image2D")]
IMAGE2D,
#[display("iimage2D")]
IIMAGE2D,
#[display("uimage2D")]
UIMAGE2D,
#[display("image2DArray")]
IMAGE2DARRAY,
#[display("iimage2DArray")]
IIMAGE2DARRAY,
#[display("uimage2DArray")]
UIMAGE2DARRAY,
#[display("image2DRect")]
IMAGE2DRECT,
#[display("iimage2DRect")]
IIMAGE2DRECT,
#[display("uimage2DRect")]
UIMAGE2DRECT,
#[display("image2DMS")]
IMAGE2DMS,
#[display("iimage2DMS")]
IIMAGE2DMS,
#[display("uimage2DMS")]
UIMAGE2DMS,
#[display("image2DMSArray")]
IMAGE2DMSARRAY,
#[display("iimage2DMSArray")]
IIMAGE2DMSARRAY,
#[display("uimage2DMSArray")]
UIMAGE2DMSARRAY,
#[display("image3D")]
IMAGE3D,
#[display("iimage3D")]
IIMAGE3D,
#[display("uimage3D")]
UIMAGE3D,
#[display("imageCube")]
IMAGECUBE,
#[display("iimageCube")]
IIMAGECUBE,
#[display("uimageCube")]
UIMAGECUBE,
#[display("imageCubeArray")]
IMAGECUBEARRAY,
#[display("iimageCubeArray")]
IIMAGECUBEARRAY,
#[display("uimageCubeArray")]
UIMAGECUBEARRAY,
#[display("imageBuffer")]
IMAGEBUFFER,
#[display("iimageBuffer")]
IIMAGEBUFFER,
#[display("uimageBuffer")]
UIMAGEBUFFER,
#[display("texture1D")]
TEXTURE1D,
#[display("texture1DArray")]
TEXTURE1DARRAY,
#[display("itexture1D")]
ITEXTURE1D,
#[display("itexture1DArray")]
ITEXTURE1DARRAY,
#[display("utexture1D")]
UTEXTURE1D,
#[display("utexture1DArray")]
UTEXTURE1DARRAY,
#[display("texture2D")]
TEXTURE2D,
#[display("texture2DArray")]
TEXTURE2DARRAY,
#[display("itexture2D")]
ITEXTURE2D,
#[display("itexture2DArray")]
ITEXTURE2DARRAY,
#[display("utexture2D")]
UTEXTURE2D,
#[display("utexture2DArray")]
UTEXTURE2DARRAY,
#[display("texture2DRect")]
TEXTURE2DRECT,
#[display("itexture2DRect")]
ITEXTURE2DRECT,
#[display("utexture2DRect")]
UTEXTURE2DRECT,
#[display("texture2DMS")]
TEXTURE2DMS,
#[display("itexture2DMS")]
ITEXTURE2DMS,
#[display("utexture2DMS")]
UTEXTURE2DMS,
#[display("texture2DMSArray")]
TEXTURE2DMSARRAY,
#[display("itexture2DMSArray")]
ITEXTURE2DMSARRAY,
#[display("utexture2DMSArray")]
UTEXTURE2DMSARRAY,
#[display("texture3D")]
TEXTURE3D,
#[display("itexture3D")]
ITEXTURE3D,
#[display("utexture3D")]
UTEXTURE3D,
#[display("textureCube")]
TEXTURECUBE,
#[display("itextureCube")]
ITEXTURECUBE,
#[display("utextureCube")]
UTEXTURECUBE,
#[display("textureCubeArray")]
TEXTURECUBEARRAY,
#[display("itextureCubeArray")]
ITEXTURECUBEARRAY,
#[display("utextureCubeArray")]
UTEXTURECUBEARRAY,
#[display("textureBuffer")]
TEXTUREBUFFER,
#[display("itextureBuffer")]
ITEXTUREBUFFER,
#[display("utextureBuffer")]
UTEXTUREBUFFER,
#[display("sampler")]
SAMPLER,
#[display("samplerShadow")]
SAMPLERSHADOW,
#[display("subpassInput")]
SUBPASSINPUT,
#[display("isubpassInput")]
ISUBPASSINPUT,
#[display("usubpassInput")]
USUBPASSINPUT,
#[display("subpassInputMS")]
SUBPASSINPUTMS,
#[display("isubpassInputMS")]
ISUBPASSINPUTMS,
#[display("usubpassInputMS")]
USUBPASSINPUTMS,
RESERVED(TypeNameAtom),
OTHER(TypeNameAtom),
}
impl TypeName {
fn gate(
self,
version_gate: bool,
reserved_gate: bool,
atom: TypeNameAtom,
is_type_name: impl Fn(&TypeNameAtom) -> TypeNameState,
) -> Option<(Self, Option<TypeNameState>)> {
if version_gate {
return Some((self, None));
}
let result = is_type_name(&atom);
if result.is_type_name() {
return Some((self, Some(result)));
}
if reserved_gate {
return Some((Self::RESERVED(atom), None));
}
None
}
pub(crate) fn parse(
name: &str,
version: u16,
target_vulkan: bool,
is_type_name: impl Fn(&TypeNameAtom) -> TypeNameState,
) -> Option<(Self, Option<TypeNameState>)> {
use TypeName::*;
let type_name_atom = TypeNameAtom::from(name);
if type_name_atom == type_name!("void") {
return VOID.gate(version >= 100, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("int") {
return INT.gate(version >= 100, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("bool") {
return BOOL.gate(version >= 100, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("float") {
return FLOAT.gate(version >= 100, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("vec2") {
return VEC2.gate(version >= 100, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("vec3") {
return VEC3.gate(version >= 100, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("vec4") {
return VEC4.gate(version >= 100, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("ivec2") {
return IVEC2.gate(version >= 100, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("ivec3") {
return IVEC3.gate(version >= 100, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("ivec4") {
return IVEC4.gate(version >= 100, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("bvec2") {
return BVEC2.gate(version >= 100, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("bvec3") {
return BVEC3.gate(version >= 100, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("bvec4") {
return BVEC4.gate(version >= 100, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("mat2") {
return MAT2.gate(version >= 100, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("mat3") {
return MAT3.gate(version >= 100, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("mat4") {
return MAT4.gate(version >= 100, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("sampler1D") {
return SAMPLER1D.gate(version >= 100, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("sampler1DShadow") {
return SAMPLER1DSHADOW.gate(version >= 100, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("sampler2D") {
return SAMPLER2D.gate(version >= 100, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("sampler2DShadow") {
return SAMPLER2DSHADOW.gate(version >= 100, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("sampler3D") {
return SAMPLER3D.gate(version >= 100, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("samplerCube") {
return SAMPLERCUBE.gate(version >= 100, false, type_name_atom, is_type_name);
}
if type_name_atom == type_name!("mat2x2") {
return MAT2X2.gate(version >= 120, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("mat2x3") {
return MAT2X3.gate(version >= 120, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("mat2x4") {
return MAT2X4.gate(version >= 120, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("mat3x2") {
return MAT3X2.gate(version >= 120, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("mat3x3") {
return MAT3X3.gate(version >= 120, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("mat3x4") {
return MAT3X4.gate(version >= 120, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("mat4x2") {
return MAT4X2.gate(version >= 120, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("mat4x3") {
return MAT4X3.gate(version >= 120, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("mat4x4") {
return MAT4X4.gate(version >= 120, false, type_name_atom, is_type_name);
}
if type_name_atom == type_name!("uint") {
return UINT.gate(version >= 130, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("uvec2") {
return UVEC2.gate(version >= 130, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("uvec3") {
return UVEC3.gate(version >= 130, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("uvec4") {
return UVEC4.gate(version >= 130, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("isampler1D") {
return ISAMPLER1D.gate(version >= 130, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("isampler1DArray") {
return ISAMPLER1DARRAY.gate(version >= 130, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("isampler2D") {
return ISAMPLER2D.gate(version >= 130, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("isampler2DArray") {
return ISAMPLER2DARRAY.gate(version >= 130, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("isampler3D") {
return ISAMPLER3D.gate(version >= 130, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("isamplerCube") {
return ISAMPLERCUBE.gate(version >= 130, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("sampler1DArray") {
return SAMPLER1DARRAY.gate(version >= 130, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("sampler1DArrayShadow") {
return SAMPLER1DARRAYSHADOW.gate(version >= 130, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("sampler2DArray") {
return SAMPLER2DARRAY.gate(version >= 130, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("sampler2DArrayShadow") {
return SAMPLER2DARRAYSHADOW.gate(version >= 130, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("samplerCubeShadow") {
return SAMPLERCUBESHADOW.gate(version >= 130, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("usampler1D") {
return USAMPLER1D.gate(version >= 130, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("usampler1DArray") {
return USAMPLER1DARRAY.gate(version >= 130, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("usampler2D") {
return USAMPLER2D.gate(version >= 130, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("usampler2DArray") {
return USAMPLER2DARRAY.gate(version >= 130, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("usampler3D") {
return USAMPLER3D.gate(version >= 130, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("usamplerCube") {
return USAMPLERCUBE.gate(version >= 130, false, type_name_atom, is_type_name);
}
if type_name_atom == type_name!("sampler2DRect") {
return SAMPLER2DRECT.gate(
version >= 140,
version >= 110,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("sampler2DRectShadow") {
return SAMPLER2DRECTSHADOW.gate(
version >= 140,
version >= 110,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("isampler2DRect") {
return ISAMPLER2DRECT.gate(version >= 140, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("usampler2DRect") {
return USAMPLER2DRECT.gate(version >= 140, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("samplerBuffer") {
return SAMPLERBUFFER.gate(version >= 140, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("isamplerBuffer") {
return ISAMPLERBUFFER.gate(version >= 140, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("usamplerBuffer") {
return USAMPLERBUFFER.gate(version >= 140, false, type_name_atom, is_type_name);
}
if type_name_atom == type_name!("sampler2DMS") {
return SAMPLER2DMS.gate(version >= 150, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("isampler2DMS") {
return ISAMPLER2DMS.gate(version >= 150, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("usampler2DMS") {
return USAMPLER2DMS.gate(version >= 150, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("sampler2DMSArray") {
return SAMPLER2DMSARRAY.gate(version >= 150, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("isampler2DMSArray") {
return ISAMPLER2DMSARRAY.gate(version >= 150, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("usampler2DMSArray") {
return USAMPLER2DMSARRAY.gate(version >= 150, false, type_name_atom, is_type_name);
}
if type_name_atom == type_name!("double") {
return DOUBLE.gate(version >= 400, version >= 110, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("dvec2") {
return DVEC2.gate(version >= 400, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("dvec3") {
return DVEC3.gate(version >= 400, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("dvec4") {
return DVEC4.gate(version >= 400, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("dmat2") {
return DMAT2.gate(version >= 400, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("dmat3") {
return DMAT3.gate(version >= 400, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("dmat4") {
return DMAT4.gate(version >= 400, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("dmat2x2") {
return DMAT2X2.gate(version >= 400, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("dmat2x3") {
return DMAT2X3.gate(version >= 400, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("dmat2x4") {
return DMAT2X4.gate(version >= 400, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("dmat3x2") {
return DMAT3X2.gate(version >= 400, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("dmat3x3") {
return DMAT3X3.gate(version >= 400, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("dmat3x4") {
return DMAT3X4.gate(version >= 400, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("dmat4x2") {
return DMAT4X2.gate(version >= 400, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("dmat4x3") {
return DMAT4X3.gate(version >= 400, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("dmat4x4") {
return DMAT4X4.gate(version >= 400, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("samplerCubeArray") {
return SAMPLERCUBEARRAY.gate(version >= 400, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("samplerCubeArrayShadow") {
return SAMPLERCUBEARRAYSHADOW.gate(
version >= 400,
false,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("isamplerCubeArray") {
return ISAMPLERCUBEARRAY.gate(version >= 400, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("usamplerCubeArray") {
return USAMPLERCUBEARRAY.gate(version >= 400, false, type_name_atom, is_type_name);
}
if type_name_atom == type_name!("atomic_uint") {
return ATOMIC_UINT.gate(version >= 420, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("image1D") {
return IMAGE1D.gate(version >= 420, version >= 130, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("iimage1D") {
return IIMAGE1D.gate(version >= 420, version >= 130, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("uimage1D") {
return UIMAGE1D.gate(version >= 420, version >= 130, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("image1DArray") {
return IMAGE1DARRAY.gate(version >= 420, version >= 130, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("iimage1DArray") {
return IIMAGE1DARRAY.gate(
version >= 420,
version >= 130,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("uimage1DArray") {
return UIMAGE1DARRAY.gate(
version >= 420,
version >= 130,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("image2D") {
return IMAGE2D.gate(version >= 420, version >= 130, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("iimage2D") {
return IIMAGE2D.gate(version >= 420, version >= 130, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("uimage2D") {
return UIMAGE2D.gate(version >= 420, version >= 130, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("image2DArray") {
return IMAGE2DARRAY.gate(version >= 420, version >= 130, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("iimage2DArray") {
return IIMAGE2DARRAY.gate(
version >= 420,
version >= 130,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("uimage2DArray") {
return UIMAGE2DARRAY.gate(
version >= 420,
version >= 130,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("image2DRect") {
return IMAGE2DRECT.gate(version >= 420, version >= 130, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("iimage2DRect") {
return IIMAGE2DRECT.gate(version >= 420, version >= 130, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("uimage2DRect") {
return UIMAGE2DRECT.gate(version >= 420, version >= 130, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("image2DMS") {
return IMAGE2DMS.gate(version >= 420, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("iimage2DMS") {
return IIMAGE2DMS.gate(version >= 420, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("uimage2DMS") {
return UIMAGE2DMS.gate(version >= 420, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("image2DMSArray") {
return IMAGE2DMSARRAY.gate(version >= 420, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("iimage2DMSArray") {
return IIMAGE2DMSARRAY.gate(version >= 420, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("uimage2DMSArray") {
return UIMAGE2DMSARRAY.gate(version >= 420, false, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("image3D") {
return IMAGE3D.gate(version >= 420, version >= 130, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("iimage3D") {
return IIMAGE3D.gate(version >= 420, version >= 130, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("uimage3D") {
return UIMAGE3D.gate(version >= 420, version >= 130, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("imageCube") {
return IMAGECUBE.gate(version >= 420, version >= 130, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("iimageCube") {
return IIMAGECUBE.gate(version >= 420, version >= 130, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("uimageCube") {
return UIMAGECUBE.gate(version >= 420, version >= 130, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("imageCubeArray") {
return IMAGECUBEARRAY.gate(
version >= 420,
version >= 130,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("iimageCubeArray") {
return IIMAGECUBEARRAY.gate(
version >= 420,
version >= 130,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("uimageCubeArray") {
return UIMAGECUBEARRAY.gate(
version >= 420,
version >= 130,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("imageBuffer") {
return IMAGEBUFFER.gate(version >= 420, version >= 130, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("iimageBuffer") {
return IIMAGEBUFFER.gate(version >= 420, version >= 130, type_name_atom, is_type_name);
} else if type_name_atom == type_name!("uimageBuffer") {
return UIMAGEBUFFER.gate(version >= 420, version >= 130, type_name_atom, is_type_name);
}
if type_name_atom == type_name!("texture1D") {
return TEXTURE1D.gate(
version >= 460 && target_vulkan,
false,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("texture1DArray") {
return TEXTURE1DARRAY.gate(
version >= 460 && target_vulkan,
false,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("itexture1D") {
return ITEXTURE1D.gate(
version >= 460 && target_vulkan,
false,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("itexture1DArray") {
return ITEXTURE1DARRAY.gate(
version >= 460 && target_vulkan,
false,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("utexture1D") {
return UTEXTURE1D.gate(
version >= 460 && target_vulkan,
false,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("utexture1DArray") {
return UTEXTURE1DARRAY.gate(
version >= 460 && target_vulkan,
false,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("texture2D") {
return TEXTURE2D.gate(
version >= 460 && target_vulkan,
false,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("texture2DArray") {
return TEXTURE2DARRAY.gate(
version >= 460 && target_vulkan,
false,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("itexture2D") {
return ITEXTURE2D.gate(
version >= 460 && target_vulkan,
false,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("itexture2DArray") {
return ITEXTURE2DARRAY.gate(
version >= 460 && target_vulkan,
false,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("utexture2D") {
return UTEXTURE2D.gate(
version >= 460 && target_vulkan,
false,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("utexture2DArray") {
return UTEXTURE2DARRAY.gate(
version >= 460 && target_vulkan,
false,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("texture2DRect") {
return TEXTURE2DRECT.gate(
version >= 460 && target_vulkan,
false,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("itexture2DRect") {
return ITEXTURE2DRECT.gate(
version >= 460 && target_vulkan,
false,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("utexture2DRect") {
return UTEXTURE2DRECT.gate(
version >= 460 && target_vulkan,
false,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("texture2DMS") {
return TEXTURE2DMS.gate(
version >= 460 && target_vulkan,
false,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("itexture2DMS") {
return ITEXTURE2DMS.gate(
version >= 460 && target_vulkan,
false,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("utexture2DMS") {
return UTEXTURE2DMS.gate(
version >= 460 && target_vulkan,
false,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("texture2DMSArray") {
return TEXTURE2DMSARRAY.gate(
version >= 460 && target_vulkan,
false,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("itexture2DMSArray") {
return ITEXTURE2DMSARRAY.gate(
version >= 460 && target_vulkan,
false,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("utexture2DMSArray") {
return UTEXTURE2DMSARRAY.gate(
version >= 460 && target_vulkan,
false,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("texture3D") {
return TEXTURE3D.gate(
version >= 460 && target_vulkan,
false,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("itexture3D") {
return ITEXTURE3D.gate(
version >= 460 && target_vulkan,
false,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("utexture3D") {
return UTEXTURE3D.gate(
version >= 460 && target_vulkan,
false,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("textureCube") {
return TEXTURECUBE.gate(
version >= 460 && target_vulkan,
false,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("itextureCube") {
return ITEXTURECUBE.gate(
version >= 460 && target_vulkan,
false,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("utextureCube") {
return UTEXTURECUBE.gate(
version >= 460 && target_vulkan,
false,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("textureCubeArray") {
return TEXTURECUBEARRAY.gate(
version >= 460 && target_vulkan,
false,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("itextureCubeArray") {
return ITEXTURECUBEARRAY.gate(
version >= 460 && target_vulkan,
false,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("utextureCubeArray") {
return UTEXTURECUBEARRAY.gate(
version >= 460 && target_vulkan,
false,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("textureBuffer") {
return TEXTUREBUFFER.gate(
version >= 460 && target_vulkan,
false,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("itextureBuffer") {
return ITEXTUREBUFFER.gate(
version >= 460 && target_vulkan,
false,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("utextureBuffer") {
return UTEXTUREBUFFER.gate(
version >= 460 && target_vulkan,
false,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("sampler") {
return SAMPLER.gate(
version >= 460 && target_vulkan,
false,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("samplerShadow") {
return SAMPLERSHADOW.gate(
version >= 460 && target_vulkan,
false,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("subpassInput") {
return SUBPASSINPUT.gate(
version >= 460 && target_vulkan,
false,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("isubpassInput") {
return ISUBPASSINPUT.gate(
version >= 460 && target_vulkan,
false,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("usubpassInput") {
return USUBPASSINPUT.gate(
version >= 460 && target_vulkan,
false,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("subpassInputMS") {
return SUBPASSINPUTMS.gate(
version >= 460 && target_vulkan,
false,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("isubpassInputMS") {
return ISUBPASSINPUTMS.gate(
version >= 460 && target_vulkan,
false,
type_name_atom,
is_type_name,
);
} else if type_name_atom == type_name!("usubpassInputMS") {
return USUBPASSINPUTMS.gate(
version >= 460 && target_vulkan,
false,
type_name_atom,
is_type_name,
);
}
if type_name_atom == type_name!("hvec2")
|| type_name_atom == type_name!("hvec3")
|| type_name_atom == type_name!("hvec4")
|| type_name_atom == type_name!("fvec2")
|| type_name_atom == type_name!("fvec3")
|| type_name_atom == type_name!("fvec4")
|| type_name_atom == type_name!("sampler3DRect")
{
return Some((RESERVED(type_name_atom), None));
}
let result = is_type_name(&type_name_atom);
if result.is_type_name() {
return Some((OTHER(type_name_atom), Some(result)));
}
None
}
}
#[derive(Debug, Clone, PartialEq, PartialOrd, lang_util::Token)]
#[allow(non_camel_case_types)]
pub enum Token {
#[lang_util(parser = "IDENT", kind = "identifier")]
IDENT(SmolStr),
#[lang_util(parser = "TYPE_NAME", kind = "type name")]
TYPE_NAME(TypeName),
#[lang_util(parser = "FLOAT_CONST", kind = "float constant", kind = "literal")]
FLOAT_CONST(f32),
#[lang_util(parser = "INT_CONST", kind = "int constant", kind = "literal")]
INT_CONST(i32),
#[lang_util(parser = "UINT_CONST", kind = "uint constant", kind = "literal")]
UINT_CONST(u32),
#[lang_util(parser = "BOOL_CONST", kind = "bool constant", kind = "literal")]
BOOL_CONST(bool),
#[lang_util(parser = "DOUBLE_CONST", kind = "double constant", kind = "literal")]
DOUBLE_CONST(f64),
#[lang_util(token = "<<", kind = "binary operator", kind = "operator")]
LEFT_OP,
#[lang_util(token = ">>", kind = "binary operator", kind = "operator")]
RIGHT_OP,
#[lang_util(token = "++", kind = "unary operator", kind = "operator")]
INC_OP,
#[lang_util(token = "--", kind = "unary operator", kind = "operator")]
DEC_OP,
#[lang_util(token = "<=", kind = "binary operator", kind = "operator")]
LE_OP,
#[lang_util(token = ">=", kind = "binary operator", kind = "operator")]
GE_OP,
#[lang_util(token = "==", kind = "binary operator", kind = "operator")]
EQ_OP,
#[lang_util(token = "!=", kind = "binary operator", kind = "operator")]
NE_OP,
#[lang_util(token = "&&", kind = "binary operator", kind = "operator")]
AND_OP,
#[lang_util(token = "||", kind = "binary operator", kind = "operator")]
OR_OP,
#[lang_util(token = "^^", kind = "binary operator", kind = "operator")]
XOR_OP,
#[lang_util(token = "*=", kind = "binary operator", kind = "operator")]
MUL_ASSIGN,
#[lang_util(token = "/=", kind = "binary operator", kind = "operator")]
DIV_ASSIGN,
#[lang_util(token = "+=", kind = "binary operator", kind = "operator")]
ADD_ASSIGN,
#[lang_util(token = "%=", kind = "binary operator", kind = "operator")]
MOD_ASSIGN,
#[lang_util(token = "<<=", kind = "binary operator", kind = "operator")]
LEFT_ASSIGN,
#[lang_util(token = ">>=", kind = "binary operator", kind = "operator")]
RIGHT_ASSIGN,
#[lang_util(token = "&=", kind = "binary operator", kind = "operator")]
AND_ASSIGN,
#[lang_util(token = "^=", kind = "binary operator", kind = "operator")]
XOR_ASSIGN,
#[lang_util(token = "|=", kind = "binary operator", kind = "operator")]
OR_ASSIGN,
#[lang_util(token = "-=", kind = "binary operator", kind = "operator")]
SUB_ASSIGN,
#[lang_util(token = "(")]
LPAREN,
#[lang_util(token = ")")]
RPAREN,
#[lang_util(token = "[")]
LBRACKET,
#[lang_util(token = "]")]
RBRACKET,
#[lang_util(token = "{")]
LBRACE,
#[lang_util(token = "}")]
RBRACE,
#[lang_util(token = ".", kind = "binary operator", kind = "operator")]
PERIOD,
#[lang_util(token = ",", kind = "operator")]
COMMA,
#[lang_util(token = ":", kind = "operator")]
COLON,
#[lang_util(token = "=", kind = "binary operator", kind = "operator")]
EQUAL,
#[lang_util(token = ";")]
SEMICOLON,
#[lang_util(token = "!", kind = "unary operator", kind = "operator")]
BANG,
#[lang_util(
token = "-",
kind = "binary operator",
kind = "unary operator",
kind = "operator"
)]
DASH,
#[lang_util(token = "~", kind = "unary operator", kind = "operator")]
TILDE,
#[lang_util(
token = "+",
kind = "binary operator",
kind = "unary operator",
kind = "operator"
)]
PLUS,
#[lang_util(token = "*", kind = "binary operator", kind = "operator")]
ASTERISK,
#[lang_util(token = "/", kind = "binary operator", kind = "operator")]
SLASH,
#[lang_util(token = "%", kind = "binary operator", kind = "operator")]
PERCENT,
#[lang_util(token = "<", kind = "binary operator", kind = "operator")]
LANGLE,
#[lang_util(token = ">", kind = "binary operator", kind = "operator")]
RANGLE,
#[lang_util(token = "|", kind = "binary operator", kind = "operator")]
BAR,
#[lang_util(token = "^", kind = "binary operator", kind = "operator")]
CARET,
#[lang_util(token = "&", kind = "binary operator", kind = "operator")]
AMPERSAND,
#[lang_util(token = "?", kind = "operator")]
QUESTION,
#[lang_util(token = "#")]
HASH,
#[lang_util(token = "const", kind = "storage qualifier", kind = "type qualifier")]
CONST,
#[lang_util(token = "uniform", kind = "storage qualifier", kind = "type qualifier")]
UNIFORM,
#[lang_util(token = "buffer", kind = "storage qualifier", kind = "type qualifier")]
BUFFER,
#[lang_util(token = "shared", kind = "storage qualifier", kind = "type qualifier")]
SHARED,
#[lang_util(
token = "attribute",
kind = "storage qualifier",
kind = "type qualifier"
)]
ATTRIBUTE,
#[lang_util(token = "varying", kind = "storage qualifier", kind = "type qualifier")]
VARYING,
#[lang_util(
token = "coherent",
kind = "storage qualifier",
kind = "type qualifier"
)]
COHERENT,
#[lang_util(
token = "volatile",
kind = "storage qualifier",
kind = "type qualifier"
)]
VOLATILE,
#[lang_util(
token = "restrict",
kind = "storage qualifier",
kind = "type qualifier"
)]
RESTRICT,
#[lang_util(
token = "readonly",
kind = "storage qualifier",
kind = "type qualifier"
)]
READONLY,
#[lang_util(
token = "writeonly",
kind = "storage qualifier",
kind = "type qualifier"
)]
WRITEONLY,
#[lang_util(token = "layout", kind = "layout qualifier", kind = "type qualifier")]
LAYOUT,
#[lang_util(
token = "centroid",
kind = "storage qualifier",
kind = "type qualifier"
)]
CENTROID,
#[lang_util(
token = "flat",
kind = "interpolation qualifier",
kind = "type qualifier"
)]
FLAT,
#[lang_util(
token = "smooth",
kind = "interpolation qualifier",
kind = "type qualifier"
)]
SMOOTH,
#[lang_util(
token = "noperspective",
kind = "interpolation qualifier",
kind = "type qualifier"
)]
NOPERSPECTIVE,
#[lang_util(token = "patch", kind = "storage qualifier", kind = "type qualifier")]
PATCH,
#[lang_util(token = "sample", kind = "storage qualifier", kind = "type qualifier")]
SAMPLE,
#[lang_util(token = "invariant", kind = "type qualifier")]
INVARIANT,
#[lang_util(token = "precise", kind = "type qualifier")]
PRECISE,
#[lang_util(token = "break", kind = "keyword")]
BREAK,
#[lang_util(token = "continue", kind = "keyword")]
CONTINUE,
#[lang_util(token = "do", kind = "keyword")]
DO,
#[lang_util(token = "for", kind = "keyword")]
FOR,
#[lang_util(token = "while", kind = "keyword")]
WHILE,
#[lang_util(token = "switch", kind = "keyword")]
SWITCH,
#[lang_util(token = "case", kind = "keyword")]
CASE,
#[lang_util(token = "default", kind = "keyword")]
DEFAULT,
#[lang_util(token = "if", kind = "keyword")]
IF,
#[lang_util(token = "else", kind = "keyword")]
ELSE,
#[lang_util(
token = "subroutine",
kind = "storage qualifier",
kind = "type qualifier"
)]
SUBROUTINE,
#[lang_util(token = "in", kind = "storage qualifier", kind = "type qualifier")]
IN,
#[lang_util(token = "out", kind = "storage qualifier", kind = "type qualifier")]
OUT,
#[lang_util(token = "inout", kind = "storage qualifier", kind = "type qualifier")]
INOUT,
#[lang_util(token = "discard", kind = "keyword")]
DISCARD,
#[lang_util(token = "return", kind = "keyword")]
RETURN,
#[lang_util(token = "lowp", kind = "precision qualifier", kind = "type qualifier")]
LOWP,
#[lang_util(
token = "mediump",
kind = "precision qualifier",
kind = "type qualifier"
)]
MEDIUMP,
#[lang_util(token = "highp", kind = "precision qualifier", kind = "type qualifier")]
HIGHP,
#[lang_util(token = "precision")]
PRECISION,
#[lang_util(token = "struct", kind = "struct", kind = "keyword")]
STRUCT,
#[lang_util(token = "common", kind = "reserved keyword")]
COMMON,
#[lang_util(token = "partition", kind = "reserved keyword")]
PARTITION,
#[lang_util(token = "active", kind = "reserved keyword")]
ACTIVE,
#[lang_util(token = "asm", kind = "reserved keyword")]
ASM,
#[lang_util(token = "class", kind = "reserved keyword")]
CLASS,
#[lang_util(token = "union", kind = "reserved keyword")]
UNION,
#[lang_util(token = "enum", kind = "reserved keyword")]
ENUM,
#[lang_util(token = "typedef", kind = "reserved keyword")]
TYPEDEF,
#[lang_util(token = "template", kind = "reserved keyword")]
TEMPLATE,
#[lang_util(token = "this", kind = "reserved keyword")]
THIS,
#[lang_util(token = "resource", kind = "reserved keyword")]
RESOURCE,
#[lang_util(token = "goto", kind = "reserved keyword")]
GOTO,
#[lang_util(token = "inline", kind = "reserved keyword")]
INLINE,
#[lang_util(token = "noinline", kind = "reserved keyword")]
NOINLINE,
#[lang_util(token = "public", kind = "reserved keyword")]
PUBLIC,
#[lang_util(token = "static", kind = "reserved keyword")]
STATIC,
#[lang_util(token = "extern", kind = "reserved keyword")]
EXTERN,
#[lang_util(token = "external", kind = "reserved keyword")]
EXTERNAL,
#[lang_util(token = "interface", kind = "reserved keyword")]
INTERFACE,
#[lang_util(token = "long", kind = "reserved keyword")]
LONG,
#[lang_util(token = "short", kind = "reserved keyword")]
SHORT,
#[lang_util(token = "half", kind = "reserved keyword")]
HALF,
#[lang_util(token = "fixed", kind = "reserved keyword")]
FIXED,
#[lang_util(token = "unsigned", kind = "reserved keyword")]
UNSIGNED,
#[lang_util(token = "superp", kind = "reserved keyword")]
SUPERP,
#[lang_util(token = "input", kind = "reserved keyword")]
INPUT,
#[lang_util(token = "output", kind = "reserved keyword")]
OUTPUT,
#[lang_util(token = "filter", kind = "reserved keyword")]
FILTER,
#[lang_util(token = "sizeof", kind = "reserved keyword")]
SIZEOF,
#[lang_util(token = "cast", kind = "reserved keyword")]
CAST,
#[lang_util(token = "namespace", kind = "reserved keyword")]
NAMESPACE,
#[lang_util(token = "using", kind = "reserved keyword")]
USING,
#[lang_util(display = "<whitespace>", parser(display), kind = "trivia")]
WS,
#[lang_util(display = "<comment>", parser(display), kind = "trivia")]
COMMENT,
#[lang_util(display = "<invalid token>", parser(display), kind = "error")]
ERROR(ErrorKind),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, derive_more::Display)]
pub enum ErrorKind {
#[display("invalid token")]
InvalidToken,
#[display("invalid int literal")]
InvalidIntLiteral,
#[display("invalid uint literal")]
InvalidUIntLiteral,
#[display("invalid float literal")]
InvalidFloatLiteral,
#[display("invalid double literal")]
InvalidDoubleLiteral,
}
impl Token {
pub fn from_token(
token: lexer::TextToken,
source: &str,
version: u16,
target_vulkan: bool,
is_type_name: impl Fn(&TypeNameAtom) -> TypeNameState,
) -> (Token, Option<TypeNameState>) {
use Token::*;
let kind = &*token;
match kind {
lexer::Token::IDENT_KW | lexer::Token::DIGITS => {}
lexer::Token::PERIOD => {
return (PERIOD, None);
}
lexer::Token::PLUS => {
return (PLUS, None);
}
lexer::Token::DASH => {
return (DASH, None);
}
lexer::Token::SLASH => {
return (SLASH, None);
}
lexer::Token::ASTERISK => {
return (ASTERISK, None);
}
lexer::Token::PERCENT => {
return (PERCENT, None);
}
lexer::Token::LANGLE => {
return (LANGLE, None);
}
lexer::Token::RANGLE => {
return (RANGLE, None);
}
lexer::Token::LBRACKET => {
return (LBRACKET, None);
}
lexer::Token::RBRACKET => {
return (RBRACKET, None);
}
lexer::Token::LPAREN => {
return (LPAREN, None);
}
lexer::Token::RPAREN => {
return (RPAREN, None);
}
lexer::Token::LBRACE => {
return (LBRACE, None);
}
lexer::Token::RBRACE => {
return (RBRACE, None);
}
lexer::Token::CARET => {
return (CARET, None);
}
lexer::Token::BAR => {
return (BAR, None);
}
lexer::Token::AMPERSAND => {
return (AMPERSAND, None);
}
lexer::Token::TILDE => {
return (TILDE, None);
}
lexer::Token::EQUAL => {
return (EQUAL, None);
}
lexer::Token::BANG => {
return (BANG, None);
}
lexer::Token::COLON => {
return (COLON, None);
}
lexer::Token::SEMICOLON => {
return (SEMICOLON, None);
}
lexer::Token::COMMA => {
return (COMMA, None);
}
lexer::Token::QUESTION => {
return (QUESTION, None);
}
lexer::Token::HASH => {
return (HASH, None);
}
lexer::Token::COMMENT => {
return (COMMENT, None);
}
lexer::Token::LEFT_OP => {
return (LEFT_OP, None);
}
lexer::Token::RIGHT_OP => {
return (RIGHT_OP, None);
}
lexer::Token::INC_OP => {
return (INC_OP, None);
}
lexer::Token::DEC_OP => {
return (DEC_OP, None);
}
lexer::Token::LE_OP => {
return (LE_OP, None);
}
lexer::Token::GE_OP => {
return (GE_OP, None);
}
lexer::Token::EQ_OP => {
return (EQ_OP, None);
}
lexer::Token::NE_OP => {
return (NE_OP, None);
}
lexer::Token::AND_OP => {
return (AND_OP, None);
}
lexer::Token::OR_OP => {
return (OR_OP, None);
}
lexer::Token::XOR_OP => {
return (XOR_OP, None);
}
lexer::Token::MUL_ASSIGN => {
return (MUL_ASSIGN, None);
}
lexer::Token::DIV_ASSIGN => {
return (DIV_ASSIGN, None);
}
lexer::Token::ADD_ASSIGN => {
return (ADD_ASSIGN, None);
}
lexer::Token::MOD_ASSIGN => {
return (MOD_ASSIGN, None);
}
lexer::Token::LEFT_ASSIGN => {
return (LEFT_ASSIGN, None);
}
lexer::Token::RIGHT_ASSIGN => {
return (RIGHT_ASSIGN, None);
}
lexer::Token::AND_ASSIGN => {
return (AND_ASSIGN, None);
}
lexer::Token::XOR_ASSIGN => {
return (XOR_ASSIGN, None);
}
lexer::Token::OR_ASSIGN => {
return (OR_ASSIGN, None);
}
lexer::Token::SUB_ASSIGN => {
return (SUB_ASSIGN, None);
}
lexer::Token::DEFINED
| lexer::Token::LINECONT
| lexer::Token::NEWLINE
| lexer::Token::WS => {
return (WS, None);
}
lexer::Token::QUOTE_STRING
| lexer::Token::ANGLE_STRING
| lexer::Token::BACKSLASH
| lexer::Token::ERROR
| lexer::Token::PP_CONCAT => {
return (ERROR(ErrorKind::InvalidToken), None);
}
}
let text = Unescaped::new(token.raw(source)).to_string();
if *kind == lexer::Token::IDENT_KW {
let keyword_atom = KeywordAtom::from(text.as_ref());
if let Some(keyword) = Token::parse_kw(&keyword_atom) {
return (keyword, None);
}
if let Some((type_name, state)) =
TypeName::parse(text.as_ref(), version, target_vulkan, is_type_name)
{
return (TYPE_NAME(type_name), state);
}
(IDENT(text.into()), None)
} else if *kind == lexer::Token::DIGITS {
(Token::parse_digits(&text), None)
} else {
unreachable!()
}
}
pub(crate) fn parse_kw(keyword_atom: &KeywordAtom) -> Option<Self> {
use Token::*;
if *keyword_atom == keyword!("const") {
Some(CONST)
} else if *keyword_atom == keyword!("uniform") {
Some(UNIFORM)
} else if *keyword_atom == keyword!("buffer") {
Some(BUFFER)
} else if *keyword_atom == keyword!("shared") {
Some(SHARED)
} else if *keyword_atom == keyword!("attribute") {
Some(ATTRIBUTE)
} else if *keyword_atom == keyword!("varying") {
Some(VARYING)
} else if *keyword_atom == keyword!("coherent") {
Some(COHERENT)
} else if *keyword_atom == keyword!("volatile") {
Some(VOLATILE)
} else if *keyword_atom == keyword!("restrict") {
Some(RESTRICT)
} else if *keyword_atom == keyword!("readonly") {
Some(READONLY)
} else if *keyword_atom == keyword!("writeonly") {
Some(WRITEONLY)
} else if *keyword_atom == keyword!("layout") {
Some(LAYOUT)
} else if *keyword_atom == keyword!("centroid") {
Some(CENTROID)
} else if *keyword_atom == keyword!("flat") {
Some(FLAT)
} else if *keyword_atom == keyword!("smooth") {
Some(SMOOTH)
} else if *keyword_atom == keyword!("noperspective") {
Some(NOPERSPECTIVE)
} else if *keyword_atom == keyword!("patch") {
Some(PATCH)
} else if *keyword_atom == keyword!("sample") {
Some(SAMPLE)
} else if *keyword_atom == keyword!("invariant") {
Some(INVARIANT)
} else if *keyword_atom == keyword!("precise") {
Some(PRECISE)
} else if *keyword_atom == keyword!("break") {
Some(BREAK)
} else if *keyword_atom == keyword!("continue") {
Some(CONTINUE)
} else if *keyword_atom == keyword!("do") {
Some(DO)
} else if *keyword_atom == keyword!("for") {
Some(FOR)
} else if *keyword_atom == keyword!("while") {
Some(WHILE)
} else if *keyword_atom == keyword!("switch") {
Some(SWITCH)
} else if *keyword_atom == keyword!("case") {
Some(CASE)
} else if *keyword_atom == keyword!("default") {
Some(DEFAULT)
} else if *keyword_atom == keyword!("if") {
Some(IF)
} else if *keyword_atom == keyword!("else") {
Some(ELSE)
} else if *keyword_atom == keyword!("subroutine") {
Some(SUBROUTINE)
} else if *keyword_atom == keyword!("in") {
Some(IN)
} else if *keyword_atom == keyword!("out") {
Some(OUT)
} else if *keyword_atom == keyword!("inout") {
Some(INOUT)
} else if *keyword_atom == keyword!("true") {
Some(BOOL_CONST(true))
} else if *keyword_atom == keyword!("false") {
Some(BOOL_CONST(false))
} else if *keyword_atom == keyword!("discard") {
Some(DISCARD)
} else if *keyword_atom == keyword!("return") {
Some(RETURN)
} else if *keyword_atom == keyword!("lowp") {
Some(LOWP)
} else if *keyword_atom == keyword!("mediump") {
Some(MEDIUMP)
} else if *keyword_atom == keyword!("highp") {
Some(HIGHP)
} else if *keyword_atom == keyword!("precision") {
Some(PRECISION)
} else if *keyword_atom == keyword!("struct") {
Some(STRUCT)
}
else if *keyword_atom == keyword!("common") {
Some(COMMON)
} else if *keyword_atom == keyword!("partition") {
Some(PARTITION)
} else if *keyword_atom == keyword!("active") {
Some(ACTIVE)
} else if *keyword_atom == keyword!("asm") {
Some(ASM)
} else if *keyword_atom == keyword!("class") {
Some(CLASS)
} else if *keyword_atom == keyword!("union") {
Some(UNION)
} else if *keyword_atom == keyword!("enum") {
Some(ENUM)
} else if *keyword_atom == keyword!("typedef") {
Some(TYPEDEF)
} else if *keyword_atom == keyword!("template") {
Some(TEMPLATE)
} else if *keyword_atom == keyword!("this") {
Some(THIS)
} else if *keyword_atom == keyword!("resource") {
Some(RESOURCE)
} else if *keyword_atom == keyword!("goto") {
Some(GOTO)
} else if *keyword_atom == keyword!("inline") {
Some(INLINE)
} else if *keyword_atom == keyword!("noinline") {
Some(NOINLINE)
} else if *keyword_atom == keyword!("public") {
Some(PUBLIC)
} else if *keyword_atom == keyword!("static") {
Some(STATIC)
} else if *keyword_atom == keyword!("extern") {
Some(EXTERN)
} else if *keyword_atom == keyword!("external") {
Some(EXTERNAL)
} else if *keyword_atom == keyword!("interface") {
Some(INTERFACE)
} else if *keyword_atom == keyword!("long") {
Some(LONG)
} else if *keyword_atom == keyword!("short") {
Some(SHORT)
} else if *keyword_atom == keyword!("half") {
Some(HALF)
} else if *keyword_atom == keyword!("fixed") {
Some(FIXED)
} else if *keyword_atom == keyword!("unsigned") {
Some(UNSIGNED)
} else if *keyword_atom == keyword!("superp") {
Some(SUPERP)
} else if *keyword_atom == keyword!("input") {
Some(INPUT)
} else if *keyword_atom == keyword!("output") {
Some(OUTPUT)
} else if *keyword_atom == keyword!("filter") {
Some(FILTER)
} else if *keyword_atom == keyword!("sizeof") {
Some(SIZEOF)
} else if *keyword_atom == keyword!("cast") {
Some(CAST)
} else if *keyword_atom == keyword!("namespace") {
Some(NAMESPACE)
} else if *keyword_atom == keyword!("using") {
Some(USING)
} else {
None
}
}
fn strip_suffix(text: &str) -> (bool, &str) {
if let Some(stripped) = text.strip_suffix(&['u', 'U']) {
(true, stripped)
} else {
(false, text)
}
}
fn parse_int(text: &str, radix: u32) -> Result<Self, ErrorKind> {
use Token::*;
let (unsigned, text) = Self::strip_suffix(text);
if unsigned {
if radix == 8 && text.is_empty() {
Ok(UINT_CONST(0))
} else {
u32::from_str_radix(text, radix)
.map(UINT_CONST)
.map_err(|_| ErrorKind::InvalidUIntLiteral)
}
} else {
i32::from_str_radix(text, radix)
.map(INT_CONST)
.map_err(|_| ErrorKind::InvalidIntLiteral)
}
}
pub(crate) fn parse_digits(text: &str) -> Self {
use Token::*;
let hex_prefix = text.strip_prefix("0x").or_else(|| text.strip_prefix("0X"));
let result = if (text.ends_with('f')
|| text.ends_with('F')
|| text.contains('.')
|| (text.contains(|ch| ch == 'e' || ch == 'E')))
&& hex_prefix.is_none()
{
if let Some(double) = text.strip_suffix("lf").or_else(|| text.strip_suffix("LF")) {
double
.parse()
.map(DOUBLE_CONST)
.map_err(|_| ErrorKind::InvalidDoubleLiteral)
} else if let Some(float) = text.strip_suffix(&['f', 'F']).or(Some(text)) {
float
.parse()
.map(FLOAT_CONST)
.map_err(|_| ErrorKind::InvalidFloatLiteral)
} else {
Err(ErrorKind::InvalidFloatLiteral)
}
} else {
if let Some(text) = hex_prefix {
Self::parse_int(text, 16)
} else if let Some(text) = text.strip_prefix('0') {
if text.is_empty() {
if Self::strip_suffix(text).0 {
Ok(UINT_CONST(0))
} else {
Ok(INT_CONST(0))
}
} else {
Self::parse_int(text, 8)
}
} else {
Self::parse_int(text, 10)
}
};
match result {
Ok(res) => res,
Err(err) => ERROR(err),
}
}
}
#[cfg(test)]
mod tests {
use super::Token::{self, *};
#[test]
fn test_parse_float_constant() {
assert_eq!(Token::parse_digits("0."), FLOAT_CONST(0.));
assert_eq!(Token::parse_digits(".0"), FLOAT_CONST(0.));
assert_eq!(Token::parse_digits(".035"), FLOAT_CONST(0.035));
assert_eq!(Token::parse_digits("0."), FLOAT_CONST(0.));
assert_eq!(Token::parse_digits("0.035"), FLOAT_CONST(0.035));
assert_eq!(Token::parse_digits(".035f"), FLOAT_CONST(0.035));
assert_eq!(Token::parse_digits("0.f"), FLOAT_CONST(0.));
assert_eq!(Token::parse_digits("314.f"), FLOAT_CONST(314.));
assert_eq!(Token::parse_digits("0.035f"), FLOAT_CONST(0.035));
assert_eq!(Token::parse_digits(".035F"), FLOAT_CONST(0.035));
assert_eq!(Token::parse_digits("0.F"), FLOAT_CONST(0.));
assert_eq!(Token::parse_digits("0.035F"), FLOAT_CONST(0.035));
assert_eq!(Token::parse_digits("1.03e+34"), FLOAT_CONST(1.03e+34));
assert_eq!(Token::parse_digits("1.03E+34"), FLOAT_CONST(1.03E+34));
assert_eq!(Token::parse_digits("1.03e-34"), FLOAT_CONST(1.03e-34));
assert_eq!(Token::parse_digits("1.03E-34"), FLOAT_CONST(1.03E-34));
assert_eq!(Token::parse_digits("1.03e+34f"), FLOAT_CONST(1.03e+34));
assert_eq!(Token::parse_digits("1.03E+34f"), FLOAT_CONST(1.03E+34));
assert_eq!(Token::parse_digits("1.03e-34f"), FLOAT_CONST(1.03e-34));
assert_eq!(Token::parse_digits("1.03E-34f"), FLOAT_CONST(1.03E-34));
assert_eq!(Token::parse_digits("1.03e+34F"), FLOAT_CONST(1.03e+34));
assert_eq!(Token::parse_digits("1.03E+34F"), FLOAT_CONST(1.03E+34));
assert_eq!(Token::parse_digits("1.03e-34F"), FLOAT_CONST(1.03e-34));
assert_eq!(Token::parse_digits("1.03E-34F"), FLOAT_CONST(1.03E-34));
assert_eq!(Token::parse_digits("1e-34"), FLOAT_CONST(1E-34));
assert_eq!(Token::parse_digits("1e-34f"), FLOAT_CONST(1E-34));
assert_eq!(Token::parse_digits("1E-34f"), FLOAT_CONST(1E-34));
assert_eq!(Token::parse_digits("1e-34F"), FLOAT_CONST(1E-34));
assert_eq!(Token::parse_digits("1E-34F"), FLOAT_CONST(1E-34));
}
#[test]
fn test_parse_double_constant() {
assert_eq!(Token::parse_digits("0.lf"), DOUBLE_CONST(0.));
assert_eq!(Token::parse_digits("0.035lf"), DOUBLE_CONST(0.035));
assert_eq!(Token::parse_digits(".035lf"), DOUBLE_CONST(0.035));
assert_eq!(Token::parse_digits(".035LF"), DOUBLE_CONST(0.035));
assert_eq!(Token::parse_digits("0.LF"), DOUBLE_CONST(0.));
assert_eq!(Token::parse_digits("0.035LF"), DOUBLE_CONST(0.035));
assert_eq!(Token::parse_digits("1.03e+34lf"), DOUBLE_CONST(1.03e+34));
assert_eq!(Token::parse_digits("1.03E+34lf"), DOUBLE_CONST(1.03E+34));
assert_eq!(Token::parse_digits("1.03e-34lf"), DOUBLE_CONST(1.03e-34));
assert_eq!(Token::parse_digits("1.03E-34lf"), DOUBLE_CONST(1.03E-34));
assert_eq!(Token::parse_digits("1.03e+34LF"), DOUBLE_CONST(1.03e+34));
assert_eq!(Token::parse_digits("1.03E+34LF"), DOUBLE_CONST(1.03E+34));
assert_eq!(Token::parse_digits("1.03e-34LF"), DOUBLE_CONST(1.03e-34));
assert_eq!(Token::parse_digits("1.03E-34LF"), DOUBLE_CONST(1.03E-34));
}
#[test]
fn test_parse_int_constant() {
assert_eq!(Token::parse_digits("0"), INT_CONST(0));
assert_eq!(Token::parse_digits("012"), INT_CONST(0o12));
assert_eq!(Token::parse_digits("03"), INT_CONST(0o3));
assert_eq!(Token::parse_digits("07654321"), INT_CONST(0o7654321));
assert_eq!(Token::parse_digits("076556"), INT_CONST(0o76556));
assert_eq!(Token::parse_digits("0x0123789"), INT_CONST(0x0123789));
assert_eq!(Token::parse_digits("0x3"), INT_CONST(0x3));
assert_eq!(Token::parse_digits("0x9ABCDEF"), INT_CONST(0x9ABCDEF));
assert_eq!(Token::parse_digits("0x9abcdef"), INT_CONST(0x9abcdef));
assert_eq!(Token::parse_digits("0xABCDEF"), INT_CONST(0xabcdef));
assert_eq!(Token::parse_digits("0xabcdef"), INT_CONST(0xabcdef));
assert_eq!(Token::parse_digits("123456"), INT_CONST(123456));
assert_eq!(Token::parse_digits("13"), INT_CONST(13));
assert_eq!(Token::parse_digits("3"), INT_CONST(3));
assert_eq!(Token::parse_digits("42"), INT_CONST(42));
}
#[test]
fn test_parse_uint_constant() {
assert_eq!(Token::parse_digits("0u"), UINT_CONST(0));
assert_eq!(Token::parse_digits("1u"), UINT_CONST(1));
assert_eq!(
Token::parse_digits("0xffffffffU"),
UINT_CONST(0xffffffffu32)
);
}
}