prepare Nim codebase for upcoming parser changes

This commit is contained in:
Andreas Rumpf 2016-07-15 12:56:03 +02:00
commit 0834cd63d9
26 changed files with 46 additions and 46 deletions

View file

@ -1668,10 +1668,10 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
if optOverflowCheck notin p.options: unaryExpr(p, e, d, "($1 - 1)") if optOverflowCheck notin p.options: unaryExpr(p, e, d, "($1 - 1)")
else: unaryExpr(p, e, d, "#subInt($1, 1)") else: unaryExpr(p, e, d, "#subInt($1, 1)")
of mInc, mDec: of mInc, mDec:
const opr: array [mInc..mDec, string] = ["$1 += $2;$n", "$1 -= $2;$n"] const opr: array[mInc..mDec, string] = ["$1 += $2;$n", "$1 -= $2;$n"]
const fun64: array [mInc..mDec, string] = ["$# = #addInt64($#, $#);$n", const fun64: array[mInc..mDec, string] = ["$# = #addInt64($#, $#);$n",
"$# = #subInt64($#, $#);$n"] "$# = #subInt64($#, $#);$n"]
const fun: array [mInc..mDec, string] = ["$# = #addInt($#, $#);$n", const fun: array[mInc..mDec, string] = ["$# = #addInt($#, $#);$n",
"$# = #subInt($#, $#);$n"] "$# = #subInt($#, $#);$n"]
let underlying = skipTypes(e.sons[1].typ, {tyGenericInst, tyVar, tyRange}) let underlying = skipTypes(e.sons[1].typ, {tyGenericInst, tyVar, tyRange})
if optOverflowCheck notin p.options or underlying.kind in {tyUInt..tyUInt64}: if optOverflowCheck notin p.options or underlying.kind in {tyUInt..tyUInt64}:

View file

@ -21,7 +21,7 @@ proc toStrMaxPrecision*(f: BiggestFloat): string =
if f > 0.0: result = "INF" if f > 0.0: result = "INF"
else: result = "-INF" else: result = "-INF"
else: else:
var buf: array [0..80, char] var buf: array[0..80, char]
c_sprintf(buf, "%#.16e", f) c_sprintf(buf, "%#.16e", f)
result = $buf result = $buf

View file

@ -49,7 +49,7 @@ type
TMsgKind: MsgKind].} TMsgKind: MsgKind].}
const const
messages: array [MsgKind, string] = [ messages: array[MsgKind, string] = [
meCannotOpenFile: "cannot open '$1'", meCannotOpenFile: "cannot open '$1'",
meExpected: "'$1' expected", meExpected: "'$1' expected",
meGridTableNotImplemented: "grid table is not implemented", meGridTableNotImplemented: "grid table is not implemented",

View file

@ -110,7 +110,7 @@ type
## (not POSIX) ## (not POSIX)
when defined(linux) or defined(bsd): when defined(linux) or defined(bsd):
d_off*: Off ## Not an offset. Value that ``telldir()`` would return. d_off*: Off ## Not an offset. Value that ``telldir()`` would return.
d_name*: array [0..255, char] ## Name of entry. d_name*: array[0..255, char] ## Name of entry.
Tflock* {.importc: "struct flock", final, pure, Tflock* {.importc: "struct flock", final, pure,
header: "<fcntl.h>".} = object ## flock type header: "<fcntl.h>".} = object ## flock type
@ -242,7 +242,7 @@ type
## network to which this node is attached, if any. ## network to which this node is attached, if any.
release*, ## Current release level of this implementation. release*, ## Current release level of this implementation.
version*, ## Current version level of this release. version*, ## Current version level of this release.
machine*: array [0..255, char] ## Name of the hardware type on which the machine*: array[0..255, char] ## Name of the hardware type on which the
## system is running. ## system is running.
Sem* {.importc: "sem_t", header: "<semaphore.h>", final, pure.} = object Sem* {.importc: "sem_t", header: "<semaphore.h>", final, pure.} = object
@ -463,12 +463,12 @@ type
SockAddr* {.importc: "struct sockaddr", header: "<sys/socket.h>", SockAddr* {.importc: "struct sockaddr", header: "<sys/socket.h>",
pure, final.} = object ## struct sockaddr pure, final.} = object ## struct sockaddr
sa_family*: TSa_Family ## Address family. sa_family*: TSa_Family ## Address family.
sa_data*: array [0..255, char] ## Socket address (variable-length data). sa_data*: array[0..255, char] ## Socket address (variable-length data).
Sockaddr_un* {.importc: "struct sockaddr_un", header: "<sys/un.h>", Sockaddr_un* {.importc: "struct sockaddr_un", header: "<sys/un.h>",
pure, final.} = object ## struct sockaddr_un pure, final.} = object ## struct sockaddr_un
sun_family*: TSa_Family ## Address family. sun_family*: TSa_Family ## Address family.
sun_path*: array [0..Sockaddr_un_path_length-1, char] ## Socket path sun_path*: array[0..Sockaddr_un_path_length-1, char] ## Socket path
Sockaddr_storage* {.importc: "struct sockaddr_storage", Sockaddr_storage* {.importc: "struct sockaddr_storage",
header: "<sys/socket.h>", header: "<sys/socket.h>",
@ -526,7 +526,7 @@ type
In6Addr* {.importc: "struct in6_addr", pure, final, In6Addr* {.importc: "struct in6_addr", pure, final,
header: "<netinet/in.h>".} = object ## struct in6_addr header: "<netinet/in.h>".} = object ## struct in6_addr
s6_addr*: array [0..15, char] s6_addr*: array[0..15, char]
Sockaddr_in6* {.importc: "struct sockaddr_in6", pure, final, Sockaddr_in6* {.importc: "struct sockaddr_in6", pure, final,
header: "<netinet/in.h>".} = object ## struct sockaddr_in6 header: "<netinet/in.h>".} = object ## struct sockaddr_in6
@ -2653,7 +2653,7 @@ proc poll*(a1: ptr TPollfd, a2: Tnfds, a3: int): cint {.
proc realpath*(name, resolved: cstring): cstring {. proc realpath*(name, resolved: cstring): cstring {.
importc: "realpath", header: "<stdlib.h>".} importc: "realpath", header: "<stdlib.h>".}
proc utimes*(path: cstring, times: ptr array [2, Timeval]): int {. proc utimes*(path: cstring, times: ptr array[2, Timeval]): int {.
importc: "utimes", header: "<sys/time.h>".} importc: "utimes", header: "<sys/time.h>".}
## Sets file access and modification times. ## Sets file access and modification times.
## ##

View file

@ -18,7 +18,7 @@ type
RtArray*[T] = object ## RtArray*[T] = object ##
L: Natural L: Natural
spart: seq[T] spart: seq[T]
apart: array [ArrayPartSize, T] apart: array[ArrayPartSize, T]
UncheckedArray* {.unchecked.}[T] = array[0..100_000_000, T] UncheckedArray* {.unchecked.}[T] = array[0..100_000_000, T]
template usesSeqPart(x): expr = x.L > ArrayPartSize template usesSeqPart(x): expr = x.L > ArrayPartSize

View file

@ -126,7 +126,7 @@ type
TJsonParser: JsonParser, TTokKind: TokKind].} TJsonParser: JsonParser, TTokKind: TokKind].}
const const
errorMessages: array [JsonError, string] = [ errorMessages: array[JsonError, string] = [
"no error", "no error",
"invalid token", "invalid token",
"string expected", "string expected",
@ -139,7 +139,7 @@ const
"EOF expected", "EOF expected",
"expression expected" "expression expected"
] ]
tokToStr: array [TokKind, string] = [ tokToStr: array[TokKind, string] = [
"invalid token", "invalid token",
"EOF", "EOF",
"string literal", "string literal",

View file

@ -61,7 +61,7 @@ type
lvlNone ## no levels active lvlNone ## no levels active
const const
LevelNames*: array [Level, string] = [ LevelNames*: array[Level, string] = [
"DEBUG", "DEBUG", "INFO", "NOTICE", "WARN", "ERROR", "FATAL", "NONE" "DEBUG", "DEBUG", "INFO", "NOTICE", "WARN", "ERROR", "FATAL", "NONE"
] ]

View file

@ -27,7 +27,7 @@ const
tickCountCorrection = 50_000 tickCountCorrection = 50_000
when not declared(system.StackTrace): when not declared(system.StackTrace):
type StackTrace = array [0..20, cstring] type StackTrace = array[0..20, cstring]
{.deprecated: [TStackTrace: StackTrace].} {.deprecated: [TStackTrace: StackTrace].}
# We use a simple hash table of bounded size to keep track of the stack traces: # We use a simple hash table of bounded size to keep track of the stack traces:
@ -35,7 +35,7 @@ type
ProfileEntry = object ProfileEntry = object
total: int total: int
st: StackTrace st: StackTrace
ProfileData = array [0..64*1024-1, ptr ProfileEntry] ProfileData = array[0..64*1024-1, ptr ProfileEntry]
{.deprecated: [TProfileEntry: ProfileEntry, TProfileData: ProfileData].} {.deprecated: [TProfileEntry: ProfileEntry, TProfileData: ProfileData].}
proc `==`(a, b: StackTrace): bool = proc `==`(a, b: StackTrace): bool =

View file

@ -1122,7 +1122,7 @@ proc parseCmdLine*(c: string): seq[string] {.
while true: while true:
setLen(a, 0) setLen(a, 0)
# eat all delimiting whitespace # eat all delimiting whitespace
while c[i] == ' ' or c[i] == '\t' or c [i] == '\l' or c [i] == '\r' : inc(i) while c[i] == ' ' or c[i] == '\t' or c[i] == '\l' or c[i] == '\r' : inc(i)
when defined(windows): when defined(windows):
# parse a single argument according to the above rules: # parse a single argument according to the above rules:
if c[i] == '\0': break if c[i] == '\0': break

View file

@ -721,7 +721,7 @@ elif not defined(useNimRtl):
env: StringTableRef = nil, env: StringTableRef = nil,
options: set[ProcessOption] = {poStdErrToStdOut}): Process = options: set[ProcessOption] = {poStdErrToStdOut}): Process =
var var
pStdin, pStdout, pStderr: array [0..1, cint] pStdin, pStdout, pStderr: array[0..1, cint]
new(result) new(result)
result.options = options result.options = options
result.exitCode = -3 # for ``waitForExit`` result.exitCode = -3 # for ``waitForExit``

View file

@ -384,7 +384,7 @@ proc setForegroundColor*(f: File, fg: ForegroundColor, bright=false) =
var old = getAttributes(h) and not 0x0007 var old = getAttributes(h) and not 0x0007
if bright: if bright:
old = old or FOREGROUND_INTENSITY old = old or FOREGROUND_INTENSITY
const lookup: array [ForegroundColor, int] = [ const lookup: array[ForegroundColor, int] = [
0, 0,
(FOREGROUND_RED), (FOREGROUND_RED),
(FOREGROUND_GREEN), (FOREGROUND_GREEN),
@ -406,7 +406,7 @@ proc setBackgroundColor*(f: File, bg: BackgroundColor, bright=false) =
var old = getAttributes(h) and not 0x0070 var old = getAttributes(h) and not 0x0070
if bright: if bright:
old = old or BACKGROUND_INTENSITY old = old or BACKGROUND_INTENSITY
const lookup: array [BackgroundColor, int] = [ const lookup: array[BackgroundColor, int] = [
0, 0,
(BACKGROUND_RED), (BACKGROUND_RED),
(BACKGROUND_GREEN), (BACKGROUND_GREEN),

View file

@ -477,7 +477,7 @@ when not defined(JS):
# our own procs on top of that: # our own procs on top of that:
proc tmToTimeInfo(tm: StructTM, local: bool): TimeInfo = proc tmToTimeInfo(tm: StructTM, local: bool): TimeInfo =
const const
weekDays: array [0..6, WeekDay] = [ weekDays: array[0..6, WeekDay] = [
dSun, dMon, dTue, dWed, dThu, dFri, dSat] dSun, dMon, dTue, dWed, dThu, dFri, dSat]
when defined(freebsd) or defined(netbsd) or defined(openbsd): when defined(freebsd) or defined(netbsd) or defined(openbsd):
TimeInfo(second: int(tm.second), TimeInfo(second: int(tm.second),
@ -523,7 +523,7 @@ when not defined(JS):
proc timeInfoToTM(t: TimeInfo): StructTM = proc timeInfoToTM(t: TimeInfo): StructTM =
const const
weekDays: array [WeekDay, int8] = [1'i8,2'i8,3'i8,4'i8,5'i8,6'i8,0'i8] weekDays: array[WeekDay, int8] = [1'i8,2'i8,3'i8,4'i8,5'i8,6'i8,0'i8]
result.second = t.second result.second = t.second
result.minute = t.minute result.minute = t.minute
result.hour = t.hour result.hour = t.hour
@ -652,7 +652,7 @@ elif defined(JS):
return newDate() return newDate()
const const
weekDays: array [0..6, WeekDay] = [ weekDays: array[0..6, WeekDay] = [
dSun, dMon, dTue, dWed, dThu, dFri, dSat] dSun, dMon, dTue, dWed, dThu, dFri, dSat]
proc getLocalTime(t: Time): TimeInfo = proc getLocalTime(t: Time): TimeInfo =

View file

@ -1523,7 +1523,7 @@ type # these work for most platforms:
## This is the same as the type ``unsigned long long`` in *C*. ## This is the same as the type ``unsigned long long`` in *C*.
cstringArray* {.importc: "char**", nodecl.} = ptr cstringArray* {.importc: "char**", nodecl.} = ptr
array [0..ArrayDummySize, cstring] array[0..ArrayDummySize, cstring]
## This is binary compatible to the type ``char**`` in *C*. The array's ## This is binary compatible to the type ``char**`` in *C*. The array's
## high value is large enough to disable bounds checking in practice. ## high value is large enough to disable bounds checking in practice.
## Use `cstringArrayToSeq` to convert it into a ``seq[string]``. ## Use `cstringArrayToSeq` to convert it into a ``seq[string]``.

View file

@ -211,14 +211,14 @@ proc genericReset(dest: pointer, mt: PNimType) =
zeroMem(dest, mt.size) # set raw bits to zero zeroMem(dest, mt.size) # set raw bits to zero
proc selectBranch(discVal, L: int, proc selectBranch(discVal, L: int,
a: ptr array [0..0x7fff, ptr TNimNode]): ptr TNimNode = a: ptr array[0..0x7fff, ptr TNimNode]): ptr TNimNode =
result = a[L] # a[L] contains the ``else`` part (but may be nil) result = a[L] # a[L] contains the ``else`` part (but may be nil)
if discVal <% L: if discVal <% L:
var x = a[discVal] var x = a[discVal]
if x != nil: result = x if x != nil: result = x
proc FieldDiscriminantCheck(oldDiscVal, newDiscVal: int, proc FieldDiscriminantCheck(oldDiscVal, newDiscVal: int,
a: ptr array [0..0x7fff, ptr TNimNode], a: ptr array[0..0x7fff, ptr TNimNode],
L: int) {.compilerProc.} = L: int) {.compilerProc.} =
var oldBranch = selectBranch(oldDiscVal, L, a) var oldBranch = selectBranch(oldDiscVal, L, a)
var newBranch = selectBranch(newDiscVal, L, a) var newBranch = selectBranch(newDiscVal, L, a)

View file

@ -159,7 +159,7 @@ type
{.deprecated: [THash: Hash, TWatchpoint: Watchpoint].} {.deprecated: [THash: Hash, TWatchpoint: Watchpoint].}
var var
watchpoints: array [0..99, Watchpoint] watchpoints: array[0..99, Watchpoint]
watchpointsLen: int watchpointsLen: int
proc `!&`(h: Hash, val: int): Hash {.inline.} = proc `!&`(h: Hash, val: int): Hash {.inline.} =

View file

@ -475,7 +475,7 @@ proc dbgWriteStackTrace(f: PFrame) =
it = f it = f
i = 0 i = 0
total = 0 total = 0
tempFrames: array [0..127, PFrame] tempFrames: array[0..127, PFrame]
# setup long head: # setup long head:
while it != nil and i <= high(tempFrames)-firstCalls: while it != nil and i <= high(tempFrames)-firstCalls:
tempFrames[i] = it tempFrames[i] = it

View file

@ -90,13 +90,13 @@ when defined(nativeStacktrace) and nativeStackTraceSupported:
when not hasThreadSupport: when not hasThreadSupport:
var var
tempAddresses: array [0..127, pointer] # should not be alloc'd on stack tempAddresses: array[0..127, pointer] # should not be alloc'd on stack
tempDlInfo: TDl_info tempDlInfo: TDl_info
proc auxWriteStackTraceWithBacktrace(s: var string) = proc auxWriteStackTraceWithBacktrace(s: var string) =
when hasThreadSupport: when hasThreadSupport:
var var
tempAddresses: array [0..127, pointer] # but better than a threadvar tempAddresses: array[0..127, pointer] # but better than a threadvar
tempDlInfo: TDl_info tempDlInfo: TDl_info
# This is allowed to be expensive since it only happens during crashes # This is allowed to be expensive since it only happens during crashes
# (but this way you don't need manual stack tracing) # (but this way you don't need manual stack tracing)
@ -124,12 +124,12 @@ when defined(nativeStacktrace) and nativeStackTraceSupported:
when not hasThreadSupport: when not hasThreadSupport:
var var
tempFrames: array [0..127, PFrame] # should not be alloc'd on stack tempFrames: array[0..127, PFrame] # should not be alloc'd on stack
proc auxWriteStackTrace(f: PFrame, s: var string) = proc auxWriteStackTrace(f: PFrame, s: var string) =
when hasThreadSupport: when hasThreadSupport:
var var
tempFrames: array [0..127, PFrame] # but better than a threadvar tempFrames: array[0..127, PFrame] # but better than a threadvar
const const
firstCalls = 32 firstCalls = 32
var var
@ -250,7 +250,7 @@ proc raiseExceptionAux(e: ref Exception) =
inc L, slen inc L, slen
template add(buf, s: expr) = template add(buf, s: expr) =
xadd(buf, s, s.len) xadd(buf, s, s.len)
var buf: array [0..2000, char] var buf: array[0..2000, char]
var L = 0 var L = 0
add(buf, "Error: unhandled exception: ") add(buf, "Error: unhandled exception: ")
if not isNil(e.msg): add(buf, e.msg) if not isNil(e.msg): add(buf, e.msg)

View file

@ -239,7 +239,7 @@ else:
# We use a jmp_buf buffer that is in the C stack. # We use a jmp_buf buffer that is in the C stack.
# Used to traverse the stack and registers assuming # Used to traverse the stack and registers assuming
# that 'setjmp' will save registers in the C stack. # that 'setjmp' will save registers in the C stack.
type PStackSlice = ptr array [0..7, pointer] type PStackSlice = ptr array[0..7, pointer]
var registers {.noinit.}: Registers var registers {.noinit.}: Registers
getRegisters(registers) getRegisters(registers)
for i in registers.low .. registers.high: for i in registers.low .. registers.high:
@ -277,7 +277,7 @@ else:
# We use a jmp_buf buffer that is in the C stack. # We use a jmp_buf buffer that is in the C stack.
# Used to traverse the stack and registers assuming # Used to traverse the stack and registers assuming
# that 'setjmp' will save registers in the C stack. # that 'setjmp' will save registers in the C stack.
type PStackSlice = ptr array [0..7, pointer] type PStackSlice = ptr array[0..7, pointer]
var registers {.noinit.}: C_JmpBuf var registers {.noinit.}: C_JmpBuf
if c_setjmp(registers) == 0'i32: # To fill the C stack with registers. if c_setjmp(registers) == 0'i32: # To fill the C stack with registers.
var max = cast[ByteAddress](gch.stackBottom) var max = cast[ByteAddress](gch.stackBottom)

View file

@ -71,7 +71,7 @@ type
typ: ptr TNimType typ: ptr TNimType
name: cstring name: cstring
len: int len: int
sons: ptr array [0..0x7fff, ptr TNimNode] sons: ptr array[0..0x7fff, ptr TNimNode]
TNimTypeFlag = enum TNimTypeFlag = enum
ntfNoRefs = 0, # type contains no tyRef, tySequence, tyString ntfNoRefs = 0, # type contains no tyRef, tySequence, tyString

View file

@ -65,7 +65,7 @@ proc auxWriteStackTrace(f: PCallFrame): string =
it = f it = f
i = 0 i = 0
total = 0 total = 0
tempFrames: array [0..63, TempFrame] tempFrames: array[0..63, TempFrame]
while it != nil and i <= high(tempFrames): while it != nil and i <= high(tempFrames):
tempFrames[i].procname = it.procname tempFrames[i].procname = it.procname
tempFrames[i].line = it.line tempFrames[i].line = it.line

View file

@ -19,7 +19,7 @@ const
MaxTraceLen = 20 # tracking the last 20 calls is enough MaxTraceLen = 20 # tracking the last 20 calls is enough
type type
StackTrace* = array [0..MaxTraceLen-1, cstring] StackTrace* = array[0..MaxTraceLen-1, cstring]
ProfilerHook* = proc (st: StackTrace) {.nimcall.} ProfilerHook* = proc (st: StackTrace) {.nimcall.}
{.deprecated: [TStackTrace: StackTrace, TProfilerHook: ProfilerHook].} {.deprecated: [TStackTrace: StackTrace, TProfilerHook: ProfilerHook].}

View file

@ -16,7 +16,7 @@ proc reprInt(x: int64): string {.compilerproc.} = return $x
proc reprFloat(x: float): string {.compilerproc.} = return $x proc reprFloat(x: float): string {.compilerproc.} = return $x
proc reprPointer(x: pointer): string {.compilerproc.} = proc reprPointer(x: pointer): string {.compilerproc.} =
var buf: array [0..59, char] var buf: array[0..59, char]
discard c_sprintf(buf, "%p", x) discard c_sprintf(buf, "%p", x)
return $buf return $buf
@ -24,7 +24,7 @@ proc `$`(x: uint64): string =
if x == 0: if x == 0:
result = "0" result = "0"
else: else:
var buf: array [60, char] var buf: array[60, char]
var i = 0 var i = 0
var n = x var n = x
while n != 0: while n != 0:

View file

@ -10,7 +10,7 @@
# set handling # set handling
type type
NimSet = array [0..4*2048-1, uint8] NimSet = array[0..4*2048-1, uint8]
{.deprecated: [TNimSet: NimSet].} {.deprecated: [TNimSet: NimSet].}
proc countBits32(n: int32): int {.compilerproc.} = proc countBits32(n: int32): int {.compilerproc.} =

View file

@ -271,7 +271,7 @@ else:
importc: "freopen", nodecl.} importc: "freopen", nodecl.}
const const
FormatOpen: array [FileMode, string] = ["rb", "wb", "w+b", "r+b", "ab"] FormatOpen: array[FileMode, string] = ["rb", "wb", "w+b", "r+b", "ab"]
#"rt", "wt", "w+t", "r+t", "at" #"rt", "wt", "w+t", "r+t", "at"
# we always use binary here as for Nim the OS line ending # we always use binary here as for Nim the OS line ending
# should not be translated. # should not be translated.

View file

@ -24,7 +24,7 @@
## import locks ## import locks
## ##
## var ## var
## thr: array [0..4, Thread[tuple[a,b: int]]] ## thr: array[0..4, Thread[tuple[a,b: int]]]
## L: Lock ## L: Lock
## ##
## proc threadFunc(interval: tuple[a,b: int]) {.thread.} = ## proc threadFunc(interval: tuple[a,b: int]) {.thread.} =
@ -198,7 +198,7 @@ when emulatedThreadVars:
# allocations are needed. Currently less than 7K are used on a 64bit machine. # allocations are needed. Currently less than 7K are used on a 64bit machine.
# We use ``float`` for proper alignment: # We use ``float`` for proper alignment:
type type
ThreadLocalStorage = array [0..1_000, float] ThreadLocalStorage = array[0..1_000, float]
PGcThread = ptr GcThread PGcThread = ptr GcThread
GcThread {.pure, inheritable.} = object GcThread {.pure, inheritable.} = object

View file

@ -750,7 +750,7 @@ type
D1*: int32 D1*: int32
D2*: int16 D2*: int16
D3*: int16 D3*: int16
D4*: array [0..7, int8] D4*: array[0..7, int8]
{.deprecated: [TOVERLAPPED: OVERLAPPED, TGUID: GUID].} {.deprecated: [TOVERLAPPED: OVERLAPPED, TGUID: GUID].}
const const