예제 #1
0
    def Generate(self):
        """Generates a Code object for features.
    """
        c = Code()
        (c.Append(cpp_util.CHROMIUM_LICENSE).Append().Append(
            cpp_util.GENERATED_FEATURE_MESSAGE % self._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)

        (c.Append('#ifndef %s' % ifndef_name).Append('#define %s' %
                                                     ifndef_name).Append())

        (c.Append('#include <map>').Append(
            '#include <string>').Append().Concat(
                cpp_util.OpenNamespace(self._namespace)).Append())

        (c.Append('class %s {' %
                  self._class_name).Append(' public:').Sblock().Concat(
                      self._GeneratePublicBody()).Eblock().Append(' private:').
         Sblock().Concat(
             self._GeneratePrivateBody()).Eblock('};').Append().Cblock(
                 cpp_util.CloseNamespace(self._namespace)))
        (c.Append('#endif  // %s' % ifndef_name).Append())
        return c
예제 #2
0
    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 %
            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)

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

        # TODO(calamity): These forward declarations should be #includes to allow
        # $ref types from other files to be used as required params. This requires
        # some detangling of windows and tabs which will currently lead to circular
        # #includes.
        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.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(
            '#endif  // %s' % ifndef_name).Append())
        return c
예제 #3
0
    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 %
            self._namespace.source_file).Append())

        ifndef_name = cpp_util.GenerateIfndefName(
            self._namespace.source_file_dir, self._target_namespace)
        (c.Append('#ifndef %s' % ifndef_name).Append(
            '#define %s' %
            ifndef_name).Append().Append('#include <map>').Append(
                '#include <string>').Append('#include <vector>').Append().
         Append('#include "base/basictypes.h"').Append(
             '#include "base/logging.h"').Append(
                 '#include "base/memory/linked_ptr.h"').Append(
                     '#include "base/memory/scoped_ptr.h"').Append(
                         '#include "base/values.h"').Cblock(
                             self._type_helper.GenerateIncludes()).Append())

        c.Concat(cpp_util.OpenNamespace(self._cpp_namespace))
        # TODO(calamity): These forward declarations should be #includes to allow
        # $ref types from other files to be used as required params. This requires
        # some detangling of windows and tabs which will currently lead to circular
        # #includes.
        forward_declarations = (
            self._type_helper.GenerateForwardDeclarations())
        if not forward_declarations.IsEmpty():
            (c.Append().Cblock(forward_declarations))

        c.Concat(self._type_helper.GetNamespaceStart())
        c.Append()
        if self._namespace.properties:
            (c.Append('//').Append('// Properties').Append('//').Append())
            for property in self._namespace.properties.values():
                property_code = self._type_helper.GeneratePropertyValues(
                    property, '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.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(self._type_helper.GetNamespaceEnd()).Concat(
            cpp_util.CloseNamespace(self._cpp_namespace)).Append(
                '#endif  // %s' % ifndef_name).Append())
        return c
예제 #4
0
    def Generate(self):
        """Generates a code.Code object with the .h for a single namespace.
    """
        c = code.Code()
        (c.Append(cpp_util.CHROMIUM_LICENSE).Append().Append(
            cpp_util.GENERATED_FILE_MESSAGE %
            self._namespace.source_file).Append())

        ifndef_name = cpp_util.GenerateIfndefName(
            self._namespace.source_file_dir, self._target_namespace)
        (c.Append('#ifndef %s' % ifndef_name).Append(
            '#define %s' % ifndef_name).Append('#pragma once').Append().Append(
                '#include <string>').Append('#include <vector>').Append(
                ).Append('#include "base/basictypes.h"').Append(
                    '#include "base/memory/linked_ptr.h"').
         Append('#include "base/memory/scoped_ptr.h"').Append(
             '#include "base/values.h"').Append(
                 '#include "tools/json_schema_compiler/any.h"').Append())

        c.Concat(self._cpp_type_generator.GetRootNamespaceStart())
        # TODO(calamity): These forward declarations should be #includes to allow
        # $ref types from other files to be used as required params. This requires
        # some detangling of windows and tabs which will currently lead to circular
        # #includes.
        forward_declarations = (
            self._cpp_type_generator.GenerateForwardDeclarations())
        if not forward_declarations.IsEmpty():
            (c.Append().Concat(forward_declarations).Append())

        c.Concat(self._cpp_type_generator.GetNamespaceStart())
        c.Append()
        if self._namespace.types:
            (c.Append('//').Append('// Types').Append('//').Append())
            for type_ in self._FieldDependencyOrder():
                (c.Concat(self._GenerateType(type_)).Append())
        if self._namespace.functions:
            (c.Append('//').Append('// Functions').Append('//').Append())
            for function in self._namespace.functions.values():
                (c.Concat(self._GenerateFunction(function)).Append())
        (c.Concat(self._cpp_type_generator.GetNamespaceEnd()).Concat(
            self._cpp_type_generator.GetRootNamespaceEnd()).Append().Append(
                '#endif  // %s' % ifndef_name).Append())
        return c
    def _GenerateHeader(self, file_base, body_code):
        """Generates a code.Code object for a header file

    Parameters:
    - |file_base| - the base of the filename, e.g. 'foo' (for 'foo.h')
    - |body_code| - the code to put in between the multiple inclusion guards"""
        c = code.Code()
        c.Append(cpp_util.CHROMIUM_LICENSE)
        c.Append()
        c.Append(cpp_util.GENERATED_BUNDLE_FILE_MESSAGE % SOURCE_BASE_PATH)
        ifndef_name = cpp_util.GenerateIfndefName(SOURCE_BASE_PATH, file_base)
        c.Append()
        c.Append('#ifndef %s' % ifndef_name)
        c.Append('#define %s' % ifndef_name)
        c.Append()
        c.Concat(body_code)
        c.Append()
        c.Append('#endif  // %s' % ifndef_name)
        c.Append()
        return c
    def Generate(self):
        """Generates a Code object for features.
    """
        c = Code()
        (c.Append(cpp_util.CHROMIUM_LICENSE).Append().Append(
            cpp_util.GENERATED_FEATURE_MESSAGE % self._source_file).Append())
        ifndef_name = cpp_util.GenerateIfndefName(self._source_file_filename,
                                                  self._class_name)
        (c.Append('#ifndef %s' % ifndef_name).Append('#define %s' %
                                                     ifndef_name).Append())

        (c.Append('#include <map>').Append(
            '#include <string>').Append().Concat(
                cpp_util.OpenNamespace(self._namespace)).Append())

        (c.Append('class %s {' %
                  self._class_name).Append(' public:').Sblock().Concat(
                      self._GeneratePublicBody()).Eblock().Append(' private:').
         Sblock().Concat(
             self._GeneratePrivateBody()).Eblock('};').Append().Cblock(
                 cpp_util.CloseNamespace(self._namespace)))
        (c.Append('#endif  // %s' % ifndef_name).Append())
        return c
예제 #7
0
    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 %
            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