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 str
proc getLit*(str: string): string = proc getLit*(str: string): string =
# Used to convert #define literals into const
let let
str = str.replace(re"/[/*].*?(?:\*/)?$", "").strip() str = str.replace(re"/[/*].*?(?:\*/)?$", "").strip()
if str.contains(re"^[\-]?[\d]*[.]?[\d]+$") or if str.contains(re"^[\-]?[\d]*[.]?[\d]+$") or # decimal
str.contains(re"^0x[\da-fA-F]+$"): str.contains(re"^0x[\da-fA-F]+$") or # hexadecimal
str.contains(re"^'[[:ascii:]]'$") or # char
str.contains(re"""^"[[:ascii:]]+"$"""): # char *
return str return str
proc getNodeVal*(nimState: NimState, node: TSNode): string = proc getNodeVal*(nimState: NimState, node: TSNode): string =

View file

@ -9,6 +9,8 @@ extern "C" {
#define TEST_INT 512 #define TEST_INT 512
#define TEST_FLOAT 5.12 #define TEST_FLOAT 5.12
#define TEST_HEX 0x512 #define TEST_HEX 0x512
#define TEST_CHAR 'a'
#define TEST_STR "hello world"
#ifdef __APPLE__ #ifdef __APPLE__
#define OSDEF 10 #define OSDEF 10

View file

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

View file

@ -46,6 +46,8 @@ cImport cSearchPath "test.h"
check TEST_INT == 512 check TEST_INT == 512
check TEST_FLOAT == 5.12 check TEST_FLOAT == 5.12
check TEST_HEX == 0x512 check TEST_HEX == 0x512
check TEST_CHAR == 'a'
check TEST_STR == "hello world"
when defined(osx): when defined(osx):
check OSDEF == 10 check OSDEF == 10