[glsl-new] put validation errors behind featureUsing glsl-validate feature (#127)

This commit is contained in:
Pelle Johnsen 2020-08-13 22:27:12 +02:00 committed by GitHub
parent b4e1775b9e
commit 7f780e8efc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 5 additions and 0 deletions

View File

@ -24,6 +24,7 @@ serde = { version = "1.0", features = ["derive"], optional = true }
default = []
glsl_preprocessor = ["glsl"]
glsl-new = ["pomelo"]
glsl-validate = []
glsl-out = []
serialize = ["serde"]
deserialize = ["serde"]

View File

@ -63,6 +63,7 @@ impl Context {
None
}
#[cfg(feature = "glsl-validate")]
pub fn lookup_local_var_current_scope(&self, name: &str) -> Option<Handle<LocalVariable>> {
if let Some(current) = self.scopes.last() {
current.get(name).cloned()

View File

@ -14,6 +14,7 @@ pub enum ErrorKind {
ParserStackOverflow,
NotImplemented(&'static str),
UnknownVariable(TokenMetadata, String),
#[cfg(feature = "glsl-validate")]
VariableAlreadyDeclared(String),
ExpectedConstant,
SemanticError(&'static str),
@ -38,6 +39,7 @@ impl fmt::Display for ErrorKind {
ErrorKind::UnknownVariable(meta, val) => {
write!(f, "Unknown variable {} at {:?}", val, meta)
}
#[cfg(feature = "glsl-validate")]
ErrorKind::VariableAlreadyDeclared(val) => {
write!(f, "Variable {} already decalred in current scope", val)
}

View File

@ -545,6 +545,7 @@ pomelo! {
// local variables
for (id, initializer) in d.ids_initializers {
// check if already declared in current scope
#[cfg(feature = "glsl-validate")]
if extra.context.lookup_local_var_current_scope(&id).is_some() {
return Err(ErrorKind::VariableAlreadyDeclared(id))
}