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 {
Void,
Char,
SChar,
UChar,
Short,
UShort,
Int,
UInt,
Long,
ULong,
LongLong,
ULongLong,
Float,
Double,
Signed,
Unsigned,
LongDouble,
Bool,
Complex,
// TODO
// complex
// atomic-type-specifier
// struct-or-union-specifier
// enum-specifier

View file

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

View file

@ -20,7 +20,7 @@ where
fn get_lhs(&mut self) -> Result<Spanned<Expr>> {
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::Constant(Constant::Int(int)), span) => (Atom::Int(int), 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((
Binary(ExprBinary {
lhs: (Atom(Ident("array")), 50..55),
lhs: (Atom(Ident(("array", 50..55))), 50..55),
rhs: (Atom(Int(9)), 56..57),
op: Index,
}),

View file

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