From 76c2f2c9dae885fd51971ba8d3b9709355adeade Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Fri, 17 Jul 2015 20:09:43 +0000 Subject: [PATCH] Refactor to remove repetition, no functionality change. llvm-svn: 242564 --- clang/lib/Serialization/ASTReader.cpp | 67 ++++++++++++++--------------------- 1 file changed, 27 insertions(+), 40 deletions(-) diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 96f6ca5..c25d905 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -744,6 +744,12 @@ static bool isInterestingIdentifier(IdentifierInfo &II) { II.getFETokenInfo(); } +static bool readBit(unsigned &Bits) { + bool Value = Bits & 0x1; + Bits >>= 1; + return Value; +} + IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k, const unsigned char* d, unsigned DataLen) { @@ -754,57 +760,38 @@ IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k, // Wipe out the "is interesting" bit. RawID = RawID >> 1; + // Build the IdentifierInfo and link the identifier ID with it. + IdentifierInfo *II = KnownII; + if (!II) { + II = &Reader.getIdentifierTable().getOwn(k); + KnownII = II; + } + if (!II->isFromAST()) { + II->setIsFromAST(); + if (isInterestingIdentifier(*II)) + II->setChangedSinceDeserialization(); + } + Reader.markIdentifierUpToDate(II); + IdentID ID = Reader.getGlobalIdentifierID(F, RawID); if (!IsInteresting) { - // For uninteresting identifiers, just build the IdentifierInfo - // and associate it with the persistent ID. - IdentifierInfo *II = KnownII; - if (!II) { - II = &Reader.getIdentifierTable().getOwn(k); - KnownII = II; - } + // For uninteresting identifiers, there's nothing else to do. Just notify + // the reader that we've finished loading this identifier. Reader.SetIdentifierInfo(ID, II); - if (!II->isFromAST()) { - bool WasInteresting = isInterestingIdentifier(*II); - II->setIsFromAST(); - if (WasInteresting) - II->setChangedSinceDeserialization(); - } - Reader.markIdentifierUpToDate(II); return II; } unsigned ObjCOrBuiltinID = endian::readNext(d); unsigned Bits = endian::readNext(d); - bool CPlusPlusOperatorKeyword = Bits & 0x01; - Bits >>= 1; - bool HasRevertedTokenIDToIdentifier = Bits & 0x01; - Bits >>= 1; - bool Poisoned = Bits & 0x01; - Bits >>= 1; - bool ExtensionToken = Bits & 0x01; - Bits >>= 1; - bool hadMacroDefinition = Bits & 0x01; - Bits >>= 1; + bool CPlusPlusOperatorKeyword = readBit(Bits); + bool HasRevertedTokenIDToIdentifier = readBit(Bits); + bool Poisoned = readBit(Bits); + bool ExtensionToken = readBit(Bits); + bool HadMacroDefinition = readBit(Bits); assert(Bits == 0 && "Extra bits in the identifier?"); DataLen -= 8; - // Build the IdentifierInfo itself and link the identifier ID with - // the new IdentifierInfo. - IdentifierInfo *II = KnownII; - if (!II) { - II = &Reader.getIdentifierTable().getOwn(StringRef(k)); - KnownII = II; - } - Reader.markIdentifierUpToDate(II); - if (!II->isFromAST()) { - bool WasInteresting = isInterestingIdentifier(*II); - II->setIsFromAST(); - if (WasInteresting) - II->setChangedSinceDeserialization(); - } - // Set or check the various bits in the IdentifierInfo structure. // Token IDs are read-only. if (HasRevertedTokenIDToIdentifier && II->getTokenID() != tok::identifier) @@ -821,7 +808,7 @@ IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k, // If this identifier is a macro, deserialize the macro // definition. - if (hadMacroDefinition) { + if (HadMacroDefinition) { uint32_t MacroDirectivesOffset = endian::readNext(d); DataLen -= 4; -- 2.7.4