aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGanesh Viswanathan <dev@genotrance.com>2020-05-01 15:07:51 -0500
committerGanesh Viswanathan <dev@genotrance.com>2020-05-01 15:07:51 -0500
commit748998b0bd921a60f1c05aae7b47eb8de51b7e3e (patch)
treefa86e638cb5318cabe6952d8c162a39728a5b4e0
parent568cfc5da6e541101294b956670dddd509dadc2a (diff)
downloadnimterop-748998b0bd921a60f1c05aae7b47eb8de51b7e3e.tar.gz
nimterop-748998b0bd921a60f1c05aae7b47eb8de51b7e3e.zip
Fixes and test lzma/zlib with ast2
-rw-r--r--nimterop/ast2.nim6
-rw-r--r--nimterop/getters.nim156
-rw-r--r--tests/getheader.nims2
-rw-r--r--tests/lzma.nim8
-rw-r--r--tests/tsoloud.nim3
-rw-r--r--tests/zlib.nim6
6 files changed, 96 insertions, 85 deletions
diff --git a/nimterop/ast2.nim b/nimterop/ast2.nim
index 3ffa3f6..4d609cb 100644
--- a/nimterop/ast2.nim
+++ b/nimterop/ast2.nim
@@ -283,7 +283,9 @@ proc newXIdent(gState: State, node: TSNode, kind = nskType, fname = "", pragmas:
if name.Bl:
# Name skipped or overridden since blank
result = gState.getOverrideOrSkip(node, origname, kind)
- elif origname notin gTypeMap and gState.addNewIdentifer(name):
+ elif name notin gTypeMapValues and gState.addNewIdentifer(name):
+ # Add only if not an existing Nim type
+
if kind == nskType:
# type name* =
#
@@ -1399,7 +1401,7 @@ proc addEnum(gState: State, node: TSNode) =
continue
let
fname = gState.getIdentifier(gState.getNodeVal(en.getAtom()), nskEnumField)
- if fname.nBl:
+ if fname.nBl and gState.addNewIdentifer(fname):
var
fval = ""
if prev.Bl:
diff --git a/nimterop/getters.nim b/nimterop/getters.nim
index 69628f5..d94fae8 100644
--- a/nimterop/getters.nim
+++ b/nimterop/getters.nim
@@ -30,82 +30,86 @@ yield""".split(Whitespace).toHashSet()
# Types related
-const gTypeMap* = {
- # char
- "char": "cchar",
- "signed char": "cschar",
- "unsigned char": "cuchar",
-
- # short
- "short": "cshort",
- "short int": "cshort",
- "signed short": "cshort",
- "signed short int": "cshort",
- "unsigned short": "cushort",
- "unsigned short int": "cushort",
- "uShort": "cushort",
- "u_short": "cushort",
-
- # int
- "int": "cint",
- "signed": "cint",
- "signed int": "cint",
- "ssize_t": "int",
- "unsigned": "cuint",
- "unsigned int": "cuint",
- "uInt": "cuint",
- "u_int": "cuint",
- "size_t": "uint",
-
- "int8_t": "int8",
- "int16_t": "int16",
- "int32_t": "int32",
- "int64_t": "int64",
-
- "intptr_t": "ptr int",
-
- "Int8": "int8",
- "Int16": "int16",
- "Int32": "int32",
- "Int64": "int64",
-
- "uint8_t": "uint8",
- "uint16_t": "uint16",
- "uint32_t": "uint32",
- "uint64_t": "uint64",
-
- "uintptr_t": "ptr uint",
-
- "Uint8": "uint8",
- "Uint16": "uint16",
- "Uint32": "uint32",
- "Uint64": "uint64",
-
- # long
- "long": "clong",
- "long int": "clong",
- "signed long": "clong",
- "signed long int": "clong",
- "off_t": "clong",
- "unsigned long": "culong",
- "unsigned long int": "culong",
- "uLong": "culong",
- "u_long": "culong",
-
- # long long
- "long long": "clonglong",
- "long long int": "clonglong",
- "signed long long": "clonglong",
- "signed long long int": "clonglong",
- "off64_t": "clonglong",
- "unsigned long long": "culonglong",
- "unsigned long long int": "culonglong",
-
- # floating point
- "float": "cfloat",
- "double": "cdouble",
- "long double": "clongdouble"
-}.toTable()
+const
+ gTypeMap* = {
+ # char
+ "char": "cchar",
+ "signed char": "cschar",
+ "unsigned char": "cuchar",
+
+ # short
+ "short": "cshort",
+ "short int": "cshort",
+ "signed short": "cshort",
+ "signed short int": "cshort",
+ "unsigned short": "cushort",
+ "unsigned short int": "cushort",
+ "uShort": "cushort",
+ "u_short": "cushort",
+
+ # int
+ "int": "cint",
+ "signed": "cint",
+ "signed int": "cint",
+ "ssize_t": "int",
+ "unsigned": "cuint",
+ "unsigned int": "cuint",
+ "uInt": "cuint",
+ "u_int": "cuint",
+ "size_t": "uint",
+
+ "int8_t": "int8",
+ "int16_t": "int16",
+ "int32_t": "int32",
+ "int64_t": "int64",
+
+ "intptr_t": "ptr int",
+
+ "Int8": "int8",
+ "Int16": "int16",
+ "Int32": "int32",
+ "Int64": "int64",
+
+ "uint8_t": "uint8",
+ "uint16_t": "uint16",
+ "uint32_t": "uint32",
+ "uint64_t": "uint64",
+
+ "uintptr_t": "ptr uint",
+
+ "Uint8": "uint8",
+ "Uint16": "uint16",
+ "Uint32": "uint32",
+ "Uint64": "uint64",
+
+ # long
+ "long": "clong",
+ "long int": "clong",
+ "signed long": "clong",
+ "signed long int": "clong",
+ "off_t": "clong",
+ "unsigned long": "culong",
+ "unsigned long int": "culong",
+ "uLong": "culong",
+ "u_long": "culong",
+
+ # long long
+ "long long": "clonglong",
+ "long long int": "clonglong",
+ "signed long long": "clonglong",
+ "signed long long int": "clonglong",
+ "off64_t": "clonglong",
+ "unsigned long long": "culonglong",
+ "unsigned long long int": "culonglong",
+
+ # floating point
+ "float": "cfloat",
+ "double": "cdouble",
+ "long double": "clongdouble"
+ }.toTable()
+
+ # Nim type names that shouldn't need to be wrapped again
+ gTypeMapValues* = toSeq(gTypeMap.values).toHashSet()
proc getType*(str: string): string =
if str == "void":
diff --git a/tests/getheader.nims b/tests/getheader.nims
index 1e8027a..987545a 100644
--- a/tests/getheader.nims
+++ b/tests/getheader.nims
@@ -14,7 +14,7 @@ proc testCall(cmd, output: string, exitCode: int, delete = true) =
doAssert outp.contains(output), outp
var
- cmd = "nim c -f --hints:off"
+ cmd = "nim c -f --hints:off -d:FLAGS=\"-f:ast2\""
lrcmd = " -r lzma.nim"
zrcmd = " -r zlib.nim"
lexp = "liblzma version = "
diff --git a/tests/lzma.nim b/tests/lzma.nim
index f30b974..cff39de 100644
--- a/tests/lzma.nim
+++ b/tests/lzma.nim
@@ -3,8 +3,10 @@ import os, strutils
import nimterop/[build, cimport]
const
+ FLAGS {.strdefine.} = ""
+
baseDir = getProjectCacheDir("nimterop" / "tests" / "liblzma")
- flags = "--prefix=___,__,_ --suffix=__,_"
+ tflags = "--prefix=___,__,_ --suffix=__,_ " & FLAGS
static:
cSkipSymbol(@[
@@ -38,8 +40,8 @@ cOverride:
lzma_index_iter = object
when not lzmaStatic:
- cImport(lzmaPath, recurse = true, dynlib = "lzmaLPath", flags = flags)
+ cImport(lzmaPath, recurse = true, dynlib = "lzmaLPath", flags = tflags)
else:
- cImport(lzmaPath, recurse = true, flags = flags)
+ cImport(lzmaPath, recurse = true, flags = tflags)
echo "liblzma version = " & $lzma_version_string()
diff --git a/tests/tsoloud.nim b/tests/tsoloud.nim
index 8dd197c..4d9a28b 100644
--- a/tests/tsoloud.nim
+++ b/tests/tsoloud.nim
@@ -1,6 +1,8 @@
import os, nimterop/[cimport, build]
const
+ FLAGS {.strdefine.} = ""
+
baseDir = getProjectCacheDir("nimterop" / "tests" / "soloud")
incl = baseDir/"include"
src = baseDir/"src"
@@ -42,7 +44,6 @@ cCompile(src/"audiosource", "cpp", exclude="ay/")
cCompile(src/"audiosource", "c")
cCompile(src/"filter/*.cpp")
-const FLAGS {.strdefine.} = ""
cImport(incl/"soloud_c.h", flags = FLAGS)
var
diff --git a/tests/zlib.nim b/tests/zlib.nim
index febc6b1..852dca9 100644
--- a/tests/zlib.nim
+++ b/tests/zlib.nim
@@ -3,6 +3,8 @@ import os, strutils
import nimterop/[build, cimport]
const
+ FLAGS {.strdefine.} = ""
+
baseDir = getProjectCacheDir("nimterop" / "tests" / "zlib")
proc zlibPreBuild(outdir, path: string) =
@@ -64,8 +66,8 @@ when zlibGit or zlibDL:
cIncludeDir(baseDir / "buildcache")
when not zlibStatic:
- cImport(zlibPath, recurse = true, dynlib = "zlibLPath")
+ cImport(zlibPath, recurse = true, dynlib = "zlibLPath", flags = FLAGS)
else:
- cImport(zlibPath, recurse = true)
+ cImport(zlibPath, recurse = true, flags = FLAGS)
echo "zlib version = " & $zlibVersion()