MCPcopy Create free account
hub / github.com/ZeroIntensity/pointers.py / _gen_str

Function _gen_str

gen.py:182–243  ·  view source on GitHub ↗
(
    name: str | None,
    signature: str,
    params: dict[str, list[str]],
    minver: str | None,
)

Source from the content-addressed store, hash-verified

180
181
182async def _gen_str(
183 name: str | None,
184 signature: str,
185 params: dict[str, list[str]],
186 minver: str | None,
187) -> str | None:
188 signature = signature.replace(" *", "* ").replace("* *", "** ").replace("struct ", "")
189
190 for i in {"#", "//", "typedef", "static", "/*"}:
191 if signature.startswith(i):
192 return None
193 match = C_FUNC.match(signature)
194
195 if not name:
196 if match:
197 name = match.group(6)
198
199 if match and (name not in params):
200 assert name
201 params[name] = []
202 group = match.group(1)
203 ret = _get_type(group)
204
205 if not ret:
206 not_found(group, name)
207 return None
208
209 if match.group(12):
210 argtypes = ""
211 else:
212 args = match.group(7)
213 if not args:
214 args = "void"
215 argtypes = ", ("
216
217 if args != "void":
218 for arg in args.split(", "):
219 arg_split = arg.split(" ")
220 argname = arg_split.pop(-1)
221 add_pointer: bool = False
222
223 if argname.endswith("[]"):
224 argname = argname[:-2]
225 add_pointer = True
226
227 params[name].append(argname if argname != "def" else "df")
228
229 join = " ".join(arg_split).replace(
230 "const ", ""
231 ) # we dont care about consts
232 typ = _get_type(join, add_pointer=add_pointer)
233
234 if not typ:
235 not_found(join, name)
236 continue
237
238 argtypes += typ + ","
239

Callers 1

_gen_ct_bindingsFunction · 0.85

Calls 7

_get_typeFunction · 0.85
not_foundFunction · 0.85
replaceMethod · 0.80
splitMethod · 0.80
popMethod · 0.80
appendMethod · 0.80
joinMethod · 0.80

Tested by

no test coverage detected