diff options
author | Francois Pichet <pichet2000@gmail.com> | 2010-12-19 06:50:37 +0000 |
---|---|---|
committer | Francois Pichet <pichet2000@gmail.com> | 2010-12-19 06:50:37 +0000 |
commit | 11542141e385859df6b4f1a8f1f01856ad193b5b (patch) | |
tree | 5cb0f87600d25ce71441a4ab44e4c453af863294 | |
parent | e6a365d772a6b455f1e23ac9ae5f40d65a55a18c (diff) |
Add support for the Microsoft uuid attribute:
example:
struct __declspec(uuid("6d5140c1-7436-11ce-8034-00aa006009fa"))
test { };
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@122173 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Basic/Attr.td | 6 | ||||
-rw-r--r-- | include/clang/Sema/AttributeList.h | 1 | ||||
-rw-r--r-- | lib/Sema/AttributeList.cpp | 1 | ||||
-rw-r--r-- | lib/Sema/SemaDeclAttr.cpp | 27 |
4 files changed, 34 insertions, 1 deletions
diff --git a/include/clang/Basic/Attr.td b/include/clang/Basic/Attr.td index afd476372a..cd5dc21409 100644 --- a/include/clang/Basic/Attr.td +++ b/include/clang/Basic/Attr.td @@ -422,6 +422,12 @@ def Used : Attr { let Spellings = ["used"]; } +def Uuid : Attr { + let Spellings = ["uuid"]; + let Args = [StringArgument<"Guid">]; + let Subjects = [CXXRecord]; +} + def Visibility : Attr { let Spellings = ["visibility"]; let Args = [EnumArgument<"Visibility", "VisibilityType", diff --git a/include/clang/Sema/AttributeList.h b/include/clang/Sema/AttributeList.h index d524861287..69170fa23c 100644 --- a/include/clang/Sema/AttributeList.h +++ b/include/clang/Sema/AttributeList.h @@ -148,6 +148,7 @@ public: AT_unavailable, AT_unused, AT_used, + AT_uuid, AT_vecreturn, // PS3 PPU-specific. AT_vector_size, AT_visibility, diff --git a/lib/Sema/AttributeList.cpp b/lib/Sema/AttributeList.cpp index 789c17b7f0..6aa9690476 100644 --- a/lib/Sema/AttributeList.cpp +++ b/lib/Sema/AttributeList.cpp @@ -133,5 +133,6 @@ AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) { .Case("launch_bounds", AT_launch_bounds) .Case("common", AT_common) .Case("nocommon", AT_nocommon) + .Case("uuid", AT_uuid) .Default(UnknownAttribute); } diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index e9f885e62f..b0e022fd33 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -2516,7 +2516,29 @@ static void HandleNSReturnsRetainedAttr(Decl *d, const AttributeList &Attr, static bool isKnownDeclSpecAttr(const AttributeList &Attr) { return Attr.getKind() == AttributeList::AT_dllimport || - Attr.getKind() == AttributeList::AT_dllexport; + Attr.getKind() == AttributeList::AT_dllexport || + Attr.getKind() == AttributeList::AT_uuid; +} + +//===----------------------------------------------------------------------===// +// Microsoft specific attribute handlers. +//===----------------------------------------------------------------------===// + +static void HandleUuidAttr(Decl *d, const AttributeList &Attr, Sema &S) { + if (S.LangOpts.Microsoft || S.LangOpts.Borland) { + // check the attribute arguments. + if (Attr.getNumArgs() != 1) { + S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 1; + return; + } + Expr *Arg = Attr.getArg(0); + StringLiteral *Str = dyn_cast<StringLiteral>(Arg); + + d->addAttr(::new (S.Context) UuidAttr(Attr.getLoc(), S.Context, + Str->getString())); + } else { + S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << "uuid"; + } } //===----------------------------------------------------------------------===// @@ -2646,6 +2668,9 @@ static void ProcessDeclAttribute(Scope *scope, Decl *D, case AttributeList::AT_pascal: HandleCallConvAttr(D, Attr, S); break; + case AttributeList::AT_uuid: + HandleUuidAttr(D, Attr, S); + break; default: // Ask target about the attribute. const TargetAttributesSema &TargetAttrs = S.getTargetAttributesSema(); |