l-values are preserved modulo type distinction
This commit is contained in:
parent
92543a3037
commit
033e3dfc50
4 changed files with 14 additions and 7 deletions
|
|
@ -1395,6 +1395,10 @@ proc genRangeChck(p: BProc, n: PNode, d: var TLoc, magic: string) =
|
||||||
toRope(magic)]))
|
toRope(magic)]))
|
||||||
|
|
||||||
proc genConv(p: BProc, e: PNode, d: var TLoc) =
|
proc genConv(p: BProc, e: PNode, d: var TLoc) =
|
||||||
|
if equalOrDistinctOf(e.typ, e.sons[1].typ) or
|
||||||
|
equalOrDistinctOf(e.sons[1].typ, e.typ):
|
||||||
|
expr(p, e.sons[1], d)
|
||||||
|
else:
|
||||||
genCast(p, e, d)
|
genCast(p, e, d)
|
||||||
|
|
||||||
proc convStrToCStr(p: BProc, n: PNode, d: var TLoc) =
|
proc convStrToCStr(p: BProc, n: PNode, d: var TLoc) =
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ proc GetUniqueType*(key: PType): PType =
|
||||||
if result == nil:
|
if result == nil:
|
||||||
IdTablePut(gTypeTable[k], key, key)
|
IdTablePut(gTypeTable[k], key, key)
|
||||||
result = key
|
result = key
|
||||||
of tyGenericInst, tyDistinct, tyOrdinal:
|
of tyGenericInst, tyDistinct, tyOrdinal, tyMutable, tyConst, tyIter:
|
||||||
result = GetUniqueType(lastSon(key))
|
result = GetUniqueType(lastSon(key))
|
||||||
of tyProc:
|
of tyProc:
|
||||||
nil
|
nil
|
||||||
|
|
@ -116,9 +116,8 @@ proc makeCString*(s: string): PRope =
|
||||||
# further information.
|
# further information.
|
||||||
const
|
const
|
||||||
MaxLineLength = 64
|
MaxLineLength = 64
|
||||||
var res: string
|
|
||||||
result = nil
|
result = nil
|
||||||
res = "\""
|
var res = "\""
|
||||||
for i in countup(0, len(s) - 1):
|
for i in countup(0, len(s) - 1):
|
||||||
if (i + 1) mod MaxLineLength == 0:
|
if (i + 1) mod MaxLineLength == 0:
|
||||||
add(res, '\"')
|
add(res, '\"')
|
||||||
|
|
@ -132,9 +131,8 @@ proc makeCString*(s: string): PRope =
|
||||||
|
|
||||||
proc makeLLVMString*(s: string): PRope =
|
proc makeLLVMString*(s: string): PRope =
|
||||||
const MaxLineLength = 64
|
const MaxLineLength = 64
|
||||||
var res: string
|
|
||||||
result = nil
|
result = nil
|
||||||
res = "c\""
|
var res = "c\""
|
||||||
for i in countup(0, len(s) - 1):
|
for i in countup(0, len(s) - 1):
|
||||||
if (i + 1) mod MaxLineLength == 0:
|
if (i + 1) mod MaxLineLength == 0:
|
||||||
app(result, toRope(res))
|
app(result, toRope(res))
|
||||||
|
|
|
||||||
|
|
@ -1316,6 +1316,7 @@ proc complexOrSimpleStmt(p: var TParser): PNode =
|
||||||
of tkConverter: result = parseRoutine(p, nkConverterDef)
|
of tkConverter: result = parseRoutine(p, nkConverterDef)
|
||||||
of tkType: result = parseSection(p, nkTypeSection, parseTypeDef)
|
of tkType: result = parseSection(p, nkTypeSection, parseTypeDef)
|
||||||
of tkConst: result = parseSection(p, nkConstSection, parseConstant)
|
of tkConst: result = parseSection(p, nkConstSection, parseConstant)
|
||||||
|
of tkLet: result = parseSection(p, nkLetSection, parseConstant)
|
||||||
of tkWhen: result = parseIfOrWhen(p, nkWhenStmt)
|
of tkWhen: result = parseIfOrWhen(p, nkWhenStmt)
|
||||||
of tkVar: result = parseSection(p, nkVarSection, parseVariable)
|
of tkVar: result = parseSection(p, nkVarSection, parseVariable)
|
||||||
else: result = simpleStmt(p)
|
else: result = simpleStmt(p)
|
||||||
|
|
|
||||||
|
|
@ -378,6 +378,10 @@ proc isAssignable(c: PContext, n: PNode): TAssignableResult =
|
||||||
# Object and tuple conversions are still addressable, so we skip them
|
# Object and tuple conversions are still addressable, so we skip them
|
||||||
if skipTypes(n.typ, abstractPtrs).kind in {tyOpenArray, tyTuple, tyObject}:
|
if skipTypes(n.typ, abstractPtrs).kind in {tyOpenArray, tyTuple, tyObject}:
|
||||||
result = isAssignable(c, n.sons[1])
|
result = isAssignable(c, n.sons[1])
|
||||||
|
elif equalOrDistinctOf(n.typ, n.sons[1].typ) or
|
||||||
|
equalOrDistinctOf(n.sons[1].typ, n.typ):
|
||||||
|
# types that are equal modulo distinction preserve l-value:
|
||||||
|
result = isAssignable(c, n.sons[1])
|
||||||
of nkHiddenDeref, nkDerefExpr:
|
of nkHiddenDeref, nkDerefExpr:
|
||||||
result = arLValue
|
result = arLValue
|
||||||
of nkObjUpConv, nkObjDownConv, nkCheckedFieldExpr:
|
of nkObjUpConv, nkObjDownConv, nkCheckedFieldExpr:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue