diff options
Diffstat (limited to 'compiler/semdata.nim')
-rw-r--r-- | compiler/semdata.nim | 53 |
1 files changed, 28 insertions, 25 deletions
diff --git a/compiler/semdata.nim b/compiler/semdata.nim index 62be471f7..12ac19ca3 100644 --- a/compiler/semdata.nim +++ b/compiler/semdata.nim @@ -14,7 +14,7 @@ import wordrecg, ropes, msgs, platform, os, condsyms, idents, renderer, types, extccomp, math, magicsys, nversion, nimsets, parser, times, passes, rodread, vmdef, - modulegraphs + modulegraphs, configuration type TOptionEntry* = object # entries to put on a stack for pragma parsing @@ -140,6 +140,8 @@ type # would otherwise fail. runnableExamples*: PNode +template config*(c: PContext): ConfigRef = c.graph.config + proc makeInstPair*(s: PSym, inst: PInstantiation): TInstantiationPair = result.genericSym = s result.inst = inst @@ -165,7 +167,7 @@ proc pushOwner*(c: PContext; owner: PSym) = proc popOwner*(c: PContext) = var length = len(c.graph.owners) if length > 0: setLen(c.graph.owners, length - 1) - else: internalError("popOwner") + else: internalError(c.config, "popOwner") proc lastOptionEntry*(c: PContext): POptionEntry = result = c.optionStack[^1] @@ -201,19 +203,19 @@ proc considerGenSyms*(c: PContext; n: PNode) = for i in 0..<n.safeLen: considerGenSyms(c, n.sons[i]) -proc newOptionEntry*(): POptionEntry = +proc newOptionEntry*(conf: ConfigRef): POptionEntry = new(result) - result.options = gOptions + result.options = conf.options result.defaultCC = ccDefault result.dynlib = nil - result.notes = gNotes + result.notes = conf.notes proc newContext*(graph: ModuleGraph; module: PSym; cache: IdentCache): PContext = new(result) result.ambiguousSymbols = initIntSet() result.optionStack = @[] result.libs = @[] - result.optionStack.add(newOptionEntry()) + result.optionStack.add(newOptionEntry(graph.config)) result.module = module result.friendModules = @[module] result.converters = @[] @@ -256,7 +258,7 @@ proc newTypeS*(kind: TTypeKind, c: PContext): PType = proc makePtrType*(c: PContext, baseType: PType): PType = result = newTypeS(tyPtr, c) - addSonSkipIntLit(result, baseType.assertNotNil) + addSonSkipIntLit(result, baseType) proc makeTypeWithModifier*(c: PContext, modifier: TTypeKind, @@ -267,25 +269,26 @@ proc makeTypeWithModifier*(c: PContext, result = baseType else: result = newTypeS(modifier, c) - addSonSkipIntLit(result, baseType.assertNotNil) + addSonSkipIntLit(result, baseType) proc makeVarType*(c: PContext, baseType: PType; kind = tyVar): PType = if baseType.kind == kind: result = baseType else: result = newTypeS(kind, c) - addSonSkipIntLit(result, baseType.assertNotNil) + addSonSkipIntLit(result, baseType) proc makeTypeDesc*(c: PContext, typ: PType): PType = if typ.kind == tyTypeDesc: result = typ else: result = newTypeS(tyTypeDesc, c) - result.addSonSkipIntLit(typ.assertNotNil) + result.addSonSkipIntLit(typ) proc makeTypeSymNode*(c: PContext, typ: PType, info: TLineInfo): PNode = let typedesc = makeTypeDesc(c, typ) - let sym = newSym(skType, c.cache.idAnon, getCurrOwner(c), info).linkTo(typedesc) + let sym = newSym(skType, c.cache.idAnon, getCurrOwner(c), info, + c.config.options).linkTo(typedesc) return newSymNode(sym, info) proc makeTypeFromExpr*(c: PContext, n: PNode): PType = @@ -340,21 +343,20 @@ proc makeNotType*(c: PContext, t1: PType): PType = result.flags.incl(t1.flags * {tfHasStatic}) result.flags.incl tfHasMeta -proc nMinusOne*(n: PNode): PNode = +proc nMinusOne(c: PContext; n: PNode): PNode = result = newNode(nkCall, n.info, @[ - newSymNode(getSysMagic("pred", mPred)), - n]) + newSymNode(getSysMagic(c.graph, n.info, "pred", mPred)), n]) # Remember to fix the procs below this one when you make changes! proc makeRangeWithStaticExpr*(c: PContext, n: PNode): PType = - let intType = getSysType(tyInt) + let intType = getSysType(c.graph, n.info, tyInt) result = newTypeS(tyRange, c) result.sons = @[intType] if n.typ != nil and n.typ.n == nil: result.flags.incl tfUnresolved result.n = newNode(nkRange, n.info, @[ newIntTypeNode(nkIntLit, 0, intType), - makeStaticExpr(c, n.nMinusOne)]) + makeStaticExpr(c, nMinusOne(c, n))]) template rangeHasUnresolvedStatic*(t: PType): bool = tfUnresolved in t.flags @@ -373,7 +375,8 @@ proc fillTypeS*(dest: PType, kind: TTypeKind, c: PContext) = dest.size = - 1 proc makeRangeType*(c: PContext; first, last: BiggestInt; - info: TLineInfo; intType = getSysType(tyInt)): PType = + info: TLineInfo; intType: PType = nil): PType = + let intType = if intType != nil: intType else: getSysType(c.graph, info, tyInt) var n = newNodeI(nkRange, info) addSon(n, newIntTypeNode(nkIntLit, first, intType)) addSon(n, newIntTypeNode(nkIntLit, last, intType)) @@ -386,17 +389,17 @@ proc markIndirect*(c: PContext, s: PSym) {.inline.} = incl(s.flags, sfAddrTaken) # XXX add to 'c' for global analysis -proc illFormedAst*(n: PNode) = - globalError(n.info, errIllFormedAstX, renderTree(n, {renderNoComments})) +proc illFormedAst*(n: PNode; conf: ConfigRef) = + globalError(conf, n.info, errIllFormedAstX, renderTree(n, {renderNoComments})) -proc illFormedAstLocal*(n: PNode) = - localError(n.info, errIllFormedAstX, renderTree(n, {renderNoComments})) +proc illFormedAstLocal*(n: PNode; conf: ConfigRef) = + localError(conf, n.info, errIllFormedAstX, renderTree(n, {renderNoComments})) -proc checkSonsLen*(n: PNode, length: int) = - if sonsLen(n) != length: illFormedAst(n) +proc checkSonsLen*(n: PNode, length: int; conf: ConfigRef) = + if sonsLen(n) != length: illFormedAst(n, conf) -proc checkMinSonsLen*(n: PNode, length: int) = - if sonsLen(n) < length: illFormedAst(n) +proc checkMinSonsLen*(n: PNode, length: int; conf: ConfigRef) = + if sonsLen(n) < length: illFormedAst(n, conf) proc isTopLevel*(c: PContext): bool {.inline.} = result = c.currentScope.depthLevel <= 2 |