summary refs log tree commit diff stats
path: root/rod/expandimportc.nim
diff options
context:
space:
mode:
authorrumpf_a@web.de <>2010-01-03 12:31:21 +0100
committerrumpf_a@web.de <>2010-01-03 12:31:21 +0100
commita58a2f3823c33104992dc0e4129fa53e66a18f44 (patch)
treeaf97f1c6634d7ef2d4468c70607c20731e6c1512 /rod/expandimportc.nim
parent2169fd63bdf9caf539ca7ca5b661ee703206500c (diff)
downloadNim-a58a2f3823c33104992dc0e4129fa53e66a18f44.tar.gz
better subscript overloading
Diffstat (limited to 'rod/expandimportc.nim')
-rwxr-xr-xrod/expandimportc.nim50
1 files changed, 24 insertions, 26 deletions
diff --git a/rod/expandimportc.nim b/rod/expandimportc.nim
index e7198237c..8df90aaa6 100755
--- a/rod/expandimportc.nim
+++ b/rod/expandimportc.nim
@@ -15,30 +15,30 @@ import
 
 proc modifyPragmas(n: PNode, name: string) =
   if n == nil: return
-  for i in countup(0, sonsLen(n) - 1): 
-    var it = n.sons[i]
+  for i in 0..len(n)-1: 
+    var it = n[i]
     if it.kind == nkIdent and whichKeyword(it.ident) == wImportc:
       var x = newNode(nkExprColonExpr)
-      addSon(x, it)
-      addSon(x, newStrNode(nkStrLit, name))
+      add(x, it)
+      add(x, newStrNode(nkStrLit, name))
       n.sons[i] = x
 
 proc getName(n: PNode): string = 
   case n.kind
-  of nkPostfix: result = getName(n.sons[1])
-  of nkPragmaExpr: result = getName(n.sons[0])
+  of nkPostfix: result = getName(n[1])
+  of nkPragmaExpr: result = getName(n[0])
   of nkSym: result = n.sym.name.s
   of nkIdent: result = n.ident.s
-  of nkAccQuoted: result = getName(n.sons[0])
+  of nkAccQuoted: result = getName(n[0])
   else: internalError(n.info, "getName()")
 
 proc processRoutine(n: PNode) =
-  var name = getName(n.sons[namePos])
-  modifyPragmas(n.sons[pragmasPos], name)
+  var name = getName(n[namePos])
+  modifyPragmas(n[pragmasPos], name)
   
 proc processIdent(ident, prefix: string, n: PNode): string =
   var pattern = sequence(capture(?(termIgnoreCase"T" / termIgnoreCase"P")),
-                         termIgnoreCase(prefix), capture(*any))
+                         termIgnoreCase(prefix), ?term('_'), capture(*any()))
   if ident =~ pattern:
     result = matches[0] & matches[1]
   else:
@@ -49,27 +49,25 @@ proc processTree(n: PNode, prefix: string) =
   case n.kind
   of nkEmpty..pred(nkIdent), succ(nkIdent)..nkNilLit: nil
   of nkIdent:
-    if prefix.len > 0:
-      n.ident = getIdent(processIdent(n.ident.s, prefix, n))
+    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)
+    for i in 0..sonsLen(n)-1: processTree(n[i], prefix)
   else:
-    for i in 0..sonsLen(n)-1: processTree(n.sons[i], prefix)
+    for i in 0..sonsLen(n)-1: processTree(n[i], prefix)
 
-proc main(infile, outfile, prefix: string) =
+proc main*(infile, outfile, prefix: string) =
   var module = ParseFile(infile)
   processTree(module, prefix)
   renderModule(module, outfile)
 
-if paramcount() >= 1:
-  var infile = addFileExt(paramStr(1), "nim")
-  var outfile = changeFileExt(infile, "new.nim")
-  if paramCount() >= 2:
-    outfile = addFileExt(paramStr(2), "new.nim")
-  var prefix = ""
-  if paramCount() >= 3:
-    prefix = paramStr(3)
-  main(infile, outfile, prefix)
-else:
-  echo "usage: expand_importc filename[.nim] outfilename[.nim] [prefix]"
+when isMainModule:
+  if paramcount() >= 1:
+    var infile = addFileExt(paramStr(1), "nim")
+    var outfile = changeFileExt(infile, "new.nim")
+    if paramCount() >= 2:
+      outfile = addFileExt(paramStr(2), "new.nim")
+    var prefix = if paramCount() >= 3: paramStr(3) else: ""
+    main(infile, outfile, prefix)
+  else:
+    echo "usage: expand_importc filename[.nim] outfilename[.nim] [prefix]"