[Proposal] How i plan to implement operator __uuidof

Here is my plan on how to implement the __uuidof operator.
doc: http://msdn.microsoft.com/en-us/library/zaah6a61(v=VS.90).aspx

For each class with an uuid attribute, clang would insert an implicit declaration of type: VarDecl.

For example:

struct __declspec(uuid(“00000000-0000-0000-0000-000000000001”))
type_uuid { };

will add an implicit VarDecl looking like this:
_GUID implicit_no_name = { 0, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 1} };

A _GUID structure looks like this:

struct _GUID {
unsigned long Data1;
unsigned short Data2;
unsigned short Data3;
unsigned char Data4[ 8 ];
};

A pointer to the implicit VarDecl object will be saved in the UuidAttr class for later retrieval.
__uuidof will return a const reference to that VarDecl object.

Also, given this code:

template <const _GUID*> class T {};

T<&__uuidof(var)> foo;

The function CheckTemplateArgumentAddressOfObjectOrFunction will need to be modified to accept an expression of type CXXUuidofExpr as “ArgIn”

All this only under -fms-extensions of course…
Any comments or potential problems with this approach?

Ugh. I think the vast majority of AST clients would need to be updated to know about these special variable declarations.

If all you’re worried about is how to represent __uuidof as a template argument, I think we should just keep it as a __uuidof expression, if we can make that work. Doug?

John.

Yes I agree if we could represent __uuidof as a template argument then the need for the special variable is gone… that would be ideal.

I, too, like that idea.

  • Doug

Ok I decided to postpone the __uuidof implementation anyway. It is
used in MSVC's MFC/COM header files. Currently I am focusing on making
clang parses the MSVC C++ standard lib (vector, list, algorithm).

Ok see r130381.