semgnrc.nim 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  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[1])
  20. of nkPragmaExpr: result = getIdentNode(c, n[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, toBind: 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. onUse(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. onUse(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, c.idgen, n.info)
  87. onUse(n.info, s)
  88. of skParam:
  89. result = n
  90. onUse(n.info, s)
  91. of skType:
  92. if (s.typ != nil) and
  93. (s.typ.flags * {tfGenericTypeParam, tfImplicitTypeParam} == {}):
  94. result = newSymNodeTypeDesc(s, c.idgen, n.info)
  95. else:
  96. result = n
  97. onUse(n.info, s)
  98. of skEnumField:
  99. result = symChoice(c, n, s, scOpen)
  100. else:
  101. result = newSymNode(s, n.info)
  102. onUse(n.info, s)
  103. proc lookup(c: PContext, n: PNode, flags: TSemGenericFlags,
  104. ctx: var GenericCtx): PNode =
  105. result = n
  106. let ident = considerQuotedIdent(c, n)
  107. var amb = false
  108. var s = searchInScopes(c, ident, amb).skipAlias(n, c.config)
  109. if s == nil:
  110. s = strTableGet(c.pureEnumFields, ident)
  111. #if s != nil and contains(c.ambiguousSymbols, s.id):
  112. # s = nil
  113. if s == nil:
  114. if ident.id notin ctx.toMixin and withinMixin notin flags:
  115. errorUndeclaredIdentifier(c, n.info, ident.s)
  116. else:
  117. if withinBind in flags or s.id in ctx.toBind:
  118. result = symChoice(c, n, s, scClosed)
  119. elif s.isMixedIn:
  120. result = symChoice(c, n, s, scForceOpen)
  121. else:
  122. result = semGenericStmtSymbol(c, n, s, ctx, flags)
  123. # else: leave as nkIdent
  124. proc newDot(n, b: PNode): PNode =
  125. result = newNodeI(nkDotExpr, n.info)
  126. result.add(n[0])
  127. result.add(b)
  128. proc fuzzyLookup(c: PContext, n: PNode, flags: TSemGenericFlags,
  129. ctx: var GenericCtx; isMacro: var bool): PNode =
  130. assert n.kind == nkDotExpr
  131. semIdeForTemplateOrGenericCheck(c.config, n, ctx.cursorInBody)
  132. let luf = if withinMixin notin flags: {checkUndeclared, checkModule} else: {checkModule}
  133. var s = qualifiedLookUp(c, n, luf)
  134. if s != nil:
  135. result = semGenericStmtSymbol(c, n, s, ctx, flags)
  136. else:
  137. n[0] = semGenericStmt(c, n[0], flags, ctx)
  138. result = n
  139. let n = n[1]
  140. let ident = considerQuotedIdent(c, n)
  141. var candidates = searchInScopesFilterBy(c, ident, routineKinds) # .skipAlias(n, c.config)
  142. if candidates.len > 0:
  143. let s = candidates[0] # XXX take into account the other candidates!
  144. isMacro = s.kind in {skTemplate, skMacro}
  145. if withinBind in flags or s.id in ctx.toBind:
  146. result = newDot(result, symChoice(c, n, s, scClosed))
  147. elif s.isMixedIn:
  148. result = newDot(result, symChoice(c, n, s, scForceOpen))
  149. else:
  150. let syms = semGenericStmtSymbol(c, n, s, ctx, flags, fromDotExpr=true)
  151. if syms.kind == nkSym:
  152. let choice = symChoice(c, n, s, scForceOpen)
  153. choice.transitionSonsKind(nkClosedSymChoice)
  154. result = newDot(result, choice)
  155. else:
  156. result = newDot(result, syms)
  157. proc addTempDecl(c: PContext; n: PNode; kind: TSymKind) =
  158. let s = newSymS(skUnknown, getIdentNode(c, n), c)
  159. addPrelimDecl(c, s)
  160. styleCheckDef(c, n.info, s, kind)
  161. onDef(n.info, s)
  162. proc semGenericStmt(c: PContext, n: PNode,
  163. flags: TSemGenericFlags, ctx: var GenericCtx): PNode =
  164. result = n
  165. when defined(nimsuggest):
  166. if withinTypeDesc in flags: inc c.inTypeContext
  167. #if conf.cmd == cmdIdeTools: suggestStmt(c, n)
  168. semIdeForTemplateOrGenericCheck(c.config, n, ctx.cursorInBody)
  169. case n.kind
  170. of nkIdent, nkAccQuoted:
  171. result = lookup(c, n, flags, ctx)
  172. if result != nil and result.kind == nkSym:
  173. assert result.sym != nil
  174. markUsed(c, n.info, result.sym)
  175. of nkDotExpr:
  176. #let luf = if withinMixin notin flags: {checkUndeclared} else: {}
  177. #var s = qualifiedLookUp(c, n, luf)
  178. #if s != nil: result = semGenericStmtSymbol(c, n, s)
  179. # XXX for example: ``result.add`` -- ``add`` needs to be looked up here...
  180. var dummy: bool
  181. result = fuzzyLookup(c, n, flags, ctx, dummy)
  182. of nkSym:
  183. let a = n.sym
  184. let b = getGenSym(c, a)
  185. if b != a: n.sym = b
  186. of nkEmpty, succ(nkSym)..nkNilLit, nkComesFrom:
  187. # see tests/compile/tgensymgeneric.nim:
  188. # We need to open the gensym'ed symbol again so that the instantiation
  189. # creates a fresh copy; but this is wrong the very first reason for gensym
  190. # is that scope rules cannot be used! So simply removing 'sfGenSym' does
  191. # not work. Copying the symbol does not work either because we're already
  192. # the owner of the symbol! What we need to do is to copy the symbol
  193. # in the generic instantiation process...
  194. discard
  195. of nkBind:
  196. result = semGenericStmt(c, n[0], flags+{withinBind}, ctx)
  197. of nkMixinStmt:
  198. result = semMixinStmt(c, n, ctx.toMixin)
  199. of nkBindStmt:
  200. result = semBindStmt(c, n, ctx.toBind)
  201. of nkCall, nkHiddenCallConv, nkInfix, nkPrefix, nkCommand, nkCallStrLit:
  202. # check if it is an expression macro:
  203. checkMinSonsLen(n, 1, c.config)
  204. let fn = n[0]
  205. var s = qualifiedLookUp(c, fn, {})
  206. if s == nil and
  207. {withinMixin, withinConcept}*flags == {} and
  208. fn.kind in {nkIdent, nkAccQuoted} and
  209. considerQuotedIdent(c, fn).id notin ctx.toMixin:
  210. errorUndeclaredIdentifier(c, n.info, fn.renderTree)
  211. var first = int ord(withinConcept in flags)
  212. var mixinContext = false
  213. if s != nil:
  214. incl(s.flags, sfUsed)
  215. mixinContext = s.magic in {mDefined, mDeclared, mDeclaredInScope, mCompiles, mAstToStr}
  216. let whichChoice = if s.id in ctx.toBind: scClosed
  217. elif s.isMixedIn: scForceOpen
  218. else: scOpen
  219. let sc = symChoice(c, fn, s, whichChoice)
  220. case s.kind
  221. of skMacro:
  222. if macroToExpand(s) and sc.safeLen <= 1:
  223. onUse(fn.info, s)
  224. result = semMacroExpr(c, n, n, s, {efNoSemCheck})
  225. result = semGenericStmt(c, result, flags, ctx)
  226. else:
  227. n[0] = sc
  228. result = n
  229. mixinContext = true
  230. of skTemplate:
  231. if macroToExpand(s) and sc.safeLen <= 1:
  232. onUse(fn.info, s)
  233. result = semTemplateExpr(c, n, s, {efNoSemCheck})
  234. result = semGenericStmt(c, result, flags, ctx)
  235. else:
  236. n[0] = sc
  237. result = n
  238. # BUGFIX: we must not return here, we need to do first phase of
  239. # symbol lookup. Also since templates and macros can do scope injections
  240. # we need to put the ``c`` in ``t(c)`` in a mixin context to prevent
  241. # the famous "undeclared identifier: it" bug:
  242. mixinContext = true
  243. of skUnknown, skParam:
  244. # Leave it as an identifier.
  245. discard
  246. of skProc, skFunc, skMethod, skIterator, skConverter, skModule:
  247. result[0] = sc
  248. first = 1
  249. # We're not interested in the example code during this pass so let's
  250. # skip it
  251. if s.magic == mRunnableExamples:
  252. first = result.safeLen # see trunnableexamples.fun3
  253. of skGenericParam:
  254. result[0] = newSymNodeTypeDesc(s, c.idgen, fn.info)
  255. onUse(fn.info, s)
  256. first = 1
  257. of skType:
  258. # bad hack for generics:
  259. if (s.typ != nil) and (s.typ.kind != tyGenericParam):
  260. result[0] = newSymNodeTypeDesc(s, c.idgen, fn.info)
  261. onUse(fn.info, s)
  262. first = 1
  263. else:
  264. result[0] = newSymNode(s, fn.info)
  265. onUse(fn.info, s)
  266. first = 1
  267. elif fn.kind == nkDotExpr:
  268. result[0] = fuzzyLookup(c, fn, flags, ctx, mixinContext)
  269. first = 1
  270. # Consider 'when declared(globalsSlot): ThreadVarSetValue(globalsSlot, ...)'
  271. # in threads.nim: the subtle preprocessing here binds 'globalsSlot' which
  272. # is not exported and yet the generic 'threadProcWrapper' works correctly.
  273. let flags = if mixinContext: flags+{withinMixin} else: flags
  274. for i in first..<result.safeLen:
  275. result[i] = semGenericStmt(c, result[i], flags, ctx)
  276. of nkCurlyExpr:
  277. result = newNodeI(nkCall, n.info)
  278. result.add newIdentNode(getIdent(c.cache, "{}"), n.info)
  279. for i in 0..<n.len: result.add(n[i])
  280. result = semGenericStmt(c, result, flags, ctx)
  281. of nkBracketExpr:
  282. result = newNodeI(nkCall, n.info)
  283. result.add newIdentNode(getIdent(c.cache, "[]"), n.info)
  284. for i in 0..<n.len: result.add(n[i])
  285. result = semGenericStmt(c, result, flags, ctx)
  286. of nkAsgn, nkFastAsgn, nkSinkAsgn:
  287. checkSonsLen(n, 2, c.config)
  288. let a = n[0]
  289. let b = n[1]
  290. let k = a.kind
  291. case k
  292. of nkCurlyExpr:
  293. result = newNodeI(nkCall, n.info)
  294. result.add newIdentNode(getIdent(c.cache, "{}="), n.info)
  295. for i in 0..<a.len: result.add(a[i])
  296. result.add(b)
  297. result = semGenericStmt(c, result, flags, ctx)
  298. of nkBracketExpr:
  299. result = newNodeI(nkCall, n.info)
  300. result.add newIdentNode(getIdent(c.cache, "[]="), n.info)
  301. for i in 0..<a.len: result.add(a[i])
  302. result.add(b)
  303. result = semGenericStmt(c, result, flags, ctx)
  304. else:
  305. for i in 0..<n.len:
  306. result[i] = semGenericStmt(c, n[i], flags, ctx)
  307. of nkIfStmt:
  308. for i in 0..<n.len:
  309. n[i] = semGenericStmtScope(c, n[i], flags, ctx)
  310. of nkWhenStmt:
  311. for i in 0..<n.len:
  312. # bug #8603: conditions of 'when' statements are not
  313. # in a 'mixin' context:
  314. let it = n[i]
  315. if it.kind in {nkElifExpr, nkElifBranch}:
  316. n[i][0] = semGenericStmt(c, it[0], flags, ctx)
  317. n[i][1] = semGenericStmt(c, it[1], flags+{withinMixin}, ctx)
  318. else:
  319. n[i] = semGenericStmt(c, it, flags+{withinMixin}, ctx)
  320. of nkWhileStmt:
  321. openScope(c)
  322. for i in 0..<n.len:
  323. n[i] = semGenericStmt(c, n[i], flags, ctx)
  324. closeScope(c)
  325. of nkCaseStmt:
  326. openScope(c)
  327. n[0] = semGenericStmt(c, n[0], flags, ctx)
  328. for i in 1..<n.len:
  329. var a = n[i]
  330. checkMinSonsLen(a, 1, c.config)
  331. for j in 0..<a.len-1:
  332. a[j] = semGenericStmt(c, a[j], flags, ctx)
  333. a[^1] = semGenericStmtScope(c, a[^1], flags, ctx)
  334. closeScope(c)
  335. of nkForStmt, nkParForStmt:
  336. openScope(c)
  337. n[^2] = semGenericStmt(c, n[^2], flags, ctx)
  338. for i in 0..<n.len - 2:
  339. if (n[i].kind == nkVarTuple):
  340. for s in n[i]:
  341. if (s.kind == nkIdent):
  342. addTempDecl(c,s,skForVar)
  343. else:
  344. addTempDecl(c, n[i], skForVar)
  345. openScope(c)
  346. n[^1] = semGenericStmt(c, n[^1], flags, ctx)
  347. closeScope(c)
  348. closeScope(c)
  349. of nkBlockStmt, nkBlockExpr, nkBlockType:
  350. checkSonsLen(n, 2, c.config)
  351. openScope(c)
  352. if n[0].kind != nkEmpty:
  353. addTempDecl(c, n[0], skLabel)
  354. n[1] = semGenericStmt(c, n[1], flags, ctx)
  355. closeScope(c)
  356. of nkTryStmt, nkHiddenTryStmt:
  357. checkMinSonsLen(n, 2, c.config)
  358. n[0] = semGenericStmtScope(c, n[0], flags, ctx)
  359. for i in 1..<n.len:
  360. var a = n[i]
  361. checkMinSonsLen(a, 1, c.config)
  362. openScope(c)
  363. for j in 0..<a.len-1:
  364. if a[j].isInfixAs():
  365. addTempDecl(c, getIdentNode(c, a[j][2]), skLet)
  366. a[j][1] = semGenericStmt(c, a[j][1], flags+{withinTypeDesc}, ctx)
  367. else:
  368. a[j] = semGenericStmt(c, a[j], flags+{withinTypeDesc}, ctx)
  369. a[^1] = semGenericStmtScope(c, a[^1], flags, ctx)
  370. closeScope(c)
  371. of nkVarSection, nkLetSection, nkConstSection:
  372. let varKind =
  373. case n.kind
  374. of nkVarSection: skVar
  375. of nkLetSection: skLet
  376. else: skConst
  377. for i in 0..<n.len:
  378. var a = n[i]
  379. case a.kind:
  380. of nkCommentStmt: continue
  381. of nkIdentDefs, nkVarTuple, nkConstDef:
  382. checkMinSonsLen(a, 3, c.config)
  383. a[^2] = semGenericStmt(c, a[^2], flags+{withinTypeDesc}, ctx)
  384. a[^1] = semGenericStmt(c, a[^1], flags, ctx)
  385. for j in 0..<a.len-2:
  386. addTempDecl(c, getIdentNode(c, a[j]), varKind)
  387. else:
  388. illFormedAst(a, c.config)
  389. of nkGenericParams:
  390. for i in 0..<n.len:
  391. var a = n[i]
  392. if (a.kind != nkIdentDefs): illFormedAst(a, c.config)
  393. checkMinSonsLen(a, 3, c.config)
  394. a[^2] = semGenericStmt(c, a[^2], flags+{withinTypeDesc}, ctx)
  395. # do not perform symbol lookup for default expressions
  396. for j in 0..<a.len-2:
  397. addTempDecl(c, getIdentNode(c, a[j]), skType)
  398. of nkTypeSection:
  399. for i in 0..<n.len:
  400. var a = n[i]
  401. if a.kind == nkCommentStmt: continue
  402. if (a.kind != nkTypeDef): illFormedAst(a, c.config)
  403. checkSonsLen(a, 3, c.config)
  404. addTempDecl(c, getIdentNode(c, a[0]), skType)
  405. for i in 0..<n.len:
  406. var a = n[i]
  407. if a.kind == nkCommentStmt: continue
  408. if (a.kind != nkTypeDef): illFormedAst(a, c.config)
  409. checkSonsLen(a, 3, c.config)
  410. if a[1].kind != nkEmpty:
  411. openScope(c)
  412. a[1] = semGenericStmt(c, a[1], flags, ctx)
  413. a[2] = semGenericStmt(c, a[2], flags+{withinTypeDesc}, ctx)
  414. closeScope(c)
  415. else:
  416. a[2] = semGenericStmt(c, a[2], flags+{withinTypeDesc}, ctx)
  417. of nkEnumTy:
  418. if n.len > 0:
  419. if n[0].kind != nkEmpty:
  420. n[0] = semGenericStmt(c, n[0], flags+{withinTypeDesc}, ctx)
  421. for i in 1..<n.len:
  422. var a: PNode
  423. case n[i].kind
  424. of nkEnumFieldDef: a = n[i][0]
  425. of nkIdent: a = n[i]
  426. else: illFormedAst(n, c.config)
  427. addDecl(c, newSymS(skUnknown, getIdentNode(c, a), c))
  428. of nkObjectTy, nkTupleTy, nkTupleClassTy:
  429. discard
  430. of nkFormalParams:
  431. checkMinSonsLen(n, 1, c.config)
  432. for i in 1..<n.len:
  433. var a = n[i]
  434. if (a.kind != nkIdentDefs): illFormedAst(a, c.config)
  435. checkMinSonsLen(a, 3, c.config)
  436. a[^2] = semGenericStmt(c, a[^2], flags+{withinTypeDesc}, ctx)
  437. a[^1] = semGenericStmt(c, a[^1], flags, ctx)
  438. for j in 0..<a.len-2:
  439. addTempDecl(c, getIdentNode(c, a[j]), skParam)
  440. # XXX: last change was moving this down here, search for "1.." to keep
  441. # going from this file onward
  442. if n[0].kind != nkEmpty:
  443. n[0] = semGenericStmt(c, n[0], flags+{withinTypeDesc}, ctx)
  444. of nkProcDef, nkMethodDef, nkConverterDef, nkMacroDef, nkTemplateDef,
  445. nkFuncDef, nkIteratorDef, nkLambdaKinds:
  446. checkSonsLen(n, bodyPos + 1, c.config)
  447. if n[namePos].kind != nkEmpty:
  448. addTempDecl(c, getIdentNode(c, n[0]), skProc)
  449. openScope(c)
  450. n[genericParamsPos] = semGenericStmt(c, n[genericParamsPos],
  451. flags, ctx)
  452. if n[paramsPos].kind != nkEmpty:
  453. if n[paramsPos][0].kind != nkEmpty:
  454. addPrelimDecl(c, newSym(skUnknown, getIdent(c.cache, "result"), nextSymId c.idgen, nil, n.info))
  455. n[paramsPos] = semGenericStmt(c, n[paramsPos], flags, ctx)
  456. n[pragmasPos] = semGenericStmt(c, n[pragmasPos], flags, ctx)
  457. var body: PNode
  458. if n[namePos].kind == nkSym:
  459. let s = n[namePos].sym
  460. if sfGenSym in s.flags and s.ast == nil:
  461. body = n[bodyPos]
  462. else:
  463. body = getBody(c.graph, s)
  464. else: body = n[bodyPos]
  465. n[bodyPos] = semGenericStmtScope(c, body, flags, ctx)
  466. closeScope(c)
  467. of nkPragma, nkPragmaExpr: discard
  468. of nkExprColonExpr, nkExprEqExpr:
  469. checkMinSonsLen(n, 2, c.config)
  470. result[1] = semGenericStmt(c, n[1], flags, ctx)
  471. else:
  472. for i in 0..<n.len:
  473. result[i] = semGenericStmt(c, n[i], flags, ctx)
  474. when defined(nimsuggest):
  475. if withinTypeDesc in flags: dec c.inTypeContext
  476. proc semGenericStmt(c: PContext, n: PNode): PNode =
  477. var ctx: GenericCtx
  478. ctx.toMixin = initIntSet()
  479. ctx.toBind = initIntSet()
  480. result = semGenericStmt(c, n, {}, ctx)
  481. semIdeForTemplateOrGeneric(c, result, ctx.cursorInBody)
  482. proc semConceptBody(c: PContext, n: PNode): PNode =
  483. var ctx: GenericCtx
  484. ctx.toMixin = initIntSet()
  485. ctx.toBind = initIntSet()
  486. result = semGenericStmt(c, n, {withinConcept}, ctx)
  487. semIdeForTemplateOrGeneric(c, result, ctx.cursorInBody)