-
Notifications
You must be signed in to change notification settings - Fork 979
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
133 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
""" | ||
EventTopLevel module | ||
""" | ||
from typing import TYPE_CHECKING, Dict | ||
|
||
from slither.core.declarations.event_top_level import EventTopLevel | ||
from slither.core.variables.event_variable import EventVariable | ||
from slither.core.compilation_unit import SlitherCompilationUnit | ||
from slither.solc_parsing.variables.event_variable import EventVariableSolc | ||
from slither.solc_parsing.declarations.caller_context import CallerContextExpression | ||
|
||
if TYPE_CHECKING: | ||
from slither.solc_parsing.slither_compilation_unit_solc import SlitherCompilationUnitSolc | ||
|
||
|
||
class EventTopLevelSolc(CallerContextExpression): | ||
""" | ||
EventTopLevel class | ||
""" | ||
|
||
def __init__( | ||
self, event: EventTopLevel, event_data: Dict, slither_parser: "SlitherCompilationUnitSolc" | ||
) -> None: | ||
|
||
self._event = event | ||
self._slither_parser = slither_parser | ||
|
||
if self.is_compact_ast: | ||
self._event.name = event_data["name"] | ||
elems = event_data["parameters"] | ||
assert elems["nodeType"] == "ParameterList" | ||
self._elemsNotParsed = elems["parameters"] | ||
else: | ||
self._event.name = event_data["attributes"]["name"] | ||
for elem in event_data["children"]: | ||
# From Solidity 0.6.3 to 0.6.10 (included) | ||
# Comment above a event might be added in the children | ||
# of an event for the legacy ast | ||
if elem["name"] == "ParameterList": | ||
if "children" in elem: | ||
self._elemsNotParsed = elem["children"] | ||
else: | ||
self._elemsNotParsed = [] | ||
|
||
def analyze(self) -> None: | ||
for elem_to_parse in self._elemsNotParsed: | ||
elem = EventVariable() | ||
# Todo: check if the source offset is always here | ||
if "src" in elem_to_parse: | ||
elem.set_offset(elem_to_parse["src"], self._slither_parser.compilation_unit) | ||
elem_parser = EventVariableSolc(elem, elem_to_parse) | ||
elem_parser.analyze(self) | ||
|
||
self._event.elems.append(elem) | ||
|
||
self._elemsNotParsed = [] | ||
|
||
@property | ||
def is_compact_ast(self) -> bool: | ||
return self._slither_parser.is_compact_ast | ||
|
||
@property | ||
def compilation_unit(self) -> SlitherCompilationUnit: | ||
return self._slither_parser.compilation_unit | ||
|
||
def get_key(self) -> str: | ||
return self._slither_parser.get_key() | ||
|
||
@property | ||
def slither_parser(self) -> "SlitherCompilationUnitSolc": | ||
return self._slither_parser | ||
|
||
@property | ||
def underlying_event(self) -> EventTopLevel: | ||
return self._event |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+1.27 KB
(160%)
tests/e2e/solc_parsing/test_data/compile/event-top-level.sol-0.8.22-compact.zip
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,17 @@ | ||
event MyEvent(uint256 a); | ||
|
||
uint256 constant A = 3; | ||
event MyEvent2(uint8[A]); | ||
|
||
contract T { | ||
type MyType is uint256; | ||
event MyCustomEvent(MyType mytype); | ||
|
||
function a() public { | ||
emit MyEvent(2); | ||
} | ||
|
||
function b() public { | ||
emit MyEvent2([1,2,3]); | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
tests/e2e/solc_parsing/test_data/expected/event-top-level.sol-0.8.22-compact.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"T": { | ||
"a()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n" | ||
"a()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n", | ||
"b()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n" | ||
} | ||
} |