Possibly removed the need for ensure_semicolon
This commit is contained in:
@@ -362,7 +362,6 @@ impl ClassProcessedData {
|
|||||||
if *i > 0 {
|
if *i > 0 {
|
||||||
cg.add(", ");
|
cg.add(", ");
|
||||||
}
|
}
|
||||||
ctx.expr_ensure_semicolon = false;
|
|
||||||
param.name.gen_rust(ctx, cg);
|
param.name.gen_rust(ctx, cg);
|
||||||
}
|
}
|
||||||
cg.addln(");");
|
cg.addln(");");
|
||||||
@@ -599,7 +598,6 @@ pub fn gen_method_point(method: &FunctionDecl, ctx: &mut Context, cg: &mut RustC
|
|||||||
|
|
||||||
for (_, param) in ¶ms {
|
for (_, param) in ¶ms {
|
||||||
cg.add(", ");
|
cg.add(", ");
|
||||||
ctx.expr_ensure_semicolon = false;
|
|
||||||
param.name.gen_rust(ctx, cg);
|
param.name.gen_rust(ctx, cg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -68,14 +68,6 @@ impl GenRust for Literal {
|
|||||||
|
|
||||||
impl GenRust for Expression {
|
impl GenRust for Expression {
|
||||||
fn gen_rust(&self, ctx: &mut Context, cg: &mut RustCodegen) {
|
fn gen_rust(&self, ctx: &mut Context, cg: &mut RustCodegen) {
|
||||||
let ensure_semicolon = if ctx.expr_ensure_semicolon {
|
|
||||||
ctx.expr_ensure_semicolon = false;
|
|
||||||
|
|
||||||
true
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
};
|
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
Expression::Path(path) => cg.add(&path.get_rust_ctx(ctx)),
|
Expression::Path(path) => cg.add(&path.get_rust_ctx(ctx)),
|
||||||
Expression::Literal(literal) => literal.gen_rust(ctx, cg),
|
Expression::Literal(literal) => literal.gen_rust(ctx, cg),
|
||||||
@@ -152,14 +144,6 @@ impl GenRust for Expression {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ensure_semicolon {
|
|
||||||
ctx.expr_ensure_semicolon = true;
|
|
||||||
|
|
||||||
if !self.is_block() {
|
|
||||||
cg.add(";");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,13 +4,6 @@ use crate::fmt::{Context, GenMist, GetMist, MistCodegen};
|
|||||||
|
|
||||||
impl GenMist for Expression {
|
impl GenMist for Expression {
|
||||||
fn gen_mist(&self, ctx: &mut Context, cg: &mut MistCodegen) {
|
fn gen_mist(&self, ctx: &mut Context, cg: &mut MistCodegen) {
|
||||||
let ensure_semicolon = if ctx.expr_ensure_semicolon {
|
|
||||||
ctx.expr_ensure_semicolon = false;
|
|
||||||
true
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
};
|
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
Expression::Path(path) => cg.add(&path.get_mist()),
|
Expression::Path(path) => cg.add(&path.get_mist()),
|
||||||
Expression::Literal(literal) => literal.gen_mist(ctx, cg),
|
Expression::Literal(literal) => literal.gen_mist(ctx, cg),
|
||||||
@@ -75,13 +68,6 @@ impl GenMist for Expression {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ensure_semicolon {
|
|
||||||
ctx.expr_ensure_semicolon = true;
|
|
||||||
if !self.is_block() {
|
|
||||||
cg.add(";");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ use mist_parser::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub struct Context {
|
pub struct Context {
|
||||||
pub expr_ensure_semicolon: bool,
|
|
||||||
pub expr_super: Option<ExprPath>,
|
pub expr_super: Option<ExprPath>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,7 +80,6 @@ impl RustCodegen {
|
|||||||
|
|
||||||
pub fn generate(&mut self, toplevels: Vec<TopLevel>) -> String {
|
pub fn generate(&mut self, toplevels: Vec<TopLevel>) -> String {
|
||||||
let mut ctx = Context {
|
let mut ctx = Context {
|
||||||
expr_ensure_semicolon: true,
|
|
||||||
expr_super: None,
|
expr_super: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -10,14 +10,15 @@ impl GenRust for Block {
|
|||||||
cg.indent += 1;
|
cg.indent += 1;
|
||||||
|
|
||||||
for stmt in &self.statements {
|
for stmt in &self.statements {
|
||||||
ctx.expr_ensure_semicolon = true;
|
|
||||||
cg.add_indented("");
|
cg.add_indented("");
|
||||||
stmt.gen_rust(ctx, cg);
|
stmt.gen_rust(ctx, cg);
|
||||||
|
if stmt.item.is_semicolon_required() {
|
||||||
|
cg.add(";");
|
||||||
|
}
|
||||||
cg.addln("");
|
cg.addln("");
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(soft_return) = &self.soft_return {
|
if let Some(soft_return) = &self.soft_return {
|
||||||
ctx.expr_ensure_semicolon = false;
|
|
||||||
cg.add_indented("");
|
cg.add_indented("");
|
||||||
soft_return.gen_rust(ctx, cg);
|
soft_return.gen_rust(ctx, cg);
|
||||||
cg.addln("");
|
cg.addln("");
|
||||||
@@ -86,14 +87,12 @@ impl GenRust for Statement {
|
|||||||
else_branch,
|
else_branch,
|
||||||
} => {
|
} => {
|
||||||
cg.add("if ");
|
cg.add("if ");
|
||||||
ctx.expr_ensure_semicolon = false;
|
|
||||||
initial.condition.gen_rust(ctx, cg);
|
initial.condition.gen_rust(ctx, cg);
|
||||||
cg.add(" ");
|
cg.add(" ");
|
||||||
initial.body.gen_rust(ctx, cg);
|
initial.body.gen_rust(ctx, cg);
|
||||||
|
|
||||||
for else_if_branch in else_if {
|
for else_if_branch in else_if {
|
||||||
cg.add(" else if ");
|
cg.add(" else if ");
|
||||||
ctx.expr_ensure_semicolon = false;
|
|
||||||
else_if_branch.condition.gen_rust(ctx, cg);
|
else_if_branch.condition.gen_rust(ctx, cg);
|
||||||
cg.add(" ");
|
cg.add(" ");
|
||||||
else_if_branch.body.gen_rust(ctx, cg);
|
else_if_branch.body.gen_rust(ctx, cg);
|
||||||
@@ -126,17 +125,18 @@ impl GenRust for Statement {
|
|||||||
cg.addln("{");
|
cg.addln("{");
|
||||||
cg.indent += 1;
|
cg.indent += 1;
|
||||||
|
|
||||||
ctx.expr_ensure_semicolon = true;
|
|
||||||
|
|
||||||
cg.add_indented("");
|
cg.add_indented("");
|
||||||
|
|
||||||
init.gen_rust(ctx, cg);
|
init.gen_rust(ctx, cg);
|
||||||
|
|
||||||
|
if init.is_semicolon_required() {
|
||||||
|
cg.add(";");
|
||||||
|
}
|
||||||
|
|
||||||
cg.addln("");
|
cg.addln("");
|
||||||
|
|
||||||
cg.add_indented("while ");
|
cg.add_indented("while ");
|
||||||
|
|
||||||
ctx.expr_ensure_semicolon = false;
|
|
||||||
condition.gen_rust(ctx, cg);
|
condition.gen_rust(ctx, cg);
|
||||||
|
|
||||||
cg.add(" ");
|
cg.add(" ");
|
||||||
@@ -144,12 +144,14 @@ impl GenRust for Statement {
|
|||||||
cg.add("{");
|
cg.add("{");
|
||||||
cg.indent += 1;
|
cg.indent += 1;
|
||||||
|
|
||||||
ctx.expr_ensure_semicolon = true;
|
|
||||||
|
|
||||||
body.gen_rust(ctx, cg);
|
body.gen_rust(ctx, cg);
|
||||||
|
|
||||||
update.gen_rust(ctx, cg);
|
update.gen_rust(ctx, cg);
|
||||||
|
|
||||||
|
if update.is_semicolon_required() {
|
||||||
|
cg.add(";");
|
||||||
|
}
|
||||||
|
|
||||||
cg.addln("");
|
cg.addln("");
|
||||||
|
|
||||||
cg.indent -= 1;
|
cg.indent -= 1;
|
||||||
|
|||||||
@@ -96,16 +96,6 @@ pub enum Generic {
|
|||||||
Type(TypeExpr),
|
Type(TypeExpr),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Expression {
|
|
||||||
pub fn is_block(&self) -> bool {
|
|
||||||
if let Expression::Statement(stmt) = self {
|
|
||||||
stmt.is_block()
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<Path> for ExprPath {
|
impl From<Path> for ExprPath {
|
||||||
fn from(path: Path) -> Self {
|
fn from(path: Path) -> Self {
|
||||||
Self(
|
Self(
|
||||||
@@ -125,9 +115,17 @@ impl Expression {
|
|||||||
match self {
|
match self {
|
||||||
Self::Statement(v) => match &**v {
|
Self::Statement(v) => match &**v {
|
||||||
Statement::TopLevel(_) => false,
|
Statement::TopLevel(_) => false,
|
||||||
_ => true,
|
stmt => !stmt.is_block(),
|
||||||
},
|
},
|
||||||
_ => true,
|
_ => true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_block(&self) -> bool {
|
||||||
|
if let Expression::Statement(stmt) = self {
|
||||||
|
stmt.is_block()
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user