Scan the file, looking for tagged functions. Assuming ``tag=='API'``, a tagged function looks like:: /*API*/ static returntype* function_name(argtype1 arg1, argtype2 arg2) { } where the return type must be on a separate line, the function n
(filename, tag='API')
| 215 | |
| 216 | |
| 217 | def find_functions(filename, tag='API'): |
| 218 | """ |
| 219 | Scan the file, looking for tagged functions. |
| 220 | |
| 221 | Assuming ``tag=='API'``, a tagged function looks like:: |
| 222 | |
| 223 | /*API*/ |
| 224 | static returntype* |
| 225 | function_name(argtype1 arg1, argtype2 arg2) |
| 226 | { |
| 227 | } |
| 228 | |
| 229 | where the return type must be on a separate line, the function |
| 230 | name must start the line, and the opening ``{`` must start the line. |
| 231 | |
| 232 | An optional documentation comment in ReST format may follow the tag, |
| 233 | as in:: |
| 234 | |
| 235 | /*API |
| 236 | This function does foo... |
| 237 | */ |
| 238 | """ |
| 239 | if filename.endswith(('.c.src', '.h.src')): |
| 240 | fo = io.StringIO(process_c_file(filename)) |
| 241 | else: |
| 242 | fo = open(filename, 'r') |
| 243 | functions = [] |
| 244 | return_type = None |
| 245 | function_name = None |
| 246 | function_args = [] |
| 247 | doclist = [] |
| 248 | SCANNING, STATE_DOC, STATE_RETTYPE, STATE_NAME, STATE_ARGS = list(range(5)) |
| 249 | state = SCANNING |
| 250 | tagcomment = '/*' + tag |
| 251 | for lineno, line in enumerate(fo): |
| 252 | try: |
| 253 | line = line.strip() |
| 254 | if state == SCANNING: |
| 255 | if line.startswith(tagcomment): |
| 256 | if line.endswith('*/'): |
| 257 | state = STATE_RETTYPE |
| 258 | else: |
| 259 | state = STATE_DOC |
| 260 | elif state == STATE_DOC: |
| 261 | if line.startswith('*/'): |
| 262 | state = STATE_RETTYPE |
| 263 | else: |
| 264 | line = line.lstrip(' *') |
| 265 | doclist.append(line) |
| 266 | elif state == STATE_RETTYPE: |
| 267 | # first line of declaration with return type |
| 268 | m = re.match(r'NPY_NO_EXPORT\s+(.*)$', line) |
| 269 | if m: |
| 270 | line = m.group(1) |
| 271 | return_type = line |
| 272 | state = STATE_NAME |
| 273 | elif state == STATE_NAME: |
| 274 | # second line, with function name |
no test coverage detected