[DEV] Parser c++ start to be interesting
This commit is contained in:
parent
397f9eb124
commit
61610b3a13
@ -14,10 +14,13 @@ def concatenate_template(list):
|
|||||||
|
|
||||||
class Class(Node.Node):
|
class Class(Node.Node):
|
||||||
def __init__(self, stack=[], file="", lineNumber=0):
|
def __init__(self, stack=[], file="", lineNumber=0):
|
||||||
|
# check input :
|
||||||
if len(stack) < 2:
|
if len(stack) < 2:
|
||||||
debug.error("Can not parse class : " + str(stack))
|
debug.error("Can not parse class : " + str(stack))
|
||||||
return
|
return
|
||||||
Node.Node.__init__(self, 'class', stack[1], file, lineNumber)
|
Node.Node.__init__(self, 'class', stack[1], file, lineNumber)
|
||||||
|
self.subList = []
|
||||||
|
self.access = "private"
|
||||||
# heritage list :
|
# heritage list :
|
||||||
self.inherit = []
|
self.inherit = []
|
||||||
if len(stack) == 2:
|
if len(stack) == 2:
|
||||||
@ -30,7 +33,7 @@ class Class(Node.Node):
|
|||||||
debug.error("error in parsing class : " + str(stack) + " missing ':' at the 3rd position ...")
|
debug.error("error in parsing class : " + str(stack) + " missing ':' at the 3rd position ...")
|
||||||
|
|
||||||
list = concatenate_template(stack[3:])
|
list = concatenate_template(stack[3:])
|
||||||
debug.info("inherit : " + str(list))
|
debug.verbose("inherit : " + str(list))
|
||||||
access = "private"
|
access = "private"
|
||||||
for element in list:
|
for element in list:
|
||||||
if element in ['private', 'protected', 'public']:
|
if element in ['private', 'protected', 'public']:
|
||||||
@ -40,7 +43,7 @@ class Class(Node.Node):
|
|||||||
else:
|
else:
|
||||||
self.inherit.append({'access' : access, 'class' : element})
|
self.inherit.append({'access' : access, 'class' : element})
|
||||||
|
|
||||||
debug.info("class : " + self.to_str())
|
debug.verbose("class : " + self.to_str())
|
||||||
|
|
||||||
def to_str(self) :
|
def to_str(self) :
|
||||||
ret = "class " + self.name
|
ret = "class " + self.name
|
||||||
|
@ -4,12 +4,39 @@ import Node
|
|||||||
|
|
||||||
class Enum(Node.Node):
|
class Enum(Node.Node):
|
||||||
def __init__(self, stack=[], file="", lineNumber=0):
|
def __init__(self, stack=[], file="", lineNumber=0):
|
||||||
name = ""
|
self.baseValue = 0;
|
||||||
Node.Node.__init__(self, 'enum', name, file, lineNumber)
|
# check input :
|
||||||
# CPP section:
|
if len(stack) < 2:
|
||||||
|
debug.error("Can not parse class : " + str(stack))
|
||||||
|
return
|
||||||
|
self.typedef = False
|
||||||
|
if stack[0] == 'typedef':
|
||||||
|
self.typedef = True
|
||||||
|
stack[1:]
|
||||||
|
|
||||||
|
Node.Node.__init__(self, 'enum', stack[1], file, lineNumber)
|
||||||
|
|
||||||
self.listElement = []
|
self.listElement = []
|
||||||
|
|
||||||
def to_str(self) :
|
def to_str(self) :
|
||||||
return "enum " + self.name + " { ... };"
|
return "enum " + self.name + " { ... };"
|
||||||
|
|
||||||
|
def enum_append(self, stack):
|
||||||
|
subList = []
|
||||||
|
tmp = []
|
||||||
|
for element in stack:
|
||||||
|
if element == ',':
|
||||||
|
subList.append(tmp)
|
||||||
|
tmp = []
|
||||||
|
else:
|
||||||
|
tmp.append(element)
|
||||||
|
if len(tmp) != 0:
|
||||||
|
subList.append(tmp)
|
||||||
|
|
||||||
|
debug.verbose(" TODO : Need to append enum : " + str(subList))
|
||||||
|
|
||||||
|
# TODO : Set the value at the enum ...
|
||||||
|
for element in subList:
|
||||||
|
self.listElement.append(element[0])
|
||||||
|
|
||||||
|
debug.info("enum list : " + str(self.listElement))
|
@ -2,20 +2,83 @@
|
|||||||
import lutinDebug as debug
|
import lutinDebug as debug
|
||||||
import Node
|
import Node
|
||||||
import Type
|
import Type
|
||||||
|
import Variable
|
||||||
|
|
||||||
class Methode(Node.Node):
|
class Methode(Node.Node):
|
||||||
def __init__(self, stack=[], file="", lineNumber=0):
|
def __init__(self, stack=[], file="", lineNumber=0):
|
||||||
name = ""
|
name = ""
|
||||||
Node.Node.__init__(self, 'methode', name, file, lineNumber)
|
type = 'methode'
|
||||||
self.name = ""
|
self.virtual = False
|
||||||
self.returnType = Type.TypeVoid()
|
self.virtualPure = False
|
||||||
self.virtual = False # only for C++
|
|
||||||
self.static = False
|
self.static = False
|
||||||
self.inline = False
|
self.inline = False
|
||||||
self.const = False # the end of line cont methode is sont for the class ...
|
self.const = False # the end of line cont methode is sont for the class ...
|
||||||
self.doc = None
|
|
||||||
self.variable = None
|
# remove constructer inside declaration ...
|
||||||
self.visibility = "private" # only for C++ : "public" "protected" "private"
|
if ':' in stack:
|
||||||
|
res = []
|
||||||
|
for element in stack:
|
||||||
|
if element != ':':
|
||||||
|
res.append(element)
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
stack = res
|
||||||
|
|
||||||
|
if stack[len(stack)-2] == '=' \
|
||||||
|
and stack[len(stack)-1] == '0':
|
||||||
|
stack = stack[:len(stack)-2]
|
||||||
|
self.virtualPure = True
|
||||||
|
|
||||||
|
if stack[0] == 'virtual':
|
||||||
|
self.virtual = True
|
||||||
|
stack = stack[1:]
|
||||||
|
if stack[0] == 'static':
|
||||||
|
self.static = True
|
||||||
|
stack = stack[1:]
|
||||||
|
if stack[0] == 'inline':
|
||||||
|
self.inline = True
|
||||||
|
stack = stack[1:]
|
||||||
|
if stack[len(stack)-1] == 'const':
|
||||||
|
self.const = True
|
||||||
|
stack = stack[:len(stack)-1]
|
||||||
|
|
||||||
|
namePos = -1
|
||||||
|
|
||||||
|
debug.verbose("methode parse : " + str(stack))
|
||||||
|
for iii in range(0, len(stack)-2):
|
||||||
|
if stack[iii+1] == '(':
|
||||||
|
name = stack[iii]
|
||||||
|
namePos = iii
|
||||||
|
break;
|
||||||
|
|
||||||
|
if namePos == 0:
|
||||||
|
debug.verbose("start with '" + str(name[0]) + "'")
|
||||||
|
if name[0] == '~':
|
||||||
|
type = 'destructor'
|
||||||
|
else:
|
||||||
|
type = 'constructor'
|
||||||
|
debug.verbose("methode name : " + name)
|
||||||
|
Node.Node.__init__(self, type, name, file, lineNumber)
|
||||||
|
|
||||||
|
self.returnType = Type.TypeNone()
|
||||||
|
self.variable = []
|
||||||
|
|
||||||
|
# create the return Type (Can be Empty)
|
||||||
|
retTypeStack = stack[:namePos]
|
||||||
|
debug.verbose("return : " + str(retTypeStack))
|
||||||
|
self.returnType = Type.Type(retTypeStack)
|
||||||
|
|
||||||
|
parameterStack = stack[namePos+2:len(stack)-1]
|
||||||
|
debug.verbose("parameter : " + str(parameterStack))
|
||||||
|
paramTmp = []
|
||||||
|
for element in parameterStack:
|
||||||
|
if element == ',':
|
||||||
|
self.variable.append(Variable.Variable(paramTmp))
|
||||||
|
paramTmp = []
|
||||||
|
else:
|
||||||
|
paramTmp.append(element)
|
||||||
|
if len(paramTmp) != 0:
|
||||||
|
self.variable.append(Variable.Variable(paramTmp))
|
||||||
|
|
||||||
def to_str(self):
|
def to_str(self):
|
||||||
ret = ""
|
ret = ""
|
||||||
@ -31,6 +94,8 @@ class Methode(Node.Node):
|
|||||||
ret += "("
|
ret += "("
|
||||||
# ...
|
# ...
|
||||||
ret += ")"
|
ret += ")"
|
||||||
|
if self.virtualPure == True:
|
||||||
|
ret += " = 0"
|
||||||
if self.const == True:
|
if self.const == True:
|
||||||
ret += " const"
|
ret += " const"
|
||||||
return ret
|
return ret
|
||||||
|
@ -7,8 +7,10 @@ class Namespace(Node.Node):
|
|||||||
if len(stack) != 2:
|
if len(stack) != 2:
|
||||||
debug.error("Can not parse namespace : " + str(stack))
|
debug.error("Can not parse namespace : " + str(stack))
|
||||||
Node.Node.__init__(self, 'namespace', stack[1], file, lineNumber)
|
Node.Node.__init__(self, 'namespace', stack[1], file, lineNumber)
|
||||||
|
# enable sub list
|
||||||
|
self.subList = []
|
||||||
|
|
||||||
debug.verbose("find class : " + self.to_str())
|
debug.verbose("find namespace : " + self.to_str())
|
||||||
|
|
||||||
def to_str(self) :
|
def to_str(self) :
|
||||||
return "namespace " + self.name + " { ... };"
|
return "namespace " + self.name + " { ... };"
|
||||||
|
@ -1,6 +1,14 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
import lutinDebug as debug
|
import lutinDebug as debug
|
||||||
|
|
||||||
|
accessList = ['private', 'protected', 'public']
|
||||||
|
|
||||||
|
def debug_space(level):
|
||||||
|
ret = ""
|
||||||
|
for iii in range(0,level):
|
||||||
|
ret += " "
|
||||||
|
return ret
|
||||||
|
|
||||||
class Node():
|
class Node():
|
||||||
def __init__(self, type, name="", file="", lineNumber=0):
|
def __init__(self, type, name="", file="", lineNumber=0):
|
||||||
self.nodeType = type
|
self.nodeType = type
|
||||||
@ -8,13 +16,83 @@ class Node():
|
|||||||
self.doc = None
|
self.doc = None
|
||||||
self.fileName = file
|
self.fileName = file
|
||||||
self.lineNumber = lineNumber
|
self.lineNumber = lineNumber
|
||||||
self.subList = []
|
self.subList = None
|
||||||
|
self.access = None
|
||||||
|
|
||||||
def to_str(self):
|
def to_str(self):
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
def str(self):
|
||||||
|
return self.to_str()
|
||||||
|
|
||||||
|
def get_node_type(self):
|
||||||
|
return self.nodeType
|
||||||
|
|
||||||
|
def get_name(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
def debug_display(self, level=0, access = None):
|
||||||
|
if access == 'private':
|
||||||
|
debug.info(debug_space(level) + "- " + self.nodeType + " => " + self.name)
|
||||||
|
elif access == 'protected':
|
||||||
|
debug.info(debug_space(level) + "# " + self.nodeType + " => " + self.name)
|
||||||
|
elif access == 'public':
|
||||||
|
debug.info(debug_space(level) + "+ " + self.nodeType + " => " + self.name)
|
||||||
|
else:
|
||||||
|
debug.info(debug_space(level) + self.nodeType + " => " + self.name)
|
||||||
|
if self.subList!= None:
|
||||||
|
for element in self.subList:
|
||||||
|
if 'access' in element.keys():
|
||||||
|
element['node'].debug_display(level+1, element['access'])
|
||||||
|
else:
|
||||||
|
element['node'].debug_display(level+1)
|
||||||
|
|
||||||
|
def set_access(self, access):
|
||||||
|
if access not in accessList:
|
||||||
|
debug.warning("This is not a valid access : '" + access + "' : availlable : " + str(accessList))
|
||||||
|
return
|
||||||
|
if self.access == None:
|
||||||
|
debug.error("This Node does not support acces configuration...")
|
||||||
|
return
|
||||||
|
self.access = access
|
||||||
|
|
||||||
|
def get_access(self):
|
||||||
|
return self.access
|
||||||
|
|
||||||
def append(self, newSubElement):
|
def append(self, newSubElement):
|
||||||
# just add it in a sub List :
|
# just add it in a sub List :
|
||||||
self.subList.append(newSubElement)
|
if self.subList == None:
|
||||||
|
debug.error("can not add a '" + newSubElement.nodeType + "' at this '" + self.nodeType + "'")
|
||||||
|
return
|
||||||
|
if newSubElement.get_node_type() != 'namespace':
|
||||||
|
if self.access == None:
|
||||||
|
self.subList.append({'node' : newSubElement})
|
||||||
|
else:
|
||||||
|
self.subList.append({'access' : self.access, 'node' : newSubElement})
|
||||||
|
return
|
||||||
|
|
||||||
|
# check if the element already exist
|
||||||
|
for element in self.subList:
|
||||||
|
if element['node'].get_node_type() == 'namespace':
|
||||||
|
if element['node'].get_name() == newSubElement.get_name():
|
||||||
|
debug.verbose("fusionate with previous declaration")
|
||||||
|
element['node'].fusion(newSubElement)
|
||||||
|
return
|
||||||
|
# normal case adding :
|
||||||
|
if self.access == None:
|
||||||
|
self.subList.append({'node' : newSubElement})
|
||||||
|
else:
|
||||||
|
self.subList.append({'access' : self.access, 'node' : newSubElement})
|
||||||
|
|
||||||
|
## @ brief only for namespace :
|
||||||
|
def fusion(self, addedElement):
|
||||||
|
for element in addedElement.subList:
|
||||||
|
self.append(element['node'])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class MainNode(Node):
|
||||||
|
def __init__(self, type="library", name=""):
|
||||||
|
Node.__init__(self, type, name)
|
||||||
|
self.subList = []
|
@ -15,6 +15,7 @@ import Union
|
|||||||
import Methode
|
import Methode
|
||||||
import Enum
|
import Enum
|
||||||
import Variable
|
import Variable
|
||||||
|
import Node
|
||||||
|
|
||||||
tokens = [
|
tokens = [
|
||||||
'NUMBER',
|
'NUMBER',
|
||||||
@ -114,11 +115,6 @@ lex.lex()
|
|||||||
|
|
||||||
doxygenCommentCache = ""
|
doxygenCommentCache = ""
|
||||||
|
|
||||||
supportedAccessSpecifier = [
|
|
||||||
'public',
|
|
||||||
'protected',
|
|
||||||
'private'
|
|
||||||
]
|
|
||||||
|
|
||||||
##
|
##
|
||||||
## @brief Join the class name element : ['class', 'Bar', ':', ':', 'Foo'] -> ['class', 'Bar::Foo']
|
## @brief Join the class name element : ['class', 'Bar', ':', ':', 'Foo'] -> ['class', 'Bar::Foo']
|
||||||
@ -168,10 +164,14 @@ class parse_file():
|
|||||||
ret += " "
|
ret += " "
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
def fusion(self, baseNode):
|
||||||
|
baseNode.fusion(self.mainNode)
|
||||||
|
return baseNode
|
||||||
|
|
||||||
def __init__(self, fileName):
|
def __init__(self, fileName):
|
||||||
self.m_classes = []
|
self.mainNode = Node.MainNode("main-node", "tmp")
|
||||||
self.m_elementParseStack = []
|
self.m_elementParseStack = []
|
||||||
debug.info("Parse File tod document : '" + fileName + "'")
|
debug.debug("Parse file : '" + fileName + "'")
|
||||||
|
|
||||||
self.headerFileName = fileName
|
self.headerFileName = fileName
|
||||||
|
|
||||||
@ -179,11 +179,6 @@ class parse_file():
|
|||||||
# load all the file data :
|
# load all the file data :
|
||||||
headerFileStr = lutinTools.FileReadData(fileName)
|
headerFileStr = lutinTools.FileReadData(fileName)
|
||||||
|
|
||||||
# Make sure supportedAccessSpecifier are sane
|
|
||||||
for i in range(0, len(supportedAccessSpecifier)):
|
|
||||||
if " " not in supportedAccessSpecifier[i]: continue
|
|
||||||
supportedAccessSpecifier[i] = re.sub("[ ]+", " ", supportedAccessSpecifier[i]).strip()
|
|
||||||
|
|
||||||
# Strip out template declarations
|
# Strip out template declarations
|
||||||
# TODO : What is the real need ???
|
# TODO : What is the real need ???
|
||||||
headerFileStr = re.sub("template[\t ]*<[^>]*>", "", headerFileStr)
|
headerFileStr = re.sub("template[\t ]*<[^>]*>", "", headerFileStr)
|
||||||
@ -193,8 +188,12 @@ class parse_file():
|
|||||||
headerFileStr = re.sub("\r", "", headerFileStr)
|
headerFileStr = re.sub("\r", "", headerFileStr)
|
||||||
# TODO : Can generate some error ...
|
# TODO : Can generate some error ...
|
||||||
headerFileStr = re.sub("\#if 0(.*?)(\#endif|\#else)", "", headerFileStr, flags=re.DOTALL)
|
headerFileStr = re.sub("\#if 0(.*?)(\#endif|\#else)", "", headerFileStr, flags=re.DOTALL)
|
||||||
|
headerFileafter = re.sub("\@interface(.*?)\@end", "", headerFileStr, flags=re.DOTALL)
|
||||||
|
if headerFileStr != headerFileafter :
|
||||||
|
debug.debug(" Objective C interface ... ==> not supported")
|
||||||
|
return
|
||||||
|
|
||||||
debug.debug(headerFileStr)
|
debug.verbose(headerFileStr)
|
||||||
|
|
||||||
# Change multi line #defines and expressions to single lines maintaining line nubmers
|
# Change multi line #defines and expressions to single lines maintaining line nubmers
|
||||||
matches = re.findall(r'(?m)^(?:.*\\\n)+.*$', headerFileStr)
|
matches = re.findall(r'(?m)^(?:.*\\\n)+.*$', headerFileStr)
|
||||||
@ -278,7 +277,7 @@ class parse_file():
|
|||||||
elif tok.type == 'CLOSE_BRACE':
|
elif tok.type == 'CLOSE_BRACE':
|
||||||
if len(self.nameStack) != 0:
|
if len(self.nameStack) != 0:
|
||||||
if self.previous_is('enum') == True:
|
if self.previous_is('enum') == True:
|
||||||
debug.info(self.gen_debug_space() + "enum list... : " + str(self.nameStack));
|
self.brace_type_append('enum list', self.nameStack);
|
||||||
else:
|
else:
|
||||||
debug.warning(self.gen_debug_space() + "end brace DROP : " + str(self.nameStack));
|
debug.warning(self.gen_debug_space() + "end brace DROP : " + str(self.nameStack));
|
||||||
self.stack = []
|
self.stack = []
|
||||||
@ -325,7 +324,7 @@ class parse_file():
|
|||||||
or tok.type == 'CHAR_LITERAL':
|
or tok.type == 'CHAR_LITERAL':
|
||||||
self.nameStack.append(tok.value)
|
self.nameStack.append(tok.value)
|
||||||
elif tok.type == 'COLON':
|
elif tok.type == 'COLON':
|
||||||
if self.nameStack[0] in ['private', 'protected', 'public']:
|
if self.nameStack[0] in Node.accessList:
|
||||||
debug.debug(self.gen_debug_space() + "change visibility : " + self.nameStack[0]);
|
debug.debug(self.gen_debug_space() + "change visibility : " + self.nameStack[0]);
|
||||||
self.brace_type_change_access(self.nameStack[0])
|
self.brace_type_change_access(self.nameStack[0])
|
||||||
self.nameStack = []
|
self.nameStack = []
|
||||||
@ -336,7 +335,7 @@ class parse_file():
|
|||||||
if len(self.nameStack) != 0:
|
if len(self.nameStack) != 0:
|
||||||
self.nameStack = create_compleate_class_name(self.nameStack)
|
self.nameStack = create_compleate_class_name(self.nameStack)
|
||||||
if is_a_function(self.nameStack):
|
if is_a_function(self.nameStack):
|
||||||
debug.info(self.gen_debug_space() + "function : " + str(self.nameStack));
|
self.brace_type_append('function', self.nameStack);
|
||||||
elif 'namespace' in self.nameStack:
|
elif 'namespace' in self.nameStack:
|
||||||
debug.debug(self.gen_debug_space() + "find a namespace DECLARATION : " + str(self.nameStack));
|
debug.debug(self.gen_debug_space() + "find a namespace DECLARATION : " + str(self.nameStack));
|
||||||
elif 'class' in self.nameStack:
|
elif 'class' in self.nameStack:
|
||||||
@ -351,17 +350,23 @@ class parse_file():
|
|||||||
debug.debug(self.gen_debug_space() + "find a union DECLARATION : " + str(self.nameStack));
|
debug.debug(self.gen_debug_space() + "find a union DECLARATION : " + str(self.nameStack));
|
||||||
else:
|
else:
|
||||||
if self.previous_is('enum') == True:
|
if self.previous_is('enum') == True:
|
||||||
debug.info(self.gen_debug_space() + "enum list : " + str(self.nameStack));
|
self.brace_type_append('enum list', self.nameStack);
|
||||||
else:
|
else:
|
||||||
# TODO : Check if it is true in all case :
|
# TODO : Check if it is true in all case :
|
||||||
self.brace_type_append('variable', self.nameStack);
|
self.brace_type_append('variable', self.nameStack);
|
||||||
#debug.warning(self.gen_debug_space() + "semicolumn : " + str(self.nameStack));
|
#debug.warning(self.gen_debug_space() + "semicolumn : " + str(self.nameStack));
|
||||||
self.stack = []
|
self.stack = []
|
||||||
self.nameStack = []
|
self.nameStack = []
|
||||||
|
#self.debug_display();
|
||||||
|
|
||||||
|
def debug_display(self):
|
||||||
|
debug.info("Debug display :")
|
||||||
|
self.mainNode.debug_display(1)
|
||||||
|
|
||||||
def create_element(self, type, stack):
|
def create_element(self, type, stack):
|
||||||
ret = None
|
ret = None
|
||||||
if type == 'empty':
|
if type == 'empty' \
|
||||||
|
or type == 'enum list':
|
||||||
pass
|
pass
|
||||||
elif type == 'namespace':
|
elif type == 'namespace':
|
||||||
ret = Namespace.Namespace(stack, self.headerFileName, self.curLine)
|
ret = Namespace.Namespace(stack, self.headerFileName, self.curLine)
|
||||||
@ -386,46 +391,75 @@ class parse_file():
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
def brace_type_push(self, type, stack):
|
def brace_type_push(self, type, stack):
|
||||||
debug.info(self.gen_debug_space() + "find a <<" + type + ">> : " + str(stack));
|
debug.debug(self.gen_debug_space() + "find a <<" + type + ">> : " + str(stack));
|
||||||
myClassElement = self.create_element(type, stack)
|
myClassElement = self.create_element(type, stack)
|
||||||
element = { 'type' : type,
|
element = { 'type' : type,
|
||||||
'stack' : stack,
|
'stack' : stack,
|
||||||
'access' : None,
|
|
||||||
'node' : myClassElement
|
'node' : myClassElement
|
||||||
}
|
}
|
||||||
if type == 'class':
|
|
||||||
element['access'] = "private"
|
|
||||||
elif type == 'struct':
|
|
||||||
element['access'] = "public"
|
|
||||||
self.braceDepthType.append(element)
|
self.braceDepthType.append(element)
|
||||||
#debug.info ("append : " + str(element))
|
#debug.info ("append : " + str(element))
|
||||||
|
|
||||||
|
def brace_type_append_current(self, element, id = -50):
|
||||||
|
if id == -50:
|
||||||
|
id = len(self.braceDepthType)-1
|
||||||
|
if id >= 0:
|
||||||
|
while self.braceDepthType[id]['node'] == None:
|
||||||
|
# special case for empty brace, just add it to the upper
|
||||||
|
id -=1
|
||||||
|
if id < 0:
|
||||||
|
break;
|
||||||
|
if id < 0:
|
||||||
|
self.mainNode.append(element)
|
||||||
|
else:
|
||||||
|
self.braceDepthType[id]['node'].append(element)
|
||||||
|
|
||||||
def brace_type_append(self, type, stack):
|
def brace_type_append(self, type, stack):
|
||||||
debug.info(self.gen_debug_space() + " append a <<" + type + ">> : " + str(stack));
|
debug.debug(self.gen_debug_space() + " append a <<" + type + ">> : " + str(stack));
|
||||||
lastType = self.get_last_type()
|
lastType = self.get_last_type()
|
||||||
newType = self.create_element(type, stack)
|
newType = self.create_element(type, stack)
|
||||||
if newType == None:
|
if newType != None:
|
||||||
|
self.brace_type_append_current(newType)
|
||||||
|
return
|
||||||
|
# enum sub list:
|
||||||
|
if lastType == 'enum' \
|
||||||
|
and type == 'enum list':
|
||||||
|
id = len(self.braceDepthType)-1
|
||||||
|
self.braceDepthType[id]['node'].enum_append(stack)
|
||||||
|
return
|
||||||
debug.info("TODO : Parse the special type")
|
debug.info("TODO : Parse the special type")
|
||||||
return
|
|
||||||
if len(self.braceDepthType) == 0:
|
|
||||||
debug.info("TODO : Append in glocal directly ...")
|
|
||||||
return
|
|
||||||
self.braceDepthType[len(self.braceDepthType)-1]['node'].append(newType)
|
|
||||||
|
|
||||||
def brace_type_pop(self):
|
def brace_type_pop(self):
|
||||||
|
id = len(self.braceDepthType)-1
|
||||||
|
if id < 0:
|
||||||
|
debug.warning("Try to pop the stack with No more element ...")
|
||||||
|
return
|
||||||
|
if self.braceDepthType[id]['node'] == None:
|
||||||
|
# nothing to add at the upper ...
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
# add it on the previous
|
||||||
|
self.brace_type_append_current(self.braceDepthType[id]['node'], id-1)
|
||||||
self.braceDepthType.pop()
|
self.braceDepthType.pop()
|
||||||
|
|
||||||
def brace_type_change_access(self, newOne):
|
def brace_type_change_access(self, newOne):
|
||||||
if len(self.braceDepthType) == 0:
|
if newOne not in Node.accessList:
|
||||||
debug.error("set access in nothing ... ")
|
|
||||||
return
|
|
||||||
if newOne not in supportedAccessSpecifier:
|
|
||||||
debug.error("unknow access type : " + newOne)
|
debug.error("unknow access type : " + newOne)
|
||||||
return
|
return
|
||||||
if self.braceDepthType[len(self.braceDepthType)-1]['access'] == None:
|
id = len(self.braceDepthType)-1
|
||||||
debug.error("Can not set access in other as : 'class' or 'struct' :" + str(self.braceDepthType[len(self.braceDepthType)-1]))
|
if id >= 0:
|
||||||
|
while self.braceDepthType[id]['node'] == None:
|
||||||
|
# special case for empty brace, just add it to the upper
|
||||||
|
id -=1
|
||||||
|
if id < 0:
|
||||||
|
break;
|
||||||
|
if id < 0:
|
||||||
|
debug.warning("can not change the main access on the library")
|
||||||
|
else:
|
||||||
|
if self.braceDepthType[id]['node'].get_access() == None:
|
||||||
|
debug.error("Can not set access in other as : 'class' or 'struct' :" + str(self.braceDepthType[id]))
|
||||||
return
|
return
|
||||||
self.braceDepthType[len(self.braceDepthType)-1]['access'] = newOne
|
self.braceDepthType[id]['node'].set_access(newOne)
|
||||||
|
|
||||||
def previous_is(self, type):
|
def previous_is(self, type):
|
||||||
if self.get_last_type() == type:
|
if self.get_last_type() == type:
|
||||||
@ -441,6 +475,17 @@ def is_a_function(stack) :
|
|||||||
# in a function we need to have functionName + ( + )
|
# in a function we need to have functionName + ( + )
|
||||||
if len(stack) < 3:
|
if len(stack) < 3:
|
||||||
return False
|
return False
|
||||||
|
if ':' in stack:
|
||||||
|
res = []
|
||||||
|
for element in stack:
|
||||||
|
if element != ':':
|
||||||
|
res.append(element)
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
stack = res
|
||||||
|
if stack[len(stack)-2] == '=' \
|
||||||
|
and stack[len(stack)-1] == '0':
|
||||||
|
stack = stack[:len(stack)-2]
|
||||||
#can end with 2 possibilities : ')', 'const' or ')'
|
#can end with 2 possibilities : ')', 'const' or ')'
|
||||||
if stack[len(stack)-1] == ')' \
|
if stack[len(stack)-1] == ')' \
|
||||||
or ( stack[len(stack)-2] == ')' \
|
or ( stack[len(stack)-2] == ')' \
|
||||||
|
@ -6,15 +6,8 @@ class Struct(Node.Node):
|
|||||||
def __init__(self, stack=[], file="", lineNumber=0):
|
def __init__(self, stack=[], file="", lineNumber=0):
|
||||||
name = ""
|
name = ""
|
||||||
Node.Node.__init__(self, 'struct', name, file, lineNumber)
|
Node.Node.__init__(self, 'struct', name, file, lineNumber)
|
||||||
# CPP section:
|
self.access = "public"
|
||||||
self.namespaces = []
|
|
||||||
self.classes = []
|
|
||||||
# C section:
|
|
||||||
self.structs = []
|
|
||||||
self.variables = []
|
|
||||||
self.methodes = []
|
|
||||||
self.unions = []
|
|
||||||
self.types = []
|
|
||||||
|
|
||||||
def to_str(self) :
|
def to_str(self) :
|
||||||
return "struct " + self.name + " { ... };"
|
return "struct " + self.name + " { ... };"
|
||||||
|
@ -5,12 +5,14 @@ import Node
|
|||||||
|
|
||||||
class Type():
|
class Type():
|
||||||
def __init__(self, stack=[]):
|
def __init__(self, stack=[]):
|
||||||
if len(stack) == 0:
|
|
||||||
debug.error("Can not parse Type : " + str(stack))
|
|
||||||
self.name = ""
|
self.name = ""
|
||||||
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
|
||||||
|
|
||||||
|
if len(stack) == 0:
|
||||||
|
# None type
|
||||||
|
return
|
||||||
if len(stack) == 1:
|
if len(stack) == 1:
|
||||||
self.name = stack[0]
|
self.name = stack[0]
|
||||||
return;
|
return;
|
||||||
@ -46,3 +48,7 @@ class TypeVoid(Type):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
Type.__init__(self, ['void'])
|
Type.__init__(self, ['void'])
|
||||||
|
|
||||||
|
class TypeNone(Type):
|
||||||
|
def __init__(self):
|
||||||
|
Type.__init__(self)
|
||||||
|
|
||||||
|
@ -5,8 +5,24 @@ import Node
|
|||||||
|
|
||||||
class Variable(Node.Node):
|
class Variable(Node.Node):
|
||||||
def __init__(self, stack=[], file="", lineNumber=0):
|
def __init__(self, stack=[], file="", lineNumber=0):
|
||||||
|
name = ""
|
||||||
|
# TODO : better manageement for xxx[**][**] element:
|
||||||
|
res = []
|
||||||
|
for element in stack:
|
||||||
|
if element == '[':
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
res.append(element)
|
||||||
|
stack = res
|
||||||
|
|
||||||
if len(stack) < 2:
|
if len(stack) < 2:
|
||||||
|
if stack[0] == 'void':
|
||||||
|
pass
|
||||||
|
else:
|
||||||
debug.error("Can not parse variable : " + str(stack))
|
debug.error("Can not parse variable : " + str(stack))
|
||||||
|
else:
|
||||||
|
name = stack[len(stack)-1]
|
||||||
|
|
||||||
Node.Node.__init__(self, 'variable', stack[len(stack)-1], file, lineNumber)
|
Node.Node.__init__(self, 'variable', stack[len(stack)-1], file, lineNumber)
|
||||||
# force the sublist error generation ...
|
# force the sublist error generation ...
|
||||||
self.subList = None
|
self.subList = None
|
||||||
@ -15,6 +31,9 @@ class Variable(Node.Node):
|
|||||||
self.static = False
|
self.static = False
|
||||||
self.external = False
|
self.external = False
|
||||||
self.volatile = False
|
self.volatile = False
|
||||||
|
#empty name ... ==> this is really bad ...
|
||||||
|
if name == "":
|
||||||
|
return
|
||||||
|
|
||||||
if 'static' in stack:
|
if 'static' in stack:
|
||||||
self.static = True
|
self.static = True
|
||||||
|
File diff suppressed because it is too large
Load Diff
13
lutinDoc.py
13
lutinDoc.py
@ -8,6 +8,7 @@ sys.path.append(lutinTools.GetCurrentPath(__file__) + "/cppParser/")
|
|||||||
sys.path.append(lutinTools.GetCurrentPath(__file__) + "/codeBB/")
|
sys.path.append(lutinTools.GetCurrentPath(__file__) + "/codeBB/")
|
||||||
sys.path.append(lutinTools.GetCurrentPath(__file__) + "/codeHL/")
|
sys.path.append(lutinTools.GetCurrentPath(__file__) + "/codeHL/")
|
||||||
import Parse
|
import Parse
|
||||||
|
import Node
|
||||||
import lutinDocHtml
|
import lutinDocHtml
|
||||||
import lutinDocMd
|
import lutinDocMd
|
||||||
import os
|
import os
|
||||||
@ -21,6 +22,7 @@ class doc:
|
|||||||
def __init__(self, moduleName):
|
def __init__(self, moduleName):
|
||||||
self.moduleName = moduleName
|
self.moduleName = moduleName
|
||||||
self.listDocFile = []
|
self.listDocFile = []
|
||||||
|
self.structureLib = Node.MainNode("library", moduleName)
|
||||||
self.listTutorialFile = []
|
self.listTutorialFile = []
|
||||||
self.listClass = dict()
|
self.listClass = dict()
|
||||||
self.listEnum = dict()
|
self.listEnum = dict()
|
||||||
@ -90,6 +92,8 @@ class doc:
|
|||||||
fileCompleteName = os.path.join(root, filename)
|
fileCompleteName = os.path.join(root, filename)
|
||||||
debug.debug(" Find a file : '" + fileCompleteName + "'")
|
debug.debug(" Find a file : '" + fileCompleteName + "'")
|
||||||
self.add_file(fileCompleteName)
|
self.add_file(fileCompleteName)
|
||||||
|
self.structureLib.debug_display()
|
||||||
|
debug.error("ended")
|
||||||
if self.pathGlobalDoc != "":
|
if self.pathGlobalDoc != "":
|
||||||
for root, dirnames, filenames in os.walk(self.pathGlobalDoc):
|
for root, dirnames, filenames in os.walk(self.pathGlobalDoc):
|
||||||
tmpList = fnmatch.filter(filenames, "*.bb")
|
tmpList = fnmatch.filter(filenames, "*.bb")
|
||||||
@ -131,6 +135,15 @@ class doc:
|
|||||||
##
|
##
|
||||||
def add_file(self, filename):
|
def add_file(self, filename):
|
||||||
debug.debug("adding file in documantation : '" + filename + "'");
|
debug.debug("adding file in documantation : '" + filename + "'");
|
||||||
|
|
||||||
|
#plop = Parse.parse_file('ewol/sources/ewol/context/MacOs/OpenglView.h')
|
||||||
|
#debug.error("parse done");
|
||||||
|
|
||||||
|
parsedFile = Parse.parse_file(filename)
|
||||||
|
self.structureLib = parsedFile.fusion(self.structureLib)
|
||||||
|
|
||||||
|
|
||||||
|
def deprecate(self):
|
||||||
plop = Parse.parse_file('Widget.h')
|
plop = Parse.parse_file('Widget.h')
|
||||||
debug.error("parse done");
|
debug.error("parse done");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user