This commit is contained in:
nora 2022-07-24 18:38:19 +02:00
parent 475a520de3
commit 683f11c997
6 changed files with 111 additions and 13 deletions

View file

@ -262,3 +262,25 @@ pub enum ExternalDecl {
}
pub type TranslationUnit = Vec<Spanned<ExternalDecl>>;
impl Decl {
pub fn uwnrap_normal(&self) -> &NormalDecl {
match self {
Decl::Normal(decl) => decl,
Decl::StaticAssert => {
panic!("Expected normal declaration, found static assert declaration")
}
}
}
}
impl DirectDeclarator {
pub fn unwrap_with_params(&self) -> (&Ident, &Vec<FunctionParamDecl>) {
match self {
DirectDeclarator::Ident(_) => {
panic!("Expected declarator with parameters, found single identifier declarator1")
}
DirectDeclarator::WithParams { ident, params } => (ident, params),
}
}
}

View file

@ -5,7 +5,7 @@ use crate::{
ast::{
Decl, DeclAttr, DeclSpec, Declarator, DirectDeclarator, ExternalDecl, FunctionDef,
FunctionParamDecl, Ident, InitDecl, IntTy, IntTyKind, IntTySignedness, NormalDecl, Stmt,
TypeSpecifier, TranslationUnit,
TranslationUnit, TypeSpecifier,
},
pre::Punctuator as P,
token::{Keyword as Kw, Token as Tok},
@ -307,7 +307,7 @@ where
kind: IntTyKind::Int,
}),
Tok::Kw(Kw::Long) => {
if let Some(_) = eat!(self, Tok::Kw(Kw::Long)) {
if eat!(self, Tok::Kw(Kw::Long)).is_some() {
eat!(self, Tok::Kw(Kw::Int));
TypeSpecifier::Integer(IntTy {
sign: signedness.unwrap_or_default(),