fix ints in ast

This commit is contained in:
nora 2022-07-05 20:34:19 +02:00
parent fb1ce74e08
commit c519241bd4
5 changed files with 22 additions and 11 deletions

View file

@ -125,16 +125,22 @@ pub enum Stmt {
pub enum TypeSpecifier { pub enum TypeSpecifier {
Void, Void,
Char, Char,
SChar,
UChar,
Short, Short,
UShort,
Int, Int,
UInt,
Long, Long,
ULong,
LongLong,
ULongLong,
Float, Float,
Double, Double,
Signed, LongDouble,
Unsigned,
Bool, Bool,
Complex,
// TODO // TODO
// complex
// atomic-type-specifier // atomic-type-specifier
// struct-or-union-specifier // struct-or-union-specifier
// enum-specifier // enum-specifier

View file

@ -291,8 +291,8 @@ where
Tok::Kw(Kw::Long) => TypeSpecifier::Long, Tok::Kw(Kw::Long) => TypeSpecifier::Long,
Tok::Kw(Kw::Float) => TypeSpecifier::Float, Tok::Kw(Kw::Float) => TypeSpecifier::Float,
Tok::Kw(Kw::Double) => TypeSpecifier::Double, Tok::Kw(Kw::Double) => TypeSpecifier::Double,
Tok::Kw(Kw::Signed) => TypeSpecifier::Signed, Tok::Kw(Kw::Signed) => TypeSpecifier::Int,
Tok::Kw(Kw::Unsigned) => TypeSpecifier::Unsigned, Tok::Kw(Kw::Unsigned) => TypeSpecifier::UInt,
Tok::Kw(Kw::Bool) => TypeSpecifier::Bool, Tok::Kw(Kw::Bool) => TypeSpecifier::Bool,
Tok::Kw(Kw::Complex) => { Tok::Kw(Kw::Complex) => {
return Err(ParserError::new( return Err(ParserError::new(

View file

@ -20,7 +20,7 @@ where
fn get_lhs(&mut self) -> Result<Spanned<Expr>> { fn get_lhs(&mut self) -> Result<Spanned<Expr>> {
let (typ, span) = match self.peek_t()? { let (typ, span) = match self.peek_t()? {
&(Tok::Ident(ident), span) => (Atom::Ident(ident.to_string()), span), &(Tok::Ident(ident), span) => (Atom::Ident((ident.to_string(), span)), span),
&(Tok::StringLiteral(literal), span) => (Atom::String(literal.to_string()), span), &(Tok::StringLiteral(literal), span) => (Atom::String(literal.to_string()), span),
&(Tok::Constant(Constant::Int(int)), span) => (Atom::Int(int), span), &(Tok::Constant(Constant::Int(int)), span) => (Atom::Int(int), span),
&(Tok::Constant(Constant::Float(float)), span) => (Atom::Float(float), span), &(Tok::Constant(Constant::Float(float)), span) => (Atom::Float(float), span),

View file

@ -87,7 +87,7 @@ expression: "(parsed_pretty, pretty_printed_source)"
}, },
init: Some(( init: Some((
Binary(ExprBinary { Binary(ExprBinary {
lhs: (Atom(Ident("array")), 50..55), lhs: (Atom(Ident(("array", 50..55))), 50..55),
rhs: (Atom(Int(9)), 56..57), rhs: (Atom(Int(9)), 56..57),
op: Index, op: Index,
}), }),

View file

@ -123,15 +123,20 @@ impl<W: Write> PrettyPrinter<W> {
self.string(match spec { self.string(match spec {
TypeSpecifier::Void => "void", TypeSpecifier::Void => "void",
TypeSpecifier::Char => "char", TypeSpecifier::Char => "char",
TypeSpecifier::SChar => "signed char",
TypeSpecifier::UChar => "unsigned char",
TypeSpecifier::Short => "short", TypeSpecifier::Short => "short",
TypeSpecifier::UShort => "usigned short",
TypeSpecifier::Int => "int", TypeSpecifier::Int => "int",
TypeSpecifier::UInt => "unsugned int",
TypeSpecifier::Long => "long", TypeSpecifier::Long => "long",
TypeSpecifier::ULong => "unsigned long",
TypeSpecifier::LongLong => "long",
TypeSpecifier::ULongLong => "unsigned long long",
TypeSpecifier::Float => "float", TypeSpecifier::Float => "float",
TypeSpecifier::Double => "double", TypeSpecifier::Double => "double",
TypeSpecifier::Signed => "signed", TypeSpecifier::LongDouble => "long double",
TypeSpecifier::Unsigned => "unsigned",
TypeSpecifier::Bool => "_Bool", TypeSpecifier::Bool => "_Bool",
TypeSpecifier::Complex => "_Complex",
}) })
} }
@ -192,7 +197,7 @@ impl<W: Write> PrettyPrinter<W> {
fn expr(&mut self, expr: &Expr) -> Result { fn expr(&mut self, expr: &Expr) -> Result {
match expr { match expr {
Expr::Atom(atom) => match atom { Expr::Atom(atom) => match atom {
Atom::Ident(ident) => self.string(ident), Atom::Ident((ident, _)) => self.string(ident),
Atom::Int(int) => write!(self.output, "{}", int), Atom::Int(int) => write!(self.output, "{}", int),
Atom::Float(float) => write!(self.output, "{}", float), Atom::Float(float) => write!(self.output, "{}", float),
Atom::String(string) => { Atom::String(string) => {