From 7ef4bffa797623c608c15329717f0a9ee06a5d38 Mon Sep 17 00:00:00 2001 From: Ridho Pratama Date: Tue, 8 Oct 2019 16:12:24 +0700 Subject: [PATCH] renderer letAux fix only for octal literal (#12343) * renderer letAux fix only for octal literal * Handle when it's octal -1 for i64 * Added testcases --- compiler/renderer.nim | 13 +++--- nimdoc/testproject/expected/testproject.html | 47 ++++++++++++++++++++ nimdoc/testproject/expected/theindex.html | 16 +++++++ nimdoc/testproject/testproject.nim | 7 ++- 4 files changed, 77 insertions(+), 6 deletions(-) diff --git a/compiler/renderer.nim b/compiler/renderer.nim index a92ce999f..54090d844 100644 --- a/compiler/renderer.nim +++ b/compiler/renderer.nim @@ -314,6 +314,7 @@ proc litAux(g: TSrcGen; n: PNode, x: BiggestInt, size: int): string = while result != nil and result.kind in {tyGenericInst, tyRange, tyVar, tyLent, tyDistinct, tyOrdinal, tyAlias, tySink}: result = lastSon(result) + let typ = n.typ.skip if typ != nil and typ.kind in {tyBool, tyEnum}: if sfPure in typ.sym.flags: @@ -324,11 +325,13 @@ proc litAux(g: TSrcGen; n: PNode, x: BiggestInt, size: int): string = if e.sym.position == x: result &= e.sym.name.s return - - let y = x and ((1 shl (size*8)) - 1) - if nfBase2 in n.flags: result = "0b" & toBin(y, size * 8) - elif nfBase8 in n.flags: result = "0o" & toOct(y, size * 3) - elif nfBase16 in n.flags: result = "0x" & toHex(y, size * 2) + + if nfBase2 in n.flags: result = "0b" & toBin(x, size * 8) + elif nfBase8 in n.flags: + var y = if size < sizeof(BiggestInt): x and ((1 shl (size*8)) - 1) + else: x + result = "0o" & toOct(y, size * 3) + elif nfBase16 in n.flags: result = "0x" & toHex(x, size * 2) else: result = $x proc ulitAux(g: TSrcGen; n: PNode, x: BiggestInt, size: int): string = diff --git a/nimdoc/testproject/expected/testproject.html b/nimdoc/testproject/expected/testproject.html index 273defbbf..8c9082d7a 100644 --- a/nimdoc/testproject/expected/testproject.html +++ b/nimdoc/testproject/expected/testproject.html @@ -849,6 +849,20 @@ function main() { +
  • + Consts + +
  • Procs +
    C_A:
    +
    C_B:
    +
    C_C:
    +
    C_D:
    enumValueA:
    • SomeType.enumValueA
    • diff --git a/nimdoc/testproject/testproject.nim b/nimdoc/testproject/testproject.nim index c3ab6a153..d1fcf58cd 100644 --- a/nimdoc/testproject/testproject.nim +++ b/nimdoc/testproject/testproject.nim @@ -9,6 +9,11 @@ runnableExamples: # bug #11078 for x in "xx": discard +const + C_A* = 0x7FF0000000000000'f64 + C_B* = 0o377'i8 + C_C* = 0o277'i8 + C_D* = 0o177777'i16 template foo*(a, b: SomeType) = ## This does nothing @@ -31,7 +36,7 @@ import std/macros macro bar*(): untyped = result = newStmtList() -var aVariable*: array[1,int] +var aVariable*: array[1, int] aEnum() bEnum()