semgnrc.nim 18 KB

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