DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (25c4c2685699)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
# vim: set ts=4 sw=4 tw=99 et:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

from __future__ import print_function

import sys
from ipdl.ast import Visitor, ASYNC


class SyncMessageChecker(Visitor):
    syncMsgList = []
    seenProtocols = []
    seenSyncMessages = []

    def __init__(self, syncMsgList):
        SyncMessageChecker.syncMsgList = syncMsgList
        self.errors = []

    def prettyMsgName(self, msg):
        return "%s::%s" % (self.currentProtocol, msg)

    def errorUnknownSyncMessage(self, loc, msg):
        self.errors.append('%s: error: Unknown sync IPC message %s' %
                           (str(loc), msg))

    def errorAsyncMessageCanRemove(self, loc, msg):
        self.errors.append('%s: error: IPC message %s is async, can be delisted' %
                           (str(loc), msg))

    def visitProtocol(self, p):
        self.errors = []
        self.currentProtocol = p.name
        SyncMessageChecker.seenProtocols.append(p.name)
        Visitor.visitProtocol(self, p)

    def visitMessageDecl(self, md):
        pn = self.prettyMsgName(md.name)
        if md.sendSemantics is not ASYNC:
            if pn not in SyncMessageChecker.syncMsgList:
                self.errorUnknownSyncMessage(md.loc, pn)
            SyncMessageChecker.seenSyncMessages.append(pn)
        elif pn in SyncMessageChecker.syncMsgList:
            self.errorAsyncMessageCanRemove(md.loc, pn)

    @staticmethod
    def getFixedSyncMessages():
        return set(SyncMessageChecker.syncMsgList) - set(SyncMessageChecker.seenSyncMessages)


def checkSyncMessage(tu, syncMsgList, errout=sys.stderr):
    checker = SyncMessageChecker(syncMsgList)
    tu.accept(checker)
    if len(checker.errors):
        for error in checker.errors:
            print(error, file=errout)
        return False
    return True


def checkFixedSyncMessages(config, errout=sys.stderr):
    fixed = SyncMessageChecker.getFixedSyncMessages()
    error_free = True
    for item in fixed:
        protocol = item.split('::')[0]
        # Ignore things like sync messages in test protocols we didn't compile.
        # Also, ignore platform-specific IPC messages.
        if protocol in SyncMessageChecker.seenProtocols and \
           'platform' not in config.options(item):
            print('Error: Sync IPC message %s not found, it appears to be fixed.\n'
                  'Please remove it from sync-messages.ini.' % item, file=errout)
            error_free = False
    return error_free