|
1 | 1 | import dataclasses |
2 | 2 |
|
3 | 3 | import pytest |
4 | | - |
5 | | -from openqasm3.visitor import QASMVisitor |
6 | | - |
| 4 | +from openpulse.ast import (AngleType, Annotation, ArrayLiteral, ArrayType, |
| 5 | + AssignmentOperator, CalibrationDefinition, |
| 6 | + CalibrationStatement, ClassicalArgument, |
| 7 | + ClassicalAssignment, ClassicalDeclaration, |
| 8 | + ComplexType, DurationType, ExpressionStatement, |
| 9 | + ExternArgument, ExternDeclaration, FloatLiteral, |
| 10 | + FloatType, ForInLoop, FrameType, FunctionCall, |
| 11 | + Identifier, IntegerLiteral, IntType, PortType, |
| 12 | + Pragma, Program, QASMNode, QuantumBarrier, |
| 13 | + RangeDefinition, ReturnStatement, UnaryExpression, |
| 14 | + UnaryOperator, WaveformType) |
7 | 15 | from openpulse.parser import parse |
8 | | -from openpulse.ast import ( |
9 | | - AngleType, |
10 | | - Annotation, |
11 | | - ArrayLiteral, |
12 | | - ArrayType, |
13 | | - CalibrationDefinition, |
14 | | - CalibrationStatement, |
15 | | - ClassicalArgument, |
16 | | - ClassicalDeclaration, |
17 | | - ComplexType, |
18 | | - DurationType, |
19 | | - ExpressionStatement, |
20 | | - ExternArgument, |
21 | | - ExternDeclaration, |
22 | | - FloatLiteral, |
23 | | - FloatType, |
24 | | - ForInLoop, |
25 | | - FunctionCall, |
26 | | - Identifier, |
27 | | - IntegerLiteral, |
28 | | - IntType, |
29 | | - Pragma, |
30 | | - Program, |
31 | | - QASMNode, |
32 | | - QuantumBarrier, |
33 | | - RangeDefinition, |
34 | | - ReturnStatement, |
35 | | - UnaryExpression, |
36 | | - UnaryOperator, |
37 | | - FrameType, |
38 | | - PortType, |
39 | | - WaveformType, |
40 | | -) |
| 16 | +from openqasm3.visitor import QASMVisitor |
41 | 17 |
|
42 | 18 |
|
43 | 19 | class SpanGuard(QASMVisitor): |
@@ -273,27 +249,33 @@ def test_array(): |
273 | 249 | def test_annotation_in_cal_block(): |
274 | 250 | p = """ |
275 | 251 | cal { |
276 | | - @foo |
| 252 | + @word1 |
277 | 253 | int x = 10; |
| 254 | +
|
| 255 | + @word1 command1 |
| 256 | + @word2 command2 32f%^& |
| 257 | + x = 0; |
| 258 | +
|
| 259 | + @word1 @not_a_separate_annotation uint x; |
| 260 | + z(); |
278 | 261 | } |
279 | 262 | """ |
280 | 263 |
|
281 | | - program = parse(p) |
282 | | - expected = Program( |
283 | | - statements=[ |
284 | | - CalibrationStatement( |
285 | | - body=[ |
286 | | - ClassicalDeclaration( |
287 | | - type=IntType(), |
288 | | - identifier=Identifier("x"), |
289 | | - init_expression=IntegerLiteral(10), |
290 | | - ) |
291 | | - ] |
292 | | - ) |
293 | | - ] |
| 264 | + xdecl = ClassicalDeclaration( |
| 265 | + type=IntType(), |
| 266 | + identifier=Identifier("x"), |
| 267 | + init_expression=IntegerLiteral(10), |
294 | 268 | ) |
295 | | - # annotate the declaration |
296 | | - expected.statements[0].body[0].annotations = [Annotation("foo")] |
| 269 | + xdecl.annotations = [Annotation("word1")] |
| 270 | + |
| 271 | + xassign = ClassicalAssignment(Identifier("x"), AssignmentOperator["="], IntegerLiteral(0)) |
| 272 | + xassign.annotations = [Annotation("word1", "command1"), Annotation("word2", "command2 32f%^&")] |
| 273 | + |
| 274 | + zcall = ExpressionStatement(FunctionCall(Identifier("z"), [])) |
| 275 | + zcall.annotations = [Annotation("word1", "@not_a_separate_annotation uint x;")] |
| 276 | + program = parse(p) |
| 277 | + expected = Program(statements=[CalibrationStatement(body=[xdecl, xassign, zcall])]) |
| 278 | + |
297 | 279 | assert _remove_spans(program) == expected |
298 | 280 |
|
299 | 281 |
|
|
0 commit comments