[DEV] start parse of all sub elements
This commit is contained in:
parent
c572dc8c15
commit
825875dd12
@ -1,38 +1,59 @@
|
||||
#!/usr/bin/python
|
||||
try :
|
||||
# normal install module
|
||||
import ply.lex as lex
|
||||
except ImportError :
|
||||
# local module
|
||||
import lex
|
||||
import os
|
||||
import sys
|
||||
import re
|
||||
import Node
|
||||
import lutinDebug as debug
|
||||
import Node
|
||||
|
||||
import inspect
|
||||
|
||||
##
|
||||
## @brief transform template descrption in one element.
|
||||
## @param[in] list of elements. ex : 'public', 'ewol::classee', '<', 'plop', '<', 'uint8_t', ',', 'int32_t', '>', '>'
|
||||
## @return a simplify list. ex : 'public', 'ewol::classee<plop<uint8_t,int32_t>>'
|
||||
##
|
||||
def concatenate_template(list):
|
||||
# TODO ...
|
||||
return list
|
||||
|
||||
class Class(Node.Node):
|
||||
def __init__(self):
|
||||
def __init__(self, stack=[], file="", lineNumber=0):
|
||||
if len(stack) < 2:
|
||||
debug.error("Can not parse class : " + str(stack))
|
||||
return
|
||||
Node.Node.__init__(self, 'class', stack[1], file, lineNumber)
|
||||
# heritage list :
|
||||
self.inherit = []
|
||||
if len(stack) == 2:
|
||||
# just a simple class...
|
||||
return
|
||||
if len(stack) == 3:
|
||||
debug.error("error in parsing class : " + str(stack))
|
||||
return
|
||||
if stack[2] != ':':
|
||||
debug.error("error in parsing class : " + str(stack) + " missing ':' at the 3rd position ...")
|
||||
|
||||
# List of the class name (with their namespace : [['ewol','widget','plop'], ...])
|
||||
self.parents = []
|
||||
|
||||
# CPP section:
|
||||
self.namespaces = []
|
||||
self.classes = []
|
||||
# C section:
|
||||
self.structs = []
|
||||
self.variables = []
|
||||
self.methodes = []
|
||||
self.unions = []
|
||||
self.types = []
|
||||
list = concatenate_template(stack[3:])
|
||||
debug.info("inherit : " + str(list))
|
||||
access = "private"
|
||||
for element in list:
|
||||
if element in ['private', 'protected', 'public']:
|
||||
access = element
|
||||
elif element == ',':
|
||||
pass
|
||||
else:
|
||||
self.inherit.append({'access' : access, 'class' : element})
|
||||
|
||||
debug.info("class : " + self.to_str())
|
||||
|
||||
|
||||
def to_str(self):
|
||||
return ""
|
||||
def to_str(self) :
|
||||
ret = "class " + self.name
|
||||
if len(self.inherit) != 0 :
|
||||
ret += " : "
|
||||
isFirst = True
|
||||
for element in self.inherit:
|
||||
if isFirst == False:
|
||||
ret += ", "
|
||||
isFirst = False
|
||||
ret += element['access'] + " " + element['class']
|
||||
ret += " { ... };"
|
||||
return ret
|
||||
|
||||
|
||||
|
||||
|
@ -1,24 +1,15 @@
|
||||
#!/usr/bin/python
|
||||
try :
|
||||
# normal install module
|
||||
import ply.lex as lex
|
||||
except ImportError :
|
||||
# local module
|
||||
import lex
|
||||
import os
|
||||
import sys
|
||||
import re
|
||||
|
||||
import lutinDebug as debug
|
||||
import Node
|
||||
|
||||
import inspect
|
||||
|
||||
|
||||
class Enum(Node):
|
||||
def __init__(self):
|
||||
self.name = libName
|
||||
|
||||
#List is contituated of 3 element : {'name':"plop", 'value':5, 'doc'=""}, ...]
|
||||
self.list = []
|
||||
|
||||
class Enum(Node.Node):
|
||||
def __init__(self, stack=[], file="", lineNumber=0):
|
||||
name = ""
|
||||
Node.Node.__init__(self, 'enum', name, file, lineNumber)
|
||||
# CPP section:
|
||||
self.listElement = []
|
||||
|
||||
def to_str(self) :
|
||||
return "enum " + self.name + " { ... };"
|
||||
|
||||
|
||||
|
@ -1,23 +1,18 @@
|
||||
#!/usr/bin/python
|
||||
try :
|
||||
# normal install module
|
||||
import ply.lex as lex
|
||||
except ImportError :
|
||||
# local module
|
||||
import lex
|
||||
import os
|
||||
import sys
|
||||
import re
|
||||
##!/usr/bin/python
|
||||
import lutinDebug as debug
|
||||
import Node
|
||||
import Type
|
||||
|
||||
|
||||
|
||||
class Methode():
|
||||
def __init__(self):
|
||||
class Methode(Node.Node):
|
||||
def __init__(self, stack=[], file="", lineNumber=0):
|
||||
name = ""
|
||||
Node.Node.__init__(self, 'methode', name, file, lineNumber)
|
||||
self.name = ""
|
||||
self.returnType = Type.TypeVoid()
|
||||
self.virtual = False # only for C++
|
||||
self.static = False
|
||||
self.inline = False
|
||||
self.const = False # the end of line cont methode is sont for the class ...
|
||||
self.doc = None
|
||||
self.variable = None
|
||||
self.visibility = "private" # only for C++ : "public" "protected" "private"
|
||||
@ -36,5 +31,7 @@ class Methode():
|
||||
ret += "("
|
||||
# ...
|
||||
ret += ")"
|
||||
if self.const == True:
|
||||
ret += " const"
|
||||
return ret
|
||||
|
||||
|
@ -1,29 +1,16 @@
|
||||
#!/usr/bin/python
|
||||
try :
|
||||
# normal install module
|
||||
import ply.lex as lex
|
||||
except ImportError :
|
||||
# local module
|
||||
import lex
|
||||
import os
|
||||
import sys
|
||||
import re
|
||||
import lutinDebug as debug
|
||||
import Node
|
||||
|
||||
import inspect
|
||||
|
||||
class Namespace():
|
||||
def __init__(self):
|
||||
self.name = ""
|
||||
# CPP section:
|
||||
self.namespaces = []
|
||||
self.classes = []
|
||||
# C section:
|
||||
self.structs = []
|
||||
self.variables = []
|
||||
self.methodes = []
|
||||
self.unions = []
|
||||
self.types = []
|
||||
class Namespace(Node.Node):
|
||||
def __init__(self, stack=[], file="", lineNumber=0):
|
||||
if len(stack) != 2:
|
||||
debug.error("Can not parse namespace : " + str(stack))
|
||||
Node.Node.__init__(self, 'namespace', stack[1], file, lineNumber)
|
||||
|
||||
debug.verbose("find class : " + self.to_str())
|
||||
|
||||
def to_str(self) :
|
||||
return ""
|
||||
return "namespace " + self.name + " { ... };"
|
||||
|
||||
|
||||
|
@ -1,22 +1,20 @@
|
||||
#!/usr/bin/python
|
||||
try :
|
||||
# normal install module
|
||||
import ply.lex as lex
|
||||
except ImportError :
|
||||
# local module
|
||||
import lex
|
||||
import os
|
||||
import sys
|
||||
import re
|
||||
import lutinDebug as debug
|
||||
|
||||
class Node():
|
||||
def __init__(self):
|
||||
self.name = ""
|
||||
def __init__(self, type, name="", file="", lineNumber=0):
|
||||
self.nodeType = type
|
||||
self.name = name
|
||||
self.doc = None
|
||||
self.fileName = ""
|
||||
self.lineNumber = ""
|
||||
self.fileName = file
|
||||
self.lineNumber = lineNumber
|
||||
self.subList = []
|
||||
|
||||
def to_str():
|
||||
def to_str(self):
|
||||
return ""
|
||||
|
||||
def append(self, newSubElement):
|
||||
# just add it in a sub List :
|
||||
self.subList.append(newSubElement)
|
||||
|
||||
|
||||
|
@ -3,12 +3,18 @@ import os
|
||||
import sys
|
||||
import re
|
||||
|
||||
import ply.lex as lex
|
||||
import lex
|
||||
|
||||
import inspect
|
||||
import lutinDebug as debug
|
||||
import lutinTools
|
||||
import Class
|
||||
import Namespace
|
||||
import Struct
|
||||
import Union
|
||||
import Methode
|
||||
import Enum
|
||||
import Variable
|
||||
|
||||
tokens = [
|
||||
'NUMBER',
|
||||
@ -106,215 +112,62 @@ def t_error(v):
|
||||
|
||||
lex.lex()
|
||||
|
||||
|
||||
class TagStr(str):
|
||||
"""Wrapper for a string that allows us to store the line number associated with it"""
|
||||
lineno_reg = {}
|
||||
def __new__(cls,*args,**kw):
|
||||
new_obj = str.__new__(cls,*args)
|
||||
if "lineno" in kw:
|
||||
TagStr.lineno_reg[id(new_obj)] = kw["lineno"]
|
||||
return new_obj
|
||||
|
||||
def __del__(self):
|
||||
try:
|
||||
del TagStr.lineno_reg[id(self)]
|
||||
except: pass
|
||||
|
||||
def lineno(self):
|
||||
return TagStr.lineno_reg.get(id(self), -1)
|
||||
|
||||
|
||||
doxygenCommentCache = ""
|
||||
|
||||
#Track what was added in what order and at what depth
|
||||
parseHistory = []
|
||||
|
||||
def is_namespace(nameStack):
|
||||
"""Determines if a namespace is being specified"""
|
||||
if len(nameStack) == 0:
|
||||
return False
|
||||
if nameStack[0] == "namespace":
|
||||
return True
|
||||
return False
|
||||
|
||||
def is_enum_namestack(nameStack):
|
||||
"""Determines if a namestack is an enum namestack"""
|
||||
if len(nameStack) == 0:
|
||||
return False
|
||||
if nameStack[0] == "enum":
|
||||
return True
|
||||
if len(nameStack) > 1 \
|
||||
and nameStack[0] == "typedef" \
|
||||
and nameStack[1] == "enum":
|
||||
return True
|
||||
return False
|
||||
|
||||
def is_fundamental(s):
|
||||
for a in s.split():
|
||||
if a not in ["size_t", \
|
||||
"struct", \
|
||||
"union", \
|
||||
"unsigned", \
|
||||
"signed", \
|
||||
"bool", \
|
||||
"char", \
|
||||
"short", \
|
||||
"int", \
|
||||
"float", \
|
||||
"double", \
|
||||
"long", \
|
||||
"void", \
|
||||
"*"]:
|
||||
return False
|
||||
return True
|
||||
|
||||
def is_function_pointer_stack(stack):
|
||||
"""Count how many non-nested paranthesis are in the stack. Useful for determining if a stack is a function pointer"""
|
||||
paren_depth = 0
|
||||
paren_count = 0
|
||||
star_after_first_paren = False
|
||||
last_e = None
|
||||
for e in stack:
|
||||
if e == "(":
|
||||
paren_depth += 1
|
||||
elif e == ")" \
|
||||
and paren_depth > 0:
|
||||
paren_depth -= 1
|
||||
if paren_depth == 0:
|
||||
paren_count += 1
|
||||
elif e == "*" \
|
||||
and last_e == "(" \
|
||||
and paren_count == 0 \
|
||||
and paren_depth == 1:
|
||||
star_after_first_paren = True
|
||||
last_e = e
|
||||
if star_after_first_paren and paren_count == 2:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def is_method_namestack(stack):
|
||||
r = False
|
||||
if '(' not in stack:
|
||||
r = False
|
||||
elif stack[0] == 'typedef':
|
||||
r = False # TODO deal with typedef function prototypes
|
||||
#elif '=' in stack and stack.index('=') < stack.index('(') and stack[stack.index('=')-1] != 'operator': r = False #disabled July6th - allow all operators
|
||||
elif 'operator' in stack:
|
||||
r = True # allow all operators
|
||||
elif '{' in stack \
|
||||
and stack.index('{') < stack.index('('):
|
||||
r = False # struct that looks like a method/class
|
||||
elif '(' in stack \
|
||||
and ')' in stack:
|
||||
if '{' in stack \
|
||||
and '}' in stack:
|
||||
r = True
|
||||
elif stack[-1] == ';':
|
||||
if is_function_pointer_stack(stack):
|
||||
r = False
|
||||
else:
|
||||
r = True
|
||||
elif '{' in stack:
|
||||
r = True # ideally we catch both braces... TODO
|
||||
else:
|
||||
r = False
|
||||
#Test for case of property set to something with parens such as "static const int CONST_A = (1 << 7) - 1;"
|
||||
if r \
|
||||
and "(" in stack \
|
||||
and "=" in stack \
|
||||
and 'operator' not in stack:
|
||||
if stack.index("=") < stack.index("("): r = False
|
||||
return r
|
||||
|
||||
def is_property_namestack(nameStack):
|
||||
r = False
|
||||
if '(' not in nameStack \
|
||||
and ')' not in nameStack:
|
||||
r = True
|
||||
elif "(" in nameStack \
|
||||
and "=" in nameStack \
|
||||
and nameStack.index("=") < nameStack.index("("):
|
||||
r = True
|
||||
#See if we are a function pointer
|
||||
if not r \
|
||||
and is_function_pointer_stack(nameStack):
|
||||
r = True
|
||||
return r
|
||||
|
||||
def detect_lineno(s):
|
||||
"""Detect the line number for a given token string"""
|
||||
try:
|
||||
rtn = s.lineno()
|
||||
if rtn != -1:
|
||||
return rtn
|
||||
except: pass
|
||||
global curLine
|
||||
return curLine
|
||||
|
||||
def filter_out_attribute_keyword(stack):
|
||||
"""Strips __attribute__ and its parenthetical expression from the stack"""
|
||||
if "__attribute__" not in stack:
|
||||
return stack
|
||||
try:
|
||||
debug.debug("Stripping __attribute__ from %s"% stack)
|
||||
attr_index = stack.index("__attribute__")
|
||||
attr_end = attr_index + 1 #Assuming not followed by parenthetical expression which wont happen
|
||||
#Find final paren
|
||||
if stack[attr_index + 1] == '(':
|
||||
paren_count = 1
|
||||
for i in xrange(attr_index + 2, len(stack)):
|
||||
elm = stack[i]
|
||||
if elm == '(':
|
||||
paren_count += 1
|
||||
elif elm == ')':
|
||||
paren_count -= 1
|
||||
if paren_count == 0:
|
||||
attr_end = i + 1
|
||||
break
|
||||
new_stack = stack[0:attr_index] + stack[attr_end:]
|
||||
debug.debug("stripped stack is %s"% new_stack)
|
||||
return new_stack
|
||||
except:
|
||||
return stack
|
||||
|
||||
|
||||
|
||||
supportedAccessSpecifier = [
|
||||
'public',
|
||||
'protected',
|
||||
'private'
|
||||
]
|
||||
|
||||
|
||||
##
|
||||
## @brief Join the class name element : ['class', 'Bar', ':', ':', 'Foo'] -> ['class', 'Bar::Foo']
|
||||
## @param table Input table to convert. ex: [':', '\t', 'class', 'Bar', ':', ':', 'Foo']
|
||||
## @return The new table. ex: ['class', 'Bar::Foo']
|
||||
##
|
||||
def create_compleate_class_name(table):
|
||||
compleateLine = ""
|
||||
compleateLine = compleateLine.join(table);
|
||||
if "::" not in compleateLine:
|
||||
return table
|
||||
# we need to convert it :
|
||||
out = []
|
||||
for name in table:
|
||||
if len(out) == 0:
|
||||
out.append(name)
|
||||
elif name == ":" \
|
||||
and out[-1].endswith(":"):
|
||||
out[-1] += name
|
||||
elif out[-1].endswith("::"):
|
||||
out[-2] += out[-1] + name
|
||||
del out[-1]
|
||||
else:
|
||||
out.append(name)
|
||||
if "::" not in "".join(table):
|
||||
out = table
|
||||
else:
|
||||
# we need to convert it :
|
||||
out = []
|
||||
for name in table:
|
||||
if len(out) == 0:
|
||||
out.append(name)
|
||||
elif name == ":" \
|
||||
and out[-1].endswith(":"):
|
||||
out[-1] += name
|
||||
elif out[-1].endswith("::"):
|
||||
out[-2] += out[-1] + name
|
||||
del out[-1]
|
||||
else:
|
||||
out.append(name)
|
||||
table = out
|
||||
if 'operator' not in "".join(table):
|
||||
out = table
|
||||
else:
|
||||
out = []
|
||||
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:
|
||||
out[-1] += name
|
||||
else:
|
||||
out.append(name)
|
||||
|
||||
return out
|
||||
|
||||
|
||||
class parse_file():
|
||||
|
||||
def gen_debug_space(self):
|
||||
ret = "[" + str(len(self.braceDepthType)+1) + "]"
|
||||
for iii in range(0,len(self.braceDepthType)):
|
||||
ret += " "
|
||||
return ret
|
||||
|
||||
def __init__(self, fileName):
|
||||
self.m_classes = []
|
||||
self.m_elementParseStack = []
|
||||
@ -365,57 +218,73 @@ class parse_file():
|
||||
self.stack = [] # token stack to find the namespace and the element name ...
|
||||
self.nameStack = [] #
|
||||
self.braceDepth = 0
|
||||
self.braceDepthType = []
|
||||
self.subModuleCountBrace = 0;
|
||||
lex.lex()
|
||||
lex.input(headerFileStr)
|
||||
global curLine
|
||||
global curChar
|
||||
curLine = 0
|
||||
curChar = 0
|
||||
self.curLine = 0
|
||||
self.curChar = 0
|
||||
while True:
|
||||
tok = lex.token()
|
||||
if not tok:
|
||||
break
|
||||
tok.value = TagStr(tok.value, lineno=tok.lineno)
|
||||
debug.debug("TOK: " + str(tok))
|
||||
self.stack.append( tok.value )
|
||||
curLine = tok.lineno
|
||||
curChar = tok.lexpos
|
||||
self.curLine = tok.lineno
|
||||
self.curChar = tok.lexpos
|
||||
# special case to remove internal function define in header:
|
||||
if self.previous_is('function') == True:
|
||||
if tok.type == 'OPEN_BRACE':
|
||||
self.subModuleCountBrace += 1
|
||||
elif tok.type == 'CLOSE_BRACE':
|
||||
self.subModuleCountBrace -= 1
|
||||
if self.subModuleCountBrace <= 0:
|
||||
self.brace_type_pop()
|
||||
continue
|
||||
# normal case:
|
||||
if (tok.type in ('PRECOMP_MACRO', 'PRECOMP_MACRO_CONT')):
|
||||
debug.debug("PRECOMP: " + str(tok))
|
||||
self.stack = []
|
||||
self.nameStack = []
|
||||
# Do nothing for macro ==> many time not needed ...
|
||||
continue
|
||||
if (tok.type == 'OPEN_BRACE'):
|
||||
if tok.type == 'OPEN_BRACE':
|
||||
# When we open a brace, this is the time to parse the stack ...
|
||||
# Clean the stack : (remove \t\r\n , and concatenate the 'xx', ':', ':', 'yy' in 'xx::yy',
|
||||
self.nameStack = create_compleate_class_name(self.nameStack)
|
||||
if len(self.nameStack) <= 0:
|
||||
#open brace with no name ...
|
||||
debug.warning("[" + str(self.braceDepth) + "] find an empty stack ...")
|
||||
self.brace_type_push('empty', [])
|
||||
elif is_a_function(self.nameStack):
|
||||
# need to parse sub function internal description...
|
||||
self.subModuleCountBrace = 1
|
||||
self.brace_type_push('function', self.nameStack)
|
||||
elif 'namespace' in self.nameStack:
|
||||
debug.info("[" + str(self.braceDepth) + "] find a namespace : " + str(self.nameStack));
|
||||
self.brace_type_push('namespace', self.nameStack)
|
||||
elif 'class' in self.nameStack:
|
||||
debug.info("[" + str(self.braceDepth) + "] find a class : " + str(self.nameStack));
|
||||
self.brace_type_push('class', self.nameStack)
|
||||
elif 'enum' in self.nameStack:
|
||||
debug.info("[" + str(self.braceDepth) + "] find a enum : " + str(self.nameStack));
|
||||
self.brace_type_push('enum', self.nameStack)
|
||||
elif 'struct' in self.nameStack:
|
||||
debug.info("[" + str(self.braceDepth) + "] find a struct : " + str(self.nameStack));
|
||||
self.brace_type_push('struct', self.nameStack)
|
||||
elif 'typedef' in self.nameStack:
|
||||
debug.info("[" + str(self.braceDepth) + "] find a typedef : " + str(self.nameStack));
|
||||
self.brace_type_push('typedef', self.nameStack)
|
||||
elif 'union' in self.nameStack:
|
||||
debug.info("[" + str(self.braceDepth) + "] find a union : " + str(self.nameStack));
|
||||
self.brace_type_push('union', self.nameStack)
|
||||
else:
|
||||
debug.warning("[" + str(self.braceDepth) + "] find an unknow stack : " + str(self.nameStack))
|
||||
self.brace_type_push('unknow', self.nameStack)
|
||||
self.stack = []
|
||||
self.nameStack = []
|
||||
self.braceDepth += 1
|
||||
elif tok.type == 'CLOSE_BRACE':
|
||||
self.braceDepth -= 1
|
||||
debug.info("[" + str(self.braceDepth) + "] close brace");
|
||||
if len(self.m_elementParseStack) != 0 \
|
||||
and self.m_elementParseStack[len(self.m_elementParseStack)-1]['level'] == self.braceDepth :
|
||||
self.m_elementParseStack.pop()
|
||||
if len(self.nameStack) != 0:
|
||||
if self.previous_is('enum') == True:
|
||||
debug.info(self.gen_debug_space() + "enum list... : " + str(self.nameStack));
|
||||
else:
|
||||
debug.warning(self.gen_debug_space() + "end brace DROP : " + str(self.nameStack));
|
||||
self.stack = []
|
||||
self.nameStack = []
|
||||
self.brace_type_pop()
|
||||
self.nameStack = create_compleate_class_name(self.nameStack)
|
||||
if tok.type == 'OPEN_PAREN':
|
||||
self.nameStack.append(tok.value)
|
||||
elif tok.type == 'CLOSE_PAREN':
|
||||
@ -457,13 +326,124 @@ class parse_file():
|
||||
self.nameStack.append(tok.value)
|
||||
elif tok.type == 'COLON':
|
||||
if self.nameStack[0] in ['private', 'protected', 'public']:
|
||||
debug.info("[" + str(self.braceDepth) + "] 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.nameStack = []
|
||||
self.stack = []
|
||||
else :
|
||||
self.nameStack.append(tok.value)
|
||||
elif tok.type == 'SEMI_COLON':
|
||||
if len(self.nameStack) != 0:
|
||||
debug.info("[" + str(self.braceDepth) + "] semicolumn : " + str(self.nameStack));
|
||||
self.nameStack = create_compleate_class_name(self.nameStack)
|
||||
if is_a_function(self.nameStack):
|
||||
debug.info(self.gen_debug_space() + "function : " + str(self.nameStack));
|
||||
elif 'namespace' in self.nameStack:
|
||||
debug.debug(self.gen_debug_space() + "find a namespace DECLARATION : " + str(self.nameStack));
|
||||
elif 'class' in self.nameStack:
|
||||
debug.debug(self.gen_debug_space() + "find a class DECLARATION : " + str(self.nameStack));
|
||||
elif 'enum' in self.nameStack:
|
||||
debug.debug(self.gen_debug_space() + "find a enum DECLARATION : " + str(self.nameStack));
|
||||
elif 'struct' in self.nameStack:
|
||||
debug.debug(self.gen_debug_space() + "find a struct DECLARATION : " + str(self.nameStack));
|
||||
elif 'typedef' in self.nameStack:
|
||||
debug.info(self.gen_debug_space() + "find a typedef DECLARATION : " + str(self.nameStack));
|
||||
elif 'union' in self.nameStack:
|
||||
debug.debug(self.gen_debug_space() + "find a union DECLARATION : " + str(self.nameStack));
|
||||
else:
|
||||
if self.previous_is('enum') == True:
|
||||
debug.info(self.gen_debug_space() + "enum list : " + str(self.nameStack));
|
||||
else:
|
||||
# TODO : Check if it is true in all case :
|
||||
self.brace_type_append('variable', self.nameStack);
|
||||
#debug.warning(self.gen_debug_space() + "semicolumn : " + str(self.nameStack));
|
||||
self.stack = []
|
||||
self.nameStack = []
|
||||
|
||||
def create_element(self, type, stack):
|
||||
ret = None
|
||||
if type == 'empty':
|
||||
pass
|
||||
elif type == 'namespace':
|
||||
ret = Namespace.Namespace(stack, self.headerFileName, self.curLine)
|
||||
elif type == 'class':
|
||||
ret = Class.Class(stack, self.headerFileName, self.curLine)
|
||||
elif type == 'struct':
|
||||
ret = Struct.Struct(stack, self.headerFileName, self.curLine)
|
||||
elif type == 'typedef':
|
||||
#ret = Namespace.Namespace(stack, self.headerFileName, self.curLine)
|
||||
# TODO ...
|
||||
pass
|
||||
elif type == 'union':
|
||||
ret = Union.Union(stack, self.headerFileName, self.curLine)
|
||||
elif type == 'function':
|
||||
ret = Methode.Methode(stack, self.headerFileName, self.curLine)
|
||||
elif type == 'enum':
|
||||
ret = Enum.Enum(stack, self.headerFileName, self.curLine)
|
||||
elif type == 'variable':
|
||||
ret = Variable.Variable(stack, self.headerFileName, self.curLine)
|
||||
else:
|
||||
debug.error("unknow type ...")
|
||||
return ret
|
||||
|
||||
def brace_type_push(self, type, stack):
|
||||
debug.info(self.gen_debug_space() + "find a <<" + type + ">> : " + str(stack));
|
||||
myClassElement = self.create_element(type, stack)
|
||||
element = { 'type' : type,
|
||||
'stack' : stack,
|
||||
'access' : None,
|
||||
'node' : myClassElement
|
||||
}
|
||||
if type == 'class':
|
||||
element['access'] = "private"
|
||||
elif type == 'struct':
|
||||
element['access'] = "public"
|
||||
self.braceDepthType.append(element)
|
||||
#debug.info ("append : " + str(element))
|
||||
|
||||
def brace_type_append(self, type, stack):
|
||||
debug.info(self.gen_debug_space() + " append a <<" + type + ">> : " + str(stack));
|
||||
lastType = self.get_last_type()
|
||||
newType = self.create_element(type, stack)
|
||||
if newType == None:
|
||||
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):
|
||||
self.braceDepthType.pop()
|
||||
|
||||
def brace_type_change_access(self, newOne):
|
||||
if len(self.braceDepthType) == 0:
|
||||
debug.error("set access in nothing ... ")
|
||||
return
|
||||
if newOne not in supportedAccessSpecifier:
|
||||
debug.error("unknow access type : " + newOne)
|
||||
return
|
||||
if self.braceDepthType[len(self.braceDepthType)-1]['access'] == None:
|
||||
debug.error("Can not set access in other as : 'class' or 'struct' :" + str(self.braceDepthType[len(self.braceDepthType)-1]))
|
||||
return
|
||||
self.braceDepthType[len(self.braceDepthType)-1]['access'] = newOne
|
||||
|
||||
def previous_is(self, type):
|
||||
if self.get_last_type() == type:
|
||||
return True
|
||||
return False
|
||||
|
||||
def get_last_type(self):
|
||||
if len(self.braceDepthType) > 0:
|
||||
return self.braceDepthType[len(self.braceDepthType)-1]['type']
|
||||
return None
|
||||
|
||||
def is_a_function(stack) :
|
||||
# in a function we need to have functionName + ( + )
|
||||
if len(stack) < 3:
|
||||
return False
|
||||
#can end with 2 possibilities : ')', 'const' or ')'
|
||||
if stack[len(stack)-1] == ')' \
|
||||
or ( stack[len(stack)-2] == ')' \
|
||||
and stack[len(stack)-1] == 'const'):
|
||||
return True
|
||||
return False
|
@ -1,22 +1,22 @@
|
||||
#!/usr/bin/python
|
||||
try :
|
||||
# normal install module
|
||||
import ply.lex as lex
|
||||
except ImportError :
|
||||
# local module
|
||||
import lex
|
||||
import os
|
||||
import sys
|
||||
import re
|
||||
import lutinDebug as debug
|
||||
import Node
|
||||
|
||||
import inspect
|
||||
class Struct(Node.Node):
|
||||
def __init__(self, stack=[], file="", lineNumber=0):
|
||||
name = ""
|
||||
Node.Node.__init__(self, 'struct', name, file, lineNumber)
|
||||
# CPP section:
|
||||
self.namespaces = []
|
||||
self.classes = []
|
||||
# C section:
|
||||
self.structs = []
|
||||
self.variables = []
|
||||
self.methodes = []
|
||||
self.unions = []
|
||||
self.types = []
|
||||
|
||||
def to_str(self) :
|
||||
return "struct " + self.name + " { ... };"
|
||||
|
||||
|
||||
class CppStruct(dict):
|
||||
Structs = []
|
||||
def __init__(self, nameStack):
|
||||
if len(nameStack) >= 2: self['type'] = nameStack[1]
|
||||
else: self['type'] = None
|
||||
self['fields'] = []
|
||||
self.Structs.append( self )
|
||||
global curLine
|
||||
self["line_number"] = curLine
|
||||
|
@ -1,28 +1,48 @@
|
||||
#!/usr/bin/python
|
||||
try :
|
||||
# normal install module
|
||||
import ply.lex as lex
|
||||
except ImportError :
|
||||
# local module
|
||||
import lex
|
||||
import os
|
||||
import sys
|
||||
import re
|
||||
|
||||
import inspect
|
||||
import lutinDebug as debug
|
||||
import Type
|
||||
import Node
|
||||
|
||||
class Type():
|
||||
def __init__(self):
|
||||
def __init__(self, stack=[]):
|
||||
if len(stack) == 0:
|
||||
debug.error("Can not parse Type : " + str(stack))
|
||||
self.name = ""
|
||||
self.const = False # the const xxxxx
|
||||
self.constVar = False # the char* const VarName
|
||||
self.static = False
|
||||
self.inline = False
|
||||
self.reference = False
|
||||
|
||||
self.constVar = False # the char* const VarName
|
||||
if len(stack) == 1:
|
||||
self.name = stack[0]
|
||||
return;
|
||||
# check end const
|
||||
if stack[len(stack)-1] == 'const':
|
||||
self.constVar = True
|
||||
stack = stack[:len(stack)-1]
|
||||
# check if element is a reference ...
|
||||
if stack[len(stack)-1] == '&':
|
||||
self.reference = True
|
||||
stack = stack[:len(stack)-1]
|
||||
# che k if it start with const ...
|
||||
if stack[0] == 'const':
|
||||
self.const = True
|
||||
stack = stack[1:]
|
||||
|
||||
self.name = ""
|
||||
for element in stack:
|
||||
self.name += element
|
||||
|
||||
def to_str(self) :
|
||||
ret = ""
|
||||
if self.const == True:
|
||||
ret += "const "
|
||||
ret += self.name
|
||||
if self.reference == True:
|
||||
ret += " &"
|
||||
if self.constVar == True:
|
||||
ret += " const"
|
||||
return ret
|
||||
|
||||
class TypeVoid(Type):
|
||||
def __init__(self):
|
||||
Type.__init__()
|
||||
self.name = "void"
|
||||
Type.__init__(self, ['void'])
|
||||
|
||||
|
@ -1,10 +1,14 @@
|
||||
#!/usr/bin/python
|
||||
try :
|
||||
# normal install module
|
||||
import ply.lex as lex
|
||||
except ImportError :
|
||||
# local module
|
||||
import lex
|
||||
import os
|
||||
import sys
|
||||
import re
|
||||
import lutinDebug as debug
|
||||
import Node
|
||||
|
||||
class Union(Node.Node):
|
||||
def __init__(self, stack=[], file="", lineNumber=0):
|
||||
name = ""
|
||||
Node.Node.__init__(self, 'union', name, file, lineNumber)
|
||||
self.list = []
|
||||
|
||||
def to_str(self) :
|
||||
return "union " + self.name + " { ... };"
|
||||
|
||||
|
||||
|
@ -1,23 +1,45 @@
|
||||
#!/usr/bin/python
|
||||
try :
|
||||
# normal install module
|
||||
import ply.lex as lex
|
||||
except ImportError :
|
||||
# local module
|
||||
import lex
|
||||
import os
|
||||
import sys
|
||||
import re
|
||||
import lutinDebug as debug
|
||||
import Type
|
||||
import Node
|
||||
|
||||
class Variable():
|
||||
def __init__(self):
|
||||
self.name = ""
|
||||
class Variable(Node.Node):
|
||||
def __init__(self, stack=[], file="", lineNumber=0):
|
||||
if len(stack) < 2:
|
||||
debug.error("Can not parse variable : " + str(stack))
|
||||
Node.Node.__init__(self, 'variable', stack[len(stack)-1], file, lineNumber)
|
||||
# force the sublist error generation ...
|
||||
self.subList = None
|
||||
# default variable :
|
||||
self.type = Type.TypeVoid()
|
||||
self.const = False # the const xxxxx
|
||||
self.constVar = False # the char* const VarName
|
||||
self.static = False
|
||||
self.external = False
|
||||
self.volatile = False
|
||||
|
||||
if 'static' in stack:
|
||||
self.static = True
|
||||
stack = [value for value in stack if value != 'static']
|
||||
if 'volatile' in stack:
|
||||
self.volatile = True
|
||||
stack = [value for value in stack if value != 'volatile']
|
||||
if 'external' in stack:
|
||||
self.external = True
|
||||
stack = [value for value in stack if value != 'external']
|
||||
|
||||
self.type = Type.Type(stack[:len(stack)-1])
|
||||
|
||||
debug.verbose("find variable : " + self.to_str())
|
||||
|
||||
def to_str(self) :
|
||||
return ""
|
||||
ret = ""
|
||||
if self.external == True:
|
||||
ret += "external "
|
||||
if self.volatile == True:
|
||||
ret += "volatile "
|
||||
if self.static == True:
|
||||
ret += "static "
|
||||
ret += self.type.to_str()
|
||||
ret += " "
|
||||
ret += self.name
|
||||
return ret
|
||||
|
||||
|
@ -4,11 +4,9 @@ import sys
|
||||
import lutinTools
|
||||
# TODO : Add try of generic input ...
|
||||
sys.path.append(lutinTools.GetCurrentPath(__file__) + "/ply/ply/")
|
||||
sys.path.append(lutinTools.GetCurrentPath(__file__) + "/cppParser/CppHeaderParser/")
|
||||
sys.path.append(lutinTools.GetCurrentPath(__file__) + "/cppParser/")
|
||||
sys.path.append(lutinTools.GetCurrentPath(__file__) + "/codeBB/")
|
||||
sys.path.append(lutinTools.GetCurrentPath(__file__) + "/codeHL/")
|
||||
import CppHeaderParser
|
||||
import Parse
|
||||
import lutinDocHtml
|
||||
import lutinDocMd
|
||||
@ -133,7 +131,7 @@ class doc:
|
||||
##
|
||||
def add_file(self, filename):
|
||||
debug.debug("adding file in documantation : '" + filename + "'");
|
||||
plop = Parse.parse_file('/home/edupin/dev/perso/Widget.h')
|
||||
plop = Parse.parse_file('Widget.h')
|
||||
debug.error("parse done");
|
||||
|
||||
try:
|
||||
|
@ -2,7 +2,7 @@
|
||||
import lutinDebug as debug
|
||||
import sys
|
||||
import lutinTools
|
||||
import CppHeaderParser
|
||||
#import CppHeaderParser
|
||||
import re
|
||||
import codeBB
|
||||
import collections
|
||||
|
@ -2,7 +2,7 @@
|
||||
import lutinDebug as debug
|
||||
import sys
|
||||
import lutinTools
|
||||
import CppHeaderParser
|
||||
#import CppHeaderParser
|
||||
|
||||
def parse_doxygen(data) :
|
||||
pos = data.find("/*");
|
||||
|
@ -38,7 +38,7 @@ class Target:
|
||||
self.global_flags_xx=['-std=c++11']
|
||||
self.global_flags_mm=['-std=c++11']
|
||||
else:
|
||||
self.global_flags_xx=['-std=c++0X']
|
||||
self.global_flags_xx=['-static-libgcc', '-static-libstdc++', '-L', '-std=c++11']
|
||||
self.global_flags_mm=[]
|
||||
self.global_flags_m=[]
|
||||
self.global_flags_ar=['rcs']
|
||||
|
@ -17,7 +17,9 @@ class Target(lutinTarget.Target):
|
||||
sys.path.append("c:\\MinGW\\bin" )
|
||||
os.environ['PATH'] += ";c:\\MinGW\\bin\\"
|
||||
else:
|
||||
cross = "i586-mingw32msvc-"
|
||||
#cross = "i586-mingw32msvc-"
|
||||
cross = "x86_64-w64-mingw32-"
|
||||
#cross = "i686-w64-mingw32-"
|
||||
|
||||
if typeCompilator!="gcc":
|
||||
debug.error("Android does not support '" + typeCompilator + "' compilator ... availlable : [gcc]")
|
||||
|
Loading…
x
Reference in New Issue
Block a user