-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathpayload.py
More file actions
executable file
·70 lines (56 loc) · 2.35 KB
/
Copy pathpayload.py
File metadata and controls
executable file
·70 lines (56 loc) · 2.35 KB
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
import scrib_constants as constants
import scrib_util as util
from ast.payloadelement import (
get_annotation as payloadelement_get_annotation,
get_type as payloadelement_get_type,
EMPTY_ANNOTATION as payloadelement_EMPTY_ANNOTATION,
pretty_print as payloadelement_pretty_print
)
##
# For message sig payloads
def traverse(traverser, node_):
traversed = []
for child in get_payloadelement_children(node_):
traversed.append(traverser.traverse(child))
new = util.antlr_dupnode_and_replace_children(node_, traversed)
return new
# An auxiliary function, not directly called by the Visitor pattern
#
# Updates checker, void return (as for main WellformednessChecker visitor --
# node_ is not modified)
def check_wellformedness(checker, node_):
context = checker.get_context()
payloads = get_payloadelement_children(node_)
for payload in payloads:
annot = payloadelement_get_annotation(payload)
payloadtype = payloadelement_get_type(payload)
# TODO: annotation well-formedness will be further specified in langref
# when annotations framework is added
if annot != payloadelement_EMPTY_ANNOTATION:
# Section 4.6.2 -- distinct annotation names
if annot in context.get_annotationss():
util.report_error("Bad annotation: " + annot)
context = context.add_annotation(annot)
# Section 4.5 -- Visible payload types
if payloadtype not in context.get_visible_payloads().keys():
# "type" parameters
# Section 4.5 -- Bound (type) parameter
if payloadtype not in context.get_parameters().keys():
util.report_error("Bad payload type: " + payloadtype)
# Section 4.5 -- type parameter
if context.get_parameter(payloadtype) != \
constants.KIND_PAYLOAD_TYPE:
util.report_error("Bad payload type parameter: " + \
payloadtype)
checker.set_context(context)
def pretty_print(node_):
text = ""
pes = get_payloadelement_children(node_)
if pes:
text = payloadelement_pretty_print(pes[0])
for child in pes[1:]:
text = text + ', '
text = text + payloadelement_pretty_print(child)
return text
def get_payloadelement_children(node_):
return node_.getChildren()