@@ -12,8 +12,8 @@ use resolve::Resolvable;
12
12
pub use rust_ast:: ToFragment ;
13
13
14
14
use crate :: {
15
- Arith , BaseType , DynFormat , Expr , Format , FormatModule , IntRel , IntoLabel , Label , MatchTree ,
16
- Pattern , StyleHint , UnaryOp , ViewExpr , ViewFormat ,
15
+ Arith , BaseKind , BaseType , CommonOp , DynFormat , Endian , Expr , Format , FormatModule , IntRel ,
16
+ IntoLabel , Label , MatchTree , Pattern , StyleHint , UnaryOp , ViewExpr , ViewFormat ,
17
17
byte_set:: ByteSet ,
18
18
decoder:: extract_pair,
19
19
parser:: error:: TraceHash ,
@@ -2702,7 +2702,7 @@ impl ToAst for SimpleLogic<GTExpr> {
2702
2702
enum ViewLogic < ExprT > {
2703
2703
LetView ( Label , Box < CaseLogic < ExprT > > ) ,
2704
2704
CaptureBytes ( RustExpr , RustExpr ) ,
2705
- ReadArray ( RustExpr , RustExpr , crate :: BaseKind ) ,
2705
+ ReadArray ( RustExpr , RustExpr , BaseKind < Endian > ) ,
2706
2706
ReifyView ( RustExpr ) ,
2707
2707
}
2708
2708
@@ -3293,11 +3293,14 @@ where
3293
3293
}
3294
3294
OtherLogic :: Hint ( _hint, inner) => {
3295
3295
let inner_block = inner. to_ast ( ctxt) ;
3296
-
3297
3296
match _hint {
3298
3297
// REVIEW - do we want to perform any local modifications?
3299
3298
StyleHint :: Record { .. } => inner_block,
3300
3299
StyleHint :: AsciiStr => inner_block,
3300
+ StyleHint :: Common ( CommonOp :: EndianParse ( _kind_endian) ) => {
3301
+ // REVIEW - do we want to swap-in particular endian parses instead?
3302
+ inner_block
3303
+ }
3301
3304
}
3302
3305
}
3303
3306
}
@@ -4401,7 +4404,25 @@ impl<'a> Elaborator<'a> {
4401
4404
}
4402
4405
}
4403
4406
}
4404
- StyleHint :: AsciiStr => ( ) ,
4407
+ StyleHint :: AsciiStr => {
4408
+ // REVIEW - should we check for Seq(u8)-like types?
4409
+ }
4410
+ StyleHint :: Common ( common_op) => match common_op {
4411
+ CommonOp :: EndianParse ( base_kind) => {
4412
+ // double-check the base kind against the type
4413
+ let ty = gt. to_rust_type ( ) ;
4414
+ let prim1 = PrimType :: from ( BaseType :: from ( * base_kind) ) ;
4415
+ let Some ( prim0) = ty. try_as_prim ( ) else {
4416
+ unreachable ! (
4417
+ "found non-primitive type for common format elaboration: {ty:?} @ {index} (expected {prim1:?})"
4418
+ ) ;
4419
+ } ;
4420
+ assert_eq ! (
4421
+ prim0, prim1,
4422
+ "CommonOp: actual inner-parse type ({prim0:?}) does not match claimed type ({prim1:?})"
4423
+ ) ;
4424
+ }
4425
+ } ,
4405
4426
}
4406
4427
TypedFormat :: Hint ( gt, style_hint. clone ( ) , Box :: new ( t_inner) )
4407
4428
}
0 commit comments