MCPcopy Index your code
hub / github.com/SFTtech/openage / Namespace

Class Namespace

openage/codegen/cpp_testlist.py:11–61  ·  view source on GitHub ↗

Represents a C++ namespace, which contains other namespaces and functions. gen_prototypes() generates the code for the namespace.

Source from the content-addressed store, hash-verified

9
10
11class Namespace:
12 """
13 Represents a C++ namespace, which contains other namespaces and functions.
14
15 gen_prototypes() generates the code for the namespace.
16 """
17
18 def __init__(self):
19 self.namespaces = collections.defaultdict(self.__class__)
20 self.functions = []
21
22 def add_functionname(self, path):
23 """
24 Adds a function to the namespace.
25
26 Path is the qualified function "path" (e.g., openage::test::foo)
27 has the path ["openage", "test", "foo"].
28
29 Descends recursively, creating subnamespaces as required.
30 """
31 if len(path) == 1:
32 self.functions.append(path[0])
33 else:
34 subnamespace = self.namespaces[path[0]]
35 subnamespace.add_functionname(path[1:])
36
37 def gen_prototypes(self):
38 """
39 Generates the actual C++ code for this namespace,
40 including all sub-namespaces and function prototypes.
41 """
42 for name in self.functions:
43 yield f"void {name}();\n"
44
45 for namespacename, namespace in sorted(self.namespaces.items()):
46 yield f"namespace {namespacename} {{\n"
47 for line in namespace.gen_prototypes():
48 yield line
49 yield f"}} // {namespacename}\n\n"
50
51 def get_functionnames(self):
52 """
53 Yields all function names in this namespace,
54 as well as all subnamespaces.
55 """
56 for name in self.functions:
57 yield name
58
59 for namespacename, namespace in sorted(self.namespaces.items()):
60 for name in namespace.get_functionnames():
61 yield namespacename + "::" + name
62
63
64def generate_testlist(projectdir):

Callers 1

generate_testlistFunction · 0.85

Calls

no outgoing calls

Tested by 1

generate_testlistFunction · 0.68