1# ====-- Function class for libc function headers -------------*- python -*--==# 2# 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 6# 7# ==-------------------------------------------------------------------------==# 8 9 10class Function: 11 def __init__( 12 self, return_type, name, arguments, standards, guard=None, attributes=[] 13 ): 14 self.return_type = return_type 15 self.name = name 16 self.arguments = [ 17 arg if isinstance(arg, str) else arg["type"] for arg in arguments 18 ] 19 self.standards = standards 20 self.guard = guard 21 self.attributes = attributes or "" 22 23 def __str__(self): 24 attributes_str = " ".join(self.attributes) 25 arguments_str = ", ".join(self.arguments) if self.arguments else "void" 26 if attributes_str == "": 27 result = f"{self.return_type} {self.name}({arguments_str})" 28 else: 29 result = f"{attributes_str} {self.return_type} {self.name}({arguments_str})" 30 return result 31