r197629 - Refactor the Microsoft inheritance attribute handling so that it no longer has special treatment. Also fixes a minor bug where the attributes were being parsed as though they were GNU-style attributes when they were in fact keyword attributes.
Aaron Ballman
aaron at aaronballman.com
Wed Dec 18 15:44:19 PST 2013
Author: aaronballman
Date: Wed Dec 18 17:44:18 2013
New Revision: 197629
URL: http://llvm.org/viewvc/llvm-project?rev=197629&view=rev
Log:
Refactor the Microsoft inheritance attribute handling so that it no longer has special treatment. Also fixes a minor bug where the attributes were being parsed as though they were GNU-style attributes when they were in fact keyword attributes.
Modified:
cfe/trunk/include/clang/AST/Attr.h
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/include/clang/Basic/AttrKinds.h
cfe/trunk/lib/AST/AttrImpl.cpp
cfe/trunk/lib/AST/MicrosoftCXXABI.cpp
cfe/trunk/lib/Parse/ParseDeclCXX.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
Modified: cfe/trunk/include/clang/AST/Attr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Attr.h?rev=197629&r1=197628&r2=197629&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Attr.h (original)
+++ cfe/trunk/include/clang/AST/Attr.h Wed Dec 18 17:44:18 2013
@@ -136,21 +136,6 @@ public:
}
};
-class MSInheritanceAttr : public InheritableAttr {
- virtual void anchor();
-protected:
- MSInheritanceAttr(attr::Kind AK, SourceRange R, unsigned SpellingListIndex = 0)
- : InheritableAttr(AK, R, SpellingListIndex) {}
-
-public:
- // Implement isa/cast/dyncast/etc.
- static bool classof(const Attr *A) {
- // Relies on relative order of enum emission with respect to param attrs.
- return (A->getKind() <= attr::LAST_MS_INHERITANCE &&
- A->getKind() > attr::LAST_INHERITABLE_PARAM);
- }
-};
-
#include "clang/AST/Attrs.inc"
} // end namespace clang
Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=197629&r1=197628&r2=197629&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Wed Dec 18 17:44:18 2013
@@ -1271,26 +1271,21 @@ def UPtr : TypeAttr {
let ASTNode = 0;
}
-class MSInheritanceAttr : InheritableAttr {
+def MSInheritance : InheritableAttr {
let LangOpts = [MicrosoftExt];
-}
-
-def SingleInheritance : MSInheritanceAttr {
- let Spellings = [Keyword<"__single_inheritance">];
-}
-
-def MultipleInheritance : MSInheritanceAttr {
- let Spellings = [Keyword<"__multiple_inheritance">];
-}
-
-def VirtualInheritance : MSInheritanceAttr {
- let Spellings = [Keyword<"__virtual_inheritance">];
-}
-
-// This attribute doesn't have any spellings, but we can apply it implicitly to
-// incomplete types that lack any of the other attributes.
-def UnspecifiedInheritance : MSInheritanceAttr {
- let Spellings = [];
+ let Spellings = [Keyword<"__single_inheritance">,
+ Keyword<"__multiple_inheritance">,
+ Keyword<"__virtual_inheritance">,
+ // We use an empty string to denote an unspecified
+ // inheritance attribute.
+ Keyword<"">];
+ let Accessors = [Accessor<"IsSingle", [Keyword<"__single_inheritance">]>,
+ Accessor<"IsMultiple", [Keyword<"__multiple_inheritance">]>,
+ Accessor<"IsVirtual", [Keyword<"__virtual_inheritance">]>,
+ Accessor<"IsUnspecified", [Keyword<"">]>];
+ // This index is based off the Spellings list and corresponds to the empty
+ // keyword "spelling."
+ let AdditionalMembers = [{static const int UnspecifiedSpellingIndex = 3;}];
}
def Unaligned : IgnoredAttr {
Modified: cfe/trunk/include/clang/Basic/AttrKinds.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/AttrKinds.h?rev=197629&r1=197628&r2=197629&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/AttrKinds.h (original)
+++ cfe/trunk/include/clang/Basic/AttrKinds.h Wed Dec 18 17:44:18 2013
@@ -24,7 +24,6 @@ enum Kind {
#define ATTR(X) X,
#define LAST_INHERITABLE_ATTR(X) X, LAST_INHERITABLE = X,
#define LAST_INHERITABLE_PARAM_ATTR(X) X, LAST_INHERITABLE_PARAM = X,
-#define LAST_MS_INHERITANCE_ATTR(X) X, LAST_MS_INHERITANCE = X,
#include "clang/Basic/AttrList.inc"
NUM_ATTRS
};
Modified: cfe/trunk/lib/AST/AttrImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/AttrImpl.cpp?rev=197629&r1=197628&r2=197629&view=diff
==============================================================================
--- cfe/trunk/lib/AST/AttrImpl.cpp (original)
+++ cfe/trunk/lib/AST/AttrImpl.cpp Wed Dec 18 17:44:18 2013
@@ -24,6 +24,4 @@ void InheritableAttr::anchor() { }
void InheritableParamAttr::anchor() { }
-void MSInheritanceAttr::anchor() { }
-
#include "clang/AST/AttrImpl.inc"
Modified: cfe/trunk/lib/AST/MicrosoftCXXABI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftCXXABI.cpp?rev=197629&r1=197628&r2=197629&view=diff
==============================================================================
--- cfe/trunk/lib/AST/MicrosoftCXXABI.cpp (original)
+++ cfe/trunk/lib/AST/MicrosoftCXXABI.cpp Wed Dec 18 17:44:18 2013
@@ -92,19 +92,21 @@ static bool usesMultipleInheritanceModel
return false;
}
-static MSInheritanceModel MSInheritanceAttrToModel(attr::Kind Kind) {
- switch (Kind) {
- default: llvm_unreachable("expected MS inheritance attribute");
- case attr::SingleInheritance: return MSIM_Single;
- case attr::MultipleInheritance: return MSIM_Multiple;
- case attr::VirtualInheritance: return MSIM_Virtual;
- case attr::UnspecifiedInheritance: return MSIM_Unspecified;
- }
+static MSInheritanceModel MSInheritanceAttrToModel(MSInheritanceAttr *Attr) {
+ if (Attr->IsSingle())
+ return MSIM_Single;
+ else if (Attr->IsMultiple())
+ return MSIM_Multiple;
+ else if (Attr->IsVirtual())
+ return MSIM_Virtual;
+
+ assert(Attr->IsUnspecified() && "Expected unspecified inheritance attr");
+ return MSIM_Unspecified;
}
MSInheritanceModel CXXRecordDecl::getMSInheritanceModel() const {
- if (Attr *IA = this->getAttr<MSInheritanceAttr>())
- return MSInheritanceAttrToModel(IA->getKind());
+ if (MSInheritanceAttr *IA = this->getAttr<MSInheritanceAttr>())
+ return MSInheritanceAttrToModel(IA);
// If there was no explicit attribute, the record must be defined already, and
// we can figure out the inheritance model from its other properties.
if (this->getNumVBases() > 0)
Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=197629&r1=197628&r2=197629&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Wed Dec 18 17:44:18 2013
@@ -998,7 +998,7 @@ void Parser::ParseMicrosoftInheritanceCl
IdentifierInfo *AttrName = Tok.getIdentifierInfo();
SourceLocation AttrNameLoc = ConsumeToken();
attrs.addNew(AttrName, AttrNameLoc, 0, AttrNameLoc, 0, 0,
- AttributeList::AS_GNU);
+ AttributeList::AS_Keyword);
}
}
Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=197629&r1=197628&r2=197629&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Wed Dec 18 17:44:18 2013
@@ -4091,12 +4091,8 @@ static void ProcessDeclAttribute(Sema &S
case AttributeList::AT_Uuid:
handleUuidAttr(S, D, Attr);
break;
- case AttributeList::AT_SingleInheritance:
- handleSimpleAttribute<SingleInheritanceAttr>(S, D, Attr); break;
- case AttributeList::AT_MultipleInheritance:
- handleSimpleAttribute<MultipleInheritanceAttr>(S, D, Attr); break;
- case AttributeList::AT_VirtualInheritance:
- handleSimpleAttribute<VirtualInheritanceAttr>(S, D, Attr); break;
+ case AttributeList::AT_MSInheritance:
+ handleSimpleAttribute<MSInheritanceAttr>(S, D, Attr); break;
case AttributeList::AT_ForceInline:
handleSimpleAttribute<ForceInlineAttr>(S, D, Attr); break;
case AttributeList::AT_SelectAny:
Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=197629&r1=197628&r2=197629&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Wed Dec 18 17:44:18 2013
@@ -1773,8 +1773,9 @@ QualType Sema::BuildMemberPointerType(Qu
// figure out the inheritance model.
for (CXXRecordDecl::redecl_iterator I = RD->redecls_begin(),
E = RD->redecls_end(); I != E; ++I) {
- I->addAttr(::new (Context) UnspecifiedInheritanceAttr(
- RD->getSourceRange(), Context));
+ I->addAttr(::new (Context) MSInheritanceAttr(RD->getSourceRange(),
+ Context,
+ MSInheritanceAttr::UnspecifiedSpellingIndex));
}
}
}
Modified: cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp?rev=197629&r1=197628&r2=197629&view=diff
==============================================================================
--- cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp (original)
+++ cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp Wed Dec 18 17:44:18 2013
@@ -1387,20 +1387,10 @@ void EmitClangAttrList(RecordKeeper &Rec
" INHERITABLE_PARAM_ATTR(NAME)\n";
OS << "#endif\n\n";
- OS << "#ifndef MS_INHERITANCE_ATTR\n";
- OS << "#define MS_INHERITANCE_ATTR(NAME) INHERITABLE_ATTR(NAME)\n";
- OS << "#endif\n\n";
-
- OS << "#ifndef LAST_MS_INHERITANCE_ATTR\n";
- OS << "#define LAST_MS_INHERITANCE_ATTR(NAME)"
- " MS_INHERITANCE_ATTR(NAME)\n";
- OS << "#endif\n\n";
-
Record *InhClass = Records.getClass("InheritableAttr");
Record *InhParamClass = Records.getClass("InheritableParamAttr");
- Record *MSInheritanceClass = Records.getClass("MSInheritanceAttr");
std::vector<Record*> Attrs = Records.getAllDerivedDefinitions("Attr"),
- NonInhAttrs, InhAttrs, InhParamAttrs, MSInhAttrs;
+ NonInhAttrs, InhAttrs, InhParamAttrs;
for (std::vector<Record*>::iterator i = Attrs.begin(), e = Attrs.end();
i != e; ++i) {
if (!(*i)->getValueAsBit("ASTNode"))
@@ -1408,8 +1398,6 @@ void EmitClangAttrList(RecordKeeper &Rec
if ((*i)->isSubClassOf(InhParamClass))
InhParamAttrs.push_back(*i);
- else if ((*i)->isSubClassOf(MSInheritanceClass))
- MSInhAttrs.push_back(*i);
else if ((*i)->isSubClassOf(InhClass))
InhAttrs.push_back(*i);
else
@@ -1417,16 +1405,13 @@ void EmitClangAttrList(RecordKeeper &Rec
}
EmitAttrList(OS, "INHERITABLE_PARAM_ATTR", InhParamAttrs);
- EmitAttrList(OS, "MS_INHERITANCE_ATTR", MSInhAttrs);
EmitAttrList(OS, "INHERITABLE_ATTR", InhAttrs);
EmitAttrList(OS, "ATTR", NonInhAttrs);
OS << "#undef LAST_ATTR\n";
OS << "#undef INHERITABLE_ATTR\n";
- OS << "#undef MS_INHERITANCE_ATTR\n";
OS << "#undef LAST_INHERITABLE_ATTR\n";
OS << "#undef LAST_INHERITABLE_PARAM_ATTR\n";
- OS << "#undef LAST_MS_INHERITANCE_ATTR\n";
OS << "#undef ATTR\n";
}
More information about the cfe-commits
mailing list