Exemple #1
0
def WriteGroupMarker(out, node, last_group):
    # If we are part of a group comment marker...
    if last_group and last_group != node.cls:
        pre = CommentLines(['*', ' @}', '']) + '\n'
    else:
        pre = '\n'

    if node.cls in ['Typedef', 'Interface', 'Struct', 'Enum']:
        if last_group != node.cls:
            pre += CommentLines(
                ['*', ' @addtogroup %ss' % node.cls, ' @{', ''])
        last_group = node.cls
    else:
        last_group = None
    out.Write(pre)
    return last_group
def GenerateHeader(out, filenode, releases):
    cgen = CGen()
    pref = ''
    do_comments = True

    # Generate definitions.
    last_group = None
    top_types = ['Typedef', 'Interface', 'Struct', 'Enum', 'Inline']
    for node in filenode.GetListOf(*top_types):
        # Skip if this node is not in this release
        if not node.InReleases(releases):
            print "Skiping %s" % node
            continue

        # End/Start group marker
        if do_comments:
            last_group = WriteGroupMarker(out, node, last_group)

        if node.IsA('Inline'):
            item = node.GetProperty('VALUE')
            # If 'C++' use __cplusplus wrapper
            if node.GetName() == 'cc':
                item = '#ifdef __cplusplus\n%s\n#endif  /* __cplusplus */\n\n' % item
            # If not C++ or C, then skip it
            elif not node.GetName() == 'c':
                continue
            if item: out.Write(item)
            continue

        #
        # Otherwise we are defining a file level object, so generate the
        # correct document notation.
        #
        item = cgen.Define(node, releases, prefix=pref, comment=True)
        if not item: continue
        asize = node.GetProperty('assert_size()')
        if asize:
            name = '%s%s' % (pref, node.GetName())
            if node.IsA('Struct'):
                form = 'PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(%s, %s);\n'
            elif node.IsA('Enum'):
                if node.GetProperty('notypedef'):
                    form = 'PP_COMPILE_ASSERT_ENUM_SIZE_IN_BYTES(%s, %s);\n'
                else:
                    form = 'PP_COMPILE_ASSERT_SIZE_IN_BYTES(%s, %s);\n'
            else:
                form = 'PP_COMPILE_ASSERT_SIZE_IN_BYTES(%s, %s);\n'
            item += form % (name, asize[0])

        if item: out.Write(item)
    if last_group:
        out.Write(CommentLines(['*', ' @}', '']) + '\n')