Fix #169 - header pragma omitted by default
This commit is contained in:
parent
d6e69dbf84
commit
4dd15aa7d7
6 changed files with 26 additions and 29 deletions
|
|
@ -178,7 +178,7 @@ proc printNim*(gState: State, fullpath: string, root: TSNode, astTable: AstTable
|
|||
nimState.impShort = nimState.currentHeader.replace("header", "imp")
|
||||
nimState.sourceFile = fullpath
|
||||
|
||||
if nimState.gState.dynlib.Bl:
|
||||
if nimState.gState.dynlib.Bl and nimState.gState.includeHeader:
|
||||
nimState.constStr &= &"\n {nimState.currentHeader} {{.used.}} = \"{fp}\""
|
||||
|
||||
root.searchAst(astTable, nimState)
|
||||
|
|
@ -191,7 +191,7 @@ proc printNim*(gState: State, fullpath: string, root: TSNode, astTable: AstTable
|
|||
necho &"const{nimState.constStr}\n"
|
||||
|
||||
necho &"""
|
||||
{{.pragma: {nimState.impShort}, importc{nimState.getHeader()}.}}
|
||||
{{.pragma: {nimState.impShort}, importc{nimState.getHeaderPragma()}.}}
|
||||
{{.pragma: {nimState.impShort}C, {nimState.impShort}, cdecl{nimState.getDynlib()}.}}
|
||||
"""
|
||||
|
||||
|
|
|
|||
|
|
@ -346,8 +346,7 @@ proc printLisp*(gState: State, root: TSNode): string =
|
|||
|
||||
while true:
|
||||
if not node.isNil() and depth > -1:
|
||||
if gState.pretty:
|
||||
result &= spaces(depth)
|
||||
result &= spaces(depth)
|
||||
let
|
||||
(line, col) = gState.getLineCol(node)
|
||||
result &= &"({$node.tsNodeType()} {line} {col} {node.tsNodeEndByte() - node.tsNodeStartByte()}"
|
||||
|
|
@ -359,15 +358,11 @@ proc printLisp*(gState: State, root: TSNode): string =
|
|||
break
|
||||
|
||||
if node.tsNodeNamedChildCount() != 0:
|
||||
if gState.pretty:
|
||||
result &= "\n"
|
||||
result &= "\n"
|
||||
nextnode = node.tsNodeNamedChild(0)
|
||||
depth += 1
|
||||
else:
|
||||
if gState.pretty:
|
||||
result &= ")\n"
|
||||
else:
|
||||
result &= ")"
|
||||
result &= ")\n"
|
||||
nextnode = node.tsNodeNextNamedSibling()
|
||||
|
||||
if nextnode.isNil():
|
||||
|
|
@ -376,10 +371,7 @@ proc printLisp*(gState: State, root: TSNode): string =
|
|||
depth -= 1
|
||||
if depth == -1:
|
||||
break
|
||||
if gState.pretty:
|
||||
result &= spaces(depth) & ")\n"
|
||||
else:
|
||||
result &= ")"
|
||||
result &= spaces(depth) & ")\n"
|
||||
if node == root:
|
||||
break
|
||||
if not node.tsNodeNextNamedSibling().isNil():
|
||||
|
|
@ -656,9 +648,9 @@ proc getSplitComma*(joined: seq[string]): seq[string] =
|
|||
for i in joined:
|
||||
result = result.concat(i.split(","))
|
||||
|
||||
proc getHeader*(nimState: NimState): string =
|
||||
proc getHeaderPragma*(nimState: NimState): string =
|
||||
result =
|
||||
if nimState.gState.dynlib.Bl:
|
||||
if nimState.gState.dynlib.Bl and nimState.gState.includeHeader:
|
||||
&", header: {nimState.currentHeader}"
|
||||
else:
|
||||
""
|
||||
|
|
@ -672,7 +664,7 @@ proc getDynlib*(nimState: NimState): string =
|
|||
|
||||
proc getImportC*(nimState: NimState, origName, nimName: string): string =
|
||||
if nimName != origName:
|
||||
result = &"importc: \"{origName}\"{nimState.getHeader()}"
|
||||
result = &"importc: \"{origName}\"{nimState.getHeaderPragma()}"
|
||||
else:
|
||||
result = nimState.impShort
|
||||
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ type
|
|||
State = ref object
|
||||
compile*, defines*, headers*, includeDirs*, searchDirs*, prefix*, suffix*, symOverride*: seq[string]
|
||||
|
||||
nocache*, nocomments*, debug*, past*, preprocess*, pnim*, pretty*, recurse*: bool
|
||||
debug*, includeHeader*, nocache*, nocomments*, past*, preprocess*, pnim*, recurse*: bool
|
||||
|
||||
code*, dynlib*, mode*, nim*, overrides*, pluginSource*, pluginSourcePath*: string
|
||||
|
||||
|
|
|
|||
|
|
@ -200,7 +200,7 @@ proc initGrammar(): Grammar =
|
|||
nname = nimState.getIdentifier(name, nskType)
|
||||
i += 1
|
||||
|
||||
if nimState.gState.dynlib.Bl:
|
||||
if nimState.gState.dynlib.Bl and nimState.gState.includeHeader:
|
||||
pragmas.add nimState.getImportC(name, nname)
|
||||
|
||||
let
|
||||
|
|
@ -316,7 +316,7 @@ proc initGrammar(): Grammar =
|
|||
else:
|
||||
var
|
||||
pragmas: seq[string] = @[]
|
||||
if nimState.gState.dynlib.Bl:
|
||||
if nimState.gState.dynlib.Bl and nimState.gState.includeHeader:
|
||||
pragmas.add nimState.getImportC(prefix & name, nname)
|
||||
pragmas.add "bycopy"
|
||||
if union.nBl:
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@ proc main(
|
|||
defines: seq[string] = @[],
|
||||
dynlib: string = "",
|
||||
feature: seq[Feature] = @[],
|
||||
includeHeader = false,
|
||||
includeDirs: seq[string] = @[],
|
||||
mode = modeDefault,
|
||||
nim: string = "nim",
|
||||
|
|
@ -82,6 +83,7 @@ proc main(
|
|||
defines: defines,
|
||||
dynlib: dynlib,
|
||||
feature: feature,
|
||||
includeHeader: includeHeader,
|
||||
includeDirs: includeDirs,
|
||||
mode: mode,
|
||||
nim: nim,
|
||||
|
|
@ -91,7 +93,6 @@ proc main(
|
|||
pnim: pnim,
|
||||
prefix: prefix,
|
||||
preprocess: preprocess,
|
||||
pretty: true,
|
||||
recurse: recurse,
|
||||
suffix: suffix,
|
||||
symOverride: symOverride
|
||||
|
|
@ -190,8 +191,9 @@ when isMainModule:
|
|||
"check": "check generated wrapper with compiler",
|
||||
"debug": "enable debug output",
|
||||
"defines": "definitions to pass to preprocessor",
|
||||
"dynlib": "Import symbols from library in specified Nim string",
|
||||
"dynlib": "import symbols from library in specified Nim string",
|
||||
"feature": "flags to enable experimental features",
|
||||
"includeHeader": "add {.header.} pragma to wrapper",
|
||||
"includeDirs": "include directory to pass to preprocessor",
|
||||
"mode": "language parser: c or cpp",
|
||||
"nim": "use a particular Nim executable (default: $PATH/nim)",
|
||||
|
|
@ -199,14 +201,14 @@ when isMainModule:
|
|||
"output": "file to output content - default stdout",
|
||||
"past": "print AST output",
|
||||
"pgrammar": "print grammar",
|
||||
"pluginSourcePath": "Nim file to build and load as a plugin",
|
||||
"pluginSourcePath": "nim file to build and load as a plugin",
|
||||
"pnim": "print Nim output",
|
||||
"preprocess": "run preprocessor on header",
|
||||
"recurse": "process #include files",
|
||||
"source" : "C/C++ source/header",
|
||||
"prefix": "Strip prefix from identifiers",
|
||||
"prefix": "strip prefix from identifiers",
|
||||
"stub": "stub out undefined type references as objects",
|
||||
"suffix": "Strip suffix from identifiers",
|
||||
"suffix": "strip suffix from identifiers",
|
||||
"symOverride": "skip generating specified symbols"
|
||||
}, short = {
|
||||
"check": 'k',
|
||||
|
|
@ -214,6 +216,7 @@ when isMainModule:
|
|||
"defines": 'D',
|
||||
"dynlib": 'l',
|
||||
"feature": 'f',
|
||||
"includeHeader": 'H',
|
||||
"includeDirs": 'I',
|
||||
"nocomments": 'c',
|
||||
"output": 'o',
|
||||
|
|
|
|||
|
|
@ -4,11 +4,13 @@
|
|||
#define TEST_FLOAT 5.12
|
||||
#define TEST_HEX 0x512
|
||||
|
||||
int test_call_int();
|
||||
extern "C" {
|
||||
int test_call_int();
|
||||
|
||||
struct Foo{
|
||||
int bar;
|
||||
};
|
||||
struct Foo{
|
||||
int bar;
|
||||
};
|
||||
}
|
||||
|
||||
class Foo1{
|
||||
int bar1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue