From 13d1eb1cc6ca1c66bc98206c913d7f141e5d874c Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Mon, 23 Dec 2013 21:00:43 +0100 Subject: [PATCH] [DEV] better display of operator and some other special case --- .gitignore | 1 + README.md | 59 +++++++++++++++++++++++++++++++++++ licence_BSD.txt | 32 +++++++++++++++++++ monk.py | 2 +- monkHtml.py | 83 ++++++++----------------------------------------- monkMethode.py | 18 ++++++----- monkParse.py | 16 +++++++--- monkVariable.py | 22 ++++++------- 8 files changed, 136 insertions(+), 97 deletions(-) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 licence_BSD.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7e99e36 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.pyc \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..9c9f262 --- /dev/null +++ b/README.md @@ -0,0 +1,59 @@ +MONK +==== + +`Monk` is a generic dicumentation maker is a FREE software tool. + +This is a tool to generate the binary and application static documentation. +It is designed to support the github gh-pages, the it is a no-server-side interaction. + + +Create a monk doc +================= + +Set the monk module maker with the name : + monk_xxxxx.py + xxx : represent the name of the module/application and must be lower case and no special characters + +you can see exemple for some type in : + ewol : library + edn : application + +Build your documantation: + ./monk.py + + +Copyright (c) +============= + +2011, Edouard DUPIN + +License (DSB) +============= + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + 3. The name of the author may not be used to endorse or promote + products derived from this software without specific prior + written permission. + +THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. diff --git a/licence_BSD.txt b/licence_BSD.txt new file mode 100644 index 0000000..c750aed --- /dev/null +++ b/licence_BSD.txt @@ -0,0 +1,32 @@ + +Copyright (c) 2011, Edouard DUPIN + +License (DSB) + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + 3. The name of the author may not be used to endorse or promote + products derived from this software without specific prior + written permission. + +THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE.L \ No newline at end of file diff --git a/monk.py b/monk.py index de8eee4..b26c64b 100755 --- a/monk.py +++ b/monk.py @@ -76,7 +76,7 @@ def start(): debug.warning("Can not understand argument : '" + argument.get_option_name() + "'") usage() else: - module = monkModule.get_module(argument.GetArg()) + module = monkModule.get_module(argument.get_arg()) module.parse_code() module.generate() actionDone=True diff --git a/monkHtml.py b/monkHtml.py index 1514721..97d49aa 100644 --- a/monkHtml.py +++ b/monkHtml.py @@ -15,50 +15,17 @@ global_class_link = { "std::vector" : "http://www.cplusplus.com/reference/vector/vector/" } - -def replace_type(match): - value = "" + match.group() + "" - return value - -def replace_storage_keyword(match): - value = "" + match.group() + "" - return value - -def display_color(valBase): +def display_color(val): # storage keyword : - p = re.compile("(inline|const|class|virtual|private|public|protected|friend|const|extern|auto|register|static|volatile|typedef|struct|union|enum)") - val = p.sub(replace_storage_keyword, valBase) + val = re.sub(r'(inline|const|class|virtual|private|public|protected|friend|const|extern|auto|register|static|volatile|typedef|struct|union|enum)', + r'\1', + val) # type : - p = re.compile("(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))") - val = p.sub(replace_type, val) - return val, len(valBase) + 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'\1', + val) + return val -def display_type(type, myDoc): - type = type.replace("inline ", "") - lenght = 0; - isFirst = True - out = '' - # we split all the element in list sepa=rated with space to keep class... and standard c+ class - for element in type.split(' '): - if isFirst == False: - out += " " - lenght += 1 - isFirst = False - # check if the element in internal at the current lib - name, link = myDoc.get_class_link(element) - if len(link) != 0: - out += "" + name + "" - lenght += len(element) - # Ckeck if the variable in a standard class: - elif element in global_class_link.keys(): - out += "" + element + "" - lenght += len(element) - else: - data, lenghtTmp = display_color(element) - out += data - lenght += lenghtTmp - # get every subelement class : - return [out,lenght] def display_doxygen_param(comment, input, output): data = "Parameter" @@ -131,30 +98,6 @@ def white_space(size) : ret += " " return ret - - - -def calsulateSizeFunction(function, size) : - if len(function["name"]) > size: - return len(function["name"])+1 - return size - -def calsulateSizeReturn(function, size) : - if len(function["rtnType"]) > size: - return len(function["rtnType"])+1 - return size - - -def addSub(tree, filterSubNamespace=False): - return "" - - -# ############################################################## -# NEW function ... -# ############################################################## - - - def generate_menu(element, namespaceStack=[], level=1): listBase = element.get_all_sub_type(['namespace']) if len(listBase) == 0: @@ -228,9 +171,11 @@ def write_methode(element, namespaceStack, displaySize = None, link = True): if retType != "": retType2 = re.sub("<","<", retType) retType2 = re.sub(">",">", retType2) + retType2 = display_color(retType2) ret += retType2 ret += " " - ret += white_space(displaySize[0] - len(retType)) + retType += " " + ret += white_space(displaySize[0] - len(retType)+1) name = element['node'].get_name() if link == True: ret += '' + name + '' @@ -244,7 +189,7 @@ def write_methode(element, namespaceStack, displaySize = None, link = True): ret += ',
' ret += white_space(displaySize[0] + displaySize[1] +5) first = False - retParam = param.get_type().to_str() + retParam = display_color(param.get_type().to_str()) if retParam != "": ret += retParam ret += " " @@ -253,7 +198,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 += ' const' + ret += display_color(' const') ret += ';' ret += '
' @@ -283,8 +228,6 @@ def generate_page(outFolder, header, footer, element, namespaceStack=[]): namespaceStack.pop() else: generate_page(outFolder, header, footer, elem['node'], namespaceStack) - - filename = outFolder + '/' + generate_html_page_name(element, namespaceStack) monkTools.create_directory_of_file(filename); file = open(filename, "w") diff --git a/monkMethode.py b/monkMethode.py index 48e538b..8882853 100644 --- a/monkMethode.py +++ b/monkMethode.py @@ -5,7 +5,7 @@ import monkType as Type import monkVariable as Variable class Methode(Node.Node): - def __init__(self, stack=[], file="", lineNumber=0, documentation=[]): + def __init__(self, stack=[], file="", lineNumber=0, documentation=[], className = ""): name = "" type = 'methode' self.virtual = False @@ -44,7 +44,7 @@ class Methode(Node.Node): namePos = -1 - debug.verbose("methode parse : " + str(stack)) + debug.debug("methode parse : " + str(stack)) for iii in range(0, len(stack)-2): if stack[iii+1] == '(': name = stack[iii] @@ -52,12 +52,14 @@ class Methode(Node.Node): break; if namePos == 0: - debug.verbose("start with '" + str(name[0]) + "'") + debug.debug("start with '" + str(name[0]) + "'") if name[0] == '~': - type = 'destructor' + if className == name[1:]: + type = 'destructor' else: - type = 'constructor' - debug.verbose("methode name : " + name) + if className == name: + type = 'constructor' + debug.debug("methode name : " + name) Node.Node.__init__(self, type, name, file, lineNumber, documentation) self.returnType = Type.TypeNone() @@ -65,11 +67,11 @@ class Methode(Node.Node): # create the return Type (Can be Empty) retTypeStack = stack[:namePos] - debug.verbose("return : " + str(retTypeStack)) + debug.debug("return : " + str(retTypeStack)) self.returnType = Type.Type(retTypeStack) parameterStack = stack[namePos+2:len(stack)-1] - debug.verbose("parameter : " + str(parameterStack)) + debug.debug("parameter : " + str(parameterStack)) paramTmp = [] braceOpen = 0 for element in parameterStack: diff --git a/monkParse.py b/monkParse.py index bca64ed..fd735cd 100644 --- a/monkParse.py +++ b/monkParse.py @@ -200,13 +200,15 @@ def create_compleate_class_name(table): for name in table: if len(out) == 0: out.append(name) - elif name in ['<','>','='] \ - and out[-1][:8] == 'operator' \ - and len(out[-1])-8 < 2: + elif out[-1][:8] == 'operator' \ + and name != '(': + if out[-1] == 'operator': + out[-1] += ' ' + if out[-1][-1] not in [' ', '<','>','=', '-', '!', '+', '*', '&', '|', '/']: + out[-1] += ' ' out[-1] += name else: out.append(name) - return out @@ -282,6 +284,7 @@ class parse_file(): self.subModuleCountBrace -= 1 if self.subModuleCountBrace <= 0: self.brace_type_pop() + self.lastComment = [] continue # normal case: if tok.type == 'PRECOMP': @@ -433,7 +436,10 @@ class parse_file(): ret = Union.Union(stack, self.headerFileName, self.curLine, self.lastComment) elif type == 'function': #debug.info(str(self.lastComment)) - ret = Methode.Methode(stack, self.headerFileName, self.curLine, self.lastComment) + if self.get_last_type() == 'class': + ret = Methode.Methode(stack, self.headerFileName, self.curLine, self.lastComment, self.braceDepthType[len(self.braceDepthType)-1]['node'].get_name()) + else: + ret = Methode.Methode(stack, self.headerFileName, self.curLine, self.lastComment) elif type == 'enum': ret = Enum.Enum(stack, self.headerFileName, self.curLine, self.lastComment) elif type == 'variable': diff --git a/monkVariable.py b/monkVariable.py index 4687d7d..b8fbe68 100644 --- a/monkVariable.py +++ b/monkVariable.py @@ -7,6 +7,7 @@ class Variable(Node.Node): def __init__(self, stack=[], file="", lineNumber=0, documentation=[]): debug.debug("Parse variable : " + str(stack)) name = "" + type = [] if '=' in stack: plop = [] for element in stack: @@ -26,14 +27,12 @@ class Variable(Node.Node): stack = res if len(stack) < 2: - if stack[0] == 'void': - pass - else: - debug.error("Can not parse variable : " + str(stack)) + type = stack else: name = stack[len(stack)-1] + type = stack[:len(stack)-1] - Node.Node.__init__(self, 'variable', stack[len(stack)-1], file, lineNumber, documentation) + Node.Node.__init__(self, 'variable', name, file, lineNumber, documentation) # force the sublist error generation ... self.subList = None # default variable : @@ -41,21 +40,18 @@ class Variable(Node.Node): self.static = False self.external = False self.volatile = False - #empty name ... ==> this is really bad ... - if name == "": - return - if 'static' in stack: + if 'static' in type: self.static = True - stack = [value for value in stack if value != 'static'] + type = [value for value in type if value != 'static'] if 'volatile' in stack: self.volatile = True - stack = [value for value in stack if value != 'volatile'] + type = [value for value in type if value != 'volatile'] if 'external' in stack: self.external = True - stack = [value for value in stack if value != 'external'] + type = [value for value in type if value != 'external'] - self.type = Type.Type(stack[:len(stack)-1]) + self.type = Type.Type(type) debug.verbose("find variable : " + self.to_str())