forked from OSchip/llvm-project
				
			implement serialization support for @encode,
fix a couple of bugs in reader support for ObjCInterfaceDecl, and add support for reading ObjCInterfaceType. llvm-svn: 69779
This commit is contained in:
		
							parent
							
								
									01146a5fa9
								
							
						
					
					
						commit
						19cea4eeb4
					
				| 
						 | 
					@ -65,15 +65,23 @@ public:
 | 
				
			||||||
                 SourceLocation at, SourceLocation rp)
 | 
					                 SourceLocation at, SourceLocation rp)
 | 
				
			||||||
    : Expr(ObjCEncodeExprClass, T), EncType(ET), AtLoc(at), RParenLoc(rp) {}
 | 
					    : Expr(ObjCEncodeExprClass, T), EncType(ET), AtLoc(at), RParenLoc(rp) {}
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
 | 
					  /// \brief Build an empty block expression.
 | 
				
			||||||
 | 
					  explicit ObjCEncodeExpr(EmptyShell Empty) : Expr(ObjCEncodeExprClass, Empty){}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
  SourceLocation getAtLoc() const { return AtLoc; }
 | 
					  SourceLocation getAtLoc() const { return AtLoc; }
 | 
				
			||||||
 | 
					  void setAtLoc(SourceLocation L) { AtLoc = L; }
 | 
				
			||||||
  SourceLocation getRParenLoc() const { return RParenLoc; }
 | 
					  SourceLocation getRParenLoc() const { return RParenLoc; }
 | 
				
			||||||
 | 
					  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					  QualType getEncodedType() const { return EncType; }
 | 
				
			||||||
 | 
					  void setEncodedType(QualType T) { EncType = T; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  virtual SourceRange getSourceRange() const {
 | 
					  virtual SourceRange getSourceRange() const {
 | 
				
			||||||
    return SourceRange(AtLoc, RParenLoc);
 | 
					    return SourceRange(AtLoc, RParenLoc);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
  QualType getEncodedType() const { return EncType; }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  static bool classof(const Stmt *T) {
 | 
					  static bool classof(const Stmt *T) {
 | 
				
			||||||
    return T->getStmtClass() == ObjCEncodeExprClass;
 | 
					    return T->getStmtClass() == ObjCEncodeExprClass;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -520,7 +520,12 @@ namespace clang {
 | 
				
			||||||
      /// \brief BlockExpr
 | 
					      /// \brief BlockExpr
 | 
				
			||||||
      EXPR_BLOCK,
 | 
					      EXPR_BLOCK,
 | 
				
			||||||
      /// \brief A BlockDeclRef record.
 | 
					      /// \brief A BlockDeclRef record.
 | 
				
			||||||
      EXPR_BLOCK_DECL_REF
 | 
					      EXPR_BLOCK_DECL_REF,
 | 
				
			||||||
 | 
					      
 | 
				
			||||||
 | 
					      // Objective-C
 | 
				
			||||||
 | 
					      /// \brief A ObjCEncodeExpr record.
 | 
				
			||||||
 | 
					      EXPR_OBJC_ENCODE
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /// \brief The kinds of designators that can occur in a
 | 
					    /// \brief The kinds of designators that can occur in a
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -225,7 +225,8 @@ void PCHDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
 | 
				
			||||||
void PCHDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
 | 
					void PCHDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
 | 
				
			||||||
  VisitObjCContainerDecl(ID);
 | 
					  VisitObjCContainerDecl(ID);
 | 
				
			||||||
  ID->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr());
 | 
					  ID->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr());
 | 
				
			||||||
  ID->setSuperClass(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
 | 
					  ID->setSuperClass(cast_or_null<ObjCInterfaceDecl>
 | 
				
			||||||
 | 
					                       (Reader.GetDecl(Record[Idx++])));
 | 
				
			||||||
  unsigned NumIvars = Record[Idx++];
 | 
					  unsigned NumIvars = Record[Idx++];
 | 
				
			||||||
  llvm::SmallVector<ObjCIvarDecl *, 16> IVars;
 | 
					  llvm::SmallVector<ObjCIvarDecl *, 16> IVars;
 | 
				
			||||||
  IVars.reserve(NumIvars);
 | 
					  IVars.reserve(NumIvars);
 | 
				
			||||||
| 
						 | 
					@ -237,6 +238,7 @@ void PCHDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
 | 
				
			||||||
  ID->setImplicitInterfaceDecl(Record[Idx++]);
 | 
					  ID->setImplicitInterfaceDecl(Record[Idx++]);
 | 
				
			||||||
  ID->setClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
 | 
					  ID->setClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
 | 
				
			||||||
  ID->setSuperClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
 | 
					  ID->setSuperClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
 | 
				
			||||||
 | 
					  ID->setAtEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
 | 
				
			||||||
  // FIXME: add protocols, categories.
 | 
					  // FIXME: add protocols, categories.
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -464,6 +466,7 @@ namespace {
 | 
				
			||||||
    unsigned VisitShuffleVectorExpr(ShuffleVectorExpr *E);
 | 
					    unsigned VisitShuffleVectorExpr(ShuffleVectorExpr *E);
 | 
				
			||||||
    unsigned VisitBlockExpr(BlockExpr *E);
 | 
					    unsigned VisitBlockExpr(BlockExpr *E);
 | 
				
			||||||
    unsigned VisitBlockDeclRefExpr(BlockDeclRefExpr *E);
 | 
					    unsigned VisitBlockDeclRefExpr(BlockDeclRefExpr *E);
 | 
				
			||||||
 | 
					    unsigned VisitObjCEncodeExpr(ObjCEncodeExpr *E);
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1013,6 +1016,15 @@ unsigned PCHStmtReader::VisitBlockDeclRefExpr(BlockDeclRefExpr *E) {
 | 
				
			||||||
  return 0;
 | 
					  return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					unsigned PCHStmtReader::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
 | 
				
			||||||
 | 
					  VisitExpr(E);
 | 
				
			||||||
 | 
					  E->setEncodedType(Reader.GetType(Record[Idx++]));
 | 
				
			||||||
 | 
					  E->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
 | 
				
			||||||
 | 
					  E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
 | 
				
			||||||
 | 
					  return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//===----------------------------------------------------------------------===//
 | 
					//===----------------------------------------------------------------------===//
 | 
				
			||||||
// PCH reader implementation
 | 
					// PCH reader implementation
 | 
				
			||||||
//===----------------------------------------------------------------------===//
 | 
					//===----------------------------------------------------------------------===//
 | 
				
			||||||
| 
						 | 
					@ -2040,9 +2052,9 @@ QualType PCHReader::ReadTypeRecord(uint64_t Offset) {
 | 
				
			||||||
    return Context.getTypeDeclType(cast<EnumDecl>(GetDecl(Record[0])));
 | 
					    return Context.getTypeDeclType(cast<EnumDecl>(GetDecl(Record[0])));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  case pch::TYPE_OBJC_INTERFACE:
 | 
					  case pch::TYPE_OBJC_INTERFACE:
 | 
				
			||||||
    // FIXME: Deserialize ObjCInterfaceType
 | 
					    assert(Record.size() == 1 && "Incorrect encoding of objc interface type");
 | 
				
			||||||
    assert(false && "Cannot de-serialize ObjC interface types yet");
 | 
					    return Context.getObjCInterfaceType(
 | 
				
			||||||
    return QualType();
 | 
					                                  cast<ObjCInterfaceDecl>(GetDecl(Record[0])));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  case pch::TYPE_OBJC_QUALIFIED_INTERFACE:
 | 
					  case pch::TYPE_OBJC_QUALIFIED_INTERFACE:
 | 
				
			||||||
    // FIXME: Deserialize ObjCQualifiedInterfaceType
 | 
					    // FIXME: Deserialize ObjCQualifiedInterfaceType
 | 
				
			||||||
| 
						 | 
					@ -2933,6 +2945,10 @@ Stmt *PCHReader::ReadStmt() {
 | 
				
			||||||
    case pch::EXPR_BLOCK_DECL_REF:
 | 
					    case pch::EXPR_BLOCK_DECL_REF:
 | 
				
			||||||
      S = new (Context) BlockDeclRefExpr(Empty);
 | 
					      S = new (Context) BlockDeclRefExpr(Empty);
 | 
				
			||||||
      break;
 | 
					      break;
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					    case pch::EXPR_OBJC_ENCODE:
 | 
				
			||||||
 | 
					      S = new (Context) ObjCEncodeExpr(Empty);
 | 
				
			||||||
 | 
					      break;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // We hit a STMT_STOP, so we're done with this expression.
 | 
					    // We hit a STMT_STOP, so we're done with this expression.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -656,6 +656,11 @@ namespace {
 | 
				
			||||||
    void VisitShuffleVectorExpr(ShuffleVectorExpr *E);
 | 
					    void VisitShuffleVectorExpr(ShuffleVectorExpr *E);
 | 
				
			||||||
    void VisitBlockExpr(BlockExpr *E);
 | 
					    void VisitBlockExpr(BlockExpr *E);
 | 
				
			||||||
    void VisitBlockDeclRefExpr(BlockDeclRefExpr *E);
 | 
					    void VisitBlockDeclRefExpr(BlockDeclRefExpr *E);
 | 
				
			||||||
 | 
					      
 | 
				
			||||||
 | 
					    // Objective-C
 | 
				
			||||||
 | 
					    void VisitObjCEncodeExpr(ObjCEncodeExpr *E);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1147,6 +1152,19 @@ void PCHStmtWriter::VisitBlockDeclRefExpr(BlockDeclRefExpr *E) {
 | 
				
			||||||
  Code = pch::EXPR_BLOCK_DECL_REF;
 | 
					  Code = pch::EXPR_BLOCK_DECL_REF;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//===----------------------------------------------------------------------===//
 | 
				
			||||||
 | 
					// Objective-C Expressions and Statements.
 | 
				
			||||||
 | 
					//===----------------------------------------------------------------------===//
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void PCHStmtWriter::VisitObjCEncodeExpr(ObjCEncodeExpr *E) { 
 | 
				
			||||||
 | 
					  VisitExpr(E);
 | 
				
			||||||
 | 
					  Writer.AddTypeRef(E->getEncodedType(), Record);
 | 
				
			||||||
 | 
					  Writer.AddSourceLocation(E->getAtLoc(), Record);
 | 
				
			||||||
 | 
					  Writer.AddSourceLocation(E->getRParenLoc(), Record);
 | 
				
			||||||
 | 
					  Code = pch::EXPR_OBJC_ENCODE;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//===----------------------------------------------------------------------===//
 | 
					//===----------------------------------------------------------------------===//
 | 
				
			||||||
// PCHWriter Implementation
 | 
					// PCHWriter Implementation
 | 
				
			||||||
//===----------------------------------------------------------------------===//
 | 
					//===----------------------------------------------------------------------===//
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,5 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					inline const char *foo() {
 | 
				
			||||||
 | 
					  return @encode(int);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,7 @@
 | 
				
			||||||
 | 
					// Test this without pch.
 | 
				
			||||||
 | 
					// RUN: clang-cc -fblocks -include %S/objc_exprs.h -fsyntax-only -verify %s &&
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Test with pch.
 | 
				
			||||||
 | 
					// RUN: clang-cc -x objective-c-header -emit-pch -fblocks -o %t %S/objc_exprs.h &&
 | 
				
			||||||
 | 
					// RUN: clang-cc -fblocks -include-pch %t -fsyntax-only -verify %s 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue