l-values are preserved modulo type distinction

This commit is contained in:
Araq
2011-09-24 13:15:11 +02:00
parent 92543a3037
commit 033e3dfc50
4 changed files with 14 additions and 7 deletions

View File

@@ -1395,7 +1395,11 @@ proc genRangeChck(p: BProc, n: PNode, d: var TLoc, magic: string) =
toRope(magic)]))
proc genConv(p: BProc, e: PNode, d: var TLoc) =
genCast(p, e, d)
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)
proc convStrToCStr(p: BProc, n: PNode, d: var TLoc) =
var a: TLoc

View File

@@ -72,7 +72,7 @@ proc GetUniqueType*(key: PType): PType =
if result == nil:
IdTablePut(gTypeTable[k], key, key)
result = key
of tyGenericInst, tyDistinct, tyOrdinal:
of tyGenericInst, tyDistinct, tyOrdinal, tyMutable, tyConst, tyIter:
result = GetUniqueType(lastSon(key))
of tyProc:
nil
@@ -116,9 +116,8 @@ proc makeCString*(s: string): PRope =
# further information.
const
MaxLineLength = 64
var res: string
result = nil
res = "\""
var res = "\""
for i in countup(0, len(s) - 1):
if (i + 1) mod MaxLineLength == 0:
add(res, '\"')
@@ -132,9 +131,8 @@ proc makeCString*(s: string): PRope =
proc makeLLVMString*(s: string): PRope =
const MaxLineLength = 64
var res: string
result = nil
res = "c\""
var res = "c\""
for i in countup(0, len(s) - 1):
if (i + 1) mod MaxLineLength == 0:
app(result, toRope(res))

View File

@@ -1316,6 +1316,7 @@ proc complexOrSimpleStmt(p: var TParser): PNode =
of tkConverter: result = parseRoutine(p, nkConverterDef)
of tkType: result = parseSection(p, nkTypeSection, parseTypeDef)
of tkConst: result = parseSection(p, nkConstSection, parseConstant)
of tkLet: result = parseSection(p, nkLetSection, parseConstant)
of tkWhen: result = parseIfOrWhen(p, nkWhenStmt)
of tkVar: result = parseSection(p, nkVarSection, parseVariable)
else: result = simpleStmt(p)
@@ -1379,7 +1380,7 @@ proc parseString(s: string, filename: string = "", line: int = 0): PNode =
var stream = LLStreamOpen(s)
stream.lineOffset = line
var parser : TParser
var parser: TParser
OpenParser(parser, filename, stream)
result = parser.parseAll

View File

@@ -378,6 +378,10 @@ proc isAssignable(c: PContext, n: PNode): TAssignableResult =
# Object and tuple conversions are still addressable, so we skip them
if skipTypes(n.typ, abstractPtrs).kind in {tyOpenArray, tyTuple, tyObject}:
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:
result = arLValue
of nkObjUpConv, nkObjDownConv, nkCheckedFieldExpr: