[cfe-commits] r163013 - in /cfe/trunk: include/clang-c/ include/clang/AST/ include/clang/Basic/ include/clang/Sema/ lib/AST/ lib/CodeGen/ lib/Parse/ lib/Sema/ lib/Serialization/ test/Parser/ tools/libclang/

David Robins llvm at davidrobins.net
Tue Sep 4 11:02:38 PDT 2012


I don't have any sort of commit access. Joao had kindly offerred to
commit the change for me, and I didn't know what further approval was
needed. This is my first Clang patch and I tried as best I could to
follow the available documentation and standards.

The diff that I posted doesn't include changed line endings, so you
could review that; I can resend it if you wish.

On Tue, Sep 04, 2012 at 12:42:55PM -0400, Chandler Carruth wrote:
   On Fri, Aug 31, 2012 at 2:45 PM, Joao Matos <ripzonetriton at gmail.com>
   wrote:

     Author: triton
     Date: Fri Aug 31 13:45:21 2012
     New Revision: 163013

     URL: http://llvm.org/viewvc/llvm-project?rev=163013&view=rev
     Log:
     Improved MSVC __interface support by adding first class support for it,
     instead of aliasing to "struct" which had some incorrect behaviour.
     Patch by David Robins.

   For the record, I do not think this should have been committed. David
   mailed the patch and you reviewed it, but both of you are in the
   'commit-after-approval' group as far as I'm aware. This is clearly not an
   obvious patch, it as a huge extension to the Clang AST.
   John McCall reviewed previous versions of this patch and suggested the
   changes that led to the current form. Why didn't you wait until he
   approved it? Was there some email that didn't make it to the list
   approving the patch? (I know that email was getting dropped with earlier
   phases of the review for that patch...)
   I don't think we can just revert this though because so many patches have
   gone in behind it.
   I can't even post-commit review this because several files have had *all*
   lines changed due to your client thrashing line endings!!! This is really
   terrible. I know we already discussed this some, but let me re-iterate:
   you must not submit patches with thrashed line endings like this.
   John, thoughts on how to handle this? How can you effectively review it?
   I can offer to back out the entire sequence of patches and essentially
   return us to before this patch went in, and then perhaps we can get
   meaningful diffs that you can review?
   A 

     Modified:
     A  A  cfe/trunk/include/clang-c/Index.h
     A  A  cfe/trunk/include/clang/AST/CanonicalType.h
     A  A  cfe/trunk/include/clang/AST/Decl.h
     A  A  cfe/trunk/include/clang/AST/DeclCXX.h
     A  A  cfe/trunk/include/clang/AST/Type.h
     A  A  cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
     A  A  cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
     A  A  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
     A  A  cfe/trunk/include/clang/Basic/Specifiers.h
     A  A  cfe/trunk/include/clang/Basic/TokenKinds.def
     A  A  cfe/trunk/include/clang/Sema/DeclSpec.h
     A  A  cfe/trunk/lib/AST/DeclCXX.cpp
     A  A  cfe/trunk/lib/AST/MicrosoftMangle.cpp
     A  A  cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
     A  A  cfe/trunk/lib/AST/Type.cpp
     A  A  cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
     A  A  cfe/trunk/lib/Parse/ParseDecl.cpp
     A  A  cfe/trunk/lib/Parse/ParseDeclCXX.cpp
     A  A  cfe/trunk/lib/Sema/DeclSpec.cpp
     A  A  cfe/trunk/lib/Sema/SemaCodeComplete.cpp
     A  A  cfe/trunk/lib/Sema/SemaDecl.cpp
     A  A  cfe/trunk/lib/Sema/SemaDeclCXX.cpp
     A  A  cfe/trunk/lib/Sema/SemaExprCXX.cpp
     A  A  cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp
     A  A  cfe/trunk/lib/Sema/SemaType.cpp
     A  A  cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
     A  A  cfe/trunk/test/Parser/MicrosoftExtensions.cpp
     A  A  cfe/trunk/tools/libclang/CIndexCXX.cpp
     A  A  cfe/trunk/tools/libclang/CIndexUSRs.cpp
     A  A  cfe/trunk/tools/libclang/IndexingContext.cpp

     Modified: cfe/trunk/include/clang-c/Index.h
     URL:
     http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=163013&r1=163012&r2=163013&view=diff
     ==============================================================================
     --- cfe/trunk/include/clang-c/Index.h (original)
     +++ cfe/trunk/include/clang-c/Index.h Fri Aug 31 13:45:21 2012
     @@ -4962,13 +4962,14 @@
     A  A CXIdxEntity_CXXStaticVariable A  A  = 19,
     A  A CXIdxEntity_CXXStaticMethod A  A  A  = 20,
     A  A CXIdxEntity_CXXInstanceMethod A  A  = 21,
     - A CXIdxEntity_CXXConstructor A  A  A  A = 22,
     - A CXIdxEntity_CXXDestructor A  A  A  A  = 23,
     - A CXIdxEntity_CXXConversionFunction = 24,
     - A CXIdxEntity_CXXTypeAlias A  A  A  A  A = 25
     -
     -} CXIdxEntityKind;
     -
     + A CXIdxEntity_CXXConstructor A  A  A  A = 22,
     + A CXIdxEntity_CXXDestructor A  A  A  A  = 23,
     + A CXIdxEntity_CXXConversionFunction = 24,
     + A CXIdxEntity_CXXTypeAlias A  A  A  A  A = 25,
     + A CXIdxEntity_CXXInterface A  A  A  A  A = 26
     +
     +} CXIdxEntityKind;
     +
     A typedef enum {
     A  A CXIdxEntityLang_None = 0,
     A  A CXIdxEntityLang_C A  A = 1,

     Modified: cfe/trunk/include/clang/AST/CanonicalType.h
     URL:
     http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/CanonicalType.h?rev=163013&r1=163012&r2=163013&view=diff
     ==============================================================================
     --- cfe/trunk/include/clang/AST/CanonicalType.h (original)
     +++ cfe/trunk/include/clang/AST/CanonicalType.h Fri Aug 31 13:45:21 2012
     @@ -276,6 +276,7 @@
     A  A LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool,
     isMemberFunctionPointerType)
     A  A LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isClassType)
     A  A LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isStructureType)
     + A LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isInterfaceType)
     A  A LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isStructureOrClassType)
     A  A LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isUnionType)
     A  A LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isComplexIntegerType)

     Modified: cfe/trunk/include/clang/AST/Decl.h
     URL:
     http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=163013&r1=163012&r2=163013&view=diff
     ==============================================================================
     --- cfe/trunk/include/clang/AST/Decl.h (original)
     +++ cfe/trunk/include/clang/AST/Decl.h Fri Aug 31 13:45:21 2012
     @@ -2448,7 +2448,7 @@
     A private:
     A  A // FIXME: This can be packed into the bitfields in Decl.
     A  A /// TagDeclKind - The TagKind enum.
     - A unsigned TagDeclKind : 2;
     + A unsigned TagDeclKind : 3;

     A  A /// IsCompleteDefinition - True if this is a definition ("struct
     foo
     A  A /// {};"), false if it is a declaration ("struct foo;"). A It is
     not
     @@ -2625,6 +2625,7 @@
     A  A void setTagKind(TagKind TK) { TagDeclKind = TK; }

     A  A bool isStruct() const { return getTagKind() == TTK_Struct; }
     + A bool isInterface() const { return getTagKind() == TTK_Interface; }
     A  A bool isClass() A const { return getTagKind() == TTK_Class; }
     A  A bool isUnion() A const { return getTagKind() == TTK_Union; }
     A  A bool isEnum() A  const { return getTagKind() == TTK_Enum; }

     Modified: cfe/trunk/include/clang/AST/DeclCXX.h
     URL:
     http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=163013&r1=163012&r2=163013&view=diff
     ==============================================================================
     --- cfe/trunk/include/clang/AST/DeclCXX.h (original)
     +++ cfe/trunk/include/clang/AST/DeclCXX.h Fri Aug 31 13:45:21 2012
     @@ -1553,13 +1553,15 @@
     A  A bool isVolatile() { return
     getType()->castAs<FunctionType>()->isVolatile(); }

     A  A bool isVirtual() const {
     - A  A CXXMethodDecl *CD =
     - A  A 
     A cast<CXXMethodDecl>(const_cast<CXXMethodDecl*>(this)->getCanonicalDecl());
     -
     - A  A if (CD->isVirtualAsWritten())
     - A  A  A return true;
     -
     - A  A return (CD->begin_overridden_methods() !=
     CD->end_overridden_methods());
     + A  A CXXMethodDecl *CD =
     + A  A 
     A cast<CXXMethodDecl>(const_cast<CXXMethodDecl*>(this)->getCanonicalDecl());
     +
     + A  A // Methods declared in interfaces are automatically (pure)
     virtual
     + A  A if (CD->isVirtualAsWritten() ||
     + A  A  A  A CD->getParent()->getTagKind() == TTK_Interface)
     + A  A  A return true;
     +
     + A  A return (CD->begin_overridden_methods() !=
     CD->end_overridden_methods());
     A  A }

     A  A /// \brief Determine whether this is a usual deallocation function

     Modified: cfe/trunk/include/clang/AST/Type.h
     URL:
     http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=163013&r1=163012&r2=163013&view=diff
     ==============================================================================
     --- cfe/trunk/include/clang/AST/Type.h (original)
     +++ cfe/trunk/include/clang/AST/Type.h Fri Aug 31 13:45:21 2012
     @@ -1512,6 +1512,7 @@
     A  A bool isRecordType() const;
     A  A bool isClassType() const;
     A  A bool isStructureType() const;
     + A bool isInterfaceType() const;
     A  A bool isStructureOrClassType() const;
     A  A bool isUnionType() const;
     A  A bool isComplexIntegerType() const; A  A  A  A  A  A // GCC _Complex
     integer type.
     @@ -3796,6 +3797,8 @@
     A enum TagTypeKind {
     A  A /// \brief The "struct" keyword.
     A  A TTK_Struct,
     + A /// \brief The "__interface" keyword.
     + A TTK_Interface,
     A  A /// \brief The "union" keyword.
     A  A TTK_Union,
     A  A /// \brief The "class" keyword.
     @@ -3809,6 +3812,8 @@
     A enum ElaboratedTypeKeyword {
     A  A /// \brief The "struct" keyword introduces the
     elaborated-type-specifier.
     A  A ETK_Struct,
     + A /// \brief The "__interface" keyword introduces the
     elaborated-type-specifier.
     + A ETK_Interface,
     A  A /// \brief The "union" keyword introduces the
     elaborated-type-specifier.
     A  A ETK_Union,
     A  A /// \brief The "class" keyword introduces the
     elaborated-type-specifier.

     Modified: cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
     URL:
     http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td?rev=163013&r1=163012&r2=163013&view=diff
     ==============================================================================
     --- cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td (original)
     +++ cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td Fri Aug 31
     13:45:21 2012
     @@ -134,13 +134,13 @@
     A def err_odr_function_type_inconsistent : Error<
     A  A "external function %0 declared with incompatible types in different
     "
     A  A "translation units (%1 vs. %2)">;
     -def warn_odr_tag_type_inconsistent : Warning<
     - A "type %0 has incompatible definitions in different translation
     units">;
     -def note_odr_tag_kind_here: Note<
     - A "%0 is a %select{struct|union|class|enum}1 here">;
     -def note_odr_field : Note<"field %0 has type %1 here">;
     -def note_odr_missing_field : Note<"no corresponding field here">;
     -def note_odr_bit_field : Note<"bit-field %0 with type %1 and length %2
     here">;
     +def warn_odr_tag_type_inconsistent : Warning<
     + A "type %0 has incompatible definitions in different translation
     units">;
     +def note_odr_tag_kind_here: Note<
     + A "%0 is a %select{struct|interface|union|class|enum}1 here">;
     +def note_odr_field : Note<"field %0 has type %1 here">;
     +def note_odr_missing_field : Note<"no corresponding field here">;
     +def note_odr_bit_field : Note<"bit-field %0 with type %1 and length %2
     here">;
     A def note_odr_not_bit_field : Note<"field %0 is not a bit-field">;
     A def note_odr_base : Note<"class has base type %0">;
     A def note_odr_virtual_base : Note<

     Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
     URL:
     http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=163013&r1=163012&r2=163013&view=diff
     ==============================================================================
     --- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
     +++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Fri Aug 31
     13:45:21 2012
     @@ -573,13 +573,13 @@
     A def err_typename_refers_to_non_type_template : Error<
     A  A "typename specifier refers to a non-template">;
     A def err_expected_type_name_after_typename : Error<
     - A "expected an identifier or template-id after '::'">;
     -def err_explicit_spec_non_template : Error<
     - A "explicit %select{specialization|instantiation}0 of non-template "
     - A "%select{class|struct|union}1 %2">;
     -
     -def err_default_template_template_parameter_not_template : Error<
     - A "default template argument for a template template parameter must be
     a class "
     + A "expected an identifier or template-id after '::'">;
     +def err_explicit_spec_non_template : Error<
     + A "explicit %select{specialization|instantiation}0 of non-template "
     + A "%select{class|struct|union|interface}1 %2">;
     +
     +def err_default_template_template_parameter_not_template : Error<
     + A "default template argument for a template template parameter must be
     a class "
     A  A "template">;

     A def err_ctor_init_missing_comma : Error<

     Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
     URL:
     http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=163013&r1=163012&r2=163013&view=diff
     ==============================================================================
     --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
     +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Aug 31
     13:45:21 2012
     @@ -793,16 +793,17 @@
     A  A "friends cannot be members of the declaring class">;
     A def warn_cxx98_compat_friend_is_member : Warning<
     A  A "friend declaration naming a member of the declaring class is
     incompatible "
     - A "with C++98">, InGroup<CXX98Compat>, DefaultIgnore;
     -def ext_unelaborated_friend_type : ExtWarn<
     - A "unelaborated friend declaration is a C++11 extension; specify "
     - A "'%select{struct|union|class|enum}0' to befriend %1">,
     InGroup<CXX11>;
     -def warn_cxx98_compat_unelaborated_friend_type : Warning<
     - A "befriending %1 without '%select{struct|union|class|enum}0' keyword
     is "
     - A "incompatible with C++98">, InGroup<CXX98Compat>, DefaultIgnore;
     -def err_qualified_friend_not_found : Error<
     - A "no function named %0 with type %1 was found in the specified
     scope">;
     -def err_introducing_special_friend : Error<
     + A "with C++98">, InGroup<CXX98Compat>, DefaultIgnore;
     +def ext_unelaborated_friend_type : ExtWarn<
     + A "unelaborated friend declaration is a C++11 extension; specify "
     + A "'%select{struct|interface|union|class|enum}0' to befriend %1">,
     + A InGroup<CXX11>;
     +def warn_cxx98_compat_unelaborated_friend_type : Warning<
     + A "befriending %1 without
     '%select{struct|interface|union|class|enum}0' "
     + A "keyword is incompatible with C++98">, InGroup<CXX98Compat>,
     DefaultIgnore;
     +def err_qualified_friend_not_found : Error<
     + A "no function named %0 with type %1 was found in the specified
     scope">;
     +def err_introducing_special_friend : Error<
     A  A "must use a qualified name when declaring a %select{constructor|"
     A  A "destructor|conversion operator}0 as a friend">;
     A def err_tagless_friend_type_template : Error<
     @@ -1114,14 +1115,14 @@
     A def err_constructor_return_type : Error<
     A  A "constructor cannot have a return type">;
     A def err_constructor_redeclared : Error<"constructor cannot be
     redeclared">;
     -def err_constructor_byvalue_arg : Error<
     - A "copy constructor must pass its first argument by reference">;
     -def warn_no_constructor_for_refconst : Warning<
     - A "%select{struct|union|class|enum}0 %1 does not declare any
     constructor to "
     - A "initialize its non-modifiable members">;
     -def note_refconst_member_not_initialized : Note<
     - A "%select{const|reference}0 member %1 will never be initialized">;
     -def ext_ms_explicit_constructor_call : ExtWarn<
     +def err_constructor_byvalue_arg : Error<
     + A "copy constructor must pass its first argument by reference">;
     +def warn_no_constructor_for_refconst : Warning<
     + A "%select{struct|interface|union|class|enum}0 %1 does not declare any
     "
     + A "constructor to initialize its non-modifiable members">;
     +def note_refconst_member_not_initialized : Note<
     + A "%select{const|reference}0 member %1 will never be initialized">;
     +def ext_ms_explicit_constructor_call : ExtWarn<
     A  A "explicit constructor calls are a Microsoft extension">,
     InGroup<Microsoft>;

     A // C++ destructors
     @@ -1308,15 +1309,16 @@
     A def err_illegal_decl_array_of_auto : Error<
     A  A "'%0' declared as array of %1">;
     A def err_new_array_of_auto : Error<
     - A "cannot allocate array of 'auto'">;
     -def err_auto_not_allowed : Error<
     - A "'auto' not allowed %select{in function prototype|in non-static
     struct member"
     - A "|in non-static union member|in non-static class member|in exception
     declaration"
     - A "|in template parameter|in block literal|in template argument"
     - A "|in typedef|in type alias|in function return type|here}0">;
     -def err_auto_var_requires_init : Error<
     - A "declaration of variable %0 with type %1 requires an initializer">;
     -def err_auto_new_requires_ctor_arg : Error<
     + A "cannot allocate array of 'auto'">;
     +def err_auto_not_allowed : Error<
     + A "'auto' not allowed %select{in function prototype|in non-static
     struct member"
     + A "|in non-static union member|in non-static class member|in interface
     member"
     + A "|in exception declaration|in template parameter|in block literal"
     + A "|in template argument|in typedef|in type alias|in function return
     type"
     + A "|here}0">;
     +def err_auto_var_requires_init : Error<
     + A "declaration of variable %0 with type %1 requires an initializer">;
     +def err_auto_new_requires_ctor_arg : Error<
     A  A "new expression for type %0 requires a constructor argument">;
     A def err_auto_new_requires_parens : Error<
     A  A "new expression for type %0 cannot use list-initialization">;
     @@ -1436,13 +1438,13 @@
     A  A "'constexpr' specifier is incompatible with C++98">,
     A  A InGroup<CXX98Compat>, DefaultIgnore;
     A def err_invalid_constexpr : Error<
     - A "%select{function parameter|typedef|non-static data member}0 "
     - A "cannot be constexpr">;
     -def err_constexpr_tag : Error<
     - A "%select{class|struct|union|enum}0 cannot be marked constexpr">;
     -def err_constexpr_dtor : Error<"destructor cannot be marked
     constexpr">;
     -def err_constexpr_no_declarators : Error<
     - A "constexpr can only be used in variable and function declarations">;
     + A "%select{function parameter|typedef|non-static data member}0 "
     + A "cannot be constexpr">;
     +def err_constexpr_tag : Error<
     + A "%select{class|struct|interface|union|enum}0 cannot be marked
     constexpr">;
     +def err_constexpr_dtor : Error<"destructor cannot be marked
     constexpr">;
     +def err_constexpr_no_declarators : Error<
     + A "constexpr can only be used in variable and function declarations">;
     A def err_invalid_constexpr_var_decl : Error<
     A  A "constexpr variable declaration must be a definition">;
     A def err_constexpr_static_mem_var_requires_init : Error<
     @@ -1454,17 +1456,18 @@
     A def err_constexpr_redecl_mismatch : Error<
     A  A "%select{non-constexpr declaration of %0 follows constexpr
     declaration"
     A  A "|constexpr declaration of %0 follows non-constexpr
     declaration}1">;
     -def err_constexpr_virtual : Error<"virtual function cannot be
     constexpr">;
     -def err_constexpr_virtual_base : Error<
     - A "constexpr %select{member function|constructor}0 not allowed in "
     - A "%select{class|struct}1 with virtual base
     %plural{1:class|:classes}2">;
     -def note_non_literal_incomplete : Note<
     - A "incomplete type %0 is not a literal type">;
     -def note_non_literal_virtual_base : Note<"%select{class|struct}0 with
     virtual "
     - A "base %plural{1:class|:classes}1 is not a literal type">;
     -def note_constexpr_virtual_base_here : Note<"virtual base class
     declared here">;
     -def err_constexpr_non_literal_return : Error<
     - A "constexpr function's return type %0 is not a literal type">;
     +def err_constexpr_virtual : Error<"virtual function cannot be
     constexpr">;
     +def err_constexpr_virtual_base : Error<
     + A "constexpr %select{member function|constructor}0 not allowed in "
     + A "%select{struct|interface|class}1 with virtual base "
     + A "%plural{1:class|:classes}2">;
     +def note_non_literal_incomplete : Note<
     + A "incomplete type %0 is not a literal type">;
     +def note_non_literal_virtual_base :
     Note<"%select{struct|interface|class}0 "
     + A "with virtual base %plural{1:class|:classes}1 is not a literal
     type">;
     +def note_constexpr_virtual_base_here : Note<"virtual base class
     declared here">;
     +def err_constexpr_non_literal_return : Error<
     + A "constexpr function's return type %0 is not a literal type">;
     A def err_constexpr_non_literal_param : Error<
     A  A "constexpr %select{function|constructor}1's %ordinal0 parameter
     type %2 is "
     A  A "not a literal type">;
     @@ -1697,13 +1700,15 @@
     A  A "__declspec attribute %0 is not supported">,
     A  A InGroup<IgnoredAttributes>;
     A def warn_attribute_invalid_on_stmt : Warning<
     - A "attribute %0 cannot be specified on a statement">,
     - A InGroup<IgnoredAttributes>;
     -def warn_declspec_attribute_ignored : Warning<
     - A "attribute %0 is ignored, place it after
     \"%select{class|struct|union|enum}1\" to apply attribute to type
     declaration">, InGroup<IgnoredAttributes>;
     -def warn_attribute_precede_definition : Warning<
     - A "attribute declaration must precede definition">,
     - A InGroup<IgnoredAttributes>;
     + A "attribute %0 cannot be specified on a statement">,
     + A InGroup<IgnoredAttributes>;
     +def warn_declspec_attribute_ignored : Warning<
     + A "attribute %0 is ignored, place it after "
     + A "\"%select{class|struct|union|interface|enum}1\" to apply attribute
     to "
     + A "type declaration">, InGroup<IgnoredAttributes>;
     +def warn_attribute_precede_definition : Warning<
     + A "attribute declaration must precede definition">,
     + A InGroup<IgnoredAttributes>;
     A def warn_attribute_void_function_method : Warning<
     A  A "attribute %0 cannot be applied to "
     A  A "%select{functions|Objective-C method}1 without return value">,
     @@ -3178,30 +3183,31 @@
     A def err_tag_reference_non_tag : Error<
     A  A "elaborated type refers to %select{a non-tag type|a typedef|a type
     alias|a template|a type alias template}0">;
     A def err_tag_reference_conflict : Error<
     - A "implicit declaration introduced by elaborated type conflicts with "
     - A "%select{a declaration|a typedef|a type alias|a template}0 of the
     same name">;
     -def err_dependent_tag_decl : Error<
     - A "%select{declaration|definition}0 of
     %select{struct|union|class|enum}1 "
     - A "in a dependent scope">;
     -def err_tag_definition_of_typedef : Error<
     - A "definition of type %0 conflicts with %select{typedef|type alias}1
     of the same name">;
     -def err_conflicting_types : Error<"conflicting types for %0">;
     + A "implicit declaration introduced by elaborated type conflicts with "
     + A "%select{a declaration|a typedef|a type alias|a template}0 of the
     same name">;
     +def err_dependent_tag_decl : Error<
     + A "%select{declaration|definition}0 of "
     + A "%select{struct|interface|union|class|enum}1 in a dependent scope">;
     +def err_tag_definition_of_typedef : Error<
     + A "definition of type %0 conflicts with %select{typedef|type alias}1
     of the same name">;
     +def err_conflicting_types : Error<"conflicting types for %0">;
     A def err_nested_redefinition : Error<"nested redefinition of %0">;
     -def err_use_with_wrong_tag : Error<
     - A "use of %0 with tag type that does not match previous declaration">;
     -def warn_struct_class_tag_mismatch : Warning<
     - A  A "%select{struct|class}0%select{| template}1 %2 was previously
     declared "
     - A  A "as a %select{class|struct}0%select{| template}1">,
     - A  A InGroup<MismatchedTags>, DefaultIgnore;
     -def warn_struct_class_previous_tag_mismatch : Warning<
     - A  A "%2 defined as a %select{struct|class}0%select{| template}1 here
     but "
     - A  A "previously declared as a %select{class|struct}0%select{|
     template}1">,
     - A  A  InGroup<MismatchedTags>, DefaultIgnore;
     -def note_struct_class_suggestion : Note<
     - A  A "did you mean %select{struct|class}0 here?">;
     -def ext_forward_ref_enum : Extension<
     - A "ISO C forbids forward references to 'enum' types">;
     -def err_forward_ref_enum : Error<
     +def err_use_with_wrong_tag : Error<
     + A "use of %0 with tag type that does not match previous declaration">;
     +def warn_struct_class_tag_mismatch : Warning<
     + A  A "%select{struct|interface|class}0%select{| template}1 %2 was
     previously "
     + A  A "declared as a %select{struct|interface|class}3%select{|
     template}1">,
     + A  A InGroup<MismatchedTags>, DefaultIgnore;
     +def warn_struct_class_previous_tag_mismatch : Warning<
     + A  A "%2 defined as %select{a struct|an interface|a class}0%select{|
     template}1 "
     + A  A "here but previously declared as "
     + A  A "%select{a struct|an interface|a class}3%select{| template}1">,
     + A  A  InGroup<MismatchedTags>, DefaultIgnore;
     +def note_struct_class_suggestion : Note<
     + A  A "did you mean %select{struct|interface|class}0 here?">;
     +def ext_forward_ref_enum : Extension<
     + A "ISO C forbids forward references to 'enum' types">;
     +def err_forward_ref_enum : Error<
     A  A "ISO C++ forbids forward references to 'enum' types">;
     A def ext_ms_forward_ref_enum : Extension<
     A  A "forward references to 'enum' types are a Microsoft extension">,
     InGroup<Microsoft>;
     @@ -3239,17 +3245,19 @@
     A def warn_array_new_too_large : Warning<"array is too large (%0
     elements)">,
     A  A // FIXME PR11644: ", will throw std::bad_array_new_length at
     runtime"
     A  A InGroup<DiagGroup<"bad-array-new-length">>;
     -
     -// -Wpadded, -Wpacked
     -def warn_padded_struct_field : Warning<
     - A "padding %select{struct|class}0 %1 with %2
     %select{byte|bit}3%select{|s}4 "
     - A "to align %5">, InGroup<Padded>, DefaultIgnore;
     -def warn_padded_struct_anon_field : Warning<
     - A "padding %select{struct|class}0 %1 with %2
     %select{byte|bit}3%select{|s}4 "
     - A "to align anonymous bit-field">, InGroup<Padded>, DefaultIgnore;
     -def warn_padded_struct_size : Warning<
     - A "padding size of %0 with %1 %select{byte|bit}2%select{|s}3 "
     - A "to alignment boundary">, InGroup<Padded>, DefaultIgnore;
     +
     +// -Wpadded, -Wpacked
     +def warn_padded_struct_field : Warning<
     + A "padding %select{struct|interface|class}0 %1 with %2 "
     + A "%select{byte|bit}3%select{|s}4 to align %5">,
     + A InGroup<Padded>, DefaultIgnore;
     +def warn_padded_struct_anon_field : Warning<
     + A "padding %select{struct|interface|class}0 %1 with %2 "
     + A "%select{byte|bit}3%select{|s}4 to align anonymous bit-field">,
     + A InGroup<Padded>, DefaultIgnore;
     +def warn_padded_struct_size : Warning<
     + A "padding size of %0 with %1 %select{byte|bit}2%select{|s}3 "
     + A "to alignment boundary">, InGroup<Padded>, DefaultIgnore;
     A def warn_unnecessary_packed : Warning<
     A  A "packed attribute is unnecessary for %0">, InGroup<Packed>,
     DefaultIgnore;

     @@ -3491,20 +3499,22 @@
     A def ext_flexible_array_in_array : Extension<
     A  A "%0 may not be used as an array element due to flexible array
     member">,
     A  A InGroup<FlexibleArrayExtensions>;
     -def err_flexible_array_init : Error<
     - A "initialization of flexible array member is not allowed">;
     -def ext_flexible_array_empty_aggregate_ms : Extension<
     - A "flexible array member %0 in otherwise empty %select{struct|class}1
     "
     - A "is a Microsoft extension">, InGroup<Microsoft>;
     -def ext_flexible_array_union_ms : Extension<
     - A "flexible array member %0 in a union is a Microsoft extension">,
     - A InGroup<Microsoft>;
     -def ext_flexible_array_empty_aggregate_gnu : Extension<
     - A "flexible array member %0 in otherwise empty %select{struct|class}1
     "
     - A "is a GNU extension">, InGroup<GNU>;
     -def ext_flexible_array_union_gnu : Extension<
     - A "flexible array member %0 in a union is a GNU extension">,
     InGroup<GNU>;
     -
     +def err_flexible_array_init : Error<
     + A "initialization of flexible array member is not allowed">;
     +def ext_flexible_array_empty_aggregate_ms : Extension<
     + A "flexible array member %0 in otherwise empty "
     + A "%select{struct|interface|union|class|enum}1 is a Microsoft
     extension">,
     + A InGroup<Microsoft>;
     +def ext_flexible_array_union_ms : Extension<
     + A "flexible array member %0 in a union is a Microsoft extension">,
     + A InGroup<Microsoft>;
     +def ext_flexible_array_empty_aggregate_gnu : Extension<
     + A "flexible array member %0 in otherwise empty "
     + A "%select{struct|interface|union|class|enum}1 is a GNU extension">,
     + A InGroup<GNU>;
     +def ext_flexible_array_union_gnu : Extension<
     + A "flexible array member %0 in a union is a GNU extension">,
     InGroup<GNU>;
     +
     A let CategoryName = "ARC Semantic Issue" in {

     A // ARC-mode diagnostics.
     @@ -4584,13 +4594,13 @@
     A  A "because namespace %1 does not enclose namespace %2">;
     A def err_invalid_declarator_global_scope : Error<
     A  A "definition or redeclaration of %0 cannot name the global scope">;
     -def err_invalid_declarator_in_function : Error<
     - A "definition or redeclaration of %0 not allowed inside a function">;
     -def err_not_tag_in_scope : Error<
     - A "no %select{struct|union|class|enum}0 named %1 in %2">;
     -
     -def err_no_typeid_with_fno_rtti : Error<
     - A "cannot use typeid with -fno-rtti">;
     +def err_invalid_declarator_in_function : Error<
     + A "definition or redeclaration of %0 not allowed inside a function">;
     +def err_not_tag_in_scope : Error<
     + A "no %select{struct|interface|union|class|enum}0 named %1 in %2">;
     +
     +def err_no_typeid_with_fno_rtti : Error<
     + A "cannot use typeid with -fno-rtti">;

     A def err_cannot_form_pointer_to_member_of_reference_type : Error<
     A  A "cannot form a pointer-to-member to member %0 of reference type
     %1">;
     @@ -5935,13 +5945,13 @@
     A  A "%select{template|partial|member}0 specialization cannot be "
     A  A "declared __module_private__">;
     A def err_module_private_local : Error<
     - A "%select{local variable|parameter|typedef}0 %1 cannot be declared "
     - A "__module_private__">;
     -def err_module_private_local_class : Error<
     - A "local %select{struct|union|class|enum}0 cannot be declared "
     - A "__module_private__">;
     -def err_module_private_definition : Error<
     - A "definition of %0 must be imported before it is required">;
     + A "%select{local variable|parameter|typedef}0 %1 cannot be declared "
     + A "__module_private__">;
     +def err_module_private_local_class : Error<
     + A "local %select{struct|interface|union|class|enum}0 cannot be
     declared "
     + A "__module_private__">;
     +def err_module_private_definition : Error<
     + A "definition of %0 must be imported before it is required">;
     A }

     A let CategoryName = "Documentation Issue" in {

     Modified: cfe/trunk/include/clang/Basic/Specifiers.h
     URL:
     http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Specifiers.h?rev=163013&r1=163012&r2=163013&view=diff
     ==============================================================================
     --- cfe/trunk/include/clang/Basic/Specifiers.h (original)
     +++ cfe/trunk/include/clang/Basic/Specifiers.h Fri Aug 31 13:45:21 2012
     @@ -50,12 +50,13 @@
     A  A  A TST_decimal64, A  A // _Decimal64
     A  A  A TST_decimal128, A  // _Decimal128
     A  A  A TST_enum,
     - A  A TST_union,
     - A  A TST_struct,
     - A  A TST_class, A  A  A  A // C++ class type
     - A  A TST_typename, A  A  // Typedef, C++ class-name or enum name, etc.
     - A  A TST_typeofType,
     - A  A TST_typeofExpr,
     + A  A TST_union,
     + A  A TST_struct,
     + A  A TST_class, A  A  A  A // C++ class type
     + A  A TST_interface, A  A // C++ (Microsoft-specific) __interface type
     + A  A TST_typename, A  A  // Typedef, C++ class-name or enum name, etc.
     + A  A TST_typeofType,
     + A  A TST_typeofExpr,
     A  A  A TST_decltype, A  A  // C++0x decltype
     A  A  A TST_underlyingType, // __underlying_type for C++0x
     A  A  A TST_auto, A  A  A  A  // C++0x auto

     Modified: cfe/trunk/include/clang/Basic/TokenKinds.def
     URL:
     http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TokenKinds.def?rev=163013&r1=163012&r2=163013&view=diff
     ==============================================================================
     --- cfe/trunk/include/clang/Basic/TokenKinds.def (original)
     +++ cfe/trunk/include/clang/Basic/TokenKinds.def Fri Aug 31 13:45:21
     2012
     @@ -505,6 +505,7 @@
     A KEYWORD(__single_inheritance A  A  A  A  A , KEYMS)
     A KEYWORD(__multiple_inheritance A  A  A  A , KEYMS)
     A KEYWORD(__virtual_inheritance A  A  A  A  , KEYMS)
     +KEYWORD(__interface A  A  A  A  A  A  A  A  A  , KEYMS)
     A ALIAS("__int8" A  A  A  A  A  , char A  A  A  , KEYMS)
     A ALIAS("__int16" A  A  A  A  A , short A  A  A , KEYMS)
     A ALIAS("__int32" A  A  A  A  A , int A  A  A  A , KEYMS)
     @@ -518,7 +519,6 @@
     A ALIAS("_uuidof" A  A  A  A  A , __uuidof A  , KEYMS | KEYBORLAND)
     A ALIAS("_inline" A  A  A  A  A , inline A  A  , KEYMS)
     A ALIAS("_declspec" A  A  A  A , __declspec , KEYMS)
     -ALIAS("__interface" A  A  A , struct A  A  , KEYMS)

     A // Borland Extensions which should be disabled in strict conformance
     mode.
     A ALIAS("_pascal" A  A  A , __pascal A  , KEYBORLAND)

     Modified: cfe/trunk/include/clang/Sema/DeclSpec.h
     URL:
     http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/DeclSpec.h?rev=163013&r1=163012&r2=163013&view=diff
     ==============================================================================
     --- cfe/trunk/include/clang/Sema/DeclSpec.h (original)
     +++ cfe/trunk/include/clang/Sema/DeclSpec.h Fri Aug 31 13:45:21 2012
     @@ -266,6 +266,7 @@
     A  A static const TST TST_enum = clang::TST_enum;
     A  A static const TST TST_union = clang::TST_union;
     A  A static const TST TST_struct = clang::TST_struct;
     + A static const TST TST_interface = clang::TST_interface;
     A  A static const TST TST_class = clang::TST_class;
     A  A static const TST TST_typename = clang::TST_typename;
     A  A static const TST TST_typeofType = clang::TST_typeofType;
     @@ -378,7 +379,8 @@
     A  A }
     A  A static bool isDeclRep(TST T) {
     A  A  A return (T == TST_enum || T == TST_struct ||
     - A  A  A  A  A  A T == TST_union || T == TST_class);
     + A  A  A  A  A  A T == TST_interface || T == TST_union ||
     + A  A  A  A  A  A T == TST_class);
     A  A }

     A  A DeclSpec(const DeclSpec&); A  A  A  // DO NOT IMPLEMENT

     Modified: cfe/trunk/lib/AST/DeclCXX.cpp
     URL:
     http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclCXX.cpp?rev=163013&r1=163012&r2=163013&view=diff
     ==============================================================================
     --- cfe/trunk/lib/AST/DeclCXX.cpp (original)
     +++ cfe/trunk/lib/AST/DeclCXX.cpp Fri Aug 31 13:45:21 2012
     @@ -463,13 +463,14 @@
     A }

     A void CXXRecordDecl::addedMember(Decl *D) {
     - A if (!D->isImplicit() &&
     - A  A  A !isa<FieldDecl>(D) &&
     - A  A  A !isa<IndirectFieldDecl>(D) &&
     - A  A  A (!isa<TagDecl>(D) || cast<TagDecl>(D)->getTagKind() ==
     TTK_Class))
     - A  A data().HasOnlyCMembers = false;
     -
     - A // Ignore friends and invalid declarations.
     + A if (!D->isImplicit() &&
     + A  A  A !isa<FieldDecl>(D) &&
     + A  A  A !isa<IndirectFieldDecl>(D) &&
     + A  A  A (!isa<TagDecl>(D) || cast<TagDecl>(D)->getTagKind() ==
     TTK_Class ||
     + A  A  A  A cast<TagDecl>(D)->getTagKind() == TTK_Interface))
     + A  A data().HasOnlyCMembers = false;
     +
     + A // Ignore friends and invalid declarations.
     A  A if (D->getFriendObjectKind() || D->isInvalidDecl())
     A  A  A return;

     @@ -933,13 +934,14 @@
     A  A  A if (Shadow->getDeclName().getNameKind()
     A  A  A  A  A  A == DeclarationName::CXXConversionFunctionName)
     A  A  A  A data().Conversions.addDecl(Shadow, Shadow->getAccess());
     -}
     -
     -bool CXXRecordDecl::isCLike() const {
     - A if (getTagKind() == TTK_Class || !TemplateOrInstantiation.isNull())
     - A  A return false;
     - A if (!hasDefinition())
     - A  A return true;
     +}
     +
     +bool CXXRecordDecl::isCLike() const {
     + A if (getTagKind() == TTK_Class || getTagKind() == TTK_Interface ||
     + A  A  A !TemplateOrInstantiation.isNull())
     + A  A return false;
     + A if (!hasDefinition())
     + A  A return true;

     A  A return isPOD() && data().HasOnlyCMembers;
     A }

     Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp
     URL:
     http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=163013&r1=163012&r2=163013&view=diff
     ==============================================================================
     --- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original)
     +++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Fri Aug 31 13:45:21 2012
     @@ -1270,12 +1270,13 @@
     A void MicrosoftCXXNameMangler::mangleType(const TagType *T) {
     A  A switch (T->getDecl()->getTagKind()) {
     A  A  A case TTK_Union:
     - A  A  A Out << 'T';
     - A  A  A break;
     - A  A case TTK_Struct:
     - A  A  A Out << 'U';
     - A  A  A break;
     - A  A case TTK_Class:
     + A  A  A Out << 'T';
     + A  A  A break;
     + A  A case TTK_Struct:
     + A  A case TTK_Interface:
     + A  A  A Out << 'U';
     + A  A  A break;
     + A  A case TTK_Class:
     A  A  A  A Out << 'V';
     A  A  A  A break;
     A  A  A case TTK_Enum:

     Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
     URL:
     http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=163013&r1=163012&r2=163013&view=diff
     ==============================================================================
     --- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
     +++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Fri Aug 31 13:45:21 2012
     @@ -2260,12 +2260,28 @@
     A  A }

     A  A // Use the externally-supplied field offset.
     - A return ExternalFieldOffset;
     -}
     -
     -void RecordLayoutBuilder::CheckFieldPadding(uint64_t Offset,
     - A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A 
     A uint64_t UnpaddedOffset,
     - A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A 
     A uint64_t UnpackedOffset,
     + A return ExternalFieldOffset;
     +}
     +
     +/// \brief Get diagnostic %select index for tag kind for
     +/// field padding diagnostic message.
     +/// WARNING: Indexes apply to particular diagnostics only!
     +///
     +/// \returns diagnostic %select index.
     +static unsigned getPaddingDiagFromTagKind(TagTypeKind Tag)
     +{
     + A switch (Tag) {
     + A  A case TTK_Struct: return 0;
     + A  A case TTK_Interface: return 1;
     + A  A case TTK_Class: A return 2;
     + A  A default: assert("Invalid tag kind for field padding
     diagnostic!");
     + A }
     + A return -1;
     +}
     +
     +void RecordLayoutBuilder::CheckFieldPadding(uint64_t Offset,
     + A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A 
     A uint64_t UnpaddedOffset,
     + A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A 
     A uint64_t UnpackedOffset,
     A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A 
     A unsigned UnpackedAlign,
     A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A bool
     isPacked,
     A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A 
     A const FieldDecl *D) {
     @@ -2288,20 +2304,20 @@
     A  A  A if (PadSize % CharBitNum == 0) {
     A  A  A  A PadSize = PadSize / CharBitNum;
     A  A  A  A InBits = false;
     - A  A }
     - A  A if (D->getIdentifier())
     - A  A  A Diag(D->getLocation(), diag::warn_padded_struct_field)
     - A  A  A  A  A << (D->getParent()->isStruct() ? 0 : 1) // struct|class
     - A  A  A  A  A << Context.getTypeDeclType(D->getParent())
     - A  A  A  A  A << PadSize
     - A  A  A  A  A << (InBits ? 1 : 0) /*(byte|bit)*/ << (PadSize > 1) //
     plural or not
     - A  A  A  A  A << D->getIdentifier();
     - A  A else
     - A  A  A Diag(D->getLocation(), diag::warn_padded_struct_anon_field)
     - A  A  A  A  A << (D->getParent()->isStruct() ? 0 : 1) // struct|class
     - A  A  A  A  A << Context.getTypeDeclType(D->getParent())
     - A  A  A  A  A << PadSize
     - A  A  A  A  A << (InBits ? 1 : 0) /*(byte|bit)*/ << (PadSize > 1); //
     plural or not
     + A  A }
     + A  A if (D->getIdentifier())
     + A  A  A Diag(D->getLocation(), diag::warn_padded_struct_field)
     + A  A  A  A  A <<
     getPaddingDiagFromTagKind(D->getParent()->getTagKind())
     + A  A  A  A  A << Context.getTypeDeclType(D->getParent())
     + A  A  A  A  A << PadSize
     + A  A  A  A  A << (InBits ? 1 : 0) /*(byte|bit)*/ << (PadSize > 1) //
     plural or not
     + A  A  A  A  A << D->getIdentifier();
     + A  A else
     + A  A  A Diag(D->getLocation(), diag::warn_padded_struct_anon_field)
     + A  A  A  A  A <<
     getPaddingDiagFromTagKind(D->getParent()->getTagKind())
     + A  A  A  A  A << Context.getTypeDeclType(D->getParent())
     + A  A  A  A  A << PadSize
     + A  A  A  A  A << (InBits ? 1 : 0) /*(byte|bit)*/ << (PadSize > 1); //
     plural or not
     A  A }

     A  A // Warn if we packed it unnecessarily. If the alignment is 1 byte
     don't

     Modified: cfe/trunk/lib/AST/Type.cpp
     URL:
     http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=163013&r1=163012&r2=163013&view=diff
     ==============================================================================
     --- cfe/trunk/lib/AST/Type.cpp (original)
     +++ cfe/trunk/lib/AST/Type.cpp Fri Aug 31 13:45:21 2012
     @@ -357,9 +357,15 @@
     A  A  A return RT->getDecl()->isStruct();
     A  A return false;
     A }
     +bool Type::isInterfaceType() const {
     + A if (const RecordType *RT = getAs<RecordType>())
     + A  A return RT->getDecl()->isInterface();
     + A return false;
     +}
     A bool Type::isStructureOrClassType() const {
     A  A if (const RecordType *RT = getAs<RecordType>())
     - A  A return RT->getDecl()->isStruct() || RT->getDecl()->isClass();
     + A  A return RT->getDecl()->isStruct() || RT->getDecl()->isClass() ||
     + A  A  A RT->getDecl()->isInterface();
     A  A return false;
     A }
     A bool Type::isVoidPointerType() const {
     @@ -1317,6 +1323,7 @@
     A  A case TST_typename: return ETK_Typename;
     A  A case TST_class: return ETK_Class;
     A  A case TST_struct: return ETK_Struct;
     + A case TST_interface: return ETK_Interface;
     A  A case TST_union: return ETK_Union;
     A  A case TST_enum: return ETK_Enum;
     A  A }
     @@ -1327,6 +1334,7 @@
     A  A switch(TypeSpec) {
     A  A case TST_class: return TTK_Class;
     A  A case TST_struct: return TTK_Struct;
     + A case TST_interface: return TTK_Interface;
     A  A case TST_union: return TTK_Union;
     A  A case TST_enum: return TTK_Enum;
     A  A }
     @@ -1339,6 +1347,7 @@
     A  A switch (Kind) {
     A  A case TTK_Class: return ETK_Class;
     A  A case TTK_Struct: return ETK_Struct;
     + A case TTK_Interface: return ETK_Interface;
     A  A case TTK_Union: return ETK_Union;
     A  A case TTK_Enum: return ETK_Enum;
     A  A }
     @@ -1350,6 +1359,7 @@
     A  A switch (Keyword) {
     A  A case ETK_Class: return TTK_Class;
     A  A case ETK_Struct: return TTK_Struct;
     + A case ETK_Interface: return TTK_Interface;
     A  A case ETK_Union: return TTK_Union;
     A  A case ETK_Enum: return TTK_Enum;
     A  A case ETK_None: // Fall through.
     @@ -1367,6 +1377,7 @@
     A  A  A return false;
     A  A case ETK_Class:
     A  A case ETK_Struct:
     + A case ETK_Interface:
     A  A case ETK_Union:
     A  A case ETK_Enum:
     A  A  A return true;
     @@ -1381,6 +1392,7 @@
     A  A case ETK_Typename: return "typename";
     A  A case ETK_Class: A return "class";
     A  A case ETK_Struct: return "struct";
     + A case ETK_Interface: return "__interface";
     A  A case ETK_Union: A return "union";
     A  A case ETK_Enum: A  return "enum";
     A  A }

     Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
     URL:
     http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=163013&r1=163012&r2=163013&view=diff
     ==============================================================================
     --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
     +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Fri Aug 31 13:45:21 2012
     @@ -520,13 +520,13 @@
     A  A const CXXRecordDecl *CXXDecl = dyn_cast<CXXRecordDecl>(RD);
     A  A unsigned Tag = 0;
     A  A if (CXXDecl) {
     - A  A RDName = getClassName(RD);
     - A  A Tag = llvm::dwarf::DW_TAG_class_type;
     - A }
     - A else if (RD->isStruct())
     - A  A Tag = llvm::dwarf::DW_TAG_structure_type;
     - A else if (RD->isUnion())
     - A  A Tag = llvm::dwarf::DW_TAG_union_type;
     + A  A RDName = getClassName(RD);
     + A  A Tag = llvm::dwarf::DW_TAG_class_type;
     + A }
     + A else if (RD->isStruct() || RD->isInterface())
     + A  A Tag = llvm::dwarf::DW_TAG_structure_type;
     + A else if (RD->isUnion())
     + A  A Tag = llvm::dwarf::DW_TAG_union_type;
     A  A else
     A  A  A llvm_unreachable("Unknown RecordDecl type!");

     Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
     URL:
     http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=163013&r1=163012&r2=163013&view=diff
     ==============================================================================
     --- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
     +++ cfe/trunk/lib/Parse/ParseDecl.cpp Fri Aug 31 13:45:21 2012
     @@ -1875,6 +1875,9 @@
     A  A  A  A  A TagName="union" ; FixitTagName = "union "
     ;TagKind=tok::kw_union ;break;
     A  A  A  A case DeclSpec::TST_struct:
     A  A  A  A  A TagName="struct"; FixitTagName = "struct
     ";TagKind=tok::kw_struct;break;
     + A  A  A case DeclSpec::TST_interface:
     + A  A  A  A TagName="__interface"; FixitTagName = "__interface ";
     + A  A  A  A TagKind=tok::kw___interface;break;
     A  A  A  A case DeclSpec::TST_class:
     A  A  A  A  A TagName="class" ; FixitTagName = "class "
     ;TagKind=tok::kw_class ;break;
     A  A  A }
     @@ -2709,6 +2712,7 @@
     A  A  A // class-specifier:
     A  A  A case tok::kw_class:
     A  A  A case tok::kw_struct:
     + A  A case tok::kw___interface:
     A  A  A case tok::kw_union: {
     A  A  A  A tok::TokenKind Kind = Tok.getKind();
     A  A  A  A ConsumeToken();
     @@ -3531,6 +3535,7 @@
     A  A  A // struct-or-union-specifier (C99) or class-specifier (C++)
     A  A case tok::kw_class:
     A  A case tok::kw_struct:
     + A case tok::kw___interface:
     A  A case tok::kw_union:
     A  A  A // enum-specifier
     A  A case tok::kw_enum:
     @@ -3602,6 +3607,7 @@
     A  A  A // struct-or-union-specifier (C99) or class-specifier (C++)
     A  A case tok::kw_class:
     A  A case tok::kw_struct:
     + A case tok::kw___interface:
     A  A case tok::kw_union:
     A  A  A // enum-specifier
     A  A case tok::kw_enum:
     @@ -3740,6 +3746,7 @@
     A  A case tok::kw_class:
     A  A case tok::kw_struct:
     A  A case tok::kw_union:
     + A case tok::kw___interface:
     A  A  A // enum-specifier
     A  A case tok::kw_enum:

     Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
     URL:
     http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=163013&r1=163012&r2=163013&view=diff
     ==============================================================================
     --- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
     +++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Fri Aug 31 13:45:21 2012
     @@ -1031,12 +1031,14 @@
     A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  const
     ParsedTemplateInfo &TemplateInfo,
     A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  AccessSpecifier AS,
     A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  bool EnteringContext,
     DeclSpecContext DSC) {
     - A DeclSpec::TST TagType;
     - A if (TagTokKind == tok::kw_struct)
     - A  A TagType = DeclSpec::TST_struct;
     - A else if (TagTokKind == tok::kw_class)
     - A  A TagType = DeclSpec::TST_class;
     - A else {
     + A DeclSpec::TST TagType;
     + A if (TagTokKind == tok::kw_struct)
     + A  A TagType = DeclSpec::TST_struct;
     + A else if (TagTokKind == tok::kw___interface)
     + A  A TagType = DeclSpec::TST_interface;
     + A else if (TagTokKind == tok::kw_class)
     + A  A TagType = DeclSpec::TST_class;
     + A else {
     A  A  A assert(TagTokKind == tok::kw_union && "Not a class specifier");
     A  A  A TagType = DeclSpec::TST_union;
     A  A }
     @@ -1148,13 +1150,14 @@
     A  A  A  A }

     A  A  A  A Diag(NameLoc, diag::err_explicit_spec_non_template)
     - A  A  A  A << (TemplateInfo.Kind ==
     ParsedTemplateInfo::ExplicitInstantiation)
     - A  A  A  A << (TagType == DeclSpec::TST_class? 0
     - A  A  A  A  A  A : TagType == DeclSpec::TST_struct? 1
     - A  A  A  A  A  A : 2)
     - A  A  A  A << Name
     - A  A  A  A << SourceRange(LAngleLoc, RAngleLoc);
     -
     + A  A  A  A << (TemplateInfo.Kind ==
     ParsedTemplateInfo::ExplicitInstantiation)
     + A  A  A  A << (TagType == DeclSpec::TST_class? 0
     + A  A  A  A  A  A : TagType == DeclSpec::TST_struct? 1
     + A  A  A  A  A  A : TagType == DeclSpec::TST_interface? 2
     + A  A  A  A  A  A : 3)
     + A  A  A  A << Name
     + A  A  A  A << SourceRange(LAngleLoc, RAngleLoc);
     +
     A  A  A  A // Strip off the last template parameter list if it was
     empty, since
     A  A  A  A // we've removed its template argument list.
     A  A  A  A if (TemplateParams && TemplateInfo.LastParameterListWasEmpty)
     {
     @@ -1240,14 +1243,13 @@
     A  A  A  A  A  A  A  (Tok.is(tok::semi) ||
     A  A  A  A  A  A  A  A (Tok.isAtStartOfLine() &&
     !isValidAfterTypeSpecifier(false)))) {
     A  A  A TUK = DS.isFriendSpecified() ? Sema::TUK_Friend :
     Sema::TUK_Declaration;
     - A  A if (Tok.isNot(tok::semi)) {
     - A  A  A // A semicolon was missing after this declaration. Diagnose
     and recover.
     - A  A  A ExpectAndConsume(tok::semi,
     diag::err_expected_semi_after_tagdecl,
     - A  A  A  A  A  A  A  A  A  A  A  TagType == DeclSpec::TST_class ?
     "class" :
     - A  A  A  A  A  A  A  A  A  A  A  TagType == DeclSpec::TST_struct ?
     "struct" : "union");
     - A  A  A PP.EnterToken(Tok);
     - A  A  A Tok.setKind(tok::semi);
     - A  A }
     + A  A if (Tok.isNot(tok::semi)) {
     + A  A  A // A semicolon was missing after this declaration. Diagnose
     and recover.
     + A  A  A ExpectAndConsume(tok::semi,
     diag::err_expected_semi_after_tagdecl,
     + A  A  A  A DeclSpec::getSpecifierName(TagType));
     + A  A  A PP.EnterToken(Tok);
     + A  A  A Tok.setKind(tok::semi);
     + A  A }
     A  A } else
     A  A  A TUK = Sema::TUK_Reference;

     @@ -1466,14 +1468,13 @@
     A  A // Also enforce C++ [temp]p3:
     A  A // A  In a template-declaration which defines a class, no
     declarator
     A  A // A  is permitted.
     - A if (TUK == Sema::TUK_Definition &&
     - A  A  A (TemplateInfo.Kind || !isValidAfterTypeSpecifier(false))) {
     - A  A ExpectAndConsume(tok::semi,
     diag::err_expected_semi_after_tagdecl,
     - A  A  A  A  A  A  A  A  A  A  TagType == DeclSpec::TST_class ? "class"
     :
     - A  A  A  A  A  A  A  A  A  A  TagType == DeclSpec::TST_struct ?
     "struct" : "union");
     - A  A // Push this token back into the preprocessor and change our
     current token
     - A  A // to ';' so that the rest of the code recovers as though there
     were an
     - A  A // ';' after the definition.
     + A if (TUK == Sema::TUK_Definition &&
     + A  A  A (TemplateInfo.Kind || !isValidAfterTypeSpecifier(false))) {
     + A  A ExpectAndConsume(tok::semi,
     diag::err_expected_semi_after_tagdecl,
     + A  A  A DeclSpec::getSpecifierName(TagType));
     + A  A // Push this token back into the preprocessor and change our
     current token
     + A  A // to ';' so that the rest of the code recovers as though there
     were an
     + A  A // ';' after the definition.
     A  A  A PP.EnterToken(Tok);
     A  A  A Tok.setKind(tok::semi);
     A  A }
     @@ -2236,12 +2237,13 @@
     A /// A  A  A  A  member-declaration member-specification[opt]
     A /// A  A  A  A  access-specifier ':' member-specification[opt]
     A ///
     -void Parser::ParseCXXMemberSpecification(SourceLocation RecordLoc,
     - A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  unsigned
     TagType, Decl *TagDecl) {
     - A assert((TagType == DeclSpec::TST_struct ||
     - A  A  A  A  TagType == DeclSpec::TST_union A ||
     - A  A  A  A  TagType == DeclSpec::TST_class) && "Invalid TagType!");
     -
     +void Parser::ParseCXXMemberSpecification(SourceLocation RecordLoc,
     + A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  unsigned
     TagType, Decl *TagDecl) {
     + A assert((TagType == DeclSpec::TST_struct ||
     + A  A  A  A  TagType == DeclSpec::TST_interface ||
     + A  A  A  A  TagType == DeclSpec::TST_union A ||
     + A  A  A  A  TagType == DeclSpec::TST_class) && "Invalid TagType!");
     +
     A  A PrettyDeclStackTraceEntry CrashInfo(Actions, TagDecl, RecordLoc,
     A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A "parsing
     struct/union/class body");

     Modified: cfe/trunk/lib/Sema/DeclSpec.cpp
     URL:
     http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/DeclSpec.cpp?rev=163013&r1=163012&r2=163013&view=diff
     ==============================================================================
     --- cfe/trunk/lib/Sema/DeclSpec.cpp (original)
     +++ cfe/trunk/lib/Sema/DeclSpec.cpp Fri Aug 31 13:45:21 2012
     @@ -270,6 +270,7 @@
     A  A  A case TST_int:
     A  A  A case TST_int128:
     A  A  A case TST_struct:
     + A  A case TST_interface:
     A  A  A case TST_union:
     A  A  A case TST_unknown_anytype:
     A  A  A case TST_unspecified:
     @@ -400,6 +401,7 @@
     A  A case DeclSpec::TST_class: A  A  A  return "class";
     A  A case DeclSpec::TST_union: A  A  A  return "union";
     A  A case DeclSpec::TST_struct: A  A  A return "struct";
     + A case DeclSpec::TST_interface: A  return "__interface";
     A  A case DeclSpec::TST_typename: A  A return "type-name";
     A  A case DeclSpec::TST_typeofType:
     A  A case DeclSpec::TST_typeofExpr: A return "typeof";

     Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
     URL:
     http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=163013&r1=163012&r2=163013&view=diff
     ==============================================================================
     --- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
     +++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Fri Aug 31 13:45:21 2012
     @@ -1059,10 +1059,12 @@
     A  A // Allow us to find class templates, too.
     A  A if (ClassTemplateDecl *ClassTemplate =
     dyn_cast<ClassTemplateDecl>(ND))
     A  A  A ND = ClassTemplate->getTemplatedDecl();
     -
     +
     + A // For purposes of this check, interfaces match too.
     A  A if (RecordDecl *RD = dyn_cast<RecordDecl>(ND))
     A  A  A return RD->getTagKind() == TTK_Class ||
     - A  A RD->getTagKind() == TTK_Struct;
     + A  A RD->getTagKind() == TTK_Struct ||
     + A  A RD->getTagKind() == TTK_Interface;

     A  A return false;
     A }
     @@ -1422,7 +1424,8 @@
     A  A  A  A  A if (!Tag->getIdentifier() &&
     !Tag->getTypedefNameForAnonDecl()) {
     A  A  A  A  A  A switch (Tag->getTagKind()) {
     A  A  A  A  A  A case TTK_Struct: return "struct <anonymous>";
     - A  A  A  A  A case TTK_Class: A return "class <anonymous>";
     + A  A  A  A  A case TTK_Interface: return "__interface <anonymous>";
     + A  A  A  A  A case TTK_Class: A return "class <anonymous>";
     A  A  A  A  A  A case TTK_Union: A return "union <anonymous>";
     A  A  A  A  A  A case TTK_Enum: A  return "enum <anonymous>";
     A  A  A  A  A  A }
     @@ -1449,7 +1452,7 @@
     A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A 
     A  A  A  Policy,
     A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A 
     A  A  A  Allocator));
     A  A Builder.AddTypedTextChunk("this");
     - A Results.AddResult(CodeCompletionResult(Builder.TakeString()));
     + A Results.AddResult(CodeCompletionResult(Builder.TakeString()));
     A }

     A /// \brief Add language constructs that show up for "ordinary" names.
     @@ -2884,6 +2887,7 @@
     A  A  A default:
     A  A  A  A if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
     A  A  A  A  A switch (TD->getTagKind()) {
     + A  A  A  A  A case TTK_Interface: A // fall through
     A  A  A  A  A  A case TTK_Struct: return CXCursor_StructDecl;
     A  A  A  A  A  A case TTK_Class: A return CXCursor_ClassDecl;
     A  A  A  A  A  A case TTK_Union: A return CXCursor_UnionDecl;
     @@ -3601,6 +3605,7 @@

     A  A case DeclSpec::TST_struct:
     A  A case DeclSpec::TST_class:
     + A case DeclSpec::TST_interface:
     A  A  A Filter = &ResultBuilder::IsClassOrStruct;
     A  A  A ContextKind = CodeCompletionContext::CCC_ClassOrStructTag;
     A  A  A break;

     Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
     URL:
     http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=163013&r1=163012&r2=163013&view=diff
     ==============================================================================
     --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
     +++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Aug 31 13:45:21 2012
     @@ -350,8 +350,8 @@
     A /// isTagName() - This method is called *for error recovery purposes
     only*
     A /// to determine if the specified name is a valid tag name ("struct
     foo"). A If
     A /// so, this returns the TST for the tag corresponding to it
     (TST_enum,
     -/// TST_union, TST_struct, TST_class). A This is used to diagnose cases
     in C
     -/// where the user forgot to specify the tag.
     +/// TST_union, TST_struct, TST_interface, TST_class). A This is used to
     diagnose
     +/// cases in C where the user forgot to specify the tag.
     A DeclSpec::TST Sema::isTagName(IdentifierInfo &II, Scope *S) {
     A  A // Do a tag name lookup in this scope.
     A  A LookupResult R(*this, &II, SourceLocation(), LookupTagName);
     @@ -361,6 +361,7 @@
     A  A  A if (const TagDecl *TD = R.getAsSingle<TagDecl>()) {
     A  A  A  A switch (TD->getTagKind()) {
     A  A  A  A case TTK_Struct: return DeclSpec::TST_struct;
     + A  A  A case TTK_Interface: return DeclSpec::TST_interface;
     A  A  A  A case TTK_Union: A return DeclSpec::TST_union;
     A  A  A  A case TTK_Class: A return DeclSpec::TST_class;
     A  A  A  A case TTK_Enum: A  return DeclSpec::TST_enum;
     @@ -538,6 +539,11 @@
     A  A  A  A  A FixItTagName = "struct ";
     A  A  A  A  A break;

     + A  A  A case TTK_Interface:
     + A  A  A  A TagName = "__interface";
     + A  A  A  A FixItTagName = "__interface ";
     + A  A  A  A break;
     +
     A  A  A  A case TTK_Union:
     A  A  A  A  A TagName = "union";
     A  A  A  A  A FixItTagName = "union ";
     @@ -2604,6 +2610,7 @@
     A  A TagDecl *Tag = 0;
     A  A if (DS.getTypeSpecType() == DeclSpec::TST_class ||
     A  A  A  A DS.getTypeSpecType() == DeclSpec::TST_struct ||
     + A  A  A DS.getTypeSpecType() == DeclSpec::TST_interface ||
     A  A  A  A DS.getTypeSpecType() == DeclSpec::TST_union ||
     A  A  A  A DS.getTypeSpecType() == DeclSpec::TST_enum) {
     A  A  A TagD = DS.getRepAsDecl();
     @@ -2642,7 +2649,8 @@
     A  A  A  A Diag(DS.getConstexprSpecLoc(), diag::err_constexpr_tag)
     A  A  A  A  A << (DS.getTypeSpecType() == DeclSpec::TST_class ? 0 :
     A  A  A  A  A  A  A DS.getTypeSpecType() == DeclSpec::TST_struct ? 1 :
     - A  A  A  A  A  A DS.getTypeSpecType() == DeclSpec::TST_union ? 2 : 3);
     + A  A  A  A  A  A DS.getTypeSpecType() == DeclSpec::TST_interface ? 2 :
     + A  A  A  A  A  A DS.getTypeSpecType() == DeclSpec::TST_union ? 3 : 4);
     A  A  A else
     A  A  A  A Diag(DS.getConstexprSpecLoc(),
     diag::err_constexpr_no_declarators);
     A  A  A // Don't emit warnings after this error.
     @@ -2763,6 +2771,7 @@
     A  A  A DeclSpec::TST TypeSpecType = DS.getTypeSpecType();
     A  A  A if (TypeSpecType == DeclSpec::TST_class ||
     A  A  A  A  A TypeSpecType == DeclSpec::TST_struct ||
     + A  A  A  A TypeSpecType == DeclSpec::TST_interface ||
     A  A  A  A  A TypeSpecType == DeclSpec::TST_union ||
     A  A  A  A  A TypeSpecType == DeclSpec::TST_enum) {
     A  A  A  A AttributeList* attrs = DS.getAttributes().getList();
     @@ -2772,7 +2781,8 @@
     A  A  A  A  A << attrs->getName()
     A  A  A  A  A << (TypeSpecType == DeclSpec::TST_class ? 0 :
     A  A  A  A  A  A  A TypeSpecType == DeclSpec::TST_struct ? 1 :
     - A  A  A  A  A  A TypeSpecType == DeclSpec::TST_union ? 2 : 3);
     + A  A  A  A  A  A TypeSpecType == DeclSpec::TST_union ? 2 :
     + A  A  A  A  A  A TypeSpecType == DeclSpec::TST_interface ? 3 : 4);
     A  A  A  A  A attrs = attrs->getNext();
     A  A  A  A }
     A  A  A }
     @@ -5185,6 +5195,14 @@
     A  A  A  A NewFD->setImplicitlyInline();
     A  A  A }

     + A  A // if this is a method defined in an __interface, set pure
     + A  A // (isVirtual will already return true)
     + A  A if (CXXRecordDecl *Parent = dyn_cast<CXXRecordDecl>(
     + A  A  A  A NewFD->getDeclContext())) {
     + A  A  A if (Parent->getTagKind() == TTK_Interface)
     + A  A  A  A NewFD->setPure(true);
     + A  A }
     +
     A  A  A SetNestedNameSpecifier(NewFD, D);
     A  A  A isExplicitSpecialization = false;
     A  A  A isFunctionTemplateSpecialization = false;
     @@ -8118,6 +8136,7 @@
     A  A switch (D.getDeclSpec().getTypeSpecType()) {
     A  A case TST_enum:
     A  A case TST_struct:
     + A case TST_interface:
     A  A case TST_union:
     A  A case TST_class: {
     A  A  A TagDecl *tagFromDeclSpec =
     cast<TagDecl>(D.getDeclSpec().getRepAsDecl());
     @@ -8193,6 +8212,31 @@
     A  A return false;
     A }

     +/// \brief Get diagnostic %select index for tag kind for
     +/// redeclaration diagnostic message.
     +/// WARNING: Indexes apply to particular diagnostics only!
     +///
     +/// \returns diagnostic %select index.
     +static unsigned getRedeclDiagFromTagKind(TagTypeKind Tag)
     +{
     + A switch (Tag) {
     + A  A case TTK_Struct: return 0;
     + A  A case TTK_Interface: return 1;
     + A  A case TTK_Class: A return 2;
     + A  A default: assert("Invalid tag kind for redecl diagnostic!");
     + A }
     + A return -1;
     +}
     +
     +/// \brief Determine if tag kind is a class-key compatible with
     +/// class for redeclaration (class, struct, or __interface).
     +///
     +/// \returns true iff the tag kind is compatible.
     +static bool isClassCompatTagKind(TagTypeKind Tag)
     +{
     + A return Tag == TTK_Struct || Tag == TTK_Class || Tag ==
     TTK_Interface;
     +}
     +
     A /// \brief Determine whether a tag with a given kind is acceptable
     A /// as a redeclaration of the given tag declaration.
     A ///
     @@ -8215,12 +8259,11 @@
     A  A // A  struct class-key shall be used to refer to a class (clause 9)
     A  A // A  declared using the class or struct class-key.
     A  A TagTypeKind OldTag = Previous->getTagKind();
     - A if (!isDefinition || (NewTag != TTK_Class && NewTag != TTK_Struct))
     + A if (!isDefinition || !isClassCompatTagKind(NewTag))
     A  A  A if (OldTag == NewTag)
     A  A  A  A return true;

     - A if ((OldTag == TTK_Struct || OldTag == TTK_Class) &&
     - A  A  A (NewTag == TTK_Struct || NewTag == TTK_Class)) {
     + A if (isClassCompatTagKind(OldTag) && isClassCompatTagKind(NewTag)) {
     A  A  A // Warn about the struct/class tag mismatch.
     A  A  A bool isTemplate = false;
     A  A  A if (const CXXRecordDecl *Record =
     dyn_cast<CXXRecordDecl>(Previous))
     @@ -8230,7 +8273,8 @@
     A  A  A  A // In a template instantiation, do not offer fix-its for tag
     mismatches
     A  A  A  A // since they usually mess up the template instead of fixing
     the problem.
     A  A  A  A Diag(NewTagLoc, diag::warn_struct_class_tag_mismatch)
     - A  A  A  A << (NewTag == TTK_Class) << isTemplate << &Name;
     + A  A  A  A << getRedeclDiagFromTagKind(NewTag) << isTemplate << &Name
     + A  A  A  A << getRedeclDiagFromTagKind(OldTag);
     A  A  A  A return true;
     A  A  A }

     @@ -8249,13 +8293,13 @@
     A  A  A  A  A  A if (!previousMismatch) {
     A  A  A  A  A  A  A previousMismatch = true;
     A  A  A  A  A  A  A Diag(NewTagLoc,
     diag::warn_struct_class_previous_tag_mismatch)
     - A  A  A  A  A  A  A << (NewTag == TTK_Class) << isTemplate << &Name;
     + A  A  A  A  A  A  A << getRedeclDiagFromTagKind(NewTag) << isTemplate
     << &Name
     + A  A  A  A  A  A  A << getRedeclDiagFromTagKind(I->getTagKind());
     A  A  A  A  A  A }
     A  A  A  A  A  A Diag(I->getInnerLocStart(),
     diag::note_struct_class_suggestion)
     - A  A  A  A  A  A << (NewTag == TTK_Class)
     + A  A  A  A  A  A << getRedeclDiagFromTagKind(NewTag)
     A  A  A  A  A  A  A <<
     FixItHint::CreateReplacement(I->getInnerLocStart(),
     - A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A 
     A NewTag == TTK_Class?
     - A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A 
     A "class" : "struct");
     + A  A  A  A  A  A  A  A  TypeWithKeyword::getTagTypeKindName(NewTag));
     A  A  A  A  A }
     A  A  A  A }
     A  A  A  A return true;
     @@ -8271,16 +8315,16 @@
     A  A  A }

     A  A  A Diag(NewTagLoc, diag::warn_struct_class_tag_mismatch)
     - A  A  A << (NewTag == TTK_Class)
     - A  A  A << isTemplate << &Name;
     + A  A  A << getRedeclDiagFromTagKind(NewTag) << isTemplate << &Name
     + A  A  A << getRedeclDiagFromTagKind(OldTag);
     A  A  A Diag(Redecl->getLocation(), diag::note_previous_use);

     A  A  A // If there is a previous defintion, suggest a fix-it.
     A  A  A if (Previous->getDefinition()) {
     A  A  A  A  A Diag(NewTagLoc, diag::note_struct_class_suggestion)
     - A  A  A  A  A << (Redecl->getTagKind() == TTK_Class)
     + A  A  A  A  A << getRedeclDiagFromTagKind(Redecl->getTagKind())
     A  A  A  A  A  A << FixItHint::CreateReplacement(SourceRange(NewTagLoc),
     - A  A  A  A  A  A  A  A  A  A  A  A Redecl->getTagKind() == TTK_Class?
     "class" : "struct");
     + A  A  A  A  A  A  A 
     TypeWithKeyword::getTagTypeKindName(Redecl->getTagKind()));
     A  A  A }

     A  A  A return true;

     Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
     URL:
     http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=163013&r1=163012&r2=163013&view=diff
     ==============================================================================
     --- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
     +++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Fri Aug 31 13:45:21 2012
     @@ -672,12 +672,28 @@
     A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A 
     isa<CXXConstructorDecl>(FD)))
     A  A  A  A return false;
     A  A }
     - A return true;
     -}
     -
     -// CheckConstexprFunctionDecl - Check whether a function declaration
     satisfies
     -// the requirements of a constexpr function definition or a constexpr
     -// constructor definition. If so, return true. If not, produce
     appropriate
     + A return true;
     +}
     +
     +/// \brief Get diagnostic %select index for tag kind for
     +/// record diagnostic message.
     +/// WARNING: Indexes apply to particular diagnostics only!
     +///
     +/// \returns diagnostic %select index.
     +static unsigned getRecordDiagFromTagKind(TagTypeKind Tag)
     +{
     + A switch (Tag) {
     + A  A case TTK_Struct: return 0;
     + A  A case TTK_Interface: return 1;
     + A  A case TTK_Class: A return 2;
     + A  A default: assert("Invalid tag kind for record diagnostic!");
     + A }
     + A return -1;
     +}
     +
     +// CheckConstexprFunctionDecl - Check whether a function declaration
     satisfies
     +// the requirements of a constexpr function definition or a constexpr
     +// constructor definition. If so, return true. If not, produce
     appropriate
     A // diagnostics and return false.
     A //
     A // This implements C++11 [dcl.constexpr]p3,4, as amended by DR1360.
     @@ -688,14 +704,14 @@
     A  A  A // A The definition of a constexpr constructor shall satisfy the
     following
     A  A  A // A constraints:
     A  A  A // A - the class shall not have any virtual base classes;
     - A  A const CXXRecordDecl *RD = MD->getParent();
     - A  A if (RD->getNumVBases()) {
     - A  A  A Diag(NewFD->getLocation(), diag::err_constexpr_virtual_base)
     - A  A  A  A << isa<CXXConstructorDecl>(NewFD) << RD->isStruct()
     - A  A  A  A << RD->getNumVBases();
     - A  A  A for (CXXRecordDecl::base_class_const_iterator I =
     RD->vbases_begin(),
     - A  A  A  A  A  A  E = RD->vbases_end(); I != E; ++I)
     - A  A  A  A Diag(I->getLocStart(),
     + A  A const CXXRecordDecl *RD = MD->getParent();
     + A  A if (RD->getNumVBases()) {
     + A  A  A Diag(NewFD->getLocation(), diag::err_constexpr_virtual_base)
     + A  A  A  A << isa<CXXConstructorDecl>(NewFD)
     + A  A  A  A << getRecordDiagFromTagKind(RD->getTagKind()) <<
     RD->getNumVBases();
     + A  A  A for (CXXRecordDecl::base_class_const_iterator I =
     RD->vbases_begin(),
     + A  A  A  A  A  A  E = RD->vbases_end(); I != E; ++I)
     + A  A  A  A Diag(I->getLocStart(),
     A  A  A  A  A  A  A  diag::note_constexpr_virtual_base_here) <<
     I->getSourceRange();
     A  A  A  A return false;
     A  A  A }

     Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
     URL:
     http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=163013&r1=163012&r2=163013&view=diff
     ==============================================================================
     --- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
     +++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Fri Aug 31 13:45:21 2012
     @@ -2998,7 +2998,7 @@
     A  A case UTT_IsUnion:
     A  A  A return T->isUnionType();
     A  A case UTT_IsClass:
     - A  A return T->isClassType() || T->isStructureType();
     + A  A return T->isClassType() || T->isStructureType() ||
     T->isInterfaceType();
     A  A case UTT_IsFunction:
     A  A  A return T->isFunctionType();

     Modified: cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp
     URL:
     http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp?rev=163013&r1=163012&r2=163013&view=diff
     ==============================================================================
     --- cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp (original)
     +++ cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp Fri Aug 31 13:45:21 2012
     @@ -727,6 +727,7 @@
     A  A case TST_enum:
     A  A case TST_union:
     A  A case TST_struct:
     + A case TST_interface:
     A  A case TST_class:
     A  A case TST_auto:
     A  A case TST_unknown_anytype:

     Modified: cfe/trunk/lib/Sema/SemaType.cpp
     URL:
     http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=163013&r1=163012&r2=163013&view=diff
     ==============================================================================
     --- cfe/trunk/lib/Sema/SemaType.cpp (original)
     +++ cfe/trunk/lib/Sema/SemaType.cpp Fri Aug 31 13:45:21 2012
     @@ -753,7 +753,8 @@
     A  A case DeclSpec::TST_class:
     A  A case DeclSpec::TST_enum:
     A  A case DeclSpec::TST_union:
     - A case DeclSpec::TST_struct: {
     + A case DeclSpec::TST_struct:
     + A case DeclSpec::TST_interface: {
     A  A  A TypeDecl *D = dyn_cast_or_null<TypeDecl>(DS.getRepAsDecl());
     A  A  A if (!D) {
     A  A  A  A // This can happen in C++ with ambiguous lookups.
     @@ -1853,30 +1854,31 @@
     A  A  A  A case TTK_Struct: Error = 1; /* Struct member */ break;
     A  A  A  A case TTK_Union: A Error = 2; /* Union member */ break;
     A  A  A  A case TTK_Class: A Error = 3; /* Class member */ break;
     + A  A  A case TTK_Interface: Error = 4; /* Interface member */ break;
     A  A  A  A }
     A  A  A  A break;
     A  A  A case Declarator::CXXCatchContext:
     A  A  A case Declarator::ObjCCatchContext:
     - A  A  A Error = 4; // Exception declaration
     + A  A  A Error = 5; // Exception declaration
     A  A  A  A break;
     A  A  A case Declarator::TemplateParamContext:
     - A  A  A Error = 5; // Template parameter
     + A  A  A Error = 6; // Template parameter
     A  A  A  A break;
     A  A  A case Declarator::BlockLiteralContext:
     - A  A  A Error = 6; // Block literal
     + A  A  A Error = 7; // Block literal
     A  A  A  A break;
     A  A  A case Declarator::TemplateTypeArgContext:
     - A  A  A Error = 7; // Template type argument
     + A  A  A Error = 8; // Template type argument
     A  A  A  A break;
     A  A  A case Declarator::AliasDeclContext:
     A  A  A case Declarator::AliasTemplateContext:
     - A  A  A Error = 9; // Type alias
     + A  A  A Error = 10; // Type alias
     A  A  A  A break;
     A  A  A case Declarator::TrailingReturnContext:
     - A  A  A Error = 10; // Function return type
     + A  A  A Error = 11; // Function return type
     A  A  A  A break;
     A  A  A case Declarator::TypeNameContext:
     - A  A  A Error = 11; // Generic
     + A  A  A Error = 12; // Generic
     A  A  A  A break;
     A  A  A case Declarator::FileContext:
     A  A  A case Declarator::BlockContext:
     @@ -1887,11 +1889,11 @@
     A  A  A }

     A  A  A if (D.getDeclSpec().getStorageClassSpec() ==
     DeclSpec::SCS_typedef)
     - A  A  A Error = 8;
     + A  A  A Error = 9;

     A  A  A // In Objective-C it is an error to use 'auto' on a function
     declarator.
     A  A  A if (D.isFunctionDeclarator())
     - A  A  A Error = 10;
     + A  A  A Error = 11;

     A  A  A // C++11 [dcl.spec.auto]p2: 'auto' is always fine if the
     declarator
     A  A  A // contains a trailing return type. That is only legal at the
     outermost
     @@ -4430,6 +4432,22 @@
     A  A return RequireCompleteType(Loc, T, Diagnoser);
     A }

     +/// \brief Get diagnostic %select index for tag kind for
     +/// literal type diagnostic message.
     +/// WARNING: Indexes apply to particular diagnostics only!
     +///
     +/// \returns diagnostic %select index.
     +static unsigned getLiteralDiagFromTagKind(TagTypeKind Tag)
     +{
     + A switch (Tag) {
     + A  A case TTK_Struct: return 0;
     + A  A case TTK_Interface: return 1;
     + A  A case TTK_Class: A return 2;
     + A  A default: assert("Invalid tag kind for literal type diagnostic!");
     + A }
     + A return -1;
     +}
     +
     A /// @brief Ensure that the type T is a literal type.
     A ///
     A /// This routine checks whether the type @p T is a literal type. If @p
     T is an
     @@ -4486,7 +4504,7 @@
     A  A // of constexpr constructors.
     A  A if (RD->getNumVBases()) {
     A  A  A Diag(RD->getLocation(), diag::note_non_literal_virtual_base)
     - A  A  A << RD->isStruct() << RD->getNumVBases();
     + A  A  A << getLiteralDiagFromTagKind(RD->getTagKind()) <<
     RD->getNumVBases();
     A  A  A for (CXXRecordDecl::base_class_const_iterator I =
     RD->vbases_begin(),
     A  A  A  A  A  A  E = RD->vbases_end(); I != E; ++I)
     A  A  A  A Diag(I->getLocStart(),

     Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
     URL:
     http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=163013&r1=163012&r2=163013&view=diff
     ==============================================================================
     --- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
     +++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Fri Aug 31 13:45:21
     2012
     @@ -1716,14 +1716,16 @@
     A  A  A return true;

     A  A // Compatible tags match.
     - A if (TagDecl *TagX = dyn_cast<TagDecl>(X)) {
     - A  A TagDecl *TagY = cast<TagDecl>(Y);
     - A  A return (TagX->getTagKind() == TagY->getTagKind()) ||
     - A  A  A ((TagX->getTagKind() == TTK_Struct || TagX->getTagKind() ==
     TTK_Class) &&
     - A  A  A  (TagY->getTagKind() == TTK_Struct || TagY->getTagKind() ==
     TTK_Class));
     - A }
     -
     - A // Functions with the same type and linkage match.
     + A if (TagDecl *TagX = dyn_cast<TagDecl>(X)) {
     + A  A TagDecl *TagY = cast<TagDecl>(Y);
     + A  A return (TagX->getTagKind() == TagY->getTagKind()) ||
     + A  A  A ((TagX->getTagKind() == TTK_Struct || TagX->getTagKind() ==
     TTK_Class ||
     + A  A  A  A TagX->getTagKind() == TTK_Interface) &&
     + A  A  A  (TagY->getTagKind() == TTK_Struct || TagY->getTagKind() ==
     TTK_Class ||
     + A  A  A  A TagY->getTagKind() == TTK_Interface));
     + A }
     +
     + A // Functions with the same type and linkage match.
     A  A // FIXME: This needs to cope with function templates, merging of
     A  A //prototyped/non-prototyped functions, etc.
     A  A if (FunctionDecl *FuncX = dyn_cast<FunctionDecl>(X)) {

     Modified: cfe/trunk/test/Parser/MicrosoftExtensions.cpp
     URL:
     http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/MicrosoftExtensions.cpp?rev=163013&r1=163012&r2=163013&view=diff
     ==============================================================================
     --- cfe/trunk/test/Parser/MicrosoftExtensions.cpp (original)
     +++ cfe/trunk/test/Parser/MicrosoftExtensions.cpp Fri Aug 31 13:45:21
     2012
     @@ -171,19 +171,27 @@
     A  A  int k = typename var;// expected-error {{expected a qualified name
     after 'typename'}}
     A }

     -
     -__interface MicrosoftInterface;
     -__interface MicrosoftInterface {
     - A  virtual void foo1() = 0;
     - A  virtual void foo2() = 0;
     -};
     -
     -void interface_test() {
     - A MicrosoftInterface* a;
     - A a->foo1();
     -}
     -
     -__int64 x7 = __int64(0);
     +
     +__interface MicrosoftInterface;
     +__interface MicrosoftInterface {
     + A  void foo1() = 0;
     + A  virtual void foo2() = 0;
     +};
     +
     +__interface MicrosoftDerivedInterface : public MicrosoftInterface {
     + A void foo1();
     + A void foo2() override;
     + A void foo3();
     +};
     +
     +void interface_test() {
     + A MicrosoftInterface* a;
     + A a->foo1();
     + A MicrosoftDerivedInterface* b;
     + A b->foo2();
     +}
     +
     +__int64 x7 = __int64(0);

     A namespace If_exists_test {

     Modified: cfe/trunk/tools/libclang/CIndexCXX.cpp
     URL:
     http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexCXX.cpp?rev=163013&r1=163012&r2=163013&view=diff
     ==============================================================================
     --- cfe/trunk/tools/libclang/CIndexCXX.cpp (original)
     +++ cfe/trunk/tools/libclang/CIndexCXX.cpp Fri Aug 31 13:45:21 2012
     @@ -64,14 +64,15 @@

     A  A case CXCursor_ClassTemplatePartialSpecialization:
     A  A  A if (ClassTemplateSpecializationDecl *PartialSpec
     - A  A  A  A  A =
     dyn_cast_or_null<ClassTemplatePartialSpecializationDecl>(
     - A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A 
     A  A  A  A  A  A  A getCursorDecl(C))) {
     - A  A  A switch (PartialSpec->getTagKind()) {
     - A  A  A case TTK_Class: return CXCursor_ClassDecl;
     - A  A  A case TTK_Struct: return CXCursor_StructDecl;
     - A  A  A case TTK_Union: return CXCursor_UnionDecl;
     - A  A  A case TTK_Enum: return CXCursor_NoDeclFound;
     - A  A  A }
     + A  A  A  A  A =
     dyn_cast_or_null<ClassTemplatePartialSpecializationDecl>(
     + A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A 
     A  A  A  A  A  A  A getCursorDecl(C))) {
     + A  A  A switch (PartialSpec->getTagKind()) {
     + A  A  A case TTK_Interface:
     + A  A  A case TTK_Struct: return CXCursor_StructDecl;
     + A  A  A case TTK_Class: return CXCursor_ClassDecl;
     + A  A  A case TTK_Union: return CXCursor_UnionDecl;
     + A  A  A case TTK_Enum: return CXCursor_NoDeclFound;
     + A  A  A }
     A  A  A }
     A  A  A break;

     Modified: cfe/trunk/tools/libclang/CIndexUSRs.cpp
     URL:
     http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexUSRs.cpp?rev=163013&r1=163012&r2=163013&view=diff
     ==============================================================================
     --- cfe/trunk/tools/libclang/CIndexUSRs.cpp (original)
     +++ cfe/trunk/tools/libclang/CIndexUSRs.cpp Fri Aug 31 13:45:21 2012
     @@ -1,932 +1,935 @@
     -//===- CIndexUSR.cpp - Clang-C Source Indexing Library
     --------------------===//
     -//
     -// A  A  A  A  A  A  A  A  A  A  The LLVM Compiler Infrastructure
     -//
     -// This file is distributed under the University of Illinois Open
     Source
     -// License. See LICENSE.TXT for details.
     -//
     -//===----------------------------------------------------------------------===//
     -//
     -// This file implements the generation and use of USRs from CXEntities.
     -//
     -//===----------------------------------------------------------------------===//
     -
     -#include "CIndexer.h"
     -#include "CXCursor.h"
     -#include "CXString.h"
     -#include "clang/AST/DeclTemplate.h"
     -#include "clang/AST/DeclVisitor.h"
     -#include "clang/Frontend/ASTUnit.h"
     -#include "clang/Lex/PreprocessingRecord.h"
     -#include "llvm/ADT/SmallString.h"
     -#include "llvm/Support/raw_ostream.h"
     -
     -using namespace clang;
     -using namespace clang::cxstring;
     -
     -//===----------------------------------------------------------------------===//
     -// USR generation.
     -//===----------------------------------------------------------------------===//
     -
     -namespace {
     -class USRGenerator : public DeclVisitor<USRGenerator> {
     - A OwningPtr<SmallString<128> > OwnedBuf;
     - A SmallVectorImpl<char> &Buf;
     - A llvm::raw_svector_ostream Out;
     - A bool IgnoreResults;
     - A ASTContext *Context;
     - A bool generatedLoc;
     -
     - A llvm::DenseMap<const Type *, unsigned> TypeSubstitutions;
     -
     -public:
     - A explicit USRGenerator(ASTContext *Ctx = 0, SmallVectorImpl<char>
     *extBuf = 0)
     - A : OwnedBuf(extBuf ? 0 : new SmallString<128>()),
     - A  A Buf(extBuf ? *extBuf : *OwnedBuf.get()),
     - A  A Out(Buf),
     - A  A IgnoreResults(false),
     - A  A Context(Ctx),
     - A  A generatedLoc(false)
     - A {
     - A  A // Add the USR space prefix.
     - A  A Out << "c:";
     - A }
     -
     - A StringRef str() {
     - A  A return Out.str();
     - A }
     -
     - A USRGenerator* operator->() { return this; }
     -
     - A template <typename T>
     - A llvm::raw_svector_ostream &operator<<(const T &x) {
     - A  A Out << x;
     - A  A return Out;
     - A }
     -
     - A bool ignoreResults() const { return IgnoreResults; }
     -
     - A // Visitation methods from generating USRs from AST elements.
     - A void VisitDeclContext(DeclContext *D);
     - A void VisitFieldDecl(FieldDecl *D);
     - A void VisitFunctionDecl(FunctionDecl *D);
     - A void VisitNamedDecl(NamedDecl *D);
     - A void VisitNamespaceDecl(NamespaceDecl *D);
     - A void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
     - A void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
     - A void VisitClassTemplateDecl(ClassTemplateDecl *D);
     - A void VisitObjCContainerDecl(ObjCContainerDecl *CD);
     - A void VisitObjCMethodDecl(ObjCMethodDecl *MD);
     - A void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
     - A void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
     - A void VisitTagDecl(TagDecl *D);
     - A void VisitTypedefDecl(TypedefDecl *D);
     - A void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
     - A void VisitVarDecl(VarDecl *D);
     - A void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
     - A void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
     - A void VisitLinkageSpecDecl(LinkageSpecDecl *D) {
     - A  A IgnoreResults = true;
     - A }
     - A void VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
     - A  A IgnoreResults = true;
     - A }
     - A void VisitUsingDecl(UsingDecl *D) {
     - A  A IgnoreResults = true;
     - A }
     - A void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
     - A  A IgnoreResults = true;
     - A }
     - A void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl
     *D) {
     - A  A IgnoreResults = true;
     - A }
     -
     - A /// Generate the string component containing the location of the
     - A /// A declaration.
     - A bool GenLoc(const Decl *D);
     -
     - A /// String generation methods used both by the visitation methods
     - A /// and from other clients that want to directly generate USRs.
     A These
     - A /// methods do not construct complete USRs (which incorporate the
     parents
     - A /// of an AST element), but only the fragments concerning the AST
     element
     - A /// itself.
     -
     - A /// Generate a USR for an Objective-C class.
     - A void GenObjCClass(StringRef cls);
     - A /// Generate a USR for an Objective-C class category.
     - A void GenObjCCategory(StringRef cls, StringRef cat);
     - A /// Generate a USR fragment for an Objective-C instance variable.
     A The
     - A /// complete USR can be created by concatenating the USR for the
     - A /// encompassing class with this USR fragment.
     - A void GenObjCIvar(StringRef ivar);
     - A /// Generate a USR fragment for an Objective-C method.
     - A void GenObjCMethod(StringRef sel, bool isInstanceMethod);
     - A /// Generate a USR fragment for an Objective-C property.
     - A void GenObjCProperty(StringRef prop);
     - A /// Generate a USR for an Objective-C protocol.
     - A void GenObjCProtocol(StringRef prot);
     -
     - A void VisitType(QualType T);
     - A void VisitTemplateParameterList(const TemplateParameterList
     *Params);
     - A void VisitTemplateName(TemplateName Name);
     - A void VisitTemplateArgument(const TemplateArgument &Arg);
     -
     - A /// Emit a Decl's name using NamedDecl::printName() and return true
     if
     - A /// A the decl had no name.
     - A bool EmitDeclName(const NamedDecl *D);
     -};
     -
     -} // end anonymous namespace
     -
     -//===----------------------------------------------------------------------===//
     -// Generating USRs from ASTS.
     -//===----------------------------------------------------------------------===//
     -
     -bool USRGenerator::EmitDeclName(const NamedDecl *D) {
     - A Out.flush();
     - A const unsigned startSize = Buf.size();
     - A D->printName(Out);
     - A Out.flush();
     - A const unsigned endSize = Buf.size();
     - A return startSize == endSize;
     -}
     -
     -static bool InAnonymousNamespace(const Decl *D) {
     - A if (const NamespaceDecl *ND =
     dyn_cast<NamespaceDecl>(D->getDeclContext()))
     - A  A return ND->isAnonymousNamespace();
     - A return false;
     -}
     -
     -static inline bool ShouldGenerateLocation(const NamedDecl *D) {
     - A return D->getLinkage() != ExternalLinkage &&
     !InAnonymousNamespace(D);
     -}
     -
     -void USRGenerator::VisitDeclContext(DeclContext *DC) {
     - A if (NamedDecl *D = dyn_cast<NamedDecl>(DC))
     - A  A Visit(D);
     -}
     -
     -void USRGenerator::VisitFieldDecl(FieldDecl *D) {
     - A // The USR for an ivar declared in a class extension is based on the
     - A // ObjCInterfaceDecl, not the ObjCCategoryDecl.
     - A if (ObjCInterfaceDecl *ID = Context->getObjContainingInterface(D))
     - A  A Visit(ID);
     - A else
     - A  A VisitDeclContext(D->getDeclContext());
     - A Out << (isa<ObjCIvarDecl>(D) ? "@" : "@FI@");
     - A if (EmitDeclName(D)) {
     - A  A // Bit fields can be anonymous.
     - A  A IgnoreResults = true;
     - A  A return;
     - A }
     -}
     -
     -void USRGenerator::VisitFunctionDecl(FunctionDecl *D) {
     - A if (ShouldGenerateLocation(D) && GenLoc(D))
     - A  A return;
     -
     - A VisitDeclContext(D->getDeclContext());
     - A if (FunctionTemplateDecl *FunTmpl =
     D->getDescribedFunctionTemplate()) {
     - A  A Out << "@FT@";
     - A  A VisitTemplateParameterList(FunTmpl->getTemplateParameters());
     - A } else
     - A  A Out << "@F@";
     - A D->printName(Out);
     -
     - A ASTContext &Ctx = *Context;
     - A if (!Ctx.getLangOpts().CPlusPlus || D->isExternC())
     - A  A return;
     -
     - A if (const TemplateArgumentList *
     - A  A  A  A SpecArgs = D->getTemplateSpecializationArgs()) {
     - A  A Out << '<';
     - A  A for (unsigned I = 0, N = SpecArgs->size(); I != N; ++I) {
     - A  A  A Out << '#';
     - A  A  A VisitTemplateArgument(SpecArgs->get(I));
     - A  A }
     - A  A Out << '>';
     - A }
     -
     - A // Mangle in type information for the arguments.
     - A for (FunctionDecl::param_iterator I = D->param_begin(), E =
     D->param_end();
     - A  A  A  I != E; ++I) {
     - A  A Out << '#';
     - A  A if (ParmVarDecl *PD = *I)
     - A  A  A VisitType(PD->getType());
     - A }
     - A if (D->isVariadic())
     - A  A Out << '.';
     - A Out << '#';
     - A if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(D)) {
     - A  A if (MD->isStatic())
     - A  A  A Out << 'S';
     - A  A if (unsigned quals = MD->getTypeQualifiers())
     - A  A  A Out << (char)('0' + quals);
     - A }
     -}
     -
     -void USRGenerator::VisitNamedDecl(NamedDecl *D) {
     - A VisitDeclContext(D->getDeclContext());
     - A Out << "@";
     -
     - A if (EmitDeclName(D)) {
     - A  A // The string can be empty if the declaration has no name; e.g.,
     it is
     - A  A // the ParmDecl with no name for declaration of a function
     pointer type,
     - A  A // e.g.: void A (*f)(void *);
     - A  A // In this case, don't generate a USR.
     - A  A IgnoreResults = true;
     - A }
     -}
     -
     -void USRGenerator::VisitVarDecl(VarDecl *D) {
     - A // VarDecls can be declared 'extern' within a function or method
     body,
     - A // but their enclosing DeclContext is the function, not the TU. A We
     need
     - A // to check the storage class to correctly generate the USR.
     - A if (ShouldGenerateLocation(D) && GenLoc(D))
     - A  A return;
     -
     - A VisitDeclContext(D->getDeclContext());
     -
     - A // Variables always have simple names.
     - A StringRef s = D->getName();
     -
     - A // The string can be empty if the declaration has no name; e.g., it
     is
     - A // the ParmDecl with no name for declaration of a function pointer
     type, e.g.:
     - A // A  A void A (*f)(void *);
     - A // In this case, don't generate a USR.
     - A if (s.empty())
     - A  A IgnoreResults = true;
     - A else
     - A  A Out << '@' << s;
     -}
     -
     -void USRGenerator::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl
     *D) {
     - A GenLoc(D);
     - A return;
     -}
     -
     -void
     USRGenerator::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D)
     {
     - A GenLoc(D);
     - A return;
     -}
     -
     -void USRGenerator::VisitNamespaceDecl(NamespaceDecl *D) {
     - A if (D->isAnonymousNamespace()) {
     - A  A Out << "@aN";
     - A  A return;
     - A }
     -
     - A VisitDeclContext(D->getDeclContext());
     - A if (!IgnoreResults)
     - A  A Out << "@N@" << D->getName();
     -}
     -
     -void USRGenerator::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
     - A VisitFunctionDecl(D->getTemplatedDecl());
     -}
     -
     -void USRGenerator::VisitClassTemplateDecl(ClassTemplateDecl *D) {
     - A VisitTagDecl(D->getTemplatedDecl());
     -}
     -
     -void USRGenerator::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
     - A VisitDeclContext(D->getDeclContext());
     - A if (!IgnoreResults)
     - A  A Out << "@NA@" << D->getName();
     -}
     -
     -void USRGenerator::VisitObjCMethodDecl(ObjCMethodDecl *D) {
     - A DeclContext *container = D->getDeclContext();
     - A if (ObjCProtocolDecl *pd = dyn_cast<ObjCProtocolDecl>(container)) {
     - A  A Visit(pd);
     - A }
     - A else {
     - A  A // The USR for a method declared in a class extension or category
     is based on
     - A  A // the ObjCInterfaceDecl, not the ObjCCategoryDecl.
     - A  A ObjCInterfaceDecl *ID = D->getClassInterface();
     - A  A if (!ID) {
     - A  A  A IgnoreResults = true;
     - A  A  A return;
     - A  A }
     - A  A Visit(ID);
     - A }
     - A // Ideally we would use 'GenObjCMethod', but this is such a hot path
     - A // for Objective-C code that we don't want to use
     - A // DeclarationName::getAsString().
     - A Out << (D->isInstanceMethod() ? "(im)" : "(cm)");
     - A DeclarationName N(D->getSelector());
     - A N.printName(Out);
     -}
     -
     -void USRGenerator::VisitObjCContainerDecl(ObjCContainerDecl *D) {
     - A switch (D->getKind()) {
     - A  A default:
     - A  A  A llvm_unreachable("Invalid ObjC container.");
     - A  A case Decl::ObjCInterface:
     - A  A case Decl::ObjCImplementation:
     - A  A  A GenObjCClass(D->getName());
     - A  A  A break;
     - A  A case Decl::ObjCCategory: {
     - A  A  A ObjCCategoryDecl *CD = cast<ObjCCategoryDecl>(D);
     - A  A  A ObjCInterfaceDecl *ID = CD->getClassInterface();
     - A  A  A if (!ID) {
     - A  A  A  A // Handle invalid code where the @interface might not
     - A  A  A  A // have been specified.
     - A  A  A  A // FIXME: We should be able to generate this USR even if
     the
     - A  A  A  A // @interface isn't available.
     - A  A  A  A IgnoreResults = true;
     - A  A  A  A return;
     - A  A  A }
     - A  A  A // Specially handle class extensions, which are anonymous
     categories.
     - A  A  A // We want to mangle in the location to uniquely distinguish
     them.
     - A  A  A if (CD->IsClassExtension()) {
     - A  A  A  A Out << "objc(ext)" << ID->getName() << '@';
     - A  A  A  A GenLoc(CD);
     - A  A  A }
     - A  A  A else
     - A  A  A  A GenObjCCategory(ID->getName(), CD->getName());
     -
     - A  A  A break;
     - A  A }
     - A  A case Decl::ObjCCategoryImpl: {
     - A  A  A ObjCCategoryImplDecl *CD = cast<ObjCCategoryImplDecl>(D);
     - A  A  A ObjCInterfaceDecl *ID = CD->getClassInterface();
     - A  A  A if (!ID) {
     - A  A  A  A // Handle invalid code where the @interface might not
     - A  A  A  A // have been specified.
     - A  A  A  A // FIXME: We should be able to generate this USR even if
     the
     - A  A  A  A // @interface isn't available.
     - A  A  A  A IgnoreResults = true;
     - A  A  A  A return;
     - A  A  A }
     - A  A  A GenObjCCategory(ID->getName(), CD->getName());
     - A  A  A break;
     - A  A }
     - A  A case Decl::ObjCProtocol:
     - A  A  A GenObjCProtocol(cast<ObjCProtocolDecl>(D)->getName());
     - A  A  A break;
     - A }
     -}
     -
     -void USRGenerator::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
     - A // The USR for a property declared in a class extension or category
     is based
     - A // on the ObjCInterfaceDecl, not the ObjCCategoryDecl.
     - A if (ObjCInterfaceDecl *ID = Context->getObjContainingInterface(D))
     - A  A Visit(ID);
     - A else
     - A  A Visit(cast<Decl>(D->getDeclContext()));
     - A GenObjCProperty(D->getName());
     -}
     -
     -void USRGenerator::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
     - A if (ObjCPropertyDecl *PD = D->getPropertyDecl()) {
     - A  A VisitObjCPropertyDecl(PD);
     - A  A return;
     - A }
     -
     - A IgnoreResults = true;
     -}
     -
     -void USRGenerator::VisitTagDecl(TagDecl *D) {
     - A // Add the location of the tag decl to handle resolution across
     - A // translation units.
     - A if (ShouldGenerateLocation(D) && GenLoc(D))
     - A  A return;
     -
     - A D = D->getCanonicalDecl();
     - A VisitDeclContext(D->getDeclContext());
     -
     - A bool AlreadyStarted = false;
     - A if (CXXRecordDecl *CXXRecord = dyn_cast<CXXRecordDecl>(D)) {
     - A  A if (ClassTemplateDecl *ClassTmpl =
     CXXRecord->getDescribedClassTemplate()) {
     - A  A  A AlreadyStarted = true;
     -
     - A  A  A switch (D->getTagKind()) {
     - A  A  A case TTK_Struct: Out << "@ST"; break;
     - A  A  A case TTK_Class: A Out << "@CT"; break;
     - A  A  A case TTK_Union: A Out << "@UT"; break;
     - A  A  A case TTK_Enum: llvm_unreachable("enum template");
     - A  A  A }
     - A  A 
     A VisitTemplateParameterList(ClassTmpl->getTemplateParameters());
     - A  A } else if (ClassTemplatePartialSpecializationDecl *PartialSpec
     - A  A  A  A  A  A  A  A =
     dyn_cast<ClassTemplatePartialSpecializationDecl>(CXXRecord)) {
     - A  A  A AlreadyStarted = true;
     -
     - A  A  A switch (D->getTagKind()) {
     - A  A  A case TTK_Struct: Out << "@SP"; break;
     - A  A  A case TTK_Class: A Out << "@CP"; break;
     - A  A  A case TTK_Union: A Out << "@UP"; break;
     - A  A  A case TTK_Enum: llvm_unreachable("enum partial
     specialization");
     - A  A  A }
     - A  A 
     A VisitTemplateParameterList(PartialSpec->getTemplateParameters());
     - A  A }
     - A }
     -
     - A if (!AlreadyStarted) {
     - A  A switch (D->getTagKind()) {
     - A  A  A case TTK_Struct: Out << "@S"; break;
     - A  A  A case TTK_Class: A Out << "@C"; break;
     - A  A  A case TTK_Union: A Out << "@U"; break;
     - A  A  A case TTK_Enum: A  Out << "@E"; break;
     - A  A }
     - A }
     -
     - A Out << '@';
     - A Out.flush();
     - A assert(Buf.size() > 0);
     - A const unsigned off = Buf.size() - 1;
     -
     - A if (EmitDeclName(D)) {
     - A  A if (const TypedefNameDecl *TD = D->getTypedefNameForAnonDecl()) {
     - A  A  A Buf[off] = 'A';
     - A  A  A Out << '@' << *TD;
     - A  A }
     - A  A else
     - A  A  A Buf[off] = 'a';
     - A }
     -
     - A // For a class template specialization, mangle the template
     arguments.
     - A if (ClassTemplateSpecializationDecl *Spec
     - A  A  A  A  A  A  A  A  A  A  A  A  A  A  A =
     dyn_cast<ClassTemplateSpecializationDecl>(D)) {
     - A  A const TemplateArgumentList &Args =
     Spec->getTemplateInstantiationArgs();
     - A  A Out << '>';
     - A  A for (unsigned I = 0, N = Args.size(); I != N; ++I) {
     - A  A  A Out << '#';
     - A  A  A VisitTemplateArgument(Args.get(I));
     - A  A }
     - A }
     -}
     -
     -void USRGenerator::VisitTypedefDecl(TypedefDecl *D) {
     - A if (ShouldGenerateLocation(D) && GenLoc(D))
     - A  A return;
     - A DeclContext *DC = D->getDeclContext();
     - A if (NamedDecl *DCN = dyn_cast<NamedDecl>(DC))
     - A  A Visit(DCN);
     - A Out << "@T@";
     - A Out << D->getName();
     -}
     -
     -void USRGenerator::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
     - A GenLoc(D);
     - A return;
     -}
     -
     -bool USRGenerator::GenLoc(const Decl *D) {
     - A if (generatedLoc)
     - A  A return IgnoreResults;
     - A generatedLoc = true;
     -
     - A // Guard against null declarations in invalid code.
     - A if (!D) {
     - A  A IgnoreResults = true;
     - A  A return true;
     - A }
     -
     - A // Use the location of canonical decl.
     - A D = D->getCanonicalDecl();
     -
     - A const SourceManager &SM = Context->getSourceManager();
     - A SourceLocation L = D->getLocStart();
     - A if (L.isInvalid()) {
     - A  A IgnoreResults = true;
     - A  A return true;
     - A }
     - A L = SM.getExpansionLoc(L);
     - A const std::pair<FileID, unsigned> &Decomposed =
     SM.getDecomposedLoc(L);
     - A const FileEntry *FE = SM.getFileEntryForID(Decomposed.first);
     - A if (FE) {
     - A  A Out << llvm::sys::path::filename(FE->getName());
     - A }
     - A else {
     - A  A // This case really isn't interesting.
     - A  A IgnoreResults = true;
     - A  A return true;
     - A }
     - A // Use the offest into the FileID to represent the location. A Using
     - A // a line/column can cause us to look back at the original source
     file,
     - A // which is expensive.
     - A Out << '@' << Decomposed.second;
     - A return IgnoreResults;
     -}
     -
     -void USRGenerator::VisitType(QualType T) {
     - A // This method mangles in USR information for types. A It can
     possibly
     - A // just reuse the naming-mangling logic used by codegen, although
     the
     - A // requirements for USRs might not be the same.
     - A ASTContext &Ctx = *Context;
     -
     - A do {
     - A  A T = Ctx.getCanonicalType(T);
     - A  A Qualifiers Q = T.getQualifiers();
     - A  A unsigned qVal = 0;
     - A  A if (Q.hasConst())
     - A  A  A qVal |= 0x1;
     - A  A if (Q.hasVolatile())
     - A  A  A qVal |= 0x2;
     - A  A if (Q.hasRestrict())
     - A  A  A qVal |= 0x4;
     - A  A if(qVal)
     - A  A  A Out << ((char) ('0' + qVal));
     -
     - A  A // Mangle in ObjC GC qualifiers?
     -
     - A  A if (const PackExpansionType *Expansion =
     T->getAs<PackExpansionType>()) {
     - A  A  A Out << 'P';
     - A  A  A T = Expansion->getPattern();
     - A  A }
     -
     - A  A if (const BuiltinType *BT = T->getAs<BuiltinType>()) {
     - A  A  A unsigned char c = '\0';
     - A  A  A switch (BT->getKind()) {
     - A  A  A  A case BuiltinType::Void:
     - A  A  A  A  A c = 'v'; break;
     - A  A  A  A case BuiltinType::Bool:
     - A  A  A  A  A c = 'b'; break;
     - A  A  A  A case BuiltinType::Char_U:
     - A  A  A  A case BuiltinType::UChar:
     - A  A  A  A  A c = 'c'; break;
     - A  A  A  A case BuiltinType::Char16:
     - A  A  A  A  A c = 'q'; break;
     - A  A  A  A case BuiltinType::Char32:
     - A  A  A  A  A c = 'w'; break;
     - A  A  A  A case BuiltinType::UShort:
     - A  A  A  A  A c = 's'; break;
     - A  A  A  A case BuiltinType::UInt:
     - A  A  A  A  A c = 'i'; break;
     - A  A  A  A case BuiltinType::ULong:
     - A  A  A  A  A c = 'l'; break;
     - A  A  A  A case BuiltinType::ULongLong:
     - A  A  A  A  A c = 'k'; break;
     - A  A  A  A case BuiltinType::UInt128:
     - A  A  A  A  A c = 'j'; break;
     - A  A  A  A case BuiltinType::Char_S:
     - A  A  A  A case BuiltinType::SChar:
     - A  A  A  A  A c = 'C'; break;
     - A  A  A  A case BuiltinType::WChar_S:
     - A  A  A  A case BuiltinType::WChar_U:
     - A  A  A  A  A c = 'W'; break;
     - A  A  A  A case BuiltinType::Short:
     - A  A  A  A  A c = 'S'; break;
     - A  A  A  A case BuiltinType::Int:
     - A  A  A  A  A c = 'I'; break;
     - A  A  A  A case BuiltinType::Long:
     - A  A  A  A  A c = 'L'; break;
     - A  A  A  A case BuiltinType::LongLong:
     - A  A  A  A  A c = 'K'; break;
     - A  A  A  A case BuiltinType::Int128:
     - A  A  A  A  A c = 'J'; break;
     - A  A  A  A case BuiltinType::Half:
     - A  A  A  A  A c = 'h'; break;
     - A  A  A  A case BuiltinType::Float:
     - A  A  A  A  A c = 'f'; break;
     - A  A  A  A case BuiltinType::Double:
     - A  A  A  A  A c = 'd'; break;
     - A  A  A  A case BuiltinType::LongDouble:
     - A  A  A  A  A c = 'D'; break;
     - A  A  A  A case BuiltinType::NullPtr:
     - A  A  A  A  A c = 'n'; break;
     -#define BUILTIN_TYPE(Id, SingletonId)
     -#define PLACEHOLDER_TYPE(Id, SingletonId) case BuiltinType::Id:
     -#include "clang/AST/BuiltinTypes.def"
     - A  A  A  A case BuiltinType::Dependent:
     - A  A  A  A  A IgnoreResults = true;
     - A  A  A  A  A return;
     - A  A  A  A case BuiltinType::ObjCId:
     - A  A  A  A  A c = 'o'; break;
     - A  A  A  A case BuiltinType::ObjCClass:
     - A  A  A  A  A c = 'O'; break;
     - A  A  A  A case BuiltinType::ObjCSel:
     - A  A  A  A  A c = 'e'; break;
     - A  A  A }
     - A  A  A Out << c;
     - A  A  A return;
     - A  A }
     -
     - A  A // If we have already seen this (non-built-in) type, use a
     substitution
     - A  A // encoding.
     - A  A llvm::DenseMap<const Type *, unsigned>::iterator Substitution
     - A  A  A = TypeSubstitutions.find(T.getTypePtr());
     - A  A if (Substitution != TypeSubstitutions.end()) {
     - A  A  A Out << 'S' << Substitution->second << '_';
     - A  A  A return;
     - A  A } else {
     - A  A  A // Record this as a substitution.
     - A  A  A unsigned Number = TypeSubstitutions.size();
     - A  A  A TypeSubstitutions[T.getTypePtr()] = Number;
     - A  A }
     -
     - A  A if (const PointerType *PT = T->getAs<PointerType>()) {
     - A  A  A Out << '*';
     - A  A  A T = PT->getPointeeType();
     - A  A  A continue;
     - A  A }
     - A  A if (const ReferenceType *RT = T->getAs<ReferenceType>()) {
     - A  A  A Out << '&';
     - A  A  A T = RT->getPointeeType();
     - A  A  A continue;
     - A  A }
     - A  A if (const FunctionProtoType *FT = T->getAs<FunctionProtoType>())
     {
     - A  A  A Out << 'F';
     - A  A  A VisitType(FT->getResultType());
     - A  A  A for (FunctionProtoType::arg_type_iterator
     - A  A  A  A  A  A I = FT->arg_type_begin(), E = FT->arg_type_end();
     I!=E; ++I) {
     - A  A  A  A VisitType(*I);
     - A  A  A }
     - A  A  A if (FT->isVariadic())
     - A  A  A  A Out << '.';
     - A  A  A return;
     - A  A }
     - A  A if (const BlockPointerType *BT = T->getAs<BlockPointerType>()) {
     - A  A  A Out << 'B';
     - A  A  A T = BT->getPointeeType();
     - A  A  A continue;
     - A  A }
     - A  A if (const ComplexType *CT = T->getAs<ComplexType>()) {
     - A  A  A Out << '<';
     - A  A  A T = CT->getElementType();
     - A  A  A continue;
     - A  A }
     - A  A if (const TagType *TT = T->getAs<TagType>()) {
     - A  A  A Out << '$';
     - A  A  A VisitTagDecl(TT->getDecl());
     - A  A  A return;
     - A  A }
     - A  A if (const TemplateTypeParmType *TTP =
     T->getAs<TemplateTypeParmType>()) {
     - A  A  A Out << 't' << TTP->getDepth() << '.' << TTP->getIndex();
     - A  A  A return;
     - A  A }
     - A  A if (const TemplateSpecializationType *Spec
     - A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A =
     T->getAs<TemplateSpecializationType>()) {
     - A  A  A Out << '>';
     - A  A  A VisitTemplateName(Spec->getTemplateName());
     - A  A  A Out << Spec->getNumArgs();
     - A  A  A for (unsigned I = 0, N = Spec->getNumArgs(); I != N; ++I)
     - A  A  A  A VisitTemplateArgument(Spec->getArg(I));
     - A  A  A return;
     - A  A }
     -
     - A  A // Unhandled type.
     - A  A Out << ' ';
     - A  A break;
     - A } while (true);
     -}
     -
     -void USRGenerator::VisitTemplateParameterList(
     - A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  const
     TemplateParameterList *Params) {
     - A if (!Params)
     - A  A return;
     - A Out << '>' << Params->size();
     - A for (TemplateParameterList::const_iterator P = Params->begin(),
     - A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A PEnd =
     Params->end();
     - A  A  A  P != PEnd; ++P) {
     - A  A Out << '#';
     - A  A if (isa<TemplateTypeParmDecl>(*P)) {
     - A  A  A if (cast<TemplateTypeParmDecl>(*P)->isParameterPack())
     - A  A  A  A Out<< 'p';
     - A  A  A Out << 'T';
     - A  A  A continue;
     - A  A }
     -
     - A  A if (NonTypeTemplateParmDecl *NTTP =
     dyn_cast<NonTypeTemplateParmDecl>(*P)) {
     - A  A  A if (NTTP->isParameterPack())
     - A  A  A  A Out << 'p';
     - A  A  A Out << 'N';
     - A  A  A VisitType(NTTP->getType());
     - A  A  A continue;
     - A  A }
     -
     - A  A TemplateTemplateParmDecl *TTP =
     cast<TemplateTemplateParmDecl>(*P);
     - A  A if (TTP->isParameterPack())
     - A  A  A Out << 'p';
     - A  A Out << 't';
     - A  A VisitTemplateParameterList(TTP->getTemplateParameters());
     - A }
     -}
     -
     -void USRGenerator::VisitTemplateName(TemplateName Name) {
     - A if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
     - A  A if (TemplateTemplateParmDecl *TTP
     - A  A  A  A  A  A  A  A  A  A  A  A  A  A  A =
     dyn_cast<TemplateTemplateParmDecl>(Template)) {
     - A  A  A Out << 't' << TTP->getDepth() << '.' << TTP->getIndex();
     - A  A  A return;
     - A  A }
     -
     - A  A Visit(Template);
     - A  A return;
     - A }
     -
     - A // FIXME: Visit dependent template names.
     -}
     -
     -void USRGenerator::VisitTemplateArgument(const TemplateArgument &Arg) {
     - A switch (Arg.getKind()) {
     - A case TemplateArgument::Null:
     - A  A break;
     -
     - A case TemplateArgument::Declaration:
     - A  A if (Decl *D = Arg.getAsDecl())
     - A  A  A Visit(D);
     - A  A break;
     -
     - A case TemplateArgument::TemplateExpansion:
     - A  A Out << 'P'; // pack expansion of...
     - A  A // Fall through
     - A case TemplateArgument::Template:
     - A  A VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
     - A  A break;
     -
     - A case TemplateArgument::Expression:
     - A  A // FIXME: Visit expressions.
     - A  A break;
     -
     - A case TemplateArgument::Pack:
     - A  A Out << 'p' << Arg.pack_size();
     - A  A for (TemplateArgument::pack_iterator P = Arg.pack_begin(), PEnd =
     Arg.pack_end();
     - A  A  A  A  P != PEnd; ++P)
     - A  A  A VisitTemplateArgument(*P);
     - A  A break;
     -
     - A case TemplateArgument::Type:
     - A  A VisitType(Arg.getAsType());
     - A  A break;
     -
     - A case TemplateArgument::Integral:
     - A  A Out << 'V';
     - A  A VisitType(Arg.getIntegralType());
     - A  A Out << Arg.getAsIntegral();
     - A  A break;
     - A }
     -}
     -
     -//===----------------------------------------------------------------------===//
     -// General purpose USR generation methods.
     -//===----------------------------------------------------------------------===//
     -
     -void USRGenerator::GenObjCClass(StringRef cls) {
     - A Out << "objc(cs)" << cls;
     -}
     -
     -void USRGenerator::GenObjCCategory(StringRef cls, StringRef cat) {
     - A Out << "objc(cy)" << cls << '@' << cat;
     -}
     -
     -void USRGenerator::GenObjCIvar(StringRef ivar) {
     - A Out << '@' << ivar;
     -}
     -
     -void USRGenerator::GenObjCMethod(StringRef meth, bool isInstanceMethod)
     {
     - A Out << (isInstanceMethod ? "(im)" : "(cm)") << meth;
     -}
     -
     -void USRGenerator::GenObjCProperty(StringRef prop) {
     - A Out << "(py)" << prop;
     -}
     -
     -void USRGenerator::GenObjCProtocol(StringRef prot) {
     - A Out << "objc(pl)" << prot;
     -}
     -
     -//===----------------------------------------------------------------------===//
     -// API hooks.
     -//===----------------------------------------------------------------------===//
     -
     -static inline StringRef extractUSRSuffix(StringRef s) {
     - A return s.startswith("c:") ? s.substr(2) : "";
     -}
     -
     -bool cxcursor::getDeclCursorUSR(const Decl *D, SmallVectorImpl<char>
     &Buf) {
     - A // Don't generate USRs for things with invalid locations.
     - A if (!D || D->getLocStart().isInvalid())
     - A  A return true;
     -
     - A // Check if the cursor has 'NoLinkage'.
     - A if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
     - A  A switch (ND->getLinkage()) {
     - A  A  A case ExternalLinkage:
     - A  A  A  A // Generate USRs for all entities with external linkage.
     - A  A  A  A break;
     - A  A  A case NoLinkage:
     - A  A  A case UniqueExternalLinkage:
     - A  A  A  A // We allow enums, typedefs, and structs that have no
     linkage to
     - A  A  A  A // have USRs that are anchored to the file they were
     defined in
     - A  A  A  A // (e.g., the header). A This is a little gross, but in
     principal
     - A  A  A  A // enums/anonymous structs/etc. defined in a common header
     file
     - A  A  A  A // are referred to across multiple translation units.
     - A  A  A  A if (isa<TagDecl>(ND) || isa<TypedefDecl>(ND) ||
     - A  A  A  A  A  A isa<EnumConstantDecl>(ND) || isa<FieldDecl>(ND) ||
     - A  A  A  A  A  A isa<VarDecl>(ND) || isa<NamespaceDecl>(ND))
     - A  A  A  A  A break;
     - A  A  A  A // Fall-through.
     - A  A  A case InternalLinkage:
     - A  A  A  A if (isa<FunctionDecl>(ND))
     - A  A  A  A  A break;
     - A  A }
     -
     - A {
     - A  A USRGenerator UG(&D->getASTContext(), &Buf);
     - A  A UG->Visit(const_cast<Decl*>(D));
     -
     - A  A if (UG->ignoreResults())
     - A  A  A return true;
     - A }
     -
     - A return false;
     -}
     -
     -extern "C" {
     -
     -CXString clang_getCursorUSR(CXCursor C) {
     - A const CXCursorKind &K = clang_getCursorKind(C);
     -
     - A if (clang_isDeclaration(K)) {
     - A  A Decl *D = cxcursor::getCursorDecl(C);
     - A  A if (!D)
     - A  A  A return createCXString("");
     -
     - A  A CXTranslationUnit TU = cxcursor::getCursorTU(C);
     - A  A if (!TU)
     - A  A  A return createCXString("");
     -
     - A  A CXStringBuf *buf = cxstring::getCXStringBuf(TU);
     - A  A if (!buf)
     - A  A  A return createCXString("");
     -
     - A  A bool Ignore = cxcursor::getDeclCursorUSR(D, buf->Data);
     - A  A if (Ignore) {
     - A  A  A disposeCXStringBuf(buf);
     - A  A  A return createCXString("");
     - A  A }
     -
     - A  A // Return the C-string, but don't make a copy since it is already
     in
     - A  A // the string buffer.
     - A  A buf->Data.push_back('\0');
     - A  A return createCXString(buf);
     - A }
     -
     - A if (K == CXCursor_MacroDefinition) {
     - A  A CXTranslationUnit TU = cxcursor::getCursorTU(C);
     - A  A if (!TU)
     - A  A  A return createCXString("");
     -
     - A  A CXStringBuf *buf = cxstring::getCXStringBuf(TU);
     - A  A if (!buf)
     - A  A  A return createCXString("");
     -
     - A  A {
     - A  A  A USRGenerator
     UG(&cxcursor::getCursorASTUnit(C)->getASTContext(),
     - A  A  A  A  A  A  A  A  A  A  A &buf->Data);
     - A  A  A UG << "macro@"
     - A  A  A  A <<
     cxcursor::getCursorMacroDefinition(C)->getName()->getNameStart();
     - A  A }
     - A  A buf->Data.push_back('\0');
     - A  A return createCXString(buf);
     - A }
     -
     - A return createCXString("");
     -}
     -
     -CXString clang_constructUSR_ObjCIvar(const char *name, CXString
     classUSR) {
     - A USRGenerator UG;
     - A UG << extractUSRSuffix(clang_getCString(classUSR));
     - A UG->GenObjCIvar(name);
     - A return createCXString(UG.str(), true);
     -}
     -
     -CXString clang_constructUSR_ObjCMethod(const char *name,
     - A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  unsigned
     isInstanceMethod,
     - A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  CXString
     classUSR) {
     - A USRGenerator UG;
     - A UG << extractUSRSuffix(clang_getCString(classUSR));
     - A UG->GenObjCMethod(name, isInstanceMethod);
     - A return createCXString(UG.str(), true);
     -}
     -
     -CXString clang_constructUSR_ObjCClass(const char *name) {
     - A USRGenerator UG;
     - A UG->GenObjCClass(name);
     - A return createCXString(UG.str(), true);
     -}
     -
     -CXString clang_constructUSR_ObjCProtocol(const char *name) {
     - A USRGenerator UG;
     - A UG->GenObjCProtocol(name);
     - A return createCXString(UG.str(), true);
     -}
     -
     -CXString clang_constructUSR_ObjCCategory(const char *class_name,
     - A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  const char
     *category_name) {
     - A USRGenerator UG;
     - A UG->GenObjCCategory(class_name, category_name);
     - A return createCXString(UG.str(), true);
     -}
     -
     -CXString clang_constructUSR_ObjCProperty(const char *property,
     - A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  A  CXString
     classUSR) {
     - A USRGenerator UG;
     - A UG << extractUSRSuffix(clang_getCString(classUSR));
     - A UG->GenObjCProperty(property);
     - A return createCXString(UG.str(), true);
     -}
     -
     -} // end extern "C"
     +//===- CIndexUSR.cpp - Clang-C Source Indexing Library
     --------------------===//
     +//
     +// A  A  A  A  A  A  A  A  A  A  The LLVM Compiler Infrastructure
     +//
     +// This file is distributed under the University of Illinois Open
     Source
     +// License. See LICENSE.TXT for details.
     +//
     +//===----------------------------------------------------------------------===//
     +//
     +// This file implements the generation and use of USRs from CXEntities.
     +//
     +//===----------------------------------------------------------------------===//
     +
     +#include "CIndexer.h"
     +#include "CXCursor.h"
     +#include "CXString.h"
     +#include "clang/AST/DeclTemplate.h"
     +#include "clang/AST/DeclVisitor.h"
     +#include "clang/Frontend/ASTUnit.h"
     +#include "clang/Lex/PreprocessingRecord.h"
     +#include "llvm/ADT/SmallString.h"
     +#include "llvm/Support/raw_ostream.h"
     +
     +using namespace clang;
     +using namespace clang::cxstring;
     +
     +//===----------------------------------------------------------------------===//
     +// USR generation.
     +//===----------------------------------------------------------------------===//
     +
     +namespace {
     +class USRGenerator : public DeclVisitor<USRGenerator> {
     + A OwningPtr<SmallString<128> > OwnedBuf;
     + A SmallVectorImpl<char> &Buf;
     + A llvm::raw_svector_ostream Out;
     + A bool IgnoreResults;
     + A ASTContext *Context;
     + A bool generatedLoc;
     +
     + A llvm::DenseMap<const Type *, unsigned> TypeSubstitutions;
     +
     +public:
     + A explicit USRGenerator(ASTContext *Ctx = 0, SmallVectorImpl<char>
     *extBuf = 0)
     + A : OwnedBuf(extBuf ? 0 : new SmallString<128>()),
     + A  A Buf(extBuf ? *extBuf : *OwnedBuf.get()),
     + A  A Out(Buf),
     + A  A IgnoreResults(false),
     + A  A Context(Ctx),
     + A  A generatedLoc(false)
     + A {
     + A  A // Add the USR space prefix.
     + A  A Out << "c:";
     + A }
     +
     + A Str...

     [Message clipped]A A 

_______________________________________________
cfe-commits mailing list
cfe-commits at cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits




More information about the cfe-commits mailing list