-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReferenceScope.py
70 lines (53 loc) · 2.08 KB
/
ReferenceScope.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
class ReferenceScope:
def __init__(self):
self.rtype = ""
self.name = ""
self.inheritances = []
self.atributes = []
self.functions = []
self.generics = []
## Prints out the class information
def describe(self, prefix=""):
attributesNames = ""
separator = ""
for atr in self.atributes:
attributesNames += "{} {}: {}\n".format(prefix, atr.name, atr.inheritances[0])
print("\n{}{} {}".format(prefix, self.rtype, self.name))
if len(self.inheritances) > 0:
print("{}* inheritances: {}".format(prefix, self.inheritances))
if len(attributesNames) > 0:
separator = "\n"
print("{}* attributes: {}{}".format(prefix, separator, attributesNames))
if len(self.functions) > 0:
print("{}* functions:".format(prefix))
for func in self.functions:
func.describe(prefix + '\t')
if len(self.generics) > 0:
print("{}* generics:".format(prefix))
for gen in self.generics:
gen.describe(prefix + '\t')
print("{}.".format(prefix))
## Returns true if has some reference of otherClass
def checkExternalReference(self, otherClass):
# local attributes
for attr in self.atributes:
if attr.inheritances[0] == otherClass.name:
return True
# function attributes
for func in self.functions:
for attr in func.atributes:
if attr.inheritances[0] == otherClass.name:
return True
for inheritance in self.inheritances:
if inheritance == otherClass.name:
return True
for gen in self.generics:
if gen.inheritances[0] == otherClass.name:
return True
return False
class ReferenceConnection:
def __init__(self):
self.caller = ReferenceScope()
self.called = ReferenceScope()
def describe(self):
print("{} calls {}".format(self.caller.name, self.called.name))