MCPcopy Index your code
hub / github.com/KhronosGroup/Vulkan-Docs / evalDependencyLanguage

Function evalDependencyLanguage

scripts/parse_dependency.py:232–260  ·  view source on GitHub ↗

Evaluate an expression stack, returning an English equivalent - stack - the stack - leafMarkup, opMarkup, parenthesize - same as dependencyLanguage - root - True only if this is the outer (root) expression level - parent_op - the parent operator ('+' or ','), used to avoid unnec

(stack, leafMarkup, opMarkup, parenthesize, root, parent_op = None)

Source from the content-addressed store, hash-verified

230 return val
231
232def evalDependencyLanguage(stack, leafMarkup, opMarkup, parenthesize, root, parent_op = None):
233 """Evaluate an expression stack, returning an English equivalent
234
235 - stack - the stack
236 - leafMarkup, opMarkup, parenthesize - same as dependencyLanguage
237 - root - True only if this is the outer (root) expression level
238 - parent_op - the parent operator ('+' or ','), used to avoid unnecessary parentheses"""
239
240 op, num_args = stack.pop(), 0
241 if isinstance(op, tuple):
242 op, num_args = op
243 if op in '+,':
244 # Recursively evaluate left and right sides, passing current op as parent
245 rhs = evalDependencyLanguage(stack, leafMarkup, opMarkup, parenthesize, root = False, parent_op = op)
246 opname = opMarkup(op)
247 lhs = evalDependencyLanguage(stack, leafMarkup, opMarkup, parenthesize, root = False, parent_op = op)
248 # Only add parentheses if:
249 # 1. parenthesize is True, AND
250 # 2. not at root level, AND
251 # 3. the current operator differs from parent operator (mixed precedence)
252 if parenthesize and not root and parent_op is not None and parent_op != op:
253 return f'({lhs} {opname} {rhs})'
254 else:
255 return f'{lhs} {opname} {rhs}'
256 elif op[0].isalpha() or (op.startswith('!') and len(op) > 1 and op[1].isalpha()):
257 # This is an extension or feature name (optionally negated with '!' for protect expressions)
258 return leafMarkup(op)
259 else:
260 raise Exception(f'invalid op: {op}')
261
262def dependencyLanguage(dependency, leafMarkup, opMarkup, parenthesize):
263 """Return an API dependency expression translated to a form suitable for

Callers 2

dependencyLanguageFunction · 0.85
protectLanguageCFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected