From d214ac12bbf068ea810f374f77268345be4fafc6 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: Fri, 22 Mar 2024 22:45:49 +0300 Subject: [PATCH] d --- .../__pycache__/process.cpython-37.pyc | Bin 0 -> 979 bytes translator-C++-Swift/process.py | 59 ++++++++++++++++ translator-C++-Swift/translate | 63 ++---------------- 3 files changed, 63 insertions(+), 59 deletions(-) create mode 100644 translator-C++-Swift/__pycache__/process.cpython-37.pyc create mode 100755 translator-C++-Swift/process.py diff --git a/translator-C++-Swift/__pycache__/process.cpython-37.pyc b/translator-C++-Swift/__pycache__/process.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b2e2999f26bf7389c18c26e48f023824628ad6a7 GIT binary patch literal 979 zcmY*Y&rj4q6rSm??Ur^~5sexT8$IBLta~@c5I_E7k z-i^ub4KMx?{29G?@Uq-YyciOrZ+0Qzn|$-;y>I5tH?Qfu<5&pn+xI^~%|Pgf46aOp z#T0?L2|0NaM_KFTpi0`>66N4awHKq!mo%~Y-m+{Z%g zD+4sZ7#&S-p)IKS3az7Uc}62R*8v8gL{M%5%8<7J6DPj~hAKaETiCKfZWBe=hXzfL zT*#W1g4|pGg)4Hi5wiJ&bXA3POljf=j6F>|Md@-ae-+k( z2`L)3U_4YcSlt+kg-zAOiuBmVl`*GINw1CfSxOaR8{frM7@AU1=pCros^gI#iN7&T T16P>O+X=~{;DuE13xNIsA3h2w literal 0 HcmV?d00001 diff --git a/translator-C++-Swift/process.py b/translator-C++-Swift/process.py new file mode 100755 index 0000000..76fc475 --- /dev/null +++ b/translator-C++-Swift/process.py @@ -0,0 +1,59 @@ + +def process(FILE_IN): + # Read file. + lines_in = [] + with open(FILE_IN) as file: + for line in file: + lines_in.append(line.rstrip()) + + # Translate. + lines_out = [] + + isDeclaration = False + isDeclarationLine = False + isBody = False + functionName = None + returnType = None + argumentNames = [] + argumentTypes = [] + + for ln in lines_in: + ln = ln.rstrip() + + # Ignore includes. + if "#include" in ln: + continue + + parts = ln.split(" ") + count = len(parts) + lastPart = parts[count - 1] + if not isBody and lastPart.endswith("("): + isDeclaration = True + isDeclarationLine = True + isBody = False + + # End of function arguments. + if not isDeclarationLine and not isBody and ln.endswith(") {"): + isDeclaration = False + isBody = True + + # Function argument. + if ( + isDeclaration and + not isDeclarationLine and + not isBody and + not ln.endswith(") {") + ): + print(f"TODO argument: '{ln}'") + + # Function return type and function name. + if isDeclaration and lastPart.endswith("("): + functionName = lastPart[:-1] + returnType = ln[:-len(lastPart) - 1] # -1 for space before function name + print(f"Function name: '{functionName}'") + print(f"Return type: '{returnType}'") + isDeclarationLine = False + + lines_out.append(ln) + + return "\n".join(lines_out) diff --git a/translator-C++-Swift/translate b/translator-C++-Swift/translate index a26c623..a07f23d 100755 --- a/translator-C++-Swift/translate +++ b/translator-C++-Swift/translate @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import os import sys +from process import * DIR = os.path.dirname(os.path.realpath(sys.argv[0])) @@ -11,62 +12,6 @@ if len(sys.argv) < 2: FILE_IN = sys.argv[1] -# Read file. -lines_in = [] -with open(FILE_IN) as file: - for line in file: - lines_in.append(line.rstrip()) - -# Translate. -lines_out = [] - -isDeclaration = False -isDeclarationLine = False -isBody = False -functionName = None -returnType = None -argumentNames = [] -argumentTypes = [] - -for ln in lines_in: - ln = ln.lstrip() - # Ignore includes. - if "#include" in ln: - continue - - parts = ln.split(" ") - count = len(parts) - lastPart = parts[count - 1] - if not isBody and lastPart.endswith("("): - isDeclaration = True - isDeclarationLine = True - isBody = False - - # End of function arguments. - if not isDeclarationLine and not isBody and ln.endswith(") {"): - isDeclaration = False - isBody = True - - # Function argument. - if ( - isDeclaration and - not isDeclarationLine and - not isBody and - not ln.endswith(") {") - ): - print(f"TODO argument: '{ln}'") - - # Function return type and function name. - if isDeclaration and lastPart.endswith("("): - functionName = lastPart[:-1] - returnType = ln[:-len(lastPart) - 1] # -1 for space before function name - print(f"Function name: '{functionName}'") - print(f"Return type: '{returnType}'") - isDeclarationLine = False - - lines_out.append(ln) - - - -# Output result. -print(lines_out) +# Translate file. +out = process(FILE_IN) +print(out)