Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 8f0e8d2

Browse files
committed
The ARC Migration Tool. All the credit goes to Argyrios and Fariborz
for this. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@133104 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent f85e193 commit 8f0e8d2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+6340
-15
lines changed

clang.xcodeproj/project.pbxproj

+41
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,12 @@
373373
90FD6D90103C3D80005F5B73 /* TypeXML.def */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = TypeXML.def; path = clang/Frontend/TypeXML.def; sourceTree = "<group>"; };
374374
90FD6D91103C3D80005F5B73 /* Utils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Utils.h; path = clang/Frontend/Utils.h; sourceTree = "<group>"; };
375375
90FD6DB5103D977E005F5B73 /* index-test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "index-test.cpp"; path = "tools/index-test/index-test.cpp"; sourceTree = "<group>"; };
376+
BB20603B131EDDBF003C3343 /* CMakeLists.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CMakeLists.txt; sourceTree = "<group>"; };
377+
BB20603C131EDDBF003C3343 /* Makefile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.make; path = Makefile; sourceTree = "<group>"; };
378+
BB206041131EDDDA003C3343 /* ARRMT.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ARRMT.h; sourceTree = "<group>"; };
379+
BB206043131EDE03003C3343 /* arrmt-test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = "arrmt-test.cpp"; sourceTree = "<group>"; };
380+
BB206044131EDE03003C3343 /* CMakeLists.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CMakeLists.txt; sourceTree = "<group>"; };
381+
BB206045131EDE03003C3343 /* Makefile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.make; path = Makefile; sourceTree = "<group>"; };
376382
BB5C372812A5057500259F53 /* DumpXML.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DumpXML.cpp; path = /Volumes/Data/llvm/tools/clang/lib/AST/DumpXML.cpp; sourceTree = "<absolute>"; };
377383
BBA5AB141309C2FA000B38F1 /* AdjustedReturnValueChecker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AdjustedReturnValueChecker.cpp; sourceTree = "<group>"; };
378384
BBA5AB151309C2FA000B38F1 /* AnalyzerStatsChecker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AnalyzerStatsChecker.cpp; sourceTree = "<group>"; };
@@ -777,6 +783,7 @@
777783
08FB7795FE84155DC02AAC07 /* Libraries */ = {
778784
isa = PBXGroup;
779785
children = (
786+
BB20603A131EDDBF003C3343 /* ARRMigrate */,
780787
BBA5AB121309C2FA000B38F1 /* StaticAnalyzer */,
781788
57EB5660121B034300ECA335 /* Serialization */,
782789
BFE2F67911DA95590007EDC0 /* Rewrite */,
@@ -1105,6 +1112,38 @@
11051112
name = "index-test";
11061113
sourceTree = "<group>";
11071114
};
1115+
BB20603A131EDDBF003C3343 /* ARRMigrate */ = {
1116+
isa = PBXGroup;
1117+
children = (
1118+
BB20603B131EDDBF003C3343 /* CMakeLists.txt */,
1119+
BB20603C131EDDBF003C3343 /* Makefile */,
1120+
BDDF60E91337BF40009F1764 /* Transforms.cpp */,
1121+
);
1122+
name = ARRMigrate;
1123+
path = lib/ARRMigrate;
1124+
sourceTree = "<group>";
1125+
};
1126+
BB206040131EDDDA003C3343 /* ARRMigrate */ = {
1127+
isa = PBXGroup;
1128+
children = (
1129+
BB206041131EDDDA003C3343 /* ARRMT.h */,
1130+
);
1131+
name = ARRMigrate;
1132+
path = clang/ARRMigrate;
1133+
sourceTree = "<group>";
1134+
};
1135+
BB206042131EDE03003C3343 /* arrmt-test */ = {
1136+
isa = PBXGroup;
1137+
children = (
1138+
BD8A47E7133D32660066FE40 /* ARRMT.cpp */,
1139+
BB206043131EDE03003C3343 /* arrmt-test.cpp */,
1140+
BB206044131EDE03003C3343 /* CMakeLists.txt */,
1141+
BB206045131EDE03003C3343 /* Makefile */,
1142+
);
1143+
name = "arrmt-test";
1144+
path = "tools/arrmt-test";
1145+
sourceTree = "<group>";
1146+
};
11081147
BBA5AB121309C2FA000B38F1 /* StaticAnalyzer */ = {
11091148
isa = PBXGroup;
11101149
children = (
@@ -1575,6 +1614,7 @@
15751614
DED7D72E0A524295003AD0FB /* include */ = {
15761615
isa = PBXGroup;
15771616
children = (
1617+
BB206040131EDDDA003C3343 /* ARRMigrate */,
15781618
DED7D7300A524295003AD0FB /* Basic */,
15791619
DED7D7390A524295003AD0FB /* Lex */,
15801620
DE1F21F20A7D84E800FBF588 /* Parse */,
@@ -1724,6 +1764,7 @@
17241764
DEDFE61F0F7B3AE10035BD10 /* Tools */ = {
17251765
isa = PBXGroup;
17261766
children = (
1767+
BB206042131EDE03003C3343 /* arrmt-test */,
17271768
90F9EFA8104ABDC400D09A15 /* c-index-test */,
17281769
9012911E104812DA0083456D /* CIndex */,
17291770
90FD6DB4103D9763005F5B73 /* index-test */,

include/clang/ARCMigrate/ARCMT.h

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
//===-- ARCMT.h - ARC Migration Rewriter ------------------------*- C++ -*-===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is distributed under the University of Illinois Open Source
6+
// License. See LICENSE.TXT for details.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#ifndef LLVM_CLANG_ARCMIGRATE_ARCMT_H
11+
#define LLVM_CLANG_ARCMIGRATE_ARCMT_H
12+
13+
#include "clang/ARCMigrate/FileRemapper.h"
14+
#include "clang/Frontend/CompilerInvocation.h"
15+
16+
namespace clang {
17+
class ASTContext;
18+
class DiagnosticClient;
19+
20+
namespace arcmt {
21+
class MigrationPass;
22+
23+
/// \brief Creates an AST with the provided CompilerInvocation but with these
24+
/// changes:
25+
/// -if a PCH/PTH is set, the original header is used instead
26+
/// -Automatic Reference Counting mode is enabled
27+
///
28+
/// It then checks the AST and produces errors/warning for ARC migration issues
29+
/// that the user needs to handle manually.
30+
///
31+
/// \returns false if no error is produced, true otherwise.
32+
bool checkForManualIssues(CompilerInvocation &CI,
33+
llvm::StringRef Filename, InputKind Kind,
34+
DiagnosticClient *DiagClient);
35+
36+
/// \brief Works similar to checkForManualIssues but instead of checking, it
37+
/// applies automatic modifications to source files to conform to ARC.
38+
///
39+
/// \returns false if no error is produced, true otherwise.
40+
bool applyTransformations(CompilerInvocation &origCI,
41+
llvm::StringRef Filename, InputKind Kind,
42+
DiagnosticClient *DiagClient);
43+
44+
/// \brief Like applyTransformations but no source file is modified, compilation
45+
/// happens using in-memory buffers.
46+
bool applyTransformationsInMemory(CompilerInvocation &origCI,
47+
llvm::StringRef Filename, InputKind Kind,
48+
DiagnosticClient *DiagClient);
49+
50+
typedef void (*TransformFn)(MigrationPass &pass);
51+
52+
std::vector<TransformFn> getAllTransformations();
53+
54+
class MigrationProcess {
55+
CompilerInvocation OrigCI;
56+
DiagnosticClient *DiagClient;
57+
FileRemapper Remapper;
58+
59+
public:
60+
MigrationProcess(const CompilerInvocation &CI, DiagnosticClient *diagClient)
61+
: OrigCI(CI), DiagClient(diagClient) { }
62+
63+
class RewriteListener {
64+
public:
65+
virtual ~RewriteListener();
66+
67+
virtual void start(ASTContext &Ctx) { }
68+
virtual void finish() { }
69+
70+
virtual void insert(SourceLocation loc, llvm::StringRef text) { }
71+
virtual void remove(CharSourceRange range) { }
72+
};
73+
74+
bool applyTransform(TransformFn trans, RewriteListener *listener = 0);
75+
76+
FileRemapper &getRemapper() { return Remapper; }
77+
};
78+
79+
} // end namespace arcmt
80+
81+
} // end namespace clang
82+
83+
#endif
+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
//===-- FileRemapper.h - File Remapping Helper ------------------*- C++ -*-===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is distributed under the University of Illinois Open Source
6+
// License. See LICENSE.TXT for details.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#ifndef LLVM_CLANG_ARCMIGRATE_FILEREMAPPER_H
11+
#define LLVM_CLANG_ARCMIGRATE_FILEREMAPPER_H
12+
13+
#include "llvm/ADT/OwningPtr.h"
14+
#include "llvm/ADT/PointerUnion.h"
15+
#include "llvm/ADT/DenseMap.h"
16+
#include "llvm/ADT/StringRef.h"
17+
18+
namespace llvm {
19+
class MemoryBuffer;
20+
}
21+
22+
namespace clang {
23+
class FileManager;
24+
class FileEntry;
25+
class Diagnostic;
26+
class CompilerInvocation;
27+
28+
namespace arcmt {
29+
30+
class FileRemapper {
31+
// FIXME: Reuse the same FileManager for multiple ASTContexts.
32+
llvm::OwningPtr<FileManager> FileMgr;
33+
34+
typedef llvm::PointerUnion<const FileEntry *, llvm::MemoryBuffer *> Target;
35+
typedef llvm::DenseMap<const FileEntry *, Target> MappingsTy;
36+
MappingsTy FromToMappings;
37+
38+
llvm::DenseMap<const FileEntry *, const FileEntry *> ToFromMappings;
39+
40+
public:
41+
FileRemapper();
42+
~FileRemapper();
43+
44+
bool initFromDisk(llvm::StringRef outputDir, Diagnostic &Diag,
45+
bool ignoreIfFilesChanged);
46+
bool flushToDisk(llvm::StringRef outputDir, Diagnostic &Diag);
47+
48+
bool overwriteOriginal(Diagnostic &Diag,
49+
llvm::StringRef outputDir = llvm::StringRef());
50+
51+
void remap(llvm::StringRef filePath, llvm::MemoryBuffer *memBuf);
52+
void remap(llvm::StringRef filePath, llvm::StringRef newPath);
53+
54+
void applyMappings(CompilerInvocation &CI) const;
55+
56+
void transferMappingsAndClear(CompilerInvocation &CI);
57+
58+
void clear(llvm::StringRef outputDir = llvm::StringRef());
59+
60+
private:
61+
void remap(const FileEntry *file, llvm::MemoryBuffer *memBuf);
62+
void remap(const FileEntry *file, const FileEntry *newfile);
63+
64+
const FileEntry *getOriginalFile(llvm::StringRef filePath);
65+
void resetTarget(Target &targ);
66+
67+
bool report(const std::string &err, Diagnostic &Diag);
68+
69+
std::string getRemapInfoFile(llvm::StringRef outputDir);
70+
};
71+
72+
} // end namespace arcmt
73+
74+
} // end namespace clang
75+
76+
#endif

0 commit comments

Comments
 (0)