MCPcopy Create free account
hub / github.com/NVIDIA/cuda-quantum / visit_Expr

Method visit_Expr

python/cudaq/kernel/ast_bridge.py:1933–1954  ·  view source on GitHub ↗

Implement `ast.Expr` visitation to screen out all multi-line `docstrings`. These are differentiated from other strings at the node-type level. Strings we may care about will have been assigned to a variable (hence `ast.Assign` nodes), while other strings will exist a

(self, node)

Source from the content-addressed store, hash-verified

1931 pass
1932
1933 def visit_Expr(self, node):
1934 """Implement `ast.Expr` visitation to screen out all multi-line
1935 `docstrings`.
1936
1937 These are differentiated from other strings at the
1938 node-type level. Strings we may care about will have been assigned to a
1939 variable (hence `ast.Assign` nodes), while other strings will exist as
1940 standalone expressions with no uses.
1941 """
1942 if hasattr(node, 'value') and isinstance(node.value, ast.Constant):
1943 self.debug_msg(lambda: f'[(Inline) Visit Constant]', node.value)
1944 constant = node.value
1945 if isinstance(constant.value, str):
1946 return
1947
1948 self.visit(node.value)
1949 if self.valueStack.currentNumValues > 0:
1950 # An `ast.Expr` object is created when an expression is used as a
1951 # statement. This expression may produce a value, which is ignored
1952 # (not assigned) in the Python code. We hence need to pop that value
1953 # to match that behavior and ignore it.
1954 self.popValue()
1955
1956 def visit_Lambda(self, node):
1957 """Map a lambda expression in a CUDA-Q kernel to a CC Lambda (a Value of

Callers

nothing calls this directly

Calls 3

debug_msgMethod · 0.95
visitMethod · 0.95
popValueMethod · 0.95

Tested by

no test coverage detected