9def render(idl_node, indent_str=' '):
14 indent_stack.append(indent_str)
20 return sorted(nodes, key=
lambda node: node.id)
23 """Writes the given node and adds a new line."""
28 """Writes the given node and adds a space if there was output."""
31 if mark !=
len(output):
34 def w(node, list_separator=None):
35 """Writes the given node.
38 node -- a string, IDLNode instance or a list of such.
39 list_separator --
if provided,
and node
is a list,
40 list_separator will be written between the list items.
44 elif isinstance(node, str):
45 if output
and output[-1].endswith(
'\n'):
47 output.extend(indent_stack)
49 elif isinstance(node, list):
50 for i
in range(0,
len(node)):
54 elif isinstance(node, IDLFile):
58 elif isinstance(node, IDLModule):
61 wln(
'module %s {' % node.id)
68 elif isinstance(node, IDLEnum):
69 w(
'enum %s {}' % node.id)
71 elif isinstance(node, IDLInterface):
76 w(
'interface %s' % node.id)
81 w(node.parents,
',\n')
86 wln(
'/* Constants */')
87 w(
sort(node.constants))
90 wln(
'/* Attributes */')
91 w(
sort(node.attributes))
94 wln(
'/* Operations */')
95 w(
sort(node.operations))
98 elif isinstance(node, IDLParentInterface):
101 elif isinstance(node, IDLAnnotations):
103 for (name, annotation)
in sorted(node.items()):
106 if annotation
and len(annotation):
108 for (argName, argValue)
in sorted(annotation.items()):
110 subRes.append(argName)
112 subRes.append(
'%s=%s' % (argName, argValue))
113 w(
'@%s(%s)' % (name,
', '.
join(subRes)))
116 elif isinstance(node, IDLExtAttrs):
120 for k
in sorted(node):
126 if isinstance(v, IDLExtAttrFunctionValue):
130 elif isinstance(v, list):
131 assert k ==
'Constructor'
138 w(
'=%s' % v.__str__())
141 elif isinstance(node, IDLExtAttrFunctionValue):
145 w(node.arguments,
', ')
147 elif isinstance(node, IDLAttribute):
148 wsp(node.annotations)
150 if node.is_read_only:
154 if (node.type.nullable):
159 elif isinstance(node, IDLConstant):
160 wsp(node.annotations)
162 wln(
'const %s %s = %s;' % (node.type.id, node.id, node.value))
163 elif isinstance(node, IDLOperation):
164 wsp(node.annotations)
169 w(node.specials,
' ')
172 if (node.type.nullable):
177 w(node.arguments,
', ')
180 elif isinstance(node, IDLArgument):
185 if node.type.nullable:
189 raise TypeError(
"Expected str or IDLNode but %s found" %
type(node))
192 return ''.
join(output)
static std::vector< SkPDFIndirectReference > sort(const THashSet< SkPDFIndirectReference > &src)
def render(idl_node, indent_str=' ')
static SkString join(const CommandLineFlags::StringArray &)