SemaType.cpp (193380) | SemaType.cpp (194179) |
---|---|
1//===--- SemaType.cpp - Semantic Analysis for Types -----------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// --- 586 unchanged lines hidden (view full) --- 595 } 596 597 if (Invalid) 598 return QualType(); 599 600 return Context.getFunctionType(T, ParamTypes, NumParamTypes, Variadic, 601 Quals); 602} | 1//===--- SemaType.cpp - Semantic Analysis for Types -----------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// --- 586 unchanged lines hidden (view full) --- 595 } 596 597 if (Invalid) 598 return QualType(); 599 600 return Context.getFunctionType(T, ParamTypes, NumParamTypes, Variadic, 601 Quals); 602} |
603 | 603 604/// \brief Build a member pointer type \c T Class::*. 605/// 606/// \param T the type to which the member pointer refers. 607/// \param Class the class type into which the member pointer points. 608/// \param Quals Qualifiers applied to the member pointer type 609/// \param Loc the location where this type begins 610/// \param Entity the name of the entity that will have this member pointer type 611/// 612/// \returns a member pointer type, if successful, or a NULL type if there was 613/// an error. 614QualType Sema::BuildMemberPointerType(QualType T, QualType Class, 615 unsigned Quals, SourceLocation Loc, 616 DeclarationName Entity) { 617 // Verify that we're not building a pointer to pointer to function with 618 // exception specification. 619 if (CheckDistantExceptionSpec(T)) { 620 Diag(Loc, diag::err_distant_exception_spec); 621 622 // FIXME: If we're doing this as part of template instantiation, 623 // we should return immediately. 624 625 // Build the type anyway, but use the canonical type so that the 626 // exception specifiers are stripped off. 627 T = Context.getCanonicalType(T); 628 } 629 630 // C++ 8.3.3p3: A pointer to member shall not pointer to ... a member 631 // with reference type, or "cv void." 632 if (T->isReferenceType()) { 633 Diag(Loc, diag::err_illegal_decl_pointer_to_reference) 634 << (Entity? Entity.getAsString() : "type name"); 635 return QualType(); 636 } 637 638 if (T->isVoidType()) { 639 Diag(Loc, diag::err_illegal_decl_mempointer_to_void) 640 << (Entity? Entity.getAsString() : "type name"); 641 return QualType(); 642 } 643 644 // Enforce C99 6.7.3p2: "Types other than pointer types derived from 645 // object or incomplete types shall not be restrict-qualified." 646 if ((Quals & QualType::Restrict) && !T->isIncompleteOrObjectType()) { 647 Diag(Loc, diag::err_typecheck_invalid_restrict_invalid_pointee) 648 << T; 649 650 // FIXME: If we're doing this as part of template instantiation, 651 // we should return immediately. 652 Quals &= ~QualType::Restrict; 653 } 654 655 if (!Class->isDependentType() && !Class->isRecordType()) { 656 Diag(Loc, diag::err_mempointer_in_nonclass_type) << Class; 657 return QualType(); 658 } 659 660 return Context.getMemberPointerType(T, Class.getTypePtr()) 661 .getQualifiedType(Quals); 662} 663 664/// \brief Build a block pointer type. 665/// 666/// \param T The type to which we'll be building a block pointer. 667/// 668/// \param Quals The cvr-qualifiers to be applied to the block pointer type. 669/// 670/// \param Loc The location of the entity whose type involves this 671/// block pointer type or, if there is no such entity, the location of the 672/// type that will have block pointer type. 673/// 674/// \param Entity The name of the entity that involves the block pointer 675/// type, if known. 676/// 677/// \returns A suitable block pointer type, if there are no 678/// errors. Otherwise, returns a NULL type. 679QualType Sema::BuildBlockPointerType(QualType T, unsigned Quals, 680 SourceLocation Loc, 681 DeclarationName Entity) { 682 if (!T.getTypePtr()->isFunctionType()) { 683 Diag(Loc, diag::err_nonfunction_block_type); 684 return QualType(); 685 } 686 687 return Context.getBlockPointerType(T).getQualifiedType(Quals); 688} 689 |
604/// GetTypeForDeclarator - Convert the type for the specified 605/// declarator to Type instances. Skip the outermost Skip type 606/// objects. 607/// 608/// If OwnedDecl is non-NULL, and this declarator's decl-specifier-seq 609/// owns the declaration of a type (e.g., the definition of a struct 610/// type), then *OwnedDecl will receive the owned declaration. 611QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S, unsigned Skip, --- 58 unchanged lines hidden (view full) --- 670 DeclaratorChunk &DeclType = D.getTypeObject(e-i-1+Skip); 671 switch (DeclType.Kind) { 672 default: assert(0 && "Unknown decltype!"); 673 case DeclaratorChunk::BlockPointer: 674 // If blocks are disabled, emit an error. 675 if (!LangOpts.Blocks) 676 Diag(DeclType.Loc, diag::err_blocks_disable); 677 | 690/// GetTypeForDeclarator - Convert the type for the specified 691/// declarator to Type instances. Skip the outermost Skip type 692/// objects. 693/// 694/// If OwnedDecl is non-NULL, and this declarator's decl-specifier-seq 695/// owns the declaration of a type (e.g., the definition of a struct 696/// type), then *OwnedDecl will receive the owned declaration. 697QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S, unsigned Skip, --- 58 unchanged lines hidden (view full) --- 756 DeclaratorChunk &DeclType = D.getTypeObject(e-i-1+Skip); 757 switch (DeclType.Kind) { 758 default: assert(0 && "Unknown decltype!"); 759 case DeclaratorChunk::BlockPointer: 760 // If blocks are disabled, emit an error. 761 if (!LangOpts.Blocks) 762 Diag(DeclType.Loc, diag::err_blocks_disable); 763 |
678 if (!T.getTypePtr()->isFunctionType()) 679 Diag(D.getIdentifierLoc(), diag::err_nonfunction_block_type); 680 else 681 T = (Context.getBlockPointerType(T) 682 .getQualifiedType(DeclType.Cls.TypeQuals)); | 764 T = BuildBlockPointerType(T, DeclType.Cls.TypeQuals, D.getIdentifierLoc(), 765 Name); |
683 break; 684 case DeclaratorChunk::Pointer: 685 // Verify that we're not building a pointer to pointer to function with 686 // exception specification. 687 if (getLangOptions().CPlusPlus && CheckDistantExceptionSpec(T)) { 688 Diag(D.getIdentifierLoc(), diag::err_distant_exception_spec); 689 D.setInvalidType(true); 690 // Build the type anyway. --- 174 unchanged lines hidden (view full) --- 865 FTI.isVariadic, FTI.TypeQuals, 866 FTI.hasExceptionSpec, 867 FTI.hasAnyExceptionSpec, 868 Exceptions.size(), Exceptions.data()); 869 } 870 break; 871 } 872 case DeclaratorChunk::MemberPointer: | 766 break; 767 case DeclaratorChunk::Pointer: 768 // Verify that we're not building a pointer to pointer to function with 769 // exception specification. 770 if (getLangOptions().CPlusPlus && CheckDistantExceptionSpec(T)) { 771 Diag(D.getIdentifierLoc(), diag::err_distant_exception_spec); 772 D.setInvalidType(true); 773 // Build the type anyway. --- 174 unchanged lines hidden (view full) --- 948 FTI.isVariadic, FTI.TypeQuals, 949 FTI.hasExceptionSpec, 950 FTI.hasAnyExceptionSpec, 951 Exceptions.size(), Exceptions.data()); 952 } 953 break; 954 } 955 case DeclaratorChunk::MemberPointer: |
873 // Verify that we're not building a pointer to pointer to function with 874 // exception specification. 875 if (getLangOptions().CPlusPlus && CheckDistantExceptionSpec(T)) { 876 Diag(D.getIdentifierLoc(), diag::err_distant_exception_spec); 877 D.setInvalidType(true); 878 // Build the type anyway. 879 } | |
880 // The scope spec must refer to a class, or be dependent. | 956 // The scope spec must refer to a class, or be dependent. |
881 DeclContext *DC = computeDeclContext(DeclType.Mem.Scope()); | |
882 QualType ClsType; | 957 QualType ClsType; |
883 // FIXME: Extend for dependent types when it's actually supported. 884 // See ActOnCXXNestedNameSpecifier. 885 if (CXXRecordDecl *RD = dyn_cast_or_null<CXXRecordDecl>(DC)) { | 958 if (isDependentScopeSpecifier(DeclType.Mem.Scope())) { 959 NestedNameSpecifier *NNS 960 = (NestedNameSpecifier *)DeclType.Mem.Scope().getScopeRep(); 961 assert(NNS->getAsType() && "Nested-name-specifier must name a type"); 962 ClsType = QualType(NNS->getAsType(), 0); 963 } else if (CXXRecordDecl *RD 964 = dyn_cast_or_null<CXXRecordDecl>( 965 computeDeclContext(DeclType.Mem.Scope()))) { |
886 ClsType = Context.getTagDeclType(RD); 887 } else { | 966 ClsType = Context.getTagDeclType(RD); 967 } else { |
888 if (DC) { 889 Diag(DeclType.Mem.Scope().getBeginLoc(), 890 diag::err_illegal_decl_mempointer_in_nonclass) 891 << (D.getIdentifier() ? D.getIdentifier()->getName() : "type name") 892 << DeclType.Mem.Scope().getRange(); 893 } | 968 Diag(DeclType.Mem.Scope().getBeginLoc(), 969 diag::err_illegal_decl_mempointer_in_nonclass) 970 << (D.getIdentifier() ? D.getIdentifier()->getName() : "type name") 971 << DeclType.Mem.Scope().getRange(); |
894 D.setInvalidType(true); | 972 D.setInvalidType(true); |
895 ClsType = Context.IntTy; | |
896 } 897 | 973 } 974 |
898 // C++ 8.3.3p3: A pointer to member shall not pointer to ... a member 899 // with reference type, or "cv void." 900 if (T->isReferenceType()) { 901 Diag(DeclType.Loc, diag::err_illegal_decl_pointer_to_reference) 902 << (D.getIdentifier() ? D.getIdentifier()->getName() : "type name"); 903 D.setInvalidType(true); | 975 if (!ClsType.isNull()) 976 T = BuildMemberPointerType(T, ClsType, DeclType.Mem.TypeQuals, 977 DeclType.Loc, D.getIdentifier()); 978 if (T.isNull()) { |
904 T = Context.IntTy; | 979 T = Context.IntTy; |
980 D.setInvalidType(true); |
|
905 } | 981 } |
906 if (T->isVoidType()) { 907 Diag(DeclType.Loc, diag::err_illegal_decl_mempointer_to_void) 908 << (D.getIdentifier() ? D.getIdentifier()->getName() : "type name"); 909 T = Context.IntTy; 910 } 911 912 // Enforce C99 6.7.3p2: "Types other than pointer types derived from 913 // object or incomplete types shall not be restrict-qualified." 914 if ((DeclType.Mem.TypeQuals & QualType::Restrict) && 915 !T->isIncompleteOrObjectType()) { 916 Diag(DeclType.Loc, diag::err_typecheck_invalid_restrict_invalid_pointee) 917 << T; 918 DeclType.Mem.TypeQuals &= ~QualType::Restrict; 919 } 920 921 T = Context.getMemberPointerType(T, ClsType.getTypePtr()). 922 getQualifiedType(DeclType.Mem.TypeQuals); 923 | |
924 break; 925 } 926 927 if (T.isNull()) { 928 D.setInvalidType(true); 929 T = Context.IntTy; 930 } 931 --- 370 unchanged lines hidden --- | 982 break; 983 } 984 985 if (T.isNull()) { 986 D.setInvalidType(true); 987 T = Context.IntTy; 988 } 989 --- 370 unchanged lines hidden --- |