r194710 - [objcmt] Introduce "objcmt-white-list-dir-path=" option.
Argyrios Kyrtzidis
akyrtzi at gmail.com
Thu Nov 14 08:33:29 PST 2013
Author: akirtzidis
Date: Thu Nov 14 10:33:29 2013
New Revision: 194710
URL: http://llvm.org/viewvc/llvm-project?rev=194710&view=rev
Log:
[objcmt] Introduce "objcmt-white-list-dir-path=" option.
This options accepts a path to a directory, collects the filenames of the files
it contains, and the migrator will only modify files with the same filename.
Added:
cfe/trunk/test/ARCMT/whitelisted/
cfe/trunk/test/ARCMT/whitelisted/Inputs/
cfe/trunk/test/ARCMT/whitelisted/Inputs/header1.h
cfe/trunk/test/ARCMT/whitelisted/header1.h
cfe/trunk/test/ARCMT/whitelisted/header1.h.result
cfe/trunk/test/ARCMT/whitelisted/header2.h
cfe/trunk/test/ARCMT/whitelisted/header2.h.result
cfe/trunk/test/ARCMT/whitelisted/objcmt-with-whitelist.m
Modified:
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Frontend/FrontendOptions.h
cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
Modified: cfe/trunk/include/clang/Driver/Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=194710&r1=194709&r2=194710&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Thu Nov 14 10:33:29 2013
@@ -178,13 +178,14 @@ def objcmt_migrate_nsmacros : Flag<["-"]
HelpText<"Enable migration to NS_ENUM/NS_OPTIONS macros">;
def objcmt_migrate_protocol_conformance : Flag<["-"], "objcmt-migrate-protocol-conformance">, Flags<[CC1Option]>,
HelpText<"Enable migration to add protocol conformance on classes">;
-def objcmt_atomic_property : Flag<["-"], "objcmt-atomic-property">,
- Flags<[CC1Option]>,
+def objcmt_atomic_property : Flag<["-"], "objcmt-atomic-property">, Flags<[CC1Option]>,
HelpText<"Make migration to 'atomic' properties">;
def objcmt_returns_innerpointer_property : Flag<["-"], "objcmt-returns-innerpointer-property">, Flags<[CC1Option]>,
HelpText<"Enable migration to annotate property with NS_RETURNS_INNER_POINTER">;
def objcmt_ns_nonatomic_iosonly: Flag<["-"], "objcmt-ns-nonatomic-iosonly">, Flags<[CC1Option]>,
HelpText<"Enable migration to use NS_NONATOMIC_IOSONLY macro for setting property's 'atomic' attribute">;
+def objcmt_white_list_dir_path: Joined<["-"], "objcmt-white-list-dir-path=">, Flags<[CC1Option]>,
+ HelpText<"Only modify files with a filename contained in the provided directory path">;
// Make sure all other -ccc- options are rejected.
def ccc_ : Joined<["-"], "ccc-">, Group<internal_Group>, Flags<[Unsupported]>;
Modified: cfe/trunk/include/clang/Frontend/FrontendOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/FrontendOptions.h?rev=194710&r1=194709&r2=194710&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/FrontendOptions.h (original)
+++ cfe/trunk/include/clang/Frontend/FrontendOptions.h Thu Nov 14 10:33:29 2013
@@ -186,6 +186,7 @@ public:
ObjCMT_MigrateAll = (ObjCMT_Literals | ObjCMT_Subscripting | ObjCMT_MigrateDecls)
};
unsigned ObjCMTAction;
+ std::string ObjCMTWhiteListPath;
std::string MTMigrateDir;
std::string ARCMTMigrateReportOut;
Modified: cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/ObjCMT.cpp?rev=194710&r1=194709&r2=194710&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/ObjCMT.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/ObjCMT.cpp Thu Nov 14 10:33:29 2013
@@ -28,6 +28,7 @@
#include "clang/StaticAnalyzer/Checkers/ObjCRetainCount.h"
#include "clang/AST/Attr.h"
#include "llvm/ADT/SmallString.h"
+#include "llvm/Support/Path.h"
using namespace clang;
using namespace arcmt;
@@ -90,6 +91,7 @@ public:
bool IsOutputFile;
llvm::SmallPtrSet<ObjCProtocolDecl *, 32> ObjCProtocolDecls;
llvm::SmallVector<const Decl *, 8> CFFunctionIBCandidates;
+ llvm::StringMap<char> WhiteListFilenames;
ObjCMigrateASTConsumer(StringRef migrateDir,
unsigned astMigrateActions,
@@ -97,12 +99,19 @@ public:
FileManager &fileMgr,
const PPConditionalDirectiveRecord *PPRec,
Preprocessor &PP,
- bool isOutputFile = false)
+ bool isOutputFile,
+ ArrayRef<std::string> WhiteList)
: MigrateDir(migrateDir),
ASTMigrateActions(astMigrateActions),
NSIntegerTypedefed(0), NSUIntegerTypedefed(0),
Remapper(remapper), FileMgr(fileMgr), PPRec(PPRec), PP(PP),
- IsOutputFile(isOutputFile) { }
+ IsOutputFile(isOutputFile) {
+
+ for (ArrayRef<std::string>::iterator
+ I = WhiteList.begin(), E = WhiteList.end(); I != E; ++I) {
+ WhiteListFilenames.GetOrCreateValue(*I);
+ }
+ }
protected:
virtual void Initialize(ASTContext &Context) {
@@ -125,6 +134,13 @@ protected:
}
virtual void HandleTranslationUnit(ASTContext &Ctx);
+
+ bool canModifyFile(StringRef Path) {
+ if (WhiteListFilenames.empty())
+ return true;
+ return WhiteListFilenames.find(llvm::sys::path::filename(Path))
+ != WhiteListFilenames.end();
+ }
};
}
@@ -151,7 +167,9 @@ ASTConsumer *ObjCMigrateAction::CreateAS
Remapper,
CompInst->getFileManager(),
PPRec,
- CompInst->getPreprocessor());
+ CompInst->getPreprocessor(),
+ false,
+ ArrayRef<std::string>());
ASTConsumer *Consumers[] = { MTConsumer, WrappedConsumer };
return new MultiplexConsumer(Consumers);
}
@@ -1682,6 +1700,8 @@ void ObjCMigrateASTConsumer::HandleTrans
assert(file);
if (IsReallyASystemHeader(Ctx, file, FID))
continue;
+ if (!canModifyFile(file->getName()))
+ continue;
SmallString<512> newText;
llvm::raw_svector_ostream vecOS(newText);
buf.write(vecOS);
@@ -1705,6 +1725,25 @@ bool MigrateSourceAction::BeginInvocatio
return true;
}
+static std::vector<std::string> getWhiteListFilenames(StringRef DirPath) {
+ using namespace llvm::sys::fs;
+ using namespace llvm::sys::path;
+
+ std::vector<std::string> Filenames;
+ if (DirPath.empty() || !is_directory(DirPath))
+ return Filenames;
+
+ llvm::error_code EC;
+ directory_iterator DI = directory_iterator(DirPath, EC);
+ directory_iterator DE;
+ for (; !EC && DI != DE; DI = DI.increment(EC)) {
+ if (is_regular_file(DI->path()))
+ Filenames.push_back(filename(DI->path()));
+ }
+
+ return Filenames;
+}
+
ASTConsumer *MigrateSourceAction::CreateASTConsumer(CompilerInstance &CI,
StringRef InFile) {
PPConditionalDirectiveRecord *
@@ -1721,11 +1760,14 @@ ASTConsumer *MigrateSourceAction::Create
FrontendOptions::ObjCMT_Subscripting;
}
CI.getPreprocessor().addPPCallbacks(PPRec);
+ std::vector<std::string> WhiteList =
+ getWhiteListFilenames(CI.getFrontendOpts().ObjCMTWhiteListPath);
return new ObjCMigrateASTConsumer(CI.getFrontendOpts().OutputFile,
ObjCMTAction,
Remapper,
CI.getFileManager(),
PPRec,
CI.getPreprocessor(),
- /*isOutputFile=*/true);
+ /*isOutputFile=*/true,
+ WhiteList);
}
Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=194710&r1=194709&r2=194710&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Thu Nov 14 10:33:29 2013
@@ -2726,6 +2726,7 @@ void Clang::ConstructJob(Compilation &C,
Args.AddLastArg(CmdArgs, options::OPT_objcmt_atomic_property);
Args.AddLastArg(CmdArgs, options::OPT_objcmt_returns_innerpointer_property);
Args.AddLastArg(CmdArgs, options::OPT_objcmt_ns_nonatomic_iosonly);
+ Args.AddLastArg(CmdArgs, options::OPT_objcmt_white_list_dir_path);
}
// Add preprocessing options like -I, -D, etc. if we are using the
Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=194710&r1=194709&r2=194710&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Thu Nov 14 10:33:29 2013
@@ -821,6 +821,8 @@ static InputKind ParseFrontendArgs(Front
if (Args.hasArg(OPT_objcmt_migrate_all))
Opts.ObjCMTAction |= FrontendOptions::ObjCMT_MigrateDecls;
+ Opts.ObjCMTWhiteListPath = Args.getLastArgValue(OPT_objcmt_white_list_dir_path);
+
if (Opts.ARCMTAction != FrontendOptions::ARCMT_None &&
Opts.ObjCMTAction != FrontendOptions::ObjCMT_None) {
Diags.Report(diag::err_drv_argument_not_allowed_with)
Added: cfe/trunk/test/ARCMT/whitelisted/Inputs/header1.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/whitelisted/Inputs/header1.h?rev=194710&view=auto
==============================================================================
--- cfe/trunk/test/ARCMT/whitelisted/Inputs/header1.h (added)
+++ cfe/trunk/test/ARCMT/whitelisted/Inputs/header1.h Thu Nov 14 10:33:29 2013
@@ -0,0 +1 @@
+// the contents are not important
Added: cfe/trunk/test/ARCMT/whitelisted/header1.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/whitelisted/header1.h?rev=194710&view=auto
==============================================================================
--- cfe/trunk/test/ARCMT/whitelisted/header1.h (added)
+++ cfe/trunk/test/ARCMT/whitelisted/header1.h Thu Nov 14 10:33:29 2013
@@ -0,0 +1,5 @@
+
+ at interface I1 : NSObject
+-(int)prop;
+-(void)setProp:(int)p;
+ at end
Added: cfe/trunk/test/ARCMT/whitelisted/header1.h.result
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/whitelisted/header1.h.result?rev=194710&view=auto
==============================================================================
--- cfe/trunk/test/ARCMT/whitelisted/header1.h.result (added)
+++ cfe/trunk/test/ARCMT/whitelisted/header1.h.result Thu Nov 14 10:33:29 2013
@@ -0,0 +1,4 @@
+
+ at interface I1 : NSObject
+ at property (nonatomic) int prop;
+ at end
Added: cfe/trunk/test/ARCMT/whitelisted/header2.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/whitelisted/header2.h?rev=194710&view=auto
==============================================================================
--- cfe/trunk/test/ARCMT/whitelisted/header2.h (added)
+++ cfe/trunk/test/ARCMT/whitelisted/header2.h Thu Nov 14 10:33:29 2013
@@ -0,0 +1,5 @@
+
+ at interface I2 : NSObject
+-(int)prop;
+-(void)setProp:(int)p;
+ at end
Added: cfe/trunk/test/ARCMT/whitelisted/header2.h.result
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/whitelisted/header2.h.result?rev=194710&view=auto
==============================================================================
--- cfe/trunk/test/ARCMT/whitelisted/header2.h.result (added)
+++ cfe/trunk/test/ARCMT/whitelisted/header2.h.result Thu Nov 14 10:33:29 2013
@@ -0,0 +1,4 @@
+
+ at interface I2 : NSObject
+ at property (nonatomic) int prop;
+ at end
Added: cfe/trunk/test/ARCMT/whitelisted/objcmt-with-whitelist.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/whitelisted/objcmt-with-whitelist.m?rev=194710&view=auto
==============================================================================
--- cfe/trunk/test/ARCMT/whitelisted/objcmt-with-whitelist.m (added)
+++ cfe/trunk/test/ARCMT/whitelisted/objcmt-with-whitelist.m Thu Nov 14 10:33:29 2013
@@ -0,0 +1,12 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -objcmt-migrate-readwrite-property %s -triple x86_64-apple-darwin11 -migrate -o %t.remap
+// RUN: c-arcmt-test %t.remap | arcmt-test -verify-transformed-files %S/header1.h.result %S/header2.h.result
+// RUN: %clang_cc1 -objcmt-migrate-readwrite-property -objcmt-white-list-dir-path=%S/Inputs %s -triple x86_64-apple-darwin11 -migrate -o %t.remap
+// RUN: c-arcmt-test %t.remap | arcmt-test -verify-transformed-files %S/header1.h.result
+
+ at interface NSObject
++ (id)alloc;
+ at end
+
+#include "header1.h"
+#include "header2.h"
More information about the cfe-commits
mailing list