Skip to content

Commit

Permalink
Cpp: Updated version of the Cpp generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
agdavydov81 committed Oct 11, 2023
1 parent 215930d commit 2b589da
Show file tree
Hide file tree
Showing 17 changed files with 834 additions and 443 deletions.
6 changes: 3 additions & 3 deletions java/dfp/src/main/java/com/epam/deltix/dfp/JavaImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ public static String fastToScientificString(final long value, final char decimal
}

if (partsCoefficient == 0)
return "0.000000000000000e+000";
return "0" + decimalMark + "000000000000000e+000";

int exponent = partsExponent - EXPONENT_BIAS;

Expand Down Expand Up @@ -942,7 +942,7 @@ public static StringBuilder fastScientificAppendToStringBuilder(final long value
}

if (partsCoefficient == 0)
return stringBuilder.append("0.000000000000000e+000");
return stringBuilder.append("0").append(decimalMark).append("000000000000000e+000");

int exponent = partsExponent - EXPONENT_BIAS;

Expand Down Expand Up @@ -1242,7 +1242,7 @@ public static Appendable fastScientificAppendToAppendable(final long value, fina
}

if (partsCoefficient == 0)
return appendable.append("0.000000000000000e+000");
return appendable.append("0").append(decimalMark).append("000000000000000e+000");

int exponent = partsExponent - EXPONENT_BIAS;

Expand Down
4 changes: 1 addition & 3 deletions java/nativeWrappers/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ task makeNativeWrappersDfp(dependsOn: compileJava, type: JavaExec) {
"$rootDir/native/NativeImpl.c",
"$rootDir/java/dfp/build/generated/sources/nativeWrappers/com/epam/deltix/dfp/NativeImpl.java",
"$rootDir/csharp/EPAM.Deltix.DFP/NativeImpl.cs",
"$rootDir/native/DecimalNative.h",
"$rootDir/native/DecimalNative.hpp"
"$rootDir/native"
]
onlyIf {
!file("$rootDir/native/DecimalNative.h").exists() ||
Expand All @@ -41,7 +40,6 @@ task makeNativeWrappersDfpMath(dependsOn: compileJava, type: JavaExec) {
"$rootDir/native/NativeMathImpl.c",
"$rootDir/java/dfp-math/build/generated/sources/nativeWrappers/com/epam/deltix/dfpmath/NativeMathImpl.java",
"$rootDir/csharp/EPAM.Deltix.DFPMath/NativeMathImpl.cs",
"",
""
]
onlyIf {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public ApiEntry(final String returnType, final String name, final String argumen
this.arguments = arguments;
}

@Override
public String toString() {
return returnType + ' ' + name + '(' + arguments + ')';
}

public static List<ApiEntry> collectApi(String body, final String apiPrefix) {
body = body
.replaceAll("\\b__declspec\\s*\\(\\s*dllexport\\s*\\)", "")
Expand All @@ -42,10 +47,15 @@ public static List<ApiEntry> collectApi(String body, final String apiPrefix) {
// https://stackoverflow.com/questions/17759004/how-to-match-string-within-parentheses-nested-in-java
"\\(([^()]*|\\(([^()]*|\\([^()]*\\))*\\))*\\)";

public static String getCppType(String type) {
type = type.replaceAll(gccAttributePattern, "")
.replaceAll("\\bconst\\b", "")
.replace("\\bextern\\b", "");
public static String getCppType(final String type) {
return getCppType(type, true);
}

public static String getCppType(String type, boolean replaceConst) {
type = type.replaceAll(gccAttributePattern, "");
if (replaceConst)
type = type.replaceAll("\\bconst\\b", "");
type = type.replace("\\bextern\\b", "");

return type.trim();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ public static void make(final String outputFile, final List<ApiEntry> api, final
nativeClassBody.append("\t\tinternal static readonly " + outputClass + "Obj impl = new " + outputClass + "Obj();\n");

for (final ApiEntry entry : api) {
writer.write("\n\t\t[DllImport(libName, CallingConvention = callType)]\n");
if (entry.name.startsWith(apiPrefix + "to_string_3") ||
entry.name.startsWith(apiPrefix + "to_scientific_string_3"))
continue;

writer.write("\n\t\t[DllImport(libName, CallingConvention = callType, CharSet = CharSet.Ansi)]\n");

final String csRetType = cppTypeToCs(entry.returnType);
writer.write("\t\tinternal static extern " + csRetType + " " + entry.name + "(");
Expand All @@ -72,8 +76,16 @@ public static void make(final String outputFile, final List<ApiEntry> api, final
final Matcher cppArgMatcher = cppArgRegEx.matcher(cppArg);
if (!cppArgMatcher.matches())
throw new RuntimeException("Can't parse c++ argument(=" + cppArg + ").");
csArgs.append("[In] ").append(cppTypeToCs(cppArgMatcher.group(1))).append(" ").append(cppArgMatcher.group(2).trim());
csCall.append(cppArgMatcher.group(2).trim());

final String csType = cppTypeToCs(cppArgMatcher.group(1));
final boolean isOutType = csType.startsWith("out ");

csArgs.append(isOutType ? "[Out] " : "[In] ")
.append(cppTypeToCs(cppArgMatcher.group(1)))
.append(" ")
.append(cppArgMatcher.group(2).trim());
csCall.append(isOutType ? "out " : "")
.append(cppArgMatcher.group(2).trim());
}
final String csArgsStr = csArgs.toString();
final String csCallStr = csCall.toString();
Expand Down Expand Up @@ -146,6 +158,14 @@ private static String cppTypeToCs(String type) {
return "double";
case "intBool":
return "bool";
case "char *":
case "char*":
return "string";
case "char":
return "char";
case "uint32 *":
case "uint32*":
return "out uint";
default:
throw new RuntimeException("Can't convert C++ type (='" + type + "') to Cs type.");
}
Expand Down
Loading

0 comments on commit 2b589da

Please sign in to comment.