ASTContext.cpp (195099) | ASTContext.cpp (195341) |
---|---|
1//===--- ASTContext.cpp - Context to hold long-lived AST nodes ------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// --- 23 unchanged lines hidden (view full) --- 32 33ASTContext::ASTContext(const LangOptions& LOpts, SourceManager &SM, 34 TargetInfo &t, 35 IdentifierTable &idents, SelectorTable &sels, 36 Builtin::Context &builtins, 37 bool FreeMem, unsigned size_reserve) : 38 GlobalNestedNameSpecifier(0), CFConstantStringTypeDecl(0), 39 ObjCFastEnumerationStateTypeDecl(0), SourceMgr(SM), LangOpts(LOpts), | 1//===--- ASTContext.cpp - Context to hold long-lived AST nodes ------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// --- 23 unchanged lines hidden (view full) --- 32 33ASTContext::ASTContext(const LangOptions& LOpts, SourceManager &SM, 34 TargetInfo &t, 35 IdentifierTable &idents, SelectorTable &sels, 36 Builtin::Context &builtins, 37 bool FreeMem, unsigned size_reserve) : 38 GlobalNestedNameSpecifier(0), CFConstantStringTypeDecl(0), 39 ObjCFastEnumerationStateTypeDecl(0), SourceMgr(SM), LangOpts(LOpts), |
40 FreeMemory(FreeMem), Target(t), Idents(idents), Selectors(sels), 41 BuiltinInfo(builtins), ExternalSource(0) { | 40 LoadedExternalComments(false), FreeMemory(FreeMem), Target(t), 41 Idents(idents), Selectors(sels), 42 BuiltinInfo(builtins), ExternalSource(0), PrintingPolicy(LOpts) { |
42 if (size_reserve > 0) Types.reserve(size_reserve); 43 InitBuiltinTypes(); 44 TUDecl = TranslationUnitDecl::Create(*this); | 43 if (size_reserve > 0) Types.reserve(size_reserve); 44 InitBuiltinTypes(); 45 TUDecl = TranslationUnitDecl::Create(*this); |
45 PrintingPolicy.CPlusPlus = LangOpts.CPlusPlus; | |
46} 47 48ASTContext::~ASTContext() { 49 // Deallocate all the types. 50 while (!Types.empty()) { 51 Types.back()->Destroy(*this); 52 Types.pop_back(); 53 } --- 144 unchanged lines hidden (view full) --- 198 199 // void * type 200 VoidPtrTy = getPointerType(VoidTy); 201 202 // nullptr type (C++0x 2.14.7) 203 InitBuiltinType(NullPtrTy, BuiltinType::NullPtr); 204} 205 | 46} 47 48ASTContext::~ASTContext() { 49 // Deallocate all the types. 50 while (!Types.empty()) { 51 Types.back()->Destroy(*this); 52 Types.pop_back(); 53 } --- 144 unchanged lines hidden (view full) --- 198 199 // void * type 200 VoidPtrTy = getPointerType(VoidTy); 201 202 // nullptr type (C++0x 2.14.7) 203 InitBuiltinType(NullPtrTy, BuiltinType::NullPtr); 204} 205 |
206namespace { 207 class BeforeInTranslationUnit 208 : std::binary_function<SourceRange, SourceRange, bool> { 209 SourceManager *SourceMgr; 210 211 public: 212 explicit BeforeInTranslationUnit(SourceManager *SM) : SourceMgr(SM) { } 213 214 bool operator()(SourceRange X, SourceRange Y) { 215 return SourceMgr->isBeforeInTranslationUnit(X.getBegin(), Y.getBegin()); 216 } 217 }; 218} 219 220/// \brief Determine whether the given comment is a Doxygen-style comment. 221/// 222/// \param Start the start of the comment text. 223/// 224/// \param End the end of the comment text. 225/// 226/// \param Member whether we want to check whether this is a member comment 227/// (which requires a < after the Doxygen-comment delimiter). Otherwise, 228/// we only return true when we find a non-member comment. 229static bool 230isDoxygenComment(SourceManager &SourceMgr, SourceRange Comment, 231 bool Member = false) { 232 const char *BufferStart 233 = SourceMgr.getBufferData(SourceMgr.getFileID(Comment.getBegin())).first; 234 const char *Start = BufferStart + SourceMgr.getFileOffset(Comment.getBegin()); 235 const char* End = BufferStart + SourceMgr.getFileOffset(Comment.getEnd()); 236 237 if (End - Start < 4) 238 return false; 239 240 assert(Start[0] == '/' && "Not a comment?"); 241 if (Start[1] == '*' && !(Start[2] == '!' || Start[2] == '*')) 242 return false; 243 if (Start[1] == '/' && !(Start[2] == '!' || Start[2] == '/')) 244 return false; 245 246 return (Start[3] == '<') == Member; 247} 248 249/// \brief Retrieve the comment associated with the given declaration, if 250/// it has one. 251const char *ASTContext::getCommentForDecl(const Decl *D) { 252 if (!D) 253 return 0; 254 255 // Check whether we have cached a comment string for this declaration 256 // already. 257 llvm::DenseMap<const Decl *, std::string>::iterator Pos 258 = DeclComments.find(D); 259 if (Pos != DeclComments.end()) 260 return Pos->second.c_str(); 261 262 // If we have an external AST source and have not yet loaded comments from 263 // that source, do so now. 264 if (ExternalSource && !LoadedExternalComments) { 265 std::vector<SourceRange> LoadedComments; 266 ExternalSource->ReadComments(LoadedComments); 267 268 if (!LoadedComments.empty()) 269 Comments.insert(Comments.begin(), LoadedComments.begin(), 270 LoadedComments.end()); 271 272 LoadedExternalComments = true; 273 } 274 275 // If there are no comments anywhere, we won't find anything. 276 if (Comments.empty()) 277 return 0; 278 279 // If the declaration doesn't map directly to a location in a file, we 280 // can't find the comment. 281 SourceLocation DeclStartLoc = D->getLocStart(); 282 if (DeclStartLoc.isInvalid() || !DeclStartLoc.isFileID()) 283 return 0; 284 285 // Find the comment that occurs just before this declaration. 286 std::vector<SourceRange>::iterator LastComment 287 = std::lower_bound(Comments.begin(), Comments.end(), 288 SourceRange(DeclStartLoc), 289 BeforeInTranslationUnit(&SourceMgr)); 290 291 // Decompose the location for the start of the declaration and find the 292 // beginning of the file buffer. 293 std::pair<FileID, unsigned> DeclStartDecomp 294 = SourceMgr.getDecomposedLoc(DeclStartLoc); 295 const char *FileBufferStart 296 = SourceMgr.getBufferData(DeclStartDecomp.first).first; 297 298 // First check whether we have a comment for a member. 299 if (LastComment != Comments.end() && 300 !isa<TagDecl>(D) && !isa<NamespaceDecl>(D) && 301 isDoxygenComment(SourceMgr, *LastComment, true)) { 302 std::pair<FileID, unsigned> LastCommentEndDecomp 303 = SourceMgr.getDecomposedLoc(LastComment->getEnd()); 304 if (DeclStartDecomp.first == LastCommentEndDecomp.first && 305 SourceMgr.getLineNumber(DeclStartDecomp.first, DeclStartDecomp.second) 306 == SourceMgr.getLineNumber(LastCommentEndDecomp.first, 307 LastCommentEndDecomp.second)) { 308 // The Doxygen member comment comes after the declaration starts and 309 // is on the same line and in the same file as the declaration. This 310 // is the comment we want. 311 std::string &Result = DeclComments[D]; 312 Result.append(FileBufferStart + 313 SourceMgr.getFileOffset(LastComment->getBegin()), 314 FileBufferStart + LastCommentEndDecomp.second + 1); 315 return Result.c_str(); 316 } 317 } 318 319 if (LastComment == Comments.begin()) 320 return 0; 321 --LastComment; 322 323 // Decompose the end of the comment. 324 std::pair<FileID, unsigned> LastCommentEndDecomp 325 = SourceMgr.getDecomposedLoc(LastComment->getEnd()); 326 327 // If the comment and the declaration aren't in the same file, then they 328 // aren't related. 329 if (DeclStartDecomp.first != LastCommentEndDecomp.first) 330 return 0; 331 332 // Check that we actually have a Doxygen comment. 333 if (!isDoxygenComment(SourceMgr, *LastComment)) 334 return 0; 335 336 // Compute the starting line for the declaration and for the end of the 337 // comment (this is expensive). 338 unsigned DeclStartLine 339 = SourceMgr.getLineNumber(DeclStartDecomp.first, DeclStartDecomp.second); 340 unsigned CommentEndLine 341 = SourceMgr.getLineNumber(LastCommentEndDecomp.first, 342 LastCommentEndDecomp.second); 343 344 // If the comment does not end on the line prior to the declaration, then 345 // the comment is not associated with the declaration at all. 346 if (CommentEndLine + 1 != DeclStartLine) 347 return 0; 348 349 // We have a comment, but there may be more comments on the previous lines. 350 // Keep looking so long as the comments are still Doxygen comments and are 351 // still adjacent. 352 unsigned ExpectedLine 353 = SourceMgr.getSpellingLineNumber(LastComment->getBegin()) - 1; 354 std::vector<SourceRange>::iterator FirstComment = LastComment; 355 while (FirstComment != Comments.begin()) { 356 // Look at the previous comment 357 --FirstComment; 358 std::pair<FileID, unsigned> Decomp 359 = SourceMgr.getDecomposedLoc(FirstComment->getEnd()); 360 361 // If this previous comment is in a different file, we're done. 362 if (Decomp.first != DeclStartDecomp.first) { 363 ++FirstComment; 364 break; 365 } 366 367 // If this comment is not a Doxygen comment, we're done. 368 if (!isDoxygenComment(SourceMgr, *FirstComment)) { 369 ++FirstComment; 370 break; 371 } 372 373 // If the line number is not what we expected, we're done. 374 unsigned Line = SourceMgr.getLineNumber(Decomp.first, Decomp.second); 375 if (Line != ExpectedLine) { 376 ++FirstComment; 377 break; 378 } 379 380 // Set the next expected line number. 381 ExpectedLine 382 = SourceMgr.getSpellingLineNumber(FirstComment->getBegin()) - 1; 383 } 384 385 // The iterator range [FirstComment, LastComment] contains all of the 386 // BCPL comments that, together, are associated with this declaration. 387 // Form a single comment block string for this declaration that concatenates 388 // all of these comments. 389 std::string &Result = DeclComments[D]; 390 while (FirstComment != LastComment) { 391 std::pair<FileID, unsigned> DecompStart 392 = SourceMgr.getDecomposedLoc(FirstComment->getBegin()); 393 std::pair<FileID, unsigned> DecompEnd 394 = SourceMgr.getDecomposedLoc(FirstComment->getEnd()); 395 Result.append(FileBufferStart + DecompStart.second, 396 FileBufferStart + DecompEnd.second + 1); 397 ++FirstComment; 398 } 399 400 // Append the last comment line. 401 Result.append(FileBufferStart + 402 SourceMgr.getFileOffset(LastComment->getBegin()), 403 FileBufferStart + LastCommentEndDecomp.second + 1); 404 return Result.c_str(); 405} 406 |
|
206//===----------------------------------------------------------------------===// 207// Type Sizing and Analysis 208//===----------------------------------------------------------------------===// 209 210/// getFloatTypeSemantics - Return the APFloat 'semantics' for the specified 211/// scalar floating point type. 212const llvm::fltSemantics &ASTContext::getFloatTypeSemantics(QualType T) const { 213 const BuiltinType *BT = T->getAsBuiltinType(); --- 7 unchanged lines hidden (view full) --- 221} 222 223/// getDeclAlign - Return a conservative estimate of the alignment of the 224/// specified decl. Note that bitfields do not have a valid alignment, so 225/// this method will assert on them. 226unsigned ASTContext::getDeclAlignInBytes(const Decl *D) { 227 unsigned Align = Target.getCharWidth(); 228 | 407//===----------------------------------------------------------------------===// 408// Type Sizing and Analysis 409//===----------------------------------------------------------------------===// 410 411/// getFloatTypeSemantics - Return the APFloat 'semantics' for the specified 412/// scalar floating point type. 413const llvm::fltSemantics &ASTContext::getFloatTypeSemantics(QualType T) const { 414 const BuiltinType *BT = T->getAsBuiltinType(); --- 7 unchanged lines hidden (view full) --- 422} 423 424/// getDeclAlign - Return a conservative estimate of the alignment of the 425/// specified decl. Note that bitfields do not have a valid alignment, so 426/// this method will assert on them. 427unsigned ASTContext::getDeclAlignInBytes(const Decl *D) { 428 unsigned Align = Target.getCharWidth(); 429 |
229 if (const AlignedAttr* AA = D->getAttr<AlignedAttr>(*this)) | 430 if (const AlignedAttr* AA = D->getAttr |
230 Align = std::max(Align, AA->getAlignment()); 231 232 if (const ValueDecl *VD = dyn_cast<ValueDecl>(D)) { 233 QualType T = VD->getType(); 234 if (const ReferenceType* RT = T->getAsReferenceType()) { 235 unsigned AS = RT->getPointeeType().getAddressSpace(); 236 Align = Target.getPointerAlign(AS); 237 } else if (!T->isIncompleteType() && !T->isFunctionType()) { --- 206 unchanged lines hidden (view full) --- 444 const ASTRecordLayout &Layout = getASTRecordLayout(RT->getDecl()); 445 Width = Layout.getSize(); 446 Align = Layout.getAlignment(); 447 break; 448 } 449 450 case Type::Typedef: { 451 const TypedefDecl *Typedef = cast<TypedefType>(T)->getDecl(); | 431 Align = std::max(Align, AA->getAlignment()); 432 433 if (const ValueDecl *VD = dyn_cast<ValueDecl>(D)) { 434 QualType T = VD->getType(); 435 if (const ReferenceType* RT = T->getAsReferenceType()) { 436 unsigned AS = RT->getPointeeType().getAddressSpace(); 437 Align = Target.getPointerAlign(AS); 438 } else if (!T->isIncompleteType() && !T->isFunctionType()) { --- 206 unchanged lines hidden (view full) --- 645 const ASTRecordLayout &Layout = getASTRecordLayout(RT->getDecl()); 646 Width = Layout.getSize(); 647 Align = Layout.getAlignment(); 648 break; 649 } 650 651 case Type::Typedef: { 652 const TypedefDecl *Typedef = cast<TypedefType>(T)->getDecl(); |
452 if (const AlignedAttr *Aligned = Typedef->getAttr<AlignedAttr>(*this)) { | 653 if (const AlignedAttr *Aligned = Typedef->getAttr |
453 Align = Aligned->getAlignment(); 454 Width = getTypeSize(Typedef->getUnderlyingType().getTypePtr()); 455 } else 456 return getTypeInfo(Typedef->getUnderlyingType().getTypePtr()); 457 break; 458 } 459 460 case Type::TypeOfExpr: --- 47 unchanged lines hidden (view full) --- 508 ASTContext &Context) { 509 unsigned FieldPacking = StructPacking; 510 uint64_t FieldOffset = IsUnion ? 0 : Size; 511 uint64_t FieldSize; 512 unsigned FieldAlign; 513 514 // FIXME: Should this override struct packing? Probably we want to 515 // take the minimum? | 654 Align = Aligned->getAlignment(); 655 Width = getTypeSize(Typedef->getUnderlyingType().getTypePtr()); 656 } else 657 return getTypeInfo(Typedef->getUnderlyingType().getTypePtr()); 658 break; 659 } 660 661 case Type::TypeOfExpr: --- 47 unchanged lines hidden (view full) --- 709 ASTContext &Context) { 710 unsigned FieldPacking = StructPacking; 711 uint64_t FieldOffset = IsUnion ? 0 : Size; 712 uint64_t FieldSize; 713 unsigned FieldAlign; 714 715 // FIXME: Should this override struct packing? Probably we want to 716 // take the minimum? |
516 if (const PackedAttr *PA = FD->getAttr<PackedAttr>(Context)) | 717 if (const PackedAttr *PA = FD->getAttr |
517 FieldPacking = PA->getAlignment(); 518 519 if (const Expr *BitWidthExpr = FD->getBitWidth()) { 520 // TODO: Need to check this algorithm on other targets! 521 // (tested on Linux-X86) 522 FieldSize = BitWidthExpr->EvaluateAsInt(Context).getZExtValue(); 523 524 std::pair<uint64_t, unsigned> FieldInfo = 525 Context.getTypeInfo(FD->getType()); 526 uint64_t TypeSize = FieldInfo.first; 527 528 // Determine the alignment of this bitfield. The packing 529 // attributes define a maximum and the alignment attribute defines 530 // a minimum. 531 // FIXME: What is the right behavior when the specified alignment 532 // is smaller than the specified packing? 533 FieldAlign = FieldInfo.second; 534 if (FieldPacking) 535 FieldAlign = std::min(FieldAlign, FieldPacking); | 718 FieldPacking = PA->getAlignment(); 719 720 if (const Expr *BitWidthExpr = FD->getBitWidth()) { 721 // TODO: Need to check this algorithm on other targets! 722 // (tested on Linux-X86) 723 FieldSize = BitWidthExpr->EvaluateAsInt(Context).getZExtValue(); 724 725 std::pair<uint64_t, unsigned> FieldInfo = 726 Context.getTypeInfo(FD->getType()); 727 uint64_t TypeSize = FieldInfo.first; 728 729 // Determine the alignment of this bitfield. The packing 730 // attributes define a maximum and the alignment attribute defines 731 // a minimum. 732 // FIXME: What is the right behavior when the specified alignment 733 // is smaller than the specified packing? 734 FieldAlign = FieldInfo.second; 735 if (FieldPacking) 736 FieldAlign = std::min(FieldAlign, FieldPacking); |
536 if (const AlignedAttr *AA = FD->getAttr<AlignedAttr>(Context)) | 737 if (const AlignedAttr *AA = FD->getAttr |
537 FieldAlign = std::max(FieldAlign, AA->getAlignment()); 538 539 // Check if we need to add padding to give the field the correct 540 // alignment. 541 if (FieldSize == 0 || (FieldOffset & (FieldAlign-1)) + FieldSize > TypeSize) 542 FieldOffset = (FieldOffset + (FieldAlign-1)) & ~(FieldAlign-1); 543 544 // Padding members don't affect overall alignment --- 23 unchanged lines hidden (view full) --- 568 // attributes define a maximum and the alignment attribute defines 569 // a minimum. Additionally, the packing alignment must be at least 570 // a byte for non-bitfields. 571 // 572 // FIXME: What is the right behavior when the specified alignment 573 // is smaller than the specified packing? 574 if (FieldPacking) 575 FieldAlign = std::min(FieldAlign, std::max(8U, FieldPacking)); | 738 FieldAlign = std::max(FieldAlign, AA->getAlignment()); 739 740 // Check if we need to add padding to give the field the correct 741 // alignment. 742 if (FieldSize == 0 || (FieldOffset & (FieldAlign-1)) + FieldSize > TypeSize) 743 FieldOffset = (FieldOffset + (FieldAlign-1)) & ~(FieldAlign-1); 744 745 // Padding members don't affect overall alignment --- 23 unchanged lines hidden (view full) --- 769 // attributes define a maximum and the alignment attribute defines 770 // a minimum. Additionally, the packing alignment must be at least 771 // a byte for non-bitfields. 772 // 773 // FIXME: What is the right behavior when the specified alignment 774 // is smaller than the specified packing? 775 if (FieldPacking) 776 FieldAlign = std::min(FieldAlign, std::max(8U, FieldPacking)); |
576 if (const AlignedAttr *AA = FD->getAttr<AlignedAttr>(Context)) | 777 if (const AlignedAttr *AA = FD->getAttr |
577 FieldAlign = std::max(FieldAlign, AA->getAlignment()); 578 579 // Round up the current record size to the field's alignment boundary. 580 FieldOffset = (FieldOffset + (FieldAlign-1)) & ~(FieldAlign-1); 581 } 582 583 // Place this field at the current location. 584 FieldOffsets[FieldNo] = FieldOffset; --- 41 unchanged lines hidden (view full) --- 626 Ivars.push_back(*I); 627 } 628 if (CollectSynthesized) 629 CollectSynthesizedIvars(OI, Ivars); 630} 631 632void ASTContext::CollectProtocolSynthesizedIvars(const ObjCProtocolDecl *PD, 633 llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars) { | 778 FieldAlign = std::max(FieldAlign, AA->getAlignment()); 779 780 // Round up the current record size to the field's alignment boundary. 781 FieldOffset = (FieldOffset + (FieldAlign-1)) & ~(FieldAlign-1); 782 } 783 784 // Place this field at the current location. 785 FieldOffsets[FieldNo] = FieldOffset; --- 41 unchanged lines hidden (view full) --- 827 Ivars.push_back(*I); 828 } 829 if (CollectSynthesized) 830 CollectSynthesizedIvars(OI, Ivars); 831} 832 833void ASTContext::CollectProtocolSynthesizedIvars(const ObjCProtocolDecl *PD, 834 llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars) { |
634 for (ObjCContainerDecl::prop_iterator I = PD->prop_begin(*this), 635 E = PD->prop_end(*this); I != E; ++I) | 835 for (ObjCContainerDecl::prop_iterator I = PD->prop_begin(), 836 E = PD->prop_end(); I != E; ++I) |
636 if (ObjCIvarDecl *Ivar = (*I)->getPropertyIvarDecl()) 637 Ivars.push_back(Ivar); 638 639 // Also look into nested protocols. 640 for (ObjCProtocolDecl::protocol_iterator P = PD->protocol_begin(), 641 E = PD->protocol_end(); P != E; ++P) 642 CollectProtocolSynthesizedIvars(*P, Ivars); 643} 644 645/// CollectSynthesizedIvars - 646/// This routine collect synthesized ivars for the designated class. 647/// 648void ASTContext::CollectSynthesizedIvars(const ObjCInterfaceDecl *OI, 649 llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars) { | 837 if (ObjCIvarDecl *Ivar = (*I)->getPropertyIvarDecl()) 838 Ivars.push_back(Ivar); 839 840 // Also look into nested protocols. 841 for (ObjCProtocolDecl::protocol_iterator P = PD->protocol_begin(), 842 E = PD->protocol_end(); P != E; ++P) 843 CollectProtocolSynthesizedIvars(*P, Ivars); 844} 845 846/// CollectSynthesizedIvars - 847/// This routine collect synthesized ivars for the designated class. 848/// 849void ASTContext::CollectSynthesizedIvars(const ObjCInterfaceDecl *OI, 850 llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars) { |
650 for (ObjCInterfaceDecl::prop_iterator I = OI->prop_begin(*this), 651 E = OI->prop_end(*this); I != E; ++I) { | 851 for (ObjCInterfaceDecl::prop_iterator I = OI->prop_begin(), 852 E = OI->prop_end(); I != E; ++I) { |
652 if (ObjCIvarDecl *Ivar = (*I)->getPropertyIvarDecl()) 653 Ivars.push_back(Ivar); 654 } 655 // Also look into interface's protocol list for properties declared 656 // in the protocol and whose ivars are synthesized. 657 for (ObjCInterfaceDecl::protocol_iterator P = OI->protocol_begin(), 658 PE = OI->protocol_end(); P != PE; ++P) { 659 ObjCProtocolDecl *PD = (*P); 660 CollectProtocolSynthesizedIvars(PD, Ivars); 661 } 662} 663 664unsigned ASTContext::CountProtocolSynthesizedIvars(const ObjCProtocolDecl *PD) { 665 unsigned count = 0; | 853 if (ObjCIvarDecl *Ivar = (*I)->getPropertyIvarDecl()) 854 Ivars.push_back(Ivar); 855 } 856 // Also look into interface's protocol list for properties declared 857 // in the protocol and whose ivars are synthesized. 858 for (ObjCInterfaceDecl::protocol_iterator P = OI->protocol_begin(), 859 PE = OI->protocol_end(); P != PE; ++P) { 860 ObjCProtocolDecl *PD = (*P); 861 CollectProtocolSynthesizedIvars(PD, Ivars); 862 } 863} 864 865unsigned ASTContext::CountProtocolSynthesizedIvars(const ObjCProtocolDecl *PD) { 866 unsigned count = 0; |
666 for (ObjCContainerDecl::prop_iterator I = PD->prop_begin(*this), 667 E = PD->prop_end(*this); I != E; ++I) | 867 for (ObjCContainerDecl::prop_iterator I = PD->prop_begin(), 868 E = PD->prop_end(); I != E; ++I) |
668 if ((*I)->getPropertyIvarDecl()) 669 ++count; 670 671 // Also look into nested protocols. 672 for (ObjCProtocolDecl::protocol_iterator P = PD->protocol_begin(), 673 E = PD->protocol_end(); P != E; ++P) 674 count += CountProtocolSynthesizedIvars(*P); 675 return count; 676} 677 678unsigned ASTContext::CountSynthesizedIvars(const ObjCInterfaceDecl *OI) 679{ 680 unsigned count = 0; | 869 if ((*I)->getPropertyIvarDecl()) 870 ++count; 871 872 // Also look into nested protocols. 873 for (ObjCProtocolDecl::protocol_iterator P = PD->protocol_begin(), 874 E = PD->protocol_end(); P != E; ++P) 875 count += CountProtocolSynthesizedIvars(*P); 876 return count; 877} 878 879unsigned ASTContext::CountSynthesizedIvars(const ObjCInterfaceDecl *OI) 880{ 881 unsigned count = 0; |
681 for (ObjCInterfaceDecl::prop_iterator I = OI->prop_begin(*this), 682 E = OI->prop_end(*this); I != E; ++I) { | 882 for (ObjCInterfaceDecl::prop_iterator I = OI->prop_begin(), 883 E = OI->prop_end(); I != E; ++I) { |
683 if ((*I)->getPropertyIvarDecl()) 684 ++count; 685 } 686 // Also look into interface's protocol list for properties declared 687 // in the protocol and whose ivars are synthesized. 688 for (ObjCInterfaceDecl::protocol_iterator P = OI->protocol_begin(), 689 PE = OI->protocol_end(); P != PE; ++P) { 690 ObjCProtocolDecl *PD = (*P); --- 43 unchanged lines hidden (view full) --- 734 ObjCLayouts[Key] = NewEntry = new ASTRecordLayout(Size, Alignment); 735 NewEntry->InitializeLayout(FieldCount); 736 } else { 737 ObjCLayouts[Key] = NewEntry = new ASTRecordLayout(); 738 NewEntry->InitializeLayout(FieldCount); 739 } 740 741 unsigned StructPacking = 0; | 884 if ((*I)->getPropertyIvarDecl()) 885 ++count; 886 } 887 // Also look into interface's protocol list for properties declared 888 // in the protocol and whose ivars are synthesized. 889 for (ObjCInterfaceDecl::protocol_iterator P = OI->protocol_begin(), 890 PE = OI->protocol_end(); P != PE; ++P) { 891 ObjCProtocolDecl *PD = (*P); --- 43 unchanged lines hidden (view full) --- 935 ObjCLayouts[Key] = NewEntry = new ASTRecordLayout(Size, Alignment); 936 NewEntry->InitializeLayout(FieldCount); 937 } else { 938 ObjCLayouts[Key] = NewEntry = new ASTRecordLayout(); 939 NewEntry->InitializeLayout(FieldCount); 940 } 941 942 unsigned StructPacking = 0; |
742 if (const PackedAttr *PA = D->getAttr<PackedAttr>(*this)) | 943 if (const PackedAttr *PA = D->getAttr |
743 StructPacking = PA->getAlignment(); 744 | 944 StructPacking = PA->getAlignment(); 945 |
745 if (const AlignedAttr *AA = D->getAttr<AlignedAttr>(*this)) | 946 if (const AlignedAttr *AA = D->getAttr |
746 NewEntry->SetAlignment(std::max(NewEntry->getAlignment(), 747 AA->getAlignment())); 748 749 // Layout each ivar sequentially. 750 unsigned i = 0; 751 llvm::SmallVector<ObjCIvarDecl*, 16> Ivars; 752 ShallowCollectObjCIvars(D, Ivars, Impl); 753 for (unsigned k = 0, e = Ivars.size(); k != e; ++k) --- 27 unchanged lines hidden (view full) --- 781 if (Entry) return *Entry; 782 783 // Allocate and assign into ASTRecordLayouts here. The "Entry" reference can 784 // be invalidated (dangle) if the ASTRecordLayouts hashtable is inserted into. 785 ASTRecordLayout *NewEntry = new ASTRecordLayout(); 786 Entry = NewEntry; 787 788 // FIXME: Avoid linear walk through the fields, if possible. | 947 NewEntry->SetAlignment(std::max(NewEntry->getAlignment(), 948 AA->getAlignment())); 949 950 // Layout each ivar sequentially. 951 unsigned i = 0; 952 llvm::SmallVector<ObjCIvarDecl*, 16> Ivars; 953 ShallowCollectObjCIvars(D, Ivars, Impl); 954 for (unsigned k = 0, e = Ivars.size(); k != e; ++k) --- 27 unchanged lines hidden (view full) --- 982 if (Entry) return *Entry; 983 984 // Allocate and assign into ASTRecordLayouts here. The "Entry" reference can 985 // be invalidated (dangle) if the ASTRecordLayouts hashtable is inserted into. 986 ASTRecordLayout *NewEntry = new ASTRecordLayout(); 987 Entry = NewEntry; 988 989 // FIXME: Avoid linear walk through the fields, if possible. |
789 NewEntry->InitializeLayout(std::distance(D->field_begin(*this), 790 D->field_end(*this))); | 990 NewEntry->InitializeLayout(std::distance(D->field_begin(), D->field_end())); |
791 bool IsUnion = D->isUnion(); 792 793 unsigned StructPacking = 0; | 991 bool IsUnion = D->isUnion(); 992 993 unsigned StructPacking = 0; |
794 if (const PackedAttr *PA = D->getAttr<PackedAttr>(*this)) | 994 if (const PackedAttr *PA = D->getAttr |
795 StructPacking = PA->getAlignment(); 796 | 995 StructPacking = PA->getAlignment(); 996 |
797 if (const AlignedAttr *AA = D->getAttr<AlignedAttr>(*this)) | 997 if (const AlignedAttr *AA = D->getAttr |
798 NewEntry->SetAlignment(std::max(NewEntry->getAlignment(), 799 AA->getAlignment())); 800 801 // Layout each field, for now, just sequentially, respecting alignment. In 802 // the future, this will need to be tweakable by targets. 803 unsigned FieldIdx = 0; | 998 NewEntry->SetAlignment(std::max(NewEntry->getAlignment(), 999 AA->getAlignment())); 1000 1001 // Layout each field, for now, just sequentially, respecting alignment. In 1002 // the future, this will need to be tweakable by targets. 1003 unsigned FieldIdx = 0; |
804 for (RecordDecl::field_iterator Field = D->field_begin(*this), 805 FieldEnd = D->field_end(*this); | 1004 for (RecordDecl::field_iterator Field = D->field_begin(), 1005 FieldEnd = D->field_end(); |
806 Field != FieldEnd; (void)++Field, ++FieldIdx) 807 NewEntry->LayoutField(*Field, FieldIdx, IsUnion, StructPacking, *this); 808 809 // Finally, round the size of the total struct up to the alignment of the 810 // struct itself. 811 NewEntry->FinalizeLayout(getLangOptions().CPlusPlus); 812 return *NewEntry; 813} --- 817 unchanged lines hidden (view full) --- 1631 ObjCQualifiedInterfaceType *QType = 1632 new (*this,8) ObjCQualifiedInterfaceType(Decl, Protocols, NumProtocols); 1633 1634 Types.push_back(QType); 1635 ObjCQualifiedInterfaceTypes.InsertNode(QType, InsertPos); 1636 return QualType(QType, 0); 1637} 1638 | 1006 Field != FieldEnd; (void)++Field, ++FieldIdx) 1007 NewEntry->LayoutField(*Field, FieldIdx, IsUnion, StructPacking, *this); 1008 1009 // Finally, round the size of the total struct up to the alignment of the 1010 // struct itself. 1011 NewEntry->FinalizeLayout(getLangOptions().CPlusPlus); 1012 return *NewEntry; 1013} --- 817 unchanged lines hidden (view full) --- 1831 ObjCQualifiedInterfaceType *QType = 1832 new (*this,8) ObjCQualifiedInterfaceType(Decl, Protocols, NumProtocols); 1833 1834 Types.push_back(QType); 1835 ObjCQualifiedInterfaceTypes.InsertNode(QType, InsertPos); 1836 return QualType(QType, 0); 1837} 1838 |
1639/// getObjCQualifiedIdType - Return an ObjCQualifiedIdType for the 'id' decl 1640/// and the conforming protocol list. 1641QualType ASTContext::getObjCQualifiedIdType(ObjCProtocolDecl **Protocols, 1642 unsigned NumProtocols) { 1643 return getObjCObjectPointerType(0, Protocols, NumProtocols); 1644} 1645 | |
1646/// getTypeOfExprType - Unlike many "get<Type>" functions, we can't unique 1647/// TypeOfExprType AST's (since expression's are never shared). For example, 1648/// multiple declarations that refer to "typeof(x)" all contain different 1649/// DeclRefExpr's. This doesn't effect the type checker, since it operates 1650/// on canonical type's (which are always unique). 1651QualType ASTContext::getTypeOfExprType(Expr *tofExpr) { 1652 QualType Canonical = getCanonicalType(tofExpr->getType()); 1653 TypeOfExprType *toe = new (*this,8) TypeOfExprType(tofExpr, Canonical); --- 154 unchanged lines hidden (view full) --- 1808 } 1809 1810 if (const FunctionDecl *Function = dyn_cast<FunctionDecl>(D)) { 1811 while (Function->getPreviousDeclaration()) 1812 Function = Function->getPreviousDeclaration(); 1813 return const_cast<FunctionDecl *>(Function); 1814 } 1815 | 1839/// getTypeOfExprType - Unlike many "get<Type>" functions, we can't unique 1840/// TypeOfExprType AST's (since expression's are never shared). For example, 1841/// multiple declarations that refer to "typeof(x)" all contain different 1842/// DeclRefExpr's. This doesn't effect the type checker, since it operates 1843/// on canonical type's (which are always unique). 1844QualType ASTContext::getTypeOfExprType(Expr *tofExpr) { 1845 QualType Canonical = getCanonicalType(tofExpr->getType()); 1846 TypeOfExprType *toe = new (*this,8) TypeOfExprType(tofExpr, Canonical); --- 154 unchanged lines hidden (view full) --- 2001 } 2002 2003 if (const FunctionDecl *Function = dyn_cast<FunctionDecl>(D)) { 2004 while (Function->getPreviousDeclaration()) 2005 Function = Function->getPreviousDeclaration(); 2006 return const_cast<FunctionDecl *>(Function); 2007 } 2008 |
2009 if (FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>(D)) { 2010 while (FunTmpl->getPreviousDeclaration()) 2011 FunTmpl = FunTmpl->getPreviousDeclaration(); 2012 return FunTmpl; 2013 } 2014 |
|
1816 if (const VarDecl *Var = dyn_cast<VarDecl>(D)) { 1817 while (Var->getPreviousDeclaration()) 1818 Var = Var->getPreviousDeclaration(); 1819 return const_cast<VarDecl *>(Var); 1820 } 1821 1822 return D; 1823} --- 314 unchanged lines hidden (view full) --- 2138 FieldTypes[3] = LongTy; 2139 2140 // Create fields 2141 for (unsigned i = 0; i < 4; ++i) { 2142 FieldDecl *Field = FieldDecl::Create(*this, CFConstantStringTypeDecl, 2143 SourceLocation(), 0, 2144 FieldTypes[i], /*BitWidth=*/0, 2145 /*Mutable=*/false); | 2015 if (const VarDecl *Var = dyn_cast<VarDecl>(D)) { 2016 while (Var->getPreviousDeclaration()) 2017 Var = Var->getPreviousDeclaration(); 2018 return const_cast<VarDecl *>(Var); 2019 } 2020 2021 return D; 2022} --- 314 unchanged lines hidden (view full) --- 2337 FieldTypes[3] = LongTy; 2338 2339 // Create fields 2340 for (unsigned i = 0; i < 4; ++i) { 2341 FieldDecl *Field = FieldDecl::Create(*this, CFConstantStringTypeDecl, 2342 SourceLocation(), 0, 2343 FieldTypes[i], /*BitWidth=*/0, 2344 /*Mutable=*/false); |
2146 CFConstantStringTypeDecl->addDecl(*this, Field); | 2345 CFConstantStringTypeDecl->addDecl(Field); |
2147 } 2148 2149 CFConstantStringTypeDecl->completeDefinition(*this); 2150 } 2151 2152 return getTagDeclType(CFConstantStringTypeDecl); 2153} 2154 --- 19 unchanged lines hidden (view full) --- 2174 }; 2175 2176 for (size_t i = 0; i < 4; ++i) { 2177 FieldDecl *Field = FieldDecl::Create(*this, 2178 ObjCFastEnumerationStateTypeDecl, 2179 SourceLocation(), 0, 2180 FieldTypes[i], /*BitWidth=*/0, 2181 /*Mutable=*/false); | 2346 } 2347 2348 CFConstantStringTypeDecl->completeDefinition(*this); 2349 } 2350 2351 return getTagDeclType(CFConstantStringTypeDecl); 2352} 2353 --- 19 unchanged lines hidden (view full) --- 2373 }; 2374 2375 for (size_t i = 0; i < 4; ++i) { 2376 FieldDecl *Field = FieldDecl::Create(*this, 2377 ObjCFastEnumerationStateTypeDecl, 2378 SourceLocation(), 0, 2379 FieldTypes[i], /*BitWidth=*/0, 2380 /*Mutable=*/false); |
2182 ObjCFastEnumerationStateTypeDecl->addDecl(*this, Field); | 2381 ObjCFastEnumerationStateTypeDecl->addDecl(Field); |
2183 } 2184 2185 ObjCFastEnumerationStateTypeDecl->completeDefinition(*this); 2186 } 2187 2188 return getTagDeclType(ObjCFastEnumerationStateTypeDecl); 2189} 2190 --- 110 unchanged lines hidden (view full) --- 2301 bool Dynamic = false; 2302 ObjCPropertyImplDecl *SynthesizePID = 0; 2303 2304 // FIXME: Duplicated code due to poor abstraction. 2305 if (Container) { 2306 if (const ObjCCategoryImplDecl *CID = 2307 dyn_cast<ObjCCategoryImplDecl>(Container)) { 2308 for (ObjCCategoryImplDecl::propimpl_iterator | 2382 } 2383 2384 ObjCFastEnumerationStateTypeDecl->completeDefinition(*this); 2385 } 2386 2387 return getTagDeclType(ObjCFastEnumerationStateTypeDecl); 2388} 2389 --- 110 unchanged lines hidden (view full) --- 2500 bool Dynamic = false; 2501 ObjCPropertyImplDecl *SynthesizePID = 0; 2502 2503 // FIXME: Duplicated code due to poor abstraction. 2504 if (Container) { 2505 if (const ObjCCategoryImplDecl *CID = 2506 dyn_cast<ObjCCategoryImplDecl>(Container)) { 2507 for (ObjCCategoryImplDecl::propimpl_iterator |
2309 i = CID->propimpl_begin(*this), e = CID->propimpl_end(*this); | 2508 i = CID->propimpl_begin(), e = CID->propimpl_end(); |
2310 i != e; ++i) { 2311 ObjCPropertyImplDecl *PID = *i; 2312 if (PID->getPropertyDecl() == PD) { 2313 if (PID->getPropertyImplementation()==ObjCPropertyImplDecl::Dynamic) { 2314 Dynamic = true; 2315 } else { 2316 SynthesizePID = PID; 2317 } 2318 } 2319 } 2320 } else { 2321 const ObjCImplementationDecl *OID=cast<ObjCImplementationDecl>(Container); 2322 for (ObjCCategoryImplDecl::propimpl_iterator | 2509 i != e; ++i) { 2510 ObjCPropertyImplDecl *PID = *i; 2511 if (PID->getPropertyDecl() == PD) { 2512 if (PID->getPropertyImplementation()==ObjCPropertyImplDecl::Dynamic) { 2513 Dynamic = true; 2514 } else { 2515 SynthesizePID = PID; 2516 } 2517 } 2518 } 2519 } else { 2520 const ObjCImplementationDecl *OID=cast<ObjCImplementationDecl>(Container); 2521 for (ObjCCategoryImplDecl::propimpl_iterator |
2323 i = OID->propimpl_begin(*this), e = OID->propimpl_end(*this); | 2522 i = OID->propimpl_begin(), e = OID->propimpl_end(); |
2324 i != e; ++i) { 2325 ObjCPropertyImplDecl *PID = *i; 2326 if (PID->getPropertyDecl() == PD) { 2327 if (PID->getPropertyImplementation()==ObjCPropertyImplDecl::Dynamic) { 2328 Dynamic = true; 2329 } else { 2330 SynthesizePID = PID; 2331 } --- 274 unchanged lines hidden (view full) --- 2606 // Anonymous structures print as '?' 2607 if (const IdentifierInfo *II = RDecl->getIdentifier()) { 2608 S += II->getName(); 2609 } else { 2610 S += '?'; 2611 } 2612 if (ExpandStructures) { 2613 S += '='; | 2523 i != e; ++i) { 2524 ObjCPropertyImplDecl *PID = *i; 2525 if (PID->getPropertyDecl() == PD) { 2526 if (PID->getPropertyImplementation()==ObjCPropertyImplDecl::Dynamic) { 2527 Dynamic = true; 2528 } else { 2529 SynthesizePID = PID; 2530 } --- 274 unchanged lines hidden (view full) --- 2805 // Anonymous structures print as '?' 2806 if (const IdentifierInfo *II = RDecl->getIdentifier()) { 2807 S += II->getName(); 2808 } else { 2809 S += '?'; 2810 } 2811 if (ExpandStructures) { 2812 S += '='; |
2614 for (RecordDecl::field_iterator Field = RDecl->field_begin(*this), 2615 FieldEnd = RDecl->field_end(*this); | 2813 for (RecordDecl::field_iterator Field = RDecl->field_begin(), 2814 FieldEnd = RDecl->field_end(); |
2616 Field != FieldEnd; ++Field) { 2617 if (FD) { 2618 S += '"'; 2619 S += Field->getNameAsString(); 2620 S += '"'; 2621 } 2622 2623 // Special case bit-fields. --- 205 unchanged lines hidden (view full) --- 2829 2830/// isObjCNSObjectType - Return true if this is an NSObject object using 2831/// NSObject attribute on a c-style pointer type. 2832/// FIXME - Make it work directly on types. 2833/// 2834bool ASTContext::isObjCNSObjectType(QualType Ty) const { 2835 if (TypedefType *TDT = dyn_cast<TypedefType>(Ty)) { 2836 if (TypedefDecl *TD = TDT->getDecl()) | 2815 Field != FieldEnd; ++Field) { 2816 if (FD) { 2817 S += '"'; 2818 S += Field->getNameAsString(); 2819 S += '"'; 2820 } 2821 2822 // Special case bit-fields. --- 205 unchanged lines hidden (view full) --- 3028 3029/// isObjCNSObjectType - Return true if this is an NSObject object using 3030/// NSObject attribute on a c-style pointer type. 3031/// FIXME - Make it work directly on types. 3032/// 3033bool ASTContext::isObjCNSObjectType(QualType Ty) const { 3034 if (TypedefType *TDT = dyn_cast<TypedefType>(Ty)) { 3035 if (TypedefDecl *TD = TDT->getDecl()) |
2837 if (TD->getAttr<ObjCNSObjectAttr>(*const_cast<ASTContext*>(this))) | 3036 if (TD->getAttr |
2838 return true; 2839 } 2840 return false; 2841} 2842 2843/// isObjCObjectPointerType - Returns true if type is an Objective-C pointer 2844/// to an object type. This includes "id" and "Class" (two 'special' pointers 2845/// to struct), Interface* (pointer to ObjCInterfaceType) and id<P> (qualified --- 727 unchanged lines hidden (view full) --- 3573 3574 QualType ElementType = DecodeTypeFromStr(Str, Context, Error, false); 3575 Type = Context.getVectorType(ElementType, NumElements); 3576 break; 3577 } 3578 case 'P': { 3579 IdentifierInfo *II = &Context.Idents.get("FILE"); 3580 DeclContext::lookup_result Lookup | 3037 return true; 3038 } 3039 return false; 3040} 3041 3042/// isObjCObjectPointerType - Returns true if type is an Objective-C pointer 3043/// to an object type. This includes "id" and "Class" (two 'special' pointers 3044/// to struct), Interface* (pointer to ObjCInterfaceType) and id<P> (qualified --- 727 unchanged lines hidden (view full) --- 3772 3773 QualType ElementType = DecodeTypeFromStr(Str, Context, Error, false); 3774 Type = Context.getVectorType(ElementType, NumElements); 3775 break; 3776 } 3777 case 'P': { 3778 IdentifierInfo *II = &Context.Idents.get("FILE"); 3779 DeclContext::lookup_result Lookup |
3581 = Context.getTranslationUnitDecl()->lookup(Context, II); | 3780 = Context.getTranslationUnitDecl()->lookup(II); |
3582 if (Lookup.first != Lookup.second && isa<TypeDecl>(*Lookup.first)) { 3583 Type = Context.getTypeDeclType(cast<TypeDecl>(*Lookup.first)); 3584 break; 3585 } 3586 else { 3587 Error = ASTContext::GE_Missing_FILE; 3588 return QualType(); 3589 } --- 58 unchanged lines hidden --- | 3781 if (Lookup.first != Lookup.second && isa<TypeDecl>(*Lookup.first)) { 3782 Type = Context.getTypeDeclType(cast<TypeDecl>(*Lookup.first)); 3783 break; 3784 } 3785 else { 3786 Error = ASTContext::GE_Missing_FILE; 3787 return QualType(); 3788 } --- 58 unchanged lines hidden --- |