[cfe-commits] r79396 - in /cfe/trunk/lib/Frontend: PCHReaderDecl.cpp PCHWriterDecl.cpp

Argiris Kirtzidis akyrtzi at gmail.com
Tue Aug 18 18:28:35 PDT 2009


Author: akirtzidis
Date: Tue Aug 18 20:28:35 2009
New Revision: 79396

URL: http://llvm.org/viewvc/llvm-project?rev=79396&view=rev
Log:
Store/load type source info from/to PCH files.

Modified:
    cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
    cfe/trunk/lib/Frontend/PCHWriterDecl.cpp

Modified: cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReaderDecl.cpp?rev=79396&r1=79395&r2=79396&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHReaderDecl.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReaderDecl.cpp Tue Aug 18 20:28:35 2009
@@ -18,6 +18,7 @@
 #include "clang/AST/DeclVisitor.h"
 #include "clang/AST/DeclGroup.h"
 #include "clang/AST/Expr.h"
+#include "clang/AST/TypeLoc.h"
 using namespace clang;
 
 
@@ -46,6 +47,7 @@
     void VisitRecordDecl(RecordDecl *RD);
     void VisitValueDecl(ValueDecl *VD);
     void VisitEnumConstantDecl(EnumConstantDecl *ECD);
+    void VisitDeclaratorDecl(DeclaratorDecl *DD);
     void VisitFunctionDecl(FunctionDecl *FD);
     void VisitFieldDecl(FieldDecl *FD);
     void VisitVarDecl(VarDecl *VD);
@@ -147,8 +149,76 @@
   ECD->setInitVal(Reader.ReadAPSInt(Record, Idx));
 }
 
+namespace {
+
+class TypeLocReader : public TypeLocVisitor<TypeLocReader> {
+  PCHReader &Reader;
+  const PCHReader::RecordData &Record;
+  unsigned &Idx;
+
+public:
+  TypeLocReader(PCHReader &Reader, const PCHReader::RecordData &Record,
+                unsigned &Idx)
+    : Reader(Reader), Record(Record), Idx(Idx) { }
+
+#define ABSTRACT_TYPELOC(CLASS)
+#define TYPELOC(CLASS, PARENT, TYPE) \
+    void Visit##CLASS(CLASS TyLoc); 
+#include "clang/AST/TypeLocNodes.def"
+  
+  void VisitTypeLoc(TypeLoc TyLoc) {
+    assert(0 && "A type loc wrapper was not handled!");
+  }
+};
+
+}
+
+void TypeLocReader::VisitDefaultTypeSpecLoc(DefaultTypeSpecLoc TyLoc) {
+  TyLoc.setStartLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+}
+void TypeLocReader::VisitTypedefLoc(TypedefLoc TyLoc) {
+  TyLoc.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+}
+void TypeLocReader::VisitPointerLoc(PointerLoc TyLoc) {
+  TyLoc.setStarLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+}
+void TypeLocReader::VisitBlockPointerLoc(BlockPointerLoc TyLoc) {
+  TyLoc.setCaretLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+}
+void TypeLocReader::VisitMemberPointerLoc(MemberPointerLoc TyLoc) {
+  TyLoc.setStarLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+}
+void TypeLocReader::VisitReferenceLoc(ReferenceLoc TyLoc) {
+  TyLoc.setAmpLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+}
+void TypeLocReader::VisitFunctionLoc(FunctionLoc TyLoc) {
+  TyLoc.setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+  TyLoc.setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+  for (unsigned i = 0, e = TyLoc.getNumArgs(); i != e; ++i)
+    TyLoc.setArg(i, cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
+}
+void TypeLocReader::VisitArrayLoc(ArrayLoc TyLoc) {
+  TyLoc.setLBracketLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+  TyLoc.setRBracketLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+  if (Record[Idx++])
+    TyLoc.setSizeExpr(Reader.ReadDeclExpr());
+}
+
+void PCHDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
+  VisitValueDecl(DD);
+  QualType InfoTy = Reader.GetType(Record[Idx++]);
+  if (InfoTy.isNull())
+    return;
+
+  DeclaratorInfo *DInfo = Reader.getContext()->CreateDeclaratorInfo(InfoTy);
+  TypeLocReader TLR(Reader, Record, Idx);
+  for (TypeLoc TL = DInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc())
+    TLR.Visit(TL);
+  DD->setDeclaratorInfo(DInfo);
+}
+
 void PCHDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
-  VisitValueDecl(FD);
+  VisitDeclaratorDecl(FD);
   if (Record[Idx++])
     FD->setLazyBody(Reader.getDeclsCursor().GetCurrentBitNo());
   FD->setPreviousDeclaration(
@@ -333,7 +403,7 @@
 }
 
 void PCHDeclReader::VisitFieldDecl(FieldDecl *FD) {
-  VisitValueDecl(FD);
+  VisitDeclaratorDecl(FD);
   FD->setMutable(Record[Idx++]);
   FD->setTypeSpecStartLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
   if (Record[Idx++])
@@ -341,7 +411,7 @@
 }
 
 void PCHDeclReader::VisitVarDecl(VarDecl *VD) {
-  VisitValueDecl(VD);
+  VisitDeclaratorDecl(VD);
   VD->setStorageClass((VarDecl::StorageClass)Record[Idx++]);
   VD->setThreadSpecified(Record[Idx++]);
   VD->setCXXDirectInitializer(Record[Idx++]);

Modified: cfe/trunk/lib/Frontend/PCHWriterDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriterDecl.cpp?rev=79396&r1=79395&r2=79396&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriterDecl.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriterDecl.cpp Tue Aug 18 20:28:35 2009
@@ -14,6 +14,7 @@
 #include "clang/Frontend/PCHWriter.h"
 #include "clang/AST/DeclVisitor.h"
 #include "clang/AST/Expr.h"
+#include "clang/AST/TypeLoc.h"
 #include "llvm/Bitcode/BitstreamWriter.h"
 using namespace clang;
 
@@ -47,6 +48,7 @@
     void VisitRecordDecl(RecordDecl *D);
     void VisitValueDecl(ValueDecl *D);
     void VisitEnumConstantDecl(EnumConstantDecl *D);
+    void VisitDeclaratorDecl(DeclaratorDecl *D);
     void VisitFunctionDecl(FunctionDecl *D);
     void VisitFieldDecl(FieldDecl *D);
     void VisitVarDecl(VarDecl *D);
@@ -145,9 +147,76 @@
   Writer.AddAPSInt(D->getInitVal(), Record);
   Code = pch::DECL_ENUM_CONSTANT;
 }
+namespace {
 
-void PCHDeclWriter::VisitFunctionDecl(FunctionDecl *D) {
+class TypeLocWriter : public TypeLocVisitor<TypeLocWriter> {
+  PCHWriter &Writer;
+  PCHWriter::RecordData &Record;
+
+public:
+  TypeLocWriter(PCHWriter &Writer, PCHWriter::RecordData &Record)
+    : Writer(Writer), Record(Record) { }
+
+#define ABSTRACT_TYPELOC(CLASS)
+#define TYPELOC(CLASS, PARENT, TYPE) \
+    void Visit##CLASS(CLASS TyLoc); 
+#include "clang/AST/TypeLocNodes.def"
+  
+  void VisitTypeLoc(TypeLoc TyLoc) {
+    assert(0 && "A type loc wrapper was not handled!");
+  }
+};
+
+}
+
+void TypeLocWriter::VisitDefaultTypeSpecLoc(DefaultTypeSpecLoc TyLoc) {
+  Writer.AddSourceLocation(TyLoc.getStartLoc(), Record);
+}
+void TypeLocWriter::VisitTypedefLoc(TypedefLoc TyLoc) {
+  Writer.AddSourceLocation(TyLoc.getNameLoc(), Record);
+}
+void TypeLocWriter::VisitPointerLoc(PointerLoc TyLoc) {
+  Writer.AddSourceLocation(TyLoc.getStarLoc(), Record);
+}
+void TypeLocWriter::VisitBlockPointerLoc(BlockPointerLoc TyLoc) {
+  Writer.AddSourceLocation(TyLoc.getCaretLoc(), Record);
+}
+void TypeLocWriter::VisitMemberPointerLoc(MemberPointerLoc TyLoc) {
+  Writer.AddSourceLocation(TyLoc.getStarLoc(), Record);
+}
+void TypeLocWriter::VisitReferenceLoc(ReferenceLoc TyLoc) {
+  Writer.AddSourceLocation(TyLoc.getAmpLoc(), Record);
+}
+void TypeLocWriter::VisitFunctionLoc(FunctionLoc TyLoc) {
+  Writer.AddSourceLocation(TyLoc.getLParenLoc(), Record);
+  Writer.AddSourceLocation(TyLoc.getRParenLoc(), Record);
+  for (unsigned i = 0, e = TyLoc.getNumArgs(); i != e; ++i)
+    Writer.AddDeclRef(TyLoc.getArg(i), Record);
+}
+void TypeLocWriter::VisitArrayLoc(ArrayLoc TyLoc) {
+  Writer.AddSourceLocation(TyLoc.getLBracketLoc(), Record);
+  Writer.AddSourceLocation(TyLoc.getRBracketLoc(), Record);
+  Record.push_back(TyLoc.getSizeExpr() ? 1 : 0);
+  if (TyLoc.getSizeExpr())
+    Writer.AddStmt(TyLoc.getSizeExpr());
+}
+
+void PCHDeclWriter::VisitDeclaratorDecl(DeclaratorDecl *D) {
   VisitValueDecl(D);
+  DeclaratorInfo *DInfo = D->getDeclaratorInfo();
+  if (DInfo == 0) {
+    Writer.AddTypeRef(QualType(), Record);
+    return;
+  }
+  
+  Writer.AddTypeRef(DInfo->getTypeLoc().getSourceType(), Record);
+  TypeLocWriter TLW(Writer, Record);
+  for (TypeLoc TL = DInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc())
+    TLW.Visit(TL);
+}
+
+void PCHDeclWriter::VisitFunctionDecl(FunctionDecl *D) {
+  VisitDeclaratorDecl(D);
   Record.push_back(D->isThisDeclarationADefinition());
   if (D->isThisDeclarationADefinition())
     Writer.AddStmt(D->getBody());
@@ -324,7 +393,7 @@
 }
 
 void PCHDeclWriter::VisitFieldDecl(FieldDecl *D) {
-  VisitValueDecl(D);
+  VisitDeclaratorDecl(D);
   Record.push_back(D->isMutable());
   Writer.AddSourceLocation(D->getTypeSpecStartLoc(), Record);
   Record.push_back(D->getBitWidth()? 1 : 0);
@@ -334,7 +403,7 @@
 }
 
 void PCHDeclWriter::VisitVarDecl(VarDecl *D) {
-  VisitValueDecl(D);
+  VisitDeclaratorDecl(D);
   Record.push_back(D->getStorageClass()); // FIXME: stable encoding
   Record.push_back(D->isThreadSpecified());
   Record.push_back(D->hasCXXDirectInitializer());
@@ -361,7 +430,8 @@
   // If the assumptions about the DECL_PARM_VAR abbrev are true, use it.  Here
   // we dynamically check for the properties that we optimize for, but don't
   // know are true of all PARM_VAR_DECLs.
-  if (!D->hasAttrs() &&
+  if (!D->getDeclaratorInfo() &&
+      !D->hasAttrs() &&
       !D->isImplicit() &&
       !D->isUsed() &&
       D->getAccess() == AS_none &&
@@ -446,6 +516,8 @@
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
   // ValueDecl
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
+  // DeclaratorDecl
+  Abv->Add(BitCodeAbbrevOp(pch::PREDEF_TYPE_NULL_ID)); // InfoType
   // VarDecl
   Abv->Add(BitCodeAbbrevOp(0));                       // StorageClass
   Abv->Add(BitCodeAbbrevOp(0));                       // isThreadSpecified





More information about the cfe-commits mailing list