Back to index

enigmail  1.4.3
Functions | Variables
header Namespace Reference

Functions

def printComments
def firstCap
def attributeParamName
def attributeParamNames
def attributeNativeName
def attributeReturnType
def attributeParamlist
def attributeAsNative
def methodNativeName
def methodReturnType
def methodAsNative
def paramlistAsNative
def paramAsNative
def paramlistNames
def idl_basename
def print_header
def write_interface

Variables

 printdoccomments = False
string header
string include
string jspubtd_include
string header_end
string footer
string forward_decl
string iface_header = r""
tuple uuid_decoder = re.compile(r"""(?P<m0>[a-f0-9]{8})- (?P<m1>[a-f0-9]{4})- (?P<m2>[a-f0-9]{4})- (?P<m3>[a-f0-9]{4})- (?P<m4>[a-f0-9]{12})$""", re.X)
string iface_prolog
string iface_epilog
string iface_forward
string iface_forward_safe
string iface_template_prolog
string example_tmpl
string iface_template_epilog
tuple o = OptionParser()
string help = "Directory to search for imported files"
list file = args[0]
tuple deadfiles = os.path.join(options.cachedir, "*.py*")
tuple p = xpidl.IDLParser(outputdir=options.cachedir)
tuple outfd = open(options.outfile, 'w')
 closeoutfd = True
tuple idl = p.parse(open(file).read(), filename=file)
tuple dirname = os.path.dirname(options.depfile)
tuple depfd = open(options.depfile, 'w')
list deps = [dep.replace('\\', '/') for dep in idl.deps]

Function Documentation

def header.attributeAsNative (   a,
  getter 
)

Definition at line 86 of file header.py.

00086 
00087 def attributeAsNative(a, getter):
00088         scriptable = a.isScriptable() and "NS_SCRIPTABLE " or ""
00089         deprecated = a.deprecated and "NS_DEPRECATED " or ""
00090         params = {'scriptable': scriptable,
00091                   'deprecated': deprecated,
00092                   'returntype': attributeReturnType(a, 'NS_IMETHOD'),
00093                   'binaryname': attributeNativeName(a, getter),
00094                   'paramlist': attributeParamlist(a, getter)}
00095         return "%(deprecated)s%(scriptable)s%(returntype)s %(binaryname)s(%(paramlist)s)" % params

Here is the call graph for this function:

Here is the caller graph for this function:

def header.attributeNativeName (   a,
  getter 
)

Definition at line 67 of file header.py.

00067 
00068 def attributeNativeName(a, getter):
00069     binaryname = a.binaryname is not None and a.binaryname or firstCap(a.name)
00070     return "%s%s" % (getter and 'Get' or 'Set', binaryname)

Here is the call graph for this function:

Here is the caller graph for this function:

def header.attributeParamlist (   a,
  getter 
)

Definition at line 78 of file header.py.

00078 
00079 def attributeParamlist(a, getter):
00080     l = ["%s%s" % (a.realtype.nativeType(getter and 'out' or 'in'),
00081                    attributeParamName(a))]
00082     if a.implicit_jscontext:
00083         l.insert(0, "JSContext* cx")
00084 
00085     return ", ".join(l)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 58 of file header.py.

00058 
00059 def attributeParamName(a):
00060     return "a" + firstCap(a.name)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 61 of file header.py.

00061 
00062 def attributeParamNames(a):
00063     l = [attributeParamName(a)]
00064     if a.implicit_jscontext:
00065         l.insert(0, "cx")
00066     return ", ".join(l)

Here is the call graph for this function:

Here is the caller graph for this function:

def header.attributeReturnType (   a,
  macro 
)
macro should be NS_IMETHOD or NS_IMETHODIMP

Definition at line 71 of file header.py.

00071 
00072 def attributeReturnType(a, macro):
00073     """macro should be NS_IMETHOD or NS_IMETHODIMP"""
00074     if (a.nostdcall):
00075         return macro == "NS_IMETHOD" and "virtual nsresult" or "nsresult"
00076     else:
00077         return macro

Here is the caller graph for this function:

def header.firstCap (   str)

Definition at line 55 of file header.py.

00055 
00056 def firstCap(str):
00057     return str[0].upper() + str[1:]

Here is the caller graph for this function:

def header.idl_basename (   f)
returns the base name of a file with the last extension stripped

Definition at line 199 of file header.py.

00199 
00200 def idl_basename(f):
00201     """returns the base name of a file with the last extension stripped"""
00202     return os.path.basename(f).rpartition('.')[0]

Here is the caller graph for this function:

def header.methodAsNative (   m)

Definition at line 111 of file header.py.

00111 
00112 def methodAsNative(m):
00113     scriptable = m.isScriptable() and "NS_SCRIPTABLE " or ""
00114 
00115     return "%s%s %s(%s)" % (scriptable,
00116                             methodReturnType(m, 'NS_IMETHOD'),
00117                             methodNativeName(m),
00118                             paramlistAsNative(m))

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 96 of file header.py.

00096 
00097 def methodNativeName(m):
00098     return m.binaryname is not None and m.binaryname or firstCap(m.name)

Here is the call graph for this function:

Here is the caller graph for this function:

def header.methodReturnType (   m,
  macro 
)
macro should be NS_IMETHOD or NS_IMETHODIMP

Definition at line 99 of file header.py.

00099 
00100 def methodReturnType(m, macro):
00101     """macro should be NS_IMETHOD or NS_IMETHODIMP"""
00102     if m.nostdcall and m.notxpcom:
00103         return "%s%s" % (macro == "NS_IMETHOD" and "virtual " or "",
00104                          m.realtype.nativeType('in').strip())
00105     elif m.nostdcall:
00106         return "%snsresult" % (macro == "NS_IMETHOD" and "virtual " or "")
00107     elif m.notxpcom:
00108         return "%s_(%s)" % (macro, m.realtype.nativeType('in').strip())
00109     else:
00110         return macro

Here is the caller graph for this function:

def header.paramAsNative (   p)

Definition at line 141 of file header.py.

00141 
00142 def paramAsNative(p):
00143     if p.paramtype == 'in':
00144         typeannotate = ''
00145     else:
00146         typeannotate = ' NS_%sPARAM' % p.paramtype.upper()
00147 
00148     return "%s%s%s" % (p.nativeType(),
00149                        p.name,
00150                        typeannotate)

Here is the caller graph for this function:

def header.paramlistAsNative (   m,
  empty = 'void' 
)

Definition at line 119 of file header.py.

00119 
00120 def paramlistAsNative(m, empty='void'):
00121     l = [paramAsNative(p) for p in m.params]
00122 
00123     if m.implicit_jscontext:
00124         l.append("JSContext* cx")
00125 
00126     if m.optional_argc:
00127         l.append('PRUint8 _argc')
00128 
00129     if not m.notxpcom and m.realtype.name != 'void':
00130         l.append(paramAsNative(xpidl.Param(paramtype='out',
00131                                            type=None,
00132                                            name='_retval',
00133                                            attlist=[],
00134                                            location=None,
00135                                            realtype=m.realtype)))
00136 
00137     if len(l) == 0:
00138         return empty
00139 
00140     return ", ".join(l)

Here is the call graph for this function:

Here is the caller graph for this function:

def header.paramlistNames (   m)

Definition at line 151 of file header.py.

00151 
00152 def paramlistNames(m):
00153     names = [p.name for p in m.params]
00154 
00155     if m.implicit_jscontext:
00156         names.append('cx')
00157 
00158     if m.optional_argc:
00159         names.append('_argc')
00160 
00161     if not m.notxpcom and m.realtype.name != 'void':
00162         names.append('_retval')
00163 
00164     if len(names) == 0:
00165         return ''
00166     return ', '.join(names)

Here is the caller graph for this function:

def header.print_header (   idl,
  fd,
  filename 
)

Definition at line 203 of file header.py.

00203 
00204 def print_header(idl, fd, filename):
00205     fd.write(header % {'filename': filename,
00206                        'basename': idl_basename(filename)})
00207 
00208     foundinc = False
00209     for inc in idl.includes():
00210         if not foundinc:
00211             foundinc = True
00212             fd.write('\n')
00213         fd.write(include % {'basename': idl_basename(inc.filename)})
00214 
00215     if idl.needsJSTypes():
00216         fd.write(jspubtd_include)
00217 
00218     fd.write('\n')
00219     fd.write(header_end)
00220 
00221     for p in idl.productions:
00222         if p.kind == 'include': continue
00223         if p.kind == 'cdata':
00224             fd.write(p.data)
00225             continue
00226 
00227         if p.kind == 'forward':
00228             fd.write(forward_decl % {'name': p.name})
00229             continue
00230         if p.kind == 'interface':
00231             write_interface(p, fd)
00232             continue
00233         if p.kind == 'typedef':
00234             printComments(fd, p.doccomments, '')
00235             fd.write("typedef %s %s;\n\n" % (p.realtype.nativeType('in'),
00236                                              p.name))
00237 
00238     fd.write(footer % {'basename': idl_basename(filename)})

Here is the call graph for this function:

def header.printComments (   fd,
  clist,
  indent 
)

Definition at line 48 of file header.py.

00048 
00049     def printComments(fd, clist, indent):
00050         for c in clist:
00051             fd.write("%s%s\n" % (indent, c))
else:

Here is the caller graph for this function:

def header.write_interface (   iface,
  fd 
)

Definition at line 327 of file header.py.

00327 
00328 def write_interface(iface, fd):
00329     if iface.namemap is None:
00330         raise Exception("Interface was not resolved.")
00331 
00332     def write_const_decls(g):
00333         fd.write("  enum {\n")
00334         enums = []
00335         for c in g:
00336             printComments(fd, c.doccomments, '  ')
00337             basetype = c.basetype
00338             value = c.getValue()
00339             enums.append("    %(name)s = %(value)s%(signed)s" % {
00340                          'name': c.name,
00341                          'value': value,
00342                          'signed': (not basetype.signed) and 'U' or ''})
00343         fd.write(",\n".join(enums))
00344         fd.write("\n  };\n\n")
00345 
00346     def write_method_decl(m):
00347         printComments(fd, m.doccomments, '  ')
00348 
00349         fd.write("  /* %s */\n" % m.toIDL())
00350         fd.write("  %s = 0;\n\n" % methodAsNative(m))
00351                                                                            
00352     def write_attr_decl(a):
00353         printComments(fd, a.doccomments, '  ')
00354 
00355         fd.write("  /* %s */\n" % a.toIDL());
00356 
00357         fd.write("  %s = 0;\n" % attributeAsNative(a, True))
00358         if not a.readonly:
00359             fd.write("  %s = 0;\n" % attributeAsNative(a, False))
00360         fd.write("\n")
00361 
00362     defname = iface.name.upper()
00363     if iface.name[0:2] == 'ns':
00364         defname = 'NS_' + defname[2:]
00365 
00366     names = uuid_decoder.match(iface.attributes.uuid).groupdict()
00367     m3str = names['m3'] + names['m4']
00368     names['m3joined'] = ", ".join(["0x%s" % m3str[i:i+2] for i in xrange(0, 16, 2)])
00369 
00370     if iface.name[2] == 'I':
00371         implclass = iface.name[:2] + iface.name[3:]
00372     else:
00373         implclass = '_MYCLASS_'
00374 
00375     names.update({'defname': defname,
00376                   'macroname': iface.name.upper(),
00377                   'name': iface.name,
00378                   'iid': iface.attributes.uuid,
00379                   'implclass': implclass})
00380 
00381     fd.write(iface_header % names)
00382 
00383     printComments(fd, iface.doccomments, '')
00384 
00385     fd.write("class ")
00386     foundcdata = False
00387     for m in iface.members:
00388         if isinstance(m, xpidl.CDATA):
00389             foundcdata = True
00390 
00391     if not foundcdata:
00392         fd.write("NS_NO_VTABLE ")
00393 
00394     if iface.attributes.scriptable:
00395         fd.write("NS_SCRIPTABLE ")
00396     if iface.attributes.deprecated:
00397         fd.write("MOZ_DEPRECATED ")
00398     fd.write(iface.name)
00399     if iface.base:
00400         fd.write(" : public %s" % iface.base)
00401     fd.write(iface_prolog % names)
00402 
00403     for key, group in itertools.groupby(iface.members, key=type):
00404         if key == xpidl.ConstMember:
00405             write_const_decls(group) # iterator of all the consts
00406         else:
00407             for member in group:
00408                 if key == xpidl.Attribute:
00409                     write_attr_decl(member)
00410                 elif key == xpidl.Method:
00411                     write_method_decl(member)
00412                 elif key == xpidl.CDATA:
00413                     fd.write(" %s" % member.data)
00414                 else:
00415                     raise Exception("Unexpected interface member: %s" % member)
00416 
00417     fd.write(iface_epilog % names)
00418 
00419     for member in iface.members:
00420         if isinstance(member, xpidl.Attribute):
00421             fd.write("\\\n  %s; " % attributeAsNative(member, True))
00422             if not member.readonly:
00423                 fd.write("\\\n  %s; " % attributeAsNative(member, False))
00424         elif isinstance(member, xpidl.Method):
00425             fd.write("\\\n  %s; " % methodAsNative(member))
00426     if len(iface.members) == 0:
00427         fd.write('\\\n  /* no methods! */')
00428     elif not member.kind in ('attribute', 'method'):
00429        fd.write('\\')
00430 
00431     fd.write(iface_forward % names)
00432 
00433     def emitTemplate(tmpl):
00434         for member in iface.members:
00435             if isinstance(member, xpidl.Attribute):
00436                 fd.write(tmpl % {'asNative': attributeAsNative(member, True),
00437                                  'nativeName': attributeNativeName(member, True),
00438                                  'paramList': attributeParamNames(member)})
00439                 if not member.readonly:
00440                     fd.write(tmpl % {'asNative': attributeAsNative(member, False),
00441                                      'nativeName': attributeNativeName(member, False),
00442                                      'paramList': attributeParamNames(member)})
00443             elif isinstance(member, xpidl.Method):
00444                 fd.write(tmpl % {'asNative': methodAsNative(member),
00445                                  'nativeName': methodNativeName(member),
00446                                  'paramList': paramlistNames(member)})
00447         if len(iface.members) == 0:
00448             fd.write('\\\n  /* no methods! */')
00449         elif not member.kind in ('attribute', 'method'):
00450             fd.write('\\')
00451 
00452     emitTemplate("\\\n  %(asNative)s { return _to %(nativeName)s(%(paramList)s); } ")
00453 
00454     fd.write(iface_forward_safe % names)
00455 
00456     emitTemplate("\\\n  %(asNative)s { return !_to ? NS_ERROR_NULL_POINTER : _to->%(nativeName)s(%(paramList)s); } ")
00457 
00458     fd.write(iface_template_prolog % names)
00459 
00460     for member in iface.members:
00461         if isinstance(member, xpidl.ConstMember) or isinstance(member, xpidl.CDATA): continue
00462         fd.write("/* %s */\n" % member.toIDL())
00463         if isinstance(member, xpidl.Attribute):
00464             fd.write(example_tmpl % {'implclass': implclass,
00465                                      'returntype': attributeReturnType(member, 'NS_IMETHODIMP'),
00466                                      'nativeName': attributeNativeName(member, True),
00467                                      'paramList': attributeParamlist(member, True)})
00468             if not member.readonly:
00469                 fd.write(example_tmpl % {'implclass': implclass,
00470                                          'returntype': attributeReturnType(member, 'NS_IMETHODIMP'),
00471                                          'nativeName': attributeNativeName(member, False),
00472                                          'paramList': attributeParamlist(member, False)})
00473         elif isinstance(member, xpidl.Method):
00474             fd.write(example_tmpl % {'implclass': implclass,
00475                                      'returntype': methodReturnType(member, 'NS_IMETHODIMP'),
00476                                      'nativeName': methodNativeName(member),
00477                                      'paramList': paramlistAsNative(member, empty='')})
00478         fd.write('\n')
00479 
00480     fd.write(iface_template_epilog)

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 525 of file header.py.

tuple header.deadfiles = os.path.join(options.cachedir, "*.py*")

Definition at line 508 of file header.py.

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

Definition at line 544 of file header.py.

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

Definition at line 545 of file header.py.

tuple header.dirname = os.path.dirname(options.depfile)

Definition at line 538 of file header.py.

Initial value:
00001 """%(returntype)s %(implclass)s::%(nativeName)s(%(paramList)s)
00002 {
00003     return NS_ERROR_NOT_IMPLEMENTED;
00004 }
00005 """

Definition at line 316 of file header.py.

list header.file = args[0]

Definition at line 495 of file header.py.

string header.footer
Initial value:
00001 """
00002 #endif /* __gen_%(basename)s_h__ */
00003 """

Definition at line 191 of file header.py.

Initial value:
00001 """class %(name)s; /* forward declaration */
00002 
00003 """

Definition at line 195 of file header.py.

string header.header
Initial value:
00001 """/*
00002  * DO NOT EDIT.  THIS FILE IS GENERATED FROM %(filename)s
00003  */
00004 
00005 #ifndef __gen_%(basename)s_h__
00006 #define __gen_%(basename)s_h__
00007 """

Definition at line 167 of file header.py.

Initial value:
00001 """/* For IDL files that don't want to include root IDL files. */
00002 #ifndef NS_NO_VTABLE
00003 #define NS_NO_VTABLE
00004 #endif
00005 """

Definition at line 185 of file header.py.

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

Definition at line 485 of file header.py.

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

Definition at line 530 of file header.py.

Initial value:
00001 """};
00002 
00003   NS_DEFINE_STATIC_IID_ACCESSOR(%(name)s, %(defname)s_IID)
00004 
00005 /* Use this macro when declaring classes that implement this interface. */
00006 #define NS_DECL_%(macroname)s """

Definition at line 262 of file header.py.

Initial value:
00001 """
00002 
00003 /* Use this macro to declare functions that forward the behavior of this interface to another object. */
00004 #define NS_FORWARD_%(macroname)s(_to) """

Definition at line 270 of file header.py.

Initial value:
00001 """
00002 
00003 /* Use this macro to declare functions that forward the behavior of this interface to another object in a safe way. */
00004 #define NS_FORWARD_SAFE_%(macroname)s(_to) """

Definition at line 275 of file header.py.

string header.iface_header = r""

Definition at line 239 of file header.py.

Initial value:
00001 """ {
00002  public: 
00003 
00004   NS_DECLARE_STATIC_IID_ACCESSOR(%(defname)s_IID)
00005 
00006 """

Definition at line 255 of file header.py.

Initial value:
00001 """/* End of implementation class template. */
00002 #endif
00003 
00004 """

Definition at line 322 of file header.py.

Definition at line 280 of file header.py.

Initial value:
00001 """
00002 #ifndef __gen_%(basename)s_h__
00003 #include "%(basename)s.h"
00004 #endif
00005 """

Definition at line 175 of file header.py.

Initial value:
00001 """
00002 #include "jspubtd.h"
00003 """

Definition at line 181 of file header.py.

tuple header.o = OptionParser()

Definition at line 483 of file header.py.

header.outfd = open(options.outfile, 'w')

Definition at line 524 of file header.py.

tuple header.p = xpidl.IDLParser(outputdir=options.cachedir)

Definition at line 514 of file header.py.

Definition at line 45 of file header.py.

tuple header.uuid_decoder = re.compile(r"""(?P<m0>[a-f0-9]{8})- (?P<m1>[a-f0-9]{4})- (?P<m2>[a-f0-9]{4})- (?P<m3>[a-f0-9]{4})- (?P<m4>[a-f0-9]{12})$""", re.X)

Definition at line 249 of file header.py.