Esempio n. 1
0
def generate_declarations():
    writer = codegen.CodeWriter()
    writer.public_suffix = options.suffix
    writer.write(license)

    # all types
    for t in ptypes.get_named_types():
        if isinstance(t, ptypes.StructType):
            generate_declaration(t, writer)
        if isinstance(t, ptypes.ChannelType):
            for m in t.client_messages + t.server_messages:
                generate_declaration(m.message_type, writer)

    content = writer.getvalue()
    write_content(options.generated_declaration_file, content,
                  options.keep_identical_file)
Esempio n. 2
0
def generate_declaration(t, writer_top):
    writer = codegen.CodeWriter()
    try:
        c_type = t.c_type()
        t.generate_c_declaration(writer)
        value = writer.getvalue().strip()
        if not value:
            return
        if c_type in all_structures:
            assert all_structures[
                c_type] == value, """Structure %s redefinition
previous:
%s
---
current:
%s
---""" % (c_type, all_structures[c_type], value)
        else:
            all_structures[c_type] = value
            t.generate_c_declaration(writer_top)
    except:
        print >> sys.stderr, 'type %s' % t
        print >> sys.stderr, writer.getvalue()
        traceback.print_exc(sys.stderr)
Esempio n. 3
0
    parser.error("No protocol file specified")

if len(args) == 1:
    parser.error("No destination file specified")

ptypes.default_pointer_size = int(options.ptrsize)

proto_file = args[0]
dest_file = args[1]
proto = spice_parser.parse(proto_file)

if proto == None:
    exit(1)

codegen.set_prefix(proto.name)
writer = codegen.CodeWriter()
writer.header = codegen.CodeWriter()
writer.set_option("source", os.path.basename(proto_file))

license = """/*
  Copyright (C) 2013 Red Hat, Inc.

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.