1 # ====- HeaderFile Class for libc function headers -----------*- python -*--==#
3 # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 # See https://llvm.org/LICENSE.txt for license information.
5 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 # ==-------------------------------------------------------------------------==#
11 def __init__(self
, name
):
15 self
.enumerations
= []
19 def add_macro(self
, macro
):
20 self
.macros
.append(macro
)
22 def add_type(self
, type_
):
23 self
.types
.append(type_
)
25 def add_enumeration(self
, enumeration
):
26 self
.enumerations
.append(enumeration
)
28 def add_object(self
, object):
29 self
.objects
.append(object)
31 def add_function(self
, function
):
32 self
.functions
.append(function
)
37 for macro
in self
.macros
:
38 content
.append(f
"{macro}\n")
40 for type_
in self
.types
:
41 content
.append(f
"{type_}")
44 combined_enum_content
= ",\n ".join(
45 str(enum
) for enum
in self
.enumerations
47 content
.append(f
"\nenum {{\n {combined_enum_content},\n}};")
49 content
.append("\n__BEGIN_C_DECLS\n")
52 for function
in self
.functions
:
53 if function
.guard
== None:
54 content
.append(str(function
) + " __NOEXCEPT;")
57 if current_guard
== None:
58 current_guard
= function
.guard
59 content
.append(f
"#ifdef {current_guard}")
60 content
.append(str(function
) + " __NOEXCEPT;")
62 elif current_guard
== function
.guard
:
63 content
.append(str(function
) + " __NOEXCEPT;")
67 content
.append(f
"#endif // {current_guard}")
69 current_guard
= function
.guard
70 content
.append(f
"#ifdef {current_guard}")
71 content
.append(str(function
) + " __NOEXCEPT;")
73 if current_guard
!= None:
75 content
.append(f
"#endif // {current_guard}")
78 for object in self
.objects
:
79 content
.append(str(object))
81 content
.append("\n__END_C_DECLS")
83 content
.append("__END_C_DECLS")
85 return "\n".join(content
)