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 return isa<ObjCImplDecl>(ContD);
160 bool isInMainFile(
Decl *D) {
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,
224 IndivPropsTy &IndProps) {
225 if (IndProps.empty())
228 for (IndivPropsTy::iterator
229 PI = IndProps.begin(), PE = IndProps.end(); PI != PE; ++PI) {
236 bool hasWeak =
false, hasStrong =
false;
239 for (IndivPropsTy::iterator
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) {
293 TA.
clearDiagnostic(diag::err_objc_property_attr_mutually_exclusive, AtLoc);
295 ATLs[i].second->getLocation());
301 std::vector<ObjCPropertyDecl *> &AllProps) {
302 typedef llvm::TinyPtrVector<ObjCPropertyDecl *>
IndivPropsTy;
303 llvm::DenseMap<unsigned, IndivPropsTy> AtProps;
305 for (
unsigned i = 0, e = AllProps.size(); i != e; ++i) {
314 AtProps[RawAt].push_back(PD);
318 for (llvm::DenseMap<unsigned, IndivPropsTy>::iterator
319 I = AtProps.begin(), E = AtProps.end(); I != E; ++I) {
321 IndivPropsTy &IndProps = I->second;
327 std::vector<ObjCPropertyDecl *> AllProps;
328 GCAttrsCollector(MigrateCtx, AllProps).TraverseDecl(
337 llvm::errs() <<
"\n################\n";
338 for (
unsigned i = 0, e = GCAttrs.size(); i != e; ++i) {
340 llvm::errs() <<
"KIND: " 341 << (Attr.
Kind == GCAttrOccurrence::Strong ?
"strong" :
"weak");
342 llvm::errs() <<
"\nLOC: ";
343 Attr.
Loc.
dump(Pass.Ctx.getSourceManager());
344 llvm::errs() <<
"\nTYPE: ";
347 llvm::errs() <<
"DECL:\n";
350 llvm::errs() <<
"DECL: NONE";
353 llvm::errs() <<
"\n----------------\n";
355 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...
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
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.
SourceLocation getAttrNameLoc() const
The location of the attribute name, i.e.
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...
SourceLocation getSpellingLoc(SourceLocation Loc) const
Given a SourceLocation object, return the spelling 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.
void dump(const SourceManager &SM) const
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.
AttributedType::Kind getAttrKind() const
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
SourceLocation getAttrEnumOperandLoc() const
The location of the attribute's enumerated operand, if it has one.
Wrapper for source info for pointers.
const LangOptions & getLangOpts() const
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.