Skip to content

Commit

Permalink
Track function natspec comments
Browse files Browse the repository at this point in the history
  • Loading branch information
smonicas committed Nov 29, 2023
1 parent 456a414 commit 96b57fa
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
15 changes: 15 additions & 0 deletions slither/core/declarations/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ def __init__(self, compilation_unit: "SlitherCompilationUnit") -> None:

# To be improved with a parsing of the documentation
self.has_documentation: bool = False
self._comments: Optional[str] = None

###################################################################################
###################################################################################
Expand Down Expand Up @@ -363,6 +364,20 @@ def id(self) -> Optional[str]:
def id(self, new_id: str):
self._id = new_id

@property
def comments(self) -> Optional[str]:
"""
Return the comments associated with the function.
Returns:
the comment as a string
"""
return self._comments

@comments.setter
def comments(self, comments: str):
self._comments = comments

@property
@abstractmethod
def file_scope(self) -> "FileScope":
Expand Down
17 changes: 17 additions & 0 deletions slither/solc_parsing/declarations/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,23 @@ def __init__(
if "documentation" in function_data:
function.has_documentation = True

# Old solc versions store the comment in attributes["documentation"]
# More recent ones store it in attributes["documentation"]["text"]
if (
"documentation" in function_data
and function_data["documentation"] is not None
and (
"text" in function_data["documentation"]
or isinstance(function_data["documentation"], str)
)
):
text = (
function_data["documentation"]
if isinstance(function_data["documentation"], str)
else function_data["documentation"]["text"]
)
self._function.comments = text

@property
def underlying_function(self) -> Function:
return self._function
Expand Down

0 comments on commit 96b57fa

Please sign in to comment.