From 1584571c3e8fbade46d938cfea22eddb72c7aeee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Sun, 24 Mar 2024 23:08:29 +0300 Subject: [PATCH] d --- translator-C++-Swift/Function.py | 8 +++++--- translator-C++-Swift/Type.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 translator-C++-Swift/Type.py diff --git a/translator-C++-Swift/Function.py b/translator-C++-Swift/Function.py index 7d36e91..9088bab 100644 --- a/translator-C++-Swift/Function.py +++ b/translator-C++-Swift/Function.py @@ -1,3 +1,4 @@ +from Type import * class Function: def __init__(self): @@ -6,7 +7,7 @@ class Function: self.isSignature = False self.name = None self.parameters = [] - self.returnValue = None + self.returnType = None self.statements = [] def parseLine(self, ln): @@ -16,7 +17,7 @@ class Function: # Beginning of signature. if ( - self.returnValue is None and + self.returnType is None and self.name is None and lastPart.endswith("(") ): @@ -43,7 +44,8 @@ class Function: lastPart.endswith("(") ): self.name = lastPart[:-1] - self.returnType = ln[:-len(lastPart) - 1] # -1 for space before function name + rawReturnType = ln[:-len(lastPart) - 1] # -1 for space before function name + self.returnType = Type(rawReturnType) def __repr__(self): return self.__str__() diff --git a/translator-C++-Swift/Type.py b/translator-C++-Swift/Type.py new file mode 100644 index 0000000..fda68e1 --- /dev/null +++ b/translator-C++-Swift/Type.py @@ -0,0 +1,28 @@ +class Type: + def __init__(self, s): + # Currently no recursion is allowed, + # so you can't have a dictionary in dictionary. + self.name = None + self.first = None + self.second = None + + # Dictionary. + if s.startswith("std::map"): + self.name = "map" + # Remove prefix and suffix. + prefix = "std::map<" + s = s[len(prefix):] + suffix = ">" + s = s[:-len(suffix)] + # Get map types. + parts = s.split(", ") + self.first = parts[0] + self.second = parts[1] + # By default we treat the type as is. + else: + self.name = s + + def __repr__(self): + return self.__str__() + def __str__(self): + return f"Type(n/f/s: '{self.name}'/'{self.first}'/'{self.second}')"