Fix #75 - support char and char* #defines

This commit is contained in:
Ganesh Viswanathan 2019-12-21 12:20:33 -06:00
commit 3fcc3b9526
4 changed files with 14 additions and 2 deletions

View file

@ -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 =

View file

@ -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

View file

@ -8,6 +8,11 @@ const
static:
cDebug()
cSkipSymbol(@[
"PRIX8", "PRIX16", "PRIX32",
"PRIXLEAST8", "PRIXLEAST16", "PRIXLEAST32",
"PRIXFAST8"
])
when defined(envTest):
setDefines(@["lzmaStd"])

View file

@ -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