use std::fmt::Debug; use bitflags::bitflags; use dbg_pls::DebugPls; use crate::Spanned; #[derive(Debug, DebugPls)] pub enum TypeSpecifier { Void, Char, Short, Int, Long, Float, Double, Signed, Unsigned, Bool, Complex, // TODO // atomic-type-specifier // struct-or-union-specifier // enum-specifier // typedef-name } pub type Ident = Spanned; bitflags! { pub struct DeclAttr: u8 { const EXTERN = 0b00000001; const STATIC = 0b00000010; const THREAD_LOCAL = 0b00000100; } } impl DebugPls for DeclAttr { fn fmt(&self, f: dbg_pls::Formatter<'_>) { use std::fmt::Write; let mut string = String::new(); write!(string, "{:?}", self).unwrap(); DebugPls::fmt(&string, f); } } #[derive(Debug, DebugPls)] pub struct DeclSpec { pub ty: TypeSpecifier, pub attrs: DeclAttr, } #[derive(Debug, DebugPls)] pub enum Decl { Normal(NormalDecl), StaticAssert, } #[derive(Debug, DebugPls)] pub struct InitDecl { pub declarator: Declarator, pub init: Option<()>, } #[derive(Debug, DebugPls)] pub struct NormalDecl { pub decl_spec: DeclSpec, pub init_declarators: Vec>, } #[derive(Debug, DebugPls)] pub struct FunctionParamDecl { pub decl_spec: Spanned, pub declarator: Spanned, } #[derive(Debug, DebugPls)] pub enum DirectDeclarator { Ident(Ident), WithParams { ident: Ident, params: Vec, }, } #[derive(Debug, DebugPls)] pub struct Declarator { pub decl: DirectDeclarator, pub pointer: bool, } #[derive(Debug, DebugPls)] pub struct FunctionDef { pub declaration: Decl, pub body: Vec<()>, } #[derive(Debug, DebugPls)] pub enum ExternalDecl { Decl(Decl), FunctionDef(FunctionDef), }