зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1805445 - Centralize defining a new priority in the IPDL compiler. r=nika
This patch makes it so that you only need to add a new element to a list to add a new priority to the IPDL compiler. Differential Revision: https://phabricator.services.mozilla.com/D164836
This commit is contained in:
Родитель
0b205ebf31
Коммит
865f6e802e
|
@ -9,25 +9,18 @@ NOT_NESTED = 1
|
|||
INSIDE_SYNC_NESTED = 2
|
||||
INSIDE_CPOW_NESTED = 3
|
||||
|
||||
NORMAL_PRIORITY = 1
|
||||
INPUT_PRIORITY = 2
|
||||
VSYNC_PRIORITY = 3
|
||||
MEDIUMHIGH_PRIORITY = 4
|
||||
CONTROL_PRIORITY = 5
|
||||
|
||||
NESTED_ATTR_MAP = {
|
||||
"not": NOT_NESTED,
|
||||
"inside_sync": INSIDE_SYNC_NESTED,
|
||||
"inside_cpow": INSIDE_CPOW_NESTED,
|
||||
}
|
||||
|
||||
PRIORITY_ATTR_MAP = {
|
||||
"normal": NORMAL_PRIORITY,
|
||||
"input": INPUT_PRIORITY,
|
||||
"vsync": VSYNC_PRIORITY,
|
||||
"mediumhigh": MEDIUMHIGH_PRIORITY,
|
||||
"control": CONTROL_PRIORITY,
|
||||
}
|
||||
# Each element of this list is the IPDL source representation of a priority.
|
||||
priorityList = ["normal", "input", "vsync", "mediumhigh", "control"]
|
||||
|
||||
priorityAttrMap = {src: idx for idx, src in enumerate(priorityList)}
|
||||
|
||||
NORMAL_PRIORITY = priorityAttrMap["normal"]
|
||||
|
||||
|
||||
class Visitor:
|
||||
|
@ -385,10 +378,11 @@ class MessageDecl(Node):
|
|||
return NESTED_ATTR_MAP.get(self.attributes["Nested"].value, NOT_NESTED)
|
||||
|
||||
def priority(self):
|
||||
if "Priority" not in self.attributes:
|
||||
return NORMAL_PRIORITY
|
||||
|
||||
return PRIORITY_ATTR_MAP.get(self.attributes["Priority"].value, NORMAL_PRIORITY)
|
||||
if "Priority" in self.attributes:
|
||||
sourcePriority = self.attributes["Priority"].value
|
||||
else:
|
||||
sourcePriority = "normal"
|
||||
return priorityAttrMap.get(sourcePriority, NORMAL_PRIORITY)
|
||||
|
||||
|
||||
class Param(Node):
|
||||
|
|
|
@ -1786,6 +1786,10 @@ class _GenerateProtocolCode(ipdl.ast.Visitor):
|
|||
|
||||
# --------------------------------------------------
|
||||
|
||||
cppPriorityList = list(
|
||||
map(lambda src: src.upper() + "_PRIORITY", ipdl.ast.priorityList)
|
||||
)
|
||||
|
||||
|
||||
def _generateMessageConstructor(md, segmentSize, protocol, forReply=False):
|
||||
if forReply:
|
||||
|
@ -1798,7 +1802,8 @@ def _generateMessageConstructor(md, segmentSize, protocol, forReply=False):
|
|||
replyEnum = "NOT_REPLY"
|
||||
|
||||
nested = md.decl.type.nested
|
||||
prio = md.decl.type.prio
|
||||
prioEnum = cppPriorityList[md.decl.type.prio]
|
||||
|
||||
compress = md.decl.type.compress
|
||||
|
||||
routingId = ExprVar("routingId")
|
||||
|
@ -1827,17 +1832,6 @@ def _generateMessageConstructor(md, segmentSize, protocol, forReply=False):
|
|||
assert nested == ipdl.ast.INSIDE_CPOW_NESTED
|
||||
nestedEnum = "NESTED_INSIDE_CPOW"
|
||||
|
||||
if prio == ipdl.ast.NORMAL_PRIORITY:
|
||||
prioEnum = "NORMAL_PRIORITY"
|
||||
elif prio == ipdl.ast.INPUT_PRIORITY:
|
||||
prioEnum = "INPUT_PRIORITY"
|
||||
elif prio == ipdl.ast.VSYNC_PRIORITY:
|
||||
prioEnum = "VSYNC_PRIORITY"
|
||||
elif prio == ipdl.ast.MEDIUMHIGH_PRIORITY:
|
||||
prioEnum = "MEDIUMHIGH_PRIORITY"
|
||||
else:
|
||||
prioEnum = "CONTROL_PRIORITY"
|
||||
|
||||
if md.decl.type.isSync():
|
||||
syncEnum = "SYNC"
|
||||
else:
|
||||
|
|
|
@ -13,6 +13,7 @@ from ipdl.ast import TypeSpec, UnionDecl, UsingStmt, Visitor, StringLiteral
|
|||
from ipdl.ast import ASYNC, SYNC, INTR
|
||||
from ipdl.ast import IN, OUT, INOUT
|
||||
from ipdl.ast import NOT_NESTED, INSIDE_SYNC_NESTED, INSIDE_CPOW_NESTED
|
||||
from ipdl.ast import priorityList
|
||||
import ipdl.builtin as builtin
|
||||
from ipdl.util import hash_str
|
||||
|
||||
|
@ -1290,7 +1291,7 @@ class GatherDecls(TcheckVisitor):
|
|||
{
|
||||
"Tainted": None,
|
||||
"Compress": (None, "all"),
|
||||
"Priority": ("normal", "input", "vsync", "mediumhigh", "control"),
|
||||
"Priority": priorityList,
|
||||
"Nested": ("not", "inside_sync", "inside_cpow"),
|
||||
"LegacyIntr": None,
|
||||
"VirtualSendImpl": None,
|
||||
|
|
Загрузка…
Ссылка в новой задаче