16 #include "llvm/ADT/SmallString.h" 17 #include "llvm/ADT/TinyPtrVector.h" 18 #include "llvm/Support/SaveAndRestore.h" 20 using namespace clang;
21 using namespace arcmt;
22 using namespace trans;
30 std::vector<ObjCPropertyDecl *> &AllProps;
35 std::vector<ObjCPropertyDecl *> &AllProps)
36 : MigrateCtx(ctx), FullyMigratable(
false),
37 AllProps(AllProps) { }
39 bool shouldWalkTypesOfTypeLocs()
const {
return false; }
46 bool TraverseDecl(
Decl *D) {
53 lookForAttribute(PropD, PropD->getTypeSourceInfo());
54 AllProps.push_back(PropD);
56 lookForAttribute(DD, DD->getTypeSourceInfo());
58 return base::TraverseDecl(D);
69 if (handleAttr(
Attr, D))
71 TL =
Attr.getModifiedLoc();
73 TL = Arr.getElementLoc();
75 TL = PT.getPointeeLoc();
77 TL = RT.getPointeeLoc();
84 auto *OwnershipAttr = TL.
getAttrAs<ObjCOwnershipAttr>();
90 if (MigrateCtx.
AttrSet.count(RawLoc))
97 StringRef Spell = OwnershipAttr->getKind()->getName();
99 if (Spell ==
"strong")
101 else if (Spell ==
"weak")
106 MigrateCtx.
AttrSet.insert(RawLoc);
118 bool isMigratable(
Decl *D) {
119 if (isa<TranslationUnitDecl>(D))
126 return FD->hasBody();
129 return hasObjCImpl(ContD);
132 for (
const auto *MI : RD->methods()) {
133 if (MI->isOutOfLine())
142 static bool hasObjCImpl(
Decl *D) {
147 return ID->getImplementation() !=
nullptr;
149 return CD->getImplementation() !=
nullptr;
150 return isa<ObjCImplDecl>(ContD);
155 bool isInMainFile(
Decl *D) {
160 if (!isInMainFile(I->getLocation()))
180 for (
unsigned i = 0, e = MigrateCtx.
GCAttrs.size(); i != e; ++i) {
186 TA.
reportError(
"GC managed memory will become unmanaged in ARC",
196 for (
unsigned i = 0, e = MigrateCtx.
GCAttrs.size(); i != e; ++i) {
208 diag::err_arc_unsupported_weak_class,
219 IndivPropsTy &IndProps) {
220 if (IndProps.empty())
223 for (IndivPropsTy::iterator
224 PI = IndProps.begin(), PE = IndProps.end(); PI != PE; ++PI) {
231 bool hasWeak =
false, hasStrong =
false;
234 for (IndivPropsTy::iterator
235 PI = IndProps.begin(), PE = IndProps.end(); PI != PE; ++PI) {
244 ATLs.push_back(std::make_pair(ATL, PD));
255 if (hasWeak && hasStrong)
261 if (GCAttrsCollector::hasObjCImpl(
262 cast<Decl>(IndProps.front()->getDeclContext()))) {
267 StringRef toAttr =
"strong";
273 toAttr =
"unsafe_unretained";
281 for (
unsigned i = 0, e = ATLs.size(); i != e; ++i) {
288 TA.
clearDiagnostic(diag::err_objc_property_attr_mutually_exclusive, AtLoc);
290 ATLs[i].second->getLocation());
296 std::vector<ObjCPropertyDecl *> &AllProps) {
297 typedef llvm::TinyPtrVector<ObjCPropertyDecl *>
IndivPropsTy;
298 llvm::DenseMap<unsigned, IndivPropsTy> AtProps;
300 for (
unsigned i = 0, e = AllProps.size(); i != e; ++i) {
309 AtProps[RawAt].push_back(PD);
313 for (llvm::DenseMap<unsigned, IndivPropsTy>::iterator
314 I = AtProps.begin(), E = AtProps.end(); I != E; ++I) {
316 IndivPropsTy &IndProps = I->second;
322 std::vector<ObjCPropertyDecl *> AllProps;
323 GCAttrsCollector(MigrateCtx, AllProps).TraverseDecl(
332 llvm::errs() <<
"\n################\n";
333 for (
unsigned i = 0, e = GCAttrs.size(); i != e; ++i) {
335 llvm::errs() <<
"KIND: " 336 << (Attr.
Kind == GCAttrOccurrence::Strong ?
"strong" :
"weak");
337 llvm::errs() <<
"\nLOC: ";
338 Attr.
Loc.
print(llvm::errs(), Pass.Ctx.getSourceManager());
339 llvm::errs() <<
"\nTYPE: ";
342 llvm::errs() <<
"DECL:\n";
345 llvm::errs() <<
"DECL: NONE";
348 llvm::errs() <<
"\n----------------\n";
350 llvm::errs() <<
"\n################\n";
Defines the clang::ASTContext interface.
Represents a function declaration or definition.
unsigned getRawEncoding() const
When a SourceLocation itself cannot be used, this returns an (opaque) 32-bit integer encoding for it...
A (possibly-)qualified type.
Defines the SourceManager interface.
Decl - This represents one declaration (or definition), e.g.
A container of type source information.
bool rewritePropertyAttribute(StringRef fromAttr, StringRef toAttr, SourceLocation atLoc)
static void checkWeakGCAttrs(MigrationContext &MigrateCtx)
Wrapper of type source information for a type with non-trivial direct qualifiers. ...
std::vector< GCAttrOccurrence > GCAttrs
Base wrapper for a particular "section" of type source info.
SourceLocation getBegin() const
void print(raw_ostream &OS, const SourceManager &SM) const
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
static SourceLocation getFromRawEncoding(unsigned Encoding)
Turn a raw encoding of a SourceLocation object into a real SourceLocation.
bool FullyMigratable
true if the attribute is owned, e.g.
ObjCContainerDecl - Represents a container for method declarations.
SourceLocation getExpansionLoc(SourceLocation Loc) const
Given a SourceLocation object Loc, return the expansion location referenced by the ID...
A class that does preorder or postorder depth-first traversal on the entire Clang AST and visits each...
Represents an ObjC class declaration.
llvm::DenseSet< unsigned > RemovedAttrSet
Represents a ValueDecl that came out of a declarator.
bool isInFileID(SourceLocation Loc, FileID FID, unsigned *RelativeOffset=nullptr) const
Given a specific FileID, returns true if Loc is inside that FileID chunk and sets relative offset (of...
Type source information for an attributed type.
TypeSourceInfo * getTypeSourceInfo() const
UnqualTypeLoc getUnqualifiedLoc() const
Skips past any qualifiers, if this is qualified.
bool isObjCRetainableType() const
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
DeclContext * getDeclContext()
CharSourceRange getImmediateExpansionRange(SourceLocation Loc) const
Return the start/end of the expansion information for an expansion location.
bool addPropertyAttribute(StringRef attr, SourceLocation atLoc)
bool isNull() const
Return true if this QualType doesn't point to a type yet.
bool canApplyWeak(ASTContext &Ctx, QualType type, bool AllowOnUnknownClass=false)
Determine whether we can add weak to the given type.
static void checkAllProps(MigrationContext &MigrateCtx, std::vector< ObjCPropertyDecl *> &AllProps)
llvm::TinyPtrVector< ObjCPropertyDecl * > IndivPropsTy
static void errorForGCAttrsOnNonObjC(MigrationContext &MigrateCtx)
Wrapper for source info for arrays.
Assigning into this object requires the old value to be released and the new value to be retained...
llvm::DenseSet< unsigned > AttrSet
Encodes a location in the source.
void traverseTU(MigrationContext &MigrateCtx) override
ObjCCategoryDecl - Represents a category declaration.
Represents one property declaration in an Objective-C interface.
static void checkAllAtProps(MigrationContext &MigrateCtx, SourceLocation AtLoc, IndivPropsTy &IndProps)
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
Dataflow Directional Tag Classes.
PropertyAttributeKind getPropertyAttributesAsWritten() const
QualType getType() const
Get the type for which this source info wrapper provides information.
SourceLocation getAtLoc() const
FileID getMainFileID() const
Returns the FileID of the main source file.
TypeLoc getModifiedLoc() const
The modified type, which is generally canonically different from the attribute type.
SourceManager & getSourceManager()
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Reading or writing from this object requires a barrier call.
TranslationUnitDecl * getTranslationUnitDecl() const
Represents a C++ struct/union/class.
enum clang::arcmt::trans::MigrationContext::GCAttrOccurrence::AttrKind Kind
void dump(const char *s) const
Wrapper for source info for pointers.
This class handles loading and caching of source files into memory.
Attr - This represents one attribute.
QualType getType() const
Return the type wrapped by this type source info.
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.
llvm::DenseSet< unsigned > AtPropsWeak
Set of raw '@' locations for 'assign' properties group that contain GC __weak.