Skip to content

Commit 25f2352

Browse files
committed
v1.1.1 alpha patch
1 parent 0e8bdc2 commit 25f2352

File tree

4 files changed

+49
-46
lines changed

4 files changed

+49
-46
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# visualizer (v1.1.1)
1+
# visualizer (v1.1.1a)
22

33
This project aims to make a quick visual representation for a C++ project (though Python support is planned).
44

visualizer/tree_objects.py

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,35 @@ def __init__(self):
2222
self.namespaces = {}
2323

2424

25-
def parse_cursor(children_nodes, cursor: clang.cindex.Cursor, parent_node):
25+
def parse_cursor(children_nodes, cursor: clang.cindex.Cursor, parent_node, bruteforce: bool, verbose: bool):
2626
if cursor.kind.name == 'COMPOUND_STMT':
2727
for i in cursor.get_children():
28-
parse_cursor(children_nodes, i, parent_node)
28+
parse_cursor(children_nodes, i, parent_node, bruteforce, verbose)
2929
elif cursor.kind.name == 'FOR_STMT':
30-
children_nodes.append(ForLoop(parent_node, cursor))
30+
children_nodes.append(ForLoop(parent_node, cursor, bruteforce, verbose))
3131
elif cursor.kind.name == 'CXX_FOR_RANGE_STMT':
32-
children_nodes.append(ForRangeLoop(parent_node, cursor))
32+
children_nodes.append(ForRangeLoop(parent_node, cursor, bruteforce, verbose))
3333
elif cursor.kind.name == 'WHILE_STMT':
34-
children_nodes.append(WhileLoop(parent_node, cursor))
34+
children_nodes.append(WhileLoop(parent_node, cursor, bruteforce, verbose))
3535
elif cursor.kind.name == 'IF_STMT':
36-
children_nodes.append(If(parent_node, cursor))
36+
children_nodes.append(If(parent_node, cursor, bruteforce, verbose))
3737
elif cursor.kind.name in ['BINARY_OPERATOR',
3838
'CALL_EXPR',
3939
'RETURN_STMT',
4040
'DECL_STMT',
4141
'UNARY_OPERATOR',
4242
'UNEXPOSED_EXPR',
4343
'CXX_DELETE_EXPR',
44+
'BREAK_STMT',
45+
'CXX_TRY_STMT',
46+
'COMPOUND_ASSIGNMENT_OPERATOR',
47+
'CXX_UNARY_EXPR',
4448
]:
4549
if len(children_nodes) == 0 or type(children_nodes[-1]) != CodeBlock:
46-
children_nodes.append(CodeBlock(parent_node))
47-
children_nodes[-1].add_line(cursor)
50+
children_nodes.append(CodeBlock(parent_node, bruteforce, verbose))
51+
children_nodes[-1].add_line(cursor, bruteforce, verbose)
4852
else:
49-
# FIXME: pass brute-force
50-
output_error(False, "Unknown object: ", cursor.kind.name, " located: ", cursor.location)
53+
output_error(bruteforce, "Unknown object: ", cursor.kind.name, " located: ", cursor.location)
5154

5255

5356
class Node:
@@ -61,7 +64,7 @@ def __init__(self, parent_node):
6164

6265
class CodeLine(Node):
6366
# FIXME: move construction away from constructor
64-
def __init__(self, parent_node, cursor: clang.cindex.Cursor):
67+
def __init__(self, parent_node, cursor: clang.cindex.Cursor, bruteforce: bool, verbose: bool):
6568
super().__init__(parent_node)
6669
self.cursor = cursor
6770

@@ -71,12 +74,12 @@ def print(self, depth):
7174

7275
class CodeBlock(Node):
7376
# FIXME: move construction away from constructor
74-
def __init__(self, parent_node):
77+
def __init__(self, parent_node, bruteforce: bool, verbose: bool):
7578
super().__init__(parent_node)
7679
self.body_nodes = []
7780

78-
def add_line(self, cursor: clang.cindex.Cursor):
79-
self.body_nodes.append(CodeLine(self, cursor))
81+
def add_line(self, cursor: clang.cindex.Cursor, bruteforce: bool, verbose: bool):
82+
self.body_nodes.append(CodeLine(self, cursor, bruteforce, verbose))
8083

8184
def print(self, depth):
8285
print('\t' * depth, 'Block of code:')
@@ -86,7 +89,7 @@ def print(self, depth):
8689

8790
class Loop(Node):
8891
# FIXME: move construction away from constructor
89-
def __init__(self, parent_node, cursor: clang.cindex.Cursor):
92+
def __init__(self, parent_node, cursor: clang.cindex.Cursor, bruteforce: bool, verbose: bool):
9093
super().__init__(parent_node)
9194
self.body_nodes = []
9295

@@ -97,11 +100,11 @@ def print(self, depth):
97100

98101
class ForLoop(Loop):
99102
# FIXME: move construction away from constructor
100-
def __init__(self, parent_node, cursor: clang.cindex.Cursor):
101-
super().__init__(parent_node, cursor)
103+
def __init__(self, parent_node, cursor: clang.cindex.Cursor, bruteforce: bool, verbose: bool):
104+
super().__init__(parent_node, cursor, bruteforce, verbose)
102105

103106
cursor_children = list(cursor.get_children())
104-
parse_cursor(self.body_nodes, cursor_children[-1], self)
107+
parse_cursor(self.body_nodes, cursor_children[-1], self, bruteforce, verbose)
105108
# FIXME: make a proper loop arguments parse
106109

107110
def print(self, depth):
@@ -111,11 +114,11 @@ def print(self, depth):
111114

112115
class ForRangeLoop(Loop):
113116
# FIXME: move construction away from constructor
114-
def __init__(self, parent_node, cursor: clang.cindex.Cursor):
115-
super().__init__(parent_node, cursor)
117+
def __init__(self, parent_node, cursor: clang.cindex.Cursor, bruteforce: bool, verbose: bool):
118+
super().__init__(parent_node, cursor, bruteforce, verbose)
116119

117120
cursor_children = list(cursor.get_children())
118-
parse_cursor(self.body_nodes, cursor_children[-1], self)
121+
parse_cursor(self.body_nodes, cursor_children[-1], self, bruteforce, verbose)
119122
# FIXME: make a proper loop arguments parse
120123

121124
def print(self, depth):
@@ -125,11 +128,11 @@ def print(self, depth):
125128

126129
class WhileLoop(Loop):
127130
# FIXME: move construction away from constructor
128-
def __init__(self, parent_node, cursor: clang.cindex.Cursor):
129-
super().__init__(parent_node, cursor)
131+
def __init__(self, parent_node, cursor: clang.cindex.Cursor, bruteforce: bool, verbose: bool):
132+
super().__init__(parent_node, cursor, bruteforce, verbose)
130133

131134
cursor_children = list(cursor.get_children())
132-
parse_cursor(self.body_nodes, cursor_children[-1], self)
135+
parse_cursor(self.body_nodes, cursor_children[-1], self, bruteforce, verbose)
133136
# FIXME: make a proper loop arguments parse
134137

135138
def print(self, depth):
@@ -139,7 +142,7 @@ def print(self, depth):
139142

140143
class If(Node):
141144
# FIXME: move construction away from constructor
142-
def __init__(self, parent_node, cursor: clang.cindex.Cursor):
145+
def __init__(self, parent_node, cursor: clang.cindex.Cursor, bruteforce: bool, verbose: bool):
143146
super().__init__(parent_node)
144147

145148
self.body_nodes = []
@@ -150,9 +153,9 @@ def __init__(self, parent_node, cursor: clang.cindex.Cursor):
150153
# FIXME: parse condition
151154

152155
for i in cursor_children[1].get_children():
153-
parse_cursor(self.body_nodes, i, self)
156+
parse_cursor(self.body_nodes, i, self, bruteforce, verbose)
154157
if len(cursor_children) == 3:
155-
parse_cursor(self.else_nodes, cursor_children[2], self)
158+
parse_cursor(self.else_nodes, cursor_children[2], self, bruteforce, verbose)
156159

157160
def print(self, depth):
158161
print('\t' * depth, 'If:')
@@ -171,13 +174,13 @@ def __init__(self, parent_node):
171174
self.body_nodes = []
172175
self.name = ""
173176

174-
def parse_cpp(self, cursor: clang.cindex.Cursor):
177+
def parse_cpp(self, cursor: clang.cindex.Cursor, bruteforce: bool, verbose: bool):
175178
self.name = cursor.spelling
176179

177180
cursor_children = list(cursor.get_children())
178181

179182
if len(cursor_children) and cursor_children[-1].kind.name == 'COMPOUND_STMT':
180-
parse_cursor(self.body_nodes, cursor_children[-1], self)
183+
parse_cursor(self.body_nodes, cursor_children[-1], self, bruteforce, verbose)
181184
# FIXME: parse function arguments
182185
# FIXME: parse function return
183186
# TODO: add print method
@@ -189,7 +192,7 @@ def __init__(self, parent_node):
189192
self.body_nodes = []
190193
self.name = ""
191194

192-
def parse_cpp(self, cursor: clang.cindex.Cursor):
195+
def parse_cpp(self, cursor: clang.cindex.Cursor, bruteforce: bool, verbose: bool):
193196
self.name = cursor.spelling
194197

195198
# FIXME: parse class data (methods are parsed externally)
@@ -202,7 +205,7 @@ def __init__(self, parent_node):
202205
self.body_nodes = []
203206
self.name = ""
204207

205-
def parse_cpp(self, cursor: clang.cindex.Cursor, code_tree: CodeTree):
208+
def parse_cpp(self, cursor: clang.cindex.Cursor, code_tree: CodeTree, bruteforce: bool, verbose: bool):
206209
self.name = cursor.spelling
207210

208211
# cursor_dump_rec(cursor, 0, 2)
@@ -217,7 +220,7 @@ def parse_cpp(self, cursor: clang.cindex.Cursor, code_tree: CodeTree):
217220
elif i.kind.name == 'CXX_METHOD':
218221
code_tree.methods[i.get_usr()] = Function(self)
219222
self.body_nodes.append(code_tree.methods[i.get_usr()])
220-
code_tree.methods[i.get_usr()].parse_cpp(i)
223+
code_tree.methods[i.get_usr()].parse_cpp(i, bruteforce, verbose)
221224
else:
222225
output_error(False, "Unknown structure field: ", i.kind.name)
223226

visualizer/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def no_print(*args):
3333

3434
def output_error(brute_force: bool, *args):
3535
if brute_force:
36-
red_on_black_print(args)
36+
red_on_black_print(*args)
3737
else:
3838
s = ''
3939
for i in args:

visualizer/visualizer.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,22 +88,22 @@ def parse_cpp_file(self, file_path: str) -> None:
8888

8989
diagnostics = list(translation_unit.diagnostics)
9090
if len(diagnostics):
91-
output_error(self.bruteforce, 'FOUND ERRORS:')
91+
message = 'FOUND ERRORS:\n'
9292
for diag in diagnostics:
93-
output_error(self.bruteforce, 'Error:')
94-
output_error(self.bruteforce, '\tseverity:', diag.severity)
95-
output_error(self.bruteforce, '\tlocation:', diag.location)
96-
output_error(self.bruteforce, '\tspelling:', diag.spelling)
97-
output_error(self.bruteforce, '\tranges:', diag.ranges)
98-
output_error(self.bruteforce, '\tfixits:', diag.fixits)
99-
# sys.exit(2)
93+
message += 'Error:\n'
94+
message += '\tseverity:' + str(diag.severity) + '\n'
95+
message += '\tlocation:' + str(diag.location) + '\n'
96+
message += '\tspelling:' + str(diag.spelling) + '\n'
97+
message += '\tranges:' + str(diag.ranges) + '\n'
98+
message += '\tfixits:' + str(diag.fixits) + '\n'
99+
output_error(self.bruteforce, message)
100100

101101
for cursor in translation_unit.cursor.get_children():
102102
if not is_file_in_standart(str(cursor.location.file)):
103103
if cursor.kind.name == 'FUNCTION_DECL':
104104
if self.code_tree.functions.get(cursor.get_usr()) is None:
105105
self.code_tree.functions[cursor.get_usr()] = Function(None)
106-
self.code_tree.functions[cursor.get_usr()].parse_cpp(cursor)
106+
self.code_tree.functions[cursor.get_usr()].parse_cpp(cursor, self.bruteforce, self.verbose)
107107
elif cursor.kind.name == 'CXX_METHOD':
108108
cursor_children = list(cursor.get_children())
109109
for i in cursor_children:
@@ -118,15 +118,15 @@ def parse_cpp_file(self, file_path: str) -> None:
118118
if self.code_tree.methods.get(cursor.get_usr()) is None:
119119
output_error(self.bruteforce, "Error: Could not create a method!!")
120120
else:
121-
self.code_tree.methods[cursor.get_usr()].parse_cpp(cursor)
121+
self.code_tree.methods[cursor.get_usr()].parse_cpp(cursor, self.bruteforce, self.verbose)
122122
elif cursor.kind.name == 'CLASS_DECL':
123123
if self.code_tree.classes.get(cursor.get_usr()) is None:
124124
self.code_tree.classes[cursor.get_usr()] = Class(None)
125-
self.code_tree.classes[cursor.get_usr()].parse_cpp(cursor)
125+
self.code_tree.classes[cursor.get_usr()].parse_cpp(cursor, self.bruteforce, self.verbose)
126126
elif cursor.kind.name == 'STRUCT_DECL':
127127
if self.code_tree.structures.get(cursor.get_usr()) is None:
128128
self.code_tree.structures[cursor.get_usr()] = Struct(None)
129-
self.code_tree.structures[cursor.get_usr()].parse_cpp(cursor, self.code_tree)
129+
self.code_tree.structures[cursor.get_usr()].parse_cpp(cursor, self.code_tree, self.bruteforce, self.verbose)
130130
else:
131131
output_error(self.bruteforce, "Error: ", cursor.kind.name, " not supported!!")
132132

0 commit comments

Comments
 (0)