Giter VIP home page Giter VIP logo

cpp-to-java-source-converter's Introduction

C++ to Java Translator

Main source

This project aims to convert C++ code to high level Java source code. Where that is not possible, a TODO should appear in the generated source code.

Status

The project is about three quarters of the way to an initial release. The below items will not be handled by the initial release:

  • goto statement
  • untyped malloc
  • template code generation (generics to be used instead).
  • C++/C std lib
  • order of operation differences
  • platform dependent/undefined behavior
  • unions
  • dynamic cast and other RTTI features
  • multiple inheritance
  • C++11 features
  • overloaded operator new and operator delete memory management

Everything else should work with the initial release.

Example Code

The following lines give an indication of what generated code using pointers looks like.

 // Test plain assignment...
 f[4] = 111;
 *f = 112;
 (((*(f + 2)))) = 113;
 *(f--) = 114;

 // Test compound assignment...
 f[1] *= 3;
 (*f) += 4;

 // Test pointer comparison
 f < &f[1];
 &f[0] == f;

 // Test addressof ptr
 &f;
 f.ptrOffset(4).set(111);
 f.set(112);
 ((((f.ptrOffset(+2))))).set(113);
 (f.ptrPostDec()).set(114);

 f.ptrOffset(1).set(f.ptrOffset(1).get() * 3);
 (f).set((f.get()) + 4);

 f.ptrCompare() < f.ptrOffset(1).ptrCompare();
 f.ptrOffset(0).ptrCompare() == f.ptrCompare();

 f.ptrAddressOf();

Required JARs

This fork will build with Maven. Eclipse CDT is not in Maven central, or any repository I could find, but for your convenience, private copies of certain JARS are shipped in the lib/ directory:

  • org.eclipse.cdt.core_5.4.1.201209170703.jar
  • org.eclipse.equinox.common_3.6.100.v20120522-1841.jar
  • com.ibm.icu_50.1.1.v201304230130.jar (I needed it at run-time once to fix a logging error)

Please note these are from a separate project with separate licenses.

Historical required JARs:

These are the JAR files I use to get this code to run. They are from Eclipse Juno (4.2.x) and CDT 8.1.1 for Eclipse Juno. Additionally, jOOR is required by the runtime template handling code.

License

This project is licensed under the Apache license. The CDT walking code is based loosely on code I found (and lost the url) on the web (also licensed under the Apache license).

TODO

This is an incomplete and fluid list of items that need doing before the initial release.

  • General
    • Lots more assertions
    • Destructor calls on static duration objects
    • Cast operators other than C style cast should not resolve overloaded operator cast
    • Basic type classes other than MInteger
    • Global variables
    • Templates
    • Should be able to take the address of an enumerator
    • Putting in comments/defines from original
    • A lot of work on multi dimension arrays.
    • cleanup cpptojavatype method.
    • function pointers.
    • typed malloc.
    • testing cleanup.
    • making logger useful.
    • relacing deprecated methods.
    • make lists.
    • correct names (camel case, capitalized classes etc.)
    • Varargs.
    • Bracketed expressions
    • Special case this pointer and void pointer.
    • exact bit position for bitfield.
  • First pass
    • Recursively evaluate templates and generate expanded cpp code.
    • Generate implicit special methods and output cpp code.
    • Record if a basic variable(int, bool, etc) has its address taken so we can skip objectifying it if it does not.

cpp-to-java-source-converter's People

Contributors

damjanjovanovic avatar danfickle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cpp-to-java-source-converter's Issues

CPPClassType cannot be cast to ICPPConstructor

First of all, not sure if I am setting this up correctly, as there were no instructions really. I created a folder "\home\daniel\workspace\cpp-to-java-source-converter" and put the repository (master branch) there. I then ran "mvn clean package". I found I needed to create a directory called "crap" under the root directory and put an empty file "test-statements.java" there, as this is expected. I changed to the target directory to run:

D:\home\daniel\workspace\cpp-to-java-source-converter\target>java -cp cpp-to-java-source-converter-0.1-SNAPSHOT.jar;..\lib\* com.github.danfickle.cpptojavasourceconverter.Main

Secondly, it doesn't seem to work, due to a class cast exception. Here is the output I get:

D:\home\daniel\workspace\cpp-to-java-source-converter\target>java -cp cpp-to-jav
a-source-converter-0.1-SNAPSHOT.jar;..\lib\* com.github.danfickle.cpptojavasourc
econverter.Main
In: D:\home\daniel\workspace\cpp-to-java-source-converter\tests\test-bitfield.cp
p
org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassType cannot be cast to org.
eclipse.cdt.core.dom.ast.cpp.ICPPConstructor
java.lang.ClassCastException: org.eclipse.cdt.internal.core.dom.parser.cpp.CPPCl
assType cannot be cast to org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor
        at com.github.danfickle.cpptojavasourceconverter.ExpressionEvaluator.eva
lExprNew(ExpressionEvaluator.java:162)
        at com.github.danfickle.cpptojavasourceconverter.ExpressionEvaluator.eva
l1Expr(ExpressionEvaluator.java:67)
        at com.github.danfickle.cpptojavasourceconverter.InitializationManager.e
val1Init(InitializationManager.java:76)
        at com.github.danfickle.cpptojavasourceconverter.SourceConverter.evaluat
eDeclarationReturnInitializers(SourceConverter.java:282)
        at com.github.danfickle.cpptojavasourceconverter.StmtEvaluator.evalStmt(
StmtEvaluator.java:141)
        at com.github.danfickle.cpptojavasourceconverter.StmtEvaluator.evalStmt(
StmtEvaluator.java:123)
        at com.github.danfickle.cpptojavasourceconverter.StmtEvaluator.eval1Stmt
(StmtEvaluator.java:25)
        at com.github.danfickle.cpptojavasourceconverter.FunctionManager.evalFun
ction(FunctionManager.java:162)
        at com.github.danfickle.cpptojavasourceconverter.SourceConverter.evalDec
laration(SourceConverter.java:299)
        at com.github.danfickle.cpptojavasourceconverter.Traverser.traverse(Trav
erser.java:50)
        at com.github.danfickle.cpptojavasourceconverter.Main.main(Main.java:37)

In: D:\home\daniel\workspace\cpp-to-java-source-converter\tests\test-operator-ov
erloading.cpp
Failure to determine type of expression
In: D:\home\daniel\workspace\cpp-to-java-source-converter\tests\test-operator-ov
erloading.cpp
Failure to determine type of expression
In: D:\home\daniel\workspace\cpp-to-java-source-converter\tests\test-operator-ov
erloading.cpp
Failure to determine type of expression
In: D:\home\daniel\workspace\cpp-to-java-source-converter\tests\test-operator-ov
erloading.cpp
Failure to determine type of expression
In: D:\home\daniel\workspace\cpp-to-java-source-converter\tests\test-operator-ov
erloading.cpp
Failure to determine type of expression
In: D:\home\daniel\workspace\cpp-to-java-source-converter\tests\test-operator-ov
erloading.cpp
Failure to determine type of expression
In: D:\home\daniel\workspace\cpp-to-java-source-converter\tests\test-operator-ov
erloading.cpp
Failure to determine type of expression
In: D:\home\daniel\workspace\cpp-to-java-source-converter\tests\test-operator-ov
erloading.cpp
Failure to determine type of expression
In: D:\home\daniel\workspace\cpp-to-java-source-converter\tests\test-operator-ov
erloading.cpp
Failure to determine type of expression
In: D:\home\daniel\workspace\cpp-to-java-source-converter\tests\test-operator-ov
erloading.cpp
Failure to determine type of expression
In: D:\home\daniel\workspace\cpp-to-java-source-converter\tests\test-operator-ov
erloading.cpp
Failure to determine type of expression
In: D:\home\daniel\workspace\cpp-to-java-source-converter\tests\test-operator-ov
erloading.cpp
Failure to determine type of expression
In: D:\home\daniel\workspace\cpp-to-java-source-converter\tests\test-operator-ov
erloading.cpp
Failure to determine type of expression
In: D:\home\daniel\workspace\cpp-to-java-source-converter\tests\test-operator-ov
erloading.cpp
Failure to determine type of expression
In: D:\home\daniel\workspace\cpp-to-java-source-converter\tests\test-operator-ov
erloading.cpp
org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassType cannot be cast to org.
eclipse.cdt.core.dom.ast.cpp.ICPPConstructor
java.lang.ClassCastException: org.eclipse.cdt.internal.core.dom.parser.cpp.CPPCl
assType cannot be cast to org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor
        at com.github.danfickle.cpptojavasourceconverter.ExpressionEvaluator.eva
lExprNew(ExpressionEvaluator.java:162)
        at com.github.danfickle.cpptojavasourceconverter.ExpressionEvaluator.eva
l1Expr(ExpressionEvaluator.java:67)
        at com.github.danfickle.cpptojavasourceconverter.InitializationManager.e
val1Init(InitializationManager.java:76)
        at com.github.danfickle.cpptojavasourceconverter.SourceConverter.evaluat
eDeclarationReturnInitializers(SourceConverter.java:282)
        at com.github.danfickle.cpptojavasourceconverter.StmtEvaluator.evalStmt(
StmtEvaluator.java:141)
        at com.github.danfickle.cpptojavasourceconverter.StmtEvaluator.evalStmt(
StmtEvaluator.java:123)
        at com.github.danfickle.cpptojavasourceconverter.StmtEvaluator.eval1Stmt
(StmtEvaluator.java:25)
        at com.github.danfickle.cpptojavasourceconverter.FunctionManager.evalFun
ction(FunctionManager.java:162)
        at com.github.danfickle.cpptojavasourceconverter.SourceConverter.evalDec
laration(SourceConverter.java:299)
        at com.github.danfickle.cpptojavasourceconverter.Traverser.traverse(Trav
erser.java:50)
        at com.github.danfickle.cpptojavasourceconverter.Main.main(Main.java:37)

In: D:\home\daniel\workspace\cpp-to-java-source-converter\tests\test-expressions
.cpp
org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassType cannot be cast to org.
eclipse.cdt.core.dom.ast.cpp.ICPPConstructor
java.lang.ClassCastException: org.eclipse.cdt.internal.core.dom.parser.cpp.CPPCl
assType cannot be cast to org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor
        at com.github.danfickle.cpptojavasourceconverter.ExpressionEvaluator.eva
lExprNew(ExpressionEvaluator.java:143)
        at com.github.danfickle.cpptojavasourceconverter.ExpressionEvaluator.eva
l1Expr(ExpressionEvaluator.java:67)
        at com.github.danfickle.cpptojavasourceconverter.ExpressionEvaluator.eva
lExprBinary(ExpressionEvaluator.java:1158)
        at com.github.danfickle.cpptojavasourceconverter.ExpressionEvaluator.eva
l1Expr(ExpressionEvaluator.java:59)
        at com.github.danfickle.cpptojavasourceconverter.StmtEvaluator.evalStmt(
StmtEvaluator.java:177)
        at com.github.danfickle.cpptojavasourceconverter.StmtEvaluator.evalStmt(
StmtEvaluator.java:123)
        at com.github.danfickle.cpptojavasourceconverter.StmtEvaluator.eval1Stmt
(StmtEvaluator.java:25)
        at com.github.danfickle.cpptojavasourceconverter.FunctionManager.evalFun
ction(FunctionManager.java:162)
        at com.github.danfickle.cpptojavasourceconverter.SourceConverter.evalDec
laration(SourceConverter.java:299)
        at com.github.danfickle.cpptojavasourceconverter.SourceConverter.evalDec
lSpecifier(SourceConverter.java:668)
        at com.github.danfickle.cpptojavasourceconverter.SourceConverter.evalDec
laration(SourceConverter.java:313)
        at com.github.danfickle.cpptojavasourceconverter.Traverser.traverse(Trav
erser.java:50)
        at com.github.danfickle.cpptojavasourceconverter.Main.main(Main.java:37)


D:\home\daniel\workspace\cpp-to-java-source-converter\target>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.