Skip to content

Commit 952ea35

Browse files
Franco Victoriomattiaerre
authored andcommitted
Add assembly case blocks (#92)
* Add support for AssemblyIf * Print assembly cases blocks * Indent switch cases in assembly code
1 parent 2d6f34d commit 952ea35

3 files changed

Lines changed: 43 additions & 2 deletions

File tree

src/printer.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,14 +512,19 @@ function genericPrint(path, options, print) {
512512
return node.value;
513513
case 'AssemblySwitch':
514514
doc = join(hardline, path.map(print, 'cases'));
515-
return concat(['switch ', path.call(print, 'expression'), hardline, doc]);
515+
return concat([
516+
'switch ',
517+
path.call(print, 'expression'),
518+
indent(hardline),
519+
indent(doc)
520+
]);
516521
case 'AssemblyCase':
517522
if (node.default) {
518523
doc = concat(['default']);
519524
} else {
520525
doc = concat(['case ', path.call(print, 'value')]);
521526
}
522-
return join(' ', [doc, '{}']);
527+
return join(' ', [doc, path.call(print, 'block')]);
523528
case 'AssemblyLocalDefinition':
524529
return join(' ', [
525530
'let',

tests/Assembly/Assembly.sol

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,16 @@ contract Assembly {
77
}
88
}
99
}
10+
11+
function caseAssembly() {
12+
assembly {
13+
switch value
14+
case 0 {
15+
mstore(0, 0x0000000000000000000000000000000000000000000000000000000000000000)
16+
}
17+
case 1 {
18+
mstore(0, 0x1111111111111111111111111111111111111111111111111111111111111111)
19+
}
20+
}
21+
}
1022
}

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ contract Assembly {
1010
}
1111
}
1212
}
13+
14+
function caseAssembly() {
15+
assembly {
16+
switch value
17+
case 0 {
18+
mstore(0, 0x0000000000000000000000000000000000000000000000000000000000000000)
19+
}
20+
case 1 {
21+
mstore(0, 0x1111111111111111111111111111111111111111111111111111111111111111)
22+
}
23+
}
24+
}
1325
}
1426
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1527
contract Assembly {
@@ -20,6 +32,18 @@ contract Assembly {
2032
}
2133
}
2234
}
35+
36+
function caseAssembly() {
37+
assembly {
38+
switch value
39+
case 0 {
40+
mstore(0, 0x0000000000000000000000000000000000000000000000000000000000000000)
41+
}
42+
case 1 {
43+
mstore(0, 0x1111111111111111111111111111111111111111111111111111111111111111)
44+
}
45+
}
46+
}
2347
}
2448
2549
`;

0 commit comments

Comments
 (0)