mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
* Proof of concept for "span" feature, with WGSL parsing augmented. * Review: 1) add_span was actually a bad idea, make it set_span and add set_span_if_unknown too. 2) panics on getting/setting span for invalid handles. 3) only set span for constants with a name 4) don't overwrite spans for types. * Added spans to blocks & more expressions getting spans in frontends. Definitely the shotgunny type of commit, but what can you do. The design I went with made spans mandatory to specify, so I had to go and wire them through wherever I could. * Moved Block to a separate module, +clippy * More spans for types in GLSL. * Remove pointless body method. * Make Arena interface require spans. Another shotgun commit, oh boy... * Fix tests. My loathsome habit to "quickly fix things along the way" made a lot of extra work for me here, having to fix my "fixes" for WGSL parser. * Rustfmt + clippy. * Fix compile-errors with span feature enabled. * Nuked set_span* from orbit. Deleting code feels great! * Code review - move feature flags inside functions. * Fix build with "deserialize" feature enabled.
39 lines
988 B
Rust
39 lines
988 B
Rust
use std::ops::Range;
|
|
|
|
// A source code span, used for error reporting.
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
pub enum Span {
|
|
// Span is unknown - no source information.
|
|
Unknown,
|
|
// Byte range.
|
|
ByteRange(Range<usize>),
|
|
}
|
|
|
|
impl Default for Span {
|
|
fn default() -> Self {
|
|
Self::Unknown
|
|
}
|
|
}
|
|
|
|
impl Span {
|
|
pub fn subsume(&mut self, other: &Self) {
|
|
match *self {
|
|
Self::Unknown => self.clone_from(other),
|
|
Self::ByteRange(ref mut self_range) => {
|
|
if let Self::ByteRange(ref other_range) = *other {
|
|
self_range.start = self_range.start.min(other_range.start);
|
|
self_range.end = self_range.end.max(other_range.end);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn total_span<'a, T: Iterator<Item = &'a Self>>(from: T) -> Self {
|
|
let mut span: Self = Default::default();
|
|
for other in from {
|
|
span.subsume(other);
|
|
}
|
|
span
|
|
}
|
|
}
|