tools/json_schema_compiler/h_generator.py
def Generate(self):
    """Generates a Code object with the .h for a single namespace.
    """
    c = Code()
    (c.Append(cpp_util.CHROMIUM_LICENSE)
      .Append()
      .Append(cpp_util.GENERATED_FILE_MESSAGE %
              cpp_util.ToPosixPath(self._namespace.source_file))
      .Append()
    )

    # Hack: for the purpose of gyp the header file will always be the source
    # file with its file extension replaced by '.h'. Assume so.
    output_file = os.path.splitext(self._namespace.source_file)[0] + '.h'
    ifndef_name = cpp_util.GenerateIfndefName(output_file)

    # Hack: tabs and windows have circular references, so only generate hard
    # references for them (i.e. anything that can't be forward declared). In
    # other cases, generate soft dependencies so that they can include
    # non-optional types from other namespaces.
    include_soft = self._namespace.name not in ('tabs', 'windows')

    (c.Append('#ifndef %s' % ifndef_name)
      .Append('#define %s' % ifndef_name)
      .Append()
      .Append('#include <stdint.h>')
      .Append()
      .Append('#include <map>')
      .Append('#include <memory>')
      .Append('#include <string>')
      .Append('#include <vector>')
      .Append()
      .Append('#include "base/values.h"')
      .Cblock(self._type_helper.GenerateIncludes(include_soft=include_soft))
      .Append()
    )

    # Hack: we're not generating soft includes for tabs and windows, so we need
    # to generate forward declarations for them.
    if not include_soft:
      c.Cblock(self._type_helper.GenerateForwardDeclarations())

    cpp_namespace = cpp_util.GetCppNamespace(
        self._namespace.environment.namespace_pattern,
        self._namespace.unix_name)
    c.Concat(cpp_util.OpenNamespace(cpp_namespace))
    c.Append()
    if self._namespace.properties:
      (c.Append('//')
        .Append('// Properties')
        .Append('//')
        .Append()
      )
      for prop in self._namespace.properties.values():
        property_code = self._type_helper.GeneratePropertyValues(
            prop,
            'extern const %(type)s %(name)s;')
        if property_code:
          c.Cblock(property_code)
    if self._namespace.types:
      (c.Append('//')
        .Append('// Types')
        .Append('//')
        .Append()
        .Cblock(self._GenerateTypes(self._FieldDependencyOrder(),
                                    is_toplevel=True,
                                    generate_typedefs=True))
      )
    if self._namespace.manifest_keys:
      c.Append('//')
      c.Append('// Manifest Keys')
      c.Append('//')
      c.Append()
      c.Cblock(self._GenerateManifestKeys())
    if self._namespace.functions:
      (c.Append('//')
        .Append('// Functions')
        .Append('//')
        .Append()
      )
      for function in self._namespace.functions.values():
        c.Cblock(self._GenerateFunction(function))
    if self._namespace.events:
      (c.Append('//')
        .Append('// Events')
        .Append('//')
        .Append()
      )
      for event in self._namespace.events.values():
        c.Cblock(self._GenerateEvent(event))
    (c.Concat(cpp_util.CloseNamespace(cpp_namespace))
      .Append()
      .Append('#endif  // %s' % ifndef_name)
      .Append()
    )
    return c
Generates a Code object with the .h for a single namespace.
    
Generates a Code object with the .h for a single namespace.
Generates a Code object with the . h for a single namespace .
def Generate(self):
    c = Code()
    (c.Append(cpp_util.CHROMIUM_LICENSE)
      .Append()
      .Append(cpp_util.GENERATED_FILE_MESSAGE %
              cpp_util.ToPosixPath(self._namespace.source_file))
      .Append()
    )
    output_file = os.path.splitext(self._namespace.source_file)[0] + '.h'
    ifndef_name = cpp_util.GenerateIfndefName(output_file)
    include_soft = self._namespace.name not in ('tabs', 'windows')
    (c.Append('#ifndef %s' % ifndef_name)
      .Append('#define %s' % ifndef_name)
      .Append()
      .Append('#include <stdint.h>')
      .Append()
      .Append('#include <map>')
      .Append('#include <memory>')
      .Append('#include <string>')
      .Append('#include <vector>')
      .Append()
      .Append('#include "base/values.h"')
      .Cblock(self._type_helper.GenerateIncludes(include_soft=include_soft))
      .Append()
    )
    if not include_soft:
      c.Cblock(self._type_helper.GenerateForwardDeclarations())
    cpp_namespace = cpp_util.GetCppNamespace(
        self._namespace.environment.namespace_pattern,
        self._namespace.unix_name)
    c.Concat(cpp_util.OpenNamespace(cpp_namespace))
    c.Append()
    if self._namespace.properties:
      (c.Append('//')
        .Append('// Properties')
        .Append('//')
        .Append()
      )
      for prop in self._namespace.properties.values():
        property_code = self._type_helper.GeneratePropertyValues(
            prop,
            'extern const %(type)s %(name)s;')
        if property_code:
          c.Cblock(property_code)
    if self._namespace.types:
      (c.Append('//')
        .Append('// Types')
        .Append('//')
        .Append()
        .Cblock(self._GenerateTypes(self._FieldDependencyOrder(),
                                    is_toplevel=True,
                                    generate_typedefs=True))
      )
    if self._namespace.manifest_keys:
      c.Append('//')
      c.Append('// Manifest Keys')
      c.Append('//')
      c.Append()
      c.Cblock(self._GenerateManifestKeys())
    if self._namespace.functions:
      (c.Append('//')
        .Append('// Functions')
        .Append('//')
        .Append()
      )
      for function in self._namespace.functions.values():
        c.Cblock(self._GenerateFunction(function))
    if self._namespace.events:
      (c.Append('//')
        .Append('// Events')
        .Append('//')
        .Append()
      )
      for event in self._namespace.events.values():
        c.Cblock(self._GenerateEvent(event))
    (c.Concat(cpp_util.CloseNamespace(cpp_namespace))
      .Append()
      .Append('#endif  // %s' % ifndef_name)
      .Append()
    )
    return c
def Generate ( self ) : c = Code ( ) ( c . Append ( cpp_util . CHROMIUM_LICENSE ) . Append ( ) . Append ( cpp_util . GENERATED_FILE_MESSAGE % cpp_util . ToPosixPath ( self . _namespace . source_file ) ) . Append ( ) ) output_file = os . path . splitext ( self . _namespace . source_file ) [ 0 ] + '.h' ifndef_name = cpp_util . GenerateIfndefName ( output_file ) include_soft = self . _namespace . name not in ( 'tabs' , 'windows' ) ( c . Append ( '#ifndef %s' % ifndef_name ) . Append ( '#define %s' % ifndef_name ) . Append ( ) . Append ( '#include <stdint.h>' ) . Append ( ) . Append ( '#include <map>' ) . Append ( '#include <memory>' ) . Append ( '#include <string>' ) . Append ( '#include <vector>' ) . Append ( ) . Append ( '#include "base/values.h"' ) . Cblock ( self . _type_helper . GenerateIncludes ( include_soft = include_soft ) ) . Append ( ) ) if not include_soft : c . Cblock ( self . _type_helper . GenerateForwardDeclarations ( ) ) cpp_namespace = cpp_util . GetCppNamespace ( self . _namespace . environment . namespace_pattern , self . _namespace . unix_name ) c . Concat ( cpp_util . OpenNamespace ( cpp_namespace ) ) c . Append ( ) if self . _namespace . properties : ( c . Append ( '//' ) . Append ( '// Properties' ) . Append ( '//' ) . Append ( ) ) for prop in self . _namespace . properties . values ( ) : property_code = self . _type_helper . GeneratePropertyValues ( prop , 'extern const %(type)s %(name)s;' ) if property_code : c . Cblock ( property_code ) if self . _namespace . types : ( c . Append ( '//' ) . Append ( '// Types' ) . Append ( '//' ) . Append ( ) . Cblock ( self . _GenerateTypes ( self . _FieldDependencyOrder ( ) , is_toplevel = True , generate_typedefs = True ) ) ) if self . _namespace . manifest_keys : c . Append ( '//' ) c . Append ( '// Manifest Keys' ) c . Append ( '//' ) c . Append ( ) c . Cblock ( self . _GenerateManifestKeys ( ) ) if self . _namespace . functions : ( c . Append ( '//' ) . Append ( '// Functions' ) . Append ( '//' ) . Append ( ) ) for function in self . _namespace . functions . values ( ) : c . Cblock ( self . _GenerateFunction ( function ) ) if self . _namespace . events : ( c . Append ( '//' ) . Append ( '// Events' ) . Append ( '//' ) . Append ( ) ) for event in self . _namespace . events . values ( ) : c . Cblock ( self . _GenerateEvent ( event ) ) ( c . Concat ( cpp_util . CloseNamespace ( cpp_namespace ) ) . Append ( ) . Append ( '#endif  // %s' % ifndef_name ) . Append ( ) ) return c
Generates a Code object with the .h for a single namespace.
Generates a Code object with the . h for a single namespace .
"""Generates a Code object with the .h for a single namespace.
    """ # Hack: for the purpose of gyp the header file will always be the source # file with its file extension replaced by '.h'. Assume so. # Hack: tabs and windows have circular references, so only generate hard # references for them (i.e. anything that can't be forward declared). In # other cases, generate soft dependencies so that they can include # non-optional types from other namespaces. # Hack: we're not generating soft includes for tabs and windows, so we need # to generate forward declarations for them.
self