|
@@ -1,3 +1,4 @@ |
|
|
|
|
|
from Function import * |
|
|
|
|
|
|
|
|
def process(FILE_IN): |
|
|
def process(FILE_IN): |
|
|
# Read file. |
|
|
# Read file. |
|
@@ -6,17 +7,9 @@ def process(FILE_IN): |
|
|
for line in file: |
|
|
for line in file: |
|
|
lines_in.append(line.rstrip()) |
|
|
lines_in.append(line.rstrip()) |
|
|
|
|
|
|
|
|
# Translate. |
|
|
|
|
|
lines_out = [] |
|
|
|
|
|
|
|
|
|
|
|
isDeclaration = False |
|
|
|
|
|
isDeclarationLine = False |
|
|
|
|
|
isBody = False |
|
|
|
|
|
functionName = None |
|
|
|
|
|
returnType = None |
|
|
|
|
|
argumentNames = [] |
|
|
|
|
|
argumentTypes = [] |
|
|
|
|
|
|
|
|
f = Function() |
|
|
|
|
|
|
|
|
|
|
|
# Translate. |
|
|
for ln in lines_in: |
|
|
for ln in lines_in: |
|
|
ln = ln.rstrip() |
|
|
ln = ln.rstrip() |
|
|
|
|
|
|
|
@@ -24,36 +17,9 @@ def process(FILE_IN): |
|
|
if "#include" in ln: |
|
|
if "#include" in ln: |
|
|
continue |
|
|
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) |
|
|
|
|
|
|
|
|
f.parseLine(ln) |
|
|
|
|
|
if f.isComplete: |
|
|
|
|
|
print("Function ready!") |
|
|
|
|
|
break |
|
|
|
|
|
|
|
|
return "\n".join(lines_out) |
|
|
|
|
|
|
|
|
return f"Debug: {f}" |