This commit is contained in:
nora 2023-05-23 21:16:49 +02:00
parent 54226ad499
commit 05c617f6de
8 changed files with 150 additions and 72 deletions

View file

@ -145,12 +145,12 @@ pub enum Stmt {
//
#[derive(Debug, DebugPls, Clone, Copy, PartialEq, Eq, Hash)]
pub enum IntTySignedness {
pub enum IntSign {
Signed,
Unsigned,
}
impl Default for IntTySignedness {
impl Default for IntSign {
fn default() -> Self {
// C defaults to unsigned for integers.
Self::Signed
@ -170,7 +170,7 @@ pub enum IntTyKind {
#[derive(Debug, DebugPls, Clone, Copy, PartialEq, Eq, Hash)]
pub struct IntTy {
pub sign: IntTySignedness,
pub sign: IntSign,
pub kind: IntTyKind,
}
@ -295,7 +295,7 @@ impl DirectDeclarator {
}
}
impl IntTySignedness {
impl IntSign {
pub fn signed(self) -> bool {
matches!(self, Self::Signed)
}

View file

@ -4,7 +4,7 @@ use peekmore::PeekMoreIterator;
use crate::{
ast::{
Decl, DeclAttr, DeclSpec, Declarator, DirectDeclarator, ExternalDecl, FunctionDef,
FunctionParamDecl, Ident, InitDecl, IntTy, IntTyKind, IntTySignedness, NormalDecl, Stmt,
FunctionParamDecl, Ident, InitDecl, IntTy, IntTyKind, IntSign, NormalDecl, Stmt,
TranslationUnit, TypeSpecifier,
},
pre::Punctuator as P,
@ -335,11 +335,11 @@ where
self.peek_t()
{
// the signed is an integer qualifier
signedness = Some(IntTySignedness::Signed);
signedness = Some(IntSign::Signed);
continue;
}
TypeSpecifier::Integer(IntTy {
sign: IntTySignedness::Signed,
sign: IntSign::Signed,
kind: IntTyKind::Int,
})
}
@ -354,18 +354,18 @@ where
self.peek_t()
{
// the unsigned is an integer qualifier
signedness = Some(IntTySignedness::Unsigned);
signedness = Some(IntSign::Unsigned);
continue;
}
TypeSpecifier::Integer(IntTy {
sign: IntTySignedness::Unsigned,
sign: IntSign::Unsigned,
kind: IntTyKind::Int,
})
}
Tok::Kw(Kw::Float) => TypeSpecifier::Float,
Tok::Kw(Kw::Double) => TypeSpecifier::Double,
Tok::Kw(Kw::Bool) => TypeSpecifier::Integer(IntTy {
sign: IntTySignedness::Unsigned,
sign: IntSign::Unsigned,
kind: IntTyKind::Bool,
}),
Tok::Kw(Kw::Complex) => {

View file

@ -6,7 +6,7 @@ use crate::{
ast::{
ArithOpKind, Atom, BinaryOp, ComparisonKind, Decl, DeclAttr, DeclSpec, Declarator,
DirectDeclarator, Expr, ExprBinary, ExprPostfix, ExprUnary, ExternalDecl, FunctionDef,
FunctionParamDecl, InitDecl, IntTyKind, IntTySignedness, NormalDecl, PostfixOp, Stmt,
FunctionParamDecl, InitDecl, IntTyKind, IntSign, NormalDecl, PostfixOp, Stmt,
TypeSpecifier, UnaryOp,
},
sym::Symbol,
@ -233,7 +233,7 @@ impl<W: Write> PrettyPrinter<W> {
TypeSpecifier::Char => self.string("char"),
TypeSpecifier::Integer(int) => {
// prefix the unsignedness if desired
if let IntTySignedness::Unsigned = int.sign {
if let IntSign::Unsigned = int.sign {
self.string("unsigned ")?;
}