'addSon' for types deprecated for 'int literal type' analysis (3)
This commit is contained in:
parent
82b5e430cf
commit
049de0ef66
7 changed files with 55 additions and 56 deletions
|
|
@ -138,7 +138,7 @@ const
|
||||||
proc checkConvertible(info: TLineInfo, castDest, src: PType) =
|
proc checkConvertible(info: TLineInfo, castDest, src: PType) =
|
||||||
if sameType(castDest, src) and castDest.sym == src.sym:
|
if sameType(castDest, src) and castDest.sym == src.sym:
|
||||||
# don't annoy conversions that may be needed on another processor:
|
# don't annoy conversions that may be needed on another processor:
|
||||||
if castDest.kind notin {tyInt..tyUInt64, tyNil}:
|
if castDest.kind notin IntegralTypes+{tyRange}:
|
||||||
Message(info, hintConvFromXtoItselfNotNeeded, typeToString(castDest))
|
Message(info, hintConvFromXtoItselfNotNeeded, typeToString(castDest))
|
||||||
return
|
return
|
||||||
var d = skipTypes(castDest, abstractVar)
|
var d = skipTypes(castDest, abstractVar)
|
||||||
|
|
|
||||||
|
|
@ -251,8 +251,8 @@ proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode =
|
||||||
# BUGFIX: ``fitNode`` is needed here!
|
# BUGFIX: ``fitNode`` is needed here!
|
||||||
# check type compability between def.typ and typ:
|
# check type compability between def.typ and typ:
|
||||||
if typ != nil: def = fitNode(c, typ, def)
|
if typ != nil: def = fitNode(c, typ, def)
|
||||||
else: typ = def.typ
|
else: typ = skipIntLit(def.typ)
|
||||||
else:
|
else:
|
||||||
def = ast.emptyNode
|
def = ast.emptyNode
|
||||||
if symkind == skLet: GlobalError(a.info, errLetNeedsInit)
|
if symkind == skLet: GlobalError(a.info, errLetNeedsInit)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ proc newOrPrevType(kind: TTypeKind, prev: PType, c: PContext): PType =
|
||||||
|
|
||||||
proc newConstraint(c: PContext, k: TTypeKind): PType =
|
proc newConstraint(c: PContext, k: TTypeKind): PType =
|
||||||
result = newTypeS(tyTypeClass, c)
|
result = newTypeS(tyTypeClass, c)
|
||||||
result.addSon(newTypeS(k, c))
|
result.addSonSkipIntLit(newTypeS(k, c))
|
||||||
|
|
||||||
proc semEnum(c: PContext, n: PNode, prev: PType): PType =
|
proc semEnum(c: PContext, n: PNode, prev: PType): PType =
|
||||||
if n.sonsLen == 0: return newConstraint(c, tyEnum)
|
if n.sonsLen == 0: return newConstraint(c, tyEnum)
|
||||||
|
|
@ -37,7 +37,7 @@ proc semEnum(c: PContext, n: PNode, prev: PType): PType =
|
||||||
if base.kind != tyEnum:
|
if base.kind != tyEnum:
|
||||||
localError(n.sons[0].info, errInheritanceOnlyWithEnums)
|
localError(n.sons[0].info, errInheritanceOnlyWithEnums)
|
||||||
counter = lastOrd(base) + 1
|
counter = lastOrd(base) + 1
|
||||||
addSon(result, base)
|
rawAddSon(result, base)
|
||||||
for i in countup(1, sonsLen(n) - 1):
|
for i in countup(1, sonsLen(n) - 1):
|
||||||
case n.sons[i].kind
|
case n.sons[i].kind
|
||||||
of nkEnumFieldDef:
|
of nkEnumFieldDef:
|
||||||
|
|
@ -81,7 +81,7 @@ proc semSet(c: PContext, n: PNode, prev: PType): PType =
|
||||||
result = newOrPrevType(tySet, prev, c)
|
result = newOrPrevType(tySet, prev, c)
|
||||||
if sonsLen(n) == 2:
|
if sonsLen(n) == 2:
|
||||||
var base = semTypeNode(c, n.sons[1], nil)
|
var base = semTypeNode(c, n.sons[1], nil)
|
||||||
addSon(result, base)
|
addSonSkipIntLit(result, base)
|
||||||
if base.kind == tyGenericInst: base = lastSon(base)
|
if base.kind == tyGenericInst: base = lastSon(base)
|
||||||
if base.kind != tyGenericParam:
|
if base.kind != tyGenericParam:
|
||||||
if not isOrdinalType(base): GlobalError(n.info, errOrdinalTypeExpected)
|
if not isOrdinalType(base): GlobalError(n.info, errOrdinalTypeExpected)
|
||||||
|
|
@ -94,7 +94,7 @@ proc semContainer(c: PContext, n: PNode, kind: TTypeKind, kindStr: string,
|
||||||
result = newOrPrevType(kind, prev, c)
|
result = newOrPrevType(kind, prev, c)
|
||||||
if sonsLen(n) == 2:
|
if sonsLen(n) == 2:
|
||||||
var base = semTypeNode(c, n.sons[1], nil)
|
var base = semTypeNode(c, n.sons[1], nil)
|
||||||
addSon(result, base)
|
addSonSkipIntLit(result, base)
|
||||||
else:
|
else:
|
||||||
GlobalError(n.info, errXExpectsOneTypeParam, kindStr)
|
GlobalError(n.info, errXExpectsOneTypeParam, kindStr)
|
||||||
|
|
||||||
|
|
@ -102,7 +102,7 @@ proc semAnyRef(c: PContext, n: PNode, kind: TTypeKind, prev: PType): PType =
|
||||||
if sonsLen(n) == 1:
|
if sonsLen(n) == 1:
|
||||||
result = newOrPrevType(kind, prev, c)
|
result = newOrPrevType(kind, prev, c)
|
||||||
var base = semTypeNode(c, n.sons[0], nil)
|
var base = semTypeNode(c, n.sons[0], nil)
|
||||||
addSon(result, base)
|
addSonSkipIntLit(result, base)
|
||||||
else:
|
else:
|
||||||
result = newConstraint(c, kind)
|
result = newConstraint(c, kind)
|
||||||
|
|
||||||
|
|
@ -111,14 +111,14 @@ proc semVarType(c: PContext, n: PNode, prev: PType): PType =
|
||||||
result = newOrPrevType(tyVar, prev, c)
|
result = newOrPrevType(tyVar, prev, c)
|
||||||
var base = semTypeNode(c, n.sons[0], nil)
|
var base = semTypeNode(c, n.sons[0], nil)
|
||||||
if base.kind == tyVar: GlobalError(n.info, errVarVarTypeNotAllowed)
|
if base.kind == tyVar: GlobalError(n.info, errVarVarTypeNotAllowed)
|
||||||
addSon(result, base)
|
addSonSkipIntLit(result, base)
|
||||||
else:
|
else:
|
||||||
result = newConstraint(c, tyVar)
|
result = newConstraint(c, tyVar)
|
||||||
|
|
||||||
proc semDistinct(c: PContext, n: PNode, prev: PType): PType =
|
proc semDistinct(c: PContext, n: PNode, prev: PType): PType =
|
||||||
if sonsLen(n) == 1:
|
if sonsLen(n) == 1:
|
||||||
result = newOrPrevType(tyDistinct, prev, c)
|
result = newOrPrevType(tyDistinct, prev, c)
|
||||||
addSon(result, semTypeNode(c, n.sons[0], nil))
|
addSonSkipIntLit(result, semTypeNode(c, n.sons[0], nil))
|
||||||
else:
|
else:
|
||||||
result = newConstraint(c, tyDistinct)
|
result = newConstraint(c, tyDistinct)
|
||||||
|
|
||||||
|
|
@ -140,7 +140,7 @@ proc semRangeAux(c: PContext, n: PNode, prev: PType): PType =
|
||||||
if not leValue(a, b): GlobalError(n.Info, errRangeIsEmpty)
|
if not leValue(a, b): GlobalError(n.Info, errRangeIsEmpty)
|
||||||
addSon(result.n, a)
|
addSon(result.n, a)
|
||||||
addSon(result.n, b)
|
addSon(result.n, b)
|
||||||
addSon(result, b.typ)
|
addSonSkipIntLit(result, b.typ)
|
||||||
|
|
||||||
proc semRange(c: PContext, n: PNode, prev: PType): PType =
|
proc semRange(c: PContext, n: PNode, prev: PType): PType =
|
||||||
result = nil
|
result = nil
|
||||||
|
|
@ -157,7 +157,7 @@ proc semArray(c: PContext, n: PNode, prev: PType): PType =
|
||||||
# 3 = length(array indx base)
|
# 3 = length(array indx base)
|
||||||
if isRange(n[1]): indx = semRangeAux(c, n[1], nil)
|
if isRange(n[1]): indx = semRangeAux(c, n[1], nil)
|
||||||
else: indx = semTypeNode(c, n.sons[1], nil)
|
else: indx = semTypeNode(c, n.sons[1], nil)
|
||||||
addSon(result, indx)
|
addSonSkipIntLit(result, indx)
|
||||||
if indx.kind == tyGenericInst: indx = lastSon(indx)
|
if indx.kind == tyGenericInst: indx = lastSon(indx)
|
||||||
if indx.kind != tyGenericParam:
|
if indx.kind != tyGenericParam:
|
||||||
if not isOrdinalType(indx):
|
if not isOrdinalType(indx):
|
||||||
|
|
@ -165,7 +165,7 @@ proc semArray(c: PContext, n: PNode, prev: PType): PType =
|
||||||
if enumHasHoles(indx):
|
if enumHasHoles(indx):
|
||||||
GlobalError(n.sons[1].info, errEnumXHasHoles, indx.sym.name.s)
|
GlobalError(n.sons[1].info, errEnumXHasHoles, indx.sym.name.s)
|
||||||
base = semTypeNode(c, n.sons[2], nil)
|
base = semTypeNode(c, n.sons[2], nil)
|
||||||
addSon(result, base)
|
addSonSkipIntLit(result, base)
|
||||||
else:
|
else:
|
||||||
GlobalError(n.info, errArrayExpectsTwoTypeParams)
|
GlobalError(n.info, errArrayExpectsTwoTypeParams)
|
||||||
|
|
||||||
|
|
@ -176,7 +176,7 @@ proc semOrdinal(c: PContext, n: PNode, prev: PType): PType =
|
||||||
if base.kind != tyGenericParam:
|
if base.kind != tyGenericParam:
|
||||||
if not isOrdinalType(base):
|
if not isOrdinalType(base):
|
||||||
GlobalError(n.sons[1].info, errOrdinalTypeExpected)
|
GlobalError(n.sons[1].info, errOrdinalTypeExpected)
|
||||||
addSon(result, base)
|
addSonSkipIntLit(result, base)
|
||||||
else:
|
else:
|
||||||
GlobalError(n.info, errXExpectsOneTypeParam, "ordinal")
|
GlobalError(n.info, errXExpectsOneTypeParam, "ordinal")
|
||||||
|
|
||||||
|
|
@ -232,7 +232,7 @@ proc semTuple(c: PContext, n: PNode, prev: PType): PType =
|
||||||
if ContainsOrIncl(check, field.name.id):
|
if ContainsOrIncl(check, field.name.id):
|
||||||
GlobalError(a.sons[j].info, errAttemptToRedefine, field.name.s)
|
GlobalError(a.sons[j].info, errAttemptToRedefine, field.name.s)
|
||||||
addSon(result.n, newSymNode(field))
|
addSon(result.n, newSymNode(field))
|
||||||
addSon(result, typ)
|
addSonSkipIntLit(result, typ)
|
||||||
|
|
||||||
proc semIdentVis(c: PContext, kind: TSymKind, n: PNode,
|
proc semIdentVis(c: PContext, kind: TSymKind, n: PNode,
|
||||||
allowed: TSymFlags): PSym =
|
allowed: TSymFlags): PSym =
|
||||||
|
|
@ -487,7 +487,7 @@ proc semObjectNode(c: PContext, n: PNode, prev: PType): PType =
|
||||||
localError(n.sons[1].info, errInheritanceOnlyWithNonFinalObjects)
|
localError(n.sons[1].info, errInheritanceOnlyWithNonFinalObjects)
|
||||||
if n.kind != nkObjectTy: InternalError(n.info, "semObjectNode")
|
if n.kind != nkObjectTy: InternalError(n.info, "semObjectNode")
|
||||||
result = newOrPrevType(tyObject, prev, c)
|
result = newOrPrevType(tyObject, prev, c)
|
||||||
addSon(result, base)
|
rawAddSon(result, base)
|
||||||
result.n = newNodeI(nkRecList, n.info)
|
result.n = newNodeI(nkRecList, n.info)
|
||||||
semRecordNodeAux(c, n.sons[2], check, pos, result.n, result.sym)
|
semRecordNodeAux(c, n.sons[2], check, pos, result.n, result.sym)
|
||||||
if n.sons[0].kind != nkEmpty:
|
if n.sons[0].kind != nkEmpty:
|
||||||
|
|
@ -537,7 +537,7 @@ proc paramTypeClass(c: PContext, paramType: PType, procKind: TSymKind):
|
||||||
# type Foo[T] = object
|
# type Foo[T] = object
|
||||||
# proc x(a: Foo, b: Foo)
|
# proc x(a: Foo, b: Foo)
|
||||||
result.typ = newTypeS(tyTypeClass, c)
|
result.typ = newTypeS(tyTypeClass, c)
|
||||||
result.typ.addSon(paramType)
|
result.typ.addSonSkipIntLit(paramType)
|
||||||
result.id = paramType.sym.name # bindOnce by default
|
result.id = paramType.sym.name # bindOnce by default
|
||||||
of tyTypeClass:
|
of tyTypeClass:
|
||||||
result.typ = copyType(paramType, getCurrOwner(), false)
|
result.typ = copyType(paramType, getCurrOwner(), false)
|
||||||
|
|
@ -588,7 +588,7 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode,
|
||||||
result.n = newNodeI(nkFormalParams, n.info)
|
result.n = newNodeI(nkFormalParams, n.info)
|
||||||
if genericParams != nil and sonsLen(genericParams) == 0:
|
if genericParams != nil and sonsLen(genericParams) == 0:
|
||||||
cl = initIntSet()
|
cl = initIntSet()
|
||||||
addSon(result, nil) # return type
|
rawAddSon(result, nil) # return type
|
||||||
res = newNodeI(nkType, n.info)
|
res = newNodeI(nkType, n.info)
|
||||||
addSon(result.n, res)
|
addSon(result.n, res)
|
||||||
var check = initIntSet()
|
var check = initIntSet()
|
||||||
|
|
@ -625,7 +625,7 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode,
|
||||||
for j in countup(0, length-3):
|
for j in countup(0, length-3):
|
||||||
var arg = newSymS(skParam, a.sons[j], c)
|
var arg = newSymS(skParam, a.sons[j], c)
|
||||||
var finalType = liftParamType(c, kind, genericParams, typ, arg.name.s,
|
var finalType = liftParamType(c, kind, genericParams, typ, arg.name.s,
|
||||||
arg.info)
|
arg.info).skipIntLit
|
||||||
arg.typ = finalType
|
arg.typ = finalType
|
||||||
arg.position = counter
|
arg.position = counter
|
||||||
inc(counter)
|
inc(counter)
|
||||||
|
|
@ -633,7 +633,7 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode,
|
||||||
if ContainsOrIncl(check, arg.name.id):
|
if ContainsOrIncl(check, arg.name.id):
|
||||||
LocalError(a.sons[j].info, errAttemptToRedefine, arg.name.s)
|
LocalError(a.sons[j].info, errAttemptToRedefine, arg.name.s)
|
||||||
addSon(result.n, newSymNode(arg))
|
addSon(result.n, newSymNode(arg))
|
||||||
addSon(result, finalType)
|
rawAddSon(result, finalType)
|
||||||
addParamOrResult(c, arg, kind)
|
addParamOrResult(c, arg, kind)
|
||||||
|
|
||||||
if n.sons[0].kind != nkEmpty:
|
if n.sons[0].kind != nkEmpty:
|
||||||
|
|
@ -643,7 +643,7 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode,
|
||||||
if skipTypes(r, {tyGenericInst}).kind != tyEmpty:
|
if skipTypes(r, {tyGenericInst}).kind != tyEmpty:
|
||||||
if r.sym == nil or sfAnon notin r.sym.flags:
|
if r.sym == nil or sfAnon notin r.sym.flags:
|
||||||
r = liftParamType(c, kind, genericParams, r, "result", n.sons[0].info)
|
r = liftParamType(c, kind, genericParams, r, "result", n.sons[0].info)
|
||||||
result.sons[0] = r
|
result.sons[0] = skipIntLit(r)
|
||||||
res.typ = result.sons[0]
|
res.typ = result.sons[0]
|
||||||
|
|
||||||
proc semStmtListType(c: PContext, n: PNode, prev: PType): PType =
|
proc semStmtListType(c: PContext, n: PNode, prev: PType): PType =
|
||||||
|
|
@ -700,13 +700,14 @@ proc semGeneric(c: PContext, n: PNode, s: PSym, prev: PType): PType =
|
||||||
InternalError(n.info, "semtypes.semGeneric")
|
InternalError(n.info, "semtypes.semGeneric")
|
||||||
elif sonsLen(n) != sonsLen(s.typ):
|
elif sonsLen(n) != sonsLen(s.typ):
|
||||||
GlobalError(n.info, errWrongNumberOfArguments)
|
GlobalError(n.info, errWrongNumberOfArguments)
|
||||||
addSon(result, s.typ)
|
addSonSkipIntLit(result, s.typ)
|
||||||
# iterate over arguments:
|
# iterate over arguments:
|
||||||
for i in countup(1, sonsLen(n)-1):
|
for i in countup(1, sonsLen(n)-1):
|
||||||
var elem = semGenericParamInInvokation(c, n.sons[i])
|
var elem = semGenericParamInInvokation(c, n.sons[i])
|
||||||
if containsGenericType(elem): isConcrete = false
|
if containsGenericType(elem): isConcrete = false
|
||||||
#if elem.kind in {tyGenericParam, tyGenericInvokation}: isConcrete = false
|
#if elem.kind in {tyGenericParam, tyGenericInvokation}: isConcrete = false
|
||||||
addSon(result, elem)
|
if elem.isNil: rawAddSon(result, elem)
|
||||||
|
else: addSonSkipIntLit(result, elem)
|
||||||
if isConcrete:
|
if isConcrete:
|
||||||
if s.ast == nil: GlobalError(n.info, errCannotInstantiateX, s.name.s)
|
if s.ast == nil: GlobalError(n.info, errCannotInstantiateX, s.name.s)
|
||||||
result = instGenericContainer(c, n, result)
|
result = instGenericContainer(c, n, result)
|
||||||
|
|
@ -747,8 +748,8 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
|
||||||
elif t2 == nil: GlobalError(n.sons[2].info, errTypeExpected)
|
elif t2 == nil: GlobalError(n.sons[2].info, errTypeExpected)
|
||||||
else:
|
else:
|
||||||
result = newTypeS(tyTypeClass, c)
|
result = newTypeS(tyTypeClass, c)
|
||||||
result.addSon(t1)
|
result.addSonSkipIntLit(t1)
|
||||||
result.addSon(t2)
|
result.addSonSkipIntLit(t2)
|
||||||
result.flags.incl(if op.id == ord(wAnd): tfAll else: tfAny)
|
result.flags.incl(if op.id == ord(wAnd): tfAll else: tfAny)
|
||||||
else:
|
else:
|
||||||
result = semTypeFromMacro(c, n)
|
result = semTypeFromMacro(c, n)
|
||||||
|
|
@ -757,7 +758,7 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
|
||||||
if result != nil:
|
if result != nil:
|
||||||
result = copyType(result, getCurrOwner(), false)
|
result = copyType(result, getCurrOwner(), false)
|
||||||
for i in countup(1, n.len - 1):
|
for i in countup(1, n.len - 1):
|
||||||
result.addSon(semTypeNode(c, n.sons[i], nil))
|
result.rawAddSon(semTypeNode(c, n.sons[i], nil))
|
||||||
of nkWhenStmt:
|
of nkWhenStmt:
|
||||||
var whenResult = semWhen(c, n, false)
|
var whenResult = semWhen(c, n, false)
|
||||||
if whenResult.kind == nkStmtList: whenResult.kind = nkStmtListType
|
if whenResult.kind == nkStmtList: whenResult.kind = nkStmtListType
|
||||||
|
|
@ -841,14 +842,14 @@ proc processMagicType(c: PContext, m: PSym) =
|
||||||
of mChar: setMagicType(m, tyChar, 1)
|
of mChar: setMagicType(m, tyChar, 1)
|
||||||
of mString:
|
of mString:
|
||||||
setMagicType(m, tyString, ptrSize)
|
setMagicType(m, tyString, ptrSize)
|
||||||
addSon(m.typ, getSysType(tyChar))
|
rawAddSon(m.typ, getSysType(tyChar))
|
||||||
of mCstring:
|
of mCstring:
|
||||||
setMagicType(m, tyCString, ptrSize)
|
setMagicType(m, tyCString, ptrSize)
|
||||||
addSon(m.typ, getSysType(tyChar))
|
rawAddSon(m.typ, getSysType(tyChar))
|
||||||
of mPointer: setMagicType(m, tyPointer, ptrSize)
|
of mPointer: setMagicType(m, tyPointer, ptrSize)
|
||||||
of mEmptySet:
|
of mEmptySet:
|
||||||
setMagicType(m, tySet, 1)
|
setMagicType(m, tySet, 1)
|
||||||
addSon(m.typ, newTypeS(tyEmpty, c))
|
rawAddSon(m.typ, newTypeS(tyEmpty, c))
|
||||||
of mIntSetBaseType: setMagicType(m, tyRange, intSize)
|
of mIntSetBaseType: setMagicType(m, tyRange, intSize)
|
||||||
of mNil: setMagicType(m, tyNil, ptrSize)
|
of mNil: setMagicType(m, tyNil, ptrSize)
|
||||||
of mExpr: setMagicType(m, tyExpr, 0)
|
of mExpr: setMagicType(m, tyExpr, 0)
|
||||||
|
|
@ -869,7 +870,7 @@ proc semGenericConstraints(c: PContext, n: PNode, result: PType) =
|
||||||
if x.kind in StructuralEquivTypes and (
|
if x.kind in StructuralEquivTypes and (
|
||||||
sonsLen(x) == 0 or x.sons[0].kind in {tyGenericParam, tyEmpty}):
|
sonsLen(x) == 0 or x.sons[0].kind in {tyGenericParam, tyEmpty}):
|
||||||
x = newConstraint(c, x.kind)
|
x = newConstraint(c, x.kind)
|
||||||
result.addSon(x)
|
result.addSonSkipIntLit(x)
|
||||||
|
|
||||||
proc semGenericParamList(c: PContext, n: PNode, father: PType = nil): PNode =
|
proc semGenericParamList(c: PContext, n: PNode, father: PType = nil): PNode =
|
||||||
result = copyNode(n)
|
result = copyNode(n)
|
||||||
|
|
@ -910,9 +911,7 @@ proc semGenericParamList(c: PContext, n: PNode, father: PType = nil): PNode =
|
||||||
s.typ = typ
|
s.typ = typ
|
||||||
if def.kind != nkEmpty: s.ast = def
|
if def.kind != nkEmpty: s.ast = def
|
||||||
s.typ.sym = s
|
s.typ.sym = s
|
||||||
if father != nil: addSon(father, s.typ)
|
if father != nil: addSonSkipIntLit(father, s.typ)
|
||||||
s.position = i
|
s.position = i
|
||||||
addSon(result, newSymNode(s))
|
addSon(result, newSymNode(s))
|
||||||
addDecl(c, s)
|
addDecl(c, s)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ proc fontFinalizer(f: PFont) = closeFont(f.f)
|
||||||
proc newFont*(name = "VeraMono.ttf", size = 9, color = colBlack): PFont =
|
proc newFont*(name = "VeraMono.ttf", size = 9, color = colBlack): PFont =
|
||||||
## Creates a new font object. Raises ``EIO`` if the font cannot be loaded.
|
## Creates a new font object. Raises ``EIO`` if the font cannot be loaded.
|
||||||
new(result, fontFinalizer)
|
new(result, fontFinalizer)
|
||||||
result.f = OpenFont(name, size)
|
result.f = OpenFont(name, size.cint)
|
||||||
if result.f == nil:
|
if result.f == nil:
|
||||||
raise newException(EIO, "Could not open font file: " & name)
|
raise newException(EIO, "Could not open font file: " & name)
|
||||||
result.color = toSdlColor(color)
|
result.color = toSdlColor(color)
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ proc findBounds*(s: string, pattern: TRegEx, matches: var openarray[string],
|
||||||
## is written into `matches` and ``(-1,0)`` is returned.
|
## is written into `matches` and ``(-1,0)`` is returned.
|
||||||
var
|
var
|
||||||
rawMatches: array[0..maxSubpatterns * 3 - 1, cint]
|
rawMatches: array[0..maxSubpatterns * 3 - 1, cint]
|
||||||
res = pcre.Exec(pattern.h, pattern.e, s, len(s).cint, start, 0'i32,
|
res = pcre.Exec(pattern.h, pattern.e, s, len(s).cint, start.cint, 0'i32,
|
||||||
cast[ptr cint](addr(rawMatches)), maxSubpatterns * 3)
|
cast[ptr cint](addr(rawMatches)), maxSubpatterns * 3)
|
||||||
if res < 0'i32: return (-1, 0)
|
if res < 0'i32: return (-1, 0)
|
||||||
for i in 1..int(res)-1:
|
for i in 1..int(res)-1:
|
||||||
|
|
@ -119,7 +119,7 @@ proc findBounds*(s: string, pattern: TRegEx,
|
||||||
## ``(-1,0)`` is returned.
|
## ``(-1,0)`` is returned.
|
||||||
var
|
var
|
||||||
rawMatches: array[0..maxSubpatterns * 3 - 1, cint]
|
rawMatches: array[0..maxSubpatterns * 3 - 1, cint]
|
||||||
res = pcre.Exec(pattern.h, pattern.e, s, len(s).cint, start, 0'i32,
|
res = pcre.Exec(pattern.h, pattern.e, s, len(s).cint, start.cint, 0'i32,
|
||||||
cast[ptr cint](addr(rawMatches)), maxSubpatterns * 3)
|
cast[ptr cint](addr(rawMatches)), maxSubpatterns * 3)
|
||||||
if res < 0'i32: return (-1, 0)
|
if res < 0'i32: return (-1, 0)
|
||||||
for i in 1..int(res)-1:
|
for i in 1..int(res)-1:
|
||||||
|
|
@ -135,7 +135,7 @@ proc findBounds*(s: string, pattern: TRegEx,
|
||||||
## match, ``(-1,0)`` is returned.
|
## match, ``(-1,0)`` is returned.
|
||||||
var
|
var
|
||||||
rawMatches: array[0..3 - 1, cint]
|
rawMatches: array[0..3 - 1, cint]
|
||||||
res = pcre.Exec(pattern.h, nil, s, len(s).cint, start, 0'i32,
|
res = pcre.Exec(pattern.h, nil, s, len(s).cint, start.cint, 0'i32,
|
||||||
cast[ptr cint](addr(rawMatches)), 3)
|
cast[ptr cint](addr(rawMatches)), 3)
|
||||||
if res < 0'i32: return (int(res), 0)
|
if res < 0'i32: return (int(res), 0)
|
||||||
return (int(rawMatches[0]), int(rawMatches[1]-1))
|
return (int(rawMatches[0]), int(rawMatches[1]-1))
|
||||||
|
|
@ -153,25 +153,25 @@ proc match*(s: string, pattern: TRegEx, matches: var openarray[string],
|
||||||
## the captured substrings in the array ``matches``. If it does not
|
## the captured substrings in the array ``matches``. If it does not
|
||||||
## match, nothing is written into ``matches`` and ``false`` is
|
## match, nothing is written into ``matches`` and ``false`` is
|
||||||
## returned.
|
## returned.
|
||||||
return matchOrFind(s, pattern, matches, start,
|
return matchOrFind(s, pattern, matches, start.cint,
|
||||||
pcre.ANCHORED) == cint(s.len - start)
|
pcre.ANCHORED) == cint(s.len - start)
|
||||||
|
|
||||||
proc match*(s: string, pattern: TRegEx, start = 0): bool =
|
proc match*(s: string, pattern: TRegEx, start = 0): bool =
|
||||||
## returns ``true`` if ``s[start..]`` matches the ``pattern``.
|
## returns ``true`` if ``s[start..]`` matches the ``pattern``.
|
||||||
return matchOrFind(s, pattern, start, pcre.ANCHORED) == cint(s.len - start)
|
return matchOrFind(s, pattern, start.cint, pcre.ANCHORED) == cint(s.len-start)
|
||||||
|
|
||||||
proc matchLen*(s: string, pattern: TRegEx, matches: var openarray[string],
|
proc matchLen*(s: string, pattern: TRegEx, matches: var openarray[string],
|
||||||
start = 0): int =
|
start = 0): int =
|
||||||
## the same as ``match``, but it returns the length of the match,
|
## the same as ``match``, but it returns the length of the match,
|
||||||
## if there is no match, -1 is returned. Note that a match length
|
## if there is no match, -1 is returned. Note that a match length
|
||||||
## of zero can happen.
|
## of zero can happen.
|
||||||
return matchOrFind(s, pattern, matches, start, pcre.ANCHORED)
|
return matchOrFind(s, pattern, matches, start.cint, pcre.ANCHORED)
|
||||||
|
|
||||||
proc matchLen*(s: string, pattern: TRegEx, start = 0): int =
|
proc matchLen*(s: string, pattern: TRegEx, start = 0): int =
|
||||||
## the same as ``match``, but it returns the length of the match,
|
## the same as ``match``, but it returns the length of the match,
|
||||||
## if there is no match, -1 is returned. Note that a match length
|
## if there is no match, -1 is returned. Note that a match length
|
||||||
## of zero can happen.
|
## of zero can happen.
|
||||||
return matchOrFind(s, pattern, start, pcre.ANCHORED)
|
return matchOrFind(s, pattern, start.cint, pcre.ANCHORED)
|
||||||
|
|
||||||
proc find*(s: string, pattern: TRegEx, matches: var openarray[string],
|
proc find*(s: string, pattern: TRegEx, matches: var openarray[string],
|
||||||
start = 0): int =
|
start = 0): int =
|
||||||
|
|
@ -180,7 +180,7 @@ proc find*(s: string, pattern: TRegEx, matches: var openarray[string],
|
||||||
## is written into ``matches`` and -1 is returned.
|
## is written into ``matches`` and -1 is returned.
|
||||||
var
|
var
|
||||||
rawMatches: array[0..maxSubpatterns * 3 - 1, cint]
|
rawMatches: array[0..maxSubpatterns * 3 - 1, cint]
|
||||||
res = pcre.Exec(pattern.h, pattern.e, s, len(s).cint, start, 0'i32,
|
res = pcre.Exec(pattern.h, pattern.e, s, len(s).cint, start.cint, 0'i32,
|
||||||
cast[ptr cint](addr(rawMatches)), maxSubpatterns * 3)
|
cast[ptr cint](addr(rawMatches)), maxSubpatterns * 3)
|
||||||
if res < 0'i32: return res
|
if res < 0'i32: return res
|
||||||
for i in 1..int(res)-1:
|
for i in 1..int(res)-1:
|
||||||
|
|
@ -195,7 +195,7 @@ proc find*(s: string, pattern: TRegEx, start = 0): int =
|
||||||
## match, -1 is returned.
|
## match, -1 is returned.
|
||||||
var
|
var
|
||||||
rawMatches: array[0..3 - 1, cint]
|
rawMatches: array[0..3 - 1, cint]
|
||||||
res = pcre.Exec(pattern.h, nil, s, len(s).cint, start, 0'i32,
|
res = pcre.Exec(pattern.h, nil, s, len(s).cint, start.cint, 0'i32,
|
||||||
cast[ptr cint](addr(rawMatches)), 3)
|
cast[ptr cint](addr(rawMatches)), 3)
|
||||||
if res < 0'i32: return res
|
if res < 0'i32: return res
|
||||||
return rawMatches[0]
|
return rawMatches[0]
|
||||||
|
|
|
||||||
|
|
@ -137,8 +137,8 @@ proc getStream*(z: var TZipArchive, filename: string): PZipFileStream =
|
||||||
iterator walkFiles*(z: var TZipArchive): string =
|
iterator walkFiles*(z: var TZipArchive): string =
|
||||||
## walks over all files in the archive `z` and returns the filename
|
## walks over all files in the archive `z` and returns the filename
|
||||||
## (including the path).
|
## (including the path).
|
||||||
var i = 0
|
var i = 0'i32
|
||||||
var num = int(zip_get_num_files(z.w))
|
var num = zip_get_num_files(z.w)
|
||||||
while i < num:
|
while i < num:
|
||||||
yield $zip_get_name(z.w, i, 0'i32)
|
yield $zip_get_name(z.w, i, 0'i32)
|
||||||
inc(i)
|
inc(i)
|
||||||
|
|
|
||||||
|
|
@ -55,23 +55,23 @@ type
|
||||||
## a type description (for templates)
|
## a type description (for templates)
|
||||||
void* {.magic: "VoidType".} ## meta type to denote the absense of any type
|
void* {.magic: "VoidType".} ## meta type to denote the absense of any type
|
||||||
|
|
||||||
TSignedInt* = distinct int|int8|int16|int32|int64
|
TSignedInt* = int|int8|int16|int32|int64
|
||||||
## type class matching all signed integer types
|
## type class matching all signed integer types
|
||||||
|
|
||||||
TUnsignedInt* = distinct uint|uint8|uint16|uint32|uint64
|
TUnsignedInt* = uint|uint8|uint16|uint32|uint64
|
||||||
## type class matching all unsigned integer types
|
## type class matching all unsigned integer types
|
||||||
|
|
||||||
TInteger* = distinct TSignedInt|TUnsignedInt
|
TInteger* = TSignedInt|TUnsignedInt
|
||||||
## type class matching all integer types
|
## type class matching all integer types
|
||||||
|
|
||||||
TOrdinal* = distinct TInteger|bool|enum
|
TOrdinal* = TInteger|bool|enum
|
||||||
## type class matching all ordinal types; however this includes enums with
|
## type class matching all ordinal types; however this includes enums with
|
||||||
## holes.
|
## holes.
|
||||||
|
|
||||||
TReal* = distinct float|float32|float64
|
TReal* = float|float32|float64
|
||||||
## type class matching all floating point number types
|
## type class matching all floating point number types
|
||||||
|
|
||||||
TNumber* = distinct TInteger|TReal
|
TNumber* = TInteger|TReal
|
||||||
## type class matching all number types
|
## type class matching all number types
|
||||||
|
|
||||||
proc defined*(x: expr): bool {.magic: "Defined", noSideEffect.}
|
proc defined*(x: expr): bool {.magic: "Defined", noSideEffect.}
|
||||||
|
|
@ -1234,14 +1234,14 @@ iterator countup*[S, T](a: S, b: T, step = 1): T {.inline.} =
|
||||||
## Counts from ordinal value `a` up to `b` with the given
|
## Counts from ordinal value `a` up to `b` with the given
|
||||||
## step count. `S`, `T` may be any ordinal type, `step` may only
|
## step count. `S`, `T` may be any ordinal type, `step` may only
|
||||||
## be positive.
|
## be positive.
|
||||||
var res: T = a
|
var res: T = T(a)
|
||||||
while res <= b:
|
while res <= b:
|
||||||
yield res
|
yield res
|
||||||
inc(res, step)
|
inc(res, step)
|
||||||
|
|
||||||
iterator `..`*[S, T](a: S, b: T): T {.inline.} =
|
iterator `..`*[S, T](a: S, b: T): T {.inline.} =
|
||||||
## An alias for `countup`.
|
## An alias for `countup`.
|
||||||
var res: T = a
|
var res: T = T(a)
|
||||||
while res <= b:
|
while res <= b:
|
||||||
yield res
|
yield res
|
||||||
inc res
|
inc res
|
||||||
|
|
@ -2242,13 +2242,13 @@ proc staticExec*(command: string, input = ""): string {.
|
||||||
##
|
##
|
||||||
## ``gorge`` is an alias for ``staticExec``.
|
## ``gorge`` is an alias for ``staticExec``.
|
||||||
|
|
||||||
proc `+=`*[T](x, y: ordinal[T]) {.magic: "Inc", noSideEffect.}
|
proc `+=`*[T: TOrdinal](x: var T, y: T) {.magic: "Inc", noSideEffect.}
|
||||||
## Increments an ordinal
|
## Increments an ordinal
|
||||||
|
|
||||||
proc `-=`*[T](x, y: ordinal[T]) {.magic: "Dec", noSideEffect.}
|
proc `-=`*[T: TOrdinal](x: var T, y: T) {.magic: "Dec", noSideEffect.}
|
||||||
## Decrements an ordinal
|
## Decrements an ordinal
|
||||||
|
|
||||||
proc `*=`*[T](x: var ordinal[T], y: ordinal[T]) {.inline, noSideEffect.} =
|
proc `*=`*[T: TOrdinal](x: var T, y: T) {.inline, noSideEffect.} =
|
||||||
## Binary `*=` operator for ordinals
|
## Binary `*=` operator for ordinals
|
||||||
x = x * y
|
x = x * y
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue