15 #include "llvm/ADT/SmallString.h" 16 #include "llvm/ADT/TinyPtrVector.h" 17 #include "llvm/Support/SaveAndRestore.h" 19 using namespace clang;
20 using namespace arcmt;
21 using namespace trans;
29 std::vector<ObjCPropertyDecl *> &AllProps;
34 std::vector<ObjCPropertyDecl *> &AllProps)
35 : MigrateCtx(ctx), FullyMigratable(
false),
36 AllProps(AllProps) { }
38 bool shouldWalkTypesOfTypeLocs()
const {
return false; }
45 bool TraverseDecl(
Decl *D) {
52 lookForAttribute(PropD, PropD->getTypeSourceInfo());
53 AllProps.push_back(PropD);
55 lookForAttribute(DD, DD->getTypeSourceInfo());
57 return base::TraverseDecl(D);
68 if (handleAttr(
Attr, D))
70 TL =
Attr.getModifiedLoc();
73 TL = MDTL.getInnerLoc();
75 TL = Arr.getElementLoc();
77 TL = PT.getPointeeLoc();
79 TL = RT.getPointeeLoc();
86 auto *OwnershipAttr = TL.
getAttrAs<ObjCOwnershipAttr>();
92 if (MigrateCtx.
AttrSet.count(RawLoc))
99 StringRef Spell = OwnershipAttr->getKind()->getName();
101 if (Spell ==
"strong")
103 else if (Spell ==
"weak")
108 MigrateCtx.
AttrSet.insert(RawLoc);
120 bool isMigratable(
Decl *D) {
121 if (isa<TranslationUnitDecl>(D))
128 return FD->hasBody();
131 return hasObjCImpl(ContD);
134 for (
const auto *MI : RD->methods()) {
135 if (MI->isOutOfLine())
144 static bool hasObjCImpl(
Decl *D) {
149 return ID->getImplementation() !=
nullptr;
151 return CD->getImplementation() !=
nullptr;
152 return isa<ObjCImplDecl>(ContD);
182 for (
unsigned i = 0, e = MigrateCtx.
GCAttrs.size(); i != e; ++i) {
188 TA.
reportError(
"GC managed memory will become unmanaged in ARC",
198 for (
unsigned i = 0, e = MigrateCtx.
GCAttrs.size(); i != e; ++i) {
210 diag::err_arc_unsupported_weak_class,
221 IndivPropsTy &IndProps) {
222 if (IndProps.empty())
225 for (IndivPropsTy::iterator
226 PI = IndProps.begin(), PE = IndProps.end(); PI != PE; ++PI) {
233 bool hasWeak =
false, hasStrong =
false;
236 for (IndivPropsTy::iterator
237 PI = IndProps.begin(), PE = IndProps.end(); PI != PE; ++PI) {
246 ATLs.push_back(std::make_pair(ATL, PD));
257 if (hasWeak && hasStrong)
263 if (GCAttrsCollector::hasObjCImpl(
264 cast<Decl>(IndProps.front()->getDeclContext()))) {
269 StringRef toAttr =
"strong";
275 toAttr =
"unsafe_unretained";
283 for (
unsigned i = 0, e = ATLs.size(); i != e; ++i) {
290 TA.
clearDiagnostic(diag::err_objc_property_attr_mutually_exclusive, AtLoc);
292 ATLs[i].second->getLocation());
298 std::vector<ObjCPropertyDecl *> &AllProps) {
299 typedef llvm::TinyPtrVector<ObjCPropertyDecl *>
IndivPropsTy;
300 llvm::DenseMap<unsigned, IndivPropsTy> AtProps;
302 for (
unsigned i = 0, e = AllProps.size(); i != e; ++i) {
311 AtProps[RawAt].push_back(PD);
315 for (llvm::DenseMap<unsigned, IndivPropsTy>::iterator
316 I = AtProps.begin(), E = AtProps.end(); I != E; ++I) {
318 IndivPropsTy &IndProps = I->second;
324 std::vector<ObjCPropertyDecl *> AllProps;
325 GCAttrsCollector(MigrateCtx, AllProps).TraverseDecl(
334 llvm::errs() <<
"\n################\n";
335 for (
unsigned i = 0, e = GCAttrs.size(); i != e; ++i) {
337 llvm::errs() <<
"KIND: " 338 << (Attr.
Kind == GCAttrOccurrence::Strong ?
"strong" :
"weak");
339 llvm::errs() <<
"\nLOC: ";
340 Attr.
Loc.
print(llvm::errs(), Pass.Ctx.getSourceManager());
341 llvm::errs() <<
"\nTYPE: ";
344 llvm::errs() <<
"DECL:\n";
347 llvm::errs() <<
"DECL: NONE";
350 llvm::errs() <<
"\n----------------\n";
352 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.
static bool isInMainFile(const clang::Diagnostic &D)
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.