-
Notifications
You must be signed in to change notification settings - Fork 1
/
CWDelphiSearchParse.py
148 lines (112 loc) · 3.93 KB
/
CWDelphiSearchParse.py
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/python
import string
import copy
from CWDelphiSearchModel import CWDelphiClass
class CWDelphiSearchParse:
def __init__(self):
self.foundPrivate = False
self.foundPublic = False
self.foundProtected = False
self.foundPublished = False
self.foundClass = False
self.foundConst = False
def SetFlags(self, foundPrivate, foundPublic, foundProtected, foundPublished, foundConst, foundClass):
self.foundPrivate = foundPrivate
self.foundProtected = foundProtected
self.foundPublic = foundPublic
self.foundPublished = foundPublished
self.foundClass = foundClass
self.foundConst = foundConst
def FoundClassTag(self, line):
if "=class" in line.translate(None, string.whitespace).lower():
return True
else:
return False
def SaveFunctions(self, line):
if self.delphiClass != None and len(line.translate(None, string.whitespace).lower()) > 0 and '//' not in line.translate(None, string.whitespace).lower():
if self.foundConst == True:
self.delphiClass.consts.append(line)
return True
if self.foundClass == True:
self.delphiClass.nonFlagedFunctions.append(line)
return True
if self.foundPrivate == True:
self.delphiClass.privateFunctions.append(line)
return True
if self.foundPublic == True:
self.delphiClass.publicFunctions.append(line)
return True
if self.foundProtected == True:
self.delphiClass.protectedFunctions.append(line)
return True
if self.foundPublished == True:
self.delphiClass.publishedFunctions.append(line)
return True
return False
def SaveFlags(self, line):
if "private" in line.lower():
self.SetFlags(True, False, False, False, False, False)
return True
if "public" in line.lower():
self.SetFlags(False, True, False, False, False, False)
return True
if "protected" in line.lower():
self.SetFlags(False, False, True, False, False, False)
return True
if "published" in line.lower():
self.SetFlags(False, False, False, True, False, False)
return True
if line.translate(None, string.whitespace).lower() == "const":
self.SetFlags(False, False, False, False, True, False)
return True
if line.translate(None, string.whitespace).lower() == "type":
self.SetFlags(False, False, False, False, False, False)
return True
if "record" in line.lower():
self.SetFlags(False, False, False, False, False, False)
return True
if self.foundConst == True and ("function" in line.lower() or "procedure" in line.lower()):
self.SetFlags(False, False, False, False, False, True)
return False
def findBetween(self, s, first, last ):
try:
start = s.index( first ) + len( first )
end = s.index( last, start )
return s[start:end]
except ValueError:
return ""
def searchForDependencies(self, foundDelphi):
searchDelphi = list(foundDelphi)
for found in foundDelphi:
for search in searchDelphi:
for foundClass in found.classes:
for searchClass in search.classes:
if foundClass.name == searchClass.superClass:
foundClass.dependencies.append(searchClass.name)
def ParseFile(self, path):
classes = []
self.delphiClass = None
f = open(path)
lines = f.readlines()
f.close()
for line in lines:
if self.FoundClassTag(line) == True:
if self.delphiClass != None:
classes.append(self.delphiClass)
self.delphiClass = CWDelphiClass()
self.delphiClass.name = line.split('=')[0].translate(None, string.whitespace)
self.delphiClass.superClass = self.findBetween(line, "(", ")").translate(None, string.whitespace)
self.SetFlags(False, False, False, False, False, True)
continue
if "end;" in line.lower():
self.SetFlags(False, False, False, False, False, False)
continue
if "implementation" in line.lower():
break
if self.SaveFlags(line) == True:
continue
if self.SaveFunctions(line) == True:
continue
if self.delphiClass != None:
classes.append(self.delphiClass)
return classes