1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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(Preprocessor),
#[error("unsupported declarator list in minifying mode: {0:?}")]
UnsupportedIdl(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),
}
}
}