diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-11-23 11:41:28 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-11-23 11:41:28 +0000 |
commit | ed6c7440915937b9ecab0868a6130d906d4cb716 (patch) | |
tree | 37e94c2c4b2ccbd74ea60c557fa49d9a95812a30 /clang/lib/AST | |
parent | 9d786d701d91cc149c54016d1881bd0f990235f6 (diff) | |
download | bcm5719-llvm-ed6c7440915937b9ecab0868a6130d906d4cb716.tar.gz bcm5719-llvm-ed6c7440915937b9ecab0868a6130d906d4cb716.zip |
Centralize and complete the computation of value- and type-dependence for DeclRefExprs
llvm-svn: 89649
Diffstat (limited to 'clang/lib/AST')
-rw-r--r-- | clang/lib/AST/DeclTemplate.cpp | 4 | ||||
-rw-r--r-- | clang/lib/AST/Expr.cpp | 72 |
2 files changed, 59 insertions, 17 deletions
diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp index 2d2851036c1..902339e1efc 100644 --- a/clang/lib/AST/DeclTemplate.cpp +++ b/clang/lib/AST/DeclTemplate.cpp @@ -214,9 +214,7 @@ QualType ClassTemplateDecl::getInjectedClassNameType(ASTContext &Context) { } else if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(*Param)) { Expr *E = new (Context) DeclRefExpr(NTTP, NTTP->getType(), - NTTP->getLocation(), - NTTP->getType()->isDependentType(), - /*Value-dependent=*/true); + NTTP->getLocation()); TemplateArgs.push_back(TemplateArgument(E)); } else { TemplateTemplateParmDecl *TTP = cast<TemplateTemplateParmDecl>(*Param); diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index 61492694fcb..7c80f04be26 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -56,12 +56,64 @@ std::size_t ExplicitTemplateArgumentList::sizeFor( sizeof(TemplateArgumentLoc) * Info.size(); } +void DeclRefExpr::computeDependence() { + TypeDependent = false; + ValueDependent = false; + + NamedDecl *D = getDecl(); + + // (TD) C++ [temp.dep.expr]p3: + // An id-expression is type-dependent if it contains: + // + // and + // + // (VD) C++ [temp.dep.constexpr]p2: + // An identifier is value-dependent if it is: + + // (TD) - an identifier that was declared with dependent type + // (VD) - a name declared with a dependent type, + if (getType()->isDependentType()) { + TypeDependent = true; + ValueDependent = true; + } + // (TD) - a conversion-function-id that specifies a dependent type + else if (D->getDeclName().getNameKind() + == DeclarationName::CXXConversionFunctionName && + D->getDeclName().getCXXNameType()->isDependentType()) { + TypeDependent = true; + ValueDependent = true; + } + // (TD) - a template-id that is dependent, + else if (hasExplicitTemplateArgumentList() && + TemplateSpecializationType::anyDependentTemplateArguments( + getTemplateArgs(), + getNumTemplateArgs())) { + TypeDependent = true; + ValueDependent = true; + } + // (VD) - the name of a non-type template parameter, + else if (isa<NonTypeTemplateParmDecl>(D)) + ValueDependent = true; + // (VD) - a constant with integral or enumeration type and is + // initialized with an expression that is value-dependent. + else if (VarDecl *Var = dyn_cast<VarDecl>(D)) { + if (Var->getType()->isIntegralType() && + Var->getType().getCVRQualifiers() == Qualifiers::Const && + Var->getInit() && + Var->getInit()->isValueDependent()) + ValueDependent = true; + } + // (TD) - a nested-name-specifier or a qualified-id that names a + // member of an unknown specialization. + // (handled by DependentScopeDeclRefExpr) +} + DeclRefExpr::DeclRefExpr(NestedNameSpecifier *Qualifier, SourceRange QualifierRange, NamedDecl *D, SourceLocation NameLoc, const TemplateArgumentListInfo *TemplateArgs, - QualType T, bool TD, bool VD) - : Expr(DeclRefExprClass, T, TD, VD), + QualType T) + : Expr(DeclRefExprClass, T, false, false), DecoratedD(D, (Qualifier? HasQualifierFlag : 0) | (TemplateArgs ? HasExplicitTemplateArgumentListFlag : 0)), @@ -75,16 +127,8 @@ DeclRefExpr::DeclRefExpr(NestedNameSpecifier *Qualifier, if (TemplateArgs) getExplicitTemplateArgumentList()->initializeFrom(*TemplateArgs); -} -DeclRefExpr *DeclRefExpr::Create(ASTContext &Context, - NestedNameSpecifier *Qualifier, - SourceRange QualifierRange, - NamedDecl *D, - SourceLocation NameLoc, - QualType T, bool TD, bool VD) { - return Create(Context, Qualifier, QualifierRange, D, NameLoc, - /*TemplateArgs*/ 0, T, TD, VD); + computeDependence(); } DeclRefExpr *DeclRefExpr::Create(ASTContext &Context, @@ -92,8 +136,8 @@ DeclRefExpr *DeclRefExpr::Create(ASTContext &Context, SourceRange QualifierRange, NamedDecl *D, SourceLocation NameLoc, - const TemplateArgumentListInfo *TemplateArgs, - QualType T, bool TD, bool VD) { + QualType T, + const TemplateArgumentListInfo *TemplateArgs) { std::size_t Size = sizeof(DeclRefExpr); if (Qualifier != 0) Size += sizeof(NameQualifier); @@ -103,7 +147,7 @@ DeclRefExpr *DeclRefExpr::Create(ASTContext &Context, void *Mem = Context.Allocate(Size, llvm::alignof<DeclRefExpr>()); return new (Mem) DeclRefExpr(Qualifier, QualifierRange, D, NameLoc, - TemplateArgs, T, TD, VD); + TemplateArgs, T); } SourceRange DeclRefExpr::getSourceRange() const { |