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}')"