mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-17 18:17:11 +00:00
The PR branch had merge conflicts with `devel` due to a major compiler refactoring that extracted type definitions from `compiler/ast.nim` into a new `compiler/astdef.nim` file. ## Changes - Resolved conflict in `compiler/ast.nim` by accepting `devel`'s refactored structure - Merged 763 commits from `devel` branch (commit range: `ce6a345..b3273e7`) - Preserved original PR changes removing deprecated symbols from `lib/core/macros.nim` The core PR functionality (removal of deprecated macros API since v0.18.1) remains intact while incorporating the upstream AST refactoring. <!-- START COPILOT CODING AGENT TIPS --> --- 💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
46 lines
1.3 KiB
Nim
46 lines
1.3 KiB
Nim
from std/private/digitsutils import addInt
|
|
|
|
template toLocation*(result: var string, file: string | cstring, line: int, col: int) =
|
|
## avoids spurious allocations
|
|
# Hopefully this can be re-used everywhere so that if a user needs to customize,
|
|
# it can be done in a single place.
|
|
when file is cstring:
|
|
var i = 0
|
|
while file[i] != '\0':
|
|
add(result, file[i])
|
|
inc i
|
|
else:
|
|
result.add file
|
|
if line > 0:
|
|
result.add "("
|
|
addInt(result, line)
|
|
if col > 0:
|
|
result.add ", "
|
|
addInt(result, col)
|
|
result.add ")"
|
|
|
|
proc isNamedTuple(T: typedesc): bool {.magic: "TypeTrait".}
|
|
|
|
template tupleObjectDollar*[T: tuple | object](result: var string, x: T) =
|
|
result = "("
|
|
const isNamed = T is object or isNamedTuple(typeof(T))
|
|
var count {.used.} = 0
|
|
for name, value in fieldPairs(x):
|
|
if count > 0: result.add(", ")
|
|
when isNamed:
|
|
result.add(name)
|
|
result.add(": ")
|
|
count.inc
|
|
when compiles($value):
|
|
when value isnot string and value isnot seq and compiles(value.isNil):
|
|
if value.isNil: result.add "nil"
|
|
else: result.addQuoted(value)
|
|
else:
|
|
result.addQuoted(value)
|
|
else:
|
|
result.add("...")
|
|
when not isNamed:
|
|
if count == 1:
|
|
result.add(",") # $(1,) should print as the semantically legal (1,)
|
|
result.add(")")
|