Beispiel #1
0
 def visitAttribute(self, node):
     ti = typeinfo.GetTypeInformation(node.attrType().unalias())
     for identifier in node.identifiers():
         if node.readonly():
             readonly = 'readonly '
         else:
             readonly = ''
         self._idl.out('@readonly@attribute @type@ @name@;',
                       readonly=readonly,
                       type=ti.type_xpidl,
                       name=identifier)
Beispiel #2
0
 def visitOperation(self, node):
     name = node.identifier()
     paramspec = []
     for p in node.parameters():
         ti = typeinfo.GetTypeInformation(p.paramType().unalias())
         paramspec.append(
             ti.XPIDLArgument(p.identifier(), p.is_in(), p.is_out()))
     rettype = node.returnType().unalias()
     if not (isinstance(rettype, idltype.Base) and
             (rettype.kind() == idltype.tk_void)):
         ti = typeinfo.GetTypeInformation(rettype)
         if not (isinstance(rettype, idltype.Sequence)):
             retval = ti.type_xpidl
         else:
             # Sequences can't be returned in XPCOM...
             retval = 'void'
             paramspec.append(ti.XPIDLArgument(retval.identifier(), 0, 1))
     else:
         retval = 'void'
     self._idl.out('@retval@ @name@(@paramspec@);',
                   retval=retval,
                   name=name,
                   paramspec=string.join(paramspec, ', '))
Beispiel #3
0
    def visitConst(self, node):
        scoped_name = node.scopedName()[:-1]

        if len(scoped_name) and isinstance(idlast.findDecl(scoped_name),
                                           idlast.Interface):
            name = node.identifier()

            ti = typeinfo.GetTypeInformation(node.constType().unalias())

            cleaned_value = str(node.value())
            if cleaned_value[-1] == 'L':
                cleaned_value = cleaned_value[0:-1]

            self._idl.out("const @type@ @name@ = @value@;",
                          type=ti.type_xpidl,
                          name=name,
                          value=cleaned_value)
Beispiel #4
0
    def visitTypedef(self, node):
        if not isinstance(node.aliasType().unalias(), idltype.Sequence):
            ti = typeinfo.GetTypeInformation(node.aliasType().unalias())

            for d in node.declarators():
                # Treated specially by XPIDL due to nsrootidl.idl
                if (d.identifier() == 'DOMString'):
                    continue
                # If the alias type has the same name as the aliases, we just
                # ignore the typedef. This allows typedefs designed to forward
                # definitions between modules to work in XPIDL (which doesn't
                # have the concept of modules).
                if isinstance(node.aliasType(), idltype.Declared):
                    if d.identifier() == node.aliasType().scopedName()[-1]:
                        continue
                self._idl.out('typedef @alias_type@ @name@;',
                              alias_type=ti.type_xpidl,
                              name=d.identifier())
Beispiel #5
0
    def visitOperation(self, node):
        rtype = node.returnType().unalias()
        if isinstance(rtype, idltype.Sequence):
            ti = typeinfo.GetTypeInformation(rtype.seqType().unalias())
            rettype = ti.type_pcm + '*'
            extra_args = 'unsigned long* _ret_len'
            xret = ti.GetXPCOMStorage(self)
            pret = ti.GetPCMStorage(self)
        else:
            extra_args = ''
            if not (isinstance(rtype, idltype.Base)
                    and rtype.kind() == idltype.tk_void):
                ti = typeinfo.GetTypeInformation(rtype)
                rettype = ti.type_pcm
                xret = ti.GetXPCOMStorage()
                pret = ti.GetPCMStorage()
            else:
                rettype = 'void'
                xret = None
                pret = None
                ti = None
        retti = ti
        needcomma = 0
        parstr = ''
        for p in node.parameters():
            if needcomma:
                parstr = parstr + ', '
            else:
                needcomma = 1
            ptype = p.paramType().unalias()
            ti = typeinfo.GetTypeInformation(ptype)
            p.ti = ti
            parstr = parstr + p.ti.PCMArgument(p.simplename, p.is_in(),
                                               p.is_out())
        if extra_args != '':
            if needcomma:
                parstr = parstr + ', '
            parstr = parstr + extra_args
        if not self.visitingOther:
            self.hxx.out('@rettype@ @name@(@args@) throw(std::exception&);',
                         rettype=rettype,
                         name=node.simplename,
                         args=parstr)
        self.cpp.out('@rettype@ @name@(@args@)',
                     rettype=rettype,
                     name=node.p2xscoped,
                     args=parstr)
        self.cpp.out('  throw(std::exception&)')
        self.cpp.out('{')
        self.cpp.inc_indent()

        # Create storage for each parameter. In and In/Out parameters also get
        # converted...
        callargs = ''
        for p in node.parameters():
            p.xs = p.ti.GetXPCOMStorage()
            self.cpp.out(p.xs.GetStorageDefinition())
            if callargs != '':
                callargs = callargs + ', '
            if p.is_in():
                if p.is_out():
                    deref = '*'
                    callargs = callargs + p.xs.GetInOutArgument()
                else:
                    deref = ''
                    callargs = callargs + p.xs.GetInArgument()
                self.cpp.out(
                    p.ti.ConvertPCMToXPCOM(deref + p.simplename, p.xs.name))
            else:
                callargs = callargs + p.xs.GetAssignmentRValue()

        if xret != None:
            self.cpp.out(xret.GetStorageDefinition())
            if callargs != '':
                callargs = callargs + ', '
            callargs = callargs + xret.GetAssignmentRValue()

        # Call the XPCOM method...
        self.cpp.out('nsresult ret =')
        self.cpp.out('  ' + self.dptr + '->' +
                     string.upper(node.simplename[0]) + node.simplename[1:] +
                     '(' + callargs + ');')
        rl = node.raises()
        if len(rl) == 0:
            exception = 'std::exception'
        else:
            exception = rl[0].simplecxxscoped
        self.cpp.out('if (!NS_SUCCEEDED(ret))')
        self.cpp.out('  throw ' + exception + '();')

        for p in node.parameters():
            if p.is_out():
                self.cpp.out(p.ti.ConvertXPCOMToPCM(p.xs.name, '*' +\
                                                    p.simplename))
            self.cpp.out(p.xs.GetDestroyer())

        if pret != None:
            self.cpp.out(pret.GetStorageDefinition())
            self.cpp.out(retti.ConvertXPCOMToPCM(xret.name, pret.name))
            self.cpp.out(xret.GetDestroyer())
            self.cpp.out(pret.GetReturn())

        self.cpp.dec_indent()
        self.cpp.out('}')
Beispiel #6
0
 def visitAttribute(self, node):
     nt = node.attrType().unalias()
     if isinstance(nt, idltype.Sequence):
         ti = typeinfo.GetTypeInformation(nt.seqType().unalias())
         rettype = ti.type_pcm + '*'
         intype = 'const ' + ti.type_pcm_const + '*'
         extra_getter_args = 'unsigned long* _ret_len'
         extra_setter_args = ', unsigned long _arg_len'
     else:
         ti = typeinfo.GetTypeInformation(nt)
         rettype = ti.type_pcm
         intype = ti.type_pcm_const
         extra_getter_args = ''
         extra_setter_args = ''
     for n in node.declarators():
         if not self.visitingOther:
             self.hxx.out('@rettype@ @name@(@args@) ' +
                          'throw(std::exception&);',
                          rettype=rettype,
                          name=n.simplename,
                          args=extra_getter_args)
         self.cpp.out('@rettype@ @name@(@args@)',
                      rettype=rettype,
                      name=n.p2xscoped,
                      args=extra_getter_args)
         self.cpp.out('  throw(std::exception&)')
         self.cpp.out('{')
         self.cpp.inc_indent()
         # Make a storage variable...
         xs = ti.GetXPCOMStorage()
         self.cpp.out(xs.GetStorageDefinition())
         # self.cpp.out('  ' + rettype.type_xpcom)
         self.cpp.out('nsresult ret =')
         self.cpp.out('  ' + self.dptr + '->Get' +
                      string.upper(n.identifier()[0]) + n.identifier()[1:] +
                      '(' + xs.GetAssignmentRValue() + ');')
         self.cpp.out('if (!NS_SUCCEEDED(ret))')
         self.cpp.out('  throw std::exception();')
         ps = ti.GetPCMStorage()
         self.cpp.out(ps.GetStorageDefinition())
         self.cpp.out(ti.ConvertXPCOMToPCM(xs.name, ps.name))
         self.cpp.out(xs.GetDestroyer())
         self.cpp.out(ps.GetReturn())
         self.cpp.dec_indent()
         self.cpp.out('}')
         if not node.readonly():
             if not self.visitingOther:
                 self.hxx.out('void @name@(@type@@args@) ' +
                              'throw(std::exception&);',
                              name=n.simplename,
                              type=intype,
                              args=extra_setter_args)
             self.cpp.out('void @name@(@type@ _arg@args@)',
                          name=n.p2xscoped,
                          type=intype,
                          args=extra_setter_args)
             self.cpp.out('  throw(std::exception&)')
             self.cpp.out('{')
             self.cpp.inc_indent()
             xs = ti.GetXPCOMStorage()
             self.cpp.out(xs.GetStorageDefinition())
             self.cpp.out(ti.ConvertPCMToXPCOM('_arg', xs.name))
             self.cpp.out('nsresult ret =')
             self.cpp.out('  ' + self.dptr + '->Set' +
                          string.upper(n.identifier()[0]) +
                          n.identifier()[1:] + '(' + xs.GetInArgument() +
                          ');')
             self.cpp.out(xs.GetDestroyer())
             self.cpp.out('if (!NS_SUCCEEDED(ret))')
             self.cpp.out('  throw std::exception();')
             self.cpp.dec_indent()
             self.cpp.out('}')
Beispiel #7
0
    def visitOperation(self, node):
        rtype = node.returnType().unalias()
        if isinstance(rtype, idltype.Base) and \
           rtype.kind() == idltype.tk_void:
            rtype = None
            pret = None
        else:
            rti = typeinfo.GetTypeInformation(rtype)
            pret = rti.GetPCMStorage()
        needcomma = 0
        parstr = ''
        for p in node.parameters():
            if needcomma:
                parstr = parstr + ', '
            else:
                needcomma = 1
            ptype = p.paramType().unalias()
            p.ti = typeinfo.GetTypeInformation(ptype)
            parstr = parstr + p.ti.XPCOMArgument(p.simplename, p.is_in(),
                                                 p.is_out())
        if rtype != None:
            if needcomma:
                parstr = parstr + ', '
            parstr = parstr + rti.XPCOMArgument('_ret', 0, 1)

        name = string.upper(node.simplename[0]) + node.simplename[1:]
        self.hxx.out('NS_IMETHOD @name@(@args@);', name=name, args=parstr)
        self.cpp.out('NS_IMETHODIMP @classn@::@name@(@args@)',
                     classn=self.classn,
                     name=name,
                     args=parstr)
        self.cpp.out('{')
        self.cpp.inc_indent()
        callargs = ''
        for p in node.parameters():
            p.ps = p.ti.GetPCMStorage()
            self.cpp.out(p.ps.GetStorageDefinition())
            if callargs != '':
                callargs = callargs + ', '
            if p.is_in():
                if p.is_out():
                    deref = '*'
                    callargs = callargs + p.ps.GetInOutArgument()
                else:
                    deref = ''
                    callargs = callargs + p.ps.GetInArgument()
                self.cpp.out(
                    p.ti.ConvertXPCOMToPCM(deref + p.simplename, p.ps.name))
            else:
                callargs = callargs + p.ps.GetAssignmentRValue()

        pref = ''
        if pret != None:
            self.cpp.out(pret.GetStorageDefinition())
            pref = pret.GetAssignmentLValue() + ' = '

        # Call the XPCOM method...
        self.cpp.out('try')
        self.cpp.out('{')
        self.cpp.inc_indent()
        self.cpp.out(pref + self.dptr + '->' + node.simplename + '(' +\
                     callargs + ');')
        self.cpp.dec_indent()
        self.cpp.out('}')
        self.cpp.out('catch (...)')
        self.cpp.out('{')
        self.cpp.inc_indent()
        for p in node.parameters():
            if p.is_in():
                self.cpp.out(p.ps.GetDestroyer())
        self.cpp.out('return NS_ERROR_FAILURE;')
        self.cpp.dec_indent()
        self.cpp.out('}')
        for p in node.parameters():
            if not p.is_out():
                self.cpp.out(p.ps.GetDestroyer())
                continue
            xs = p.ti.GetXPCOMStorage()
            self.cpp.out(xs.GetStorageDefinition())
            self.cpp.out(p.ti.ConvertPCMToXPCOM(p.ps.name, xs.name))
            self.cpp.out(xs.GetAssignOut(p.simplename))
            self.cpp.out(p.ps.GetDestroyer())
            self.cpp.out(xs.GetDestroyer())

        if pret != None:
            xs = rti.GetXPCOMStorage()
            self.cpp.out(xs.GetStorageDefinition())
            self.cpp.out(rti.ConvertPCMToXPCOM(pret.name, xs.name))
            self.cpp.out(xs.GetAssignOut('_ret'))
            self.cpp.out(pret.GetDestroyer())
            self.cpp.out(xs.GetDestroyer())

        self.cpp.out('return NS_OK;')

        self.cpp.dec_indent()
        self.cpp.out('}')
Beispiel #8
0
 def visitAttribute(self, node):
     nt = node.attrType().unalias()
     ti = typeinfo.GetTypeInformation(nt)
     getter_args = ti.XPCOMArgument('_ret', 0, 1)
     setter_args = ti.XPCOMArgument('_arg', 1, 0)
     for n in node.declarators():
         name = string.upper(n.identifier()[0]) + n.identifier()[1:]
         self.hxx.out('NS_IMETHOD Get@name@(@args@);',
                      name=name,
                      args=getter_args)
         self.cpp.out('NS_IMETHODIMP @classn@::Get@name@(@args@)',
                      classn=self.classn,
                      name=name,
                      args=getter_args)
         self.cpp.out('{')
         self.cpp.inc_indent()
         ps = ti.GetPCMStorage()
         self.cpp.out(ps.GetStorageDefinition())
         self.cpp.out('try')
         self.cpp.out('{')
         self.cpp.inc_indent()
         callstr = ps.GetAssignmentLValue() + ' = ' +\
                   self.dptr + '->' + n.simplename + '('
         if ps.__dict__.has_key('lenname'):
             callstr = callstr + ps.lenname
         callstr = callstr + ');'
         self.cpp.out(callstr)
         self.cpp.dec_indent()
         self.cpp.out('}')
         self.cpp.out('catch (...)')
         self.cpp.out('{')
         self.cpp.inc_indent()
         self.cpp.out('return NS_ERROR_FAILURE;')
         self.cpp.dec_indent()
         self.cpp.out('}')
         xs = ti.GetXPCOMStorage()
         self.cpp.out(xs.GetStorageDefinition())
         self.cpp.out(ti.ConvertPCMToXPCOM(ps.name, xs.name))
         self.cpp.out(xs.GetAssignOut('_ret'))
         self.cpp.out(xs.GetDestroyer())
         self.cpp.out(ps.GetDestroyer())
         self.cpp.out('return NS_OK;')
         self.cpp.dec_indent()
         self.cpp.out('}')
         if not node.readonly():
             self.hxx.out('NS_IMETHOD Set@name@(@args@);',
                          name=name,
                          args=setter_args)
             self.cpp.out('NS_IMETHODIMP @classn@::Set@name@(@args@)',
                          classn=self.classn,
                          name=name,
                          args=setter_args)
             self.cpp.out('{')
             self.cpp.inc_indent()
             ps = ti.GetPCMStorage()
             self.cpp.out(ps.GetStorageDefinition())
             self.cpp.out(ti.ConvertXPCOMToPCM('_arg', ps.name))
             self.cpp.out('try')
             self.cpp.out('{')
             self.cpp.inc_indent()
             self.cpp.out(self.dptr + '->' + n.simplename + '(' +\
                          ps.GetInArgument() + ');')
             self.cpp.dec_indent()
             self.cpp.out('}')
             self.cpp.out('catch (...)')
             self.cpp.out('{')
             self.cpp.inc_indent()
             self.cpp.out(ps.GetDestroyer())
             self.cpp.out('return NS_ERROR_FAILURE;')
             self.cpp.dec_indent()
             self.cpp.out('}')
             self.cpp.out(ps.GetDestroyer())
             self.cpp.out('return NS_OK;')
             self.cpp.dec_indent()
             self.cpp.out('}')