Bug 1306708 - Add prio() for message priority to IPDL (r=dvander)

This commit is contained in:
Bill McCloskey 2016-09-30 16:51:53 -07:00
parent f478d1188c
commit 1f13f73c7f
6 changed files with 67 additions and 16 deletions

View File

@ -8,6 +8,9 @@ NOT_NESTED = 1
INSIDE_SYNC_NESTED = 2 INSIDE_SYNC_NESTED = 2
INSIDE_CPOW_NESTED = 3 INSIDE_CPOW_NESTED = 3
NORMAL_PRIORITY = 1
HIGH_PRIORITY = 2
class Visitor: class Visitor:
def defaultVisit(self, node): def defaultVisit(self, node):
raise Exception, "INTERNAL ERROR: no visitor for node type `%s'"% ( raise Exception, "INTERNAL ERROR: no visitor for node type `%s'"% (
@ -297,6 +300,7 @@ class MessageDecl(Node):
self.name = None self.name = None
self.sendSemantics = ASYNC self.sendSemantics = ASYNC
self.nested = NOT_NESTED self.nested = NOT_NESTED
self.prio = NORMAL_PRIORITY
self.direction = None self.direction = None
self.inParams = [ ] self.inParams = [ ]
self.outParams = [ ] self.outParams = [ ]

View File

@ -1686,6 +1686,7 @@ class _GenerateProtocolCode(ipdl.ast.Visitor):
mfDecl, mfDefn = _splitFuncDeclDefn( mfDecl, mfDefn = _splitFuncDeclDefn(
_generateMessageConstructor(md.msgCtorFunc(), md.msgId(), _generateMessageConstructor(md.msgCtorFunc(), md.msgId(),
md.decl.type.nested, md.decl.type.nested,
md.decl.type.prio,
md.prettyMsgName(p.name+'::'), md.prettyMsgName(p.name+'::'),
md.decl.type.compress)) md.decl.type.compress))
decls.append(mfDecl) decls.append(mfDecl)
@ -1696,6 +1697,7 @@ class _GenerateProtocolCode(ipdl.ast.Visitor):
_generateMessageConstructor( _generateMessageConstructor(
md.replyCtorFunc(), md.replyId(), md.replyCtorFunc(), md.replyId(),
md.decl.type.nested, md.decl.type.nested,
md.decl.type.prio,
md.prettyReplyName(p.name+'::'), md.prettyReplyName(p.name+'::'),
md.decl.type.compress)) md.decl.type.compress))
decls.append(rfDecl) decls.append(rfDecl)
@ -1926,7 +1928,7 @@ class _GenerateProtocolCode(ipdl.ast.Visitor):
##-------------------------------------------------- ##--------------------------------------------------
def _generateMessageConstructor(clsname, msgid, nested, prettyName, compress): def _generateMessageConstructor(clsname, msgid, nested, prio, prettyName, compress):
routingId = ExprVar('routingId') routingId = ExprVar('routingId')
func = FunctionDefn(FunctionDecl( func = FunctionDefn(FunctionDecl(
@ -1950,12 +1952,18 @@ def _generateMessageConstructor(clsname, msgid, nested, prettyName, compress):
assert nested == ipdl.ast.INSIDE_CPOW_NESTED assert nested == ipdl.ast.INSIDE_CPOW_NESTED
nestedEnum = 'IPC::Message::NESTED_INSIDE_CPOW' nestedEnum = 'IPC::Message::NESTED_INSIDE_CPOW'
if prio == ipdl.ast.NORMAL_PRIORITY:
prioEnum = 'IPC::Message::NORMAL_PRIORITY'
else:
assert prio == ipdl.ast.HIGH_PRIORITY
prioEnum = 'IPC::Message::HIGH_PRIORITY'
func.addstmt( func.addstmt(
StmtReturn(ExprNew(Type('IPC::Message'), StmtReturn(ExprNew(Type('IPC::Message'),
args=[ routingId, args=[ routingId,
ExprVar(msgid), ExprVar(msgid),
ExprVar(nestedEnum), ExprVar(nestedEnum),
ExprVar('IPC::Message::NORMAL_PRIORITY'), ExprVar(prioEnum),
compression, compression,
ExprLiteral.String(prettyName) ]))) ExprLiteral.String(prettyName) ])))

View File

@ -138,6 +138,7 @@ reserved = set((
'opens', 'opens',
'or', 'or',
'parent', 'parent',
'prio',
'protocol', 'protocol',
'recv', 'recv',
'returns', 'returns',
@ -500,7 +501,8 @@ def p_MessageDecl(p):
"""MessageDecl : SendSemanticsQual MessageBody""" """MessageDecl : SendSemanticsQual MessageBody"""
msg = p[2] msg = p[2]
msg.nested = p[1][0] msg.nested = p[1][0]
msg.sendSemantics = p[1][1] msg.prio = p[1][1]
msg.sendSemantics = p[1][2]
if Parser.current.direction is None: if Parser.current.direction is None:
_error(msg.loc, 'missing message direction') _error(msg.loc, 'missing message direction')
@ -646,27 +648,48 @@ def p_Nested(p):
if p[1] not in kinds: if p[1] not in kinds:
_error(locFromTok(p, 1), "Expected not, inside_sync, or inside_cpow for nested()") _error(locFromTok(p, 1), "Expected not, inside_sync, or inside_cpow for nested()")
p[0] = kinds[p[1]] p[0] = { 'nested': kinds[p[1]] }
def p_Priority(p):
"""Priority : ID"""
kinds = {'normal': 1,
'high': 2}
if p[1] not in kinds:
_error(locFromTok(p, 1), "Expected normal or high for prio()")
p[0] = { 'prio': kinds[p[1]] }
def p_SendQualifier(p):
"""SendQualifier : NESTED '(' Nested ')'
| PRIO '(' Priority ')'"""
p[0] = p[3]
def p_SendQualifierList(p):
"""SendQualifierList : SendQualifier SendQualifierList
| """
if len(p) > 1:
p[0] = p[1]
p[0].update(p[2])
else:
p[0] = {}
def p_SendSemanticsQual(p): def p_SendSemanticsQual(p):
"""SendSemanticsQual : ASYNC """SendSemanticsQual : SendQualifierList ASYNC
| SYNC | SendQualifierList SYNC
| NESTED '(' Nested ')' ASYNC
| NESTED '(' Nested ')' SYNC
| INTR""" | INTR"""
if p[1] == 'nested': quals = {}
mtype = p[5] if len(p) == 3:
nested = p[3] quals = p[1]
mtype = p[2]
else: else:
mtype = p[1] mtype = 'intr'
nested = NOT_NESTED
if mtype == 'async': mtype = ASYNC if mtype == 'async': mtype = ASYNC
elif mtype == 'sync': mtype = SYNC elif mtype == 'sync': mtype = SYNC
elif mtype == 'intr': mtype = INTR elif mtype == 'intr': mtype = INTR
else: assert 0 else: assert 0
p[0] = [ nested, mtype ] p[0] = [ quals.get('nested', NOT_NESTED), quals.get('prio', NORMAL_PRIORITY), mtype ]
def p_OptionalProtocolSendSemanticsQual(p): def p_OptionalProtocolSendSemanticsQual(p):
"""OptionalProtocolSendSemanticsQual : ProtocolSendSemanticsQual """OptionalProtocolSendSemanticsQual : ProtocolSendSemanticsQual

View File

@ -251,13 +251,14 @@ class StateType(IPDLType):
return self.name() return self.name()
class MessageType(IPDLType): class MessageType(IPDLType):
def __init__(self, nested, sendSemantics, direction, def __init__(self, nested, prio, sendSemantics, direction,
ctor=False, dtor=False, cdtype=None, compress=False, ctor=False, dtor=False, cdtype=None, compress=False,
verify=False): verify=False):
assert not (ctor and dtor) assert not (ctor and dtor)
assert not (ctor or dtor) or type is not None assert not (ctor or dtor) or type is not None
self.nested = nested self.nested = nested
self.prio = prio
self.nestedRange = (nested, nested) self.nestedRange = (nested, nested)
self.sendSemantics = sendSemantics self.sendSemantics = sendSemantics
self.direction = direction self.direction = direction
@ -1125,7 +1126,7 @@ class GatherDecls(TcheckVisitor):
# enter message scope # enter message scope
self.symtab.enterScope(md) self.symtab.enterScope(md)
msgtype = MessageType(md.nested, md.sendSemantics, md.direction, msgtype = MessageType(md.nested, md.prio, md.sendSemantics, md.direction,
ctor=isctor, dtor=isdtor, cdtype=cdtype, ctor=isctor, dtor=isdtor, cdtype=cdtype,
compress=md.compress, verify=md.verify) compress=md.compress, verify=md.verify)

View File

@ -0,0 +1,14 @@
namespace mozilla {
namespace _ipdltest {
sync protocol PTestPriority {
parent:
prio(high) async Msg1();
prio(high) sync Msg2();
child:
prio(high) async Msg3();
};
} // namespace _ipdltest
} // namespace mozilla

View File

@ -107,6 +107,7 @@ IPDL_SOURCES += [
'PTestNestedLoops.ipdl', 'PTestNestedLoops.ipdl',
'PTestOpens.ipdl', 'PTestOpens.ipdl',
'PTestOpensOpened.ipdl', 'PTestOpensOpened.ipdl',
'PTestPriority.ipdl',
'PTestRaceDeadlock.ipdl', 'PTestRaceDeadlock.ipdl',
'PTestRaceDeferral.ipdl', 'PTestRaceDeferral.ipdl',
'PTestRacyInterruptReplies.ipdl', 'PTestRacyInterruptReplies.ipdl',