diff options
| author | zhanyong.wan <zhanyong.wan@8415998a-534a-0410-bf83-d39667b30386> | 2010-10-05 06:11:56 +0000 | 
|---|---|---|
| committer | zhanyong.wan <zhanyong.wan@8415998a-534a-0410-bf83-d39667b30386> | 2010-10-05 06:11:56 +0000 | 
| commit | 4b16e8ed2785136d863fb52961539c27c9716497 (patch) | |
| tree | 94411d85bf3f7988f2248b82cd2cfb423b50a098 /scripts/generator | |
| parent | 5921483640fed07d8dcfff9cc34fe353fec55f26 (diff) | |
| download | googletest-4b16e8ed2785136d863fb52961539c27c9716497.tar.gz googletest-4b16e8ed2785136d863fb52961539c27c9716497.tar.bz2 googletest-4b16e8ed2785136d863fb52961539c27c9716497.zip  | |
Enables gmock_gen to handle return types that are templates (based on Pride Haveit's patch); also fixes deprecation warnings when using gmock_gen with python 2.6 (by Aaron Jacobs).
Diffstat (limited to 'scripts/generator')
| -rwxr-xr-x | scripts/generator/cpp/gmock_class.py | 32 | 
1 files changed, 23 insertions, 9 deletions
diff --git a/scripts/generator/cpp/gmock_class.py b/scripts/generator/cpp/gmock_class.py index 3ad0bcdd..645c295b 100755 --- a/scripts/generator/cpp/gmock_class.py +++ b/scripts/generator/cpp/gmock_class.py @@ -31,12 +31,18 @@ __author__ = 'nnorwitz@google.com (Neal Norwitz)'  import os  import re -import sets  import sys  from cpp import ast  from cpp import utils +# Preserve compatibility with Python 2.3. +try: +  _dummy = set +except NameError: +  import sets +  set = sets.Set +  _VERSION = (1, 0, 1)  # The version of this script.  # How many spaces to indent.  Can set me with the INDENT environment variable.  _INDENT = 2 @@ -45,6 +51,7 @@ _INDENT = 2  def _GenerateMethods(output_lines, source, class_node):    function_type = ast.FUNCTION_VIRTUAL | ast.FUNCTION_PURE_VIRTUAL    ctor_or_dtor = ast.FUNCTION_CTOR | ast.FUNCTION_DTOR +  indent = ' ' * _INDENT    for node in class_node.body:      # We only care about virtual functions. @@ -62,11 +69,20 @@ def _GenerateMethods(output_lines, source, class_node):          if node.return_type.modifiers:            modifiers = ' '.join(node.return_type.modifiers) + ' '          return_type = modifiers + node.return_type.name +        template_args = [arg.name for arg in node.return_type.templated_types] +        if template_args: +          return_type += '<' + ', '.join(template_args) + '>' +          if len(template_args) > 1: +            for line in [ +                '// The following line won\'t really compile, as the return', +                '// type has multiple template arguments.  To fix it, use a', +                '// typedef for the return type.']: +              output_lines.append(indent + line)          if node.return_type.pointer:            return_type += '*'          if node.return_type.reference:            return_type += '&' -      prefix = 'MOCK_%sMETHOD%d' % (const, len(node.parameters)) +      mock_method_macro = 'MOCK_%sMETHOD%d' % (const, len(node.parameters))        args = ''        if node.parameters:          # Get the full text of the parameters from the start @@ -81,15 +97,13 @@ def _GenerateMethods(output_lines, source, class_node):          # intervening whitespace, e.g.: int\nBar          args = re.sub('  +', ' ', args_strings.replace('\n', ' ')) -      # Create the prototype. -      indent = ' ' * _INDENT -      line = ('%s%s(%s,\n%s%s(%s));' % -              (indent, prefix, node.name, indent*3, return_type, args)) -      output_lines.append(line) +      # Create the mock method definition. +      output_lines.extend(['%s%s(%s,' % (indent, mock_method_macro, node.name), +                           '%s%s(%s));' % (indent*3, return_type, args)])  def _GenerateMocks(filename, source, ast_list, desired_class_names): -  processed_class_names = sets.Set() +  processed_class_names = set()    lines = []    for node in ast_list:      if (isinstance(node, ast.Class) and node.body and @@ -156,7 +170,7 @@ def main(argv=sys.argv):    filename = argv[1]    desired_class_names = None  # None means all classes in the source file.    if len(argv) >= 3: -    desired_class_names = sets.Set(argv[2:]) +    desired_class_names = set(argv[2:])    source = utils.ReadFile(filename)    if source is None:      return 1  | 
