From 24d61a716cc99015a6b699d760528c9d50afeee6 Mon Sep 17 00:00:00 2001 From: playXE Date: Fri, 24 May 2019 23:36:26 +0300 Subject: [PATCH] fmt --- src/eval.rs | 29 ++++++++++++++++++---------- src/gccjit.rs | 6 +----- src/semantic.rs | 7 +++---- src/syntax/ast/display.rs | 40 ++++++++++++++++++++++----------------- src/syntax/ast/mod.rs | 2 +- src/syntax/lexer/mod.rs | 3 ++- src/syntax/parser.rs | 5 ++--- 7 files changed, 51 insertions(+), 41 deletions(-) diff --git a/src/eval.rs b/src/eval.rs index 27a68e9..0179b5a 100644 --- a/src/eval.rs +++ b/src/eval.rs @@ -877,21 +877,30 @@ impl<'a> EvalCtx<'a> } else { - match &stmt.kind { - StmtKind::CompTime(s) => return self.eval_stmt(s,true), - StmtKind::Block(b) => { - for s in b.iter() {self.eval_stmt(s,false);} - return Some(rc(Const::Void)) + match &stmt.kind + { + StmtKind::CompTime(s) => return self.eval_stmt(s, true), + StmtKind::Block(b) => + { + for s in b.iter() + { + self.eval_stmt(s, false); + } + return Some(rc(Const::Void)); } - StmtKind::Expr(e) => { - if let ExprKind::CompTime(s) = &e.kind { return Some(self.expr(s,true))} - else { + StmtKind::Expr(e) => + { + if let ExprKind::CompTime(s) = &e.kind + { + return Some(self.expr(s, true)); + } + else + { return None; } } - _ => None + _ => None, } - } } diff --git a/src/gccjit.rs b/src/gccjit.rs index 0b5c281..85bd9f7 100644 --- a/src/gccjit.rs +++ b/src/gccjit.rs @@ -276,7 +276,6 @@ impl<'a> Codegen<'a> } let ty = if struct_.union { - self.ctx .new_union_type(None, &str(struct_.name).to_string(), &fields) } @@ -1376,7 +1375,6 @@ impl<'a> Codegen<'a> if this.is_some() { - let expr = this.clone().unwrap().clone(); let ty = self.get_id_type(expr.id); let val = if !ty.is_ptr() @@ -1387,7 +1385,7 @@ impl<'a> Codegen<'a> id: expr.id, kind: ExprKind::AddressOf(expr), }); - let val = self.ctx.new_cast(None,val,cty); + let val = self.ctx.new_cast(None, val, cty); val } else @@ -1461,12 +1459,10 @@ impl<'a> Codegen<'a> ¶ms, ); } - else if let Some(var) = self.variables.get(&name.name()) { var.lval } - else { panic!(); diff --git a/src/semantic.rs b/src/semantic.rs index 5bcc334..e5598da 100644 --- a/src/semantic.rs +++ b/src/semantic.rs @@ -682,7 +682,6 @@ impl<'a> SemCheck<'a> { let _id = stmt.id; match &stmt.kind - { StmtKind::CFor(var, cond, then, body) => { @@ -838,13 +837,13 @@ impl<'a> SemCheck<'a> { match &expr.kind { - ExprKind::CompTime(e) => { + ExprKind::CompTime(e) => + { let ty = self.tc_expr(e); let ty = self.infer_type(&ty); - self.types.insert(expr.id,ty.clone()); + self.types.insert(expr.id, ty.clone()); return ty; - } ExprKind::New(ty) => { diff --git a/src/syntax/ast/display.rs b/src/syntax/ast/display.rs index 0024a34..182bd88 100644 --- a/src/syntax/ast/display.rs +++ b/src/syntax/ast/display.rs @@ -16,7 +16,7 @@ impl Display for ExprKind { match self { - ExprKind::MacroCall(name,_) => write!(f,"{}!()",name), + ExprKind::MacroCall(name, _) => write!(f, "{}!()", name), ExprKind::CompTime(e) => write!(f, "constexpr {}", e), ExprKind::New(val) => write!(f, "new {}", val), ExprKind::Int(i, base, _) => match base @@ -216,25 +216,31 @@ impl Display for Global } } -impl Display for Macro { - fn fmt(&self,f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f,"macro {}!(",self.name)?; - for (i,var) in self.args.iter().enumerate() { - write!(f,"{}",var)?; - if i != self.args.len() - 1 { - write!(f,",")?; +impl Display for Macro +{ + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result + { + write!(f, "macro {}!(", self.name)?; + for (i, var) in self.args.iter().enumerate() + { + write!(f, "{}", var)?; + if i != self.args.len() - 1 + { + write!(f, ",")?; } } - write!(f,") ")?; - write!(f,"{{\n")?; - for tok in self.body.iter() { - match tok { - MacroToken::Token(tok) => write!(f," {}",tok.name())?, - MacroToken::Var(var) => write!(f," ${}",var)?, - MacroToken::VarArgs => write!(f,"...")?, + write!(f, ") ")?; + write!(f, "{{\n")?; + for tok in self.body.iter() + { + match tok + { + MacroToken::Token(tok) => write!(f, " {}", tok.name())?, + MacroToken::Var(var) => write!(f, " ${}", var)?, + MacroToken::VarArgs => write!(f, "...")?, } } - write!(f,"\n}}") + write!(f, "\n}}") } } @@ -251,7 +257,7 @@ impl Display for Elem Elem::ConstExpr { name, expr, .. } => write!(f, "constexpr {} = {}", name, expr), Elem::Global(g) => write!(f, "{}", g), Elem::Link(l) => write!(f, "link \"{}\" ", l), - Elem::Macro(m) => write!(f,"{}",m), + Elem::Macro(m) => write!(f, "{}", m), _ => write!(f, ""), } } diff --git a/src/syntax/ast/mod.rs b/src/syntax/ast/mod.rs index 434058a..061ddf4 100644 --- a/src/syntax/ast/mod.rs +++ b/src/syntax/ast/mod.rs @@ -843,7 +843,7 @@ impl Expr #[derive(Clone, Debug)] pub enum ExprKind { - MacroCall(Name,Vec>), + MacroCall(Name, Vec>), CompTime(Box), Unary(String, Box), Binary(String, Box, Box), diff --git a/src/syntax/lexer/mod.rs b/src/syntax/lexer/mod.rs index fb2589b..4ab7c35 100644 --- a/src/syntax/lexer/mod.rs +++ b/src/syntax/lexer/mod.rs @@ -65,7 +65,8 @@ impl Lexer { return self.read_identifier(); } - else if ch == Some('$') { + else if ch == Some('$') + { self.read_char(); return Ok(self.build_token(TokenKind::Dollar)); } diff --git a/src/syntax/parser.rs b/src/syntax/parser.rs index 2282bbc..ffe95b4 100644 --- a/src/syntax/parser.rs +++ b/src/syntax/parser.rs @@ -945,7 +945,6 @@ impl<'a> Parser<'a> TokenKind::LBracket => gen_t_tree!(TokenKind::LBracket, TokenKind::RBracket, t), TokenKind::Dollar => { - let name = self.expect_identifier()?; if args.contains(&name) { @@ -990,8 +989,8 @@ impl<'a> Parser<'a> let mut body: Vec = vec![]; loop { - - if self.token.is(TokenKind::RBrace) { + if self.token.is(TokenKind::RBrace) + { self.advance_token()?; break; }