@@ -62,10 +62,11 @@ pub struct Stmt {
6262impl Display for Stmt {
6363 fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
6464 let mut indent = set_indentation ( indented ( f) , 0 ) ;
65+ write ! ( indent, "Stmt {}" , self . span) ?;
66+ indent = set_indentation ( indent, 1 ) ;
6567 for annotation in & self . annotations {
6668 write ! ( indent, "\n {annotation}" ) ?;
6769 }
68- write ! ( indent, "Stmt {}" , self . span) ?;
6970 write ! ( indent, "\n {}" , self . kind) ?;
7071 Ok ( ( ) )
7172 }
@@ -74,15 +75,19 @@ impl Display for Stmt {
7475#[ derive( Clone , Debug ) ]
7576pub struct Annotation {
7677 pub span : Span ,
77- pub name : Box < PathKind > ,
78+ pub identifier : Rc < str > ,
7879 pub value : Option < Rc < str > > ,
7980}
8081impl Display for Annotation {
8182 fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
8283 if let Some ( value) = & self . value {
83- write ! ( f, "Annotation {}: {}, {}" , self . span, self . name, value)
84+ write ! (
85+ f,
86+ "Annotation {}: ({}, {})" ,
87+ self . span, self . identifier, value
88+ )
8489 } else {
85- write ! ( f, "Annotation {}: {} " , self . span, self . name )
90+ write ! ( f, "Annotation {}: ({}) " , self . span, self . identifier )
8691 }
8792 }
8893}
@@ -712,7 +717,7 @@ impl Display for QuantumMeasurement {
712717#[ derive( Clone , Debug ) ]
713718pub struct ClassicalArgument {
714719 pub span : Span ,
715- pub r#type : ClassicalType ,
720+ pub r#type : ScalarType ,
716721 pub name : Identifier ,
717722 pub access : Option < AccessControl > ,
718723}
@@ -738,7 +743,7 @@ impl Display for ClassicalArgument {
738743#[ derive( Clone , Debug ) ]
739744pub struct ExternArgument {
740745 pub span : Span ,
741- pub r#type : ClassicalType ,
746+ pub r#type : ScalarType ,
742747 pub access : Option < AccessControl > ,
743748}
744749
@@ -757,46 +762,42 @@ impl Display for ExternArgument {
757762}
758763
759764#[ derive( Clone , Debug ) ]
760- pub struct ClassicalType {
765+ pub struct ScalarType {
761766 pub span : Span ,
762- pub kind : ClassicalTypeKind ,
767+ pub kind : ScalarTypeKind ,
763768}
764769
765- impl Display for ClassicalType {
770+ impl Display for ScalarType {
766771 fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
767772 write ! ( f, "ClassicalType {}: {}" , self . span, self . kind)
768773 }
769774}
770775
771776#[ derive( Clone , Debug ) ]
772- pub enum ClassicalTypeKind {
777+ pub enum ScalarTypeKind {
778+ Bit ( BitType ) ,
773779 Int ( IntType ) ,
774780 UInt ( UIntType ) ,
775781 Float ( FloatType ) ,
776782 Complex ( ComplexType ) ,
777783 Angle ( AngleType ) ,
778- Bit ( BitType ) ,
779784 BoolType ,
780- Array ( ArrayType ) ,
781- ArrayReference ( ArrayReferenceType ) ,
782785 Duration ,
783786 Stretch ,
784787}
785788
786- impl Display for ClassicalTypeKind {
789+ impl Display for ScalarTypeKind {
787790 fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
788791 match self {
789- ClassicalTypeKind :: Int ( int) => write ! ( f, "ClassicalTypeKind {int}" ) ,
790- ClassicalTypeKind :: UInt ( uint) => write ! ( f, "ClassicalTypeKind {uint}" ) ,
791- ClassicalTypeKind :: Float ( float) => write ! ( f, "ClassicalTypeKind {float}" ) ,
792- ClassicalTypeKind :: Complex ( complex) => write ! ( f, "ClassicalTypeKind {complex}" ) ,
793- ClassicalTypeKind :: Angle ( angle) => write ! ( f, "ClassicalTypeKind {angle}" ) ,
794- ClassicalTypeKind :: Bit ( bit) => write ! ( f, "ClassicalTypeKind {bit}" ) ,
795- ClassicalTypeKind :: BoolType => write ! ( f, "ClassicalTypeKind BoolType" ) ,
796- ClassicalTypeKind :: Array ( array) => write ! ( f, "ClassicalTypeKind {array}" ) ,
797- ClassicalTypeKind :: ArrayReference ( array) => write ! ( f, "ClassicalTypeKind {array}" ) ,
798- ClassicalTypeKind :: Duration => write ! ( f, "ClassicalTypeKind Duration" ) ,
799- ClassicalTypeKind :: Stretch => write ! ( f, "ClassicalTypeKind Stretch" ) ,
792+ ScalarTypeKind :: Int ( int) => write ! ( f, "{int}" ) ,
793+ ScalarTypeKind :: UInt ( uint) => write ! ( f, "{uint}" ) ,
794+ ScalarTypeKind :: Float ( float) => write ! ( f, "{float}" ) ,
795+ ScalarTypeKind :: Complex ( complex) => write ! ( f, "{complex}" ) ,
796+ ScalarTypeKind :: Angle ( angle) => write ! ( f, "{angle}" ) ,
797+ ScalarTypeKind :: Bit ( bit) => write ! ( f, "{bit}" ) ,
798+ ScalarTypeKind :: BoolType => write ! ( f, "BoolType" ) ,
799+ ScalarTypeKind :: Duration => write ! ( f, "Duration" ) ,
800+ ScalarTypeKind :: Stretch => write ! ( f, "Stretch" ) ,
800801 }
801802 }
802803}
@@ -808,8 +809,8 @@ pub enum ArrayBaseTypeKind {
808809 Float ( FloatType ) ,
809810 Complex ( ComplexType ) ,
810811 Angle ( AngleType ) ,
811- Bit ( BitType ) ,
812812 BoolType ,
813+ Duration ,
813814}
814815
815816impl Display for ArrayBaseTypeKind {
@@ -820,7 +821,7 @@ impl Display for ArrayBaseTypeKind {
820821 ArrayBaseTypeKind :: Float ( float) => write ! ( f, "ArrayBaseTypeKind {float}" ) ,
821822 ArrayBaseTypeKind :: Complex ( complex) => write ! ( f, "ArrayBaseTypeKind {complex}" ) ,
822823 ArrayBaseTypeKind :: Angle ( angle) => write ! ( f, "ArrayBaseTypeKind {angle}" ) ,
823- ArrayBaseTypeKind :: Bit ( bit ) => write ! ( f, "ArrayBaseTypeKind {bit} " ) ,
824+ ArrayBaseTypeKind :: Duration => write ! ( f, "ArrayBaseTypeKind DurationType " ) ,
824825 ArrayBaseTypeKind :: BoolType => write ! ( f, "ArrayBaseTypeKind BoolType" ) ,
825826 }
826827 }
@@ -835,9 +836,9 @@ pub struct IntType {
835836impl Display for IntType {
836837 fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
837838 if let Some ( size) = & self . size {
838- write ! ( f, "IntType {} : {}" , self . span, size )
839+ write ! ( f, "IntType[{}] : {}" , size , self . span)
839840 } else {
840- write ! ( f, "IntType" )
841+ write ! ( f, "IntType {}" , self . span )
841842 }
842843 }
843844}
@@ -851,9 +852,9 @@ pub struct UIntType {
851852impl Display for UIntType {
852853 fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
853854 if let Some ( size) = & self . size {
854- write ! ( f, "UIntType {} : {}" , self . span, size )
855+ write ! ( f, "UIntType[{}] : {}" , size , self . span)
855856 } else {
856- write ! ( f, "UIntType" )
857+ write ! ( f, "UIntType {}" , self . span )
857858 }
858859 }
859860}
@@ -867,9 +868,9 @@ pub struct FloatType {
867868impl Display for FloatType {
868869 fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
869870 if let Some ( size) = & self . size {
870- write ! ( f, "FloatType {} : {}" , self . span, size )
871+ write ! ( f, "FloatType[{}] : {}" , size , self . span)
871872 } else {
872- write ! ( f, "FloatType" )
873+ write ! ( f, "FloatType {}" , self . span )
873874 }
874875 }
875876}
@@ -883,9 +884,9 @@ pub struct ComplexType {
883884impl Display for ComplexType {
884885 fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
885886 if let Some ( size) = & self . base_size {
886- write ! ( f, "ComplexType {} : {}" , self . span, size )
887+ write ! ( f, "ComplexType[float[{}]] : {}" , size , self . span)
887888 } else {
888- write ! ( f, "ComplexType" )
889+ write ! ( f, "ComplexType {}" , self . span )
889890 }
890891 }
891892}
@@ -901,7 +902,7 @@ impl Display for AngleType {
901902 if let Some ( size) = & self . size {
902903 write ! ( f, "AngleType {}: {}" , self . span, size)
903904 } else {
904- write ! ( f, "AngleType" )
905+ write ! ( f, "AngleType {}" , self . span )
905906 }
906907 }
907908}
@@ -922,11 +923,28 @@ impl Display for BitType {
922923 }
923924}
924925
926+ #[ derive( Clone , Debug ) ]
927+ pub enum TypeDef {
928+ Scalar ( ScalarType ) ,
929+ Array ( ArrayType ) ,
930+ ArrayReference ( ArrayReferenceType ) ,
931+ }
932+
933+ impl Display for TypeDef {
934+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
935+ match self {
936+ TypeDef :: Scalar ( scalar) => write ! ( f, "{scalar}" ) ,
937+ TypeDef :: Array ( array) => write ! ( f, "{array}" ) ,
938+ TypeDef :: ArrayReference ( array) => write ! ( f, "{array}" ) ,
939+ }
940+ }
941+ }
942+
925943#[ derive( Clone , Debug ) ]
926944pub struct ArrayType {
927945 pub span : Span ,
928946 pub base_type : ArrayBaseTypeKind ,
929- pub dimensions : List < ExprStmt > ,
947+ pub dimensions : List < Expr > ,
930948}
931949
932950impl Display for ArrayType {
@@ -992,16 +1010,16 @@ impl Display for QuantumArgument {
9921010#[ derive( Clone , Debug ) ]
9931011pub struct Pragma {
9941012 pub span : Span ,
995- pub name : Box < PathKind > ,
1013+ pub identifier : Rc < str > ,
9961014 pub value : Option < Rc < str > > ,
9971015}
9981016
9991017impl Display for Pragma {
10001018 fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
10011019 if let Some ( value) = & self . value {
1002- write ! ( f, "Pragma {}: {}, {}" , self . span, self . name , value)
1020+ write ! ( f, "Pragma {}: ( {}, {}) " , self . span, self . identifier , value)
10031021 } else {
1004- write ! ( f, "Pragma {}: {} " , self . span, self . name )
1022+ write ! ( f, "Pragma {}: ({}) " , self . span, self . identifier )
10051023 }
10061024 }
10071025}
@@ -1087,7 +1105,7 @@ pub struct ExternDecl {
10871105 pub span : Span ,
10881106 pub name : Identifier ,
10891107 pub arguments : List < ExternArgument > ,
1090- pub return_type : Option < ClassicalType > ,
1108+ pub return_type : Option < ScalarType > ,
10911109}
10921110
10931111impl Display for ExternDecl {
@@ -1245,8 +1263,8 @@ impl Display for MeasureStmt {
12451263#[ derive( Clone , Debug ) ]
12461264pub struct ClassicalDeclarationStmt {
12471265 pub span : Span ,
1248- pub r#type : ClassicalType ,
1249- pub identifier : Identifier ,
1266+ pub r#type : TypeDef ,
1267+ pub identifier : Box < Ident > ,
12501268 pub init_expr : Option < Box < ValueExpression > > ,
12511269}
12521270
@@ -1287,8 +1305,8 @@ impl Display for ValueExpression {
12871305pub struct IODeclaration {
12881306 pub span : Span ,
12891307 pub io_identifier : IOKeyword ,
1290- pub r#type : ClassicalType ,
1291- pub identifier : Identifier ,
1308+ pub r#type : TypeDef ,
1309+ pub identifier : Box < Ident > ,
12921310}
12931311
12941312impl Display for IODeclaration {
@@ -1303,10 +1321,10 @@ impl Display for IODeclaration {
13031321
13041322#[ derive( Clone , Debug ) ]
13051323pub struct ConstantDeclaration {
1306- span : Span ,
1307- r#type : ClassicalType ,
1308- identifier : Identifier ,
1309- init_expr : ExprStmt ,
1324+ pub span : Span ,
1325+ pub r#type : TypeDef ,
1326+ pub identifier : Box < Ident > ,
1327+ pub init_expr : Box < ExprStmt > ,
13101328}
13111329
13121330impl Display for ConstantDeclaration {
@@ -1353,7 +1371,7 @@ pub struct CalibrationDefinition {
13531371 name : Identifier ,
13541372 args : List < CalibrationArgument > ,
13551373 qubits : List < Identifier > ,
1356- return_type : Option < ClassicalType > ,
1374+ return_type : Option < ScalarType > ,
13571375 body : String ,
13581376}
13591377
@@ -1395,7 +1413,7 @@ pub struct DefStmt {
13951413 name : Identifier ,
13961414 args : List < Box < Operand > > ,
13971415 body : List < Box < Stmt > > ,
1398- return_type : Option < ClassicalType > ,
1416+ return_type : Option < ScalarType > ,
13991417}
14001418
14011419impl Display for DefStmt {
@@ -1489,7 +1507,7 @@ impl Display for WhileLoop {
14891507#[ derive( Clone , Debug ) ]
14901508pub struct ForStmt {
14911509 span : Span ,
1492- r#type : ClassicalType ,
1510+ r#type : ScalarType ,
14931511 identifier : Identifier ,
14941512 set_declaration : Box < EnumerableSet > ,
14951513 block : List < Stmt > ,
@@ -1647,7 +1665,7 @@ impl Display for FunctionCall {
16471665#[ derive( Clone , Debug ) ]
16481666pub struct Cast {
16491667 pub span : Span ,
1650- pub r#type : ClassicalType ,
1668+ pub r#type : ScalarType ,
16511669 pub arg : ExprStmt ,
16521670}
16531671
0 commit comments