madfish-solutions / sol2ligo

⌨️ 🔮 Transpiler from Solidity to PascalLIGO language
https://madfish-solutions.github.io/sol2ligo/
MIT License
70 stars 4 forks source link

++ should be processed as operation that modifies storage #298

Closed vird closed 4 years ago

vird commented 4 years ago

Input:

pragma solidity ^0.4.18;

contract Thing {
  uint private quality;
  address public owner;

  function changeOwner(address newOwner) public {
     owner = newOwner;
  }
  function makeBetter() public {
     quality++;   
  }
  function makeWorse() public{
     quality--;   
  }
}

Current output:

type changeOwner_args is record
  newOwner : address;
end;

type makeBetter_args is unit;
type makeWorse_args is unit;
type state is record
  quality : nat;
  owner : address;
end;

type router_enum is
  | ChangeOwner of changeOwner_args
 | MakeBetter of makeBetter_args
 | MakeWorse of makeWorse_args;

function changeOwner (const self : state; const newOwner : address) : (state) is
  block {
    self.owner := newOwner;
  } with (self);

function makeBetter (const self : state) : (unit) is
  block {
    self.quality := self.quality + 1n;
  } with (unit);

function makeWorse (const self : state) : (unit) is
  block {
    self.quality := abs(self.quality - 1n);
  } with (unit);

function main (const action : router_enum; const self : state) : (list(operation) * state) is
  (case action of
  | ChangeOwner(match_action) -> ((nil: list(operation)), changeOwner(self, match_action.newOwner))
  | MakeBetter(match_action) -> block {
    (* This function does nothing, but it's present in router *)
    const tmp : unit = makeBetter(self);
  } with (((nil: list(operation)), self))
  | MakeWorse(match_action) -> block {
    (* This function does nothing, but it's present in router *)
    const tmp : unit = makeWorse(self);
  } with (((nil: list(operation)), self))
  end);

Problems with output: