Skip to content

Commit

Permalink
[glsl-in] Use Span instead of SourceMetadata
Browse files Browse the repository at this point in the history
  • Loading branch information
JCapucho authored and kvark committed Sep 21, 2021
1 parent 42db646 commit af44603
Show file tree
Hide file tree
Showing 18 changed files with 256 additions and 348 deletions.
8 changes: 5 additions & 3 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,11 @@ pub fn emit_glsl_parser_error(errors: Vec<naga::front::glsl::Error>, filename: &
let writer = StandardStream::stderr(ColorChoice::Auto);

for err in errors {
let diagnostic = Diagnostic::error()
.with_message(err.kind.to_string())
.with_labels(vec![Label::primary((), err.meta.start..err.meta.end)]);
let mut diagnostic = Diagnostic::error().with_message(err.kind.to_string());

if let Some(range) = err.meta.to_range() {
diagnostic = diagnostic.with_labels(vec![Label::primary((), range)]);
}

term::emit(&mut writer.lock(), &config, &files, &diagnostic).expect("cannot write error");
}
Expand Down
4 changes: 2 additions & 2 deletions src/front/glsl/ast.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::fmt;

use super::{builtins::MacroCall, context::ExprPos, SourceMetadata};
use super::{builtins::MacroCall, context::ExprPos, Span};
use crate::{
BinaryOperator, Binding, Constant, Expression, Function, GlobalVariable, Handle, Interpolation,
Sampling, StorageAccess, StorageClass, Type, UnaryOperator,
Expand Down Expand Up @@ -89,7 +89,7 @@ pub struct VariableReference {
#[derive(Debug, Clone)]
pub struct HirExpr {
pub kind: HirExprKind,
pub meta: SourceMetadata,
pub meta: Span,
}

#[derive(Debug, Clone)]
Expand Down
59 changes: 28 additions & 31 deletions src/front/glsl/builtins.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::{
ast::{FunctionDeclaration, FunctionKind, Overload, ParameterInfo, ParameterQualifier},
context::Context,
Error, ErrorKind, Parser, Result, SourceMetadata,
Error, ErrorKind, Parser, Result,
};
use crate::{
BinaryOperator, Block, Constant, ConstantInner, DerivativeAxis, Expression, Handle, ImageClass,
Expand Down Expand Up @@ -1474,7 +1474,7 @@ impl MacroCall {
ctx: &mut Context,
body: &mut Block,
args: &mut [Handle<Expression>],
meta: SourceMetadata,
meta: Span,
) -> Result<Handle<Expression>> {
match *self {
MacroCall::Sampler => {
Expand Down Expand Up @@ -1505,7 +1505,7 @@ impl MacroCall {
base: coords,
index: size as u32 - 1,
},
SourceMetadata::none(),
Span::default(),
body,
);
let left = if let VectorSize::Bi = size {
Expand All @@ -1514,7 +1514,7 @@ impl MacroCall {
base: coords,
index: 0,
},
SourceMetadata::none(),
Span::default(),
body,
)
} else {
Expand All @@ -1524,18 +1524,18 @@ impl MacroCall {
};
right = ctx.add_expression(
Expression::Splat { size, value: right },
SourceMetadata::none(),
Span::default(),
body,
);
ctx.vector_resize(size, coords, SourceMetadata::none(), body)
ctx.vector_resize(size, coords, Span::default(), body)
};
coords = ctx.add_expression(
Expression::Binary {
op: BinaryOperator::Divide,
left,
right,
},
SourceMetadata::none(),
Span::default(),
body,
);
}
Expand Down Expand Up @@ -1617,7 +1617,7 @@ impl MacroCall {
level: args.get(1).copied(),
},
},
SourceMetadata::none(),
Span::default(),
body,
)),
MacroCall::TexelFetch => {
Expand All @@ -1630,7 +1630,7 @@ impl MacroCall {
array_index: comps.array_index,
index: Some(args[2]),
},
SourceMetadata::none(),
Span::default(),
body,
))
}
Expand All @@ -1641,15 +1641,15 @@ impl MacroCall {
arg1: args.get(1).copied(),
arg2: args.get(2).copied(),
},
SourceMetadata::none(),
Span::default(),
body,
)),
MacroCall::Relational(fun) => Ok(ctx.add_expression(
Expression::Relational {
fun,
argument: args[0],
},
SourceMetadata::none(),
Span::default(),
body,
)),
MacroCall::Binary(op) => Ok(ctx.add_expression(
Expand All @@ -1658,7 +1658,7 @@ impl MacroCall {
left: args[0],
right: args[1],
},
SourceMetadata::none(),
Span::default(),
body,
)),
MacroCall::Mod(size) => {
Expand All @@ -1670,7 +1670,7 @@ impl MacroCall {
left: args[0],
right: args[1],
},
SourceMetadata::none(),
Span::default(),
body,
))
}
Expand All @@ -1684,7 +1684,7 @@ impl MacroCall {
arg1: args.get(1).copied(),
arg2: args.get(2).copied(),
},
SourceMetadata::none(),
Span::default(),
body,
))
}
Expand All @@ -1694,7 +1694,7 @@ impl MacroCall {
accept: args[1],
reject: args[0],
},
SourceMetadata::none(),
Span::default(),
body,
)),
MacroCall::Clamp(size) => {
Expand All @@ -1708,7 +1708,7 @@ impl MacroCall {
arg1: args.get(1).copied(),
arg2: args.get(2).copied(),
},
SourceMetadata::none(),
Span::default(),
body,
))
}
Expand All @@ -1724,18 +1724,15 @@ impl MacroCall {
},
Span::default(),
);
let right = ctx.add_expression(
Expression::Constant(constant),
SourceMetadata::none(),
body,
);
let right =
ctx.add_expression(Expression::Constant(constant), Span::default(), body);
Ok(ctx.add_expression(
Expression::Binary {
op: BinaryOperator::Multiply,
left: args[0],
right,
},
SourceMetadata::none(),
Span::default(),
body,
))
}
Expand All @@ -1745,15 +1742,15 @@ impl MacroCall {
kind,
convert: None,
},
SourceMetadata::none(),
Span::default(),
body,
)),
MacroCall::Derivate(axis) => Ok(ctx.add_expression(
Expression::Derivative {
axis,
expr: args[0],
},
SourceMetadata::none(),
Span::default(),
body,
)),
}
Expand All @@ -1767,7 +1764,7 @@ fn texture_call(
comps: CoordComponents,
offset: Option<Handle<Constant>>,
body: &mut Block,
meta: SourceMetadata,
meta: Span,
) -> Result<Handle<Expression>> {
if let Some(sampler) = ctx.samplers.get(&image).copied() {
let mut array_index = comps.array_index;
Expand Down Expand Up @@ -1816,7 +1813,7 @@ impl Parser {
image: Handle<Expression>,
coord: Handle<Expression>,
extra: Option<Handle<Expression>>,
meta: SourceMetadata,
meta: Span,
body: &mut Block,
) -> Result<CoordComponents> {
if let TypeInner::Image {
Expand All @@ -1842,14 +1839,14 @@ impl Parser {

let coordinate = match (image_size, coord_size) {
(Some(size), Some(coord_s)) if size != coord_s => {
ctx.vector_resize(size, coord, SourceMetadata::none(), body)
ctx.vector_resize(size, coord, Span::default(), body)
}
(None, Some(_)) => ctx.add_expression(
Expression::AccessIndex {
base: coord,
index: 0,
},
SourceMetadata::none(),
Span::default(),
body,
),
_ => coord,
Expand All @@ -1864,7 +1861,7 @@ impl Parser {

Some(ctx.add_expression(
Expression::AccessIndex { base: coord, index },
SourceMetadata::none(),
Span::default(),
body,
))
}
Expand All @@ -1881,7 +1878,7 @@ impl Parser {
} else {
Some(ctx.add_expression(
Expression::AccessIndex { base: coord, index },
SourceMetadata::none(),
Span::default(),
body,
))
}
Expand Down Expand Up @@ -1917,7 +1914,7 @@ pub fn sampled_to_depth(
module: &mut Module,
ctx: &mut Context,
image: Handle<Expression>,
meta: SourceMetadata,
meta: Span,
errors: &mut Vec<Error>,
) -> Result<()> {
let ty = match ctx[image] {
Expand Down
Loading

0 comments on commit af44603

Please sign in to comment.