Skip to content

Commit 1f7caa4

Browse files
fvictorioJanther
andauthored
Upgrade parser and fix several issues (#750)
* Support address as member * Add support for boolean literals in assembly * Add test for multiple assembly assignment * Add support for AssemblyStackAssignment node * cleaning printer Co-authored-by: Klaus Hott <klahott@gmail.com>
1 parent 5af6a55 commit 1f7caa4

File tree

9 files changed

+126
-7
lines changed

9 files changed

+126
-7
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
"solc": "^0.8.17"
8484
},
8585
"dependencies": {
86-
"@solidity-parser/parser": "^0.14.3",
86+
"@solidity-parser/parser": "^0.14.5",
8787
"emoji-regex": "^10.1.0",
8888
"escape-string-regexp": "^4.0.0",
8989
"semver": "^7.3.7",

src/binary-operator-printers/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* This file was automatically generated on 1657595765.198 */
1+
/* This file was automatically generated on 1666691919.933 */
22

33
/* eslint-disable global-require */
44

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const AssemblyAssignment = {
2+
print: ({ node, path, print }) => [
3+
path.call(print, 'expression'),
4+
' =: ',
5+
node.name
6+
]
7+
};
8+
9+
module.exports = AssemblyAssignment;

src/nodes/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* This file was automatically generated on 1657595765.093 */
1+
/* This file was automatically generated on 1666691919.885 */
22

33
/* eslint-disable global-require */
44

@@ -13,6 +13,7 @@ module.exports = {
1313
AssemblyIf: require('./AssemblyIf'),
1414
AssemblyLocalDefinition: require('./AssemblyLocalDefinition'),
1515
AssemblyMemberAccess: require('./AssemblyMemberAccess'),
16+
AssemblyStackAssignment: require('./AssemblyStackAssignment'),
1617
AssemblySwitch: require('./AssemblySwitch'),
1718
BinaryOperation: require('./BinaryOperation'),
1819
Block: require('./Block'),

tests/format/Assembly/Assembly.sol

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,34 @@ for { let i := 0 } lt(i, x) { i := add(i, 1) } {
201201
}
202202
}
203203
}
204+
205+
contract BooleanLiteralsInAssembly {
206+
function f() {
207+
uint a;
208+
assembly {
209+
a := true
210+
a := false
211+
}
212+
}
213+
}
214+
215+
contract MultipleAssemblyAssignement {
216+
function foo() public pure {
217+
assembly {
218+
function bar() -> a, b {
219+
a := 1
220+
b := 2
221+
}
222+
223+
let i, j := bar()
224+
}
225+
}
226+
}
227+
228+
contract AssemblyStackAssignment {
229+
function f() public {
230+
assembly {
231+
4 =: y
232+
}
233+
}
234+
}

tests/format/Assembly/__snapshots__/jsfmt.spec.js.snap

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,37 @@ for { let i := 0 } lt(i, x) { i := add(i, 1) } {
210210
}
211211
}
212212
213+
contract BooleanLiteralsInAssembly {
214+
function f() {
215+
uint a;
216+
assembly {
217+
a := true
218+
a := false
219+
}
220+
}
221+
}
222+
223+
contract MultipleAssemblyAssignement {
224+
function foo() public pure {
225+
assembly {
226+
function bar() -> a, b {
227+
a := 1
228+
b := 2
229+
}
230+
231+
let i, j := bar()
232+
}
233+
}
234+
}
235+
236+
contract AssemblyStackAssignment {
237+
function f() public {
238+
assembly {
239+
4 =: y
240+
}
241+
}
242+
}
243+
213244
=====================================output=====================================
214245
contract Assembly {
215246
function ifAssembly() {
@@ -454,5 +485,36 @@ contract Assembly {
454485
}
455486
}
456487
488+
contract BooleanLiteralsInAssembly {
489+
function f() {
490+
uint a;
491+
assembly {
492+
a := true
493+
a := false
494+
}
495+
}
496+
}
497+
498+
contract MultipleAssemblyAssignement {
499+
function foo() public pure {
500+
assembly {
501+
function bar() -> a, b {
502+
a := 1
503+
b := 2
504+
}
505+
506+
let i, j := bar()
507+
}
508+
}
509+
}
510+
511+
contract AssemblyStackAssignment {
512+
function f() public {
513+
assembly {
514+
4 =: y
515+
}
516+
}
517+
}
518+
457519
================================================================================
458520
`;

tests/format/MemberAccess/MemberAccess.sol

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ contract MemberAccess {
5757
path,
5858
address(this, aoeu, aoeueu, aoeu)
5959
);
60+
vm.mockCall(
61+
f.address,
62+
abi.encodeWithSelector(f.selector),
63+
abi.encode(returned1)
64+
);
6065
}
6166
}
6267

@@ -99,4 +104,4 @@ contract MemberAccessIsEndOfChainCases {
99104
// break if is an ReturnStatement
100105
return b.c;
101106
}
102-
}
107+
}

tests/format/MemberAccess/__snapshots__/jsfmt.spec.js.snap

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ contract MemberAccess {
6565
path,
6666
address(this, aoeu, aoeueu, aoeu)
6767
);
68+
vm.mockCall(
69+
f.address,
70+
abi.encodeWithSelector(f.selector),
71+
abi.encode(returned1)
72+
);
6873
}
6974
}
7075
@@ -108,6 +113,7 @@ contract MemberAccessIsEndOfChainCases {
108113
return b.c;
109114
}
110115
}
116+
111117
=====================================output=====================================
112118
pragma solidity ^0.5.0;
113119
@@ -195,6 +201,11 @@ contract MemberAccess {
195201
path,
196202
address(this, aoeu, aoeueu, aoeu)
197203
);
204+
vm.mockCall(
205+
f.address,
206+
abi.encodeWithSelector(f.selector),
207+
abi.encode(returned1)
208+
);
198209
}
199210
}
200211

0 commit comments

Comments
 (0)