@@ -8843,63 +8843,14 @@ namespace Slang
8843
8843
}
8844
8844
}
8845
8845
8846
- RefPtr<Expr> visitStaticMemberExpr(StaticMemberExpr* /*expr*/)
8846
+ // Look up a static member
8847
+ // @param expr Can be StaticMemberExpr or MemberExpr
8848
+ // @param baseExpression Is the underlying type expression determined from resolving expr
8849
+ RefPtr<Expr> _lookupStaticMember(RefPtr<DeclRefExpr> expr, RefPtr<Expr> baseExpression)
8847
8850
{
8848
- // StaticMemberExpr means it is already checked
8849
- SLANG_UNEXPECTED("should not occur in unchecked AST");
8850
- UNREACHABLE_RETURN(nullptr);
8851
- }
8852
-
8853
- RefPtr<Expr> lookupResultFailure(
8854
- MemberExpr* expr,
8855
- QualType const& baseType)
8856
- {
8857
- getSink()->diagnose(expr, Diagnostics::noMemberOfNameInType, expr->name, baseType);
8858
- expr->type = QualType(getSession()->getErrorType());
8859
- return expr;
8860
-
8861
- }
8862
-
8863
- RefPtr<Expr> visitMemberExpr(MemberExpr * expr)
8864
- {
8865
- expr->BaseExpression = CheckExpr(expr->BaseExpression);
8866
-
8867
- expr->BaseExpression = MaybeDereference(expr->BaseExpression);
8851
+ auto& baseType = baseExpression->type;
8868
8852
8869
- // If the base of the member lookup has an interface type
8870
- // *without* a suitable this-type substitution, then we are
8871
- // trying to perform lookup on a value of existential type,
8872
- // and we should "open" the existential here so that we
8873
- // can expose its structure.
8874
- //
8875
- expr->BaseExpression = maybeOpenExistential(expr->BaseExpression);
8876
-
8877
- auto & baseType = expr->BaseExpression->type;
8878
-
8879
- // Note: Checking for vector types before declaration-reference types,
8880
- // because vectors are also declaration reference types...
8881
- //
8882
- // Also note: the way this is done right now means that the ability
8883
- // to swizzle vectors interferes with any chance of looking up
8884
- // members via extension, for vector or scalar types.
8885
- //
8886
- // TODO: Matrix swizzles probably need to be handled at some point.
8887
- if (auto baseVecType = as<VectorExpressionType>(baseType))
8888
- {
8889
- return CheckSwizzleExpr(
8890
- expr,
8891
- baseVecType->elementType,
8892
- baseVecType->elementCount);
8893
- }
8894
- else if(auto baseScalarType = as<BasicExpressionType>(baseType))
8895
- {
8896
- // Treat scalar like a 1-element vector when swizzling
8897
- return CheckSwizzleExpr(
8898
- expr,
8899
- baseScalarType,
8900
- 1);
8901
- }
8902
- else if(auto typeType = as<TypeType>(baseType))
8853
+ if (auto typeType = as<TypeType>(baseType))
8903
8854
{
8904
8855
// We are looking up a member inside a type.
8905
8856
// We want to be careful here because we should only find members
@@ -8921,7 +8872,7 @@ namespace Slang
8921
8872
type);
8922
8873
if (!lookupResult.isValid())
8923
8874
{
8924
- return lookupResultFailure (expr, baseType);
8875
+ return lookupMemberResultFailure (expr, baseType);
8925
8876
}
8926
8877
8927
8878
// We need to confirm that whatever member we
@@ -8947,13 +8898,13 @@ namespace Slang
8947
8898
// For now let's just be expedient and disallow all of that, because
8948
8899
// we can always add it back in later.
8949
8900
8950
- if(!lookupResult.isOverloaded())
8901
+ if (!lookupResult.isOverloaded())
8951
8902
{
8952
8903
// The non-overloaded case is relatively easy. We just want
8953
8904
// to look at the member being referenced, and check if
8954
8905
// it is allowed in a `static` context:
8955
8906
//
8956
- if(!isUsableAsStaticMember(lookupResult.item))
8907
+ if (!isUsableAsStaticMember(lookupResult.item))
8957
8908
{
8958
8909
getSink()->diagnose(
8959
8910
expr->loc,
@@ -8972,10 +8923,10 @@ namespace Slang
8972
8923
// are non-static.
8973
8924
bool anyNonStatic = false;
8974
8925
List<LookupResultItem> staticItems;
8975
- for(auto item : lookupResult.items)
8926
+ for (auto item : lookupResult.items)
8976
8927
{
8977
8928
// Is this item usable as a static member?
8978
- if(isUsableAsStaticMember(item))
8929
+ if (isUsableAsStaticMember(item))
8979
8930
{
8980
8931
// If yes, then it will be part of the output.
8981
8932
staticItems.Add(item);
@@ -8988,11 +8939,11 @@ namespace Slang
8988
8939
}
8989
8940
8990
8941
// Was there anything non-static in the list?
8991
- if(anyNonStatic)
8942
+ if (anyNonStatic)
8992
8943
{
8993
8944
// If we had some static items, then that's okay,
8994
8945
// we just want to use our newly-filtered list.
8995
- if(staticItems.Count())
8946
+ if (staticItems.Count())
8996
8947
{
8997
8948
lookupResult.items = staticItems;
8998
8949
}
@@ -9012,13 +8963,96 @@ namespace Slang
9012
8963
9013
8964
return createLookupResultExpr(
9014
8965
lookupResult,
9015
- expr->BaseExpression ,
8966
+ baseExpression ,
9016
8967
expr->loc);
9017
8968
}
9018
8969
else if (as<ErrorType>(baseType))
9019
8970
{
9020
8971
return CreateErrorExpr(expr);
9021
8972
}
8973
+
8974
+ // Failure
8975
+ return lookupMemberResultFailure(expr, baseType);
8976
+ }
8977
+
8978
+ RefPtr<Expr> visitStaticMemberExpr(StaticMemberExpr* expr)
8979
+ {
8980
+ expr->BaseExpression = CheckExpr(expr->BaseExpression);
8981
+
8982
+ // Not sure this is needed -> but guess someone could do
8983
+ expr->BaseExpression = MaybeDereference(expr->BaseExpression);
8984
+
8985
+ // If the base of the member lookup has an interface type
8986
+ // *without* a suitable this-type substitution, then we are
8987
+ // trying to perform lookup on a value of existential type,
8988
+ // and we should "open" the existential here so that we
8989
+ // can expose its structure.
8990
+ //
8991
+
8992
+ expr->BaseExpression = maybeOpenExistential(expr->BaseExpression);
8993
+ // Do a static lookup
8994
+ return _lookupStaticMember(expr, expr->BaseExpression);
8995
+ }
8996
+
8997
+ RefPtr<Expr> lookupMemberResultFailure(
8998
+ DeclRefExpr* expr,
8999
+ QualType const& baseType)
9000
+ {
9001
+ // Check it's a member expression
9002
+ SLANG_ASSERT(as<StaticMemberExpr>(expr) || as<MemberExpr>(expr));
9003
+
9004
+ getSink()->diagnose(expr, Diagnostics::noMemberOfNameInType, expr->name, baseType);
9005
+ expr->type = QualType(getSession()->getErrorType());
9006
+ return expr;
9007
+ }
9008
+
9009
+ RefPtr<Expr> visitMemberExpr(MemberExpr * expr)
9010
+ {
9011
+ expr->BaseExpression = CheckExpr(expr->BaseExpression);
9012
+
9013
+ expr->BaseExpression = MaybeDereference(expr->BaseExpression);
9014
+
9015
+ // If the base of the member lookup has an interface type
9016
+ // *without* a suitable this-type substitution, then we are
9017
+ // trying to perform lookup on a value of existential type,
9018
+ // and we should "open" the existential here so that we
9019
+ // can expose its structure.
9020
+ //
9021
+ expr->BaseExpression = maybeOpenExistential(expr->BaseExpression);
9022
+
9023
+ auto & baseType = expr->BaseExpression->type;
9024
+
9025
+ // Note: Checking for vector types before declaration-reference types,
9026
+ // because vectors are also declaration reference types...
9027
+ //
9028
+ // Also note: the way this is done right now means that the ability
9029
+ // to swizzle vectors interferes with any chance of looking up
9030
+ // members via extension, for vector or scalar types.
9031
+ //
9032
+ // TODO: Matrix swizzles probably need to be handled at some point.
9033
+ if (auto baseVecType = as<VectorExpressionType>(baseType))
9034
+ {
9035
+ return CheckSwizzleExpr(
9036
+ expr,
9037
+ baseVecType->elementType,
9038
+ baseVecType->elementCount);
9039
+ }
9040
+ else if(auto baseScalarType = as<BasicExpressionType>(baseType))
9041
+ {
9042
+ // Treat scalar like a 1-element vector when swizzling
9043
+ return CheckSwizzleExpr(
9044
+ expr,
9045
+ baseScalarType,
9046
+ 1);
9047
+ }
9048
+ else if(auto typeType = as<TypeType>(baseType))
9049
+ {
9050
+ return _lookupStaticMember(expr, expr->BaseExpression);
9051
+ }
9052
+ else if (as<ErrorType>(baseType))
9053
+ {
9054
+ return CreateErrorExpr(expr);
9055
+ }
9022
9056
else
9023
9057
{
9024
9058
LookupResult lookupResult = lookUpMember(
@@ -9028,7 +9062,7 @@ namespace Slang
9028
9062
baseType.Ptr());
9029
9063
if (!lookupResult.isValid())
9030
9064
{
9031
- return lookupResultFailure (expr, baseType);
9065
+ return lookupMemberResultFailure (expr, baseType);
9032
9066
}
9033
9067
9034
9068
// TODO: need to filter for declarations that are valid to refer
0 commit comments