Debian Codegraph @

libc/newhdrgen/class_implementation/classes/function.py

raw
1 #!/usr/bin/env python
2 #
3 # ====-- Function class for libc function headers -------------*- python -*--==#
4 #
5 # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
6 # See https://llvm.org/LICENSE.txt for license information.
7 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 #
9 # ==-------------------------------------------------------------------------==#
10
11
12 class Function:
13 def __init__(
14 self, return_type, name, arguments, standards, guard=None, attributes=[]
15 ):
16 self.return_type = return_type
17 self.name = name
18 self.arguments = [
19 arg if isinstance(arg, str) else arg["type"] for arg in arguments
20 ]
21 self.standards = standards
22 self.guard = guard
23 self.attributes = attributes or ""
24
25 def __str__(self):
26 attributes_str = " ".join(self.attributes)
27 arguments_str = ", ".join(self.arguments)
28 if attributes_str == "":
29 result = f"{self.return_type} {self.name}({arguments_str})"
30 else:
31 result = f"{attributes_str} {self.return_type} {self.name}({arguments_str})"
32 return result