[cfe-dev] Visual C++ __interface keyword

John McCall rjmccall at apple.com
Sun Aug 12 15:22:00 PDT 2012


On Aug 12, 2012, at 2:11 PM, David Robins wrote:
> I'm running into problems compiling code that uses the
> Microsoft-specific __interface keyword. Although it's been implemented
> in clang as an alias for struct, it's missing the automatic pure virtual
> specifier for member functions that is implied by the keyword.
> 
> I understand that implementing MS-specific keywords likely isn't high on
> anyone's list, and was hoping to be able to make the change myself if it
> is something that would be accepted as a patch (provided it conforms to
> the coding standards, has tests, etc.; I have read the internals/hacking
> pages).
> 
> While not new to compilers generally I'm new to clang, so pointers for
> this task would be appreciated. As I see it I first have to upgrade
> __interface to a keyword in TokenKinds.def so it can be appropriately
> detected at higher levels (and still mostly treated as a struct) -
> perhaps set a flag in CXXRecordDecl, and apply the pure/virtual
> specifiers when a method within the interface is parsed?

Can __interface be used in all the same ways as a standard class-key?

That is, can you write:
  __interface foo; // forward declaration
or
  __interface foo *ptr = 0; // elaborated type specifier

If so, the right way to model this in the AST is to add it as a new alternative
to both TypeSpecifierType (in clang/Basic/Specifiers.h) and TagTypeKind
(in clang/AST/Type.h).  You might have to audit all the places that store the
latter to make sure they don't stuff it into a 2-bit bitfield.  You'll also have to
audit all the users to make sure that they do the right thing on the new
alternative.

If not, it would be less invasive to model this as an attribute and either
  (1) make __interface a macro that expands to 'struct [[ms_interface]]' or
  (2) make the parser recognize the keyword and add the attribute.

John.



More information about the cfe-dev mailing list