From a3f622ace1bdef1f1a4150ec85d1328d1a589333 Mon Sep 17 00:00:00 2001 From: Ellie Hermaszewska Date: Mon, 17 Apr 2023 22:22:13 +0800 Subject: WIP: "deprecated" attribute (#2698) * Implement deprecated attribute * Prevent duplicate deprecated diagnostic on non-overloaded functions * Use FileCheck for deprecation test * formatting --- source/slang/slang-check-expr.cpp | 41 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'source/slang/slang-check-expr.cpp') 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 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(originalExpr); + auto originalAppFunDecl = originalAppExpr ? as(originalAppExpr->functionExpr) : nullptr; + if(originalAppFunDecl && originalAppFunDecl->declRef) + { + return; + } + if (auto deprecatedAttr = declRef.getDecl()->findModifier()) + { + getSink()->diagnose( + loc, + Diagnostics::deprecatedUsage, + declRef.getName(), + deprecatedAttr->message); + } + } + + DeclRefExpr* SemanticsVisitor::ConstructDeclRefExpr( DeclRef 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. // -- cgit v1.2.3