示例#1
0
def makeBuiltinUsing(tname):
    quals = tname.split('::')
    base = quals.pop()
    quals = quals[0:]
    return UsingStmt(
        _builtinloc,
        TypeSpec(_builtinloc, QualifiedId(_builtinloc, base, quals)))
示例#2
0
    def visitTranslationUnit(self, tu):
        # all TranslationUnits declare symbols in global scope
        if hasattr(tu, 'visited'):
            return
        tu.visited = True
        savedSymtab = self.symtab
        self.symtab = SymbolTable(self.errors)

        # pretend like the translation unit "using"-ed these for the
        # sake of type checking and C++ code generation
        tu.builtinUsing = self.builtinUsing

        # for everyone's sanity, enforce that the filename and tu name
        # match
        basefilename = os.path.basename(tu.filename)
        expectedfilename = '%s.ipdl' % (tu.name)
        if not tu.protocol:
            # header
            expectedfilename += 'h'
        if basefilename != expectedfilename:
            self.error(
                tu.loc,
                "expected file for translation unit `%s' to be named `%s'; instead it's named `%s'",  # NOQA: E501
                tu.name,
                expectedfilename,
                basefilename)

        if tu.protocol:
            assert tu.name == tu.protocol.name

            p = tu.protocol

            # FIXME/cjones: it's a little weird and counterintuitive
            # to put both the namespace and non-namespaced name in the
            # global scope.  try to figure out something better; maybe
            # a type-neutral |using| that works for C++ and protocol
            # types?
            qname = p.qname()
            fullname = str(qname)
            p.decl = self.declare(
                loc=p.loc,
                type=ProtocolType(qname, p.nested, p.sendSemantics),
                shortname=p.name,
                fullname=None if 0 == len(qname.quals) else fullname)

            p.parentEndpointDecl = self.declare(
                loc=p.loc,
                type=EndpointType(
                    QualifiedId(p.loc, 'Endpoint<' + fullname + 'Parent>',
                                ['mozilla', 'ipc'])),
                shortname='Endpoint<' + p.name + 'Parent>')
            p.childEndpointDecl = self.declare(
                loc=p.loc,
                type=EndpointType(
                    QualifiedId(p.loc, 'Endpoint<' + fullname + 'Child>',
                                ['mozilla', 'ipc'])),
                shortname='Endpoint<' + p.name + 'Child>')

            p.parentManagedEndpointDecl = self.declare(
                loc=p.loc,
                type=ManagedEndpointType(
                    QualifiedId(p.loc,
                                'ManagedEndpoint<' + fullname + 'Parent>',
                                ['mozilla', 'ipc'])),
                shortname='ManagedEndpoint<' + p.name + 'Parent>')
            p.childManagedEndpointDecl = self.declare(
                loc=p.loc,
                type=ManagedEndpointType(
                    QualifiedId(p.loc,
                                'ManagedEndpoint<' + fullname + 'Child>',
                                ['mozilla', 'ipc'])),
                shortname='ManagedEndpoint<' + p.name + 'Child>')

            # XXX ugh, this sucks.  but we need this information to compute
            # what friend decls we need in generated C++
            p.decl.type._ast = p

        # make sure we have decls for all dependent protocols
        for pinc in tu.includes:
            pinc.accept(self)

        # declare imported (and builtin) C++ types
        for using in tu.builtinUsing:
            using.accept(self)
        for using in tu.using:
            using.accept(self)

        # first pass to "forward-declare" all structs and unions in
        # order to support recursive definitions
        for su in tu.structsAndUnions:
            self.declareStructOrUnion(su)

        # second pass to check each definition
        for su in tu.structsAndUnions:
            su.accept(self)

        if tu.protocol:
            # grab symbols in the protocol itself
            p.accept(self)

        self.symtab = savedSymtab