Introduction
--
J2C will convert Java code into hopefully compilable C++(11) code. It works on
source level, translating Java source code constructs into their rough
equivalents in C++ . The output will be reasonably valid C++ code that looks a
lot like its Java counterpart and hopefully works mostly the same.
The translation is based on The Java Language Specification, Third Edition, by
Gosling, James and Joy, Bill and Steele, Guy and Bracha, Gilad (that's
Java 1.6). The translated code should be valid as specified by the ISO/IEC
14882:2011 C++ standard (or C++11 as the rest of the world knows it).
*The generated code won't work out of the box - you need to remove or implement
dependencies such as the JRE.*
Status
--
This project is an idea I've been wanting to try out written down in code.
Think of it as a paper napkin with some notes on, but in this case, the notes
compile and sometimes spit out working stuff. In other words, no guarantees
and no quality control label.
That said, j2c successfully converts most of OpenJDK 6 and SWT 3.7 to C++
that compiles and passes a quick ocular inspection. Most *language* features
of Java 1.6 are covered (i e you'll still need a JDK and runtime).
With a few patches and implementations of native methods in the converted
OpenJDK code, the included Hello test prints it's message. A more complete
example would need a more complete runtime, either by implementing the native
and JVM parts of a class library or by implementing the stubs that are
generated for missing dependencies.
This is the first time I write an Eclipse plugin, so be nice.
Install / Run
--
J2C comes in the form of an Eclipse plugin. You need at least Eclipse 3.8+ and
Java 1.6+ to run this plugin!
The most recent version of the project is available as source code. You can get
it either from Bitbucket (https://bitbucket.org/arnetheduck/j2c/)
or github (https://github.com/arnetheduck/j2c).
From time to time, a release may appear at the Bitbucket site - see
https://bitbucket.org/arnetheduck/j2c/downloads . About that same
time, the update site (https://bitbucket.org/arnetheduck/j2c.site/raw/default/)
should be updated.
If you installed via site, it should just work.
If you downloaded the jar, copy it to `$ECLIPSE_HOME/dropins`.
If you downloaded the source code you'll have run the plugin by opening the
project in Eclipse and starting a new Eclipse test instance by using the run
button in the plugin.xml overview.
Once you have the plugin running, set up your Java code as a Java
Project. Eclipse must be able to compile your code for J2C do to its work!
Once the Java Project is set up (with all dependencies etc), you can run J2C by
right-clicking the project (or a class/package) in the 'Project Explorer' or
'Package Explorer' view and choosing the 'Translate to C++' option. You will
need to create a folder for the conversion output - the plugin will tell you
where.
The generated code will contain references to your JRE (stuff from the `java.*`
packages), as well as some generic helpers. The JRE dependencies will likely be
stubbed out in the ext folder in the generated code, and trivial, non-working
implementations of the rest can be found in j2c.cpp. You'll need to supplant
the converted code with implementations of all JRE features you're using,
or replace them manually to use equivalents from C++ libraries such as STL.
Testing
--
The test project contains a few cases which should be handled correctly by the
translator (by correctly, I mean that they compile with g++ 4.7). You'll find
a CDT project in ctest that builds using the generated Makefile after running
the plugin on the test project.
Output
--
For each Java class, j2c will output a header file and its implementation.
Inner classes end up in separate .h/.cpp pairs. Native method stubs will be
put in a separate file for your editing pleasure.
Classes for which there is no source will have a header written as well as
a stub file with empty implementations. Throughout, the heap will be used
to allocate class instances but no attempt is made to collect garbage -
I recommend Boehm's garbage collector for that.
What's missing (that I can think of right now)
--
* Reflection
* Anything involving byte code (class loading, dynamic code generation, etc)
* Command line support / build integration
Helping out
--
Patches and forks are most welcome, as is testing, but please don't report
issues unless you also attach a simple test case.
Final words
--
Send me a note if you manage (or not) to do something useful with this
converter!
Licensing
--
The project is licensed under the Eclipse Public License 1.0.
Thanks
--
No animals were hurt while writing this code, but the Nightwatchman
might have sore fingers and throat from all that playing...
Have fun,
Jacek Sieka (arnetheduck using google mail point com)
没有合适的资源?快使用搜索试试~ 我知道了~
Java to C++ translator.zip
共202个文件
java:172个
hpp:7个
project:4个
需积分: 5 0 下载量 19 浏览量
2024-01-05
14:53:58
上传
评论
收藏 137KB ZIP 举报
温馨提示
Java to C++ translator
资源推荐
资源详情
资源评论
收起资源包目录
Java to C++ translator.zip (202个子文件)
.classpath 369B
.classpath 226B
j2c.cpp 1KB
.cproject 6KB
sample.gif 983B
.hgignore 53B
.hgtags 376B
Array.hpp 4KB
ObjectArray.hpp 4KB
SubArray.hpp 3KB
finally.hpp 382B
synchronized.hpp 350B
java_cast.hpp 210B
npc.hpp 118B
ImplWriter.java 61KB
TransformUtil.java 36KB
TransformWriter.java 21KB
Header.java 19KB
Transformer.java 14KB
Impl.java 11KB
CName.java 11KB
HeaderWriter.java 9KB
StubWriter.java 9KB
TypeUtil.java 6KB
TypeInfoVisitor.java 5KB
DepInfo.java 4KB
TypeBindingHeaderWriter.java 4KB
HandlerHelper.java 3KB
ForwardWriter.java 3KB
LocalClassTest.java 3KB
FileUtil.java 3KB
TransformHandler.java 3KB
GetSetSnippet.java 2KB
TypeInfo.java 2KB
Sort.java 2KB
LabelTest.java 2KB
ReplaceInvocation.java 2KB
Stats.java 1KB
Activator.java 1KB
EmptySnippet.java 1KB
TestHandler.java 1KB
ReturnCovariance.java 1KB
Names.java 1KB
MakefileWriter.java 1KB
ForTest.java 1KB
ConstExpr.java 1KB
StringTest.java 980B
Snippet.java 955B
GenHiding.java 874B
InitInfo.java 873B
NestedTest.java 858B
QualifiedThisSuper.java 847B
PrimitiveTest.java 776B
BaseImplements.java 766B
Hiding.java 751B
MainWriter.java 664B
BridgeTest.java 630B
BoxTest.java 627B
Volatile.java 609B
ExtendsTest.java 608B
Overrides.java 585B
SwitchEnum.java 580B
SwitchTest.java 566B
CovariantInterface.java 556B
CovariantReturn.java 530B
BaseFinalImpl.java 515B
MethodInvocationCast.java 513B
ClosureNames.java 499B
StaticInvokes.java 477B
SameNameOverload.java 474B
DiamondImplements.java 471B
IfElseTest.java 469B
NestedAccessTest.java 467B
Constructor.java 467B
TryTest.java 465B
VarargTest.java 460B
ReturnTest.java 430B
NestedEnumSwitch.java 430B
Infix.java 429B
Friends.java 420B
CovariantCircularDeep.java 412B
SuperTest.java 403B
DefaultVirtualOverride.java 395B
LocalPrivateCtor.java 392B
CovariantCircular.java 392B
SameName.java 388B
DiamondImplements.java 381B
LiteralTest.java 372B
SuperBridgeCall.java 370B
DoubleInheritedImplements.java 365B
AmbiguousSuper.java 364B
Fields.java 361B
SyntheticTest.java 357B
CastTest.java 353B
UnrelatedCovariant.java 353B
Classes.java 352B
Primitives.java 346B
CrossCovariant.java 346B
GenericBaseImplements.java 341B
Implement.java 338B
共 202 条
- 1
- 2
- 3
资源评论
Lei宝啊
- 粉丝: 2071
- 资源: 1330
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功