-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonkClass.py
166 lines (154 loc) · 4.63 KB
/
monkClass.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/bin/python
import monkDebug as debug
import monkNode as Node
import monkModule as module
##
## @brief transform template descrption in one element.
## @param[in] list of elements. ex : 'public', 'ewol::classee', '<', 'plop', '<', 'uint8_t', ',', 'int32_t', '>', '>'
## @return a simplify list. ex : 'public', 'ewol::classee<plop<uint8_t,int32_t>>'
##
def concatenate_template(list):
# TODO ...
return list
def splitList(list):
base = []
out = []
for elem in list:
if elem == ",":
out.append(base)
base = []
else:
base.append(elem)
if len(base) != 0:
out.append(base)
base = []
return out
class Class(Node.Node):
def __init__(self, stack=[], file="", lineNumber=0, documentation=[]):
# check input :
if len(stack) < 2:
debug.error("Can not parse class : " + str(stack))
return
#check if it is a template class:
templateDeclatation = []
if stack[0] == "template":
debug.debug("find a template class: " + str(stack))
#remove template properties ==> not manage for now ...
idEnd = 2
level = 1
for tmpClassElem in stack[2:]:
if tmpClassElem[0] == '<':
level+=1
elif tmpClassElem[0] == '>':
level-=1
if level == 0:
break
idEnd+=1
propertyTemplate = stack[1:idEnd]
propertyTemplate[0] = propertyTemplate[0][1:]
templateDeclatation = splitList(propertyTemplate)
stack = stack[idEnd+1:]
# TODO : add the template properties back ...
debug.debug("template property : " + str(templateDeclatation))
if len(stack) < 2:
debug.error("Can not parse class 2 : " + str(stack))
return
Node.Node.__init__(self, 'class', stack[1], file, lineNumber, documentation)
self.template = templateDeclatation
self.sub_list = []
self.access = "private"
# heritage list :
self.template_type = None
self.template_type_str = ""
self.inherit = []
if len(stack) == 2:
# just a simple class...
return
# remove template specification:
if stack[2][0] == '<':
# This is a template
for iii in range(0, len(stack)):
if stack[iii] == '>':
self.template_type = stack[2:iii]
stack = stack[:2] + stack[iii+1:]
break;
# TODO : add tpe in rendering
if self.template_type == None:
debug.error("error in parsing class : " + str(stack) + " can not parse template property ...")
else:
copytemplate_type = self.template_type;
self.template_type = []
self.template_type_str = "<"
for val in copytemplate_type:
if val[0] == '<':
val = val[1:]
if val != '>':
self.template_type.append(val)
self.template_type_str += val + " "
self.template_type_str = ">"
if len(stack) == 3:
debug.error("error in parsing class : " + str(stack))
return
if stack[2] != ':':
debug.error("error in parsing class : " + str(stack) + " missing ':' at the 3rd position ...")
list = concatenate_template(stack[3:])
debug.verbose("inherit : " + str(list))
access = "private"
classProperty = []
for element in list:
if element in ['private', 'protected', 'public']:
access = element
elif element == ',':
concatenate = ""
for classProp in classProperty:
concatenate += classProp
self.inherit.append({'access' : access, 'class' : concatenate})
classProperty = []
else:
classProperty.append(element)
if len(classProperty) != 0:
concatenate = ""
for classProp in classProperty:
concatenate += classProp
self.inherit.append({'access' : access, 'class' : concatenate})
classProperty = []
debug.verbose("class : " + self.to_str())
def to_str(self) :
ret = "class " + self.name
ret += self.template_type_str
if len(self.inherit) != 0 :
ret += " : "
isFirst = True
for element in self.inherit:
if isFirst == False:
ret += ", "
isFirst = False
ret += element['access'] + " " + element['class']
ret += " { ... };"
return ret
def get_parents(self):
if len(self.inherit) == 0:
return []
# note this ony get the first parent ...
parent = module.get_element_with_name(self.inherit[0]['class'])
cparent = []
if parent != None:
debug.verbose("Prent : " + self.name + " " + str(parent) + " " + parent.get_name())
cparent = parent.get_parents()
pass
#heritage = parent.
cparent.append(self.inherit)
return cparent
def get_whith_specific_parrent(self, parrentName):
ret = []
for parrent in self.inherit:
if parrentName == self.inherit[0]['class']:
ret.append(self.get_displayable_name())
# set for all sub elements ...
if self.sub_list != None:
for element in self.sub_list:
tmpRet = element['node'].get_whith_specific_parrent(parrentName)
if len(tmpRet) != 0:
for tmp in tmpRet:
ret.append(tmp)
return ret