diff options
Diffstat (limited to 'rod')
-rw-r--r-- | rod/ccgexprs.nim | 5 | ||||
-rwxr-xr-x | rod/expandimportc.nim | 34 | ||||
-rwxr-xr-x | rod/filters.nim | 29 | ||||
-rwxr-xr-x | rod/nimrod.ini | 2 |
4 files changed, 39 insertions, 31 deletions
diff --git a/rod/ccgexprs.nim b/rod/ccgexprs.nim index 62f8a267b..aa6ec2ed0 100644 --- a/rod/ccgexprs.nim +++ b/rod/ccgexprs.nim @@ -1774,13 +1774,11 @@ proc genConstSimpleList(p: BProc, n: PNode): PRope = app(result, '}' & tnl) proc genConstExpr(p: BProc, n: PNode): PRope = - var - cs: TBitSet - d: TLoc case n.Kind of nkHiddenStdConv, nkHiddenSubConv: result = genConstExpr(p, n.sons[1]) of nkCurly: + var cs: TBitSet toBitSet(n, cs) result = genRawSetData(cs, int(getSize(n.typ))) of nkBracket, nkPar: @@ -1788,5 +1786,6 @@ proc genConstExpr(p: BProc, n: PNode): PRope = result = genConstSimpleList(p, n) else: # result := genLiteral(p, n) + var d: TLoc initLocExpr(p, n, d) result = rdLoc(d) diff --git a/rod/expandimportc.nim b/rod/expandimportc.nim index 9613626f1..e7198237c 100755 --- a/rod/expandimportc.nim +++ b/rod/expandimportc.nim @@ -11,7 +11,7 @@ ## the diverse wrappers. import - os, ropes, idents, ast, pnimsyn, rnimsyn, msgs, wordrecg, syntaxes + os, ropes, idents, ast, pnimsyn, rnimsyn, msgs, wordrecg, syntaxes, pegs proc modifyPragmas(n: PNode, name: string) = if n == nil: return @@ -36,17 +36,30 @@ proc processRoutine(n: PNode) = var name = getName(n.sons[namePos]) modifyPragmas(n.sons[pragmasPos], name) -proc processTree(n: PNode) = +proc processIdent(ident, prefix: string, n: PNode): string = + var pattern = sequence(capture(?(termIgnoreCase"T" / termIgnoreCase"P")), + termIgnoreCase(prefix), capture(*any)) + if ident =~ pattern: + result = matches[0] & matches[1] + else: + result = ident + +proc processTree(n: PNode, prefix: string) = if n == nil: return case n.kind - of nkEmpty..nkNilLit: nil - of nkProcDef, nkConverterDef: processRoutine(n) + of nkEmpty..pred(nkIdent), succ(nkIdent)..nkNilLit: nil + of nkIdent: + if prefix.len > 0: + n.ident = getIdent(processIdent(n.ident.s, prefix, n)) + of nkProcDef, nkConverterDef: + processRoutine(n) + for i in 0..sonsLen(n)-1: processTree(n.sons[i], prefix) else: - for i in 0..sonsLen(n)-1: processTree(n.sons[i]) + for i in 0..sonsLen(n)-1: processTree(n.sons[i], prefix) -proc main(infile, outfile: string) = +proc main(infile, outfile, prefix: string) = var module = ParseFile(infile) - processTree(module) + processTree(module, prefix) renderModule(module, outfile) if paramcount() >= 1: @@ -54,6 +67,9 @@ if paramcount() >= 1: var outfile = changeFileExt(infile, "new.nim") if paramCount() >= 2: outfile = addFileExt(paramStr(2), "new.nim") - main(infile, outfile) + var prefix = "" + if paramCount() >= 3: + prefix = paramStr(3) + main(infile, outfile, prefix) else: - echo "usage: expand_importc filename[.nim] outfilename[.nim]" + echo "usage: expand_importc filename[.nim] outfilename[.nim] [prefix]" diff --git a/rod/filters.nim b/rod/filters.nim index 608c00d05..20db697bf 100755 --- a/rod/filters.nim +++ b/rod/filters.nim @@ -35,38 +35,32 @@ proc getArg(n: PNode, name: string, pos: int): PNode = return n.sons[i] proc charArg(n: PNode, name: string, pos: int, default: Char): Char = - var x: PNode - x = getArg(n, name, pos) + var x = getArg(n, name, pos) if x == nil: result = default elif x.kind == nkCharLit: result = chr(int(x.intVal)) else: invalidPragma(n) proc strArg(n: PNode, name: string, pos: int, default: string): string = - var x: PNode - x = getArg(n, name, pos) + var x = getArg(n, name, pos) if x == nil: result = default elif x.kind in {nkStrLit..nkTripleStrLit}: result = x.strVal else: invalidPragma(n) proc boolArg(n: PNode, name: string, pos: int, default: bool): bool = - var x: PNode - x = getArg(n, name, pos) + var x = getArg(n, name, pos) if x == nil: result = default elif (x.kind == nkIdent) and IdentEq(x.ident, "true"): result = true elif (x.kind == nkIdent) and IdentEq(x.ident, "false"): result = false else: invalidPragma(n) proc filterStrip(stdin: PLLStream, filename: string, call: PNode): PLLStream = - var - line, pattern, stripped: string - leading, trailing: bool - pattern = strArg(call, "startswith", 1, "") - leading = boolArg(call, "leading", 2, true) - trailing = boolArg(call, "trailing", 3, true) + var pattern = strArg(call, "startswith", 1, "") + var leading = boolArg(call, "leading", 2, true) + var trailing = boolArg(call, "trailing", 3, true) result = LLStreamOpen("") while not LLStreamAtEnd(stdin): - line = LLStreamReadLine(stdin) - stripped = strip(line, leading, trailing) + var line = LLStreamReadLine(stdin) + var stripped = strip(line, leading, trailing) if (len(pattern) == 0) or startsWith(stripped, pattern): LLStreamWriteln(result, stripped) else: @@ -74,12 +68,11 @@ proc filterStrip(stdin: PLLStream, filename: string, call: PNode): PLLStream = LLStreamClose(stdin) proc filterReplace(stdin: PLLStream, filename: string, call: PNode): PLLStream = - var line, sub, by: string - sub = strArg(call, "sub", 1, "") + var sub = strArg(call, "sub", 1, "") if len(sub) == 0: invalidPragma(call) - by = strArg(call, "by", 2, "") + var by = strArg(call, "by", 2, "") result = LLStreamOpen("") while not LLStreamAtEnd(stdin): - line = LLStreamReadLine(stdin) + var line = LLStreamReadLine(stdin) LLStreamWriteln(result, replace(line, sub, by)) LLStreamClose(stdin) diff --git a/rod/nimrod.ini b/rod/nimrod.ini index a09f8233a..98c520c63 100755 --- a/rod/nimrod.ini +++ b/rod/nimrod.ini @@ -30,7 +30,7 @@ Files: "doc/*.html" Files: "doc/*.cfg" [Other] -Files: "readme.txt;install.txt" +Files: "readme.txt;install.txt;contributors.txt" Files: "configure;makefile" Files: "*.html" Files: "*.ini" |