[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.
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

View File

@ -6,25 +6,8 @@ import monkTools
import re
import codeBB
import collections
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/"
}
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
import monkModule as module
import monkNode as node
def display_doxygen_param(comment, input, output):
@ -134,18 +117,18 @@ def generate_link(element):
def calculate_methode_size(list):
returnSize = 0;
methodeSize = 0;
haveVirtual = False
for element in list:
retType = ""
if element['node'].get_virtual() == True:
retType += 'virtual '
retType += element['node'].get_return_type().to_str()
haveVirtual = True
retType = element['node'].get_return_type().to_str()
tmpLen = len(retType)
if returnSize < tmpLen:
returnSize = tmpLen
tmpLen = len(element['node'].get_name())
if methodeSize < tmpLen:
methodeSize = tmpLen
return [returnSize, methodeSize]
return [returnSize, methodeSize, haveVirtual]
def write_methode(element, namespaceStack, displaySize = None, link = True):
@ -161,18 +144,20 @@ def write_methode(element, namespaceStack, displaySize = None, link = True):
ret += '+ '
else:
ret += ' '
retType = ""
else:
ret += ' '
if element['node'].get_virtual() == True:
retType += 'virtual '
retType += element['node'].get_return_type().to_str()
if retType != "":
retType2 = re.sub("<","&lt;", retType)
retType2 = re.sub(">","&gt;", retType2)
retType2 = display_color(retType2)
ret += retType2
ret += module.display_color('virtual') + ' '
elif displaySize[2] == True:
ret += ' '
raw, decorated = element['node'].get_return_type().to_str_decorated()
if raw != "":
ret += decorated
ret += " "
retType += " "
ret += white_space(displaySize[0] - len(retType)+1)
raw += " "
ret += white_space(displaySize[0] - len(raw)+1)
name = element['node'].get_name()
if link == True:
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:
if first == False:
ret += ',<br/>'
if displaySize[2] == True:
ret += ' '
ret += white_space(displaySize[0] + displaySize[1] +5)
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 != "":
ret += retParam
ret += " "
@ -195,7 +184,7 @@ def write_methode(element, namespaceStack, displaySize = None, link = True):
if element['node'].get_virtual_pure() == True:
ret += ' = 0'
if element['node'].get_constant() == True:
ret += display_color(' const')
ret += module.display_color(' const')
ret += ';'
ret += '<br/>'
@ -216,6 +205,7 @@ def generate_stupid_index_page(outFolder, header, footer, myLutinDoc):
file.close();
def generate_page(outFolder, header, footer, element):
currentPageSite = element.get_doc_website_page()
namespaceStack = element.get_namespace()
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'])
@ -282,16 +272,14 @@ def generate_page(outFolder, header, footer, element):
if element.get_node_type() == 'class':
parent = element.get_parents()
debug.verbose("parrent of " + element.get_name() + " : " + str(parent))
child = None
if len(parent) != 0:
child = module.get_whith_specific_parrent(element.get_displayable_name(), )
if len(parent) != 0 \
or len(child) != 0:
file.write('<h2>Object Hierarchy:<h2>\n')
file.write('<pre>\n');
level = 0
revertList = []
for elemmm in reversed(parent):
revertList.append(elemmm)
revertList.append({'access':'me', 'class':element.get_displayable_name()})
for parentElem in revertList:
parent.append({'access':'me', 'class':element.get_displayable_name()})
for parentElem in parent:
access = ""
if parentElem['access'] == 'public':
access = "+"
@ -299,11 +287,47 @@ def generate_page(outFolder, header, footer, element):
access = "#"
elif parentElem['access'] == 'private':
access = "-"
file.write(white_space(level * 4))
tmpLen = level * 7
if tmpLen > 0:
tmpLen -= 5
file.write(white_space(tmpLen))
if level != 0:
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
# 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');

View File

@ -113,6 +113,34 @@ class Methode(Node.Node):
ret += " const"
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(...);)
## @return True if vitual is present, False otherwise

View File

@ -29,7 +29,6 @@ class Module:
# Name of the module
self.name=moduleName
self.listDocFile = []
self.structureLib = Node.MainNode("library", moduleName)
self.listTutorialFile = []
self.webSite = ""
self.pathParsing = ""
@ -38,13 +37,15 @@ class Module:
self.title = moduleName + " Library"
self.styleHtml = ""
## end of basic INIT ...
if moduleType == 'APPLICATION' \
or moduleType == 'LIBRARY':
self.type=moduleType
if moduleType.upper() == 'APPLICATION':
self.type = 'application'
elif moduleType.upper() == 'LIBRARY':
self.type = "library"
else :
debug.error('for module "%s"' %moduleName)
debug.error(' ==> error : "%s" ' %moduleType)
raise 'Input value error'
self.structureLib = Node.MainNode(self.type, moduleName)
self.originFile = file;
self.originFolder = tools.get_current_path(self.originFile)
@ -172,7 +173,7 @@ class Module:
def generate(self):
debug.info('Generate documantation code : ' + 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:
debug.warning("Generation Documentation ==> return an error for " + self.name)
@ -219,99 +220,13 @@ class Module:
debug.verbose("find childs : " + str(list))
return list
##
## @brief trnsform the classname in a generic link (HTML)
## @param[in] elementName Name of the class requested
## @return [className, link]
##
def get_class_link(self, elementName):
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, ""]
def get_whith_specific_parrent(self, name, appName=None):
if self.structureLib.get_node_type() == "library":
return self.structureLib.get_whith_specific_parrent(name)
if appName != self.structureLib.get_name():
return []
return self.structureLib.get_whith_specific_parrent(name)
##
## @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=[]
@ -375,5 +290,29 @@ def get_element_with_name(type):
if element != None:
debug.debug("we find : " + type + " = " + str(ret) + " " + str(element))
return element
debug.warning("we not find : " + type + " = " + str(ret))
return None
debug.debug("we not find : " + type + " = " + str(ret))
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
import monkDebug as debug
import monkModule as module
accessList = ['private', 'protected', 'public']
@ -52,16 +53,53 @@ class Node():
def get_doc(self):
#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 ""
ret = ""
parent = ""
isFirst = True
for req in self.documenatationCode:
for namesapace in self.namespace:
if isFirst == False:
ret += '\n'
parent += "::"
isFirst = False
ret += req
return ret
parent += namesapace
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):
if access == 'private':
@ -150,7 +188,8 @@ class Node():
if self.moduleLink == None:
return ""
ret = self.moduleLink.get_website()
ret += "/"
if ret[-1] != '/':
ret += '/'
ret += self.get_node_type()
ret += "_"
for name in self.namespace:
@ -237,9 +276,52 @@ class Node():
return ret
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):
def __init__(self, type="library", 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
import monkDebug as debug
import monkType as Type
import monkNode as Node
import monkNode as node
import monkModule as module
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():
def __init__(self, stack=[]):
self.nameBefore = ""
self.name = ""
self.nameAfter = ""
self.const = False # the const xxxxx
self.reference = False
self.constVar = False # the char* const VarName
self.enum = False
self.struct = False
if len(stack) == 0:
# None type
@ -25,25 +47,95 @@ class Type():
if stack[len(stack)-1] == '&':
self.reference = True
stack = stack[:len(stack)-1]
# che k if it start with const ...
# check if it start with const ...
if stack[0] == 'const':
self.const = True
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.nameAfter = ""
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
#debug.info("get type : " + str(stack) + " ==> " +self.name)
def to_str(self) :
ret = ""
if self.const == True:
ret += "const "
if self.enum == True:
ret += "enum "
if self.struct == True:
ret += "struct "
ret += self.nameBefore
ret += self.name
ret += self.nameAfter
if self.reference == True:
ret += " &"
if self.constVar == True:
ret += " const"
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):
def __init__(self):