[DEV] 90% of the type display and heritage copy doc

This commit is contained in:
Edouard DUPIN 2013-12-26 21:17:20 +01:00
parent 7370fb2ac9
commit 7a9c47e1a9
6 changed files with 332 additions and 154 deletions

View File

@ -72,6 +72,19 @@ class Class(Node.Node):
#heritage = parent. #heritage = parent.
cparent.append(self.inherit[0]) cparent.append(self.inherit[0])
return cparent 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

View File

@ -6,25 +6,8 @@ import monkTools
import re import re
import codeBB import codeBB
import collections import collections
import monkModule as module
global_class_link = { import monkNode as node
"std::string" : "http://www.cplusplus.com/reference/string/string/",
"std::u16string" : "http://www.cplusplus.com/reference/string/u16string/",
"std::u32string" : "http://www.cplusplus.com/reference/string/u32string/",
"std::wstring" : "http://www.cplusplus.com/reference/string/wstring/",
"std::vector" : "http://www.cplusplus.com/reference/vector/vector/"
}
def display_color(val):
# storage keyword :
val = re.sub(r'(inline|const|class|virtual|private|public|protected|friend|const|extern|auto|register|static|volatile|typedef|struct|union|enum)',
r'<span class="code-storage-keyword">\1</span>',
val)
# type :
val = re.sub(r'(bool|BOOL|char(16_t|32_t)?|double|float|u?int(8|16|32|64|128)?(_t)?|long|short|signed|size_t|unsigned|void|(I|U)(8|16|32|64|128))',
r'<span class="code-type">\1</span>',
val)
return val
def display_doxygen_param(comment, input, output): def display_doxygen_param(comment, input, output):
@ -134,18 +117,18 @@ def generate_link(element):
def calculate_methode_size(list): def calculate_methode_size(list):
returnSize = 0; returnSize = 0;
methodeSize = 0; methodeSize = 0;
haveVirtual = False
for element in list: for element in list:
retType = ""
if element['node'].get_virtual() == True: if element['node'].get_virtual() == True:
retType += 'virtual ' haveVirtual = True
retType += element['node'].get_return_type().to_str() retType = element['node'].get_return_type().to_str()
tmpLen = len(retType) tmpLen = len(retType)
if returnSize < tmpLen: if returnSize < tmpLen:
returnSize = tmpLen returnSize = tmpLen
tmpLen = len(element['node'].get_name()) tmpLen = len(element['node'].get_name())
if methodeSize < tmpLen: if methodeSize < tmpLen:
methodeSize = tmpLen methodeSize = tmpLen
return [returnSize, methodeSize] return [returnSize, methodeSize, haveVirtual]
def write_methode(element, namespaceStack, displaySize = None, link = True): def write_methode(element, namespaceStack, displaySize = None, link = True):
@ -161,18 +144,20 @@ def write_methode(element, namespaceStack, displaySize = None, link = True):
ret += '+ ' ret += '+ '
else: else:
ret += ' ' ret += ' '
retType = "" else:
ret += ' '
if element['node'].get_virtual() == True: if element['node'].get_virtual() == True:
retType += 'virtual ' ret += module.display_color('virtual') + ' '
retType += element['node'].get_return_type().to_str() elif displaySize[2] == True:
if retType != "": ret += ' '
retType2 = re.sub("<","&lt;", retType)
retType2 = re.sub(">","&gt;", retType2) raw, decorated = element['node'].get_return_type().to_str_decorated()
retType2 = display_color(retType2) if raw != "":
ret += retType2 ret += decorated
ret += " " ret += " "
retType += " " raw += " "
ret += white_space(displaySize[0] - len(retType)+1) ret += white_space(displaySize[0] - len(raw)+1)
name = element['node'].get_name() name = element['node'].get_name()
if link == True: if link == True:
ret += '<a class="code-function" href="#' + str(element['node'].get_uid()) + '">' + name + '</a>' ret += '<a class="code-function" href="#' + str(element['node'].get_uid()) + '">' + name + '</a>'
@ -184,9 +169,13 @@ def write_methode(element, namespaceStack, displaySize = None, link = True):
for param in listParam: for param in listParam:
if first == False: if first == False:
ret += ',<br/>' ret += ',<br/>'
if displaySize[2] == True:
ret += ' '
ret += white_space(displaySize[0] + displaySize[1] +5) ret += white_space(displaySize[0] + displaySize[1] +5)
first = False first = False
retParam = display_color(param.get_type().to_str()) typeNoDecoration, typeDecorated = param.get_type().to_str_decorated()
#retParam = module.display_color(param.get_type().to_str())
retParam = typeDecorated
if retParam != "": if retParam != "":
ret += retParam ret += retParam
ret += " " ret += " "
@ -195,7 +184,7 @@ def write_methode(element, namespaceStack, displaySize = None, link = True):
if element['node'].get_virtual_pure() == True: if element['node'].get_virtual_pure() == True:
ret += ' = 0' ret += ' = 0'
if element['node'].get_constant() == True: if element['node'].get_constant() == True:
ret += display_color(' const') ret += module.display_color(' const')
ret += ';' ret += ';'
ret += '<br/>' ret += '<br/>'
@ -216,6 +205,7 @@ def generate_stupid_index_page(outFolder, header, footer, myLutinDoc):
file.close(); file.close();
def generate_page(outFolder, header, footer, element): def generate_page(outFolder, header, footer, element):
currentPageSite = element.get_doc_website_page()
namespaceStack = element.get_namespace() namespaceStack = element.get_namespace()
if element.get_node_type() in ['library', 'application', 'namespace', 'class', 'struct', 'enum', 'union']: if element.get_node_type() in ['library', 'application', 'namespace', 'class', 'struct', 'enum', 'union']:
listBase = element.get_all_sub_type(['library', 'application', 'namespace', 'class', 'struct', 'enum', 'union']) listBase = element.get_all_sub_type(['library', 'application', 'namespace', 'class', 'struct', 'enum', 'union'])
@ -282,16 +272,14 @@ def generate_page(outFolder, header, footer, element):
if element.get_node_type() == 'class': if element.get_node_type() == 'class':
parent = element.get_parents() parent = element.get_parents()
debug.verbose("parrent of " + element.get_name() + " : " + str(parent)) debug.verbose("parrent of " + element.get_name() + " : " + str(parent))
child = None child = module.get_whith_specific_parrent(element.get_displayable_name(), )
if len(parent) != 0: if len(parent) != 0 \
or len(child) != 0:
file.write('<h2>Object Hierarchy:<h2>\n') file.write('<h2>Object Hierarchy:<h2>\n')
file.write('<pre>\n'); file.write('<pre>\n');
level = 0 level = 0
revertList = [] parent.append({'access':'me', 'class':element.get_displayable_name()})
for elemmm in reversed(parent): for parentElem in parent:
revertList.append(elemmm)
revertList.append({'access':'me', 'class':element.get_displayable_name()})
for parentElem in revertList:
access = "" access = ""
if parentElem['access'] == 'public': if parentElem['access'] == 'public':
access = "+" access = "+"
@ -299,11 +287,47 @@ def generate_page(outFolder, header, footer, element):
access = "#" access = "#"
elif parentElem['access'] == 'private': elif parentElem['access'] == 'private':
access = "-" access = "-"
file.write(white_space(level * 4)) tmpLen = level * 7
if tmpLen > 0:
tmpLen -= 5
file.write(white_space(tmpLen))
if level != 0: if level != 0:
file.write('+--> ') file.write('+--> ')
file.write(access + parentElem['class'] + '<br/>') file.write(access)
if parentElem['access'] == 'me':
file.write(parentElem['class'])
else:
classPointer = module.get_element_with_name(parentElem['class'])
if classPointer != None:
link = classPointer.get_doc_website_page()
link = node.get_doc_website_page_relative(currentPageSite, link)
file.write('<a href="' + link + '">')
file.write(parentElem['class'])
if classPointer != None:
file.write('</a>')
file.write('<br/>')
level += 1 level += 1
# all child not in application :
for childElem in child:
tmpLen = level * 7
if tmpLen > 0:
tmpLen -= 5
file.write(white_space(tmpLen))
if level != 0:
file.write('+--> ')
classPointer = module.get_element_with_name(childElem)
if classPointer != None:
link = classPointer.get_doc_website_page()
link = node.get_doc_website_page_relative(currentPageSite, link)
file.write('<a href="' + link + '">')
file.write(childElem)
if classPointer != None:
file.write('</a>')
file.write('<br/>')
file.write('</pre>\n'); file.write('</pre>\n');

View File

@ -113,6 +113,34 @@ class Methode(Node.Node):
ret += " const" ret += " const"
return ret return ret
def to_str_decorated(self):
ret = ""
retDecorated = ""
if self.virtual == True:
ret += "virtual "
retDecorated += module.display_color("virtual") + " "
if self.static == True:
ret += "static "
retDecorated += module.display_color("static") + " "
if self.inline == True:
ret += "inline "
retDecorated += module.display_color("inline") + " "
raw, decorated = self.returnType.to_str_decorated()
ret += raw
retDecorated += decorated
ret += " "
ret += self.name
ret += "("
# ...
ret += ")"
if self.virtualPure == True:
ret += " = 0"
retDecorated += " = 0"
if self.const == True:
ret += " const"
retDecorated += " " + module.display_color("const")
return [ret, retDecorated]
## ##
## @brief Get the status of the virtual function ( virtual XXX(...);) ## @brief Get the status of the virtual function ( virtual XXX(...);)
## @return True if vitual is present, False otherwise ## @return True if vitual is present, False otherwise

View File

@ -29,7 +29,6 @@ class Module:
# Name of the module # Name of the module
self.name=moduleName self.name=moduleName
self.listDocFile = [] self.listDocFile = []
self.structureLib = Node.MainNode("library", moduleName)
self.listTutorialFile = [] self.listTutorialFile = []
self.webSite = "" self.webSite = ""
self.pathParsing = "" self.pathParsing = ""
@ -38,13 +37,15 @@ class Module:
self.title = moduleName + " Library" self.title = moduleName + " Library"
self.styleHtml = "" self.styleHtml = ""
## end of basic INIT ... ## end of basic INIT ...
if moduleType == 'APPLICATION' \ if moduleType.upper() == 'APPLICATION':
or moduleType == 'LIBRARY': self.type = 'application'
self.type=moduleType elif moduleType.upper() == 'LIBRARY':
self.type = "library"
else : else :
debug.error('for module "%s"' %moduleName) debug.error('for module "%s"' %moduleName)
debug.error(' ==> error : "%s" ' %moduleType) debug.error(' ==> error : "%s" ' %moduleType)
raise 'Input value error' raise 'Input value error'
self.structureLib = Node.MainNode(self.type, moduleName)
self.originFile = file; self.originFile = file;
self.originFolder = tools.get_current_path(self.originFile) self.originFolder = tools.get_current_path(self.originFile)
@ -172,7 +173,7 @@ class Module:
def generate(self): def generate(self):
debug.info('Generate documantation code : ' + self.name) debug.info('Generate documantation code : ' + self.name)
destFolder = "out/doc/" + self.name + '/' destFolder = "out/doc/" + self.name + '/'
#tools.remove_folder_and_sub_folder(target.get_doc_folder(self.name)); tools.remove_folder_and_sub_folder(destFolder);
if monkHtml.generate(self, destFolder) == False: if monkHtml.generate(self, destFolder) == False:
debug.warning("Generation Documentation ==> return an error for " + self.name) debug.warning("Generation Documentation ==> return an error for " + self.name)
@ -219,99 +220,13 @@ class Module:
debug.verbose("find childs : " + str(list)) debug.verbose("find childs : " + str(list))
return list return list
## def get_whith_specific_parrent(self, name, appName=None):
## @brief trnsform the classname in a generic link (HTML) if self.structureLib.get_node_type() == "library":
## @param[in] elementName Name of the class requested return self.structureLib.get_whith_specific_parrent(name)
## @return [className, link] if appName != self.structureLib.get_name():
## return []
def get_class_link(self, elementName): return self.structureLib.get_whith_specific_parrent(name)
if elementName == "const" \
or elementName == "enum" \
or elementName == "void" \
or elementName == "char" \
or elementName == "char32_t" \
or elementName == "float" \
or elementName == "double" \
or elementName == "bool" \
or elementName == "int8_t" \
or elementName == "uint8_t" \
or elementName == "int16_t" \
or elementName == "uint16_t" \
or elementName == "int32_t" \
or elementName == "uint32_t" \
or elementName == "int64_t" \
or elementName == "uint64_t" \
or elementName == "int" \
or elementName == "T" \
or elementName == "CLASS_TYPE" \
or elementName[:5] == "std::" \
or elementName[:6] == "appl::" \
or elementName == "&" \
or elementName == "*" \
or elementName == "**":
return [elementName, ""]
if elementName in self.listClass.keys():
link = elementName.replace(":","_") + ".html"
return [elementName, link]
elif elementName in self.listEnum.keys():
link = elementName.replace(":","_") + ".html"
return [elementName, link]
#else:
# return self.target.doc_get_link(elementName)
return [elementName, ""]
##
## @brief trnsform the classname in a generic link (HTML) (external access ==> from target)
## @param[in] elementName Name of the class requested
## @return [className, link]
##
def get_class_link_from_target(self, elementName, target):
# reject when auto call :
if self.target != None:
return [elementName, ""]
# search in local list :
if elementName in self.listClass.keys():
link = elementName.replace(":","_") + ".html"
if target.get_build_mode() == "debug":
return [elementName, "../" + self.moduleName + "/" + link]
elif self.webSite != "":
return [elementName, self.webSite + "/" + link]
elif elementName in self.listEnum.keys():
link = elementName.replace(":","_") + ".html"
if target.get_build_mode() == "debug":
return [elementName, "../" + self.moduleName + "/" + link]
elif self.webSite != "":
return [elementName, self.webSite + "/" + link]
# did not find :
return [elementName, ""]
##
## @brief Get link on a class or an enum in all the subclasses
## @param[in] name of the class
## @return [real element name, link on it]
##
def doc_get_link(self, target, elementName):
if self.documentation == None:
return [elementName, ""]
return self.documentation.get_class_link_from_target(elementName, target);
def display(self, target):
print '-----------------------------------------------'
print ' package : "' + self.name + '"'
print '-----------------------------------------------'
print ' type:"%s"' %self.type
print ' file:"%s"' %self.originFile
print ' folder:"%s"' %self.originFolder
self.print_list('local_path',self.local_path)
moduleList=[] moduleList=[]
@ -375,5 +290,29 @@ def get_element_with_name(type):
if element != None: if element != None:
debug.debug("we find : " + type + " = " + str(ret) + " " + str(element)) debug.debug("we find : " + type + " = " + str(ret) + " " + str(element))
return element return element
debug.warning("we not find : " + type + " = " + str(ret)) debug.debug("we not find : " + type + " = " + str(ret))
return None return None
def get_whith_specific_parrent(name, appName=None):
global moduleList
ret = []
for mod in moduleList:
tmpRet = mod['node'].get_whith_specific_parrent(name, appName)
if len(tmpRet) != 0:
for tmp in tmpRet:
ret.append(tmp)
return ret
def display_color(val):
# storage keyword :
val = re.sub(r'(inline|const|class|virtual|private|public|protected|friend|const|extern|auto|register|static|volatile|typedef|struct|union|enum)',
r'<span class="code-storage-keyword">\1</span>',
val)
# type :
val = re.sub(r'(bool|BOOL|char(16_t|32_t)?|double|float|u?int(8|16|32|64|128)?(_t)?|long|short|signed|size_t|unsigned|void|(I|U)(8|16|32|64|128))',
r'<span class="code-type">\1</span>',
val)
return val

View File

@ -1,5 +1,6 @@
#!/usr/bin/python #!/usr/bin/python
import monkDebug as debug import monkDebug as debug
import monkModule as module
accessList = ['private', 'protected', 'public'] accessList = ['private', 'protected', 'public']
@ -52,16 +53,53 @@ class Node():
def get_doc(self): def get_doc(self):
#debug.info(str(self.doc)) #debug.info(str(self.doc))
if self.documenatationCode== None: if len(self.documenatationCode) > 0:
ret = ""
isFirst = True
for req in self.documenatationCode:
if isFirst == False:
ret += '\n'
isFirst = False
ret += req
return ret
#try to get previous element :
if len(self.namespace) == 0:
return "" return ""
ret = "" parent = ""
isFirst = True isFirst = True
for req in self.documenatationCode: for namesapace in self.namespace:
if isFirst == False: if isFirst == False:
ret += '\n' parent += "::"
isFirst = False isFirst = False
ret += req parent += namesapace
return ret element = module.get_element_with_name(parent)
if element == None:
return ""
if element.get_node_type() != 'class':
return ""
parents = element.get_parents()
if len(parents) == 0:
return ""
for myParent in reversed(parents):
element = module.get_element_with_name(myParent['class'])
if element == None:
continue
heveMethode, pointerMethode = element.have_methode(self.name)
if heveMethode == False:
continue
if len(pointerMethode.documenatationCode) != 0:
return pointerMethode.get_doc()
return ""
def get_lib_name(self):
if self.moduleLink == None:
return None
return self.moduleLink.get_base_doc_node().get_name()
def debug_display(self, level=0, access = None): def debug_display(self, level=0, access = None):
if access == 'private': if access == 'private':
@ -150,7 +188,8 @@ class Node():
if self.moduleLink == None: if self.moduleLink == None:
return "" return ""
ret = self.moduleLink.get_website() ret = self.moduleLink.get_website()
ret += "/" if ret[-1] != '/':
ret += '/'
ret += self.get_node_type() ret += self.get_node_type()
ret += "_" ret += "_"
for name in self.namespace: for name in self.namespace:
@ -237,9 +276,52 @@ class Node():
return ret return ret
return None return None
def get_whith_specific_parrent(self, parrentName):
ret = []
# 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
def have_methode(self, methodeName):
if self.subList != None:
for element in self.subList:
if element['node'].get_node_type() != 'methode':
continue
if element['access'] == "private":
continue
if element['node'].get_virtual() == False:
continue
if element['node'].get_name() == methodeName:
return [True, element['node']]
return [False, None]
class MainNode(Node): class MainNode(Node):
def __init__(self, type="library", name=""): def __init__(self, type="library", name=""):
Node.__init__(self, type, name) Node.__init__(self, type, name)
self.subList = [] self.subList = []
def get_doc_website_page_relative(base, dest):
realBase = ""
tmpBase = ""
lastFolder = ""
for element in base:
tmpBase += element
if element == '/':
realBase += tmpBase
lastFolder = tmpBase
tmpBase = ""
if dest[:len(realBase)] == realBase:
return dest[len(realBase):]
#debug.info(dest[:len(realBase)-len(lastFolder)] + "==" + realBase[:-len(lastFolder)])
if dest[:len(realBase)-len(lastFolder)] == realBase[:-len(lastFolder)]:
return '../' + dest[len(realBase)-len(lastFolder):]
return dest

View File

@ -1,15 +1,37 @@
#!/usr/bin/python #!/usr/bin/python
import monkDebug as debug import monkDebug as debug
import monkType as Type import monkType as Type
import monkNode as Node import monkNode as node
import monkModule as module
import re import re
global_basic_type = ['void', 'bool', \
'char', 'char8_t', 'char16_t', 'char32_t', \
'float', 'double', \
'int', 'unsigned int', 'short', 'unsigned short', 'long', 'unsigned long', \
'int8_t', 'int16_t', 'int32_t', 'int64_t', 'int128_t', \
'uint8_t', 'uint16_t', 'uint32_t', 'uint64_t', 'uint128_t', \
'T', 'CLASS_TYPE']
global_class_link = {
"std::string" : "http://www.cplusplus.com/reference/string/string/",
"std::u16string" : "http://www.cplusplus.com/reference/string/u16string/",
"std::u32string" : "http://www.cplusplus.com/reference/string/u32string/",
"std::wstring" : "http://www.cplusplus.com/reference/string/wstring/",
"std::vector" : "http://www.cplusplus.com/reference/vector/vector/"
}
class Type(): class Type():
def __init__(self, stack=[]): def __init__(self, stack=[]):
self.nameBefore = ""
self.name = "" self.name = ""
self.nameAfter = ""
self.const = False # the const xxxxx self.const = False # the const xxxxx
self.reference = False self.reference = False
self.constVar = False # the char* const VarName self.constVar = False # the char* const VarName
self.enum = False
self.struct = False
if len(stack) == 0: if len(stack) == 0:
# None type # None type
@ -25,25 +47,95 @@ class Type():
if stack[len(stack)-1] == '&': if stack[len(stack)-1] == '&':
self.reference = True self.reference = True
stack = stack[:len(stack)-1] stack = stack[:len(stack)-1]
# che k if it start with const ... # check if it start with const ...
if stack[0] == 'const': if stack[0] == 'const':
self.const = True self.const = True
stack = stack[1:] stack = stack[1:]
# check if it start with enum & struct ...
if stack[0] == 'enum':
self.enum = True
stack = stack[1:]
if stack[0] == 'struct':
self.struct = True
stack = stack[1:]
self.nameBefore = ""
self.name = "" self.name = ""
self.nameAfter = ""
for element in stack: for element in stack:
if self.nameAfter != "":
self.nameAfter += element
continue
if element[0] in ['*', '&', '<']:
if self.name == "":
self.nameBefore += element
continue
else:
self.nameAfter += element
continue
self.name += element self.name += element
#debug.info("get type : " + str(stack) + " ==> " +self.name)
def to_str(self) : def to_str(self) :
ret = "" ret = ""
if self.const == True: if self.const == True:
ret += "const " ret += "const "
if self.enum == True:
ret += "enum "
if self.struct == True:
ret += "struct "
ret += self.nameBefore
ret += self.name ret += self.name
ret += self.nameAfter
if self.reference == True: if self.reference == True:
ret += " &" ret += " &"
if self.constVar == True: if self.constVar == True:
ret += " const" ret += " const"
return ret return ret
def to_str_decorated(self) :
global global_basic_type
global global_class_link
ret = ""
retDecorated = ""
if self.const == True:
ret += "const "
retDecorated += module.display_color("const") + " "
if self.enum == True:
ret += "enum "
retDecorated += module.display_color("enum") + " "
if self.struct == True:
ret += "struct "
retDecorated += module.display_color("struct") + " "
ret += self.nameBefore
ret += self.name
ret += self.nameAfter
retDecorated += self.nameBefore
element = module.get_element_with_name(self.name)
if element == None:
if self.name in global_basic_type:
retDecorated += '<span class="code-type" >' + self.name + '</span>'
elif self.name in global_class_link.keys():
retDecorated += '<a class="code-type" href="' + global_class_link[self.name] + '">' + self.name + '</a>'
else:
retDecorated += self.name
else:
currentPageSite = element.get_doc_website_page()
link = element.get_doc_website_page()
link = node.get_doc_website_page_relative(currentPageSite, link)
retDecorated += '<a class="code-type" href="' + link + '">'
retDecorated += self.name
retDecorated += '</a>'
retDecorated += re.sub(">","&gt;", re.sub("<","&lt;", self.nameAfter))
if self.reference == True:
ret += " &"
retDecorated += " &"
if self.constVar == True:
ret += " const"
retDecorated += " " + module.display_color("const")
return [ret, retDecorated]
class TypeVoid(Type): class TypeVoid(Type):
def __init__(self): def __init__(self):