Skip to content

Commit

Permalink
sema: rename L field as Left and R field as Right of Assign
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Aug 29, 2024
1 parent 8375a1a commit 2ee8bdf
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 35 deletions.
4 changes: 2 additions & 2 deletions src/julec/obj/cxx/scope.jule
Original file line number Diff line number Diff line change
Expand Up @@ -466,9 +466,9 @@ impl scopeCoder {
}

fn assign(mut &self, mut a: &Assign) {
self.oc.ec.possibleRefExpr(a.L.Model)
self.oc.ec.possibleRefExpr(a.Left.Model)
self.oc.write(a.Op.Kind)
self.oc.ec.possibleRefExpr(a.R.Model)
self.oc.ec.possibleRefExpr(a.Right.Model)
}

fn mapLookupAssign(mut &self, mut &a: &MultiAssign) {
Expand Down
4 changes: 2 additions & 2 deletions src/julec/opt/deadcode/scope.jule
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ impl scopeDeadCode {
}

fn optimizeAssign(mut &self, mut assign: &Assign) {
self.optimizeExprModel(assign.L.Model)
self.optimizeExprModel(assign.R.Model)
self.optimizeExprModel(assign.Left.Model)
self.optimizeExprModel(assign.Right.Model)
}

fn optimizeMultiAssign(mut &self, mut assign: &MultiAssign) {
Expand Down
54 changes: 27 additions & 27 deletions src/julec/opt/scope.jule
Original file line number Diff line number Diff line change
Expand Up @@ -375,10 +375,10 @@ impl scopeOptimizer {
if a.Op.Id != TokenId.Eq {
ret false
}
match type a.R.Model {
match type a.Right.Model {
| &SlicingExprModel:
mut sem := (&SlicingExprModel)(a.R.Model)
if equalModels(a.L.Model, sem.Expr) {
mut sem := (&SlicingExprModel)(a.Right.Model)
if equalModels(a.Left.Model, sem.Expr) {
self.setCurrentStmt(&MutSlicingExprModel{
Token: sem.Token,
Expr: sem.Expr,
Expand All @@ -395,15 +395,15 @@ impl scopeOptimizer {
if !Str {
ret false
}
lp := a.L.Kind.Prim()
lp := a.Left.Kind.Prim()
if lp == nil || !lp.IsStr() {
ret false
}
ret self.substr(a)
}

fn sliceAssign(mut &self, mut a: &sema::Assign): bool {
if !Slice || a.L.Kind.Slc() == nil {
if !Slice || a.Left.Kind.Slc() == nil {
ret false
}
// [self.substr] applies this optimization without type dependence.
Expand All @@ -419,36 +419,36 @@ impl scopeOptimizer {

fn optimizeAssign(mut &self, mut assign: &sema::Assign) {
if assign.Op.Id == TokenId.Eq &&
equalModels(assign.L.Model, assign.R.Model) {
equalModels(assign.Left.Model, assign.Right.Model) {
self.removeCurrent()
self.i-- // In next iteration, point to correct statement.
ret
}

if self.data.boundary != nil {
if isBoundaryRiskyType(assign.L.Kind) {
possibleBoundaryRemove(self.data.boundary, assign.L.Model)
if isBoundaryRiskyType(assign.Left.Kind) {
possibleBoundaryRemove(self.data.boundary, assign.Left.Model)
}
}
if self.data.nils != nil {
if isGuaranteedNonNilExpr(self.data.nils, assign.R.Model) {
if isNilValidType(assign.L.Kind) {
if isGuaranteedNonNilExpr(self.data.nils, assign.Right.Model) {
if isNilValidType(assign.Left.Kind) {
const safe = true
self.data.nils.pushVar(getNilVar(assign.L.Model), safe)
self.data.nils.pushVar(getNilVar(assign.Left.Model), safe)
}
} else {
possibleNilRemove(self.data.nils, assign.L.Model)
possibleNilRemove(self.data.nils, assign.Left.Model)
}
}
if self.data.dynamic != nil {
mut kind := isTypeGuaranteedDynamicData(
self.data.dynamic, assign.R.Kind, assign.R.Model)
self.data.dynamic, assign.Right.Kind, assign.Right.Model)
if kind != nil {
if isDynamicValidType(assign.L.Kind) {
self.data.dynamic.pushVar(getDynamicVar(assign.L.Model), kind)
if isDynamicValidType(assign.Left.Kind) {
self.data.dynamic.pushVar(getDynamicVar(assign.Left.Model), kind)
}
} else {
possibleDynamicRemove(self.data.dynamic, assign.L.Model)
possibleDynamicRemove(self.data.dynamic, assign.Left.Model)
}
}

Expand All @@ -458,13 +458,13 @@ impl scopeOptimizer {
ret
}

exprOptimizer.optimizeData(assign.L.Model, self.data)
exprOptimizer.optimizeData(assign.R.Model, self.data)
exprOptimizer.optimizeData(assign.Left.Model, self.data)
exprOptimizer.optimizeData(assign.Right.Model, self.data)

match assign.Op.Id {
| TokenId.SolidusEq | TokenId.PercentEq:
// Do not check division of structures safety.
if !Math || assign.L.Kind.Struct() != nil {
if !Math || assign.Left.Kind.Struct() != nil {
break
}
oldId, oldKind := assign.Op.Id, assign.Op.Kind
Expand All @@ -480,16 +480,16 @@ impl scopeOptimizer {
}
mut model := ExprModel(&BinaryExprModel{
Op: assign.Op,
Left: assign.L,
Right: assign.R,
Left: assign.Left,
Right: assign.Right,
})
exprOptimizer.optimizeData(model, self.data)
match type model {
| &BinaryExprModel:
assign.R = new(OperandExprModel, *assign.R)
assign.Right = new(OperandExprModel, *assign.Right)
assign.Op.Id = TokenId.Eq
assign.Op.Kind = TokenKind.Eq
assign.R.Model = model
assign.Right.Model = model
ret
}
assign.Op.Id = oldId
Expand All @@ -498,10 +498,10 @@ impl scopeOptimizer {
}

if Append {
match type assign.R.Model {
match type assign.Right.Model {
| &BuiltinAppendCallExprModel:
mut m := (&BuiltinAppendCallExprModel)(assign.R.Model)
if !areSameLvalueExprModel(assign.L.Model, m.Dest) {
mut m := (&BuiltinAppendCallExprModel)(assign.Right.Model)
if !areSameLvalueExprModel(assign.Left.Model, m.Dest) {
ret
}
match type m.Elements {
Expand All @@ -514,7 +514,7 @@ impl scopeOptimizer {
|:
// Append directly if appended to slice and assigned to the same memory.
self.setCurrentStmt(&AppendToSliceExprModel{
Dest: assign.L.Model,
Dest: assign.Left.Model,
Slice: m.Elements,
})
}
Expand Down
8 changes: 4 additions & 4 deletions std/jule/sema/scope.jule
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,9 @@ struct Postfix {

// Assigment.
struct Assign {
L: &OperandExprModel
R: &OperandExprModel
Op: &Token
Left: &OperandExprModel
Right: &OperandExprModel
Op: &Token
}

// Multi-declarative assignment.
Expand Down Expand Up @@ -1363,7 +1363,7 @@ impl scopeChecker {
Kind: r.Kind,
Model: r.Model,
}
self.scope.Stmts = append(self.scope.Stmts, &Assign{L: lm, R: rm, Op: a.Setter})
self.scope.Stmts = append(self.scope.Stmts, &Assign{Left: lm, Right: rm, Op: a.Setter})

if a.Setter.Id == TokenId.Eq {
mut checker := assignTypeChecker{
Expand Down

0 comments on commit 2ee8bdf

Please sign in to comment.