Deserialize a collection of modules. The modules can contain dependencies on each other. Arguments: data: A dict containing the modules to deserialize. ctx: The deserialization maps to use and to populate. They are populated with information from the deserializ
(data: dict[str, JsonDict], ctx: DeserMaps)
| 104 | |
| 105 | |
| 106 | def deserialize_modules(data: dict[str, JsonDict], ctx: DeserMaps) -> dict[str, ModuleIR]: |
| 107 | """Deserialize a collection of modules. |
| 108 | |
| 109 | The modules can contain dependencies on each other. |
| 110 | |
| 111 | Arguments: |
| 112 | data: A dict containing the modules to deserialize. |
| 113 | ctx: The deserialization maps to use and to populate. |
| 114 | They are populated with information from the deserialized |
| 115 | modules and as a precondition must have been populated by |
| 116 | deserializing any dependencies of the modules being deserialized |
| 117 | (outside of dependencies between the modules themselves). |
| 118 | |
| 119 | Returns a map containing the deserialized modules. |
| 120 | """ |
| 121 | for mod in data.values(): |
| 122 | # First create ClassIRs for every class so that we can construct types and whatnot |
| 123 | for cls in mod["classes"]: |
| 124 | ir = ClassIR(cls["name"], cls["module_name"]) |
| 125 | assert ir.fullname not in ctx.classes, "Class %s already in map" % ir.fullname |
| 126 | ctx.classes[ir.fullname] = ir |
| 127 | |
| 128 | for mod in data.values(): |
| 129 | # Then deserialize all of the functions so that methods are available |
| 130 | # to the class deserialization. |
| 131 | for method in mod["functions"]: |
| 132 | func = FuncIR.deserialize(method, ctx) |
| 133 | assert func.decl.id not in ctx.functions, ( |
| 134 | "Method %s already in map" % func.decl.fullname |
| 135 | ) |
| 136 | ctx.functions[func.decl.id] = func |
| 137 | |
| 138 | return {k: ModuleIR.deserialize(v, ctx) for k, v in data.items()} |
| 139 | |
| 140 | |
| 141 | # ModulesIRs should also always be an *OrderedDict*, but if we |
searching dependent graphs…