[cfe-dev] How to add a new rewriting option

Vincent R. forumer at smartmobili.com
Sun Jul 28 06:16:50 PDT 2013


Le 28.07.2013 14:31, Vincent R. a écrit :
> Le 28.07.2013 12:24, Vincent R. a écrit :
>> 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 ?
>>
> Actually I think I found I forgot to add the corresponding enum
> inside FrontendOptions.h :
>
> Index: tools/clang/include/clang/Frontend/FrontendOptions.h
> ===================================================================
> --- tools/clang/include/clang/Frontend/FrontendOptions.h	(revision 
> 186145)
> +++ tools/clang/include/clang/Frontend/FrontendOptions.h	(working 
> copy)
> @@ -51,6 +51,7 @@
>      PrintPreprocessedInput, ///< -E mode.
>      RewriteMacros,          ///< Expand macros but not \#includes.
>      RewriteObjC,            ///< ObjC->C Rewriter.
> +    RewriteObjC2Cs,         ///< ObjC->C# Rewriter.
>      RewriteTest,            ///< Rewriter playground
>      RunAnalysis,            ///< Run one or more source code 
> analyses.
>      MigrateSource,          ///< Run migrator.
>

Hum still problem because when I try to use the new rewrite options 
clang shows me the command usage (with the
new option) :

With the working rewrite-objc it works because I end up with a .cpp 
file
  ~/objc2cs/gnustep/core/gui/Source $ clang -rewrite-objc NSButton.m -c 
-MMD -MP -DGNUSTEP_TARGET_DIR=\".\" -DGNUSTEP_TARGET_CPU=\"x86_64\" 
-DGNUSTEP_TARGET_OS=\"linux-gnu\" -DLIBRARY_COMBO=\"gnu-gnu-gnu\" 
-DBACKEND_BUNDLE=1 -DGNUSTEP -DGNUSTEP_BASE_LIBRARY=1 
-DGNU_GUI_LIBRARY=1 -DGNU_RUNTIME=1 -DGNUSTEP_BASE_LIBRARY=1 
-fno-strict-aliasing -fexceptions -fobjc-exceptions 
-D_NATIVE_OBJC_EXCEPTIONS -fobjc-nonfragile-abi -D_NONFRAGILE_ABI 
-pthread -fPIC -DDEBUG -fno-omit-frame-pointer -Wall -DGSWARN 
-DGSDIAGNOSE -Wno-import -g -fgnu-runtime -Wall 
-fconstant-string-class=NSConstantString -I../Headers/Additions 
-I../Headers -I./. -I. -I/home/vincent/GNUstep/Library/Headers 
-I/GNUstep/Local/Library/Headers -I/GNUstep/System/Library/Headers 
-I/usr/include/libpng12

However if I try with the same command line and replace with 
-rewrite-objc2cs it shows me the command usage ...

Any idea ?







More information about the cfe-dev mailing list