From ea307ad3ac0c73a81fbedbb3d697e33e12197ac9 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Mon, 16 Jun 2014 21:53:04 +0200 Subject: [PATCH] [DEV] manage the template function in parsing (not written in doc ...) --- monkClass.py | 9 +++++++++ monkMethode.py | 27 +++++++++++++++++++++++++++ monkParse.py | 13 ++++++++++--- 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/monkClass.py b/monkClass.py index 8d713e5..876eed4 100644 --- a/monkClass.py +++ b/monkClass.py @@ -19,6 +19,15 @@ class Class(Node.Node): 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 ... + stack = stack[stack.index("class"):] + # TODO : add the template properties back ... + 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.subList = [] self.access = "private" diff --git a/monkMethode.py b/monkMethode.py index 6cc8f79..bb83598 100644 --- a/monkMethode.py +++ b/monkMethode.py @@ -13,6 +13,7 @@ class Methode(Node.Node): self.static = False self.inline = False self.const = False # the end of line cont methode is sont for the class ... + self.noexcept = False # remove constructer inside declaration ... if ':' in stack: @@ -24,6 +25,29 @@ class Methode(Node.Node): break stack = res + #check if it is a template class: + if stack[0] == "template": + debug.debug("find a template methode: " + str(stack)) + #remove template properties ==> not manage for now ... + newStack = [] + counter = 0 + counterEnable = True + # start at the first '<' + for element in stack[1:]: + if counterEnable == True: + if element[0] == '<': + counter += 1; + elif element[0] == '>': + counter -= 1; + if counter == 0: + if counterEnable == True: + counterEnable = False + else: + newStack.append(element) + stack = newStack + # TODO : add the template properties back ... + debug.verbose("find a template methode: " + str(stack)) + if stack[len(stack)-2] == '=' \ and stack[len(stack)-1] == '0': stack = stack[:len(stack)-2] @@ -38,6 +62,9 @@ class Methode(Node.Node): if stack[0] == 'inline': self.inline = True stack = stack[1:] + if stack[len(stack)-1] == 'noexcept': + self.noexcept = True + stack = stack[:len(stack)-1] if stack[len(stack)-1] == 'const': self.const = True stack = stack[:len(stack)-1] diff --git a/monkParse.py b/monkParse.py index 9fcf368..6f756ba 100644 --- a/monkParse.py +++ b/monkParse.py @@ -24,6 +24,7 @@ import monkNode as Node tokens = [ 'NUMBER', + 'TEMPLATE', 'NAME', 'OPEN_PAREN', 'CLOSE_PAREN', @@ -59,7 +60,8 @@ tokens = [ ] t_ignore = " \r.?@\f" -t_NUMBER = r'[0-9][0-9XxA-Fa-f]*' +t_TEMPLATE = r'template' +t_NUMBER = r'[0-9][0-9XxA-Fa-f]*L?' t_NAME = r'[<>A-Za-z_~][A-Za-z0-9_]*' t_OPEN_PAREN = r'\(' t_CLOSE_PAREN = r'\)' @@ -237,7 +239,7 @@ class parse_file(): # Strip out template declarations # TODO : What is the real need ??? - headerFileStr = re.sub("template[\t ]*<[^>]*>", "", headerFileStr) + #headerFileStr = re.sub("template[\t ]*<[^>]*>", "", headerFileStr) # remove all needed \r unneeded ==> this simplify next resExp ... headerFileStr = re.sub("\r", "\r\n", headerFileStr) headerFileStr = re.sub("\r\n\n", "\r\n", headerFileStr) @@ -561,6 +563,11 @@ def is_a_function(stack) : #can end with 2 possibilities : ')', 'const' or ')' if stack[len(stack)-1] == ')' \ or ( stack[len(stack)-2] == ')' \ - and stack[len(stack)-1] == 'const'): + and stack[len(stack)-1] == 'const')\ + or ( stack[len(stack)-2] == ')' \ + and stack[len(stack)-1] == 'noexcept')\ + or ( stack[len(stack)-3] == ')' \ + and stack[len(stack)-2] == 'const' \ + and stack[len(stack)-1] == 'noexcept'): return True return False \ No newline at end of file