Skip to content

Commit

Permalink
Fix forward reference to enumeration types in GtkDoc header
Browse files Browse the repository at this point in the history
It's invalid to forward-declare enumerations, yet they might be
referenced by typedefs.

Fix this by outputting enumerations first so typedefs can references
them.  As enumerations can't reference other types, it's safe to place
them before anything else.

Closes #952.
Closes #955.
  • Loading branch information
b4n committed Mar 9, 2016
1 parent e18011f commit ed700a9
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions scripts/gen-api-gtkdoc.py
Expand Up @@ -362,6 +362,7 @@ def main(args):
root = transform(doc)

other = []
enums = []
typedefs = []

c_files = root.xpath(".//compounddef[@kind='file']/compoundname[substring(.,string-length(.)-1)='.c']/..")
Expand All @@ -376,7 +377,7 @@ def main(args):

for n0 in f.xpath(".//*/memberdef[@kind='enum' and @prot='public']"):
e = DoxyEnum.from_memberdef(n0)
other.append(e)
enums.append(e)

for n0 in root.xpath(".//compounddef[@kind='struct' and @prot='public']"):
e = DoxyStruct.from_compounddef(n0)
Expand Down Expand Up @@ -404,12 +405,21 @@ def main(args):
outfile.write("typedef struct TMSourceFile TMSourceFile;\n")
outfile.write("typedef struct TMWorkspace TMWorkspace;\n")

# write typedefs first, they are possibly undocumented but still required (even
# write enums first, so typedefs to them are valid (as forward enum declaration
# is invalid). It's fine as an enum can't contain reference to other types.
for e in filter(lambda x: x.is_documented(), enums):
outfile.write("\n\n")
outfile.write(e.to_gtkdoc())
outfile.write(e.definition)
outfile.write("\n\n")

# write typedefs second, they are possibly undocumented but still required (even
# if they are documented, they must be written out without gtkdoc)
for e in typedefs:
outfile.write(e.definition)
outfile.write("\n\n")

# write the rest (structures, functions, ...)
for e in filter(lambda x: x.is_documented(), other):
outfile.write("\n\n")
outfile.write(e.to_gtkdoc())
Expand Down

0 comments on commit ed700a9

Please sign in to comment.