typedef llvm::SmallVector<uint64_t, 64> RecordData;
PCHReader(Preprocessor &PP, ASTContext &Context)
- : PP(PP), Context(Context), Buffer() { }
+ : PP(PP), Context(Context), IdentifierTable(0) { }
- ~PCHReader();
+ ~PCHReader() {}
PCHReadResult ReadPCH(const std::string &FileName);
/// \brief Report a diagnostic.
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID);
- const IdentifierInfo *GetIdentifierInfo(const RecordData &Record,
- unsigned &Idx);
+ IdentifierInfo *DecodeIdentifierInfo(unsigned Idx);
+
+ IdentifierInfo *GetIdentifierInfo(const RecordData &Record, unsigned &Idx) {
+ return DecodeIdentifierInfo(Record[Idx++]);
+ }
DeclarationName ReadDeclarationName(const RecordData &Record, unsigned &Idx);
};
if (Stream.EnterSubBlock(pch::PREPROCESSOR_BLOCK_ID))
return Error("Malformed preprocessor block record");
- std::string CurName; // FIXME: HACK.
RecordData Record;
llvm::SmallVector<IdentifierInfo*, 16> MacroArgs;
MacroInfo *LastMacro = 0;
default: // Default behavior: ignore unknown records.
break;
- case pch::PP_MACRO_NAME:
- // Set CurName. FIXME: This is a hack and should be removed when we have
- // identifier id's.
- CurName.clear();
- for (unsigned i = 0, e = Record.size(); i != e; ++i)
- CurName += (char)Record[i];
- break;
-
case pch::PP_MACRO_OBJECT_LIKE:
case pch::PP_MACRO_FUNCTION_LIKE: {
- unsigned IdentInfo = Record[0];
- IdentInfo = IdentInfo; // FIXME: Decode into identifier info*.
- assert(!CurName.empty());
- IdentifierInfo *II = PP.getIdentifierInfo(CurName.c_str());
-
+ IdentifierInfo *II = DecodeIdentifierInfo(Record[0]);
+ if (II == 0)
+ return Error("Macro must have a name");
SourceLocation Loc = SourceLocation::getFromRawEncoding(Record[1]);
bool isUsed = Record[2];
MacroArgs.clear();
unsigned NumArgs = Record[5];
for (unsigned i = 0; i != NumArgs; ++i)
- ; // FIXME: Decode macro arg names: MacroArgs.push_back(Record[6+i]);
+ MacroArgs.push_back(DecodeIdentifierInfo(Record[6+i]));
// Install function-like macro info.
MI->setIsFunctionLike();
Tok.startToken();
Tok.setLocation(SourceLocation::getFromRawEncoding(Record[0]));
Tok.setLength(Record[1]);
- unsigned IdentInfo = Record[2];
- IdentInfo = IdentInfo; // FIXME: Handle this right.
+ if (IdentifierInfo *II = DecodeIdentifierInfo(Record[2]))
+ Tok.setIdentifierInfo(II);
Tok.setKind((tok::TokenKind)Record[3]);
Tok.setFlag((Token::TokenFlags)Record[4]);
LastMacro->AddTokenToBody(Tok);
return Failure;
}
+ uint64_t PreprocessorBlockBit = 0;
+
// Read all of the records and blocks for the PCH file.
RecordData Record;
while (!Stream.AtEndOfStream()) {
unsigned Code = Stream.ReadCode();
if (Code == llvm::bitc::END_BLOCK) {
+ // If we saw the preprocessor block, read it now.
+ if (PreprocessorBlockBit) {
+ uint64_t SavedPos = Stream.GetCurrentBitNo();
+ Stream.JumpToBit(PreprocessorBlockBit);
+ if (ReadPreprocessorBlock()) {
+ Error("Malformed preprocessor block");
+ return Failure;
+ }
+ Stream.JumpToBit(SavedPos);
+ }
+
if (Stream.ReadBlockEnd()) {
Error("Error at end of module block");
return Failure;
}
+
return Success;
}
}
break;
+ case pch::PREPROCESSOR_BLOCK_ID:
+ // Skip the preprocessor block for now, but remember where it is. We
+ // want to read it in after the identifier table.
+ if (PreprocessorBlockBit) {
+ Error("Multiple preprocessor blocks found.");
+ return Failure;
+ }
+ PreprocessorBlockBit = Stream.GetCurrentBitNo();
+ if (Stream.SkipBlock()) {
+ Error("Malformed block record");
+ return Failure;
+ }
+ break;
+
case pch::SOURCE_MANAGER_BLOCK_ID:
switch (ReadSourceManagerBlock()) {
case Success:
return IgnorePCH;
}
break;
-
- case pch::PREPROCESSOR_BLOCK_ID:
- if (ReadPreprocessorBlock()) {
- Error("Malformed preprocessor block");
- return Failure;
- }
- break;
}
continue;
}
return Failure;
}
-PCHReader::~PCHReader() { }
-
PCHReader::PCHReadResult PCHReader::ReadPCH(const std::string &FileName) {
// Set the PCH file name.
this->FileName = FileName;
std::fprintf(stderr, "\n");
}
-const IdentifierInfo *PCHReader::GetIdentifierInfo(const RecordData &Record,
- unsigned &Idx) {
- pch::IdentID ID = Record[Idx++];
+IdentifierInfo *PCHReader::DecodeIdentifierInfo(unsigned ID) {
if (ID == 0)
return 0;
-
+
if (!IdentifierTable || IdentifierData.empty()) {
Error("No identifier table in PCH file");
return 0;
}
-
+
if (IdentifierData[ID - 1] & 0x01) {
uint64_t Offset = IdentifierData[ID - 1];
IdentifierData[ID - 1] = reinterpret_cast<uint64_t>(
- &Context.Idents.get(IdentifierTable + Offset));
+ &Context.Idents.get(IdentifierTable + Offset));
}
-
- return reinterpret_cast<const IdentifierInfo *>(IdentifierData[ID - 1]);
+
+ return reinterpret_cast<IdentifierInfo *>(IdentifierData[ID - 1]);
}
DeclarationName
if (MI->isBuiltinMacro())
continue;
- IdentifierInfo *II = I->first;
-
- // FIXME: Emit a PP_MACRO_NAME for testing. This should be removed when we
- // have identifierinfo id's.
- for (unsigned i = 0, e = II->getLength(); i != e; ++i)
- Record.push_back(II->getName()[i]);
- S.EmitRecord(pch::PP_MACRO_NAME, Record);
- Record.clear();
-
- // FIXME: Output the identifier Info ID #!
- Record.push_back((intptr_t)II);
+ AddIdentifierRef(I->first, Record);
Record.push_back(MI->getDefinitionLoc().getRawEncoding());
Record.push_back(MI->isUsed());
Record.push_back(MI->getNumArgs());
for (MacroInfo::arg_iterator I = MI->arg_begin(), E = MI->arg_end();
I != E; ++I)
- // FIXME: Output the identifier Info ID #!
- Record.push_back((intptr_t)II);
+ AddIdentifierRef(*I, Record);
}
S.EmitRecord(Code, Record);
Record.clear();
Record.push_back(Tok.getLocation().getRawEncoding());
Record.push_back(Tok.getLength());
- // FIXME: Output the identifier Info ID #!
// FIXME: When reading literal tokens, reconstruct the literal pointer if
// it is needed.
- Record.push_back((intptr_t)Tok.getIdentifierInfo());
+ AddIdentifierRef(Tok.getIdentifierInfo(), Record);
// FIXME: Should translate token kind to a stable encoding.
Record.push_back(Tok.getKind());