diff options
Diffstat (limited to 'lib/AST/Decl.cpp')
-rw-r--r-- | lib/AST/Decl.cpp | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index a3e406b..bf63932 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -315,6 +315,12 @@ void VarDecl::Destroy(ASTContext& C) { VarDecl::~VarDecl() { } +SourceRange VarDecl::getSourceRange() const { + if (getInit()) + return SourceRange(getLocation(), getInit()->getLocEnd()); + return SourceRange(getLocation(), getLocation()); +} + bool VarDecl::isTentativeDefinition(ASTContext &Context) const { if (!isFileVarDecl() || Context.getLangOptions().CPlusPlus) return false; @@ -371,6 +377,12 @@ Stmt *FunctionDecl::getBodyIfAvailable() const { return 0; } +void FunctionDecl::setBody(Stmt *B) { + Body = B; + if (B && EndRangeLoc < B->getLocEnd()) + EndRangeLoc = B->getLocEnd(); +} + bool FunctionDecl::isMain() const { return getDeclContext()->getLookupContext()->isTranslationUnit() && getIdentifier() && getIdentifier()->isStr("main"); @@ -380,13 +392,14 @@ bool FunctionDecl::isExternC(ASTContext &Context) const { // In C, any non-static, non-overloadable function has external // linkage. if (!Context.getLangOptions().CPlusPlus) - return getStorageClass() != Static && !getAttr<OverloadableAttr>(); + return getStorageClass() != Static && !getAttr<OverloadableAttr>(Context); for (const DeclContext *DC = getDeclContext(); !DC->isTranslationUnit(); DC = DC->getParent()) { if (const LinkageSpecDecl *Linkage = dyn_cast<LinkageSpecDecl>(DC)) { if (Linkage->getLanguage() == LinkageSpecDecl::lang_c) - return getStorageClass() != Static && !getAttr<OverloadableAttr>(); + return getStorageClass() != Static && + !getAttr<OverloadableAttr>(Context); break; } @@ -451,7 +464,7 @@ unsigned FunctionDecl::getBuiltinID(ASTContext &Context) const { if (isa<LinkageSpecDecl>(getDeclContext()) && cast<LinkageSpecDecl>(getDeclContext())->getLanguage() == LinkageSpecDecl::lang_c && - !getAttr<OverloadableAttr>()) + !getAttr<OverloadableAttr>(Context)) return BuiltinID; // Not a builtin @@ -480,6 +493,10 @@ void FunctionDecl::setParams(ASTContext& C, ParmVarDecl **NewParamInfo, void *Mem = C.Allocate(sizeof(ParmVarDecl*)*NumParams); ParamInfo = new (Mem) ParmVarDecl*[NumParams]; memcpy(ParamInfo, NewParamInfo, sizeof(ParmVarDecl*)*NumParams); + + // Update source range. + if (EndRangeLoc < NewParamInfo[NumParams-1]->getLocEnd()) + EndRangeLoc = NewParamInfo[NumParams-1]->getLocEnd(); } } @@ -496,25 +513,25 @@ unsigned FunctionDecl::getMinRequiredArguments() const { return NumRequiredArgs; } -bool FunctionDecl::hasActiveGNUInlineAttribute() const { - if (!isInline() || !hasAttr<GNUInlineAttr>()) +bool FunctionDecl::hasActiveGNUInlineAttribute(ASTContext &Context) const { + if (!isInline() || !hasAttr<GNUInlineAttr>(Context)) return false; for (const FunctionDecl *FD = getPreviousDeclaration(); FD; FD = FD->getPreviousDeclaration()) { - if (FD->isInline() && !FD->hasAttr<GNUInlineAttr>()) + if (FD->isInline() && !FD->hasAttr<GNUInlineAttr>(Context)) return false; } return true; } -bool FunctionDecl::isExternGNUInline() const { - if (!hasActiveGNUInlineAttribute()) +bool FunctionDecl::isExternGNUInline(ASTContext &Context) const { + if (!hasActiveGNUInlineAttribute(Context)) return false; for (const FunctionDecl *FD = this; FD; FD = FD->getPreviousDeclaration()) - if (FD->getStorageClass() == Extern && FD->hasAttr<GNUInlineAttr>()) + if (FD->getStorageClass() == Extern && FD->hasAttr<GNUInlineAttr>(Context)) return true; return false; |