@@ -850,108 +850,102 @@ IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k,
850
850
return II;
851
851
}
852
852
853
- unsigned
854
- ASTDeclContextNameLookupTrait::ComputeHash (const DeclNameKey &Key) {
855
- llvm::FoldingSetNodeID ID;
856
- ID.AddInteger (Key.Kind );
857
-
858
- switch (Key.Kind ) {
853
+ DeclarationNameKey::DeclarationNameKey (DeclarationName Name)
854
+ : Kind(Name.getNameKind()) {
855
+ switch (Kind) {
859
856
case DeclarationName::Identifier:
860
- case DeclarationName::CXXLiteralOperatorName:
861
- ID.AddString (((IdentifierInfo*)Key.Data )->getName ());
857
+ Data = (uint64_t )Name.getAsIdentifierInfo ();
862
858
break ;
863
859
case DeclarationName::ObjCZeroArgSelector:
864
860
case DeclarationName::ObjCOneArgSelector:
865
861
case DeclarationName::ObjCMultiArgSelector:
866
- ID. AddInteger ( serialization::ComputeHash ( Selector (Key. Data )) );
862
+ Data = ( uint64_t )Name. getObjCSelector (). getAsOpaquePtr ( );
867
863
break ;
868
864
case DeclarationName::CXXOperatorName:
869
- ID.AddInteger ((OverloadedOperatorKind)Key.Data );
865
+ Data = Name.getCXXOverloadedOperator ();
866
+ break ;
867
+ case DeclarationName::CXXLiteralOperatorName:
868
+ Data = (uint64_t )Name.getCXXLiteralIdentifier ();
870
869
break ;
871
870
case DeclarationName::CXXConstructorName:
872
871
case DeclarationName::CXXDestructorName:
873
872
case DeclarationName::CXXConversionFunctionName:
874
873
case DeclarationName::CXXUsingDirective:
874
+ Data = 0 ;
875
875
break ;
876
876
}
877
-
878
- return ID.ComputeHash ();
879
877
}
880
878
881
- ASTDeclContextNameLookupTrait::internal_key_type
882
- ASTDeclContextNameLookupTrait::GetInternalKey (
883
- const external_key_type& Name) {
884
- DeclNameKey Key;
885
- Key.Kind = Name.getNameKind ();
886
- switch (Name.getNameKind ()) {
879
+ unsigned DeclarationNameKey::getHash () const {
880
+ llvm::FoldingSetNodeID ID;
881
+ ID.AddInteger (Kind);
882
+
883
+ switch (Kind) {
887
884
case DeclarationName::Identifier:
888
- Key.Data = (uint64_t )Name.getAsIdentifierInfo ();
885
+ case DeclarationName::CXXLiteralOperatorName:
886
+ ID.AddString (((IdentifierInfo*)Data)->getName ());
889
887
break ;
890
888
case DeclarationName::ObjCZeroArgSelector:
891
889
case DeclarationName::ObjCOneArgSelector:
892
890
case DeclarationName::ObjCMultiArgSelector:
893
- Key. Data = ( uint64_t )Name. getObjCSelector (). getAsOpaquePtr ( );
891
+ ID. AddInteger ( serialization::ComputeHash ( Selector (Data)) );
894
892
break ;
895
893
case DeclarationName::CXXOperatorName:
896
- Key.Data = Name.getCXXOverloadedOperator ();
897
- break ;
898
- case DeclarationName::CXXLiteralOperatorName:
899
- Key.Data = (uint64_t )Name.getCXXLiteralIdentifier ();
894
+ ID.AddInteger ((OverloadedOperatorKind)Data);
900
895
break ;
901
896
case DeclarationName::CXXConstructorName:
902
897
case DeclarationName::CXXDestructorName:
903
898
case DeclarationName::CXXConversionFunctionName:
904
899
case DeclarationName::CXXUsingDirective:
905
- Key.Data = 0 ;
906
900
break ;
907
901
}
908
902
909
- return Key ;
903
+ return ID. ComputeHash () ;
910
904
}
911
905
912
906
std::pair<unsigned , unsigned >
913
- ASTDeclContextNameLookupTrait::ReadKeyDataLength (const unsigned char *& d) {
907
+ ASTDeclContextNameLookupTrait::ReadKeyDataLength (const unsigned char *& d) {
914
908
using namespace llvm ::support;
915
909
unsigned KeyLen = endian::readNext<uint16_t , little, unaligned>(d);
916
910
unsigned DataLen = endian::readNext<uint16_t , little, unaligned>(d);
917
911
return std::make_pair (KeyLen, DataLen);
918
912
}
919
913
920
- ASTDeclContextNameLookupTrait::internal_key_type
921
- ASTDeclContextNameLookupTrait::ReadKey (const unsigned char * d, unsigned ) {
914
+ ASTDeclContextNameLookupTrait::internal_key_type
915
+ ASTDeclContextNameLookupTrait::ReadKey (const unsigned char * d, unsigned ) {
922
916
using namespace llvm ::support;
923
917
924
- DeclNameKey Key ;
925
- Key. Kind = (DeclarationName::NameKind)*d++ ;
926
- switch (Key. Kind ) {
918
+ auto Kind = (DeclarationName::NameKind)*d++ ;
919
+ uint64_t Data ;
920
+ switch (Kind) {
927
921
case DeclarationName::Identifier:
928
- Key. Data = (uint64_t )Reader.getLocalIdentifier (
922
+ Data = (uint64_t )Reader.getLocalIdentifier (
929
923
F, endian::readNext<uint32_t , little, unaligned>(d));
930
924
break ;
931
925
case DeclarationName::ObjCZeroArgSelector:
932
926
case DeclarationName::ObjCOneArgSelector:
933
927
case DeclarationName::ObjCMultiArgSelector:
934
- Key. Data =
928
+ Data =
935
929
(uint64_t )Reader.getLocalSelector (
936
930
F, endian::readNext<uint32_t , little, unaligned>(
937
931
d)).getAsOpaquePtr ();
938
932
break ;
939
933
case DeclarationName::CXXOperatorName:
940
- Key. Data = *d++; // OverloadedOperatorKind
934
+ Data = *d++; // OverloadedOperatorKind
941
935
break ;
942
936
case DeclarationName::CXXLiteralOperatorName:
943
- Key. Data = (uint64_t )Reader.getLocalIdentifier (
937
+ Data = (uint64_t )Reader.getLocalIdentifier (
944
938
F, endian::readNext<uint32_t , little, unaligned>(d));
945
939
break ;
946
940
case DeclarationName::CXXConstructorName:
947
941
case DeclarationName::CXXDestructorName:
948
942
case DeclarationName::CXXConversionFunctionName:
949
943
case DeclarationName::CXXUsingDirective:
950
- Key. Data = 0 ;
944
+ Data = 0 ;
951
945
break ;
952
946
}
953
947
954
- return Key ;
948
+ return DeclarationNameKey (Kind, Data) ;
955
949
}
956
950
957
951
ASTDeclContextNameLookupTrait::data_type
@@ -6388,21 +6382,18 @@ namespace {
6388
6382
ASTReader &Reader;
6389
6383
const DeclContext *Context;
6390
6384
DeclarationName Name;
6391
- ASTDeclContextNameLookupTrait::DeclNameKey NameKey;
6385
+ DeclarationNameKey NameKey;
6392
6386
unsigned NameHash;
6393
6387
SmallVectorImpl<NamedDecl *> &Decls;
6394
6388
llvm::SmallPtrSetImpl<NamedDecl *> &DeclSet;
6395
6389
6396
6390
public:
6397
- DeclContextNameLookupVisitor (ASTReader &Reader,
6398
- const DeclContext *Context,
6391
+ DeclContextNameLookupVisitor (ASTReader &Reader, const DeclContext *Context,
6399
6392
DeclarationName Name,
6400
6393
SmallVectorImpl<NamedDecl *> &Decls,
6401
6394
llvm::SmallPtrSetImpl<NamedDecl *> &DeclSet)
6402
- : Reader(Reader), Context(Context), Name(Name),
6403
- NameKey (ASTDeclContextNameLookupTrait::GetInternalKey(Name)),
6404
- NameHash(ASTDeclContextNameLookupTrait::ComputeHash(NameKey)),
6405
- Decls(Decls), DeclSet(DeclSet) {}
6395
+ : Reader(Reader), Context(Context), Name(Name), NameKey(Name),
6396
+ NameHash (NameKey.getHash()), Decls(Decls), DeclSet(DeclSet) {}
6406
6397
6407
6398
bool operator ()(ModuleFile &M) {
6408
6399
// Check whether we have any visible declaration information for
@@ -6427,12 +6418,9 @@ namespace {
6427
6418
continue ;
6428
6419
6429
6420
if (ND->getDeclName () != Name) {
6430
- // A name might be null because the decl's redeclarable part is
6431
- // currently read before reading its name. The lookup is triggered by
6432
- // building that decl (likely indirectly), and so it is later in the
6433
- // sense of "already existing" and can be ignored here.
6434
- // FIXME: This should not happen; deserializing declarations should
6435
- // not perform lookups since that can lead to deserialization cycles.
6421
+ // Not all names map to a unique DeclarationNameKey.
6422
+ assert (DeclarationNameKey (ND->getDeclName ()) == NameKey &&
6423
+ " mismatched name for decl in decl context lookup table?" );
6436
6424
continue ;
6437
6425
}
6438
6426
0 commit comments