[cfe-commits] r156728 - in /cfe/trunk: include/clang/Sema/Sema.h lib/Sema/SemaDecl.cpp lib/Sema/SemaDeclAttr.cpp lib/Sema/TargetAttributesSema.cpp
Rafael Espindola
rafael.espindola at gmail.com
Sat May 12 20:25:18 PDT 2012
Author: rafael
Date: Sat May 12 22:25:18 2012
New Revision: 156728
URL: http://llvm.org/viewvc/llvm-project?rev=156728&view=rev
Log:
Refactor all the
if (Inherited)
Attr->setInherited(true);
To a central location.
Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/lib/Sema/TargetAttributesSema.cpp
Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=156728&r1=156727&r2=156728&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Sat May 12 22:25:18 2012
@@ -1562,18 +1562,20 @@
bool isIncompatibleTypedef(TypeDecl *Old, TypedefNameDecl *New);
/// Attribute merging methods. Return true if a new attribute was added.
- bool mergeAvailabilityAttr(Decl *D, SourceRange Range, bool Inherited,
- IdentifierInfo *Platform, VersionTuple Introduced,
- VersionTuple Deprecated, VersionTuple Obsoleted,
- bool IsUnavailable, StringRef Message);
- bool mergeVisibilityAttr(Decl *D, SourceRange Range,
- bool Inherited, VisibilityAttr::VisibilityType Vis);
- bool mergeDLLImportAttr(Decl *D, SourceRange Range, bool Inherited);
- bool mergeDLLExportAttr(Decl *D, SourceRange Range, bool Inherited);
- bool mergeFormatAttr(Decl *D, SourceRange Range, bool Inherited,
- StringRef Format, int FormatIdx, int FirstArg);
- bool mergeSectionAttr(Decl *D, SourceRange Range, bool Inherited,
- StringRef Name);
+ AvailabilityAttr *mergeAvailabilityAttr(Decl *D, SourceRange Range,
+ IdentifierInfo *Platform,
+ VersionTuple Introduced,
+ VersionTuple Deprecated,
+ VersionTuple Obsoleted,
+ bool IsUnavailable,
+ StringRef Message);
+ VisibilityAttr *mergeVisibilityAttr(Decl *D, SourceRange Range,
+ VisibilityAttr::VisibilityType Vis);
+ DLLImportAttr *mergeDLLImportAttr(Decl *D, SourceRange Range);
+ DLLExportAttr *mergeDLLExportAttr(Decl *D, SourceRange Range);
+ FormatAttr *mergeFormatAttr(Decl *D, SourceRange Range, StringRef Format,
+ int FormatIdx, int FirstArg);
+ SectionAttr *mergeSectionAttr(Decl *D, SourceRange Range, StringRef Name);
bool mergeDeclAttribute(Decl *New, InheritableAttr *Attr);
void mergeDeclAttributes(Decl *New, Decl *Old, bool MergeDeprecation = true);
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=156728&r1=156727&r2=156728&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sat May 12 22:25:18 2012
@@ -1659,30 +1659,27 @@
}
bool Sema::mergeDeclAttribute(Decl *D, InheritableAttr *Attr) {
+ InheritableAttr *NewAttr = NULL;
if (AvailabilityAttr *AA = dyn_cast<AvailabilityAttr>(Attr))
- return mergeAvailabilityAttr(D, AA->getRange(), true, AA->getPlatform(),
- AA->getIntroduced(), AA->getDeprecated(),
- AA->getObsoleted(), AA->getUnavailable(),
- AA->getMessage());
+ NewAttr = mergeAvailabilityAttr(D, AA->getRange(), AA->getPlatform(),
+ AA->getIntroduced(), AA->getDeprecated(),
+ AA->getObsoleted(), AA->getUnavailable(),
+ AA->getMessage());
+ else if (VisibilityAttr *VA = dyn_cast<VisibilityAttr>(Attr))
+ NewAttr = mergeVisibilityAttr(D, VA->getRange(), VA->getVisibility());
+ else if (DLLImportAttr *ImportA = dyn_cast<DLLImportAttr>(Attr))
+ NewAttr = mergeDLLImportAttr(D, ImportA->getRange());
+ else if (DLLExportAttr *ExportA = dyn_cast<DLLExportAttr>(Attr))
+ NewAttr = mergeDLLExportAttr(D, ExportA->getRange());
+ else if (FormatAttr *FA = dyn_cast<FormatAttr>(Attr))
+ NewAttr = mergeFormatAttr(D, FA->getRange(), FA->getType(),
+ FA->getFormatIdx(), FA->getFirstArg());
+ else if (SectionAttr *SA = dyn_cast<SectionAttr>(Attr))
+ NewAttr = mergeSectionAttr(D, SA->getRange(), SA->getName());
+ else if (!DeclHasAttr(D, Attr))
+ NewAttr = cast<InheritableAttr>(Attr->clone(Context));
- if (VisibilityAttr *VA = dyn_cast<VisibilityAttr>(Attr))
- return mergeVisibilityAttr(D, VA->getRange(), true, VA->getVisibility());
-
- if (DLLImportAttr *ImportA = dyn_cast<DLLImportAttr>(Attr))
- return mergeDLLImportAttr(D, ImportA->getRange(), true);
-
- if (DLLExportAttr *ExportA = dyn_cast<DLLExportAttr>(Attr))
- return mergeDLLExportAttr(D, ExportA->getRange(), true);
-
- if (FormatAttr *FA = dyn_cast<FormatAttr>(Attr))
- return mergeFormatAttr(D, FA->getRange(), true, FA->getType(),
- FA->getFormatIdx(), FA->getFirstArg());
-
- if (SectionAttr *SA = dyn_cast<SectionAttr>(Attr))
- return mergeSectionAttr(D, SA->getRange(), true, SA->getName());
-
- if (!DeclHasAttr(D, Attr)) {
- InheritableAttr *NewAttr = cast<InheritableAttr>(Attr->clone(Context));
+ if (NewAttr) {
NewAttr->setInherited(true);
D->addAttr(NewAttr);
return true;
Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=156728&r1=156727&r2=156728&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Sat May 12 22:25:18 2012
@@ -1769,14 +1769,13 @@
return false;
}
-bool Sema::mergeAvailabilityAttr(Decl *D, SourceRange Range,
- bool Inherited,
- IdentifierInfo *Platform,
- VersionTuple Introduced,
- VersionTuple Deprecated,
- VersionTuple Obsoleted,
- bool IsUnavailable,
- StringRef Message) {
+AvailabilityAttr *Sema::mergeAvailabilityAttr(Decl *D, SourceRange Range,
+ IdentifierInfo *Platform,
+ VersionTuple Introduced,
+ VersionTuple Deprecated,
+ VersionTuple Obsoleted,
+ bool IsUnavailable,
+ StringRef Message) {
VersionTuple MergedIntroduced = Introduced;
VersionTuple MergedDeprecated = Deprecated;
VersionTuple MergedObsoleted = Obsoleted;
@@ -1849,21 +1848,15 @@
MergedIntroduced == Introduced &&
MergedDeprecated == Deprecated &&
MergedObsoleted == Obsoleted)
- return false;
+ return NULL;
if (!checkAvailabilityAttr(*this, Range, Platform, MergedIntroduced,
MergedDeprecated, MergedObsoleted)) {
- AvailabilityAttr *Attr =
- ::new (Context) AvailabilityAttr(Range, Context, Platform,
- Introduced, Deprecated,
- Obsoleted, IsUnavailable, Message);
-
- if (Inherited)
- Attr->setInherited(true);
- D->addAttr(Attr);
- return true;
+ return ::new (Context) AvailabilityAttr(Range, Context, Platform,
+ Introduced, Deprecated,
+ Obsoleted, IsUnavailable, Message);
}
- return false;
+ return NULL;
}
static void handleAvailabilityAttr(Sema &S, Decl *D,
@@ -1885,36 +1878,32 @@
if (SE)
Str = SE->getString();
- S.mergeAvailabilityAttr(D, Attr.getRange(),
- false, Platform,
- Introduced.Version,
- Deprecated.Version,
- Obsoleted.Version,
- IsUnavailable,
- Str);
+ AvailabilityAttr *NewAttr = S.mergeAvailabilityAttr(D, Attr.getRange(),
+ Platform,
+ Introduced.Version,
+ Deprecated.Version,
+ Obsoleted.Version,
+ IsUnavailable, Str);
+ if (NewAttr)
+ D->addAttr(NewAttr);
}
-bool Sema::mergeVisibilityAttr(Decl *D, SourceRange Range,
- bool Inherited,
- VisibilityAttr::VisibilityType Vis) {
+VisibilityAttr *Sema::mergeVisibilityAttr(Decl *D, SourceRange Range,
+ VisibilityAttr::VisibilityType Vis) {
if (isa<TypedefNameDecl>(D)) {
Diag(Range.getBegin(), diag::warn_attribute_ignored) << "visibility";
- return false;
+ return NULL;
}
VisibilityAttr *ExistingAttr = D->getAttr<VisibilityAttr>();
if (ExistingAttr) {
VisibilityAttr::VisibilityType ExistingVis = ExistingAttr->getVisibility();
if (ExistingVis == Vis)
- return false;
+ return NULL;
Diag(ExistingAttr->getLocation(), diag::err_mismatched_visibility);
Diag(Range.getBegin(), diag::note_previous_attribute);
D->dropAttr<VisibilityAttr>();
}
- VisibilityAttr *Attr = ::new (Context) VisibilityAttr(Range, Context, Vis);
- if (Inherited)
- Attr->setInherited(true);
- D->addAttr(Attr);
- return true;
+ return ::new (Context) VisibilityAttr(Range, Context, Vis);
}
static void handleVisibilityAttr(Sema &S, Decl *D, const AttributeList &Attr) {
@@ -1955,7 +1944,9 @@
return;
}
- S.mergeVisibilityAttr(D, Attr.getRange(), false, type);
+ VisibilityAttr *NewAttr = S.mergeVisibilityAttr(D, Attr.getRange(), type);
+ if (NewAttr)
+ D->addAttr(NewAttr);
}
static void handleObjCMethodFamilyAttr(Sema &S, Decl *decl,
@@ -2286,20 +2277,16 @@
WGSize[2]));
}
-bool Sema::mergeSectionAttr(Decl *D, SourceRange Range, bool Inherited,
- StringRef Name) {
+SectionAttr *Sema::mergeSectionAttr(Decl *D, SourceRange Range,
+ StringRef Name) {
if (SectionAttr *ExistingAttr = D->getAttr<SectionAttr>()) {
if (ExistingAttr->getName() == Name)
- return false;
+ return NULL;
Diag(ExistingAttr->getLocation(), diag::warn_mismatched_section);
Diag(Range.getBegin(), diag::note_previous_attribute);
- return false;
+ return NULL;
}
- SectionAttr *Attr = ::new (Context) SectionAttr(Range, Context, Name);
- if (Inherited)
- Attr->setInherited(true);
- D->addAttr(Attr);
- return true;
+ return ::new (Context) SectionAttr(Range, Context, Name);
}
static void handleSectionAttr(Sema &S, Decl *D, const AttributeList &Attr) {
@@ -2329,7 +2316,10 @@
S.Diag(SE->getLocStart(), diag::err_attribute_section_local_variable);
return;
}
- S.mergeSectionAttr(D, Attr.getRange(), false, SE->getString());
+ SectionAttr *NewAttr = S.mergeSectionAttr(D, Attr.getRange(),
+ SE->getString());
+ if (NewAttr)
+ D->addAttr(NewAttr);
}
@@ -2589,8 +2579,8 @@
prioritynum));
}
-bool Sema::mergeFormatAttr(Decl *D, SourceRange Range, bool Inherited,
- StringRef Format, int FormatIdx, int FirstArg) {
+FormatAttr *Sema::mergeFormatAttr(Decl *D, SourceRange Range, StringRef Format,
+ int FormatIdx, int FirstArg) {
// Check whether we already have an equivalent format attribute.
for (specific_attr_iterator<FormatAttr>
i = D->specific_attr_begin<FormatAttr>(),
@@ -2604,14 +2594,12 @@
// location.
if (f->getLocation().isInvalid())
f->setRange(Range);
- return false;
+ return NULL;
}
}
- FormatAttr *Attr = ::new (Context) FormatAttr(Range, Context, Format,
- FormatIdx, FirstArg);
- D->addAttr(Attr);
- return true;
+ return ::new (Context) FormatAttr(Range, Context, Format, FormatIdx,
+ FirstArg);
}
/// Handle __attribute__((format(type,idx,firstarg))) attributes based on
@@ -2749,8 +2737,11 @@
return;
}
- S.mergeFormatAttr(D, Attr.getRange(), false, Format, Idx.getZExtValue(),
- FirstArg.getZExtValue());
+ FormatAttr *NewAttr = S.mergeFormatAttr(D, Attr.getRange(), Format,
+ Idx.getZExtValue(),
+ FirstArg.getZExtValue());
+ if (NewAttr)
+ D->addAttr(NewAttr);
}
static void handleTransparentUnionAttr(Sema &S, Decl *D,
Modified: cfe/trunk/lib/Sema/TargetAttributesSema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TargetAttributesSema.cpp?rev=156728&r1=156727&r2=156728&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/TargetAttributesSema.cpp (original)
+++ cfe/trunk/lib/Sema/TargetAttributesSema.cpp Sat May 12 22:25:18 2012
@@ -151,22 +151,16 @@
S.Context));
}
-bool Sema::mergeDLLImportAttr(Decl *D, SourceRange Range, bool Inherited) {
+DLLImportAttr *Sema::mergeDLLImportAttr(Decl *D, SourceRange Range) {
if (D->hasAttr<DLLExportAttr>()) {
Diag(Range.getBegin(), diag::warn_attribute_ignored) << "dllimport";
- return false;
+ return NULL;
}
if (D->hasAttr<DLLImportAttr>())
- return false;
+ return NULL;
- DLLImportAttr *Attr =
- ::new (Context) DLLImportAttr(Range, Context);
- if (Inherited)
- Attr->setInherited(true);
- D->addAttr(Attr);
-
- return true;
+ return ::new (Context) DLLImportAttr(Range, Context);
}
static void HandleDLLImportAttr(Decl *D, const AttributeList &Attr, Sema &S) {
@@ -195,25 +189,21 @@
return;
}
- S.mergeDLLImportAttr(D, Attr.getRange(), false);
+ DLLImportAttr *NewAttr = S.mergeDLLImportAttr(D, Attr.getRange());
+ if (NewAttr)
+ D->addAttr(NewAttr);
}
-bool Sema::mergeDLLExportAttr(Decl *D, SourceRange Range, bool Inherited) {
+DLLExportAttr *Sema::mergeDLLExportAttr(Decl *D, SourceRange Range) {
if (DLLImportAttr *Import = D->getAttr<DLLImportAttr>()) {
Diag(Import->getLocation(), diag::warn_attribute_ignored) << "dllimport";
D->dropAttr<DLLImportAttr>();
}
if (D->hasAttr<DLLExportAttr>())
- return false;
-
- DLLExportAttr *Attr =
- ::new (Context) DLLExportAttr(Range, Context);
- if (Inherited)
- Attr->setInherited(true);
- D->addAttr(Attr);
+ return NULL;
- return true;
+ return ::new (Context) DLLExportAttr(Range, Context);
}
static void HandleDLLExportAttr(Decl *D, const AttributeList &Attr, Sema &S) {
@@ -239,7 +229,9 @@
return;
}
- S.mergeDLLExportAttr(D, Attr.getRange(), false);
+ DLLExportAttr *NewAttr = S.mergeDLLExportAttr(D, Attr.getRange());
+ if (NewAttr)
+ D->addAttr(NewAttr);
}
namespace {
More information about the cfe-commits
mailing list