mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-08 12:54:22 +00:00
clean separation of PNimrodNode and tyExpr
This commit is contained in:
@@ -31,8 +31,8 @@ proc semLambda(c: PContext, n: PNode): PNode
|
||||
proc semTypeNode(c: PContext, n: PNode, prev: PType): PType
|
||||
proc semStmt(c: PContext, n: PNode): PNode
|
||||
proc semParamList(c: PContext, n, genericParams: PNode, s: PSym)
|
||||
proc addParams(c: PContext, n: PNode)
|
||||
proc addResult(c: PContext, t: PType, info: TLineInfo)
|
||||
proc addParams(c: PContext, n: PNode, kind: TSymKind)
|
||||
proc addResult(c: PContext, t: PType, info: TLineInfo, owner: TSymKind)
|
||||
proc addResultNode(c: PContext, n: PNode)
|
||||
proc instGenericContainer(c: PContext, n: PNode, header: PType): PType
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ proc instantiateBody(c: PContext, n: PNode, result: PSym) =
|
||||
addDecl(c, result)
|
||||
pushProcCon(c, result)
|
||||
if result.kind in {skProc, skMethod, skConverter}:
|
||||
addResult(c, result.typ.sons[0], n.info)
|
||||
addResult(c, result.typ.sons[0], n.info, result.kind)
|
||||
addResultNode(c, n)
|
||||
var b = semStmtScope(c, n.sons[bodyPos])
|
||||
# XXX Bad hack for tests/titer2 and tests/tactiontable
|
||||
@@ -92,7 +92,8 @@ proc fixupInstantiatedSymbols(c: PContext, s: PSym) =
|
||||
openScope(c.tab)
|
||||
var n = oldPrc.ast
|
||||
n.sons[bodyPos] = copyTree(s.getBody)
|
||||
if n.sons[paramsPos].kind != nkEmpty: addParams(c, oldPrc.typ.n)
|
||||
if n.sons[paramsPos].kind != nkEmpty:
|
||||
addParams(c, oldPrc.typ.n, oldPrc.kind)
|
||||
instantiateBody(c, n, oldPrc)
|
||||
closeScope(c.tab)
|
||||
popInfoContext()
|
||||
|
||||
@@ -599,12 +599,12 @@ proc SemTypeSection(c: PContext, n: PNode): PNode =
|
||||
result = n
|
||||
|
||||
proc semParamList(c: PContext, n, genericParams: PNode, s: PSym) =
|
||||
s.typ = semProcTypeNode(c, n, genericParams, nil)
|
||||
s.typ = semProcTypeNode(c, n, genericParams, nil, s.kind)
|
||||
|
||||
proc addParams(c: PContext, n: PNode) =
|
||||
proc addParams(c: PContext, n: PNode, kind: TSymKind) =
|
||||
for i in countup(1, sonsLen(n)-1):
|
||||
if (n.sons[i].kind != nkSym): InternalError(n.info, "addParams")
|
||||
addDecl(c, n.sons[i].sym)
|
||||
addParamOrResult(c, n.sons[i].sym, kind)
|
||||
|
||||
proc semBorrow(c: PContext, n: PNode, s: PSym) =
|
||||
# search for the correct alias:
|
||||
@@ -615,13 +615,13 @@ proc semBorrow(c: PContext, n: PNode, s: PSym) =
|
||||
else:
|
||||
LocalError(n.info, errNoSymbolToBorrowFromFound)
|
||||
|
||||
proc addResult(c: PContext, t: PType, info: TLineInfo) =
|
||||
proc addResult(c: PContext, t: PType, info: TLineInfo, owner: TSymKind) =
|
||||
if t != nil:
|
||||
var s = newSym(skResult, getIdent"result", getCurrOwner())
|
||||
s.info = info
|
||||
s.typ = t
|
||||
incl(s.flags, sfUsed)
|
||||
addDecl(c, s)
|
||||
addParamOrResult(c, s, owner)
|
||||
c.p.resultSym = s
|
||||
|
||||
proc addResultNode(c: PContext, n: PNode) =
|
||||
@@ -653,7 +653,7 @@ proc semLambda(c: PContext, n: PNode): PNode =
|
||||
if sfImportc in s.flags:
|
||||
LocalError(n.sons[bodyPos].info, errImplOfXNotAllowed, s.name.s)
|
||||
pushProcCon(c, s)
|
||||
addResult(c, s.typ.sons[0], n.info)
|
||||
addResult(c, s.typ.sons[0], n.info, skProc)
|
||||
n.sons[bodyPos] = semStmtScope(c, n.sons[bodyPos])
|
||||
addResultNode(c, n)
|
||||
popProcCon(c)
|
||||
@@ -717,7 +717,7 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind,
|
||||
openScope(c.tab) # open scope for old (correct) parameter symbols
|
||||
if proto.ast.sons[genericParamsPos].kind != nkEmpty:
|
||||
addGenericParamListToScope(c, proto.ast.sons[genericParamsPos])
|
||||
addParams(c, proto.typ.n)
|
||||
addParams(c, proto.typ.n, proto.kind)
|
||||
proto.info = s.info # more accurate line information
|
||||
s.typ = proto.typ
|
||||
s = proto
|
||||
@@ -737,7 +737,7 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind,
|
||||
ParamsTypeCheck(c, s.typ)
|
||||
pushProcCon(c, s)
|
||||
if s.typ.sons[0] != nil and kind != skIterator:
|
||||
addResult(c, s.typ.sons[0], n.info)
|
||||
addResult(c, s.typ.sons[0], n.info, kind)
|
||||
if sfImportc notin s.flags:
|
||||
# no semantic checking for importc:
|
||||
n.sons[bodyPos] = semStmtScope(c, n.sons[bodyPos])
|
||||
|
||||
@@ -510,9 +510,18 @@ proc paramType(c: PContext, n, genericParams: PNode, cl: var TIntSet): PType =
|
||||
if genericParams != nil and sonsLen(genericParams) == 0:
|
||||
result = addTypeVarsOfGenericBody(c, result, genericParams, cl)
|
||||
|
||||
proc addParamOrResult(c: PContext, param: PSym, kind: TSymKind) =
|
||||
if kind == skMacro and param.typ.kind in {tyTypeDesc, tyExpr, tyStmt}:
|
||||
let nn = getSysSym"PNimrodNode"
|
||||
var a = copySym(param)
|
||||
a.typ = nn.typ
|
||||
addDecl(c, a)
|
||||
else:
|
||||
addDecl(c, param)
|
||||
|
||||
proc semProcTypeNode(c: PContext, n, genericParams: PNode,
|
||||
prev: PType): PType =
|
||||
var
|
||||
prev: PType, kind: TSymKind): PType =
|
||||
var
|
||||
def, res: PNode
|
||||
typ: PType
|
||||
cl: TIntSet
|
||||
@@ -568,7 +577,7 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode,
|
||||
LocalError(a.sons[j].info, errAttemptToRedefine, arg.name.s)
|
||||
addSon(result.n, newSymNode(arg))
|
||||
addSon(result, typ)
|
||||
addDecl(c, arg)
|
||||
addParamOrResult(c, arg, kind)
|
||||
|
||||
if n.sons[0].kind != nkEmpty:
|
||||
var r = paramType(c, n.sons[0], genericParams, cl)
|
||||
@@ -717,7 +726,7 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
|
||||
of nkProcTy:
|
||||
checkSonsLen(n, 2)
|
||||
openScope(c.tab)
|
||||
result = semProcTypeNode(c, n.sons[0], nil, prev)
|
||||
result = semProcTypeNode(c, n.sons[0], nil, prev, skProc)
|
||||
# dummy symbol for `pragma`:
|
||||
var s = newSymS(skProc, newIdentNode(getIdent("dummy"), n.info), c)
|
||||
s.typ = result
|
||||
@@ -769,6 +778,7 @@ proc processMagicType(c: PContext, m: PSym) =
|
||||
of mSet: setMagicType(m, tySet, 0)
|
||||
of mSeq: setMagicType(m, tySequence, 0)
|
||||
of mOrdinal: setMagicType(m, tyOrdinal, 0)
|
||||
of mPNimrodNode: nil
|
||||
else: GlobalError(m.info, errTypeExpected)
|
||||
|
||||
proc newConstraint(c: PContext, k: TTypeKind): PType =
|
||||
|
||||
@@ -87,10 +87,6 @@ type
|
||||
## represents a Nimrod *symbol* in the compiler; a *symbol* is a looked-up
|
||||
## *ident*.
|
||||
|
||||
TNimrodNode {.final.} = object
|
||||
PNimrodNode* {.magic: "PNimrodNode".} = ref TNimrodNode
|
||||
## represents a Nimrod AST node. Macros operate on this type.
|
||||
|
||||
const
|
||||
nnkLiterals* = {nnkCharLit..nnkNilLit}
|
||||
nnkCallKinds* = {nnkCall, nnkInfix, nnkPrefix, nnkPostfix, nnkCommand,
|
||||
|
||||
@@ -2220,6 +2220,11 @@ proc shallow*(s: var string) {.noSideEffect, inline.} =
|
||||
# const res = e
|
||||
# res
|
||||
|
||||
type
|
||||
TNimrodNode {.final.} = object
|
||||
PNimrodNode* {.magic: "PNimrodNode".} = ref TNimrodNode
|
||||
## represents a Nimrod AST node. Macros operate on this type.
|
||||
|
||||
template eval*(blk: stmt): stmt =
|
||||
## executes a block of code at compile time just as if it was a macro
|
||||
## optonally, the block can return an AST tree that will replace the
|
||||
|
||||
Reference in New Issue
Block a user