Skip to content

Commit

Permalink
[sourcegen] Roll back adding annotations to Func
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl committed Aug 21, 2024
1 parent 61119e1 commit b6914fe
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 16 deletions.
5 changes: 2 additions & 3 deletions interfaces/sourcegen/sourcegen/_dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,22 +109,21 @@ def n_optional(self):
class Func:
"""Represents a function parsed from a C header file."""

annotations: str # documentation block
ret_type: str # may include leading specifier
name: str
params: List[Param]
spec: str # trailing specifier

@classmethod
def from_str(cls, func: str, annotations: str="") -> 'Func':
def from_str(cls, func: str) -> 'Func':
"""Generate Func from string function signature"""
func = func.strip()
name = re.findall(re.compile(r'.*?(?=\(|$)'), func)[0]
arglist = ArgList.from_str(func.replace(name, "").strip())
r_type = ""
if " " in name:
r_type, name = name.rsplit(" ", 1)
return cls(annotations, r_type, name, arglist.params, arglist.spec)
return cls(r_type, name, arglist.params, arglist.spec)

def declaration(self) -> str:
"""Return a string representation of the function (without semi-colon)."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def merge_params(implements, details: TagDetails) -> List[Param]:
recipe.name, recipe.what)
sys.exit(1)

c_func = Func("", ret_param.p_type, recipe.name, args, "")
c_func = Func(ret_param.p_type, recipe.name, args, "")
declaration = c_func.declaration()
annotations = self._build_annotation(details, ret_param, args, recipe.relates)

Expand Down
16 changes: 4 additions & 12 deletions interfaces/sourcegen/sourcegen/csharp/_CSharpSourceGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,11 @@ def _join_params(params: List[Param]) -> str:
return ", ".join(p.p_type + " " + p.name for p in params)

def _get_interop_func_text(self, func: CsFunc) -> str:
comments, ret_type, name, params, _, _, _ = func
ret_type, name, params, _, _, _ = func
requires_unsafe_keyword = any(p.p_type.endswith("*") for p in params)
params_text = self._join_params(params)

ret = ""
if comments:
# convert trailing C++ doxygen comments, but retain C++ formatting
# comment blocks will not be parsed by .NET
comments = comments.replace("//!< ", "//! ").strip()
ret += f"{comments}\n"

ret += f"{self._config.func_prolog} "
ret = f"{self._config.func_prolog} "
if requires_unsafe_keyword:
ret += "unsafe "
ret += f"{ret_type} {name}({params_text});" # function text
Expand Down Expand Up @@ -137,7 +130,7 @@ def _get_handle_class_name(self, clib_area: str) -> str:
return self._get_wrapper_class_name(clib_area) + "Handle"

def _convert_func(self, parsed: Func) -> CsFunc:
comments, ret_type, name, _, _ = parsed
ret_type, name, _, _ = parsed
clib_area, method = name.split("_", 1)

# Shallow copy the params list
Expand Down Expand Up @@ -205,8 +198,7 @@ def _convert_func(self, parsed: Func) -> CsFunc:

params[i] = Param(param_type, param_name)

func = CsFunc(comments,
ret_type,
func = CsFunc(ret_type,
name,
params,
"",
Expand Down

0 comments on commit b6914fe

Please sign in to comment.