semgnrc.nim 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. #
  2. #
  3. # The Nim Compiler
  4. # (c) Copyright 2015 Andreas Rumpf
  5. #
  6. # See the file "copying.txt", included in this
  7. # distribution, for details about the copyright.
  8. #
  9. # This implements the first pass over the generic body; it resolves some
  10. # symbols. Thus for generics there is a two-phase symbol lookup just like
  11. # in C++.
  12. # A problem is that it cannot be detected if the symbol is introduced
  13. # as in ``var x = ...`` or used because macros/templates can hide this!
  14. # So we have to eval templates/macros right here so that symbol
  15. # lookup can be accurate.
  16. # included from sem.nim
  17. proc getIdentNode(c: PContext; n: PNode): PNode =
  18. case n.kind
  19. of nkPostfix: result = getIdentNode(c, n.sons[1])
  20. of nkPragmaExpr: result = getIdentNode(c, n.sons[0])
  21. of nkIdent, nkAccQuoted, nkSym: result = n
  22. else:
  23. illFormedAst(n, c.config)
  24. result = n
  25. type
  26. GenericCtx = object
  27. toMixin: IntSet
  28. cursorInBody: bool # only for nimsuggest
  29. bracketExpr: PNode
  30. TSemGenericFlag = enum
  31. withinBind,
  32. withinTypeDesc,
  33. withinMixin,
  34. withinConcept
  35. TSemGenericFlags = set[TSemGenericFlag]
  36. proc semGenericStmt(c: PContext, n: PNode,
  37. flags: TSemGenericFlags, ctx: var GenericCtx): PNode
  38. proc semGenericStmtScope(c: PContext, n: PNode,
  39. flags: TSemGenericFlags,
  40. ctx: var GenericCtx): PNode =
  41. openScope(c)
  42. result = semGenericStmt(c, n, flags, ctx)
  43. closeScope(c)
  44. template macroToExpand(s): untyped =
  45. s.kind in {skMacro, skTemplate} and (s.typ.len == 1 or sfAllUntyped in s.flags)
  46. template macroToExpandSym(s): untyped =
  47. sfCustomPragma notin s.flags and s.kind in {skMacro, skTemplate} and
  48. (s.typ.len == 1) and not fromDotExpr
  49. template isMixedIn(sym): bool =
  50. let s = sym
  51. s.name.id in ctx.toMixin or (withinConcept in flags and
  52. s.magic == mNone and
  53. s.kind in OverloadableSyms)
  54. proc semGenericStmtSymbol(c: PContext, n: PNode, s: PSym,
  55. ctx: var GenericCtx; flags: TSemGenericFlags,
  56. fromDotExpr=false): PNode =
  57. semIdeForTemplateOrGenericCheck(c.config, n, ctx.cursorInBody)
  58. incl(s.flags, sfUsed)
  59. case s.kind
  60. of skUnknown:
  61. # Introduced in this pass! Leave it as an identifier.
  62. result = n
  63. of skProc, skFunc, skMethod, skIterator, skConverter, skModule:
  64. result = symChoice(c, n, s, scOpen)
  65. of skTemplate:
  66. if macroToExpandSym(s):
  67. styleCheckUse(n.info, s)
  68. result = semTemplateExpr(c, n, s, {efNoSemCheck})
  69. result = semGenericStmt(c, result, {}, ctx)
  70. else:
  71. result = symChoice(c, n, s, scOpen)
  72. of skMacro:
  73. if macroToExpandSym(s):
  74. styleCheckUse(n.info, s)
  75. result = semMacroExpr(c, n, n, s, {efNoSemCheck})
  76. result = semGenericStmt(c, result, {}, ctx)
  77. else:
  78. result = symChoice(c, n, s, scOpen)
  79. of skGenericParam:
  80. if s.typ != nil and s.typ.kind == tyStatic:
  81. if s.typ.n != nil:
  82. result = s.typ.n
  83. else:
  84. result = n
  85. else:
  86. result = newSymNodeTypeDesc(s, n.info)
  87. styleCheckUse(n.info, s)
  88. of skParam:
  89. result = n
  90. styleCheckUse(n.info, s)
  91. of skType:
  92. if (s.typ != nil) and
  93. (s.typ.flags * {tfGenericTypeParam, tfImplicitTypeParam} == {}):
  94. result = newSymNodeTypeDesc(s, n.info)
  95. else:
  96. result = n
  97. styleCheckUse(n.info, s)
  98. else:
  99. result = newSymNode(s, n.info)
  100. styleCheckUse(n.info, s)
  101. proc lookup(c: PContext, n: PNode, flags: TSemGenericFlags,
  102. ctx: var GenericCtx): PNode =
  103. result = n
  104. let ident = considerQuotedIdent(c, n)
  105. var s = searchInScopes(c, ident).skipAlias(n, c.config)
  106. if s == nil:
  107. s = strTableGet(c.pureEnumFields, ident)
  108. if s != nil and contains(c.ambiguousSymbols, s.id):
  109. s = nil
  110. if s == nil:
  111. if ident.id notin ctx.toMixin and withinMixin notin flags:
  112. errorUndeclaredIdentifier(c, n.info, ident.s)
  113. else:
  114. if withinBind in flags:
  115. result = symChoice(c, n, s, scClosed)
  116. elif s.isMixedIn:
  117. result = symChoice(c, n, s, scForceOpen)
  118. else:
  119. result = semGenericStmtSymbol(c, n, s, ctx, flags)
  120. # else: leave as nkIdent
  121. proc newDot(n, b: PNode): PNode =
  122. result = newNodeI(nkDotExpr, n.info)
  123. result.add(n.sons[0])
  124. result.add(b)
  125. proc fuzzyLookup(c: PContext, n: PNode, flags: TSemGenericFlags,
  126. ctx: var GenericCtx; isMacro: var bool): PNode =
  127. assert n.kind == nkDotExpr
  128. semIdeForTemplateOrGenericCheck(c.config, n, ctx.cursorInBody)
  129. let luf = if withinMixin notin flags: {checkUndeclared, checkModule} else: {checkModule}
  130. var s = qualifiedLookUp(c, n, luf)
  131. if s != nil:
  132. result = semGenericStmtSymbol(c, n, s, ctx, flags)
  133. else:
  134. n.sons[0] = semGenericStmt(c, n.sons[0], flags, ctx)
  135. result = n
  136. let n = n[1]
  137. let ident = considerQuotedIdent(c, n)
  138. var s = searchInScopes(c, ident).skipAlias(n, c.config)
  139. if s != nil and s.kind in routineKinds:
  140. isMacro = s.kind in {skTemplate, skMacro}
  141. if withinBind in flags:
  142. result = newDot(result, symChoice(c, n, s, scClosed))
  143. elif s.isMixedIn:
  144. result = newDot(result, symChoice(c, n, s, scForceOpen))
  145. else:
  146. let syms = semGenericStmtSymbol(c, n, s, ctx, flags, fromDotExpr=true)
  147. if syms.kind == nkSym:
  148. let choice = symChoice(c, n, s, scForceOpen)
  149. choice.kind = nkClosedSymChoice
  150. result = newDot(result, choice)
  151. else:
  152. result = newDot(result, syms)
  153. proc addTempDecl(c: PContext; n: PNode; kind: TSymKind) =
  154. let s = newSymS(skUnknown, getIdentNode(c, n), c)
  155. addPrelimDecl(c, s)
  156. styleCheckDef(c.config, n.info, s, kind)
  157. proc semGenericStmt(c: PContext, n: PNode,
  158. flags: TSemGenericFlags, ctx: var GenericCtx): PNode =
  159. result = n
  160. when defined(nimsuggest):
  161. if withinTypeDesc in flags: inc c.inTypeContext
  162. #if conf.cmd == cmdIdeTools: suggestStmt(c, n)
  163. semIdeForTemplateOrGenericCheck(c.config, n, ctx.cursorInBody)
  164. case n.kind
  165. of nkIdent, nkAccQuoted:
  166. result = lookup(c, n, flags, ctx)
  167. of nkDotExpr:
  168. #let luf = if withinMixin notin flags: {checkUndeclared} else: {}
  169. #var s = qualifiedLookUp(c, n, luf)
  170. #if s != nil: result = semGenericStmtSymbol(c, n, s)
  171. # XXX for example: ``result.add`` -- ``add`` needs to be looked up here...
  172. var dummy: bool
  173. result = fuzzyLookup(c, n, flags, ctx, dummy)
  174. of nkSym:
  175. let a = n.sym
  176. let b = getGenSym(c, a)
  177. if b != a: n.sym = b
  178. of nkEmpty, succ(nkSym)..nkNilLit, nkComesFrom:
  179. # see tests/compile/tgensymgeneric.nim:
  180. # We need to open the gensym'ed symbol again so that the instantiation
  181. # creates a fresh copy; but this is wrong the very first reason for gensym
  182. # is that scope rules cannot be used! So simply removing 'sfGenSym' does
  183. # not work. Copying the symbol does not work either because we're already
  184. # the owner of the symbol! What we need to do is to copy the symbol
  185. # in the generic instantiation process...
  186. discard
  187. of nkBind:
  188. result = semGenericStmt(c, n.sons[0], flags+{withinBind}, ctx)
  189. of nkMixinStmt:
  190. result = semMixinStmt(c, n, ctx.toMixin)
  191. of nkCall, nkHiddenCallConv, nkInfix, nkPrefix, nkCommand, nkCallStrLit:
  192. # check if it is an expression macro:
  193. checkMinSonsLen(n, 1, c.config)
  194. let fn = n.sons[0]
  195. var s = qualifiedLookUp(c, fn, {})
  196. if s == nil and
  197. {withinMixin, withinConcept}*flags == {} and
  198. fn.kind in {nkIdent, nkAccQuoted} and
  199. considerQuotedIdent(c, fn).id notin ctx.toMixin:
  200. errorUndeclaredIdentifier(c, n.info, fn.renderTree)
  201. var first = int ord(withinConcept in flags)
  202. var mixinContext = false
  203. if s != nil:
  204. incl(s.flags, sfUsed)
  205. mixinContext = s.magic in {mDefined, mDefinedInScope, mCompiles}
  206. let sc = symChoice(c, fn, s, if s.isMixedIn: scForceOpen else: scOpen)
  207. case s.kind
  208. of skMacro:
  209. if macroToExpand(s) and sc.safeLen <= 1:
  210. styleCheckUse(fn.info, s)
  211. result = semMacroExpr(c, n, n, s, {efNoSemCheck})
  212. result = semGenericStmt(c, result, flags, ctx)
  213. else:
  214. n.sons[0] = sc
  215. result = n
  216. mixinContext = true
  217. of skTemplate:
  218. if macroToExpand(s) and sc.safeLen <= 1:
  219. styleCheckUse(fn.info, s)
  220. result = semTemplateExpr(c, n, s, {efNoSemCheck})
  221. result = semGenericStmt(c, result, flags, ctx)
  222. else:
  223. n.sons[0] = sc
  224. result = n
  225. # BUGFIX: we must not return here, we need to do first phase of
  226. # symbol lookup. Also since templates and macros can do scope injections
  227. # we need to put the ``c`` in ``t(c)`` in a mixin context to prevent
  228. # the famous "undeclared identifier: it" bug:
  229. mixinContext = true
  230. of skUnknown, skParam:
  231. # Leave it as an identifier.
  232. discard
  233. of skProc, skFunc, skMethod, skIterator, skConverter, skModule:
  234. result.sons[0] = sc
  235. first = 1
  236. # We're not interested in the example code during this pass so let's
  237. # skip it
  238. if s.magic == mRunnableExamples:
  239. inc first
  240. of skGenericParam:
  241. result.sons[0] = newSymNodeTypeDesc(s, fn.info)
  242. styleCheckUse(fn.info, s)
  243. first = 1
  244. of skType:
  245. # bad hack for generics:
  246. if (s.typ != nil) and (s.typ.kind != tyGenericParam):
  247. result.sons[0] = newSymNodeTypeDesc(s, fn.info)
  248. styleCheckUse(fn.info, s)
  249. first = 1
  250. else:
  251. result.sons[0] = newSymNode(s, fn.info)
  252. styleCheckUse(fn.info, s)
  253. first = 1
  254. elif fn.kind == nkDotExpr:
  255. result.sons[0] = fuzzyLookup(c, fn, flags, ctx, mixinContext)
  256. first = 1
  257. # Consider 'when declared(globalsSlot): ThreadVarSetValue(globalsSlot, ...)'
  258. # in threads.nim: the subtle preprocessing here binds 'globalsSlot' which
  259. # is not exported and yet the generic 'threadProcWrapper' works correctly.
  260. let flags = if mixinContext: flags+{withinMixin} else: flags
  261. for i in countup(first, sonsLen(result) - 1):
  262. result.sons[i] = semGenericStmt(c, result.sons[i], flags, ctx)
  263. of nkCurlyExpr:
  264. result = newNodeI(nkCall, n.info)
  265. result.add newIdentNode(getIdent(c.cache, "{}"), n.info)
  266. for i in 0 ..< n.len: result.add(n[i])
  267. result = semGenericStmt(c, result, flags, ctx)
  268. of nkBracketExpr:
  269. result = newNodeI(nkCall, n.info)
  270. result.add newIdentNode(getIdent(c.cache, "[]"), n.info)
  271. for i in 0 ..< n.len: result.add(n[i])
  272. withBracketExpr ctx, n.sons[0]:
  273. result = semGenericStmt(c, result, flags, ctx)
  274. of nkAsgn, nkFastAsgn:
  275. checkSonsLen(n, 2, c.config)
  276. let a = n.sons[0]
  277. let b = n.sons[1]
  278. let k = a.kind
  279. case k
  280. of nkCurlyExpr:
  281. result = newNodeI(nkCall, n.info)
  282. result.add newIdentNode(getIdent(c.cache, "{}="), n.info)
  283. for i in 0 ..< a.len: result.add(a[i])
  284. result.add(b)
  285. result = semGenericStmt(c, result, flags, ctx)
  286. of nkBracketExpr:
  287. result = newNodeI(nkCall, n.info)
  288. result.add newIdentNode(getIdent(c.cache, "[]="), n.info)
  289. for i in 0 ..< a.len: result.add(a[i])
  290. result.add(b)
  291. withBracketExpr ctx, a.sons[0]:
  292. result = semGenericStmt(c, result, flags, ctx)
  293. else:
  294. for i in countup(0, sonsLen(n) - 1):
  295. result.sons[i] = semGenericStmt(c, n.sons[i], flags, ctx)
  296. of nkIfStmt:
  297. for i in countup(0, sonsLen(n)-1):
  298. n.sons[i] = semGenericStmtScope(c, n.sons[i], flags, ctx)
  299. of nkWhenStmt:
  300. for i in countup(0, sonsLen(n)-1):
  301. n.sons[i] = semGenericStmt(c, n.sons[i], flags+{withinMixin}, ctx)
  302. of nkWhileStmt:
  303. openScope(c)
  304. for i in countup(0, sonsLen(n)-1):
  305. n.sons[i] = semGenericStmt(c, n.sons[i], flags, ctx)
  306. closeScope(c)
  307. of nkCaseStmt:
  308. openScope(c)
  309. n.sons[0] = semGenericStmt(c, n.sons[0], flags, ctx)
  310. for i in countup(1, sonsLen(n)-1):
  311. var a = n.sons[i]
  312. checkMinSonsLen(a, 1, c.config)
  313. var L = sonsLen(a)
  314. for j in countup(0, L-2):
  315. a.sons[j] = semGenericStmt(c, a.sons[j], flags, ctx)
  316. a.sons[L - 1] = semGenericStmtScope(c, a.sons[L-1], flags, ctx)
  317. closeScope(c)
  318. of nkForStmt, nkParForStmt:
  319. var L = sonsLen(n)
  320. openScope(c)
  321. n.sons[L - 2] = semGenericStmt(c, n.sons[L-2], flags, ctx)
  322. for i in countup(0, L - 3):
  323. addTempDecl(c, n.sons[i], skForVar)
  324. openScope(c)
  325. n.sons[L - 1] = semGenericStmt(c, n.sons[L-1], flags, ctx)
  326. closeScope(c)
  327. closeScope(c)
  328. of nkBlockStmt, nkBlockExpr, nkBlockType:
  329. checkSonsLen(n, 2, c.config)
  330. openScope(c)
  331. if n.sons[0].kind != nkEmpty:
  332. addTempDecl(c, n.sons[0], skLabel)
  333. n.sons[1] = semGenericStmt(c, n.sons[1], flags, ctx)
  334. closeScope(c)
  335. of nkTryStmt:
  336. checkMinSonsLen(n, 2, c.config)
  337. n.sons[0] = semGenericStmtScope(c, n.sons[0], flags, ctx)
  338. for i in countup(1, sonsLen(n)-1):
  339. var a = n.sons[i]
  340. checkMinSonsLen(a, 1, c.config)
  341. var L = sonsLen(a)
  342. openScope(c)
  343. for j in countup(0, L-2):
  344. if a.sons[j].isInfixAs():
  345. addTempDecl(c, getIdentNode(c, a.sons[j][2]), skLet)
  346. a.sons[j].sons[1] = semGenericStmt(c, a.sons[j][1], flags+{withinTypeDesc}, ctx)
  347. else:
  348. a.sons[j] = semGenericStmt(c, a.sons[j], flags+{withinTypeDesc}, ctx)
  349. a.sons[L-1] = semGenericStmtScope(c, a.sons[L-1], flags, ctx)
  350. closeScope(c)
  351. of nkVarSection, nkLetSection:
  352. for i in countup(0, sonsLen(n) - 1):
  353. var a = n.sons[i]
  354. if a.kind == nkCommentStmt: continue
  355. if (a.kind != nkIdentDefs) and (a.kind != nkVarTuple): illFormedAst(a, c.config)
  356. checkMinSonsLen(a, 3, c.config)
  357. var L = sonsLen(a)
  358. a.sons[L-2] = semGenericStmt(c, a.sons[L-2], flags+{withinTypeDesc}, ctx)
  359. a.sons[L-1] = semGenericStmt(c, a.sons[L-1], flags, ctx)
  360. for j in countup(0, L-3):
  361. addTempDecl(c, getIdentNode(c, a.sons[j]), skVar)
  362. of nkGenericParams:
  363. for i in countup(0, sonsLen(n) - 1):
  364. var a = n.sons[i]
  365. if (a.kind != nkIdentDefs): illFormedAst(a, c.config)
  366. checkMinSonsLen(a, 3, c.config)
  367. var L = sonsLen(a)
  368. a.sons[L-2] = semGenericStmt(c, a.sons[L-2], flags+{withinTypeDesc}, ctx)
  369. # do not perform symbol lookup for default expressions
  370. for j in countup(0, L-3):
  371. addTempDecl(c, getIdentNode(c, a.sons[j]), skType)
  372. of nkConstSection:
  373. for i in countup(0, sonsLen(n) - 1):
  374. var a = n.sons[i]
  375. if a.kind == nkCommentStmt: continue
  376. if (a.kind != nkConstDef): illFormedAst(a, c.config)
  377. checkSonsLen(a, 3, c.config)
  378. addTempDecl(c, getIdentNode(c, a.sons[0]), skConst)
  379. a.sons[1] = semGenericStmt(c, a.sons[1], flags+{withinTypeDesc}, ctx)
  380. a.sons[2] = semGenericStmt(c, a.sons[2], flags, ctx)
  381. of nkTypeSection:
  382. for i in countup(0, sonsLen(n) - 1):
  383. var a = n.sons[i]
  384. if a.kind == nkCommentStmt: continue
  385. if (a.kind != nkTypeDef): illFormedAst(a, c.config)
  386. checkSonsLen(a, 3, c.config)
  387. addTempDecl(c, getIdentNode(c, a.sons[0]), skType)
  388. for i in countup(0, sonsLen(n) - 1):
  389. var a = n.sons[i]
  390. if a.kind == nkCommentStmt: continue
  391. if (a.kind != nkTypeDef): illFormedAst(a, c.config)
  392. checkSonsLen(a, 3, c.config)
  393. if a.sons[1].kind != nkEmpty:
  394. openScope(c)
  395. a.sons[1] = semGenericStmt(c, a.sons[1], flags, ctx)
  396. a.sons[2] = semGenericStmt(c, a.sons[2], flags+{withinTypeDesc}, ctx)
  397. closeScope(c)
  398. else:
  399. a.sons[2] = semGenericStmt(c, a.sons[2], flags+{withinTypeDesc}, ctx)
  400. of nkEnumTy:
  401. if n.sonsLen > 0:
  402. if n.sons[0].kind != nkEmpty:
  403. n.sons[0] = semGenericStmt(c, n.sons[0], flags+{withinTypeDesc}, ctx)
  404. for i in countup(1, sonsLen(n) - 1):
  405. var a: PNode
  406. case n.sons[i].kind
  407. of nkEnumFieldDef: a = n.sons[i].sons[0]
  408. of nkIdent: a = n.sons[i]
  409. else: illFormedAst(n, c.config)
  410. addDecl(c, newSymS(skUnknown, getIdentNode(c, a), c))
  411. of nkObjectTy, nkTupleTy, nkTupleClassTy:
  412. discard
  413. of nkFormalParams:
  414. checkMinSonsLen(n, 1, c.config)
  415. if n.sons[0].kind != nkEmpty:
  416. n.sons[0] = semGenericStmt(c, n.sons[0], flags+{withinTypeDesc}, ctx)
  417. for i in countup(1, sonsLen(n) - 1):
  418. var a = n.sons[i]
  419. if (a.kind != nkIdentDefs): illFormedAst(a, c.config)
  420. checkMinSonsLen(a, 3, c.config)
  421. var L = sonsLen(a)
  422. a.sons[L-2] = semGenericStmt(c, a.sons[L-2], flags+{withinTypeDesc}, ctx)
  423. a.sons[L-1] = semGenericStmt(c, a.sons[L-1], flags, ctx)
  424. for j in countup(0, L-3):
  425. addTempDecl(c, getIdentNode(c, a.sons[j]), skParam)
  426. of nkProcDef, nkMethodDef, nkConverterDef, nkMacroDef, nkTemplateDef,
  427. nkFuncDef, nkIteratorDef, nkLambdaKinds:
  428. checkSonsLen(n, bodyPos + 1, c.config)
  429. if n.sons[namePos].kind != nkEmpty:
  430. addTempDecl(c, getIdentNode(c, n.sons[0]), skProc)
  431. openScope(c)
  432. n.sons[genericParamsPos] = semGenericStmt(c, n.sons[genericParamsPos],
  433. flags, ctx)
  434. if n.sons[paramsPos].kind != nkEmpty:
  435. if n.sons[paramsPos].sons[0].kind != nkEmpty:
  436. addPrelimDecl(c, newSym(skUnknown, getIdent(c.cache, "result"), nil, n.info))
  437. n.sons[paramsPos] = semGenericStmt(c, n.sons[paramsPos], flags, ctx)
  438. n.sons[pragmasPos] = semGenericStmt(c, n.sons[pragmasPos], flags, ctx)
  439. var body: PNode
  440. if n.sons[namePos].kind == nkSym:
  441. let s = n.sons[namePos].sym
  442. if sfGenSym in s.flags and s.ast == nil:
  443. body = n.sons[bodyPos]
  444. else:
  445. body = s.getBody
  446. else: body = n.sons[bodyPos]
  447. n.sons[bodyPos] = semGenericStmtScope(c, body, flags, ctx)
  448. closeScope(c)
  449. of nkPragma, nkPragmaExpr: discard
  450. of nkExprColonExpr, nkExprEqExpr:
  451. checkMinSonsLen(n, 2, c.config)
  452. result.sons[1] = semGenericStmt(c, n.sons[1], flags, ctx)
  453. else:
  454. for i in countup(0, sonsLen(n) - 1):
  455. result.sons[i] = semGenericStmt(c, n.sons[i], flags, ctx)
  456. when defined(nimsuggest):
  457. if withinTypeDesc in flags: dec c.inTypeContext
  458. proc semGenericStmt(c: PContext, n: PNode): PNode =
  459. var ctx: GenericCtx
  460. ctx.toMixin = initIntset()
  461. result = semGenericStmt(c, n, {}, ctx)
  462. semIdeForTemplateOrGeneric(c, result, ctx.cursorInBody)
  463. proc semConceptBody(c: PContext, n: PNode): PNode =
  464. var ctx: GenericCtx
  465. ctx.toMixin = initIntset()
  466. result = semGenericStmt(c, n, {withinConcept}, ctx)
  467. semIdeForTemplateOrGeneric(c, result, ctx.cursorInBody)