diff options
Diffstat (limited to 'oryxc/src/parser.rs')
| -rw-r--r-- | oryxc/src/parser.rs | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/oryxc/src/parser.rs b/oryxc/src/parser.rs index 8c24df1..93adc9f 100644 --- a/oryxc/src/parser.rs +++ b/oryxc/src/parser.rs @@ -1,3 +1,5 @@ +use std::iter; + use soa_rs::{ Soa, Soars, @@ -36,6 +38,16 @@ pub enum AstType { UnaryOperator, /* (rhs, _) */ } +/// The number of AstType variants that represent expressions/binops/etc. In +/// the places where we match/switch on just the subset of AstTypes that are +/// expressions/etc., we can static assert that this equals its current value. +/// This is useful because if a new AstType of the given subset is added and +/// these numbers are incremented, the static asserts fail everywhere where code +/// changes are required. +pub const NEXPRKINDS: usize = 10; +pub const NUNARYKINDS: usize = 5; +pub const NBINARYKINDS: usize = 23; + #[derive(Soars)] #[soa_derive(Debug)] pub struct AstNode { @@ -48,7 +60,7 @@ pub struct AstNode { pub struct Ast { pub nodes: Soa<AstNode>, pub extra: Vec<u32>, - pub types: Box<[TypeId]>, + pub types: Box<[TypeCell]>, pub textra: boxcar::Vec<TypeId>, } @@ -923,7 +935,9 @@ pub fn parse(tokens: &Soa<Token>) -> Result<Ast, Vec<OryxError>> { return Ok(Ast { nodes: p.ast, extra: p.extra_data, - types: vec![TypeId::INVALID; nodecnt].into_boxed_slice(), + types: iter::repeat_with(|| TypeCell::new(TypeId::INVALID)) + .take(nodecnt) + .collect::<Box<[_]>>(), /* TODO: Get the parser to try to compute the required capacity */ textra: boxcar::vec![], }); |