From 361093dc6f79eff44e7ab44ae78409b0aba8bb62 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Sat, 16 Aug 2025 16:42:07 +0200 Subject: [PATCH 1/2] Update npm dependencies --- package-lock.json | 1101 ++++++++++++++++++++++++++------------------- package.json | 16 +- 2 files changed, 657 insertions(+), 460 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7352f6f0..69d9119e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,14 +13,14 @@ ], "devDependencies": { "@eslint/js": "^9.33.0", - "@radix-ui/react-dialog": "^1.1.14", + "@radix-ui/react-dialog": "^1.1.15", "@radix-ui/react-separator": "^1.1.7", "@radix-ui/react-slot": "^1.2.3", - "@radix-ui/react-tooltip": "^1.2.7", - "@tailwindcss/vite": "^4.1.11", - "@tanstack/react-query": "^5.84.2", + "@radix-ui/react-tooltip": "^1.2.8", + "@tailwindcss/vite": "^4.1.12", + "@tanstack/react-query": "^5.85.3", "@types/node": "^24.2.1", - "@types/react": "^19.1.9", + "@types/react": "^19.1.10", "@types/react-dom": "^19.1.7", "@types/react-window": "^1.8.8", "@vitejs/plugin-react": "^5.0.0", @@ -44,13 +44,13 @@ "react-virtualized-auto-sizer": "^1.0.26", "react-window": "^1.8.11", "tailwind-merge": "^3.3.1", - "tailwindcss": "^4.1.11", + "tailwindcss": "^4.1.12", "tw-animate-css": "^1.3.6", "typedoc": "^0.28.9", "typescript": "^5.9.2", - "typescript-eslint": "^8.39.0", + "typescript-eslint": "^8.39.1", "use-debounce": "^10.0.5", - "vite": "^7.1.1", + "vite": "^7.1.2", "zx": "^8.8.0" } }, @@ -94,22 +94,22 @@ } }, "node_modules/@babel/core": { - "version": "7.28.0", - "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.28.0.tgz", - "integrity": "sha512-UlLAnTPrFdNGoFtbSXwcGFQBtQZJCNjaN6hQNP3UPvuNXT1i82N26KL3dZeIpNalWywr9IuQuncaAfUaS1g6sQ==", + "version": "7.28.3", + "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.28.3.tgz", + "integrity": "sha512-yDBHV9kQNcr2/sUr9jghVyz9C3Y5G2zUM2H2lo+9mKv4sFgbA8s8Z9t8D1jiTkGoO/NoIfKMyKWr4s6CN23ZwQ==", "dev": true, "license": "MIT", "dependencies": { "@ampproject/remapping": "^2.2.0", "@babel/code-frame": "^7.27.1", - "@babel/generator": "^7.28.0", + "@babel/generator": "^7.28.3", "@babel/helper-compilation-targets": "^7.27.2", - "@babel/helper-module-transforms": "^7.27.3", - "@babel/helpers": "^7.27.6", - "@babel/parser": "^7.28.0", + "@babel/helper-module-transforms": "^7.28.3", + "@babel/helpers": "^7.28.3", + "@babel/parser": "^7.28.3", "@babel/template": "^7.27.2", - "@babel/traverse": "^7.28.0", - "@babel/types": "^7.28.0", + "@babel/traverse": "^7.28.3", + "@babel/types": "^7.28.2", "convert-source-map": "^2.0.0", "debug": "^4.1.0", "gensync": "^1.0.0-beta.2", @@ -125,14 +125,14 @@ } }, "node_modules/@babel/generator": { - "version": "7.28.0", - "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.28.0.tgz", - "integrity": "sha512-lJjzvrbEeWrhB4P3QBsH7tey117PjLZnDbLiQEKjQ/fNJTjuq4HSqgFA+UNSwZT8D7dxxbnuSBMsa1lrWzKlQg==", + "version": "7.28.3", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.28.3.tgz", + "integrity": "sha512-3lSpxGgvnmZznmBkCRnVREPUFJv2wrv9iAoFDvADJc0ypmdOxdUtcLeBgBJ6zE0PMeTKnxeQzyk0xTBq4Ep7zw==", "dev": true, "license": "MIT", "dependencies": { - "@babel/parser": "^7.28.0", - "@babel/types": "^7.28.0", + "@babel/parser": "^7.28.3", + "@babel/types": "^7.28.2", "@jridgewell/gen-mapping": "^0.3.12", "@jridgewell/trace-mapping": "^0.3.28", "jsesc": "^3.0.2" @@ -183,15 +183,15 @@ } }, "node_modules/@babel/helper-module-transforms": { - "version": "7.27.3", - "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.27.3.tgz", - "integrity": "sha512-dSOvYwvyLsWBeIRyOeHXp5vPj5l1I011r52FM1+r1jCERv+aFXYk4whgQccYEGYxK2H3ZAIA8nuPkQ0HaUo3qg==", + "version": "7.28.3", + "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.28.3.tgz", + "integrity": "sha512-gytXUbs8k2sXS9PnQptz5o0QnpLL51SwASIORY6XaBKF88nsOT0Zw9szLqlSGQDP/4TljBAD5y98p2U1fqkdsw==", "dev": true, "license": "MIT", "dependencies": { "@babel/helper-module-imports": "^7.27.1", "@babel/helper-validator-identifier": "^7.27.1", - "@babel/traverse": "^7.27.3" + "@babel/traverse": "^7.28.3" }, "engines": { "node": ">=6.9.0" @@ -241,9 +241,9 @@ } }, "node_modules/@babel/helpers": { - "version": "7.28.2", - "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.28.2.tgz", - "integrity": "sha512-/V9771t+EgXz62aCcyofnQhGM8DQACbRhvzKFsXKC9QM+5MadF8ZmIm0crDMaz3+o0h0zXfJnd4EhbYbxsrcFw==", + "version": "7.28.3", + "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.28.3.tgz", + "integrity": "sha512-PTNtvUQihsAsDHMOP5pfobP8C6CM4JWXmP8DrEIt46c3r2bf87Ua1zoqevsMo9g+tWDwgWrFP5EIxuBx5RudAw==", "dev": true, "license": "MIT", "dependencies": { @@ -255,13 +255,13 @@ } }, "node_modules/@babel/parser": { - "version": "7.28.0", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.28.0.tgz", - "integrity": "sha512-jVZGvOxOuNSsuQuLRTh13nU0AogFlw32w/MT+LV6D3sP5WdbW61E77RnkbaO2dUvmPAYrBDJXGn5gGS6tH4j8g==", + "version": "7.28.3", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.28.3.tgz", + "integrity": "sha512-7+Ey1mAgYqFAx2h0RuoxcQT5+MlG3GTV0TQrgr7/ZliKsm/MNDxVVutlWaziMq7wJNAz8MTqz55XLpWvva6StA==", "dev": true, "license": "MIT", "dependencies": { - "@babel/types": "^7.28.0" + "@babel/types": "^7.28.2" }, "bin": { "parser": "bin/babel-parser.js" @@ -303,9 +303,9 @@ } }, "node_modules/@babel/runtime": { - "version": "7.28.2", - "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.28.2.tgz", - "integrity": "sha512-KHp2IflsnGywDjBWDkR9iEqiWSpc8GIi0lgTT3mOElT0PP1tG26P4tmFI2YvAdzgq9RGyoHZQEIEdZy6Ec5xCA==", + "version": "7.28.3", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.28.3.tgz", + "integrity": "sha512-9uIQ10o0WGdpP6GDhXcdOJPJuDgFtIDtN/9+ArJQ2NAfAmiuhTQdzkaTGR33v43GYS2UrSA0eX2pPPHoFVvpxA==", "dev": true, "license": "MIT", "engines": { @@ -328,18 +328,18 @@ } }, "node_modules/@babel/traverse": { - "version": "7.28.0", - "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.28.0.tgz", - "integrity": "sha512-mGe7UK5wWyh0bKRfupsUchrQGqvDbZDbKJw+kcRGSmdHVYrv+ltd0pnpDTVpiTqnaBru9iEvA8pz8W46v0Amwg==", + "version": "7.28.3", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.28.3.tgz", + "integrity": "sha512-7w4kZYHneL3A6NP2nxzHvT3HCZ7puDZZjFMqDpBPECub79sTtSO5CGXDkKrTQq8ksAwfD/XI2MRFX23njdDaIQ==", "dev": true, "license": "MIT", "dependencies": { "@babel/code-frame": "^7.27.1", - "@babel/generator": "^7.28.0", + "@babel/generator": "^7.28.3", "@babel/helper-globals": "^7.28.0", - "@babel/parser": "^7.28.0", + "@babel/parser": "^7.28.3", "@babel/template": "^7.27.2", - "@babel/types": "^7.28.0", + "@babel/types": "^7.28.2", "debug": "^4.3.1" }, "engines": { @@ -361,9 +361,9 @@ } }, "node_modules/@esbuild/aix-ppc64": { - "version": "0.25.8", - "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.25.8.tgz", - "integrity": "sha512-urAvrUedIqEiFR3FYSLTWQgLu5tb+m0qZw0NBEasUeo6wuqatkMDaRT+1uABiGXEu5vqgPd7FGE1BhsAIy9QVA==", + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.25.9.tgz", + "integrity": "sha512-OaGtL73Jck6pBKjNIe24BnFE6agGl+6KxDtTfHhy1HmhthfKouEcOhqpSL64K4/0WCtbKFLOdzD/44cJ4k9opA==", "cpu": [ "ppc64" ], @@ -378,9 +378,9 @@ } }, "node_modules/@esbuild/android-arm": { - "version": "0.25.8", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.25.8.tgz", - "integrity": "sha512-RONsAvGCz5oWyePVnLdZY/HHwA++nxYWIX1atInlaW6SEkwq6XkP3+cb825EUcRs5Vss/lGh/2YxAb5xqc07Uw==", + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.25.9.tgz", + "integrity": "sha512-5WNI1DaMtxQ7t7B6xa572XMXpHAaI/9Hnhk8lcxF4zVN4xstUgTlvuGDorBguKEnZO70qwEcLpfifMLoxiPqHQ==", "cpu": [ "arm" ], @@ -395,9 +395,9 @@ } }, "node_modules/@esbuild/android-arm64": { - "version": "0.25.8", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.25.8.tgz", - "integrity": "sha512-OD3p7LYzWpLhZEyATcTSJ67qB5D+20vbtr6vHlHWSQYhKtzUYrETuWThmzFpZtFsBIxRvhO07+UgVA9m0i/O1w==", + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.25.9.tgz", + "integrity": "sha512-IDrddSmpSv51ftWslJMvl3Q2ZT98fUSL2/rlUXuVqRXHCs5EUF1/f+jbjF5+NG9UffUDMCiTyh8iec7u8RlTLg==", "cpu": [ "arm64" ], @@ -412,9 +412,9 @@ } }, "node_modules/@esbuild/android-x64": { - "version": "0.25.8", - "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.25.8.tgz", - "integrity": "sha512-yJAVPklM5+4+9dTeKwHOaA+LQkmrKFX96BM0A/2zQrbS6ENCmxc4OVoBs5dPkCCak2roAD+jKCdnmOqKszPkjA==", + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.25.9.tgz", + "integrity": "sha512-I853iMZ1hWZdNllhVZKm34f4wErd4lMyeV7BLzEExGEIZYsOzqDWDf+y082izYUE8gtJnYHdeDpN/6tUdwvfiw==", "cpu": [ "x64" ], @@ -429,9 +429,9 @@ } }, "node_modules/@esbuild/darwin-arm64": { - "version": "0.25.8", - "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.25.8.tgz", - "integrity": "sha512-Jw0mxgIaYX6R8ODrdkLLPwBqHTtYHJSmzzd+QeytSugzQ0Vg4c5rDky5VgkoowbZQahCbsv1rT1KW72MPIkevw==", + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.25.9.tgz", + "integrity": "sha512-XIpIDMAjOELi/9PB30vEbVMs3GV1v2zkkPnuyRRURbhqjyzIINwj+nbQATh4H9GxUgH1kFsEyQMxwiLFKUS6Rg==", "cpu": [ "arm64" ], @@ -446,9 +446,9 @@ } }, "node_modules/@esbuild/darwin-x64": { - "version": "0.25.8", - "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.25.8.tgz", - "integrity": "sha512-Vh2gLxxHnuoQ+GjPNvDSDRpoBCUzY4Pu0kBqMBDlK4fuWbKgGtmDIeEC081xi26PPjn+1tct+Bh8FjyLlw1Zlg==", + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.25.9.tgz", + "integrity": "sha512-jhHfBzjYTA1IQu8VyrjCX4ApJDnH+ez+IYVEoJHeqJm9VhG9Dh2BYaJritkYK3vMaXrf7Ogr/0MQ8/MeIefsPQ==", "cpu": [ "x64" ], @@ -463,9 +463,9 @@ } }, "node_modules/@esbuild/freebsd-arm64": { - "version": "0.25.8", - "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.25.8.tgz", - "integrity": "sha512-YPJ7hDQ9DnNe5vxOm6jaie9QsTwcKedPvizTVlqWG9GBSq+BuyWEDazlGaDTC5NGU4QJd666V0yqCBL2oWKPfA==", + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.25.9.tgz", + "integrity": "sha512-z93DmbnY6fX9+KdD4Ue/H6sYs+bhFQJNCPZsi4XWJoYblUqT06MQUdBCpcSfuiN72AbqeBFu5LVQTjfXDE2A6Q==", "cpu": [ "arm64" ], @@ -480,9 +480,9 @@ } }, "node_modules/@esbuild/freebsd-x64": { - "version": "0.25.8", - "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.25.8.tgz", - "integrity": "sha512-MmaEXxQRdXNFsRN/KcIimLnSJrk2r5H8v+WVafRWz5xdSVmWLoITZQXcgehI2ZE6gioE6HirAEToM/RvFBeuhw==", + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.25.9.tgz", + "integrity": "sha512-mrKX6H/vOyo5v71YfXWJxLVxgy1kyt1MQaD8wZJgJfG4gq4DpQGpgTB74e5yBeQdyMTbgxp0YtNj7NuHN0PoZg==", "cpu": [ "x64" ], @@ -497,9 +497,9 @@ } }, "node_modules/@esbuild/linux-arm": { - "version": "0.25.8", - "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.25.8.tgz", - "integrity": "sha512-FuzEP9BixzZohl1kLf76KEVOsxtIBFwCaLupVuk4eFVnOZfU+Wsn+x5Ryam7nILV2pkq2TqQM9EZPsOBuMC+kg==", + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.25.9.tgz", + "integrity": "sha512-HBU2Xv78SMgaydBmdor38lg8YDnFKSARg1Q6AT0/y2ezUAKiZvc211RDFHlEZRFNRVhcMamiToo7bDx3VEOYQw==", "cpu": [ "arm" ], @@ -514,9 +514,9 @@ } }, "node_modules/@esbuild/linux-arm64": { - "version": "0.25.8", - "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.25.8.tgz", - "integrity": "sha512-WIgg00ARWv/uYLU7lsuDK00d/hHSfES5BzdWAdAig1ioV5kaFNrtK8EqGcUBJhYqotlUByUKz5Qo6u8tt7iD/w==", + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.25.9.tgz", + "integrity": "sha512-BlB7bIcLT3G26urh5Dmse7fiLmLXnRlopw4s8DalgZ8ef79Jj4aUcYbk90g8iCa2467HX8SAIidbL7gsqXHdRw==", "cpu": [ "arm64" ], @@ -531,9 +531,9 @@ } }, "node_modules/@esbuild/linux-ia32": { - "version": "0.25.8", - "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.25.8.tgz", - "integrity": "sha512-A1D9YzRX1i+1AJZuFFUMP1E9fMaYY+GnSQil9Tlw05utlE86EKTUA7RjwHDkEitmLYiFsRd9HwKBPEftNdBfjg==", + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.25.9.tgz", + "integrity": "sha512-e7S3MOJPZGp2QW6AK6+Ly81rC7oOSerQ+P8L0ta4FhVi+/j/v2yZzx5CqqDaWjtPFfYz21Vi1S0auHrap3Ma3A==", "cpu": [ "ia32" ], @@ -548,9 +548,9 @@ } }, "node_modules/@esbuild/linux-loong64": { - "version": "0.25.8", - "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.25.8.tgz", - "integrity": "sha512-O7k1J/dwHkY1RMVvglFHl1HzutGEFFZ3kNiDMSOyUrB7WcoHGf96Sh+64nTRT26l3GMbCW01Ekh/ThKM5iI7hQ==", + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.25.9.tgz", + "integrity": "sha512-Sbe10Bnn0oUAB2AalYztvGcK+o6YFFA/9829PhOCUS9vkJElXGdphz0A3DbMdP8gmKkqPmPcMJmJOrI3VYB1JQ==", "cpu": [ "loong64" ], @@ -565,9 +565,9 @@ } }, "node_modules/@esbuild/linux-mips64el": { - "version": "0.25.8", - "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.25.8.tgz", - "integrity": "sha512-uv+dqfRazte3BzfMp8PAQXmdGHQt2oC/y2ovwpTteqrMx2lwaksiFZ/bdkXJC19ttTvNXBuWH53zy/aTj1FgGw==", + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.25.9.tgz", + "integrity": "sha512-YcM5br0mVyZw2jcQeLIkhWtKPeVfAerES5PvOzaDxVtIyZ2NUBZKNLjC5z3/fUlDgT6w89VsxP2qzNipOaaDyA==", "cpu": [ "mips64el" ], @@ -582,9 +582,9 @@ } }, "node_modules/@esbuild/linux-ppc64": { - "version": "0.25.8", - "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.25.8.tgz", - "integrity": "sha512-GyG0KcMi1GBavP5JgAkkstMGyMholMDybAf8wF5A70CALlDM2p/f7YFE7H92eDeH/VBtFJA5MT4nRPDGg4JuzQ==", + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.25.9.tgz", + "integrity": "sha512-++0HQvasdo20JytyDpFvQtNrEsAgNG2CY1CLMwGXfFTKGBGQT3bOeLSYE2l1fYdvML5KUuwn9Z8L1EWe2tzs1w==", "cpu": [ "ppc64" ], @@ -599,9 +599,9 @@ } }, "node_modules/@esbuild/linux-riscv64": { - "version": "0.25.8", - "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.25.8.tgz", - "integrity": "sha512-rAqDYFv3yzMrq7GIcen3XP7TUEG/4LK86LUPMIz6RT8A6pRIDn0sDcvjudVZBiiTcZCY9y2SgYX2lgK3AF+1eg==", + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.25.9.tgz", + "integrity": "sha512-uNIBa279Y3fkjV+2cUjx36xkx7eSjb8IvnL01eXUKXez/CBHNRw5ekCGMPM0BcmqBxBcdgUWuUXmVWwm4CH9kg==", "cpu": [ "riscv64" ], @@ -616,9 +616,9 @@ } }, "node_modules/@esbuild/linux-s390x": { - "version": "0.25.8", - "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.25.8.tgz", - "integrity": "sha512-Xutvh6VjlbcHpsIIbwY8GVRbwoviWT19tFhgdA7DlenLGC/mbc3lBoVb7jxj9Z+eyGqvcnSyIltYUrkKzWqSvg==", + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.25.9.tgz", + "integrity": "sha512-Mfiphvp3MjC/lctb+7D287Xw1DGzqJPb/J2aHHcHxflUo+8tmN/6d4k6I2yFR7BVo5/g7x2Monq4+Yew0EHRIA==", "cpu": [ "s390x" ], @@ -633,9 +633,9 @@ } }, "node_modules/@esbuild/linux-x64": { - "version": "0.25.8", - "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.25.8.tgz", - "integrity": "sha512-ASFQhgY4ElXh3nDcOMTkQero4b1lgubskNlhIfJrsH5OKZXDpUAKBlNS0Kx81jwOBp+HCeZqmoJuihTv57/jvQ==", + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.25.9.tgz", + "integrity": "sha512-iSwByxzRe48YVkmpbgoxVzn76BXjlYFXC7NvLYq+b+kDjyyk30J0JY47DIn8z1MO3K0oSl9fZoRmZPQI4Hklzg==", "cpu": [ "x64" ], @@ -650,9 +650,9 @@ } }, "node_modules/@esbuild/netbsd-arm64": { - "version": "0.25.8", - "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.25.8.tgz", - "integrity": "sha512-d1KfruIeohqAi6SA+gENMuObDbEjn22olAR7egqnkCD9DGBG0wsEARotkLgXDu6c4ncgWTZJtN5vcgxzWRMzcw==", + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.25.9.tgz", + "integrity": "sha512-9jNJl6FqaUG+COdQMjSCGW4QiMHH88xWbvZ+kRVblZsWrkXlABuGdFJ1E9L7HK+T0Yqd4akKNa/lO0+jDxQD4Q==", "cpu": [ "arm64" ], @@ -667,9 +667,9 @@ } }, "node_modules/@esbuild/netbsd-x64": { - "version": "0.25.8", - "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.25.8.tgz", - "integrity": "sha512-nVDCkrvx2ua+XQNyfrujIG38+YGyuy2Ru9kKVNyh5jAys6n+l44tTtToqHjino2My8VAY6Lw9H7RI73XFi66Cg==", + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.25.9.tgz", + "integrity": "sha512-RLLdkflmqRG8KanPGOU7Rpg829ZHu8nFy5Pqdi9U01VYtG9Y0zOG6Vr2z4/S+/3zIyOxiK6cCeYNWOFR9QP87g==", "cpu": [ "x64" ], @@ -684,9 +684,9 @@ } }, "node_modules/@esbuild/openbsd-arm64": { - "version": "0.25.8", - "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.25.8.tgz", - "integrity": "sha512-j8HgrDuSJFAujkivSMSfPQSAa5Fxbvk4rgNAS5i3K+r8s1X0p1uOO2Hl2xNsGFppOeHOLAVgYwDVlmxhq5h+SQ==", + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.25.9.tgz", + "integrity": "sha512-YaFBlPGeDasft5IIM+CQAhJAqS3St3nJzDEgsgFixcfZeyGPCd6eJBWzke5piZuZ7CtL656eOSYKk4Ls2C0FRQ==", "cpu": [ "arm64" ], @@ -701,9 +701,9 @@ } }, "node_modules/@esbuild/openbsd-x64": { - "version": "0.25.8", - "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.25.8.tgz", - "integrity": "sha512-1h8MUAwa0VhNCDp6Af0HToI2TJFAn1uqT9Al6DJVzdIBAd21m/G0Yfc77KDM3uF3T/YaOgQq3qTJHPbTOInaIQ==", + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.25.9.tgz", + "integrity": "sha512-1MkgTCuvMGWuqVtAvkpkXFmtL8XhWy+j4jaSO2wxfJtilVCi0ZE37b8uOdMItIHz4I6z1bWWtEX4CJwcKYLcuA==", "cpu": [ "x64" ], @@ -718,9 +718,9 @@ } }, "node_modules/@esbuild/openharmony-arm64": { - "version": "0.25.8", - "resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.25.8.tgz", - "integrity": "sha512-r2nVa5SIK9tSWd0kJd9HCffnDHKchTGikb//9c7HX+r+wHYCpQrSgxhlY6KWV1nFo1l4KFbsMlHk+L6fekLsUg==", + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.25.9.tgz", + "integrity": "sha512-4Xd0xNiMVXKh6Fa7HEJQbrpP3m3DDn43jKxMjxLLRjWnRsfxjORYJlXPO4JNcXtOyfajXorRKY9NkOpTHptErg==", "cpu": [ "arm64" ], @@ -735,9 +735,9 @@ } }, "node_modules/@esbuild/sunos-x64": { - "version": "0.25.8", - "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.25.8.tgz", - "integrity": "sha512-zUlaP2S12YhQ2UzUfcCuMDHQFJyKABkAjvO5YSndMiIkMimPmxA+BYSBikWgsRpvyxuRnow4nS5NPnf9fpv41w==", + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.25.9.tgz", + "integrity": "sha512-WjH4s6hzo00nNezhp3wFIAfmGZ8U7KtrJNlFMRKxiI9mxEK1scOMAaa9i4crUtu+tBr+0IN6JCuAcSBJZfnphw==", "cpu": [ "x64" ], @@ -752,9 +752,9 @@ } }, "node_modules/@esbuild/win32-arm64": { - "version": "0.25.8", - "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.25.8.tgz", - "integrity": "sha512-YEGFFWESlPva8hGL+zvj2z/SaK+pH0SwOM0Nc/d+rVnW7GSTFlLBGzZkuSU9kFIGIo8q9X3ucpZhu8PDN5A2sQ==", + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.25.9.tgz", + "integrity": "sha512-mGFrVJHmZiRqmP8xFOc6b84/7xa5y5YvR1x8djzXpJBSv/UsNK6aqec+6JDjConTgvvQefdGhFDAs2DLAds6gQ==", "cpu": [ "arm64" ], @@ -769,9 +769,9 @@ } }, "node_modules/@esbuild/win32-ia32": { - "version": "0.25.8", - "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.25.8.tgz", - "integrity": "sha512-hiGgGC6KZ5LZz58OL/+qVVoZiuZlUYlYHNAmczOm7bs2oE1XriPFi5ZHHrS8ACpV5EjySrnoCKmcbQMN+ojnHg==", + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.25.9.tgz", + "integrity": "sha512-b33gLVU2k11nVx1OhX3C8QQP6UHQK4ZtN56oFWvVXvz2VkDoe6fbG8TOgHFxEvqeqohmRnIHe5A1+HADk4OQww==", "cpu": [ "ia32" ], @@ -786,9 +786,9 @@ } }, "node_modules/@esbuild/win32-x64": { - "version": "0.25.8", - "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.25.8.tgz", - "integrity": "sha512-cn3Yr7+OaaZq1c+2pe+8yxC8E144SReCQjN6/2ynubzYjvyqZjTXfQJpAcQpsdJq3My7XADANiYGHoFC69pLQw==", + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.25.9.tgz", + "integrity": "sha512-PPOl1mi6lpLNQxnGoyAfschAodRFYXJ+9fs6WHXz7CSWKbOqiMZsubC+BQsVKuul+3vKLuwTHsS2c2y9EoKwxQ==", "cpu": [ "x64" ], @@ -1092,9 +1092,9 @@ } }, "node_modules/@jridgewell/gen-mapping": { - "version": "0.3.12", - "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.12.tgz", - "integrity": "sha512-OuLGC46TjB5BbN1dH8JULVVZY4WTdkF7tV9Ys6wLL1rubZnCMstOhNHueU5bLCrnRuDhKPDM4g6sw4Bel5Gzqg==", + "version": "0.3.13", + "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.13.tgz", + "integrity": "sha512-2kkt/7niJ6MgEPxF0bYdQ6etZaA+fQvDcLKckhy1yIQOzaoKjBBjSj63/aLVjYE3qhRt5dvM+uUyfCg6UKCBbA==", "dev": true, "license": "MIT", "dependencies": { @@ -1102,6 +1102,17 @@ "@jridgewell/trace-mapping": "^0.3.24" } }, + "node_modules/@jridgewell/remapping": { + "version": "2.3.5", + "resolved": "https://registry.npmjs.org/@jridgewell/remapping/-/remapping-2.3.5.tgz", + "integrity": "sha512-LI9u/+laYG4Ds1TDKSJW2YPrIlcVYOwi2fUC6xB43lueCjgxV4lffOCZCtYFiH6TNOX+tQKXx97T4IKHbhyHEQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/gen-mapping": "^0.3.5", + "@jridgewell/trace-mapping": "^0.3.24" + } + }, "node_modules/@jridgewell/resolve-uri": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz", @@ -1113,16 +1124,16 @@ } }, "node_modules/@jridgewell/sourcemap-codec": { - "version": "1.5.4", - "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.4.tgz", - "integrity": "sha512-VT2+G1VQs/9oz078bLrYbecdZKs912zQlkelYpuf+SXF+QvZDYJlbx/LSx+meSAwdDFnF8FVXW92AVjjkVmgFw==", + "version": "1.5.5", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.5.tgz", + "integrity": "sha512-cYQ9310grqxueWbl+WuIUIaiUaDcj7WOq5fVhEljNVgRfOUhY9fy2zTvfoqWsnebh8Sl70VScFbICvJnLKB0Og==", "dev": true, "license": "MIT" }, "node_modules/@jridgewell/trace-mapping": { - "version": "0.3.29", - "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.29.tgz", - "integrity": "sha512-uw6guiW/gcAGPDhLmd77/6lW8QLeiV5RUTsAX46Db6oLhGaVj4lhnPwb184s1bkc8kdVg/+h988dro8GRDpmYQ==", + "version": "0.3.30", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.30.tgz", + "integrity": "sha512-GQ7Nw5G2lTu/BtHTKfXhKHok2WGetd4XYcVKGx00SjAk8GMwgJM3zr6zORiPGuOE+/vkc90KtTosSSvaCjKb2Q==", "dev": true, "license": "MIT", "dependencies": { @@ -1169,9 +1180,9 @@ } }, "node_modules/@radix-ui/primitive": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@radix-ui/primitive/-/primitive-1.1.2.tgz", - "integrity": "sha512-XnbHrrprsNqZKQhStrSwgRUQzoCI1glLzdw79xiZPoofhGICeZRSQ3dIxAKH1gb3OHfNf4d6f+vAv3kil2eggA==", + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/@radix-ui/primitive/-/primitive-1.1.3.tgz", + "integrity": "sha512-JTF99U/6XIjCBo0wqkU5sK10glYe27MRRsfwoiq5zzOEZLHU3A3KCMa5X/azekYRCJ0HlwI0crAXS/5dEHTzDg==", "dev": true, "license": "MIT" }, @@ -1232,21 +1243,21 @@ } }, "node_modules/@radix-ui/react-dialog": { - "version": "1.1.14", - "resolved": "https://registry.npmjs.org/@radix-ui/react-dialog/-/react-dialog-1.1.14.tgz", - "integrity": "sha512-+CpweKjqpzTmwRwcYECQcNYbI8V9VSQt0SNFKeEBLgfucbsLssU6Ppq7wUdNXEGb573bMjFhVjKVll8rmV6zMw==", + "version": "1.1.15", + "resolved": "https://registry.npmjs.org/@radix-ui/react-dialog/-/react-dialog-1.1.15.tgz", + "integrity": "sha512-TCglVRtzlffRNxRMEyR36DGBLJpeusFcgMVD9PZEzAKnUs1lKCgX5u9BmC2Yg+LL9MgZDugFFs1Vl+Jp4t/PGw==", "dev": true, "license": "MIT", "dependencies": { - "@radix-ui/primitive": "1.1.2", + "@radix-ui/primitive": "1.1.3", "@radix-ui/react-compose-refs": "1.1.2", "@radix-ui/react-context": "1.1.2", - "@radix-ui/react-dismissable-layer": "1.1.10", - "@radix-ui/react-focus-guards": "1.1.2", + "@radix-ui/react-dismissable-layer": "1.1.11", + "@radix-ui/react-focus-guards": "1.1.3", "@radix-ui/react-focus-scope": "1.1.7", "@radix-ui/react-id": "1.1.1", "@radix-ui/react-portal": "1.1.9", - "@radix-ui/react-presence": "1.1.4", + "@radix-ui/react-presence": "1.1.5", "@radix-ui/react-primitive": "2.1.3", "@radix-ui/react-slot": "1.2.3", "@radix-ui/react-use-controllable-state": "1.2.2", @@ -1269,13 +1280,13 @@ } }, "node_modules/@radix-ui/react-dismissable-layer": { - "version": "1.1.10", - "resolved": "https://registry.npmjs.org/@radix-ui/react-dismissable-layer/-/react-dismissable-layer-1.1.10.tgz", - "integrity": "sha512-IM1zzRV4W3HtVgftdQiiOmA0AdJlCtMLe00FXaHwgt3rAnNsIyDqshvkIW3hj/iu5hu8ERP7KIYki6NkqDxAwQ==", + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/@radix-ui/react-dismissable-layer/-/react-dismissable-layer-1.1.11.tgz", + "integrity": "sha512-Nqcp+t5cTB8BinFkZgXiMJniQH0PsUt2k51FUhbdfeKvc4ACcG2uQniY/8+h1Yv6Kza4Q7lD7PQV0z0oicE0Mg==", "dev": true, "license": "MIT", "dependencies": { - "@radix-ui/primitive": "1.1.2", + "@radix-ui/primitive": "1.1.3", "@radix-ui/react-compose-refs": "1.1.2", "@radix-ui/react-primitive": "2.1.3", "@radix-ui/react-use-callback-ref": "1.1.1", @@ -1297,9 +1308,9 @@ } }, "node_modules/@radix-ui/react-focus-guards": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@radix-ui/react-focus-guards/-/react-focus-guards-1.1.2.tgz", - "integrity": "sha512-fyjAACV62oPV925xFCrH8DR5xWhg9KYtJT4s3u54jxp+L/hbpTY2kIeEFFbFe+a/HCE94zGQMZLIpVTPVZDhaA==", + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/@radix-ui/react-focus-guards/-/react-focus-guards-1.1.3.tgz", + "integrity": "sha512-0rFg/Rj2Q62NCm62jZw0QX7a3sz6QCQU0LpZdNrJX8byRGaGVTqbrW9jAoIAHyMQqsNpeZ81YgSizOt5WXq0Pw==", "dev": true, "license": "MIT", "peerDependencies": { @@ -1358,9 +1369,9 @@ } }, "node_modules/@radix-ui/react-popper": { - "version": "1.2.7", - "resolved": "https://registry.npmjs.org/@radix-ui/react-popper/-/react-popper-1.2.7.tgz", - "integrity": "sha512-IUFAccz1JyKcf/RjB552PlWwxjeCJB8/4KxT7EhBHOJM+mN7LdW+B3kacJXILm32xawcMMjb2i0cIZpo+f9kiQ==", + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/@radix-ui/react-popper/-/react-popper-1.2.8.tgz", + "integrity": "sha512-0NJQ4LFFUuWkE7Oxf0htBKS6zLkkjBH+hM1uk7Ng705ReR8m/uelduy1DBo0PyBXPKVnBA6YBlU94MBGXrSBCw==", "dev": true, "license": "MIT", "dependencies": { @@ -1416,9 +1427,9 @@ } }, "node_modules/@radix-ui/react-presence": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/@radix-ui/react-presence/-/react-presence-1.1.4.tgz", - "integrity": "sha512-ueDqRbdc4/bkaQT3GIpLQssRlFgWaL/U2z/S31qRwwLWoxHLgry3SIfCwhxeQNbirEUXFa+lq3RL3oBYXtcmIA==", + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/@radix-ui/react-presence/-/react-presence-1.1.5.tgz", + "integrity": "sha512-/jfEwNDdQVBCNvjkGit4h6pMOzq8bHkopq458dPt2lMjx+eBQUohZNG9A7DtO/O5ukSbxuaNGXMjHicgwy6rQQ==", "dev": true, "license": "MIT", "dependencies": { @@ -1508,20 +1519,20 @@ } }, "node_modules/@radix-ui/react-tooltip": { - "version": "1.2.7", - "resolved": "https://registry.npmjs.org/@radix-ui/react-tooltip/-/react-tooltip-1.2.7.tgz", - "integrity": "sha512-Ap+fNYwKTYJ9pzqW+Xe2HtMRbQ/EeWkj2qykZ6SuEV4iS/o1bZI5ssJbk4D2r8XuDuOBVz/tIx2JObtuqU+5Zw==", + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/@radix-ui/react-tooltip/-/react-tooltip-1.2.8.tgz", + "integrity": "sha512-tY7sVt1yL9ozIxvmbtN5qtmH2krXcBCfjEiCgKGLqunJHvgvZG2Pcl2oQ3kbcZARb1BGEHdkLzcYGO8ynVlieg==", "dev": true, "license": "MIT", "dependencies": { - "@radix-ui/primitive": "1.1.2", + "@radix-ui/primitive": "1.1.3", "@radix-ui/react-compose-refs": "1.1.2", "@radix-ui/react-context": "1.1.2", - "@radix-ui/react-dismissable-layer": "1.1.10", + "@radix-ui/react-dismissable-layer": "1.1.11", "@radix-ui/react-id": "1.1.1", - "@radix-ui/react-popper": "1.2.7", + "@radix-ui/react-popper": "1.2.8", "@radix-ui/react-portal": "1.1.9", - "@radix-ui/react-presence": "1.1.4", + "@radix-ui/react-presence": "1.1.5", "@radix-ui/react-primitive": "2.1.3", "@radix-ui/react-slot": "1.2.3", "@radix-ui/react-use-controllable-state": "1.2.2", @@ -2050,25 +2061,25 @@ "license": "MIT" }, "node_modules/@tailwindcss/node": { - "version": "4.1.11", - "resolved": "https://registry.npmjs.org/@tailwindcss/node/-/node-4.1.11.tgz", - "integrity": "sha512-yzhzuGRmv5QyU9qLNg4GTlYI6STedBWRE7NjxP45CsFYYq9taI0zJXZBMqIC/c8fViNLhmrbpSFS57EoxUmD6Q==", + "version": "4.1.12", + "resolved": "https://registry.npmjs.org/@tailwindcss/node/-/node-4.1.12.tgz", + "integrity": "sha512-3hm9brwvQkZFe++SBt+oLjo4OLDtkvlE8q2WalaD/7QWaeM7KEJbAiY/LJZUaCs7Xa8aUu4xy3uoyX4q54UVdQ==", "dev": true, "license": "MIT", "dependencies": { - "@ampproject/remapping": "^2.3.0", - "enhanced-resolve": "^5.18.1", - "jiti": "^2.4.2", + "@jridgewell/remapping": "^2.3.4", + "enhanced-resolve": "^5.18.3", + "jiti": "^2.5.1", "lightningcss": "1.30.1", "magic-string": "^0.30.17", "source-map-js": "^1.2.1", - "tailwindcss": "4.1.11" + "tailwindcss": "4.1.12" } }, "node_modules/@tailwindcss/oxide": { - "version": "4.1.11", - "resolved": "https://registry.npmjs.org/@tailwindcss/oxide/-/oxide-4.1.11.tgz", - "integrity": "sha512-Q69XzrtAhuyfHo+5/HMgr1lAiPP/G40OMFAnws7xcFEYqcypZmdW8eGXaOUIeOl1dzPJBPENXgbjsOyhg2nkrg==", + "version": "4.1.12", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide/-/oxide-4.1.12.tgz", + "integrity": "sha512-gM5EoKHW/ukmlEtphNwaGx45fGoEmP10v51t9unv55voWh6WrOL19hfuIdo2FjxIaZzw776/BUQg7Pck++cIVw==", "dev": true, "hasInstallScript": true, "license": "MIT", @@ -2080,24 +2091,24 @@ "node": ">= 10" }, "optionalDependencies": { - "@tailwindcss/oxide-android-arm64": "4.1.11", - "@tailwindcss/oxide-darwin-arm64": "4.1.11", - "@tailwindcss/oxide-darwin-x64": "4.1.11", - "@tailwindcss/oxide-freebsd-x64": "4.1.11", - "@tailwindcss/oxide-linux-arm-gnueabihf": "4.1.11", - "@tailwindcss/oxide-linux-arm64-gnu": "4.1.11", - "@tailwindcss/oxide-linux-arm64-musl": "4.1.11", - "@tailwindcss/oxide-linux-x64-gnu": "4.1.11", - "@tailwindcss/oxide-linux-x64-musl": "4.1.11", - "@tailwindcss/oxide-wasm32-wasi": "4.1.11", - "@tailwindcss/oxide-win32-arm64-msvc": "4.1.11", - "@tailwindcss/oxide-win32-x64-msvc": "4.1.11" + "@tailwindcss/oxide-android-arm64": "4.1.12", + "@tailwindcss/oxide-darwin-arm64": "4.1.12", + "@tailwindcss/oxide-darwin-x64": "4.1.12", + "@tailwindcss/oxide-freebsd-x64": "4.1.12", + "@tailwindcss/oxide-linux-arm-gnueabihf": "4.1.12", + "@tailwindcss/oxide-linux-arm64-gnu": "4.1.12", + "@tailwindcss/oxide-linux-arm64-musl": "4.1.12", + "@tailwindcss/oxide-linux-x64-gnu": "4.1.12", + "@tailwindcss/oxide-linux-x64-musl": "4.1.12", + "@tailwindcss/oxide-wasm32-wasi": "4.1.12", + "@tailwindcss/oxide-win32-arm64-msvc": "4.1.12", + "@tailwindcss/oxide-win32-x64-msvc": "4.1.12" } }, "node_modules/@tailwindcss/oxide-android-arm64": { - "version": "4.1.11", - "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-android-arm64/-/oxide-android-arm64-4.1.11.tgz", - "integrity": "sha512-3IfFuATVRUMZZprEIx9OGDjG3Ou3jG4xQzNTvjDoKmU9JdmoCohQJ83MYd0GPnQIu89YoJqvMM0G3uqLRFtetg==", + "version": "4.1.12", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-android-arm64/-/oxide-android-arm64-4.1.12.tgz", + "integrity": "sha512-oNY5pq+1gc4T6QVTsZKwZaGpBb2N1H1fsc1GD4o7yinFySqIuRZ2E4NvGasWc6PhYJwGK2+5YT1f9Tp80zUQZQ==", "cpu": [ "arm64" ], @@ -2112,9 +2123,9 @@ } }, "node_modules/@tailwindcss/oxide-darwin-arm64": { - "version": "4.1.11", - "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-darwin-arm64/-/oxide-darwin-arm64-4.1.11.tgz", - "integrity": "sha512-ESgStEOEsyg8J5YcMb1xl8WFOXfeBmrhAwGsFxxB2CxY9evy63+AtpbDLAyRkJnxLy2WsD1qF13E97uQyP1lfQ==", + "version": "4.1.12", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-darwin-arm64/-/oxide-darwin-arm64-4.1.12.tgz", + "integrity": "sha512-cq1qmq2HEtDV9HvZlTtrj671mCdGB93bVY6J29mwCyaMYCP/JaUBXxrQQQm7Qn33AXXASPUb2HFZlWiiHWFytw==", "cpu": [ "arm64" ], @@ -2129,9 +2140,9 @@ } }, "node_modules/@tailwindcss/oxide-darwin-x64": { - "version": "4.1.11", - "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-darwin-x64/-/oxide-darwin-x64-4.1.11.tgz", - "integrity": "sha512-EgnK8kRchgmgzG6jE10UQNaH9Mwi2n+yw1jWmof9Vyg2lpKNX2ioe7CJdf9M5f8V9uaQxInenZkOxnTVL3fhAw==", + "version": "4.1.12", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-darwin-x64/-/oxide-darwin-x64-4.1.12.tgz", + "integrity": "sha512-6UCsIeFUcBfpangqlXay9Ffty9XhFH1QuUFn0WV83W8lGdX8cD5/+2ONLluALJD5+yJ7k8mVtwy3zMZmzEfbLg==", "cpu": [ "x64" ], @@ -2146,9 +2157,9 @@ } }, "node_modules/@tailwindcss/oxide-freebsd-x64": { - "version": "4.1.11", - "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-freebsd-x64/-/oxide-freebsd-x64-4.1.11.tgz", - "integrity": "sha512-xdqKtbpHs7pQhIKmqVpxStnY1skuNh4CtbcyOHeX1YBE0hArj2romsFGb6yUmzkq/6M24nkxDqU8GYrKrz+UcA==", + "version": "4.1.12", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-freebsd-x64/-/oxide-freebsd-x64-4.1.12.tgz", + "integrity": "sha512-JOH/f7j6+nYXIrHobRYCtoArJdMJh5zy5lr0FV0Qu47MID/vqJAY3r/OElPzx1C/wdT1uS7cPq+xdYYelny1ww==", "cpu": [ "x64" ], @@ -2163,9 +2174,9 @@ } }, "node_modules/@tailwindcss/oxide-linux-arm-gnueabihf": { - "version": "4.1.11", - "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-linux-arm-gnueabihf/-/oxide-linux-arm-gnueabihf-4.1.11.tgz", - "integrity": "sha512-ryHQK2eyDYYMwB5wZL46uoxz2zzDZsFBwfjssgB7pzytAeCCa6glsiJGjhTEddq/4OsIjsLNMAiMlHNYnkEEeg==", + "version": "4.1.12", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-linux-arm-gnueabihf/-/oxide-linux-arm-gnueabihf-4.1.12.tgz", + "integrity": "sha512-v4Ghvi9AU1SYgGr3/j38PD8PEe6bRfTnNSUE3YCMIRrrNigCFtHZ2TCm8142X8fcSqHBZBceDx+JlFJEfNg5zQ==", "cpu": [ "arm" ], @@ -2180,9 +2191,9 @@ } }, "node_modules/@tailwindcss/oxide-linux-arm64-gnu": { - "version": "4.1.11", - "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-linux-arm64-gnu/-/oxide-linux-arm64-gnu-4.1.11.tgz", - "integrity": "sha512-mYwqheq4BXF83j/w75ewkPJmPZIqqP1nhoghS9D57CLjsh3Nfq0m4ftTotRYtGnZd3eCztgbSPJ9QhfC91gDZQ==", + "version": "4.1.12", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-linux-arm64-gnu/-/oxide-linux-arm64-gnu-4.1.12.tgz", + "integrity": "sha512-YP5s1LmetL9UsvVAKusHSyPlzSRqYyRB0f+Kl/xcYQSPLEw/BvGfxzbH+ihUciePDjiXwHh+p+qbSP3SlJw+6g==", "cpu": [ "arm64" ], @@ -2197,9 +2208,9 @@ } }, "node_modules/@tailwindcss/oxide-linux-arm64-musl": { - "version": "4.1.11", - "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-linux-arm64-musl/-/oxide-linux-arm64-musl-4.1.11.tgz", - "integrity": "sha512-m/NVRFNGlEHJrNVk3O6I9ggVuNjXHIPoD6bqay/pubtYC9QIdAMpS+cswZQPBLvVvEF6GtSNONbDkZrjWZXYNQ==", + "version": "4.1.12", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-linux-arm64-musl/-/oxide-linux-arm64-musl-4.1.12.tgz", + "integrity": "sha512-V8pAM3s8gsrXcCv6kCHSuwyb/gPsd863iT+v1PGXC4fSL/OJqsKhfK//v8P+w9ThKIoqNbEnsZqNy+WDnwQqCA==", "cpu": [ "arm64" ], @@ -2214,9 +2225,9 @@ } }, "node_modules/@tailwindcss/oxide-linux-x64-gnu": { - "version": "4.1.11", - "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-linux-x64-gnu/-/oxide-linux-x64-gnu-4.1.11.tgz", - "integrity": "sha512-YW6sblI7xukSD2TdbbaeQVDysIm/UPJtObHJHKxDEcW2exAtY47j52f8jZXkqE1krdnkhCMGqP3dbniu1Te2Fg==", + "version": "4.1.12", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-linux-x64-gnu/-/oxide-linux-x64-gnu-4.1.12.tgz", + "integrity": "sha512-xYfqYLjvm2UQ3TZggTGrwxjYaLB62b1Wiysw/YE3Yqbh86sOMoTn0feF98PonP7LtjsWOWcXEbGqDL7zv0uW8Q==", "cpu": [ "x64" ], @@ -2231,9 +2242,9 @@ } }, "node_modules/@tailwindcss/oxide-linux-x64-musl": { - "version": "4.1.11", - "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-linux-x64-musl/-/oxide-linux-x64-musl-4.1.11.tgz", - "integrity": "sha512-e3C/RRhGunWYNC3aSF7exsQkdXzQ/M+aYuZHKnw4U7KQwTJotnWsGOIVih0s2qQzmEzOFIJ3+xt7iq67K/p56Q==", + "version": "4.1.12", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-linux-x64-musl/-/oxide-linux-x64-musl-4.1.12.tgz", + "integrity": "sha512-ha0pHPamN+fWZY7GCzz5rKunlv9L5R8kdh+YNvP5awe3LtuXb5nRi/H27GeL2U+TdhDOptU7T6Is7mdwh5Ar3A==", "cpu": [ "x64" ], @@ -2248,9 +2259,9 @@ } }, "node_modules/@tailwindcss/oxide-wasm32-wasi": { - "version": "4.1.11", - "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-wasm32-wasi/-/oxide-wasm32-wasi-4.1.11.tgz", - "integrity": "sha512-Xo1+/GU0JEN/C/dvcammKHzeM6NqKovG+6921MR6oadee5XPBaKOumrJCXvopJ/Qb5TH7LX/UAywbqrP4lax0g==", + "version": "4.1.12", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-wasm32-wasi/-/oxide-wasm32-wasi-4.1.12.tgz", + "integrity": "sha512-4tSyu3dW+ktzdEpuk6g49KdEangu3eCYoqPhWNsZgUhyegEda3M9rG0/j1GV/JjVVsj+lG7jWAyrTlLzd/WEBg==", "bundleDependencies": [ "@napi-rs/wasm-runtime", "@emnapi/core", @@ -2266,11 +2277,11 @@ "license": "MIT", "optional": true, "dependencies": { - "@emnapi/core": "^1.4.3", - "@emnapi/runtime": "^1.4.3", - "@emnapi/wasi-threads": "^1.0.2", - "@napi-rs/wasm-runtime": "^0.2.11", - "@tybys/wasm-util": "^0.9.0", + "@emnapi/core": "^1.4.5", + "@emnapi/runtime": "^1.4.5", + "@emnapi/wasi-threads": "^1.0.4", + "@napi-rs/wasm-runtime": "^0.2.12", + "@tybys/wasm-util": "^0.10.0", "tslib": "^2.8.0" }, "engines": { @@ -2278,9 +2289,9 @@ } }, "node_modules/@tailwindcss/oxide-win32-arm64-msvc": { - "version": "4.1.11", - "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-win32-arm64-msvc/-/oxide-win32-arm64-msvc-4.1.11.tgz", - "integrity": "sha512-UgKYx5PwEKrac3GPNPf6HVMNhUIGuUh4wlDFR2jYYdkX6pL/rn73zTq/4pzUm8fOjAn5L8zDeHp9iXmUGOXZ+w==", + "version": "4.1.12", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-win32-arm64-msvc/-/oxide-win32-arm64-msvc-4.1.12.tgz", + "integrity": "sha512-iGLyD/cVP724+FGtMWslhcFyg4xyYyM+5F4hGvKA7eifPkXHRAUDFaimu53fpNg9X8dfP75pXx/zFt/jlNF+lg==", "cpu": [ "arm64" ], @@ -2295,9 +2306,9 @@ } }, "node_modules/@tailwindcss/oxide-win32-x64-msvc": { - "version": "4.1.11", - "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-win32-x64-msvc/-/oxide-win32-x64-msvc-4.1.11.tgz", - "integrity": "sha512-YfHoggn1j0LK7wR82TOucWc5LDCguHnoS879idHekmmiR7g9HUtMw9MI0NHatS28u/Xlkfi9w5RJWgz2Dl+5Qg==", + "version": "4.1.12", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-win32-x64-msvc/-/oxide-win32-x64-msvc-4.1.12.tgz", + "integrity": "sha512-NKIh5rzw6CpEodv/++r0hGLlfgT/gFN+5WNdZtvh6wpU2BpGNgdjvj6H2oFc8nCM839QM1YOhjpgbAONUb4IxA==", "cpu": [ "x64" ], @@ -2312,24 +2323,24 @@ } }, "node_modules/@tailwindcss/vite": { - "version": "4.1.11", - "resolved": "https://registry.npmjs.org/@tailwindcss/vite/-/vite-4.1.11.tgz", - "integrity": "sha512-RHYhrR3hku0MJFRV+fN2gNbDNEh3dwKvY8XJvTxCSXeMOsCRSr+uKvDWQcbizrHgjML6ZmTE5OwMrl5wKcujCw==", + "version": "4.1.12", + "resolved": "https://registry.npmjs.org/@tailwindcss/vite/-/vite-4.1.12.tgz", + "integrity": "sha512-4pt0AMFDx7gzIrAOIYgYP0KCBuKWqyW8ayrdiLEjoJTT4pKTjrzG/e4uzWtTLDziC+66R9wbUqZBccJalSE5vQ==", "dev": true, "license": "MIT", "dependencies": { - "@tailwindcss/node": "4.1.11", - "@tailwindcss/oxide": "4.1.11", - "tailwindcss": "4.1.11" + "@tailwindcss/node": "4.1.12", + "@tailwindcss/oxide": "4.1.12", + "tailwindcss": "4.1.12" }, "peerDependencies": { "vite": "^5.2.0 || ^6 || ^7" } }, "node_modules/@tanstack/query-core": { - "version": "5.83.1", - "resolved": "https://registry.npmjs.org/@tanstack/query-core/-/query-core-5.83.1.tgz", - "integrity": "sha512-OG69LQgT7jSp+5pPuCfzltq/+7l2xoweggjme9vlbCPa/d7D7zaqv5vN/S82SzSYZ4EDLTxNO1PWrv49RAS64Q==", + "version": "5.85.3", + "resolved": "https://registry.npmjs.org/@tanstack/query-core/-/query-core-5.85.3.tgz", + "integrity": "sha512-9Ne4USX83nHmRuEYs78LW+3lFEEO2hBDHu7mrdIgAFx5Zcrs7ker3n/i8p4kf6OgKExmaDN5oR0efRD7i2J0DQ==", "dev": true, "license": "MIT", "funding": { @@ -2338,13 +2349,13 @@ } }, "node_modules/@tanstack/react-query": { - "version": "5.84.2", - "resolved": "https://registry.npmjs.org/@tanstack/react-query/-/react-query-5.84.2.tgz", - "integrity": "sha512-cZadySzROlD2+o8zIfbD978p0IphuQzRWiiH3I2ugnTmz4jbjc0+TdibpwqxlzynEen8OulgAg+rzdNF37s7XQ==", + "version": "5.85.3", + "resolved": "https://registry.npmjs.org/@tanstack/react-query/-/react-query-5.85.3.tgz", + "integrity": "sha512-AqU8TvNh5GVIE8I+TUU0noryBRy7gOY0XhSayVXmOPll4UkZeLWKDwi0rtWOZbwLRCbyxorfJ5DIjDqE7GXpcQ==", "dev": true, "license": "MIT", "dependencies": { - "@tanstack/query-core": "5.83.1" + "@tanstack/query-core": "5.85.3" }, "funding": { "type": "github", @@ -2424,9 +2435,9 @@ "license": "MIT" }, "node_modules/@types/node": { - "version": "24.2.1", - "resolved": "https://registry.npmjs.org/@types/node/-/node-24.2.1.tgz", - "integrity": "sha512-DRh5K+ka5eJic8CjH7td8QpYEV6Zo10gfRkjHCO3weqZHWDtAaSTFtl4+VMqOJ4N5jcuhZ9/l+yy8rVgw7BQeQ==", + "version": "24.3.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-24.3.0.tgz", + "integrity": "sha512-aPTXCrfwnDLj4VvXrm+UUCQjNEvJgNA8s5F1cvwQU+3KNltTOkBm1j30uNLyqqPNe7gE3KFzImYoZEfLhp4Yow==", "dev": true, "license": "MIT", "dependencies": { @@ -2434,9 +2445,9 @@ } }, "node_modules/@types/react": { - "version": "19.1.9", - "resolved": "https://registry.npmjs.org/@types/react/-/react-19.1.9.tgz", - "integrity": "sha512-WmdoynAX8Stew/36uTSVMcLJJ1KRh6L3IZRx1PZ7qJtBqT3dYTgyDTx8H1qoRghErydW7xw9mSJ3wS//tCRpFA==", + "version": "19.1.10", + "resolved": "https://registry.npmjs.org/@types/react/-/react-19.1.10.tgz", + "integrity": "sha512-EhBeSYX0Y6ye8pNebpKrwFJq7BoQ8J5SO6NlvNwwHjSj6adXJViPQrKlsyPw7hLBLvckEMO1yxeGdR82YBBlDg==", "dev": true, "license": "MIT", "dependencies": { @@ -2488,17 +2499,17 @@ "license": "MIT" }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "8.39.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.39.0.tgz", - "integrity": "sha512-bhEz6OZeUR+O/6yx9Jk6ohX6H9JSFTaiY0v9/PuKT3oGK0rn0jNplLmyFUGV+a9gfYnVNwGDwS/UkLIuXNb2Rw==", + "version": "8.39.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.39.1.tgz", + "integrity": "sha512-yYegZ5n3Yr6eOcqgj2nJH8cH/ZZgF+l0YIdKILSDjYFRjgYQMgv/lRjV5Z7Up04b9VYUondt8EPMqg7kTWgJ2g==", "dev": true, "license": "MIT", "dependencies": { "@eslint-community/regexpp": "^4.10.0", - "@typescript-eslint/scope-manager": "8.39.0", - "@typescript-eslint/type-utils": "8.39.0", - "@typescript-eslint/utils": "8.39.0", - "@typescript-eslint/visitor-keys": "8.39.0", + "@typescript-eslint/scope-manager": "8.39.1", + "@typescript-eslint/type-utils": "8.39.1", + "@typescript-eslint/utils": "8.39.1", + "@typescript-eslint/visitor-keys": "8.39.1", "graphemer": "^1.4.0", "ignore": "^7.0.0", "natural-compare": "^1.4.0", @@ -2512,7 +2523,7 @@ "url": "https://opencollective.com/typescript-eslint" }, "peerDependencies": { - "@typescript-eslint/parser": "^8.39.0", + "@typescript-eslint/parser": "^8.39.1", "eslint": "^8.57.0 || ^9.0.0", "typescript": ">=4.8.4 <6.0.0" } @@ -2528,16 +2539,16 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "8.39.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.39.0.tgz", - "integrity": "sha512-g3WpVQHngx0aLXn6kfIYCZxM6rRJlWzEkVpqEFLT3SgEDsp9cpCbxxgwnE504q4H+ruSDh/VGS6nqZIDynP+vg==", + "version": "8.39.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.39.1.tgz", + "integrity": "sha512-pUXGCuHnnKw6PyYq93lLRiZm3vjuslIy7tus1lIQTYVK9bL8XBgJnCWm8a0KcTtHC84Yya1Q6rtll+duSMj0dg==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/scope-manager": "8.39.0", - "@typescript-eslint/types": "8.39.0", - "@typescript-eslint/typescript-estree": "8.39.0", - "@typescript-eslint/visitor-keys": "8.39.0", + "@typescript-eslint/scope-manager": "8.39.1", + "@typescript-eslint/types": "8.39.1", + "@typescript-eslint/typescript-estree": "8.39.1", + "@typescript-eslint/visitor-keys": "8.39.1", "debug": "^4.3.4" }, "engines": { @@ -2552,15 +2563,83 @@ "typescript": ">=4.8.4 <6.0.0" } }, + "node_modules/@typescript-eslint/parser/node_modules/@typescript-eslint/typescript-estree": { + "version": "8.39.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.39.1.tgz", + "integrity": "sha512-EKkpcPuIux48dddVDXyQBlKdeTPMmALqBUbEk38McWv0qVEZwOpVJBi7ugK5qVNgeuYjGNQxrrnoM/5+TI/BPw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/project-service": "8.39.1", + "@typescript-eslint/tsconfig-utils": "8.39.1", + "@typescript-eslint/types": "8.39.1", + "@typescript-eslint/visitor-keys": "8.39.1", + "debug": "^4.3.4", + "fast-glob": "^3.3.2", + "is-glob": "^4.0.3", + "minimatch": "^9.0.4", + "semver": "^7.6.0", + "ts-api-utils": "^2.1.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "typescript": ">=4.8.4 <6.0.0" + } + }, + "node_modules/@typescript-eslint/parser/node_modules/brace-expansion": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.2.tgz", + "integrity": "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "node_modules/@typescript-eslint/parser/node_modules/minimatch": { + "version": "9.0.5", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", + "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", + "dev": true, + "license": "ISC", + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/@typescript-eslint/parser/node_modules/semver": { + "version": "7.7.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.2.tgz", + "integrity": "sha512-RF0Fw+rO5AMf9MAyaRXI4AV0Ulj5lMHqVxxdSgiVbixSCXoEmmX/jk0CuJw4+3SqroYO9VoUh+HcuJivvtJemA==", + "dev": true, + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/@typescript-eslint/project-service": { - "version": "8.39.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/project-service/-/project-service-8.39.0.tgz", - "integrity": "sha512-CTzJqaSq30V/Z2Og9jogzZt8lJRR5TKlAdXmWgdu4hgcC9Kww5flQ+xFvMxIBWVNdxJO7OifgdOK4PokMIWPew==", + "version": "8.39.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/project-service/-/project-service-8.39.1.tgz", + "integrity": "sha512-8fZxek3ONTwBu9ptw5nCKqZOSkXshZB7uAxuFF0J/wTMkKydjXCzqqga7MlFMpHi9DoG4BadhmTkITBcg8Aybw==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/tsconfig-utils": "^8.39.0", - "@typescript-eslint/types": "^8.39.0", + "@typescript-eslint/tsconfig-utils": "^8.39.1", + "@typescript-eslint/types": "^8.39.1", "debug": "^4.3.4" }, "engines": { @@ -2575,14 +2654,14 @@ } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "8.39.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.39.0.tgz", - "integrity": "sha512-8QOzff9UKxOh6npZQ/4FQu4mjdOCGSdO3p44ww0hk8Vu+IGbg0tB/H1LcTARRDzGCC8pDGbh2rissBuuoPgH8A==", + "version": "8.39.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.39.1.tgz", + "integrity": "sha512-RkBKGBrjgskFGWuyUGz/EtD8AF/GW49S21J8dvMzpJitOF1slLEbbHnNEtAHtnDAnx8qDEdRrULRnWVx27wGBw==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/types": "8.39.0", - "@typescript-eslint/visitor-keys": "8.39.0" + "@typescript-eslint/types": "8.39.1", + "@typescript-eslint/visitor-keys": "8.39.1" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -2593,9 +2672,9 @@ } }, "node_modules/@typescript-eslint/tsconfig-utils": { - "version": "8.39.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/tsconfig-utils/-/tsconfig-utils-8.39.0.tgz", - "integrity": "sha512-Fd3/QjmFV2sKmvv3Mrj8r6N8CryYiCS8Wdb/6/rgOXAWGcFuc+VkQuG28uk/4kVNVZBQuuDHEDUpo/pQ32zsIQ==", + "version": "8.39.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/tsconfig-utils/-/tsconfig-utils-8.39.1.tgz", + "integrity": "sha512-ePUPGVtTMR8XMU2Hee8kD0Pu4NDE1CN9Q1sxGSGd/mbOtGZDM7pnhXNJnzW63zk/q+Z54zVzj44HtwXln5CvHA==", "dev": true, "license": "MIT", "engines": { @@ -2610,15 +2689,15 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "8.39.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.39.0.tgz", - "integrity": "sha512-6B3z0c1DXVT2vYA9+z9axjtc09rqKUPRmijD5m9iv8iQpHBRYRMBcgxSiKTZKm6FwWw1/cI4v6em35OsKCiN5Q==", + "version": "8.39.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.39.1.tgz", + "integrity": "sha512-gu9/ahyatyAdQbKeHnhT4R+y3YLtqqHyvkfDxaBYk97EcbfChSJXyaJnIL3ygUv7OuZatePHmQvuH5ru0lnVeA==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/types": "8.39.0", - "@typescript-eslint/typescript-estree": "8.39.0", - "@typescript-eslint/utils": "8.39.0", + "@typescript-eslint/types": "8.39.1", + "@typescript-eslint/typescript-estree": "8.39.1", + "@typescript-eslint/utils": "8.39.1", "debug": "^4.3.4", "ts-api-utils": "^2.1.0" }, @@ -2634,31 +2713,17 @@ "typescript": ">=4.8.4 <6.0.0" } }, - "node_modules/@typescript-eslint/types": { - "version": "8.39.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.39.0.tgz", - "integrity": "sha512-ArDdaOllnCj3yn/lzKn9s0pBQYmmyme/v1HbGIGB0GB/knFI3fWMHloC+oYTJW46tVbYnGKTMDK4ah1sC2v0Kg==", - "dev": true, - "license": "MIT", - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - } - }, - "node_modules/@typescript-eslint/typescript-estree": { - "version": "8.39.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.39.0.tgz", - "integrity": "sha512-ndWdiflRMvfIgQRpckQQLiB5qAKQ7w++V4LlCHwp62eym1HLB/kw7D9f2e8ytONls/jt89TEasgvb+VwnRprsw==", + "node_modules/@typescript-eslint/type-utils/node_modules/@typescript-eslint/typescript-estree": { + "version": "8.39.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.39.1.tgz", + "integrity": "sha512-EKkpcPuIux48dddVDXyQBlKdeTPMmALqBUbEk38McWv0qVEZwOpVJBi7ugK5qVNgeuYjGNQxrrnoM/5+TI/BPw==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/project-service": "8.39.0", - "@typescript-eslint/tsconfig-utils": "8.39.0", - "@typescript-eslint/types": "8.39.0", - "@typescript-eslint/visitor-keys": "8.39.0", + "@typescript-eslint/project-service": "8.39.1", + "@typescript-eslint/tsconfig-utils": "8.39.1", + "@typescript-eslint/types": "8.39.1", + "@typescript-eslint/visitor-keys": "8.39.1", "debug": "^4.3.4", "fast-glob": "^3.3.2", "is-glob": "^4.0.3", @@ -2677,7 +2742,7 @@ "typescript": ">=4.8.4 <6.0.0" } }, - "node_modules/@typescript-eslint/typescript-estree/node_modules/brace-expansion": { + "node_modules/@typescript-eslint/type-utils/node_modules/brace-expansion": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.2.tgz", "integrity": "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ==", @@ -2687,7 +2752,7 @@ "balanced-match": "^1.0.0" } }, - "node_modules/@typescript-eslint/typescript-estree/node_modules/minimatch": { + "node_modules/@typescript-eslint/type-utils/node_modules/minimatch": { "version": "9.0.5", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", @@ -2703,7 +2768,7 @@ "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/@typescript-eslint/typescript-estree/node_modules/semver": { + "node_modules/@typescript-eslint/type-utils/node_modules/semver": { "version": "7.7.2", "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.2.tgz", "integrity": "sha512-RF0Fw+rO5AMf9MAyaRXI4AV0Ulj5lMHqVxxdSgiVbixSCXoEmmX/jk0CuJw4+3SqroYO9VoUh+HcuJivvtJemA==", @@ -2716,17 +2781,31 @@ "node": ">=10" } }, + "node_modules/@typescript-eslint/types": { + "version": "8.39.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.39.1.tgz", + "integrity": "sha512-7sPDKQQp+S11laqTrhHqeAbsCfMkwJMrV7oTDvtDds4mEofJYir414bYKUEb8YPUm9QL3U+8f6L6YExSoAGdQw==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, "node_modules/@typescript-eslint/utils": { - "version": "8.39.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.39.0.tgz", - "integrity": "sha512-4GVSvNA0Vx1Ktwvf4sFE+exxJ3QGUorQG1/A5mRfRNZtkBT2xrA/BCO2H0eALx/PnvCS6/vmYwRdDA41EoffkQ==", + "version": "8.39.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.39.1.tgz", + "integrity": "sha512-VF5tZ2XnUSTuiqZFXCZfZs1cgkdd3O/sSYmdo2EpSyDlC86UM/8YytTmKnehOW3TGAlivqTDT6bS87B/GQ/jyg==", "dev": true, "license": "MIT", "dependencies": { "@eslint-community/eslint-utils": "^4.7.0", - "@typescript-eslint/scope-manager": "8.39.0", - "@typescript-eslint/types": "8.39.0", - "@typescript-eslint/typescript-estree": "8.39.0" + "@typescript-eslint/scope-manager": "8.39.1", + "@typescript-eslint/types": "8.39.1", + "@typescript-eslint/typescript-estree": "8.39.1" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -2740,14 +2819,82 @@ "typescript": ">=4.8.4 <6.0.0" } }, + "node_modules/@typescript-eslint/utils/node_modules/@typescript-eslint/typescript-estree": { + "version": "8.39.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.39.1.tgz", + "integrity": "sha512-EKkpcPuIux48dddVDXyQBlKdeTPMmALqBUbEk38McWv0qVEZwOpVJBi7ugK5qVNgeuYjGNQxrrnoM/5+TI/BPw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/project-service": "8.39.1", + "@typescript-eslint/tsconfig-utils": "8.39.1", + "@typescript-eslint/types": "8.39.1", + "@typescript-eslint/visitor-keys": "8.39.1", + "debug": "^4.3.4", + "fast-glob": "^3.3.2", + "is-glob": "^4.0.3", + "minimatch": "^9.0.4", + "semver": "^7.6.0", + "ts-api-utils": "^2.1.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "typescript": ">=4.8.4 <6.0.0" + } + }, + "node_modules/@typescript-eslint/utils/node_modules/brace-expansion": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.2.tgz", + "integrity": "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "node_modules/@typescript-eslint/utils/node_modules/minimatch": { + "version": "9.0.5", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", + "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", + "dev": true, + "license": "ISC", + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/@typescript-eslint/utils/node_modules/semver": { + "version": "7.7.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.2.tgz", + "integrity": "sha512-RF0Fw+rO5AMf9MAyaRXI4AV0Ulj5lMHqVxxdSgiVbixSCXoEmmX/jk0CuJw4+3SqroYO9VoUh+HcuJivvtJemA==", + "dev": true, + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "8.39.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.39.0.tgz", - "integrity": "sha512-ldgiJ+VAhQCfIjeOgu8Kj5nSxds0ktPOSO9p4+0VDH2R2pLvQraaM5Oen2d7NxzMCm+Sn/vJT+mv2H5u6b/3fA==", + "version": "8.39.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.39.1.tgz", + "integrity": "sha512-W8FQi6kEh2e8zVhQ0eeRnxdvIoOkAp/CPAahcNio6nO9dsIwb9b34z90KOlheoyuVf6LSOEdjlkxSkapNEc+4A==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/types": "8.39.0", + "@typescript-eslint/types": "8.39.1", "eslint-visitor-keys": "^4.2.1" }, "engines": { @@ -2907,9 +3054,9 @@ } }, "node_modules/browserslist": { - "version": "4.25.1", - "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.25.1.tgz", - "integrity": "sha512-KGj0KoOMXLpSNkkEI6Z6mShmQy0bc1I+T7K9N81k4WWMrfz+6fQ6es80B/YLAeRoKvjYE1YSHHOW1qe9xIVzHw==", + "version": "4.25.2", + "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.25.2.tgz", + "integrity": "sha512-0si2SJK3ooGzIawRu61ZdPCO1IncZwS8IzuX73sPZsXW6EQ/w/DAfPyKI8l1ETTCr2MnvqWitmlCUxgdul45jA==", "dev": true, "funding": [ { @@ -2927,8 +3074,8 @@ ], "license": "MIT", "dependencies": { - "caniuse-lite": "^1.0.30001726", - "electron-to-chromium": "^1.5.173", + "caniuse-lite": "^1.0.30001733", + "electron-to-chromium": "^1.5.199", "node-releases": "^2.0.19", "update-browserslist-db": "^1.1.3" }, @@ -2950,9 +3097,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001733", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001733.tgz", - "integrity": "sha512-e4QKw/O2Kavj2VQTKZWrwzkt3IxOmIlU6ajRb6LP64LHpBo1J67k2Hi4Vu/TgJWsNtynurfS0uK3MaUTCPfu5Q==", + "version": "1.0.30001735", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001735.tgz", + "integrity": "sha512-EV/laoX7Wq2J9TQlyIXRxTJqIw4sxfXS4OYgudGxBYRuTv0q7AM6yMEpU/Vo1I94thg9U6EZ2NfZx9GJq83u7w==", "dev": true, "funding": [ { @@ -3138,9 +3285,9 @@ "license": "MIT" }, "node_modules/electron-to-chromium": { - "version": "1.5.199", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.199.tgz", - "integrity": "sha512-3gl0S7zQd88kCAZRO/DnxtBKuhMO4h0EaQIN3YgZfV6+pW+5+bf2AdQeHNESCoaQqo/gjGVYEf2YM4O5HJQqpQ==", + "version": "1.5.203", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.203.tgz", + "integrity": "sha512-uz4i0vLhfm6dLZWbz/iH88KNDV+ivj5+2SA+utpgjKaj9Q0iDLuwk6Idhe9BTxciHudyx6IvTvijhkPvFGUQ0g==", "dev": true, "license": "ISC" }, @@ -3179,9 +3326,9 @@ } }, "node_modules/esbuild": { - "version": "0.25.8", - "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.25.8.tgz", - "integrity": "sha512-vVC0USHGtMi8+R4Kz8rt6JhEWLxsv9Rnu/lGYbPR8u47B+DCBksq9JarW0zOO7bs37hyOK1l2/oqtbciutL5+Q==", + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.25.9.tgz", + "integrity": "sha512-CRbODhYyQx3qp7ZEwzxOk4JBqmD/seJrzPa/cGjY1VtIn5E09Oi9/dB4JwctnfZ8Q8iT7rioVv5k/FNT/uf54g==", "dev": true, "hasInstallScript": true, "license": "MIT", @@ -3192,32 +3339,32 @@ "node": ">=18" }, "optionalDependencies": { - "@esbuild/aix-ppc64": "0.25.8", - "@esbuild/android-arm": "0.25.8", - "@esbuild/android-arm64": "0.25.8", - "@esbuild/android-x64": "0.25.8", - "@esbuild/darwin-arm64": "0.25.8", - "@esbuild/darwin-x64": "0.25.8", - "@esbuild/freebsd-arm64": "0.25.8", - "@esbuild/freebsd-x64": "0.25.8", - "@esbuild/linux-arm": "0.25.8", - "@esbuild/linux-arm64": "0.25.8", - "@esbuild/linux-ia32": "0.25.8", - "@esbuild/linux-loong64": "0.25.8", - "@esbuild/linux-mips64el": "0.25.8", - "@esbuild/linux-ppc64": "0.25.8", - "@esbuild/linux-riscv64": "0.25.8", - "@esbuild/linux-s390x": "0.25.8", - "@esbuild/linux-x64": "0.25.8", - "@esbuild/netbsd-arm64": "0.25.8", - "@esbuild/netbsd-x64": "0.25.8", - "@esbuild/openbsd-arm64": "0.25.8", - "@esbuild/openbsd-x64": "0.25.8", - "@esbuild/openharmony-arm64": "0.25.8", - "@esbuild/sunos-x64": "0.25.8", - "@esbuild/win32-arm64": "0.25.8", - "@esbuild/win32-ia32": "0.25.8", - "@esbuild/win32-x64": "0.25.8" + "@esbuild/aix-ppc64": "0.25.9", + "@esbuild/android-arm": "0.25.9", + "@esbuild/android-arm64": "0.25.9", + "@esbuild/android-x64": "0.25.9", + "@esbuild/darwin-arm64": "0.25.9", + "@esbuild/darwin-x64": "0.25.9", + "@esbuild/freebsd-arm64": "0.25.9", + "@esbuild/freebsd-x64": "0.25.9", + "@esbuild/linux-arm": "0.25.9", + "@esbuild/linux-arm64": "0.25.9", + "@esbuild/linux-ia32": "0.25.9", + "@esbuild/linux-loong64": "0.25.9", + "@esbuild/linux-mips64el": "0.25.9", + "@esbuild/linux-ppc64": "0.25.9", + "@esbuild/linux-riscv64": "0.25.9", + "@esbuild/linux-s390x": "0.25.9", + "@esbuild/linux-x64": "0.25.9", + "@esbuild/netbsd-arm64": "0.25.9", + "@esbuild/netbsd-x64": "0.25.9", + "@esbuild/openbsd-arm64": "0.25.9", + "@esbuild/openbsd-x64": "0.25.9", + "@esbuild/openharmony-arm64": "0.25.9", + "@esbuild/sunos-x64": "0.25.9", + "@esbuild/win32-arm64": "0.25.9", + "@esbuild/win32-ia32": "0.25.9", + "@esbuild/win32-x64": "0.25.9" } }, "node_modules/escalade": { @@ -3482,6 +3629,24 @@ "reusify": "^1.0.4" } }, + "node_modules/fdir": { + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz", + "integrity": "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12.0.0" + }, + "peerDependencies": { + "picomatch": "^3 || ^4" + }, + "peerDependenciesMeta": { + "picomatch": { + "optional": true + } + } + }, "node_modules/file-entry-cache": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-8.0.0.tgz", @@ -3546,21 +3711,6 @@ "dev": true, "license": "ISC" }, - "node_modules/fsevents": { - "version": "2.3.3", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", - "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", - "dev": true, - "hasInstallScript": true, - "license": "MIT", - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": "^8.16.0 || ^10.6.0 || >=11.0.0" - } - }, "node_modules/gensync": { "version": "1.0.0-beta.2", "resolved": "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz", @@ -4231,6 +4381,19 @@ "node": ">=8.6" } }, + "node_modules/micromatch/node_modules/picomatch": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", + "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8.6" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, "node_modules/minimatch": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", @@ -4421,13 +4584,13 @@ "license": "ISC" }, "node_modules/picomatch": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", - "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.3.tgz", + "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==", "dev": true, "license": "MIT", "engines": { - "node": ">=8.6" + "node": ">=12" }, "funding": { "url": "https://github.com/sponsors/jonschlinkert" @@ -4751,6 +4914,21 @@ "fsevents": "~2.3.2" } }, + "node_modules/rollup/node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, "node_modules/run-parallel": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", @@ -4891,9 +5069,9 @@ } }, "node_modules/tailwindcss": { - "version": "4.1.11", - "resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-4.1.11.tgz", - "integrity": "sha512-2E9TBm6MDD/xKYe+dvJZAmg3yxIEDNRc0jwlNyDg/4Fil2QcSLjFKGVff0lAf1jjeaArlG/M75Ey/EYr/OJtBA==", + "version": "4.1.12", + "resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-4.1.12.tgz", + "integrity": "sha512-DzFtxOi+7NsFf7DBtI3BJsynR+0Yp6etH+nRPTbpWnS2pZBaSksv/JGctNwSWzbFjp0vxSqknaUylseZqMDGrA==", "dev": true, "license": "MIT" }, @@ -4952,34 +5130,6 @@ "url": "https://github.com/sponsors/SuperchupuDev" } }, - "node_modules/tinyglobby/node_modules/fdir": { - "version": "6.4.6", - "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.4.6.tgz", - "integrity": "sha512-hiFoqpyZcfNm1yc4u8oWCf9A2c4D3QjCrks3zmoVKVxpQRzmPNar1hUJcBG2RQHvEVGDN+Jm81ZheVLAQMK6+w==", - "dev": true, - "license": "MIT", - "peerDependencies": { - "picomatch": "^3 || ^4" - }, - "peerDependenciesMeta": { - "picomatch": { - "optional": true - } - } - }, - "node_modules/tinyglobby/node_modules/picomatch": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.3.tgz", - "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/sponsors/jonschlinkert" - } - }, "node_modules/to-regex-range": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", @@ -5037,9 +5187,9 @@ } }, "node_modules/typedoc": { - "version": "0.28.9", - "resolved": "https://registry.npmjs.org/typedoc/-/typedoc-0.28.9.tgz", - "integrity": "sha512-aw45vwtwOl3QkUAmWCnLV9QW1xY+FSX2zzlit4MAfE99wX+Jij4ycnpbAWgBXsRrxmfs9LaYktg/eX5Bpthd3g==", + "version": "0.28.10", + "resolved": "https://registry.npmjs.org/typedoc/-/typedoc-0.28.10.tgz", + "integrity": "sha512-zYvpjS2bNJ30SoNYfHSRaFpBMZAsL7uwKbWwqoCNFWjcPnI3e/mPLh2SneH9mX7SJxtDpvDgvd9/iZxGbo7daw==", "dev": true, "license": "Apache-2.0", "dependencies": { @@ -5101,16 +5251,16 @@ } }, "node_modules/typescript-eslint": { - "version": "8.39.0", - "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-8.39.0.tgz", - "integrity": "sha512-lH8FvtdtzcHJCkMOKnN73LIn6SLTpoojgJqDAxPm1jCR14eWSGPX8ul/gggBdPMk/d5+u9V854vTYQ8T5jF/1Q==", + "version": "8.39.1", + "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-8.39.1.tgz", + "integrity": "sha512-GDUv6/NDYngUlNvwaHM1RamYftxf782IyEDbdj3SeaIHHv8fNQVRC++fITT7kUJV/5rIA/tkoRSSskt6osEfqg==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/eslint-plugin": "8.39.0", - "@typescript-eslint/parser": "8.39.0", - "@typescript-eslint/typescript-estree": "8.39.0", - "@typescript-eslint/utils": "8.39.0" + "@typescript-eslint/eslint-plugin": "8.39.1", + "@typescript-eslint/parser": "8.39.1", + "@typescript-eslint/typescript-estree": "8.39.1", + "@typescript-eslint/utils": "8.39.1" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -5124,6 +5274,74 @@ "typescript": ">=4.8.4 <6.0.0" } }, + "node_modules/typescript-eslint/node_modules/@typescript-eslint/typescript-estree": { + "version": "8.39.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.39.1.tgz", + "integrity": "sha512-EKkpcPuIux48dddVDXyQBlKdeTPMmALqBUbEk38McWv0qVEZwOpVJBi7ugK5qVNgeuYjGNQxrrnoM/5+TI/BPw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/project-service": "8.39.1", + "@typescript-eslint/tsconfig-utils": "8.39.1", + "@typescript-eslint/types": "8.39.1", + "@typescript-eslint/visitor-keys": "8.39.1", + "debug": "^4.3.4", + "fast-glob": "^3.3.2", + "is-glob": "^4.0.3", + "minimatch": "^9.0.4", + "semver": "^7.6.0", + "ts-api-utils": "^2.1.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "typescript": ">=4.8.4 <6.0.0" + } + }, + "node_modules/typescript-eslint/node_modules/brace-expansion": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.2.tgz", + "integrity": "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "node_modules/typescript-eslint/node_modules/minimatch": { + "version": "9.0.5", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", + "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", + "dev": true, + "license": "ISC", + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/typescript-eslint/node_modules/semver": { + "version": "7.7.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.2.tgz", + "integrity": "sha512-RF0Fw+rO5AMf9MAyaRXI4AV0Ulj5lMHqVxxdSgiVbixSCXoEmmX/jk0CuJw4+3SqroYO9VoUh+HcuJivvtJemA==", + "dev": true, + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/uc.micro": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-2.1.0.tgz", @@ -5238,9 +5456,9 @@ } }, "node_modules/vite": { - "version": "7.1.1", - "resolved": "https://registry.npmjs.org/vite/-/vite-7.1.1.tgz", - "integrity": "sha512-yJ+Mp7OyV+4S+afWo+QyoL9jFWD11QFH0i5i7JypnfTcA1rmgxCbiA8WwAICDEtZ1Z1hzrVhN8R8rGTqkTY8ZQ==", + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/vite/-/vite-7.1.2.tgz", + "integrity": "sha512-J0SQBPlQiEXAF7tajiH+rUooJPo0l8KQgyg4/aMunNtrOa7bwuZJsJbDWzeljqQpgftxuq5yNJxQ91O9ts29UQ==", "dev": true, "license": "MIT", "dependencies": { @@ -5312,32 +5530,19 @@ } } }, - "node_modules/vite/node_modules/fdir": { - "version": "6.4.6", - "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.4.6.tgz", - "integrity": "sha512-hiFoqpyZcfNm1yc4u8oWCf9A2c4D3QjCrks3zmoVKVxpQRzmPNar1hUJcBG2RQHvEVGDN+Jm81ZheVLAQMK6+w==", - "dev": true, - "license": "MIT", - "peerDependencies": { - "picomatch": "^3 || ^4" - }, - "peerDependenciesMeta": { - "picomatch": { - "optional": true - } - } - }, - "node_modules/vite/node_modules/picomatch": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.3.tgz", - "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==", + "node_modules/vite/node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", "dev": true, + "hasInstallScript": true, "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/sponsors/jonschlinkert" + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" } }, "node_modules/which": { @@ -5456,16 +5661,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/zod": { - "version": "3.25.76", - "resolved": "https://registry.npmjs.org/zod/-/zod-3.25.76.tgz", - "integrity": "sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ==", - "dev": true, - "license": "MIT", - "funding": { - "url": "https://github.com/sponsors/colinhacks" - } - }, "node_modules/zx": { "version": "8.8.0", "resolved": "https://registry.npmjs.org/zx/-/zx-8.8.0.tgz", @@ -5632,6 +5827,14 @@ "node": "^20.19.0 || ^22.12.0 || >=23" } }, + "packages/cxx-gen-ast/node_modules/zod": { + "version": "3.25.76", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/colinhacks" + } + }, "packages/cxx-gen-lsp": { "name": "@robertoraggi/cxx-gen-lsp", "version": "1.0.0", @@ -5684,15 +5887,11 @@ }, "packages/cxx-playground/node_modules/@rolldown/pluginutils": { "version": "1.0.0-beta.27", - "resolved": "https://registry.npmjs.org/@rolldown/pluginutils/-/pluginutils-1.0.0-beta.27.tgz", - "integrity": "sha512-+d0F4MKMCbeVUJwG96uQ4SgAznZNSq93I3V+9NHA4OpvqG8mRCpGdKmK8l/dl02h2CCDHwW2FqilnTyDcAnqjA==", "dev": true, "license": "MIT" }, "packages/cxx-playground/node_modules/@vitejs/plugin-react": { "version": "4.7.0", - "resolved": "https://registry.npmjs.org/@vitejs/plugin-react/-/plugin-react-4.7.0.tgz", - "integrity": "sha512-gUu9hwfWvvEDBBmgtAowQCojwZmJ5mcLn3aufeCsitijs3+f2NsrPtlAWIR6OPiqljl96GVCUbLe0HyqIpVaoA==", "dev": true, "license": "MIT", "dependencies": { @@ -5712,8 +5911,6 @@ }, "packages/cxx-playground/node_modules/lucide-react": { "version": "0.525.0", - "resolved": "https://registry.npmjs.org/lucide-react/-/lucide-react-0.525.0.tgz", - "integrity": "sha512-Tm1txJ2OkymCGkvwoHt33Y2JpN5xucVq1slHcgE6Lk0WjDfjgKWor5CdVER8U6DvcfMwh4M8XxmpTiyzfmfDYQ==", "dev": true, "license": "ISC", "peerDependencies": { diff --git a/package.json b/package.json index 2b6f1a47..d5b7a1a8 100644 --- a/package.json +++ b/package.json @@ -25,14 +25,14 @@ }, "devDependencies": { "@eslint/js": "^9.33.0", - "@radix-ui/react-dialog": "^1.1.14", + "@radix-ui/react-dialog": "^1.1.15", "@radix-ui/react-separator": "^1.1.7", "@radix-ui/react-slot": "^1.2.3", - "@radix-ui/react-tooltip": "^1.2.7", - "@tailwindcss/vite": "^4.1.11", - "@tanstack/react-query": "^5.84.2", + "@radix-ui/react-tooltip": "^1.2.8", + "@tailwindcss/vite": "^4.1.12", + "@tanstack/react-query": "^5.85.3", "@types/node": "^24.2.1", - "@types/react": "^19.1.9", + "@types/react": "^19.1.10", "@types/react-dom": "^19.1.7", "@types/react-window": "^1.8.8", "@vitejs/plugin-react": "^5.0.0", @@ -56,13 +56,13 @@ "react-virtualized-auto-sizer": "^1.0.26", "react-window": "^1.8.11", "tailwind-merge": "^3.3.1", - "tailwindcss": "^4.1.11", + "tailwindcss": "^4.1.12", "tw-animate-css": "^1.3.6", "typedoc": "^0.28.9", "typescript": "^5.9.2", - "typescript-eslint": "^8.39.0", + "typescript-eslint": "^8.39.1", "use-debounce": "^10.0.5", - "vite": "^7.1.1", + "vite": "^7.1.2", "zx": "^8.8.0" }, "workspaces": [ From 32da7854d3faff5037d2297d12b5bf32f587730c Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Fri, 15 Aug 2025 11:20:19 +0200 Subject: [PATCH 2/2] Integrate AST rewriter --- .../cxx-gen-ast/src/new_ast_rewriter_cc.ts | 2 +- src/mlir/cxx/mlir/codegen.cc | 11 + src/mlir/cxx/mlir/codegen.h | 2 + src/mlir/cxx/mlir/codegen_declarations.cc | 30 +- src/mlir/cxx/mlir/codegen_expressions.cc | 44 +- src/mlir/cxx/mlir/codegen_units.cc | 38 + src/parser/CMakeLists.txt | 8 +- src/parser/cxx/ast.h | 2 +- src/parser/cxx/ast_rewriter.cc | 4875 +---------------- src/parser/cxx/ast_rewriter.h | 150 +- src/parser/cxx/ast_rewriter_declarations.cc | 1045 ++++ src/parser/cxx/ast_rewriter_declarators.cc | 504 ++ src/parser/cxx/ast_rewriter_expressions.cc | 1543 ++++++ src/parser/cxx/ast_rewriter_names.cc | 325 ++ src/parser/cxx/ast_rewriter_specifiers.cc | 947 ++++ src/parser/cxx/ast_rewriter_statements.cc | 552 ++ src/parser/cxx/ast_rewriter_units.cc | 195 + src/parser/cxx/binder.cc | 133 +- src/parser/cxx/binder.h | 16 +- src/parser/cxx/control.cc | 33 +- src/parser/cxx/control.h | 17 +- src/parser/cxx/external_name_encoder.cc | 13 +- src/parser/cxx/parser.cc | 137 +- src/parser/cxx/parser.h | 4 +- src/parser/cxx/symbol_instantiation.cc | 679 --- src/parser/cxx/symbol_instantiation.h | 75 - src/parser/cxx/symbol_printer.cc | 41 +- src/parser/cxx/symbols.cc | 82 +- src/parser/cxx/symbols.h | 52 +- src/parser/cxx/type_printer.cc | 27 +- src/parser/cxx/type_traits.h | 18 +- src/parser/cxx/types.h | 32 +- tests/api_tests/CMakeLists.txt | 2 - tests/api_tests/test_rewriter.cc | 324 -- tests/api_tests/test_substitution.cc | 164 - tests/api_tests/test_utils.h | 6 - tests/unit_tests/sema/template_alias_01.cc | 2 +- tests/unit_tests/sema/template_alias_02.cc | 26 +- tests/unit_tests/sema/template_class_01.cc | 16 +- tests/unit_tests/sema/template_class_02.cc | 40 +- 40 files changed, 5848 insertions(+), 6364 deletions(-) create mode 100644 src/parser/cxx/ast_rewriter_declarations.cc create mode 100644 src/parser/cxx/ast_rewriter_declarators.cc create mode 100644 src/parser/cxx/ast_rewriter_expressions.cc create mode 100644 src/parser/cxx/ast_rewriter_names.cc create mode 100644 src/parser/cxx/ast_rewriter_specifiers.cc create mode 100644 src/parser/cxx/ast_rewriter_statements.cc create mode 100644 src/parser/cxx/ast_rewriter_units.cc delete mode 100644 src/parser/cxx/symbol_instantiation.cc delete mode 100644 src/parser/cxx/symbol_instantiation.h delete mode 100644 tests/api_tests/test_rewriter.cc delete mode 100644 tests/api_tests/test_substitution.cc diff --git a/packages/cxx-gen-ast/src/new_ast_rewriter_cc.ts b/packages/cxx-gen-ast/src/new_ast_rewriter_cc.ts index 84ba4d6c..7b36fd77 100644 --- a/packages/cxx-gen-ast/src/new_ast_rewriter_cc.ts +++ b/packages/cxx-gen-ast/src/new_ast_rewriter_cc.ts @@ -359,7 +359,7 @@ if (auto param = symbol_cast(ast->symbol); std::optional index{n}; std::swap(rewrite.elementIndex_, index); - auto expression = rewrite(ast->expression); + auto expression = rewrite.expression(ast->expression); if (!current) { current = expression; } else { diff --git a/src/mlir/cxx/mlir/codegen.cc b/src/mlir/cxx/mlir/codegen.cc index fd29345d..fc694c7e 100644 --- a/src/mlir/cxx/mlir/codegen.cc +++ b/src/mlir/cxx/mlir/codegen.cc @@ -109,6 +109,17 @@ auto Codegen::findOrCreateFunction(FunctionSymbol* functionSymbol) std::vector inputTypes; std::vector resultTypes; + if (!functionSymbol->isStatic() && + functionSymbol->enclosingSymbol()->isClass()) { + // if it is a non static member function, we need to add the `this` pointer + + auto classSymbol = + symbol_cast(functionSymbol->enclosingSymbol()); + + inputTypes.push_back(builder_.getType( + convertType(classSymbol->type()))); + } + for (auto paramTy : functionType->parameterTypes()) { inputTypes.push_back(convertType(paramTy)); } diff --git a/src/mlir/cxx/mlir/codegen.h b/src/mlir/cxx/mlir/codegen.h index 3800c7aa..06fb25f1 100644 --- a/src/mlir/cxx/mlir/codegen.h +++ b/src/mlir/cxx/mlir/codegen.h @@ -314,8 +314,10 @@ class Codegen { mlir::ModuleOp module_; mlir::cxx::FuncOp function_; TranslationUnit* unit_ = nullptr; + mlir::Block* entryBlock_ = nullptr; mlir::Block* exitBlock_ = nullptr; mlir::cxx::AllocaOp exitValue_; + mlir::Value thisValue_; std::unordered_map classNames_; std::unordered_map locals_; std::unordered_map funcOps_; diff --git a/src/mlir/cxx/mlir/codegen_declarations.cc b/src/mlir/cxx/mlir/codegen_declarations.cc index 04b90d0f..a193d3f9 100644 --- a/src/mlir/cxx/mlir/codegen_declarations.cc +++ b/src/mlir/cxx/mlir/codegen_declarations.cc @@ -348,7 +348,9 @@ auto Codegen::DeclarationVisitor::operator()(FunctionDefinitionAST* ast) // Add the function body. auto entryBlock = gen.builder_.createBlock(&func.getBody()); - for (const auto& input : func.getFunctionType().getInputs()) { + auto inputs = func.getFunctionType().getInputs(); + + for (const auto& input : inputs) { entryBlock->addArgument(input, loc); } @@ -370,17 +372,36 @@ auto Codegen::DeclarationVisitor::operator()(FunctionDefinitionAST* ast) // function state std::swap(gen.function_, func); + std::swap(gen.entryBlock_, entryBlock); std::swap(gen.exitBlock_, exitBlock); std::swap(gen.exitValue_, exitValue); std::swap(gen.locals_, locals); + mlir::Value thisValue; + + // if this is a non static member function, we need to allocate the `this` + if (!functionSymbol->isStatic() && + functionSymbol->enclosingSymbol()->isClass()) { + auto classSymbol = + symbol_cast(functionSymbol->enclosingSymbol()); + + auto thisType = gen.convertType(classSymbol->type()); + auto ptrType = gen.builder_.getType(thisType); + + thisValue = gen.newTemp(classSymbol->type(), ast->firstSourceLocation()); + + // store the `this` pointer in the entry block + gen.builder_.create( + loc, gen.entryBlock_->getArgument(0), thisValue); + } + FunctionParametersSymbol* params = nullptr; for (auto member : ast->symbol->scope()->symbols()) { params = symbol_cast(member); if (!params) continue; int argc = 0; - auto args = entryBlock->getArguments(); + auto args = gen.entryBlock_->getArguments(); for (auto param : params->scope()->symbols()) { auto arg = symbol_cast(param); if (!arg) continue; @@ -399,6 +420,8 @@ auto Codegen::DeclarationVisitor::operator()(FunctionDefinitionAST* ast) } } + std::swap(gen.thisValue_, thisValue); + allocateLocals(functionSymbol); // generate code for the function body @@ -428,7 +451,10 @@ auto Codegen::DeclarationVisitor::operator()(FunctionDefinitionAST* ast) } // restore the state + std::swap(gen.thisValue_, thisValue); + std::swap(gen.function_, func); + std::swap(gen.entryBlock_, entryBlock); std::swap(gen.exitBlock_, exitBlock); std::swap(gen.exitValue_, exitValue); std::swap(gen.locals_, locals); diff --git a/src/mlir/cxx/mlir/codegen_expressions.cc b/src/mlir/cxx/mlir/codegen_expressions.cc index 2e2227d3..560d9e98 100644 --- a/src/mlir/cxx/mlir/codegen_expressions.cc +++ b/src/mlir/cxx/mlir/codegen_expressions.cc @@ -299,9 +299,15 @@ auto Codegen::ExpressionVisitor::operator()(ObjectLiteralExpressionAST* ast) auto Codegen::ExpressionVisitor::operator()(ThisExpressionAST* ast) -> ExpressionResult { - auto op = - gen.emitTodoExpr(ast->firstSourceLocation(), to_string(ast->kind())); - return {op}; + auto type = gen.convertType(ast->type); + auto loc = gen.getLocation(ast->firstSourceLocation()); + + auto loadOp = + gen.builder_.create(loc, type, gen.thisValue_); + return {loadOp}; + // auto op = + // gen.emitTodoExpr(ast->firstSourceLocation(), to_string(ast->kind())); + // return {op}; } auto Codegen::ExpressionVisitor::operator()(GenericSelectionExpressionAST* ast) @@ -499,6 +505,38 @@ auto Codegen::ExpressionVisitor::operator()(CallExpressionAST* ast) func = nested->expression; } + if (auto member = ast_cast(func)) { + auto thisValue = gen.expression(member->baseExpression); + auto functionSymbol = symbol_cast(member->symbol); + + auto funcOp = gen.findOrCreateFunction(functionSymbol); + + mlir::SmallVector arguments; + arguments.push_back(thisValue.value); + for (auto node : ListView{ast->expressionList}) { + auto value = gen.expression(node); + arguments.push_back(value.value); + } + + auto loc = gen.getLocation(ast->lparenLoc); + + auto functionType = type_cast(functionSymbol->type()); + mlir::SmallVector resultTypes; + if (!control()->is_void(functionType->returnType())) { + resultTypes.push_back(gen.convertType(functionType->returnType())); + } + + auto op = gen.builder_.create( + loc, resultTypes, funcOp.getSymName(), arguments, mlir::TypeAttr{}); + + if (functionType->isVariadic()) { + op.setVarCalleeType( + cast(gen.convertType(functionType))); + } + + return ExpressionResult{op.getResult()}; + } + auto id = ast_cast(func); if (!id) return {}; diff --git a/src/mlir/cxx/mlir/codegen_units.cc b/src/mlir/cxx/mlir/codegen_units.cc index 9ecac161..cb7a79e7 100644 --- a/src/mlir/cxx/mlir/codegen_units.cc +++ b/src/mlir/cxx/mlir/codegen_units.cc @@ -25,6 +25,8 @@ #include #include #include +#include +#include #include // mlir @@ -62,6 +64,38 @@ struct Codegen::UnitVisitor { auto operator()(TranslationUnitAST* ast) -> UnitResult; auto operator()(ModuleUnitAST* ast) -> UnitResult; + + struct VisitSymbols { + UnitVisitor& p; + + void operator()(NamespaceSymbol* symbol) { + for (auto member : symbol->scope()->symbols()) { + visit(*this, member); + } + } + + void operator()(FunctionSymbol* symbol) { + if (auto funcDecl = symbol->declaration()) { + p.gen.declaration(funcDecl); + } + } + + void operator()(ClassSymbol* symbol) { + for (auto specialization : symbol->specializations()) { + visit(*this, specialization.symbol); + } + + if (!symbol->templateParameters()) { + for (auto member : symbol->scope()->symbols()) { + visit(*this, member); + } + } + } + + void operator()(Symbol*) { + // Do nothing for other symbols. + } + } visitor{*this}; }; auto Codegen::operator()(UnitAST* ast) -> UnitResult { @@ -115,6 +149,9 @@ auto Codegen::UnitVisitor::operator()(TranslationUnitAST* ast) -> UnitResult { std::swap(gen.module_, module); + visit(visitor, gen.unit_->globalScope()->owner()); + +#if false ForEachExternalDefinition forEachExternalDefinition; forEachExternalDefinition.functionCallback = @@ -125,6 +162,7 @@ auto Codegen::UnitVisitor::operator()(TranslationUnitAST* ast) -> UnitResult { for (auto node : ListView{ast->declarationList}) { forEachExternalDefinition.accept(node); } +#endif std::swap(gen.module_, module); diff --git a/src/parser/CMakeLists.txt b/src/parser/CMakeLists.txt index d471adeb..cfec9b11 100644 --- a/src/parser/CMakeLists.txt +++ b/src/parser/CMakeLists.txt @@ -25,6 +25,13 @@ add_library(cxx-parser cxx/ast_interpreter.cc cxx/ast_pretty_printer.cc cxx/ast_printer.cc + cxx/ast_rewriter_declarations.cc + cxx/ast_rewriter_declarators.cc + cxx/ast_rewriter_expressions.cc + cxx/ast_rewriter_names.cc + cxx/ast_rewriter_specifiers.cc + cxx/ast_rewriter_statements.cc + cxx/ast_rewriter_units.cc cxx/ast_rewriter.cc cxx/ast_slot.cc cxx/ast_visitor.cc @@ -54,7 +61,6 @@ add_library(cxx-parser cxx/scope.cc cxx/source_location.cc cxx/symbol_chain_view.cc - cxx/symbol_instantiation.cc cxx/symbol_printer.cc cxx/symbols.cc cxx/token.cc diff --git a/src/parser/cxx/ast.h b/src/parser/cxx/ast.h index c5ec219d..2c67e47d 100644 --- a/src/parser/cxx/ast.h +++ b/src/parser/cxx/ast.h @@ -3703,7 +3703,7 @@ class SimpleTemplateIdAST final : public UnqualifiedIdAST { List* templateArgumentList = nullptr; SourceLocation greaterLoc; const Identifier* identifier = nullptr; - Symbol* primaryTemplateSymbol = nullptr; + Symbol* symbol = nullptr; void accept(ASTVisitor* visitor) override { visitor->visit(this); } diff --git a/src/parser/cxx/ast_rewriter.cc b/src/parser/cxx/ast_rewriter.cc index 98ae84ec..23fff81e 100644 --- a/src/parser/cxx/ast_rewriter.cc +++ b/src/parser/cxx/ast_rewriter.cc @@ -22,27 +22,62 @@ // cxx #include -#include -#include +#include #include -#include -#include -#include #include #include #include #include -#include +// todo remove +#include namespace cxx { -ASTRewriter::ASTRewriter(TypeChecker* typeChcker, +auto ASTRewriter::make_substitution( + TranslationUnit* unit, TemplateDeclarationAST* templateDecl, + List* templateArgumentList) + -> std::vector { + auto control = unit->control(); + auto interp = ASTInterpreter{unit}; + + std::vector templateArguments; + + for (auto arg : ListView{templateArgumentList}) { + if (auto exprArg = ast_cast(arg)) { + auto expr = exprArg->expression; + auto value = interp.evaluate(expr); + if (!value.has_value()) { +#if false + unit->error(arg->firstSourceLocation(), + "template argument is not a constant expression"); +#endif + continue; + } + + // ### need to set scope and location + auto templArg = control->newVariableSymbol(nullptr, {}); + templArg->setInitializer(expr); + templArg->setType(control->add_const(expr->type)); + templArg->setConstValue(value); + templateArguments.push_back(templArg); + } else if (auto typeArg = ast_cast(arg)) { + auto type = typeArg->typeId->type; + // ### need to set scope and location + auto templArg = control->newTypeAliasSymbol(nullptr, {}); + templArg->setType(type); + templateArguments.push_back(templArg); + } + } + + return templateArguments; +} + +ASTRewriter::ASTRewriter(TranslationUnit* unit, Scope* scope, const std::vector& templateArguments) - : typeChecker_(typeChcker), - unit_(typeChcker->translationUnit()), - templateArguments_(templateArguments), - binder_(typeChcker->translationUnit()) {} + : unit_(unit), templateArguments_(templateArguments), binder_(unit_) { + binder_.setScope(scope); +} ASTRewriter::~ASTRewriter() {} @@ -58,6 +93,20 @@ void ASTRewriter::setRestrictedToDeclarations(bool restrictedToDeclarations) { restrictedToDeclarations_ = restrictedToDeclarations; } +void ASTRewriter::warning(SourceLocation loc, std::string message) { + binder_.warning(loc, std::move(message)); +} + +void ASTRewriter::error(SourceLocation loc, std::string message) { + binder_.error(loc, std::move(message)); +} + +void ASTRewriter::check(ExpressionAST* ast) { + auto typeChecker = TypeChecker{unit_}; + typeChecker.setScope(binder_.scope()); + typeChecker.check(ast); +} + auto ASTRewriter::getParameterPack(ExpressionAST* ast) -> ParameterPackSymbol* { for (auto cursor = ASTCursor{ast, {}}; cursor; ++cursor) { const auto& current = *cursor; @@ -81,4774 +130,110 @@ auto ASTRewriter::getParameterPack(ExpressionAST* ast) -> ParameterPackSymbol* { return nullptr; } -struct ASTRewriter::UnitVisitor { - ASTRewriter& rewrite; - [[nodiscard]] auto translationUnit() const -> TranslationUnit* { - return rewrite.unit_; - } - - [[nodiscard]] auto control() const -> Control* { return rewrite.control(); } - [[nodiscard]] auto arena() const -> Arena* { return rewrite.arena(); } - [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } - [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } - - [[nodiscard]] auto operator()(TranslationUnitAST* ast) -> UnitAST*; - - [[nodiscard]] auto operator()(ModuleUnitAST* ast) -> UnitAST*; -}; - -struct ASTRewriter::DeclarationVisitor { - ASTRewriter& rewrite; - [[nodiscard]] auto translationUnit() const -> TranslationUnit* { - return rewrite.unit_; - } - - [[nodiscard]] auto control() const -> Control* { return rewrite.control(); } - [[nodiscard]] auto arena() const -> Arena* { return rewrite.arena(); } - [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } - [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } - - [[nodiscard]] auto operator()(SimpleDeclarationAST* ast) -> DeclarationAST*; - - [[nodiscard]] auto operator()(AsmDeclarationAST* ast) -> DeclarationAST*; - - [[nodiscard]] auto operator()(NamespaceAliasDefinitionAST* ast) - -> DeclarationAST*; - - [[nodiscard]] auto operator()(UsingDeclarationAST* ast) -> DeclarationAST*; - - [[nodiscard]] auto operator()(UsingEnumDeclarationAST* ast) - -> DeclarationAST*; - - [[nodiscard]] auto operator()(UsingDirectiveAST* ast) -> DeclarationAST*; - - [[nodiscard]] auto operator()(StaticAssertDeclarationAST* ast) - -> DeclarationAST*; - - [[nodiscard]] auto operator()(AliasDeclarationAST* ast) -> DeclarationAST*; - - [[nodiscard]] auto operator()(OpaqueEnumDeclarationAST* ast) - -> DeclarationAST*; - - [[nodiscard]] auto operator()(FunctionDefinitionAST* ast) -> DeclarationAST*; - - [[nodiscard]] auto operator()(TemplateDeclarationAST* ast) -> DeclarationAST*; - - [[nodiscard]] auto operator()(ConceptDefinitionAST* ast) -> DeclarationAST*; - - [[nodiscard]] auto operator()(DeductionGuideAST* ast) -> DeclarationAST*; - - [[nodiscard]] auto operator()(ExplicitInstantiationAST* ast) - -> DeclarationAST*; - - [[nodiscard]] auto operator()(ExportDeclarationAST* ast) -> DeclarationAST*; - - [[nodiscard]] auto operator()(ExportCompoundDeclarationAST* ast) - -> DeclarationAST*; - - [[nodiscard]] auto operator()(LinkageSpecificationAST* ast) - -> DeclarationAST*; - - [[nodiscard]] auto operator()(NamespaceDefinitionAST* ast) -> DeclarationAST*; - - [[nodiscard]] auto operator()(EmptyDeclarationAST* ast) -> DeclarationAST*; - - [[nodiscard]] auto operator()(AttributeDeclarationAST* ast) - -> DeclarationAST*; - - [[nodiscard]] auto operator()(ModuleImportDeclarationAST* ast) - -> DeclarationAST*; - - [[nodiscard]] auto operator()(ParameterDeclarationAST* ast) - -> DeclarationAST*; - - [[nodiscard]] auto operator()(AccessDeclarationAST* ast) -> DeclarationAST*; - - [[nodiscard]] auto operator()(ForRangeDeclarationAST* ast) -> DeclarationAST*; - - [[nodiscard]] auto operator()(StructuredBindingDeclarationAST* ast) - -> DeclarationAST*; -}; - -struct ASTRewriter::StatementVisitor { - ASTRewriter& rewrite; - [[nodiscard]] auto translationUnit() const -> TranslationUnit* { - return rewrite.unit_; - } - - [[nodiscard]] auto control() const -> Control* { return rewrite.control(); } - [[nodiscard]] auto arena() const -> Arena* { return rewrite.arena(); } - [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } - [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } - - [[nodiscard]] auto operator()(LabeledStatementAST* ast) -> StatementAST*; - - [[nodiscard]] auto operator()(CaseStatementAST* ast) -> StatementAST*; - - [[nodiscard]] auto operator()(DefaultStatementAST* ast) -> StatementAST*; - - [[nodiscard]] auto operator()(ExpressionStatementAST* ast) -> StatementAST*; - - [[nodiscard]] auto operator()(CompoundStatementAST* ast) -> StatementAST*; - - [[nodiscard]] auto operator()(IfStatementAST* ast) -> StatementAST*; - - [[nodiscard]] auto operator()(ConstevalIfStatementAST* ast) -> StatementAST*; - - [[nodiscard]] auto operator()(SwitchStatementAST* ast) -> StatementAST*; - - [[nodiscard]] auto operator()(WhileStatementAST* ast) -> StatementAST*; - - [[nodiscard]] auto operator()(DoStatementAST* ast) -> StatementAST*; - - [[nodiscard]] auto operator()(ForRangeStatementAST* ast) -> StatementAST*; - - [[nodiscard]] auto operator()(ForStatementAST* ast) -> StatementAST*; - - [[nodiscard]] auto operator()(BreakStatementAST* ast) -> StatementAST*; - - [[nodiscard]] auto operator()(ContinueStatementAST* ast) -> StatementAST*; - - [[nodiscard]] auto operator()(ReturnStatementAST* ast) -> StatementAST*; - - [[nodiscard]] auto operator()(CoroutineReturnStatementAST* ast) - -> StatementAST*; - - [[nodiscard]] auto operator()(GotoStatementAST* ast) -> StatementAST*; - - [[nodiscard]] auto operator()(DeclarationStatementAST* ast) -> StatementAST*; - - [[nodiscard]] auto operator()(TryBlockStatementAST* ast) -> StatementAST*; -}; - -struct ASTRewriter::ExpressionVisitor { - ASTRewriter& rewrite; - [[nodiscard]] auto translationUnit() const -> TranslationUnit* { - return rewrite.unit_; - } - - [[nodiscard]] auto control() const -> Control* { return rewrite.control(); } - [[nodiscard]] auto arena() const -> Arena* { return rewrite.arena(); } - [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } - [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } - - [[nodiscard]] auto operator()(GeneratedLiteralExpressionAST* ast) - -> ExpressionAST*; - - [[nodiscard]] auto operator()(CharLiteralExpressionAST* ast) - -> ExpressionAST*; - - [[nodiscard]] auto operator()(BoolLiteralExpressionAST* ast) - -> ExpressionAST*; - - [[nodiscard]] auto operator()(IntLiteralExpressionAST* ast) -> ExpressionAST*; - - [[nodiscard]] auto operator()(FloatLiteralExpressionAST* ast) - -> ExpressionAST*; - - [[nodiscard]] auto operator()(NullptrLiteralExpressionAST* ast) - -> ExpressionAST*; - - [[nodiscard]] auto operator()(StringLiteralExpressionAST* ast) - -> ExpressionAST*; - - [[nodiscard]] auto operator()(UserDefinedStringLiteralExpressionAST* ast) - -> ExpressionAST*; - - [[nodiscard]] auto operator()(ObjectLiteralExpressionAST* ast) - -> ExpressionAST*; - - [[nodiscard]] auto operator()(ThisExpressionAST* ast) -> ExpressionAST*; - - [[nodiscard]] auto operator()(GenericSelectionExpressionAST* ast) - -> ExpressionAST*; - - [[nodiscard]] auto operator()(NestedStatementExpressionAST* ast) - -> ExpressionAST*; - - [[nodiscard]] auto operator()(NestedExpressionAST* ast) -> ExpressionAST*; - - [[nodiscard]] auto operator()(IdExpressionAST* ast) -> ExpressionAST*; - - [[nodiscard]] auto operator()(LambdaExpressionAST* ast) -> ExpressionAST*; - - [[nodiscard]] auto operator()(FoldExpressionAST* ast) -> ExpressionAST*; - - [[nodiscard]] auto operator()(RightFoldExpressionAST* ast) -> ExpressionAST*; - - [[nodiscard]] auto operator()(LeftFoldExpressionAST* ast) -> ExpressionAST*; - - [[nodiscard]] auto operator()(RequiresExpressionAST* ast) -> ExpressionAST*; - - [[nodiscard]] auto operator()(VaArgExpressionAST* ast) -> ExpressionAST*; - - [[nodiscard]] auto operator()(SubscriptExpressionAST* ast) -> ExpressionAST*; - - [[nodiscard]] auto operator()(CallExpressionAST* ast) -> ExpressionAST*; - - [[nodiscard]] auto operator()(TypeConstructionAST* ast) -> ExpressionAST*; - - [[nodiscard]] auto operator()(BracedTypeConstructionAST* ast) - -> ExpressionAST*; - - [[nodiscard]] auto operator()(SpliceMemberExpressionAST* ast) - -> ExpressionAST*; - - [[nodiscard]] auto operator()(MemberExpressionAST* ast) -> ExpressionAST*; - - [[nodiscard]] auto operator()(PostIncrExpressionAST* ast) -> ExpressionAST*; - - [[nodiscard]] auto operator()(CppCastExpressionAST* ast) -> ExpressionAST*; - - [[nodiscard]] auto operator()(BuiltinBitCastExpressionAST* ast) - -> ExpressionAST*; - - [[nodiscard]] auto operator()(BuiltinOffsetofExpressionAST* ast) - -> ExpressionAST*; - - [[nodiscard]] auto operator()(TypeidExpressionAST* ast) -> ExpressionAST*; - - [[nodiscard]] auto operator()(TypeidOfTypeExpressionAST* ast) - -> ExpressionAST*; - - [[nodiscard]] auto operator()(SpliceExpressionAST* ast) -> ExpressionAST*; - - [[nodiscard]] auto operator()(GlobalScopeReflectExpressionAST* ast) - -> ExpressionAST*; - - [[nodiscard]] auto operator()(NamespaceReflectExpressionAST* ast) - -> ExpressionAST*; - - [[nodiscard]] auto operator()(TypeIdReflectExpressionAST* ast) - -> ExpressionAST*; - - [[nodiscard]] auto operator()(ReflectExpressionAST* ast) -> ExpressionAST*; - - [[nodiscard]] auto operator()(LabelAddressExpressionAST* ast) - -> ExpressionAST*; - - [[nodiscard]] auto operator()(UnaryExpressionAST* ast) -> ExpressionAST*; - - [[nodiscard]] auto operator()(AwaitExpressionAST* ast) -> ExpressionAST*; - - [[nodiscard]] auto operator()(SizeofExpressionAST* ast) -> ExpressionAST*; - - [[nodiscard]] auto operator()(SizeofTypeExpressionAST* ast) -> ExpressionAST*; - - [[nodiscard]] auto operator()(SizeofPackExpressionAST* ast) -> ExpressionAST*; - - [[nodiscard]] auto operator()(AlignofTypeExpressionAST* ast) - -> ExpressionAST*; - - [[nodiscard]] auto operator()(AlignofExpressionAST* ast) -> ExpressionAST*; - - [[nodiscard]] auto operator()(NoexceptExpressionAST* ast) -> ExpressionAST*; - - [[nodiscard]] auto operator()(NewExpressionAST* ast) -> ExpressionAST*; - - [[nodiscard]] auto operator()(DeleteExpressionAST* ast) -> ExpressionAST*; - - [[nodiscard]] auto operator()(CastExpressionAST* ast) -> ExpressionAST*; - - [[nodiscard]] auto operator()(ImplicitCastExpressionAST* ast) - -> ExpressionAST*; - - [[nodiscard]] auto operator()(BinaryExpressionAST* ast) -> ExpressionAST*; - - [[nodiscard]] auto operator()(ConditionalExpressionAST* ast) - -> ExpressionAST*; - - [[nodiscard]] auto operator()(YieldExpressionAST* ast) -> ExpressionAST*; - - [[nodiscard]] auto operator()(ThrowExpressionAST* ast) -> ExpressionAST*; - - [[nodiscard]] auto operator()(AssignmentExpressionAST* ast) -> ExpressionAST*; +auto ASTRewriter::instantiateClassTemplate( + TranslationUnit* unit, List* templateArgumentList, + ClassSymbol* classSymbol) -> ClassSymbol* { + auto templateDecl = classSymbol->templateDeclaration(); - [[nodiscard]] auto operator()(CompoundAssignmentExpressionAST* ast) - -> ExpressionAST*; + ClassSpecifierAST* classSpecifier = + ast_cast(classSymbol->declaration()); - [[nodiscard]] auto operator()(PackExpansionExpressionAST* ast) - -> ExpressionAST*; + if (!classSpecifier) return nullptr; - [[nodiscard]] auto operator()(DesignatedInitializerClauseAST* ast) - -> ExpressionAST*; + auto templateArguments = + make_substitution(unit, templateDecl, templateArgumentList); - [[nodiscard]] auto operator()(TypeTraitExpressionAST* ast) -> ExpressionAST*; + auto is_primary_template = [&]() -> bool { + int expected = 0; + for (const auto& arg : templateArguments) { + if (!std::holds_alternative(arg)) return false; - [[nodiscard]] auto operator()(ConditionExpressionAST* ast) -> ExpressionAST*; + auto ty = type_cast(std::get(arg)->type()); + if (!ty) return false; - [[nodiscard]] auto operator()(EqualInitializerAST* ast) -> ExpressionAST*; - - [[nodiscard]] auto operator()(BracedInitListAST* ast) -> ExpressionAST*; - - [[nodiscard]] auto operator()(ParenInitializerAST* ast) -> ExpressionAST*; -}; - -struct ASTRewriter::GenericAssociationVisitor { - ASTRewriter& rewrite; - [[nodiscard]] auto translationUnit() const -> TranslationUnit* { - return rewrite.unit_; - } - - [[nodiscard]] auto control() const -> Control* { return rewrite.control(); } - [[nodiscard]] auto arena() const -> Arena* { return rewrite.arena(); } - [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } - [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } - - [[nodiscard]] auto operator()(DefaultGenericAssociationAST* ast) - -> GenericAssociationAST*; - - [[nodiscard]] auto operator()(TypeGenericAssociationAST* ast) - -> GenericAssociationAST*; -}; - -struct ASTRewriter::DesignatorVisitor { - ASTRewriter& rewrite; - [[nodiscard]] auto translationUnit() const -> TranslationUnit* { - return rewrite.unit_; - } - - [[nodiscard]] auto control() const -> Control* { return rewrite.control(); } - [[nodiscard]] auto arena() const -> Arena* { return rewrite.arena(); } - [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } - [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } - - [[nodiscard]] auto operator()(DotDesignatorAST* ast) -> DesignatorAST*; - - [[nodiscard]] auto operator()(SubscriptDesignatorAST* ast) -> DesignatorAST*; -}; - -struct ASTRewriter::TemplateParameterVisitor { - ASTRewriter& rewrite; - [[nodiscard]] auto translationUnit() const -> TranslationUnit* { - return rewrite.unit_; - } - - [[nodiscard]] auto control() const -> Control* { return rewrite.control(); } - [[nodiscard]] auto arena() const -> Arena* { return rewrite.arena(); } - [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } - [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } - - [[nodiscard]] auto operator()(TemplateTypeParameterAST* ast) - -> TemplateParameterAST*; - - [[nodiscard]] auto operator()(NonTypeTemplateParameterAST* ast) - -> TemplateParameterAST*; - - [[nodiscard]] auto operator()(TypenameTypeParameterAST* ast) - -> TemplateParameterAST*; - - [[nodiscard]] auto operator()(ConstraintTypeParameterAST* ast) - -> TemplateParameterAST*; -}; - -struct ASTRewriter::SpecifierVisitor { - ASTRewriter& rewrite; - [[nodiscard]] auto translationUnit() const -> TranslationUnit* { - return rewrite.unit_; - } - - [[nodiscard]] auto control() const -> Control* { return rewrite.control(); } - [[nodiscard]] auto arena() const -> Arena* { return rewrite.arena(); } - [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } - [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } - - [[nodiscard]] auto operator()(GeneratedTypeSpecifierAST* ast) - -> SpecifierAST*; - - [[nodiscard]] auto operator()(TypedefSpecifierAST* ast) -> SpecifierAST*; - - [[nodiscard]] auto operator()(FriendSpecifierAST* ast) -> SpecifierAST*; - - [[nodiscard]] auto operator()(ConstevalSpecifierAST* ast) -> SpecifierAST*; - - [[nodiscard]] auto operator()(ConstinitSpecifierAST* ast) -> SpecifierAST*; - - [[nodiscard]] auto operator()(ConstexprSpecifierAST* ast) -> SpecifierAST*; - - [[nodiscard]] auto operator()(InlineSpecifierAST* ast) -> SpecifierAST*; - - [[nodiscard]] auto operator()(NoreturnSpecifierAST* ast) -> SpecifierAST*; - - [[nodiscard]] auto operator()(StaticSpecifierAST* ast) -> SpecifierAST*; - - [[nodiscard]] auto operator()(ExternSpecifierAST* ast) -> SpecifierAST*; - - [[nodiscard]] auto operator()(RegisterSpecifierAST* ast) -> SpecifierAST*; - - [[nodiscard]] auto operator()(ThreadLocalSpecifierAST* ast) -> SpecifierAST*; - - [[nodiscard]] auto operator()(ThreadSpecifierAST* ast) -> SpecifierAST*; - - [[nodiscard]] auto operator()(MutableSpecifierAST* ast) -> SpecifierAST*; - - [[nodiscard]] auto operator()(VirtualSpecifierAST* ast) -> SpecifierAST*; - - [[nodiscard]] auto operator()(ExplicitSpecifierAST* ast) -> SpecifierAST*; - - [[nodiscard]] auto operator()(AutoTypeSpecifierAST* ast) -> SpecifierAST*; - - [[nodiscard]] auto operator()(VoidTypeSpecifierAST* ast) -> SpecifierAST*; - - [[nodiscard]] auto operator()(SizeTypeSpecifierAST* ast) -> SpecifierAST*; - - [[nodiscard]] auto operator()(SignTypeSpecifierAST* ast) -> SpecifierAST*; - - [[nodiscard]] auto operator()(VaListTypeSpecifierAST* ast) -> SpecifierAST*; - - [[nodiscard]] auto operator()(IntegralTypeSpecifierAST* ast) -> SpecifierAST*; - - [[nodiscard]] auto operator()(FloatingPointTypeSpecifierAST* ast) - -> SpecifierAST*; - - [[nodiscard]] auto operator()(ComplexTypeSpecifierAST* ast) -> SpecifierAST*; - - [[nodiscard]] auto operator()(NamedTypeSpecifierAST* ast) -> SpecifierAST*; - - [[nodiscard]] auto operator()(AtomicTypeSpecifierAST* ast) -> SpecifierAST*; - - [[nodiscard]] auto operator()(UnderlyingTypeSpecifierAST* ast) - -> SpecifierAST*; - - [[nodiscard]] auto operator()(ElaboratedTypeSpecifierAST* ast) - -> SpecifierAST*; - - [[nodiscard]] auto operator()(DecltypeAutoSpecifierAST* ast) -> SpecifierAST*; - - [[nodiscard]] auto operator()(DecltypeSpecifierAST* ast) -> SpecifierAST*; - - [[nodiscard]] auto operator()(PlaceholderTypeSpecifierAST* ast) - -> SpecifierAST*; - - [[nodiscard]] auto operator()(ConstQualifierAST* ast) -> SpecifierAST*; - - [[nodiscard]] auto operator()(VolatileQualifierAST* ast) -> SpecifierAST*; - - [[nodiscard]] auto operator()(AtomicQualifierAST* ast) -> SpecifierAST*; - - [[nodiscard]] auto operator()(RestrictQualifierAST* ast) -> SpecifierAST*; - - [[nodiscard]] auto operator()(EnumSpecifierAST* ast) -> SpecifierAST*; - - [[nodiscard]] auto operator()(ClassSpecifierAST* ast) -> SpecifierAST*; - - [[nodiscard]] auto operator()(TypenameSpecifierAST* ast) -> SpecifierAST*; - - [[nodiscard]] auto operator()(SplicerTypeSpecifierAST* ast) -> SpecifierAST*; -}; - -struct ASTRewriter::PtrOperatorVisitor { - ASTRewriter& rewrite; - [[nodiscard]] auto translationUnit() const -> TranslationUnit* { - return rewrite.unit_; - } - - [[nodiscard]] auto control() const -> Control* { return rewrite.control(); } - [[nodiscard]] auto arena() const -> Arena* { return rewrite.arena(); } - [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } - [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } - - [[nodiscard]] auto operator()(PointerOperatorAST* ast) -> PtrOperatorAST*; - - [[nodiscard]] auto operator()(ReferenceOperatorAST* ast) -> PtrOperatorAST*; - - [[nodiscard]] auto operator()(PtrToMemberOperatorAST* ast) -> PtrOperatorAST*; -}; - -struct ASTRewriter::CoreDeclaratorVisitor { - ASTRewriter& rewrite; - [[nodiscard]] auto translationUnit() const -> TranslationUnit* { - return rewrite.unit_; - } - - [[nodiscard]] auto control() const -> Control* { return rewrite.control(); } - [[nodiscard]] auto arena() const -> Arena* { return rewrite.arena(); } - [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } - [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } - - [[nodiscard]] auto operator()(BitfieldDeclaratorAST* ast) - -> CoreDeclaratorAST*; - - [[nodiscard]] auto operator()(ParameterPackAST* ast) -> CoreDeclaratorAST*; - - [[nodiscard]] auto operator()(IdDeclaratorAST* ast) -> CoreDeclaratorAST*; - - [[nodiscard]] auto operator()(NestedDeclaratorAST* ast) -> CoreDeclaratorAST*; -}; - -struct ASTRewriter::DeclaratorChunkVisitor { - ASTRewriter& rewrite; - [[nodiscard]] auto translationUnit() const -> TranslationUnit* { - return rewrite.unit_; - } - - [[nodiscard]] auto control() const -> Control* { return rewrite.control(); } - [[nodiscard]] auto arena() const -> Arena* { return rewrite.arena(); } - [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } - [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } - - [[nodiscard]] auto operator()(FunctionDeclaratorChunkAST* ast) - -> DeclaratorChunkAST*; - - [[nodiscard]] auto operator()(ArrayDeclaratorChunkAST* ast) - -> DeclaratorChunkAST*; -}; - -struct ASTRewriter::UnqualifiedIdVisitor { - ASTRewriter& rewrite; - [[nodiscard]] auto translationUnit() const -> TranslationUnit* { - return rewrite.unit_; - } - - [[nodiscard]] auto control() const -> Control* { return rewrite.control(); } - [[nodiscard]] auto arena() const -> Arena* { return rewrite.arena(); } - [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } - [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } - - [[nodiscard]] auto operator()(NameIdAST* ast) -> UnqualifiedIdAST*; - - [[nodiscard]] auto operator()(DestructorIdAST* ast) -> UnqualifiedIdAST*; - - [[nodiscard]] auto operator()(DecltypeIdAST* ast) -> UnqualifiedIdAST*; - - [[nodiscard]] auto operator()(OperatorFunctionIdAST* ast) - -> UnqualifiedIdAST*; - - [[nodiscard]] auto operator()(LiteralOperatorIdAST* ast) -> UnqualifiedIdAST*; - - [[nodiscard]] auto operator()(ConversionFunctionIdAST* ast) - -> UnqualifiedIdAST*; - - [[nodiscard]] auto operator()(SimpleTemplateIdAST* ast) -> UnqualifiedIdAST*; - - [[nodiscard]] auto operator()(LiteralOperatorTemplateIdAST* ast) - -> UnqualifiedIdAST*; - - [[nodiscard]] auto operator()(OperatorFunctionTemplateIdAST* ast) - -> UnqualifiedIdAST*; -}; - -struct ASTRewriter::NestedNameSpecifierVisitor { - ASTRewriter& rewrite; - [[nodiscard]] auto translationUnit() const -> TranslationUnit* { - return rewrite.unit_; - } - - [[nodiscard]] auto control() const -> Control* { return rewrite.control(); } - [[nodiscard]] auto arena() const -> Arena* { return rewrite.arena(); } - [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } - [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } - - [[nodiscard]] auto operator()(GlobalNestedNameSpecifierAST* ast) - -> NestedNameSpecifierAST*; - - [[nodiscard]] auto operator()(SimpleNestedNameSpecifierAST* ast) - -> NestedNameSpecifierAST*; - - [[nodiscard]] auto operator()(DecltypeNestedNameSpecifierAST* ast) - -> NestedNameSpecifierAST*; - - [[nodiscard]] auto operator()(TemplateNestedNameSpecifierAST* ast) - -> NestedNameSpecifierAST*; -}; - -struct ASTRewriter::FunctionBodyVisitor { - ASTRewriter& rewrite; - [[nodiscard]] auto translationUnit() const -> TranslationUnit* { - return rewrite.unit_; - } - - [[nodiscard]] auto control() const -> Control* { return rewrite.control(); } - [[nodiscard]] auto arena() const -> Arena* { return rewrite.arena(); } - [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } - [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } - - [[nodiscard]] auto operator()(DefaultFunctionBodyAST* ast) - -> FunctionBodyAST*; - - [[nodiscard]] auto operator()(CompoundStatementFunctionBodyAST* ast) - -> FunctionBodyAST*; - - [[nodiscard]] auto operator()(TryStatementFunctionBodyAST* ast) - -> FunctionBodyAST*; - - [[nodiscard]] auto operator()(DeleteFunctionBodyAST* ast) -> FunctionBodyAST*; -}; + if (ty->index() != expected) return false; + ++expected; + } + return true; + }; -struct ASTRewriter::TemplateArgumentVisitor { - ASTRewriter& rewrite; - [[nodiscard]] auto translationUnit() const -> TranslationUnit* { - return rewrite.unit_; + if (is_primary_template()) { + // if this is a primary template, we can just return the class symbol + return classSymbol; } - [[nodiscard]] auto control() const -> Control* { return rewrite.control(); } - [[nodiscard]] auto arena() const -> Arena* { return rewrite.arena(); } - [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } - [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } - - [[nodiscard]] auto operator()(TypeTemplateArgumentAST* ast) - -> TemplateArgumentAST*; - - [[nodiscard]] auto operator()(ExpressionTemplateArgumentAST* ast) - -> TemplateArgumentAST*; -}; - -struct ASTRewriter::ExceptionSpecifierVisitor { - ASTRewriter& rewrite; - [[nodiscard]] auto translationUnit() const -> TranslationUnit* { - return rewrite.unit_; + auto subst = classSymbol->findSpecialization(templateArguments); + if (subst) { + return subst; } - [[nodiscard]] auto control() const -> Control* { return rewrite.control(); } - [[nodiscard]] auto arena() const -> Arena* { return rewrite.arena(); } - [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } - [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } - - [[nodiscard]] auto operator()(ThrowExceptionSpecifierAST* ast) - -> ExceptionSpecifierAST*; - - [[nodiscard]] auto operator()(NoexceptSpecifierAST* ast) - -> ExceptionSpecifierAST*; -}; - -struct ASTRewriter::RequirementVisitor { - ASTRewriter& rewrite; - [[nodiscard]] auto translationUnit() const -> TranslationUnit* { - return rewrite.unit_; - } + auto parentScope = classSymbol->enclosingSymbol()->scope(); - [[nodiscard]] auto control() const -> Control* { return rewrite.control(); } - [[nodiscard]] auto arena() const -> Arena* { return rewrite.arena(); } - [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } - [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } + auto rewriter = ASTRewriter{unit, parentScope, templateArguments}; - [[nodiscard]] auto operator()(SimpleRequirementAST* ast) -> RequirementAST*; + rewriter.binder().setInstantiatingSymbol(classSymbol); - [[nodiscard]] auto operator()(CompoundRequirementAST* ast) -> RequirementAST*; + auto instance = + ast_cast(rewriter.specifier(classSpecifier)); - [[nodiscard]] auto operator()(TypeRequirementAST* ast) -> RequirementAST*; + if (!instance) return nullptr; - [[nodiscard]] auto operator()(NestedRequirementAST* ast) -> RequirementAST*; -}; + auto classInstance = instance->symbol; -struct ASTRewriter::NewInitializerVisitor { - ASTRewriter& rewrite; - [[nodiscard]] auto translationUnit() const -> TranslationUnit* { - return rewrite.unit_; - } + return classInstance; +} - [[nodiscard]] auto control() const -> Control* { return rewrite.control(); } - [[nodiscard]] auto arena() const -> Arena* { return rewrite.arena(); } - [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } - [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } +auto ASTRewriter::instantiateTypeAliasTemplate( + TranslationUnit* unit, List* templateArgumentList, + TypeAliasSymbol* typeAliasSymbol) -> TypeAliasSymbol* { + auto templateDecl = typeAliasSymbol->templateDeclaration(); - [[nodiscard]] auto operator()(NewParenInitializerAST* ast) - -> NewInitializerAST*; + auto aliasDeclaration = + ast_cast(templateDecl->declaration); - [[nodiscard]] auto operator()(NewBracedInitializerAST* ast) - -> NewInitializerAST*; -}; + if (!aliasDeclaration) return nullptr; -struct ASTRewriter::MemInitializerVisitor { - ASTRewriter& rewrite; - [[nodiscard]] auto translationUnit() const -> TranslationUnit* { - return rewrite.unit_; - } + auto templateArguments = + make_substitution(unit, templateDecl, templateArgumentList); - [[nodiscard]] auto control() const -> Control* { return rewrite.control(); } - [[nodiscard]] auto arena() const -> Arena* { return rewrite.arena(); } - [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } - [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } + auto is_primary_template = [&]() -> bool { + int expected = 0; + for (const auto& arg : templateArguments) { + if (!std::holds_alternative(arg)) return false; - [[nodiscard]] auto operator()(ParenMemInitializerAST* ast) - -> MemInitializerAST*; + auto ty = type_cast(std::get(arg)->type()); + if (!ty) return false; - [[nodiscard]] auto operator()(BracedMemInitializerAST* ast) - -> MemInitializerAST*; -}; + if (ty->index() != expected) return false; + ++expected; + } + return true; + }; -struct ASTRewriter::LambdaCaptureVisitor { - ASTRewriter& rewrite; - [[nodiscard]] auto translationUnit() const -> TranslationUnit* { - return rewrite.unit_; + if (is_primary_template()) { + // if this is a primary template, we can just return the class symbol + return typeAliasSymbol; } - [[nodiscard]] auto control() const -> Control* { return rewrite.control(); } - [[nodiscard]] auto arena() const -> Arena* { return rewrite.arena(); } - [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } - [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } - - [[nodiscard]] auto operator()(ThisLambdaCaptureAST* ast) -> LambdaCaptureAST*; - - [[nodiscard]] auto operator()(DerefThisLambdaCaptureAST* ast) - -> LambdaCaptureAST*; - - [[nodiscard]] auto operator()(SimpleLambdaCaptureAST* ast) - -> LambdaCaptureAST*; - - [[nodiscard]] auto operator()(RefLambdaCaptureAST* ast) -> LambdaCaptureAST*; - - [[nodiscard]] auto operator()(RefInitLambdaCaptureAST* ast) - -> LambdaCaptureAST*; - - [[nodiscard]] auto operator()(InitLambdaCaptureAST* ast) -> LambdaCaptureAST*; -}; - -struct ASTRewriter::ExceptionDeclarationVisitor { - ASTRewriter& rewrite; - [[nodiscard]] auto translationUnit() const -> TranslationUnit* { - return rewrite.unit_; +#if false + auto subst = typeAliasSymbol->findSpecialization(templateArguments); + if (subst) { + return subst; } +#endif - [[nodiscard]] auto control() const -> Control* { return rewrite.control(); } - [[nodiscard]] auto arena() const -> Arena* { return rewrite.arena(); } - [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } - [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } - - [[nodiscard]] auto operator()(EllipsisExceptionDeclarationAST* ast) - -> ExceptionDeclarationAST*; - - [[nodiscard]] auto operator()(TypeExceptionDeclarationAST* ast) - -> ExceptionDeclarationAST*; -}; - -struct ASTRewriter::AttributeSpecifierVisitor { - ASTRewriter& rewrite; - [[nodiscard]] auto translationUnit() const -> TranslationUnit* { - return rewrite.unit_; - } + auto parentScope = typeAliasSymbol->enclosingSymbol()->scope(); - [[nodiscard]] auto control() const -> Control* { return rewrite.control(); } - [[nodiscard]] auto arena() const -> Arena* { return rewrite.arena(); } - [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } - [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } + auto rewriter = ASTRewriter{unit, parentScope, templateArguments}; - [[nodiscard]] auto operator()(CxxAttributeAST* ast) -> AttributeSpecifierAST*; - - [[nodiscard]] auto operator()(GccAttributeAST* ast) -> AttributeSpecifierAST*; - - [[nodiscard]] auto operator()(AlignasAttributeAST* ast) - -> AttributeSpecifierAST*; - - [[nodiscard]] auto operator()(AlignasTypeAttributeAST* ast) - -> AttributeSpecifierAST*; - - [[nodiscard]] auto operator()(AsmAttributeAST* ast) -> AttributeSpecifierAST*; -}; - -struct ASTRewriter::AttributeTokenVisitor { - ASTRewriter& rewrite; - [[nodiscard]] auto translationUnit() const -> TranslationUnit* { - return rewrite.unit_; - } - - [[nodiscard]] auto control() const -> Control* { return rewrite.control(); } - [[nodiscard]] auto arena() const -> Arena* { return rewrite.arena(); } - [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } - [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } - - [[nodiscard]] auto operator()(ScopedAttributeTokenAST* ast) - -> AttributeTokenAST*; - - [[nodiscard]] auto operator()(SimpleAttributeTokenAST* ast) - -> AttributeTokenAST*; -}; - -auto ASTRewriter::operator()(UnitAST* ast) -> UnitAST* { - if (!ast) return {}; - return visit(UnitVisitor{*this}, ast); -} - -auto ASTRewriter::operator()(DeclarationAST* ast) -> DeclarationAST* { - if (!ast) return {}; - return visit(DeclarationVisitor{*this}, ast); -} - -auto ASTRewriter::operator()(StatementAST* ast) -> StatementAST* { - if (!ast) return {}; - return visit(StatementVisitor{*this}, ast); -} - -auto ASTRewriter::operator()(ExpressionAST* ast) -> ExpressionAST* { - if (!ast) return {}; - auto expr = visit(ExpressionVisitor{*this}, ast); - if (expr) typeChecker_->check(expr); - return expr; -} - -auto ASTRewriter::operator()(GenericAssociationAST* ast) - -> GenericAssociationAST* { - if (!ast) return {}; - return visit(GenericAssociationVisitor{*this}, ast); -} - -auto ASTRewriter::operator()(DesignatorAST* ast) -> DesignatorAST* { - if (!ast) return {}; - return visit(DesignatorVisitor{*this}, ast); -} - -auto ASTRewriter::operator()(TemplateParameterAST* ast) - -> TemplateParameterAST* { - if (!ast) return {}; - return visit(TemplateParameterVisitor{*this}, ast); -} - -auto ASTRewriter::operator()(SpecifierAST* ast) -> SpecifierAST* { - if (!ast) return {}; - auto specifier = visit(SpecifierVisitor{*this}, ast); - return specifier; -} - -auto ASTRewriter::operator()(PtrOperatorAST* ast) -> PtrOperatorAST* { - if (!ast) return {}; - return visit(PtrOperatorVisitor{*this}, ast); -} - -auto ASTRewriter::operator()(CoreDeclaratorAST* ast) -> CoreDeclaratorAST* { - if (!ast) return {}; - return visit(CoreDeclaratorVisitor{*this}, ast); -} - -auto ASTRewriter::operator()(DeclaratorChunkAST* ast) -> DeclaratorChunkAST* { - if (!ast) return {}; - return visit(DeclaratorChunkVisitor{*this}, ast); -} - -auto ASTRewriter::operator()(UnqualifiedIdAST* ast) -> UnqualifiedIdAST* { - if (!ast) return {}; - return visit(UnqualifiedIdVisitor{*this}, ast); -} - -auto ASTRewriter::operator()(NestedNameSpecifierAST* ast) - -> NestedNameSpecifierAST* { - if (!ast) return {}; - return visit(NestedNameSpecifierVisitor{*this}, ast); -} - -auto ASTRewriter::operator()(FunctionBodyAST* ast) -> FunctionBodyAST* { - if (!ast) return {}; - return visit(FunctionBodyVisitor{*this}, ast); -} - -auto ASTRewriter::operator()(TemplateArgumentAST* ast) -> TemplateArgumentAST* { - if (!ast) return {}; - return visit(TemplateArgumentVisitor{*this}, ast); -} - -auto ASTRewriter::operator()(ExceptionSpecifierAST* ast) - -> ExceptionSpecifierAST* { - if (!ast) return {}; - return visit(ExceptionSpecifierVisitor{*this}, ast); -} - -auto ASTRewriter::operator()(RequirementAST* ast) -> RequirementAST* { - if (!ast) return {}; - return visit(RequirementVisitor{*this}, ast); -} - -auto ASTRewriter::operator()(NewInitializerAST* ast) -> NewInitializerAST* { - if (!ast) return {}; - return visit(NewInitializerVisitor{*this}, ast); -} - -auto ASTRewriter::operator()(MemInitializerAST* ast) -> MemInitializerAST* { - if (!ast) return {}; - return visit(MemInitializerVisitor{*this}, ast); -} - -auto ASTRewriter::operator()(LambdaCaptureAST* ast) -> LambdaCaptureAST* { - if (!ast) return {}; - return visit(LambdaCaptureVisitor{*this}, ast); -} - -auto ASTRewriter::operator()(ExceptionDeclarationAST* ast) - -> ExceptionDeclarationAST* { - if (!ast) return {}; - return visit(ExceptionDeclarationVisitor{*this}, ast); -} - -auto ASTRewriter::operator()(AttributeSpecifierAST* ast) - -> AttributeSpecifierAST* { - if (!ast) return {}; - return visit(AttributeSpecifierVisitor{*this}, ast); -} - -auto ASTRewriter::operator()(AttributeTokenAST* ast) -> AttributeTokenAST* { - if (!ast) return {}; - return visit(AttributeTokenVisitor{*this}, ast); -} - -auto ASTRewriter::operator()(SplicerAST* ast) -> SplicerAST* { - if (!ast) return {}; - - auto copy = make_node(arena()); - - copy->lbracketLoc = ast->lbracketLoc; - copy->colonLoc = ast->colonLoc; - copy->ellipsisLoc = ast->ellipsisLoc; - copy->expression = operator()(ast->expression); - copy->secondColonLoc = ast->secondColonLoc; - copy->rbracketLoc = ast->rbracketLoc; - - return copy; -} - -auto ASTRewriter::operator()(GlobalModuleFragmentAST* ast) - -> GlobalModuleFragmentAST* { - if (!ast) return {}; - - auto copy = make_node(arena()); - - copy->moduleLoc = ast->moduleLoc; - copy->semicolonLoc = ast->semicolonLoc; - - for (auto declarationList = ©->declarationList; - auto node : ListView{ast->declarationList}) { - auto value = operator()(node); - *declarationList = make_list_node(arena(), value); - declarationList = &(*declarationList)->next; - } - - return copy; -} - -auto ASTRewriter::operator()(PrivateModuleFragmentAST* ast) - -> PrivateModuleFragmentAST* { - if (!ast) return {}; - - auto copy = make_node(arena()); - - copy->moduleLoc = ast->moduleLoc; - copy->colonLoc = ast->colonLoc; - copy->privateLoc = ast->privateLoc; - copy->semicolonLoc = ast->semicolonLoc; - - for (auto declarationList = ©->declarationList; - auto node : ListView{ast->declarationList}) { - auto value = operator()(node); - *declarationList = make_list_node(arena(), value); - declarationList = &(*declarationList)->next; - } - - return copy; -} - -auto ASTRewriter::operator()(ModuleDeclarationAST* ast) - -> ModuleDeclarationAST* { - if (!ast) return {}; - - auto copy = make_node(arena()); - - copy->exportLoc = ast->exportLoc; - copy->moduleLoc = ast->moduleLoc; - copy->moduleName = operator()(ast->moduleName); - copy->modulePartition = operator()(ast->modulePartition); - - for (auto attributeList = ©->attributeList; - auto node : ListView{ast->attributeList}) { - auto value = operator()(node); - *attributeList = make_list_node(arena(), value); - attributeList = &(*attributeList)->next; - } - - copy->semicolonLoc = ast->semicolonLoc; - - return copy; -} - -auto ASTRewriter::operator()(ModuleNameAST* ast) -> ModuleNameAST* { - if (!ast) return {}; - - auto copy = make_node(arena()); - - copy->moduleQualifier = operator()(ast->moduleQualifier); - copy->identifierLoc = ast->identifierLoc; - copy->identifier = ast->identifier; - - return copy; -} - -auto ASTRewriter::operator()(ModuleQualifierAST* ast) -> ModuleQualifierAST* { - if (!ast) return {}; - - auto copy = make_node(arena()); - - copy->moduleQualifier = operator()(ast->moduleQualifier); - copy->identifierLoc = ast->identifierLoc; - copy->dotLoc = ast->dotLoc; - copy->identifier = ast->identifier; - - return copy; -} - -auto ASTRewriter::operator()(ModulePartitionAST* ast) -> ModulePartitionAST* { - if (!ast) return {}; - - auto copy = make_node(arena()); - - copy->colonLoc = ast->colonLoc; - copy->moduleName = operator()(ast->moduleName); - - return copy; -} - -auto ASTRewriter::operator()(ImportNameAST* ast) -> ImportNameAST* { - if (!ast) return {}; - - auto copy = make_node(arena()); - - copy->headerLoc = ast->headerLoc; - copy->modulePartition = operator()(ast->modulePartition); - copy->moduleName = operator()(ast->moduleName); - - return copy; -} - -auto ASTRewriter::operator()(InitDeclaratorAST* ast, const DeclSpecs& declSpecs) - -> InitDeclaratorAST* { - if (!ast) return {}; - - auto copy = make_node(arena()); - - copy->declarator = operator()(ast->declarator); - - auto decl = Decl{declSpecs, copy->declarator}; - - auto type = - getDeclaratorType(translationUnit(), copy->declarator, declSpecs.type()); - - // ### fix scope - if (binder_.scope() && binder_.scope()->isClassScope()) { - auto symbol = binder_.declareMemberSymbol(ast->declarator, decl); - copy->symbol = symbol; - } else { - // ### TODO - copy->symbol = ast->symbol; - } - - copy->requiresClause = operator()(ast->requiresClause); - copy->initializer = operator()(ast->initializer); - // copy->symbol = ast->symbol; // TODO remove, done above - - return copy; -} - -auto ASTRewriter::operator()(DeclaratorAST* ast) -> DeclaratorAST* { - if (!ast) return {}; - - auto copy = make_node(arena()); - - for (auto ptrOpList = ©->ptrOpList; - auto node : ListView{ast->ptrOpList}) { - auto value = operator()(node); - *ptrOpList = make_list_node(arena(), value); - ptrOpList = &(*ptrOpList)->next; - } - - copy->coreDeclarator = operator()(ast->coreDeclarator); - - for (auto declaratorChunkList = ©->declaratorChunkList; - auto node : ListView{ast->declaratorChunkList}) { - auto value = operator()(node); - *declaratorChunkList = make_list_node(arena(), value); - declaratorChunkList = &(*declaratorChunkList)->next; - } - - return copy; -} - -auto ASTRewriter::operator()(UsingDeclaratorAST* ast) -> UsingDeclaratorAST* { - if (!ast) return {}; - - auto copy = make_node(arena()); - - copy->typenameLoc = ast->typenameLoc; - copy->nestedNameSpecifier = operator()(ast->nestedNameSpecifier); - copy->unqualifiedId = operator()(ast->unqualifiedId); - copy->ellipsisLoc = ast->ellipsisLoc; - copy->symbol = ast->symbol; - copy->isPack = ast->isPack; - - return copy; -} - -auto ASTRewriter::operator()(EnumeratorAST* ast) -> EnumeratorAST* { - if (!ast) return {}; - - auto copy = make_node(arena()); - - copy->identifierLoc = ast->identifierLoc; - - for (auto attributeList = ©->attributeList; - auto node : ListView{ast->attributeList}) { - auto value = operator()(node); - *attributeList = make_list_node(arena(), value); - attributeList = &(*attributeList)->next; - } - - copy->equalLoc = ast->equalLoc; - copy->expression = operator()(ast->expression); - copy->identifier = ast->identifier; - copy->symbol = ast->symbol; - - return copy; -} - -auto ASTRewriter::operator()(TypeIdAST* ast) -> TypeIdAST* { - if (!ast) return {}; - - auto copy = make_node(arena()); - - auto typeSpecifierListCtx = DeclSpecs{rewriter()}; - for (auto typeSpecifierList = ©->typeSpecifierList; - auto node : ListView{ast->typeSpecifierList}) { - auto value = operator()(node); - *typeSpecifierList = make_list_node(arena(), value); - typeSpecifierList = &(*typeSpecifierList)->next; - typeSpecifierListCtx.accept(value); - } - typeSpecifierListCtx.finish(); - - copy->declarator = operator()(ast->declarator); - - auto declaratorDecl = Decl{typeSpecifierListCtx, copy->declarator}; - auto declaratorType = getDeclaratorType(translationUnit(), copy->declarator, - typeSpecifierListCtx.type()); - copy->type = declaratorType; - - return copy; -} - -auto ASTRewriter::operator()(HandlerAST* ast) -> HandlerAST* { - if (!ast) return {}; - - auto copy = make_node(arena()); - - copy->catchLoc = ast->catchLoc; - copy->lparenLoc = ast->lparenLoc; - copy->exceptionDeclaration = operator()(ast->exceptionDeclaration); - copy->rparenLoc = ast->rparenLoc; - copy->statement = ast_cast(operator()(ast->statement)); - - return copy; -} - -auto ASTRewriter::operator()(BaseSpecifierAST* ast) -> BaseSpecifierAST* { - if (!ast) return {}; - - auto copy = make_node(arena()); - - for (auto attributeList = ©->attributeList; - auto node : ListView{ast->attributeList}) { - auto value = operator()(node); - *attributeList = make_list_node(arena(), value); - attributeList = &(*attributeList)->next; - } - - copy->virtualOrAccessLoc = ast->virtualOrAccessLoc; - copy->otherVirtualOrAccessLoc = ast->otherVirtualOrAccessLoc; - copy->nestedNameSpecifier = operator()(ast->nestedNameSpecifier); - copy->templateLoc = ast->templateLoc; - copy->unqualifiedId = operator()(ast->unqualifiedId); - copy->ellipsisLoc = ast->ellipsisLoc; - copy->isTemplateIntroduced = ast->isTemplateIntroduced; - copy->isVirtual = ast->isVirtual; - copy->isVariadic = ast->isVariadic; - copy->accessSpecifier = ast->accessSpecifier; - copy->symbol = ast->symbol; - - binder_.bind(ast); - - return copy; -} - -auto ASTRewriter::operator()(RequiresClauseAST* ast) -> RequiresClauseAST* { - if (!ast) return {}; - - auto copy = make_node(arena()); - - copy->requiresLoc = ast->requiresLoc; - copy->expression = operator()(ast->expression); - - return copy; -} - -auto ASTRewriter::operator()(ParameterDeclarationClauseAST* ast) - -> ParameterDeclarationClauseAST* { - if (!ast) return {}; - - auto copy = make_node(arena()); - - for (auto parameterDeclarationList = ©->parameterDeclarationList; - auto node : ListView{ast->parameterDeclarationList}) { - auto value = operator()(node); - *parameterDeclarationList = - make_list_node(arena(), ast_cast(value)); - parameterDeclarationList = &(*parameterDeclarationList)->next; - } - - copy->commaLoc = ast->commaLoc; - copy->ellipsisLoc = ast->ellipsisLoc; - copy->functionParametersSymbol = ast->functionParametersSymbol; - copy->isVariadic = ast->isVariadic; - - return copy; -} - -auto ASTRewriter::operator()(TrailingReturnTypeAST* ast) - -> TrailingReturnTypeAST* { - if (!ast) return {}; - - auto copy = make_node(arena()); - - copy->minusGreaterLoc = ast->minusGreaterLoc; - copy->typeId = operator()(ast->typeId); - - return copy; -} - -auto ASTRewriter::operator()(LambdaSpecifierAST* ast) -> LambdaSpecifierAST* { - if (!ast) return {}; - - auto copy = make_node(arena()); - - copy->specifierLoc = ast->specifierLoc; - copy->specifier = ast->specifier; - - return copy; -} - -auto ASTRewriter::operator()(TypeConstraintAST* ast) -> TypeConstraintAST* { - if (!ast) return {}; - - auto copy = make_node(arena()); - - copy->nestedNameSpecifier = operator()(ast->nestedNameSpecifier); - copy->identifierLoc = ast->identifierLoc; - copy->lessLoc = ast->lessLoc; - - for (auto templateArgumentList = ©->templateArgumentList; - auto node : ListView{ast->templateArgumentList}) { - auto value = operator()(node); - *templateArgumentList = make_list_node(arena(), value); - templateArgumentList = &(*templateArgumentList)->next; - } - - copy->greaterLoc = ast->greaterLoc; - copy->identifier = ast->identifier; - - return copy; -} - -auto ASTRewriter::operator()(AttributeArgumentClauseAST* ast) - -> AttributeArgumentClauseAST* { - if (!ast) return {}; - - auto copy = make_node(arena()); - - copy->lparenLoc = ast->lparenLoc; - copy->rparenLoc = ast->rparenLoc; - - return copy; -} - -auto ASTRewriter::operator()(AttributeAST* ast) -> AttributeAST* { - if (!ast) return {}; - - auto copy = make_node(arena()); - - copy->attributeToken = operator()(ast->attributeToken); - copy->attributeArgumentClause = operator()(ast->attributeArgumentClause); - copy->ellipsisLoc = ast->ellipsisLoc; - - return copy; -} - -auto ASTRewriter::operator()(AttributeUsingPrefixAST* ast) - -> AttributeUsingPrefixAST* { - if (!ast) return {}; - - auto copy = make_node(arena()); - - copy->usingLoc = ast->usingLoc; - copy->attributeNamespaceLoc = ast->attributeNamespaceLoc; - copy->colonLoc = ast->colonLoc; - - return copy; -} - -auto ASTRewriter::operator()(NewPlacementAST* ast) -> NewPlacementAST* { - if (!ast) return {}; - - auto copy = make_node(arena()); - - copy->lparenLoc = ast->lparenLoc; - - for (auto expressionList = ©->expressionList; - auto node : ListView{ast->expressionList}) { - auto value = operator()(node); - *expressionList = make_list_node(arena(), value); - expressionList = &(*expressionList)->next; - } - - copy->rparenLoc = ast->rparenLoc; - - return copy; -} - -auto ASTRewriter::operator()(NestedNamespaceSpecifierAST* ast) - -> NestedNamespaceSpecifierAST* { - if (!ast) return {}; - - auto copy = make_node(arena()); - - copy->inlineLoc = ast->inlineLoc; - copy->identifierLoc = ast->identifierLoc; - copy->scopeLoc = ast->scopeLoc; - copy->identifier = ast->identifier; - copy->isInline = ast->isInline; - - return copy; -} - -auto ASTRewriter::operator()(AsmOperandAST* ast) -> AsmOperandAST* { - auto copy = make_node(arena()); - - copy->lbracketLoc = ast->lbracketLoc; - copy->symbolicNameLoc = ast->symbolicNameLoc; - copy->rbracketLoc = ast->rbracketLoc; - copy->constraintLiteralLoc = ast->constraintLiteralLoc; - copy->lparenLoc = ast->lparenLoc; - copy->expression = operator()(ast->expression); - copy->rparenLoc = ast->rparenLoc; - copy->symbolicName = ast->symbolicName; - copy->constraintLiteral = ast->constraintLiteral; - - return copy; -} - -auto ASTRewriter::operator()(AsmQualifierAST* ast) -> AsmQualifierAST* { - auto copy = make_node(arena()); - - copy->qualifierLoc = ast->qualifierLoc; - copy->qualifier = ast->qualifier; - - return copy; -} - -auto ASTRewriter::operator()(AsmClobberAST* ast) -> AsmClobberAST* { - auto copy = make_node(arena()); - - copy->literalLoc = ast->literalLoc; - copy->literal = ast->literal; - - return copy; -} - -auto ASTRewriter::operator()(AsmGotoLabelAST* ast) -> AsmGotoLabelAST* { - auto copy = make_node(arena()); - - copy->identifierLoc = ast->identifierLoc; - copy->identifier = ast->identifier; - - return copy; -} - -auto ASTRewriter::UnitVisitor::operator()(TranslationUnitAST* ast) -> UnitAST* { - auto copy = make_node(arena()); - - for (auto declarationList = ©->declarationList; - auto node : ListView{ast->declarationList}) { - auto value = rewrite(node); - *declarationList = make_list_node(arena(), value); - declarationList = &(*declarationList)->next; - } - - return copy; -} - -auto ASTRewriter::UnitVisitor::operator()(ModuleUnitAST* ast) -> UnitAST* { - auto copy = make_node(arena()); - - copy->globalModuleFragment = rewrite(ast->globalModuleFragment); - copy->moduleDeclaration = rewrite(ast->moduleDeclaration); - - for (auto declarationList = ©->declarationList; - auto node : ListView{ast->declarationList}) { - auto value = rewrite(node); - *declarationList = make_list_node(arena(), value); - declarationList = &(*declarationList)->next; - } - - copy->privateModuleFragment = rewrite(ast->privateModuleFragment); - - return copy; -} - -auto ASTRewriter::DeclarationVisitor::operator()(SimpleDeclarationAST* ast) - -> DeclarationAST* { - auto copy = make_node(arena()); - - for (auto attributeList = ©->attributeList; - auto node : ListView{ast->attributeList}) { - auto value = rewrite(node); - *attributeList = make_list_node(arena(), value); - attributeList = &(*attributeList)->next; - } - - auto declSpecifierListCtx = DeclSpecs{rewriter()}; - for (auto declSpecifierList = ©->declSpecifierList; - auto node : ListView{ast->declSpecifierList}) { - auto value = rewrite(node); - *declSpecifierList = make_list_node(arena(), value); - declSpecifierList = &(*declSpecifierList)->next; - declSpecifierListCtx.accept(value); - } - declSpecifierListCtx.finish(); - - for (auto initDeclaratorList = ©->initDeclaratorList; - auto node : ListView{ast->initDeclaratorList}) { - auto value = rewrite(node, declSpecifierListCtx); - *initDeclaratorList = make_list_node(arena(), value); - initDeclaratorList = &(*initDeclaratorList)->next; - } - - copy->requiresClause = rewrite(ast->requiresClause); - copy->semicolonLoc = ast->semicolonLoc; - - return copy; -} - -auto ASTRewriter::DeclarationVisitor::operator()(AsmDeclarationAST* ast) - -> DeclarationAST* { - auto copy = make_node(arena()); - - for (auto attributeList = ©->attributeList; - auto node : ListView{ast->attributeList}) { - auto value = rewrite(node); - *attributeList = make_list_node(arena(), value); - attributeList = &(*attributeList)->next; - } - - for (auto asmQualifierList = ©->asmQualifierList; - auto node : ListView{ast->asmQualifierList}) { - auto value = rewrite(node); - *asmQualifierList = - make_list_node(arena(), ast_cast(value)); - asmQualifierList = &(*asmQualifierList)->next; - } - - copy->asmLoc = ast->asmLoc; - copy->lparenLoc = ast->lparenLoc; - copy->literalLoc = ast->literalLoc; - - for (auto outputOperandList = ©->outputOperandList; - auto node : ListView{ast->outputOperandList}) { - auto value = rewrite(node); - *outputOperandList = - make_list_node(arena(), ast_cast(value)); - outputOperandList = &(*outputOperandList)->next; - } - - for (auto inputOperandList = ©->inputOperandList; - auto node : ListView{ast->inputOperandList}) { - auto value = rewrite(node); - *inputOperandList = make_list_node(arena(), ast_cast(value)); - inputOperandList = &(*inputOperandList)->next; - } - - for (auto clobberList = ©->clobberList; - auto node : ListView{ast->clobberList}) { - auto value = rewrite(node); - *clobberList = make_list_node(arena(), ast_cast(value)); - clobberList = &(*clobberList)->next; - } - - for (auto gotoLabelList = ©->gotoLabelList; - auto node : ListView{ast->gotoLabelList}) { - auto value = rewrite(node); - *gotoLabelList = make_list_node(arena(), ast_cast(value)); - gotoLabelList = &(*gotoLabelList)->next; - } - - copy->rparenLoc = ast->rparenLoc; - copy->semicolonLoc = ast->semicolonLoc; - copy->literal = ast->literal; - - return copy; -} - -auto ASTRewriter::DeclarationVisitor::operator()( - NamespaceAliasDefinitionAST* ast) -> DeclarationAST* { - auto copy = make_node(arena()); - - copy->namespaceLoc = ast->namespaceLoc; - copy->identifierLoc = ast->identifierLoc; - copy->equalLoc = ast->equalLoc; - copy->nestedNameSpecifier = rewrite(ast->nestedNameSpecifier); - copy->unqualifiedId = ast_cast(rewrite(ast->unqualifiedId)); - copy->semicolonLoc = ast->semicolonLoc; - copy->identifier = ast->identifier; - - return copy; -} - -auto ASTRewriter::DeclarationVisitor::operator()(UsingDeclarationAST* ast) - -> DeclarationAST* { - auto copy = make_node(arena()); - - copy->usingLoc = ast->usingLoc; - - for (auto usingDeclaratorList = ©->usingDeclaratorList; - auto node : ListView{ast->usingDeclaratorList}) { - auto value = rewrite(node); - *usingDeclaratorList = make_list_node(arena(), value); - usingDeclaratorList = &(*usingDeclaratorList)->next; - } - - copy->semicolonLoc = ast->semicolonLoc; - - return copy; -} - -auto ASTRewriter::DeclarationVisitor::operator()(UsingEnumDeclarationAST* ast) - -> DeclarationAST* { - auto copy = make_node(arena()); - - copy->usingLoc = ast->usingLoc; - copy->enumTypeSpecifier = - ast_cast(rewrite(ast->enumTypeSpecifier)); - copy->semicolonLoc = ast->semicolonLoc; - - return copy; -} - -auto ASTRewriter::DeclarationVisitor::operator()(UsingDirectiveAST* ast) - -> DeclarationAST* { - auto copy = make_node(arena()); - - for (auto attributeList = ©->attributeList; - auto node : ListView{ast->attributeList}) { - auto value = rewrite(node); - *attributeList = make_list_node(arena(), value); - attributeList = &(*attributeList)->next; - } - - copy->usingLoc = ast->usingLoc; - copy->namespaceLoc = ast->namespaceLoc; - copy->nestedNameSpecifier = rewrite(ast->nestedNameSpecifier); - copy->unqualifiedId = ast_cast(rewrite(ast->unqualifiedId)); - copy->semicolonLoc = ast->semicolonLoc; - - return copy; -} - -auto ASTRewriter::DeclarationVisitor::operator()( - StaticAssertDeclarationAST* ast) -> DeclarationAST* { - auto copy = make_node(arena()); - - copy->staticAssertLoc = ast->staticAssertLoc; - copy->lparenLoc = ast->lparenLoc; - copy->expression = rewrite(ast->expression); - copy->commaLoc = ast->commaLoc; - copy->literalLoc = ast->literalLoc; - copy->literal = ast->literal; - copy->rparenLoc = ast->rparenLoc; - copy->semicolonLoc = ast->semicolonLoc; - - return copy; -} - -auto ASTRewriter::DeclarationVisitor::operator()(AliasDeclarationAST* ast) - -> DeclarationAST* { - auto copy = make_node(arena()); - - copy->usingLoc = ast->usingLoc; - copy->identifierLoc = ast->identifierLoc; - - for (auto attributeList = ©->attributeList; - auto node : ListView{ast->attributeList}) { - auto value = rewrite(node); - *attributeList = make_list_node(arena(), value); - attributeList = &(*attributeList)->next; - } - - copy->equalLoc = ast->equalLoc; - - for (auto gnuAttributeList = ©->gnuAttributeList; - auto node : ListView{ast->gnuAttributeList}) { - auto value = rewrite(node); - *gnuAttributeList = make_list_node(arena(), value); - gnuAttributeList = &(*gnuAttributeList)->next; - } - - copy->typeId = rewrite(ast->typeId); - copy->semicolonLoc = ast->semicolonLoc; - copy->identifier = ast->identifier; - copy->symbol = ast->symbol; - - return copy; -} - -auto ASTRewriter::DeclarationVisitor::operator()(OpaqueEnumDeclarationAST* ast) - -> DeclarationAST* { - auto copy = make_node(arena()); - - copy->enumLoc = ast->enumLoc; - copy->classLoc = ast->classLoc; - - for (auto attributeList = ©->attributeList; - auto node : ListView{ast->attributeList}) { - auto value = rewrite(node); - *attributeList = make_list_node(arena(), value); - attributeList = &(*attributeList)->next; - } - - copy->nestedNameSpecifier = rewrite(ast->nestedNameSpecifier); - copy->unqualifiedId = ast_cast(rewrite(ast->unqualifiedId)); - copy->colonLoc = ast->colonLoc; - - auto typeSpecifierListCtx = DeclSpecs{rewriter()}; - for (auto typeSpecifierList = ©->typeSpecifierList; - auto node : ListView{ast->typeSpecifierList}) { - auto value = rewrite(node); - *typeSpecifierList = make_list_node(arena(), value); - typeSpecifierList = &(*typeSpecifierList)->next; - typeSpecifierListCtx.accept(value); - } - typeSpecifierListCtx.finish(); - - copy->emicolonLoc = ast->emicolonLoc; - - return copy; -} - -auto ASTRewriter::DeclarationVisitor::operator()(FunctionDefinitionAST* ast) - -> DeclarationAST* { - auto copy = make_node(arena()); - - for (auto attributeList = ©->attributeList; - auto node : ListView{ast->attributeList}) { - auto value = rewrite(node); - *attributeList = make_list_node(arena(), value); - attributeList = &(*attributeList)->next; - } - - auto declSpecifierListCtx = DeclSpecs{rewriter()}; - for (auto declSpecifierList = ©->declSpecifierList; - auto node : ListView{ast->declSpecifierList}) { - auto value = rewrite(node); - *declSpecifierList = make_list_node(arena(), value); - declSpecifierList = &(*declSpecifierList)->next; - declSpecifierListCtx.accept(value); - } - declSpecifierListCtx.finish(); - - copy->declarator = rewrite(ast->declarator); - - auto declaratorDecl = Decl{declSpecifierListCtx, copy->declarator}; - auto declaratorType = getDeclaratorType(translationUnit(), copy->declarator, - declSpecifierListCtx.type()); - copy->requiresClause = rewrite(ast->requiresClause); - copy->functionBody = rewrite(ast->functionBody); - copy->symbol = ast->symbol; - - return copy; -} - -auto ASTRewriter::DeclarationVisitor::operator()(TemplateDeclarationAST* ast) - -> DeclarationAST* { - auto copy = make_node(arena()); - - copy->templateLoc = ast->templateLoc; - copy->lessLoc = ast->lessLoc; - - for (auto templateParameterList = ©->templateParameterList; - auto node : ListView{ast->templateParameterList}) { - auto value = rewrite(node); - *templateParameterList = make_list_node(arena(), value); - templateParameterList = &(*templateParameterList)->next; - } - - copy->greaterLoc = ast->greaterLoc; - copy->requiresClause = rewrite(ast->requiresClause); - copy->declaration = rewrite(ast->declaration); - copy->symbol = ast->symbol; - - return copy; -} - -auto ASTRewriter::DeclarationVisitor::operator()(ConceptDefinitionAST* ast) - -> DeclarationAST* { - auto copy = make_node(arena()); - - copy->conceptLoc = ast->conceptLoc; - copy->identifierLoc = ast->identifierLoc; - copy->equalLoc = ast->equalLoc; - copy->expression = rewrite(ast->expression); - copy->semicolonLoc = ast->semicolonLoc; - copy->identifier = ast->identifier; - copy->symbol = ast->symbol; - - return copy; -} - -auto ASTRewriter::DeclarationVisitor::operator()(DeductionGuideAST* ast) - -> DeclarationAST* { - auto copy = make_node(arena()); - - copy->explicitSpecifier = rewrite(ast->explicitSpecifier); - copy->identifierLoc = ast->identifierLoc; - copy->lparenLoc = ast->lparenLoc; - copy->parameterDeclarationClause = rewrite(ast->parameterDeclarationClause); - copy->rparenLoc = ast->rparenLoc; - copy->arrowLoc = ast->arrowLoc; - copy->templateId = ast_cast(rewrite(ast->templateId)); - copy->semicolonLoc = ast->semicolonLoc; - copy->identifier = ast->identifier; - - return copy; -} - -auto ASTRewriter::DeclarationVisitor::operator()(ExplicitInstantiationAST* ast) - -> DeclarationAST* { - auto copy = make_node(arena()); - - copy->externLoc = ast->externLoc; - copy->templateLoc = ast->templateLoc; - copy->declaration = rewrite(ast->declaration); - - return copy; -} - -auto ASTRewriter::DeclarationVisitor::operator()(ExportDeclarationAST* ast) - -> DeclarationAST* { - auto copy = make_node(arena()); - - copy->exportLoc = ast->exportLoc; - copy->declaration = rewrite(ast->declaration); - - return copy; -} - -auto ASTRewriter::DeclarationVisitor::operator()( - ExportCompoundDeclarationAST* ast) -> DeclarationAST* { - auto copy = make_node(arena()); - - copy->exportLoc = ast->exportLoc; - copy->lbraceLoc = ast->lbraceLoc; - - for (auto declarationList = ©->declarationList; - auto node : ListView{ast->declarationList}) { - auto value = rewrite(node); - *declarationList = make_list_node(arena(), value); - declarationList = &(*declarationList)->next; - } - - copy->rbraceLoc = ast->rbraceLoc; - - return copy; -} - -auto ASTRewriter::DeclarationVisitor::operator()(LinkageSpecificationAST* ast) - -> DeclarationAST* { - auto copy = make_node(arena()); - - copy->externLoc = ast->externLoc; - copy->stringliteralLoc = ast->stringliteralLoc; - copy->lbraceLoc = ast->lbraceLoc; - - for (auto declarationList = ©->declarationList; - auto node : ListView{ast->declarationList}) { - auto value = rewrite(node); - *declarationList = make_list_node(arena(), value); - declarationList = &(*declarationList)->next; - } - - copy->rbraceLoc = ast->rbraceLoc; - copy->stringLiteral = ast->stringLiteral; - - return copy; -} - -auto ASTRewriter::DeclarationVisitor::operator()(NamespaceDefinitionAST* ast) - -> DeclarationAST* { - auto copy = make_node(arena()); - - copy->inlineLoc = ast->inlineLoc; - copy->namespaceLoc = ast->namespaceLoc; - - for (auto attributeList = ©->attributeList; - auto node : ListView{ast->attributeList}) { - auto value = rewrite(node); - *attributeList = make_list_node(arena(), value); - attributeList = &(*attributeList)->next; - } - - for (auto nestedNamespaceSpecifierList = ©->nestedNamespaceSpecifierList; - auto node : ListView{ast->nestedNamespaceSpecifierList}) { - auto value = rewrite(node); - *nestedNamespaceSpecifierList = make_list_node(arena(), value); - nestedNamespaceSpecifierList = &(*nestedNamespaceSpecifierList)->next; - } - - copy->identifierLoc = ast->identifierLoc; - - for (auto extraAttributeList = ©->extraAttributeList; - auto node : ListView{ast->extraAttributeList}) { - auto value = rewrite(node); - *extraAttributeList = make_list_node(arena(), value); - extraAttributeList = &(*extraAttributeList)->next; - } - - copy->lbraceLoc = ast->lbraceLoc; - - for (auto declarationList = ©->declarationList; - auto node : ListView{ast->declarationList}) { - auto value = rewrite(node); - *declarationList = make_list_node(arena(), value); - declarationList = &(*declarationList)->next; - } - - copy->rbraceLoc = ast->rbraceLoc; - copy->identifier = ast->identifier; - copy->isInline = ast->isInline; - - return copy; -} - -auto ASTRewriter::DeclarationVisitor::operator()(EmptyDeclarationAST* ast) - -> DeclarationAST* { - auto copy = make_node(arena()); - - copy->semicolonLoc = ast->semicolonLoc; - - return copy; -} - -auto ASTRewriter::DeclarationVisitor::operator()(AttributeDeclarationAST* ast) - -> DeclarationAST* { - auto copy = make_node(arena()); - - for (auto attributeList = ©->attributeList; - auto node : ListView{ast->attributeList}) { - auto value = rewrite(node); - *attributeList = make_list_node(arena(), value); - attributeList = &(*attributeList)->next; - } - - copy->semicolonLoc = ast->semicolonLoc; - - return copy; -} - -auto ASTRewriter::DeclarationVisitor::operator()( - ModuleImportDeclarationAST* ast) -> DeclarationAST* { - auto copy = make_node(arena()); - - copy->importLoc = ast->importLoc; - copy->importName = rewrite(ast->importName); - - for (auto attributeList = ©->attributeList; - auto node : ListView{ast->attributeList}) { - auto value = rewrite(node); - *attributeList = make_list_node(arena(), value); - attributeList = &(*attributeList)->next; - } - - copy->semicolonLoc = ast->semicolonLoc; - - return copy; -} - -auto ASTRewriter::DeclarationVisitor::operator()(ParameterDeclarationAST* ast) - -> DeclarationAST* { - auto copy = make_node(arena()); - - for (auto attributeList = ©->attributeList; - auto node : ListView{ast->attributeList}) { - auto value = rewrite(node); - *attributeList = make_list_node(arena(), value); - attributeList = &(*attributeList)->next; - } - - copy->thisLoc = ast->thisLoc; - - auto typeSpecifierListCtx = DeclSpecs{rewriter()}; - for (auto typeSpecifierList = ©->typeSpecifierList; - auto node : ListView{ast->typeSpecifierList}) { - auto value = rewrite(node); - *typeSpecifierList = make_list_node(arena(), value); - typeSpecifierList = &(*typeSpecifierList)->next; - typeSpecifierListCtx.accept(value); - } - typeSpecifierListCtx.finish(); - - copy->declarator = rewrite(ast->declarator); - - auto declaratorDecl = Decl{typeSpecifierListCtx, copy->declarator}; - auto declaratorType = getDeclaratorType(translationUnit(), copy->declarator, - typeSpecifierListCtx.type()); - copy->type = declaratorType; - copy->equalLoc = ast->equalLoc; - copy->expression = rewrite(ast->expression); - copy->identifier = ast->identifier; - copy->isThisIntroduced = ast->isThisIntroduced; - copy->isPack = ast->isPack; - - return copy; -} - -auto ASTRewriter::DeclarationVisitor::operator()(AccessDeclarationAST* ast) - -> DeclarationAST* { - auto copy = make_node(arena()); - - copy->accessLoc = ast->accessLoc; - copy->colonLoc = ast->colonLoc; - copy->accessSpecifier = ast->accessSpecifier; - - return copy; -} - -auto ASTRewriter::DeclarationVisitor::operator()(ForRangeDeclarationAST* ast) - -> DeclarationAST* { - auto copy = make_node(arena()); - - return copy; -} - -auto ASTRewriter::DeclarationVisitor::operator()( - StructuredBindingDeclarationAST* ast) -> DeclarationAST* { - auto copy = make_node(arena()); - - for (auto attributeList = ©->attributeList; - auto node : ListView{ast->attributeList}) { - auto value = rewrite(node); - *attributeList = make_list_node(arena(), value); - attributeList = &(*attributeList)->next; - } - - auto declSpecifierListCtx = DeclSpecs{rewriter()}; - for (auto declSpecifierList = ©->declSpecifierList; - auto node : ListView{ast->declSpecifierList}) { - auto value = rewrite(node); - *declSpecifierList = make_list_node(arena(), value); - declSpecifierList = &(*declSpecifierList)->next; - declSpecifierListCtx.accept(value); - } - declSpecifierListCtx.finish(); - - copy->refQualifierLoc = ast->refQualifierLoc; - copy->lbracketLoc = ast->lbracketLoc; - - for (auto bindingList = ©->bindingList; - auto node : ListView{ast->bindingList}) { - auto value = rewrite(node); - *bindingList = make_list_node(arena(), ast_cast(value)); - bindingList = &(*bindingList)->next; - } - - copy->rbracketLoc = ast->rbracketLoc; - copy->initializer = rewrite(ast->initializer); - copy->semicolonLoc = ast->semicolonLoc; - - return copy; -} - -auto ASTRewriter::StatementVisitor::operator()(LabeledStatementAST* ast) - -> StatementAST* { - auto copy = make_node(arena()); - - copy->identifierLoc = ast->identifierLoc; - copy->colonLoc = ast->colonLoc; - copy->identifier = ast->identifier; - - return copy; -} - -auto ASTRewriter::StatementVisitor::operator()(CaseStatementAST* ast) - -> StatementAST* { - auto copy = make_node(arena()); - - copy->caseLoc = ast->caseLoc; - copy->expression = rewrite(ast->expression); - copy->colonLoc = ast->colonLoc; - - return copy; -} - -auto ASTRewriter::StatementVisitor::operator()(DefaultStatementAST* ast) - -> StatementAST* { - auto copy = make_node(arena()); - - copy->defaultLoc = ast->defaultLoc; - copy->colonLoc = ast->colonLoc; - - return copy; -} - -auto ASTRewriter::StatementVisitor::operator()(ExpressionStatementAST* ast) - -> StatementAST* { - auto copy = make_node(arena()); - - copy->expression = rewrite(ast->expression); - copy->semicolonLoc = ast->semicolonLoc; - - return copy; -} - -auto ASTRewriter::StatementVisitor::operator()(CompoundStatementAST* ast) - -> StatementAST* { - auto copy = make_node(arena()); - - auto _ = Binder::ScopeGuard(binder()); - - if (ast->symbol) { - copy->symbol = binder()->enterBlock(ast->symbol->location()); - } - - copy->lbraceLoc = ast->lbraceLoc; - - for (auto statementList = ©->statementList; - auto node : ListView{ast->statementList}) { - auto value = rewrite(node); - *statementList = make_list_node(arena(), value); - statementList = &(*statementList)->next; - } - - copy->rbraceLoc = ast->rbraceLoc; - - return copy; -} - -auto ASTRewriter::StatementVisitor::operator()(IfStatementAST* ast) - -> StatementAST* { - auto copy = make_node(arena()); - - auto _ = Binder::ScopeGuard(binder()); - - if (ast->symbol) { - copy->symbol = binder()->enterBlock(ast->symbol->location()); - } - - copy->ifLoc = ast->ifLoc; - copy->constexprLoc = ast->constexprLoc; - copy->lparenLoc = ast->lparenLoc; - copy->initializer = rewrite(ast->initializer); - copy->condition = rewrite(ast->condition); - copy->rparenLoc = ast->rparenLoc; - copy->statement = rewrite(ast->statement); - copy->elseLoc = ast->elseLoc; - copy->elseStatement = rewrite(ast->elseStatement); - - return copy; -} - -auto ASTRewriter::StatementVisitor::operator()(ConstevalIfStatementAST* ast) - -> StatementAST* { - auto copy = make_node(arena()); - - copy->ifLoc = ast->ifLoc; - copy->exclaimLoc = ast->exclaimLoc; - copy->constvalLoc = ast->constvalLoc; - copy->statement = rewrite(ast->statement); - copy->elseLoc = ast->elseLoc; - copy->elseStatement = rewrite(ast->elseStatement); - copy->isNot = ast->isNot; - - return copy; -} - -auto ASTRewriter::StatementVisitor::operator()(SwitchStatementAST* ast) - -> StatementAST* { - auto copy = make_node(arena()); - - auto _ = Binder::ScopeGuard(binder()); - - if (ast->symbol) { - copy->symbol = binder()->enterBlock(ast->symbol->location()); - } - - copy->switchLoc = ast->switchLoc; - copy->lparenLoc = ast->lparenLoc; - copy->initializer = rewrite(ast->initializer); - copy->condition = rewrite(ast->condition); - copy->rparenLoc = ast->rparenLoc; - copy->statement = rewrite(ast->statement); - - return copy; -} - -auto ASTRewriter::StatementVisitor::operator()(WhileStatementAST* ast) - -> StatementAST* { - auto copy = make_node(arena()); - - auto _ = Binder::ScopeGuard(binder()); - - if (ast->symbol) { - copy->symbol = binder()->enterBlock(ast->symbol->location()); - } - - copy->whileLoc = ast->whileLoc; - copy->lparenLoc = ast->lparenLoc; - copy->condition = rewrite(ast->condition); - copy->rparenLoc = ast->rparenLoc; - copy->statement = rewrite(ast->statement); - - return copy; -} - -auto ASTRewriter::StatementVisitor::operator()(DoStatementAST* ast) - -> StatementAST* { - auto copy = make_node(arena()); - - copy->doLoc = ast->doLoc; - copy->statement = rewrite(ast->statement); - copy->whileLoc = ast->whileLoc; - copy->lparenLoc = ast->lparenLoc; - copy->expression = rewrite(ast->expression); - copy->rparenLoc = ast->rparenLoc; - copy->semicolonLoc = ast->semicolonLoc; - - return copy; -} - -auto ASTRewriter::StatementVisitor::operator()(ForRangeStatementAST* ast) - -> StatementAST* { - auto copy = make_node(arena()); - - auto _ = Binder::ScopeGuard(binder()); - - if (ast->symbol) { - copy->symbol = binder()->enterBlock(ast->symbol->location()); - } - - copy->forLoc = ast->forLoc; - copy->lparenLoc = ast->lparenLoc; - copy->initializer = rewrite(ast->initializer); - copy->rangeDeclaration = rewrite(ast->rangeDeclaration); - copy->colonLoc = ast->colonLoc; - copy->rangeInitializer = rewrite(ast->rangeInitializer); - copy->rparenLoc = ast->rparenLoc; - copy->statement = rewrite(ast->statement); - - return copy; -} - -auto ASTRewriter::StatementVisitor::operator()(ForStatementAST* ast) - -> StatementAST* { - auto copy = make_node(arena()); - - auto _ = Binder::ScopeGuard(binder()); - - if (ast->symbol) { - copy->symbol = binder()->enterBlock(ast->symbol->location()); - } - - copy->forLoc = ast->forLoc; - copy->lparenLoc = ast->lparenLoc; - copy->initializer = rewrite(ast->initializer); - copy->condition = rewrite(ast->condition); - copy->semicolonLoc = ast->semicolonLoc; - copy->expression = rewrite(ast->expression); - copy->rparenLoc = ast->rparenLoc; - copy->statement = rewrite(ast->statement); - - return copy; -} - -auto ASTRewriter::StatementVisitor::operator()(BreakStatementAST* ast) - -> StatementAST* { - auto copy = make_node(arena()); - - copy->breakLoc = ast->breakLoc; - copy->semicolonLoc = ast->semicolonLoc; - - return copy; -} - -auto ASTRewriter::StatementVisitor::operator()(ContinueStatementAST* ast) - -> StatementAST* { - auto copy = make_node(arena()); - - copy->continueLoc = ast->continueLoc; - copy->semicolonLoc = ast->semicolonLoc; - - return copy; -} - -auto ASTRewriter::StatementVisitor::operator()(ReturnStatementAST* ast) - -> StatementAST* { - auto copy = make_node(arena()); - - copy->returnLoc = ast->returnLoc; - copy->expression = rewrite(ast->expression); - copy->semicolonLoc = ast->semicolonLoc; - - return copy; -} - -auto ASTRewriter::StatementVisitor::operator()(CoroutineReturnStatementAST* ast) - -> StatementAST* { - auto copy = make_node(arena()); - - copy->coreturnLoc = ast->coreturnLoc; - copy->expression = rewrite(ast->expression); - copy->semicolonLoc = ast->semicolonLoc; - - return copy; -} - -auto ASTRewriter::StatementVisitor::operator()(GotoStatementAST* ast) - -> StatementAST* { - auto copy = make_node(arena()); - - copy->gotoLoc = ast->gotoLoc; - copy->starLoc = ast->starLoc; - copy->identifierLoc = ast->identifierLoc; - copy->semicolonLoc = ast->semicolonLoc; - copy->identifier = ast->identifier; - copy->isIndirect = ast->isIndirect; - - return copy; -} - -auto ASTRewriter::StatementVisitor::operator()(DeclarationStatementAST* ast) - -> StatementAST* { - auto copy = make_node(arena()); - - copy->declaration = rewrite(ast->declaration); - - return copy; -} - -auto ASTRewriter::StatementVisitor::operator()(TryBlockStatementAST* ast) - -> StatementAST* { - auto copy = make_node(arena()); - - copy->tryLoc = ast->tryLoc; - copy->statement = ast_cast(rewrite(ast->statement)); - - for (auto handlerList = ©->handlerList; - auto node : ListView{ast->handlerList}) { - auto value = rewrite(node); - *handlerList = make_list_node(arena(), value); - handlerList = &(*handlerList)->next; - } - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()( - GeneratedLiteralExpressionAST* ast) -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->literalLoc = ast->literalLoc; - copy->value = ast->value; - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(CharLiteralExpressionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->literalLoc = ast->literalLoc; - copy->literal = ast->literal; - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(BoolLiteralExpressionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->literalLoc = ast->literalLoc; - copy->isTrue = ast->isTrue; - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(IntLiteralExpressionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->literalLoc = ast->literalLoc; - copy->literal = ast->literal; - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(FloatLiteralExpressionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->literalLoc = ast->literalLoc; - copy->literal = ast->literal; - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()( - NullptrLiteralExpressionAST* ast) -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->literalLoc = ast->literalLoc; - copy->literal = ast->literal; - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(StringLiteralExpressionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->literalLoc = ast->literalLoc; - copy->literal = ast->literal; - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()( - UserDefinedStringLiteralExpressionAST* ast) -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->literalLoc = ast->literalLoc; - copy->literal = ast->literal; - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(ObjectLiteralExpressionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->lparenLoc = ast->lparenLoc; - copy->typeId = rewrite(ast->typeId); - copy->rparenLoc = ast->rparenLoc; - copy->bracedInitList = - ast_cast(rewrite(ast->bracedInitList)); - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(ThisExpressionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->thisLoc = ast->thisLoc; - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()( - GenericSelectionExpressionAST* ast) -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->genericLoc = ast->genericLoc; - copy->lparenLoc = ast->lparenLoc; - copy->expression = rewrite(ast->expression); - copy->commaLoc = ast->commaLoc; - - for (auto genericAssociationList = ©->genericAssociationList; - auto node : ListView{ast->genericAssociationList}) { - auto value = rewrite(node); - *genericAssociationList = make_list_node(arena(), value); - genericAssociationList = &(*genericAssociationList)->next; - } - - copy->rparenLoc = ast->rparenLoc; - copy->matchedAssocIndex = ast->matchedAssocIndex; - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()( - NestedStatementExpressionAST* ast) -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->lparenLoc = ast->lparenLoc; - copy->statement = ast_cast(rewrite(ast->statement)); - copy->rparenLoc = ast->rparenLoc; - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(NestedExpressionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->lparenLoc = ast->lparenLoc; - copy->expression = rewrite(ast->expression); - copy->rparenLoc = ast->rparenLoc; - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(IdExpressionAST* ast) - -> ExpressionAST* { - if (auto param = symbol_cast(ast->symbol); - param && param->depth() == 0 && - param->index() < rewrite.templateArguments_.size()) { - auto symbolPtr = - std::get_if(&rewrite.templateArguments_[param->index()]); - - if (!symbolPtr) { - cxx_runtime_error("expected initializer for non-type template parameter"); - } - - auto parameterPack = symbol_cast(*symbolPtr); - - if (parameterPack && parameterPack == rewrite.parameterPack_ && - rewrite.elementIndex_.has_value()) { - auto idx = rewrite.elementIndex_.value(); - auto element = parameterPack->elements()[idx]; - if (auto var = symbol_cast(element)) { - return rewrite(var->initializer()); - } - } - } - - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->nestedNameSpecifier = rewrite(ast->nestedNameSpecifier); - copy->templateLoc = ast->templateLoc; - copy->unqualifiedId = rewrite(ast->unqualifiedId); - copy->symbol = ast->symbol; - - if (auto param = symbol_cast(copy->symbol); - param && param->depth() == 0 && - param->index() < rewrite.templateArguments_.size()) { - auto symbolPtr = - std::get_if(&rewrite.templateArguments_[param->index()]); - - if (!symbolPtr) { - cxx_runtime_error("expected initializer for non-type template parameter"); - } - - copy->symbol = *symbolPtr; - copy->type = copy->symbol->type(); - } - copy->isTemplateIntroduced = ast->isTemplateIntroduced; - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(LambdaExpressionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->lbracketLoc = ast->lbracketLoc; - copy->captureDefaultLoc = ast->captureDefaultLoc; - - for (auto captureList = ©->captureList; - auto node : ListView{ast->captureList}) { - auto value = rewrite(node); - *captureList = make_list_node(arena(), value); - captureList = &(*captureList)->next; - } - - copy->rbracketLoc = ast->rbracketLoc; - copy->lessLoc = ast->lessLoc; - - for (auto templateParameterList = ©->templateParameterList; - auto node : ListView{ast->templateParameterList}) { - auto value = rewrite(node); - *templateParameterList = make_list_node(arena(), value); - templateParameterList = &(*templateParameterList)->next; - } - - copy->greaterLoc = ast->greaterLoc; - copy->templateRequiresClause = rewrite(ast->templateRequiresClause); - copy->lparenLoc = ast->lparenLoc; - copy->parameterDeclarationClause = rewrite(ast->parameterDeclarationClause); - copy->rparenLoc = ast->rparenLoc; - - for (auto gnuAtributeList = ©->gnuAtributeList; - auto node : ListView{ast->gnuAtributeList}) { - auto value = rewrite(node); - *gnuAtributeList = make_list_node(arena(), value); - gnuAtributeList = &(*gnuAtributeList)->next; - } - - for (auto lambdaSpecifierList = ©->lambdaSpecifierList; - auto node : ListView{ast->lambdaSpecifierList}) { - auto value = rewrite(node); - *lambdaSpecifierList = make_list_node(arena(), value); - lambdaSpecifierList = &(*lambdaSpecifierList)->next; - } - - { - auto _ = Binder::ScopeGuard(binder()); - - if (copy->parameterDeclarationClause) { - binder()->setScope( - copy->parameterDeclarationClause->functionParametersSymbol); - } - - copy->exceptionSpecifier = rewrite(ast->exceptionSpecifier); - - for (auto attributeList = ©->attributeList; - auto node : ListView{ast->attributeList}) { - auto value = rewrite(node); - *attributeList = make_list_node(arena(), value); - attributeList = &(*attributeList)->next; - } - - copy->trailingReturnType = rewrite(ast->trailingReturnType); - copy->requiresClause = rewrite(ast->requiresClause); - } - - copy->statement = ast_cast(rewrite(ast->statement)); - copy->captureDefault = ast->captureDefault; - copy->symbol = ast->symbol; - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(FoldExpressionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->lparenLoc = ast->lparenLoc; - copy->leftExpression = rewrite(ast->leftExpression); - copy->opLoc = ast->opLoc; - copy->ellipsisLoc = ast->ellipsisLoc; - copy->foldOpLoc = ast->foldOpLoc; - copy->rightExpression = rewrite(ast->rightExpression); - copy->rparenLoc = ast->rparenLoc; - copy->op = ast->op; - copy->foldOp = ast->foldOp; - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(RightFoldExpressionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->lparenLoc = ast->lparenLoc; - copy->expression = rewrite(ast->expression); - copy->opLoc = ast->opLoc; - copy->ellipsisLoc = ast->ellipsisLoc; - copy->rparenLoc = ast->rparenLoc; - copy->op = ast->op; - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(LeftFoldExpressionAST* ast) - -> ExpressionAST* { - if (auto parameterPack = rewrite.getParameterPack(ast->expression)) { - auto savedParameterPack = rewrite.parameterPack_; - std::swap(rewrite.parameterPack_, parameterPack); - - std::vector instantiations; - ExpressionAST* current = nullptr; - - int n = 0; - for (auto element : rewrite.parameterPack_->elements()) { - std::optional index{n}; - std::swap(rewrite.elementIndex_, index); - - auto expression = rewrite(ast->expression); - if (!current) { - current = expression; - } else { - auto binop = make_node(arena()); - binop->valueCategory = current->valueCategory; - binop->type = current->type; - binop->leftExpression = current; - binop->op = ast->op; - binop->opLoc = ast->opLoc; - binop->rightExpression = expression; - current = binop; - } - - std::swap(rewrite.elementIndex_, index); - ++n; - } - - std::swap(rewrite.parameterPack_, parameterPack); - - return current; - } - - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->lparenLoc = ast->lparenLoc; - copy->ellipsisLoc = ast->ellipsisLoc; - copy->opLoc = ast->opLoc; - copy->expression = rewrite(ast->expression); - copy->rparenLoc = ast->rparenLoc; - copy->op = ast->op; - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(RequiresExpressionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->requiresLoc = ast->requiresLoc; - copy->lparenLoc = ast->lparenLoc; - copy->parameterDeclarationClause = rewrite(ast->parameterDeclarationClause); - copy->rparenLoc = ast->rparenLoc; - copy->lbraceLoc = ast->lbraceLoc; - - for (auto requirementList = ©->requirementList; - auto node : ListView{ast->requirementList}) { - auto value = rewrite(node); - *requirementList = make_list_node(arena(), value); - requirementList = &(*requirementList)->next; - } - - copy->rbraceLoc = ast->rbraceLoc; - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(VaArgExpressionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->vaArgLoc = ast->vaArgLoc; - copy->lparenLoc = ast->lparenLoc; - copy->expression = rewrite(ast->expression); - copy->commaLoc = ast->commaLoc; - copy->typeId = rewrite(ast->typeId); - copy->rparenLoc = ast->rparenLoc; - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(SubscriptExpressionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->baseExpression = rewrite(ast->baseExpression); - copy->lbracketLoc = ast->lbracketLoc; - copy->indexExpression = rewrite(ast->indexExpression); - copy->rbracketLoc = ast->rbracketLoc; - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(CallExpressionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->baseExpression = rewrite(ast->baseExpression); - copy->lparenLoc = ast->lparenLoc; - - for (auto expressionList = ©->expressionList; - auto node : ListView{ast->expressionList}) { - auto value = rewrite(node); - *expressionList = make_list_node(arena(), value); - expressionList = &(*expressionList)->next; - } - - copy->rparenLoc = ast->rparenLoc; - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(TypeConstructionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->typeSpecifier = rewrite(ast->typeSpecifier); - copy->lparenLoc = ast->lparenLoc; - - for (auto expressionList = ©->expressionList; - auto node : ListView{ast->expressionList}) { - auto value = rewrite(node); - *expressionList = make_list_node(arena(), value); - expressionList = &(*expressionList)->next; - } - - copy->rparenLoc = ast->rparenLoc; - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(BracedTypeConstructionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->typeSpecifier = rewrite(ast->typeSpecifier); - copy->bracedInitList = - ast_cast(rewrite(ast->bracedInitList)); - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(SpliceMemberExpressionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->baseExpression = rewrite(ast->baseExpression); - copy->accessLoc = ast->accessLoc; - copy->templateLoc = ast->templateLoc; - copy->splicer = rewrite(ast->splicer); - copy->symbol = ast->symbol; - copy->accessOp = ast->accessOp; - copy->isTemplateIntroduced = ast->isTemplateIntroduced; - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(MemberExpressionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->baseExpression = rewrite(ast->baseExpression); - copy->accessLoc = ast->accessLoc; - copy->nestedNameSpecifier = rewrite(ast->nestedNameSpecifier); - copy->templateLoc = ast->templateLoc; - copy->unqualifiedId = rewrite(ast->unqualifiedId); - copy->symbol = ast->symbol; - copy->accessOp = ast->accessOp; - copy->isTemplateIntroduced = ast->isTemplateIntroduced; - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(PostIncrExpressionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->baseExpression = rewrite(ast->baseExpression); - copy->opLoc = ast->opLoc; - copy->op = ast->op; - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(CppCastExpressionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->castLoc = ast->castLoc; - copy->lessLoc = ast->lessLoc; - copy->typeId = rewrite(ast->typeId); - copy->greaterLoc = ast->greaterLoc; - copy->lparenLoc = ast->lparenLoc; - copy->expression = rewrite(ast->expression); - copy->rparenLoc = ast->rparenLoc; - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()( - BuiltinBitCastExpressionAST* ast) -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->castLoc = ast->castLoc; - copy->lparenLoc = ast->lparenLoc; - copy->typeId = rewrite(ast->typeId); - copy->commaLoc = ast->commaLoc; - copy->expression = rewrite(ast->expression); - copy->rparenLoc = ast->rparenLoc; - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()( - BuiltinOffsetofExpressionAST* ast) -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->offsetofLoc = ast->offsetofLoc; - copy->lparenLoc = ast->lparenLoc; - copy->typeId = rewrite(ast->typeId); - copy->commaLoc = ast->commaLoc; - copy->identifierLoc = ast->identifierLoc; - - for (auto designatorList = ©->designatorList; - auto node : ListView{ast->designatorList}) { - auto value = rewrite(node); - *designatorList = make_list_node(arena(), value); - designatorList = &(*designatorList)->next; - } - - copy->rparenLoc = ast->rparenLoc; - copy->identifier = ast->identifier; - copy->symbol = ast->symbol; - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(TypeidExpressionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->typeidLoc = ast->typeidLoc; - copy->lparenLoc = ast->lparenLoc; - copy->expression = rewrite(ast->expression); - copy->rparenLoc = ast->rparenLoc; - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(TypeidOfTypeExpressionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->typeidLoc = ast->typeidLoc; - copy->lparenLoc = ast->lparenLoc; - copy->typeId = rewrite(ast->typeId); - copy->rparenLoc = ast->rparenLoc; - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(SpliceExpressionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->splicer = rewrite(ast->splicer); - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()( - GlobalScopeReflectExpressionAST* ast) -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->caretLoc = ast->caretLoc; - copy->scopeLoc = ast->scopeLoc; - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()( - NamespaceReflectExpressionAST* ast) -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->caretLoc = ast->caretLoc; - copy->identifierLoc = ast->identifierLoc; - copy->identifier = ast->identifier; - copy->symbol = ast->symbol; - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(TypeIdReflectExpressionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->caretLoc = ast->caretLoc; - copy->typeId = rewrite(ast->typeId); - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(ReflectExpressionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->caretLoc = ast->caretLoc; - copy->expression = rewrite(ast->expression); - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(LabelAddressExpressionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->ampAmpLoc = ast->ampAmpLoc; - copy->identifierLoc = ast->identifierLoc; - copy->identifier = ast->identifier; - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(UnaryExpressionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->opLoc = ast->opLoc; - copy->expression = rewrite(ast->expression); - copy->op = ast->op; - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(AwaitExpressionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->awaitLoc = ast->awaitLoc; - copy->expression = rewrite(ast->expression); - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(SizeofExpressionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->sizeofLoc = ast->sizeofLoc; - copy->expression = rewrite(ast->expression); - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(SizeofTypeExpressionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->sizeofLoc = ast->sizeofLoc; - copy->lparenLoc = ast->lparenLoc; - copy->typeId = rewrite(ast->typeId); - copy->rparenLoc = ast->rparenLoc; - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(SizeofPackExpressionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->sizeofLoc = ast->sizeofLoc; - copy->ellipsisLoc = ast->ellipsisLoc; - copy->lparenLoc = ast->lparenLoc; - copy->identifierLoc = ast->identifierLoc; - copy->rparenLoc = ast->rparenLoc; - copy->identifier = ast->identifier; - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(AlignofTypeExpressionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->alignofLoc = ast->alignofLoc; - copy->lparenLoc = ast->lparenLoc; - copy->typeId = rewrite(ast->typeId); - copy->rparenLoc = ast->rparenLoc; - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(AlignofExpressionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->alignofLoc = ast->alignofLoc; - copy->expression = rewrite(ast->expression); - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(NoexceptExpressionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->noexceptLoc = ast->noexceptLoc; - copy->lparenLoc = ast->lparenLoc; - copy->expression = rewrite(ast->expression); - copy->rparenLoc = ast->rparenLoc; - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(NewExpressionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->scopeLoc = ast->scopeLoc; - copy->newLoc = ast->newLoc; - copy->newPlacement = rewrite(ast->newPlacement); - copy->lparenLoc = ast->lparenLoc; - - auto typeSpecifierListCtx = DeclSpecs{rewriter()}; - for (auto typeSpecifierList = ©->typeSpecifierList; - auto node : ListView{ast->typeSpecifierList}) { - auto value = rewrite(node); - *typeSpecifierList = make_list_node(arena(), value); - typeSpecifierList = &(*typeSpecifierList)->next; - typeSpecifierListCtx.accept(value); - } - typeSpecifierListCtx.finish(); - - copy->declarator = rewrite(ast->declarator); - - auto declaratorDecl = Decl{typeSpecifierListCtx, copy->declarator}; - auto declaratorType = getDeclaratorType(translationUnit(), copy->declarator, - typeSpecifierListCtx.type()); - copy->rparenLoc = ast->rparenLoc; - copy->newInitalizer = rewrite(ast->newInitalizer); - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(DeleteExpressionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->scopeLoc = ast->scopeLoc; - copy->deleteLoc = ast->deleteLoc; - copy->lbracketLoc = ast->lbracketLoc; - copy->rbracketLoc = ast->rbracketLoc; - copy->expression = rewrite(ast->expression); - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(CastExpressionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->lparenLoc = ast->lparenLoc; - copy->typeId = rewrite(ast->typeId); - copy->rparenLoc = ast->rparenLoc; - copy->expression = rewrite(ast->expression); - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(ImplicitCastExpressionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->expression = rewrite(ast->expression); - copy->castKind = ast->castKind; - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(BinaryExpressionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->leftExpression = rewrite(ast->leftExpression); - copy->opLoc = ast->opLoc; - copy->rightExpression = rewrite(ast->rightExpression); - copy->op = ast->op; - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(ConditionalExpressionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->condition = rewrite(ast->condition); - copy->questionLoc = ast->questionLoc; - copy->iftrueExpression = rewrite(ast->iftrueExpression); - copy->colonLoc = ast->colonLoc; - copy->iffalseExpression = rewrite(ast->iffalseExpression); - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(YieldExpressionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->yieldLoc = ast->yieldLoc; - copy->expression = rewrite(ast->expression); - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(ThrowExpressionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->throwLoc = ast->throwLoc; - copy->expression = rewrite(ast->expression); - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(AssignmentExpressionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->leftExpression = rewrite(ast->leftExpression); - copy->opLoc = ast->opLoc; - copy->rightExpression = rewrite(ast->rightExpression); - copy->op = ast->op; - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()( - CompoundAssignmentExpressionAST* ast) -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->leftExpression = rewrite(ast->leftExpression); - copy->opLoc = ast->opLoc; - copy->rightExpression = rewrite(ast->rightExpression); - copy->op = ast->op; - copy->leftCastKind = ast->leftCastKind; - copy->leftCastType = ast->leftCastType; - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(PackExpansionExpressionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->expression = rewrite(ast->expression); - copy->ellipsisLoc = ast->ellipsisLoc; - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()( - DesignatedInitializerClauseAST* ast) -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - - for (auto designatorList = ©->designatorList; - auto node : ListView{ast->designatorList}) { - auto value = rewrite(node); - *designatorList = make_list_node(arena(), value); - designatorList = &(*designatorList)->next; - } - - copy->initializer = rewrite(ast->initializer); - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(TypeTraitExpressionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->typeTraitLoc = ast->typeTraitLoc; - copy->lparenLoc = ast->lparenLoc; - - for (auto typeIdList = ©->typeIdList; - auto node : ListView{ast->typeIdList}) { - auto value = rewrite(node); - *typeIdList = make_list_node(arena(), value); - typeIdList = &(*typeIdList)->next; - } - - copy->rparenLoc = ast->rparenLoc; - copy->typeTrait = ast->typeTrait; - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(ConditionExpressionAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - - for (auto attributeList = ©->attributeList; - auto node : ListView{ast->attributeList}) { - auto value = rewrite(node); - *attributeList = make_list_node(arena(), value); - attributeList = &(*attributeList)->next; - } - - auto declSpecifierListCtx = DeclSpecs{rewriter()}; - for (auto declSpecifierList = ©->declSpecifierList; - auto node : ListView{ast->declSpecifierList}) { - auto value = rewrite(node); - *declSpecifierList = make_list_node(arena(), value); - declSpecifierList = &(*declSpecifierList)->next; - declSpecifierListCtx.accept(value); - } - declSpecifierListCtx.finish(); - - copy->declarator = rewrite(ast->declarator); - - auto declaratorDecl = Decl{declSpecifierListCtx, copy->declarator}; - auto declaratorType = getDeclaratorType(translationUnit(), copy->declarator, - declSpecifierListCtx.type()); - copy->initializer = rewrite(ast->initializer); - copy->symbol = ast->symbol; - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(EqualInitializerAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->equalLoc = ast->equalLoc; - copy->expression = rewrite(ast->expression); - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(BracedInitListAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->lbraceLoc = ast->lbraceLoc; - - for (auto expressionList = ©->expressionList; - auto node : ListView{ast->expressionList}) { - auto value = rewrite(node); - *expressionList = make_list_node(arena(), value); - expressionList = &(*expressionList)->next; - } - - copy->commaLoc = ast->commaLoc; - copy->rbraceLoc = ast->rbraceLoc; - - return copy; -} - -auto ASTRewriter::ExpressionVisitor::operator()(ParenInitializerAST* ast) - -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->lparenLoc = ast->lparenLoc; - - for (auto expressionList = ©->expressionList; - auto node : ListView{ast->expressionList}) { - auto value = rewrite(node); - *expressionList = make_list_node(arena(), value); - expressionList = &(*expressionList)->next; - } - - copy->rparenLoc = ast->rparenLoc; - - return copy; -} - -auto ASTRewriter::GenericAssociationVisitor::operator()( - DefaultGenericAssociationAST* ast) -> GenericAssociationAST* { - auto copy = make_node(arena()); - - copy->defaultLoc = ast->defaultLoc; - copy->colonLoc = ast->colonLoc; - copy->expression = rewrite(ast->expression); - - return copy; -} - -auto ASTRewriter::GenericAssociationVisitor::operator()( - TypeGenericAssociationAST* ast) -> GenericAssociationAST* { - auto copy = make_node(arena()); - - copy->typeId = rewrite(ast->typeId); - copy->colonLoc = ast->colonLoc; - copy->expression = rewrite(ast->expression); - - return copy; -} - -auto ASTRewriter::DesignatorVisitor::operator()(DotDesignatorAST* ast) - -> DesignatorAST* { - auto copy = make_node(arena()); - - copy->dotLoc = ast->dotLoc; - copy->identifierLoc = ast->identifierLoc; - copy->identifier = ast->identifier; - - return copy; -} - -auto ASTRewriter::DesignatorVisitor::operator()(SubscriptDesignatorAST* ast) - -> DesignatorAST* { - auto copy = make_node(arena()); - - copy->lbracketLoc = ast->lbracketLoc; - copy->expression = rewrite(ast->expression); - copy->rbracketLoc = ast->rbracketLoc; - - return copy; -} - -auto ASTRewriter::TemplateParameterVisitor::operator()( - TemplateTypeParameterAST* ast) -> TemplateParameterAST* { - auto copy = make_node(arena()); - - copy->symbol = ast->symbol; - copy->depth = ast->depth; - copy->index = ast->index; - copy->templateLoc = ast->templateLoc; - copy->lessLoc = ast->lessLoc; - - for (auto templateParameterList = ©->templateParameterList; - auto node : ListView{ast->templateParameterList}) { - auto value = rewrite(node); - *templateParameterList = make_list_node(arena(), value); - templateParameterList = &(*templateParameterList)->next; - } - - copy->greaterLoc = ast->greaterLoc; - copy->requiresClause = rewrite(ast->requiresClause); - copy->classKeyLoc = ast->classKeyLoc; - copy->ellipsisLoc = ast->ellipsisLoc; - copy->identifierLoc = ast->identifierLoc; - copy->equalLoc = ast->equalLoc; - copy->idExpression = ast_cast(rewrite(ast->idExpression)); - copy->identifier = ast->identifier; - copy->isPack = ast->isPack; - - return copy; -} - -auto ASTRewriter::TemplateParameterVisitor::operator()( - NonTypeTemplateParameterAST* ast) -> TemplateParameterAST* { - auto copy = make_node(arena()); - - copy->symbol = ast->symbol; - copy->depth = ast->depth; - copy->index = ast->index; - copy->declaration = - ast_cast(rewrite(ast->declaration)); - - return copy; -} - -auto ASTRewriter::TemplateParameterVisitor::operator()( - TypenameTypeParameterAST* ast) -> TemplateParameterAST* { - auto copy = make_node(arena()); - - copy->symbol = ast->symbol; - copy->depth = ast->depth; - copy->index = ast->index; - copy->classKeyLoc = ast->classKeyLoc; - copy->ellipsisLoc = ast->ellipsisLoc; - copy->identifierLoc = ast->identifierLoc; - copy->equalLoc = ast->equalLoc; - copy->typeId = rewrite(ast->typeId); - copy->identifier = ast->identifier; - copy->isPack = ast->isPack; - - return copy; -} - -auto ASTRewriter::TemplateParameterVisitor::operator()( - ConstraintTypeParameterAST* ast) -> TemplateParameterAST* { - auto copy = make_node(arena()); - - copy->symbol = ast->symbol; - copy->depth = ast->depth; - copy->index = ast->index; - copy->typeConstraint = rewrite(ast->typeConstraint); - copy->ellipsisLoc = ast->ellipsisLoc; - copy->identifierLoc = ast->identifierLoc; - copy->equalLoc = ast->equalLoc; - copy->typeId = rewrite(ast->typeId); - copy->identifier = ast->identifier; - - return copy; -} - -auto ASTRewriter::SpecifierVisitor::operator()(GeneratedTypeSpecifierAST* ast) - -> SpecifierAST* { - auto copy = make_node(arena()); - - copy->typeLoc = ast->typeLoc; - copy->type = ast->type; - - return copy; -} - -auto ASTRewriter::SpecifierVisitor::operator()(TypedefSpecifierAST* ast) - -> SpecifierAST* { - auto copy = make_node(arena()); - - copy->typedefLoc = ast->typedefLoc; - - return copy; -} - -auto ASTRewriter::SpecifierVisitor::operator()(FriendSpecifierAST* ast) - -> SpecifierAST* { - auto copy = make_node(arena()); - - copy->friendLoc = ast->friendLoc; - - return copy; -} - -auto ASTRewriter::SpecifierVisitor::operator()(ConstevalSpecifierAST* ast) - -> SpecifierAST* { - auto copy = make_node(arena()); - - copy->constevalLoc = ast->constevalLoc; - - return copy; -} - -auto ASTRewriter::SpecifierVisitor::operator()(ConstinitSpecifierAST* ast) - -> SpecifierAST* { - auto copy = make_node(arena()); - - copy->constinitLoc = ast->constinitLoc; - - return copy; -} - -auto ASTRewriter::SpecifierVisitor::operator()(ConstexprSpecifierAST* ast) - -> SpecifierAST* { - auto copy = make_node(arena()); - - copy->constexprLoc = ast->constexprLoc; - - return copy; -} - -auto ASTRewriter::SpecifierVisitor::operator()(InlineSpecifierAST* ast) - -> SpecifierAST* { - auto copy = make_node(arena()); - - copy->inlineLoc = ast->inlineLoc; - - return copy; -} - -auto ASTRewriter::SpecifierVisitor::operator()(NoreturnSpecifierAST* ast) - -> SpecifierAST* { - auto copy = make_node(arena()); - - copy->noreturnLoc = ast->noreturnLoc; - - return copy; -} - -auto ASTRewriter::SpecifierVisitor::operator()(StaticSpecifierAST* ast) - -> SpecifierAST* { - auto copy = make_node(arena()); - - copy->staticLoc = ast->staticLoc; - - return copy; -} - -auto ASTRewriter::SpecifierVisitor::operator()(ExternSpecifierAST* ast) - -> SpecifierAST* { - auto copy = make_node(arena()); - - copy->externLoc = ast->externLoc; - - return copy; -} - -auto ASTRewriter::SpecifierVisitor::operator()(RegisterSpecifierAST* ast) - -> SpecifierAST* { - auto copy = make_node(arena()); - - copy->registerLoc = ast->registerLoc; - - return copy; -} - -auto ASTRewriter::SpecifierVisitor::operator()(ThreadLocalSpecifierAST* ast) - -> SpecifierAST* { - auto copy = make_node(arena()); - - copy->threadLocalLoc = ast->threadLocalLoc; - - return copy; -} - -auto ASTRewriter::SpecifierVisitor::operator()(ThreadSpecifierAST* ast) - -> SpecifierAST* { - auto copy = make_node(arena()); - - copy->threadLoc = ast->threadLoc; - - return copy; -} - -auto ASTRewriter::SpecifierVisitor::operator()(MutableSpecifierAST* ast) - -> SpecifierAST* { - auto copy = make_node(arena()); - - copy->mutableLoc = ast->mutableLoc; - - return copy; -} - -auto ASTRewriter::SpecifierVisitor::operator()(VirtualSpecifierAST* ast) - -> SpecifierAST* { - auto copy = make_node(arena()); - - copy->virtualLoc = ast->virtualLoc; - - return copy; -} - -auto ASTRewriter::SpecifierVisitor::operator()(ExplicitSpecifierAST* ast) - -> SpecifierAST* { - auto copy = make_node(arena()); - - copy->explicitLoc = ast->explicitLoc; - copy->lparenLoc = ast->lparenLoc; - copy->expression = rewrite(ast->expression); - copy->rparenLoc = ast->rparenLoc; - - return copy; -} - -auto ASTRewriter::SpecifierVisitor::operator()(AutoTypeSpecifierAST* ast) - -> SpecifierAST* { - auto copy = make_node(arena()); - - copy->autoLoc = ast->autoLoc; - - return copy; -} - -auto ASTRewriter::SpecifierVisitor::operator()(VoidTypeSpecifierAST* ast) - -> SpecifierAST* { - auto copy = make_node(arena()); - - copy->voidLoc = ast->voidLoc; - - return copy; -} - -auto ASTRewriter::SpecifierVisitor::operator()(SizeTypeSpecifierAST* ast) - -> SpecifierAST* { - auto copy = make_node(arena()); - - copy->specifierLoc = ast->specifierLoc; - copy->specifier = ast->specifier; - - return copy; -} - -auto ASTRewriter::SpecifierVisitor::operator()(SignTypeSpecifierAST* ast) - -> SpecifierAST* { - auto copy = make_node(arena()); - - copy->specifierLoc = ast->specifierLoc; - copy->specifier = ast->specifier; - - return copy; -} - -auto ASTRewriter::SpecifierVisitor::operator()(VaListTypeSpecifierAST* ast) - -> SpecifierAST* { - auto copy = make_node(arena()); - - copy->specifierLoc = ast->specifierLoc; - copy->specifier = ast->specifier; - - return copy; -} - -auto ASTRewriter::SpecifierVisitor::operator()(IntegralTypeSpecifierAST* ast) - -> SpecifierAST* { - auto copy = make_node(arena()); - - copy->specifierLoc = ast->specifierLoc; - copy->specifier = ast->specifier; - - return copy; -} - -auto ASTRewriter::SpecifierVisitor::operator()( - FloatingPointTypeSpecifierAST* ast) -> SpecifierAST* { - auto copy = make_node(arena()); - - copy->specifierLoc = ast->specifierLoc; - copy->specifier = ast->specifier; - - return copy; -} - -auto ASTRewriter::SpecifierVisitor::operator()(ComplexTypeSpecifierAST* ast) - -> SpecifierAST* { - auto copy = make_node(arena()); - - copy->complexLoc = ast->complexLoc; - - return copy; -} - -auto ASTRewriter::SpecifierVisitor::operator()(NamedTypeSpecifierAST* ast) - -> SpecifierAST* { - auto copy = make_node(arena()); - - copy->nestedNameSpecifier = rewrite(ast->nestedNameSpecifier); - copy->templateLoc = ast->templateLoc; - copy->unqualifiedId = rewrite(ast->unqualifiedId); - copy->isTemplateIntroduced = ast->isTemplateIntroduced; - copy->symbol = ast->symbol; - - if (auto typeParameter = symbol_cast(copy->symbol)) { - const auto& args = rewrite.templateArguments_; - if (typeParameter && typeParameter->depth() == 0 && - typeParameter->index() < args.size()) { - auto index = typeParameter->index(); - - if (auto sym = std::get_if(&args[index])) { - copy->symbol = *sym; - } - } - } - - return copy; -} - -auto ASTRewriter::SpecifierVisitor::operator()(AtomicTypeSpecifierAST* ast) - -> SpecifierAST* { - auto copy = make_node(arena()); - - copy->atomicLoc = ast->atomicLoc; - copy->lparenLoc = ast->lparenLoc; - copy->typeId = rewrite(ast->typeId); - copy->rparenLoc = ast->rparenLoc; - - return copy; -} - -auto ASTRewriter::SpecifierVisitor::operator()(UnderlyingTypeSpecifierAST* ast) - -> SpecifierAST* { - auto copy = make_node(arena()); - - copy->underlyingTypeLoc = ast->underlyingTypeLoc; - copy->lparenLoc = ast->lparenLoc; - copy->typeId = rewrite(ast->typeId); - copy->rparenLoc = ast->rparenLoc; - - return copy; -} - -auto ASTRewriter::SpecifierVisitor::operator()(ElaboratedTypeSpecifierAST* ast) - -> SpecifierAST* { - auto copy = make_node(arena()); - - copy->classLoc = ast->classLoc; - - for (auto attributeList = ©->attributeList; - auto node : ListView{ast->attributeList}) { - auto value = rewrite(node); - *attributeList = make_list_node(arena(), value); - attributeList = &(*attributeList)->next; - } - - copy->nestedNameSpecifier = rewrite(ast->nestedNameSpecifier); - copy->templateLoc = ast->templateLoc; - copy->unqualifiedId = rewrite(ast->unqualifiedId); - copy->classKey = ast->classKey; - copy->isTemplateIntroduced = ast->isTemplateIntroduced; - copy->symbol = ast->symbol; - - return copy; -} - -auto ASTRewriter::SpecifierVisitor::operator()(DecltypeAutoSpecifierAST* ast) - -> SpecifierAST* { - auto copy = make_node(arena()); - - copy->decltypeLoc = ast->decltypeLoc; - copy->lparenLoc = ast->lparenLoc; - copy->autoLoc = ast->autoLoc; - copy->rparenLoc = ast->rparenLoc; - - return copy; -} - -auto ASTRewriter::SpecifierVisitor::operator()(DecltypeSpecifierAST* ast) - -> SpecifierAST* { - auto copy = make_node(arena()); - - copy->decltypeLoc = ast->decltypeLoc; - copy->lparenLoc = ast->lparenLoc; - copy->expression = rewrite(ast->expression); - copy->rparenLoc = ast->rparenLoc; - copy->type = ast->type; - - return copy; -} - -auto ASTRewriter::SpecifierVisitor::operator()(PlaceholderTypeSpecifierAST* ast) - -> SpecifierAST* { - auto copy = make_node(arena()); - - copy->typeConstraint = rewrite(ast->typeConstraint); - copy->specifier = rewrite(ast->specifier); - - return copy; -} - -auto ASTRewriter::SpecifierVisitor::operator()(ConstQualifierAST* ast) - -> SpecifierAST* { - auto copy = make_node(arena()); - - copy->constLoc = ast->constLoc; - - return copy; -} - -auto ASTRewriter::SpecifierVisitor::operator()(VolatileQualifierAST* ast) - -> SpecifierAST* { - auto copy = make_node(arena()); - - copy->volatileLoc = ast->volatileLoc; - - return copy; -} - -auto ASTRewriter::SpecifierVisitor::operator()(AtomicQualifierAST* ast) - -> SpecifierAST* { - auto copy = make_node(arena()); - - copy->atomicLoc = ast->atomicLoc; - - return copy; -} - -auto ASTRewriter::SpecifierVisitor::operator()(RestrictQualifierAST* ast) - -> SpecifierAST* { - auto copy = make_node(arena()); - - copy->restrictLoc = ast->restrictLoc; - - return copy; -} - -auto ASTRewriter::SpecifierVisitor::operator()(EnumSpecifierAST* ast) - -> SpecifierAST* { - auto copy = make_node(arena()); - - copy->enumLoc = ast->enumLoc; - copy->classLoc = ast->classLoc; - - for (auto attributeList = ©->attributeList; - auto node : ListView{ast->attributeList}) { - auto value = rewrite(node); - *attributeList = make_list_node(arena(), value); - attributeList = &(*attributeList)->next; - } - - copy->nestedNameSpecifier = rewrite(ast->nestedNameSpecifier); - copy->unqualifiedId = ast_cast(rewrite(ast->unqualifiedId)); - copy->colonLoc = ast->colonLoc; - - auto typeSpecifierListCtx = DeclSpecs{rewriter()}; - for (auto typeSpecifierList = ©->typeSpecifierList; - auto node : ListView{ast->typeSpecifierList}) { - auto value = rewrite(node); - *typeSpecifierList = make_list_node(arena(), value); - typeSpecifierList = &(*typeSpecifierList)->next; - typeSpecifierListCtx.accept(value); - } - typeSpecifierListCtx.finish(); - - copy->lbraceLoc = ast->lbraceLoc; - - for (auto enumeratorList = ©->enumeratorList; - auto node : ListView{ast->enumeratorList}) { - auto value = rewrite(node); - *enumeratorList = make_list_node(arena(), value); - enumeratorList = &(*enumeratorList)->next; - } - - copy->commaLoc = ast->commaLoc; - copy->rbraceLoc = ast->rbraceLoc; - copy->symbol = ast->symbol; - - return copy; -} - -auto ASTRewriter::SpecifierVisitor::operator()(ClassSpecifierAST* ast) - -> SpecifierAST* { - auto copy = make_node(arena()); - - copy->classLoc = ast->classLoc; - - for (auto attributeList = ©->attributeList; - auto node : ListView{ast->attributeList}) { - auto value = rewrite(node); - *attributeList = make_list_node(arena(), value); - attributeList = &(*attributeList)->next; - } - - copy->nestedNameSpecifier = rewrite(ast->nestedNameSpecifier); - copy->unqualifiedId = rewrite(ast->unqualifiedId); - copy->finalLoc = ast->finalLoc; - copy->colonLoc = ast->colonLoc; - - // ### TODO: use Binder::bind() - auto _ = Binder::ScopeGuard{binder()}; - auto location = ast->symbol->location(); - auto className = ast->symbol->name(); - auto classSymbol = control()->newClassSymbol(binder()->scope(), location); - classSymbol->setName(className); - classSymbol->setIsUnion(ast->symbol->isUnion()); - classSymbol->setFinal(ast->isFinal); - binder()->setScope(classSymbol); - - copy->symbol = classSymbol; - - for (auto baseSpecifierList = ©->baseSpecifierList; - auto node : ListView{ast->baseSpecifierList}) { - auto value = rewrite(node); - *baseSpecifierList = make_list_node(arena(), value); - baseSpecifierList = &(*baseSpecifierList)->next; - - if (value->symbol) { - classSymbol->addBaseClass(value->symbol); - } - } - - copy->lbraceLoc = ast->lbraceLoc; - - for (auto declarationList = ©->declarationList; - auto node : ListView{ast->declarationList}) { - auto value = rewrite(node); - *declarationList = make_list_node(arena(), value); - declarationList = &(*declarationList)->next; - } - - copy->rbraceLoc = ast->rbraceLoc; - copy->classKey = ast->classKey; - // copy->symbol = ast->symbol; // TODO: remove done by the binder - copy->isFinal = ast->isFinal; - - binder()->complete(copy); - - return copy; -} - -auto ASTRewriter::SpecifierVisitor::operator()(TypenameSpecifierAST* ast) - -> SpecifierAST* { - auto copy = make_node(arena()); - - copy->typenameLoc = ast->typenameLoc; - copy->nestedNameSpecifier = rewrite(ast->nestedNameSpecifier); - copy->templateLoc = ast->templateLoc; - copy->unqualifiedId = rewrite(ast->unqualifiedId); - copy->isTemplateIntroduced = ast->isTemplateIntroduced; - - return copy; -} - -auto ASTRewriter::SpecifierVisitor::operator()(SplicerTypeSpecifierAST* ast) - -> SpecifierAST* { - auto copy = make_node(arena()); - - copy->typenameLoc = ast->typenameLoc; - copy->splicer = rewrite(ast->splicer); - - return copy; -} - -auto ASTRewriter::PtrOperatorVisitor::operator()(PointerOperatorAST* ast) - -> PtrOperatorAST* { - auto copy = make_node(arena()); - - copy->starLoc = ast->starLoc; - - for (auto attributeList = ©->attributeList; - auto node : ListView{ast->attributeList}) { - auto value = rewrite(node); - *attributeList = make_list_node(arena(), value); - attributeList = &(*attributeList)->next; - } - - auto cvQualifierListCtx = DeclSpecs{rewriter()}; - for (auto cvQualifierList = ©->cvQualifierList; - auto node : ListView{ast->cvQualifierList}) { - auto value = rewrite(node); - *cvQualifierList = make_list_node(arena(), value); - cvQualifierList = &(*cvQualifierList)->next; - cvQualifierListCtx.accept(value); - } - - return copy; -} - -auto ASTRewriter::PtrOperatorVisitor::operator()(ReferenceOperatorAST* ast) - -> PtrOperatorAST* { - auto copy = make_node(arena()); - - copy->refLoc = ast->refLoc; - - for (auto attributeList = ©->attributeList; - auto node : ListView{ast->attributeList}) { - auto value = rewrite(node); - *attributeList = make_list_node(arena(), value); - attributeList = &(*attributeList)->next; - } - - copy->refOp = ast->refOp; - - return copy; -} - -auto ASTRewriter::PtrOperatorVisitor::operator()(PtrToMemberOperatorAST* ast) - -> PtrOperatorAST* { - auto copy = make_node(arena()); - - copy->nestedNameSpecifier = rewrite(ast->nestedNameSpecifier); - copy->starLoc = ast->starLoc; - - for (auto attributeList = ©->attributeList; - auto node : ListView{ast->attributeList}) { - auto value = rewrite(node); - *attributeList = make_list_node(arena(), value); - attributeList = &(*attributeList)->next; - } - - auto cvQualifierListCtx = DeclSpecs{rewriter()}; - for (auto cvQualifierList = ©->cvQualifierList; - auto node : ListView{ast->cvQualifierList}) { - auto value = rewrite(node); - *cvQualifierList = make_list_node(arena(), value); - cvQualifierList = &(*cvQualifierList)->next; - cvQualifierListCtx.accept(value); - } - - return copy; -} - -auto ASTRewriter::CoreDeclaratorVisitor::operator()(BitfieldDeclaratorAST* ast) - -> CoreDeclaratorAST* { - auto copy = make_node(arena()); - - copy->unqualifiedId = ast_cast(rewrite(ast->unqualifiedId)); - copy->colonLoc = ast->colonLoc; - copy->sizeExpression = rewrite(ast->sizeExpression); - - return copy; -} - -auto ASTRewriter::CoreDeclaratorVisitor::operator()(ParameterPackAST* ast) - -> CoreDeclaratorAST* { - auto copy = make_node(arena()); - - copy->ellipsisLoc = ast->ellipsisLoc; - copy->coreDeclarator = rewrite(ast->coreDeclarator); - - return copy; -} - -auto ASTRewriter::CoreDeclaratorVisitor::operator()(IdDeclaratorAST* ast) - -> CoreDeclaratorAST* { - auto copy = make_node(arena()); - - copy->nestedNameSpecifier = rewrite(ast->nestedNameSpecifier); - copy->templateLoc = ast->templateLoc; - copy->unqualifiedId = rewrite(ast->unqualifiedId); - - for (auto attributeList = ©->attributeList; - auto node : ListView{ast->attributeList}) { - auto value = rewrite(node); - *attributeList = make_list_node(arena(), value); - attributeList = &(*attributeList)->next; - } - - copy->isTemplateIntroduced = ast->isTemplateIntroduced; - - return copy; -} - -auto ASTRewriter::CoreDeclaratorVisitor::operator()(NestedDeclaratorAST* ast) - -> CoreDeclaratorAST* { - auto copy = make_node(arena()); - - copy->lparenLoc = ast->lparenLoc; - copy->declarator = rewrite(ast->declarator); - copy->rparenLoc = ast->rparenLoc; - - return copy; -} - -auto ASTRewriter::DeclaratorChunkVisitor::operator()( - FunctionDeclaratorChunkAST* ast) -> DeclaratorChunkAST* { - auto copy = make_node(arena()); - - copy->lparenLoc = ast->lparenLoc; - copy->parameterDeclarationClause = rewrite(ast->parameterDeclarationClause); - copy->rparenLoc = ast->rparenLoc; - - auto _ = Binder::ScopeGuard{binder()}; - - if (copy->parameterDeclarationClause) { - binder()->setScope( - copy->parameterDeclarationClause->functionParametersSymbol); - } - - auto cvQualifierListCtx = DeclSpecs{rewriter()}; - for (auto cvQualifierList = ©->cvQualifierList; - auto node : ListView{ast->cvQualifierList}) { - auto value = rewrite(node); - *cvQualifierList = make_list_node(arena(), value); - cvQualifierList = &(*cvQualifierList)->next; - cvQualifierListCtx.accept(value); - } - - copy->refLoc = ast->refLoc; - copy->exceptionSpecifier = rewrite(ast->exceptionSpecifier); - - for (auto attributeList = ©->attributeList; - auto node : ListView{ast->attributeList}) { - auto value = rewrite(node); - *attributeList = make_list_node(arena(), value); - attributeList = &(*attributeList)->next; - } - - copy->trailingReturnType = rewrite(ast->trailingReturnType); - copy->isFinal = ast->isFinal; - copy->isOverride = ast->isOverride; - copy->isPure = ast->isPure; - - return copy; -} - -auto ASTRewriter::DeclaratorChunkVisitor::operator()( - ArrayDeclaratorChunkAST* ast) -> DeclaratorChunkAST* { - auto copy = make_node(arena()); - - copy->lbracketLoc = ast->lbracketLoc; - - auto typeQualifierListCtx = DeclSpecs{rewriter()}; - for (auto typeQualifierList = ©->typeQualifierList; - auto node : ListView{ast->typeQualifierList}) { - auto value = rewrite(node); - *typeQualifierList = make_list_node(arena(), value); - typeQualifierList = &(*typeQualifierList)->next; - typeQualifierListCtx.accept(value); - } - - copy->expression = rewrite(ast->expression); - copy->rbracketLoc = ast->rbracketLoc; - - for (auto attributeList = ©->attributeList; - auto node : ListView{ast->attributeList}) { - auto value = rewrite(node); - *attributeList = make_list_node(arena(), value); - attributeList = &(*attributeList)->next; - } - - return copy; -} - -auto ASTRewriter::UnqualifiedIdVisitor::operator()(NameIdAST* ast) - -> UnqualifiedIdAST* { - auto copy = make_node(arena()); - - copy->identifierLoc = ast->identifierLoc; - copy->identifier = ast->identifier; - - return copy; -} - -auto ASTRewriter::UnqualifiedIdVisitor::operator()(DestructorIdAST* ast) - -> UnqualifiedIdAST* { - auto copy = make_node(arena()); - - copy->tildeLoc = ast->tildeLoc; - copy->id = rewrite(ast->id); - - return copy; -} - -auto ASTRewriter::UnqualifiedIdVisitor::operator()(DecltypeIdAST* ast) - -> UnqualifiedIdAST* { - auto copy = make_node(arena()); - - copy->decltypeSpecifier = - ast_cast(rewrite(ast->decltypeSpecifier)); - - return copy; -} - -auto ASTRewriter::UnqualifiedIdVisitor::operator()(OperatorFunctionIdAST* ast) - -> UnqualifiedIdAST* { - auto copy = make_node(arena()); - - copy->operatorLoc = ast->operatorLoc; - copy->opLoc = ast->opLoc; - copy->openLoc = ast->openLoc; - copy->closeLoc = ast->closeLoc; - copy->op = ast->op; - - return copy; -} - -auto ASTRewriter::UnqualifiedIdVisitor::operator()(LiteralOperatorIdAST* ast) - -> UnqualifiedIdAST* { - auto copy = make_node(arena()); - - copy->operatorLoc = ast->operatorLoc; - copy->literalLoc = ast->literalLoc; - copy->identifierLoc = ast->identifierLoc; - copy->literal = ast->literal; - copy->identifier = ast->identifier; - - return copy; -} - -auto ASTRewriter::UnqualifiedIdVisitor::operator()(ConversionFunctionIdAST* ast) - -> UnqualifiedIdAST* { - auto copy = make_node(arena()); - - copy->operatorLoc = ast->operatorLoc; - copy->typeId = rewrite(ast->typeId); - - return copy; -} - -auto ASTRewriter::UnqualifiedIdVisitor::operator()(SimpleTemplateIdAST* ast) - -> UnqualifiedIdAST* { - auto copy = make_node(arena()); - - copy->identifierLoc = ast->identifierLoc; - copy->lessLoc = ast->lessLoc; - - for (auto templateArgumentList = ©->templateArgumentList; - auto node : ListView{ast->templateArgumentList}) { - auto value = rewrite(node); - *templateArgumentList = make_list_node(arena(), value); - templateArgumentList = &(*templateArgumentList)->next; - } - - copy->greaterLoc = ast->greaterLoc; - copy->identifier = ast->identifier; - copy->primaryTemplateSymbol = ast->primaryTemplateSymbol; - - return copy; -} - -auto ASTRewriter::UnqualifiedIdVisitor::operator()( - LiteralOperatorTemplateIdAST* ast) -> UnqualifiedIdAST* { - auto copy = make_node(arena()); - - copy->literalOperatorId = - ast_cast(rewrite(ast->literalOperatorId)); - copy->lessLoc = ast->lessLoc; - - for (auto templateArgumentList = ©->templateArgumentList; - auto node : ListView{ast->templateArgumentList}) { - auto value = rewrite(node); - *templateArgumentList = make_list_node(arena(), value); - templateArgumentList = &(*templateArgumentList)->next; - } - - copy->greaterLoc = ast->greaterLoc; - - return copy; -} - -auto ASTRewriter::UnqualifiedIdVisitor::operator()( - OperatorFunctionTemplateIdAST* ast) -> UnqualifiedIdAST* { - auto copy = make_node(arena()); - - copy->operatorFunctionId = - ast_cast(rewrite(ast->operatorFunctionId)); - copy->lessLoc = ast->lessLoc; - - for (auto templateArgumentList = ©->templateArgumentList; - auto node : ListView{ast->templateArgumentList}) { - auto value = rewrite(node); - *templateArgumentList = make_list_node(arena(), value); - templateArgumentList = &(*templateArgumentList)->next; - } - - copy->greaterLoc = ast->greaterLoc; - - return copy; -} - -auto ASTRewriter::NestedNameSpecifierVisitor::operator()( - GlobalNestedNameSpecifierAST* ast) -> NestedNameSpecifierAST* { - auto copy = make_node(arena()); - - copy->symbol = ast->symbol; - copy->scopeLoc = ast->scopeLoc; - - return copy; -} - -auto ASTRewriter::NestedNameSpecifierVisitor::operator()( - SimpleNestedNameSpecifierAST* ast) -> NestedNameSpecifierAST* { - auto copy = make_node(arena()); - - copy->symbol = ast->symbol; - copy->nestedNameSpecifier = rewrite(ast->nestedNameSpecifier); - copy->identifierLoc = ast->identifierLoc; - copy->identifier = ast->identifier; - copy->scopeLoc = ast->scopeLoc; - - return copy; -} - -auto ASTRewriter::NestedNameSpecifierVisitor::operator()( - DecltypeNestedNameSpecifierAST* ast) -> NestedNameSpecifierAST* { - auto copy = make_node(arena()); - - copy->symbol = ast->symbol; - copy->decltypeSpecifier = - ast_cast(rewrite(ast->decltypeSpecifier)); - copy->scopeLoc = ast->scopeLoc; - - return copy; -} - -auto ASTRewriter::NestedNameSpecifierVisitor::operator()( - TemplateNestedNameSpecifierAST* ast) -> NestedNameSpecifierAST* { - auto copy = make_node(arena()); - - copy->symbol = ast->symbol; - copy->nestedNameSpecifier = rewrite(ast->nestedNameSpecifier); - copy->templateLoc = ast->templateLoc; - copy->templateId = ast_cast(rewrite(ast->templateId)); - copy->scopeLoc = ast->scopeLoc; - copy->isTemplateIntroduced = ast->isTemplateIntroduced; - - return copy; -} - -auto ASTRewriter::FunctionBodyVisitor::operator()(DefaultFunctionBodyAST* ast) - -> FunctionBodyAST* { - auto copy = make_node(arena()); - - copy->equalLoc = ast->equalLoc; - copy->defaultLoc = ast->defaultLoc; - copy->semicolonLoc = ast->semicolonLoc; - - return copy; -} - -auto ASTRewriter::FunctionBodyVisitor::operator()( - CompoundStatementFunctionBodyAST* ast) -> FunctionBodyAST* { - auto copy = make_node(arena()); - - copy->colonLoc = ast->colonLoc; - - for (auto memInitializerList = ©->memInitializerList; - auto node : ListView{ast->memInitializerList}) { - auto value = rewrite(node); - *memInitializerList = make_list_node(arena(), value); - memInitializerList = &(*memInitializerList)->next; - } - - copy->statement = ast_cast(rewrite(ast->statement)); - - return copy; -} - -auto ASTRewriter::FunctionBodyVisitor::operator()( - TryStatementFunctionBodyAST* ast) -> FunctionBodyAST* { - auto copy = make_node(arena()); - - copy->tryLoc = ast->tryLoc; - copy->colonLoc = ast->colonLoc; - - for (auto memInitializerList = ©->memInitializerList; - auto node : ListView{ast->memInitializerList}) { - auto value = rewrite(node); - *memInitializerList = make_list_node(arena(), value); - memInitializerList = &(*memInitializerList)->next; - } - - copy->statement = ast_cast(rewrite(ast->statement)); - - for (auto handlerList = ©->handlerList; - auto node : ListView{ast->handlerList}) { - auto value = rewrite(node); - *handlerList = make_list_node(arena(), value); - handlerList = &(*handlerList)->next; - } - - return copy; -} - -auto ASTRewriter::FunctionBodyVisitor::operator()(DeleteFunctionBodyAST* ast) - -> FunctionBodyAST* { - auto copy = make_node(arena()); - - copy->equalLoc = ast->equalLoc; - copy->deleteLoc = ast->deleteLoc; - copy->semicolonLoc = ast->semicolonLoc; - - return copy; -} - -auto ASTRewriter::TemplateArgumentVisitor::operator()( - TypeTemplateArgumentAST* ast) -> TemplateArgumentAST* { - auto copy = make_node(arena()); - - copy->typeId = rewrite(ast->typeId); - - return copy; -} - -auto ASTRewriter::TemplateArgumentVisitor::operator()( - ExpressionTemplateArgumentAST* ast) -> TemplateArgumentAST* { - auto copy = make_node(arena()); - - copy->expression = rewrite(ast->expression); - - return copy; -} - -auto ASTRewriter::ExceptionSpecifierVisitor::operator()( - ThrowExceptionSpecifierAST* ast) -> ExceptionSpecifierAST* { - auto copy = make_node(arena()); - - copy->throwLoc = ast->throwLoc; - copy->lparenLoc = ast->lparenLoc; - copy->rparenLoc = ast->rparenLoc; - - return copy; -} - -auto ASTRewriter::ExceptionSpecifierVisitor::operator()( - NoexceptSpecifierAST* ast) -> ExceptionSpecifierAST* { - auto copy = make_node(arena()); - - copy->noexceptLoc = ast->noexceptLoc; - copy->lparenLoc = ast->lparenLoc; - copy->expression = rewrite(ast->expression); - copy->rparenLoc = ast->rparenLoc; - - return copy; -} - -auto ASTRewriter::RequirementVisitor::operator()(SimpleRequirementAST* ast) - -> RequirementAST* { - auto copy = make_node(arena()); - - copy->expression = rewrite(ast->expression); - copy->semicolonLoc = ast->semicolonLoc; - - return copy; -} - -auto ASTRewriter::RequirementVisitor::operator()(CompoundRequirementAST* ast) - -> RequirementAST* { - auto copy = make_node(arena()); - - copy->lbraceLoc = ast->lbraceLoc; - copy->expression = rewrite(ast->expression); - copy->rbraceLoc = ast->rbraceLoc; - copy->noexceptLoc = ast->noexceptLoc; - copy->minusGreaterLoc = ast->minusGreaterLoc; - copy->typeConstraint = rewrite(ast->typeConstraint); - copy->semicolonLoc = ast->semicolonLoc; - - return copy; -} - -auto ASTRewriter::RequirementVisitor::operator()(TypeRequirementAST* ast) - -> RequirementAST* { - auto copy = make_node(arena()); - - copy->typenameLoc = ast->typenameLoc; - copy->nestedNameSpecifier = rewrite(ast->nestedNameSpecifier); - copy->templateLoc = ast->templateLoc; - copy->unqualifiedId = rewrite(ast->unqualifiedId); - copy->semicolonLoc = ast->semicolonLoc; - copy->isTemplateIntroduced = ast->isTemplateIntroduced; - - return copy; -} - -auto ASTRewriter::RequirementVisitor::operator()(NestedRequirementAST* ast) - -> RequirementAST* { - auto copy = make_node(arena()); - - copy->requiresLoc = ast->requiresLoc; - copy->expression = rewrite(ast->expression); - copy->semicolonLoc = ast->semicolonLoc; - - return copy; -} - -auto ASTRewriter::NewInitializerVisitor::operator()(NewParenInitializerAST* ast) - -> NewInitializerAST* { - auto copy = make_node(arena()); - - copy->lparenLoc = ast->lparenLoc; - - for (auto expressionList = ©->expressionList; - auto node : ListView{ast->expressionList}) { - auto value = rewrite(node); - *expressionList = make_list_node(arena(), value); - expressionList = &(*expressionList)->next; - } - - copy->rparenLoc = ast->rparenLoc; - - return copy; -} - -auto ASTRewriter::NewInitializerVisitor::operator()( - NewBracedInitializerAST* ast) -> NewInitializerAST* { - auto copy = make_node(arena()); - - copy->bracedInitList = - ast_cast(rewrite(ast->bracedInitList)); - - return copy; -} - -auto ASTRewriter::MemInitializerVisitor::operator()(ParenMemInitializerAST* ast) - -> MemInitializerAST* { - auto copy = make_node(arena()); - - copy->nestedNameSpecifier = rewrite(ast->nestedNameSpecifier); - copy->unqualifiedId = rewrite(ast->unqualifiedId); - copy->lparenLoc = ast->lparenLoc; - - for (auto expressionList = ©->expressionList; - auto node : ListView{ast->expressionList}) { - auto value = rewrite(node); - *expressionList = make_list_node(arena(), value); - expressionList = &(*expressionList)->next; - } - - copy->rparenLoc = ast->rparenLoc; - copy->ellipsisLoc = ast->ellipsisLoc; - - return copy; -} - -auto ASTRewriter::MemInitializerVisitor::operator()( - BracedMemInitializerAST* ast) -> MemInitializerAST* { - auto copy = make_node(arena()); - - copy->nestedNameSpecifier = rewrite(ast->nestedNameSpecifier); - copy->unqualifiedId = rewrite(ast->unqualifiedId); - copy->bracedInitList = - ast_cast(rewrite(ast->bracedInitList)); - copy->ellipsisLoc = ast->ellipsisLoc; - - return copy; -} - -auto ASTRewriter::LambdaCaptureVisitor::operator()(ThisLambdaCaptureAST* ast) - -> LambdaCaptureAST* { - auto copy = make_node(arena()); - - copy->thisLoc = ast->thisLoc; - - return copy; -} - -auto ASTRewriter::LambdaCaptureVisitor::operator()( - DerefThisLambdaCaptureAST* ast) -> LambdaCaptureAST* { - auto copy = make_node(arena()); - - copy->starLoc = ast->starLoc; - copy->thisLoc = ast->thisLoc; - - return copy; -} - -auto ASTRewriter::LambdaCaptureVisitor::operator()(SimpleLambdaCaptureAST* ast) - -> LambdaCaptureAST* { - auto copy = make_node(arena()); - - copy->identifierLoc = ast->identifierLoc; - copy->ellipsisLoc = ast->ellipsisLoc; - copy->identifier = ast->identifier; - - return copy; -} - -auto ASTRewriter::LambdaCaptureVisitor::operator()(RefLambdaCaptureAST* ast) - -> LambdaCaptureAST* { - auto copy = make_node(arena()); - - copy->ampLoc = ast->ampLoc; - copy->identifierLoc = ast->identifierLoc; - copy->ellipsisLoc = ast->ellipsisLoc; - copy->identifier = ast->identifier; - - return copy; -} - -auto ASTRewriter::LambdaCaptureVisitor::operator()(RefInitLambdaCaptureAST* ast) - -> LambdaCaptureAST* { - auto copy = make_node(arena()); - - copy->ampLoc = ast->ampLoc; - copy->ellipsisLoc = ast->ellipsisLoc; - copy->identifierLoc = ast->identifierLoc; - copy->initializer = rewrite(ast->initializer); - copy->identifier = ast->identifier; - - return copy; -} - -auto ASTRewriter::LambdaCaptureVisitor::operator()(InitLambdaCaptureAST* ast) - -> LambdaCaptureAST* { - auto copy = make_node(arena()); - - copy->ellipsisLoc = ast->ellipsisLoc; - copy->identifierLoc = ast->identifierLoc; - copy->initializer = rewrite(ast->initializer); - copy->identifier = ast->identifier; - - return copy; -} - -auto ASTRewriter::ExceptionDeclarationVisitor::operator()( - EllipsisExceptionDeclarationAST* ast) -> ExceptionDeclarationAST* { - auto copy = make_node(arena()); - - copy->ellipsisLoc = ast->ellipsisLoc; - - return copy; -} - -auto ASTRewriter::ExceptionDeclarationVisitor::operator()( - TypeExceptionDeclarationAST* ast) -> ExceptionDeclarationAST* { - auto copy = make_node(arena()); - - for (auto attributeList = ©->attributeList; - auto node : ListView{ast->attributeList}) { - auto value = rewrite(node); - *attributeList = make_list_node(arena(), value); - attributeList = &(*attributeList)->next; - } - - auto typeSpecifierListCtx = DeclSpecs{rewriter()}; - for (auto typeSpecifierList = ©->typeSpecifierList; - auto node : ListView{ast->typeSpecifierList}) { - auto value = rewrite(node); - *typeSpecifierList = make_list_node(arena(), value); - typeSpecifierList = &(*typeSpecifierList)->next; - typeSpecifierListCtx.accept(value); - } - typeSpecifierListCtx.finish(); - - copy->declarator = rewrite(ast->declarator); - - auto declaratorDecl = Decl{typeSpecifierListCtx, copy->declarator}; - auto declaratorType = getDeclaratorType(translationUnit(), copy->declarator, - typeSpecifierListCtx.type()); - - return copy; -} - -auto ASTRewriter::AttributeSpecifierVisitor::operator()(CxxAttributeAST* ast) - -> AttributeSpecifierAST* { - auto copy = make_node(arena()); - - copy->lbracketLoc = ast->lbracketLoc; - copy->lbracket2Loc = ast->lbracket2Loc; - copy->attributeUsingPrefix = rewrite(ast->attributeUsingPrefix); - - for (auto attributeList = ©->attributeList; - auto node : ListView{ast->attributeList}) { - auto value = rewrite(node); - *attributeList = make_list_node(arena(), value); - attributeList = &(*attributeList)->next; - } - - copy->rbracketLoc = ast->rbracketLoc; - copy->rbracket2Loc = ast->rbracket2Loc; - - return copy; -} - -auto ASTRewriter::AttributeSpecifierVisitor::operator()(GccAttributeAST* ast) - -> AttributeSpecifierAST* { - auto copy = make_node(arena()); - - copy->attributeLoc = ast->attributeLoc; - copy->lparenLoc = ast->lparenLoc; - copy->lparen2Loc = ast->lparen2Loc; - copy->rparenLoc = ast->rparenLoc; - copy->rparen2Loc = ast->rparen2Loc; - - return copy; -} - -auto ASTRewriter::AttributeSpecifierVisitor::operator()( - AlignasAttributeAST* ast) -> AttributeSpecifierAST* { - auto copy = make_node(arena()); - - copy->alignasLoc = ast->alignasLoc; - copy->lparenLoc = ast->lparenLoc; - copy->expression = rewrite(ast->expression); - copy->ellipsisLoc = ast->ellipsisLoc; - copy->rparenLoc = ast->rparenLoc; - copy->isPack = ast->isPack; - - return copy; -} - -auto ASTRewriter::AttributeSpecifierVisitor::operator()( - AlignasTypeAttributeAST* ast) -> AttributeSpecifierAST* { - auto copy = make_node(arena()); - - copy->alignasLoc = ast->alignasLoc; - copy->lparenLoc = ast->lparenLoc; - copy->typeId = rewrite(ast->typeId); - copy->ellipsisLoc = ast->ellipsisLoc; - copy->rparenLoc = ast->rparenLoc; - copy->isPack = ast->isPack; - - return copy; -} - -auto ASTRewriter::AttributeSpecifierVisitor::operator()(AsmAttributeAST* ast) - -> AttributeSpecifierAST* { - auto copy = make_node(arena()); - - copy->asmLoc = ast->asmLoc; - copy->lparenLoc = ast->lparenLoc; - copy->literalLoc = ast->literalLoc; - copy->rparenLoc = ast->rparenLoc; - copy->literal = ast->literal; - - return copy; -} - -auto ASTRewriter::AttributeTokenVisitor::operator()( - ScopedAttributeTokenAST* ast) -> AttributeTokenAST* { - auto copy = make_node(arena()); - - copy->attributeNamespaceLoc = ast->attributeNamespaceLoc; - copy->scopeLoc = ast->scopeLoc; - copy->identifierLoc = ast->identifierLoc; - copy->attributeNamespace = ast->attributeNamespace; - copy->identifier = ast->identifier; - - return copy; -} + rewriter.binder().setInstantiatingSymbol(typeAliasSymbol); -auto ASTRewriter::AttributeTokenVisitor::operator()( - SimpleAttributeTokenAST* ast) -> AttributeTokenAST* { - auto copy = make_node(arena()); + auto instance = + ast_cast(rewriter.declaration(aliasDeclaration)); - copy->identifierLoc = ast->identifierLoc; - copy->identifier = ast->identifier; + if (!instance) return nullptr; - return copy; + return instance->symbol; } } // namespace cxx diff --git a/src/parser/cxx/ast_rewriter.h b/src/parser/cxx/ast_rewriter.h index 1c531b10..d9cd38bf 100644 --- a/src/parser/cxx/ast_rewriter.h +++ b/src/parser/cxx/ast_rewriter.h @@ -29,13 +29,25 @@ namespace cxx { class TranslationUnit; -class TypeChecker; class Control; class Arena; class ASTRewriter { public: - explicit ASTRewriter(TypeChecker* typeChecker, + [[nodiscard]] static auto instantiateClassTemplate( + TranslationUnit* unit, List* templateArgumentList, + ClassSymbol* symbol) -> ClassSymbol*; + + [[nodiscard]] static auto instantiateTypeAliasTemplate( + TranslationUnit* unit, List* templateArgumentList, + TypeAliasSymbol* typeAliasSymbol) -> TypeAliasSymbol*; + + [[nodiscard]] static auto make_substitution( + TranslationUnit* unit, TemplateDeclarationAST* templateDecl, + List* templateArgumentList) + -> std::vector; + + explicit ASTRewriter(TranslationUnit* unit, Scope* scope, const std::vector& templateArguments); ~ASTRewriter(); @@ -43,13 +55,18 @@ class ASTRewriter { return unit_; } - [[nodiscard]] const std::vector& templateArguments() const { + [[nodiscard]] auto declaration(DeclarationAST* ast) -> DeclarationAST*; + + private: + [[nodiscard]] auto templateArguments() const + -> const std::vector& { return templateArguments_; } - [[nodiscard]] auto typeChecker() const -> TypeChecker* { - return typeChecker_; - } + void error(SourceLocation loc, std::string message); + void warning(SourceLocation loc, std::string message); + + void check(ExpressionAST* ast); [[nodiscard]] auto binder() -> Binder& { return binder_; } @@ -60,77 +77,87 @@ class ASTRewriter { void setRestrictedToDeclarations(bool restrictedToDeclarations); // run on the base nodes - [[nodiscard]] auto operator()(UnitAST* ast) -> UnitAST*; - [[nodiscard]] auto operator()(DeclarationAST* ast) -> DeclarationAST*; - [[nodiscard]] auto operator()(StatementAST* ast) -> StatementAST*; - [[nodiscard]] auto operator()(ExpressionAST* ast) -> ExpressionAST*; - [[nodiscard]] auto operator()(GenericAssociationAST* ast) + [[nodiscard]] auto unit(UnitAST* ast) -> UnitAST*; + [[nodiscard]] auto statement(StatementAST* ast) -> StatementAST*; + [[nodiscard]] auto expression(ExpressionAST* ast) -> ExpressionAST*; + [[nodiscard]] auto genericAssociation(GenericAssociationAST* ast) -> GenericAssociationAST*; - [[nodiscard]] auto operator()(DesignatorAST* ast) -> DesignatorAST*; - [[nodiscard]] auto operator()(TemplateParameterAST* ast) + [[nodiscard]] auto designator(DesignatorAST* ast) -> DesignatorAST*; + [[nodiscard]] auto templateParameter(TemplateParameterAST* ast) -> TemplateParameterAST*; - [[nodiscard]] auto operator()(SpecifierAST* ast) -> SpecifierAST*; - [[nodiscard]] auto operator()(PtrOperatorAST* ast) -> PtrOperatorAST*; - [[nodiscard]] auto operator()(CoreDeclaratorAST* ast) -> CoreDeclaratorAST*; - [[nodiscard]] auto operator()(DeclaratorChunkAST* ast) -> DeclaratorChunkAST*; - [[nodiscard]] auto operator()(UnqualifiedIdAST* ast) -> UnqualifiedIdAST*; - [[nodiscard]] auto operator()(NestedNameSpecifierAST* ast) + [[nodiscard]] auto specifier(SpecifierAST* ast) -> SpecifierAST*; + [[nodiscard]] auto ptrOperator(PtrOperatorAST* ast) -> PtrOperatorAST*; + [[nodiscard]] auto coreDeclarator(CoreDeclaratorAST* ast) + -> CoreDeclaratorAST*; + [[nodiscard]] auto declaratorChunk(DeclaratorChunkAST* ast) + -> DeclaratorChunkAST*; + [[nodiscard]] auto unqualifiedId(UnqualifiedIdAST* ast) -> UnqualifiedIdAST*; + [[nodiscard]] auto nestedNameSpecifier(NestedNameSpecifierAST* ast) -> NestedNameSpecifierAST*; - [[nodiscard]] auto operator()(FunctionBodyAST* ast) -> FunctionBodyAST*; - [[nodiscard]] auto operator()(TemplateArgumentAST* ast) + [[nodiscard]] auto functionBody(FunctionBodyAST* ast) -> FunctionBodyAST*; + [[nodiscard]] auto templateArgument(TemplateArgumentAST* ast) -> TemplateArgumentAST*; - [[nodiscard]] auto operator()(ExceptionSpecifierAST* ast) + [[nodiscard]] auto exceptionSpecifier(ExceptionSpecifierAST* ast) -> ExceptionSpecifierAST*; - [[nodiscard]] auto operator()(RequirementAST* ast) -> RequirementAST*; - [[nodiscard]] auto operator()(NewInitializerAST* ast) -> NewInitializerAST*; - [[nodiscard]] auto operator()(MemInitializerAST* ast) -> MemInitializerAST*; - [[nodiscard]] auto operator()(LambdaCaptureAST* ast) -> LambdaCaptureAST*; - [[nodiscard]] auto operator()(ExceptionDeclarationAST* ast) + [[nodiscard]] auto requirement(RequirementAST* ast) -> RequirementAST*; + [[nodiscard]] auto newInitializer(NewInitializerAST* ast) + -> NewInitializerAST*; + [[nodiscard]] auto memInitializer(MemInitializerAST* ast) + -> MemInitializerAST*; + [[nodiscard]] auto lambdaCapture(LambdaCaptureAST* ast) -> LambdaCaptureAST*; + [[nodiscard]] auto exceptionDeclaration(ExceptionDeclarationAST* ast) -> ExceptionDeclarationAST*; - [[nodiscard]] auto operator()(AttributeSpecifierAST* ast) + [[nodiscard]] auto attributeSpecifier(AttributeSpecifierAST* ast) -> AttributeSpecifierAST*; - [[nodiscard]] auto operator()(AttributeTokenAST* ast) -> AttributeTokenAST*; + [[nodiscard]] auto attributeToken(AttributeTokenAST* ast) + -> AttributeTokenAST*; // run on the misc nodes - [[nodiscard]] auto operator()(SplicerAST* ast) -> SplicerAST*; - [[nodiscard]] auto operator()(GlobalModuleFragmentAST* ast) + [[nodiscard]] auto splicer(SplicerAST* ast) -> SplicerAST*; + [[nodiscard]] auto globalModuleFragment(GlobalModuleFragmentAST* ast) -> GlobalModuleFragmentAST*; - [[nodiscard]] auto operator()(PrivateModuleFragmentAST* ast) + [[nodiscard]] auto privateModuleFragment(PrivateModuleFragmentAST* ast) -> PrivateModuleFragmentAST*; - [[nodiscard]] auto operator()(ModuleDeclarationAST* ast) + [[nodiscard]] auto moduleDeclaration(ModuleDeclarationAST* ast) -> ModuleDeclarationAST*; - [[nodiscard]] auto operator()(ModuleNameAST* ast) -> ModuleNameAST*; - [[nodiscard]] auto operator()(ModuleQualifierAST* ast) -> ModuleQualifierAST*; - [[nodiscard]] auto operator()(ModulePartitionAST* ast) -> ModulePartitionAST*; - [[nodiscard]] auto operator()(ImportNameAST* ast) -> ImportNameAST*; - [[nodiscard]] auto operator()(InitDeclaratorAST* ast, - const DeclSpecs& declSpecs) + [[nodiscard]] auto moduleName(ModuleNameAST* ast) -> ModuleNameAST*; + [[nodiscard]] auto moduleQualifier(ModuleQualifierAST* ast) + -> ModuleQualifierAST*; + [[nodiscard]] auto modulePartition(ModulePartitionAST* ast) + -> ModulePartitionAST*; + [[nodiscard]] auto importName(ImportNameAST* ast) -> ImportNameAST*; + [[nodiscard]] auto initDeclarator(InitDeclaratorAST* ast, + const DeclSpecs& declSpecs) -> InitDeclaratorAST*; - [[nodiscard]] auto operator()(DeclaratorAST* ast) -> DeclaratorAST*; - [[nodiscard]] auto operator()(UsingDeclaratorAST* ast) -> UsingDeclaratorAST*; - [[nodiscard]] auto operator()(EnumeratorAST* ast) -> EnumeratorAST*; - [[nodiscard]] auto operator()(TypeIdAST* ast) -> TypeIdAST*; - [[nodiscard]] auto operator()(HandlerAST* ast) -> HandlerAST*; - [[nodiscard]] auto operator()(BaseSpecifierAST* ast) -> BaseSpecifierAST*; - [[nodiscard]] auto operator()(RequiresClauseAST* ast) -> RequiresClauseAST*; - [[nodiscard]] auto operator()(ParameterDeclarationClauseAST* ast) - -> ParameterDeclarationClauseAST*; - [[nodiscard]] auto operator()(TrailingReturnTypeAST* ast) + [[nodiscard]] auto declarator(DeclaratorAST* ast) -> DeclaratorAST*; + [[nodiscard]] auto usingDeclarator(UsingDeclaratorAST* ast) + -> UsingDeclaratorAST*; + [[nodiscard]] auto enumerator(EnumeratorAST* ast) -> EnumeratorAST*; + [[nodiscard]] auto typeId(TypeIdAST* ast) -> TypeIdAST*; + [[nodiscard]] auto handler(HandlerAST* ast) -> HandlerAST*; + [[nodiscard]] auto baseSpecifier(BaseSpecifierAST* ast) -> BaseSpecifierAST*; + [[nodiscard]] auto requiresClause(RequiresClauseAST* ast) + -> RequiresClauseAST*; + [[nodiscard]] auto parameterDeclarationClause( + ParameterDeclarationClauseAST* ast) -> ParameterDeclarationClauseAST*; + [[nodiscard]] auto trailingReturnType(TrailingReturnTypeAST* ast) -> TrailingReturnTypeAST*; - [[nodiscard]] auto operator()(LambdaSpecifierAST* ast) -> LambdaSpecifierAST*; - [[nodiscard]] auto operator()(TypeConstraintAST* ast) -> TypeConstraintAST*; - [[nodiscard]] auto operator()(AttributeArgumentClauseAST* ast) + [[nodiscard]] auto lambdaSpecifier(LambdaSpecifierAST* ast) + -> LambdaSpecifierAST*; + [[nodiscard]] auto typeConstraint(TypeConstraintAST* ast) + -> TypeConstraintAST*; + [[nodiscard]] auto attributeArgumentClause(AttributeArgumentClauseAST* ast) -> AttributeArgumentClauseAST*; - [[nodiscard]] auto operator()(AttributeAST* ast) -> AttributeAST*; - [[nodiscard]] auto operator()(AttributeUsingPrefixAST* ast) + [[nodiscard]] auto attribute(AttributeAST* ast) -> AttributeAST*; + [[nodiscard]] auto attributeUsingPrefix(AttributeUsingPrefixAST* ast) -> AttributeUsingPrefixAST*; - [[nodiscard]] auto operator()(NewPlacementAST* ast) -> NewPlacementAST*; - [[nodiscard]] auto operator()(NestedNamespaceSpecifierAST* ast) + [[nodiscard]] auto newPlacement(NewPlacementAST* ast) -> NewPlacementAST*; + [[nodiscard]] auto nestedNamespaceSpecifier(NestedNamespaceSpecifierAST* ast) -> NestedNamespaceSpecifierAST*; - [[nodiscard]] auto operator()(AsmOperandAST* ast) -> AsmOperandAST*; - [[nodiscard]] auto operator()(AsmQualifierAST* ast) -> AsmQualifierAST*; - [[nodiscard]] auto operator()(AsmClobberAST* ast) -> AsmClobberAST*; - [[nodiscard]] auto operator()(AsmGotoLabelAST* ast) -> AsmGotoLabelAST*; + [[nodiscard]] auto asmOperand(AsmOperandAST* ast) -> AsmOperandAST*; + [[nodiscard]] auto asmQualifier(AsmQualifierAST* ast) -> AsmQualifierAST*; + [[nodiscard]] auto asmClobber(AsmClobberAST* ast) -> AsmClobberAST*; + [[nodiscard]] auto asmGotoLabel(AsmGotoLabelAST* ast) -> AsmGotoLabelAST*; private: struct UnitVisitor; @@ -163,8 +190,7 @@ class ASTRewriter { [[nodiscard]] auto getParameterPack(ExpressionAST* ast) -> ParameterPackSymbol*; - TypeChecker* typeChecker_ = nullptr; - const std::vector& templateArguments_; + std::vector templateArguments_; ParameterPackSymbol* parameterPack_ = nullptr; std::optional elementIndex_; TranslationUnit* unit_ = nullptr; diff --git a/src/parser/cxx/ast_rewriter_declarations.cc b/src/parser/cxx/ast_rewriter_declarations.cc new file mode 100644 index 00000000..7c157012 --- /dev/null +++ b/src/parser/cxx/ast_rewriter_declarations.cc @@ -0,0 +1,1045 @@ +// Copyright (c) 2025 Roberto Raggi +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#include + +// cxx +#include +#include +#include +#include +#include + +namespace cxx { + +struct ASTRewriter::DeclarationVisitor { + ASTRewriter& rewrite; + [[nodiscard]] auto translationUnit() const -> TranslationUnit* { + return rewrite.unit_; + } + + [[nodiscard]] auto control() const -> Control* { return rewrite.control(); } + [[nodiscard]] auto arena() const -> Arena* { return rewrite.arena(); } + [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } + [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } + + [[nodiscard]] auto operator()(SimpleDeclarationAST* ast) -> DeclarationAST*; + + [[nodiscard]] auto operator()(AsmDeclarationAST* ast) -> DeclarationAST*; + + [[nodiscard]] auto operator()(NamespaceAliasDefinitionAST* ast) + -> DeclarationAST*; + + [[nodiscard]] auto operator()(UsingDeclarationAST* ast) -> DeclarationAST*; + + [[nodiscard]] auto operator()(UsingEnumDeclarationAST* ast) + -> DeclarationAST*; + + [[nodiscard]] auto operator()(UsingDirectiveAST* ast) -> DeclarationAST*; + + [[nodiscard]] auto operator()(StaticAssertDeclarationAST* ast) + -> DeclarationAST*; + + [[nodiscard]] auto operator()(AliasDeclarationAST* ast) -> DeclarationAST*; + + [[nodiscard]] auto operator()(OpaqueEnumDeclarationAST* ast) + -> DeclarationAST*; + + [[nodiscard]] auto operator()(FunctionDefinitionAST* ast) -> DeclarationAST*; + + [[nodiscard]] auto operator()(TemplateDeclarationAST* ast) -> DeclarationAST*; + + [[nodiscard]] auto operator()(ConceptDefinitionAST* ast) -> DeclarationAST*; + + [[nodiscard]] auto operator()(DeductionGuideAST* ast) -> DeclarationAST*; + + [[nodiscard]] auto operator()(ExplicitInstantiationAST* ast) + -> DeclarationAST*; + + [[nodiscard]] auto operator()(ExportDeclarationAST* ast) -> DeclarationAST*; + + [[nodiscard]] auto operator()(ExportCompoundDeclarationAST* ast) + -> DeclarationAST*; + + [[nodiscard]] auto operator()(LinkageSpecificationAST* ast) + -> DeclarationAST*; + + [[nodiscard]] auto operator()(NamespaceDefinitionAST* ast) -> DeclarationAST*; + + [[nodiscard]] auto operator()(EmptyDeclarationAST* ast) -> DeclarationAST*; + + [[nodiscard]] auto operator()(AttributeDeclarationAST* ast) + -> DeclarationAST*; + + [[nodiscard]] auto operator()(ModuleImportDeclarationAST* ast) + -> DeclarationAST*; + + [[nodiscard]] auto operator()(ParameterDeclarationAST* ast) + -> DeclarationAST*; + + [[nodiscard]] auto operator()(AccessDeclarationAST* ast) -> DeclarationAST*; + + [[nodiscard]] auto operator()(ForRangeDeclarationAST* ast) -> DeclarationAST*; + + [[nodiscard]] auto operator()(StructuredBindingDeclarationAST* ast) + -> DeclarationAST*; +}; + +struct ASTRewriter::TemplateParameterVisitor { + ASTRewriter& rewrite; + [[nodiscard]] auto translationUnit() const -> TranslationUnit* { + return rewrite.unit_; + } + + [[nodiscard]] auto control() const -> Control* { return rewrite.control(); } + [[nodiscard]] auto arena() const -> Arena* { return rewrite.arena(); } + [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } + [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } + + [[nodiscard]] auto operator()(TemplateTypeParameterAST* ast) + -> TemplateParameterAST*; + + [[nodiscard]] auto operator()(NonTypeTemplateParameterAST* ast) + -> TemplateParameterAST*; + + [[nodiscard]] auto operator()(TypenameTypeParameterAST* ast) + -> TemplateParameterAST*; + + [[nodiscard]] auto operator()(ConstraintTypeParameterAST* ast) + -> TemplateParameterAST*; +}; + +struct ASTRewriter::FunctionBodyVisitor { + ASTRewriter& rewrite; + [[nodiscard]] auto translationUnit() const -> TranslationUnit* { + return rewrite.unit_; + } + + [[nodiscard]] auto control() const -> Control* { return rewrite.control(); } + [[nodiscard]] auto arena() const -> Arena* { return rewrite.arena(); } + [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } + [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } + + [[nodiscard]] auto operator()(DefaultFunctionBodyAST* ast) + -> FunctionBodyAST*; + + [[nodiscard]] auto operator()(CompoundStatementFunctionBodyAST* ast) + -> FunctionBodyAST*; + + [[nodiscard]] auto operator()(TryStatementFunctionBodyAST* ast) + -> FunctionBodyAST*; + + [[nodiscard]] auto operator()(DeleteFunctionBodyAST* ast) -> FunctionBodyAST*; +}; + +struct ASTRewriter::RequirementVisitor { + ASTRewriter& rewrite; + [[nodiscard]] auto translationUnit() const -> TranslationUnit* { + return rewrite.unit_; + } + + [[nodiscard]] auto control() const -> Control* { return rewrite.control(); } + [[nodiscard]] auto arena() const -> Arena* { return rewrite.arena(); } + [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } + [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } + + [[nodiscard]] auto operator()(SimpleRequirementAST* ast) -> RequirementAST*; + + [[nodiscard]] auto operator()(CompoundRequirementAST* ast) -> RequirementAST*; + + [[nodiscard]] auto operator()(TypeRequirementAST* ast) -> RequirementAST*; + + [[nodiscard]] auto operator()(NestedRequirementAST* ast) -> RequirementAST*; +}; + +auto ASTRewriter::declaration(DeclarationAST* ast) -> DeclarationAST* { + if (!ast) return {}; + return visit(DeclarationVisitor{*this}, ast); +} + +auto ASTRewriter::templateParameter(TemplateParameterAST* ast) + -> TemplateParameterAST* { + if (!ast) return {}; + return visit(TemplateParameterVisitor{*this}, ast); +} + +auto ASTRewriter::functionBody(FunctionBodyAST* ast) -> FunctionBodyAST* { + if (!ast) return {}; + return visit(FunctionBodyVisitor{*this}, ast); +} + +auto ASTRewriter::requirement(RequirementAST* ast) -> RequirementAST* { + if (!ast) return {}; + return visit(RequirementVisitor{*this}, ast); +} + +auto ASTRewriter::typeConstraint(TypeConstraintAST* ast) -> TypeConstraintAST* { + if (!ast) return {}; + + auto copy = make_node(arena()); + + copy->nestedNameSpecifier = nestedNameSpecifier(ast->nestedNameSpecifier); + copy->identifierLoc = ast->identifierLoc; + copy->lessLoc = ast->lessLoc; + + for (auto templateArgumentList = ©->templateArgumentList; + auto node : ListView{ast->templateArgumentList}) { + auto value = templateArgument(node); + *templateArgumentList = make_list_node(arena(), value); + templateArgumentList = &(*templateArgumentList)->next; + } + + copy->greaterLoc = ast->greaterLoc; + copy->identifier = ast->identifier; + + return copy; +} + +auto ASTRewriter::nestedNamespaceSpecifier(NestedNamespaceSpecifierAST* ast) + -> NestedNamespaceSpecifierAST* { + if (!ast) return {}; + + auto copy = make_node(arena()); + + copy->inlineLoc = ast->inlineLoc; + copy->identifierLoc = ast->identifierLoc; + copy->scopeLoc = ast->scopeLoc; + copy->identifier = ast->identifier; + copy->isInline = ast->isInline; + + return copy; +} + +auto ASTRewriter::usingDeclarator(UsingDeclaratorAST* ast) + -> UsingDeclaratorAST* { + if (!ast) return {}; + + auto copy = make_node(arena()); + + copy->typenameLoc = ast->typenameLoc; + copy->nestedNameSpecifier = nestedNameSpecifier(ast->nestedNameSpecifier); + copy->unqualifiedId = unqualifiedId(ast->unqualifiedId); + copy->ellipsisLoc = ast->ellipsisLoc; + copy->symbol = ast->symbol; + copy->isPack = ast->isPack; + + return copy; +} + +auto ASTRewriter::DeclarationVisitor::operator()(SimpleDeclarationAST* ast) + -> DeclarationAST* { + auto copy = make_node(arena()); + + for (auto attributeList = ©->attributeList; + auto node : ListView{ast->attributeList}) { + auto value = rewrite.attributeSpecifier(node); + *attributeList = make_list_node(arena(), value); + attributeList = &(*attributeList)->next; + } + + auto declSpecifierListCtx = DeclSpecs{rewriter()}; + for (auto declSpecifierList = ©->declSpecifierList; + auto node : ListView{ast->declSpecifierList}) { + auto value = rewrite.specifier(node); + *declSpecifierList = make_list_node(arena(), value); + declSpecifierList = &(*declSpecifierList)->next; + declSpecifierListCtx.accept(value); + } + declSpecifierListCtx.finish(); + + for (auto initDeclaratorList = ©->initDeclaratorList; + auto node : ListView{ast->initDeclaratorList}) { + auto value = rewrite.initDeclarator(node, declSpecifierListCtx); + *initDeclaratorList = make_list_node(arena(), value); + initDeclaratorList = &(*initDeclaratorList)->next; + } + + copy->requiresClause = rewrite.requiresClause(ast->requiresClause); + copy->semicolonLoc = ast->semicolonLoc; + + return copy; +} + +auto ASTRewriter::DeclarationVisitor::operator()(AsmDeclarationAST* ast) + -> DeclarationAST* { + auto copy = make_node(arena()); + + for (auto attributeList = ©->attributeList; + auto node : ListView{ast->attributeList}) { + auto value = rewrite.attributeSpecifier(node); + *attributeList = make_list_node(arena(), value); + attributeList = &(*attributeList)->next; + } + + for (auto asmQualifierList = ©->asmQualifierList; + auto node : ListView{ast->asmQualifierList}) { + auto value = rewrite.asmQualifier(node); + *asmQualifierList = + make_list_node(arena(), ast_cast(value)); + asmQualifierList = &(*asmQualifierList)->next; + } + + copy->asmLoc = ast->asmLoc; + copy->lparenLoc = ast->lparenLoc; + copy->literalLoc = ast->literalLoc; + + for (auto outputOperandList = ©->outputOperandList; + auto node : ListView{ast->outputOperandList}) { + auto value = rewrite.asmOperand(node); + *outputOperandList = + make_list_node(arena(), ast_cast(value)); + outputOperandList = &(*outputOperandList)->next; + } + + for (auto inputOperandList = ©->inputOperandList; + auto node : ListView{ast->inputOperandList}) { + auto value = rewrite.asmOperand(node); + *inputOperandList = make_list_node(arena(), ast_cast(value)); + inputOperandList = &(*inputOperandList)->next; + } + + for (auto clobberList = ©->clobberList; + auto node : ListView{ast->clobberList}) { + auto value = rewrite.asmClobber(node); + *clobberList = make_list_node(arena(), ast_cast(value)); + clobberList = &(*clobberList)->next; + } + + for (auto gotoLabelList = ©->gotoLabelList; + auto node : ListView{ast->gotoLabelList}) { + auto value = rewrite.asmGotoLabel(node); + *gotoLabelList = make_list_node(arena(), ast_cast(value)); + gotoLabelList = &(*gotoLabelList)->next; + } + + copy->rparenLoc = ast->rparenLoc; + copy->semicolonLoc = ast->semicolonLoc; + copy->literal = ast->literal; + + return copy; +} + +auto ASTRewriter::DeclarationVisitor::operator()( + NamespaceAliasDefinitionAST* ast) -> DeclarationAST* { + auto copy = make_node(arena()); + + copy->namespaceLoc = ast->namespaceLoc; + copy->identifierLoc = ast->identifierLoc; + copy->equalLoc = ast->equalLoc; + copy->nestedNameSpecifier = + rewrite.nestedNameSpecifier(ast->nestedNameSpecifier); + copy->unqualifiedId = + ast_cast(rewrite.unqualifiedId(ast->unqualifiedId)); + copy->semicolonLoc = ast->semicolonLoc; + copy->identifier = ast->identifier; + + return copy; +} + +auto ASTRewriter::DeclarationVisitor::operator()(UsingDeclarationAST* ast) + -> DeclarationAST* { + auto copy = make_node(arena()); + + copy->usingLoc = ast->usingLoc; + + for (auto usingDeclaratorList = ©->usingDeclaratorList; + auto node : ListView{ast->usingDeclaratorList}) { + auto value = rewrite.usingDeclarator(node); + *usingDeclaratorList = make_list_node(arena(), value); + usingDeclaratorList = &(*usingDeclaratorList)->next; + } + + copy->semicolonLoc = ast->semicolonLoc; + + return copy; +} + +auto ASTRewriter::DeclarationVisitor::operator()(UsingEnumDeclarationAST* ast) + -> DeclarationAST* { + auto copy = make_node(arena()); + + copy->usingLoc = ast->usingLoc; + copy->enumTypeSpecifier = ast_cast( + rewrite.specifier(ast->enumTypeSpecifier)); + copy->semicolonLoc = ast->semicolonLoc; + + return copy; +} + +auto ASTRewriter::DeclarationVisitor::operator()(UsingDirectiveAST* ast) + -> DeclarationAST* { + auto copy = make_node(arena()); + + for (auto attributeList = ©->attributeList; + auto node : ListView{ast->attributeList}) { + auto value = rewrite.attributeSpecifier(node); + *attributeList = make_list_node(arena(), value); + attributeList = &(*attributeList)->next; + } + + copy->usingLoc = ast->usingLoc; + copy->namespaceLoc = ast->namespaceLoc; + copy->nestedNameSpecifier = + rewrite.nestedNameSpecifier(ast->nestedNameSpecifier); + copy->unqualifiedId = + ast_cast(rewrite.unqualifiedId(ast->unqualifiedId)); + copy->semicolonLoc = ast->semicolonLoc; + + return copy; +} + +auto ASTRewriter::DeclarationVisitor::operator()( + StaticAssertDeclarationAST* ast) -> DeclarationAST* { + auto copy = make_node(arena()); + + copy->staticAssertLoc = ast->staticAssertLoc; + copy->lparenLoc = ast->lparenLoc; + copy->expression = rewrite.expression(ast->expression); + copy->commaLoc = ast->commaLoc; + copy->literalLoc = ast->literalLoc; + copy->literal = ast->literal; + copy->rparenLoc = ast->rparenLoc; + copy->semicolonLoc = ast->semicolonLoc; + + return copy; +} + +auto ASTRewriter::DeclarationVisitor::operator()(AliasDeclarationAST* ast) + -> DeclarationAST* { + auto copy = make_node(arena()); + + copy->usingLoc = ast->usingLoc; + copy->identifierLoc = ast->identifierLoc; + + for (auto attributeList = ©->attributeList; + auto node : ListView{ast->attributeList}) { + auto value = rewrite.attributeSpecifier(node); + *attributeList = make_list_node(arena(), value); + attributeList = &(*attributeList)->next; + } + + copy->equalLoc = ast->equalLoc; + + for (auto gnuAttributeList = ©->gnuAttributeList; + auto node : ListView{ast->gnuAttributeList}) { + auto value = rewrite.attributeSpecifier(node); + *gnuAttributeList = make_list_node(arena(), value); + gnuAttributeList = &(*gnuAttributeList)->next; + } + + copy->typeId = rewrite.typeId(ast->typeId); + copy->semicolonLoc = ast->semicolonLoc; + copy->identifier = ast->identifier; + + const auto addSymbolToParentScope = + rewrite.binder().instantiatingSymbol() != ast->symbol; + + auto symbol = binder()->declareTypeAlias(copy->identifierLoc, copy->typeId, + addSymbolToParentScope); + // symbol->setTemplateDeclaration(templateHead); + + copy->symbol = symbol; + + return copy; +} + +auto ASTRewriter::DeclarationVisitor::operator()(OpaqueEnumDeclarationAST* ast) + -> DeclarationAST* { + auto copy = make_node(arena()); + + copy->enumLoc = ast->enumLoc; + copy->classLoc = ast->classLoc; + + for (auto attributeList = ©->attributeList; + auto node : ListView{ast->attributeList}) { + auto value = rewrite.attributeSpecifier(node); + *attributeList = make_list_node(arena(), value); + attributeList = &(*attributeList)->next; + } + + copy->nestedNameSpecifier = + rewrite.nestedNameSpecifier(ast->nestedNameSpecifier); + copy->unqualifiedId = + ast_cast(rewrite.unqualifiedId(ast->unqualifiedId)); + copy->colonLoc = ast->colonLoc; + + auto typeSpecifierListCtx = DeclSpecs{rewriter()}; + for (auto typeSpecifierList = ©->typeSpecifierList; + auto node : ListView{ast->typeSpecifierList}) { + auto value = rewrite.specifier(node); + *typeSpecifierList = make_list_node(arena(), value); + typeSpecifierList = &(*typeSpecifierList)->next; + typeSpecifierListCtx.accept(value); + } + typeSpecifierListCtx.finish(); + + copy->emicolonLoc = ast->emicolonLoc; + + return copy; +} + +auto ASTRewriter::DeclarationVisitor::operator()(FunctionDefinitionAST* ast) + -> DeclarationAST* { + auto copy = make_node(arena()); + + for (auto attributeList = ©->attributeList; + auto node : ListView{ast->attributeList}) { + auto value = rewrite.attributeSpecifier(node); + *attributeList = make_list_node(arena(), value); + attributeList = &(*attributeList)->next; + } + + auto declSpecifierListCtx = DeclSpecs{rewriter()}; + for (auto declSpecifierList = ©->declSpecifierList; + auto node : ListView{ast->declSpecifierList}) { + auto value = rewrite.specifier(node); + *declSpecifierList = make_list_node(arena(), value); + declSpecifierList = &(*declSpecifierList)->next; + declSpecifierListCtx.accept(value); + } + declSpecifierListCtx.finish(); + + copy->declarator = rewrite.declarator(ast->declarator); + + auto declaratorDecl = Decl{declSpecifierListCtx, copy->declarator}; + auto declaratorType = getDeclaratorType(translationUnit(), copy->declarator, + declSpecifierListCtx.type()); + + copy->requiresClause = rewrite.requiresClause(ast->requiresClause); + + auto functionSymbol = binder()->getFunction( + binder()->scope(), declaratorDecl.getName(), declaratorType); + + if (!functionSymbol) { + functionSymbol = + binder()->declareFunction(copy->declarator, declaratorDecl); + } + + auto _ = Binder::ScopeGuard{binder()}; + + binder()->setScope(functionSymbol); + + copy->symbol = functionSymbol; + copy->symbol->setDeclaration(copy); + copy->functionBody = rewrite.functionBody(ast->functionBody); + + return copy; +} + +auto ASTRewriter::DeclarationVisitor::operator()(TemplateDeclarationAST* ast) + -> DeclarationAST* { + auto copy = make_node(arena()); + + copy->templateLoc = ast->templateLoc; + copy->lessLoc = ast->lessLoc; + + for (auto templateParameterList = ©->templateParameterList; + auto node : ListView{ast->templateParameterList}) { + auto value = rewrite.templateParameter(node); + *templateParameterList = make_list_node(arena(), value); + templateParameterList = &(*templateParameterList)->next; + } + + copy->greaterLoc = ast->greaterLoc; + copy->requiresClause = rewrite.requiresClause(ast->requiresClause); + copy->declaration = rewrite.declaration(ast->declaration); + copy->symbol = ast->symbol; + + return copy; +} + +auto ASTRewriter::DeclarationVisitor::operator()(ConceptDefinitionAST* ast) + -> DeclarationAST* { + auto copy = make_node(arena()); + + copy->conceptLoc = ast->conceptLoc; + copy->identifierLoc = ast->identifierLoc; + copy->equalLoc = ast->equalLoc; + copy->expression = rewrite.expression(ast->expression); + copy->semicolonLoc = ast->semicolonLoc; + copy->identifier = ast->identifier; + copy->symbol = ast->symbol; + + return copy; +} + +auto ASTRewriter::DeclarationVisitor::operator()(DeductionGuideAST* ast) + -> DeclarationAST* { + auto copy = make_node(arena()); + + copy->explicitSpecifier = rewrite.specifier(ast->explicitSpecifier); + copy->identifierLoc = ast->identifierLoc; + copy->lparenLoc = ast->lparenLoc; + copy->parameterDeclarationClause = + rewrite.parameterDeclarationClause(ast->parameterDeclarationClause); + copy->rparenLoc = ast->rparenLoc; + copy->arrowLoc = ast->arrowLoc; + copy->templateId = + ast_cast(rewrite.unqualifiedId(ast->templateId)); + copy->semicolonLoc = ast->semicolonLoc; + copy->identifier = ast->identifier; + + return copy; +} + +auto ASTRewriter::DeclarationVisitor::operator()(ExplicitInstantiationAST* ast) + -> DeclarationAST* { + auto copy = make_node(arena()); + + copy->externLoc = ast->externLoc; + copy->templateLoc = ast->templateLoc; + copy->declaration = rewrite.declaration(ast->declaration); + + return copy; +} + +auto ASTRewriter::DeclarationVisitor::operator()(ExportDeclarationAST* ast) + -> DeclarationAST* { + auto copy = make_node(arena()); + + copy->exportLoc = ast->exportLoc; + copy->declaration = rewrite.declaration(ast->declaration); + + return copy; +} + +auto ASTRewriter::DeclarationVisitor::operator()( + ExportCompoundDeclarationAST* ast) -> DeclarationAST* { + auto copy = make_node(arena()); + + copy->exportLoc = ast->exportLoc; + copy->lbraceLoc = ast->lbraceLoc; + + for (auto declarationList = ©->declarationList; + auto node : ListView{ast->declarationList}) { + auto value = rewrite.declaration(node); + *declarationList = make_list_node(arena(), value); + declarationList = &(*declarationList)->next; + } + + copy->rbraceLoc = ast->rbraceLoc; + + return copy; +} + +auto ASTRewriter::DeclarationVisitor::operator()(LinkageSpecificationAST* ast) + -> DeclarationAST* { + auto copy = make_node(arena()); + + copy->externLoc = ast->externLoc; + copy->stringliteralLoc = ast->stringliteralLoc; + copy->lbraceLoc = ast->lbraceLoc; + + for (auto declarationList = ©->declarationList; + auto node : ListView{ast->declarationList}) { + auto value = rewrite.declaration(node); + *declarationList = make_list_node(arena(), value); + declarationList = &(*declarationList)->next; + } + + copy->rbraceLoc = ast->rbraceLoc; + copy->stringLiteral = ast->stringLiteral; + + return copy; +} + +auto ASTRewriter::DeclarationVisitor::operator()(NamespaceDefinitionAST* ast) + -> DeclarationAST* { + auto copy = make_node(arena()); + + copy->inlineLoc = ast->inlineLoc; + copy->namespaceLoc = ast->namespaceLoc; + + for (auto attributeList = ©->attributeList; + auto node : ListView{ast->attributeList}) { + auto value = rewrite.attributeSpecifier(node); + *attributeList = make_list_node(arena(), value); + attributeList = &(*attributeList)->next; + } + + for (auto nestedNamespaceSpecifierList = ©->nestedNamespaceSpecifierList; + auto node : ListView{ast->nestedNamespaceSpecifierList}) { + auto value = rewrite.nestedNamespaceSpecifier(node); + *nestedNamespaceSpecifierList = make_list_node(arena(), value); + nestedNamespaceSpecifierList = &(*nestedNamespaceSpecifierList)->next; + } + + copy->identifierLoc = ast->identifierLoc; + + for (auto extraAttributeList = ©->extraAttributeList; + auto node : ListView{ast->extraAttributeList}) { + auto value = rewrite.attributeSpecifier(node); + *extraAttributeList = make_list_node(arena(), value); + extraAttributeList = &(*extraAttributeList)->next; + } + + copy->lbraceLoc = ast->lbraceLoc; + + for (auto declarationList = ©->declarationList; + auto node : ListView{ast->declarationList}) { + auto value = rewrite.declaration(node); + *declarationList = make_list_node(arena(), value); + declarationList = &(*declarationList)->next; + } + + copy->rbraceLoc = ast->rbraceLoc; + copy->identifier = ast->identifier; + copy->isInline = ast->isInline; + + return copy; +} + +auto ASTRewriter::DeclarationVisitor::operator()(EmptyDeclarationAST* ast) + -> DeclarationAST* { + auto copy = make_node(arena()); + + copy->semicolonLoc = ast->semicolonLoc; + + return copy; +} + +auto ASTRewriter::DeclarationVisitor::operator()(AttributeDeclarationAST* ast) + -> DeclarationAST* { + auto copy = make_node(arena()); + + for (auto attributeList = ©->attributeList; + auto node : ListView{ast->attributeList}) { + auto value = rewrite.attributeSpecifier(node); + *attributeList = make_list_node(arena(), value); + attributeList = &(*attributeList)->next; + } + + copy->semicolonLoc = ast->semicolonLoc; + + return copy; +} + +auto ASTRewriter::DeclarationVisitor::operator()( + ModuleImportDeclarationAST* ast) -> DeclarationAST* { + auto copy = make_node(arena()); + + copy->importLoc = ast->importLoc; + copy->importName = rewrite.importName(ast->importName); + + for (auto attributeList = ©->attributeList; + auto node : ListView{ast->attributeList}) { + auto value = rewrite.attributeSpecifier(node); + *attributeList = make_list_node(arena(), value); + attributeList = &(*attributeList)->next; + } + + copy->semicolonLoc = ast->semicolonLoc; + + return copy; +} + +auto ASTRewriter::DeclarationVisitor::operator()(ParameterDeclarationAST* ast) + -> DeclarationAST* { + auto copy = make_node(arena()); + + for (auto attributeList = ©->attributeList; + auto node : ListView{ast->attributeList}) { + auto value = rewrite.attributeSpecifier(node); + *attributeList = make_list_node(arena(), value); + attributeList = &(*attributeList)->next; + } + + copy->thisLoc = ast->thisLoc; + + auto typeSpecifierListCtx = DeclSpecs{rewriter()}; + for (auto typeSpecifierList = ©->typeSpecifierList; + auto node : ListView{ast->typeSpecifierList}) { + auto value = rewrite.specifier(node); + *typeSpecifierList = make_list_node(arena(), value); + typeSpecifierList = &(*typeSpecifierList)->next; + typeSpecifierListCtx.accept(value); + } + typeSpecifierListCtx.finish(); + + copy->declarator = rewrite.declarator(ast->declarator); + + auto declaratorDecl = Decl{typeSpecifierListCtx, copy->declarator}; + auto declaratorType = getDeclaratorType(translationUnit(), copy->declarator, + typeSpecifierListCtx.type()); + copy->type = declaratorType; + copy->equalLoc = ast->equalLoc; + copy->expression = rewrite.expression(ast->expression); + copy->identifier = ast->identifier; + copy->isThisIntroduced = ast->isThisIntroduced; + copy->isPack = ast->isPack; + + return copy; +} + +auto ASTRewriter::DeclarationVisitor::operator()(AccessDeclarationAST* ast) + -> DeclarationAST* { + auto copy = make_node(arena()); + + copy->accessLoc = ast->accessLoc; + copy->colonLoc = ast->colonLoc; + copy->accessSpecifier = ast->accessSpecifier; + + return copy; +} + +auto ASTRewriter::DeclarationVisitor::operator()(ForRangeDeclarationAST* ast) + -> DeclarationAST* { + auto copy = make_node(arena()); + + return copy; +} + +auto ASTRewriter::DeclarationVisitor::operator()( + StructuredBindingDeclarationAST* ast) -> DeclarationAST* { + auto copy = make_node(arena()); + + for (auto attributeList = ©->attributeList; + auto node : ListView{ast->attributeList}) { + auto value = rewrite.attributeSpecifier(node); + *attributeList = make_list_node(arena(), value); + attributeList = &(*attributeList)->next; + } + + auto declSpecifierListCtx = DeclSpecs{rewriter()}; + for (auto declSpecifierList = ©->declSpecifierList; + auto node : ListView{ast->declSpecifierList}) { + auto value = rewrite.specifier(node); + *declSpecifierList = make_list_node(arena(), value); + declSpecifierList = &(*declSpecifierList)->next; + declSpecifierListCtx.accept(value); + } + declSpecifierListCtx.finish(); + + copy->refQualifierLoc = ast->refQualifierLoc; + copy->lbracketLoc = ast->lbracketLoc; + + for (auto bindingList = ©->bindingList; + auto node : ListView{ast->bindingList}) { + auto value = rewrite.unqualifiedId(node); + *bindingList = make_list_node(arena(), ast_cast(value)); + bindingList = &(*bindingList)->next; + } + + copy->rbracketLoc = ast->rbracketLoc; + copy->initializer = rewrite.expression(ast->initializer); + copy->semicolonLoc = ast->semicolonLoc; + + return copy; +} + +auto ASTRewriter::TemplateParameterVisitor::operator()( + TemplateTypeParameterAST* ast) -> TemplateParameterAST* { + auto copy = make_node(arena()); + + copy->symbol = ast->symbol; + copy->depth = ast->depth; + copy->index = ast->index; + copy->templateLoc = ast->templateLoc; + copy->lessLoc = ast->lessLoc; + + for (auto templateParameterList = ©->templateParameterList; + auto node : ListView{ast->templateParameterList}) { + auto value = rewrite.templateParameter(node); + *templateParameterList = make_list_node(arena(), value); + templateParameterList = &(*templateParameterList)->next; + } + + copy->greaterLoc = ast->greaterLoc; + copy->requiresClause = rewrite.requiresClause(ast->requiresClause); + copy->classKeyLoc = ast->classKeyLoc; + copy->ellipsisLoc = ast->ellipsisLoc; + copy->identifierLoc = ast->identifierLoc; + copy->equalLoc = ast->equalLoc; + copy->idExpression = + ast_cast(rewrite.expression(ast->idExpression)); + copy->identifier = ast->identifier; + copy->isPack = ast->isPack; + + return copy; +} + +auto ASTRewriter::TemplateParameterVisitor::operator()( + NonTypeTemplateParameterAST* ast) -> TemplateParameterAST* { + auto copy = make_node(arena()); + + copy->symbol = ast->symbol; + copy->depth = ast->depth; + copy->index = ast->index; + copy->declaration = + ast_cast(rewrite.declaration(ast->declaration)); + + return copy; +} + +auto ASTRewriter::TemplateParameterVisitor::operator()( + TypenameTypeParameterAST* ast) -> TemplateParameterAST* { + auto copy = make_node(arena()); + + copy->symbol = ast->symbol; + copy->depth = ast->depth; + copy->index = ast->index; + copy->classKeyLoc = ast->classKeyLoc; + copy->ellipsisLoc = ast->ellipsisLoc; + copy->identifierLoc = ast->identifierLoc; + copy->equalLoc = ast->equalLoc; + copy->typeId = rewrite.typeId(ast->typeId); + copy->identifier = ast->identifier; + copy->isPack = ast->isPack; + + return copy; +} + +auto ASTRewriter::TemplateParameterVisitor::operator()( + ConstraintTypeParameterAST* ast) -> TemplateParameterAST* { + auto copy = make_node(arena()); + + copy->symbol = ast->symbol; + copy->depth = ast->depth; + copy->index = ast->index; + copy->typeConstraint = rewrite.typeConstraint(ast->typeConstraint); + copy->ellipsisLoc = ast->ellipsisLoc; + copy->identifierLoc = ast->identifierLoc; + copy->equalLoc = ast->equalLoc; + copy->typeId = rewrite.typeId(ast->typeId); + copy->identifier = ast->identifier; + + return copy; +} + +auto ASTRewriter::FunctionBodyVisitor::operator()(DefaultFunctionBodyAST* ast) + -> FunctionBodyAST* { + auto copy = make_node(arena()); + + copy->equalLoc = ast->equalLoc; + copy->defaultLoc = ast->defaultLoc; + copy->semicolonLoc = ast->semicolonLoc; + + return copy; +} + +auto ASTRewriter::FunctionBodyVisitor::operator()( + CompoundStatementFunctionBodyAST* ast) -> FunctionBodyAST* { + auto copy = make_node(arena()); + + copy->colonLoc = ast->colonLoc; + + for (auto memInitializerList = ©->memInitializerList; + auto node : ListView{ast->memInitializerList}) { + auto value = rewrite.memInitializer(node); + *memInitializerList = make_list_node(arena(), value); + memInitializerList = &(*memInitializerList)->next; + } + + copy->statement = + ast_cast(rewrite.statement(ast->statement)); + + return copy; +} + +auto ASTRewriter::FunctionBodyVisitor::operator()( + TryStatementFunctionBodyAST* ast) -> FunctionBodyAST* { + auto copy = make_node(arena()); + + copy->tryLoc = ast->tryLoc; + copy->colonLoc = ast->colonLoc; + + for (auto memInitializerList = ©->memInitializerList; + auto node : ListView{ast->memInitializerList}) { + auto value = rewrite.memInitializer(node); + *memInitializerList = make_list_node(arena(), value); + memInitializerList = &(*memInitializerList)->next; + } + + copy->statement = + ast_cast(rewrite.statement(ast->statement)); + + for (auto handlerList = ©->handlerList; + auto node : ListView{ast->handlerList}) { + auto value = rewrite.handler(node); + *handlerList = make_list_node(arena(), value); + handlerList = &(*handlerList)->next; + } + + return copy; +} + +auto ASTRewriter::FunctionBodyVisitor::operator()(DeleteFunctionBodyAST* ast) + -> FunctionBodyAST* { + auto copy = make_node(arena()); + + copy->equalLoc = ast->equalLoc; + copy->deleteLoc = ast->deleteLoc; + copy->semicolonLoc = ast->semicolonLoc; + + return copy; +} + +auto ASTRewriter::RequirementVisitor::operator()(SimpleRequirementAST* ast) + -> RequirementAST* { + auto copy = make_node(arena()); + + copy->expression = rewrite.expression(ast->expression); + copy->semicolonLoc = ast->semicolonLoc; + + return copy; +} + +auto ASTRewriter::RequirementVisitor::operator()(CompoundRequirementAST* ast) + -> RequirementAST* { + auto copy = make_node(arena()); + + copy->lbraceLoc = ast->lbraceLoc; + copy->expression = rewrite.expression(ast->expression); + copy->rbraceLoc = ast->rbraceLoc; + copy->noexceptLoc = ast->noexceptLoc; + copy->minusGreaterLoc = ast->minusGreaterLoc; + copy->typeConstraint = rewrite.typeConstraint(ast->typeConstraint); + copy->semicolonLoc = ast->semicolonLoc; + + return copy; +} + +auto ASTRewriter::RequirementVisitor::operator()(TypeRequirementAST* ast) + -> RequirementAST* { + auto copy = make_node(arena()); + + copy->typenameLoc = ast->typenameLoc; + copy->nestedNameSpecifier = + rewrite.nestedNameSpecifier(ast->nestedNameSpecifier); + copy->templateLoc = ast->templateLoc; + copy->unqualifiedId = rewrite.unqualifiedId(ast->unqualifiedId); + copy->semicolonLoc = ast->semicolonLoc; + copy->isTemplateIntroduced = ast->isTemplateIntroduced; + + return copy; +} + +auto ASTRewriter::RequirementVisitor::operator()(NestedRequirementAST* ast) + -> RequirementAST* { + auto copy = make_node(arena()); + + copy->requiresLoc = ast->requiresLoc; + copy->expression = rewrite.expression(ast->expression); + copy->semicolonLoc = ast->semicolonLoc; + + return copy; +} + +} // namespace cxx diff --git a/src/parser/cxx/ast_rewriter_declarators.cc b/src/parser/cxx/ast_rewriter_declarators.cc new file mode 100644 index 00000000..3a88109a --- /dev/null +++ b/src/parser/cxx/ast_rewriter_declarators.cc @@ -0,0 +1,504 @@ +// Copyright (c) 2025 Roberto Raggi +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#include + +// cxx +#include +#include +#include +#include +#include +#include +#include + +namespace cxx { + +struct ASTRewriter::CoreDeclaratorVisitor { + ASTRewriter& rewrite; + [[nodiscard]] auto translationUnit() const -> TranslationUnit* { + return rewrite.unit_; + } + + [[nodiscard]] auto control() const -> Control* { return rewrite.control(); } + [[nodiscard]] auto arena() const -> Arena* { return rewrite.arena(); } + [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } + [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } + + [[nodiscard]] auto operator()(BitfieldDeclaratorAST* ast) + -> CoreDeclaratorAST*; + + [[nodiscard]] auto operator()(ParameterPackAST* ast) -> CoreDeclaratorAST*; + + [[nodiscard]] auto operator()(IdDeclaratorAST* ast) -> CoreDeclaratorAST*; + + [[nodiscard]] auto operator()(NestedDeclaratorAST* ast) -> CoreDeclaratorAST*; +}; + +struct ASTRewriter::DeclaratorChunkVisitor { + ASTRewriter& rewrite; + [[nodiscard]] auto translationUnit() const -> TranslationUnit* { + return rewrite.unit_; + } + + [[nodiscard]] auto control() const -> Control* { return rewrite.control(); } + [[nodiscard]] auto arena() const -> Arena* { return rewrite.arena(); } + [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } + [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } + + [[nodiscard]] auto operator()(FunctionDeclaratorChunkAST* ast) + -> DeclaratorChunkAST*; + + [[nodiscard]] auto operator()(ArrayDeclaratorChunkAST* ast) + -> DeclaratorChunkAST*; +}; + +struct ASTRewriter::PtrOperatorVisitor { + ASTRewriter& rewrite; + [[nodiscard]] auto translationUnit() const -> TranslationUnit* { + return rewrite.unit_; + } + + [[nodiscard]] auto control() const -> Control* { return rewrite.control(); } + [[nodiscard]] auto arena() const -> Arena* { return rewrite.arena(); } + [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } + [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } + + [[nodiscard]] auto operator()(PointerOperatorAST* ast) -> PtrOperatorAST*; + + [[nodiscard]] auto operator()(ReferenceOperatorAST* ast) -> PtrOperatorAST*; + + [[nodiscard]] auto operator()(PtrToMemberOperatorAST* ast) -> PtrOperatorAST*; +}; + +struct ASTRewriter::DesignatorVisitor { + ASTRewriter& rewrite; + [[nodiscard]] auto translationUnit() const -> TranslationUnit* { + return rewrite.unit_; + } + + [[nodiscard]] auto control() const -> Control* { return rewrite.control(); } + [[nodiscard]] auto arena() const -> Arena* { return rewrite.arena(); } + [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } + [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } + + [[nodiscard]] auto operator()(DotDesignatorAST* ast) -> DesignatorAST*; + + [[nodiscard]] auto operator()(SubscriptDesignatorAST* ast) -> DesignatorAST*; +}; + +struct ASTRewriter::ExceptionSpecifierVisitor { + ASTRewriter& rewrite; + [[nodiscard]] auto translationUnit() const -> TranslationUnit* { + return rewrite.unit_; + } + + [[nodiscard]] auto control() const -> Control* { return rewrite.control(); } + [[nodiscard]] auto arena() const -> Arena* { return rewrite.arena(); } + [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } + [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } + + [[nodiscard]] auto operator()(ThrowExceptionSpecifierAST* ast) + -> ExceptionSpecifierAST*; + + [[nodiscard]] auto operator()(NoexceptSpecifierAST* ast) + -> ExceptionSpecifierAST*; +}; + +auto ASTRewriter::ptrOperator(PtrOperatorAST* ast) -> PtrOperatorAST* { + if (!ast) return {}; + return visit(PtrOperatorVisitor{*this}, ast); +} + +auto ASTRewriter::coreDeclarator(CoreDeclaratorAST* ast) -> CoreDeclaratorAST* { + if (!ast) return {}; + return visit(CoreDeclaratorVisitor{*this}, ast); +} + +auto ASTRewriter::declaratorChunk(DeclaratorChunkAST* ast) + -> DeclaratorChunkAST* { + if (!ast) return {}; + return visit(DeclaratorChunkVisitor{*this}, ast); +} + +auto ASTRewriter::designator(DesignatorAST* ast) -> DesignatorAST* { + if (!ast) return {}; + return visit(DesignatorVisitor{*this}, ast); +} + +auto ASTRewriter::exceptionSpecifier(ExceptionSpecifierAST* ast) + -> ExceptionSpecifierAST* { + if (!ast) return {}; + return visit(ExceptionSpecifierVisitor{*this}, ast); +} + +auto ASTRewriter::requiresClause(RequiresClauseAST* ast) -> RequiresClauseAST* { + if (!ast) return {}; + + auto copy = make_node(arena()); + + copy->requiresLoc = ast->requiresLoc; + copy->expression = expression(ast->expression); + + return copy; +} + +auto ASTRewriter::parameterDeclarationClause(ParameterDeclarationClauseAST* ast) + -> ParameterDeclarationClauseAST* { + if (!ast) return {}; + + auto copy = make_node(arena()); + + for (auto parameterDeclarationList = ©->parameterDeclarationList; + auto node : ListView{ast->parameterDeclarationList}) { + auto value = ast_cast(declaration(node)); + *parameterDeclarationList = make_list_node(arena(), value); + parameterDeclarationList = &(*parameterDeclarationList)->next; + } + + copy->commaLoc = ast->commaLoc; + copy->ellipsisLoc = ast->ellipsisLoc; + copy->functionParametersSymbol = ast->functionParametersSymbol; + copy->isVariadic = ast->isVariadic; + + return copy; +} + +auto ASTRewriter::trailingReturnType(TrailingReturnTypeAST* ast) + -> TrailingReturnTypeAST* { + if (!ast) return {}; + + auto copy = make_node(arena()); + + copy->minusGreaterLoc = ast->minusGreaterLoc; + copy->typeId = typeId(ast->typeId); + + return copy; +} + +auto ASTRewriter::initDeclarator(InitDeclaratorAST* ast, + const DeclSpecs& declSpecs) + -> InitDeclaratorAST* { + if (!ast) return {}; + + auto copy = make_node(arena()); + + copy->declarator = declarator(ast->declarator); + + auto decl = Decl{declSpecs, copy->declarator}; + + auto type = + getDeclaratorType(translationUnit(), copy->declarator, declSpecs.type()); + + // ### fix scope + if (binder_.scope()->isClassScope()) { + auto symbol = binder_.declareMemberSymbol(copy->declarator, decl); + copy->symbol = symbol; + } else { + // todo: move to Binder + if (auto declId = decl.declaratorId; declId) { + if (decl.specs.isTypedef) { + auto typedefSymbol = binder_.declareTypedef(copy->declarator, decl); + copy->symbol = typedefSymbol; + } else if (getFunctionPrototype(copy->declarator)) { + auto functionSymbol = binder_.declareFunction(copy->declarator, decl); + copy->symbol = functionSymbol; + } else { + auto variableSymbol = binder_.declareVariable(copy->declarator, decl); + // variableSymbol->setTemplateDeclaration(templateHead); + copy->symbol = variableSymbol; + } + } + } + + copy->requiresClause = requiresClause(ast->requiresClause); + copy->initializer = expression(ast->initializer); + // copy->symbol = ast->symbol; // TODO remove, done above + + return copy; +} + +auto ASTRewriter::declarator(DeclaratorAST* ast) -> DeclaratorAST* { + if (!ast) return {}; + + auto copy = make_node(arena()); + + for (auto ptrOpList = ©->ptrOpList; + auto node : ListView{ast->ptrOpList}) { + auto value = ptrOperator(node); + *ptrOpList = make_list_node(arena(), value); + ptrOpList = &(*ptrOpList)->next; + } + + copy->coreDeclarator = coreDeclarator(ast->coreDeclarator); + + for (auto declaratorChunkList = ©->declaratorChunkList; + auto node : ListView{ast->declaratorChunkList}) { + auto value = declaratorChunk(node); + *declaratorChunkList = make_list_node(arena(), value); + declaratorChunkList = &(*declaratorChunkList)->next; + } + + return copy; +} + +auto ASTRewriter::PtrOperatorVisitor::operator()(PointerOperatorAST* ast) + -> PtrOperatorAST* { + auto copy = make_node(arena()); + + copy->starLoc = ast->starLoc; + + for (auto attributeList = ©->attributeList; + auto node : ListView{ast->attributeList}) { + auto value = rewrite.attributeSpecifier(node); + *attributeList = make_list_node(arena(), value); + attributeList = &(*attributeList)->next; + } + + auto cvQualifierListCtx = DeclSpecs{rewriter()}; + for (auto cvQualifierList = ©->cvQualifierList; + auto node : ListView{ast->cvQualifierList}) { + auto value = rewrite.specifier(node); + *cvQualifierList = make_list_node(arena(), value); + cvQualifierList = &(*cvQualifierList)->next; + cvQualifierListCtx.accept(value); + } + + return copy; +} + +auto ASTRewriter::PtrOperatorVisitor::operator()(ReferenceOperatorAST* ast) + -> PtrOperatorAST* { + auto copy = make_node(arena()); + + copy->refLoc = ast->refLoc; + + for (auto attributeList = ©->attributeList; + auto node : ListView{ast->attributeList}) { + auto value = rewrite.attributeSpecifier(node); + *attributeList = make_list_node(arena(), value); + attributeList = &(*attributeList)->next; + } + + copy->refOp = ast->refOp; + + return copy; +} + +auto ASTRewriter::PtrOperatorVisitor::operator()(PtrToMemberOperatorAST* ast) + -> PtrOperatorAST* { + auto copy = make_node(arena()); + + copy->nestedNameSpecifier = + rewrite.nestedNameSpecifier(ast->nestedNameSpecifier); + copy->starLoc = ast->starLoc; + + for (auto attributeList = ©->attributeList; + auto node : ListView{ast->attributeList}) { + auto value = rewrite.attributeSpecifier(node); + *attributeList = make_list_node(arena(), value); + attributeList = &(*attributeList)->next; + } + + auto cvQualifierListCtx = DeclSpecs{rewriter()}; + for (auto cvQualifierList = ©->cvQualifierList; + auto node : ListView{ast->cvQualifierList}) { + auto value = rewrite.specifier(node); + *cvQualifierList = make_list_node(arena(), value); + cvQualifierList = &(*cvQualifierList)->next; + cvQualifierListCtx.accept(value); + } + + return copy; +} + +auto ASTRewriter::CoreDeclaratorVisitor::operator()(BitfieldDeclaratorAST* ast) + -> CoreDeclaratorAST* { + auto copy = make_node(arena()); + + copy->unqualifiedId = + ast_cast(rewrite.unqualifiedId(ast->unqualifiedId)); + copy->colonLoc = ast->colonLoc; + copy->sizeExpression = rewrite.expression(ast->sizeExpression); + + return copy; +} + +auto ASTRewriter::CoreDeclaratorVisitor::operator()(ParameterPackAST* ast) + -> CoreDeclaratorAST* { + auto copy = make_node(arena()); + + copy->ellipsisLoc = ast->ellipsisLoc; + copy->coreDeclarator = rewrite.coreDeclarator(ast->coreDeclarator); + + return copy; +} + +auto ASTRewriter::CoreDeclaratorVisitor::operator()(IdDeclaratorAST* ast) + -> CoreDeclaratorAST* { + auto copy = make_node(arena()); + + copy->nestedNameSpecifier = + rewrite.nestedNameSpecifier(ast->nestedNameSpecifier); + copy->templateLoc = ast->templateLoc; + copy->unqualifiedId = rewrite.unqualifiedId(ast->unqualifiedId); + + for (auto attributeList = ©->attributeList; + auto node : ListView{ast->attributeList}) { + auto value = rewrite.attributeSpecifier(node); + *attributeList = make_list_node(arena(), value); + attributeList = &(*attributeList)->next; + } + + copy->isTemplateIntroduced = ast->isTemplateIntroduced; + + return copy; +} + +auto ASTRewriter::CoreDeclaratorVisitor::operator()(NestedDeclaratorAST* ast) + -> CoreDeclaratorAST* { + auto copy = make_node(arena()); + + copy->lparenLoc = ast->lparenLoc; + copy->declarator = rewrite.declarator(ast->declarator); + copy->rparenLoc = ast->rparenLoc; + + return copy; +} + +auto ASTRewriter::DeclaratorChunkVisitor::operator()( + FunctionDeclaratorChunkAST* ast) -> DeclaratorChunkAST* { + auto copy = make_node(arena()); + + copy->lparenLoc = ast->lparenLoc; + copy->parameterDeclarationClause = + rewrite.parameterDeclarationClause(ast->parameterDeclarationClause); + copy->rparenLoc = ast->rparenLoc; + + auto _ = Binder::ScopeGuard{binder()}; + + if (copy->parameterDeclarationClause) { + binder()->setScope( + copy->parameterDeclarationClause->functionParametersSymbol); + } + + auto cvQualifierListCtx = DeclSpecs{rewriter()}; + for (auto cvQualifierList = ©->cvQualifierList; + auto node : ListView{ast->cvQualifierList}) { + auto value = rewrite.specifier(node); + *cvQualifierList = make_list_node(arena(), value); + cvQualifierList = &(*cvQualifierList)->next; + cvQualifierListCtx.accept(value); + } + + copy->refLoc = ast->refLoc; + copy->exceptionSpecifier = + rewrite.exceptionSpecifier(ast->exceptionSpecifier); + + for (auto attributeList = ©->attributeList; + auto node : ListView{ast->attributeList}) { + auto value = rewrite.attributeSpecifier(node); + *attributeList = make_list_node(arena(), value); + attributeList = &(*attributeList)->next; + } + + copy->trailingReturnType = + rewrite.trailingReturnType(ast->trailingReturnType); + copy->isFinal = ast->isFinal; + copy->isOverride = ast->isOverride; + copy->isPure = ast->isPure; + + return copy; +} + +auto ASTRewriter::DeclaratorChunkVisitor::operator()( + ArrayDeclaratorChunkAST* ast) -> DeclaratorChunkAST* { + auto copy = make_node(arena()); + + copy->lbracketLoc = ast->lbracketLoc; + + auto typeQualifierListCtx = DeclSpecs{rewriter()}; + for (auto typeQualifierList = ©->typeQualifierList; + auto node : ListView{ast->typeQualifierList}) { + auto value = rewrite.specifier(node); + *typeQualifierList = make_list_node(arena(), value); + typeQualifierList = &(*typeQualifierList)->next; + typeQualifierListCtx.accept(value); + } + + copy->expression = rewrite.expression(ast->expression); + copy->rbracketLoc = ast->rbracketLoc; + + for (auto attributeList = ©->attributeList; + auto node : ListView{ast->attributeList}) { + auto value = rewrite.attributeSpecifier(node); + *attributeList = make_list_node(arena(), value); + attributeList = &(*attributeList)->next; + } + + return copy; +} + +auto ASTRewriter::DesignatorVisitor::operator()(DotDesignatorAST* ast) + -> DesignatorAST* { + auto copy = make_node(arena()); + + copy->dotLoc = ast->dotLoc; + copy->identifierLoc = ast->identifierLoc; + copy->identifier = ast->identifier; + + return copy; +} + +auto ASTRewriter::DesignatorVisitor::operator()(SubscriptDesignatorAST* ast) + -> DesignatorAST* { + auto copy = make_node(arena()); + + copy->lbracketLoc = ast->lbracketLoc; + copy->expression = rewrite.expression(ast->expression); + copy->rbracketLoc = ast->rbracketLoc; + + return copy; +} + +auto ASTRewriter::ExceptionSpecifierVisitor::operator()( + ThrowExceptionSpecifierAST* ast) -> ExceptionSpecifierAST* { + auto copy = make_node(arena()); + + copy->throwLoc = ast->throwLoc; + copy->lparenLoc = ast->lparenLoc; + copy->rparenLoc = ast->rparenLoc; + + return copy; +} + +auto ASTRewriter::ExceptionSpecifierVisitor::operator()( + NoexceptSpecifierAST* ast) -> ExceptionSpecifierAST* { + auto copy = make_node(arena()); + + copy->noexceptLoc = ast->noexceptLoc; + copy->lparenLoc = ast->lparenLoc; + copy->expression = rewrite.expression(ast->expression); + copy->rparenLoc = ast->rparenLoc; + + return copy; +} + +} // namespace cxx \ No newline at end of file diff --git a/src/parser/cxx/ast_rewriter_expressions.cc b/src/parser/cxx/ast_rewriter_expressions.cc new file mode 100644 index 00000000..d00c007d --- /dev/null +++ b/src/parser/cxx/ast_rewriter_expressions.cc @@ -0,0 +1,1543 @@ +// Copyright (c) 2025 Roberto Raggi +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#include + +// cxx +#include +#include +#include +#include +#include + +namespace cxx { + +struct ASTRewriter::ExpressionVisitor { + ASTRewriter& rewrite; + [[nodiscard]] auto translationUnit() const -> TranslationUnit* { + return rewrite.unit_; + } + + [[nodiscard]] auto control() const -> Control* { return rewrite.control(); } + [[nodiscard]] auto arena() const -> Arena* { return rewrite.arena(); } + [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } + [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } + + [[nodiscard]] auto operator()(GeneratedLiteralExpressionAST* ast) + -> ExpressionAST*; + + [[nodiscard]] auto operator()(CharLiteralExpressionAST* ast) + -> ExpressionAST*; + + [[nodiscard]] auto operator()(BoolLiteralExpressionAST* ast) + -> ExpressionAST*; + + [[nodiscard]] auto operator()(IntLiteralExpressionAST* ast) -> ExpressionAST*; + + [[nodiscard]] auto operator()(FloatLiteralExpressionAST* ast) + -> ExpressionAST*; + + [[nodiscard]] auto operator()(NullptrLiteralExpressionAST* ast) + -> ExpressionAST*; + + [[nodiscard]] auto operator()(StringLiteralExpressionAST* ast) + -> ExpressionAST*; + + [[nodiscard]] auto operator()(UserDefinedStringLiteralExpressionAST* ast) + -> ExpressionAST*; + + [[nodiscard]] auto operator()(ObjectLiteralExpressionAST* ast) + -> ExpressionAST*; + + [[nodiscard]] auto operator()(ThisExpressionAST* ast) -> ExpressionAST*; + + [[nodiscard]] auto operator()(GenericSelectionExpressionAST* ast) + -> ExpressionAST*; + + [[nodiscard]] auto operator()(NestedStatementExpressionAST* ast) + -> ExpressionAST*; + + [[nodiscard]] auto operator()(NestedExpressionAST* ast) -> ExpressionAST*; + + [[nodiscard]] auto operator()(IdExpressionAST* ast) -> ExpressionAST*; + + [[nodiscard]] auto operator()(LambdaExpressionAST* ast) -> ExpressionAST*; + + [[nodiscard]] auto operator()(FoldExpressionAST* ast) -> ExpressionAST*; + + [[nodiscard]] auto operator()(RightFoldExpressionAST* ast) -> ExpressionAST*; + + [[nodiscard]] auto operator()(LeftFoldExpressionAST* ast) -> ExpressionAST*; + + [[nodiscard]] auto operator()(RequiresExpressionAST* ast) -> ExpressionAST*; + + [[nodiscard]] auto operator()(VaArgExpressionAST* ast) -> ExpressionAST*; + + [[nodiscard]] auto operator()(SubscriptExpressionAST* ast) -> ExpressionAST*; + + [[nodiscard]] auto operator()(CallExpressionAST* ast) -> ExpressionAST*; + + [[nodiscard]] auto operator()(TypeConstructionAST* ast) -> ExpressionAST*; + + [[nodiscard]] auto operator()(BracedTypeConstructionAST* ast) + -> ExpressionAST*; + + [[nodiscard]] auto operator()(SpliceMemberExpressionAST* ast) + -> ExpressionAST*; + + [[nodiscard]] auto operator()(MemberExpressionAST* ast) -> ExpressionAST*; + + [[nodiscard]] auto operator()(PostIncrExpressionAST* ast) -> ExpressionAST*; + + [[nodiscard]] auto operator()(CppCastExpressionAST* ast) -> ExpressionAST*; + + [[nodiscard]] auto operator()(BuiltinBitCastExpressionAST* ast) + -> ExpressionAST*; + + [[nodiscard]] auto operator()(BuiltinOffsetofExpressionAST* ast) + -> ExpressionAST*; + + [[nodiscard]] auto operator()(TypeidExpressionAST* ast) -> ExpressionAST*; + + [[nodiscard]] auto operator()(TypeidOfTypeExpressionAST* ast) + -> ExpressionAST*; + + [[nodiscard]] auto operator()(SpliceExpressionAST* ast) -> ExpressionAST*; + + [[nodiscard]] auto operator()(GlobalScopeReflectExpressionAST* ast) + -> ExpressionAST*; + + [[nodiscard]] auto operator()(NamespaceReflectExpressionAST* ast) + -> ExpressionAST*; + + [[nodiscard]] auto operator()(TypeIdReflectExpressionAST* ast) + -> ExpressionAST*; + + [[nodiscard]] auto operator()(ReflectExpressionAST* ast) -> ExpressionAST*; + + [[nodiscard]] auto operator()(LabelAddressExpressionAST* ast) + -> ExpressionAST*; + + [[nodiscard]] auto operator()(UnaryExpressionAST* ast) -> ExpressionAST*; + + [[nodiscard]] auto operator()(AwaitExpressionAST* ast) -> ExpressionAST*; + + [[nodiscard]] auto operator()(SizeofExpressionAST* ast) -> ExpressionAST*; + + [[nodiscard]] auto operator()(SizeofTypeExpressionAST* ast) -> ExpressionAST*; + + [[nodiscard]] auto operator()(SizeofPackExpressionAST* ast) -> ExpressionAST*; + + [[nodiscard]] auto operator()(AlignofTypeExpressionAST* ast) + -> ExpressionAST*; + + [[nodiscard]] auto operator()(AlignofExpressionAST* ast) -> ExpressionAST*; + + [[nodiscard]] auto operator()(NoexceptExpressionAST* ast) -> ExpressionAST*; + + [[nodiscard]] auto operator()(NewExpressionAST* ast) -> ExpressionAST*; + + [[nodiscard]] auto operator()(DeleteExpressionAST* ast) -> ExpressionAST*; + + [[nodiscard]] auto operator()(CastExpressionAST* ast) -> ExpressionAST*; + + [[nodiscard]] auto operator()(ImplicitCastExpressionAST* ast) + -> ExpressionAST*; + + [[nodiscard]] auto operator()(BinaryExpressionAST* ast) -> ExpressionAST*; + + [[nodiscard]] auto operator()(ConditionalExpressionAST* ast) + -> ExpressionAST*; + + [[nodiscard]] auto operator()(YieldExpressionAST* ast) -> ExpressionAST*; + + [[nodiscard]] auto operator()(ThrowExpressionAST* ast) -> ExpressionAST*; + + [[nodiscard]] auto operator()(AssignmentExpressionAST* ast) -> ExpressionAST*; + + [[nodiscard]] auto operator()(CompoundAssignmentExpressionAST* ast) + -> ExpressionAST*; + + [[nodiscard]] auto operator()(PackExpansionExpressionAST* ast) + -> ExpressionAST*; + + [[nodiscard]] auto operator()(DesignatedInitializerClauseAST* ast) + -> ExpressionAST*; + + [[nodiscard]] auto operator()(TypeTraitExpressionAST* ast) -> ExpressionAST*; + + [[nodiscard]] auto operator()(ConditionExpressionAST* ast) -> ExpressionAST*; + + [[nodiscard]] auto operator()(EqualInitializerAST* ast) -> ExpressionAST*; + + [[nodiscard]] auto operator()(BracedInitListAST* ast) -> ExpressionAST*; + + [[nodiscard]] auto operator()(ParenInitializerAST* ast) -> ExpressionAST*; +}; + +struct ASTRewriter::NewInitializerVisitor { + ASTRewriter& rewrite; + [[nodiscard]] auto translationUnit() const -> TranslationUnit* { + return rewrite.unit_; + } + + [[nodiscard]] auto control() const -> Control* { return rewrite.control(); } + [[nodiscard]] auto arena() const -> Arena* { return rewrite.arena(); } + [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } + [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } + + [[nodiscard]] auto operator()(NewParenInitializerAST* ast) + -> NewInitializerAST*; + + [[nodiscard]] auto operator()(NewBracedInitializerAST* ast) + -> NewInitializerAST*; +}; + +struct ASTRewriter::GenericAssociationVisitor { + ASTRewriter& rewrite; + [[nodiscard]] auto translationUnit() const -> TranslationUnit* { + return rewrite.unit_; + } + + [[nodiscard]] auto control() const -> Control* { return rewrite.control(); } + [[nodiscard]] auto arena() const -> Arena* { return rewrite.arena(); } + [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } + [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } + + [[nodiscard]] auto operator()(DefaultGenericAssociationAST* ast) + -> GenericAssociationAST*; + + [[nodiscard]] auto operator()(TypeGenericAssociationAST* ast) + -> GenericAssociationAST*; +}; + +struct ASTRewriter::LambdaCaptureVisitor { + ASTRewriter& rewrite; + [[nodiscard]] auto translationUnit() const -> TranslationUnit* { + return rewrite.unit_; + } + + [[nodiscard]] auto control() const -> Control* { return rewrite.control(); } + [[nodiscard]] auto arena() const -> Arena* { return rewrite.arena(); } + [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } + [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } + + [[nodiscard]] auto operator()(ThisLambdaCaptureAST* ast) -> LambdaCaptureAST*; + + [[nodiscard]] auto operator()(DerefThisLambdaCaptureAST* ast) + -> LambdaCaptureAST*; + + [[nodiscard]] auto operator()(SimpleLambdaCaptureAST* ast) + -> LambdaCaptureAST*; + + [[nodiscard]] auto operator()(RefLambdaCaptureAST* ast) -> LambdaCaptureAST*; + + [[nodiscard]] auto operator()(RefInitLambdaCaptureAST* ast) + -> LambdaCaptureAST*; + + [[nodiscard]] auto operator()(InitLambdaCaptureAST* ast) -> LambdaCaptureAST*; +}; + +auto ASTRewriter::expression(ExpressionAST* ast) -> ExpressionAST* { + if (!ast) return {}; + auto expr = visit(ExpressionVisitor{*this}, ast); + if (expr) check(expr); + return expr; +} + +auto ASTRewriter::newInitializer(NewInitializerAST* ast) -> NewInitializerAST* { + if (!ast) return {}; + return visit(NewInitializerVisitor{*this}, ast); +} + +auto ASTRewriter::genericAssociation(GenericAssociationAST* ast) + -> GenericAssociationAST* { + if (!ast) return {}; + return visit(GenericAssociationVisitor{*this}, ast); +} + +auto ASTRewriter::lambdaCapture(LambdaCaptureAST* ast) -> LambdaCaptureAST* { + if (!ast) return {}; + return visit(LambdaCaptureVisitor{*this}, ast); +} + +auto ASTRewriter::newPlacement(NewPlacementAST* ast) -> NewPlacementAST* { + if (!ast) return {}; + + auto copy = make_node(arena()); + + copy->lparenLoc = ast->lparenLoc; + + for (auto expressionList = ©->expressionList; + auto node : ListView{ast->expressionList}) { + auto value = expression(node); + *expressionList = make_list_node(arena(), value); + expressionList = &(*expressionList)->next; + } + + copy->rparenLoc = ast->rparenLoc; + + return copy; +} + +auto ASTRewriter::lambdaSpecifier(LambdaSpecifierAST* ast) + -> LambdaSpecifierAST* { + if (!ast) return {}; + + auto copy = make_node(arena()); + + copy->specifierLoc = ast->specifierLoc; + copy->specifier = ast->specifier; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()( + GeneratedLiteralExpressionAST* ast) -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->literalLoc = ast->literalLoc; + copy->value = ast->value; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(CharLiteralExpressionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->literalLoc = ast->literalLoc; + copy->literal = ast->literal; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(BoolLiteralExpressionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->literalLoc = ast->literalLoc; + copy->isTrue = ast->isTrue; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(IntLiteralExpressionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->literalLoc = ast->literalLoc; + copy->literal = ast->literal; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(FloatLiteralExpressionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->literalLoc = ast->literalLoc; + copy->literal = ast->literal; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()( + NullptrLiteralExpressionAST* ast) -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->literalLoc = ast->literalLoc; + copy->literal = ast->literal; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(StringLiteralExpressionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->literalLoc = ast->literalLoc; + copy->literal = ast->literal; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()( + UserDefinedStringLiteralExpressionAST* ast) -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->literalLoc = ast->literalLoc; + copy->literal = ast->literal; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(ObjectLiteralExpressionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->lparenLoc = ast->lparenLoc; + copy->typeId = rewrite.typeId(ast->typeId); + copy->rparenLoc = ast->rparenLoc; + copy->bracedInitList = + ast_cast(rewrite.expression(ast->bracedInitList)); + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(ThisExpressionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->thisLoc = ast->thisLoc; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()( + GenericSelectionExpressionAST* ast) -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->genericLoc = ast->genericLoc; + copy->lparenLoc = ast->lparenLoc; + copy->expression = rewrite.expression(ast->expression); + copy->commaLoc = ast->commaLoc; + + for (auto genericAssociationList = ©->genericAssociationList; + auto node : ListView{ast->genericAssociationList}) { + auto value = rewrite.genericAssociation(node); + *genericAssociationList = make_list_node(arena(), value); + genericAssociationList = &(*genericAssociationList)->next; + } + + copy->rparenLoc = ast->rparenLoc; + copy->matchedAssocIndex = ast->matchedAssocIndex; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()( + NestedStatementExpressionAST* ast) -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->lparenLoc = ast->lparenLoc; + copy->statement = + ast_cast(rewrite.statement(ast->statement)); + copy->rparenLoc = ast->rparenLoc; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(NestedExpressionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->lparenLoc = ast->lparenLoc; + copy->expression = rewrite.expression(ast->expression); + copy->rparenLoc = ast->rparenLoc; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(IdExpressionAST* ast) + -> ExpressionAST* { + if (auto param = symbol_cast(ast->symbol); + param && param->depth() == 0 && + param->index() < rewrite.templateArguments_.size()) { + auto symbolPtr = + std::get_if(&rewrite.templateArguments_[param->index()]); + + if (!symbolPtr) { + cxx_runtime_error("expected initializer for non-type template parameter"); + } + + auto parameterPack = symbol_cast(*symbolPtr); + + if (parameterPack && parameterPack == rewrite.parameterPack_ && + rewrite.elementIndex_.has_value()) { + auto idx = rewrite.elementIndex_.value(); + auto element = parameterPack->elements()[idx]; + if (auto var = symbol_cast(element)) { + return rewrite.expression(var->initializer()); + } + } + } + + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->nestedNameSpecifier = + rewrite.nestedNameSpecifier(ast->nestedNameSpecifier); + copy->templateLoc = ast->templateLoc; + copy->unqualifiedId = rewrite.unqualifiedId(ast->unqualifiedId); + copy->symbol = ast->symbol; + + if (auto param = symbol_cast(copy->symbol); + param && param->depth() == 0 && + param->index() < rewrite.templateArguments_.size()) { + auto symbolPtr = + std::get_if(&rewrite.templateArguments_[param->index()]); + + if (!symbolPtr) { + cxx_runtime_error("expected initializer for non-type template parameter"); + } + + copy->symbol = *symbolPtr; + copy->type = copy->symbol->type(); + } + copy->isTemplateIntroduced = ast->isTemplateIntroduced; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(LambdaExpressionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->lbracketLoc = ast->lbracketLoc; + copy->captureDefaultLoc = ast->captureDefaultLoc; + + for (auto captureList = ©->captureList; + auto node : ListView{ast->captureList}) { + auto value = rewrite.lambdaCapture(node); + *captureList = make_list_node(arena(), value); + captureList = &(*captureList)->next; + } + + copy->rbracketLoc = ast->rbracketLoc; + copy->lessLoc = ast->lessLoc; + + for (auto templateParameterList = ©->templateParameterList; + auto node : ListView{ast->templateParameterList}) { + auto value = rewrite.templateParameter(node); + *templateParameterList = make_list_node(arena(), value); + templateParameterList = &(*templateParameterList)->next; + } + + copy->greaterLoc = ast->greaterLoc; + copy->templateRequiresClause = + rewrite.requiresClause(ast->templateRequiresClause); + copy->lparenLoc = ast->lparenLoc; + copy->parameterDeclarationClause = + rewrite.parameterDeclarationClause(ast->parameterDeclarationClause); + copy->rparenLoc = ast->rparenLoc; + + for (auto gnuAtributeList = ©->gnuAtributeList; + auto node : ListView{ast->gnuAtributeList}) { + auto value = rewrite.attributeSpecifier(node); + *gnuAtributeList = make_list_node(arena(), value); + gnuAtributeList = &(*gnuAtributeList)->next; + } + + for (auto lambdaSpecifierList = ©->lambdaSpecifierList; + auto node : ListView{ast->lambdaSpecifierList}) { + auto value = rewrite.lambdaSpecifier(node); + *lambdaSpecifierList = make_list_node(arena(), value); + lambdaSpecifierList = &(*lambdaSpecifierList)->next; + } + + { + auto _ = Binder::ScopeGuard(binder()); + + if (copy->parameterDeclarationClause) { + binder()->setScope( + copy->parameterDeclarationClause->functionParametersSymbol); + } + + copy->exceptionSpecifier = + rewrite.exceptionSpecifier(ast->exceptionSpecifier); + + for (auto attributeList = ©->attributeList; + auto node : ListView{ast->attributeList}) { + auto value = rewrite.attributeSpecifier(node); + *attributeList = make_list_node(arena(), value); + attributeList = &(*attributeList)->next; + } + + copy->trailingReturnType = + rewrite.trailingReturnType(ast->trailingReturnType); + copy->requiresClause = rewrite.requiresClause(ast->requiresClause); + } + + copy->statement = + ast_cast(rewrite.statement(ast->statement)); + copy->captureDefault = ast->captureDefault; + copy->symbol = ast->symbol; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(FoldExpressionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->lparenLoc = ast->lparenLoc; + copy->leftExpression = rewrite.expression(ast->leftExpression); + copy->opLoc = ast->opLoc; + copy->ellipsisLoc = ast->ellipsisLoc; + copy->foldOpLoc = ast->foldOpLoc; + copy->rightExpression = rewrite.expression(ast->rightExpression); + copy->rparenLoc = ast->rparenLoc; + copy->op = ast->op; + copy->foldOp = ast->foldOp; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(RightFoldExpressionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->lparenLoc = ast->lparenLoc; + copy->expression = rewrite.expression(ast->expression); + copy->opLoc = ast->opLoc; + copy->ellipsisLoc = ast->ellipsisLoc; + copy->rparenLoc = ast->rparenLoc; + copy->op = ast->op; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(LeftFoldExpressionAST* ast) + -> ExpressionAST* { + if (auto parameterPack = rewrite.getParameterPack(ast->expression)) { + auto savedParameterPack = rewrite.parameterPack_; + std::swap(rewrite.parameterPack_, parameterPack); + + std::vector instantiations; + ExpressionAST* current = nullptr; + + int n = 0; + for (auto element : rewrite.parameterPack_->elements()) { + std::optional index{n}; + std::swap(rewrite.elementIndex_, index); + + auto expression = rewrite.expression(ast->expression); + if (!current) { + current = expression; + } else { + auto binop = make_node(arena()); + binop->valueCategory = current->valueCategory; + binop->type = current->type; + binop->leftExpression = current; + binop->op = ast->op; + binop->opLoc = ast->opLoc; + binop->rightExpression = expression; + current = binop; + } + + std::swap(rewrite.elementIndex_, index); + ++n; + } + + std::swap(rewrite.parameterPack_, parameterPack); + + return current; + } + + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->lparenLoc = ast->lparenLoc; + copy->ellipsisLoc = ast->ellipsisLoc; + copy->opLoc = ast->opLoc; + copy->expression = rewrite.expression(ast->expression); + copy->rparenLoc = ast->rparenLoc; + copy->op = ast->op; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(RequiresExpressionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->requiresLoc = ast->requiresLoc; + copy->lparenLoc = ast->lparenLoc; + copy->parameterDeclarationClause = + rewrite.parameterDeclarationClause(ast->parameterDeclarationClause); + copy->rparenLoc = ast->rparenLoc; + copy->lbraceLoc = ast->lbraceLoc; + + for (auto requirementList = ©->requirementList; + auto node : ListView{ast->requirementList}) { + auto value = rewrite.requirement(node); + *requirementList = make_list_node(arena(), value); + requirementList = &(*requirementList)->next; + } + + copy->rbraceLoc = ast->rbraceLoc; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(VaArgExpressionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->vaArgLoc = ast->vaArgLoc; + copy->lparenLoc = ast->lparenLoc; + copy->expression = rewrite.expression(ast->expression); + copy->commaLoc = ast->commaLoc; + copy->typeId = rewrite.typeId(ast->typeId); + copy->rparenLoc = ast->rparenLoc; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(SubscriptExpressionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->baseExpression = rewrite.expression(ast->baseExpression); + copy->lbracketLoc = ast->lbracketLoc; + copy->indexExpression = rewrite.expression(ast->indexExpression); + copy->rbracketLoc = ast->rbracketLoc; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(CallExpressionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->baseExpression = rewrite.expression(ast->baseExpression); + copy->lparenLoc = ast->lparenLoc; + + for (auto expressionList = ©->expressionList; + auto node : ListView{ast->expressionList}) { + auto value = rewrite.expression(node); + *expressionList = make_list_node(arena(), value); + expressionList = &(*expressionList)->next; + } + + copy->rparenLoc = ast->rparenLoc; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(TypeConstructionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->typeSpecifier = rewrite.specifier(ast->typeSpecifier); + copy->lparenLoc = ast->lparenLoc; + + for (auto expressionList = ©->expressionList; + auto node : ListView{ast->expressionList}) { + auto value = rewrite.expression(node); + *expressionList = make_list_node(arena(), value); + expressionList = &(*expressionList)->next; + } + + copy->rparenLoc = ast->rparenLoc; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(BracedTypeConstructionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->typeSpecifier = rewrite.specifier(ast->typeSpecifier); + copy->bracedInitList = + ast_cast(rewrite.expression(ast->bracedInitList)); + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(SpliceMemberExpressionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->baseExpression = rewrite.expression(ast->baseExpression); + copy->accessLoc = ast->accessLoc; + copy->templateLoc = ast->templateLoc; + copy->splicer = rewrite.splicer(ast->splicer); + copy->symbol = ast->symbol; + copy->accessOp = ast->accessOp; + copy->isTemplateIntroduced = ast->isTemplateIntroduced; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(MemberExpressionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->baseExpression = rewrite.expression(ast->baseExpression); + copy->accessLoc = ast->accessLoc; + copy->nestedNameSpecifier = + rewrite.nestedNameSpecifier(ast->nestedNameSpecifier); + copy->templateLoc = ast->templateLoc; + copy->unqualifiedId = rewrite.unqualifiedId(ast->unqualifiedId); + copy->symbol = ast->symbol; + copy->accessOp = ast->accessOp; + copy->isTemplateIntroduced = ast->isTemplateIntroduced; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(PostIncrExpressionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->baseExpression = rewrite.expression(ast->baseExpression); + copy->opLoc = ast->opLoc; + copy->op = ast->op; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(CppCastExpressionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->castLoc = ast->castLoc; + copy->lessLoc = ast->lessLoc; + copy->typeId = rewrite.typeId(ast->typeId); + copy->greaterLoc = ast->greaterLoc; + copy->lparenLoc = ast->lparenLoc; + copy->expression = rewrite.expression(ast->expression); + copy->rparenLoc = ast->rparenLoc; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()( + BuiltinBitCastExpressionAST* ast) -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->castLoc = ast->castLoc; + copy->lparenLoc = ast->lparenLoc; + copy->typeId = rewrite.typeId(ast->typeId); + copy->commaLoc = ast->commaLoc; + copy->expression = rewrite.expression(ast->expression); + copy->rparenLoc = ast->rparenLoc; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()( + BuiltinOffsetofExpressionAST* ast) -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->offsetofLoc = ast->offsetofLoc; + copy->lparenLoc = ast->lparenLoc; + copy->typeId = rewrite.typeId(ast->typeId); + copy->commaLoc = ast->commaLoc; + copy->identifierLoc = ast->identifierLoc; + + for (auto designatorList = ©->designatorList; + auto node : ListView{ast->designatorList}) { + auto value = rewrite.designator(node); + *designatorList = make_list_node(arena(), value); + designatorList = &(*designatorList)->next; + } + + copy->rparenLoc = ast->rparenLoc; + copy->identifier = ast->identifier; + copy->symbol = ast->symbol; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(TypeidExpressionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->typeidLoc = ast->typeidLoc; + copy->lparenLoc = ast->lparenLoc; + copy->expression = rewrite.expression(ast->expression); + copy->rparenLoc = ast->rparenLoc; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(TypeidOfTypeExpressionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->typeidLoc = ast->typeidLoc; + copy->lparenLoc = ast->lparenLoc; + copy->typeId = rewrite.typeId(ast->typeId); + copy->rparenLoc = ast->rparenLoc; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(SpliceExpressionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->splicer = rewrite.splicer(ast->splicer); + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()( + GlobalScopeReflectExpressionAST* ast) -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->caretLoc = ast->caretLoc; + copy->scopeLoc = ast->scopeLoc; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()( + NamespaceReflectExpressionAST* ast) -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->caretLoc = ast->caretLoc; + copy->identifierLoc = ast->identifierLoc; + copy->identifier = ast->identifier; + copy->symbol = ast->symbol; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(TypeIdReflectExpressionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->caretLoc = ast->caretLoc; + copy->typeId = rewrite.typeId(ast->typeId); + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(ReflectExpressionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->caretLoc = ast->caretLoc; + copy->expression = rewrite.expression(ast->expression); + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(LabelAddressExpressionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->ampAmpLoc = ast->ampAmpLoc; + copy->identifierLoc = ast->identifierLoc; + copy->identifier = ast->identifier; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(UnaryExpressionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->opLoc = ast->opLoc; + copy->expression = rewrite.expression(ast->expression); + copy->op = ast->op; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(AwaitExpressionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->awaitLoc = ast->awaitLoc; + copy->expression = rewrite.expression(ast->expression); + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(SizeofExpressionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->sizeofLoc = ast->sizeofLoc; + copy->expression = rewrite.expression(ast->expression); + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(SizeofTypeExpressionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->sizeofLoc = ast->sizeofLoc; + copy->lparenLoc = ast->lparenLoc; + copy->typeId = rewrite.typeId(ast->typeId); + copy->rparenLoc = ast->rparenLoc; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(SizeofPackExpressionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->sizeofLoc = ast->sizeofLoc; + copy->ellipsisLoc = ast->ellipsisLoc; + copy->lparenLoc = ast->lparenLoc; + copy->identifierLoc = ast->identifierLoc; + copy->rparenLoc = ast->rparenLoc; + copy->identifier = ast->identifier; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(AlignofTypeExpressionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->alignofLoc = ast->alignofLoc; + copy->lparenLoc = ast->lparenLoc; + copy->typeId = rewrite.typeId(ast->typeId); + copy->rparenLoc = ast->rparenLoc; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(AlignofExpressionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->alignofLoc = ast->alignofLoc; + copy->expression = rewrite.expression(ast->expression); + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(NoexceptExpressionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->noexceptLoc = ast->noexceptLoc; + copy->lparenLoc = ast->lparenLoc; + copy->expression = rewrite.expression(ast->expression); + copy->rparenLoc = ast->rparenLoc; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(NewExpressionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->scopeLoc = ast->scopeLoc; + copy->newLoc = ast->newLoc; + copy->newPlacement = rewrite.newPlacement(ast->newPlacement); + copy->lparenLoc = ast->lparenLoc; + + auto typeSpecifierListCtx = DeclSpecs{rewriter()}; + for (auto typeSpecifierList = ©->typeSpecifierList; + auto node : ListView{ast->typeSpecifierList}) { + auto value = rewrite.specifier(node); + *typeSpecifierList = make_list_node(arena(), value); + typeSpecifierList = &(*typeSpecifierList)->next; + typeSpecifierListCtx.accept(value); + } + typeSpecifierListCtx.finish(); + + copy->declarator = rewrite.declarator(ast->declarator); + + auto declaratorDecl = Decl{typeSpecifierListCtx, copy->declarator}; + auto declaratorType = getDeclaratorType(translationUnit(), copy->declarator, + typeSpecifierListCtx.type()); + copy->rparenLoc = ast->rparenLoc; + copy->newInitalizer = rewrite.newInitializer(ast->newInitalizer); + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(DeleteExpressionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->scopeLoc = ast->scopeLoc; + copy->deleteLoc = ast->deleteLoc; + copy->lbracketLoc = ast->lbracketLoc; + copy->rbracketLoc = ast->rbracketLoc; + copy->expression = rewrite.expression(ast->expression); + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(CastExpressionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->lparenLoc = ast->lparenLoc; + copy->typeId = rewrite.typeId(ast->typeId); + copy->rparenLoc = ast->rparenLoc; + copy->expression = rewrite.expression(ast->expression); + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(ImplicitCastExpressionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->expression = rewrite.expression(ast->expression); + copy->castKind = ast->castKind; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(BinaryExpressionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->leftExpression = rewrite.expression(ast->leftExpression); + copy->opLoc = ast->opLoc; + copy->rightExpression = rewrite.expression(ast->rightExpression); + copy->op = ast->op; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(ConditionalExpressionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->condition = rewrite.expression(ast->condition); + copy->questionLoc = ast->questionLoc; + copy->iftrueExpression = rewrite.expression(ast->iftrueExpression); + copy->colonLoc = ast->colonLoc; + copy->iffalseExpression = rewrite.expression(ast->iffalseExpression); + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(YieldExpressionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->yieldLoc = ast->yieldLoc; + copy->expression = rewrite.expression(ast->expression); + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(ThrowExpressionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->throwLoc = ast->throwLoc; + copy->expression = rewrite.expression(ast->expression); + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(AssignmentExpressionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->leftExpression = rewrite.expression(ast->leftExpression); + copy->opLoc = ast->opLoc; + copy->rightExpression = rewrite.expression(ast->rightExpression); + copy->op = ast->op; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()( + CompoundAssignmentExpressionAST* ast) -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->leftExpression = rewrite.expression(ast->leftExpression); + copy->opLoc = ast->opLoc; + copy->rightExpression = rewrite.expression(ast->rightExpression); + copy->op = ast->op; + copy->leftCastKind = ast->leftCastKind; + copy->leftCastType = ast->leftCastType; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(PackExpansionExpressionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->expression = rewrite.expression(ast->expression); + copy->ellipsisLoc = ast->ellipsisLoc; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()( + DesignatedInitializerClauseAST* ast) -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + + for (auto designatorList = ©->designatorList; + auto node : ListView{ast->designatorList}) { + auto value = rewrite.designator(node); + *designatorList = make_list_node(arena(), value); + designatorList = &(*designatorList)->next; + } + + copy->initializer = rewrite.expression(ast->initializer); + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(TypeTraitExpressionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->typeTraitLoc = ast->typeTraitLoc; + copy->lparenLoc = ast->lparenLoc; + + for (auto typeIdList = ©->typeIdList; + auto node : ListView{ast->typeIdList}) { + auto value = rewrite.typeId(node); + *typeIdList = make_list_node(arena(), value); + typeIdList = &(*typeIdList)->next; + } + + copy->rparenLoc = ast->rparenLoc; + copy->typeTrait = ast->typeTrait; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(ConditionExpressionAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + + for (auto attributeList = ©->attributeList; + auto node : ListView{ast->attributeList}) { + auto value = rewrite.attributeSpecifier(node); + *attributeList = make_list_node(arena(), value); + attributeList = &(*attributeList)->next; + } + + auto declSpecifierListCtx = DeclSpecs{rewriter()}; + for (auto declSpecifierList = ©->declSpecifierList; + auto node : ListView{ast->declSpecifierList}) { + auto value = rewrite.specifier(node); + *declSpecifierList = make_list_node(arena(), value); + declSpecifierList = &(*declSpecifierList)->next; + declSpecifierListCtx.accept(value); + } + declSpecifierListCtx.finish(); + + copy->declarator = rewrite.declarator(ast->declarator); + + auto declaratorDecl = Decl{declSpecifierListCtx, copy->declarator}; + auto declaratorType = getDeclaratorType(translationUnit(), copy->declarator, + declSpecifierListCtx.type()); + copy->initializer = rewrite.expression(ast->initializer); + copy->symbol = ast->symbol; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(EqualInitializerAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->equalLoc = ast->equalLoc; + copy->expression = rewrite.expression(ast->expression); + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(BracedInitListAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->lbraceLoc = ast->lbraceLoc; + + for (auto expressionList = ©->expressionList; + auto node : ListView{ast->expressionList}) { + auto value = rewrite.expression(node); + *expressionList = make_list_node(arena(), value); + expressionList = &(*expressionList)->next; + } + + copy->commaLoc = ast->commaLoc; + copy->rbraceLoc = ast->rbraceLoc; + + return copy; +} + +auto ASTRewriter::ExpressionVisitor::operator()(ParenInitializerAST* ast) + -> ExpressionAST* { + auto copy = make_node(arena()); + + copy->valueCategory = ast->valueCategory; + copy->type = ast->type; + copy->lparenLoc = ast->lparenLoc; + + for (auto expressionList = ©->expressionList; + auto node : ListView{ast->expressionList}) { + auto value = rewrite.expression(node); + *expressionList = make_list_node(arena(), value); + expressionList = &(*expressionList)->next; + } + + copy->rparenLoc = ast->rparenLoc; + + return copy; +} + +auto ASTRewriter::NewInitializerVisitor::operator()(NewParenInitializerAST* ast) + -> NewInitializerAST* { + auto copy = make_node(arena()); + + copy->lparenLoc = ast->lparenLoc; + + for (auto expressionList = ©->expressionList; + auto node : ListView{ast->expressionList}) { + auto value = rewrite.expression(node); + *expressionList = make_list_node(arena(), value); + expressionList = &(*expressionList)->next; + } + + copy->rparenLoc = ast->rparenLoc; + + return copy; +} + +auto ASTRewriter::NewInitializerVisitor::operator()( + NewBracedInitializerAST* ast) -> NewInitializerAST* { + auto copy = make_node(arena()); + + copy->bracedInitList = + ast_cast(rewrite.expression(ast->bracedInitList)); + + return copy; +} + +auto ASTRewriter::GenericAssociationVisitor::operator()( + DefaultGenericAssociationAST* ast) -> GenericAssociationAST* { + auto copy = make_node(arena()); + + copy->defaultLoc = ast->defaultLoc; + copy->colonLoc = ast->colonLoc; + copy->expression = rewrite.expression(ast->expression); + + return copy; +} + +auto ASTRewriter::GenericAssociationVisitor::operator()( + TypeGenericAssociationAST* ast) -> GenericAssociationAST* { + auto copy = make_node(arena()); + + copy->typeId = rewrite.typeId(ast->typeId); + copy->colonLoc = ast->colonLoc; + copy->expression = rewrite.expression(ast->expression); + + return copy; +} + +auto ASTRewriter::LambdaCaptureVisitor::operator()(ThisLambdaCaptureAST* ast) + -> LambdaCaptureAST* { + auto copy = make_node(arena()); + + copy->thisLoc = ast->thisLoc; + + return copy; +} + +auto ASTRewriter::LambdaCaptureVisitor::operator()( + DerefThisLambdaCaptureAST* ast) -> LambdaCaptureAST* { + auto copy = make_node(arena()); + + copy->starLoc = ast->starLoc; + copy->thisLoc = ast->thisLoc; + + return copy; +} + +auto ASTRewriter::LambdaCaptureVisitor::operator()(SimpleLambdaCaptureAST* ast) + -> LambdaCaptureAST* { + auto copy = make_node(arena()); + + copy->identifierLoc = ast->identifierLoc; + copy->ellipsisLoc = ast->ellipsisLoc; + copy->identifier = ast->identifier; + + return copy; +} + +auto ASTRewriter::LambdaCaptureVisitor::operator()(RefLambdaCaptureAST* ast) + -> LambdaCaptureAST* { + auto copy = make_node(arena()); + + copy->ampLoc = ast->ampLoc; + copy->identifierLoc = ast->identifierLoc; + copy->ellipsisLoc = ast->ellipsisLoc; + copy->identifier = ast->identifier; + + return copy; +} + +auto ASTRewriter::LambdaCaptureVisitor::operator()(RefInitLambdaCaptureAST* ast) + -> LambdaCaptureAST* { + auto copy = make_node(arena()); + + copy->ampLoc = ast->ampLoc; + copy->ellipsisLoc = ast->ellipsisLoc; + copy->identifierLoc = ast->identifierLoc; + copy->initializer = rewrite.expression(ast->initializer); + copy->identifier = ast->identifier; + + return copy; +} + +auto ASTRewriter::LambdaCaptureVisitor::operator()(InitLambdaCaptureAST* ast) + -> LambdaCaptureAST* { + auto copy = make_node(arena()); + + copy->ellipsisLoc = ast->ellipsisLoc; + copy->identifierLoc = ast->identifierLoc; + copy->initializer = rewrite.expression(ast->initializer); + copy->identifier = ast->identifier; + + return copy; +} + +} // namespace cxx diff --git a/src/parser/cxx/ast_rewriter_names.cc b/src/parser/cxx/ast_rewriter_names.cc new file mode 100644 index 00000000..afa8d377 --- /dev/null +++ b/src/parser/cxx/ast_rewriter_names.cc @@ -0,0 +1,325 @@ +// Copyright (c) 2025 Roberto Raggi +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#include + +// cxx +#include +#include +#include +#include +#include +#include + +#include + +namespace cxx { + +struct ASTRewriter::UnqualifiedIdVisitor { + ASTRewriter& rewrite; + [[nodiscard]] auto translationUnit() const -> TranslationUnit* { + return rewrite.unit_; + } + + [[nodiscard]] auto control() const -> Control* { return rewrite.control(); } + [[nodiscard]] auto arena() const -> Arena* { return rewrite.arena(); } + [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } + [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } + + [[nodiscard]] auto operator()(NameIdAST* ast) -> UnqualifiedIdAST*; + + [[nodiscard]] auto operator()(DestructorIdAST* ast) -> UnqualifiedIdAST*; + + [[nodiscard]] auto operator()(DecltypeIdAST* ast) -> UnqualifiedIdAST*; + + [[nodiscard]] auto operator()(OperatorFunctionIdAST* ast) + -> UnqualifiedIdAST*; + + [[nodiscard]] auto operator()(LiteralOperatorIdAST* ast) -> UnqualifiedIdAST*; + + [[nodiscard]] auto operator()(ConversionFunctionIdAST* ast) + -> UnqualifiedIdAST*; + + [[nodiscard]] auto operator()(SimpleTemplateIdAST* ast) -> UnqualifiedIdAST*; + + [[nodiscard]] auto operator()(LiteralOperatorTemplateIdAST* ast) + -> UnqualifiedIdAST*; + + [[nodiscard]] auto operator()(OperatorFunctionTemplateIdAST* ast) + -> UnqualifiedIdAST*; +}; + +struct ASTRewriter::NestedNameSpecifierVisitor { + ASTRewriter& rewrite; + [[nodiscard]] auto translationUnit() const -> TranslationUnit* { + return rewrite.unit_; + } + + [[nodiscard]] auto control() const -> Control* { return rewrite.control(); } + [[nodiscard]] auto arena() const -> Arena* { return rewrite.arena(); } + [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } + [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } + + [[nodiscard]] auto operator()(GlobalNestedNameSpecifierAST* ast) + -> NestedNameSpecifierAST*; + + [[nodiscard]] auto operator()(SimpleNestedNameSpecifierAST* ast) + -> NestedNameSpecifierAST*; + + [[nodiscard]] auto operator()(DecltypeNestedNameSpecifierAST* ast) + -> NestedNameSpecifierAST*; + + [[nodiscard]] auto operator()(TemplateNestedNameSpecifierAST* ast) + -> NestedNameSpecifierAST*; +}; + +struct ASTRewriter::TemplateArgumentVisitor { + ASTRewriter& rewrite; + [[nodiscard]] auto translationUnit() const -> TranslationUnit* { + return rewrite.unit_; + } + + [[nodiscard]] auto control() const -> Control* { return rewrite.control(); } + [[nodiscard]] auto arena() const -> Arena* { return rewrite.arena(); } + [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } + [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } + + [[nodiscard]] auto operator()(TypeTemplateArgumentAST* ast) + -> TemplateArgumentAST*; + + [[nodiscard]] auto operator()(ExpressionTemplateArgumentAST* ast) + -> TemplateArgumentAST*; +}; + +auto ASTRewriter::unqualifiedId(UnqualifiedIdAST* ast) -> UnqualifiedIdAST* { + if (!ast) return {}; + return visit(UnqualifiedIdVisitor{*this}, ast); +} + +auto ASTRewriter::nestedNameSpecifier(NestedNameSpecifierAST* ast) + -> NestedNameSpecifierAST* { + if (!ast) return {}; + return visit(NestedNameSpecifierVisitor{*this}, ast); +} + +auto ASTRewriter::templateArgument(TemplateArgumentAST* ast) + -> TemplateArgumentAST* { + if (!ast) return {}; + return visit(TemplateArgumentVisitor{*this}, ast); +} + +auto ASTRewriter::UnqualifiedIdVisitor::operator()(NameIdAST* ast) + -> UnqualifiedIdAST* { + auto copy = make_node(arena()); + + copy->identifierLoc = ast->identifierLoc; + copy->identifier = ast->identifier; + + return copy; +} + +auto ASTRewriter::UnqualifiedIdVisitor::operator()(DestructorIdAST* ast) + -> UnqualifiedIdAST* { + auto copy = make_node(arena()); + + copy->tildeLoc = ast->tildeLoc; + copy->id = rewrite.unqualifiedId(ast->id); + + return copy; +} + +auto ASTRewriter::UnqualifiedIdVisitor::operator()(DecltypeIdAST* ast) + -> UnqualifiedIdAST* { + auto copy = make_node(arena()); + + copy->decltypeSpecifier = + ast_cast(rewrite.specifier(ast->decltypeSpecifier)); + + return copy; +} + +auto ASTRewriter::UnqualifiedIdVisitor::operator()(OperatorFunctionIdAST* ast) + -> UnqualifiedIdAST* { + auto copy = make_node(arena()); + + copy->operatorLoc = ast->operatorLoc; + copy->opLoc = ast->opLoc; + copy->openLoc = ast->openLoc; + copy->closeLoc = ast->closeLoc; + copy->op = ast->op; + + return copy; +} + +auto ASTRewriter::UnqualifiedIdVisitor::operator()(LiteralOperatorIdAST* ast) + -> UnqualifiedIdAST* { + auto copy = make_node(arena()); + + copy->operatorLoc = ast->operatorLoc; + copy->literalLoc = ast->literalLoc; + copy->identifierLoc = ast->identifierLoc; + copy->literal = ast->literal; + copy->identifier = ast->identifier; + + return copy; +} + +auto ASTRewriter::UnqualifiedIdVisitor::operator()(ConversionFunctionIdAST* ast) + -> UnqualifiedIdAST* { + auto copy = make_node(arena()); + + copy->operatorLoc = ast->operatorLoc; + copy->typeId = rewrite.typeId(ast->typeId); + + return copy; +} + +auto ASTRewriter::UnqualifiedIdVisitor::operator()(SimpleTemplateIdAST* ast) + -> UnqualifiedIdAST* { + auto copy = make_node(arena()); + + copy->identifierLoc = ast->identifierLoc; + copy->lessLoc = ast->lessLoc; + + for (auto templateArgumentList = ©->templateArgumentList; + auto node : ListView{ast->templateArgumentList}) { + auto value = rewrite.templateArgument(node); + *templateArgumentList = make_list_node(arena(), value); + templateArgumentList = &(*templateArgumentList)->next; + } + + copy->greaterLoc = ast->greaterLoc; + copy->identifier = ast->identifier; + copy->symbol = ast->symbol; + + return copy; +} + +auto ASTRewriter::UnqualifiedIdVisitor::operator()( + LiteralOperatorTemplateIdAST* ast) -> UnqualifiedIdAST* { + auto copy = make_node(arena()); + + copy->literalOperatorId = ast_cast( + rewrite.unqualifiedId(ast->literalOperatorId)); + copy->lessLoc = ast->lessLoc; + + for (auto templateArgumentList = ©->templateArgumentList; + auto node : ListView{ast->templateArgumentList}) { + auto value = rewrite.templateArgument(node); + *templateArgumentList = make_list_node(arena(), value); + templateArgumentList = &(*templateArgumentList)->next; + } + + copy->greaterLoc = ast->greaterLoc; + + return copy; +} + +auto ASTRewriter::UnqualifiedIdVisitor::operator()( + OperatorFunctionTemplateIdAST* ast) -> UnqualifiedIdAST* { + auto copy = make_node(arena()); + + copy->operatorFunctionId = ast_cast( + rewrite.unqualifiedId(ast->operatorFunctionId)); + copy->lessLoc = ast->lessLoc; + + for (auto templateArgumentList = ©->templateArgumentList; + auto node : ListView{ast->templateArgumentList}) { + auto value = rewrite.templateArgument(node); + *templateArgumentList = make_list_node(arena(), value); + templateArgumentList = &(*templateArgumentList)->next; + } + + copy->greaterLoc = ast->greaterLoc; + + return copy; +} + +auto ASTRewriter::NestedNameSpecifierVisitor::operator()( + GlobalNestedNameSpecifierAST* ast) -> NestedNameSpecifierAST* { + auto copy = make_node(arena()); + + copy->symbol = ast->symbol; + copy->scopeLoc = ast->scopeLoc; + + return copy; +} + +auto ASTRewriter::NestedNameSpecifierVisitor::operator()( + SimpleNestedNameSpecifierAST* ast) -> NestedNameSpecifierAST* { + auto copy = make_node(arena()); + + copy->symbol = ast->symbol; + copy->nestedNameSpecifier = + rewrite.nestedNameSpecifier(ast->nestedNameSpecifier); + copy->identifierLoc = ast->identifierLoc; + copy->identifier = ast->identifier; + copy->scopeLoc = ast->scopeLoc; + + return copy; +} + +auto ASTRewriter::NestedNameSpecifierVisitor::operator()( + DecltypeNestedNameSpecifierAST* ast) -> NestedNameSpecifierAST* { + auto copy = make_node(arena()); + + copy->symbol = ast->symbol; + copy->decltypeSpecifier = + ast_cast(rewrite.specifier(ast->decltypeSpecifier)); + copy->scopeLoc = ast->scopeLoc; + + return copy; +} + +auto ASTRewriter::NestedNameSpecifierVisitor::operator()( + TemplateNestedNameSpecifierAST* ast) -> NestedNameSpecifierAST* { + auto copy = make_node(arena()); + + copy->symbol = ast->symbol; + copy->nestedNameSpecifier = + rewrite.nestedNameSpecifier(ast->nestedNameSpecifier); + copy->templateLoc = ast->templateLoc; + copy->templateId = + ast_cast(rewrite.unqualifiedId(ast->templateId)); + copy->scopeLoc = ast->scopeLoc; + copy->isTemplateIntroduced = ast->isTemplateIntroduced; + + return copy; +} + +auto ASTRewriter::TemplateArgumentVisitor::operator()( + TypeTemplateArgumentAST* ast) -> TemplateArgumentAST* { + auto copy = make_node(arena()); + + copy->typeId = rewrite.typeId(ast->typeId); + + return copy; +} + +auto ASTRewriter::TemplateArgumentVisitor::operator()( + ExpressionTemplateArgumentAST* ast) -> TemplateArgumentAST* { + auto copy = make_node(arena()); + + copy->expression = rewrite.expression(ast->expression); + + return copy; +} + +} // namespace cxx diff --git a/src/parser/cxx/ast_rewriter_specifiers.cc b/src/parser/cxx/ast_rewriter_specifiers.cc new file mode 100644 index 00000000..ecb0ece0 --- /dev/null +++ b/src/parser/cxx/ast_rewriter_specifiers.cc @@ -0,0 +1,947 @@ +// Copyright (c) 2025 Roberto Raggi +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#include + +// cxx +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace cxx { + +struct ASTRewriter::SpecifierVisitor { + ASTRewriter& rewrite; + [[nodiscard]] auto translationUnit() const -> TranslationUnit* { + return rewrite.unit_; + } + + [[nodiscard]] auto control() const -> Control* { return rewrite.control(); } + [[nodiscard]] auto arena() const -> Arena* { return rewrite.arena(); } + [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } + [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } + + [[nodiscard]] auto operator()(GeneratedTypeSpecifierAST* ast) + -> SpecifierAST*; + + [[nodiscard]] auto operator()(TypedefSpecifierAST* ast) -> SpecifierAST*; + + [[nodiscard]] auto operator()(FriendSpecifierAST* ast) -> SpecifierAST*; + + [[nodiscard]] auto operator()(ConstevalSpecifierAST* ast) -> SpecifierAST*; + + [[nodiscard]] auto operator()(ConstinitSpecifierAST* ast) -> SpecifierAST*; + + [[nodiscard]] auto operator()(ConstexprSpecifierAST* ast) -> SpecifierAST*; + + [[nodiscard]] auto operator()(InlineSpecifierAST* ast) -> SpecifierAST*; + + [[nodiscard]] auto operator()(NoreturnSpecifierAST* ast) -> SpecifierAST*; + + [[nodiscard]] auto operator()(StaticSpecifierAST* ast) -> SpecifierAST*; + + [[nodiscard]] auto operator()(ExternSpecifierAST* ast) -> SpecifierAST*; + + [[nodiscard]] auto operator()(RegisterSpecifierAST* ast) -> SpecifierAST*; + + [[nodiscard]] auto operator()(ThreadLocalSpecifierAST* ast) -> SpecifierAST*; + + [[nodiscard]] auto operator()(ThreadSpecifierAST* ast) -> SpecifierAST*; + + [[nodiscard]] auto operator()(MutableSpecifierAST* ast) -> SpecifierAST*; + + [[nodiscard]] auto operator()(VirtualSpecifierAST* ast) -> SpecifierAST*; + + [[nodiscard]] auto operator()(ExplicitSpecifierAST* ast) -> SpecifierAST*; + + [[nodiscard]] auto operator()(AutoTypeSpecifierAST* ast) -> SpecifierAST*; + + [[nodiscard]] auto operator()(VoidTypeSpecifierAST* ast) -> SpecifierAST*; + + [[nodiscard]] auto operator()(SizeTypeSpecifierAST* ast) -> SpecifierAST*; + + [[nodiscard]] auto operator()(SignTypeSpecifierAST* ast) -> SpecifierAST*; + + [[nodiscard]] auto operator()(VaListTypeSpecifierAST* ast) -> SpecifierAST*; + + [[nodiscard]] auto operator()(IntegralTypeSpecifierAST* ast) -> SpecifierAST*; + + [[nodiscard]] auto operator()(FloatingPointTypeSpecifierAST* ast) + -> SpecifierAST*; + + [[nodiscard]] auto operator()(ComplexTypeSpecifierAST* ast) -> SpecifierAST*; + + [[nodiscard]] auto operator()(NamedTypeSpecifierAST* ast) -> SpecifierAST*; + + [[nodiscard]] auto operator()(AtomicTypeSpecifierAST* ast) -> SpecifierAST*; + + [[nodiscard]] auto operator()(UnderlyingTypeSpecifierAST* ast) + -> SpecifierAST*; + + [[nodiscard]] auto operator()(ElaboratedTypeSpecifierAST* ast) + -> SpecifierAST*; + + [[nodiscard]] auto operator()(DecltypeAutoSpecifierAST* ast) -> SpecifierAST*; + + [[nodiscard]] auto operator()(DecltypeSpecifierAST* ast) -> SpecifierAST*; + + [[nodiscard]] auto operator()(PlaceholderTypeSpecifierAST* ast) + -> SpecifierAST*; + + [[nodiscard]] auto operator()(ConstQualifierAST* ast) -> SpecifierAST*; + + [[nodiscard]] auto operator()(VolatileQualifierAST* ast) -> SpecifierAST*; + + [[nodiscard]] auto operator()(AtomicQualifierAST* ast) -> SpecifierAST*; + + [[nodiscard]] auto operator()(RestrictQualifierAST* ast) -> SpecifierAST*; + + [[nodiscard]] auto operator()(EnumSpecifierAST* ast) -> SpecifierAST*; + + [[nodiscard]] auto operator()(ClassSpecifierAST* ast) -> SpecifierAST*; + + [[nodiscard]] auto operator()(TypenameSpecifierAST* ast) -> SpecifierAST*; + + [[nodiscard]] auto operator()(SplicerTypeSpecifierAST* ast) -> SpecifierAST*; +}; + +struct ASTRewriter::AttributeSpecifierVisitor { + ASTRewriter& rewrite; + [[nodiscard]] auto translationUnit() const -> TranslationUnit* { + return rewrite.unit_; + } + + [[nodiscard]] auto control() const -> Control* { return rewrite.control(); } + [[nodiscard]] auto arena() const -> Arena* { return rewrite.arena(); } + [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } + [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } + + [[nodiscard]] auto operator()(CxxAttributeAST* ast) -> AttributeSpecifierAST*; + + [[nodiscard]] auto operator()(GccAttributeAST* ast) -> AttributeSpecifierAST*; + + [[nodiscard]] auto operator()(AlignasAttributeAST* ast) + -> AttributeSpecifierAST*; + + [[nodiscard]] auto operator()(AlignasTypeAttributeAST* ast) + -> AttributeSpecifierAST*; + + [[nodiscard]] auto operator()(AsmAttributeAST* ast) -> AttributeSpecifierAST*; +}; + +struct ASTRewriter::AttributeTokenVisitor { + ASTRewriter& rewrite; + [[nodiscard]] auto translationUnit() const -> TranslationUnit* { + return rewrite.unit_; + } + + [[nodiscard]] auto control() const -> Control* { return rewrite.control(); } + [[nodiscard]] auto arena() const -> Arena* { return rewrite.arena(); } + [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } + [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } + + [[nodiscard]] auto operator()(ScopedAttributeTokenAST* ast) + -> AttributeTokenAST*; + + [[nodiscard]] auto operator()(SimpleAttributeTokenAST* ast) + -> AttributeTokenAST*; +}; + +auto ASTRewriter::specifier(SpecifierAST* ast) -> SpecifierAST* { + if (!ast) return {}; + auto specifier = visit(SpecifierVisitor{*this}, ast); + return specifier; +} + +auto ASTRewriter::attributeSpecifier(AttributeSpecifierAST* ast) + -> AttributeSpecifierAST* { + if (!ast) return {}; + return visit(AttributeSpecifierVisitor{*this}, ast); +} + +auto ASTRewriter::attributeToken(AttributeTokenAST* ast) -> AttributeTokenAST* { + if (!ast) return {}; + return visit(AttributeTokenVisitor{*this}, ast); +} + +auto ASTRewriter::baseSpecifier(BaseSpecifierAST* ast) -> BaseSpecifierAST* { + if (!ast) return {}; + + auto copy = make_node(arena()); + + for (auto attributeList = ©->attributeList; + auto node : ListView{ast->attributeList}) { + auto value = attributeSpecifier(node); + *attributeList = make_list_node(arena(), value); + attributeList = &(*attributeList)->next; + } + + copy->virtualOrAccessLoc = ast->virtualOrAccessLoc; + copy->otherVirtualOrAccessLoc = ast->otherVirtualOrAccessLoc; + copy->nestedNameSpecifier = nestedNameSpecifier(ast->nestedNameSpecifier); + copy->templateLoc = ast->templateLoc; + copy->unqualifiedId = unqualifiedId(ast->unqualifiedId); + copy->ellipsisLoc = ast->ellipsisLoc; + copy->isTemplateIntroduced = ast->isTemplateIntroduced; + copy->isVirtual = ast->isVirtual; + copy->isVariadic = ast->isVariadic; + copy->accessSpecifier = ast->accessSpecifier; + copy->symbol = ast->symbol; + + binder_.bind(ast); + + return copy; +} + +auto ASTRewriter::enumerator(EnumeratorAST* ast) -> EnumeratorAST* { + if (!ast) return {}; + + auto copy = make_node(arena()); + + copy->identifierLoc = ast->identifierLoc; + + for (auto attributeList = ©->attributeList; + auto node : ListView{ast->attributeList}) { + auto value = attributeSpecifier(node); + *attributeList = make_list_node(arena(), value); + attributeList = &(*attributeList)->next; + } + + copy->equalLoc = ast->equalLoc; + copy->expression = expression(ast->expression); + copy->identifier = ast->identifier; + copy->symbol = ast->symbol; + + return copy; +} + +auto ASTRewriter::attributeArgumentClause(AttributeArgumentClauseAST* ast) + -> AttributeArgumentClauseAST* { + if (!ast) return {}; + + auto copy = make_node(arena()); + + copy->lparenLoc = ast->lparenLoc; + copy->rparenLoc = ast->rparenLoc; + + return copy; +} + +auto ASTRewriter::attribute(AttributeAST* ast) -> AttributeAST* { + if (!ast) return {}; + + auto copy = make_node(arena()); + + copy->attributeToken = attributeToken(ast->attributeToken); + copy->attributeArgumentClause = + attributeArgumentClause(ast->attributeArgumentClause); + copy->ellipsisLoc = ast->ellipsisLoc; + + return copy; +} + +auto ASTRewriter::attributeUsingPrefix(AttributeUsingPrefixAST* ast) + -> AttributeUsingPrefixAST* { + if (!ast) return {}; + + auto copy = make_node(arena()); + + copy->usingLoc = ast->usingLoc; + copy->attributeNamespaceLoc = ast->attributeNamespaceLoc; + copy->colonLoc = ast->colonLoc; + + return copy; +} + +auto ASTRewriter::typeId(TypeIdAST* ast) -> TypeIdAST* { + if (!ast) return {}; + + auto copy = make_node(arena()); + + auto typeSpecifierListCtx = DeclSpecs{rewriter()}; + for (auto typeSpecifierList = ©->typeSpecifierList; + auto node : ListView{ast->typeSpecifierList}) { + auto value = specifier(node); + *typeSpecifierList = make_list_node(arena(), value); + typeSpecifierList = &(*typeSpecifierList)->next; + typeSpecifierListCtx.accept(value); + } + typeSpecifierListCtx.finish(); + + copy->declarator = declarator(ast->declarator); + + auto declaratorDecl = Decl{typeSpecifierListCtx, copy->declarator}; + auto declaratorType = getDeclaratorType(translationUnit(), copy->declarator, + typeSpecifierListCtx.type()); + copy->type = declaratorType; + + return copy; +} + +auto ASTRewriter::splicer(SplicerAST* ast) -> SplicerAST* { + if (!ast) return {}; + + auto copy = make_node(arena()); + + copy->lbracketLoc = ast->lbracketLoc; + copy->colonLoc = ast->colonLoc; + copy->ellipsisLoc = ast->ellipsisLoc; + copy->expression = expression(ast->expression); + copy->secondColonLoc = ast->secondColonLoc; + copy->rbracketLoc = ast->rbracketLoc; + + return copy; +} + +auto ASTRewriter::SpecifierVisitor::operator()(GeneratedTypeSpecifierAST* ast) + -> SpecifierAST* { + auto copy = make_node(arena()); + + copy->typeLoc = ast->typeLoc; + copy->type = ast->type; + + return copy; +} + +auto ASTRewriter::SpecifierVisitor::operator()(TypedefSpecifierAST* ast) + -> SpecifierAST* { + auto copy = make_node(arena()); + + copy->typedefLoc = ast->typedefLoc; + + return copy; +} + +auto ASTRewriter::SpecifierVisitor::operator()(FriendSpecifierAST* ast) + -> SpecifierAST* { + auto copy = make_node(arena()); + + copy->friendLoc = ast->friendLoc; + + return copy; +} + +auto ASTRewriter::SpecifierVisitor::operator()(ConstevalSpecifierAST* ast) + -> SpecifierAST* { + auto copy = make_node(arena()); + + copy->constevalLoc = ast->constevalLoc; + + return copy; +} + +auto ASTRewriter::SpecifierVisitor::operator()(ConstinitSpecifierAST* ast) + -> SpecifierAST* { + auto copy = make_node(arena()); + + copy->constinitLoc = ast->constinitLoc; + + return copy; +} + +auto ASTRewriter::SpecifierVisitor::operator()(ConstexprSpecifierAST* ast) + -> SpecifierAST* { + auto copy = make_node(arena()); + + copy->constexprLoc = ast->constexprLoc; + + return copy; +} + +auto ASTRewriter::SpecifierVisitor::operator()(InlineSpecifierAST* ast) + -> SpecifierAST* { + auto copy = make_node(arena()); + + copy->inlineLoc = ast->inlineLoc; + + return copy; +} + +auto ASTRewriter::SpecifierVisitor::operator()(NoreturnSpecifierAST* ast) + -> SpecifierAST* { + auto copy = make_node(arena()); + + copy->noreturnLoc = ast->noreturnLoc; + + return copy; +} + +auto ASTRewriter::SpecifierVisitor::operator()(StaticSpecifierAST* ast) + -> SpecifierAST* { + auto copy = make_node(arena()); + + copy->staticLoc = ast->staticLoc; + + return copy; +} + +auto ASTRewriter::SpecifierVisitor::operator()(ExternSpecifierAST* ast) + -> SpecifierAST* { + auto copy = make_node(arena()); + + copy->externLoc = ast->externLoc; + + return copy; +} + +auto ASTRewriter::SpecifierVisitor::operator()(RegisterSpecifierAST* ast) + -> SpecifierAST* { + auto copy = make_node(arena()); + + copy->registerLoc = ast->registerLoc; + + return copy; +} + +auto ASTRewriter::SpecifierVisitor::operator()(ThreadLocalSpecifierAST* ast) + -> SpecifierAST* { + auto copy = make_node(arena()); + + copy->threadLocalLoc = ast->threadLocalLoc; + + return copy; +} + +auto ASTRewriter::SpecifierVisitor::operator()(ThreadSpecifierAST* ast) + -> SpecifierAST* { + auto copy = make_node(arena()); + + copy->threadLoc = ast->threadLoc; + + return copy; +} + +auto ASTRewriter::SpecifierVisitor::operator()(MutableSpecifierAST* ast) + -> SpecifierAST* { + auto copy = make_node(arena()); + + copy->mutableLoc = ast->mutableLoc; + + return copy; +} + +auto ASTRewriter::SpecifierVisitor::operator()(VirtualSpecifierAST* ast) + -> SpecifierAST* { + auto copy = make_node(arena()); + + copy->virtualLoc = ast->virtualLoc; + + return copy; +} + +auto ASTRewriter::SpecifierVisitor::operator()(ExplicitSpecifierAST* ast) + -> SpecifierAST* { + auto copy = make_node(arena()); + + copy->explicitLoc = ast->explicitLoc; + copy->lparenLoc = ast->lparenLoc; + copy->expression = rewrite.expression(ast->expression); + copy->rparenLoc = ast->rparenLoc; + + return copy; +} + +auto ASTRewriter::SpecifierVisitor::operator()(AutoTypeSpecifierAST* ast) + -> SpecifierAST* { + auto copy = make_node(arena()); + + copy->autoLoc = ast->autoLoc; + + return copy; +} + +auto ASTRewriter::SpecifierVisitor::operator()(VoidTypeSpecifierAST* ast) + -> SpecifierAST* { + auto copy = make_node(arena()); + + copy->voidLoc = ast->voidLoc; + + return copy; +} + +auto ASTRewriter::SpecifierVisitor::operator()(SizeTypeSpecifierAST* ast) + -> SpecifierAST* { + auto copy = make_node(arena()); + + copy->specifierLoc = ast->specifierLoc; + copy->specifier = ast->specifier; + + return copy; +} + +auto ASTRewriter::SpecifierVisitor::operator()(SignTypeSpecifierAST* ast) + -> SpecifierAST* { + auto copy = make_node(arena()); + + copy->specifierLoc = ast->specifierLoc; + copy->specifier = ast->specifier; + + return copy; +} + +auto ASTRewriter::SpecifierVisitor::operator()(VaListTypeSpecifierAST* ast) + -> SpecifierAST* { + auto copy = make_node(arena()); + + copy->specifierLoc = ast->specifierLoc; + copy->specifier = ast->specifier; + + return copy; +} + +auto ASTRewriter::SpecifierVisitor::operator()(IntegralTypeSpecifierAST* ast) + -> SpecifierAST* { + auto copy = make_node(arena()); + + copy->specifierLoc = ast->specifierLoc; + copy->specifier = ast->specifier; + + return copy; +} + +auto ASTRewriter::SpecifierVisitor::operator()( + FloatingPointTypeSpecifierAST* ast) -> SpecifierAST* { + auto copy = make_node(arena()); + + copy->specifierLoc = ast->specifierLoc; + copy->specifier = ast->specifier; + + return copy; +} + +auto ASTRewriter::SpecifierVisitor::operator()(ComplexTypeSpecifierAST* ast) + -> SpecifierAST* { + auto copy = make_node(arena()); + + copy->complexLoc = ast->complexLoc; + + return copy; +} + +auto ASTRewriter::SpecifierVisitor::operator()(NamedTypeSpecifierAST* ast) + -> SpecifierAST* { + auto copy = make_node(arena()); + + copy->nestedNameSpecifier = + rewrite.nestedNameSpecifier(ast->nestedNameSpecifier); + copy->templateLoc = ast->templateLoc; + copy->unqualifiedId = rewrite.unqualifiedId(ast->unqualifiedId); + copy->isTemplateIntroduced = ast->isTemplateIntroduced; + + copy->symbol = binder()->resolve( + copy->nestedNameSpecifier, copy->unqualifiedId, /*checkTemplates=*/true); + + if (auto typeParameter = symbol_cast(ast->symbol)) { + auto paramType = type_cast(ast->symbol->type()); + const auto& args = rewrite.templateArguments_; + if (paramType && paramType->depth() == 0 && + paramType->index() < args.size()) { + auto index = paramType->index(); + + if (auto sym = std::get_if(&args[index])) { + copy->symbol = *sym; + } + } + } + + return copy; +} + +auto ASTRewriter::SpecifierVisitor::operator()(AtomicTypeSpecifierAST* ast) + -> SpecifierAST* { + auto copy = make_node(arena()); + + copy->atomicLoc = ast->atomicLoc; + copy->lparenLoc = ast->lparenLoc; + copy->typeId = rewrite.typeId(ast->typeId); + copy->rparenLoc = ast->rparenLoc; + + return copy; +} + +auto ASTRewriter::SpecifierVisitor::operator()(UnderlyingTypeSpecifierAST* ast) + -> SpecifierAST* { + auto copy = make_node(arena()); + + copy->underlyingTypeLoc = ast->underlyingTypeLoc; + copy->lparenLoc = ast->lparenLoc; + copy->typeId = rewrite.typeId(ast->typeId); + copy->rparenLoc = ast->rparenLoc; + + return copy; +} + +auto ASTRewriter::SpecifierVisitor::operator()(ElaboratedTypeSpecifierAST* ast) + -> SpecifierAST* { + auto copy = make_node(arena()); + + copy->classLoc = ast->classLoc; + + for (auto attributeList = ©->attributeList; + auto node : ListView{ast->attributeList}) { + auto value = rewrite.attributeSpecifier(node); + *attributeList = make_list_node(arena(), value); + attributeList = &(*attributeList)->next; + } + + copy->nestedNameSpecifier = + rewrite.nestedNameSpecifier(ast->nestedNameSpecifier); + copy->templateLoc = ast->templateLoc; + copy->unqualifiedId = rewrite.unqualifiedId(ast->unqualifiedId); + copy->classKey = ast->classKey; + copy->isTemplateIntroduced = ast->isTemplateIntroduced; + + // copy->symbol = ast->symbol; + +#if false + auto decl = symbol_cast(ast->symbol); + + if (auto classSpec = decl->declaration()) { + auto newClassSpec = + ast_cast(rewrite.specifier(classSpec)); + + copy->symbol = newClassSpec->symbol; + } +#endif + + return copy; +} + +auto ASTRewriter::SpecifierVisitor::operator()(DecltypeAutoSpecifierAST* ast) + -> SpecifierAST* { + auto copy = make_node(arena()); + + copy->decltypeLoc = ast->decltypeLoc; + copy->lparenLoc = ast->lparenLoc; + copy->autoLoc = ast->autoLoc; + copy->rparenLoc = ast->rparenLoc; + + return copy; +} + +auto ASTRewriter::SpecifierVisitor::operator()(DecltypeSpecifierAST* ast) + -> SpecifierAST* { + auto copy = make_node(arena()); + + copy->decltypeLoc = ast->decltypeLoc; + copy->lparenLoc = ast->lparenLoc; + copy->expression = rewrite.expression(ast->expression); + copy->rparenLoc = ast->rparenLoc; + copy->type = ast->type; + + return copy; +} + +auto ASTRewriter::SpecifierVisitor::operator()(PlaceholderTypeSpecifierAST* ast) + -> SpecifierAST* { + auto copy = make_node(arena()); + + copy->typeConstraint = rewrite.typeConstraint(ast->typeConstraint); + copy->specifier = rewrite.specifier(ast->specifier); + + return copy; +} + +auto ASTRewriter::SpecifierVisitor::operator()(ConstQualifierAST* ast) + -> SpecifierAST* { + auto copy = make_node(arena()); + + copy->constLoc = ast->constLoc; + + return copy; +} + +auto ASTRewriter::SpecifierVisitor::operator()(VolatileQualifierAST* ast) + -> SpecifierAST* { + auto copy = make_node(arena()); + + copy->volatileLoc = ast->volatileLoc; + + return copy; +} + +auto ASTRewriter::SpecifierVisitor::operator()(AtomicQualifierAST* ast) + -> SpecifierAST* { + auto copy = make_node(arena()); + + copy->atomicLoc = ast->atomicLoc; + + return copy; +} + +auto ASTRewriter::SpecifierVisitor::operator()(RestrictQualifierAST* ast) + -> SpecifierAST* { + auto copy = make_node(arena()); + + copy->restrictLoc = ast->restrictLoc; + + return copy; +} + +auto ASTRewriter::SpecifierVisitor::operator()(EnumSpecifierAST* ast) + -> SpecifierAST* { + auto copy = make_node(arena()); + + copy->enumLoc = ast->enumLoc; + copy->classLoc = ast->classLoc; + + for (auto attributeList = ©->attributeList; + auto node : ListView{ast->attributeList}) { + auto value = rewrite.attributeSpecifier(node); + *attributeList = make_list_node(arena(), value); + attributeList = &(*attributeList)->next; + } + + copy->nestedNameSpecifier = + rewrite.nestedNameSpecifier(ast->nestedNameSpecifier); + copy->unqualifiedId = + ast_cast(rewrite.unqualifiedId(ast->unqualifiedId)); + copy->colonLoc = ast->colonLoc; + + auto typeSpecifierListCtx = DeclSpecs{rewriter()}; + for (auto typeSpecifierList = ©->typeSpecifierList; + auto node : ListView{ast->typeSpecifierList}) { + auto value = rewrite.specifier(node); + *typeSpecifierList = make_list_node(arena(), value); + typeSpecifierList = &(*typeSpecifierList)->next; + typeSpecifierListCtx.accept(value); + } + typeSpecifierListCtx.finish(); + + copy->lbraceLoc = ast->lbraceLoc; + + for (auto enumeratorList = ©->enumeratorList; + auto node : ListView{ast->enumeratorList}) { + auto value = rewrite.enumerator(node); + *enumeratorList = make_list_node(arena(), value); + enumeratorList = &(*enumeratorList)->next; + } + + copy->commaLoc = ast->commaLoc; + copy->rbraceLoc = ast->rbraceLoc; + copy->symbol = ast->symbol; + + return copy; +} + +auto ASTRewriter::SpecifierVisitor::operator()(ClassSpecifierAST* ast) + -> SpecifierAST* { + auto copy = make_node(arena()); + + copy->classLoc = ast->classLoc; + + for (auto attributeList = ©->attributeList; + auto node : ListView{ast->attributeList}) { + auto value = rewrite.attributeSpecifier(node); + *attributeList = make_list_node(arena(), value); + attributeList = &(*attributeList)->next; + } + + copy->nestedNameSpecifier = + rewrite.nestedNameSpecifier(ast->nestedNameSpecifier); + copy->unqualifiedId = rewrite.unqualifiedId(ast->unqualifiedId); + copy->finalLoc = ast->finalLoc; + copy->colonLoc = ast->colonLoc; + + // ### TODO: use Binder::bind() + auto _ = Binder::ScopeGuard{binder()}; + auto location = ast->symbol->location(); + auto className = ast->symbol->name(); + + auto classSymbol = control()->newClassSymbol(binder()->scope(), location); + copy->symbol = classSymbol; + + classSymbol->setName(className); + classSymbol->setIsUnion(ast->symbol->isUnion()); + classSymbol->setFinal(ast->isFinal); + classSymbol->setDeclaration(copy); + + if (ast->symbol != rewrite.binder().instantiatingSymbol()) { + // If we are not instantiating a template, we can add the class symbol to + // the scope. + binder()->declaringScope()->addSymbol(classSymbol); + } else { + ast->symbol->addSpecialization(rewrite.templateArguments(), classSymbol); + } + + // enter the class scope + binder()->setScope(classSymbol); + + for (auto baseSpecifierList = ©->baseSpecifierList; + auto node : ListView{ast->baseSpecifierList}) { + auto value = rewrite.baseSpecifier(node); + *baseSpecifierList = make_list_node(arena(), value); + baseSpecifierList = &(*baseSpecifierList)->next; + + if (value->symbol) { + classSymbol->addBaseClass(value->symbol); + } + } + + copy->lbraceLoc = ast->lbraceLoc; + + for (auto declarationList = ©->declarationList; + auto node : ListView{ast->declarationList}) { + auto value = rewrite.declaration(node); + *declarationList = make_list_node(arena(), value); + declarationList = &(*declarationList)->next; + } + + copy->rbraceLoc = ast->rbraceLoc; + copy->classKey = ast->classKey; + // copy->symbol = ast->symbol; // TODO: remove done by the binder + copy->isFinal = ast->isFinal; + + binder()->complete(copy); + + return copy; +} + +auto ASTRewriter::SpecifierVisitor::operator()(TypenameSpecifierAST* ast) + -> SpecifierAST* { + auto copy = make_node(arena()); + + copy->typenameLoc = ast->typenameLoc; + copy->nestedNameSpecifier = + rewrite.nestedNameSpecifier(ast->nestedNameSpecifier); + copy->templateLoc = ast->templateLoc; + copy->unqualifiedId = rewrite.unqualifiedId(ast->unqualifiedId); + copy->isTemplateIntroduced = ast->isTemplateIntroduced; + + return copy; +} + +auto ASTRewriter::SpecifierVisitor::operator()(SplicerTypeSpecifierAST* ast) + -> SpecifierAST* { + auto copy = make_node(arena()); + + copy->typenameLoc = ast->typenameLoc; + copy->splicer = rewrite.splicer(ast->splicer); + + return copy; +} + +auto ASTRewriter::AttributeSpecifierVisitor::operator()(CxxAttributeAST* ast) + -> AttributeSpecifierAST* { + auto copy = make_node(arena()); + + copy->lbracketLoc = ast->lbracketLoc; + copy->lbracket2Loc = ast->lbracket2Loc; + copy->attributeUsingPrefix = + rewrite.attributeUsingPrefix(ast->attributeUsingPrefix); + + for (auto attributeList = ©->attributeList; + auto node : ListView{ast->attributeList}) { + auto value = rewrite.attribute(node); + *attributeList = make_list_node(arena(), value); + attributeList = &(*attributeList)->next; + } + + copy->rbracketLoc = ast->rbracketLoc; + copy->rbracket2Loc = ast->rbracket2Loc; + + return copy; +} + +auto ASTRewriter::AttributeSpecifierVisitor::operator()(GccAttributeAST* ast) + -> AttributeSpecifierAST* { + auto copy = make_node(arena()); + + copy->attributeLoc = ast->attributeLoc; + copy->lparenLoc = ast->lparenLoc; + copy->lparen2Loc = ast->lparen2Loc; + copy->rparenLoc = ast->rparenLoc; + copy->rparen2Loc = ast->rparen2Loc; + + return copy; +} + +auto ASTRewriter::AttributeSpecifierVisitor::operator()( + AlignasAttributeAST* ast) -> AttributeSpecifierAST* { + auto copy = make_node(arena()); + + copy->alignasLoc = ast->alignasLoc; + copy->lparenLoc = ast->lparenLoc; + copy->expression = rewrite.expression(ast->expression); + copy->ellipsisLoc = ast->ellipsisLoc; + copy->rparenLoc = ast->rparenLoc; + copy->isPack = ast->isPack; + + return copy; +} + +auto ASTRewriter::AttributeSpecifierVisitor::operator()( + AlignasTypeAttributeAST* ast) -> AttributeSpecifierAST* { + auto copy = make_node(arena()); + + copy->alignasLoc = ast->alignasLoc; + copy->lparenLoc = ast->lparenLoc; + copy->typeId = rewrite.typeId(ast->typeId); + copy->ellipsisLoc = ast->ellipsisLoc; + copy->rparenLoc = ast->rparenLoc; + copy->isPack = ast->isPack; + + return copy; +} + +auto ASTRewriter::AttributeSpecifierVisitor::operator()(AsmAttributeAST* ast) + -> AttributeSpecifierAST* { + auto copy = make_node(arena()); + + copy->asmLoc = ast->asmLoc; + copy->lparenLoc = ast->lparenLoc; + copy->literalLoc = ast->literalLoc; + copy->rparenLoc = ast->rparenLoc; + copy->literal = ast->literal; + + return copy; +} + +auto ASTRewriter::AttributeTokenVisitor::operator()( + ScopedAttributeTokenAST* ast) -> AttributeTokenAST* { + auto copy = make_node(arena()); + + copy->attributeNamespaceLoc = ast->attributeNamespaceLoc; + copy->scopeLoc = ast->scopeLoc; + copy->identifierLoc = ast->identifierLoc; + copy->attributeNamespace = ast->attributeNamespace; + copy->identifier = ast->identifier; + + return copy; +} + +auto ASTRewriter::AttributeTokenVisitor::operator()( + SimpleAttributeTokenAST* ast) -> AttributeTokenAST* { + auto copy = make_node(arena()); + + copy->identifierLoc = ast->identifierLoc; + copy->identifier = ast->identifier; + + return copy; +} + +} // namespace cxx diff --git a/src/parser/cxx/ast_rewriter_statements.cc b/src/parser/cxx/ast_rewriter_statements.cc new file mode 100644 index 00000000..49e33574 --- /dev/null +++ b/src/parser/cxx/ast_rewriter_statements.cc @@ -0,0 +1,552 @@ +// Copyright (c) 2025 Roberto Raggi +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#include + +// cxx +#include +#include +#include +#include +#include + +namespace cxx { + +struct ASTRewriter::StatementVisitor { + ASTRewriter& rewrite; + [[nodiscard]] auto translationUnit() const -> TranslationUnit* { + return rewrite.unit_; + } + + [[nodiscard]] auto control() const -> Control* { return rewrite.control(); } + [[nodiscard]] auto arena() const -> Arena* { return rewrite.arena(); } + [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } + [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } + + [[nodiscard]] auto operator()(LabeledStatementAST* ast) -> StatementAST*; + + [[nodiscard]] auto operator()(CaseStatementAST* ast) -> StatementAST*; + + [[nodiscard]] auto operator()(DefaultStatementAST* ast) -> StatementAST*; + + [[nodiscard]] auto operator()(ExpressionStatementAST* ast) -> StatementAST*; + + [[nodiscard]] auto operator()(CompoundStatementAST* ast) -> StatementAST*; + + [[nodiscard]] auto operator()(IfStatementAST* ast) -> StatementAST*; + + [[nodiscard]] auto operator()(ConstevalIfStatementAST* ast) -> StatementAST*; + + [[nodiscard]] auto operator()(SwitchStatementAST* ast) -> StatementAST*; + + [[nodiscard]] auto operator()(WhileStatementAST* ast) -> StatementAST*; + + [[nodiscard]] auto operator()(DoStatementAST* ast) -> StatementAST*; + + [[nodiscard]] auto operator()(ForRangeStatementAST* ast) -> StatementAST*; + + [[nodiscard]] auto operator()(ForStatementAST* ast) -> StatementAST*; + + [[nodiscard]] auto operator()(BreakStatementAST* ast) -> StatementAST*; + + [[nodiscard]] auto operator()(ContinueStatementAST* ast) -> StatementAST*; + + [[nodiscard]] auto operator()(ReturnStatementAST* ast) -> StatementAST*; + + [[nodiscard]] auto operator()(CoroutineReturnStatementAST* ast) + -> StatementAST*; + + [[nodiscard]] auto operator()(GotoStatementAST* ast) -> StatementAST*; + + [[nodiscard]] auto operator()(DeclarationStatementAST* ast) -> StatementAST*; + + [[nodiscard]] auto operator()(TryBlockStatementAST* ast) -> StatementAST*; +}; + +struct ASTRewriter::MemInitializerVisitor { + ASTRewriter& rewrite; + [[nodiscard]] auto translationUnit() const -> TranslationUnit* { + return rewrite.unit_; + } + + [[nodiscard]] auto control() const -> Control* { return rewrite.control(); } + [[nodiscard]] auto arena() const -> Arena* { return rewrite.arena(); } + [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } + [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } + + [[nodiscard]] auto operator()(ParenMemInitializerAST* ast) + -> MemInitializerAST*; + + [[nodiscard]] auto operator()(BracedMemInitializerAST* ast) + -> MemInitializerAST*; +}; + +struct ASTRewriter::ExceptionDeclarationVisitor { + ASTRewriter& rewrite; + [[nodiscard]] auto translationUnit() const -> TranslationUnit* { + return rewrite.unit_; + } + + [[nodiscard]] auto control() const -> Control* { return rewrite.control(); } + [[nodiscard]] auto arena() const -> Arena* { return rewrite.arena(); } + [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } + [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } + + [[nodiscard]] auto operator()(EllipsisExceptionDeclarationAST* ast) + -> ExceptionDeclarationAST*; + + [[nodiscard]] auto operator()(TypeExceptionDeclarationAST* ast) + -> ExceptionDeclarationAST*; +}; + +auto ASTRewriter::statement(StatementAST* ast) -> StatementAST* { + if (!ast) return {}; + return visit(StatementVisitor{*this}, ast); +} + +auto ASTRewriter::memInitializer(MemInitializerAST* ast) -> MemInitializerAST* { + if (!ast) return {}; + return visit(MemInitializerVisitor{*this}, ast); +} + +auto ASTRewriter::exceptionDeclaration(ExceptionDeclarationAST* ast) + -> ExceptionDeclarationAST* { + if (!ast) return {}; + return visit(ExceptionDeclarationVisitor{*this}, ast); +} + +auto ASTRewriter::asmOperand(AsmOperandAST* ast) -> AsmOperandAST* { + auto copy = make_node(arena()); + + copy->lbracketLoc = ast->lbracketLoc; + copy->symbolicNameLoc = ast->symbolicNameLoc; + copy->rbracketLoc = ast->rbracketLoc; + copy->constraintLiteralLoc = ast->constraintLiteralLoc; + copy->lparenLoc = ast->lparenLoc; + copy->expression = expression(ast->expression); + copy->rparenLoc = ast->rparenLoc; + copy->symbolicName = ast->symbolicName; + copy->constraintLiteral = ast->constraintLiteral; + + return copy; +} + +auto ASTRewriter::asmQualifier(AsmQualifierAST* ast) -> AsmQualifierAST* { + auto copy = make_node(arena()); + + copy->qualifierLoc = ast->qualifierLoc; + copy->qualifier = ast->qualifier; + + return copy; +} + +auto ASTRewriter::asmClobber(AsmClobberAST* ast) -> AsmClobberAST* { + auto copy = make_node(arena()); + + copy->literalLoc = ast->literalLoc; + copy->literal = ast->literal; + + return copy; +} + +auto ASTRewriter::asmGotoLabel(AsmGotoLabelAST* ast) -> AsmGotoLabelAST* { + auto copy = make_node(arena()); + + copy->identifierLoc = ast->identifierLoc; + copy->identifier = ast->identifier; + + return copy; +} + +auto ASTRewriter::handler(HandlerAST* ast) -> HandlerAST* { + if (!ast) return {}; + + auto copy = make_node(arena()); + + copy->catchLoc = ast->catchLoc; + copy->lparenLoc = ast->lparenLoc; + copy->exceptionDeclaration = exceptionDeclaration(ast->exceptionDeclaration); + copy->rparenLoc = ast->rparenLoc; + copy->statement = ast_cast(statement(ast->statement)); + + return copy; +} + +auto ASTRewriter::StatementVisitor::operator()(LabeledStatementAST* ast) + -> StatementAST* { + auto copy = make_node(arena()); + + copy->identifierLoc = ast->identifierLoc; + copy->colonLoc = ast->colonLoc; + copy->identifier = ast->identifier; + + return copy; +} + +auto ASTRewriter::StatementVisitor::operator()(CaseStatementAST* ast) + -> StatementAST* { + auto copy = make_node(arena()); + + copy->caseLoc = ast->caseLoc; + copy->expression = rewrite.expression(ast->expression); + copy->colonLoc = ast->colonLoc; + + return copy; +} + +auto ASTRewriter::StatementVisitor::operator()(DefaultStatementAST* ast) + -> StatementAST* { + auto copy = make_node(arena()); + + copy->defaultLoc = ast->defaultLoc; + copy->colonLoc = ast->colonLoc; + + return copy; +} + +auto ASTRewriter::StatementVisitor::operator()(ExpressionStatementAST* ast) + -> StatementAST* { + auto copy = make_node(arena()); + + copy->expression = rewrite.expression(ast->expression); + copy->semicolonLoc = ast->semicolonLoc; + + return copy; +} + +auto ASTRewriter::StatementVisitor::operator()(CompoundStatementAST* ast) + -> StatementAST* { + auto copy = make_node(arena()); + + auto _ = Binder::ScopeGuard(binder()); + + if (ast->symbol) { + copy->symbol = binder()->enterBlock(ast->symbol->location()); + } + + copy->lbraceLoc = ast->lbraceLoc; + + for (auto statementList = ©->statementList; + auto node : ListView{ast->statementList}) { + auto value = rewrite.statement(node); + *statementList = make_list_node(arena(), value); + statementList = &(*statementList)->next; + } + + copy->rbraceLoc = ast->rbraceLoc; + + return copy; +} + +auto ASTRewriter::StatementVisitor::operator()(IfStatementAST* ast) + -> StatementAST* { + auto copy = make_node(arena()); + + auto _ = Binder::ScopeGuard(binder()); + + if (ast->symbol) { + copy->symbol = binder()->enterBlock(ast->symbol->location()); + } + + copy->ifLoc = ast->ifLoc; + copy->constexprLoc = ast->constexprLoc; + copy->lparenLoc = ast->lparenLoc; + copy->initializer = rewrite.statement(ast->initializer); + copy->condition = rewrite.expression(ast->condition); + copy->rparenLoc = ast->rparenLoc; + copy->statement = rewrite.statement(ast->statement); + copy->elseLoc = ast->elseLoc; + copy->elseStatement = rewrite.statement(ast->elseStatement); + + return copy; +} + +auto ASTRewriter::StatementVisitor::operator()(ConstevalIfStatementAST* ast) + -> StatementAST* { + auto copy = make_node(arena()); + + copy->ifLoc = ast->ifLoc; + copy->exclaimLoc = ast->exclaimLoc; + copy->constvalLoc = ast->constvalLoc; + copy->statement = rewrite.statement(ast->statement); + copy->elseLoc = ast->elseLoc; + copy->elseStatement = rewrite.statement(ast->elseStatement); + copy->isNot = ast->isNot; + + return copy; +} + +auto ASTRewriter::StatementVisitor::operator()(SwitchStatementAST* ast) + -> StatementAST* { + auto copy = make_node(arena()); + + auto _ = Binder::ScopeGuard(binder()); + + if (ast->symbol) { + copy->symbol = binder()->enterBlock(ast->symbol->location()); + } + + copy->switchLoc = ast->switchLoc; + copy->lparenLoc = ast->lparenLoc; + copy->initializer = rewrite.statement(ast->initializer); + copy->condition = rewrite.expression(ast->condition); + copy->rparenLoc = ast->rparenLoc; + copy->statement = rewrite.statement(ast->statement); + + return copy; +} + +auto ASTRewriter::StatementVisitor::operator()(WhileStatementAST* ast) + -> StatementAST* { + auto copy = make_node(arena()); + + auto _ = Binder::ScopeGuard(binder()); + + if (ast->symbol) { + copy->symbol = binder()->enterBlock(ast->symbol->location()); + } + + copy->whileLoc = ast->whileLoc; + copy->lparenLoc = ast->lparenLoc; + copy->condition = rewrite.expression(ast->condition); + copy->rparenLoc = ast->rparenLoc; + copy->statement = rewrite.statement(ast->statement); + + return copy; +} + +auto ASTRewriter::StatementVisitor::operator()(DoStatementAST* ast) + -> StatementAST* { + auto copy = make_node(arena()); + + copy->doLoc = ast->doLoc; + copy->statement = rewrite.statement(ast->statement); + copy->whileLoc = ast->whileLoc; + copy->lparenLoc = ast->lparenLoc; + copy->expression = rewrite.expression(ast->expression); + copy->rparenLoc = ast->rparenLoc; + copy->semicolonLoc = ast->semicolonLoc; + + return copy; +} + +auto ASTRewriter::StatementVisitor::operator()(ForRangeStatementAST* ast) + -> StatementAST* { + auto copy = make_node(arena()); + + auto _ = Binder::ScopeGuard(binder()); + + if (ast->symbol) { + copy->symbol = binder()->enterBlock(ast->symbol->location()); + } + + copy->forLoc = ast->forLoc; + copy->lparenLoc = ast->lparenLoc; + copy->initializer = rewrite.statement(ast->initializer); + copy->rangeDeclaration = rewrite.declaration(ast->rangeDeclaration); + copy->colonLoc = ast->colonLoc; + copy->rangeInitializer = rewrite.expression(ast->rangeInitializer); + copy->rparenLoc = ast->rparenLoc; + copy->statement = rewrite.statement(ast->statement); + + return copy; +} + +auto ASTRewriter::StatementVisitor::operator()(ForStatementAST* ast) + -> StatementAST* { + auto copy = make_node(arena()); + + auto _ = Binder::ScopeGuard(binder()); + + if (ast->symbol) { + copy->symbol = binder()->enterBlock(ast->symbol->location()); + } + + copy->forLoc = ast->forLoc; + copy->lparenLoc = ast->lparenLoc; + copy->initializer = rewrite.statement(ast->initializer); + copy->condition = rewrite.expression(ast->condition); + copy->semicolonLoc = ast->semicolonLoc; + copy->expression = rewrite.expression(ast->expression); + copy->rparenLoc = ast->rparenLoc; + copy->statement = rewrite.statement(ast->statement); + + return copy; +} + +auto ASTRewriter::StatementVisitor::operator()(BreakStatementAST* ast) + -> StatementAST* { + auto copy = make_node(arena()); + + copy->breakLoc = ast->breakLoc; + copy->semicolonLoc = ast->semicolonLoc; + + return copy; +} + +auto ASTRewriter::StatementVisitor::operator()(ContinueStatementAST* ast) + -> StatementAST* { + auto copy = make_node(arena()); + + copy->continueLoc = ast->continueLoc; + copy->semicolonLoc = ast->semicolonLoc; + + return copy; +} + +auto ASTRewriter::StatementVisitor::operator()(ReturnStatementAST* ast) + -> StatementAST* { + auto copy = make_node(arena()); + + copy->returnLoc = ast->returnLoc; + copy->expression = rewrite.expression(ast->expression); + copy->semicolonLoc = ast->semicolonLoc; + + return copy; +} + +auto ASTRewriter::StatementVisitor::operator()(CoroutineReturnStatementAST* ast) + -> StatementAST* { + auto copy = make_node(arena()); + + copy->coreturnLoc = ast->coreturnLoc; + copy->expression = rewrite.expression(ast->expression); + copy->semicolonLoc = ast->semicolonLoc; + + return copy; +} + +auto ASTRewriter::StatementVisitor::operator()(GotoStatementAST* ast) + -> StatementAST* { + auto copy = make_node(arena()); + + copy->gotoLoc = ast->gotoLoc; + copy->starLoc = ast->starLoc; + copy->identifierLoc = ast->identifierLoc; + copy->semicolonLoc = ast->semicolonLoc; + copy->identifier = ast->identifier; + copy->isIndirect = ast->isIndirect; + + return copy; +} + +auto ASTRewriter::StatementVisitor::operator()(DeclarationStatementAST* ast) + -> StatementAST* { + auto copy = make_node(arena()); + + copy->declaration = rewrite.declaration(ast->declaration); + + return copy; +} + +auto ASTRewriter::StatementVisitor::operator()(TryBlockStatementAST* ast) + -> StatementAST* { + auto copy = make_node(arena()); + + copy->tryLoc = ast->tryLoc; + copy->statement = + ast_cast(rewrite.statement(ast->statement)); + + for (auto handlerList = ©->handlerList; + auto node : ListView{ast->handlerList}) { + auto value = rewrite.handler(node); + *handlerList = make_list_node(arena(), value); + handlerList = &(*handlerList)->next; + } + + return copy; +} + +auto ASTRewriter::MemInitializerVisitor::operator()(ParenMemInitializerAST* ast) + -> MemInitializerAST* { + auto copy = make_node(arena()); + + copy->nestedNameSpecifier = + rewrite.nestedNameSpecifier(ast->nestedNameSpecifier); + copy->unqualifiedId = rewrite.unqualifiedId(ast->unqualifiedId); + copy->lparenLoc = ast->lparenLoc; + + for (auto expressionList = ©->expressionList; + auto node : ListView{ast->expressionList}) { + auto value = rewrite.expression(node); + *expressionList = make_list_node(arena(), value); + expressionList = &(*expressionList)->next; + } + + copy->rparenLoc = ast->rparenLoc; + copy->ellipsisLoc = ast->ellipsisLoc; + + return copy; +} + +auto ASTRewriter::MemInitializerVisitor::operator()( + BracedMemInitializerAST* ast) -> MemInitializerAST* { + auto copy = make_node(arena()); + + copy->nestedNameSpecifier = + rewrite.nestedNameSpecifier(ast->nestedNameSpecifier); + copy->unqualifiedId = rewrite.unqualifiedId(ast->unqualifiedId); + copy->bracedInitList = + ast_cast(rewrite.expression(ast->bracedInitList)); + copy->ellipsisLoc = ast->ellipsisLoc; + + return copy; +} + +auto ASTRewriter::ExceptionDeclarationVisitor::operator()( + EllipsisExceptionDeclarationAST* ast) -> ExceptionDeclarationAST* { + auto copy = make_node(arena()); + + copy->ellipsisLoc = ast->ellipsisLoc; + + return copy; +} + +auto ASTRewriter::ExceptionDeclarationVisitor::operator()( + TypeExceptionDeclarationAST* ast) -> ExceptionDeclarationAST* { + auto copy = make_node(arena()); + + for (auto attributeList = ©->attributeList; + auto node : ListView{ast->attributeList}) { + auto value = rewrite.attributeSpecifier(node); + *attributeList = make_list_node(arena(), value); + attributeList = &(*attributeList)->next; + } + + auto typeSpecifierListCtx = DeclSpecs{rewriter()}; + for (auto typeSpecifierList = ©->typeSpecifierList; + auto node : ListView{ast->typeSpecifierList}) { + auto value = rewrite.specifier(node); + *typeSpecifierList = make_list_node(arena(), value); + typeSpecifierList = &(*typeSpecifierList)->next; + typeSpecifierListCtx.accept(value); + } + typeSpecifierListCtx.finish(); + + copy->declarator = rewrite.declarator(ast->declarator); + + auto declaratorDecl = Decl{typeSpecifierListCtx, copy->declarator}; + auto declaratorType = getDeclaratorType(translationUnit(), copy->declarator, + typeSpecifierListCtx.type()); + + return copy; +} + +} // namespace cxx diff --git a/src/parser/cxx/ast_rewriter_units.cc b/src/parser/cxx/ast_rewriter_units.cc new file mode 100644 index 00000000..423bfe09 --- /dev/null +++ b/src/parser/cxx/ast_rewriter_units.cc @@ -0,0 +1,195 @@ +// Copyright (c) 2025 Roberto Raggi +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#include + +// cxx +#include + +namespace cxx { + +struct ASTRewriter::UnitVisitor { + ASTRewriter& rewrite; + [[nodiscard]] auto translationUnit() const -> TranslationUnit* { + return rewrite.unit_; + } + + [[nodiscard]] auto control() const -> Control* { return rewrite.control(); } + [[nodiscard]] auto arena() const -> Arena* { return rewrite.arena(); } + [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } + [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } + + [[nodiscard]] auto operator()(TranslationUnitAST* ast) -> UnitAST*; + + [[nodiscard]] auto operator()(ModuleUnitAST* ast) -> UnitAST*; +}; + +auto ASTRewriter::unit(UnitAST* ast) -> UnitAST* { + if (!ast) return {}; + return visit(UnitVisitor{*this}, ast); +} + +auto ASTRewriter::globalModuleFragment(GlobalModuleFragmentAST* ast) + -> GlobalModuleFragmentAST* { + if (!ast) return {}; + + auto copy = make_node(arena()); + + copy->moduleLoc = ast->moduleLoc; + copy->semicolonLoc = ast->semicolonLoc; + + for (auto declarationList = ©->declarationList; + auto node : ListView{ast->declarationList}) { + auto value = declaration(node); + *declarationList = make_list_node(arena(), value); + declarationList = &(*declarationList)->next; + } + + return copy; +} + +auto ASTRewriter::privateModuleFragment(PrivateModuleFragmentAST* ast) + -> PrivateModuleFragmentAST* { + if (!ast) return {}; + + auto copy = make_node(arena()); + + copy->moduleLoc = ast->moduleLoc; + copy->colonLoc = ast->colonLoc; + copy->privateLoc = ast->privateLoc; + copy->semicolonLoc = ast->semicolonLoc; + + for (auto declarationList = ©->declarationList; + auto node : ListView{ast->declarationList}) { + auto value = declaration(node); + *declarationList = make_list_node(arena(), value); + declarationList = &(*declarationList)->next; + } + + return copy; +} + +auto ASTRewriter::moduleDeclaration(ModuleDeclarationAST* ast) + -> ModuleDeclarationAST* { + if (!ast) return {}; + + auto copy = make_node(arena()); + + copy->exportLoc = ast->exportLoc; + copy->moduleLoc = ast->moduleLoc; + copy->moduleName = moduleName(ast->moduleName); + copy->modulePartition = modulePartition(ast->modulePartition); + + for (auto attributeList = ©->attributeList; + auto node : ListView{ast->attributeList}) { + auto value = attributeSpecifier(node); + *attributeList = make_list_node(arena(), value); + attributeList = &(*attributeList)->next; + } + + copy->semicolonLoc = ast->semicolonLoc; + + return copy; +} + +auto ASTRewriter::moduleName(ModuleNameAST* ast) -> ModuleNameAST* { + if (!ast) return {}; + + auto copy = make_node(arena()); + + copy->moduleQualifier = moduleQualifier(ast->moduleQualifier); + copy->identifierLoc = ast->identifierLoc; + copy->identifier = ast->identifier; + + return copy; +} + +auto ASTRewriter::moduleQualifier(ModuleQualifierAST* ast) + -> ModuleQualifierAST* { + if (!ast) return {}; + + auto copy = make_node(arena()); + + copy->moduleQualifier = moduleQualifier(ast->moduleQualifier); + copy->identifierLoc = ast->identifierLoc; + copy->dotLoc = ast->dotLoc; + copy->identifier = ast->identifier; + + return copy; +} + +auto ASTRewriter::modulePartition(ModulePartitionAST* ast) + -> ModulePartitionAST* { + if (!ast) return {}; + + auto copy = make_node(arena()); + + copy->colonLoc = ast->colonLoc; + copy->moduleName = moduleName(ast->moduleName); + + return copy; +} + +auto ASTRewriter::importName(ImportNameAST* ast) -> ImportNameAST* { + if (!ast) return {}; + + auto copy = make_node(arena()); + + copy->headerLoc = ast->headerLoc; + copy->modulePartition = modulePartition(ast->modulePartition); + copy->moduleName = moduleName(ast->moduleName); + + return copy; +} + +auto ASTRewriter::UnitVisitor::operator()(TranslationUnitAST* ast) -> UnitAST* { + auto copy = make_node(arena()); + + for (auto declarationList = ©->declarationList; + auto node : ListView{ast->declarationList}) { + auto value = rewrite.declaration(node); + *declarationList = make_list_node(arena(), value); + declarationList = &(*declarationList)->next; + } + + return copy; +} + +auto ASTRewriter::UnitVisitor::operator()(ModuleUnitAST* ast) -> UnitAST* { + auto copy = make_node(arena()); + + copy->globalModuleFragment = + rewrite.globalModuleFragment(ast->globalModuleFragment); + copy->moduleDeclaration = rewrite.moduleDeclaration(ast->moduleDeclaration); + + for (auto declarationList = ©->declarationList; + auto node : ListView{ast->declarationList}) { + auto value = rewrite.declaration(node); + *declarationList = make_list_node(arena(), value); + declarationList = &(*declarationList)->next; + } + + copy->privateModuleFragment = + rewrite.privateModuleFragment(ast->privateModuleFragment); + + return copy; +} + +} // namespace cxx \ No newline at end of file diff --git a/src/parser/cxx/binder.cc b/src/parser/cxx/binder.cc index a366edaa..3cb554f5 100644 --- a/src/parser/cxx/binder.cc +++ b/src/parser/cxx/binder.cc @@ -23,6 +23,7 @@ // cxx #include #include +#include #include #include #include @@ -32,6 +33,7 @@ #include #include #include +#include #include #include @@ -83,6 +85,18 @@ auto Binder::currentTemplateParameters() const -> TemplateParametersSymbol* { return templateParameters; } +auto Binder::isInstantiating() const -> bool { + return instantiatingSymbol_ != nullptr; +} + +auto Binder::instantiatingSymbol() const -> Symbol* { + return instantiatingSymbol_; +} + +void Binder::setInstantiatingSymbol(Symbol* symbol) { + instantiatingSymbol_ = symbol; +} + auto Binder::declaringScope() const -> Scope* { if (!scope_) return nullptr; if (!scope_->isTemplateParametersScope()) return scope_; @@ -404,14 +418,15 @@ void Binder::bind(EnumeratorAST* ast, const Type* type, } } -auto Binder::declareTypeAlias(SourceLocation identifierLoc, TypeIdAST* typeId) - -> TypeAliasSymbol* { - auto name = unit_->identifier(identifierLoc); +auto Binder::declareTypeAlias(SourceLocation identifierLoc, TypeIdAST* typeId, + bool addSymbolToParentScope) -> TypeAliasSymbol* { auto symbol = control()->newTypeAliasSymbol(scope(), identifierLoc); + + auto name = unit_->identifier(identifierLoc); symbol->setName(name); + if (typeId) symbol->setType(typeId->type); symbol->setTemplateParameters(currentTemplateParameters()); - declaringScope()->addSymbol(symbol); if (auto classType = type_cast(symbol->type())) { auto classSymbol = classType->symbol(); @@ -434,6 +449,10 @@ auto Binder::declareTypeAlias(SourceLocation identifierLoc, TypeIdAST* typeId) } } + if (addSymbolToParentScope) { + declaringScope()->addSymbol(symbol); + } + return symbol; } @@ -521,12 +540,10 @@ void Binder::bind(NonTypeTemplateParameterAST* ast, int index, int depth) { void Binder::bind(TypenameTypeParameterAST* ast, int index, int depth) { auto location = ast->identifier ? ast->identifierLoc : ast->classKeyLoc; - auto symbol = control()->newTypeParameterSymbol(scope(), location); + auto symbol = control()->newTypeParameterSymbol(scope(), location, index, + depth, ast->isPack); ast->symbol = symbol; - symbol->setIndex(index); - symbol->setDepth(depth); - symbol->setParameterPack(ast->isPack); symbol->setName(ast->identifier); scope()->addSymbol(symbol); } @@ -541,15 +558,14 @@ void Binder::bind(ConstraintTypeParameterAST* ast, int index, int depth) { } void Binder::bind(TemplateTypeParameterAST* ast, int index, int depth) { - auto symbol = - control()->newTemplateTypeParameterSymbol(scope(), ast->templateLoc); + std::vector parameters; + + auto symbol = control()->newTemplateTypeParameterSymbol( + scope(), ast->templateLoc, index, depth, ast->isPack, + std::move(parameters)); ast->symbol = symbol; - symbol->setIndex(index); - symbol->setDepth(depth); - symbol->setName(ast->identifier); - symbol->setParameterPack(ast->isPack); scope()->addSymbol(symbol); } @@ -849,16 +865,28 @@ auto Binder::resolveNestedNameSpecifier(Symbol* symbol) -> ScopedSymbol* { } auto Binder::resolve(NestedNameSpecifierAST* nestedNameSpecifier, - UnqualifiedIdAST* unqualifiedId, bool canInstantiate) + UnqualifiedIdAST* unqualifiedId, bool checkTemplates) -> Symbol* { if (auto templateId = ast_cast(unqualifiedId)) { - if (!canInstantiate) return nullptr; + if (!checkTemplates) return templateId->symbol; - auto instance = instantiate(templateId); + if (auto classSymbol = symbol_cast(templateId->symbol)) { + // todo: delay + auto instance = ASTRewriter::instantiateClassTemplate( + unit_, templateId->templateArgumentList, classSymbol); - if (!is_type(instance)) return nullptr; + return instance; + } + + if (auto typeAliasSymbol = + symbol_cast(templateId->symbol)) { + auto instance = ASTRewriter::instantiateTypeAliasTemplate( + unit_, templateId->templateArgumentList, typeAliasSymbol); + + return instance; + } - return instance; + return templateId->symbol; } auto name = ast_cast(unqualifiedId); @@ -871,39 +899,6 @@ auto Binder::resolve(NestedNameSpecifierAST* nestedNameSpecifier, return symbol; } -auto Binder::instantiate(SimpleTemplateIdAST* templateId) -> Symbol* { - if (!translationUnit()->config().templateInstantiation) return nullptr; - - std::vector args; - for (auto it = templateId->templateArgumentList; it; it = it->next) { - if (auto arg = ast_cast(it->value)) { - args.push_back(arg->typeId->type); - } else { - error(it->value->firstSourceLocation(), - std::format("only type template arguments are supported")); - } - } - - auto needsInstantiation = [&]() -> bool { - if (args.empty()) return true; - for (std::size_t i = 0; i < args.size(); ++i) { - auto typeArgument = std::get_if(&args[i]); - if (!typeArgument) return true; - auto ty = type_cast(*typeArgument); - if (!ty) return true; - if (ty->symbol()->index() != i) return true; - } - return false; - }; - - if (!needsInstantiation()) return nullptr; - - auto symbol = control()->instantiate(unit_, templateId->primaryTemplateSymbol, - std::move(args)); - - return symbol; -} - void Binder::bind(IdExpressionAST* ast) { if (ast->unqualifiedId) { auto name = get_name(control(), ast->unqualifiedId); @@ -914,4 +909,38 @@ void Binder::bind(IdExpressionAST* ast) { } } +auto Binder::getFunction(Scope* scope, const Name* name, const Type* type) + -> FunctionSymbol* { + auto parentScope = scope; + + while (parentScope && parentScope->isTransparent()) { + parentScope = parentScope->parent(); + } + + if (auto parentClass = symbol_cast(parentScope->owner()); + parentClass && parentClass->name() == name) { + for (auto ctor : parentClass->constructors()) { + if (control()->is_same(ctor->type(), type)) { + return ctor; + } + } + } + + for (auto candidate : scope->find(name)) { + if (auto function = symbol_cast(candidate)) { + if (control()->is_same(function->type(), type)) { + return function; + } + } else if (auto overloads = symbol_cast(candidate)) { + for (auto function : overloads->functions()) { + if (control()->is_same(function->type(), type)) { + return function; + } + } + } + } + + return nullptr; +} + } // namespace cxx diff --git a/src/parser/cxx/binder.h b/src/parser/cxx/binder.h index 6723bca8..3a1022e7 100644 --- a/src/parser/cxx/binder.h +++ b/src/parser/cxx/binder.h @@ -55,6 +55,10 @@ class Binder { void setScope(Scope* scope); void setScope(ScopedSymbol* symbol); + [[nodiscard]] auto isInstantiating() const -> bool; + [[nodiscard]] auto instantiatingSymbol() const -> Symbol*; + void setInstantiatingSymbol(Symbol* symbol); + [[nodiscard]] auto declaringScope() const -> Scope*; [[nodiscard]] auto currentTemplateParameters() const @@ -65,7 +69,9 @@ class Binder { [[nodiscard]] auto enterBlock(SourceLocation loc) -> BlockSymbol*; [[nodiscard]] auto declareTypeAlias(SourceLocation identifierLoc, - TypeIdAST* typeId) -> TypeAliasSymbol*; + TypeIdAST* typeId, + bool addSymbolToParentScope = true) + -> TypeAliasSymbol*; [[nodiscard]] auto declareTypedef(DeclaratorAST* declarator, const Decl& decl) -> TypeAliasSymbol*; @@ -131,15 +137,16 @@ class Binder { void bind(IdExpressionAST* ast); - [[nodiscard]] auto instantiate(SimpleTemplateIdAST* templateId) -> Symbol*; - [[nodiscard]] auto resolve(NestedNameSpecifierAST* nestedNameSpecifier, UnqualifiedIdAST* unqualifiedId, - bool canInstantiate) -> Symbol*; + bool checkTemplates) -> Symbol*; [[nodiscard]] auto resolveNestedNameSpecifier(Symbol* symbol) -> ScopedSymbol*; + [[nodiscard]] auto getFunction(Scope* scope, const Name* name, + const Type* type) -> FunctionSymbol*; + class ScopeGuard { public: Binder* p = nullptr; @@ -164,6 +171,7 @@ class Binder { private: TranslationUnit* unit_ = nullptr; Scope* scope_ = nullptr; + Symbol* instantiatingSymbol_ = nullptr; bool inTemplate_ = false; bool reportErrors_ = true; }; diff --git a/src/parser/cxx/control.cc b/src/parser/cxx/control.cc index a4c3b8d7..5649624e 100644 --- a/src/parser/cxx/control.cc +++ b/src/parser/cxx/control.cc @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include @@ -427,14 +426,18 @@ auto Control::getMemberFunctionPointerType(const ClassType* classType, return &*d->memberFunctionPointerTypes.emplace(classType, functionType).first; } -auto Control::getTypeParameterType(TypeParameterSymbol* symbol) +auto Control::getTypeParameterType(int index, int depth, bool isParameterPack) -> const TypeParameterType* { - return &*d->typeParameterTypes.emplace(symbol).first; + return &*d->typeParameterTypes.emplace(index, depth, isParameterPack).first; } -auto Control::getTemplateTypeParameterType(TemplateTypeParameterSymbol* symbol) +auto Control::getTemplateTypeParameterType( + int index, int depth, bool isPack, + std::vector templateParameters) -> const TemplateTypeParameterType* { - return &*d->templateTypeParameterTypes.emplace(symbol).first; + return &*d->templateTypeParameterTypes + .emplace(index, depth, isPack, std::move(templateParameters)) + .first; } auto Control::getUnresolvedNameType(TranslationUnit* unit, @@ -605,19 +608,22 @@ auto Control::newParameterPackSymbol(Scope* enclosingScope, SourceLocation loc) return symbol; } -auto Control::newTypeParameterSymbol(Scope* enclosingScope, SourceLocation loc) +auto Control::newTypeParameterSymbol(Scope* enclosingScope, SourceLocation loc, + int index, int depth, bool isParameterPack) -> TypeParameterSymbol* { auto symbol = &d->typeParameterSymbols.emplace_front(enclosingScope); - symbol->setType(getTypeParameterType(symbol)); + symbol->setType(getTypeParameterType(index, depth, isParameterPack)); symbol->setLocation(loc); return symbol; } -auto Control::newTemplateTypeParameterSymbol(Scope* enclosingScope, - SourceLocation loc) +auto Control::newTemplateTypeParameterSymbol( + Scope* enclosingScope, SourceLocation loc, int index, int depth, + bool isPack, std::vector parameters) -> TemplateTypeParameterSymbol* { auto symbol = &d->templateTypeParameterSymbols.emplace_front(enclosingScope); - symbol->setType(getTemplateTypeParameterType(symbol)); + symbol->setType(getTemplateTypeParameterType(index, depth, isPack, + std::move(parameters))); symbol->setLocation(loc); return symbol; } @@ -875,11 +881,4 @@ auto Control::decay(const Type* type) -> const Type* { return d->traits.decay(type); } -auto Control::instantiate(TranslationUnit* unit, Symbol* symbol, - const std::vector& arguments) - -> Symbol* { - SymbolInstantiation instantiate{unit, arguments}; - return instantiate(symbol); -} - } // namespace cxx diff --git a/src/parser/cxx/control.h b/src/parser/cxx/control.h index 1cc1f58f..fdd8750e 100644 --- a/src/parser/cxx/control.h +++ b/src/parser/cxx/control.h @@ -135,10 +135,12 @@ class Control { [[nodiscard]] auto getMemberFunctionPointerType( const ClassType* classType, const FunctionType* functionType) -> const MemberFunctionPointerType*; - [[nodiscard]] auto getTypeParameterType(TypeParameterSymbol* symbol) + [[nodiscard]] auto getTypeParameterType(int index, int depth, bool isPack) -> const TypeParameterType*; [[nodiscard]] auto getTemplateTypeParameterType( - TemplateTypeParameterSymbol* symbol) -> const TemplateTypeParameterType*; + int index, int depth, bool isPack, + std::vector templateParameters) + -> const TemplateTypeParameterType*; [[nodiscard]] auto getUnresolvedNameType( TranslationUnit* unit, NestedNameSpecifierAST* nestedNameSpecifier, UnqualifiedIdAST* unqualifiedId) -> const UnresolvedNameType*; @@ -208,13 +210,16 @@ class Control { SourceLocation sourceLocation) -> ParameterPackSymbol*; [[nodiscard]] auto newTypeParameterSymbol(Scope* enclosingScope, - SourceLocation sourceLocation) + SourceLocation sourceLocation, + int index, int depth, + bool isParameterPack) -> TypeParameterSymbol*; [[nodiscard]] auto newNonTypeParameterSymbol(Scope* enclosingScope, SourceLocation sourceLocation) -> NonTypeParameterSymbol*; [[nodiscard]] auto newTemplateTypeParameterSymbol( - Scope* enclosingScope, SourceLocation sourceLocation) + Scope* enclosingScope, SourceLocation sourceLocation, int index, + int depth, bool isPack, std::vector parameters) -> TemplateTypeParameterSymbol*; [[nodiscard]] auto newConstraintTypeParameterSymbol( Scope* enclosingScope, SourceLocation sourceLocation) @@ -226,10 +231,6 @@ class Control { SourceLocation sourceLocation) -> UsingDeclarationSymbol*; - [[nodiscard]] auto instantiate(TranslationUnit* unit, Symbol* primaryTemplate, - const std::vector& arguments) - -> Symbol*; - // primary type categories [[nodiscard]] auto is_void(const Type* type) -> bool; [[nodiscard]] auto is_null_pointer(const Type* type) -> bool; diff --git a/src/parser/cxx/external_name_encoder.cc b/src/parser/cxx/external_name_encoder.cc index aa9ab398..3b23a845 100644 --- a/src/parser/cxx/external_name_encoder.cc +++ b/src/parser/cxx/external_name_encoder.cc @@ -318,8 +318,10 @@ struct ExternalNameEncoder::EncodeType { } auto operator()(const BuiltinVaListType* type) -> bool { - cxx_runtime_error(std::format("todo encode type '{}'", to_string(type))); - return false; + // cxx_runtime_error(std::format("todo encode type '{}'", to_string(type))); + // return encoder.encode() + encoder.out("Pc"); + return true; } }; @@ -642,6 +644,13 @@ void ExternalNameEncoder::encodePrefix(Symbol* symbol) { void ExternalNameEncoder::encodeTemplatePrefix(Symbol* symbol) {} void ExternalNameEncoder::encodeUnqualifiedName(Symbol* symbol) { + if (auto ns = symbol_cast(symbol); ns && !ns->name()) { + auto index = ns->anonNamespaceIndex().value(); + std::string name = std::format("_GLOBAL__N_{}", index + 1); + out(std::format("{}{}", name.length(), name)); + return; + } + visit(EncodeUnqualifiedName{*this, symbol}, symbol->name()); } diff --git a/src/parser/cxx/parser.cc b/src/parser/cxx/parser.cc index 8c7f37a0..85147ab1 100644 --- a/src/parser/cxx/parser.cc +++ b/src/parser/cxx/parser.cc @@ -23,6 +23,7 @@ // cxx #include #include +#include #include #include #include @@ -31,7 +32,6 @@ #include #include #include -#include #include #include #include @@ -1010,9 +1010,8 @@ struct IsReferencingTemplateParameter { auto typeParam = type_cast(type); if (!typeParam) return false; - auto typeParamSymbol = typeParam->symbol(); - if (typeParamSymbol->depth() != depth) return false; - if (typeParamSymbol->index() != index) return false; + if (typeParam->depth() != depth) return false; + if (typeParam->index() != index) return false; return true; } @@ -1050,26 +1049,26 @@ auto Parser::parse_template_nested_name_specifier( ast->scopeLoc = scopeLoc; ast->isTemplateIntroduced = isTemplateIntroduced; - if (ctx == NestedNameSpecifierContext::kDeclarative) { - bool isReferencingPrimaryTemplate = true; + if (config().checkTypes) { + // replace with instantiated class template + if (auto classSymbol = symbol_cast(templateId->symbol)) { + auto instance = ASTRewriter::instantiateClassTemplate( + unit, templateId->templateArgumentList, classSymbol); - for (int index = 0; auto arg : ListView{templateId->templateArgumentList}) { - if (!visit(IsReferencingTemplateParameter{*this, depth, index}, arg)) { - isReferencingPrimaryTemplate = false; - break; - } - ++index; - } + templateId->symbol = instance; - if (isReferencingPrimaryTemplate) { - ast->symbol = - binder_.resolveNestedNameSpecifier(templateId->primaryTemplateSymbol); - } - } + ast->symbol = instance; + } else if (auto typeAliasSymbol = + symbol_cast(templateId->symbol)) { + auto instance = ASTRewriter::instantiateTypeAliasTemplate( + unit, templateId->templateArgumentList, typeAliasSymbol); - if (!ast->symbol && config().checkTypes) { - ast->symbol = - binder_.resolveNestedNameSpecifier(binder_.instantiate(templateId)); + templateId->symbol = instance; + + if (auto classType = type_cast(instance->type())) { + ast->symbol = classType->symbol(); + } + } } return true; @@ -4059,6 +4058,8 @@ auto Parser::enterOrCreateNamespace(const Identifier* identifier, if (identifier) { namespaceSymbol->setName(identifier); } else { + const auto anonNamespaceIndex = anonNamespaceCount_++; + namespaceSymbol->setAnonNamespaceIndex(anonNamespaceIndex); parentNamespace->setUnnamedNamespace(namespaceSymbol); } @@ -4306,7 +4307,8 @@ auto Parser::parse_simple_declaration( } const Name* functionName = decl.getName(); - auto functionSymbol = getFunction(scope(), functionName, functionType); + auto functionSymbol = + binder_.getFunction(scope(), functionName, functionType); if (!functionSymbol) { if (q && config().checkTypes) { @@ -4347,6 +4349,7 @@ auto Parser::parse_simple_declaration( ast->requiresClause = requiresClause; ast->functionBody = functionBody; ast->symbol = functionSymbol; + ast->symbol->setDeclaration(ast); if (classDepth_) pendingFunctionDefinitions_.push_back(ast); @@ -4451,8 +4454,8 @@ auto Parser::parse_notypespec_function_definition( if (!isDeclaration && !isDefinition) return false; - FunctionSymbol* functionSymbol = - getFunction(scope(), decl.getName(), functionType); + auto functionSymbol = + binder_.getFunction(scope(), decl.getName(), functionType); if (!functionSymbol) { functionSymbol = binder_.declareFunction(declarator, decl); @@ -4501,6 +4504,7 @@ auto Parser::parse_notypespec_function_definition( ast->declarator = declarator; ast->functionBody = functionBody; ast->symbol = functionSymbol; + ast->symbol->setDeclaration(ast); if (classDepth_) pendingFunctionDefinitions_.push_back(ast); @@ -5100,6 +5104,8 @@ auto Parser::parse_named_type_specifier(SpecifierAST*& yyast, DeclSpecs& specs) if (!lookat(TokenKind::T_IDENTIFIER)) return false; + auto id = unit->identifier(currentLocation()); + UnqualifiedIdAST* unqualifiedId = nullptr; if (!parse_type_name(unqualifiedId, nestedNameSpecifier, isTemplateIntroduced)) { @@ -5107,18 +5113,23 @@ auto Parser::parse_named_type_specifier(SpecifierAST*& yyast, DeclSpecs& specs) } if (auto templateId = ast_cast(unqualifiedId)) { - auto primaryTemplateSymbol = templateId->primaryTemplateSymbol; + auto primaryTemplateSymbol = templateId->symbol; auto conceptSymbol = symbol_cast(primaryTemplateSymbol); if (conceptSymbol && !lookat(TokenKind::T_AUTO)) return false; } - const auto canInstantiate = config().checkTypes; + const auto checkTemplates = config().checkTypes; auto symbol = - binder_.resolve(nestedNameSpecifier, unqualifiedId, canInstantiate); + binder_.resolve(nestedNameSpecifier, unqualifiedId, checkTemplates); - if (config().checkTypes && !symbol && ast_cast(unqualifiedId)) { - return false; + if (config().checkTypes) { + if (!is_type(symbol)) { + auto name = get_name(control_, unqualifiedId); + parse_error(unqualifiedId->firstSourceLocation(), + std::format("'{}' is not a type", to_string(name))); + return false; + } } lookahead.commit(); @@ -8176,6 +8187,7 @@ auto Parser::parse_member_declaration_helper(DeclarationAST*& yyast) -> bool { ast->requiresClause = requiresClause; ast->functionBody = functionBody; ast->symbol = functionSymbol; + ast->symbol->setDeclaration(ast); if (classDepth_) pendingFunctionDefinitions_.push_back(ast); @@ -9218,6 +9230,11 @@ auto Parser::parse_simple_template_id(SimpleTemplateIdAST*& yyast) -> bool { expect(TokenKind::T_GREATER, ast->greaterLoc); } + auto candidate = Lookup{scope()}( + ast->identifier, [this](Symbol* symbol) { return is_template(symbol); }); + + ast->symbol = candidate; + return true; } @@ -9251,7 +9268,7 @@ auto Parser::parse_simple_template_id( if (!maybe_template_name(templateId->identifier)) return false; } - templateId->primaryTemplateSymbol = primaryTemplateSymbol; + templateId->symbol = primaryTemplateSymbol; yyast = templateId; @@ -9644,6 +9661,32 @@ auto Parser::parse_explicit_instantiation(DeclarationAST*& yyast) -> bool { if (!parse_declaration(ast->declaration, BindingContext::kTemplate)) parse_error("expected a declaration"); + auto check_elaborated_type_specifier = [&] { + if (!config().checkTypes) return; + + auto simpleDecl = ast_cast(ast->declaration); + if (!simpleDecl) return; + + if (!simpleDecl->declSpecifierList) return; + + auto elabSpec = ast_cast( + simpleDecl->declSpecifierList->value); + if (!elabSpec) return; + + auto templateId = ast_cast(elabSpec->unqualifiedId); + if (!templateId) return; + + auto classSymbol = symbol_cast(templateId->symbol); + if (!classSymbol) return; + + auto instance = ASTRewriter::instantiateClassTemplate( + unit, templateId->templateArgumentList, classSymbol); + + (void)instance; + }; + + check_elaborated_type_specifier(); + return true; } @@ -9948,38 +9991,4 @@ auto Parser::implicit_conversion(ExpressionAST*& yyast, const Type* targetType) return check.implicit_conversion(yyast, targetType); } -auto Parser::getFunction(Scope* scope, const Name* name, const Type* type) - -> FunctionSymbol* { - auto parentScope = scope; - - while (parentScope && parentScope->isTransparent()) { - parentScope = parentScope->parent(); - } - - if (auto parentClass = symbol_cast(parentScope->owner()); - parentClass && parentClass->name() == name) { - for (auto ctor : parentClass->constructors()) { - if (control_->is_same(ctor->type(), type)) { - return ctor; - } - } - } - - for (auto candidate : scope->find(name)) { - if (auto function = symbol_cast(candidate)) { - if (control_->is_same(function->type(), type)) { - return function; - } - } else if (auto overloads = symbol_cast(candidate)) { - for (auto function : overloads->functions()) { - if (control_->is_same(function->type(), type)) { - return function; - } - } - } - } - - return nullptr; -} - } // namespace cxx diff --git a/src/parser/cxx/parser.h b/src/parser/cxx/parser.h index 6d650914..0e25aa9c 100644 --- a/src/parser/cxx/parser.h +++ b/src/parser/cxx/parser.h @@ -799,9 +799,6 @@ class Parser final { // lookup - [[nodiscard]] auto getFunction(Scope* scope, const Name* name, - const Type* type) -> FunctionSymbol*; - [[nodiscard]] auto enterOrCreateNamespace(const Identifier* identifier, SourceLocation identifeirLoc, bool isInline) -> NamespaceSymbol*; @@ -845,6 +842,7 @@ class Parser final { int classDepth_ = 0; std::uint32_t lastErrorCursor_ = 0; std::uint32_t cursor_ = 0; + int anonNamespaceCount_ = 0; int templateParameterDepth_ = -1; int templateParameterCount_ = 0; bool didAcceptCompletionToken_ = false; diff --git a/src/parser/cxx/symbol_instantiation.cc b/src/parser/cxx/symbol_instantiation.cc deleted file mode 100644 index a3005461..00000000 --- a/src/parser/cxx/symbol_instantiation.cc +++ /dev/null @@ -1,679 +0,0 @@ -// Copyright (c) 2025 Roberto Raggi -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -#include - -// cxx -#include -#include -#include -#include -#include -#include -#include - -#include - -namespace cxx { - -struct SymbolInstantiation::MakeSymbol { - SymbolInstantiation& self; - - auto operator()(SymbolKind kind, SourceLocation location = {}) -> Symbol* { -#define MAKE_SYMBOL(S) \ - case SymbolKind::k##S: \ - return self.control()->new##S##Symbol(nullptr, location); - - switch (kind) { - CXX_FOR_EACH_SYMBOL(MAKE_SYMBOL) - default: - return nullptr; - } // switch - } -}; - -struct SymbolInstantiation::VisitSymbol { - SymbolInstantiation& self; - - [[nodiscard]] auto operator()(NamespaceSymbol* symbol) -> Symbol*; - [[nodiscard]] auto operator()(ConceptSymbol* symbol) -> Symbol*; - [[nodiscard]] auto operator()(ClassSymbol* symbol) -> Symbol*; - [[nodiscard]] auto operator()(EnumSymbol* symbol) -> Symbol*; - [[nodiscard]] auto operator()(ScopedEnumSymbol* symbol) -> Symbol*; - [[nodiscard]] auto operator()(FunctionSymbol* symbol) -> Symbol*; - [[nodiscard]] auto operator()(TypeAliasSymbol* symbol) -> Symbol*; - [[nodiscard]] auto operator()(VariableSymbol* symbol) -> Symbol*; - [[nodiscard]] auto operator()(FieldSymbol* symbol) -> Symbol*; - [[nodiscard]] auto operator()(ParameterSymbol* symbol) -> Symbol*; - [[nodiscard]] auto operator()(ParameterPackSymbol* symbol) -> Symbol*; - [[nodiscard]] auto operator()(EnumeratorSymbol* symbol) -> Symbol*; - [[nodiscard]] auto operator()(FunctionParametersSymbol* symbol) -> Symbol*; - [[nodiscard]] auto operator()(TemplateParametersSymbol* symbol) -> Symbol*; - [[nodiscard]] auto operator()(BlockSymbol* symbol) -> Symbol*; - [[nodiscard]] auto operator()(LambdaSymbol* symbol) -> Symbol*; - [[nodiscard]] auto operator()(TypeParameterSymbol* symbol) -> Symbol*; - [[nodiscard]] auto operator()(NonTypeParameterSymbol* symbol) -> Symbol*; - [[nodiscard]] auto operator()(TemplateTypeParameterSymbol* symbol) -> Symbol*; - [[nodiscard]] auto operator()(ConstraintTypeParameterSymbol* symbol) - -> Symbol*; - [[nodiscard]] auto operator()(OverloadSetSymbol* symbol) -> Symbol*; - [[nodiscard]] auto operator()(BaseClassSymbol* symbol) -> Symbol*; - [[nodiscard]] auto operator()(UsingDeclarationSymbol* symbol) -> Symbol*; -}; - -struct SymbolInstantiation::VisitType { - SymbolInstantiation& self; - - [[nodiscard]] auto substitute(const Type* type) -> const Type* { - if (!type) return nullptr; - return visit(*this, type); - } - - [[nodiscard]] auto operator()(const BuiltinVaListType* type) -> const Type*; - [[nodiscard]] auto operator()(const VoidType* type) -> const Type*; - [[nodiscard]] auto operator()(const NullptrType* type) -> const Type*; - [[nodiscard]] auto operator()(const DecltypeAutoType* type) -> const Type*; - [[nodiscard]] auto operator()(const AutoType* type) -> const Type*; - [[nodiscard]] auto operator()(const BoolType* type) -> const Type*; - [[nodiscard]] auto operator()(const SignedCharType* type) -> const Type*; - [[nodiscard]] auto operator()(const ShortIntType* type) -> const Type*; - [[nodiscard]] auto operator()(const IntType* type) -> const Type*; - [[nodiscard]] auto operator()(const LongIntType* type) -> const Type*; - [[nodiscard]] auto operator()(const LongLongIntType* type) -> const Type*; - [[nodiscard]] auto operator()(const Int128Type* type) -> const Type*; - [[nodiscard]] auto operator()(const UnsignedCharType* type) -> const Type*; - [[nodiscard]] auto operator()(const UnsignedShortIntType* type) - -> const Type*; - [[nodiscard]] auto operator()(const UnsignedIntType* type) -> const Type*; - [[nodiscard]] auto operator()(const UnsignedLongIntType* type) -> const Type*; - [[nodiscard]] auto operator()(const UnsignedLongLongIntType* type) - -> const Type*; - [[nodiscard]] auto operator()(const UnsignedInt128Type* type) -> const Type*; - [[nodiscard]] auto operator()(const CharType* type) -> const Type*; - [[nodiscard]] auto operator()(const Char8Type* type) -> const Type*; - [[nodiscard]] auto operator()(const Char16Type* type) -> const Type*; - [[nodiscard]] auto operator()(const Char32Type* type) -> const Type*; - [[nodiscard]] auto operator()(const WideCharType* type) -> const Type*; - [[nodiscard]] auto operator()(const FloatType* type) -> const Type*; - [[nodiscard]] auto operator()(const DoubleType* type) -> const Type*; - [[nodiscard]] auto operator()(const LongDoubleType* type) -> const Type*; - [[nodiscard]] auto operator()(const QualType* type) -> const Type*; - [[nodiscard]] auto operator()(const BoundedArrayType* type) -> const Type*; - [[nodiscard]] auto operator()(const UnboundedArrayType* type) -> const Type*; - [[nodiscard]] auto operator()(const PointerType* type) -> const Type*; - [[nodiscard]] auto operator()(const LvalueReferenceType* type) -> const Type*; - [[nodiscard]] auto operator()(const RvalueReferenceType* type) -> const Type*; - [[nodiscard]] auto operator()(const FunctionType* type) -> const Type*; - [[nodiscard]] auto operator()(const ClassType* type) -> const Type*; - [[nodiscard]] auto operator()(const EnumType* type) -> const Type*; - [[nodiscard]] auto operator()(const ScopedEnumType* type) -> const Type*; - [[nodiscard]] auto operator()(const MemberObjectPointerType* type) - -> const Type*; - [[nodiscard]] auto operator()(const MemberFunctionPointerType* type) - -> const Type*; - [[nodiscard]] auto operator()(const NamespaceType* type) -> const Type*; - [[nodiscard]] auto operator()(const TypeParameterType* type) -> const Type*; - [[nodiscard]] auto operator()(const TemplateTypeParameterType* type) - -> const Type*; - [[nodiscard]] auto operator()(const UnresolvedNameType* type) -> const Type*; - [[nodiscard]] auto operator()(const UnresolvedBoundedArrayType* type) - -> const Type*; - [[nodiscard]] auto operator()(const UnresolvedUnderlyingType* type) - -> const Type*; - [[nodiscard]] auto operator()(const OverloadSetType* type) -> const Type*; -}; - -SymbolInstantiation::SymbolInstantiation( - TranslationUnit* unit, const std::vector& arguments) - : unit_(unit), arguments_(arguments) {} - -SymbolInstantiation::~SymbolInstantiation() {} - -auto SymbolInstantiation::control() const -> Control* { - return unit_->control(); -} - -auto SymbolInstantiation::operator()(Symbol* symbol) -> Symbol* { - if (!symbol) return symbol; - - if (auto classSymbol = symbol_cast(symbol)) { - if (auto specialization = classSymbol->findSpecialization(arguments_)) { - return specialization; - } - - std::swap(current_, symbol); - auto specialization = replacement(classSymbol); - std::swap(current_, symbol); - - if (specialization == classSymbol) { - cxx_runtime_error("cannot specialize itself"); - } - - classSymbol->addSpecialization(arguments_, specialization); - } - - std::swap(current_, symbol); - auto instantiation = visit(VisitSymbol{*this}, current_); - std::swap(current_, symbol); - - return instantiation; -} - -auto SymbolInstantiation::findOrCreateReplacement(Symbol* symbol) -> Symbol* { - if (!symbol) return nullptr; - - if (symbol != current_ && !symbol->hasEnclosingSymbol(current_)) - return symbol; - - auto it = replacements_.find(symbol); - if (it != replacements_.end()) return it->second; - - auto newSymbol = MakeSymbol{*this}(symbol->kind()); - replacements_[symbol] = newSymbol; - - auto enclosingSymbol = replacement(symbol->enclosingSymbol()); - - newSymbol->setEnclosingScope(enclosingSymbol->scope()); - - if (symbol->type()) { - newSymbol->setType(visit(VisitType{*this}, symbol->type())); - - auto field = symbol_cast(newSymbol); - - if (field) { - auto memoryLayout = control()->memoryLayout(); - auto alignment = memoryLayout->alignmentOf(newSymbol->type()); - field->setAlignment(alignment.value_or(0)); - } - } - - newSymbol->setName(symbol->name()); - - return newSymbol; -} - -auto SymbolInstantiation::instantiateHelper(Symbol* symbol) -> Symbol* { - if (!symbol) return symbol; - return visit(VisitSymbol{*this}, symbol); -} - -auto SymbolInstantiation::VisitSymbol::operator()(NamespaceSymbol* symbol) - -> Symbol* { - cxx_runtime_error("NamespaceSymbol cannot be instantiated."); - return nullptr; -} - -auto SymbolInstantiation::VisitSymbol::operator()(ConceptSymbol* symbol) - -> Symbol* { - cxx_runtime_error("ConceptSymbol cannot be instantiated."); - return nullptr; -} - -auto SymbolInstantiation::VisitSymbol::operator()(ClassSymbol* symbol) - -> Symbol* { - auto newSymbol = self.replacement(symbol); - newSymbol->setFlags(symbol->flags()); - - if (symbol->isComplete()) { - newSymbol->setComplete(true); - } - - if (symbol != self.current_) { - newSymbol->setTemplateParameters( - self.instantiate(symbol->templateParameters())); - } - - for (auto baseClass : symbol->baseClasses()) { - auto newBaseClass = self.instantiate(baseClass); - newSymbol->addBaseClass(newBaseClass); - } - - for (auto ctor : symbol->constructors()) { - auto newCtor = self.instantiate(ctor); - newSymbol->addConstructor(newCtor); - } - - for (auto member : views::members(symbol)) { - auto newMember = self.instantiate(member); - newSymbol->addMember(newMember); - } - - auto status = newSymbol->buildClassLayout(self.control()); - - return newSymbol; -} - -auto SymbolInstantiation::VisitSymbol::operator()(EnumSymbol* symbol) - -> Symbol* { - auto newSymbol = self.replacement(symbol); - for (auto member : views::members(symbol)) { - auto newMember = self.instantiate(member); - newSymbol->addMember(newMember); - } - return newSymbol; -} - -auto SymbolInstantiation::VisitSymbol::operator()(ScopedEnumSymbol* symbol) - -> Symbol* { - auto newSymbol = self.replacement(symbol); - for (auto member : views::members(symbol)) { - auto newMember = self.instantiate(member); - newSymbol->addMember(newMember); - } - return newSymbol; -} - -auto SymbolInstantiation::VisitSymbol::operator()(FunctionSymbol* symbol) - -> Symbol* { - auto newSymbol = self.replacement(symbol); - for (auto member : views::members(symbol)) { - if (member->isBlock()) continue; - auto newMember = self.instantiate(member); - newSymbol->addMember(newMember); - } - return newSymbol; -} - -auto SymbolInstantiation::VisitSymbol::operator()(TypeAliasSymbol* symbol) - -> Symbol* { - auto newSymbol = self.replacement(symbol); - return newSymbol; -} - -auto SymbolInstantiation::VisitSymbol::operator()(VariableSymbol* symbol) - -> Symbol* { - auto newSymbol = self.replacement(symbol); - return newSymbol; -} - -auto SymbolInstantiation::VisitSymbol::operator()(FieldSymbol* symbol) - -> Symbol* { - auto newSymbol = self.replacement(symbol); - return newSymbol; -} - -auto SymbolInstantiation::VisitSymbol::operator()(ParameterSymbol* symbol) - -> Symbol* { - auto newSymbol = self.replacement(symbol); - return newSymbol; -} - -auto SymbolInstantiation::VisitSymbol::operator()(ParameterPackSymbol* symbol) - -> Symbol* { - auto newSymbol = self.replacement(symbol); - return newSymbol; -} - -auto SymbolInstantiation::VisitSymbol::operator()(EnumeratorSymbol* symbol) - -> Symbol* { - auto newSymbol = self.replacement(symbol); - return newSymbol; -} - -auto SymbolInstantiation::VisitSymbol::operator()( - FunctionParametersSymbol* symbol) -> Symbol* { - auto newSymbol = self.replacement(symbol); - for (auto member : views::members(symbol)) { - if (member->isBlock()) continue; - auto newMember = self.instantiate(member); - newSymbol->addMember(newMember); - } - return newSymbol; -} - -auto SymbolInstantiation::VisitSymbol::operator()( - TemplateParametersSymbol* symbol) -> Symbol* { - auto newSymbol = self.replacement(symbol); - for (auto member : views::members(symbol)) { - auto newMember = self.instantiate(member); - newSymbol->addMember(newMember); - } - return newSymbol; -} - -auto SymbolInstantiation::VisitSymbol::operator()(BlockSymbol* symbol) - -> Symbol* { - cxx_runtime_error("BlockSymbol cannot be instantiated."); - return nullptr; -} - -auto SymbolInstantiation::VisitSymbol::operator()(LambdaSymbol* symbol) - -> Symbol* { - cxx_runtime_error("LambdaSymbol cannot be instantiated."); - return nullptr; -} - -auto SymbolInstantiation::VisitSymbol::operator()(TypeParameterSymbol* symbol) - -> Symbol* { - auto newSymbol = self.replacement(symbol); - newSymbol->setIndex(symbol->index()); - newSymbol->setDepth(symbol->depth()); - newSymbol->setParameterPack(symbol->isParameterPack()); - return newSymbol; -} - -auto SymbolInstantiation::VisitSymbol::operator()( - NonTypeParameterSymbol* symbol) -> Symbol* { - auto newSymbol = self.replacement(symbol); - return newSymbol; -} - -auto SymbolInstantiation::VisitSymbol::operator()( - TemplateTypeParameterSymbol* symbol) -> Symbol* { - auto newSymbol = self.replacement(symbol); - return newSymbol; -} - -auto SymbolInstantiation::VisitSymbol::operator()( - ConstraintTypeParameterSymbol* symbol) -> Symbol* { - auto newSymbol = self.replacement(symbol); - return newSymbol; -} - -auto SymbolInstantiation::VisitSymbol::operator()(OverloadSetSymbol* symbol) - -> Symbol* { - auto newSymbol = self.replacement(symbol); - for (auto member : symbol->functions()) { - auto newMember = self.instantiate(member); - newSymbol->addFunction(newMember); - } - return newSymbol; -} - -auto SymbolInstantiation::VisitSymbol::operator()(BaseClassSymbol* symbol) - -> Symbol* { - auto newSymbol = self.replacement(symbol); - return newSymbol; -} - -auto SymbolInstantiation::VisitSymbol::operator()( - UsingDeclarationSymbol* symbol) -> Symbol* { - auto newSymbol = self.replacement(symbol); - newSymbol->setTarget(self.instantiate(symbol->target())); - return newSymbol; -} - -// types - -auto SymbolInstantiation::VisitType::operator()(const BuiltinVaListType* type) - -> const Type* { - return type; -} - -auto SymbolInstantiation::VisitType::operator()(const VoidType* type) - -> const Type* { - return type; -} - -auto SymbolInstantiation::VisitType::operator()(const NullptrType* type) - -> const Type* { - return type; -} - -auto SymbolInstantiation::VisitType::operator()(const DecltypeAutoType* type) - -> const Type* { - return type; -} - -auto SymbolInstantiation::VisitType::operator()(const AutoType* type) - -> const Type* { - return type; -} - -auto SymbolInstantiation::VisitType::operator()(const BoolType* type) - -> const Type* { - return type; -} - -auto SymbolInstantiation::VisitType::operator()(const SignedCharType* type) - -> const Type* { - return type; -} - -auto SymbolInstantiation::VisitType::operator()(const ShortIntType* type) - -> const Type* { - return type; -} - -auto SymbolInstantiation::VisitType::operator()(const IntType* type) - -> const Type* { - return type; -} - -auto SymbolInstantiation::VisitType::operator()(const LongIntType* type) - -> const Type* { - return type; -} - -auto SymbolInstantiation::VisitType::operator()(const LongLongIntType* type) - -> const Type* { - return type; -} - -auto SymbolInstantiation::VisitType::operator()(const Int128Type* type) - -> const Type* { - return type; -} - -auto SymbolInstantiation::VisitType::operator()(const UnsignedCharType* type) - -> const Type* { - return type; -} - -auto SymbolInstantiation::VisitType::operator()( - const UnsignedShortIntType* type) -> const Type* { - return type; -} - -auto SymbolInstantiation::VisitType::operator()(const UnsignedIntType* type) - -> const Type* { - return type; -} - -auto SymbolInstantiation::VisitType::operator()(const UnsignedLongIntType* type) - -> const Type* { - return type; -} - -auto SymbolInstantiation::VisitType::operator()(const UnsignedInt128Type* type) - -> const Type* { - return type; -} - -auto SymbolInstantiation::VisitType::operator()( - const UnsignedLongLongIntType* type) -> const Type* { - return type; -} - -auto SymbolInstantiation::VisitType::operator()(const CharType* type) - -> const Type* { - return type; -} - -auto SymbolInstantiation::VisitType::operator()(const Char8Type* type) - -> const Type* { - return type; -} - -auto SymbolInstantiation::VisitType::operator()(const Char16Type* type) - -> const Type* { - return type; -} - -auto SymbolInstantiation::VisitType::operator()(const Char32Type* type) - -> const Type* { - return type; -} - -auto SymbolInstantiation::VisitType::operator()(const WideCharType* type) - -> const Type* { - return type; -} - -auto SymbolInstantiation::VisitType::operator()(const FloatType* type) - -> const Type* { - return type; -} - -auto SymbolInstantiation::VisitType::operator()(const DoubleType* type) - -> const Type* { - return type; -} - -auto SymbolInstantiation::VisitType::operator()(const LongDoubleType* type) - -> const Type* { - return type; -} - -auto SymbolInstantiation::VisitType::operator()(const QualType* type) - -> const Type* { - auto elementType = substitute(type->elementType()); - return self.control()->getQualType(elementType, type->cvQualifiers()); -} - -auto SymbolInstantiation::VisitType::operator()(const BoundedArrayType* type) - -> const Type* { - auto elementType = substitute(type->elementType()); - return self.control()->getBoundedArrayType(elementType, type->size()); -} - -auto SymbolInstantiation::VisitType::operator()(const UnboundedArrayType* type) - -> const Type* { - auto elementType = substitute(type->elementType()); - return self.control()->getUnboundedArrayType(elementType); -} - -auto SymbolInstantiation::VisitType::operator()(const PointerType* type) - -> const Type* { - auto elementType = substitute(type->elementType()); - return self.control()->getPointerType(elementType); -} - -auto SymbolInstantiation::VisitType::operator()(const LvalueReferenceType* type) - -> const Type* { - auto elementType = substitute(type->elementType()); - return self.control()->add_lvalue_reference(elementType); -} - -auto SymbolInstantiation::VisitType::operator()(const RvalueReferenceType* type) - -> const Type* { - auto elementType = substitute(type->elementType()); - return self.control()->add_rvalue_reference(elementType); -} - -auto SymbolInstantiation::VisitType::operator()(const FunctionType* type) - -> const Type* { - auto returnType = substitute(type->returnType()); - - std::vector parameterTypes; - for (const auto& parameterType : type->parameterTypes()) { - parameterTypes.push_back(substitute(parameterType)); - } - return self.control()->getFunctionType( - returnType, std::move(parameterTypes), type->isVariadic(), - type->cvQualifiers(), type->refQualifier(), type->isNoexcept()); -} - -auto SymbolInstantiation::VisitType::operator()(const ClassType* type) - -> const Type* { - return self.control()->getClassType(self.replacement(type->symbol())); -} - -auto SymbolInstantiation::VisitType::operator()(const EnumType* type) - -> const Type* { - return self.replacement(type->symbol())->type(); -} - -auto SymbolInstantiation::VisitType::operator()(const ScopedEnumType* type) - -> const Type* { - return self.replacement(type->symbol())->type(); -} - -auto SymbolInstantiation::VisitType::operator()( - const MemberObjectPointerType* type) -> const Type* { - cxx_runtime_error("todo: substitute MemberObjectPointerType"); -} - -auto SymbolInstantiation::VisitType::operator()( - const MemberFunctionPointerType* type) -> const Type* { - cxx_runtime_error("todo: substitute MemberFunctionPointerType"); -} - -auto SymbolInstantiation::VisitType::operator()(const NamespaceType* type) - -> const Type* { - return type; -} - -auto SymbolInstantiation::VisitType::operator()(const TypeParameterType* type) - -> const Type* { - auto templateParameters = getTemplateParameters(self.current_); - - if (type->symbol()->enclosingSymbol() != templateParameters) { - return self.replacement(type->symbol())->type(); - } - - auto index = type->symbol()->index(); - - if (index >= self.arguments_.size()) { - cxx_runtime_error("type parameter index out of range"); - } - - auto arg = self.arguments_[index]; - return std::get(arg); -} - -auto SymbolInstantiation::VisitType::operator()( - const TemplateTypeParameterType* type) -> const Type* { - cxx_runtime_error("todo: substitute TemplateTypeParameterType"); -} - -auto SymbolInstantiation::VisitType::operator()(const UnresolvedNameType* type) - -> const Type* { - if (auto templateId = ast_cast(type->unqualifiedId())) { - std::vector args; - for (auto it = templateId->templateArgumentList; it; it = it->next) { - if (auto arg = ast_cast(it->value)) { - args.push_back(substitute(arg->typeId->type)); - } - } - auto symbol = self.control()->instantiate(type->translationUnit(), - templateId->primaryTemplateSymbol, - std::move(args)); - return symbol->type(); - } - cxx_runtime_error("todo: substitute UnresolvedNameType"); -} - -auto SymbolInstantiation::VisitType::operator()( - const UnresolvedBoundedArrayType* type) -> const Type* { - cxx_runtime_error("todo: substitute UnresolvedBoundedArrayType"); -} - -auto SymbolInstantiation::VisitType::operator()( - const UnresolvedUnderlyingType* type) -> const Type* { - cxx_runtime_error("todo: substitute UnresolvedUnderlyingType"); -} - -auto SymbolInstantiation::VisitType::operator()(const OverloadSetType* type) - -> const Type* { - return self.control()->getOverloadSetType(self.replacement(type->symbol())); -} - -} // namespace cxx \ No newline at end of file diff --git a/src/parser/cxx/symbol_instantiation.h b/src/parser/cxx/symbol_instantiation.h deleted file mode 100644 index e5c4467f..00000000 --- a/src/parser/cxx/symbol_instantiation.h +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright (c) 2025 Roberto Raggi -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -#pragma once - -#include -#include -#include - -#include -#include - -namespace cxx { - -class TranslationUnit; -class Control; - -class SymbolInstantiation { - public: - explicit SymbolInstantiation(TranslationUnit* unit, - const std::vector& arguments); - ~SymbolInstantiation(); - - [[nodiscard]] auto translationUnit() const -> TranslationUnit* { - return unit_; - } - - [[nodiscard]] auto control() const -> Control*; - - [[nodiscard]] auto operator()(Symbol* symbol) -> Symbol*; - - [[nodiscard]] auto findOrCreateReplacement(Symbol* symbol) -> Symbol*; - - template - [[nodiscard]] auto replacement(S* symbol) -> S* { - return static_cast(findOrCreateReplacement(symbol)); - } - - private: - struct MakeSymbol; - struct VisitSymbol; - struct VisitType; - - template - [[nodiscard]] auto instantiate(S* symbol) -> S* { - return static_cast(instantiateHelper(symbol)); - } - - [[nodiscard]] auto instantiateHelper(Symbol* symbol) -> Symbol*; - - private: - TranslationUnit* unit_ = nullptr; - const std::vector& arguments_; - std::unordered_map replacements_; - Symbol* current_ = nullptr; -}; - -} // namespace cxx \ No newline at end of file diff --git a/src/parser/cxx/symbol_printer.cc b/src/parser/cxx/symbol_printer.cc index 2f4f95c7..c33b184a 100644 --- a/src/parser/cxx/symbol_printer.cc +++ b/src/parser/cxx/symbol_printer.cc @@ -97,21 +97,34 @@ struct DumpSymbols { std::string_view classKey = symbol->isUnion() ? "union" : "class"; if (symbol->templateParameters()) { - out << std::format("template {} {}\n", classKey, - to_string(symbol->name())); + out << std::format("template {} {}", classKey, to_string(symbol->name())); + + out << '<'; + std::string_view sep = ""; + for (const auto& param : + symbol->templateParameters()->scope()->symbols()) { + out << std::format("{}{}", sep, to_string(param->type())); + sep = ", "; + } + out << '>'; + + out << "\n"; + dumpScope(symbol->templateParameters()->scope()); } else if (symbol->isSpecialization()) { - out << std::format("{} {}<", classKey, to_string(symbol->name())); + out << std::format("{} {}", classKey, to_string(symbol->name())); + out << "<"; std::string_view sep = ""; for (auto arg : symbol->templateArguments()) { - auto type = std::get_if(&arg); - if (!type) continue; - out << std::format("{}{}", sep, to_string(*type)); + auto symbol = std::get_if(&arg); + if (!symbol) continue; + out << std::format("{}{}", sep, to_string((*symbol)->type())); sep = ", "; } out << std::format(">\n"); } else { - out << std::format("{} {}\n", classKey, to_string(symbol->name())); + out << std::format("{} {}", classKey, to_string(symbol->name())); + out << "\n"; } for (auto baseClass : symbol->baseClasses()) { ++depth; @@ -297,10 +310,11 @@ struct DumpSymbols { } void operator()(TypeParameterSymbol* symbol) { - std::string_view pack = symbol->isParameterPack() ? "..." : ""; + auto type = type_cast(symbol->type()); + std::string_view pack = type->isParameterPack() ? "..." : ""; indent(); - out << std::format("parameter typename<{}, {}>{} {}\n", symbol->index(), - symbol->depth(), pack, to_string(symbol->name())); + out << std::format("parameter typename<{}, {}>{} {}\n", type->index(), + type->depth(), pack, to_string(symbol->name())); } void operator()(NonTypeParameterSymbol* symbol) { @@ -312,10 +326,11 @@ struct DumpSymbols { } void operator()(TemplateTypeParameterSymbol* symbol) { - std::string_view pack = symbol->isParameterPack() ? "..." : ""; + auto type = type_cast(symbol->type()); + std::string_view pack = type->isParameterPack() ? "..." : ""; indent(); - out << std::format("parameter template<{}, {}>{} {}\n", symbol->index(), - symbol->depth(), pack, to_string(symbol->name())); + out << std::format("parameter template<{}, {}>{} {}\n", type->index(), + type->depth(), pack, to_string(symbol->name())); } void operator()(ConstraintTypeParameterSymbol* symbol) { diff --git a/src/parser/cxx/symbols.cc b/src/parser/cxx/symbols.cc index 1eb06024..c5e0ffa2 100644 --- a/src/parser/cxx/symbols.cc +++ b/src/parser/cxx/symbols.cc @@ -32,6 +32,28 @@ namespace cxx { +auto compare_args(const std::vector& args1, + const std::vector& args2) -> bool { + if (args1.size() != args2.size()) return false; + for (size_t i = 0; i < args1.size(); ++i) { + const auto& arg = args1[i]; + const auto& otherArg = args2[i]; + auto sym = std::get_if(&arg); + auto otherSym = std::get_if(&otherArg); + if (!sym || !otherSym) { + // If either is not a symbol, we cannot compare them + return false; + } + auto symType = (*sym)->type(); + auto otherSymType = (*otherSym)->type(); + if (symType != otherSymType) { + // If the types are different, we cannot compare them + return false; + } + } + return true; +}; + auto Symbol::EnclosingSymbolIterator::operator++() -> EnclosingSymbolIterator& { symbol_ = symbol_->enclosingSymbol(); return *this; @@ -111,6 +133,16 @@ auto NamespaceSymbol::unnamedNamespace() const -> NamespaceSymbol* { void NamespaceSymbol::setUnnamedNamespace(NamespaceSymbol* unnamedNamespace) { unnamedNamespace_ = unnamedNamespace; } + +auto NamespaceSymbol::anonNamespaceIndex() const -> std::optional { + if (anonNamespaceIndex_ < 0) return std::nullopt; + return anonNamespaceIndex_; +} + +void NamespaceSymbol::setAnonNamespaceIndex(int index) { + anonNamespaceIndex_ = index; +} + ConceptSymbol::ConceptSymbol(Scope* enclosingScope) : Symbol(Kind, enclosingScope) {} @@ -394,6 +426,14 @@ void FunctionSymbol::setTemplateParameters( templateParameters_ = templateParameters; } +auto FunctionSymbol::declaration() const -> DeclarationAST* { + return declaration_; +} + +void FunctionSymbol::setDeclaration(DeclarationAST* declaration) { + declaration_ = declaration; +} + auto FunctionSymbol::isDefined() const -> bool { return isDefined_; } void FunctionSymbol::setDefined(bool isDefined) { isDefined_ = isDefined; } @@ -709,22 +749,6 @@ TypeParameterSymbol::TypeParameterSymbol(Scope* enclosingScope) TypeParameterSymbol::~TypeParameterSymbol() {} -auto TypeParameterSymbol::index() const -> int { return index_; } - -void TypeParameterSymbol::setIndex(int index) { index_ = index; } - -auto TypeParameterSymbol::depth() const -> int { return depth_; } - -void TypeParameterSymbol::setDepth(int depth) { depth_ = depth; } - -auto TypeParameterSymbol::isParameterPack() const -> bool { - return isParameterPack_; -} - -void TypeParameterSymbol::setParameterPack(bool isParameterPack) { - isParameterPack_ = isParameterPack; -} - NonTypeParameterSymbol::NonTypeParameterSymbol(Scope* enclosingScope) : Symbol(Kind, enclosingScope) {} @@ -759,32 +783,6 @@ TemplateTypeParameterSymbol::TemplateTypeParameterSymbol(Scope* enclosingScope) TemplateTypeParameterSymbol::~TemplateTypeParameterSymbol() {} -auto TemplateTypeParameterSymbol::index() const -> int { return index_; } - -void TemplateTypeParameterSymbol::setIndex(int index) { index_ = index; } - -auto TemplateTypeParameterSymbol::depth() const -> int { return depth_; } - -void TemplateTypeParameterSymbol::setDepth(int depth) { depth_ = depth; } - -auto TemplateTypeParameterSymbol::isParameterPack() const -> bool { - return isParameterPack_; -} - -void TemplateTypeParameterSymbol::setParameterPack(bool isParameterPack) { - isParameterPack_ = isParameterPack; -} - -auto TemplateTypeParameterSymbol::templateParameters() const - -> TemplateParametersSymbol* { - return templateParameters_; -} - -void TemplateTypeParameterSymbol::setTemplateParameters( - TemplateParametersSymbol* templateParameters) { - templateParameters_ = templateParameters; -} - ConstraintTypeParameterSymbol::ConstraintTypeParameterSymbol( Scope* enclosingScope) : Symbol(Kind, enclosingScope) {} diff --git a/src/parser/cxx/symbols.h b/src/parser/cxx/symbols.h index f11f2441..b6fb26f8 100644 --- a/src/parser/cxx/symbols.h +++ b/src/parser/cxx/symbols.h @@ -45,6 +45,10 @@ struct TemplateSpecialization { S* symbol = nullptr; }; +[[nodiscard]] auto compare_args(const std::vector& args1, + const std::vector& args2) + -> bool; + template class TemplateInfo { public: @@ -68,7 +72,13 @@ class TemplateInfo { [[nodiscard]] auto findSpecialization( const std::vector& arguments) const -> S* { for (const auto& specialization : specializations_) { - if (specialization.arguments == arguments) return specialization.symbol; + const std::vector& args = specialization.arguments; + if (args == arguments) return specialization.symbol; + if (args.size() != arguments.size()) continue; + if (compare_args(args, arguments)) { + // If the arguments match, return the specialization symbol + return specialization.symbol; + } } return nullptr; } @@ -185,8 +195,12 @@ class NamespaceSymbol final : public ScopedSymbol { [[nodiscard]] auto unnamedNamespace() const -> NamespaceSymbol*; void setUnnamedNamespace(NamespaceSymbol* unnamedNamespace); + [[nodiscard]] auto anonNamespaceIndex() const -> std::optional; + void setAnonNamespaceIndex(int index); + private: NamespaceSymbol* unnamedNamespace_ = nullptr; + int anonNamespaceIndex_ = -1; bool isInline_ = false; }; @@ -420,8 +434,12 @@ class FunctionSymbol final : public ScopedSymbol { [[nodiscard]] auto hasCxxLinkage() const -> bool; void setHasCxxLinkage(bool hasCLinkage); + [[nodiscard]] auto declaration() const -> DeclarationAST*; + void setDeclaration(DeclarationAST* declaration); + private: TemplateParametersSymbol* templateParameters_ = nullptr; + DeclarationAST* declaration_ = nullptr; union { std::uint32_t flags_{}; @@ -681,20 +699,6 @@ class TypeParameterSymbol final : public Symbol { explicit TypeParameterSymbol(Scope* enclosingScope); ~TypeParameterSymbol() override; - - [[nodiscard]] auto index() const -> int; - void setIndex(int index); - - [[nodiscard]] auto depth() const -> int; - void setDepth(int depth); - - [[nodiscard]] auto isParameterPack() const -> bool; - void setParameterPack(bool isParameterPack); - - private: - int index_ = 0; - int depth_ = 0; - bool isParameterPack_ = false; }; class NonTypeParameterSymbol final : public Symbol { @@ -729,24 +733,6 @@ class TemplateTypeParameterSymbol final : public Symbol { explicit TemplateTypeParameterSymbol(Scope* enclosingScope); ~TemplateTypeParameterSymbol() override; - - [[nodiscard]] auto index() const -> int; - void setIndex(int index); - - [[nodiscard]] auto depth() const -> int; - void setDepth(int depth); - - [[nodiscard]] auto isParameterPack() const -> bool; - void setParameterPack(bool isParameterPack); - - [[nodiscard]] auto templateParameters() const -> TemplateParametersSymbol*; - void setTemplateParameters(TemplateParametersSymbol* templateParameters); - - private: - int index_ = 0; - int depth_ = 0; - bool isParameterPack_ = false; - TemplateParametersSymbol* templateParameters_ = nullptr; }; class ConstraintTypeParameterSymbol final : public Symbol { diff --git a/src/parser/cxx/type_printer.cc b/src/parser/cxx/type_printer.cc index da1d319e..b4fd140d 100644 --- a/src/parser/cxx/type_printer.cc +++ b/src/parser/cxx/type_printer.cc @@ -21,6 +21,7 @@ // cxx #include #include +#include #include #include #include @@ -301,18 +302,30 @@ class TypePrinter { void operator()(const ClassType* type) { std::string out; + if (auto parent = type->symbol()->enclosingSymbol()) { accept(parent->type()); out += "::"; } + out += to_string(type->symbol()->name()); + if (type->symbol()->isSpecialization()) { out += '<'; std::string_view sep = ""; for (auto arg : type->symbol()->templateArguments()) { - auto type = std::get_if(&arg); - if (!type) continue; - out += std::format("{}{}", sep, to_string(*type)); + auto sym = std::get_if(&arg); + if (!sym) continue; + out += std::format("{}{}", sep, to_string((*sym)->type())); + sep = ", "; + } + out += '>'; + } else if (auto templDecl = type->symbol()->templateClass()) { + out += '<'; + std::string_view sep = ""; + for (const auto& param : + templDecl->templateParameters()->scope()->symbols()) { + out += std::format("{}{}", sep, to_string(param->type())); sep = ", "; } out += '>'; @@ -338,11 +351,15 @@ class TypePrinter { } void operator()(const TypeParameterType* type) { - specifiers_.append(to_string(type->symbol()->name())); + specifiers_.append(std::format("type-param<{}, {}{}>", type->index(), + type->depth(), + type->isParameterPack() ? ", ..." : "")); } void operator()(const TemplateTypeParameterType* type) { - specifiers_.append(to_string(type->symbol()->name())); + specifiers_.append(std::format("template-type-param<{}, {}{}>", + type->index(), type->depth(), + type->isParameterPack() ? ", ..." : "")); } void operator()(const UnresolvedNameType* type) { diff --git a/src/parser/cxx/type_traits.h b/src/parser/cxx/type_traits.h index 6dccc613..4654bd8e 100644 --- a/src/parser/cxx/type_traits.h +++ b/src/parser/cxx/type_traits.h @@ -1021,12 +1021,26 @@ class TypeTraits { auto operator()(const TypeParameterType* type, const TypeParameterType* otherType) const -> bool { - return type->symbol() == otherType->symbol(); + return type->index() == otherType->index() && + type->depth() == otherType->depth() && + type->isParameterPack() == otherType->isParameterPack(); } auto operator()(const TemplateTypeParameterType* type, const TemplateTypeParameterType* otherType) const -> bool { - return type->symbol() == otherType->symbol(); + if (type->index() != otherType->index()) return false; + if (type->depth() != otherType->depth()) return false; + if (type->isParameterPack() != otherType->isParameterPack()) return false; + if (type->templateParameters().size() != + otherType->templateParameters().size()) + return false; + for (std::size_t i = 0; i < type->templateParameters().size(); ++i) { + if (!traits.is_same(type->templateParameters()[i], + otherType->templateParameters()[i])) + return false; + } + + return true; } auto operator()(const UnresolvedNameType* type, diff --git a/src/parser/cxx/types.h b/src/parser/cxx/types.h index c17cfcec..919fcfb1 100644 --- a/src/parser/cxx/types.h +++ b/src/parser/cxx/types.h @@ -423,30 +423,40 @@ class NamespaceType final : public Type, public std::tuple { } }; -class TypeParameterType final : public Type, - public std::tuple { +class TypeParameterType final : public Type, public std::tuple { public: static constexpr TypeKind Kind = TypeKind::kTypeParameter; - explicit TypeParameterType(TypeParameterSymbol* symbol) - : Type(Kind), tuple(symbol) {} + explicit TypeParameterType(int index, int depth, bool isPack) + : Type(Kind), tuple(index, depth, isPack) {} - [[nodiscard]] auto symbol() const -> TypeParameterSymbol* { - return std::get<0>(*this); + [[nodiscard]] auto index() const -> int { return std::get<0>(*this); } + [[nodiscard]] auto depth() const -> int { return std::get<1>(*this); } + [[nodiscard]] auto isParameterPack() const -> bool { + return std::get<2>(*this); } }; class TemplateTypeParameterType final : public Type, - public std::tuple { + public std::tuple> { public: static constexpr TypeKind Kind = TypeKind::kTypeParameter; - explicit TemplateTypeParameterType(TemplateTypeParameterSymbol* symbol) - : Type(Kind), tuple(symbol) {} + explicit TemplateTypeParameterType( + int index, int depth, bool isPack, + std::vector templateParameters) + : Type(Kind), + tuple(index, depth, isPack, std::move(templateParameters)) {} - [[nodiscard]] auto symbol() const -> TemplateTypeParameterSymbol* { - return std::get<0>(*this); + [[nodiscard]] auto index() const -> int { return std::get<0>(*this); } + [[nodiscard]] auto depth() const -> int { return std::get<1>(*this); } + [[nodiscard]] auto isParameterPack() const -> bool { + return std::get<2>(*this); + } + [[nodiscard]] auto templateParameters() const + -> const std::vector& { + return std::get<3>(*this); } }; diff --git a/tests/api_tests/CMakeLists.txt b/tests/api_tests/CMakeLists.txt index a4ebd820..aab76695 100644 --- a/tests/api_tests/CMakeLists.txt +++ b/tests/api_tests/CMakeLists.txt @@ -25,8 +25,6 @@ endif() add_executable(test_api test_control.cc test_external_names.cc - test_rewriter.cc - test_substitution.cc test_type_printer.cc ) diff --git a/tests/api_tests/test_rewriter.cc b/tests/api_tests/test_rewriter.cc deleted file mode 100644 index 355fd4f7..00000000 --- a/tests/api_tests/test_rewriter.cc +++ /dev/null @@ -1,324 +0,0 @@ -// Copyright (c) 2025 Roberto Raggi -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "test_utils.h" - -using namespace cxx; - -namespace { - -[[nodiscard]] auto make_substitution( - TranslationUnit* unit, TemplateDeclarationAST* templateDecl, - List* templateArgumentList) - -> std::vector { - auto control = unit->control(); - auto interp = ASTInterpreter{unit}; - - std::vector templateArguments; - - for (auto arg : ListView{templateArgumentList}) { - if (auto exprArg = ast_cast(arg)) { - auto expr = exprArg->expression; - // ### need to set scope and location - auto templArg = control->newVariableSymbol(nullptr, {}); - templArg->setInitializer(expr); - templArg->setType(control->add_const(expr->type)); - templArg->setConstValue(interp.evaluate(expr)); - if (!templArg->constValue().has_value()) - cxx_runtime_error("template argument is not a constant expression"); - templateArguments.push_back(templArg); - } else if (auto typeArg = ast_cast(arg)) { - auto type = typeArg->typeId->type; - // ### need to set scope and location - auto templArg = control->newTypeAliasSymbol(nullptr, {}); - templArg->setType(type); - templateArguments.push_back(templArg); - } - } - - return templateArguments; -} - -template -[[nodiscard]] auto substitute(Source& source, Node* ast, - std::vector args) { - auto control = source.control(); - TypeChecker typeChecker(&source.unit); - ASTRewriter rewrite{&typeChecker, args}; - return ast_cast(rewrite(ast)); -}; - -[[nodiscard]] auto getTemplateBody(TemplateDeclarationAST* ast) - -> DeclarationAST* { - if (auto nested = ast_cast(ast->declaration)) - return getTemplateBody(nested); - return ast->declaration; -} - -template -[[nodiscard]] auto getTemplateBodyAs(TemplateDeclarationAST* ast) -> Node* { - return ast_cast(getTemplateBody(ast)); -} - -} // namespace - -TEST(Rewriter, TypeAlias) { - auto source = R"( -template -using Func = void(T, const U&); - -using Func1 = Func; - )"_cxx_no_templates; - - auto control = source.control(); - - auto func1 = source.getAs("Func1"); - ASSERT_TRUE(func1 != nullptr); - - auto func1Type = type_cast(func1->type()); - ASSERT_TRUE(func1Type != nullptr); - - auto templateId = ast_cast(func1Type->unqualifiedId()); - ASSERT_TRUE(templateId != nullptr); - - auto templateSym = - symbol_cast(templateId->primaryTemplateSymbol); - ASSERT_TRUE(templateSym != nullptr); - - auto templateArguments = - make_substitution(&source.unit, templateSym->templateDeclaration(), - templateId->templateArgumentList); - - auto funcInstance = substitute(source, - getTemplateBodyAs( - templateSym->templateDeclaration()), - templateArguments); - - ASSERT_EQ(to_string(funcInstance->typeId->type), "void (int, const float&)"); -} - -TEST(Rewriter, Var) { - auto source = R"( -template -const int c = i + 321 + i; - -constexpr int y = c<123 * 2>; -)"_cxx_no_templates; - - auto interp = ASTInterpreter{&source.unit}; - - auto control = source.control(); - - auto y = source.getAs("y"); - ASSERT_TRUE(y != nullptr); - - auto yinit = ast_cast(y->initializer())->expression; - ASSERT_TRUE(yinit != nullptr); - - auto idExpr = ast_cast(yinit); - ASSERT_TRUE(idExpr != nullptr); - - ASSERT_TRUE(idExpr->symbol); - - auto templateId = ast_cast(idExpr->unqualifiedId); - ASSERT_TRUE(templateId != nullptr); - - // get the primary template declaration - auto templateSym = - symbol_cast(templateId->primaryTemplateSymbol); - ASSERT_TRUE(templateSym != nullptr); - - auto templateDecl = getTemplateBodyAs( - templateSym->templateDeclaration()); - ASSERT_TRUE(templateDecl != nullptr); - - std::vector templateArguments = - make_substitution(&source.unit, templateSym->templateDeclaration(), - templateId->templateArgumentList); - - auto instance = substitute(source, templateDecl, templateArguments); - ASSERT_TRUE(instance != nullptr); - - auto decl = instance->initDeclaratorList->value; - ASSERT_TRUE(decl != nullptr); - - auto init = ast_cast(decl->initializer); - ASSERT_TRUE(init != nullptr); - - auto value = interp.evaluate(init->expression); - ASSERT_TRUE(value.has_value()); - - ASSERT_EQ(interp.toInt(*value).value(), 123 * 2 + 321 + 123 * 2); -} - -TEST(Rewriter, Pack) { - auto source = R"( -template -const auto S = (... + (xs * xs)); - -const auto N = S<0, 1, 2>; -)"_cxx_no_templates; - - ASTInterpreter interp{&source.unit}; - - auto control = source.control(); - - auto S = source.getAs("S"); - ASSERT_TRUE(S != nullptr); - - auto N = source.getAs("N"); - ASSERT_TRUE(N != nullptr); - auto Ninit = ast_cast(N->initializer())->expression; - ASSERT_TRUE(Ninit != nullptr); - - auto idExpr = ast_cast(Ninit); - ASSERT_TRUE(idExpr != nullptr); - - auto templateId = ast_cast(idExpr->unqualifiedId); - ASSERT_TRUE(templateId != nullptr); - ASSERT_EQ(templateId->primaryTemplateSymbol, S); - - auto parameterPack = control->newParameterPackSymbol(nullptr, {}); - - for (auto arg : ListView{templateId->templateArgumentList}) { - auto exprArg = ast_cast(arg); - ASSERT_TRUE(exprArg != nullptr); - - auto expr = exprArg->expression; - auto element = control->newVariableSymbol(nullptr, {}); - element->setInitializer(expr); - element->setType(control->add_const(expr->type)); - parameterPack->addElement(element); - } - - ASSERT_EQ(parameterPack->elements().size(), 3); - - std::vector arguments; - arguments.push_back(parameterPack); - - auto templateDecl = - getTemplateBodyAs(S->templateDeclaration()); - ASSERT_TRUE(templateDecl != nullptr); - - auto instance = substitute(source, templateDecl, arguments); - ASSERT_TRUE(instance != nullptr); - - auto decl_to_string = [&](DeclarationAST* ast) { - std::ostringstream os; - ASTPrettyPrinter printer{&source.unit, os}; - printer(ast); - return os.str(); - }; - - ASSERT_EQ(decl_to_string(instance), - "const auto S = (0 * 0) + (1 * 1) + (2 * 2);"); - - auto eq = ast_cast( - instance->initDeclaratorList->value->initializer); - ASSERT_TRUE(eq != nullptr); - - const auto value = interp.evaluate(eq->expression); - ASSERT_TRUE(value.has_value()); - ASSERT_EQ(interp.toInt(*value).value(), 0 * 0 + 1 * 1 + 2 * 2); -} - -TEST(Rewriter, Class) { - auto source = R"( -struct Base { - int x; -}; - -template -struct Pair : Base { - T1 first; - T2 second; - auto operator=(const Pair& other) -> Pair&; -}; - -using Pair1 = Pair; - -)"_cxx_no_templates; - - auto control = source.control(); - - auto pair = source.getAs("Pair"); - ASSERT_TRUE(pair != nullptr); - - ASSERT_TRUE(pair->declaration() != nullptr); - - auto classDecl = ast_cast(pair->declaration()); - ASSERT_TRUE(classDecl != nullptr); - - auto templateDecl = pair->templateDeclaration(); - ASSERT_TRUE(templateDecl != nullptr); - - auto pair1 = source.getAs("Pair1"); - ASSERT_TRUE(pair1 != nullptr); - - auto pair1Type = type_cast(pair1->type()); - ASSERT_TRUE(pair1Type != nullptr); - - auto templateId = ast_cast(pair1Type->unqualifiedId()); - ASSERT_TRUE(templateId != nullptr); - - auto templateArguments = make_substitution(&source.unit, templateDecl, - templateId->templateArgumentList); - - auto instance = substitute(source, classDecl, templateArguments); - ASSERT_TRUE(instance != nullptr); - - auto classDeclInstance = ast_cast(instance); - ASSERT_TRUE(classDeclInstance != nullptr); - - auto classInstance = classDeclInstance->symbol; - - ASSERT_TRUE(classInstance != nullptr); - - std::ostringstream os; - dump(os, classDeclInstance->symbol); - - ASSERT_EQ(os.str(), R"(class Pair - base class Base - field int first - field float* second - function ::Pair& operator =(const ::Pair&) -)"); - - ASSERT_EQ(classInstance->sizeInBytes(), 12); - ASSERT_EQ(classInstance->alignment(), 4); -} diff --git a/tests/api_tests/test_substitution.cc b/tests/api_tests/test_substitution.cc deleted file mode 100644 index 29e4da45..00000000 --- a/tests/api_tests/test_substitution.cc +++ /dev/null @@ -1,164 +0,0 @@ -// Copyright (c) 2025 Roberto Raggi -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "test_utils.h" - -using namespace cxx; - -TEST(Substitution, TypeAlias) { - auto source = R"( - template - using Ptr = T*; - - template - using RefF = auto (T&, T&&) -> void; - - template - using F = T (*)(T const, U*, ...); - )"_cxx; - - auto control = source.control(); - - { - auto instance = source.instantiate("Ptr", {control->getCharType()}); - ASSERT_TRUE(instance != nullptr); - ASSERT_TRUE(instance->isTypeAlias()); - ASSERT_EQ(to_string(instance->type()), "char*"); - } - - { - auto instance = source.instantiate( - "F", {control->getIntType(), control->getCharType()}); - - ASSERT_TRUE(instance != nullptr); - ASSERT_TRUE(instance->isTypeAlias()); - ASSERT_EQ(to_string(instance->type()), "int (*)(const int, char*...)"); - } - - { - auto instance = source.instantiate("RefF", {control->getCharType()}); - ASSERT_TRUE(instance != nullptr); - ASSERT_TRUE(instance->isTypeAlias()); - ASSERT_EQ(to_string(instance->type()), "void (char&, char&&)"); - } -} - -TEST(Substitution, Variable) { - auto source = R"( - template - constexpr T value = T{}; - )"_cxx; - - auto control = source.control(); - - { - auto instance = source.instantiate("value", {control->getIntType()}); - ASSERT_TRUE(instance != nullptr); - ASSERT_TRUE(instance->isVariable()); - ASSERT_EQ(to_string(instance->type()), "int"); - } -} - -TEST(Substitution, Class) { - auto source = R"( - struct M {}; - - template - struct S { - using type = T; - T value; - - void foo(); - void foo(int x); - void foo(T* ptr); - - auto get_value() -> const T&; - - M m; - int v[10]; - - S(T* ptr, void* x); - - enum E { - A, B, C - }; - }; - )"_cxx; - - LookupMember getMember{source}; - - auto control = source.control(); - - { - auto instance = source.instantiate("S", {control->getIntType()}); - ASSERT_TRUE(instance != nullptr); - ASSERT_TRUE(instance->isClass()); - - auto S = symbol_cast(instance); - ASSERT_TRUE(S != nullptr); - - auto S2 = symbol_cast( - source.instantiate("S", {control->getCharType()})); - ASSERT_TRUE(S2 != nullptr); - - // test constructors - ASSERT_EQ(S->constructors().size(), std::size_t(1)); - ASSERT_EQ(S2->constructors().size(), std::size_t(1)); - ASSERT_EQ(to_string(S->constructors()[0]->type()), " (int*, void*)"); - ASSERT_EQ(to_string(S2->constructors()[0]->type()), " (char*, void*)"); - - auto type = getMember(S->scope(), "type"); - ASSERT_TRUE(type != nullptr); - ASSERT_TRUE(type->isTypeAlias()); - ASSERT_EQ(to_string(type->type()), "int"); - - auto value = getMember(S->scope(), "value"); - ASSERT_TRUE(value != nullptr); - ASSERT_TRUE(value->isField()); - ASSERT_EQ(to_string(value->type()), "int"); - - auto foo = symbol_cast(getMember(S->scope(), "foo")); - ASSERT_TRUE(foo != nullptr); - ASSERT_EQ(foo->functions().size(), std::size_t(3)); - ASSERT_EQ(to_string(foo->functions()[0]->type()), "void ()"); - ASSERT_EQ(to_string(foo->functions()[1]->type()), "void (int)"); - ASSERT_EQ(to_string(foo->functions()[2]->type()), "void (int*)"); - - ASSERT_EQ(to_string(getMember(S->scope(), "get_value")->type()), - "const int& ()"); - - ASSERT_EQ(getMember(S->scope(), "m")->type(), - getMember(S2->scope(), "m")->type()); - } -} diff --git a/tests/api_tests/test_utils.h b/tests/api_tests/test_utils.h index 0a6a4740..9b8dc548 100644 --- a/tests/api_tests/test_utils.h +++ b/tests/api_tests/test_utils.h @@ -80,12 +80,6 @@ struct Source { auto symbol = get(name); return symbol_cast(symbol); } - - auto instantiate(std::string_view name, - const std::vector& arguments) -> Symbol* { - auto symbol = get(name); - return control()->instantiate(&unit, symbol, arguments); - } }; inline auto operator""_cxx(const char* source, std::size_t size) -> Source { diff --git a/tests/unit_tests/sema/template_alias_01.cc b/tests/unit_tests/sema/template_alias_01.cc index 9d07d063..7ca15e29 100644 --- a/tests/unit_tests/sema/template_alias_01.cc +++ b/tests/unit_tests/sema/template_alias_01.cc @@ -7,6 +7,6 @@ using IntPointer = Pointer; // clang-format off // CHECK:namespace -// CHECK-NEXT:template typealias T* Pointer +// CHECK-NEXT: template typealias type-param<0, 0>* Pointer // CHECK-NEXT: parameter typename<0, 0> T // CHECK-NEXT: typealias int* IntPointer diff --git a/tests/unit_tests/sema/template_alias_02.cc b/tests/unit_tests/sema/template_alias_02.cc index 9e35fe99..c8415556 100644 --- a/tests/unit_tests/sema/template_alias_02.cc +++ b/tests/unit_tests/sema/template_alias_02.cc @@ -14,16 +14,16 @@ struct Scope { }; // clang-format off -// CHECK:namespace -// CHECK: template class HashMap -// CHECK: parameter typename<0, 0> Key -// CHECK: parameter typename<1, 0> Value -// CHECK: typealias Value* iterator -// CHECK: [specializations] -// CHECK: class HashMap -// CHECK: typealias ::Symbol** iterator -// CHECK: class Name -// CHECK: class Symbol -// CHECK: class Scope -// CHECK: typealias ::HashMap Table -// CHECK: typealias ::Symbol** MemberIterator +// CHECK:namespace +// CHECK-NEXT: template class HashMap, type-param<1, 0>> +// CHECK-NEXT: parameter typename<0, 0> Key +// CHECK-NEXT: parameter typename<1, 0> Value +// CHECK-NEXT: typealias type-param<1, 0>* iterator +// CHECK-NEXT: [specializations] +// CHECK-NEXT: class HashMap +// CHECK-NEXT: typealias ::Symbol** iterator +// CHECK-NEXT: class Name +// CHECK-NEXT: class Symbol +// CHECK-NEXT: class Scope +// CHECK-NEXT: typealias ::HashMap Table +// CHECK-NEXT: typealias ::Symbol** MemberIterator diff --git a/tests/unit_tests/sema/template_class_01.cc b/tests/unit_tests/sema/template_class_01.cc index 6777a4dc..ce82b318 100644 --- a/tests/unit_tests/sema/template_class_01.cc +++ b/tests/unit_tests/sema/template_class_01.cc @@ -17,14 +17,14 @@ A a2; // clang-format off // CHECK:namespace -// CHECK-NEXT: template class A +// CHECK-NEXT: template class A> // CHECK-NEXT: parameter typename<0, 0> T -// CHECK-NEXT: field T a -// CHECK-NEXT: field A* next -// CHECK-NEXT: function T get_a() -// CHECK-NEXT: function void set_a(const T&) -// CHECK-NEXT: typealias T type -// CHECK-NEXT: typealias T& reference +// CHECK-NEXT: field type-param<0, 0> a +// CHECK-NEXT: field ::A* next +// CHECK-NEXT: function type-param<0, 0> get_a() +// CHECK-NEXT: function void set_a(const type-param<0, 0>&) +// CHECK-NEXT: typealias type-param<0, 0> type +// CHECK-NEXT: typealias type-param<0, 0>& reference // CHECK-NEXT: [specializations] // CHECK-NEXT: class A // CHECK-NEXT: field int a @@ -41,4 +41,4 @@ A a2; // CHECK-NEXT: typealias void* type // CHECK-NEXT: typealias void*& reference // CHECK-NEXT: variable ::A a1 -// CHECK-NEXT: variable ::A a2 \ No newline at end of file +// CHECK-NEXT: variable ::A a2 diff --git a/tests/unit_tests/sema/template_class_02.cc b/tests/unit_tests/sema/template_class_02.cc index f6007109..8aeab3a0 100644 --- a/tests/unit_tests/sema/template_class_02.cc +++ b/tests/unit_tests/sema/template_class_02.cc @@ -37,40 +37,39 @@ using u8string = basic_string; // CHECK:namespace // CHECK-NEXT: namespace std // CHECK-NEXT: typealias unsigned long size_t -// CHECK-NEXT: template class basic_string +// CHECK-NEXT: template class basic_string> // CHECK-NEXT: parameter typename<0, 0> T -// CHECK-NEXT: constructor basic_string() -// CHECK-NEXT: constructor explicit basic_string(const T*) +// CHECK-NEXT: constructor basic_string() +// CHECK-NEXT: constructor explicit basic_string(const type-param<0, 0>*) // CHECK-NEXT: parameters -// CHECK-NEXT: parameter const T* p +// CHECK-NEXT: parameter const type-param<0, 0>* p // CHECK-NEXT: block -// CHECK-NEXT: function void append(const T*) -// CHECK-NEXT: function const T* c_str() const +// CHECK-NEXT: function void append(const type-param<0, 0>*) +// CHECK-NEXT: function const type-param<0, 0>* c_str() const // CHECK-NEXT: function unsigned long size() const -// CHECK-NEXT: function const T& operator [](unsigned long) const -// CHECK-NEXT: function T& operator [](unsigned long) +// CHECK-NEXT: function const type-param<0, 0>& operator [](unsigned long) const +// CHECK-NEXT: function type-param<0, 0>& operator [](unsigned long) // CHECK-NEXT: class iterator -// CHECK-NEXT: function std::basic_string::iterator& operator ++() +// CHECK-NEXT: function std::basic_string::iterator& operator ++() // CHECK-NEXT: function std::basic_string::iterator operator ++(int) -// CHECK-NEXT: function T& operator *() -// CHECK-NEXT: function const T& operator *() const +// CHECK-NEXT: function type-param<0, 0>& operator *() +// CHECK-NEXT: function const type-param<0, 0>& operator *() const // CHECK-NEXT: function bool operator ==(const std::basic_string::iterator&) const // CHECK-NEXT: function bool operator !=(const std::basic_string::iterator&) const // CHECK-NEXT: function std::basic_string::iterator begin() // CHECK-NEXT: function std::basic_string::iterator end() // CHECK-NEXT: [specializations] // CHECK-NEXT: class basic_string -// CHECK-NEXT: constructor basic_string() -// CHECK-NEXT: constructor basic_string(const char*) -// CHECK-NEXT: parameters -// CHECK-NEXT: parameter const char* p +// CHECK-NEXT: constructor basic_string() +// CHECK-NEXT: constructor explicit basic_string(const char*) +// CHECK-NEXT: block // CHECK-NEXT: function void append(const char*) // CHECK-NEXT: function const char* c_str() const // CHECK-NEXT: function unsigned long size() const // CHECK-NEXT: function const char& operator [](unsigned long) const // CHECK-NEXT: function char& operator [](unsigned long) // CHECK-NEXT: class iterator -// CHECK-NEXT: function std::basic_string::iterator& operator ++() +// CHECK-NEXT: function std::basic_string::iterator& operator ++() // CHECK-NEXT: function std::basic_string::iterator operator ++(int) // CHECK-NEXT: function char& operator *() // CHECK-NEXT: function const char& operator *() const @@ -79,17 +78,16 @@ using u8string = basic_string; // CHECK-NEXT: function std::basic_string::iterator begin() // CHECK-NEXT: function std::basic_string::iterator end() // CHECK-NEXT: class basic_string -// CHECK-NEXT: constructor basic_string() -// CHECK-NEXT: constructor basic_string(const char8_t*) -// CHECK-NEXT: parameters -// CHECK-NEXT: parameter const char8_t* p +// CHECK-NEXT: constructor basic_string() +// CHECK-NEXT: constructor explicit basic_string(const char8_t*) +// CHECK-NEXT: block // CHECK-NEXT: function void append(const char8_t*) // CHECK-NEXT: function const char8_t* c_str() const // CHECK-NEXT: function unsigned long size() const // CHECK-NEXT: function const char8_t& operator [](unsigned long) const // CHECK-NEXT: function char8_t& operator [](unsigned long) // CHECK-NEXT: class iterator -// CHECK-NEXT: function std::basic_string::iterator& operator ++() +// CHECK-NEXT: function std::basic_string::iterator& operator ++() // CHECK-NEXT: function std::basic_string::iterator operator ++(int) // CHECK-NEXT: function char8_t& operator *() // CHECK-NEXT: function const char8_t& operator *() const