summary refs log tree commit diff stats
path: root/rod
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2011-01-16 16:22:23 +0100
committerAraq <rumpf_a@web.de>2011-01-16 16:22:23 +0100
commit0f743e01833290e2995756fbd459728b12d833be (patch)
tree57e2e0b3315ba838cf3d616030fd3238a2f71946 /rod
parent07b784373b1701d962f3e089e648838f96ac8947 (diff)
downloadNim-0f743e01833290e2995756fbd459728b12d833be.tar.gz
explicit indices in array literals
Diffstat (limited to 'rod')
-rwxr-xr-xrod/msgs.nim2
-rwxr-xr-xrod/semexprs.nim22
2 files changed, 22 insertions, 2 deletions
diff --git a/rod/msgs.nim b/rod/msgs.nim
index d6fde38b4..e34631c90 100755
--- a/rod/msgs.nim
+++ b/rod/msgs.nim
@@ -94,6 +94,7 @@ type
     errXCannotBeInParamDecl, errPragmaOnlyInHeaderOfProc, errImplOfXNotAllowed, 
     errImplOfXexpected, errNoSymbolToBorrowFromFound, errDiscardValue, 
     errInvalidDiscard, errIllegalConvFromXtoY, errCannotBindXTwice, 
+    errInvalidOrderInArrayConstructor,
     errInvalidOrderInEnumX, errEnumXHasWholes, errExceptExpected, errInvalidTry, 
     errOptionExpected, errXisNoLabel, errNotAllCasesCovered, 
     errUnkownSubstitionVar, errComplexStmtRequiresInd, errXisNotCallable, 
@@ -214,6 +215,7 @@ const
     "value returned by statement has to be discarded", 
     "statement returns no value that can be discarded", 
     "conversion from $1 to $2 is invalid", "cannot bind parameter \'$1\' twice", 
+    "invalid order in array constructor",
     "invalid order in enum \'$1\'", "enum \'$1\' has wholes", 
     "\'except\' or \'finally\' expected", 
     "after catch all \'except\' or \'finally\' no section may follow", 
diff --git a/rod/semexprs.nim b/rod/semexprs.nim
index 10ed6567e..e6cf097e5 100755
--- a/rod/semexprs.nim
+++ b/rod/semexprs.nim
@@ -260,11 +260,29 @@ proc semArrayConstr(c: PContext, n: PNode): PNode =
   if sonsLen(n) == 0: 
     addSon(result.typ, newTypeS(tyEmpty, c)) # needs an empty basetype!
   else: 
-    addSon(result, semExprWithType(c, n.sons[0]))
+    var x = n.sons[0]
+    var lastIndex: biggestInt = 0
+    var indexType = getSysType(tyInt)
+    if x.kind == nkExprColonExpr: 
+      var idx = semConstExpr(c, x.sons[0])
+      lastIndex = getOrdValue(idx)
+      indexType = idx.typ
+      x = x.sons[1]
+    
+    addSon(result, semExprWithType(c, x))
     var typ = skipTypes(result.sons[0].typ, {tyGenericInst, tyVar, tyOrdinal})
     for i in countup(1, sonsLen(n) - 1): 
-      n.sons[i] = semExprWithType(c, n.sons[i])
+      x = n.sons[i]
+      if x.kind == nkExprColonExpr:
+        var idx = semConstExpr(c, x.sons[0])
+        idx = fitNode(c, indexType, idx)
+        if lastIndex+1 != getOrdValue(idx):
+          liMessage(x.info, errInvalidOrderInArrayConstructor)
+        x = x.sons[1]
+      
+      n.sons[i] = semExprWithType(c, x)
       addSon(result, fitNode(c, typ, n.sons[i]))
+      inc(lastIndex)
     addSon(result.typ, typ)
   result.typ.sons[0] = makeRangeType(c, 0, sonsLen(result) - 1, n.info)