[cfe-dev] How to add a new rewriting option
Vincent R.
forumer at smartmobili.com
Sun Jul 28 03:24:27 PDT 2013
Hi,
I would like to make some test about converting some objc code into C#
So I have started to locate the code responsible to handle objc-rewrite
and I tried to do the same for my case.
Presently I just want have something that compiles so I have duplicated
RewriteObjC.cpp and renamed it into RewriteObjC2Cs.cpp
and changed the class name (I didn't include it inside the diff below
because it makes things hard to read).
So now when I compile I get the following error :
Scanning dependencies of target clangFrontend
[ 84%] Building CXX object
tools/clang/lib/Frontend/CMakeFiles/clangFrontend.dir/CompilerInstance.cpp.o
/home/vincent/objc2cs/clang/llvm/tools/clang/lib/Frontend/CompilerInstance.cpp:
In member function ‘bool
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)’:
/home/vincent/objc2cs/clang/llvm/tools/clang/lib/Frontend/CompilerInstance.cpp:665:43:
error: ‘RewriteObjC2Cs’ is not a member of ‘clang::frontend’
make[2]: ***
[tools/clang/lib/Frontend/CMakeFiles/clangFrontend.dir/CompilerInstance.cpp.o]
Error 1
make[1]: ***
[tools/clang/lib/Frontend/CMakeFiles/clangFrontend.dir/all] Error 2
make: *** [all] Error 2
What am I missing ?
Index: lib/Frontend/InitPreprocessor.cpp
===================================================================
--- lib/Frontend/InitPreprocessor.cpp (revision 186145)
+++ lib/Frontend/InitPreprocessor.cpp (working copy)
@@ -624,7 +624,8 @@
else if (LangOpts.getStackProtector() == LangOptions::SSPReq)
Builder.defineMacro("__SSP_ALL__", "2");
- if (FEOpts.ProgramAction == frontend::RewriteObjC)
+ if ((FEOpts.ProgramAction == frontend::RewriteObjC) ||
+ (FEOpts.ProgramAction == frontend::RewriteObjC2Cs))
Builder.defineMacro("__weak", "__attribute__((objc_gc(weak)))");
// Define a macro that exists only when using the static analyzer.
Index: lib/Frontend/CompilerInstance.cpp
===================================================================
--- lib/Frontend/CompilerInstance.cpp (revision 186145)
+++ lib/Frontend/CompilerInstance.cpp (working copy)
@@ -661,7 +661,8 @@
getTarget().setForcedLangOptions(getLangOpts());
// rewriter project will change target built-in bool type from its
default.
- if (getFrontendOpts().ProgramAction == frontend::RewriteObjC)
+ if ((getFrontendOpts().ProgramAction == frontend::RewriteObjC) ||
+ (getFrontendOpts().ProgramAction == frontend::RewriteObjC2Cs))
getTarget().noSignedCharForObjCBool();
// Validate/process some options.
Index: lib/Frontend/CompilerInvocation.cpp
===================================================================
--- lib/Frontend/CompilerInvocation.cpp (revision 186145)
+++ lib/Frontend/CompilerInvocation.cpp (working copy)
@@ -661,6 +661,8 @@
Opts.ProgramAction = frontend::RewriteMacros; break;
case OPT_rewrite_objc:
Opts.ProgramAction = frontend::RewriteObjC; break;
+ case OPT_rewrite_objc2cs:
+ Opts.ProgramAction = frontend::RewriteObjC2Cs; break;
case OPT_rewrite_test:
Opts.ProgramAction = frontend::RewriteTest; break;
case OPT_analyze:
@@ -1473,6 +1475,7 @@
case frontend::PluginAction:
case frontend::PrintDeclContext:
case frontend::RewriteObjC:
+ case frontend::RewriteObjC2Cs:
case frontend::RewriteTest:
case frontend::RunAnalysis:
case frontend::MigrateSource:
@@ -1562,7 +1565,8 @@
ParseHeaderSearchArgs(Res.getHeaderSearchOpts(), *Args);
if (DashX != IK_AST && DashX != IK_LLVM_IR) {
ParseLangArgs(*Res.getLangOpts(), *Args, DashX, Diags);
- if (Res.getFrontendOpts().ProgramAction == frontend::RewriteObjC)
+ if ((Res.getFrontendOpts().ProgramAction == frontend::RewriteObjC)
||
+ (Res.getFrontendOpts().ProgramAction ==
frontend::RewriteObjC2Cs))
Res.getLangOpts()->ObjCExceptions = 1;
}
// FIXME: ParsePreprocessorArgs uses the FileManager to read the
contents of
Index: lib/Rewrite/Frontend/CMakeLists.txt
===================================================================
--- lib/Rewrite/Frontend/CMakeLists.txt (revision 186145)
+++ lib/Rewrite/Frontend/CMakeLists.txt (working copy)
@@ -6,6 +6,7 @@
RewriteMacros.cpp
RewriteModernObjC.cpp
RewriteObjC.cpp
+ RewriteObjC2Cs.cpp
RewriteTest.cpp
)
Index: lib/Driver/Driver.cpp
===================================================================
--- lib/Driver/Driver.cpp (revision 186145)
+++ lib/Driver/Driver.cpp (working copy)
@@ -129,6 +129,7 @@
(PhaseArg =
DAL.getLastArg(options::OPT_module_file_info)) ||
(PhaseArg = DAL.getLastArg(options::OPT_rewrite_objc)) ||
(PhaseArg =
DAL.getLastArg(options::OPT_rewrite_legacy_objc)) ||
+ (PhaseArg = DAL.getLastArg(options::OPT_rewrite_objc2cs))
||
(PhaseArg = DAL.getLastArg(options::OPT__migrate)) ||
(PhaseArg = DAL.getLastArg(options::OPT__analyze,
options::OPT__analyze_auto))
||
@@ -1153,6 +1154,8 @@
return new CompileJobAction(Input, types::TY_RewrittenObjC);
} else if (Args.hasArg(options::OPT_rewrite_legacy_objc)) {
return new CompileJobAction(Input,
types::TY_RewrittenLegacyObjC);
+ } else if (Args.hasArg(options::OPT_rewrite_objc2cs)) {
+ return new CompileJobAction(Input, types::TY_RewrittenObjC2Cs);
} else if (Args.hasArg(options::OPT__analyze,
options::OPT__analyze_auto)) {
return new AnalyzeJobAction(Input, types::TY_Plist);
} else if (Args.hasArg(options::OPT__migrate)) {
@@ -1326,6 +1329,7 @@
!C.getArgs().hasArg(options::OPT_traditional_cpp) &&
!C.getArgs().hasArg(options::OPT_save_temps) &&
!C.getArgs().hasArg(options::OPT_rewrite_objc) &&
+ !C.getArgs().hasArg(options::OPT_rewrite_objc2cs) &&
ToolForJob->hasIntegratedCPP())
Inputs = &(*Inputs)[0]->getInputs();
Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp (revision 186145)
+++ lib/Driver/Tools.cpp (working copy)
@@ -1961,7 +1961,10 @@
} else if (JA.getType() == types::TY_RewrittenLegacyObjC) {
CmdArgs.push_back("-rewrite-objc");
rewriteKind = RK_Fragile;
- } else {
+ } else if (JA.getType() == types::TY_RewrittenObjC2Cs) {
+ CmdArgs.push_back("-rewrite-objc2cs");
+ }
+ else {
assert(JA.getType() == types::TY_PP_Asm &&
"Unexpected output type!");
}
Index: include/clang/Driver/Options.td
===================================================================
--- include/clang/Driver/Options.td (revision 186145)
+++ include/clang/Driver/Options.td (working copy)
@@ -1050,6 +1050,8 @@
HelpText<"Rewrite Objective-C source to C++">, Group<Action_Group>;
def rewrite_legacy_objc : Flag<["-"], "rewrite-legacy-objc">,
Flags<[DriverOption]>,
HelpText<"Rewrite Legacy Objective-C source to C++">;
+def rewrite_objc2cs : Flag<["-"], "rewrite-objc2cs">,
Flags<[DriverOption,CC1Option]>,
+ HelpText<"Rewrite Objective-C source to C#">, Group<Action_Group>;
def rdynamic : Flag<["-"], "rdynamic">;
def resource_dir : Separate<["-"], "resource-dir">,
Flags<[DriverOption, CC1Option, HelpHidden]>,
Index: include/clang/Driver/Types.def
===================================================================
--- include/clang/Driver/Types.def (revision 186145)
+++ include/clang/Driver/Types.def (working copy)
@@ -84,6 +84,7 @@
TYPE("plist", Plist, INVALID,
"plist", "")
TYPE("rewritten-objc", RewrittenObjC,INVALID, "cpp",
"")
TYPE("rewritten-legacy-objc", RewrittenLegacyObjC,INVALID, "cpp",
"")
+TYPE("rewritten-objc2cs", RewrittenObjC2Cs,INVALID,
"cs", "")
TYPE("remap", Remap, INVALID,
"remap", "")
TYPE("precompiled-header", PCH, INVALID, "gch",
"A")
TYPE("object", Object, INVALID, "o",
"")
More information about the cfe-dev
mailing list