Added spliceHeader option to c2nim
parse a header file first, then the source. completing a c 'module'
This commit is contained in:
parent
1280c56f38
commit
0a0fec4a5c
1 changed files with 17 additions and 5 deletions
|
|
@ -34,25 +34,36 @@ Options:
|
||||||
--skipcomments do not copy comments
|
--skipcomments do not copy comments
|
||||||
--ignoreRValueRefs translate C++'s ``T&&`` to ``T`` instead ``of var T``
|
--ignoreRValueRefs translate C++'s ``T&&`` to ``T`` instead ``of var T``
|
||||||
--keepBodies keep C++'s method bodies
|
--keepBodies keep C++'s method bodies
|
||||||
|
--spliceHeader parse and emit header before source file
|
||||||
-v, --version write c2nim's version
|
-v, --version write c2nim's version
|
||||||
-h, --help show this help
|
-h, --help show this help
|
||||||
"""
|
"""
|
||||||
|
|
||||||
proc main(infile, outfile: string, options: PParserOptions) =
|
proc parse(infile: string, options: PParserOptions): PNode =
|
||||||
var start = getTime()
|
|
||||||
var stream = llStreamOpen(infile, fmRead)
|
var stream = llStreamOpen(infile, fmRead)
|
||||||
if stream == nil: rawMessage(errCannotOpenFile, infile)
|
if stream == nil: rawMessage(errCannotOpenFile, infile)
|
||||||
var p: TParser
|
var p: TParser
|
||||||
openParser(p, infile, stream, options)
|
openParser(p, infile, stream, options)
|
||||||
var module = parseUnit(p)
|
result = parseUnit(p)
|
||||||
closeParser(p)
|
closeParser(p)
|
||||||
renderModule(module, outfile)
|
|
||||||
|
proc main(infile, outfile: string, options: PParserOptions, spliceHeader: bool) =
|
||||||
|
var start = getTime()
|
||||||
|
if spliceHeader and infile[infile.len-2 .. infile.len] == ".c" and existsFile(infile[0 .. infile.len-2] & "h"):
|
||||||
|
var header_module = parse(infile[0 .. infile.len-2] & "h", options)
|
||||||
|
var source_module = parse(infile, options)
|
||||||
|
for n in source_module:
|
||||||
|
addson(header_module, n)
|
||||||
|
renderModule(header_module, outfile)
|
||||||
|
else:
|
||||||
|
renderModule(parse(infile, options), outfile)
|
||||||
rawMessage(hintSuccessX, [$gLinesCompiled, $(getTime() - start),
|
rawMessage(hintSuccessX, [$gLinesCompiled, $(getTime() - start),
|
||||||
formatSize(getTotalMem())])
|
formatSize(getTotalMem())])
|
||||||
|
|
||||||
var
|
var
|
||||||
infile = ""
|
infile = ""
|
||||||
outfile = ""
|
outfile = ""
|
||||||
|
spliceHeader = false
|
||||||
parserOptions = newParserOptions()
|
parserOptions = newParserOptions()
|
||||||
for kind, key, val in getopt():
|
for kind, key, val in getopt():
|
||||||
case kind
|
case kind
|
||||||
|
|
@ -66,6 +77,7 @@ for kind, key, val in getopt():
|
||||||
stdout.write(Version & "\n")
|
stdout.write(Version & "\n")
|
||||||
quit(0)
|
quit(0)
|
||||||
of "o", "out": outfile = val
|
of "o", "out": outfile = val
|
||||||
|
of "spliceheader": spliceHeader = true
|
||||||
else:
|
else:
|
||||||
if not parserOptions.setOption(key, val):
|
if not parserOptions.setOption(key, val):
|
||||||
stdout.writeln("[Error] unknown option: " & key)
|
stdout.writeln("[Error] unknown option: " & key)
|
||||||
|
|
@ -77,4 +89,4 @@ else:
|
||||||
if outfile.len == 0:
|
if outfile.len == 0:
|
||||||
outfile = changeFileExt(infile, "nim")
|
outfile = changeFileExt(infile, "nim")
|
||||||
infile = addFileExt(infile, "h")
|
infile = addFileExt(infile, "h")
|
||||||
main(infile, outfile, parserOptions)
|
main(infile, outfile, parserOptions, spliceHeader)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue