diff options
author | Nicolas Lesser <blitzrakete@gmail.com> | 2019-05-04 00:09:00 +0000 |
---|---|---|
committer | Nicolas Lesser <blitzrakete@gmail.com> | 2019-05-04 00:09:00 +0000 |
commit | 6de0b449c07ec7adbcb34e7c94c544ee37ef5963 (patch) | |
tree | 0e2112dbbe57b79622f5a7708add8fecc6a75b80 /lib/Serialization/ASTWriterDecl.cpp | |
parent | 6cc60c9164a96f1d73ccfd302303490e0d085b87 (diff) | |
download | clang-6de0b449c07ec7adbcb34e7c94c544ee37ef5963.tar.gz |
[clang] adding explicit(bool) from c++2a
this patch adds support for the explicit bool specifier.
Changes:
- The parsing for the explicit(bool) specifier was added in ParseDecl.cpp.
- The storage of the explicit specifier was changed. the explicit specifier was stored as a boolean value in the FunctionDeclBitfields and in the DeclSpec class. now it is stored as a PointerIntPair<Expr*, 2> with a flag and a potential expression in CXXConstructorDecl, CXXDeductionGuideDecl, CXXConversionDecl and in the DeclSpec class.
- Following the AST change, Serialization, ASTMatchers, ASTComparator and ASTPrinter were adapted.
- Template instantiation was adapted to instantiate the potential expressions of the explicit(bool) specifier When instantiating their associated declaration.
- The Add*Candidate functions were adapted, they now take a Boolean indicating if the context allowing explicit constructor or conversion function and this boolean is used to remove invalid overloads that required template instantiation to be detected.
- Test for Semantic and Serialization were added.
This patch is not yet complete. I still need to check that interaction with CTAD and deduction guides is correct. and add more tests for AST operations. But I wanted first feedback.
Perhaps this patch should be spited in smaller patches, but making each patch testable as a standalone may be tricky.
Patch by Tyker
Differential Revision: https://reviews.llvm.org/D60934
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@359949 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Serialization/ASTWriterDecl.cpp')
-rw-r--r-- | lib/Serialization/ASTWriterDecl.cpp | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/lib/Serialization/ASTWriterDecl.cpp b/lib/Serialization/ASTWriterDecl.cpp index 159a76d5ef..5c0f2dff56 100644 --- a/lib/Serialization/ASTWriterDecl.cpp +++ b/lib/Serialization/ASTWriterDecl.cpp @@ -535,7 +535,6 @@ void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) { Record.push_back(static_cast<int>(D->getStorageClass())); // FIXME: stable encoding Record.push_back(D->isInlineSpecified()); Record.push_back(D->isInlined()); - Record.push_back(D->isExplicitSpecified()); Record.push_back(D->isVirtualAsWritten()); Record.push_back(D->isPure()); Record.push_back(D->hasInheritedPrototype()); @@ -638,7 +637,18 @@ void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) { Code = serialization::DECL_FUNCTION; } +static void addExplicitSpecifier(ExplicitSpecifier ES, + ASTRecordWriter &Record) { + uint64_t Kind = static_cast<uint64_t>(ES.getKind()); + Kind = Kind << 1 | static_cast<bool>(ES.getExpr()); + Record.push_back(Kind); + if (ES.getExpr()) { + Record.AddStmt(ES.getExpr()); + } +} + void ASTDeclWriter::VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D) { + addExplicitSpecifier(D->getExplicitSpecifier(), Record); VisitFunctionDecl(D); Record.push_back(D->isCopyDeductionCandidate()); Code = serialization::DECL_CXX_DEDUCTION_GUIDE; @@ -1331,19 +1341,15 @@ void ASTDeclWriter::VisitCXXMethodDecl(CXXMethodDecl *D) { } void ASTDeclWriter::VisitCXXConstructorDecl(CXXConstructorDecl *D) { + Record.push_back(D->getTraillingAllocKind()); + addExplicitSpecifier(D->getExplicitSpecifier(), Record); if (auto Inherited = D->getInheritedConstructor()) { Record.AddDeclRef(Inherited.getShadowDecl()); Record.AddDeclRef(Inherited.getConstructor()); - Code = serialization::DECL_CXX_INHERITED_CONSTRUCTOR; - } else { - Code = serialization::DECL_CXX_CONSTRUCTOR; } VisitCXXMethodDecl(D); - - Code = D->isInheritingConstructor() - ? serialization::DECL_CXX_INHERITED_CONSTRUCTOR - : serialization::DECL_CXX_CONSTRUCTOR; + Code = serialization::DECL_CXX_CONSTRUCTOR; } void ASTDeclWriter::VisitCXXDestructorDecl(CXXDestructorDecl *D) { @@ -1357,6 +1363,7 @@ void ASTDeclWriter::VisitCXXDestructorDecl(CXXDestructorDecl *D) { } void ASTDeclWriter::VisitCXXConversionDecl(CXXConversionDecl *D) { + addExplicitSpecifier(D->getExplicitSpecifier(), Record); VisitCXXMethodDecl(D); Code = serialization::DECL_CXX_CONVERSION; } @@ -2156,7 +2163,6 @@ void ASTWriter::WriteDeclAbbrevs() { Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // StorageClass Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Inline Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InlineSpecified - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ExplicitSpecified Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // VirtualAsWritten Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Pure Abv->Add(BitCodeAbbrevOp(0)); // HasInheritedProto |