Skip to content

Commit 1d57c25

Browse files
committed
Add more structure
1 parent 0e2cd94 commit 1d57c25

19 files changed

+192
-12
lines changed

build_model.py renamed to ModelBuilder/ModelBuilder.py

+25-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,31 @@
11
import xml.etree.ElementTree as ET
22

3+
import importlib
4+
import sys
5+
import os
6+
37
from himesis.himesis import Himesis
48
from himesis.himesis_utils import graph_to_dot
5-
9+
from blocks.Block import *
610

711
class ModelBuilder:
812

913
def __init__(self):
1014
self.h = None
11-
15+
16+
def load_class(self, full_class_string):
17+
directory, module_name = os.path.split(full_class_string)
18+
module_name = os.path.splitext(module_name)[0]
19+
20+
path = list(sys.path)
21+
sys.path.insert(0, directory)
22+
23+
try:
24+
module = __import__(module_name)
25+
finally:
26+
sys.path[:] = path # restore
27+
return {module_name : getattr(module, module_name)}
28+
1229
def build(self, filename):
1330

1431
self.h = Himesis(name="simple")
@@ -18,11 +35,13 @@ def build(self, filename):
1835
tree = ET.parse(filename)
1936
root = tree.getroot()
2037

21-
symbol_table = self.traverse_node(root, None, {})
38+
node_kind = xmlNode.get('kind')
2239

23-
print("Symbol Table:")
24-
print(symbol_table)
25-
graph_to_dot("simple", self.h, directory = "./examples/")
40+
#symbol_table = self.traverse_node(root, None, {})
41+
42+
#print("Symbol Table:")
43+
#print(symbol_table)
44+
#graph_to_dot("simple", self.h, directory = "./examples/")
2645

2746
def traverse_node(self, node, parent, symbol_table):
2847
node_kind = node.get('kind')
File renamed without changes.

ModelBuilder/blocks/Block.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
3+
from XML import *
4+
class Block:
5+
6+
def __init__(self):
7+
pass
8+
9+
@staticmethod
10+
def createBlock(xmlNode):
11+
12+
node_kind = xmlNode.get('kind')
13+
print(node_kind)
14+
15+
Block.load_class("./XML.XML")
16+
17+
#function to dynamically load a new class
18+
19+
@staticmethod

ModelBuilder/blocks/XML.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from . import *
2+
3+
class XML(Block):
4+
def __init__(self):
5+
Block.__init__(self)
File renamed without changes.

ModelBuilder/himesis/__init__.py

Whitespace-only changes.
File renamed without changes.

himesis/himesis.py renamed to ModelBuilder/himesis/himesis.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

22
import uuid, os.path, copy, pickle # Pickle is used to save the attribute values as pickled strings
33
import igraph as ig
4-
from himesis.util import misc
5-
from himesis.util.misc import indent_text
6-
from himesis.epsilon_parser import EpsilonParser
4+
from util import misc
5+
from util.misc import indent_text
6+
from epsilon_parser import EpsilonParser
77

88

99

File renamed without changes.

ModelBuilder/himesis/util/__init__.py

Whitespace-only changes.
File renamed without changes.
File renamed without changes.

output.txt

+134
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
Starting to parse code
2+
===Start writing XML
3+
===Done writing XML
4+
Hello
5+
XML
6+
Symbol table:
7+
{}
8+
CursorKind.TRANSLATION_UNIT
9+
Symbol table:
10+
{}
11+
CursorKind.TYPEDEF_DECL
12+
Symbol table:
13+
{}
14+
CursorKind.TYPEDEF_DECL
15+
Child results
16+
[]
17+
KIND NOT HANDLED: CursorKind.TYPEDEF_DECL
18+
CursorKind.TYPEDEF_DECL
19+
Symbol table:
20+
{}
21+
CursorKind.TYPEDEF_DECL
22+
Child results
23+
[]
24+
KIND NOT HANDLED: CursorKind.TYPEDEF_DECL
25+
CursorKind.TYPEDEF_DECL
26+
Symbol table:
27+
{}
28+
CursorKind.TYPE_REF
29+
Symbol table:
30+
{}
31+
CursorKind.TYPE_REF
32+
Child results
33+
[]
34+
KIND NOT HANDLED: CursorKind.TYPE_REF
35+
CursorKind.TYPEDEF_DECL
36+
Child results
37+
[{}]
38+
KIND NOT HANDLED: CursorKind.TYPEDEF_DECL
39+
CursorKind.PARM_DECL
40+
Symbol table:
41+
{}
42+
CursorKind.PARM_DECL
43+
Child results
44+
[]
45+
CursorKind.DECL_STMT
46+
Symbol table:
47+
{'a': 0}
48+
CursorKind.VAR_DECL
49+
Symbol table:
50+
{'a': 0}
51+
CursorKind.INTEGER_LITERAL
52+
Symbol table:
53+
{'a': 0}
54+
CursorKind.INTEGER_LITERAL
55+
Child results
56+
[]
57+
Creating: {'1000': 1}
58+
CursorKind.VAR_DECL
59+
Child results
60+
[(1, {'a': 0, '1000': 1})]
61+
Creating: {'b': 1}
62+
CursorKind.DECL_STMT
63+
Child results
64+
[(1, {'a': 0, 'b': 1, '1000': 1})]
65+
KIND NOT HANDLED: CursorKind.DECL_STMT
66+
CursorKind.IF_STMT
67+
Symbol table:
68+
{'a': 0, 'b': 1, '1000': 1}
69+
CursorKind.BINARY_OPERATOR
70+
Symbol table:
71+
{'a': 0, 'b': 1, '1000': 1}
72+
CursorKind.UNEXPOSED_EXPR
73+
Symbol table:
74+
{'a': 0, 'b': 1, '1000': 1}
75+
CursorKind.DECL_REF_EXPR
76+
Symbol table:
77+
{'a': 0, 'b': 1, '1000': 1}
78+
CursorKind.DECL_REF_EXPR
79+
Child results
80+
[]
81+
CursorKind.UNEXPOSED_EXPR
82+
Child results
83+
[(0, {'a': 0, 'b': 1, '1000': 1})]
84+
KIND NOT HANDLED: CursorKind.UNEXPOSED_EXPR
85+
CursorKind.INTEGER_LITERAL
86+
Symbol table:
87+
{'a': 0, 'b': 1, '1000': 1}
88+
CursorKind.INTEGER_LITERAL
89+
Child results
90+
[]
91+
Creating: {'50': 2}
92+
CursorKind.BINARY_OPERATOR
93+
Child results
94+
[(0, {'a': 0, 'b': 1, '50': 2, '1000': 1}), (2, {'a': 0, 'b': 1, '50': 2, '1000': 1})]
95+
CursorKind.BINARY_OPERATOR
96+
Symbol table:
97+
{'a': 0, 'b': 1, '50': 2, '1000': 1}
98+
CursorKind.DECL_REF_EXPR
99+
Symbol table:
100+
{'a': 0, 'b': 1, '50': 2, '1000': 1}
101+
CursorKind.DECL_REF_EXPR
102+
Child results
103+
[]
104+
CursorKind.INTEGER_LITERAL
105+
Symbol table:
106+
{'a': 0, 'b': 1, '50': 2, '1000': 1}
107+
CursorKind.INTEGER_LITERAL
108+
Child results
109+
[]
110+
Creating: {'100': 4}
111+
CursorKind.BINARY_OPERATOR
112+
Child results
113+
[(1, {'a': 0, '100': 4, 'b': 1, '50': 2, '1000': 1}), (4, {'a': 0, '100': 4, 'b': 1, '50': 2, '1000': 1})]
114+
Is assignment
115+
CursorKind.IF_STMT
116+
Child results
117+
[(3, {'a': 0, '100': 4, 'b': 1, '50': 2, '1000': 1}), (None, {'a': 0, 'b': 4, '100': 4, '50': 2, '1000': 1})]
118+
IF children: 2
119+
Symbol table:
120+
{'a': 0, '100': 4, 'b': 1, '50': 2, '1000': 1}
121+
Possible values
122+
set([0])
123+
Possible values
124+
set([1, 4])
125+
CursorKind.TRANSLATION_UNIT
126+
Child results
127+
[{'a': 0, '100': 4, 'b': 1, '50': 2, '1000': 1}, {'a': 0, '100': 4, 'b': 1, '50': 2, '1000': 1}, {'a': 0, '100': 4, 'b': 1, '50': 2, '1000': 1}, {'a': 0, 'b': 5, '100': 4, '50': 2, '1000': 1}]
128+
KIND NOT HANDLED: CursorKind.TRANSLATION_UNIT
129+
XML
130+
Child results
131+
[{'a': 0, '100': 4, 'b': 1, '50': 2, '1000': 1}]
132+
KIND NOT HANDLED: XML
133+
Symbol Table:
134+
{'a': 0, '100': 4, 'b': 1, '50': 2, '1000': 1}

parse_source.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def main():
107107
if not tu:
108108
parser.error("unable to load input")
109109

110-
#print("Starting to get info")
110+
print("Starting to parse code")
111111

112112

113113
#pprint(('diags', map(get_diag_info, tu.diagnostics)))

refs/BusinessRules.pdf

694 KB
Binary file not shown.

refs/auto-compiler.pdf

217 KB
Binary file not shown.

run.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
python2 parse_source.py examples/simple.c
2-
python build_model.py examples/simple.c.xml
2+
python2 ModelBuilder/ModelBuilder.py examples/simple.c.xml
33

to_xml.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import xml.etree.cElementTree as ET
22

33
def write_xml(program, name):
4+
5+
print("===Start writing XML")
6+
47
root = ET.Element("root")
58
root.set("kind", "XML")
69

@@ -10,7 +13,7 @@ def write_xml(program, name):
1013

1114
tree.write(name + ".xml")
1215

13-
16+
print("===Done writing XML")
1417

1518

1619
def write_node(node, parent):

0 commit comments

Comments
 (0)