diff options
author | Anastasia Stulova <anastasia.stulova@arm.com> | 2019-01-09 11:25:09 +0000 |
---|---|---|
committer | Anastasia Stulova <anastasia.stulova@arm.com> | 2019-01-09 11:25:09 +0000 |
commit | a9bc4bd814ca3d4b1b7928522d9f9b6be188c75c (patch) | |
tree | cb10bf1c6d1e98592d27f515776f8da2e6fd331c /clang/lib/Sema/DeclSpec.cpp | |
parent | 1eb31c8e944c717a11f408c8ee932a378b10cbdc (diff) | |
download | bcm5719-llvm-a9bc4bd814ca3d4b1b7928522d9f9b6be188c75c.tar.gz bcm5719-llvm-a9bc4bd814ca3d4b1b7928522d9f9b6be188c75c.zip |
Use DeclSpec for quals in DeclaratorChunk::FunctionTypeInfo.
Rather than duplicating data fields, use DeclSpec directly to store
the qualifiers for the functions/methods. This change doesn't handle
attributes yet and has to be extended further.
Differential revision: https://reviews.llvm.org/D55948
llvm-svn: 350703
Diffstat (limited to 'clang/lib/Sema/DeclSpec.cpp')
-rw-r--r-- | clang/lib/Sema/DeclSpec.cpp | 53 |
1 files changed, 40 insertions, 13 deletions
diff --git a/clang/lib/Sema/DeclSpec.cpp b/clang/lib/Sema/DeclSpec.cpp index 2efa0a7fd1d..8b002dac134 100644 --- a/clang/lib/Sema/DeclSpec.cpp +++ b/clang/lib/Sema/DeclSpec.cpp @@ -156,14 +156,8 @@ DeclaratorChunk DeclaratorChunk::getFunction(bool hasProto, unsigned NumParams, SourceLocation EllipsisLoc, SourceLocation RParenLoc, - unsigned TypeQuals, bool RefQualifierIsLvalueRef, SourceLocation RefQualifierLoc, - SourceLocation ConstQualifierLoc, - SourceLocation - VolatileQualifierLoc, - SourceLocation - RestrictQualifierLoc, SourceLocation MutableLoc, ExceptionSpecificationType ESpecType, @@ -178,8 +172,9 @@ DeclaratorChunk DeclaratorChunk::getFunction(bool hasProto, SourceLocation LocalRangeBegin, SourceLocation LocalRangeEnd, Declarator &TheDeclarator, - TypeResult TrailingReturnType) { - assert(!(TypeQuals & DeclSpec::TQ_atomic) && + TypeResult TrailingReturnType, + DeclSpec *MethodQualifiers) { + assert(!(MethodQualifiers && MethodQualifiers->getTypeQualifiers() & DeclSpec::TQ_atomic) && "function cannot have _Atomic qualifier"); DeclaratorChunk I; @@ -193,14 +188,10 @@ DeclaratorChunk DeclaratorChunk::getFunction(bool hasProto, I.Fun.EllipsisLoc = EllipsisLoc.getRawEncoding(); I.Fun.RParenLoc = RParenLoc.getRawEncoding(); I.Fun.DeleteParams = false; - I.Fun.TypeQuals = TypeQuals; I.Fun.NumParams = NumParams; I.Fun.Params = nullptr; I.Fun.RefQualifierIsLValueRef = RefQualifierIsLvalueRef; I.Fun.RefQualifierLoc = RefQualifierLoc.getRawEncoding(); - I.Fun.ConstQualifierLoc = ConstQualifierLoc.getRawEncoding(); - I.Fun.VolatileQualifierLoc = VolatileQualifierLoc.getRawEncoding(); - I.Fun.RestrictQualifierLoc = RestrictQualifierLoc.getRawEncoding(); I.Fun.MutableLoc = MutableLoc.getRawEncoding(); I.Fun.ExceptionSpecType = ESpecType; I.Fun.ExceptionSpecLocBeg = ESpecRange.getBegin().getRawEncoding(); @@ -211,8 +202,21 @@ DeclaratorChunk DeclaratorChunk::getFunction(bool hasProto, I.Fun.HasTrailingReturnType = TrailingReturnType.isUsable() || TrailingReturnType.isInvalid(); I.Fun.TrailingReturnType = TrailingReturnType.get(); + I.Fun.MethodQualifiers = nullptr; + I.Fun.QualAttrFactory = nullptr; + + if (MethodQualifiers && (MethodQualifiers->getTypeQualifiers() || + MethodQualifiers->getAttributes().size())) { + auto &attrs = MethodQualifiers->getAttributes(); + I.Fun.MethodQualifiers = new DeclSpec(attrs.getPool().getFactory()); + MethodQualifiers->forEachCVRUQualifier( + [&](DeclSpec::TQ TypeQual, StringRef PrintName, SourceLocation SL) { + I.Fun.MethodQualifiers->SetTypeQual(TypeQual, SL); + }); + I.Fun.MethodQualifiers->getAttributes().takeAllFrom(attrs); + I.Fun.MethodQualifiers->getAttributePool().takeAllFrom(attrs.getPool()); + } - assert(I.Fun.TypeQuals == TypeQuals && "bitfield overflow"); assert(I.Fun.ExceptionSpecType == ESpecType && "bitfield overflow"); // new[] a parameter array if needed. @@ -403,6 +407,24 @@ bool Declarator::isCtorOrDtor() { (getName().getKind() == UnqualifiedIdKind::IK_DestructorName); } +void DeclSpec::forEachCVRUQualifier( + llvm::function_ref<void(TQ, StringRef, SourceLocation)> Handle) { + if (TypeQualifiers & TQ_const) + Handle(TQ_const, "const", TQ_constLoc); + if (TypeQualifiers & TQ_volatile) + Handle(TQ_volatile, "volatile", TQ_volatileLoc); + if (TypeQualifiers & TQ_restrict) + Handle(TQ_restrict, "restrict", TQ_restrictLoc); + if (TypeQualifiers & TQ_unaligned) + Handle(TQ_unaligned, "unaligned", TQ_unalignedLoc); +} + +void DeclSpec::forEachQualifier( + llvm::function_ref<void(TQ, StringRef, SourceLocation)> Handle) { + forEachCVRUQualifier(Handle); + // FIXME: Add code below to iterate through the attributes and call Handle. +} + bool DeclSpec::hasTagDefinition() const { if (!TypeSpecOwned) return false; @@ -862,6 +884,11 @@ bool DeclSpec::SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec, IsExtension = false; return BadSpecifier(T, T, PrevSpec, DiagID, IsExtension); } + + return SetTypeQual(T, Loc); +} + +bool DeclSpec::SetTypeQual(TQ T, SourceLocation Loc) { TypeQualifiers |= T; switch (T) { |