OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Creates windows and posix stub files for a given set of signatures. | 6 """Creates windows and posix stub files for a given set of signatures. |
7 | 7 |
8 For libraries that need to be loaded outside of the standard executable startup | 8 For libraries that need to be loaded outside of the standard executable startup |
9 path mechanism, stub files need to be generated for the wanted functions. In | 9 path mechanism, stub files need to be generated for the wanted functions. In |
10 windows, this is done via "def" files and the delay load mechanism. On a posix | 10 windows, this is done via "def" files and the delay load mechanism. On a posix |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 | 383 |
384 This function parses a file of signatures into a list of dictionaries that | 384 This function parses a file of signatures into a list of dictionaries that |
385 represent the function signatures in the input file. Each dictionary has | 385 represent the function signatures in the input file. Each dictionary has |
386 the following keys: | 386 the following keys: |
387 return_type: A string with the return type. | 387 return_type: A string with the return type. |
388 name: A string with the name of the function. | 388 name: A string with the name of the function. |
389 params: A list of each function parameter declaration (type + name) | 389 params: A list of each function parameter declaration (type + name) |
390 | 390 |
391 The format of the input file is one C-style function signature per line, no | 391 The format of the input file is one C-style function signature per line, no |
392 trailing semicolon. Empty lines are allowed. An empty line is a line that | 392 trailing semicolon. Empty lines are allowed. An empty line is a line that |
393 consists purely of whitespace. Lines that begin with a # are considered | 393 consists purely of whitespace. Lines that begin with a # or // are considered |
394 comment lines and are ignored. | 394 comment lines and are ignored. |
395 | 395 |
396 We assume that "int foo(void)" is the same as "int foo()", which is not | 396 We assume that "int foo(void)" is the same as "int foo()", which is not |
397 true in C where "int foo()" is equivalent to "int foo(...)". Our generated | 397 true in C where "int foo()" is equivalent to "int foo(...)". Our generated |
398 code is C++, and we do not handle varargs, so this is a case that can be | 398 code is C++, and we do not handle varargs, so this is a case that can be |
399 ignored for now. | 399 ignored for now. |
400 | 400 |
401 Args: | 401 Args: |
402 infile: File object holding a text file of function signatures. | 402 infile: File object holding a text file of function signatures. |
403 | 403 |
404 Returns: | 404 Returns: |
405 A list of dictionaries, where each dictionary represents one function | 405 A list of dictionaries, where each dictionary represents one function |
406 signature. | 406 signature. |
407 | 407 |
408 Raises: | 408 Raises: |
409 BadSignatureError: A line could not be parsed as a signature. | 409 BadSignatureError: A line could not be parsed as a signature. |
410 """ | 410 """ |
411 signatures = [] | 411 signatures = [] |
412 for line in infile: | 412 for line in infile: |
413 line = line.strip() | 413 line = line.strip() |
414 if line and line[0] != '#': | 414 if line and line[0] != '#' and line[0:2] != '//': |
415 m = SIGNATURE_REGEX.match(line) | 415 m = SIGNATURE_REGEX.match(line) |
416 if m is None: | 416 if m is None: |
417 raise BadSignatureError('Unparsable line: %s' % line) | 417 raise BadSignatureError('Unparsable line: %s' % line) |
418 signatures.append( | 418 signatures.append( |
419 {'return_type': m.group('return_type').strip(), | 419 {'return_type': m.group('return_type').strip(), |
420 'name': m.group('name').strip(), | 420 'name': m.group('name').strip(), |
421 'params': [arg.strip() for arg in m.group('params').split(',')]}) | 421 'params': [arg.strip() for arg in m.group('params').split(',')]}) |
422 return signatures | 422 return signatures |
423 | 423 |
424 | 424 |
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1122 elif options.type == FILE_TYPE_POSIX_STUB: | 1122 elif options.type == FILE_TYPE_POSIX_STUB: |
1123 CreatePosixStubsForSigFiles(args, options.stubfile_name, out_dir, | 1123 CreatePosixStubsForSigFiles(args, options.stubfile_name, out_dir, |
1124 intermediate_dir, options.path_from_source, | 1124 intermediate_dir, options.path_from_source, |
1125 options.extra_stub_header) | 1125 options.extra_stub_header) |
1126 elif options.type == FILE_TYPE_WIN_DEF: | 1126 elif options.type == FILE_TYPE_WIN_DEF: |
1127 CreateWindowsDefForSigFiles(args, out_dir, options.module_name) | 1127 CreateWindowsDefForSigFiles(args, out_dir, options.module_name) |
1128 | 1128 |
1129 | 1129 |
1130 if __name__ == '__main__': | 1130 if __name__ == '__main__': |
1131 main() | 1131 main() |
OLD | NEW |