use glsl_lang::ast::*;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum Error {
#[error("function pointer {name} previously declared as {previous_declaration}")]
DuplicatePointerDefinition {
name: SmolStr,
previous_declaration: String,
},
#[error("template {name} parameter #{index} cannot have an array specifier")]
ArrayedTemplateParameter {
name: SmolStr,
index: usize,
},
#[error("unsupported preprocessor directive in minifying mode: {0:?}")]
UnsupportedPreprocessor(Box<Preprocessor>),
#[error("unsupported declarator list in minifying mode: {0:?}")]
UnsupportedIdl(Box<InitDeclaratorList>),
#[error("undeclared pointer type: {0}")]
UndeclaredPointerType(SmolStr),
#[error("try to transform this call as a template call")]
TransformAsTemplate,
#[error("invalid argument at index {0}")]
InvalidParameter(usize),
}
pub type Result<T> = std::result::Result<T, Error>;
fn prototype_to_string(prototype: &FunctionPrototype) -> String {
let mut s = String::new();
glsl_lang::transpiler::glsl::show_function_prototype(
&mut s,
prototype,
&mut glsl_lang::transpiler::glsl::FormattingState::default(),
)
.unwrap();
s
}
impl Error {
pub fn new_duplicate_pointer_definition(
name: &Identifier,
previous: &FunctionPrototype,
) -> Self {
Error::DuplicatePointerDefinition {
name: name.0.clone(),
previous_declaration: prototype_to_string(previous),
}
}
}