| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 2 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 3 # for details. All rights reserved. Use of this source code is governed by a | 3 # for details. All rights reserved. Use of this source code is governed by a |
| 4 # BSD-style license that can be found in the LICENSE file. | 4 # BSD-style license that can be found in the LICENSE file. |
| 5 | 5 |
| 6 import re | 6 import re |
| 7 import subprocess | 7 import subprocess |
| 8 import tempfile | 8 import tempfile |
| 9 | 9 |
| 10 from pegparser import * | 10 from pegparser import * |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 Returns: | 401 Returns: |
| 402 The result of running gcc on the content. | 402 The result of running gcc on the content. |
| 403 | 403 |
| 404 Args: | 404 Args: |
| 405 content -- text to process. | 405 content -- text to process. |
| 406 defines -- an array of pre-processor defines. | 406 defines -- an array of pre-processor defines. |
| 407 includePaths -- an array of path strings. | 407 includePaths -- an array of path strings. |
| 408 """ | 408 """ |
| 409 # FIXME: Handle gcc not found, or any other processing errors | 409 # FIXME: Handle gcc not found, or any other processing errors |
| 410 gcc = 'gcc' | 410 gcc = 'gcc' |
| 411 cmd = [gcc, '-E', '-P', '-C', '-x', 'c++']; | 411 cmd = [gcc, '-E', '-P', '-C', '-x', 'c++'] |
| 412 for define in defines: | 412 for define in defines: |
| 413 cmd.append('-D%s' % define) | 413 cmd.append('-D%s' % define) |
| 414 cmd.append('-') | 414 cmd.append('-') |
| 415 pipe = subprocess.Popen(cmd, stdin=subprocess.PIPE, | 415 pipe = subprocess.Popen(cmd, stdin=subprocess.PIPE, |
| 416 stdout=subprocess.PIPE, stderr=subprocess.PIPE) | 416 stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 417 (content, stderr) = pipe.communicate(content) | 417 (content, stderr) = pipe.communicate(content) |
| 418 return content | 418 return content |
| 419 | 419 |
| 420 def parse(self, content, defines=[], includePaths=[]): | 420 def parse(self, content, defines=[], includePaths=[]): |
| 421 """Parse the give content string. | 421 """Parse the give content string. |
| 422 | 422 |
| 423 The WebKit IDL syntax also allows gcc pre-processing instructions. | 423 The WebKit IDL syntax also allows gcc pre-processing instructions. |
| 424 Lists of defined variables and include paths can be provided. | 424 Lists of defined variables and include paths can be provided. |
| 425 | 425 |
| 426 Returns: | 426 Returns: |
| 427 An abstract syntax tree (AST). | 427 An abstract syntax tree (AST). |
| 428 | 428 |
| 429 Args: | 429 Args: |
| 430 content -- text to parse. | 430 content -- text to parse. |
| 431 defines -- an array of pre-processor defines. | 431 defines -- an array of pre-processor defines. |
| 432 includePaths -- an array of path strings used by the | 432 includePaths -- an array of path strings used by the |
| 433 gcc pre-processor. | 433 gcc pre-processor. |
| 434 """ | 434 """ |
| 435 if self._syntax == WEBKIT_SYNTAX: | 435 if self._syntax == WEBKIT_SYNTAX: |
| 436 content = self._pre_process(content, defines, includePaths) | 436 content = self._pre_process(content, defines, includePaths) |
| 437 | 437 |
| 438 return self._pegparser.parse(content) | 438 return self._pegparser.parse(content) |
| OLD | NEW |