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
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 7538b63..298a2ba 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -6072,9 +6072,6 @@
DeclSpec DS(AttrFactory);
bool RefQualifierIsLValueRef = true;
SourceLocation RefQualifierLoc;
- SourceLocation ConstQualifierLoc;
- SourceLocation VolatileQualifierLoc;
- SourceLocation RestrictQualifierLoc;
ExceptionSpecificationType ESpecType = EST_None;
SourceRange ESpecRange;
SmallVector<ParsedType, 2> DynamicExceptions;
@@ -6137,9 +6134,6 @@
}));
if (!DS.getSourceRange().getEnd().isInvalid()) {
EndLoc = DS.getSourceRange().getEnd();
- ConstQualifierLoc = DS.getConstSpecLoc();
- VolatileQualifierLoc = DS.getVolatileSpecLoc();
- RestrictQualifierLoc = DS.getRestrictSpecLoc();
}
// Parse ref-qualifier[opt].
@@ -6239,15 +6233,13 @@
D.AddTypeInfo(DeclaratorChunk::getFunction(
HasProto, IsAmbiguous, LParenLoc, ParamInfo.data(),
ParamInfo.size(), EllipsisLoc, RParenLoc,
- DS.getTypeQualifiers(), RefQualifierIsLValueRef,
- RefQualifierLoc, ConstQualifierLoc, VolatileQualifierLoc,
- RestrictQualifierLoc,
- /*MutableLoc=*/SourceLocation(), ESpecType, ESpecRange,
- DynamicExceptions.data(), DynamicExceptionRanges.data(),
- DynamicExceptions.size(),
+ RefQualifierIsLValueRef, RefQualifierLoc,
+ /*MutableLoc=*/SourceLocation(),
+ ESpecType, ESpecRange, DynamicExceptions.data(),
+ DynamicExceptionRanges.data(), DynamicExceptions.size(),
NoexceptExpr.isUsable() ? NoexceptExpr.get() : nullptr,
ExceptionSpecTokens, DeclsInPrototype, StartLoc,
- LocalEndLoc, D, TrailingReturnType),
+ LocalEndLoc, D, TrailingReturnType, &DS),
std::move(FnAttrs), EndLoc);
}
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index 02c7397..f8359f1 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -2346,32 +2346,22 @@
if (D.isFunctionDeclarator()) {
auto &Function = D.getFunctionTypeInfo();
if (DS.getTypeQualifiers() != DeclSpec::TQ_unspecified) {
- auto DeclSpecCheck = [&] (DeclSpec::TQ TypeQual,
- const char *FixItName,
- SourceLocation SpecLoc,
- unsigned* QualifierLoc) {
+ auto DeclSpecCheck = [&](DeclSpec::TQ TypeQual, StringRef FixItName,
+ SourceLocation SpecLoc) {
FixItHint Insertion;
- if (DS.getTypeQualifiers() & TypeQual) {
- if (!(Function.TypeQuals & TypeQual)) {
- std::string Name(FixItName);
- Name += " ";
- Insertion = FixItHint::CreateInsertion(VS.getFirstLocation(), Name);
- Function.TypeQuals |= TypeQual;
- *QualifierLoc = SpecLoc.getRawEncoding();
- }
- Diag(SpecLoc, diag::err_declspec_after_virtspec)
+ auto &MQ = Function.getOrCreateMethodQualifiers();
+ if (!(MQ.getTypeQualifiers() & TypeQual)) {
+ std::string Name(FixItName.data());
+ Name += " ";
+ Insertion = FixItHint::CreateInsertion(VS.getFirstLocation(), Name);
+ MQ.SetTypeQual(TypeQual, SpecLoc);
+ }
+ Diag(SpecLoc, diag::err_declspec_after_virtspec)
<< FixItName
<< VirtSpecifiers::getSpecifierName(VS.getLastSpecifier())
- << FixItHint::CreateRemoval(SpecLoc)
- << Insertion;
- }
+ << FixItHint::CreateRemoval(SpecLoc) << Insertion;
};
- DeclSpecCheck(DeclSpec::TQ_const, "const", DS.getConstSpecLoc(),
- &Function.ConstQualifierLoc);
- DeclSpecCheck(DeclSpec::TQ_volatile, "volatile", DS.getVolatileSpecLoc(),
- &Function.VolatileQualifierLoc);
- DeclSpecCheck(DeclSpec::TQ_restrict, "restrict", DS.getRestrictSpecLoc(),
- &Function.RestrictQualifierLoc);
+ DS.forEachQualifier(DeclSpecCheck);
}
// Parse ref-qualifiers.
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 194b07d..4bcbebc 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -3012,12 +3012,8 @@
/*NumArgs=*/0,
/*EllipsisLoc=*/NoLoc,
/*RParenLoc=*/NoLoc,
- /*TypeQuals=*/0,
/*RefQualifierIsLvalueRef=*/true,
/*RefQualifierLoc=*/NoLoc,
- /*ConstQualifierLoc=*/NoLoc,
- /*VolatileQualifierLoc=*/NoLoc,
- /*RestrictQualifierLoc=*/NoLoc,
/*MutableLoc=*/NoLoc, EST_None,
/*ESpecRange=*/SourceRange(),
/*Exceptions=*/nullptr,
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index 359bcf9..3caec6b 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -1206,12 +1206,8 @@
/*hasProto=*/true,
/*isAmbiguous=*/false, LParenLoc, ParamInfo.data(),
ParamInfo.size(), EllipsisLoc, RParenLoc,
- DS.getTypeQualifiers(),
/*RefQualifierIsLValueRef=*/true,
- /*RefQualifierLoc=*/NoLoc,
- /*ConstQualifierLoc=*/NoLoc,
- /*VolatileQualifierLoc=*/NoLoc,
- /*RestrictQualifierLoc=*/NoLoc, MutableLoc, ESpecType,
+ /*RefQualifierLoc=*/NoLoc, MutableLoc, ESpecType,
ESpecRange, DynamicExceptions.data(),
DynamicExceptionRanges.data(), DynamicExceptions.size(),
NoexceptExpr.isUsable() ? NoexceptExpr.get() : nullptr,
@@ -1273,12 +1269,8 @@
/*NumParams=*/0,
/*EllipsisLoc=*/NoLoc,
/*RParenLoc=*/NoLoc,
- /*TypeQuals=*/0,
/*RefQualifierIsLValueRef=*/true,
- /*RefQualifierLoc=*/NoLoc,
- /*ConstQualifierLoc=*/NoLoc,
- /*VolatileQualifierLoc=*/NoLoc,
- /*RestrictQualifierLoc=*/NoLoc, MutableLoc, EST_None,
+ /*RefQualifierLoc=*/NoLoc, MutableLoc, EST_None,
/*ESpecRange=*/SourceRange(),
/*Exceptions=*/nullptr,
/*ExceptionRanges=*/nullptr,