Back to index

enigmail  1.4.3
Functions | Variables
typelib Namespace Reference

Functions

def isDipperType
def build_interface
def write_typelib

Variables

dictionary TypeMap
tuple o = OptionParser()
string help = "Directory to search for imported files"
list file = args[0]
tuple p = xpidl.IDLParser(outputdir=options.cachedir, regen=True)
tuple outfd = open(options.outfile, 'wb')
 closeoutfd = True
tuple idl = p.parse(open(file).read(), filename=file)
tuple depfd = open(options.depfile, 'w')
list deps = [dep.replace('\\', '/') for dep in idl.deps]

Function Documentation

def typelib.build_interface (   iface,
  ifaces 
)

Definition at line 79 of file typelib.py.

00079 
00080 def build_interface(iface, ifaces):
00081     def get_type(type, calltype, iid_is=None, size_is=None):
00082         """ Return the appropriate xpt.Type object for this param """
00083 
00084         while isinstance(type, xpidl.Typedef):
00085             type = type.realtype
00086 
00087         if isinstance(type, xpidl.Builtin):
00088             if type.name == 'string' and size_is != None:
00089                   return xpt.StringWithSizeType(size_is, size_is)
00090             elif type.name == 'wstring' and size_is != None:
00091                   return xpt.WideStringWithSizeType(size_is, size_is)
00092             else:
00093                   tag = TypeMap[type.name]
00094                   isPtr = (tag == xpt.Type.Tags.char_ptr or tag == xpt.Type.Tags.wchar_t_ptr)
00095                   return xpt.SimpleType(tag,
00096                                         pointer=isPtr,
00097                                         reference=False)
00098 
00099         if isinstance(type, xpidl.Array):
00100             # NB: For an Array<T> we pass down the iid_is to get the type of T.
00101             #     This allows Arrays of InterfaceIs types to work.
00102             return xpt.ArrayType(get_type(type.type, calltype, iid_is), size_is,
00103                                  #XXXkhuey length_is duplicates size_is (bug 677788),
00104                                  size_is)
00105 
00106         if isinstance(type, xpidl.Interface) or isinstance(type, xpidl.Forward):
00107             xptiface = None
00108             for i in ifaces:
00109                 if i.name == type.name:
00110                     xptiface = i
00111 
00112             if not xptiface:
00113                 xptiface = xpt.Interface(name=type.name)
00114                 ifaces.append(xptiface)
00115 
00116             return xpt.InterfaceType(xptiface)
00117 
00118         if isinstance(type, xpidl.Native):
00119             if type.specialtype:
00120                 # XXXkhuey jsval is marked differently in the typelib and in the headers :-(
00121                 isPtr = (type.isPtr(calltype) or type.isRef(calltype)) and not type.specialtype == 'jsval'
00122                 isRef = type.isRef(calltype) and not type.specialtype == 'jsval'
00123                 return xpt.SimpleType(TypeMap[type.specialtype],
00124                                       pointer=isPtr,
00125                                       reference=isRef)
00126             elif iid_is != None:
00127                 return xpt.InterfaceIsType(iid_is)
00128             else:
00129                 # void ptr
00130                 return xpt.SimpleType(TypeMap['void'],
00131                                       pointer=True,
00132                                       reference=False)
00133 
00134         raise Exception("Unknown type!")
00135 
00136     def get_nsresult():
00137         return xpt.SimpleType(TypeMap['nsresult'])
00138 
00139     def build_nsresult_param():
00140         return xpt.Param(get_nsresult())
00141 
00142     def get_result_type(m):
00143         if not m.notxpcom:
00144             return get_nsresult()
00145 
00146         return get_type(m.realtype, '')
00147 
00148     def build_result_param(m):
00149         return xpt.Param(get_result_type(m))
00150 
00151     def build_retval_param(m):
00152         type = get_type(m.realtype, 'out')
00153         if isDipperType(type.tag):
00154             # NB: The retval bit needs to be set here, contrary to what the
00155             # xpt spec says.
00156             return xpt.Param(type, in_=True, retval=True, dipper=True)
00157         return xpt.Param(type, in_=False, out=True, retval=True)
00158 
00159     def build_attr_param(a, getter=False, setter=False):
00160         if not (getter or setter):
00161             raise Exception("Attribute param must be for a getter or a setter!")
00162 
00163         type = get_type(a.realtype, getter and 'out' or 'in')
00164         if setter:
00165             return xpt.Param(type)
00166         else:
00167             if isDipperType(type.tag):
00168                 # NB: The retval bit needs to be set here, contrary to what the
00169                 # xpt spec says.
00170                 return xpt.Param(type, in_=True, retval=True, dipper=True)
00171             return xpt.Param(type, in_=False, out=True, retval=True)
00172 
00173     if iface.namemap is None:
00174         raise Exception("Interface was not resolved.")
00175 
00176     consts = []
00177     methods = []
00178 
00179     def build_const(c):
00180         consts.append(xpt.Constant(c.name, get_type(c.basetype, ''), c.getValue()))
00181 
00182     def build_method(m):
00183         params = []
00184 
00185         def build_param(p):
00186             def findattr(p, attr):
00187                 if hasattr(p, attr) and getattr(p, attr):
00188                     for i, param in enumerate(m.params):
00189                         if param.name == getattr(p, attr):
00190                             return i
00191                     return None
00192 
00193             iid_is = findattr(p, 'iid_is')
00194             size_is = findattr(p, 'size_is')
00195 
00196             in_ = p.paramtype.count("in")
00197             out = p.paramtype.count("out")
00198             dipper = False
00199             type = get_type(p.realtype, p.paramtype, iid_is=iid_is, size_is=size_is)
00200             if out and isDipperType(type.tag):
00201                 out = False
00202                 dipper = True
00203 
00204             return xpt.Param(type, in_, out, p.retval, p.shared, dipper, p.optional)
00205 
00206         for p in m.params:
00207             params.append(build_param(p))
00208 
00209         if not m.notxpcom and m.realtype.name != 'void':
00210             params.append(build_retval_param(m))
00211 
00212         methods.append(xpt.Method(m.name, build_result_param(m), params,
00213                                   getter=False, setter=False, notxpcom=m.notxpcom,
00214                                   constructor=False, hidden=m.noscript,
00215                                   optargc=m.optional_argc,
00216                                   implicit_jscontext=m.implicit_jscontext))
00217 
00218     def build_attr(a):
00219         # Write the getter
00220         methods.append(xpt.Method(a.name, build_nsresult_param(),
00221                                   [build_attr_param(a, getter=True)],
00222                                   getter=True, setter=False, notxpcom=a.notxpcom,
00223                                   constructor=False, hidden=a.noscript,
00224                                   optargc=False,
00225                                   implicit_jscontext=a.implicit_jscontext))
00226 
00227         # And maybe the setter
00228         if not a.readonly:
00229             methods.append(xpt.Method(a.name, build_nsresult_param(),
00230                                       [build_attr_param(a, setter=True)],
00231                                       getter=False, setter=True, notxpcom=a.notxpcom,
00232                                       constructor=False, hidden=a.noscript,
00233                                       optargc=False,
00234                                       implicit_jscontext=a.implicit_jscontext))
00235 
00236     for member in iface.members:
00237         if isinstance(member, xpidl.ConstMember):
00238             build_const(member)
00239         elif isinstance(member, xpidl.Attribute):
00240             build_attr(member)
00241         elif isinstance(member, xpidl.Method):
00242             build_method(member)
00243         elif isinstance(member, xpidl.CDATA):
00244             pass
00245         else:
00246             raise Exception("Unexpected interface member: %s" % member)
00247 
00248     parent = None
00249     if iface.base:
00250         for i in ifaces:
00251             if i.name == iface.base:
00252                 parent = i
00253         if not parent:
00254             parent = xpt.Interface(name=iface.base)
00255             ifaces.append(parent)
00256 
00257     return xpt.Interface(iface.name, iface.attributes.uuid, methods=methods,
00258                          constants=consts, resolved=True, parent=parent,
00259                          scriptable=iface.attributes.scriptable,
00260                          function=iface.attributes.function,
00261                          builtinclass=iface.attributes.builtinclass)

Here is the call graph for this function:

Here is the caller graph for this function:

def typelib.isDipperType (   type)

Definition at line 76 of file typelib.py.

00076 
00077 def isDipperType(type):
00078     return type == xpt.Type.Tags.DOMString or type == xpt.Type.Tags.AString or type == xpt.Type.Tags.CString or type == xpt.Type.Tags.UTF8String

Here is the caller graph for this function:

def typelib.write_typelib (   idl,
  fd,
  filename 
)
Generate the typelib. 

Definition at line 262 of file typelib.py.

00262 
00263 def write_typelib(idl, fd, filename):
00264     """ Generate the typelib. """
00265 
00266     # We only care about interfaces
00267     ifaces = []
00268     for p in idl.productions:
00269         if p.kind == 'interface':
00270             ifaces.append(build_interface(p, ifaces))
00271 
00272     typelib = xpt.Typelib(interfaces=ifaces)
00273     typelib.writefd(fd)

Here is the call graph for this function:


Variable Documentation

Definition at line 309 of file typelib.py.

tuple typelib.depfd = open(options.depfile, 'w')

Definition at line 322 of file typelib.py.

list typelib.deps = [dep.replace('\\', '/') for dep in idl.deps]

Definition at line 323 of file typelib.py.

list typelib.file = args[0]

Definition at line 288 of file typelib.py.

string typelib.help = "Directory to search for imported files"

Definition at line 278 of file typelib.py.

tuple typelib.idl = p.parse(open(file).read(), filename=file)

Definition at line 314 of file typelib.py.

tuple typelib.o = OptionParser()

Definition at line 276 of file typelib.py.

tuple typelib.outfd = open(options.outfile, 'wb')

Definition at line 308 of file typelib.py.

tuple typelib.p = xpidl.IDLParser(outputdir=options.cachedir, regen=True)

Definition at line 300 of file typelib.py.

dictionary typelib.TypeMap
Initial value:
00001 {
00002     # nsresult is not strictly an xpidl.py type, but it's useful here
00003     'nsresult':           xpt.Type.Tags.uint32,
00004     # builtins
00005     'boolean':            xpt.Type.Tags.boolean,
00006     'void':               xpt.Type.Tags.void,
00007     'octet':              xpt.Type.Tags.uint8,
00008     'short':              xpt.Type.Tags.int16,
00009     'long':               xpt.Type.Tags.int32,
00010     'long long':          xpt.Type.Tags.int64,
00011     'unsigned short':     xpt.Type.Tags.uint16,
00012     'unsigned long':      xpt.Type.Tags.uint32,
00013     'unsigned long long': xpt.Type.Tags.uint64,
00014     'float':              xpt.Type.Tags.float,
00015     'double':             xpt.Type.Tags.double,
00016     'char':               xpt.Type.Tags.char,
00017     'string':             xpt.Type.Tags.char_ptr,
00018     'wchar':              xpt.Type.Tags.wchar_t,
00019     'wstring':            xpt.Type.Tags.wchar_t_ptr,
00020     # special types
00021     'nsid':               xpt.Type.Tags.nsIID,
00022     'domstring':          xpt.Type.Tags.DOMString,
00023     'astring':            xpt.Type.Tags.AString,
00024     'utf8string':         xpt.Type.Tags.UTF8String,
00025     'cstring':            xpt.Type.Tags.CString,
00026     'jsval':              xpt.Type.Tags.jsval
00027 }

Definition at line 47 of file typelib.py.