From 3fcc3b9526a8afe4c8caa75b15ad074dde6dc63c Mon Sep 17 00:00:00 2001 From: Ganesh Viswanathan Date: Sat, 21 Dec 2019 12:20:33 -0600 Subject: Fix #75 - support char and char* #defines --- nimterop/getters.nim | 7 +++++-- tests/include/test.h | 2 ++ tests/lzma.nim | 5 +++++ tests/tnimterop_c.nim | 2 ++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/nimterop/getters.nim b/nimterop/getters.nim index af3dfa2..4cf5653 100644 --- a/nimterop/getters.nim +++ b/nimterop/getters.nim @@ -203,11 +203,14 @@ proc getPtrType*(str: string): string = str proc getLit*(str: string): string = + # Used to convert #define literals into const let str = str.replace(re"/[/*].*?(?:\*/)?$", "").strip() - if str.contains(re"^[\-]?[\d]*[.]?[\d]+$") or - str.contains(re"^0x[\da-fA-F]+$"): + if str.contains(re"^[\-]?[\d]*[.]?[\d]+$") or # decimal + str.contains(re"^0x[\da-fA-F]+$") or # hexadecimal + str.contains(re"^'[[:ascii:]]'$") or # char + str.contains(re"""^"[[:ascii:]]+"$"""): # char * return str proc getNodeVal*(nimState: NimState, node: TSNode): string = diff --git a/tests/include/test.h b/tests/include/test.h index 667f384..b22e2d8 100644 --- a/tests/include/test.h +++ b/tests/include/test.h @@ -9,6 +9,8 @@ extern "C" { #define TEST_INT 512 #define TEST_FLOAT 5.12 #define TEST_HEX 0x512 +#define TEST_CHAR 'a' +#define TEST_STR "hello world" #ifdef __APPLE__ #define OSDEF 10 diff --git a/tests/lzma.nim b/tests/lzma.nim index 4f6c41a..1cc6aa0 100644 --- a/tests/lzma.nim +++ b/tests/lzma.nim @@ -8,6 +8,11 @@ const static: cDebug() + cSkipSymbol(@[ + "PRIX8", "PRIX16", "PRIX32", + "PRIXLEAST8", "PRIXLEAST16", "PRIXLEAST32", + "PRIXFAST8" + ]) when defined(envTest): setDefines(@["lzmaStd"]) diff --git a/tests/tnimterop_c.nim b/tests/tnimterop_c.nim index fb1505a..319c766 100644 --- a/tests/tnimterop_c.nim +++ b/tests/tnimterop_c.nim @@ -46,6 +46,8 @@ cImport cSearchPath "test.h" check TEST_INT == 512 check TEST_FLOAT == 5.12 check TEST_HEX == 0x512 +check TEST_CHAR == 'a' +check TEST_STR == "hello world" when defined(osx): check OSDEF == 10 -- cgit v1.2.3