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
|
from dataclasses import dataclass, field
from typing import List, Set
@dataclass(frozen=True, eq=True)
class Type:
def type(self,
specialize_templates: bool = False,
without_template: bool = False) -> str:
assert False
def decl(self,
label: str,
specialize_templates: bool = False,
without_template: bool = False) -> str:
type_str = self.type(specialize_templates=specialize_templates,
without_template=without_template)
if type_str:
type_str = f"{type_str} "
return f"{type_str}{label}"
def traverse(self, callback, depth):
callback(self, depth)
def dependencies(self, filter=None, deps=None) -> Set["Type"]:
if deps == None:
deps = set()
def callback(type, depth):
if type in deps:
return True
if not filter or filter(type):
deps.add(type)
self.traverse(callback, depth=0)
return deps
def collect(self, filter=None, collection=None) -> List["Type"]:
if collection == None:
collection = set()
def callback(type, depth):
if not filter or filter(type):
collection.append(type)
self.traverse(callback, depth=0)
return collection
@property
def is_builtin(self):
return False
|