Skip to content

Commit

Permalink
auto-sync: replace assert with CS_ASSERT
Browse files Browse the repository at this point in the history
  • Loading branch information
imbillow committed Jul 6, 2024
1 parent e2f94b4 commit f081e30
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 5 additions & 3 deletions suite/auto-sync/src/autosync/cpptranslator/patches/Assert.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
from tree_sitter import Node

from autosync.cpptranslator.patches.Patch import Patch
from autosync.cpptranslator.patches.Helper import get_text_from_node


class Assert(Patch):
"""
Patch Remove asserts
Patch replace `assert` with `CS_ASSERT`
"""

def __init__(self, priority: int):
Expand All @@ -19,7 +20,7 @@ def get_search_pattern(self) -> str:
"(expression_statement"
" (call_expression"
' ((identifier) @id (#eq? @id "assert"))'
" (argument_list)"
" ((argument_list) @arg_list)"
" )"
") @assert"
)
Expand All @@ -28,4 +29,5 @@ def get_main_capture_name(self) -> str:
return "assert"

def get_patch(self, captures: [(Node, str)], src: bytes, **kwargs) -> bytes:
return b""
args = get_text_from_node(src, captures[2][0])
return b"CS_ASSERT" + args + b";"
3 changes: 3 additions & 0 deletions suite/auto-sync/src/autosync/cpptranslator/patches/Helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ def get_text(src: bytes, start_byte: int, end_byte: int) -> bytes:
return src[start_byte:end_byte]


def get_text_from_node(src: bytes, node: Node) -> bytes:
return src[node.start_byte:node.end_byte]

def namespace_enum(src: bytes, ns_id: bytes, enum: Node) -> bytes:
"""
Alters an enum in the way that it prepends the namespace id to every enum member.
Expand Down

0 comments on commit f081e30

Please sign in to comment.