mirror of
https://github.com/intel/llvm.git
synced 2026-01-25 19:44:38 +08:00
[libc] Elide extra space in hdrgen function declarations (#127287)
When the return type's rendering already doesn't end with an identifier character, such as when it's `T *`, then idiomatic syntax does not include a space before the `(` and arguments.
This commit is contained in:
@@ -81,4 +81,12 @@ class Function:
|
||||
def __str__(self):
|
||||
attrs_str = "".join(f"{attr} " for attr in self.attributes)
|
||||
arguments_str = ", ".join(self.arguments) if self.arguments else "void"
|
||||
return attrs_str + f"{self.return_type} {self.name}({arguments_str})"
|
||||
# The rendering of the return type may look like `int` or it may look
|
||||
# like `int *` (and other examples). For `int`, a space is always
|
||||
# needed to separate the tokens. For `int *`, no whitespace matters to
|
||||
# the syntax one way or the other, but an extra space between `*` and
|
||||
# the function identifier is not the canonical style.
|
||||
type_str = str(self.return_type)
|
||||
if type_str[-1].isalnum() or type_str[-1] == "_":
|
||||
type_str += " "
|
||||
return attrs_str + type_str + self.name + "(" + arguments_str + ")"
|
||||
|
||||
@@ -19,6 +19,8 @@ type_a func(type_b) __NOEXCEPT;
|
||||
|
||||
void gnufunc(type_a) __NOEXCEPT;
|
||||
|
||||
int *ptrfunc(void) __NOEXCEPT;
|
||||
|
||||
__END_C_DECLS
|
||||
|
||||
#endif // LLVM_LIBC_SUBDIR_TEST_H
|
||||
|
||||
@@ -12,3 +12,6 @@ functions:
|
||||
- type: type_a
|
||||
standards:
|
||||
- gnu
|
||||
- name: ptrfunc
|
||||
return_type: int *
|
||||
arguments: []
|
||||
|
||||
Reference in New Issue
Block a user