-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathconstructors.py
More file actions
129 lines (95 loc) · 3.42 KB
/
constructors.py
File metadata and controls
129 lines (95 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
###############
# RETROGRADLE #
# BY CURLE #
# 2020 #
###############
# This file allows you to split an MCP joined.exc file up to the MCPConfig files
# constructors.txt, access.txt and exceptions.txt.
# Part seven of eight in the RetroGradle series.
import re
ctrRegStr = "(\.<init>)(\(\S*)(=\S*\|p_i)(\d*)"
exceptionRegStr = "(\(\S*\)\S*)=(\S*)\|"
accessRegStr = "(\S*)\.(\S*)(\(\S*\)\S*)-Access=(\S*)"
def main():
print("Converting exc to MCPConfig Data:")
ctrReg = re.compile(ctrRegStr)
exceptionReg = re.compile(exceptionRegStr)
accessReg = re.compile(accessRegStr)
try:
excFile = open("joined.exc", "r")
constructorsFile = open("constructors.txt", "w")
exceptionsFile = open("exceptions.txt", "w")
accessFile = open("access.txt", "w")
excLines = excFile.readlines()
print("There are " + str(len(excLines)) + " lines of exc")
lineNo = 0
constructorLines = []
exceptionsLines = []
accessLines = []
for excLine in excLines:
lineType = 0
lineNo += 1
constructorLine = []
exceptionsLine = []
accessLine = []
constructorMatches = re.search(ctrReg, excLine)
exceptionsMatches = re.search(exceptionReg, excLine)
accessMatches = re.search(accessReg, excLine)
# If we match ".<init>" we're a constructor.
if isinstance(constructorMatches, re.Match):
# constructors.txt lines are in the form
# SRG CLASS SIGNATURE
# Matches are in the order
# .<init> SIGNATURE =|p_i SRG
# CLASS is line[0]..match0
constructorLine.append(constructorMatches[4])
className = excLine[0:constructorMatches.start(0)]
#print("Processing constructor of class " + className)
constructorLine.append(className)
constructorLine.append(constructorMatches[2])
constructorLineString = " ".join(constructorLine)
constructorLines.append(constructorLineString)
lineType = 1
# if we match (SOMETHING)SOMETHING=SOMETHING|, we're an exception line
if isinstance(exceptionsMatches, re.Match):
# exceptions.txt is in the form
# CLASS/FUNCTION (PARAMS)RETURN EXCEPTION
# Matches are in the order
# (PARAMS)RETURN = EXCEPTION |
matches = exceptionsMatches.groups()
className = excLine[0:exceptionsMatches.start(0)].replace(".", "/")
#print("Processing exception of class " + className + ": " + str(matches))
exceptionsLine.append(className)
exceptionsLine.append(matches[0])
exceptionsLine.append(matches[1])
exceptionsLineStr = " ".join(exceptionsLine)
exceptionsLines.append(exceptionsLineStr)
lineType = 2
if isinstance(accessMatches, re.Match):
# access.txt is in the form
# ACCESS CLASS OBJECT SIGNATURE
# accessMatches is in the form
# CLASS OBJECT SIGNATURE ACCESS
matches = accessMatches.groups()
print("Handling access modifier for " + matches[1] + " to " + matches[3])
accessLine.append(matches[3])
accessLine.append(matches[0])
accessLine.append(matches[1])
accessLine.append(matches[2])
accessLineStr = " ".join(accessLine)
accessLines.append(accessLineStr)
lineType = 3
if lineType == 0:
print("No useful data on line " + str(lineNo))
continue
constructorLines.sort()
constructorsFile.write("\n".join(constructorLines))
exceptionsLines.sort()
exceptionsFile.write("\n".join(exceptionsLines))
accessLines.sort()
accessFile.write("\n".join(accessLines))
finally:
excFile.close()
constructorsFile.close()
accessFile.close()
main()