@@ -4136,12 +4136,6 @@ Expr* SemanticsVisitor::CheckMatrixSwizzleExpr(
4136
4136
IntegerLiteralValue baseElementRowCount,
4137
4137
IntegerLiteralValue baseElementColCount)
4138
4138
{
4139
- MatrixSwizzleExpr* swizExpr = m_astBuilder->create <MatrixSwizzleExpr>();
4140
- swizExpr->loc = memberRefExpr->loc ;
4141
- swizExpr->base = memberRefExpr->baseExpression ;
4142
- swizExpr->memberOpLoc = memberRefExpr->memberOperatorLoc ;
4143
- swizExpr->checked = true ;
4144
-
4145
4139
// We can have up to 4 swizzles of two elements each
4146
4140
MatrixCoord elementCoords[4 ];
4147
4141
int elementCount = 0 ;
@@ -4170,24 +4164,14 @@ Expr* SemanticsVisitor::CheckMatrixSwizzleExpr(
4170
4164
// Throw out swizzling with more than 4 output elements
4171
4165
if (elementCount >= 4 )
4172
4166
{
4173
- getSink ()->diagnose (
4174
- swizExpr,
4175
- Diagnostics::invalidSwizzleExpr,
4176
- swizzleText,
4177
- baseElementType->toString ());
4178
- return CreateErrorExpr (memberRefExpr);
4167
+ return nullptr ;
4179
4168
}
4180
4169
MatrixCoord elementCoord = {0 , 0 };
4181
4170
4182
4171
// Check for the preceding underscore
4183
4172
if (*cursor++ != ' _' )
4184
4173
{
4185
- getSink ()->diagnose (
4186
- swizExpr,
4187
- Diagnostics::invalidSwizzleExpr,
4188
- swizzleText,
4189
- baseElementType->toString ());
4190
- return CreateErrorExpr (memberRefExpr);
4174
+ return nullptr ;
4191
4175
}
4192
4176
4193
4177
// Check for one or zero indexing
@@ -4196,12 +4180,7 @@ Expr* SemanticsVisitor::CheckMatrixSwizzleExpr(
4196
4180
// Can't mix one and zero indexing
4197
4181
if (zeroIndexOffset == 1 )
4198
4182
{
4199
- getSink ()->diagnose (
4200
- swizExpr,
4201
- Diagnostics::invalidSwizzleExpr,
4202
- swizzleText,
4203
- baseElementType->toString ());
4204
- return CreateErrorExpr (memberRefExpr);
4183
+ return nullptr ;
4205
4184
}
4206
4185
zeroIndexOffset = 0 ;
4207
4186
// Increment the index since we saw 'm'
@@ -4212,12 +4191,7 @@ Expr* SemanticsVisitor::CheckMatrixSwizzleExpr(
4212
4191
// Can't mix one and zero indexing
4213
4192
if (zeroIndexOffset == 0 )
4214
4193
{
4215
- getSink ()->diagnose (
4216
- swizExpr,
4217
- Diagnostics::invalidSwizzleExpr,
4218
- swizzleText,
4219
- baseElementType->toString ());
4220
- return CreateErrorExpr (memberRefExpr);
4194
+ return nullptr ;
4221
4195
}
4222
4196
zeroIndexOffset = 1 ;
4223
4197
}
@@ -4229,13 +4203,7 @@ Expr* SemanticsVisitor::CheckMatrixSwizzleExpr(
4229
4203
4230
4204
if (ch < ' 0' || ch > ' 4' )
4231
4205
{
4232
- // An invalid character in the swizzle is an error
4233
- getSink ()->diagnose (
4234
- swizExpr,
4235
- Diagnostics::invalidSwizzleExpr,
4236
- swizzleText,
4237
- baseElementType->toString ());
4238
- return CreateErrorExpr (memberRefExpr);
4206
+ return nullptr ;
4239
4207
}
4240
4208
const int subIndex = ch - ' 0' - zeroIndexOffset;
4241
4209
@@ -4255,12 +4223,7 @@ Expr* SemanticsVisitor::CheckMatrixSwizzleExpr(
4255
4223
// Account for off-by-one and reject 0 if oneIndexed
4256
4224
if (subIndex >= elementLimit || subIndex < 0 )
4257
4225
{
4258
- getSink ()->diagnose (
4259
- swizExpr,
4260
- Diagnostics::invalidSwizzleExpr,
4261
- swizzleText,
4262
- baseElementType->toString ());
4263
- return CreateErrorExpr (memberRefExpr);
4226
+ return nullptr ;
4264
4227
}
4265
4228
}
4266
4229
// Check if we've seen this index before
@@ -4275,6 +4238,12 @@ Expr* SemanticsVisitor::CheckMatrixSwizzleExpr(
4275
4238
elementCount++;
4276
4239
}
4277
4240
4241
+ MatrixSwizzleExpr* swizExpr = m_astBuilder->create <MatrixSwizzleExpr>();
4242
+ swizExpr->loc = memberRefExpr->loc ;
4243
+ swizExpr->base = memberRefExpr->baseExpression ;
4244
+ swizExpr->memberOpLoc = memberRefExpr->memberOperatorLoc ;
4245
+ swizExpr->checked = true ;
4246
+
4278
4247
// Store our list in the actual AST node
4279
4248
for (int ee = 0 ; ee < elementCount; ++ee)
4280
4249
{
@@ -4324,11 +4293,7 @@ Expr* SemanticsVisitor::CheckMatrixSwizzleExpr(
4324
4293
constantColCount->getValue ());
4325
4294
}
4326
4295
}
4327
- getSink ()->diagnose (
4328
- memberRefExpr,
4329
- Diagnostics::unimplemented,
4330
- " swizzle on matrix of unknown size" );
4331
- return CreateErrorExpr (memberRefExpr);
4296
+ return nullptr ;
4332
4297
}
4333
4298
4334
4299
Expr* SemanticsVisitor::checkTupleSwizzleExpr (MemberExpr* memberExpr, TupleType* baseTupleType)
@@ -4439,26 +4404,13 @@ Expr* SemanticsVisitor::CheckSwizzleExpr(
4439
4404
Type* baseElementType,
4440
4405
IntegerLiteralValue baseElementCount)
4441
4406
{
4442
- SwizzleExpr* swizExpr = m_astBuilder->create <SwizzleExpr>();
4443
- swizExpr->loc = memberRefExpr->loc ;
4444
- swizExpr->base = memberRefExpr->baseExpression ;
4445
- swizExpr->memberOpLoc = memberRefExpr->memberOperatorLoc ;
4446
4407
IntegerLiteralValue limitElement = baseElementCount;
4447
4408
4448
4409
ShortList<uint32_t , 4 > elementIndices;
4449
4410
4450
4411
bool anyDuplicates = false ;
4451
4412
bool anyError = false ;
4452
- if (memberRefExpr->name == getSession ()->getCompletionRequestTokenName ())
4453
- {
4454
- auto & suggestions = getLinkage ()->contentAssistInfo .completionSuggestions ;
4455
- suggestions.clear ();
4456
- suggestions.scopeKind = CompletionSuggestions::ScopeKind::Swizzle;
4457
- suggestions.swizzleBaseType =
4458
- memberRefExpr->baseExpression ? memberRefExpr->baseExpression ->type : nullptr ;
4459
- suggestions.elementCount [0 ] = baseElementCount;
4460
- suggestions.elementCount [1 ] = 0 ;
4461
- }
4413
+
4462
4414
auto swizzleText = getText (memberRefExpr->name );
4463
4415
4464
4416
for (Index i = 0 ; i < swizzleText.getLength (); i++)
@@ -4518,18 +4470,18 @@ Expr* SemanticsVisitor::CheckSwizzleExpr(
4518
4470
elementIndices.add (elementIndex);
4519
4471
}
4520
4472
4521
- swizExpr->elementIndices = _Move (elementIndices);
4522
-
4523
4473
if (anyError)
4524
4474
{
4525
- getSink ()->diagnose (
4526
- swizExpr,
4527
- Diagnostics::invalidSwizzleExpr,
4528
- swizzleText,
4529
- baseElementType->toString ());
4530
- return CreateErrorExpr (memberRefExpr);
4475
+ return nullptr ;
4531
4476
}
4532
- else if (swizExpr->elementIndices .getCount () == 1 )
4477
+
4478
+ SwizzleExpr* swizExpr = m_astBuilder->create <SwizzleExpr>();
4479
+ swizExpr->loc = memberRefExpr->loc ;
4480
+ swizExpr->base = memberRefExpr->baseExpression ;
4481
+ swizExpr->memberOpLoc = memberRefExpr->memberOperatorLoc ;
4482
+ swizExpr->elementIndices = _Move (elementIndices);
4483
+
4484
+ if (swizExpr->elementIndices .getCount () == 1 )
4533
4485
{
4534
4486
// single-component swizzle produces a scalar
4535
4487
//
@@ -4568,11 +4520,7 @@ Expr* SemanticsVisitor::CheckSwizzleExpr(
4568
4520
}
4569
4521
else
4570
4522
{
4571
- getSink ()->diagnose (
4572
- memberRefExpr,
4573
- Diagnostics::unimplemented,
4574
- " swizzle on vector of unknown size" );
4575
- return CreateErrorExpr (memberRefExpr);
4523
+ return nullptr ;
4576
4524
}
4577
4525
}
4578
4526
@@ -4914,6 +4862,28 @@ Expr* SemanticsVisitor::checkGeneralMemberLookupExpr(MemberExpr* expr, Type* bas
4914
4862
if (expr->name == getSession ()->getCompletionRequestTokenName ())
4915
4863
{
4916
4864
suggestCompletionItems (CompletionSuggestions::ScopeKind::Member, lookupResult);
4865
+ if (expr->baseExpression )
4866
+ {
4867
+ if (auto vectorType = as<VectorExpressionType>(expr->baseExpression ->type ))
4868
+ {
4869
+ auto & suggestions = getLinkage ()->contentAssistInfo .completionSuggestions ;
4870
+ suggestions.scopeKind = CompletionSuggestions::ScopeKind::Swizzle;
4871
+ suggestions.elementCount [1 ] = 0 ;
4872
+ suggestions.swizzleBaseType = vectorType;
4873
+ if (auto elementCount = as<ConstantIntVal>(vectorType->getElementCount ()))
4874
+ suggestions.elementCount [0 ] = elementCount->getValue ();
4875
+ else
4876
+ suggestions.elementCount [0 ] = 1 ;
4877
+ }
4878
+ else if (auto scalarType = as<BasicExpressionType>(expr->baseExpression ->type ))
4879
+ {
4880
+ auto & suggestions = getLinkage ()->contentAssistInfo .completionSuggestions ;
4881
+ suggestions.scopeKind = CompletionSuggestions::ScopeKind::Swizzle;
4882
+ suggestions.elementCount [1 ] = 0 ;
4883
+ suggestions.elementCount [0 ] = 1 ;
4884
+ suggestions.swizzleBaseType = scalarType;
4885
+ }
4886
+ }
4917
4887
}
4918
4888
return createLookupResultExpr (expr->name , lookupResult, expr->baseExpression , expr->loc , expr);
4919
4889
}
@@ -4942,34 +4912,36 @@ Expr* SemanticsExprVisitor::visitMemberExpr(MemberExpr* expr)
4942
4912
if (auto modifiedType = as<ModifiedType>(baseType))
4943
4913
baseType = modifiedType->getBase ();
4944
4914
4945
- // Note: Checking for vector types before declaration-reference types,
4946
- // because vectors are also declaration reference types...
4915
+ // Try handle swizzle-able types (scalar,vector,matrix) first.
4916
+ // If checking as a swizzle failed for these types,
4917
+ // we will fallback to normal member lookup.
4947
4918
//
4948
- // Also note: the way this is done right now means that the ability
4949
- // to swizzle vectors interferes with any chance of looking up
4950
- // members via extension, for vector or scalar types.
4951
- //
4952
- if (auto baseMatrixType = as<MatrixExpressionType>(baseType))
4919
+ if (auto baseScalarType = as<BasicExpressionType>(baseType))
4953
4920
{
4954
- return CheckMatrixSwizzleExpr (
4955
- expr,
4956
- baseMatrixType->getElementType (),
4957
- baseMatrixType->getRowCount (),
4958
- baseMatrixType->getColumnCount ());
4921
+ // Treat scalar like a 1-element vector when swizzling
4922
+ auto swizzle = CheckSwizzleExpr (expr, baseScalarType, 1 );
4923
+ if (swizzle)
4924
+ return swizzle;
4959
4925
}
4960
- if (auto baseVecType = as<VectorExpressionType>(baseType))
4926
+ else if (auto baseVecType = as<VectorExpressionType>(baseType))
4961
4927
{
4962
- return CheckSwizzleExpr (
4963
- expr,
4964
- baseVecType-> getElementType (),
4965
- baseVecType-> getElementCount ()) ;
4928
+ auto swizzle =
4929
+ CheckSwizzleExpr ( expr, baseVecType-> getElementType (), baseVecType-> getElementCount ());
4930
+ if (swizzle)
4931
+ return swizzle ;
4966
4932
}
4967
- else if (auto baseScalarType = as<BasicExpressionType >(baseType))
4933
+ else if (auto baseMatrixType = as<MatrixExpressionType >(baseType))
4968
4934
{
4969
- // Treat scalar like a 1-element vector when swizzling
4970
- return CheckSwizzleExpr (expr, baseScalarType, 1 );
4935
+ auto swizzle = CheckMatrixSwizzleExpr (
4936
+ expr,
4937
+ baseMatrixType->getElementType (),
4938
+ baseMatrixType->getRowCount (),
4939
+ baseMatrixType->getColumnCount ());
4940
+ if (swizzle)
4941
+ return swizzle;
4971
4942
}
4972
- else if (as<NamespaceType>(baseType))
4943
+
4944
+ if (as<NamespaceType>(baseType))
4973
4945
{
4974
4946
return _lookupStaticMember (expr, expr->baseExpression );
4975
4947
}
0 commit comments