sammccall created this revision. sammccall added a reviewer: aaron.ballman. sammccall requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
We will use this function to filter code completion of attributes. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D107836 Files: clang/include/clang/Sema/ParsedAttr.h clang/lib/Sema/ParsedAttr.cpp clang/utils/TableGen/ClangAttrEmitter.cpp Index: clang/utils/TableGen/ClangAttrEmitter.cpp =================================================================== --- clang/utils/TableGen/ClangAttrEmitter.cpp +++ clang/utils/TableGen/ClangAttrEmitter.cpp @@ -3803,14 +3803,8 @@ if (LangOpts.empty()) return; - OS << "bool diagLangOpts(Sema &S, const ParsedAttr &Attr) "; - OS << "const override {\n"; - OS << " auto &LangOpts = S.LangOpts;\n"; - OS << " if (" << GenerateTestExpression(LangOpts) << ")\n"; - OS << " return true;\n\n"; - OS << " S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) "; - OS << "<< Attr;\n"; - OS << " return false;\n"; + OS << "bool acceptsLangOpts(const LangOptions &LangOpts) const override {\n"; + OS << " return " << GenerateTestExpression(LangOpts) << ";\n"; OS << "}\n\n"; } Index: clang/lib/Sema/ParsedAttr.cpp =================================================================== --- clang/lib/Sema/ParsedAttr.cpp +++ clang/lib/Sema/ParsedAttr.cpp @@ -180,7 +180,10 @@ } bool ParsedAttr::diagnoseLangOpts(Sema &S) const { - return getInfo().diagLangOpts(S, *this); + if (getInfo().acceptsLangOpts(S.getLangOpts())) + return true; + S.Diag(getLoc(), diag::warn_attribute_ignored) << *this; + return false; } bool ParsedAttr::isTargetSpecificAttr() const { Index: clang/include/clang/Sema/ParsedAttr.h =================================================================== --- clang/include/clang/Sema/ParsedAttr.h +++ clang/include/clang/Sema/ParsedAttr.h @@ -92,11 +92,9 @@ const Decl *D) const { return true; } - /// Check if this attribute is allowed by the language we are compiling, and - /// issue a diagnostic if not. - virtual bool diagLangOpts(Sema &S, const ParsedAttr &Attr) const { - return true; - } + /// Check if this attribute is allowed by the language we are compiling. + virtual bool acceptsLangOpts(const LangOptions &LO) const { return true; } + /// Check if this attribute is allowed when compiling for the given target. virtual bool existsInTarget(const TargetInfo &Target) const { return true;
Index: clang/utils/TableGen/ClangAttrEmitter.cpp =================================================================== --- clang/utils/TableGen/ClangAttrEmitter.cpp +++ clang/utils/TableGen/ClangAttrEmitter.cpp @@ -3803,14 +3803,8 @@ if (LangOpts.empty()) return; - OS << "bool diagLangOpts(Sema &S, const ParsedAttr &Attr) "; - OS << "const override {\n"; - OS << " auto &LangOpts = S.LangOpts;\n"; - OS << " if (" << GenerateTestExpression(LangOpts) << ")\n"; - OS << " return true;\n\n"; - OS << " S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) "; - OS << "<< Attr;\n"; - OS << " return false;\n"; + OS << "bool acceptsLangOpts(const LangOptions &LangOpts) const override {\n"; + OS << " return " << GenerateTestExpression(LangOpts) << ";\n"; OS << "}\n\n"; } Index: clang/lib/Sema/ParsedAttr.cpp =================================================================== --- clang/lib/Sema/ParsedAttr.cpp +++ clang/lib/Sema/ParsedAttr.cpp @@ -180,7 +180,10 @@ } bool ParsedAttr::diagnoseLangOpts(Sema &S) const { - return getInfo().diagLangOpts(S, *this); + if (getInfo().acceptsLangOpts(S.getLangOpts())) + return true; + S.Diag(getLoc(), diag::warn_attribute_ignored) << *this; + return false; } bool ParsedAttr::isTargetSpecificAttr() const { Index: clang/include/clang/Sema/ParsedAttr.h =================================================================== --- clang/include/clang/Sema/ParsedAttr.h +++ clang/include/clang/Sema/ParsedAttr.h @@ -92,11 +92,9 @@ const Decl *D) const { return true; } - /// Check if this attribute is allowed by the language we are compiling, and - /// issue a diagnostic if not. - virtual bool diagLangOpts(Sema &S, const ParsedAttr &Attr) const { - return true; - } + /// Check if this attribute is allowed by the language we are compiling. + virtual bool acceptsLangOpts(const LangOptions &LO) const { return true; } + /// Check if this attribute is allowed when compiling for the given target. virtual bool existsInTarget(const TargetInfo &Target) const { return true;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits