X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=specs%2Fstdapi.py;h=1097347f38ce3a97a26b9312c7de183c469e8c0f;hb=81301939f025407ceb284a9dcd5d5a1f05d27b8f;hp=846227ef3468fd2f06956476dc29d10bfd27c2b2;hpb=2b807458f983e01e6c5c49a6c77ee28a145a1b2d;p=apitrace diff --git a/specs/stdapi.py b/specs/stdapi.py index 846227e..1097347 100644 --- a/specs/stdapi.py +++ b/specs/stdapi.py @@ -837,11 +837,8 @@ class Collector(Traverser): -class API: - '''API abstraction. - - Essentially, a collection of types, functions, and interfaces. - ''' +class Module: + '''A collection of functions.''' def __init__(self, name = None): self.name = name @@ -849,50 +846,73 @@ class API: self.functions = [] self.interfaces = [] + def addFunctions(self, functions): + self.functions.extend(functions) + + def addInterfaces(self, interfaces): + self.interfaces.extend(interfaces) + + def mergeModule(self, module): + self.headers.extend(module.headers) + self.functions.extend(module.functions) + self.interfaces.extend(module.interfaces) + + def getFunctionByName(self, name): + for function in self.functions: + if function.name == name: + return function + return None + + +class API: + '''API abstraction. + + Essentially, a collection of types, functions, and interfaces. + ''' + + def __init__(self, modules = None): + self.modules = [] + if modules is not None: + self.modules.extend(modules) + def getAllTypes(self): collector = Collector() - for function in self.functions: - for arg in function.args: - collector.visit(arg.type) - collector.visit(function.type) - for interface in self.interfaces: - collector.visit(interface) - for method in interface.iterMethods(): - for arg in method.args: + for module in self.modules: + for function in module.functions: + for arg in function.args: collector.visit(arg.type) - collector.visit(method.type) + collector.visit(function.type) + for interface in module.interfaces: + collector.visit(interface) + for method in interface.iterMethods(): + for arg in method.args: + collector.visit(arg.type) + collector.visit(method.type) return collector.types + def getAllFunctions(self): + functions = [] + for module in self.modules: + functions.extend(module.functions) + return functions + def getAllInterfaces(self): types = self.getAllTypes() interfaces = [type for type in types if isinstance(type, Interface)] - for interface in self.interfaces: - if interface not in interfaces: - interfaces.append(interface) + for module in self.modules: + for interface in module.interfaces: + if interface not in interfaces: + interfaces.append(interface) return interfaces - def addFunction(self, function): - self.functions.append(function) - - def addFunctions(self, functions): - for function in functions: - self.addFunction(function) - - def addInterface(self, interface): - self.interfaces.append(interface) - - def addInterfaces(self, interfaces): - self.interfaces.extend(interfaces) - - def addApi(self, api): - self.headers.extend(api.headers) - self.addFunctions(api.functions) - self.addInterfaces(api.interfaces) + def addModule(self, module): + self.modules.append(module) def getFunctionByName(self, name): - for function in self.functions: - if function.name == name: - return function + for module in self.modules: + for function in module.functions: + if function.name == name: + return function return None