diff --git a/libc/newhdrgen/header.py b/libc/newhdrgen/header.py index 1c227715991c9a..ee28ada4f557c0 100644 --- a/libc/newhdrgen/header.py +++ b/libc/newhdrgen/header.py @@ -57,9 +57,33 @@ def __str__(self): content.append("\n__BEGIN_C_DECLS\n") + current_guard = None for function in self.functions: - content.append(str(function) + "__NOEXCEPT") - content.append("") + if function.guard == None: + content.append(str(function) + "__NOEXCEPT") + content.append("") + else: + if current_guard == None: + current_guard = function.guard + content.append(f"#ifdef {current_guard}") + content.append(str(function) + "__NOEXCEPT") + content.append("") + elif current_guard == function.guard: + content.append(str(function) + "__NOEXCEPT") + content.append("") + else: + content.pop() + content.append(f"#endif // {current_guard}") + content.append("") + current_guard = function.guard + content.append(f"#ifdef {current_guard}") + content.append(str(function) + "__NOEXCEPT") + content.append("") + if current_guard != None: + content.pop() + content.append(f"#endif // {current_guard}") + content.append("") + for object in self.objects: content.append(str(object)) if self.objects: @@ -67,4 +91,4 @@ def __str__(self): else: content.append("__END_C_DECLS") - return "\n".join(content) + return "\n".join(content) \ No newline at end of file