Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Commit 712a204

Browse files
authored
Merge pull request #856 from microsoft/samarsha/sized-array
Add "[value, size = n]" array constructor
2 parents 1d03f82 + 65798d5 commit 712a204

File tree

19 files changed

+381
-239
lines changed

19 files changed

+381
-239
lines changed

src/QsCompiler/BondSchemas/BondSchemaTranslator.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,14 @@ private static QsExpressionKindComposition<TBondExpression, TBondSymbol, TBondTy
859859
kind = QsExpressionKind.ValueArray;
860860
bondExpressionArray = compilerValueArray.Item.Select(e => expressionTranslator(e)).ToList();
861861
}
862+
else if (qsExpressionKind is SyntaxTokens.QsExpressionKind<TCompilerExpression, TCompilerSymbol, TCompilerType>.SizedArray compilerSizedArray)
863+
{
864+
kind = QsExpressionKind.SizedArray;
865+
bondExpressionDouble = ToQsExpressionKindExpressionDoubleGeneric(
866+
compilerSizedArray.value,
867+
compilerSizedArray.size,
868+
expressionTranslator);
869+
}
862870
else if (qsExpressionKind is SyntaxTokens.QsExpressionKind<TCompilerExpression, TCompilerSymbol, TCompilerType>.ArrayItem compilerArrayItem)
863871
{
864872
kind = QsExpressionKind.ArrayItem;

src/QsCompiler/BondSchemas/CompilerDataStructures.bond

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ enum QsExpressionKind
105105
ControlledApplication,
106106
CallLikeExpression,
107107
MissingExpr,
108-
InvalidExpr
108+
InvalidExpr,
109+
SizedArray
109110
}
110111

111112
// Used to encapsulate data when QsExpressionKind is Identifier.
@@ -126,7 +127,8 @@ struct QsExpressionKindStringLiteral<TExpression>
126127
10: vector<TExpression> Expressions;
127128
}
128129

129-
// Used to encapsulate data when QsExpressionKind is RangeLiteral, ArrayItem, ADD, SUB, MUL, DIV, MOD, POW, EQ, NEQ, LT, LTE, GT, GTE, AND, OR, BOR, BAND, BXOR, LSHIFT, RSHIFT, CallLikeApplication.
130+
// Used to encapsulate data when QsExpressionKind is RangeLiteral, ArrayItem, ADD, SUB, MUL, DIV, MOD, POW, EQ, NEQ, LT,
131+
// LTE, GT, GTE, AND, OR, BOR, BAND, BXOR, LSHIFT, RSHIFT, CallLikeApplication, SizedArray.
130132
// N.B. Does not have an equivalent F# type.
131133
struct QsExpressionKindExpressionDouble<TExpression>
132134
{
@@ -203,7 +205,8 @@ struct QsExpressionKindComposition<TExpression, TSymbol, TType>
203205
// Not null when Kind is NEG, NOT, BNOT, UnwrapApplication, AdjointApplication, ControlledApplication.
204206
65: nullable<TExpression> Expression;
205207

206-
// Not null when Kind is RangeLiteral, ArrayItem, ADD, SUB, MUL, DIV, MOD, POW, EQ, NEQ, LT, LTE, GT, GTE, AND, OR, BOR, BAND, BXOR, LSHIFT, RSHIFT, CallLikeApplication.
208+
// Not null when Kind is RangeLiteral, ArrayItem, ADD, SUB, MUL, DIV, MOD, POW, EQ, NEQ, LT, LTE, GT, GTE, AND, OR,
209+
// BOR, BAND, BXOR, LSHIFT, RSHIFT, CallLikeApplication, SizedArray.
207210
70: nullable<QsExpressionKindExpressionDouble<TExpression>> ExpressionDouble;
208211

209212
// Not null when Kind is CONDITIONAL, CopyAndUpdate.

src/QsCompiler/BondSchemas/CompilerObjectTranslator.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,7 @@ string UnexpectedNullFieldMessage(string fieldName) =>
868868
}
869869
else if ((bondQsExpressionKindComposition.Kind == QsExpressionKind.RangeLiteral) ||
870870
(bondQsExpressionKindComposition.Kind == QsExpressionKind.ArrayItem) ||
871+
(bondQsExpressionKindComposition.Kind == QsExpressionKind.SizedArray) ||
871872
(bondQsExpressionKindComposition.Kind == QsExpressionKind.ADD) ||
872873
(bondQsExpressionKindComposition.Kind == QsExpressionKind.SUB) ||
873874
(bondQsExpressionKindComposition.Kind == QsExpressionKind.MUL) ||
@@ -901,6 +902,8 @@ string UnexpectedNullFieldMessage(string fieldName) =>
901902
NewRangeLiteral(item1: compilerExpression1, item2: compilerExpression2),
902903
QsExpressionKind.ArrayItem => SyntaxTokens.QsExpressionKind<TCompilerExpression, TCompilerSymbol, TCompilerType>.
903904
NewArrayItem(item1: compilerExpression1, item2: compilerExpression2),
905+
QsExpressionKind.SizedArray => SyntaxTokens.QsExpressionKind<TCompilerExpression, TCompilerSymbol, TCompilerType>.
906+
NewSizedArray(compilerExpression1, compilerExpression2),
904907
QsExpressionKind.ADD => SyntaxTokens.QsExpressionKind<TCompilerExpression, TCompilerSymbol, TCompilerType>.
905908
NewADD(item1: compilerExpression1, item2: compilerExpression2),
906909
QsExpressionKind.SUB => SyntaxTokens.QsExpressionKind<TCompilerExpression, TCompilerSymbol, TCompilerType>.

0 commit comments

Comments
 (0)