mirror of
https://github.com/intel/llvm.git
synced 2026-01-27 14:50:42 +08:00
Provide isConst/Volatile on CXXMethodDecl.
This also provides isConst/Volatile/Restrict on FunctionTypes to coalesce the implementation with other callers (& update those other callers). Patch contributed by Sam Panzer (panzer@google.com). llvm-svn: 161647
This commit is contained in:
@@ -1549,6 +1549,9 @@ public:
|
||||
bool isStatic() const { return getStorageClass() == SC_Static; }
|
||||
bool isInstance() const { return !isStatic(); }
|
||||
|
||||
bool isConst() { return getType()->castAs<FunctionType>()->isConst(); }
|
||||
bool isVolatile() { return getType()->castAs<FunctionType>()->isVolatile(); }
|
||||
|
||||
bool isVirtual() const {
|
||||
CXXMethodDecl *CD =
|
||||
cast<CXXMethodDecl>(const_cast<CXXMethodDecl*>(this)->getCanonicalDecl());
|
||||
|
||||
@@ -2676,6 +2676,9 @@ public:
|
||||
bool getNoReturnAttr() const { return getExtInfo().getNoReturn(); }
|
||||
CallingConv getCallConv() const { return getExtInfo().getCC(); }
|
||||
ExtInfo getExtInfo() const { return ExtInfo(FunctionTypeBits.ExtInfo); }
|
||||
bool isConst() const { return getTypeQuals() & Qualifiers::Const; }
|
||||
bool isVolatile() const { return getTypeQuals() & Qualifiers::Volatile; }
|
||||
bool isRestrict() const { return getTypeQuals() & Qualifiers::Restrict; }
|
||||
|
||||
/// \brief Determine the type of an expression that calls a function of
|
||||
/// this type.
|
||||
|
||||
@@ -440,13 +440,12 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {
|
||||
|
||||
Proto += ")";
|
||||
|
||||
if (FT && FT->getTypeQuals()) {
|
||||
unsigned TypeQuals = FT->getTypeQuals();
|
||||
if (TypeQuals & Qualifiers::Const)
|
||||
if (FT) {
|
||||
if (FT->isConst())
|
||||
Proto += " const";
|
||||
if (TypeQuals & Qualifiers::Volatile)
|
||||
if (FT->isVolatile())
|
||||
Proto += " volatile";
|
||||
if (TypeQuals & Qualifiers::Restrict)
|
||||
if (FT->isRestrict())
|
||||
Proto += " restrict";
|
||||
}
|
||||
|
||||
|
||||
@@ -971,9 +971,9 @@ struct XMLDumper : public XMLDeclVisitor<XMLDumper>,
|
||||
}
|
||||
|
||||
void visitFunctionProtoTypeAttrs(FunctionProtoType *T) {
|
||||
setFlag("const", T->getTypeQuals() & Qualifiers::Const);
|
||||
setFlag("volatile", T->getTypeQuals() & Qualifiers::Volatile);
|
||||
setFlag("restrict", T->getTypeQuals() & Qualifiers::Restrict);
|
||||
setFlag("const", T->isConst());
|
||||
setFlag("volatile", T->isVolatile());
|
||||
setFlag("restrict", T->isRestrict());
|
||||
}
|
||||
void visitFunctionProtoTypeChildren(FunctionProtoType *T) {
|
||||
push("parameters");
|
||||
|
||||
@@ -211,7 +211,7 @@ static void computeDeclRefDependence(ASTContext &Ctx, NamedDecl *D, QualType T,
|
||||
if ((Ctx.getLangOpts().CPlusPlus0x ?
|
||||
Var->getType()->isLiteralType() :
|
||||
Var->getType()->isIntegralOrEnumerationType()) &&
|
||||
(Var->getType().getCVRQualifiers() == Qualifiers::Const ||
|
||||
(Var->getType().isConstQualified() ||
|
||||
Var->getType()->isReferenceType())) {
|
||||
if (const Expr *Init = Var->getAnyInitializer())
|
||||
if (Init->isValueDependent()) {
|
||||
@@ -440,10 +440,10 @@ std::string PredefinedExpr::ComputeName(IdentType IT, const Decl *CurrentDecl) {
|
||||
POut << ")";
|
||||
|
||||
if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) {
|
||||
Qualifiers ThisQuals = Qualifiers::fromCVRMask(MD->getTypeQualifiers());
|
||||
if (ThisQuals.hasConst())
|
||||
const FunctionType *FT = cast<FunctionType>(MD->getType().getTypePtr());
|
||||
if (FT->isConst())
|
||||
POut << " const";
|
||||
if (ThisQuals.hasVolatile())
|
||||
if (FT->isVolatile())
|
||||
POut << " volatile";
|
||||
RefQualifierKind Ref = MD->getRefQualifier();
|
||||
if (Ref == RQ_LValue)
|
||||
|
||||
@@ -943,7 +943,7 @@ CompoundStmt *LambdaExpr::getBody() const {
|
||||
}
|
||||
|
||||
bool LambdaExpr::isMutable() const {
|
||||
return (getCallOperator()->getTypeQualifiers() & Qualifiers::Const) == 0;
|
||||
return !getCallOperator()->isConst();
|
||||
}
|
||||
|
||||
ExprWithCleanups::ExprWithCleanups(Expr *subexpr,
|
||||
|
||||
@@ -2369,11 +2369,11 @@ AddFunctionTypeQualsToCompletionString(CodeCompletionBuilder &Result,
|
||||
|
||||
// Handle multiple qualifiers.
|
||||
std::string QualsStr;
|
||||
if (Proto->getTypeQuals() & Qualifiers::Const)
|
||||
if (Proto->isConst())
|
||||
QualsStr += " const";
|
||||
if (Proto->getTypeQuals() & Qualifiers::Volatile)
|
||||
if (Proto->isVolatile())
|
||||
QualsStr += " volatile";
|
||||
if (Proto->getTypeQuals() & Qualifiers::Restrict)
|
||||
if (Proto->isRestrict())
|
||||
QualsStr += " restrict";
|
||||
Result.AddInformativeChunk(Result.getAllocator().CopyString(QualsStr));
|
||||
}
|
||||
|
||||
@@ -4852,7 +4852,7 @@ static NamedDecl* DiagnoseInvalidRedeclaration(
|
||||
|
||||
bool NewFDisConst = false;
|
||||
if (CXXMethodDecl *NewMD = dyn_cast<CXXMethodDecl>(NewFD))
|
||||
NewFDisConst = NewMD->getTypeQualifiers() & Qualifiers::Const;
|
||||
NewFDisConst = NewMD->isConst();
|
||||
|
||||
for (llvm::SmallVector<std::pair<FunctionDecl*, unsigned>, 1>::iterator
|
||||
NearMatch = NearMatches.begin(), NearMatchEnd = NearMatches.end();
|
||||
@@ -4860,7 +4860,7 @@ static NamedDecl* DiagnoseInvalidRedeclaration(
|
||||
FunctionDecl *FD = NearMatch->first;
|
||||
bool FDisConst = false;
|
||||
if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD))
|
||||
FDisConst = MD->getTypeQualifiers() & Qualifiers::Const;
|
||||
FDisConst = MD->isConst();
|
||||
|
||||
if (unsigned Idx = NearMatch->second) {
|
||||
ParmVarDecl *FDParam = FD->getParamDecl(Idx-1);
|
||||
|
||||
@@ -437,7 +437,7 @@ void Sema::ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro,
|
||||
LambdaScopeInfo *LSI
|
||||
= enterLambdaScope(Method, Intro.Range, Intro.Default, ExplicitParams,
|
||||
ExplicitResultType,
|
||||
(Method->getTypeQualifiers() & Qualifiers::Const) == 0);
|
||||
!Method->isConst());
|
||||
|
||||
// Handle explicit captures.
|
||||
SourceLocation PrevCaptureLoc
|
||||
|
||||
Reference in New Issue
Block a user