| 49 | return ''; |
| 50 | |
| 51 | class F(Member): |
| 52 | def __init__(self, returnValue, name, *args): |
| 53 | """ |
| 54 | A function has a name, a return value, and arguments. Each argument, |
| 55 | is a tuple whose first entry is the argument name, and the second |
| 56 | one its type. |
| 57 | |
| 58 | Note that types are not given using names ("int", "bool", etc), but |
| 59 | values of the type ("1" for an int, "true" or "false" for a boolean, |
| 60 | "new X()" for class X, etc). |
| 61 | """ |
| 62 | Member.__init__(self, name) |
| 63 | |
| 64 | self._return_value = returnValue |
| 65 | self._args = args |
| 66 | |
| 67 | def print(self): |
| 68 | if self.name() != '': |
| 69 | # This function is not a member, no need to assign it to an object |
| 70 | print(self.valueToAssign()) |
| 71 | else: |
| 72 | Member.print(self) |
| 73 | |
| 74 | def valueToAssign(self): |
| 75 | # Define the function |
| 76 | return 'function %s(%s) { return %s; }' % ( |
| 77 | self.name(), |
| 78 | ', '.join([arg[0] for arg in self._args]), |
| 79 | self._return_value |
| 80 | ) |
| 81 | |
| 82 | def valueAfterAssignation(self): |
| 83 | # Call it, so that its parameters have the correct type |
| 84 | return '%s(%s);' % ( |
| 85 | self.fullName(), |
| 86 | ', '.join([arg[1] for arg in self._args]) |
| 87 | ) |
| 88 | |
| 89 | class Var(Member): |
| 90 | def __init__(self, type, name): |