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) {
47 if (!D || D->isImplicit())
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())
144 return isMigratable(cast<Decl>(D->getDeclContext()));
147 static bool hasObjCImpl(
Decl *D) {
152 return ID->getImplementation() !=
nullptr;
154 return CD->getImplementation() !=
nullptr;
155 return isa<ObjCImplDecl>(ContD);
160 bool isInMainFile(
Decl *D) {
164 for (
auto I : D->redecls())
165 if (!isInMainFile(
I->getLocation()))
185 for (
unsigned i = 0, e = MigrateCtx.
GCAttrs.size(); i != e; ++i) {
191 TA.
reportError(
"GC managed memory will become unmanaged in ARC",
201 for (
unsigned i = 0, e = MigrateCtx.
GCAttrs.size(); i != e; ++i) {
213 diag::err_arc_unsupported_weak_class,
225 if (IndProps.empty())
229 PI = IndProps.begin(), PE = IndProps.end(); PI != PE; ++PI) {
236 bool hasWeak =
false, hasStrong =
false;
240 PI = IndProps.begin(), PE = IndProps.end(); PI != PE; ++PI) {
249 ATLs.push_back(std::make_pair(ATL, PD));
260 if (hasWeak && hasStrong)
266 if (GCAttrsCollector::hasObjCImpl(
267 cast<Decl>(IndProps.front()->getDeclContext()))) {
272 StringRef toAttr =
"strong";
278 toAttr =
"unsafe_unretained";
286 for (
unsigned i = 0, e = ATLs.size(); i != e; ++i) {
292 TA.
clearDiagnostic(diag::err_objc_property_attr_mutually_exclusive, AtLoc);
294 ATLs[i].second->getLocation());
300 std::vector<ObjCPropertyDecl *> &AllProps) {
301 typedef llvm::TinyPtrVector<ObjCPropertyDecl *>
IndivPropsTy;
302 llvm::DenseMap<unsigned, IndivPropsTy> AtProps;
304 for (
unsigned i = 0, e = AllProps.size(); i != e; ++i) {
313 AtProps[RawAt].push_back(PD);
318 I = AtProps.begin(),
E = AtProps.end();
I !=
E; ++
I) {
320 IndivPropsTy &IndProps =
I->second;
326 std::vector<ObjCPropertyDecl *> AllProps;
327 GCAttrsCollector(MigrateCtx, AllProps).TraverseDecl(
336 llvm::errs() <<
"\n################\n";
337 for (
unsigned i = 0, e =
GCAttrs.size(); i != e; ++i) {
339 llvm::errs() <<
"KIND: "
341 llvm::errs() <<
"\nLOC: ";
343 llvm::errs() <<
"\nTYPE: ";
346 llvm::errs() <<
"DECL:\n";
349 llvm::errs() <<
"DECL: NONE";
352 llvm::errs() <<
"\n----------------\n";
354 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)
getSpelling - This method is used to get the spelling of a token into a preallocated buffer...
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
A (possibly-)qualified type.
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.
ObjCContainerDecl - Represents a container for method declarations.
const LangOptions & getLangOpts() const
void dump(const SourceManager &SM) const
A class that does preordor or postorder depth-first traversal on the entire Clang AST and visits each...
Represents an ObjC class declaration.
detail::InMemoryDirectory::const_iterator I
SourceLocation getAtLoc() const
AttributedType::Kind getAttrKind() const
llvm::DenseSet< unsigned > RemovedAttrSet
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.
Represents a ValueDecl that came out of a declarator.
SourceLocation getAttrEnumOperandLoc() const
The modified type, which is generally canonically different from the attribute type.
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
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.
Assigning into this object requires the old value to be released and the new value to be retained...
Encodes a location in the source.
const TemplateArgument * iterator
void traverseTU(MigrationContext &MigrateCtx) override
ObjCCategoryDecl - Represents a category declaration.
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)
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)
detail::InMemoryDirectory::const_iterator E
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
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.