• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2016 The Chromium Embedded Framework Authors. All rights
2# reserved. Use of this source code is governed by a BSD-style license that
3# can be found in the LICENSE file.
4
5from __future__ import absolute_import
6from cef_parser import *
7from make_ctocpp_impl import *
8
9
10def make_views_function_stub_impl(clsname, func):
11  name = func.get_name()
12
13  # Build the C++ prototype.
14  parts = func.get_cpp_parts(True)
15  result = make_ctocpp_impl_proto(clsname, name, func, parts) + ' {'
16
17  # Retrieve the function return value.
18  retval = func.get_retval()
19  retval_type = retval.get_retval_type()
20  if retval_type == 'invalid':
21    notify(name + ' could not be autogenerated')
22    # Code could not be auto-generated.
23    result += '\n  // COULD NOT IMPLEMENT DUE TO: (return value)'
24    result += '\n  #pragma message("Warning: "__FILE__": ' + name + ' is not implemented")'
25    retval_default = ''
26  else:
27    retval_default = retval.get_retval_default(False)
28
29  result += '\n  NOTIMPLEMENTED();'
30  if retval_default != '':
31    result += '\n  return ' + retval_default + ';'
32
33  result += '\n}\n\n'
34
35  return result
36
37
38def make_views_class_stub_impl(header, cls):
39  impl = ''
40
41  clsname = cls.get_name()
42  funcs = cls.get_static_funcs()
43  for func in funcs:
44    impl += make_views_function_stub_impl(clsname, func)
45
46  return impl
47
48
49def make_views_stub_impl(header):
50  includes = ''
51  impl = ''
52
53  allclasses = header.get_classes()
54  for cls in allclasses:
55    dir = cls.get_file_directory()
56    # Only process files in the views/ directory.
57    if dir != None and dir.find('views') == 0:
58      cls_impl = make_views_class_stub_impl(header, cls)
59      if cls_impl != '':
60        impl += cls_impl
61        includes += '#include "include/' + cls.get_file_name() + '"\n'
62
63  includes += '\n#include "base/logging.h"\n#include "base/notreached.h"\n'
64
65  # Build the final output.
66  result = get_copyright() + includes
67  result += '\n\n// STATIC STUB METHODS - Do not edit by hand.\n\n'
68  result += impl
69  return result
70
71
72def write_views_stub_impl(header, file):
73  newcontents = make_views_stub_impl(header)
74  return (file, newcontents)
75
76
77# Test the module.
78if __name__ == "__main__":
79  import sys
80
81  # Verify that the correct number of command-line arguments are provided.
82  if len(sys.argv) < 2:
83    sys.stderr.write('Usage: ' + sys.argv[0] + ' <cpp_header_dir>\n')
84    sys.exit()
85
86  cpp_header_dir = sys.argv[1]
87
88  # Create the header object. Should match the logic in translator.py.
89  header = obj_header()
90  header.set_root_directory(cpp_header_dir)
91  excluded_files = ['cef_api_hash.h', 'cef_application_mac.h', 'cef_version.h']
92  header.add_directory(cpp_header_dir, excluded_files)
93  header.add_directory(os.path.join(cpp_header_dir, 'views'))
94
95  # Dump the result to stdout.
96  sys.stdout.write(make_views_stub_impl(header))
97