diff options
| author | Ellie Hermaszewska <ellieh@nvidia.com> | 2023-04-17 22:22:13 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-17 22:22:13 +0800 |
| commit | a3f622ace1bdef1f1a4150ec85d1328d1a589333 (patch) | |
| tree | c1c620d0e69d39870fdbc76f5e584bae8594f0ba /source/slang/slang-check-expr.cpp | |
| parent | f6ff73fe3156215e75708d155fd240788134b1f2 (diff) | |
WIP: "deprecated" attribute (#2698)
* Implement deprecated attribute
* Prevent duplicate deprecated diagnostic on non-overloaded functions
* Use FileCheck for deprecation test
* formatting
Diffstat (limited to 'source/slang/slang-check-expr.cpp')
| -rw-r--r-- | source/slang/slang-check-expr.cpp | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/source/slang/slang-check-expr.cpp b/source/slang/slang-check-expr.cpp index 507b8c30f..119077eca 100644 --- a/source/slang/slang-check-expr.cpp +++ b/source/slang/slang-check-expr.cpp @@ -254,7 +254,42 @@ namespace Slang return SourceLoc(); } - Expr* SemanticsVisitor::ConstructDeclRefExpr( + void SemanticsVisitor::diagnoseDeprecatedDeclRefUsage( + DeclRef<Decl> declRef, + SourceLoc loc, + Expr* originalExpr) + { + // This is slightly subtle, because we don't want to warn more than + // once for the same occurrence, however in some cases this function is + // called more than once for the same declref (specifically in the case + // of a non-overloaded function, once when the function is identified at + // first, and again when it's checked from + // CheckInvokeExprWithCheckedOperands). + // + // The correct fix is probably to make + // CheckInvokeExprWithCheckedOperands reuse the original declref, + // however that doesn't appear to be a simple change. + // + // What we do instead is see if there's already been a declRef + // constructed for this expression and rest assured that it's already + // had a diagnostic emitted. + auto originalAppExpr = as<AppExprBase>(originalExpr); + auto originalAppFunDecl = originalAppExpr ? as<DeclRefExpr>(originalAppExpr->functionExpr) : nullptr; + if(originalAppFunDecl && originalAppFunDecl->declRef) + { + return; + } + if (auto deprecatedAttr = declRef.getDecl()->findModifier<DeprecatedAttribute>()) + { + getSink()->diagnose( + loc, + Diagnostics::deprecatedUsage, + declRef.getName(), + deprecatedAttr->message); + } + } + + DeclRefExpr* SemanticsVisitor::ConstructDeclRefExpr( DeclRef<Decl> declRef, Expr* baseExpr, SourceLoc loc, @@ -264,6 +299,10 @@ namespace Slang // auto type = GetTypeForDeclRef(declRef, loc); + // This is the bottleneck for using declarations which might be + // deprecated, diagnose here. + diagnoseDeprecatedDeclRefUsage(declRef, loc, originalExpr); + // Construct an appropriate expression based on the structured of // the declaration reference. // |
