Bug 1513073 - make the IPDL compiler's code python3 syntax friendly; r=nika

Differential Revision: https://phabricator.services.mozilla.com/D14102

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Alex Gaynor 2018-12-11 18:12:22 +00:00
Родитель d3663591d0
Коммит 79c450dbdb
6 изменённых файлов: 43 добавлений и 30 удалений

Просмотреть файл

@ -1,6 +1,8 @@
# 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 optparse
import os
import sys
@ -99,16 +101,16 @@ for f in files:
ast = ipdl.parse(specstring, filename, includedirs=includedirs)
if ast is None:
print >>sys.stderr, 'Specification could not be parsed.'
print('Specification could not be parsed.', file=sys.stderr)
sys.exit(1)
log(2, 'checking types')
if not ipdl.typecheck(ast):
print >>sys.stderr, 'Specification is not well typed.'
print('Specification is not well typed.', file=sys.stderr)
sys.exit(1)
if not ipdl.checkSyncMessage(ast, syncMsgList):
print >>sys.stderr, 'Error: New sync IPC messages must be reviewed by an IPC peer and recorded in %s' % options.syncMsgList # NOQA: E501
print('Error: New sync IPC messages must be reviewed by an IPC peer and recorded in %s' % options.syncMsgList, file=sys.stderr) # NOQA: E501
sys.exit(1)
if not ipdl.checkFixedSyncMessages(parser):
@ -135,35 +137,35 @@ allprotocols.sort()
# This is a fool-proof of the 'message-metadata.ini' file.
undefinedMessages = set(segmentCapacityDict.keys()) - set(allmessageprognames)
if len(undefinedMessages) > 0:
print >>sys.stderr, 'Error: Undefined message names in message-metadata.ini:'
print >>sys.stderr, undefinedMessages
print('Error: Undefined message names in message-metadata.ini:', file=sys.stderr)
print(undefinedMessages, file=sys.stderr)
sys.exit(1)
ipcmsgstart = StringIO()
print >>ipcmsgstart, """
print("""
// CODE GENERATED by ipdl.py. Do not edit.
#ifndef IPCMessageStart_h
#define IPCMessageStart_h
enum IPCMessageStart {
"""
""", file=ipcmsgstart)
for name in allprotocols:
print >>ipcmsgstart, " %s," % name
print(" %s," % name, file=ipcmsgstart)
print >>ipcmsgstart, """
print("""
LastMsgIndex
};
static_assert(LastMsgIndex <= 65536, "need to update IPC_MESSAGE_MACRO");
#endif // ifndef IPCMessageStart_h
"""
""", file=ipcmsgstart)
ipc_msgtype_name = StringIO()
print >>ipc_msgtype_name, """
print("""
// CODE GENERATED by ipdl.py. Do not edit.
#include <cstdint>
@ -175,16 +177,16 @@ using std::uint32_t;
namespace {
enum IPCMessages {
"""
""", file=ipc_msgtype_name)
for protocol in sorted(allmessages.keys()):
for (msg, num) in allmessages[protocol].idnums:
if num:
print >>ipc_msgtype_name, " %s = %s," % (msg, num)
print(" %s = %s," % (msg, num), file=ipc_msgtype_name)
elif not msg.endswith('End'):
print >>ipc_msgtype_name, " %s__%s," % (protocol, msg)
print(" %s__%s," % (protocol, msg), file=ipc_msgtype_name)
print >>ipc_msgtype_name, """
print("""
};
} // anonymous namespace
@ -194,17 +196,17 @@ namespace IPC {
const char* StringFromIPCMessageType(uint32_t aMessageType)
{
switch (aMessageType) {
"""
""", file=ipc_msgtype_name)
for protocol in sorted(allmessages.keys()):
for (msg, num) in allmessages[protocol].idnums:
if num or msg.endswith('End'):
continue
print >>ipc_msgtype_name, """
print("""
case %s__%s:
return "%s::%s";""" % (protocol, msg, protocol, msg)
return "%s::%s";""" % (protocol, msg, protocol, msg), file=ipc_msgtype_name)
print >>ipc_msgtype_name, """
print("""
case CHANNEL_OPENED_MESSAGE_TYPE:
return "CHANNEL_OPENED_MESSAGE";
case SHMEM_DESTROYED_MESSAGE_TYPE:
@ -221,7 +223,7 @@ print >>ipc_msgtype_name, """
}
} // namespace IPC
"""
""", file=ipc_msgtype_name)
ipdl.writeifmodified(ipcmsgstart.getvalue(), ipcmessagestartpath)
ipdl.writeifmodified(ipc_msgtype_name.getvalue(), ipc_msgtype_name_path)

Просмотреть файл

@ -2,6 +2,8 @@
# 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
__all__ = ['gencxx', 'genipdl', 'parse', 'typecheck', 'writeifmodified',
'checkSyncMessage', 'checkFixedSyncMessages']
@ -33,7 +35,7 @@ def parse(specstring, filename='/stdin', includedirs=[], errout=sys.stderr):
try:
return Parser(type, name).parse(specstring, os.path.abspath(filename), includedirs)
except ParseError as p:
print >>errout, p
print(p, file=errout)
return None

Просмотреть файл

@ -3,6 +3,8 @@
# 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
@ -52,7 +54,7 @@ def checkSyncMessage(tu, syncMsgList, errout=sys.stderr):
tu.accept(checker)
if len(checker.errors):
for error in checker.errors:
print >>errout, error
print(error, file=errout)
return False
return True
@ -66,7 +68,7 @@ def checkFixedSyncMessages(config, errout=sys.stderr):
# Also, ignore platform-specific IPC messages.
if protocol in SyncMessageChecker.seenProtocols and \
'platform' not in config.options(item):
print >>errout, 'Error: Sync IPC message %s not found, it appears to be fixed.\n' \
'Please remove it from sync-messages.ini.' % 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

Просмотреть файл

@ -3,6 +3,8 @@
# 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 os
import sys
@ -113,9 +115,11 @@ class Type:
def typename(self):
return self.__class__.__name__
def name(self): raise Exception, 'NYI'
def name(self):
raise NotImplementedError
def fullname(self): raise Exception, 'NYI'
def fullname(self):
raise NotImplementedError
def accept(self, visitor, *args):
visit = getattr(visitor, 'visit' + self.__class__.__name__, None)
@ -661,7 +665,7 @@ With this information, it type checks the AST.'''
def reportErrors(self, errout):
for error in self.errors:
print >>errout, error
print(error, file=errout)
class TcheckVisitor(Visitor):

Просмотреть файл

@ -3,6 +3,7 @@
# 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
@ -10,4 +11,4 @@ msgid = int(sys.argv[1])
protocol = (msgid >> 16)
msg = (msgid - (protocol << 16))
print 'protocol', protocol, 'message', msg
print('protocol', protocol, 'message', msg)

Просмотреть файл

@ -2,12 +2,14 @@
# 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 string
import sys
def usage():
print >>sys.stderr, """
print("""
%s template_file -t unit_tests... -e extra_protocols...
TEMPLATE_FILE is used to generate to generate the unit-tester .cpp
@ -15,7 +17,7 @@ def usage():
EXTRA_PROTOCOLS are top-level protocols for subprocesses that can be
spawned in tests but are not unit tests in and of
themselves
""" % (sys.argv[0])
""" % (sys.argv[0]), file=sys.stderr)
sys.exit(1)