summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2012-07-19 17:38:52 +0200
committerAraq <rumpf_a@web.de>2012-07-19 17:38:52 +0200
commit39235e21f543b2b9bc556fbaaed03232622a1b61 (patch)
tree1c56191642b61e960e0e7263d0c47004454f24aa /compiler
parent98fd408adc1035fbd4ac8256f4c87acf5a9c62ae (diff)
downloadNim-39235e21f543b2b9bc556fbaaed03232622a1b61.tar.gz
bugfixes for the symbol mangling; implements #129
Diffstat (limited to 'compiler')
-rwxr-xr-xcompiler/ccgtypes.nim24
-rwxr-xr-xcompiler/parser.nim16
-rwxr-xr-xcompiler/semstmts.nim9
3 files changed, 37 insertions, 12 deletions
diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim
index 0de731598..7416f1122 100755
--- a/compiler/ccgtypes.nim
+++ b/compiler/ccgtypes.nim
@@ -12,15 +12,17 @@
 # ------------------------- Name Mangling --------------------------------
 
 proc mangle(name: string): string = 
-  case name[0]
-  of 'a'..'z': 
-    result = ""
-    add(result, chr(ord(name[0]) - ord('a') + ord('A')))
-  of '0'..'9', 'A'..'Z': 
-    result = ""
-    add(result, name[0])
-  else: result = "HEX" & toHex(ord(name[0]), 2)
-  for i in countup(0 + 1, len(name) + 0 - 1): 
+  when false:
+    case name[0]
+    of 'a'..'z': 
+      result = ""
+      add(result, chr(ord(name[0]) - ord('a') + ord('A')))
+    of '0'..'9', 'A'..'Z': 
+      result = ""
+      add(result, name[0])
+    else: result = "HEX" & toHex(ord(name[0]), 2)
+  result = ""
+  for i in countup(0, len(name) - 1): 
     case name[i]
     of 'A'..'Z': 
       add(result, chr(ord(name[i]) - ord('A') + ord('a')))
@@ -103,7 +105,7 @@ proc mangleName(s: PSym): PRope =
       # These are not properly scoped now - we need to add blocks
       # around for loops in transf
       if keepOrigName:
-        result = s.name.s.toRope
+        result = s.name.s.mangle.toRope
       else:
         app(result, toRope(mangle(s.name.s)))
         app(result, "_")
@@ -120,7 +122,7 @@ proc isCompileTimeOnly(t: PType): bool =
 var anonTypeName = toRope"TY"
 
 proc typeName(typ: PType): PRope =
-  result = if typ.sym != nil: typ.sym.name.s.toRope
+  result = if typ.sym != nil: typ.sym.name.s.mangle.toRope
            else: anonTypeName
 
 proc getTypeName(typ: PType): PRope = 
diff --git a/compiler/parser.nim b/compiler/parser.nim
index 835a48fcc..3d8fc1f7c 100755
--- a/compiler/parser.nim
+++ b/compiler/parser.nim
@@ -1390,6 +1390,18 @@ proc parseDistinct(p: var TParser): PNode =
   optInd(p, result)
   addSon(result, parseTypeDesc(p))
 
+proc parsePointerInTypeSection(p: var TParser, kind: TNodeKind): PNode =
+  result = newNodeP(kind, p)
+  getTok(p)
+  optInd(p, result)
+  if not isOperator(p.tok):
+    case p.tok.tokType
+    of tkObject: addSon(result, parseObject(p))
+    of tkTuple: addSon(result, parseTuple(p, true))
+    else:
+      if isExprStart(p):
+        addSon(result, parseTypeDesc(p))
+
 proc parseTypeDef(p: var TParser): PNode = 
   result = newNodeP(nkTypeDef, p)
   addSon(result, identWithPragma(p))
@@ -1404,9 +1416,11 @@ proc parseTypeDef(p: var TParser): PNode =
     of tkEnum: a = parseEnum(p)
     of tkDistinct: a = parseDistinct(p)
     of tkTuple: a = parseTuple(p, true)
+    of tkRef: a = parsePointerInTypeSection(p, nkRefTy)
+    of tkPtr: a = parsePointerInTypeSection(p, nkPtrTy)
     else: a = parseTypeDesc(p)
     addSon(result, a)
-  else: 
+  else:
     addSon(result, ast.emptyNode)
   indAndComment(p, result)    # special extension!
   
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim
index 256d19db1..0c727b1a5 100755
--- a/compiler/semstmts.nim
+++ b/compiler/semstmts.nim
@@ -609,6 +609,15 @@ proc typeSectionFinalPass(c: PContext, n: PNode) =
           assignType(s.typ, t)
           s.typ.id = t.id     # same id
       checkConstructedType(s.info, s.typ)
+    let aa = a.sons[2]
+    if aa.kind in {nkRefTy, nkPtrTy} and aa.len == 1 and
+       aa.sons[0].kind == nkObjectTy:
+      # give anonymous object a dummy symbol:
+      assert s.typ.sons[0].sym == nil
+      var anonObj = newSym(skType, getIdent(s.name.s & ":ObjectType"), 
+                                 getCurrOwner())
+      anonObj.info = s.info
+      s.typ.sons[0].sym = anonObj
 
 proc SemTypeSection(c: PContext, n: PNode): PNode =
   typeSectionLeftSidePass(c, n)