X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=specs%2Fstdapi.py;h=57e9aa6eb1fcacda7aa77e976b6f1c06dbb9334c;hb=0f3195f3cb97277c81ee73d0cdd16502b674f396;hp=745ea259586c88641ca2c93f468608c3c0c0f16b;hpb=1b6c87507810fe2d72c81fc109110c1ca25ce94f;p=apitrace diff --git a/specs/stdapi.py b/specs/stdapi.py index 745ea25..57e9aa6 100644 --- a/specs/stdapi.py +++ b/specs/stdapi.py @@ -401,6 +401,12 @@ class Interface(Type): def visit(self, visitor, *args, **kwargs): return visitor.visitInterface(self, *args, **kwargs) + def getMethodByName(self, name): + for method in self.iterMethods(): + if method.name == name: + return method + return None + def iterMethods(self): if self.base is not None: for method in self.base.iterMethods(): @@ -478,11 +484,12 @@ def OpaqueBlob(type, size): class Polymorphic(Type): - def __init__(self, defaultType, switchExpr, switchTypes): + def __init__(self, switchExpr, switchTypes, defaultType, contextLess=True): Type.__init__(self, defaultType.expr) - self.defaultType = defaultType self.switchExpr = switchExpr self.switchTypes = switchTypes + self.defaultType = defaultType + self.contextLess = contextLess def visit(self, visitor, *args, **kwargs): return visitor.visitPolymorphic(self, *args, **kwargs) @@ -504,6 +511,13 @@ class Polymorphic(Type): return zip(cases, types) +def EnumPolymorphic(enumName, switchExpr, switchTypes, defaultType, contextLess=True): + enumValues = [expr for expr, type in switchTypes] + enum = Enum(enumName, enumValues) + polymorphic = Polymorphic(switchExpr, switchTypes, defaultType, contextLess) + return enum, polymorphic + + class Visitor: '''Abstract visitor for the type hierarchy.''' @@ -675,10 +689,10 @@ class Rebuilder(Visitor): return interface def visitPolymorphic(self, polymorphic): - defaultType = self.visit(polymorphic.defaultType) switchExpr = polymorphic.switchExpr switchTypes = [(expr, self.visit(type)) for expr, type in polymorphic.switchTypes] - return Polymorphic(defaultType, switchExpr, switchTypes) + defaultType = self.visit(polymorphic.defaultType) + return Polymorphic(switchExpr, switchTypes, defaultType, polymorphic.contextLess) class MutableRebuilder(Rebuilder):