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();
89 if (MigrateCtx.AttrSet.count(RawLoc))
104 if (Spell ==
"strong")
106 else if (Spell ==
"weak")
111 MigrateCtx.AttrSet.insert(RawLoc);
123 bool isMigratable(
Decl *D) {
124 if (isa<TranslationUnitDecl>(D))
131 return FD->hasBody();
134 return hasObjCImpl(ContD);
137 for (
const auto *MI : RD->methods()) {
138 if (MI->isOutOfLine())
147 static bool hasObjCImpl(
Decl *D) {
152 return ID->getImplementation() !=
nullptr;
154 return CD->getImplementation() !=
nullptr;
155 if (isa<ObjCImplDecl>(ContD))
162 bool isInMainFile(
Decl *D) {
167 if (!isInMainFile(I->getLocation()))
187 for (
unsigned i = 0, e = MigrateCtx.
GCAttrs.size(); i != e; ++i) {
193 TA.
reportError(
"GC managed memory will become unmanaged in ARC",
203 for (
unsigned i = 0, e = MigrateCtx.
GCAttrs.size(); i != e; ++i) {
215 diag::err_arc_unsupported_weak_class,
227 if (IndProps.empty())
230 for (IndivPropsTy::iterator
231 PI = IndProps.begin(), PE = IndProps.end(); PI != PE; ++PI) {
238 bool hasWeak =
false, hasStrong =
false;
241 for (IndivPropsTy::iterator
242 PI = IndProps.begin(), PE = IndProps.end(); PI != PE; ++PI) {
251 ATLs.push_back(std::make_pair(ATL, PD));
262 if (hasWeak && hasStrong)
268 if (GCAttrsCollector::hasObjCImpl(
269 cast<Decl>(IndProps.front()->getDeclContext()))) {
274 StringRef toAttr =
"strong";
280 toAttr =
"unsafe_unretained";
288 for (
unsigned i = 0, e = ATLs.size(); i != e; ++i) {
294 TA.
clearDiagnostic(diag::err_objc_property_attr_mutually_exclusive, AtLoc);
296 ATLs[i].second->getLocation());
302 std::vector<ObjCPropertyDecl *> &AllProps) {
303 typedef llvm::TinyPtrVector<ObjCPropertyDecl *>
IndivPropsTy;
304 llvm::DenseMap<unsigned, IndivPropsTy> AtProps;
306 for (
unsigned i = 0, e = AllProps.size(); i != e; ++i) {
315 AtProps[RawAt].push_back(PD);
319 for (llvm::DenseMap<unsigned, IndivPropsTy>::iterator
320 I = AtProps.begin(), E = AtProps.end(); I != E; ++I) {
322 IndivPropsTy &IndProps = I->second;
328 std::vector<ObjCPropertyDecl *> AllProps;
329 GCAttrsCollector(MigrateCtx, AllProps).TraverseDecl(
338 llvm::errs() <<
"\n################\n";
339 for (
unsigned i = 0, e =
GCAttrs.size(); i != e; ++i) {
341 llvm::errs() <<
"KIND: "
343 llvm::errs() <<
"\nLOC: ";
345 llvm::errs() <<
"\nTYPE: ";
348 llvm::errs() <<
"DECL:\n";
351 llvm::errs() <<
"DECL: NONE";
354 llvm::errs() <<
"\n----------------\n";
356 llvm::errs() <<
"\n################\n";
Defines the clang::ASTContext interface.
static unsigned getSpelling(const Token &Tok, const char *&Buffer, const SourceManager &SourceMgr, const LangOptions &LangOpts, bool *Invalid=nullptr)
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
SourceLocation getSpellingLoc(SourceLocation Loc) const
Given a SourceLocation object, return the spelling location referenced by the ID. ...
Defines the SourceManager interface.
A container of type source information.
unsigned getRawEncoding() const
When a SourceLocation itself cannot be used, this returns an (opaque) 32-bit integer encoding for it...
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
bool isObjCRetainableType() const
void dump(const char *s) const
TypeSourceInfo * getTypeSourceInfo() const
Base wrapper for a particular "section" of type source info.
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. it is in a body and not just in an interface.
const LangOptions & getLangOpts() const
void dump(const SourceManager &SM) const
A class that does preorder depth-first traversal on the entire Clang AST and visits each node...
Represents an ObjC class declaration.
SourceLocation getAtLoc() const
AttributedType::Kind getAttrKind() const
llvm::DenseSet< unsigned > RemovedAttrSet
Qualifiers::ObjCLifetime getObjCLifetime() const
getObjCLifetime - Returns lifetime attribute of this type.
Represents a ValueDecl that came out of a declarator. Contains type source information through TypeSo...
SourceLocation getAttrEnumOperandLoc() const
ID
Defines the set of possible language-specific address spaces.
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.
TranslationUnitDecl * getTranslationUnitDecl() const
DeclContext * getDeclContext()
QualType getType() const
Get the type for which this source info wrapper provides information.
bool addPropertyAttribute(StringRef attr, SourceLocation atLoc)
bool canApplyWeak(ASTContext &Ctx, QualType type, bool AllowOnUnknownClass=false)
Determine whether we can add weak to the given type.
llvm::TinyPtrVector< ObjCPropertyDecl * > IndivPropsTy
static void errorForGCAttrsOnNonObjC(MigrationContext &MigrateCtx)
Wrapper for source info for arrays.
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Encodes a location in the source. The SourceManager can decode this to get at the full include stack...
void traverseTU(MigrationContext &MigrateCtx) override
Represents one property declaration in an Objective-C interface.
FileID getMainFileID() const
Returns the FileID of the main source file.
QualType getType() const
Return the type wrapped by this type source info.
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. It will iterate at least once ...
std::pair< SourceLocation, SourceLocation > getImmediateExpansionRange(SourceLocation Loc) const
Return the start/end of the expansion information for an expansion location.
static void checkAllProps(MigrationContext &MigrateCtx, std::vector< ObjCPropertyDecl * > &AllProps)
SourceManager & getSourceManager()
Reading or writing from this object requires a barrier call.
Represents a C++ struct/union/class.
enum clang::arcmt::trans::MigrationContext::GCAttrOccurrence::AttrKind Kind
PropertyAttributeKind getPropertyAttributesAsWritten() const
UnqualTypeLoc getUnqualifiedLoc() const
Skips past any qualifiers, if this is qualified.
SourceLocation getExpansionLoc(SourceLocation Loc) const
Given a SourceLocation object Loc, return the expansion location referenced by the ID...
bool isNull() const
isNull - Return true if this QualType doesn't point to a type yet.
Wrapper for source info for pointers.
This class handles loading and caching of source files into memory.
Attr - This represents one attribute.
llvm::DenseSet< unsigned > AtPropsWeak
Set of raw '@' locations for 'assign' properties group that contain GC __weak.