diff --git a/src/julec/obj/cxx/expr.jule b/src/julec/obj/cxx/expr.jule index 2618d052d..16b07f1d3 100644 --- a/src/julec/obj/cxx/expr.jule +++ b/src/julec/obj/cxx/expr.jule @@ -11,6 +11,7 @@ use opt::{ AppendToSliceExprModel, InlineStdInternalNosafeStobs, StrCompExprModel, + EmptyCompareExprModel, } use conv for std::conv use std::env::{Arch} @@ -98,6 +99,7 @@ enum compExprModel: type { &InlineStdInternalNosafeStobs, &StrCompExprModel, &RefExprModel, + &EmptyCompareExprModel, } struct exprCoder { @@ -1328,6 +1330,15 @@ impl exprCoder { self.oc.write(".fake_slice()") } + fn emptyCompare(mut &self, mut m: &EmptyCompareExprModel) { + if m.Neg { + self.oc.write("!") + } + self.oc.write("(") + self.possibleRefExpr(m.Expr) + self.oc.write(").empty()") + } + fn model(mut &self, mut m: compExprModel) { match type m { | str: @@ -1426,6 +1437,8 @@ impl exprCoder { self.inlineStdInternalNosafeStobs((&InlineStdInternalNosafeStobs)(m)) | &RefExprModel: self.var((&RefExprModel)(m).Var) + | &EmptyCompareExprModel: + self.emptyCompare((&EmptyCompareExprModel)(m)) |: self.oc.write("") } diff --git a/src/julec/opt/expr.jule b/src/julec/opt/expr.jule index 5dbde82ea..d9b563bfd 100644 --- a/src/julec/opt/expr.jule +++ b/src/julec/opt/expr.jule @@ -89,11 +89,11 @@ impl exprOptimizer { match m.Op.Id { | TokenId.Eqs: if c.ReadStr() == "" { - *self.model = &CommonSubIdentExprModel{ - ExprKind: m.Left.Kind, + let mut model = any(&EmptyCompareExprModel{ Expr: m.Left.Model, - Ident: "empty()", - } + Neg: false, + }) + *self.model = unsafe { *(*ExprModel)(&model) } break } let mut model = any(&StrCompExprModel{ @@ -104,19 +104,11 @@ impl exprOptimizer { *self.model = unsafe { *(*ExprModel)(&model) } | TokenId.NotEq: if c.ReadStr() == "" { - let mut op = m.Op - op.Id = TokenId.Excl - op.Kind = TokenKind.Excl - *self.model = &UnaryExprModel{ - Op: op, - Expr: &Data{ - Model: &CommonSubIdentExprModel{ - ExprKind: m.Left.Kind, - Expr: m.Left.Model, - Ident: "empty()", - }, - }, - } + let mut model = any(&EmptyCompareExprModel{ + Expr: m.Left.Model, + Neg: true, + }) + *self.model = unsafe { *(*ExprModel)(&model) } break } let mut model = any(&StrCompExprModel{ diff --git a/src/julec/opt/model.jule b/src/julec/opt/model.jule index bfed43acb..ec4997bd0 100644 --- a/src/julec/opt/model.jule +++ b/src/julec/opt/model.jule @@ -6,6 +6,7 @@ use std::jule::lex::{Token} use std::jule::constant::{Const} use std::jule::sema::{ Var, + TypeKind, ExprModel, BinopExprModel, IndexingExprModel, @@ -13,6 +14,11 @@ use std::jule::sema::{ SliceExprModel, } +struct EmptyCompareExprModel { + Expr: ExprModel + Neg: bool +} + struct RefExprModel { Var: &Var }