Михаил Капелько 9 months ago
parent
commit
1584571c3e
2 changed files with 33 additions and 3 deletions
  1. +5
    -3
      translator-C++-Swift/Function.py
  2. +28
    -0
      translator-C++-Swift/Type.py

+ 5
- 3
translator-C++-Swift/Function.py View File

@@ -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__()


+ 28
- 0
translator-C++-Swift/Type.py View File

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

Loading…
Cancel
Save