monk/monkClass.py

130 lines
3.8 KiB
Python
Raw Normal View History

2013-12-22 18:55:48 +01:00
#!/usr/bin/python
import monkDebug as debug
import monkNode as Node
2013-12-25 23:56:09 +01:00
import monkModule as module
2013-12-22 18:55:48 +01:00
##
## @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
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:
if stack[0] == "template":
debug.debug("find a template class: " + str(stack))
#remove template properties ==> not manage for now ...
2014-09-01 07:07:08 +02:00
propertyTemplate = stack[1:stack.index("class")-1]
propertyTemplate[0] = propertyTemplate[0][1:]
stack = stack[stack.index("class"):]
# TODO : add the template properties back ...
2014-09-01 07:07:08 +02:00
debug.debug("template property : " + str(propertyTemplate))
else:
self.template = []
if len(stack) < 2:
debug.error("Can not parse class 2 : " + str(stack))
return
2013-12-22 18:55:48 +01:00
Node.Node.__init__(self, 'class', stack[1], file, lineNumber, documentation)
self.subList = []
self.access = "private"
# heritage list :
2014-09-01 07:07:08 +02:00
self.templateType = None
self.templateTypeStr = ""
2013-12-22 18:55:48 +01:00
self.inherit = []
if len(stack) == 2:
# just a simple class...
return
2014-09-01 07:07:08 +02:00
# remove template specification:
if stack[2][0] == '<':
# This is a template
for iii in range(0, len(stack)):
if stack[iii] == '>':
self.templateType = stack[2:iii]
stack = stack[:2] + stack[iii+1:]
break;
# TODO : add tpe in rendering
if self.templateType == None:
debug.error("error in parsing class : " + str(stack) + " can not parse template property ...")
else:
copyTemplateType = self.templateType;
self.templateType = []
self.templateTypeStr = "<"
for val in copyTemplateType:
if val[0] == '<':
val = val[1:]
if val != '>':
self.templateType.append(val)
self.templateTypeStr += val + " "
self.templateTypeStr = ">"
2013-12-22 18:55:48 +01:00
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"
for element in list:
if element in ['private', 'protected', 'public']:
access = element
elif element == ',':
pass
else:
self.inherit.append({'access' : access, 'class' : element})
debug.verbose("class : " + self.to_str())
def to_str(self) :
ret = "class " + self.name
2014-09-01 07:07:08 +02:00
ret += self.templateTypeStr
2013-12-22 18:55:48 +01:00
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
2013-12-25 23:56:09 +01:00
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:
2014-09-01 07:07:08 +02:00
debug.verbose(" plop : " + self.name + " " + str(parent) + " " + parent.get_name())
2013-12-25 23:56:09 +01:00
cparent = parent.get_parents()
pass
#heritage = parent.
cparent.append(self.inherit[0])
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.subList != None:
for element in self.subList:
tmpRet = element['node'].get_whith_specific_parrent(parrentName)
if len(tmpRet) != 0:
for tmp in tmpRet:
ret.append(tmp)
return ret
2013-12-22 18:55:48 +01:00