mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
[glsl-in] Use Span instead of SourceMetadata
This commit is contained in:
committed by
Dzmitry Malyshau
parent
42db64628e
commit
af44603e47
@@ -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");
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
@@ -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)]
|
||||
|
||||
@@ -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,
|
||||
@@ -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 => {
|
||||
@@ -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 {
|
||||
@@ -1514,7 +1514,7 @@ impl MacroCall {
|
||||
base: coords,
|
||||
index: 0,
|
||||
},
|
||||
SourceMetadata::none(),
|
||||
Span::default(),
|
||||
body,
|
||||
)
|
||||
} else {
|
||||
@@ -1524,10 +1524,10 @@ 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 {
|
||||
@@ -1535,7 +1535,7 @@ impl MacroCall {
|
||||
left,
|
||||
right,
|
||||
},
|
||||
SourceMetadata::none(),
|
||||
Span::default(),
|
||||
body,
|
||||
);
|
||||
}
|
||||
@@ -1617,7 +1617,7 @@ impl MacroCall {
|
||||
level: args.get(1).copied(),
|
||||
},
|
||||
},
|
||||
SourceMetadata::none(),
|
||||
Span::default(),
|
||||
body,
|
||||
)),
|
||||
MacroCall::TexelFetch => {
|
||||
@@ -1630,7 +1630,7 @@ impl MacroCall {
|
||||
array_index: comps.array_index,
|
||||
index: Some(args[2]),
|
||||
},
|
||||
SourceMetadata::none(),
|
||||
Span::default(),
|
||||
body,
|
||||
))
|
||||
}
|
||||
@@ -1641,7 +1641,7 @@ impl MacroCall {
|
||||
arg1: args.get(1).copied(),
|
||||
arg2: args.get(2).copied(),
|
||||
},
|
||||
SourceMetadata::none(),
|
||||
Span::default(),
|
||||
body,
|
||||
)),
|
||||
MacroCall::Relational(fun) => Ok(ctx.add_expression(
|
||||
@@ -1649,7 +1649,7 @@ impl MacroCall {
|
||||
fun,
|
||||
argument: args[0],
|
||||
},
|
||||
SourceMetadata::none(),
|
||||
Span::default(),
|
||||
body,
|
||||
)),
|
||||
MacroCall::Binary(op) => Ok(ctx.add_expression(
|
||||
@@ -1658,7 +1658,7 @@ impl MacroCall {
|
||||
left: args[0],
|
||||
right: args[1],
|
||||
},
|
||||
SourceMetadata::none(),
|
||||
Span::default(),
|
||||
body,
|
||||
)),
|
||||
MacroCall::Mod(size) => {
|
||||
@@ -1670,7 +1670,7 @@ impl MacroCall {
|
||||
left: args[0],
|
||||
right: args[1],
|
||||
},
|
||||
SourceMetadata::none(),
|
||||
Span::default(),
|
||||
body,
|
||||
))
|
||||
}
|
||||
@@ -1684,7 +1684,7 @@ impl MacroCall {
|
||||
arg1: args.get(1).copied(),
|
||||
arg2: args.get(2).copied(),
|
||||
},
|
||||
SourceMetadata::none(),
|
||||
Span::default(),
|
||||
body,
|
||||
))
|
||||
}
|
||||
@@ -1694,7 +1694,7 @@ impl MacroCall {
|
||||
accept: args[1],
|
||||
reject: args[0],
|
||||
},
|
||||
SourceMetadata::none(),
|
||||
Span::default(),
|
||||
body,
|
||||
)),
|
||||
MacroCall::Clamp(size) => {
|
||||
@@ -1708,7 +1708,7 @@ impl MacroCall {
|
||||
arg1: args.get(1).copied(),
|
||||
arg2: args.get(2).copied(),
|
||||
},
|
||||
SourceMetadata::none(),
|
||||
Span::default(),
|
||||
body,
|
||||
))
|
||||
}
|
||||
@@ -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,
|
||||
))
|
||||
}
|
||||
@@ -1745,7 +1742,7 @@ impl MacroCall {
|
||||
kind,
|
||||
convert: None,
|
||||
},
|
||||
SourceMetadata::none(),
|
||||
Span::default(),
|
||||
body,
|
||||
)),
|
||||
MacroCall::Derivate(axis) => Ok(ctx.add_expression(
|
||||
@@ -1753,7 +1750,7 @@ impl MacroCall {
|
||||
axis,
|
||||
expr: args[0],
|
||||
},
|
||||
SourceMetadata::none(),
|
||||
Span::default(),
|
||||
body,
|
||||
)),
|
||||
}
|
||||
@@ -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;
|
||||
@@ -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 {
|
||||
@@ -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,
|
||||
@@ -1864,7 +1861,7 @@ impl Parser {
|
||||
|
||||
Some(ctx.add_expression(
|
||||
Expression::AccessIndex { base: coord, index },
|
||||
SourceMetadata::none(),
|
||||
Span::default(),
|
||||
body,
|
||||
))
|
||||
}
|
||||
@@ -1881,7 +1878,7 @@ impl Parser {
|
||||
} else {
|
||||
Some(ctx.add_expression(
|
||||
Expression::AccessIndex { base: coord, index },
|
||||
SourceMetadata::none(),
|
||||
Span::default(),
|
||||
body,
|
||||
))
|
||||
}
|
||||
@@ -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] {
|
||||
|
||||
@@ -5,13 +5,13 @@ use super::{
|
||||
},
|
||||
error::{Error, ErrorKind},
|
||||
types::{scalar_components, type_power},
|
||||
Parser, Result, SourceMetadata,
|
||||
Parser, Result,
|
||||
};
|
||||
use crate::{
|
||||
front::{Emitter, Typifier},
|
||||
Arena, BinaryOperator, Block, Constant, Expression, FastHashMap, FunctionArgument, Handle,
|
||||
LocalVariable, RelationalFunction, ScalarKind, ScalarValue, Statement, StorageClass, Type,
|
||||
TypeInner, VectorSize,
|
||||
LocalVariable, RelationalFunction, ScalarKind, ScalarValue, Span, Statement, StorageClass,
|
||||
Type, TypeInner, VectorSize,
|
||||
};
|
||||
use std::{convert::TryFrom, ops::Index};
|
||||
|
||||
@@ -181,14 +181,14 @@ impl Context {
|
||||
pub fn add_expression(
|
||||
&mut self,
|
||||
expr: Expression,
|
||||
meta: SourceMetadata,
|
||||
meta: Span,
|
||||
body: &mut Block,
|
||||
) -> Handle<Expression> {
|
||||
let needs_pre_emit = expr.needs_pre_emit();
|
||||
if needs_pre_emit {
|
||||
self.emit_flush(body);
|
||||
}
|
||||
let handle = self.expressions.append(expr, meta.as_span());
|
||||
let handle = self.expressions.append(expr, meta);
|
||||
if needs_pre_emit {
|
||||
self.emit_start();
|
||||
}
|
||||
@@ -238,7 +238,7 @@ impl Context {
|
||||
&mut self,
|
||||
parser: &mut Parser,
|
||||
body: &mut Block,
|
||||
name_meta: Option<(String, SourceMetadata)>,
|
||||
name_meta: Option<(String, Span)>,
|
||||
ty: Handle<Type>,
|
||||
qualifier: ParameterQualifier,
|
||||
) {
|
||||
@@ -288,7 +288,7 @@ impl Context {
|
||||
ty,
|
||||
init: None,
|
||||
},
|
||||
meta.as_span(),
|
||||
meta,
|
||||
);
|
||||
let local_expr = self.add_expression(Expression::LocalVariable(handle), meta, body);
|
||||
|
||||
@@ -300,7 +300,7 @@ impl Context {
|
||||
pointer: local_expr,
|
||||
value: expr,
|
||||
},
|
||||
meta.as_span(),
|
||||
meta,
|
||||
);
|
||||
|
||||
if let Some(current) = self.scopes.last_mut() {
|
||||
@@ -360,7 +360,7 @@ impl Context {
|
||||
expr: Handle<HirExpr>,
|
||||
pos: ExprPos,
|
||||
body: &mut Block,
|
||||
) -> Result<(Option<Handle<Expression>>, SourceMetadata)> {
|
||||
) -> Result<(Option<Handle<Expression>>, Span)> {
|
||||
let res = self.lower_inner(&stmt, parser, expr, pos, body);
|
||||
|
||||
stmt.hir_exprs.clear();
|
||||
@@ -381,7 +381,7 @@ impl Context {
|
||||
expr: Handle<HirExpr>,
|
||||
pos: ExprPos,
|
||||
body: &mut Block,
|
||||
) -> Result<(Handle<Expression>, SourceMetadata)> {
|
||||
) -> Result<(Handle<Expression>, Span)> {
|
||||
let res = self.lower_expect_inner(&stmt, parser, expr, pos, body);
|
||||
|
||||
stmt.hir_exprs.clear();
|
||||
@@ -402,7 +402,7 @@ impl Context {
|
||||
expr: Handle<HirExpr>,
|
||||
pos: ExprPos,
|
||||
body: &mut Block,
|
||||
) -> Result<(Handle<Expression>, SourceMetadata)> {
|
||||
) -> Result<(Handle<Expression>, Span)> {
|
||||
let (maybe_expr, meta) = self.lower_inner(stmt, parser, expr, pos, body)?;
|
||||
|
||||
let expr = match maybe_expr {
|
||||
@@ -426,7 +426,7 @@ impl Context {
|
||||
expr: Handle<HirExpr>,
|
||||
pos: ExprPos,
|
||||
body: &mut Block,
|
||||
) -> Result<(Option<Handle<Expression>>, SourceMetadata)> {
|
||||
) -> Result<(Option<Handle<Expression>>, Span)> {
|
||||
let HirExpr { ref kind, meta } = stmt.hir_exprs[expr];
|
||||
|
||||
let handle = match *kind {
|
||||
@@ -523,7 +523,7 @@ impl Context {
|
||||
|
||||
let argument = self
|
||||
.expressions
|
||||
.append(Expression::Binary { op, left, right }, meta.as_span());
|
||||
.append(Expression::Binary { op, left, right }, meta);
|
||||
|
||||
self.add_expression(
|
||||
Expression::Relational { fun, argument },
|
||||
@@ -622,14 +622,10 @@ impl Context {
|
||||
ty,
|
||||
init: Some(constant),
|
||||
},
|
||||
crate::Span::default(),
|
||||
Span::default(),
|
||||
);
|
||||
|
||||
self.add_expression(
|
||||
Expression::LocalVariable(local),
|
||||
SourceMetadata::none(),
|
||||
body,
|
||||
)
|
||||
self.add_expression(Expression::LocalVariable(local), Span::default(), body)
|
||||
} else {
|
||||
var.expr
|
||||
}
|
||||
@@ -738,14 +734,14 @@ impl Context {
|
||||
pointer: dst,
|
||||
value: src,
|
||||
},
|
||||
meta.as_span(),
|
||||
meta,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
self.emit_flush(body);
|
||||
self.emit_start();
|
||||
|
||||
body.push(Statement::Store { pointer, value }, meta.as_span());
|
||||
body.push(Statement::Store { pointer, value }, meta);
|
||||
}
|
||||
|
||||
value
|
||||
@@ -827,7 +823,7 @@ impl Context {
|
||||
name: None,
|
||||
inner: ty_inner,
|
||||
},
|
||||
meta.as_span(),
|
||||
meta,
|
||||
);
|
||||
|
||||
right = self.add_expression(
|
||||
@@ -846,7 +842,7 @@ impl Context {
|
||||
self.emit_flush(body);
|
||||
self.emit_start();
|
||||
|
||||
body.push(Statement::Store { pointer, value }, meta.as_span());
|
||||
body.push(Statement::Store { pointer, value }, meta);
|
||||
|
||||
if postfix {
|
||||
left
|
||||
@@ -872,7 +868,7 @@ impl Context {
|
||||
&mut self,
|
||||
parser: &mut Parser,
|
||||
expr: Handle<Expression>,
|
||||
meta: SourceMetadata,
|
||||
meta: Span,
|
||||
) -> Result<Option<(ScalarKind, crate::Bytes)>> {
|
||||
let ty = parser.resolve_type(self, expr, meta)?;
|
||||
Ok(scalar_components(ty))
|
||||
@@ -882,7 +878,7 @@ impl Context {
|
||||
&mut self,
|
||||
parser: &mut Parser,
|
||||
expr: Handle<Expression>,
|
||||
meta: SourceMetadata,
|
||||
meta: Span,
|
||||
) -> Result<Option<u32>> {
|
||||
Ok(self
|
||||
.expr_scalar_components(parser, expr, meta)?
|
||||
@@ -892,7 +888,7 @@ impl Context {
|
||||
pub fn conversion(
|
||||
&mut self,
|
||||
expr: &mut Handle<Expression>,
|
||||
meta: SourceMetadata,
|
||||
meta: Span,
|
||||
kind: ScalarKind,
|
||||
width: crate::Bytes,
|
||||
) -> Result<()> {
|
||||
@@ -902,7 +898,7 @@ impl Context {
|
||||
kind,
|
||||
convert: Some(width),
|
||||
},
|
||||
meta.as_span(),
|
||||
meta,
|
||||
);
|
||||
|
||||
Ok(())
|
||||
@@ -912,7 +908,7 @@ impl Context {
|
||||
&mut self,
|
||||
parser: &mut Parser,
|
||||
expr: &mut Handle<Expression>,
|
||||
meta: SourceMetadata,
|
||||
meta: Span,
|
||||
kind: ScalarKind,
|
||||
width: crate::Bytes,
|
||||
) -> Result<()> {
|
||||
@@ -932,9 +928,9 @@ impl Context {
|
||||
&mut self,
|
||||
parser: &mut Parser,
|
||||
left: &mut Handle<Expression>,
|
||||
left_meta: SourceMetadata,
|
||||
left_meta: Span,
|
||||
right: &mut Handle<Expression>,
|
||||
right_meta: SourceMetadata,
|
||||
right_meta: Span,
|
||||
) -> Result<()> {
|
||||
let left_components = self.expr_scalar_components(parser, *left, left_meta)?;
|
||||
let right_components = self.expr_scalar_components(parser, *right, right_meta)?;
|
||||
@@ -965,7 +961,7 @@ impl Context {
|
||||
&mut self,
|
||||
parser: &mut Parser,
|
||||
expr: &mut Handle<Expression>,
|
||||
meta: SourceMetadata,
|
||||
meta: Span,
|
||||
vector_size: Option<VectorSize>,
|
||||
) -> Result<()> {
|
||||
let expr_type = parser.resolve_type(self, *expr, meta)?;
|
||||
@@ -973,7 +969,7 @@ impl Context {
|
||||
if let (&TypeInner::Scalar { .. }, Some(size)) = (expr_type, vector_size) {
|
||||
*expr = self
|
||||
.expressions
|
||||
.append(Expression::Splat { size, value: *expr }, meta.as_span())
|
||||
.append(Expression::Splat { size, value: *expr }, meta)
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -983,7 +979,7 @@ impl Context {
|
||||
&mut self,
|
||||
size: VectorSize,
|
||||
vector: Handle<Expression>,
|
||||
meta: SourceMetadata,
|
||||
meta: Span,
|
||||
body: &mut Block,
|
||||
) -> Handle<Expression> {
|
||||
self.add_expression(
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
use super::{
|
||||
constants::ConstantSolvingError,
|
||||
token::{SourceMetadata, TokenValue},
|
||||
};
|
||||
use super::{constants::ConstantSolvingError, token::TokenValue};
|
||||
use crate::Span;
|
||||
use pp_rs::token::PreprocessorError;
|
||||
use std::borrow::Cow;
|
||||
use thiserror::Error;
|
||||
@@ -122,5 +120,5 @@ pub struct Error {
|
||||
/// Holds the information about the error itself.
|
||||
pub kind: ErrorKind,
|
||||
/// Holds information about the range of the source code where the error happened.
|
||||
pub meta: SourceMetadata,
|
||||
pub meta: Span,
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ use super::{
|
||||
context::{Context, ExprPos, StmtContext},
|
||||
error::{Error, ErrorKind},
|
||||
types::scalar_components,
|
||||
Parser, Result, SourceMetadata,
|
||||
Parser, Result,
|
||||
};
|
||||
use crate::{
|
||||
front::glsl::types::type_power, proc::ensure_block_returns, Arena, Block, Constant,
|
||||
@@ -18,7 +18,7 @@ impl Parser {
|
||||
&mut self,
|
||||
scalar_kind: ScalarKind,
|
||||
value: u64,
|
||||
meta: SourceMetadata,
|
||||
meta: Span,
|
||||
) -> Handle<Constant> {
|
||||
let value = match scalar_kind {
|
||||
ScalarKind::Uint => ScalarValue::Uint(value),
|
||||
@@ -33,7 +33,7 @@ impl Parser {
|
||||
specialization: None,
|
||||
inner: ConstantInner::Scalar { width: 4, value },
|
||||
},
|
||||
meta.as_span(),
|
||||
meta,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ impl Parser {
|
||||
body: &mut Block,
|
||||
fc: FunctionCallKind,
|
||||
raw_args: &[Handle<HirExpr>],
|
||||
meta: SourceMetadata,
|
||||
meta: Span,
|
||||
) -> Result<Option<Handle<Expression>>> {
|
||||
let args: Vec<_> = raw_args
|
||||
.iter()
|
||||
@@ -158,7 +158,7 @@ impl Parser {
|
||||
width,
|
||||
},
|
||||
},
|
||||
meta.as_span(),
|
||||
meta,
|
||||
);
|
||||
let zero_constant = self.module.constants.fetch_or_append(
|
||||
Constant {
|
||||
@@ -169,7 +169,7 @@ impl Parser {
|
||||
value: ScalarValue::Float(0.0),
|
||||
},
|
||||
},
|
||||
meta.as_span(),
|
||||
meta,
|
||||
);
|
||||
let zero = ctx.add_expression(
|
||||
Expression::Constant(zero_constant),
|
||||
@@ -305,7 +305,7 @@ impl Parser {
|
||||
width,
|
||||
},
|
||||
},
|
||||
meta.as_span(),
|
||||
meta,
|
||||
);
|
||||
|
||||
for chunk in flattened.chunks(rows as usize) {
|
||||
@@ -350,9 +350,9 @@ impl Parser {
|
||||
stmt: &StmtContext,
|
||||
body: &mut Block,
|
||||
name: String,
|
||||
args: Vec<(Handle<Expression>, SourceMetadata)>,
|
||||
args: Vec<(Handle<Expression>, Span)>,
|
||||
raw_args: &[Handle<HirExpr>],
|
||||
meta: SourceMetadata,
|
||||
meta: Span,
|
||||
) -> Result<Option<Handle<Expression>>> {
|
||||
// If the name for the function hasn't yet been initialized check if any
|
||||
// builtin can be injected.
|
||||
@@ -590,7 +590,7 @@ impl Parser {
|
||||
);
|
||||
let temp_expr = ctx.add_expression(
|
||||
Expression::LocalVariable(temp_var),
|
||||
SourceMetadata::none(),
|
||||
Span::default(),
|
||||
body,
|
||||
);
|
||||
|
||||
@@ -632,7 +632,7 @@ impl Parser {
|
||||
arguments,
|
||||
result,
|
||||
},
|
||||
meta.as_span(),
|
||||
meta,
|
||||
);
|
||||
|
||||
ctx.emit_start();
|
||||
@@ -650,7 +650,7 @@ impl Parser {
|
||||
pointer: target,
|
||||
value,
|
||||
},
|
||||
meta.as_span(),
|
||||
meta,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -668,7 +668,7 @@ impl Parser {
|
||||
name: String,
|
||||
result: Option<FunctionResult>,
|
||||
mut body: Block,
|
||||
meta: SourceMetadata,
|
||||
meta: Span,
|
||||
) {
|
||||
if self.lookup_function.get(&name).is_none() {
|
||||
let declaration = self.lookup_function.entry(name.clone()).or_default();
|
||||
@@ -741,14 +741,14 @@ impl Parser {
|
||||
match decl.kind {
|
||||
FunctionKind::Call(handle) => *self.module.functions.get_mut(handle) = function,
|
||||
FunctionKind::Macro(_) => {
|
||||
let handle = module.functions.append(function, meta.as_span());
|
||||
let handle = module.functions.append(function, meta);
|
||||
decl.kind = FunctionKind::Call(handle)
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
let handle = module.functions.append(function, meta.as_span());
|
||||
let handle = module.functions.append(function, meta);
|
||||
declaration.overloads.push(Overload {
|
||||
parameters,
|
||||
parameters_info,
|
||||
@@ -763,7 +763,7 @@ impl Parser {
|
||||
ctx: Context,
|
||||
name: String,
|
||||
result: Option<FunctionResult>,
|
||||
meta: SourceMetadata,
|
||||
meta: Span,
|
||||
) {
|
||||
if self.lookup_function.get(&name).is_none() {
|
||||
let declaration = self.lookup_function.entry(name.clone()).or_default();
|
||||
@@ -823,7 +823,7 @@ impl Parser {
|
||||
});
|
||||
}
|
||||
|
||||
let handle = module.functions.append(function, meta.as_span());
|
||||
let handle = module.functions.append(function, meta);
|
||||
declaration.overloads.push(Overload {
|
||||
parameters,
|
||||
parameters_info,
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use super::{
|
||||
ast::Precision,
|
||||
token::{Directive, DirectiveKind, SourceMetadata, Token, TokenValue},
|
||||
token::{Directive, DirectiveKind, Token, TokenValue},
|
||||
types::parse_type,
|
||||
};
|
||||
use crate::{FastHashMap, StorageAccess};
|
||||
use crate::{FastHashMap, Span, StorageAccess};
|
||||
use pp_rs::{
|
||||
pp::Preprocessor,
|
||||
token::{PreprocessorError, Punct, TokenValue as PPTokenValue},
|
||||
@@ -13,7 +13,7 @@ use pp_rs::{
|
||||
#[cfg_attr(test, derive(PartialEq))]
|
||||
pub struct LexerResult {
|
||||
pub kind: LexerResultKind,
|
||||
pub meta: SourceMetadata,
|
||||
pub meta: Span,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -202,9 +202,10 @@ mod tests {
|
||||
use pp_rs::token::{Integer, Location, Token as PPToken, TokenValue as PPTokenValue};
|
||||
|
||||
use super::{
|
||||
super::token::{Directive, DirectiveKind, SourceMetadata, Token, TokenValue},
|
||||
super::token::{Directive, DirectiveKind, Token, TokenValue},
|
||||
Lexer, LexerResult, LexerResultKind,
|
||||
};
|
||||
use crate::Span;
|
||||
|
||||
#[test]
|
||||
fn lex_tokens() {
|
||||
@@ -231,7 +232,7 @@ mod tests {
|
||||
location
|
||||
}]
|
||||
}),
|
||||
meta: SourceMetadata { start: 1, end: 8 }
|
||||
meta: Span::new(1, 8)
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
@@ -239,9 +240,9 @@ mod tests {
|
||||
LexerResult {
|
||||
kind: LexerResultKind::Token(Token {
|
||||
value: TokenValue::Void,
|
||||
meta: SourceMetadata { start: 13, end: 17 }
|
||||
meta: Span::new(13, 17)
|
||||
}),
|
||||
meta: SourceMetadata { start: 13, end: 17 }
|
||||
meta: Span::new(13, 17)
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
@@ -249,9 +250,9 @@ mod tests {
|
||||
LexerResult {
|
||||
kind: LexerResultKind::Token(Token {
|
||||
value: TokenValue::Identifier("main".into()),
|
||||
meta: SourceMetadata { start: 18, end: 22 }
|
||||
meta: Span::new(18, 22)
|
||||
}),
|
||||
meta: SourceMetadata { start: 18, end: 22 }
|
||||
meta: Span::new(18, 22)
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
@@ -259,9 +260,9 @@ mod tests {
|
||||
LexerResult {
|
||||
kind: LexerResultKind::Token(Token {
|
||||
value: TokenValue::LeftParen,
|
||||
meta: SourceMetadata { start: 23, end: 24 }
|
||||
meta: Span::new(23, 24)
|
||||
}),
|
||||
meta: SourceMetadata { start: 23, end: 24 }
|
||||
meta: Span::new(23, 24)
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
@@ -269,9 +270,9 @@ mod tests {
|
||||
LexerResult {
|
||||
kind: LexerResultKind::Token(Token {
|
||||
value: TokenValue::RightParen,
|
||||
meta: SourceMetadata { start: 24, end: 25 }
|
||||
meta: Span::new(24, 25)
|
||||
}),
|
||||
meta: SourceMetadata { start: 24, end: 25 }
|
||||
meta: Span::new(24, 25)
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
@@ -279,9 +280,9 @@ mod tests {
|
||||
LexerResult {
|
||||
kind: LexerResultKind::Token(Token {
|
||||
value: TokenValue::LeftBrace,
|
||||
meta: SourceMetadata { start: 26, end: 27 }
|
||||
meta: Span::new(26, 27)
|
||||
}),
|
||||
meta: SourceMetadata { start: 26, end: 27 }
|
||||
meta: Span::new(26, 27)
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
@@ -289,9 +290,9 @@ mod tests {
|
||||
LexerResult {
|
||||
kind: LexerResultKind::Token(Token {
|
||||
value: TokenValue::RightBrace,
|
||||
meta: SourceMetadata { start: 27, end: 28 }
|
||||
meta: Span::new(27, 28)
|
||||
}),
|
||||
meta: SourceMetadata { start: 27, end: 28 }
|
||||
meta: Span::new(27, 28)
|
||||
}
|
||||
);
|
||||
assert_eq!(lex.next(), None);
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
|
||||
pub use ast::{Precision, Profile};
|
||||
pub use error::{Error, ErrorKind, ExpectedToken};
|
||||
pub use token::{SourceMetadata, TokenValue};
|
||||
pub use token::TokenValue;
|
||||
|
||||
use crate::{FastHashMap, FastHashSet, Handle, Module, ShaderStage, Type};
|
||||
use crate::{FastHashMap, FastHashSet, Handle, Module, ShaderStage, Span, Type};
|
||||
use ast::{EntryArg, FunctionDeclaration, GlobalLookup};
|
||||
use parser::ParsingContext;
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
use super::{
|
||||
ast::StructLayout,
|
||||
error::{Error, ErrorKind},
|
||||
SourceMetadata,
|
||||
Span,
|
||||
};
|
||||
use crate::{front::align_up, Arena, Constant, Handle, Type, TypeInner};
|
||||
|
||||
@@ -37,7 +37,7 @@ pub struct TypeAlignSpan {
|
||||
/// change the stride and as such need to have a different type.
|
||||
pub fn calculate_offset(
|
||||
mut ty: Handle<Type>,
|
||||
meta: SourceMetadata,
|
||||
meta: Span,
|
||||
layout: StructLayout,
|
||||
types: &mut Arena<Type>,
|
||||
constants: &Arena<Constant>,
|
||||
|
||||
@@ -5,11 +5,11 @@ use super::{
|
||||
error::{Error, ErrorKind},
|
||||
lex::{Lexer, LexerResultKind},
|
||||
token::{Directive, DirectiveKind},
|
||||
token::{SourceMetadata, Token, TokenValue},
|
||||
token::{Token, TokenValue},
|
||||
variables::{GlobalOrConstant, VarDeclaration},
|
||||
Parser, Result,
|
||||
};
|
||||
use crate::{arena::Handle, Block, Constant, ConstantInner, Expression, ScalarValue, Type};
|
||||
use crate::{arena::Handle, Block, Constant, ConstantInner, Expression, ScalarValue, Span, Type};
|
||||
use core::convert::TryFrom;
|
||||
use pp_rs::token::{PreprocessorError, Token as PPToken, TokenValue as PPTokenValue};
|
||||
use std::iter::Peekable;
|
||||
@@ -21,18 +21,18 @@ mod types;
|
||||
|
||||
pub struct ParsingContext<'source> {
|
||||
lexer: Peekable<Lexer<'source>>,
|
||||
last_meta: SourceMetadata,
|
||||
last_meta: Span,
|
||||
}
|
||||
|
||||
impl<'source> ParsingContext<'source> {
|
||||
pub fn new(lexer: Lexer<'source>) -> Self {
|
||||
ParsingContext {
|
||||
lexer: lexer.peekable(),
|
||||
last_meta: SourceMetadata::none(),
|
||||
last_meta: Span::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn expect_ident(&mut self, parser: &mut Parser) -> Result<(String, SourceMetadata)> {
|
||||
pub fn expect_ident(&mut self, parser: &mut Parser) -> Result<(String, Span)> {
|
||||
let token = self.bump(parser)?;
|
||||
|
||||
match token.value {
|
||||
@@ -153,14 +153,14 @@ impl<'source> ParsingContext<'source> {
|
||||
Some(handle) => parser.add_entry_point(handle, body, ctx.expressions),
|
||||
None => parser.errors.push(Error {
|
||||
kind: ErrorKind::SemanticError("Missing entry point".into()),
|
||||
meta: SourceMetadata::none(),
|
||||
meta: Span::default(),
|
||||
}),
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn parse_uint_constant(&mut self, parser: &mut Parser) -> Result<(u32, SourceMetadata)> {
|
||||
fn parse_uint_constant(&mut self, parser: &mut Parser) -> Result<(u32, Span)> {
|
||||
let (value, meta) = self.parse_constant_expression(parser)?;
|
||||
|
||||
let int = match parser.module.constants[value].inner {
|
||||
@@ -192,7 +192,7 @@ impl<'source> ParsingContext<'source> {
|
||||
fn parse_constant_expression(
|
||||
&mut self,
|
||||
parser: &mut Parser,
|
||||
) -> Result<(Handle<Constant>, SourceMetadata)> {
|
||||
) -> Result<(Handle<Constant>, Span)> {
|
||||
let mut block = Block::new();
|
||||
|
||||
let mut ctx = Context::new(parser, &mut block);
|
||||
@@ -206,7 +206,7 @@ impl<'source> ParsingContext<'source> {
|
||||
}
|
||||
|
||||
impl Parser {
|
||||
fn handle_directive(&mut self, directive: Directive, meta: SourceMetadata) {
|
||||
fn handle_directive(&mut self, directive: Directive, meta: Span) {
|
||||
let mut tokens = directive.tokens.into_iter();
|
||||
|
||||
match directive.kind {
|
||||
@@ -367,7 +367,7 @@ impl Parser {
|
||||
}
|
||||
|
||||
pub struct DeclarationContext<'ctx> {
|
||||
qualifiers: Vec<(TypeQualifier, SourceMetadata)>,
|
||||
qualifiers: Vec<(TypeQualifier, Span)>,
|
||||
external: bool,
|
||||
|
||||
ctx: &'ctx mut Context,
|
||||
@@ -381,7 +381,7 @@ impl<'ctx> DeclarationContext<'ctx> {
|
||||
ty: Handle<Type>,
|
||||
name: String,
|
||||
init: Option<Handle<Constant>>,
|
||||
meta: SourceMetadata,
|
||||
meta: Span,
|
||||
) -> Result<Handle<Expression>> {
|
||||
let decl = VarDeclaration {
|
||||
qualifiers: &self.qualifiers,
|
||||
|
||||
@@ -10,7 +10,7 @@ use crate::{
|
||||
token::{Token, TokenValue},
|
||||
types::scalar_components,
|
||||
variables::{GlobalOrConstant, VarDeclaration},
|
||||
Error, ErrorKind, Parser, SourceMetadata,
|
||||
Error, ErrorKind, Parser, Span,
|
||||
},
|
||||
Block, Expression, FunctionResult, Handle, ScalarKind, Statement, StorageClass, StructMember,
|
||||
Type, TypeInner,
|
||||
@@ -54,7 +54,7 @@ impl<'source> ParsingContext<'source> {
|
||||
ty: Handle<Type>,
|
||||
ctx: &mut Context,
|
||||
body: &mut Block,
|
||||
) -> Result<(Handle<Expression>, SourceMetadata)> {
|
||||
) -> Result<(Handle<Expression>, Span)> {
|
||||
// initializer:
|
||||
// assignment_expression
|
||||
// LEFT_BRACE initializer_list RIGHT_BRACE
|
||||
@@ -76,12 +76,12 @@ impl<'source> ParsingContext<'source> {
|
||||
if let Some(Token { meta: end_meta, .. }) =
|
||||
self.bump_if(parser, TokenValue::RightBrace)
|
||||
{
|
||||
meta = meta.union(&end_meta);
|
||||
meta.subsume(end_meta);
|
||||
break;
|
||||
}
|
||||
}
|
||||
TokenValue::RightBrace => {
|
||||
meta = meta.union(&token.meta);
|
||||
meta.subsume(token.meta);
|
||||
break;
|
||||
}
|
||||
_ => {
|
||||
@@ -190,7 +190,7 @@ impl<'source> ParsingContext<'source> {
|
||||
.implicit_conversion(parser, &mut expr, init_meta, kind, width)?;
|
||||
}
|
||||
|
||||
meta = meta.union(&init_meta);
|
||||
meta.subsume(init_meta);
|
||||
|
||||
Ok((expr, init_meta))
|
||||
})
|
||||
@@ -206,8 +206,7 @@ impl<'source> ParsingContext<'source> {
|
||||
|
||||
if let Some((value, _)) = init.filter(|_| maybe_constant.is_none()) {
|
||||
ctx.flush_expressions();
|
||||
ctx.body
|
||||
.push(Statement::Store { pointer, value }, meta.as_span());
|
||||
ctx.body.push(Statement::Store { pointer, value }, meta);
|
||||
}
|
||||
|
||||
let token = self.bump(parser)?;
|
||||
@@ -236,7 +235,7 @@ impl<'source> ParsingContext<'source> {
|
||||
ctx: &mut Context,
|
||||
body: &mut Block,
|
||||
external: bool,
|
||||
) -> Result<Option<SourceMetadata>> {
|
||||
) -> Result<Option<Span>> {
|
||||
//declaration:
|
||||
// function_prototype SEMICOLON
|
||||
//
|
||||
@@ -272,7 +271,7 @@ impl<'source> ParsingContext<'source> {
|
||||
self.parse_function_args(parser, &mut context, &mut body)?;
|
||||
|
||||
let end_meta = self.expect(parser, TokenValue::RightParen)?.meta;
|
||||
meta = meta.union(&end_meta);
|
||||
meta.subsume(end_meta);
|
||||
|
||||
let token = self.bump(parser)?;
|
||||
return match token.value {
|
||||
@@ -379,7 +378,7 @@ impl<'source> ParsingContext<'source> {
|
||||
TokenValue::Semicolon => {
|
||||
let mut meta_all = token.meta;
|
||||
for &(ref qualifier, meta) in qualifiers.iter() {
|
||||
meta_all = meta_all.union(&meta);
|
||||
meta_all.subsume(meta);
|
||||
match *qualifier {
|
||||
TypeQualifier::WorkGroupSize(i, value) => {
|
||||
parser.meta.workgroup_size[i] = value
|
||||
@@ -471,10 +470,10 @@ impl<'source> ParsingContext<'source> {
|
||||
parser: &mut Parser,
|
||||
ctx: &mut Context,
|
||||
body: &mut Block,
|
||||
qualifiers: &[(TypeQualifier, SourceMetadata)],
|
||||
qualifiers: &[(TypeQualifier, Span)],
|
||||
ty_name: String,
|
||||
meta: SourceMetadata,
|
||||
) -> Result<SourceMetadata> {
|
||||
meta: Span,
|
||||
) -> Result<Span> {
|
||||
let mut storage = None;
|
||||
let mut layout = None;
|
||||
|
||||
@@ -580,7 +579,7 @@ impl<'source> ParsingContext<'source> {
|
||||
let (ty, mut meta) = self.parse_type_non_void(parser)?;
|
||||
let (name, end_meta) = self.expect_ident(parser)?;
|
||||
|
||||
meta = meta.union(&end_meta);
|
||||
meta.subsume(end_meta);
|
||||
|
||||
let array_specifier = self.parse_array_specifier(parser)?;
|
||||
let ty = parser.maybe_array(ty, meta, array_specifier);
|
||||
|
||||
@@ -5,7 +5,7 @@ use crate::{
|
||||
error::{ErrorKind, ExpectedToken},
|
||||
parser::ParsingContext,
|
||||
token::{Token, TokenValue},
|
||||
Error, Parser, Result, SourceMetadata,
|
||||
Error, Parser, Result, Span,
|
||||
},
|
||||
ArraySize, BinaryOperator, Block, Constant, ConstantInner, Handle, ScalarValue, Type,
|
||||
TypeInner, UnaryOperator,
|
||||
@@ -39,7 +39,7 @@ impl<'source> ParsingContext<'source> {
|
||||
let expr = self.parse_expression(parser, ctx, stmt, body)?;
|
||||
let meta = self.expect(parser, TokenValue::RightParen)?.meta;
|
||||
|
||||
token.meta = token.meta.union(&meta);
|
||||
token.meta.subsume(meta);
|
||||
|
||||
return Ok(expr);
|
||||
}
|
||||
@@ -65,7 +65,7 @@ impl<'source> ParsingContext<'source> {
|
||||
specialization: None,
|
||||
inner: ConstantInner::Scalar { width, value },
|
||||
},
|
||||
token.meta.as_span(),
|
||||
token.meta,
|
||||
);
|
||||
|
||||
Ok(stmt.hir_exprs.append(
|
||||
@@ -83,11 +83,11 @@ impl<'source> ParsingContext<'source> {
|
||||
ctx: &mut Context,
|
||||
stmt: &mut StmtContext,
|
||||
body: &mut Block,
|
||||
meta: &mut SourceMetadata,
|
||||
meta: &mut Span,
|
||||
) -> Result<Vec<Handle<HirExpr>>> {
|
||||
let mut args = Vec::new();
|
||||
if let Some(token) = self.bump_if(parser, TokenValue::RightParen) {
|
||||
*meta = meta.union(&token.meta);
|
||||
meta.subsume(token.meta);
|
||||
} else {
|
||||
loop {
|
||||
args.push(self.parse_assignment(parser, ctx, stmt, body)?);
|
||||
@@ -96,7 +96,7 @@ impl<'source> ParsingContext<'source> {
|
||||
match token.value {
|
||||
TokenValue::Comma => {}
|
||||
TokenValue::RightParen => {
|
||||
*meta = meta.union(&token.meta);
|
||||
meta.subsume(token.meta);
|
||||
break;
|
||||
}
|
||||
_ => {
|
||||
@@ -160,12 +160,12 @@ impl<'source> ParsingContext<'source> {
|
||||
TokenValue::TypeName(_) => {
|
||||
let Token {
|
||||
value,
|
||||
meta: name_meta,
|
||||
meta: mut name_meta,
|
||||
} = self.bump(parser)?;
|
||||
let mut meta = name_meta;
|
||||
|
||||
let mut handle = if let TokenValue::TypeName(ty) = value {
|
||||
parser.module.types.fetch_or_append(ty, name_meta.as_span())
|
||||
parser.module.types.fetch_or_append(ty, name_meta)
|
||||
} else {
|
||||
unreachable!()
|
||||
};
|
||||
@@ -192,13 +192,14 @@ impl<'source> ParsingContext<'source> {
|
||||
value: ScalarValue::Sint(args.len() as i64),
|
||||
},
|
||||
},
|
||||
meta.as_span(),
|
||||
meta,
|
||||
);
|
||||
|
||||
ArraySize::Constant(constant)
|
||||
}
|
||||
};
|
||||
|
||||
name_meta.subsume(array_meta);
|
||||
handle = parser.module.types.fetch_or_append(
|
||||
Type {
|
||||
name: None,
|
||||
@@ -208,7 +209,7 @@ impl<'source> ParsingContext<'source> {
|
||||
stride,
|
||||
},
|
||||
},
|
||||
name_meta.union(&array_meta).as_span(),
|
||||
name_meta,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -231,17 +232,18 @@ impl<'source> ParsingContext<'source> {
|
||||
| TokenValue::Increment
|
||||
| TokenValue::Decrement = self.expect_peek(parser)?.value
|
||||
{
|
||||
let Token { value, meta } = self.bump(parser)?;
|
||||
let Token { value, mut meta } = self.bump(parser)?;
|
||||
|
||||
match value {
|
||||
TokenValue::LeftBracket => {
|
||||
let index = self.parse_expression(parser, ctx, stmt, body)?;
|
||||
let end_meta = self.expect(parser, TokenValue::RightBracket)?.meta;
|
||||
|
||||
meta.subsume(end_meta);
|
||||
base = stmt.hir_exprs.append(
|
||||
HirExpr {
|
||||
kind: HirExprKind::Access { base, index },
|
||||
meta: meta.union(&end_meta),
|
||||
meta,
|
||||
},
|
||||
Default::default(),
|
||||
)
|
||||
@@ -249,10 +251,11 @@ impl<'source> ParsingContext<'source> {
|
||||
TokenValue::Dot => {
|
||||
let (field, end_meta) = self.expect_ident(parser)?;
|
||||
|
||||
meta.subsume(end_meta);
|
||||
base = stmt.hir_exprs.append(
|
||||
HirExpr {
|
||||
kind: HirExprKind::Select { base, field },
|
||||
meta: meta.union(&end_meta),
|
||||
meta,
|
||||
},
|
||||
Default::default(),
|
||||
)
|
||||
@@ -289,7 +292,7 @@ impl<'source> ParsingContext<'source> {
|
||||
) -> Result<Handle<HirExpr>> {
|
||||
Ok(match self.expect_peek(parser)?.value {
|
||||
TokenValue::Plus | TokenValue::Dash | TokenValue::Bang | TokenValue::Tilde => {
|
||||
let Token { value, meta } = self.bump(parser)?;
|
||||
let Token { value, mut meta } = self.bump(parser)?;
|
||||
|
||||
let expr = self.parse_unary(parser, ctx, stmt, body)?;
|
||||
let end_meta = stmt.hir_exprs[expr].meta;
|
||||
@@ -306,13 +309,9 @@ impl<'source> ParsingContext<'source> {
|
||||
_ => return Ok(expr),
|
||||
};
|
||||
|
||||
stmt.hir_exprs.append(
|
||||
HirExpr {
|
||||
kind,
|
||||
meta: meta.union(&end_meta),
|
||||
},
|
||||
Default::default(),
|
||||
)
|
||||
meta.subsume(end_meta);
|
||||
stmt.hir_exprs
|
||||
.append(HirExpr { kind, meta }, Default::default())
|
||||
}
|
||||
TokenValue::Increment | TokenValue::Decrement => {
|
||||
let Token { value, meta } = self.bump(parser)?;
|
||||
@@ -350,7 +349,7 @@ impl<'source> ParsingContext<'source> {
|
||||
let mut left = passtrough
|
||||
.ok_or(ErrorKind::EndOfFile /* Dummy error */)
|
||||
.or_else(|_| self.parse_unary(parser, ctx, stmt, body))?;
|
||||
let start_meta = stmt.hir_exprs[left].meta;
|
||||
let mut meta = stmt.hir_exprs[left].meta;
|
||||
|
||||
while let Some((l_bp, r_bp)) = binding_power(&self.expect_peek(parser)?.value) {
|
||||
if l_bp < min_bp {
|
||||
@@ -362,6 +361,7 @@ impl<'source> ParsingContext<'source> {
|
||||
let right = self.parse_binary(parser, ctx, stmt, body, None, r_bp)?;
|
||||
let end_meta = stmt.hir_exprs[right].meta;
|
||||
|
||||
meta.subsume(end_meta);
|
||||
left = stmt.hir_exprs.append(
|
||||
HirExpr {
|
||||
kind: HirExprKind::Binary {
|
||||
@@ -390,7 +390,7 @@ impl<'source> ParsingContext<'source> {
|
||||
},
|
||||
right,
|
||||
},
|
||||
meta: start_meta.union(&end_meta),
|
||||
meta,
|
||||
},
|
||||
Default::default(),
|
||||
)
|
||||
@@ -408,7 +408,7 @@ impl<'source> ParsingContext<'source> {
|
||||
passtrough: Option<Handle<HirExpr>>,
|
||||
) -> Result<Handle<HirExpr>> {
|
||||
let mut condition = self.parse_binary(parser, ctx, stmt, body, passtrough, 0)?;
|
||||
let start_meta = stmt.hir_exprs[condition].meta;
|
||||
let mut meta = stmt.hir_exprs[condition].meta;
|
||||
|
||||
if self.bump_if(parser, TokenValue::Question).is_some() {
|
||||
let accept = self.parse_expression(parser, ctx, stmt, body)?;
|
||||
@@ -416,6 +416,7 @@ impl<'source> ParsingContext<'source> {
|
||||
let reject = self.parse_assignment(parser, ctx, stmt, body)?;
|
||||
let end_meta = stmt.hir_exprs[reject].meta;
|
||||
|
||||
meta.subsume(end_meta);
|
||||
condition = stmt.hir_exprs.append(
|
||||
HirExpr {
|
||||
kind: HirExprKind::Conditional {
|
||||
@@ -423,7 +424,7 @@ impl<'source> ParsingContext<'source> {
|
||||
accept,
|
||||
reject,
|
||||
},
|
||||
meta: start_meta.union(&end_meta),
|
||||
meta,
|
||||
},
|
||||
Default::default(),
|
||||
)
|
||||
@@ -440,7 +441,7 @@ impl<'source> ParsingContext<'source> {
|
||||
body: &mut Block,
|
||||
) -> Result<Handle<HirExpr>> {
|
||||
let tgt = self.parse_unary(parser, ctx, stmt, body)?;
|
||||
let start_meta = stmt.hir_exprs[tgt].meta;
|
||||
let mut meta = stmt.hir_exprs[tgt].meta;
|
||||
|
||||
Ok(match self.expect_peek(parser)?.value {
|
||||
TokenValue::Assign => {
|
||||
@@ -448,10 +449,11 @@ impl<'source> ParsingContext<'source> {
|
||||
let value = self.parse_assignment(parser, ctx, stmt, body)?;
|
||||
let end_meta = stmt.hir_exprs[value].meta;
|
||||
|
||||
meta.subsume(end_meta);
|
||||
stmt.hir_exprs.append(
|
||||
HirExpr {
|
||||
kind: HirExprKind::Assign { tgt, value },
|
||||
meta: start_meta.union(&end_meta),
|
||||
meta,
|
||||
},
|
||||
Default::default(),
|
||||
)
|
||||
@@ -470,9 +472,10 @@ impl<'source> ParsingContext<'source> {
|
||||
let right = self.parse_assignment(parser, ctx, stmt, body)?;
|
||||
let end_meta = stmt.hir_exprs[right].meta;
|
||||
|
||||
meta.subsume(end_meta);
|
||||
let value = stmt.hir_exprs.append(
|
||||
HirExpr {
|
||||
meta: start_meta.union(&end_meta),
|
||||
meta,
|
||||
kind: HirExprKind::Binary {
|
||||
left: tgt,
|
||||
op: match token.value {
|
||||
@@ -497,7 +500,7 @@ impl<'source> ParsingContext<'source> {
|
||||
stmt.hir_exprs.append(
|
||||
HirExpr {
|
||||
kind: HirExprKind::Assign { tgt, value },
|
||||
meta: start_meta.union(&end_meta),
|
||||
meta,
|
||||
},
|
||||
Default::default(),
|
||||
)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::front::glsl::context::ExprPos;
|
||||
use crate::front::glsl::SourceMetadata;
|
||||
use crate::front::glsl::Span;
|
||||
use crate::{
|
||||
front::glsl::{
|
||||
ast::ParameterQualifier,
|
||||
@@ -41,7 +41,7 @@ impl<'source> ParsingContext<'source> {
|
||||
ctx: &mut Context,
|
||||
body: &mut Block,
|
||||
terminator: &mut Option<usize>,
|
||||
) -> Result<Option<SourceMetadata>> {
|
||||
) -> Result<Option<Span>> {
|
||||
// TODO: This prevents snippets like the following from working
|
||||
// ```glsl
|
||||
// vec4(1.0);
|
||||
@@ -59,18 +59,21 @@ impl<'source> ParsingContext<'source> {
|
||||
block
|
||||
};
|
||||
|
||||
let &Token { ref value, meta } = self.expect_peek(parser)?;
|
||||
let &Token {
|
||||
ref value,
|
||||
mut meta,
|
||||
} = self.expect_peek(parser)?;
|
||||
|
||||
let meta_rest = match *value {
|
||||
TokenValue::Continue => {
|
||||
let meta = self.bump(parser)?.meta;
|
||||
body.push(Statement::Continue, meta.as_span());
|
||||
body.push(Statement::Continue, meta);
|
||||
terminator.get_or_insert(body.len());
|
||||
self.expect(parser, TokenValue::Semicolon)?.meta
|
||||
}
|
||||
TokenValue::Break => {
|
||||
let meta = self.bump(parser)?.meta;
|
||||
body.push(Statement::Break, meta.as_span());
|
||||
body.push(Statement::Break, meta);
|
||||
terminator.get_or_insert(body.len());
|
||||
self.expect(parser, TokenValue::Semicolon)?.meta
|
||||
}
|
||||
@@ -92,14 +95,14 @@ impl<'source> ParsingContext<'source> {
|
||||
ctx.emit_flush(body);
|
||||
ctx.emit_start();
|
||||
|
||||
body.push(Statement::Return { value }, meta.as_span());
|
||||
body.push(Statement::Return { value }, meta);
|
||||
terminator.get_or_insert(body.len());
|
||||
|
||||
meta
|
||||
}
|
||||
TokenValue::Discard => {
|
||||
let meta = self.bump(parser)?.meta;
|
||||
body.push(Statement::Kill, meta.as_span());
|
||||
body.push(Statement::Kill, meta);
|
||||
terminator.get_or_insert(body.len());
|
||||
|
||||
self.expect(parser, TokenValue::Semicolon)?.meta
|
||||
@@ -113,7 +116,7 @@ impl<'source> ParsingContext<'source> {
|
||||
let expr = self.parse_expression(parser, ctx, &mut stmt, body)?;
|
||||
let (handle, more_meta) =
|
||||
ctx.lower_expect(stmt, parser, expr, ExprPos::Rhs, body)?;
|
||||
meta = meta.union(&more_meta);
|
||||
meta.subsume(more_meta);
|
||||
handle
|
||||
};
|
||||
self.expect(parser, TokenValue::RightParen)?;
|
||||
@@ -125,7 +128,7 @@ impl<'source> ParsingContext<'source> {
|
||||
if let Some(more_meta) =
|
||||
self.parse_statement(parser, ctx, &mut accept, &mut None)?
|
||||
{
|
||||
meta = meta.union(&more_meta)
|
||||
meta.subsume(more_meta)
|
||||
}
|
||||
|
||||
let mut reject = Block::new();
|
||||
@@ -133,7 +136,7 @@ impl<'source> ParsingContext<'source> {
|
||||
if let Some(more_meta) =
|
||||
self.parse_statement(parser, ctx, &mut reject, &mut None)?
|
||||
{
|
||||
meta = meta.union(&more_meta);
|
||||
meta.subsume(more_meta);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,13 +146,13 @@ impl<'source> ParsingContext<'source> {
|
||||
accept,
|
||||
reject,
|
||||
},
|
||||
meta.as_span(),
|
||||
meta,
|
||||
);
|
||||
|
||||
meta
|
||||
}
|
||||
TokenValue::Switch => {
|
||||
let start_meta = self.bump(parser)?.meta;
|
||||
let mut meta = self.bump(parser)?.meta;
|
||||
let end_meta;
|
||||
|
||||
self.expect(parser, TokenValue::LeftParen)?;
|
||||
@@ -297,7 +300,7 @@ impl<'source> ParsingContext<'source> {
|
||||
}
|
||||
}
|
||||
|
||||
let meta = start_meta.union(&end_meta);
|
||||
meta.subsume(end_meta);
|
||||
|
||||
body.push(
|
||||
Statement::Switch {
|
||||
@@ -305,20 +308,20 @@ impl<'source> ParsingContext<'source> {
|
||||
cases,
|
||||
default,
|
||||
},
|
||||
meta.as_span(),
|
||||
meta,
|
||||
);
|
||||
|
||||
meta
|
||||
}
|
||||
TokenValue::While => {
|
||||
let meta = self.bump(parser)?.meta;
|
||||
let mut meta = self.bump(parser)?.meta;
|
||||
|
||||
let mut loop_body = Block::new();
|
||||
|
||||
let mut stmt = ctx.stmt_ctx();
|
||||
self.expect(parser, TokenValue::LeftParen)?;
|
||||
let root = self.parse_expression(parser, ctx, &mut stmt, &mut loop_body)?;
|
||||
let meta = meta.union(&self.expect(parser, TokenValue::RightParen)?.meta);
|
||||
meta.subsume(self.expect(parser, TokenValue::RightParen)?.meta);
|
||||
|
||||
let (expr, expr_meta) =
|
||||
ctx.lower_expect(stmt, parser, root, ExprPos::Rhs, &mut loop_body)?;
|
||||
@@ -343,12 +346,12 @@ impl<'source> ParsingContext<'source> {
|
||||
crate::Span::default(),
|
||||
);
|
||||
|
||||
let mut meta = meta.union(&expr_meta);
|
||||
meta.subsume(expr_meta);
|
||||
|
||||
if let Some(body_meta) =
|
||||
self.parse_statement(parser, ctx, &mut loop_body, &mut None)?
|
||||
{
|
||||
meta = meta.union(&body_meta);
|
||||
meta.subsume(body_meta);
|
||||
}
|
||||
|
||||
body.push(
|
||||
@@ -356,13 +359,13 @@ impl<'source> ParsingContext<'source> {
|
||||
body: loop_body,
|
||||
continuing: Block::new(),
|
||||
},
|
||||
meta.as_span(),
|
||||
meta,
|
||||
);
|
||||
|
||||
meta
|
||||
}
|
||||
TokenValue::Do => {
|
||||
let start_meta = self.bump(parser)?.meta;
|
||||
let mut meta = self.bump(parser)?.meta;
|
||||
|
||||
let mut loop_body = Block::new();
|
||||
|
||||
@@ -375,7 +378,7 @@ impl<'source> ParsingContext<'source> {
|
||||
let root = self.parse_expression(parser, ctx, &mut stmt, &mut loop_body)?;
|
||||
let end_meta = self.expect(parser, TokenValue::RightParen)?.meta;
|
||||
|
||||
let meta = start_meta.union(&end_meta);
|
||||
meta.subsume(end_meta);
|
||||
|
||||
let (expr, expr_meta) =
|
||||
ctx.lower_expect(stmt, parser, root, ExprPos::Rhs, &mut loop_body)?;
|
||||
@@ -405,13 +408,13 @@ impl<'source> ParsingContext<'source> {
|
||||
body: loop_body,
|
||||
continuing: Block::new(),
|
||||
},
|
||||
meta.as_span(),
|
||||
meta,
|
||||
);
|
||||
|
||||
meta
|
||||
}
|
||||
TokenValue::For => {
|
||||
let meta = self.bump(parser)?.meta;
|
||||
let mut meta = self.bump(parser)?.meta;
|
||||
|
||||
ctx.push_scope();
|
||||
self.expect(parser, TokenValue::LeftParen)?;
|
||||
@@ -433,14 +436,14 @@ impl<'source> ParsingContext<'source> {
|
||||
let (expr, expr_meta) =
|
||||
if self.peek_type_name(parser) || self.peek_type_qualifier(parser) {
|
||||
let qualifiers = self.parse_type_qualifiers(parser)?;
|
||||
let (ty, meta) = self.parse_type_non_void(parser)?;
|
||||
let (ty, mut meta) = self.parse_type_non_void(parser)?;
|
||||
let name = self.expect_ident(parser)?.0;
|
||||
|
||||
self.expect(parser, TokenValue::Assign)?;
|
||||
|
||||
let (value, end_meta) =
|
||||
self.parse_initializer(parser, ty, ctx, &mut block)?;
|
||||
let meta = meta.union(&end_meta);
|
||||
meta.subsume(end_meta);
|
||||
|
||||
let decl = VarDeclaration {
|
||||
qualifiers: &qualifiers,
|
||||
@@ -455,7 +458,7 @@ impl<'source> ParsingContext<'source> {
|
||||
ctx.emit_flush(&mut block);
|
||||
ctx.emit_start();
|
||||
|
||||
block.push(Statement::Store { pointer, value }, meta.as_span());
|
||||
block.push(Statement::Store { pointer, value }, meta);
|
||||
|
||||
(value, end_meta)
|
||||
} else {
|
||||
@@ -498,10 +501,10 @@ impl<'source> ParsingContext<'source> {
|
||||
}
|
||||
}
|
||||
|
||||
let mut meta = meta.union(&self.expect(parser, TokenValue::RightParen)?.meta);
|
||||
meta.subsume(self.expect(parser, TokenValue::RightParen)?.meta);
|
||||
|
||||
if let Some(stmt_meta) = self.parse_statement(parser, ctx, &mut block, &mut None)? {
|
||||
meta = meta.union(&stmt_meta);
|
||||
meta.subsume(stmt_meta);
|
||||
}
|
||||
|
||||
body.push(
|
||||
@@ -509,7 +512,7 @@ impl<'source> ParsingContext<'source> {
|
||||
body: block,
|
||||
continuing,
|
||||
},
|
||||
meta.as_span(),
|
||||
meta,
|
||||
);
|
||||
|
||||
ctx.remove_current_scope();
|
||||
@@ -526,7 +529,7 @@ impl<'source> ParsingContext<'source> {
|
||||
|
||||
ctx.remove_current_scope();
|
||||
|
||||
body.push(Statement::Block(block), meta.as_span());
|
||||
body.push(Statement::Block(block), meta);
|
||||
|
||||
meta
|
||||
}
|
||||
@@ -542,30 +545,31 @@ impl<'source> ParsingContext<'source> {
|
||||
}
|
||||
};
|
||||
|
||||
Ok(Some(meta.union(&meta_rest)))
|
||||
meta.subsume(meta_rest);
|
||||
Ok(Some(meta))
|
||||
}
|
||||
|
||||
pub fn parse_compound_statement(
|
||||
&mut self,
|
||||
mut meta: SourceMetadata,
|
||||
mut meta: Span,
|
||||
parser: &mut Parser,
|
||||
ctx: &mut Context,
|
||||
body: &mut Block,
|
||||
) -> Result<SourceMetadata> {
|
||||
) -> Result<Span> {
|
||||
let mut terminator = None;
|
||||
loop {
|
||||
if let Some(Token {
|
||||
meta: brace_meta, ..
|
||||
}) = self.bump_if(parser, TokenValue::RightBrace)
|
||||
{
|
||||
meta = meta.union(&brace_meta);
|
||||
meta.subsume(brace_meta);
|
||||
break;
|
||||
}
|
||||
|
||||
let stmt = self.parse_statement(parser, ctx, body, &mut terminator)?;
|
||||
|
||||
if let Some(stmt_meta) = stmt {
|
||||
meta = meta.union(&stmt_meta);
|
||||
meta.subsume(stmt_meta);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,10 +3,10 @@ use crate::{
|
||||
ast::{StorageQualifier, StructLayout, TypeQualifier},
|
||||
error::ExpectedToken,
|
||||
parser::ParsingContext,
|
||||
token::{SourceMetadata, Token, TokenValue},
|
||||
token::{Token, TokenValue},
|
||||
Error, ErrorKind, Parser, Result,
|
||||
},
|
||||
ArraySize, Handle, StorageClass, Type, TypeInner,
|
||||
ArraySize, Handle, Span, StorageClass, Type, TypeInner,
|
||||
};
|
||||
|
||||
impl<'source> ParsingContext<'source> {
|
||||
@@ -15,44 +15,38 @@ impl<'source> ParsingContext<'source> {
|
||||
pub fn parse_array_specifier(
|
||||
&mut self,
|
||||
parser: &mut Parser,
|
||||
) -> Result<Option<(ArraySize, SourceMetadata)>> {
|
||||
if let Some(Token { meta, .. }) = self.bump_if(parser, TokenValue::LeftBracket) {
|
||||
) -> Result<Option<(ArraySize, Span)>> {
|
||||
if let Some(Token { mut meta, .. }) = self.bump_if(parser, TokenValue::LeftBracket) {
|
||||
if let Some(Token { meta: end_meta, .. }) =
|
||||
self.bump_if(parser, TokenValue::RightBracket)
|
||||
{
|
||||
return Ok(Some((ArraySize::Dynamic, meta.union(&end_meta))));
|
||||
meta.subsume(end_meta);
|
||||
return Ok(Some((ArraySize::Dynamic, meta)));
|
||||
}
|
||||
|
||||
let (constant, _) = self.parse_constant_expression(parser)?;
|
||||
let end_meta = self.expect(parser, TokenValue::RightBracket)?.meta;
|
||||
Ok(Some((ArraySize::Constant(constant), meta.union(&end_meta))))
|
||||
meta.subsume(end_meta);
|
||||
Ok(Some((ArraySize::Constant(constant), meta)))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse_type(
|
||||
&mut self,
|
||||
parser: &mut Parser,
|
||||
) -> Result<(Option<Handle<Type>>, SourceMetadata)> {
|
||||
pub fn parse_type(&mut self, parser: &mut Parser) -> Result<(Option<Handle<Type>>, Span)> {
|
||||
let token = self.bump(parser)?;
|
||||
let handle = match token.value {
|
||||
TokenValue::Void => None,
|
||||
TokenValue::TypeName(ty) => Some(
|
||||
parser
|
||||
.module
|
||||
.types
|
||||
.fetch_or_append(ty, token.meta.as_span()),
|
||||
),
|
||||
TokenValue::TypeName(ty) => Some(parser.module.types.fetch_or_append(ty, token.meta)),
|
||||
TokenValue::Struct => {
|
||||
let meta = token.meta;
|
||||
let mut meta = token.meta;
|
||||
let ty_name = self.expect_ident(parser)?.0;
|
||||
self.expect(parser, TokenValue::LeftBrace)?;
|
||||
let mut members = Vec::new();
|
||||
let span =
|
||||
self.parse_struct_declaration_list(parser, &mut members, StructLayout::Std140)?;
|
||||
let end_meta = self.expect(parser, TokenValue::RightBrace)?.meta;
|
||||
|
||||
meta.subsume(end_meta);
|
||||
let ty = parser.module.types.append(
|
||||
Type {
|
||||
name: Some(ty_name.clone()),
|
||||
@@ -62,7 +56,7 @@ impl<'source> ParsingContext<'source> {
|
||||
span,
|
||||
},
|
||||
},
|
||||
meta.union(&end_meta).as_span(),
|
||||
meta,
|
||||
);
|
||||
parser.lookup_type.insert(ty_name, ty);
|
||||
Some(ty)
|
||||
@@ -94,14 +88,12 @@ impl<'source> ParsingContext<'source> {
|
||||
let token_meta = token.meta;
|
||||
let array_specifier = self.parse_array_specifier(parser)?;
|
||||
let handle = handle.map(|ty| parser.maybe_array(ty, token_meta, array_specifier));
|
||||
let meta = array_specifier.map_or(token_meta, |(_, meta)| meta.union(&token_meta));
|
||||
let mut meta = array_specifier.map_or(token_meta, |(_, meta)| meta);
|
||||
meta.subsume(token_meta);
|
||||
Ok((handle, meta))
|
||||
}
|
||||
|
||||
pub fn parse_type_non_void(
|
||||
&mut self,
|
||||
parser: &mut Parser,
|
||||
) -> Result<(Handle<Type>, SourceMetadata)> {
|
||||
pub fn parse_type_non_void(&mut self, parser: &mut Parser) -> Result<(Handle<Type>, Span)> {
|
||||
let (maybe_ty, meta) = self.parse_type(parser)?;
|
||||
let ty = maybe_ty.ok_or_else(|| Error {
|
||||
kind: ErrorKind::SemanticError("Type can't be void".into()),
|
||||
@@ -132,7 +124,7 @@ impl<'source> ParsingContext<'source> {
|
||||
pub fn parse_type_qualifiers(
|
||||
&mut self,
|
||||
parser: &mut Parser,
|
||||
) -> Result<Vec<(TypeQualifier, SourceMetadata)>> {
|
||||
) -> Result<Vec<(TypeQualifier, Span)>> {
|
||||
let mut qualifiers = Vec::new();
|
||||
|
||||
while self.peek_type_qualifier(parser) {
|
||||
@@ -177,7 +169,7 @@ impl<'source> ParsingContext<'source> {
|
||||
pub fn parse_layout_qualifier_id_list(
|
||||
&mut self,
|
||||
parser: &mut Parser,
|
||||
qualifiers: &mut Vec<(TypeQualifier, SourceMetadata)>,
|
||||
qualifiers: &mut Vec<(TypeQualifier, Span)>,
|
||||
) -> Result<()> {
|
||||
self.expect(parser, TokenValue::LeftParen)?;
|
||||
loop {
|
||||
@@ -197,7 +189,7 @@ impl<'source> ParsingContext<'source> {
|
||||
pub fn parse_layout_qualifier_id(
|
||||
&mut self,
|
||||
parser: &mut Parser,
|
||||
qualifiers: &mut Vec<(TypeQualifier, SourceMetadata)>,
|
||||
qualifiers: &mut Vec<(TypeQualifier, Span)>,
|
||||
) -> Result<()> {
|
||||
// layout_qualifier_id:
|
||||
// IDENTIFIER
|
||||
@@ -208,7 +200,7 @@ impl<'source> ParsingContext<'source> {
|
||||
TokenValue::Identifier(name) => {
|
||||
if self.bump_if(parser, TokenValue::Assign).is_some() {
|
||||
let (value, end_meta) = self.parse_uint_constant(parser)?;
|
||||
token.meta = token.meta.union(&end_meta);
|
||||
token.meta.subsume(end_meta);
|
||||
|
||||
qualifiers.push((
|
||||
match name.as_str() {
|
||||
|
||||
@@ -3,7 +3,7 @@ use super::{
|
||||
error::ExpectedToken,
|
||||
error::{Error, ErrorKind},
|
||||
token::TokenValue,
|
||||
Options, Parser, SourceMetadata,
|
||||
Options, Parser, Span,
|
||||
};
|
||||
use crate::ShaderStage;
|
||||
use pp_rs::token::PreprocessorError;
|
||||
@@ -23,7 +23,7 @@ fn version() {
|
||||
.unwrap(),
|
||||
vec![Error {
|
||||
kind: ErrorKind::InvalidVersion(99000),
|
||||
meta: SourceMetadata { start: 9, end: 14 }
|
||||
meta: Span::new(9, 14)
|
||||
}],
|
||||
);
|
||||
|
||||
@@ -37,7 +37,7 @@ fn version() {
|
||||
.unwrap(),
|
||||
vec![Error {
|
||||
kind: ErrorKind::InvalidVersion(449),
|
||||
meta: SourceMetadata { start: 9, end: 12 }
|
||||
meta: Span::new(9, 12)
|
||||
}]
|
||||
);
|
||||
|
||||
@@ -51,7 +51,7 @@ fn version() {
|
||||
.unwrap(),
|
||||
vec![Error {
|
||||
kind: ErrorKind::InvalidProfile("smart".into()),
|
||||
meta: SourceMetadata { start: 13, end: 18 },
|
||||
meta: Span::new(13, 18),
|
||||
}]
|
||||
);
|
||||
|
||||
@@ -66,14 +66,14 @@ fn version() {
|
||||
vec![
|
||||
Error {
|
||||
kind: ErrorKind::PreprocessorError(PreprocessorError::UnexpectedHash,),
|
||||
meta: SourceMetadata { start: 27, end: 28 },
|
||||
meta: Span::new(27, 28),
|
||||
},
|
||||
Error {
|
||||
kind: ErrorKind::InvalidToken(
|
||||
TokenValue::Identifier("version".into()),
|
||||
vec![ExpectedToken::Eof]
|
||||
),
|
||||
meta: SourceMetadata { start: 28, end: 35 }
|
||||
meta: Span::new(28, 35)
|
||||
}
|
||||
]
|
||||
);
|
||||
@@ -449,10 +449,7 @@ fn functions() {
|
||||
.unwrap(),
|
||||
vec![Error {
|
||||
kind: ErrorKind::SemanticError("Function already defined".into()),
|
||||
meta: SourceMetadata {
|
||||
start: 134,
|
||||
end: 152
|
||||
},
|
||||
meta: Span::new(134, 152),
|
||||
}]
|
||||
);
|
||||
|
||||
@@ -608,10 +605,7 @@ fn implicit_conversions() {
|
||||
.unwrap(),
|
||||
vec![Error {
|
||||
kind: ErrorKind::SemanticError("Unknown function \'test\'".into()),
|
||||
meta: SourceMetadata {
|
||||
start: 156,
|
||||
end: 165
|
||||
},
|
||||
meta: Span::new(156, 165),
|
||||
}]
|
||||
);
|
||||
|
||||
@@ -633,10 +627,7 @@ fn implicit_conversions() {
|
||||
.unwrap(),
|
||||
vec![Error {
|
||||
kind: ErrorKind::SemanticError("Ambiguous best function for \'test\'".into()),
|
||||
meta: SourceMetadata {
|
||||
start: 158,
|
||||
end: 165
|
||||
},
|
||||
meta: Span::new(158, 165),
|
||||
}]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,85 +1,11 @@
|
||||
use pp_rs::token::Location;
|
||||
pub use pp_rs::token::{Float, Integer, PreprocessorError, Token as PPToken};
|
||||
pub use pp_rs::token::{Float, Integer, Location, PreprocessorError, Token as PPToken};
|
||||
|
||||
use super::ast::Precision;
|
||||
use crate::{Interpolation, Sampling, Type};
|
||||
use std::ops::Range;
|
||||
use crate::{Interpolation, Sampling, Span, Type};
|
||||
|
||||
/// Represents a range of the source code
|
||||
///
|
||||
/// The `SourceMetadata` is used in error reporting to indicate a range of the
|
||||
/// original source code where the error happened.
|
||||
///
|
||||
/// For easy interaction with error crates like
|
||||
/// [`codespan`][codespan] the [`From`](From) trait is
|
||||
/// implemeted for [`Range<usize>`](Range) allowing for conversions from `SourceMetadata`.
|
||||
///
|
||||
/// ```rust
|
||||
/// # use naga::front::glsl::SourceMetadata;
|
||||
/// # use std::ops::Range;
|
||||
/// # let meta = SourceMetadata::default();
|
||||
/// let range: Range<usize> = meta.into();
|
||||
/// ```
|
||||
///
|
||||
/// Or in the case of [`codespan`][codespan]
|
||||
///
|
||||
/// ```rust
|
||||
/// # use naga::front::glsl::SourceMetadata;
|
||||
/// # #[cfg(feature = "codespan_reporting")]
|
||||
/// # {
|
||||
/// use codespan_reporting::diagnostic::Label;
|
||||
/// # let file = ();
|
||||
/// # let meta = SourceMetadata::default();
|
||||
/// let label = Label::primary(file, meta);
|
||||
/// # }
|
||||
/// ```
|
||||
///
|
||||
/// # Notes
|
||||
///
|
||||
/// [`start`](SourceMetadata::start) can be equal to
|
||||
/// [`end`](SourceMetadata::end) especially when reporting errors which aren't
|
||||
/// associated with a specific portion of the code.
|
||||
///
|
||||
/// [codespan]: https://docs.rs/codespan-reporting
|
||||
#[derive(Debug, Clone, Copy, Default)]
|
||||
#[cfg_attr(test, derive(PartialEq))]
|
||||
pub struct SourceMetadata {
|
||||
/// Byte offset into the source where the first char starts
|
||||
pub start: usize,
|
||||
/// Byte offset into the source where the first char not belonging to this
|
||||
/// source metadata starts
|
||||
pub end: usize,
|
||||
}
|
||||
|
||||
impl SourceMetadata {
|
||||
pub(crate) fn union(&self, other: &Self) -> Self {
|
||||
SourceMetadata {
|
||||
start: self.start.min(other.start),
|
||||
end: self.end.max(other.end),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_span(&self) -> crate::Span {
|
||||
crate::Span::new(self.start as u32, self.end as u32)
|
||||
}
|
||||
|
||||
pub(crate) fn none() -> Self {
|
||||
SourceMetadata::default()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Location> for SourceMetadata {
|
||||
impl From<Location> for Span {
|
||||
fn from(loc: Location) -> Self {
|
||||
SourceMetadata {
|
||||
start: loc.start as usize,
|
||||
end: loc.end as usize,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<SourceMetadata> for Range<usize> {
|
||||
fn from(meta: SourceMetadata) -> Self {
|
||||
meta.start..meta.end
|
||||
Span::new(loc.start, loc.end)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +13,7 @@ impl From<SourceMetadata> for Range<usize> {
|
||||
#[cfg_attr(test, derive(PartialEq))]
|
||||
pub struct Token {
|
||||
pub value: TokenValue,
|
||||
pub meta: SourceMetadata,
|
||||
pub meta: Span,
|
||||
}
|
||||
|
||||
/// A token passed from the lexing used in the parsing
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use super::{
|
||||
constants::ConstantSolver, context::Context, Error, ErrorKind, Parser, Result, SourceMetadata,
|
||||
};
|
||||
use super::{constants::ConstantSolver, context::Context, Error, ErrorKind, Parser, Result, Span};
|
||||
use crate::{
|
||||
proc::ResolveContext, ArraySize, Bytes, Constant, Expression, Handle, ImageClass,
|
||||
ImageDimension, ScalarKind, Type, TypeInner, VectorSize,
|
||||
@@ -184,7 +182,7 @@ impl Parser {
|
||||
&self,
|
||||
ctx: &mut Context,
|
||||
handle: Handle<Expression>,
|
||||
meta: SourceMetadata,
|
||||
meta: Span,
|
||||
) -> Result<()> {
|
||||
let resolve_ctx = ResolveContext {
|
||||
constants: &self.module.constants,
|
||||
@@ -207,7 +205,7 @@ impl Parser {
|
||||
&'b self,
|
||||
ctx: &'b mut Context,
|
||||
handle: Handle<Expression>,
|
||||
meta: SourceMetadata,
|
||||
meta: Span,
|
||||
) -> Result<&'b TypeInner> {
|
||||
self.typifier_grow(ctx, handle, meta)?;
|
||||
Ok(ctx.typifier.get(handle, &self.module.types))
|
||||
@@ -218,7 +216,7 @@ impl Parser {
|
||||
&'b self,
|
||||
ctx: &'b mut Context,
|
||||
handle: Handle<Expression>,
|
||||
meta: SourceMetadata,
|
||||
meta: Span,
|
||||
) -> Result<()> {
|
||||
let resolve_ctx = ResolveContext {
|
||||
constants: &self.module.constants,
|
||||
@@ -241,7 +239,7 @@ impl Parser {
|
||||
&mut self,
|
||||
ctx: &Context,
|
||||
root: Handle<Expression>,
|
||||
meta: SourceMetadata,
|
||||
meta: Span,
|
||||
) -> Result<Handle<Constant>> {
|
||||
let mut solver = ConstantSolver {
|
||||
types: &self.module.types,
|
||||
@@ -258,11 +256,12 @@ impl Parser {
|
||||
pub(crate) fn maybe_array(
|
||||
&mut self,
|
||||
base: Handle<Type>,
|
||||
meta: SourceMetadata,
|
||||
array_specifier: Option<(ArraySize, SourceMetadata)>,
|
||||
mut meta: Span,
|
||||
array_specifier: Option<(ArraySize, Span)>,
|
||||
) -> Handle<Type> {
|
||||
array_specifier
|
||||
.map(|(size, size_meta)| {
|
||||
meta.subsume(size_meta);
|
||||
self.module.types.fetch_or_append(
|
||||
Type {
|
||||
name: None,
|
||||
@@ -272,7 +271,7 @@ impl Parser {
|
||||
stride: self.module.types[base].inner.span(&self.module.constants),
|
||||
},
|
||||
},
|
||||
meta.union(&size_meta).as_span(),
|
||||
meta,
|
||||
)
|
||||
})
|
||||
.unwrap_or(base)
|
||||
|
||||
@@ -2,7 +2,7 @@ use super::{
|
||||
ast::*,
|
||||
context::Context,
|
||||
error::{Error, ErrorKind},
|
||||
Parser, Result, SourceMetadata,
|
||||
Parser, Result, Span,
|
||||
};
|
||||
use crate::{
|
||||
Binding, Block, BuiltIn, Constant, Expression, GlobalVariable, Handle, Interpolation,
|
||||
@@ -24,11 +24,11 @@ macro_rules! qualifier_arm {
|
||||
}
|
||||
|
||||
pub struct VarDeclaration<'a> {
|
||||
pub qualifiers: &'a [(TypeQualifier, SourceMetadata)],
|
||||
pub qualifiers: &'a [(TypeQualifier, Span)],
|
||||
pub ty: Handle<Type>,
|
||||
pub name: Option<String>,
|
||||
pub init: Option<Handle<Constant>>,
|
||||
pub meta: SourceMetadata,
|
||||
pub meta: Span,
|
||||
}
|
||||
|
||||
/// Information about a builtin used in [`add_builtin`](Parser::add_builtin)
|
||||
@@ -56,14 +56,14 @@ impl Parser {
|
||||
body: &mut Block,
|
||||
name: &str,
|
||||
data: BuiltInData,
|
||||
meta: SourceMetadata,
|
||||
meta: Span,
|
||||
) -> Option<VariableReference> {
|
||||
let ty = self.module.types.fetch_or_append(
|
||||
Type {
|
||||
name: None,
|
||||
inner: data.inner,
|
||||
},
|
||||
meta.as_span(),
|
||||
meta,
|
||||
);
|
||||
|
||||
let handle = self.module.global_variables.append(
|
||||
@@ -74,7 +74,7 @@ impl Parser {
|
||||
ty,
|
||||
init: None,
|
||||
},
|
||||
meta.as_span(),
|
||||
meta,
|
||||
);
|
||||
|
||||
let idx = self.entry_args.len();
|
||||
@@ -114,7 +114,7 @@ impl Parser {
|
||||
ctx: &mut Context,
|
||||
body: &mut Block,
|
||||
name: &str,
|
||||
meta: SourceMetadata,
|
||||
meta: Span,
|
||||
) -> Option<VariableReference> {
|
||||
if let Some(local_var) = ctx.lookup_local_var(name) {
|
||||
return Some(local_var);
|
||||
@@ -196,7 +196,7 @@ impl Parser {
|
||||
width: 4,
|
||||
},
|
||||
},
|
||||
meta.as_span(),
|
||||
meta,
|
||||
);
|
||||
|
||||
BuiltInData {
|
||||
@@ -248,7 +248,7 @@ impl Parser {
|
||||
body: &mut Block,
|
||||
expression: Handle<Expression>,
|
||||
name: &str,
|
||||
meta: SourceMetadata,
|
||||
meta: Span,
|
||||
) -> Result<Handle<Expression>> {
|
||||
let (ty, is_pointer) = match *self.resolve_type(ctx, expression, meta)? {
|
||||
TypeInner::Pointer { base, .. } => (&self.module.types[base].inner, true),
|
||||
@@ -562,7 +562,7 @@ impl Parser {
|
||||
ty,
|
||||
init,
|
||||
},
|
||||
meta.as_span(),
|
||||
meta,
|
||||
);
|
||||
|
||||
let idx = self.entry_args.len();
|
||||
@@ -633,7 +633,7 @@ impl Parser {
|
||||
ty,
|
||||
init,
|
||||
},
|
||||
meta.as_span(),
|
||||
meta,
|
||||
);
|
||||
|
||||
if let Some(name) = name {
|
||||
@@ -711,7 +711,7 @@ impl Parser {
|
||||
ty,
|
||||
init,
|
||||
},
|
||||
meta.as_span(),
|
||||
meta,
|
||||
);
|
||||
let expr = ctx.add_expression(Expression::LocalVariable(handle), meta, body);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user