mirror of
https://gitlab.uni-freiburg.de/opensourcevdi/spice-common
synced 2026-01-05 08:36:10 +00:00
codegen: Improve header guard generation
Until now, the same header guard was used for all generated .h files. Now the header guard name is based on the name of the file being generated so that it's different for each .h file. Signed-off-by: Frediano Ziglio <fziglio@redhat.com> Signed-off-by: Christophe Fergeau <cfergeau@redhat.com> Acked-by: Frediano Ziglio <fziglio@redhat.com> Acked-by: Christophe Fergeau <cfergeau@redhat.com>
This commit is contained in:
parent
806d3273fa
commit
0eb567e6fb
@ -1,13 +1,22 @@
|
||||
|
||||
from . import ptypes
|
||||
from . import codegen
|
||||
import re
|
||||
|
||||
def write_includes(writer):
|
||||
writer.header.writeln("#include <spice/protocol.h>")
|
||||
writer.header.writeln('#include "common/marshaller.h"')
|
||||
writer.header.newline()
|
||||
writer.header.writeln("#ifndef _GENERATED_HEADERS_H")
|
||||
writer.header.writeln("#define _GENERATED_HEADERS_H")
|
||||
if writer.header.has_option("dest_file"):
|
||||
src = writer.header.options["dest_file"]
|
||||
else:
|
||||
src = "generated_headers.h"
|
||||
src = re.sub(r'[^a-z0-9]+', '_', src, flags=re.IGNORECASE)
|
||||
src = src.upper()
|
||||
if src.endswith("_H"):
|
||||
src = "_H_"+src[:-2]
|
||||
writer.header.writeln("#ifndef %s" % src)
|
||||
writer.header.writeln("#define %s" % src)
|
||||
|
||||
writer.writeln("#include <string.h>")
|
||||
writer.writeln("#include <assert.h>")
|
||||
|
||||
@ -170,6 +170,7 @@ if proto == None:
|
||||
codegen.set_prefix(proto.name)
|
||||
writer = codegen.CodeWriter()
|
||||
writer.header = codegen.CodeWriter()
|
||||
writer.header.set_option("dest_file", dest_file)
|
||||
writer.set_option("source", os.path.basename(proto_file))
|
||||
|
||||
license = """/*
|
||||
|
||||
Loading…
Reference in New Issue
Block a user