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