diff --git a/.cursor/rules/full-test-before-commit.mdc b/.cursor/rules/full-test-before-commit.mdc new file mode 100644 index 0000000..001cdc5 --- /dev/null +++ b/.cursor/rules/full-test-before-commit.mdc @@ -0,0 +1,41 @@ +--- +description: >- + Always run the full test suite before committing, and after finishing a + feature, so grammar/parser regressions are not missed by subset runs. +alwaysApply: true +--- + +# Full test suite before commit + +## When + +- **Before any git commit** (including amend/squash of local WIP), and +- **After a feature is declared complete** (ready to land or squash), + +run the **full** CTest suite for this repo — not a subset filtered to the +feature area (e.g. not only `qumode-*`). + +## How + +From the configured build directory (typically `build/Release`): + +```bash +ctest --output-on-failure +``` + +If the tree was reconfigured or new tests were added, re-run `cmake` in that +build dir first so CTest picks them up. + +## Pass / fail + +- **All tests must pass** before creating or amending a commit. +- If anything fails: fix, re-run the **full** suite, then commit. +- Do not treat “related tests passed” as sufficient when the change touches + shared surfaces (parser `.y`/`.l`, AST builders used by many productions, + symbol table, etc.). + +## Why + +Subset runs miss cross-cutting regressions (e.g. gate `ArgsList` changes +breaking function-call / OpenPulse tests). A prior commit shipped with only +qumode checks green while nine unrelated tests failed. diff --git a/.cursor/rules/safe-file-edits.mdc b/.cursor/rules/safe-file-edits.mdc new file mode 100644 index 0000000..46965dd --- /dev/null +++ b/.cursor/rules/safe-file-edits.mdc @@ -0,0 +1,51 @@ +--- +description: >- + Never overwrite or delete large/important source files without a recoverable + backup. Prefer surgical edits; forbid full-file Write on existing critical + paths unless backed up first. +alwaysApply: true +--- + +# Safe edits for large / critical files + +## Incident this prevents + +Using the **Write** tool (or equivalent full-file overwrite) on an existing +large source file replaces the entire contents. That is easy to confuse with +“replace this function,” and recovery may depend on git history, transcripts, +or stale object files — not a reliable backup. + +In this repo, high-risk paths include especially: + +- `lib/AST/ASTProductionFactory.cpp` (~30k lines) +- `lib/Parser/QasmParser.y` +- Other multi-thousand-line AST / parser / builder translation units + +## Required workflow + +1. **Prefer `StrReplace`** (or a small, targeted patch) for existing files. + Never use `Write` to “update” a function inside a large existing file. +2. **Before any full-file overwrite** of an existing file (Write with a path + that already exists, or rewrite-via-script that truncates the file): + - Copy the current file to a recoverable backup first, e.g. + `cp path path.bak.$$` or write under `/tmp/` with a clear name, **or** + ensure the content is already committed / stashable and note that. + - Confirm the backup is readable (`wc -l` / size check) before overwriting. +3. **Before deleting** a tracked or substantial untracked source file: ask the + user for permission (project rule). Do not delete “to clean up” mid-task. +4. If a full rewrite is truly required, prefer: + - write the new content to a **new temp path**, + - verify it (size, key symbols, compile if feasible), + - then `mv` over the original **only after** the backup exists. + +## After a bad overwrite + +- Prefer `git checkout -- ` / `git restore` only if losing uncommitted + work on that file is acceptable — check `git status` / `git diff` first. +- Otherwise restore from the backup copy created above, or from agent + transcript / local history — do not invent a partial file and call it done. + +## Quick check before Write + +Ask: “Does this path already exist, and is it more than a small new file?” +If yes → **do not Write**; use StrReplace or backup-then-replace. diff --git a/.cursor/skills/typed-gate-declarations/SKILL.md b/.cursor/skills/typed-gate-declarations/SKILL.md new file mode 100644 index 0000000..ff6996c --- /dev/null +++ b/.cursor/skills/typed-gate-declarations/SKILL.md @@ -0,0 +1,126 @@ +--- +name: typed-gate-declarations +description: >- + Fully-typed OpenQASM gate declarations (qubit/qumode formals + explicit + classical types) and call-site type checking in this fork. Use when editing + gate grammar, ProductionRule_10030, CreateGateCall, ValidateTypedGateCall, + ASTGateType, cvgates.inc, ECD/disp/SNAP typing, or when adding typed gate + call checks. +--- + +# Typed gate declarations + +## Design rules + +- **All-untyped** classical + bare quantum formals = legacy OpenQASM 3 (`ProductionRule_1430` / `1431`). No call-site type checks. +- **Any typed classical formals** with **typed quantum operands** = fully typed (`ProductionRule_10030`). No partial typing. +- **Templates (v1):** `gate foo[uint N](array[T, N] …)` — unsigned int templates used as array lengths. Call-site `foo([…])` infers `N` from literal arity or a sized named array’s declared length; `foo[N]([…])` checks. Uninitialized named arrays → “used before assigned.” Call Gate `TemplateParams` carry `` (NaN on decl, bound int on call); body `N` is not overwritten. +- **Fock ctrl:** `ctrl[3]` / `ctrl[N]` / `ctrl[N-1]` / `negctrl[i]` — level may be int, id, or binary/unary (or parenthesized) expression. Distinct from qubit `ctrl(n)`. See `docs/gates.md`. +- **Gate-body `for`:** `GateForStmt` + nested `GateOpList` → `ASTGateForOpNode` (`ASTTypeGateFor`). SNAP in `cvgates.inc` is `array[angle, N]` with `for i in [0:N] { ctrl[i] @ gphase(thetas[i]) qm; }`. +- **Compiler call ABI:** see `docs/gates.md` § Frozen call-node contract — `disp` / `snap` / `ecd` call fields only; decls and `GateQOpList` are unstable. +- `ctrl` is a reserved token (`TOK_CTRL`); do not use `ctrl` as an operand name. +- **Out of CV-core scope:** `while` in `GateOpList`; int/bool/duration/bit array formals; non-`uint` / non-size template params. + +## Grammar / production + +| Piece | Location | +|-------|----------| +| Typed quantum list | `GateTypedQuantumOperandList` in `lib/Parser/QasmParser.y` | +| Decl production | `ProductionRule_10030` in `ASTProductionFactory.cpp` | +| Template register | `ProductionRule_10031` + `ASTGateTemplateParamBuilder` | +| Shared AST build | Delegates to `ProductionRule_1430` after validating formals | +| Call entry | `ProductionRule_3500` → `CreateQOpNodeCall` → `CreateGateCall` | +| Compatibility | `ASTGateType` in `include/qasm/AST/ASTGateType.h` | + +Decl-time checks in `10030`: +- Classical: `IsExplicitClassicalGateParamType` (includes explicit `angle`, + float/complex/arrays; bare Identifier formals are also angles and allowed + on this path when quantum operands are typed) +- Quantum: polymorphic type must be `ASTTypeQubit` or `ASTTypeQumode` +- Stores `FormalParamTypes`, `FormalParamArraySizes`, + `FormalParamArraySizeTemplateIndices`, `TemplateParams`, `FormalQuantumTypes` + +## GateType lattice (call-site) + +`FormalParamTypes[i]` (+ optional size) is the type oracle. Carriers (`Params` / `ArrayParams` / `ComplexArrayParams` / `ComplexParams`) are storage only. + +`ASTGateType::Compatible(F, A)`: +- Real↔angle array family (`AngleArray` / `FloatArray` / `MPDecimalArray`) +- Real→complex scalar and real-array→complex-array promotion +- Reject complex→real (scalar or array) +- Array size equality when both sides known + +Hook: `ASTTypeDiscovery::ValidateTypedGateCall` from `CreateGateCall` **before** `CloneCall`, only if `GN->IsFullyTyped()`. + +## AST storage (definition gate) + +| Formal kind | Storage | Read for checking | +|-------------|---------|-------------------| +| `complex[…]` | `Params` as `MPComplex` | Prefer `FormalParamTypes[i]` on fully-typed gates | +| `float` / `double` / `mpdecimal` scalars | `Params` as declared type (type-faithful) | Prefer `FormalParamTypes[i]` | +| other non-float scalars (int/bool/…) | still coerced to angle `.gateparam` in `Params` | Must use `FormalParamTypes` | +| `array[float/mpdecimal, N]` | Declared STE in GSTM + same node in `Params` (no `.gatearray`) | `FormalParamTypes` + size | +| `array[angle, N]` | `Params` as `AngleArray` | `FormalParamTypes` + size | +| `array[complex[…], N]` | `Params` as `MPComplexArray` | `FormalParamTypes` + size | +| qubit / qumode | `OperandParams` STE; polymorphic type restored | Prefer `FormalQuantumTypes[i]` | +| `Operands` vector | synthetic GateQubitParam-shaped nodes | **Do not** use for qubit vs qumode | + +Array formals share one ctor path in `ASTGates.cpp`: erase LSTM, bind declared STE into GSTM, then `AddParam` with the declared array type (float/mpdecimal/angle/complex). + +## Call-site Params (Phase 2) + +`ArgumentNodeList` ctor keeps `Params` type-faithful when `FormalParamTypes` say so: + +- `FormalWantsComplex` → `MPComplex` (unchanged) +- `FormalWantsFloatArray` + `ProductionRule_10010` AngleArray literal → convert to `MPDecimalArray` (`ast-gate-mpdecimal-array-lit-*`) +- `FormalWantsFloatScalar` → keep float/double/mpdecimal (no angle coercion) +- Angle / complex-array formals → store as AngleArray / MPComplexArray +- Untyped OQ3 calls → still angle-shaped Params + +## Literals (`ProductionRule_10010`) + +`ASTGateType::ExpressionListHasComplex` decides complex vs angle-array literal. Call-site and builder share that classification. Real array literals stay AngleArray at 10010; float formals convert at call materialization. + +Gate call `ArgsList` is `'(' ExprList ')'`. Array literals are `ExprList` +elements (`[ExprList]`), so `foo([a,b], theta)` works alongside `… im` +complex initializers and nested function calls. Do not reintroduce a +separate `GateCallArg` list — it LR-conflicts with function-call parsing. + +## Do not + +- Check untyped OQ3 gates. +- Treat “has `ComplexParams` alone” as fully typed (classical-only typing + bare qubits is not the fully-typed form). +- Leave stray `std::cerr` / `std::cout` debug prints in production paths. + +## Array formals (SNAP-like) + +Gate param lists provisionally type identifiers as `ASTTypeAngle`. `ProductionRule_822` must **rebind** Angle/Undefined → array type and allow formals in gate/function contexts (`AllowArrayInCurrentContext` / `IsGateParameterArgument`). Do not leave hard `assert(Id->GetSymbolType() == Ty)` — that SIGABRTs on `array[float[64], N] thetas`. + +`GateOpList` includes `for` (`GateForStmt`). After an `array[…]` formal, +`SetCurrentType(ForStatement)` must win over leftover `PreviousType` array +state or induction vars are typed as arrays. + +## Tests + +- Positive: `tests/src/qumode/gate-for-fock.qasm` (gate-body `for` + Fock `ctrl[i]` + `thetas[i]`) +- Positive: `tests/src/qumode/ecd-mixed.qasm` (`ecd(0.5) qb, qm`) +- Positive: `tests/src/qumode/complex-array-param.qasm` (`array[complex[…], N]` formal + call) +- Positive: `tests/src/qumode/float-array-param.qasm` (`array[float[64], N]` body index + call) +- Positive: `tests/src/qumode/angle-array-param.qasm` (`array[angle, N]` body index + multi-gate ASTM reuse) +- Positive: `tests/src/qumode/multi-angle-array-param.qasm` (two angle arrays, different `N`) +- Positive: `tests/src/qumode/angle-scalar-param.qasm` (`angle` scalar + float array formals) +- Positive: `tests/src/qumode/gate-template-array-param.qasm` (`uint N` template + infer/`[3]`) +- Negative (expect-fail `test $? -ne 0`): + - `ecd-param-reject.qasm` — angle array for complex formal + - `ecd-operand-reject.qasm` — qumode where qubit expected + - `ecd-operand-order-reject.qasm` — swapped qubit/qumode + - `disp-qubit-reject.qasm` — builtin disp pattern + - `array-elem-complex-reject.qasm` — complex element in float array formal + - `array-size-mismatch-reject.qasm` — literal length ≠ formal `N` (param 0) + - `array-size-mismatch-param1-reject.qasm` — size mismatch on second array formal + - `gate-template-size-mismatch-reject.qasm` — `foo[2]([a,b,c])` + - `gate-template-infer-fail-reject.qasm` — uninitialized named array (`used before assigned`) + - `gate-template-conflict-reject.qasm` — conflicting inferred `N` from two arrays + - `gate-template-unused-reject.qasm` — `N` not used as an array size (cannot infer) +- Include: `tests/include/cvgates.inc` +- Manual: `gate-decl.qasm` (`rz3` + `disp3`) diff --git a/.gitignore b/.gitignore index b152d7e..9444cdf 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,9 @@ VERSION.txt build/ CMakeUserPresets.json + +# uv +.venv/ +# clangd cache +.cache/ +.cache/* diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index efe5e58..6ced4ca 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,40 +3,40 @@ repos: rev: v4.1.0 hooks: - id: no-commit-to-branch - stages: [commit] + stages: [pre-commit] args: [--branch, main, --pattern, release/.*, --pattern, .*/release/.*] - id: check-json - stages: [commit] + stages: [pre-commit] - id: end-of-file-fixer - stages: [commit] + stages: [pre-commit] exclude: '.+(\.s[ql][23])$' - id: trailing-whitespace - stages: [commit] + stages: [pre-commit] args: [--markdown-linebreak-ext=md] exclude: '.+(\.s[ql][23])$' - id: check-merge-conflict - stages: [commit] + stages: [pre-commit] - id: debug-statements - stages: [commit] + stages: [pre-commit] - repo: https://github.com/psf/black rev: 22.3.0 hooks: - id: black - stages: [commit] + stages: [pre-commit] args: - "-l 100" - repo: https://github.com/pre-commit/mirrors-clang-format rev: v17.0.5 hooks: - id: clang-format - stages: [commit] + stages: [pre-commit] args: - "--style=file:.clang-format" - repo: https://github.com/PyCQA/flake8.git - rev: 4.0.1 + rev: 7.3.0 hooks: - id: flake8 - stages: [commit] + stages: [pre-commit] args: - "--max-line-length=100" - "--extend-ignore=W503" diff --git a/README.md b/README.md index 425bda1..dadff43 100644 --- a/README.md +++ b/README.md @@ -45,16 +45,19 @@ Currently the supported platforms are Linux and OSX. It is possible to build on - Clone this repo: `git clone git@github.com:openqasm/qe-qasm.git` - Install build dependencies: `pip install -r requirements-dev.txt` - It is recommended to use a Python virtual environment for this + - If you're using `uv`, `uv sync` also works. Then, prepend every call to `conan` with `uv run` below. - The package may be built and installed to conan with: `conan create . --build=outdated -pr:h default -pr:b default` - This will build the conan package and install it locally. The version will be detected automatically from the repo tag. - If you wish to override the package name, version or remote do so by calling conan with `conan create . /@remote -pr:h default -pr:b default` #### Building for development and debugging +- If you're using `uv`, make sure you have run `uv sync` first. Then, prepend every call to `conan` with `uv run` below. - Create a build directory: `mkdir build && cd build/` - Install package with: `conan install .. --build=outdated -pr:h default -pr:b default` which will install and build all missing dependencies - Build the package with: `conan build ..` - The package tests may be run with: `conan build .. --test` +Note that the `conan` commands should be called under the `build/` directory. ### Make diff --git a/conan.lock b/conan.lock new file mode 100644 index 0000000..aaa7120 --- /dev/null +++ b/conan.lock @@ -0,0 +1,77 @@ +{ + "graph_lock": { + "nodes": { + "0": { + "ref": "qe-qasm/0.1.dev49+gd53a324.d20260722", + "options": "examples=True\nshared=False\nbison:fPIC=True\nflex:fPIC=True\nflex:shared=False\ngmp:disable_assembly=True\ngmp:enable_cxx=True\ngmp:enable_fat=False\ngmp:run_checks=False\ngmp:shared=True\nmpc:shared=True\nmpfr:exact_int=gmp\nmpfr:shared=True", + "requires": [ + "1", + "2", + "3", + "4", + "6" + ], + "path": "conanfile.py", + "context": "host" + }, + "1": { + "ref": "gmp/6.3.0", + "options": "disable_assembly=True\nenable_cxx=True\nenable_fat=False\nrun_checks=False\nshared=True", + "package_id": "fd753028090680f4f67b15fd8f9cf62b7e067d18", + "prev": "0", + "context": "host" + }, + "2": { + "ref": "mpfr/4.2.1", + "options": "exact_int=gmp\nshared=True\ngmp:disable_assembly=True\ngmp:enable_cxx=True\ngmp:enable_fat=False\ngmp:run_checks=False\ngmp:shared=True", + "package_id": "6a95df1aab838f59c295854c305f3dee0123b70a", + "prev": "0", + "requires": [ + "1" + ], + "context": "host" + }, + "3": { + "ref": "mpc/1.3.1", + "options": "shared=True\ngmp:disable_assembly=True\ngmp:enable_cxx=True\ngmp:enable_fat=False\ngmp:run_checks=False\ngmp:shared=True\nmpfr:exact_int=gmp\nmpfr:shared=True", + "package_id": "1a1af87cb4792c6f38cdc8a6684c7f3b3289a10a", + "prev": "0", + "requires": [ + "1", + "2" + ], + "context": "host" + }, + "4": { + "ref": "bison/3.8.2", + "options": "fPIC=True", + "package_id": "30a96fe53c3e98a98796c7cef11032c83754d473", + "prev": "0", + "requires": [ + "5" + ], + "context": "host" + }, + "5": { + "ref": "m4/1.4.19", + "options": "", + "package_id": "24647d9fe8ec489125dfbae4b3ebefaf7581674c", + "prev": "0", + "context": "host" + }, + "6": { + "ref": "flex/2.6.4", + "options": "fPIC=True\nshared=False", + "package_id": "30a96fe53c3e98a98796c7cef11032c83754d473", + "prev": "0", + "requires": [ + "5" + ], + "context": "host" + } + }, + "revisions_enabled": false + }, + "version": "0.4", + "profile_host": "[settings]\narch=x86_64\narch_build=x86_64\nbuild_type=Release\ncompiler=gcc\ncompiler.libcxx=libstdc++\ncompiler.version=8\nos=Linux\nos_build=Linux\n[options]\n[build_requires]\n[env]\n" +} \ No newline at end of file diff --git a/conanbuildinfo.txt b/conanbuildinfo.txt new file mode 100644 index 0000000..ebd55bc --- /dev/null +++ b/conanbuildinfo.txt @@ -0,0 +1,472 @@ +[includedirs] +/home/omt3255/.conan/data/mpc/1.3.1/_/_/package/1a1af87cb4792c6f38cdc8a6684c7f3b3289a10a/include +/home/omt3255/.conan/data/flex/2.6.4/_/_/package/30a96fe53c3e98a98796c7cef11032c83754d473/include +/home/omt3255/.conan/data/mpfr/4.2.1/_/_/package/6a95df1aab838f59c295854c305f3dee0123b70a/include +/home/omt3255/.conan/data/gmp/6.3.0/_/_/package/fd753028090680f4f67b15fd8f9cf62b7e067d18/include + +[libdirs] +/home/omt3255/.conan/data/mpc/1.3.1/_/_/package/1a1af87cb4792c6f38cdc8a6684c7f3b3289a10a/lib +/home/omt3255/.conan/data/bison/3.8.2/_/_/package/30a96fe53c3e98a98796c7cef11032c83754d473/lib +/home/omt3255/.conan/data/flex/2.6.4/_/_/package/30a96fe53c3e98a98796c7cef11032c83754d473/lib +/home/omt3255/.conan/data/mpfr/4.2.1/_/_/package/6a95df1aab838f59c295854c305f3dee0123b70a/lib +/home/omt3255/.conan/data/gmp/6.3.0/_/_/package/fd753028090680f4f67b15fd8f9cf62b7e067d18/lib + +[bindirs] +/home/omt3255/.conan/data/bison/3.8.2/_/_/package/30a96fe53c3e98a98796c7cef11032c83754d473/bin +/home/omt3255/.conan/data/flex/2.6.4/_/_/package/30a96fe53c3e98a98796c7cef11032c83754d473/bin +/home/omt3255/.conan/data/m4/1.4.19/_/_/package/24647d9fe8ec489125dfbae4b3ebefaf7581674c/bin + +[resdirs] +/home/omt3255/.conan/data/bison/3.8.2/_/_/package/30a96fe53c3e98a98796c7cef11032c83754d473/res + +[builddirs] +/home/omt3255/.conan/data/mpc/1.3.1/_/_/package/1a1af87cb4792c6f38cdc8a6684c7f3b3289a10a/ +/home/omt3255/.conan/data/bison/3.8.2/_/_/package/30a96fe53c3e98a98796c7cef11032c83754d473/ +/home/omt3255/.conan/data/flex/2.6.4/_/_/package/30a96fe53c3e98a98796c7cef11032c83754d473/ +/home/omt3255/.conan/data/mpfr/4.2.1/_/_/package/6a95df1aab838f59c295854c305f3dee0123b70a/ +/home/omt3255/.conan/data/m4/1.4.19/_/_/package/24647d9fe8ec489125dfbae4b3ebefaf7581674c/ + +[libs] +mpc +y +fl +mpfr +gmpxx +gmp + +[system_libs] +m + +[defines] + + +[cppflags] + + +[cxxflags] + + +[cflags] + + +[sharedlinkflags] + + +[exelinkflags] + + +[sysroot] + + +[frameworks] + + +[frameworkdirs] + + + +[includedirs_mpc] +/home/omt3255/.conan/data/mpc/1.3.1/_/_/package/1a1af87cb4792c6f38cdc8a6684c7f3b3289a10a/include + +[libdirs_mpc] +/home/omt3255/.conan/data/mpc/1.3.1/_/_/package/1a1af87cb4792c6f38cdc8a6684c7f3b3289a10a/lib + +[bindirs_mpc] + + +[resdirs_mpc] + + +[builddirs_mpc] +/home/omt3255/.conan/data/mpc/1.3.1/_/_/package/1a1af87cb4792c6f38cdc8a6684c7f3b3289a10a/ + +[libs_mpc] +mpc + +[system_libs_mpc] +m + +[defines_mpc] + + +[cppflags_mpc] + + +[cxxflags_mpc] + + +[cflags_mpc] + + +[sharedlinkflags_mpc] + + +[exelinkflags_mpc] + + +[sysroot_mpc] + + +[frameworks_mpc] + + +[frameworkdirs_mpc] + + +[rootpath_mpc] +/home/omt3255/.conan/data/mpc/1.3.1/_/_/package/1a1af87cb4792c6f38cdc8a6684c7f3b3289a10a + +[name_mpc] +mpc + +[version_mpc] +1.3.1 + +[generatornames_mpc] + + +[generatorfilenames_mpc] + + + +[includedirs_bison] + + +[libdirs_bison] +/home/omt3255/.conan/data/bison/3.8.2/_/_/package/30a96fe53c3e98a98796c7cef11032c83754d473/lib + +[bindirs_bison] +/home/omt3255/.conan/data/bison/3.8.2/_/_/package/30a96fe53c3e98a98796c7cef11032c83754d473/bin + +[resdirs_bison] +/home/omt3255/.conan/data/bison/3.8.2/_/_/package/30a96fe53c3e98a98796c7cef11032c83754d473/res + +[builddirs_bison] +/home/omt3255/.conan/data/bison/3.8.2/_/_/package/30a96fe53c3e98a98796c7cef11032c83754d473/ + +[libs_bison] +y + +[system_libs_bison] + + +[defines_bison] + + +[cppflags_bison] + + +[cxxflags_bison] + + +[cflags_bison] + + +[sharedlinkflags_bison] + + +[exelinkflags_bison] + + +[sysroot_bison] + + +[frameworks_bison] + + +[frameworkdirs_bison] + + +[rootpath_bison] +/home/omt3255/.conan/data/bison/3.8.2/_/_/package/30a96fe53c3e98a98796c7cef11032c83754d473 + +[name_bison] +bison + +[version_bison] +3.8.2 + +[generatornames_bison] + + +[generatorfilenames_bison] + + + +[includedirs_flex] +/home/omt3255/.conan/data/flex/2.6.4/_/_/package/30a96fe53c3e98a98796c7cef11032c83754d473/include + +[libdirs_flex] +/home/omt3255/.conan/data/flex/2.6.4/_/_/package/30a96fe53c3e98a98796c7cef11032c83754d473/lib + +[bindirs_flex] +/home/omt3255/.conan/data/flex/2.6.4/_/_/package/30a96fe53c3e98a98796c7cef11032c83754d473/bin + +[resdirs_flex] + + +[builddirs_flex] +/home/omt3255/.conan/data/flex/2.6.4/_/_/package/30a96fe53c3e98a98796c7cef11032c83754d473/ + +[libs_flex] +fl + +[system_libs_flex] +m + +[defines_flex] + + +[cppflags_flex] + + +[cxxflags_flex] + + +[cflags_flex] + + +[sharedlinkflags_flex] + + +[exelinkflags_flex] + + +[sysroot_flex] + + +[frameworks_flex] + + +[frameworkdirs_flex] + + +[rootpath_flex] +/home/omt3255/.conan/data/flex/2.6.4/_/_/package/30a96fe53c3e98a98796c7cef11032c83754d473 + +[name_flex] +flex + +[version_flex] +2.6.4 + +[generatornames_flex] + + +[generatorfilenames_flex] + + + +[includedirs_mpfr] +/home/omt3255/.conan/data/mpfr/4.2.1/_/_/package/6a95df1aab838f59c295854c305f3dee0123b70a/include + +[libdirs_mpfr] +/home/omt3255/.conan/data/mpfr/4.2.1/_/_/package/6a95df1aab838f59c295854c305f3dee0123b70a/lib + +[bindirs_mpfr] + + +[resdirs_mpfr] + + +[builddirs_mpfr] +/home/omt3255/.conan/data/mpfr/4.2.1/_/_/package/6a95df1aab838f59c295854c305f3dee0123b70a/ + +[libs_mpfr] +mpfr + +[system_libs_mpfr] + + +[defines_mpfr] + + +[cppflags_mpfr] + + +[cxxflags_mpfr] + + +[cflags_mpfr] + + +[sharedlinkflags_mpfr] + + +[exelinkflags_mpfr] + + +[sysroot_mpfr] + + +[frameworks_mpfr] + + +[frameworkdirs_mpfr] + + +[rootpath_mpfr] +/home/omt3255/.conan/data/mpfr/4.2.1/_/_/package/6a95df1aab838f59c295854c305f3dee0123b70a + +[name_mpfr] +mpfr + +[version_mpfr] +4.2.1 + +[generatornames_mpfr] + + +[generatorfilenames_mpfr] + + + +[includedirs_m4] + + +[libdirs_m4] + + +[bindirs_m4] +/home/omt3255/.conan/data/m4/1.4.19/_/_/package/24647d9fe8ec489125dfbae4b3ebefaf7581674c/bin + +[resdirs_m4] + + +[builddirs_m4] +/home/omt3255/.conan/data/m4/1.4.19/_/_/package/24647d9fe8ec489125dfbae4b3ebefaf7581674c/ + +[libs_m4] + + +[system_libs_m4] + + +[defines_m4] + + +[cppflags_m4] + + +[cxxflags_m4] + + +[cflags_m4] + + +[sharedlinkflags_m4] + + +[exelinkflags_m4] + + +[sysroot_m4] + + +[frameworks_m4] + + +[frameworkdirs_m4] + + +[rootpath_m4] +/home/omt3255/.conan/data/m4/1.4.19/_/_/package/24647d9fe8ec489125dfbae4b3ebefaf7581674c + +[name_m4] +m4 + +[version_m4] +1.4.19 + +[generatornames_m4] + + +[generatorfilenames_m4] + + + +[includedirs_gmp] +/home/omt3255/.conan/data/gmp/6.3.0/_/_/package/fd753028090680f4f67b15fd8f9cf62b7e067d18/include + +[libdirs_gmp] +/home/omt3255/.conan/data/gmp/6.3.0/_/_/package/fd753028090680f4f67b15fd8f9cf62b7e067d18/lib + +[bindirs_gmp] + + +[resdirs_gmp] + + +[builddirs_gmp] + + +[libs_gmp] +gmpxx +gmp + +[system_libs_gmp] +m + +[defines_gmp] + + +[cppflags_gmp] + + +[cxxflags_gmp] + + +[cflags_gmp] + + +[sharedlinkflags_gmp] + + +[exelinkflags_gmp] + + +[sysroot_gmp] + + +[frameworks_gmp] + + +[frameworkdirs_gmp] + + +[rootpath_gmp] +/home/omt3255/.conan/data/gmp/6.3.0/_/_/package/fd753028090680f4f67b15fd8f9cf62b7e067d18 + +[name_gmp] +gmp + +[version_gmp] +6.3.0 + +[generatornames_gmp] +pkg_config=gmp-all-do-not-use + +[generatorfilenames_gmp] + + + +[USER_bison] +YACC=/home/omt3255/.conan/data/bison/3.8.2/_/_/package/30a96fe53c3e98a98796c7cef11032c83754d473/bin/yacc +[USER_flex] +[USER_gmp] +[USER_m4] +[USER_mpc] +[USER_mpfr] +[ENV_mpc] +[ENV_bison] +BISON_PKGDATADIR=/home/omt3255/.conan/data/bison/3.8.2/_/_/package/30a96fe53c3e98a98796c7cef11032c83754d473/res/bison +CONAN_BISON_ROOT=/home/omt3255/.conan/data/bison/3.8.2/_/_/package/30a96fe53c3e98a98796c7cef11032c83754d473 +PATH=["/home/omt3255/.conan/data/bison/3.8.2/_/_/package/30a96fe53c3e98a98796c7cef11032c83754d473/bin"] +[ENV_flex] +LEX=/home/omt3255/.conan/data/flex/2.6.4/_/_/package/30a96fe53c3e98a98796c7cef11032c83754d473/bin/flex +PATH=["/home/omt3255/.conan/data/flex/2.6.4/_/_/package/30a96fe53c3e98a98796c7cef11032c83754d473/bin"] +[ENV_mpfr] +[ENV_m4] +M4=/home/omt3255/.conan/data/m4/1.4.19/_/_/package/24647d9fe8ec489125dfbae4b3ebefaf7581674c/bin/m4 +PATH=["/home/omt3255/.conan/data/m4/1.4.19/_/_/package/24647d9fe8ec489125dfbae4b3ebefaf7581674c/bin"] +[ENV_gmp] \ No newline at end of file diff --git a/conaninfo.txt b/conaninfo.txt new file mode 100644 index 0000000..067b88e --- /dev/null +++ b/conaninfo.txt @@ -0,0 +1,55 @@ +[settings] + arch=x86_64 + build_type=Release + compiler=gcc + compiler.libcxx=libstdc++ + compiler.version=8 + os=Linux + +[requires] + bison/3.Y.Z + flex/2.Y.Z + gmp/6.Y.Z + mpc/1.Y.Z + mpfr/4.Y.Z + +[options] + examples=True + shared=False + +[full_settings] + arch=x86_64 + build_type=Release + compiler=gcc + compiler.libcxx=libstdc++ + compiler.version=8 + os=Linux + +[full_requires] + bison/3.8.2:30a96fe53c3e98a98796c7cef11032c83754d473 + flex/2.6.4:30a96fe53c3e98a98796c7cef11032c83754d473 + gmp/6.3.0:fd753028090680f4f67b15fd8f9cf62b7e067d18 + m4/1.4.19:24647d9fe8ec489125dfbae4b3ebefaf7581674c + mpc/1.3.1:1a1af87cb4792c6f38cdc8a6684c7f3b3289a10a + mpfr/4.2.1:6a95df1aab838f59c295854c305f3dee0123b70a + +[full_options] + examples=True + shared=False + bison:fPIC=True + flex:fPIC=True + flex:shared=False + gmp:disable_assembly=True + gmp:enable_cxx=True + gmp:enable_fat=False + gmp:run_checks=False + gmp:shared=True + mpc:shared=True + mpfr:exact_int=gmp + mpfr:shared=True + +[recipe_hash] + + +[env] + diff --git a/docs/gates.md b/docs/gates.md new file mode 100644 index 0000000..dc7be62 --- /dev/null +++ b/docs/gates.md @@ -0,0 +1,398 @@ +# Gates + +This document describes the syntax of qumode gates in our extension to +OpenQASM 3.0, as well as the limitations of the parser on these declarations. + + + +# Basic Qumode Gates + +At the moment, the following qumode gates are supported: +- displacement `disp(alpha) qm` +- SNAP: `snap([theta_0, theta_1, ...]) qm` +- ECD: `ecd(alpha) qb, qm` + +## Displacement gate + +Gate signature: +```qasm +gate disp(complex[float[64]] alpha) qumode qm; +``` +Example Usage: +```qasm +disp(0.5 + 0.5im) qm; +disp(0.5) qm; // equivalent to disp(0.5 + 0.0im) +``` +The displacement gate is treated as a builtin gate. The user doesn't need to +include any file to use this gate. + +## SNAP gate + +Gate definition (`tests/include/cvgates.inc`): +```qasm +gate snap[uint N](array[angle, N] thetas) qumode qm { + for i in [0:N] { + ctrl[i] @ gphase(thetas[i]) qm; // controls the i-th Fock level + } +} +``` +Example Usage: +```qasm +snap([pi/2, 0, 0.3]) qm; // infer N = 3 +snap[3]([pi/2, 0, 0.3]) qm; // check length == 3 +``` +Include `tests/include/cvgates.inc` to use this gate. Call sites may omit the +template argument when `N` can be inferred from the array literal or a sized +named array (`snap([pi/2, 0, 0.3]) qm`), or pass it explicitly (`snap[3](…)`). + +## ECD gate + +Gate definition: +```qasm +gate ecd(complex[float[64]] alpha) qubit qb, qumode qm { + negctrl @ disp(-alpha/2) qb, qm; + ctrl @ disp(alpha/2) qb, qm; +} +``` +Example Usage: +```qasm +ecd(0.5 + 0.5im) qb, qm; +ecd(0.5) qb, qm; // equivalent to ecd(0.5 + 0.0im) qb, qm; +``` +Include `tests/include/cvgates.inc` to use this gate. + + + +# Gate Declaration Syntax + +These qumode gates introduce new types of parameters and operands. In +OpenQASM 3.0, all parameters and operands are of type `angle` and `qubit` +respectively. This is no longer the case in our extension. Therefore, +we introduce a typed gate declaration syntax that facilitates type checking at +the syntactic level. + + +Currently, the supported classical types for parameters are `angle`, `float[N]`, +`complex[float[N]]`, and fixed-length arrays of these types (including lengths +bound by template parameters). Type checking for typed gate declarations is +enforced both in definitions and in call sites. + +## Examples for the new syntax + +The main addition to the syntax is that the types of parameters and operands are +specified before the name of the parameter or operand (à la C). For example, +the following is a valid gate declaration: +```qasm +gate ecd(complex[float[64]] alpha) qubit c, qumode t { + negctrl @ disp(-alpha/2) c, t; + ctrl @ disp(alpha/2) c, t; +} +``` + +Arrays of `angle`s, `float[N]`s, or `complex[float[N]]`s can also be used as +parameters: +```qasm +gate foo(array[angle, 3] phases) qubit q { + ctrl @ gphase(phases[0]) q; + ctrl @ gphase(phases[1]) q; + ctrl @ gphase(phases[2]) q; +} +gate bar(array[complex[float[64]], 3] alphas) qumode qm { + disp(alphas[0]) qm; + disp(alphas[1]) qm; + disp(alphas[2]) qm; +} +``` + +It is also possible to mix and match different types of parameters and operands: +```qasm +gate baz(array[complex[float[64]], 3] alphas, angle beta) qubit qb, qumode qm { + ctrl @ gphase(beta) qb; + ecd(alphas[0]/2) qb, qm; + ecd(alphas[1]/3) qb, qm; + ecd(alphas[2]/4) qb, qm; +} +``` + +Arrays with variable lengths can also be used as parameters through +template parameters: +```qasm +gate foo[uint N](array[float[64], N] thetas) qubit q { + ... +} +``` + + +Call sites may bind `N` explicitly or omit it when it can be inferred from an +array literal’s arity or a **sized** named array’s declared length + +```qasm +foo([pi/2, 0, 0.3]) q; // infer N = 3 +foo[3]([pi/2, 0, 0.3]) q; // check length == 3 +``` + +Each template parameter must be uniquely determined by an array size at the +call. An uninitialized named array (declared but not assigned) is rejected with +a “variable used before assigned” diagnostic. v1 supports only `uint` templates +used as array sizes. Template parameters use square brackets (`gate foo[uint N]` +/ `foo[3](…)`), not angle brackets. + +## Fock-level `ctrl[…]` / `negctrl[…]` + +Distinct from qubit n-control `ctrl(n) @ …` (parentheses). Square brackets +select a **Fock level**: + +```qasm +ctrl[3] @ gphase(pi/2) qm; +ctrl[N] @ gphase(pi/2) qm; // N = gate template param or other int id +ctrl[N-1] @ gphase(pi/2) qm; +ctrl[(2*N)] @ gphase(pi/2) qm; // parentheses ok for richer exprs +negctrl[i] @ disp(alpha) qm; +``` + +Existing forms are unchanged: `ctrl @`, `ctrl(2) @`, `negctrl @`, `negctrl(2) @`. + +The level may be an integer literal, identifier, or a `+`/`-`/`*`/`/` expression +(including parentheses). Template parameters (`uint N`) are bound as gate-local +ints so `ctrl[N]` / `ctrl[N-1]` in a gate body resolve. + +**Limitation:** Multi-control syntaxes `ctrl[level](n_ctrls)` are currently not +supported. + +## Gate-body `for` + +Gate bodies may contain `for` loops whose body is a list of gate operations +(range or integer list): + +```qasm +gate snap[uint N](array[angle, N] thetas) qumode qm { + for i in [0:N] { + ctrl[i] @ gphase(thetas[i]) qm; + } +} +``` + +Induction variables are gate-local ints. The body of the `for` loop is subject +to the same limitations as elsewhere in gate bodies. In particular, only +gate calls and `barrier`s are allowed in the body. Non-unitary operations, such +as `measure` and `reset`, are not allowed. + +**Limitation:** While the parser can parse a forward traversal `for` loop, more +complicated loops may not parse correctly at the moment. +For example, the following two gate declarations will not parse: +```qasm +gate foo[uint N](array[angle, N] thetas) qubit q { + for i in [0:N] { + ctrl @ gphase(thetas[N - i - 1]) q; + } +} +gate bar[uint N](array[angle, N] thetas) qubit q { + for i in [0:(N/2)] { + ctrl @ gphase(thetas[i]) q; + ctrl @ gphase(thetas[N - i - 1]) q; + } +} +``` +This is in part due to the stock parser's defect in parsing expressions +(see [issue #12](https://github.com/paragon-lab/qe-qasm-qumode-version/issues/12)). +For now, we only support forward traversal, which is hopefully sufficient for +most use cases. + +## Type Errors at Call Sites +Typed gate declarations allows the following errors to be caught at the +syntactic/semantic level: +```qasm +qubit[2] qb; qumode[2] qm; + +ecd(0.5 + 0.5im) qb[0], qb[1]; // error, qb[1] is not a qumode +ecd(0.5 + 0.5im) qm[0], qm[1]; // error, qm[0] is not a qubit +snap(pi/2) qm[0]; // error, pi/2 is not an array of angles +snap[2]([pi/2, 0, 0.3]) qm[0]; // error, the array length is not 2 + +gate foo[uint N](array[angle, N] alphas, array[float[64], N] betas) qubit q { + ... +} +foo([pi/2, 0, 0.3], [0.5, 0.5]) qb; // error, template parameter N cannot be inferred + +gate bar[uint N](complex[float[64]] alpha) qumode qm { + ... +} +bar(0.5 + 0.5im) qm; // error, template parameter N cannot be inferred +``` + +## Compatibility with OpenQASM 3.0 gate definitions + +Since OpenQASM 3.0 is widely adopted, users may still want to use gate +definitions written in the untyped OpenQASM 3.0 syntax. +To facilitate this, the parser is backward compatible with +the `OpenQASM 3.0` gate declaration syntax. For example, consider this +declaration of the `rz` gate, which does not contain typing information: +```qasm +gate rz(theta) q { + ctrl @ gphase(theta) q; +} +``` +In this case, all parameters would be treated as `angle`s, and operands would be +treated as `qubit`s. That is, the above definition would be equivalent to the +following typed definition: +```qasm +gate rz(angle theta) qubit q { + ctrl @ gphase(theta) q; +} +``` +To avoid footguns, the untyped and typed gate declaration syntaxes cannot be +mixed with each other. As soon as one parameter or operand is typed, all other +parameters and operands must also be typed. +```qasm +gate ecd(complex[float[64]] alpha) qubit c, qumode t {...} // ok +gate ecd(alpha) qubit c, qumode t {...} // error, alpha is not typed +gate ecd(complex[float[64]] alpha) c, qumode t {...} // error, c is not typed +``` + + + +# Notes for developers + +This section is for compiler developers. Users of the language can skip it. + +## Syntax Change for Template Parameters + +- **Square brackets for templates.** This matches how OpenQASM 3 already uses + `[]` for sized types (`int[32]`, `array[int[32], 5]`). + + An earlier proposal used angle brackets (`gate foo`), which proved + to be problematic for parsing. + For example, suppose we want to support expressions like `ctrl[N-1]` or + `ctrl[3*2]`, we would have a rule like `TOK_CTRL '[' Expr ']' ...`. + But `']'` can also be a part of `Expr`, making it very annoying to parse. + Currently, we disallow expressions inside square brackets to avoid this + problem. Granted, the user might not have an incentive to put expressions + inside square brackets, but if they do, it would be hard to support that. + This is why the current implementation uses square brackets for template + parameters. + It doesn't help that expression parsing in this repo is not very robust to + begin with (see + [issue #12](https://github.com/paragon-lab/qe-qasm-qumode-version/issues/12)). + +- **Fock `ctrl[…]` vs qubit `ctrl(n)`.** An earlier proposal used `ctrl(n)` + for Fock-level control, which conflicts with the existing n-control form. For + example `ctrl(2) @ x a, b, c;` already exists in OpenQASM 3.0 and is + equivalent to a CCX gate. Therefore, for qumode Fock-level control, we use + square brackets to avoid conflicts. We can view `ctrl[N]` as an analogy of + the template syntax elsewhere in the language. + +## AST Structure for Gate Declarations and Calls + +### Frozen call-node contract (compiler-facing) + +For **gate calls** (`GateCall=true`) of the shipped CV gates, treat the +following as the stable interface. Declaration syntax, `GateQOpList` bodies, +and mangled-name spelling are **not** part of this contract and may change. + +| Gate | How to get it | Classical `Params` | Templates | Quantum | +|------|---------------|--------------------|-----------|---------| +| `disp` | builtin | one `MPComplex` (`alpha`; real promotes to real+0i) | none | one `qumode` (see note) | +| `snap` | `cvgates.inc` | one `AngleArray` (`thetas`) | `N` with bound `Value` = array length | one `qumode` | +| `ecd` | `cvgates.inc` | one `MPComplex` (`alpha`; real promotes) | none | `qubit`, then `qumode` | + +**Note on `disp`:** As a builtin, call nodes may omit `FullyTyped` / +`FormalParamTypes` / `FormalQuantumTypes`. Identify by `Name=disp`, read +`Params` as `MPComplex`, and take the qumode from `OperandParams` (a controlled +`disp` in an `ecd` body can list the control qubit first — the target qumode is +still present). Typed `snap` / `ecd` calls always carry the Formal* fields. + +**Read these fields on a call:** + +1. `Name` / `GateDefinitionName` — which gate. +2. `FullyTyped` — must be `true` for the rows above. +3. `TemplateParams` — for `snap`, `Name=N` and `Value` is the bound size + (inferred or explicit). Empty for `disp` / `ecd`. +4. `Params` — classical argument **values**. On fully typed calls, + `Params[i]/Type` matches the formal classical type (`MPComplex`, + `AngleArray`, …). Prefer this over re-deriving types from expressions. +5. `FormalQuantumTypes` — declared qubit vs qumode per operand slot + (parallel to call operands). +6. `OperandParams` — call-site operand names / refs (`qb`, `qm`, `qm[0]`, …), + same order as `FormalQuantumTypes`. Always present on typed CV calls. +7. `Operands` — when present, `Qubit` / `Qumode` nodes for those slots; may be + absent on some call shapes. Do **not** require it; use (5)+(6). + +**The Following Parts of the AST has not Stabilized** + +- `GateQOpList` (body is shared with the definition; parameters are **not** + substituted at the call site — intentional). +- `MangledName` spelling (useful for debug; not an ABI). +- Exact element node names under array literals (`ast-gate-…`). + +Illegal calls are rejected by the parser; a well-typed program should not +present e.g. `ecd` with two qubits. + +### The `` node + +The AST representation of a gate declaration is enclosed in the +` --> ` node. Inside the `` node, we have +- ``: the name of the gate. +- ``: the mangled name of the gate. The mangling logic resides in + `lib/AST/ASTMangler.cpp`. Debug aid only for the call contract above. +- ``: whether the gate is opaque. If the gate is opaque, the parser is + told that the definition of the gate exists without actually seeing it. This + option is deprecated and would typically be set to `false`. +- ``: whether the gate is a gate call. This would be false at + a gate declaration, and true at a gate call. +- ``: whether the gate is fully typed. If the gate is fully typed, + `` and `` would be present. +- ``: unsigned template formals (`uint N` in `gate foo[uint N](…)`). + Printed before classical `` to match source order + `gate name[N](…) qubits`. Each entry has ``, ``, and + ``. On a **declaration**, `` is `NaN` (placeholder). + On a **call**, `` holds the explicit or inferred binding (e.g. `3` + for `snap[3](…)` / inferred `snap([…])`). Body uses of `N` are **not** + overwritten; `GateQOpList` may still mention symbolic `N`. +- ``: declared classical types (and array size / size + template metadata). Parallel to ``. On fully typed calls, + `Params[i]/Type` matches; keep Formal* for `ArraySize` / + `ArraySizeTemplate` until that metadata moves onto Params. +- ``: declared quantum operand kinds (qubit vs qumode). +- ``: the parameters of the gate (value carrier). + On **fully typed** definitions, float/mpdecimal scalars and + `array[float|mpdecimal, N]` formals are stored with their declared types + (no synthetic `.gatearray` angle view). Angle/complex formals match their + declared types. Some other classical scalars (int/bool/…) may still appear + as angle placeholders. On **fully typed** calls, `` matches the + formal type (float/mpdecimal arrays from real literals become + `MPDecimalArray`; complex stays `MPComplex`; angle arrays stay + `AngleArray`). Untyped OQ3 calls still coerce reals to angles. +- ``: quantum operand bindings (names / indexed refs). Printed + for declarations and calls. Prefer this plus `` for + call-site quantum slots. +- ``: `Qubit` / `Qumode` nodes when materialized. Optional on some + call shapes; see the frozen call contract. + NOTE: In the original OpenQASM 3.0 parser, this field was called ``. +- ``: the list of operations in the gate body (may include + gate-body `for` nodes). Unstable for compiler ABI when treating CV gates as + basis operations. + +### How Gate Declarations and Calls are Represented in the AST + +For definitions, the parser sees a gate declaration and creates a +`` node with a `` node inside and populates the +fields accordingly. + +For calls, this `` node would be enclosed in the +`/`. + +Loosely speaking, when the parser sees a gate call, it first checks if the +definition of the gate exists either as a builtin gate, a declared gate, or an +opaque gate. +- For builtin gates, the parser builds a `` for that gate. +- For declared and opaque gates, the parser clones the `` node from the + definition, and replaces the fields in `` and `` with + the actual values from the call site. For templated gates it also fills + `` with the bound size(s); it does **not** rewrite + body identifiers named `N`. +- A quirk is that the parser does **NOT** substitute the parameters and operands + with the actual values in the gate body (the contents of ``). + The parameters in the body still need to be substituted with what the call + site provides. It seems like this is left to the compiler. + This does also mean that a gate call node can carry redundant information + if the body is never used (e.g., if the gate is considered a basis gate). diff --git a/graph_info.json b/graph_info.json new file mode 100644 index 0000000..f1fea88 --- /dev/null +++ b/graph_info.json @@ -0,0 +1,62 @@ +{ + "options": [ + [ + "examples", + "True" + ], + [ + "shared", + "False" + ], + [ + "bison:fPIC", + "True" + ], + [ + "flex:fPIC", + "True" + ], + [ + "flex:shared", + "False" + ], + [ + "gmp:disable_assembly", + "True" + ], + [ + "gmp:enable_cxx", + "True" + ], + [ + "gmp:enable_fat", + "False" + ], + [ + "gmp:run_checks", + "False" + ], + [ + "gmp:shared", + "True" + ], + [ + "mpc:shared", + "True" + ], + [ + "mpfr:exact_int", + "gmp" + ], + [ + "mpfr:shared", + "True" + ] + ], + "root": { + "name": "qe-qasm", + "version": "0.1.dev49+gd53a324.d20260722", + "user": null, + "channel": null + } +} \ No newline at end of file diff --git a/include/qasm/AST/ASTArgument.h b/include/qasm/AST/ASTArgument.h index 576cbc5..d327ab0 100644 --- a/include/qasm/AST/ASTArgument.h +++ b/include/qasm/AST/ASTArgument.h @@ -209,7 +209,8 @@ class ASTArgumentNodeList { virtual void Append(ASTExpressionNode *EN) { if (EN) - Graph.push_back(new ASTArgumentNode(EN)); + Graph.push_back( + new ASTArgumentNode(static_cast(EN))); } virtual void Append(const ASTExpressionNode *EN) { diff --git a/include/qasm/AST/ASTArray.h b/include/qasm/AST/ASTArray.h index a7575a5..3736f7c 100644 --- a/include/qasm/AST/ASTArray.h +++ b/include/qasm/AST/ASTArray.h @@ -50,11 +50,13 @@ class ASTArrayNode : public ASTExpressionNode { unsigned SZ; unsigned EXT; const ASTInitializerList *INL; + /// When set, SZ is a placeholder and the true length is gate template `Name`. + std::string SizeTemplateName; protected: ASTArrayNode(const ASTIdentifierNode *Id, const std::string &ERM, ASTType Ty) : ASTExpressionNode(Id, new ASTStringNode(ERM), ASTTypeExpressionError), - MM(), AType(Ty), SZ(0U), INL(nullptr) {} + MM(), AType(Ty), SZ(0U), INL(nullptr), SizeTemplateName() {} public: static const unsigned ArrayBits = 64U; @@ -63,12 +65,12 @@ class ASTArrayNode : public ASTExpressionNode { ASTArrayNode(const ASTIdentifierNode *Id, ASTType ATy, unsigned Size, const ASTInitializerList *IL = nullptr) : ASTExpressionNode(Id, ASTTypeArray), MM(), AType(ATy), SZ(Size), - EXT(1U), INL(IL) {} + EXT(1U), INL(IL), SizeTemplateName() {} ASTArrayNode(const ASTIdentifierNode *Id, ASTType ATy, unsigned Size, unsigned Extents, const ASTInitializerList *IL = nullptr) : ASTExpressionNode(Id, ASTTypeArray), MM(), AType(ATy), SZ(Size), - EXT(Extents), INL(IL) {} + EXT(Extents), INL(IL), SizeTemplateName() {} /// Validate the array access, emitting a diagnostic if invalid. void ValidateIndex(unsigned Index, QASM::ASTLocation location) const { @@ -103,6 +105,16 @@ class ASTArrayNode : public ASTExpressionNode { virtual unsigned Extents() const { return EXT; } + virtual void SetSizeTemplateName(const std::string &Name) { + SizeTemplateName = Name; + } + + virtual bool HasSizeTemplate() const { return !SizeTemplateName.empty(); } + + virtual const std::string &GetSizeTemplateName() const { + return SizeTemplateName; + } + virtual std::any &Memory() = 0; virtual const std::any &Memory() const = 0; @@ -754,9 +766,13 @@ class ASTAngleArrayNode : public ASTArrayNode { ASTAngleArrayNode(const ASTIdentifierNode *Id, const std::string &ERM, const ASTToken *TK) : ASTArrayNode(Id, ERM, ASTTypeAngleArray), AV(), AS(0U) { - SetLocation(TK->GetLocation()); + if (TK) + SetLocation(TK->GetLocation()); } + ASTAngleArrayNode(const ASTIdentifierNode *Id, const std::string &ERM) + : ASTArrayNode(Id, ERM, ASTTypeAngleArray), AV(), AS(0U) {} + public: using vector_type = std::vector; using iterator = typename vector_type::iterator; @@ -806,6 +822,13 @@ class ASTAngleArrayNode : public ASTArrayNode { const ASTInitializerList *IL) : ASTArrayNode(Id, ASTTypeAngleArray, Size, IL), AV(), AS(Bits) {} + /// Construct an angle-array literal from already-materialized angle elements. + ASTAngleArrayNode(const ASTIdentifierNode *Id, + const std::vector &Angles) + : ASTArrayNode(Id, ASTTypeAngleArray, + static_cast(Angles.size())), + AV(Angles), AS(ASTAngleNode::AngleBits) {} + virtual ~ASTAngleArrayNode() = default; virtual ASTType GetASTType() const override { return ASTTypeAngleArray; } @@ -888,6 +911,10 @@ class ASTAngleArrayNode : public ASTArrayNode { TK); } + static ASTAngleArrayNode *ExpressionError(const std::string &ERM) { + return new ASTAngleArrayNode(ASTIdentifierNode::AngleArray.Clone(), ERM); + } + static ASTAngleArrayNode *ExpressionError(const ASTIdentifierNode *Id, const std::string &ERM, const ASTToken *TK) { @@ -1665,6 +1692,14 @@ class ASTMPDecimalArrayNode : public ASTArrayNode { } } + /// Construct an mpdecimal-array literal from already-materialized elements. + ASTMPDecimalArrayNode(const ASTIdentifierNode *Id, + const std::vector &Decimals, + unsigned Bits = ASTMPDecimalNode::DefaultBits) + : ASTArrayNode(Id, ASTTypeMPDecimalArray, + static_cast(Decimals.size())), + MPV(Decimals), DB(Bits) {} + virtual ~ASTMPDecimalArrayNode() = default; virtual ASTType GetASTType() const override { return ASTTypeMPDecimalArray; } @@ -1853,6 +1888,14 @@ class ASTMPComplexArrayNode : public ASTArrayNode { } } + /// Construct a complex-array literal from already-materialized elements. + ASTMPComplexArrayNode(const ASTIdentifierNode *Id, + const std::vector &Elements, + unsigned Bits = ASTMPComplexNode::DefaultBits) + : ASTArrayNode(Id, ASTTypeMPComplexArray, + static_cast(Elements.size())), + MPV(Elements), CB(Bits), CTy(ASTTypeMPDecimal), CTB(Bits) {} + ASTMPComplexArrayNode(const ASTIdentifierNode *Id, unsigned Size, unsigned Bits, const ASTFunctionCallNode *FN) : ASTArrayNode(Id, ASTTypeMPComplexArray, Size), MPV(), CB(Bits), diff --git a/include/qasm/AST/ASTBuilder.h b/include/qasm/AST/ASTBuilder.h index a4a4540..b5b367b 100644 --- a/include/qasm/AST/ASTBuilder.h +++ b/include/qasm/AST/ASTBuilder.h @@ -61,6 +61,7 @@ #include #include #include +#include // OpenPulse #include @@ -382,8 +383,22 @@ class ASTBuilder { CreateASTQubitContainerNode(const ASTIdentifierNode *Id, unsigned NumBits, const std::vector &QV); + ASTQumodeContainerNode * + CreateASTQumodeContainerNode(const ASTIdentifierNode *Id, unsigned NumBits); + // unitary u; + ASTUnitaryNode * + CreateASTUnitaryNode(const ASTIdentifierNode *Id); + + //unitary u = {{1,0},{0,1}}; + ASTUnitaryNode * + CreateASTUnitaryNode(const ASTIdentifierNode *Id, + const ASTInitializerList *IL); + ASTQubitNode *CreateASTQubitNode(const ASTIdentifierNode *Id, unsigned Index); + ASTQumodeNode *CreateASTQumodeNode(const ASTIdentifierNode *Id, + unsigned Index); + ASTQubitContainerAliasNode * CreateASTQubitContainerAliasNode(const ASTIdentifierNode *Id, int32_t Index); diff --git a/include/qasm/AST/ASTDynamicTypeCast.inc b/include/qasm/AST/ASTDynamicTypeCast.inc index 0060d89..d25b9a5 100644 --- a/include/qasm/AST/ASTDynamicTypeCast.inc +++ b/include/qasm/AST/ASTDynamicTypeCast.inc @@ -407,7 +407,7 @@ ASTDynamicTypeCast::DynCast(ASTBase* From) { case ASTTypeQubitContainerAlias: return dynamic_cast<__To*>(From); break; - case ASTTypeGateQubitParam: + case ASTTypeGateOperandParam: return dynamic_cast<__To*>(From); break; case ASTTypeRegister: @@ -994,7 +994,7 @@ ASTDynamicTypeCast::DynCast(const ASTBase* From) { case ASTTypeQubitContainerAlias: return dynamic_cast(From); break; - case ASTTypeGateQubitParam: + case ASTTypeGateOperandParam: return dynamic_cast(From); break; case ASTTypeRegister: @@ -1856,7 +1856,7 @@ ASTDynamicTypeCast::DynCast(ASTAnyType& From) { return nullptr; } break; - case ASTTypeGateQubitParam: + case ASTTypeGateOperandParam: try { return std::any_cast<__To*>(From.first); } catch (const std::bad_any_cast& E) { @@ -2865,7 +2865,7 @@ ASTDynamicTypeCast::DynCast(const ASTAnyType& From) { return nullptr; } break; - case ASTTypeGateQubitParam: + case ASTTypeGateOperandParam: try { return std::any_cast(From.first); } catch (const std::bad_any_cast& E) { diff --git a/include/qasm/AST/ASTExpressionValidator.h b/include/qasm/AST/ASTExpressionValidator.h index 83fc8a9..7905811 100644 --- a/include/qasm/AST/ASTExpressionValidator.h +++ b/include/qasm/AST/ASTExpressionValidator.h @@ -205,7 +205,7 @@ class ASTExpressionValidator { bool IsQubitType(ASTType Ty) const { return Ty == ASTTypeQubit || Ty == ASTTypeQubitContainer || - Ty == ASTTypeQubitContainerAlias || Ty == ASTTypeGateQubitParam; + Ty == ASTTypeQubitContainerAlias || Ty == ASTTypeGateOperandParam; } bool IsQuantumArithmeticType(ASTType Ty) const { diff --git a/include/qasm/AST/ASTGPhase.h b/include/qasm/AST/ASTGPhase.h index 4a7dd90..08d80aa 100644 --- a/include/qasm/AST/ASTGPhase.h +++ b/include/qasm/AST/ASTGPhase.h @@ -84,8 +84,18 @@ class ASTGPhaseExpressionNode : public ASTExpressionNode { return ASTExpressionNode::Ident->GetName(); } + // Identifier-form targets store TId in Id with GT = TId->GetSymbolType() + // (Angle, MPDecimal, Float, Identifier, …). BinaryOp / UnaryOp occupy the + // same union and must not be read as Id. virtual const ASTIdentifierNode *GetTargetIdentifier() const { - return GT == ASTTypeIdentifier ? Id : nullptr; + switch (GT) { + case ASTTypeBinaryOp: + case ASTTypeUnaryOp: + case ASTTypeExpressionError: + return nullptr; + default: + return Id; + } } virtual const ASTBinaryOpNode *GetBinaryOp() const { @@ -119,12 +129,6 @@ class ASTGPhaseExpressionNode : public ASTExpressionNode { ASTExpressionNode::print(); switch (GT) { - case ASTTypeIdentifier: - Id->print(); - break; - case ASTTypeAngle: - Id->print(); - break; case ASTTypeBinaryOp: BOP->print(); break; @@ -135,6 +139,8 @@ class ASTGPhaseExpressionNode : public ASTExpressionNode { std::cout << "" << GetError() << "" << std::endl; break; default: + if (Id) + Id->print(); break; } diff --git a/include/qasm/AST/ASTGateContextBuilder.h b/include/qasm/AST/ASTGateContextBuilder.h index 3b4c664..8fbc273 100644 --- a/include/qasm/AST/ASTGateContextBuilder.h +++ b/include/qasm/AST/ASTGateContextBuilder.h @@ -23,11 +23,15 @@ namespace QASM { +class ASTToken; + // Implemented in ASTGates.cpp class ASTGateContextBuilder { private: static ASTGateContextBuilder GCB; static bool GCS; + static unsigned CMDepth; + static const ASTToken *CMTok; protected: ASTGateContextBuilder() = default; @@ -40,6 +44,22 @@ class ASTGateContextBuilder { void CloseContext() { GCS = false; } bool InOpenContext() const { return GCS; } + + void EnterControlModifier(const ASTToken *TK) { + ++CMDepth; + CMTok = TK; + } + + void ExitControlModifier() { + if (CMDepth) + --CMDepth; + if (!CMDepth) + CMTok = nullptr; + } + + bool InControlModifier() const { return CMDepth > 0; } + + const ASTToken *GetControlModifierToken() const { return CMTok; } }; } // namespace QASM diff --git a/include/qasm/AST/ASTGateFockControl.h b/include/qasm/AST/ASTGateFockControl.h new file mode 100644 index 0000000..c270569 --- /dev/null +++ b/include/qasm/AST/ASTGateFockControl.h @@ -0,0 +1,376 @@ +/* -*- coding: utf-8 -*- + * + * Copyright 2022 IBM RESEARCH. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +#ifndef __QASM_AST_GATE_FOCK_CONTROL_H +#define __QASM_AST_GATE_FOCK_CONTROL_H + +#include + +#include +#include + +namespace QASM { + +/// Fock-level control: `ctrl[level] @ target` (int / id / binary / unary). +/// Distinct from qubit n-control +/// (`ctrl` / `ctrl(n)` → ASTGateControlNode::CBits). +class ASTGateFockControlNode : public ASTExpressionNode { +private: + union { + const ASTIntNode *I; + const ASTIdentifierNode *ID; + const ASTBinaryOpNode *BOP; + const ASTUnaryOpNode *UOP; + }; + ASTType LevelType; + + union { + const ASTGateNode *GN; + const ASTGateQOpNode *GQN; + const ASTGPhaseExpressionNode *GPN; + const ASTGateGPhaseExpressionNode *GGEN; + }; + ASTType TType; + +private: + ASTGateFockControlNode() = delete; + +protected: + ASTGateFockControlNode(const ASTIdentifierNode *Id, const std::string &ERM) + : ASTExpressionNode(Id, new ASTStringNode(ERM), ASTTypeExpressionError), + I(nullptr), LevelType(ASTTypeExpressionError), GN(nullptr), + TType(ASTTypeExpressionError) {} + + void InitTargetGate(const ASTGateNode *N) { + GN = N; + TType = ASTTypeGate; + } + void InitTargetQOp(const ASTGateQOpNode *QN) { + GQN = QN; + TType = ASTTypeGateQOpNode; + } + void InitTargetGPhase(const ASTGPhaseExpressionNode *N) { + GPN = N; + TType = ASTTypeGPhaseExpression; + } + void InitTargetGateGPhase(const ASTGateGPhaseExpressionNode *N) { + GGEN = N; + TType = ASTTypeGateGPhaseExpression; + } + +public: + ASTGateFockControlNode(const ASTGateNode *N, const ASTIntNode *Lv) + : ASTExpressionNode(&ASTIdentifierNode::Ctrl, ASTTypeGateFockControl), + I(Lv), LevelType(ASTTypeInt), GN(N), TType(ASTTypeGate) { + assert(N && Lv); + } + ASTGateFockControlNode(const ASTGateNode *N, const ASTIdentifierNode *Lv) + : ASTExpressionNode(&ASTIdentifierNode::Ctrl, ASTTypeGateFockControl), + ID(Lv), LevelType(ASTTypeIdentifier), GN(N), TType(ASTTypeGate) { + assert(N && Lv); + } + ASTGateFockControlNode(const ASTGateNode *N, const ASTBinaryOpNode *Lv) + : ASTExpressionNode(&ASTIdentifierNode::Ctrl, ASTTypeGateFockControl), + BOP(Lv), LevelType(ASTTypeBinaryOp), GN(N), TType(ASTTypeGate) { + assert(N && Lv); + } + ASTGateFockControlNode(const ASTGateNode *N, const ASTUnaryOpNode *Lv) + : ASTExpressionNode(&ASTIdentifierNode::Ctrl, ASTTypeGateFockControl), + UOP(Lv), LevelType(ASTTypeUnaryOp), GN(N), TType(ASTTypeGate) { + assert(N && Lv); + } + + ASTGateFockControlNode(const ASTGateQOpNode *QN, const ASTIntNode *Lv) + : ASTExpressionNode(&ASTIdentifierNode::Ctrl, ASTTypeGateFockControl), + I(Lv), LevelType(ASTTypeInt), GQN(QN), TType(ASTTypeGateQOpNode) { + assert(QN && Lv); + } + ASTGateFockControlNode(const ASTGateQOpNode *QN, const ASTIdentifierNode *Lv) + : ASTExpressionNode(&ASTIdentifierNode::Ctrl, ASTTypeGateFockControl), + ID(Lv), LevelType(ASTTypeIdentifier), GQN(QN), + TType(ASTTypeGateQOpNode) { + assert(QN && Lv); + } + ASTGateFockControlNode(const ASTGateQOpNode *QN, const ASTBinaryOpNode *Lv) + : ASTExpressionNode(&ASTIdentifierNode::Ctrl, ASTTypeGateFockControl), + BOP(Lv), LevelType(ASTTypeBinaryOp), GQN(QN), + TType(ASTTypeGateQOpNode) { + assert(QN && Lv); + } + ASTGateFockControlNode(const ASTGateQOpNode *QN, const ASTUnaryOpNode *Lv) + : ASTExpressionNode(&ASTIdentifierNode::Ctrl, ASTTypeGateFockControl), + UOP(Lv), LevelType(ASTTypeUnaryOp), GQN(QN), TType(ASTTypeGateQOpNode) { + assert(QN && Lv); + } + + ASTGateFockControlNode(const ASTGateGPhaseExpressionNode *N, + const ASTIntNode *Lv) + : ASTExpressionNode(&ASTIdentifierNode::Ctrl, ASTTypeGateFockControl), + I(Lv), LevelType(ASTTypeInt), GGEN(N), + TType(ASTTypeGateGPhaseExpression) { + assert(N && Lv); + } + ASTGateFockControlNode(const ASTGateGPhaseExpressionNode *N, + const ASTIdentifierNode *Lv) + : ASTExpressionNode(&ASTIdentifierNode::Ctrl, ASTTypeGateFockControl), + ID(Lv), LevelType(ASTTypeIdentifier), GGEN(N), + TType(ASTTypeGateGPhaseExpression) { + assert(N && Lv); + } + ASTGateFockControlNode(const ASTGateGPhaseExpressionNode *N, + const ASTBinaryOpNode *Lv) + : ASTExpressionNode(&ASTIdentifierNode::Ctrl, ASTTypeGateFockControl), + BOP(Lv), LevelType(ASTTypeBinaryOp), GGEN(N), + TType(ASTTypeGateGPhaseExpression) { + assert(N && Lv); + } + ASTGateFockControlNode(const ASTGateGPhaseExpressionNode *N, + const ASTUnaryOpNode *Lv) + : ASTExpressionNode(&ASTIdentifierNode::Ctrl, ASTTypeGateFockControl), + UOP(Lv), LevelType(ASTTypeUnaryOp), GGEN(N), + TType(ASTTypeGateGPhaseExpression) { + assert(N && Lv); + } + + virtual ~ASTGateFockControlNode() = default; + + virtual ASTType GetASTType() const override { return ASTTypeGateFockControl; } + + virtual ASTSemaType GetSemaType() const override { + return SemaTypeExpression; + } + + virtual void Mangle() override; + + virtual ASTType GetTargetType() const { return TType; } + virtual ASTType GetLevelType() const { return LevelType; } + + virtual const ASTIntNode *GetLevelInt() const { + return LevelType == ASTTypeInt ? I : nullptr; + } + virtual const ASTIdentifierNode *GetLevelIdentifier() const { + return LevelType == ASTTypeIdentifier ? ID : nullptr; + } + virtual const ASTBinaryOpNode *GetLevelBinaryOp() const { + return LevelType == ASTTypeBinaryOp ? BOP : nullptr; + } + virtual const ASTUnaryOpNode *GetLevelUnaryOp() const { + return LevelType == ASTTypeUnaryOp ? UOP : nullptr; + } + + virtual const ASTGateNode *GetGateNode() const { + return TType == ASTTypeGate ? GN : nullptr; + } + virtual const ASTGateQOpNode *GetGateQOpNode() const { + return TType == ASTTypeGateQOpNode ? GQN : nullptr; + } + virtual const ASTGateGPhaseExpressionNode *GetGateGPhaseNode() const { + return TType == ASTTypeGateGPhaseExpression ? GGEN : nullptr; + } + + virtual bool IsError() const override { + return LevelType == ASTTypeExpressionError || + TType == ASTTypeExpressionError; + } + + virtual const std::string &GetError() const override { + return ASTExpressionNode::GetError(); + } + + static ASTGateFockControlNode *ExpressionError(const std::string &ERM) { + return new ASTGateFockControlNode(ASTIdentifierNode::BadCtrl.Clone(), ERM); + } + + virtual void print() const override; + virtual void push(ASTBase * /* unused */) override {} +}; + +/// Fock-level negative control: `negctrl[level] @ target`. +class ASTGateFockNegControlNode : public ASTExpressionNode { +private: + union { + const ASTIntNode *I; + const ASTIdentifierNode *ID; + const ASTBinaryOpNode *BOP; + const ASTUnaryOpNode *UOP; + }; + ASTType LevelType; + + union { + const ASTGateNode *GN; + const ASTGateQOpNode *GQN; + const ASTGPhaseExpressionNode *GPN; + const ASTGateGPhaseExpressionNode *GGEN; + }; + ASTType TType; + +private: + ASTGateFockNegControlNode() = delete; + +protected: + ASTGateFockNegControlNode(const ASTIdentifierNode *Id, const std::string &ERM) + : ASTExpressionNode(Id, new ASTStringNode(ERM), ASTTypeExpressionError), + I(nullptr), LevelType(ASTTypeExpressionError), GN(nullptr), + TType(ASTTypeExpressionError) {} + +public: + ASTGateFockNegControlNode(const ASTGateNode *N, const ASTIntNode *Lv) + : ASTExpressionNode(&ASTIdentifierNode::NegCtrl, + ASTTypeGateFockNegControl), + I(Lv), LevelType(ASTTypeInt), GN(N), TType(ASTTypeGate) { + assert(N && Lv); + } + ASTGateFockNegControlNode(const ASTGateNode *N, const ASTIdentifierNode *Lv) + : ASTExpressionNode(&ASTIdentifierNode::NegCtrl, + ASTTypeGateFockNegControl), + ID(Lv), LevelType(ASTTypeIdentifier), GN(N), TType(ASTTypeGate) { + assert(N && Lv); + } + ASTGateFockNegControlNode(const ASTGateNode *N, const ASTBinaryOpNode *Lv) + : ASTExpressionNode(&ASTIdentifierNode::NegCtrl, + ASTTypeGateFockNegControl), + BOP(Lv), LevelType(ASTTypeBinaryOp), GN(N), TType(ASTTypeGate) { + assert(N && Lv); + } + ASTGateFockNegControlNode(const ASTGateNode *N, const ASTUnaryOpNode *Lv) + : ASTExpressionNode(&ASTIdentifierNode::NegCtrl, + ASTTypeGateFockNegControl), + UOP(Lv), LevelType(ASTTypeUnaryOp), GN(N), TType(ASTTypeGate) { + assert(N && Lv); + } + + ASTGateFockNegControlNode(const ASTGateQOpNode *QN, const ASTIntNode *Lv) + : ASTExpressionNode(&ASTIdentifierNode::NegCtrl, + ASTTypeGateFockNegControl), + I(Lv), LevelType(ASTTypeInt), GQN(QN), TType(ASTTypeGateQOpNode) { + assert(QN && Lv); + } + ASTGateFockNegControlNode(const ASTGateQOpNode *QN, + const ASTIdentifierNode *Lv) + : ASTExpressionNode(&ASTIdentifierNode::NegCtrl, + ASTTypeGateFockNegControl), + ID(Lv), LevelType(ASTTypeIdentifier), GQN(QN), + TType(ASTTypeGateQOpNode) { + assert(QN && Lv); + } + ASTGateFockNegControlNode(const ASTGateQOpNode *QN, const ASTBinaryOpNode *Lv) + : ASTExpressionNode(&ASTIdentifierNode::NegCtrl, + ASTTypeGateFockNegControl), + BOP(Lv), LevelType(ASTTypeBinaryOp), GQN(QN), + TType(ASTTypeGateQOpNode) { + assert(QN && Lv); + } + ASTGateFockNegControlNode(const ASTGateQOpNode *QN, const ASTUnaryOpNode *Lv) + : ASTExpressionNode(&ASTIdentifierNode::NegCtrl, + ASTTypeGateFockNegControl), + UOP(Lv), LevelType(ASTTypeUnaryOp), GQN(QN), TType(ASTTypeGateQOpNode) { + assert(QN && Lv); + } + + ASTGateFockNegControlNode(const ASTGateGPhaseExpressionNode *N, + const ASTIntNode *Lv) + : ASTExpressionNode(&ASTIdentifierNode::NegCtrl, + ASTTypeGateFockNegControl), + I(Lv), LevelType(ASTTypeInt), GGEN(N), + TType(ASTTypeGateGPhaseExpression) { + assert(N && Lv); + } + ASTGateFockNegControlNode(const ASTGateGPhaseExpressionNode *N, + const ASTIdentifierNode *Lv) + : ASTExpressionNode(&ASTIdentifierNode::NegCtrl, + ASTTypeGateFockNegControl), + ID(Lv), LevelType(ASTTypeIdentifier), GGEN(N), + TType(ASTTypeGateGPhaseExpression) { + assert(N && Lv); + } + ASTGateFockNegControlNode(const ASTGateGPhaseExpressionNode *N, + const ASTBinaryOpNode *Lv) + : ASTExpressionNode(&ASTIdentifierNode::NegCtrl, + ASTTypeGateFockNegControl), + BOP(Lv), LevelType(ASTTypeBinaryOp), GGEN(N), + TType(ASTTypeGateGPhaseExpression) { + assert(N && Lv); + } + ASTGateFockNegControlNode(const ASTGateGPhaseExpressionNode *N, + const ASTUnaryOpNode *Lv) + : ASTExpressionNode(&ASTIdentifierNode::NegCtrl, + ASTTypeGateFockNegControl), + UOP(Lv), LevelType(ASTTypeUnaryOp), GGEN(N), + TType(ASTTypeGateGPhaseExpression) { + assert(N && Lv); + } + + virtual ~ASTGateFockNegControlNode() = default; + + virtual ASTType GetASTType() const override { + return ASTTypeGateFockNegControl; + } + + virtual ASTSemaType GetSemaType() const override { + return SemaTypeExpression; + } + + virtual void Mangle() override; + + virtual ASTType GetTargetType() const { return TType; } + virtual ASTType GetLevelType() const { return LevelType; } + + virtual const ASTIntNode *GetLevelInt() const { + return LevelType == ASTTypeInt ? I : nullptr; + } + virtual const ASTIdentifierNode *GetLevelIdentifier() const { + return LevelType == ASTTypeIdentifier ? ID : nullptr; + } + virtual const ASTBinaryOpNode *GetLevelBinaryOp() const { + return LevelType == ASTTypeBinaryOp ? BOP : nullptr; + } + virtual const ASTUnaryOpNode *GetLevelUnaryOp() const { + return LevelType == ASTTypeUnaryOp ? UOP : nullptr; + } + + virtual const ASTGateNode *GetGateNode() const { + return TType == ASTTypeGate ? GN : nullptr; + } + virtual const ASTGateQOpNode *GetGateQOpNode() const { + return TType == ASTTypeGateQOpNode ? GQN : nullptr; + } + virtual const ASTGateGPhaseExpressionNode *GetGateGPhaseNode() const { + return TType == ASTTypeGateGPhaseExpression ? GGEN : nullptr; + } + + virtual bool IsError() const override { + return LevelType == ASTTypeExpressionError || + TType == ASTTypeExpressionError; + } + + virtual const std::string &GetError() const override { + return ASTExpressionNode::GetError(); + } + + static ASTGateFockNegControlNode *ExpressionError(const std::string &ERM) { + return new ASTGateFockNegControlNode(ASTIdentifierNode::BadCtrl.Clone(), + ERM); + } + + virtual void print() const override; + virtual void push(ASTBase * /* unused */) override {} +}; + +} // namespace QASM + +#endif // __QASM_AST_GATE_FOCK_CONTROL_H diff --git a/include/qasm/AST/ASTGateFor.h b/include/qasm/AST/ASTGateFor.h new file mode 100644 index 0000000..bf83f60 --- /dev/null +++ b/include/qasm/AST/ASTGateFor.h @@ -0,0 +1,66 @@ +/* -*- coding: utf-8 -*- + * + * Copyright 2023 IBM RESEARCH. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +#ifndef __QASM_AST_GATE_FOR_H +#define __QASM_AST_GATE_FOR_H + +#include +#include + +#include +#include + +namespace QASM { + +/// Gate-body `for` wrapped as a listable quantum op (`ASTGateQOpList`). +class ASTGateForOpNode : public ASTGateQOpNode { +private: + const ASTForStatementNode *ForStmt; + +private: + ASTGateForOpNode() = delete; + +public: + ASTGateForOpNode(const ASTIdentifierNode *Id, const ASTForStatementNode *FS) + : ASTGateQOpNode(Id), ForStmt(FS) { + assert(FS && "Invalid ASTForStatementNode argument!"); + } + + virtual ~ASTGateForOpNode() = default; + + virtual ASTType GetASTType() const override { return ASTTypeGateFor; } + + virtual const ASTForStatementNode *GetForStatement() const { return ForStmt; } + + virtual void Mangle() override { + // Induction / body already mangled when the ForStatement was built. + } + + virtual void print() const override { + std::cout << "" << std::endl; + if (ForStmt) + ForStmt->print(); + std::cout << "" << std::endl; + } + + virtual void push(ASTBase * /* unused */) override {} +}; + +} // namespace QASM + +#endif // __QASM_AST_GATE_FOR_H diff --git a/include/qasm/AST/ASTGateOpBuilder.h b/include/qasm/AST/ASTGateOpBuilder.h index c23334b..17559f8 100644 --- a/include/qasm/AST/ASTGateOpBuilder.h +++ b/include/qasm/AST/ASTGateOpBuilder.h @@ -23,6 +23,8 @@ #include #include +#include + namespace QASM { class ASTHGateOpNode; @@ -39,6 +41,7 @@ class ASTGateOpBuilder { private: static ASTGateQOpList *GLP; static ASTGateOpBuilder B; + static std::vector GLV; protected: ASTGateOpBuilder() {} @@ -62,6 +65,20 @@ class ASTGateOpBuilder { static ASTGateQOpList *NewList() { return GLP = new ASTGateQOpList(); } + /// Nest a gate-op list (e.g. `for` body). Outer list restored by PopList. + static void PushList() { + GLV.push_back(GLP); + GLP = nullptr; + } + + static ASTGateQOpList *PopList() { + ASTGateQOpList *Inner = GLP; + assert(!GLV.empty() && "GateOpBuilder PopList without PushList!"); + GLP = GLV.back(); + GLV.pop_back(); + return Inner; + } + static ASTGateQOpNode *CreateASTQGateOpNode(const ASTIdentifierNode *Id, const ASTGateNode *GateNode); @@ -97,6 +114,10 @@ class ASTGateOpBuilder { GLP->push(Node); } + // Remove Node from the active list when a ctrl/negctrl/inv/pow wraps a + // GateEOp that CreateAST*GateOpNode already appended as a bare sibling. + bool PopIfBack(ASTGateQOpNode *Node) { return GLP && GLP->PopIfBack(Node); } + void Clear() { GLP->Clear(); } std::size_t Size() { return GLP->Size(); } diff --git a/include/qasm/AST/ASTGateOpList.h b/include/qasm/AST/ASTGateOpList.h index 580a30a..0feaf02 100644 --- a/include/qasm/AST/ASTGateOpList.h +++ b/include/qasm/AST/ASTGateOpList.h @@ -73,6 +73,15 @@ class ASTGateQOpList : public ASTBase { List.push_back(QN); } + // Drop the last op if it is Node (used when a modifier wraps a GateEOp + // that CreateAST*GateOpNode already appended). + virtual bool PopIfBack(ASTGateQOpNode *Node) { + if (!Node || List.empty() || List.back() != Node) + return false; + List.pop_back(); + return true; + } + // Implemented in ASTGates.cpp. virtual bool TransferToSymbolTable( std::map &MM) const; diff --git a/include/qasm/AST/ASTGateQubitParamBuilder.h b/include/qasm/AST/ASTGateOperandParamBuilder.h similarity index 80% rename from include/qasm/AST/ASTGateQubitParamBuilder.h rename to include/qasm/AST/ASTGateOperandParamBuilder.h index 9d26c42..d708db1 100644 --- a/include/qasm/AST/ASTGateQubitParamBuilder.h +++ b/include/qasm/AST/ASTGateOperandParamBuilder.h @@ -16,22 +16,22 @@ * ============================================================================= */ -#ifndef __QASM_AST_GATE_QUBIT_PARAM_BUILDER_H -#define __QASM_AST_GATE_QUBIT_PARAM_BUILDER_H +#ifndef __QASM_AST_GATE_OPERAND_PARAM_BUILDER_H +#define __QASM_AST_GATE_OPERAND_PARAM_BUILDER_H #include namespace QASM { -class ASTGateQubitParamBuilder { +class ASTGateOperandParamBuilder { private: static ASTIdentifierList IL; - static ASTGateQubitParamBuilder GQB; + static ASTGateOperandParamBuilder GQB; static ASTIdentifierList *ILP; static std::vector ILV; protected: - ASTGateQubitParamBuilder() {} + ASTGateOperandParamBuilder() {} public: using list_type = std::vector; @@ -39,13 +39,13 @@ class ASTGateQubitParamBuilder { using const_iterator = typename list_type::const_iterator; public: - static ASTGateQubitParamBuilder &Instance() { - return ASTGateQubitParamBuilder::GQB; + static ASTGateOperandParamBuilder &Instance() { + return ASTGateOperandParamBuilder::GQB; } - virtual ~ASTGateQubitParamBuilder() = default; + virtual ~ASTGateOperandParamBuilder() = default; - ASTIdentifierList *List() { return ASTGateQubitParamBuilder::ILP; } + ASTIdentifierList *List() { return ASTGateOperandParamBuilder::ILP; } static ASTIdentifierList *NewList() { ASTIdentifierList *IIL = new ASTIdentifierList(); @@ -86,4 +86,4 @@ class ASTGateQubitParamBuilder { } // namespace QASM -#endif // __QASM_AST_GATE_QUBIT_PARAM_BUILDER_H +#endif // __QASM_AST_GATE_OPERAND_PARAM_BUILDER_H diff --git a/include/qasm/AST/ASTGateQubitTracker.h b/include/qasm/AST/ASTGateQubitTracker.h index 7cfdc9c..036b44f 100644 --- a/include/qasm/AST/ASTGateQubitTracker.h +++ b/include/qasm/AST/ASTGateQubitTracker.h @@ -69,7 +69,7 @@ class ASTGateQubitTracker { char S = Id->GetName()[0]; if (Id->IsGateLocal() && S != '$' && - Id->GetSymbolType() == ASTTypeGateQubitParam) + Id->GetSymbolType() == ASTTypeGateOperandParam) QIS.erase(Id); } @@ -90,7 +90,7 @@ class ASTGateQubitTracker { case ASTTypeQubitContainer: case ASTTypeQubitContainerAlias: break; - case ASTTypeGateQubitParam: + case ASTTypeGateOperandParam: ASTIdentifierBuilder::List()->Erase( const_cast((*I))); break; @@ -112,8 +112,8 @@ class ASTGateQubitTracker { case ASTTypeQubitContainer: case ASTTypeQubitContainerAlias: break; - case ASTTypeGateQubitParam: - ASTSymbolTable::Instance().EraseGateQubitParam( + case ASTTypeGateOperandParam: + ASTSymbolTable::Instance().EraseGateOperandParam( IdR->GetName(), IdR->GetBits(), STE->GetValueType()); ASTSymbolTable::Instance().EraseGateLocalQubit((*I)->GetName()); break; diff --git a/include/qasm/AST/ASTGateTemplateParamBuilder.h b/include/qasm/AST/ASTGateTemplateParamBuilder.h new file mode 100644 index 0000000..2f2d70b --- /dev/null +++ b/include/qasm/AST/ASTGateTemplateParamBuilder.h @@ -0,0 +1,94 @@ +/* -*- coding: utf-8 -*- + * + * Copyright 2022 IBM RESEARCH. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +#ifndef __QASM_AST_GATE_TEMPLATE_PARAM_BUILDER_H +#define __QASM_AST_GATE_TEMPLATE_PARAM_BUILDER_H + +#include + +#include +#include +#include + +namespace QASM { + +/// One gate template formal (`uint N` in `gate foo[uint N](…)`). +/// On declarations Bound is unset (NaN analogue for ints — do not mutate body +/// identifiers named Name). On calls Bound holds the explicit or inferred +/// value. +struct ASTGateTemplateParam { + ASTType Ty; + std::string Name; + std::optional Bound; + + ASTGateTemplateParam() : Ty(ASTTypeInt), Name(), Bound() {} + + ASTGateTemplateParam(ASTType T, std::string N) + : Ty(T), Name(std::move(N)), Bound() {} + + ASTGateTemplateParam(ASTType T, std::string N, unsigned V) + : Ty(T), Name(std::move(N)), Bound(V) {} + + bool HasBound() const { return Bound.has_value(); } +}; + +/// Pending gate template parameters while parsing a gate declaration +/// (`gate foo[uint N](...)`). Cleared at the start of each +/// OptGateTemplateParams. +class ASTGateTemplateParamBuilder { +private: + static ASTGateTemplateParamBuilder TPB; + std::vector Params; + +protected: + ASTGateTemplateParamBuilder() = default; + +public: + static ASTGateTemplateParamBuilder &Instance() { return TPB; } + + void Clear() { Params.clear(); } + + void Add(ASTType Ty, const std::string &Name) { + Params.emplace_back(Ty, Name); + } + + bool Empty() const { return Params.empty(); } + + std::size_t Size() const { return Params.size(); } + + bool IsTemplateParam(const std::string &Name) const { + for (std::size_t I = 0; I < Params.size(); ++I) + if (Params[I].Name == Name) + return true; + return false; + } + + /// Index into Params, or ~0U if Name is not a template param. + unsigned IndexOf(const std::string &Name) const { + for (std::size_t I = 0; I < Params.size(); ++I) + if (Params[I].Name == Name) + return static_cast(I); + return static_cast(~0U); + } + + const std::vector &GetParams() const { return Params; } +}; + +} // namespace QASM + +#endif // __QASM_AST_GATE_TEMPLATE_PARAM_BUILDER_H diff --git a/include/qasm/AST/ASTGateType.h b/include/qasm/AST/ASTGateType.h new file mode 100644 index 0000000..9701e13 --- /dev/null +++ b/include/qasm/AST/ASTGateType.h @@ -0,0 +1,82 @@ +/* -*- coding: utf-8 -*- + * + * Copyright 2023 IBM RESEARCH. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +#ifndef __QASM_AST_GATE_TYPE_H +#define __QASM_AST_GATE_TYPE_H + +#include +#include + +#include +#include + +namespace QASM { + +/// Thin classification of classical gate formals / call args for fully-typed +/// gates. FormalParamTypes remains the oracle; this only packages ASTType plus +/// an optional array length for compatibility checks. +class ASTGateType { +private: + ASTType Ty; + /// Array length when known; empty means not an array or size unknown. + std::optional ArraySize; + + ASTGateType(ASTType T, std::optional SZ) : Ty(T), ArraySize(SZ) {} + +public: + ASTGateType() : Ty(ASTTypeUndefined), ArraySize() {} + + ASTType GetType() const { return Ty; } + + bool HasArraySize() const { return ArraySize.has_value(); } + + unsigned GetArraySize() const { return ArraySize.value_or(0U); } + + bool IsRealArrayFamily() const; + bool IsComplexArray() const; + bool IsArray() const; + bool IsComplexScalar() const; + bool IsRealScalarFamily() const; + + static ASTGateType + ClassifyFormal(ASTType Ty, std::optional Size = std::nullopt); + + static ASTGateType ClassifyArg(const ASTArgumentNode *Arg); + + /// Named array argument with a declared type but no initializer list. + static bool ArgIsUninitializedArray(const ASTArgumentNode *Arg); + + /// Identifier for a named call argument, or nullptr. + static const class ASTIdentifierNode * + ArgIdentifier(const ASTArgumentNode *Arg); + + /// True when call arg A may bind to formal F. + /// Real↔angle array family; real→complex scalar and real-array→complex-array + /// promotion; reject complex→real (scalar or array). + static bool Compatible(const ASTGateType &F, const ASTGateType &A); + + /// True if any element of a literal AngleArray arg has a complex expression. + static bool ArgHasComplexElements(const ASTArgumentNode *Arg); + + /// True if any element of a gate array literal list is complex-typed. + static bool ExpressionListHasComplex(const class ASTExpressionList *EL); +}; + +} // namespace QASM + +#endif // __QASM_AST_GATE_TYPE_H diff --git a/include/qasm/AST/ASTGates.h b/include/qasm/AST/ASTGates.h index 0247174..5891c2b 100644 --- a/include/qasm/AST/ASTGates.h +++ b/include/qasm/AST/ASTGates.h @@ -22,8 +22,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -32,6 +34,7 @@ #include #include +#include #include #include @@ -39,6 +42,15 @@ namespace QASM { class ASTSymbolTableEntry; +/// One gate parameter (classical) in source/declaration order. +struct ASTGateParam { + ASTType Ty; + ASTExpressionNode *Expr; + + ASTGateParam() : Ty(ASTTypeUndefined), Expr(nullptr) {} + ASTGateParam(ASTType T, ASTExpressionNode *E) : Ty(T), Expr(E) {} +}; + class ASTGateNode : public ASTExpressionNode { friend class ASTGateControlNode; friend class ASTGateNegControlNode; @@ -46,10 +58,12 @@ class ASTGateNode : public ASTExpressionNode { friend class ASTGatePowerNode; protected: - std::vector Params; - std::vector Qubits; - std::vector QCParams; - std::map QCParamIds; + /// Parameters in source order (angles, complex, arrays, …). + /// Quantum operands live in Operands / OperandParams. + std::vector Params; + std::vector Operands; + std::vector OperandParams; + std::map OperandParamIds; ASTGateQOpList OpList; union { mutable const ASTGateControlNode *Ctrl; @@ -64,6 +78,20 @@ class ASTGateNode : public ASTExpressionNode { mutable ASTType ControlType; bool Opaque; bool GateCall; + /// True for ProductionRule_10030 fully-typed gate declarations. + bool FullyTyped; + /// Declared classical formal types in order (fully-typed gates only). + std::vector FormalParamTypes; + /// Parallel to FormalParamTypes: array length when known, else 0. + std::vector FormalParamArraySizes; + /// Declared quantum formal kinds (Qubit/Qumode) in order. + std::vector FormalQuantumTypes; + /// Gate template parameters (`uint N`, …) from `gate foo[…](…)`. + /// Decl: Bound unset (NaN analogue). Call: Bound set; body `N` left alone. + std::vector TemplateParams; + /// Parallel to FormalParamTypes: template index when array size is symbolic, + /// else ~0U. + std::vector FormalParamArraySizeTemplateIndices; private: ASTGateNode() = delete; @@ -71,23 +99,73 @@ class ASTGateNode : public ASTExpressionNode { private: void ToGateParamSymbolTable(const ASTIdentifierNode *Id, const ASTSymbolTableEntry *STE); - ASTSymbolTableEntry *MangleGateQubitParam(ASTIdentifierNode *Id, - ASTSymbolTableEntry *&STE, - unsigned IX, unsigned Bits = 0U, - unsigned QBits = 0U); + ASTSymbolTableEntry *MangleGateOperandParam(ASTIdentifierNode *Id, + ASTSymbolTableEntry *&STE, + unsigned IX, unsigned Bits = 0U, + unsigned QBits = 0U); - void MaterializeGateQubitParam(ASTIdentifierNode *Id); + void MaterializeGateOperandParam(ASTIdentifierNode *Id); void MaterializeBuiltinUGate(const ASTIdentifierNode *GId, const ASTParameterList &PL, const ASTIdentifierList &IL); + /// Resolve qubit vs qumode for Operands[Index] from FormalQuantumTypes, + /// then the formal's polymorphic/symbol type. Defaults to qubit. + ASTType ResolveOperandQuantumType(const ASTIdentifierNode *QId, + unsigned Index) const; + ASTAngleNode *CreateAngleConversion(const ASTSymbolTableEntry *XSTE) const; ASTAngleNode *CreateAngleTemporary(const ASTSymbolTableEntry *XSTE) const; ASTAngleNode *CreateAngleSymbolTableEntry(ASTSymbolTableEntry *XSTE) const; + /// Build an MPComplex Param that retains BinaryOp/UnaryOp as Expr + /// (no Evaluate — symbolic ops are not real/imag literals). + ASTMPComplexNode *MaterializeComplexParamExpr(unsigned Index, + const ASTExpressionNode *EN); + + /// True when call formal Index is complex (FormalParamTypes or builtin disp). + bool FormalWantsComplex(unsigned Index) const; + + /// True when call formal Index is float/double/mpdecimal scalar. + bool FormalWantsFloatScalar(unsigned Index) const; + + /// True when call formal Index is float/mpdecimal array. + bool FormalWantsFloatArray(unsigned Index) const; + + /// Store a real scalar as complex real+0i for a complex formal. + ASTMPComplexNode *MaterializeComplexFromReal(unsigned Index, + const ASTMPDecimalNode *R); + + /// Convert a ProductionRule_10010 AngleArray literal to MPDecimalArray + /// when the formal wants a float/mpdecimal array. + ASTMPDecimalArrayNode * + MaterializeMPDecimalArrayFromAngles(unsigned Index, + const ASTAngleArrayNode *AAN); + + template + NodeTy *GetParamOfType(ASTType Ty, unsigned Index) const { + unsigned Seen = 0; + for (std::size_t I = 0; I < Params.size(); ++I) { + if (Params[I].Ty != Ty) + continue; + if (Seen == Index) + return dynamic_cast(Params[I].Expr); + ++Seen; + } + return nullptr; + } + + unsigned CountParamType(ASTType Ty) const { + unsigned N = 0; + for (std::size_t I = 0; I < Params.size(); ++I) + if (Params[I].Ty == Ty) + ++N; + return N; + } + protected: ASTIdentifierNode *GateCallIdentifier(const std::string &Name, ASTType Type, unsigned Bits) const; @@ -102,14 +180,18 @@ class ASTGateNode : public ASTExpressionNode { public: ASTGateNode(const ASTIdentifierNode *Id) - : ASTExpressionNode(Id, ASTTypeGate), Params(), Qubits(), QCParams(), - OpList(), Ctrl(nullptr), GDId(Id), GSTM(), - ControlType(ASTTypeUndefined), Opaque(false), GateCall(false) {} + : ASTExpressionNode(Id, ASTTypeGate), Params(), Operands(), + OperandParams(), OpList(), Ctrl(nullptr), GDId(Id), GSTM(), + ControlType(ASTTypeUndefined), Opaque(false), GateCall(false), + FullyTyped(false), FormalParamTypes(), FormalParamArraySizes(), + FormalQuantumTypes(), TemplateParams(), + FormalParamArraySizeTemplateIndices() {} // Implemented in ASTGates.cpp ASTGateNode(const ASTIdentifierNode *Id, const ASTArgumentNodeList &AL, const ASTAnyTypeList &QL, bool IsGateCall = false, - const ASTGateQOpList &OL = ASTGateQOpList::EmptyDefault); + const ASTGateQOpList &OL = ASTGateQOpList::EmptyDefault, + const std::vector *CallFormalParamTypes = nullptr); // Implemented in ASTGates.cpp ASTGateNode(const ASTIdentifierNode *Id, const ASTParameterList &PL, @@ -130,20 +212,84 @@ class ASTGateNode : public ASTExpressionNode { virtual bool IsCall() const { return GateCall; } - virtual unsigned GetNumQubits() const { - return static_cast(Qubits.size()); + virtual unsigned GetNumOperands() const { + return static_cast(Operands.size()); } virtual unsigned GetNumParams() const { return static_cast(Params.size()); } - virtual unsigned GetNumQCParams() const { - return static_cast(QCParams.size()); + virtual const std::vector &GetParams() const { return Params; } + + virtual std::vector &GetParams() { return Params; } + + virtual void AddParam(ASTType Ty, ASTExpressionNode *E) { + assert(E && "Invalid gate parameter!"); + Params.emplace_back(Ty, E); + } + + virtual unsigned GetNumArrayParams() const { + return CountParamType(ASTTypeAngleArray); + } + + virtual const ASTAngleArrayNode *GetArrayParam(unsigned Index) const { + const ASTAngleArrayNode *A = + GetParamOfType(ASTTypeAngleArray, Index); + assert(A && "Index is out-of-range!"); + return A; } - virtual unsigned GetNumQCParamIds() const { - return static_cast(QCParamIds.size()); + virtual ASTAngleArrayNode *GetArrayParam(unsigned Index) { + ASTAngleArrayNode *A = + GetParamOfType(ASTTypeAngleArray, Index); + assert(A && "Index is out-of-range!"); + return A; + } + + virtual unsigned GetNumComplexArrayParams() const { + return CountParamType(ASTTypeMPComplexArray); + } + + virtual const ASTMPComplexArrayNode * + GetComplexArrayParam(unsigned Index) const { + const ASTMPComplexArrayNode *A = + GetParamOfType(ASTTypeMPComplexArray, Index); + assert(A && "Index is out-of-range!"); + return A; + } + + virtual ASTMPComplexArrayNode *GetComplexArrayParam(unsigned Index) { + ASTMPComplexArrayNode *A = + GetParamOfType(ASTTypeMPComplexArray, Index); + assert(A && "Index is out-of-range!"); + return A; + } + + virtual unsigned GetNumComplexParams() const { + return CountParamType(ASTTypeMPComplex); + } + + virtual const ASTMPComplexNode *GetComplexParam(unsigned Index) const { + const ASTMPComplexNode *C = + GetParamOfType(ASTTypeMPComplex, Index); + assert(C && "Index is out-of-range!"); + return C; + } + + virtual ASTMPComplexNode *GetComplexParam(unsigned Index) { + ASTMPComplexNode *C = + GetParamOfType(ASTTypeMPComplex, Index); + assert(C && "Index is out-of-range!"); + return C; + } + + virtual unsigned GetNumOperandParams() const { + return static_cast(OperandParams.size()); + } + + virtual unsigned GetNumOperandParamIds() const { + return static_cast(OperandParamIds.size()); } virtual unsigned GetNumGateOps() const { @@ -171,7 +317,7 @@ class ASTGateNode : public ASTExpressionNode { return I == GSTM.end() ? nullptr : (*I).second; } - virtual void ClearGateQubits() const; + virtual void ClearGateOperands() const; static GateKind DetermineGateKind(const std::string &GN); @@ -221,6 +367,62 @@ class ASTGateNode : public ASTExpressionNode { virtual void SetOpaque(bool O = true) { Opaque = O; } + virtual void SetFullyTyped(bool FT = true) { FullyTyped = FT; } + + virtual bool IsFullyTyped() const { return FullyTyped; } + + virtual void SetFormalParamTypes(const std::vector &Tys) { + FormalParamTypes = Tys; + } + + virtual const std::vector &GetFormalParamTypes() const { + return FormalParamTypes; + } + + virtual void SetFormalParamArraySizes(const std::vector &SZs) { + FormalParamArraySizes = SZs; + } + + virtual const std::vector &GetFormalParamArraySizes() const { + return FormalParamArraySizes; + } + + virtual void SetFormalQuantumTypes(const std::vector &Tys) { + FormalQuantumTypes = Tys; + } + + virtual const std::vector &GetFormalQuantumTypes() const { + return FormalQuantumTypes; + } + + virtual void SetTemplateParams(const std::vector &TPs) { + TemplateParams = TPs; + } + + virtual const std::vector &GetTemplateParams() const { + return TemplateParams; + } + + /// Attach call-site bindings without mutating body identifiers named `N`. + /// Parallel to replacing Params with call args while leaving GateQOpList + /// formals as placeholders (angles use NaN; template formals stay unbound). + virtual void + SetTemplateParamBounds(const std::vector> &Bounds) { + for (std::size_t I = 0; I < TemplateParams.size() && I < Bounds.size(); ++I) + if (Bounds[I]) + TemplateParams[I].Bound = *Bounds[I]; + } + + virtual void + SetFormalParamArraySizeTemplateIndices(const std::vector &Idxs) { + FormalParamArraySizeTemplateIndices = Idxs; + } + + virtual const std::vector & + GetFormalParamArraySizeTemplateIndices() const { + return FormalParamArraySizeTemplateIndices; + } + virtual bool HasControl() const { return ControlType == ASTTypeGateControl && Ctrl != nullptr; } @@ -257,14 +459,14 @@ class ASTGateNode : public ASTExpressionNode { virtual ASTType GetControlType() const { return ControlType; } - virtual void AddQubit(ASTQubitNode *QN) { + virtual void AddOperand(ASTQubitNode *QN) { assert(QN && "Invalid Qubit argument!"); - Qubits.push_back(QN); + Operands.push_back(QN); } virtual void AddParam(ASTAngleNode *A) { assert(A && "Invalid Angle argument!"); - Params.push_back(A); + AddParam(ASTTypeAngle, A); } virtual void AddOpList(const ASTGateQOpList &OL) { OpList = OL; } @@ -273,27 +475,31 @@ class ASTGateNode : public ASTExpressionNode { virtual bool HasOpList() const { return !OpList.Empty(); } - iterator qubits_begin() { return Qubits.begin(); } + iterator operands_begin() { return Operands.begin(); } - const_iterator qubits_begin() const { return Qubits.begin(); } + const_iterator operands_begin() const { return Operands.begin(); } - iterator qubits_end() { return Qubits.end(); } + iterator operands_end() { return Operands.end(); } - const_iterator qubits_end() const { return Qubits.end(); } + const_iterator operands_end() const { return Operands.end(); } - virtual std::size_t ParamsSize() const { return Params.size(); } + virtual std::size_t ParamsSize() const { + return CountParamType(ASTTypeAngle); + } - virtual std::size_t QubitsSize() const { return Qubits.size(); } + virtual std::size_t OperandsSize() const { return Operands.size(); } - virtual const ASTQubitNode *qubits_front() const { return Qubits.front(); } + virtual const ASTQubitNode *operands_front() const { + return Operands.front(); + } - virtual const ASTQubitNode *qubits_back() const { return Qubits.back(); } + virtual const ASTQubitNode *operands_back() const { return Operands.back(); } - virtual const ASTQubitNode *GetQubit(const ASTIdentifierNode *Id) const { + virtual const ASTQubitNode *GetOperand(const ASTIdentifierNode *Id) const { assert(Id && "Invalid Qubit Identifier!"); - for (std::vector::const_iterator I = Qubits.begin(); - I != Qubits.end(); ++I) { + for (std::vector::const_iterator I = Operands.begin(); + I != Operands.end(); ++I) { if (*(*I)->GetIdentifier() == *Id) return *I; } @@ -304,43 +510,47 @@ class ASTGateNode : public ASTExpressionNode { virtual const ASTAngleNode *GetAngle(const ASTIdentifierNode *Id) const { assert(Id && "Invalid Param Identifier!"); - for (std::vector::const_iterator I = Params.begin(); - I != Params.end(); ++I) { - if (*(*I)->GetIdentifier() == *Id) - return *I; + for (std::size_t I = 0; I < Params.size(); ++I) { + if (Params[I].Ty != ASTTypeAngle) + continue; + ASTAngleNode *AN = dynamic_cast(Params[I].Expr); + if (AN && *(*AN).GetIdentifier() == *Id) + return AN; } return nullptr; } - virtual const ASTQubitNode *GetQubit(unsigned Index) const { - assert(Index < Qubits.size() && "Index is out-of-range!"); - return Qubits[Index]; + virtual const ASTQubitNode *GetOperand(unsigned Index) const { + assert(Index < Operands.size() && "Index is out-of-range!"); + return Operands[Index]; } virtual const ASTAngleNode *GetParam(unsigned Index) const { - assert(Index < Params.size() && "Index is out-of-range!"); - return Params[Index]; + const ASTAngleNode *A = GetParamOfType(ASTTypeAngle, Index); + assert(A && "Index is out-of-range!"); + return A; } - virtual const std::vector &GetQCParams() const { - return QCParams; + virtual const std::vector & + GetOperandParams() const { + return OperandParams; } virtual const std::map & - GetQCParamIds() const { - return QCParamIds; + GetOperandParamIds() const { + return OperandParamIds; } - virtual bool HasInductionVariableQubits() const { - return !QCParamIds.empty(); + virtual bool HasInductionVariableOperands() const { + return !OperandParamIds.empty(); } // Implemented in ASTGates.cpp. virtual void print() const override; virtual void push(ASTBase *Node) override { - AddQubit(dynamic_cast(Node)); + AddOperand(dynamic_cast(Node)); } }; @@ -539,6 +749,40 @@ class ASTUGateNode : public ASTGateNode { } }; +class ASTDispGateNode : public ASTGateNode { +private: + ASTDispGateNode() = delete; + +public: + ASTDispGateNode(const ASTIdentifierNode *Id, const ASTArgumentNodeList &AL, + const ASTAnyTypeList &TL, bool IsGateCall = false, + const ASTGateQOpList &OL = ASTGateQOpList::EmptyDefault) + : ASTGateNode(Id, AL, TL, IsGateCall, OL) {} + + ASTDispGateNode(const ASTIdentifierNode *Id, const ASTParameterList &PL, + const ASTIdentifierList &IL, bool IsGateCall = false, + const ASTGateQOpList &OL = ASTGateQOpList::EmptyDefault) + : ASTGateNode(Id, PL, IL, IsGateCall, OL) {} + + virtual ~ASTDispGateNode() = default; + + virtual ASTType GetASTType() const override { return ASTTypeDispGate; } + + virtual ASTSemaType GetSemaType() const override { + return SemaTypeExpression; + } + + virtual ASTDispGateNode *CloneCall(const ASTIdentifierNode *Id, + const ASTArgumentNodeList &AL, + const ASTAnyTypeList &QL) override; + + virtual void print() const override { + std::cout << "" << std::endl; + ASTGateNode::print(); + std::cout << "" << std::endl; + } +}; + class ASTGateDeclarationNode : public ASTStatementNode { private: ASTGateDeclarationNode() = delete; diff --git a/include/qasm/AST/ASTIdentifier.h b/include/qasm/AST/ASTIdentifier.h index ec4ed4b..32e83a8 100644 --- a/include/qasm/AST/ASTIdentifier.h +++ b/include/qasm/AST/ASTIdentifier.h @@ -637,7 +637,7 @@ class ASTIdentifierNode : public ASTExpression { static ASTIdentifierNode BoxAs; static ASTIdentifierNode BoxTo; static ASTIdentifierNode Qubit; - static ASTIdentifierNode QubitParam; + static ASTIdentifierNode OperandParam; static ASTIdentifierNode QCAlias; static ASTIdentifierNode QC; static ASTIdentifierNode Bitset; @@ -734,9 +734,12 @@ class ASTIdentifierRefNode : public ASTIdentifierNode { void SetIndex(const std::string &IdS) { std::string::size_type SP = IdS.find_last_of('['); std::string::size_type EP = IdS.find_last_of(']'); - if (SP != std::string::npos && EP != std::string::npos) - Index = - static_cast(std::stoul(IdS.substr(SP + 1, EP - (SP + 1)))); + if (SP != std::string::npos && EP != std::string::npos) { + std::string IX = IdS.substr(SP + 1, EP - (SP + 1)); + // Induction / symbolic indices are not numeric; leave Index as ~0. + if (!IX.empty() && isdigit(IX.c_str()[0])) + Index = static_cast(std::stoul(IX)); + } } ASTType ResolveReferenceType(ASTType ITy) const; @@ -1006,7 +1009,7 @@ class ASTTimedIdentifierNode : public ASTIdentifierNode { class ASTIdentifierList : public ASTBase { friend class ASTIdentifierBuilder; - friend class ASTGateQubitParamBuilder; + friend class ASTGateOperandParamBuilder; protected: std::vector Graph; diff --git a/include/qasm/AST/ASTIdentifierTypeController.h b/include/qasm/AST/ASTIdentifierTypeController.h index 4a96dfa..54c2b3f 100644 --- a/include/qasm/AST/ASTIdentifierTypeController.h +++ b/include/qasm/AST/ASTIdentifierTypeController.h @@ -66,6 +66,9 @@ class ASTIdentifierTypeController { case ASTTypeQubit: return LB == 0 && RB == 0 ? CT : CT = ASTTypeQubitContainer; break; + case ASTTypeQumode: + return LB == 0 && RB == 0 ? CT : CT = ASTTypeQumodeContainer; + break; case ASTTypeQubitArray: return LB == 1 && RB == 1 ? CT : CT = ASTTypeQubitArray; break; @@ -166,6 +169,9 @@ class ASTIdentifierTypeController { case ASTTypeQubit: CT = ASTTypeQubitContainer; break; + case ASTTypeQumode: + CT = ASTTypeQumodeContainer; + break; case ASTTypeAngle: CT = ASTTypeAngle; break; @@ -210,6 +216,15 @@ class ASTIdentifierTypeController { return; } + // for/while must always take effect. Otherwise a leftover PreviousType of + // Array / *Array (e.g. after `array[float[64], N] thetas`) rewrites CT + // back to that array type and induction vars are typed as arrays. + if (Ty == ASTTypeForStatement || Ty == ASTTypeWhileStatement) { + PT = CT = Ty; + IA = false; + return; + } + switch (CT) { case ASTTypeMPInteger: case ASTTypeMPDecimal: @@ -427,9 +442,9 @@ class ASTIdentifierTypeController { void CheckIdentifierType(const ASTIdentifierNode *Id, ASTType Ty0, ASTType Ty1, ASTType Ty2, ASTType Ty3) const; - void CheckGateQubitParamType(const ASTIdentifierNode *Id) const; + void CheckGateOperandParamType(const ASTIdentifierNode *Id) const; - void CheckGateQubitParamType(const ASTIdentifierList &IL) const; + void CheckGateOperandParamType(const ASTIdentifierList &IL) const; void CheckIsCallable(const ASTIdentifierNode *Id) const; @@ -472,6 +487,7 @@ class ASTIdentifierTypeController { case ASTTypeKernelCall: case ASTTypeQubitContainer: case ASTTypeQubitContainerAlias: + case ASTTypeQumodeContainer: case ASTTypeAngleArray: case ASTTypeBoolArray: case ASTTypeCBitArray: @@ -501,6 +517,7 @@ class ASTIdentifierTypeController { case ASTTypeCNotGate: case ASTTypeHadamardGate: case ASTTypeUGate: + case ASTTypeDispGate: return true; break; default: @@ -516,6 +533,9 @@ class ASTIdentifierTypeController { case ASTTypeUGate: return NTy == ASTTypeUGate; break; + case ASTTypeDispGate: + return NTy == ASTTypeDispGate; + break; case ASTTypeHadamardGate: return NTy == ASTTypeHadamardGate; break; @@ -589,6 +609,9 @@ class ASTIdentifierTypeController { bool IsFunctionArgument(const ASTToken *TK, const ASTIdentifierNode *Id, ASTType Ty, const ASTDeclarationContext *CTX) const; + + /// True for classical formals in a gate parameter list (before '{'). + bool IsGateParameterArgument(const ASTToken *TK, ASTType Ty) const; }; } // namespace QASM diff --git a/include/qasm/AST/ASTProductionFactory.h b/include/qasm/AST/ASTProductionFactory.h index 7cc06a3..38eb1f7 100644 --- a/include/qasm/AST/ASTProductionFactory.h +++ b/include/qasm/AST/ASTProductionFactory.h @@ -48,8 +48,12 @@ #include #include #include +#include +#include +#include #include #include + #include #include #include @@ -76,6 +80,8 @@ #include #include #include +#include +#include // OpenPulse #include @@ -161,6 +167,17 @@ class ASTProductionFactory { // const declaration ASTDeclarationNode *ProductionRule_170(ASTDeclarationNode *DN) const; + + // Unitary attribute + ASTUnitaryAttributeNode *ProductionRule_1465( + const ASTToken *TK, + const ASTIdentifierNode *Target, + ASTUnitaryAttributeKind AttributeKind, + const ASTExpressionNode *Value, + ASTOpType OpType) const; + + + // int[n] ASTDeclarationNode *ProductionRule_220(const ASTToken *TK, const ASTIdentifierNode *DId, @@ -258,6 +275,12 @@ class ASTProductionFactory { ASTStringNode *ProductionRule_816(const ASTToken *ITK, const ASTToken *STK, bool D = true) const; + // Identifier-based Aggregate Types suffix. + ASTStringNode *ProductionRule_816( + const ASTIdentifierNode *Id, + const ASTToken *STK, + bool D = true) const; + // Bitset ASTCBitNode *ProductionRule_817(const ASTToken *TK, const ASTIdentifierNode *IId) const; @@ -1298,6 +1321,16 @@ class ASTProductionFactory { ASTForLoopRangeExpressionNode *FLR, ASTStatement *ST) const; + /// Gate-body `for` with nested GateOpList (range or integer list). + ASTGateQOpNode *ProductionRule_3220(const ASTToken *TK, + ASTIdentifierNode *LId, + ASTForLoopRangeExpressionNode *FLR, + ASTGateQOpList *Body) const; + ASTGateQOpNode *ProductionRule_3221(const ASTToken *TK, + ASTIdentifierNode *LId, + ASTIntegerList *IL, + ASTGateQOpList *Body) const; + // While Loop ASTWhileStatementNode *ProductionRule_3300(const ASTToken *TK, ASTExpressionNode *EN, @@ -1314,6 +1347,12 @@ class ASTProductionFactory { const ASTArgumentNodeList *ANL, const ASTAnyTypeList *ATL) const; + ASTGateQOpNode *ProductionRule_3500(const ASTToken *TK, + const ASTIdentifierNode *Id, + const ASTExpressionList *TemplateArgs, + const ASTArgumentNodeList *ANL, + const ASTAnyTypeList *ATL) const; + ASTGateQOpNode *ProductionRule_3502(const ASTToken *TK, const ASTArgumentNodeList *ANL, const ASTAnyTypeList *ATL) const; @@ -1462,6 +1501,41 @@ class ASTProductionFactory { ProductionRule_3854(const ASTToken *TK, const ASTGateGPhaseExpressionNode *GEN) const; + // Fock-level ctrl[level] @ target + template + ASTGateFockControlNode *ProductionRule_3855(const ASTToken *TK, + const __Type *TP, + const __LevelType *Level) const; + template + ASTGateFockControlNode *ProductionRule_3855(const ASTToken *TK, + const ASTGateQOpNode *GQN, + const __LevelType *Level) const; + /// Dispatch FockLevelExpr (int / id-expr / binary / unary) to typed ctors. + template + ASTGateFockControlNode * + ProductionRule_3855(const ASTToken *TK, const __Type *TP, + const ASTExpressionNode *Level) const; + ASTGateFockControlNode * + ProductionRule_3855(const ASTToken *TK, const ASTGateQOpNode *GQN, + const ASTExpressionNode *Level) const; + + // Fock-level negctrl[level] @ target + template + ASTGateFockNegControlNode * + ProductionRule_3856(const ASTToken *TK, const __Type *TP, + const __LevelType *Level) const; + template + ASTGateFockNegControlNode * + ProductionRule_3856(const ASTToken *TK, const ASTGateQOpNode *GQN, + const __LevelType *Level) const; + template + ASTGateFockNegControlNode * + ProductionRule_3856(const ASTToken *TK, const __Type *TP, + const ASTExpressionNode *Level) const; + ASTGateFockNegControlNode * + ProductionRule_3856(const ASTToken *TK, const ASTGateQOpNode *GQN, + const ASTExpressionNode *Level) const; + // Defcal Grammar ASTDeclarationNode *ProductionRule_5000(const ASTDefcalGrammarNode *DG) const; @@ -1498,6 +1572,49 @@ class ASTProductionFactory { ASTMPIntegerNode *ProductionRule_7004(const ASTToken *TK) const; ASTMPDecimalNode *ProductionRule_7005(const ASTToken *TK) const; ASTArrayNode *ProductionRule_7006(const ASTToken *TK) const; + + // ------------------------------------------------------------------------- + // Fork-local production rules (SQMS / qumode fork). Start at 10000 so new + // upstream rules in the 1xxx–9xxx ranges cannot collide. + // ------------------------------------------------------------------------- + + // qumode + ASTDeclarationNode *ProductionRule_10000(const ASTToken *TK, + const ASTIdentifierNode *DId) const; + ASTDeclarationNode *ProductionRule_10001(const ASTToken *TK, + const ASTIdentifierNode *DId, + const ASTIntNode *BI) const; + ASTDeclarationNode *ProductionRule_10002(const ASTToken *TK, + const ASTIdentifierNode *DId, + const ASTIdentifierNode *IXd) const; + + // unitary + ASTDeclarationNode *ProductionRule_10003(const ASTToken *TK, + const ASTIdentifierNode *DId) const; + + ASTDeclarationNode *ProductionRule_10004(const ASTToken *TK, + const ASTIdentifierNode *DId, + const ASTInitializerList *IL) const; + + // Gate array literal parameter: [e0, ..., ek] as angle or complex array. + ASTExpressionNode *ProductionRule_10010(const ASTExpressionList *EL) const; + + // Builtin disp gate call: complex parameter + qumode operand. + ASTGateQOpNode *ProductionRule_10020(const ASTToken *TK, + const ASTArgumentNodeList *ANL, + const ASTAnyTypeList *ATL) const; + + // Fully-typed gate declaration: explicit classical params + typed + // qubit/qumode operands (e.g. ECD). + ASTGateDeclarationNode *ProductionRule_10030(const ASTToken *TK, + const ASTIdentifierNode *GId, + ASTDeclarationList *DL, + ASTIdentifierList *QIL, + ASTGateQOpList *GOL) const; + + /// Register a `uint N` gate template parameter while parsing `gate foo[…]`. + void ProductionRule_10031(const ASTToken *TK, + const ASTIdentifierNode *Id) const; }; } // namespace QASM diff --git a/include/qasm/AST/ASTProductionFactory.inc b/include/qasm/AST/ASTProductionFactory.inc index 4701359..5043b9a 100644 --- a/include/qasm/AST/ASTProductionFactory.inc +++ b/include/qasm/AST/ASTProductionFactory.inc @@ -32,6 +32,16 @@ namespace QASM { using DiagLevel = QasmDiagnosticEmitter::DiagLevel; +// GateEOp Create* appends to GateOpList; when a modifier wraps that GateEOp, +// drop the bare sibling so only the modifier statement remains in the list. +template +static inline void PopWrappedGateEOp(const __Type *TP) { + if constexpr (std::is_base_of_v) { + ASTGateOpBuilder::Instance().PopIfBack(const_cast( + static_cast(TP))); + } +} + template ASTUnaryOpNode* ASTProductionFactory::ProductionRule_300(const ASTToken* TK, @@ -525,6 +535,7 @@ ASTProductionFactory::ProductionRule_3850(const ASTToken* TK, GCN->SetLocation(TK->GetLocation()); GCN->Mangle(); + PopWrappedGateEOp(TP); return GCN; } @@ -550,6 +561,7 @@ ASTProductionFactory::ProductionRule_3850(const ASTToken* TK, GCN->SetLocation(TK->GetLocation()); GCN->Mangle(); + PopWrappedGateEOp(TP); return GCN; } @@ -574,6 +586,7 @@ ASTProductionFactory::ProductionRule_3850(const ASTToken* TK, GCN->SetLocation(TK->GetLocation()); GCN->Mangle(); const_cast(GQN)->SetModifier(GCN); + ASTGateOpBuilder::Instance().PopIfBack(const_cast(GQN)); return GCN; } @@ -600,6 +613,7 @@ ASTProductionFactory::ProductionRule_3850(const ASTToken* TK, GCN->SetLocation(TK->GetLocation()); GCN->Mangle(); const_cast(GQN)->SetModifier(GCN); + ASTGateOpBuilder::Instance().PopIfBack(const_cast(GQN)); return GCN; } @@ -623,6 +637,7 @@ ASTProductionFactory::ProductionRule_3851(const ASTToken* TK, GNCN->SetLocation(TK->GetLocation()); GNCN->Mangle(); + PopWrappedGateEOp(TP); return GNCN; } @@ -648,6 +663,7 @@ ASTProductionFactory::ProductionRule_3851(const ASTToken* TK, GNCN->SetLocation(TK->GetLocation()); GNCN->Mangle(); + PopWrappedGateEOp(TP); return GNCN; } @@ -672,6 +688,7 @@ ASTProductionFactory::ProductionRule_3851(const ASTToken* TK, GNCN->SetLocation(TK->GetLocation()); GNCN->Mangle(); const_cast(GQN)->SetModifier(GNCN); + ASTGateOpBuilder::Instance().PopIfBack(const_cast(GQN)); return GNCN; } @@ -697,6 +714,7 @@ ASTProductionFactory::ProductionRule_3851(const ASTToken* TK, GNCN->SetLocation(TK->GetLocation()); GNCN->Mangle(); const_cast(GQN)->SetModifier(GNCN); + ASTGateOpBuilder::Instance().PopIfBack(const_cast(GQN)); return GNCN; } @@ -722,6 +740,7 @@ ASTProductionFactory::ProductionRule_3852(const ASTToken* TK, GPN->SetLocation(TK->GetLocation()); GPN->Mangle(); + PopWrappedGateEOp(TP); return GPN; } @@ -748,6 +767,7 @@ ASTProductionFactory::ProductionRule_3852(const ASTToken* TK, GPN->SetLocation(TK->GetLocation()); GPN->Mangle(); const_cast(GQN)->SetModifier(GPN); + ASTGateOpBuilder::Instance().PopIfBack(const_cast(GQN)); return GPN; } @@ -771,6 +791,7 @@ ASTProductionFactory::ProductionRule_3853(const ASTToken* TK, GIN->SetLocation(TK->GetLocation()); GIN->Mangle(); + PopWrappedGateEOp(TP); return GIN; } @@ -795,6 +816,7 @@ ASTProductionFactory::ProductionRule_3853(const ASTToken* TK, GIN->SetLocation(TK->GetLocation()); GIN->Mangle(); const_cast(GQN)->SetModifier(GIN); + ASTGateOpBuilder::Instance().PopIfBack(const_cast(GQN)); return GIN; } @@ -932,4 +954,192 @@ ASTProductionFactory::ProductionRule_1350(const ASTToken* TK, return SN; } +template +ASTGateFockControlNode* +ASTProductionFactory::ProductionRule_3855(const ASTToken* TK, + const __Type* TP, + const __LevelType* Level) const { + assert(TK && "Invalid ASTToken argument!"); + assert(TP && "Invalid template parameter argument!"); + assert(Level && "Invalid Fock level expression!"); + + ASTGateFockControlNode* GFCN = new ASTGateFockControlNode(TP, Level); + assert(GFCN && "Could not create a valid ASTGateFockControlNode!"); + + if (!GFCN) { + std::stringstream M; + M << "Could not create a valid ASTGateFockControlNode."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(TP), M.str(), DiagLevel::ICE); + return ASTGateFockControlNode::ExpressionError(M.str()); + } + + GFCN->SetLocation(TK->GetLocation()); + GFCN->Mangle(); + PopWrappedGateEOp(TP); + return GFCN; +} + +template +ASTGateFockControlNode* +ASTProductionFactory::ProductionRule_3855(const ASTToken* TK, + const ASTGateQOpNode* GQN, + const __LevelType* Level) const { + assert(TK && "Invalid ASTToken argument!"); + assert(GQN && "Invalid ASTGateQOpNode argument!"); + assert(Level && "Invalid Fock level expression!"); + + const ASTGateNode* GN = GQN->GetGateNode(); + ASTGateFockControlNode* GFCN = + GN ? new ASTGateFockControlNode(GN, Level) + : new ASTGateFockControlNode(GQN, Level); + assert(GFCN && "Could not create a valid ASTGateFockControlNode!"); + + if (!GFCN) { + std::stringstream M; + M << "Could not create a valid ASTGateFockControlNode."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(TK), M.str(), DiagLevel::ICE); + return ASTGateFockControlNode::ExpressionError(M.str()); + } + + GFCN->SetLocation(TK->GetLocation()); + GFCN->Mangle(); + ASTGateOpBuilder::Instance().PopIfBack(const_cast(GQN)); + return GFCN; +} + +template +ASTGateFockNegControlNode* +ASTProductionFactory::ProductionRule_3856(const ASTToken* TK, + const __Type* TP, + const __LevelType* Level) const { + assert(TK && "Invalid ASTToken argument!"); + assert(TP && "Invalid template parameter argument!"); + assert(Level && "Invalid Fock level expression!"); + + ASTGateFockNegControlNode* GFNCN = new ASTGateFockNegControlNode(TP, Level); + assert(GFNCN && "Could not create a valid ASTGateFockNegControlNode!"); + + if (!GFNCN) { + std::stringstream M; + M << "Could not create a valid ASTGateFockNegControlNode."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(TP), M.str(), DiagLevel::ICE); + return ASTGateFockNegControlNode::ExpressionError(M.str()); + } + + GFNCN->SetLocation(TK->GetLocation()); + GFNCN->Mangle(); + PopWrappedGateEOp(TP); + return GFNCN; +} + +template +ASTGateFockNegControlNode* +ASTProductionFactory::ProductionRule_3856(const ASTToken* TK, + const ASTGateQOpNode* GQN, + const __LevelType* Level) const { + assert(TK && "Invalid ASTToken argument!"); + assert(GQN && "Invalid ASTGateQOpNode argument!"); + assert(Level && "Invalid Fock level expression!"); + + const ASTGateNode* GN = GQN->GetGateNode(); + ASTGateFockNegControlNode* GFNCN = + GN ? new ASTGateFockNegControlNode(GN, Level) + : new ASTGateFockNegControlNode(GQN, Level); + assert(GFNCN && "Could not create a valid ASTGateFockNegControlNode!"); + + if (!GFNCN) { + std::stringstream M; + M << "Could not create a valid ASTGateFockNegControlNode."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(TK), M.str(), DiagLevel::ICE); + return ASTGateFockNegControlNode::ExpressionError(M.str()); + } + + GFNCN->SetLocation(TK->GetLocation()); + GFNCN->Mangle(); + ASTGateOpBuilder::Instance().PopIfBack(const_cast(GQN)); + return GFNCN; +} + +template +ASTGateFockControlNode* +ASTProductionFactory::ProductionRule_3855(const ASTToken* TK, const __Type* TP, + const ASTExpressionNode* Level) const { + assert(TK && "Invalid ASTToken argument!"); + assert(TP && "Invalid template parameter argument!"); + assert(Level && "Invalid Fock level expression!"); + + switch (Level->GetASTType()) { + case ASTTypeInt: + case ASTTypeUInt: + return ProductionRule_3855(TK, TP, dynamic_cast(Level)); + case ASTTypeBinaryOp: + return ProductionRule_3855(TK, TP, + dynamic_cast(Level)); + case ASTTypeUnaryOp: + return ProductionRule_3855(TK, TP, + dynamic_cast(Level)); + case ASTTypeIdentifier: { + const ASTIdentifierNode* Id = Level->GetIdentifier(); + if (!Id) { + std::stringstream M; + M << "Invalid identifier Fock level expression."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(TK), M.str(), DiagLevel::ICE); + return ASTGateFockControlNode::ExpressionError(M.str()); + } + return ProductionRule_3855(TK, TP, Id); + } + default: { + std::stringstream M; + M << "Unsupported Fock level expression type."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(TK), M.str(), DiagLevel::Error); + return ASTGateFockControlNode::ExpressionError(M.str()); + } + } +} + +template +ASTGateFockNegControlNode* +ASTProductionFactory::ProductionRule_3856(const ASTToken* TK, const __Type* TP, + const ASTExpressionNode* Level) const { + assert(TK && "Invalid ASTToken argument!"); + assert(TP && "Invalid template parameter argument!"); + assert(Level && "Invalid Fock level expression!"); + + switch (Level->GetASTType()) { + case ASTTypeInt: + case ASTTypeUInt: + return ProductionRule_3856(TK, TP, dynamic_cast(Level)); + case ASTTypeBinaryOp: + return ProductionRule_3856(TK, TP, + dynamic_cast(Level)); + case ASTTypeUnaryOp: + return ProductionRule_3856(TK, TP, + dynamic_cast(Level)); + case ASTTypeIdentifier: { + const ASTIdentifierNode* Id = Level->GetIdentifier(); + if (!Id) { + std::stringstream M; + M << "Invalid identifier Fock level expression."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(TK), M.str(), DiagLevel::ICE); + return ASTGateFockNegControlNode::ExpressionError(M.str()); + } + return ProductionRule_3856(TK, TP, Id); + } + default: { + std::stringstream M; + M << "Unsupported Fock level expression type."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(TK), M.str(), DiagLevel::Error); + return ASTGateFockNegControlNode::ExpressionError(M.str()); + } + } +} + } // namespace QASM diff --git a/include/qasm/AST/ASTQubit.h b/include/qasm/AST/ASTQubit.h index 772ff7d..241e534 100644 --- a/include/qasm/AST/ASTQubit.h +++ b/include/qasm/AST/ASTQubit.h @@ -82,9 +82,9 @@ class ASTQubitNode : public ASTExpressionNode { return ASTExpressionNode::Ident->GetMangledName(); } - virtual void SetGateQubitName(const std::string &GN) { GQN = GN; } + virtual void SetGateOperandName(const std::string &GN) { GQN = GN; } - virtual const std::string &GetGateQubitName() const { return GQN; } + virtual const std::string &GetGateOperandName() const { return GQN; } virtual bool IsError() const override { return ASTExpressionNode::IsError(); } @@ -106,33 +106,52 @@ class ASTQubitNode : public ASTExpressionNode { virtual void push(ASTBase * /* unused */) override {} }; -class ASTGateQubitParamNode : public ASTExpressionNode { +class ASTQumodeNode : public ASTQubitNode { +public: + ASTQumodeNode(const ASTIdentifierNode *Id, + unsigned Idx = static_cast(~0x0)) + : ASTQubitNode(Id, Idx) {} + + ASTQumodeNode(const ASTIdentifierNode *Id, unsigned Idx, + const std::string &QN) + : ASTQubitNode(Id, Idx, QN) {} + + virtual ~ASTQumodeNode() = default; + + virtual ASTType GetASTType() const override { return ASTTypeQumode; } + + virtual void print() const override; +}; + +class ASTGateOperandParamNode : public ASTExpressionNode { private: unsigned Bits; unsigned IX; std::string QName; private: - ASTGateQubitParamNode() = delete; + ASTGateOperandParamNode() = delete; protected: - ASTGateQubitParamNode(const ASTIdentifierNode *Id, const std::string &ERM) + ASTGateOperandParamNode(const ASTIdentifierNode *Id, const std::string &ERM) : ASTExpressionNode(Id, new ASTStringNode(ERM), ASTTypeExpressionError), Bits(0U), IX(static_cast(~0x0)), QName(ERM) {} public: - ASTGateQubitParamNode(const ASTIdentifierNode *Id) - : ASTExpressionNode(Id, ASTTypeGateQubitParam), Bits(0U), + ASTGateOperandParamNode(const ASTIdentifierNode *Id) + : ASTExpressionNode(Id, ASTTypeGateOperandParam), Bits(0U), IX(static_cast(~0x0)), QName() {} - ASTGateQubitParamNode(const ASTIdentifierNode *Id, unsigned Index, - unsigned QBits, const std::string &Name) - : ASTExpressionNode(Id, ASTTypeGateQubitParam), Bits(QBits), IX(Index), + ASTGateOperandParamNode(const ASTIdentifierNode *Id, unsigned Index, + unsigned QBits, const std::string &Name) + : ASTExpressionNode(Id, ASTTypeGateOperandParam), Bits(QBits), IX(Index), QName(Name) {} - virtual ~ASTGateQubitParamNode() = default; + virtual ~ASTGateOperandParamNode() = default; - virtual ASTType GetASTType() const override { return ASTTypeGateQubitParam; } + virtual ASTType GetASTType() const override { + return ASTTypeGateOperandParam; + } virtual ASTSemaType GetSemaType() const override { return SemaTypeExpression; @@ -164,21 +183,21 @@ class ASTGateQubitParamNode : public ASTExpressionNode { return ASTExpressionNode::GetError(); } - static ASTGateQubitParamNode *ExpressionError(const ASTIdentifierNode *Id, - const std::string &ERM) { - return new ASTGateQubitParamNode(Id, ERM); + static ASTGateOperandParamNode *ExpressionError(const ASTIdentifierNode *Id, + const std::string &ERM) { + return new ASTGateOperandParamNode(Id, ERM); } - static ASTGateQubitParamNode *ExpressionError(const std::string &ERM) { - return new ASTGateQubitParamNode(ASTIdentifierNode::QubitParam.Clone(), - ERM); + static ASTGateOperandParamNode *ExpressionError(const std::string &ERM) { + return new ASTGateOperandParamNode(ASTIdentifierNode::OperandParam.Clone(), + ERM); } virtual void print() const override { - std::cout << "" << std::endl; + std::cout << "" << std::endl; std::cout << "" << GetName() << "" << std::endl; std::cout << "" << GetMangledName() << "" << std::endl; - std::cout << "" << std::endl; + std::cout << "" << std::endl; } virtual void push(ASTBase * /* unused */) override {} @@ -539,6 +558,29 @@ class ASTQubitContainerNode : public ASTExpressionNode { } }; +class ASTQumodeContainerNode : public ASTQubitContainerNode { +public: + ASTQumodeContainerNode(const ASTIdentifierNode *Id, unsigned Size) + : ASTQubitContainerNode(Id, Size) {} + + virtual ASTType GetASTType() const override { return ASTTypeQumodeContainer; } + + virtual void print() const override { + std::cout << "" << std::endl; + std::cout << "" << GetName() << "" << std::endl; + std::cout << "" << GetMangledName() << "" + << std::endl; + std::cout << "" << Size() << "" << std::endl; + std::cout << "" << std::endl; + + for (const_iterator I = begin(); I != end(); ++I) + (*I)->print(); + + std::cout << "" << std::endl; + std::cout << "" << std::endl; + } +}; + } // namespace QASM #endif // __QASM_AST_QUBIT_H diff --git a/include/qasm/AST/ASTStringUtils.h b/include/qasm/AST/ASTStringUtils.h index 7384cd6..777b2be 100644 --- a/include/qasm/AST/ASTStringUtils.h +++ b/include/qasm/AST/ASTStringUtils.h @@ -635,11 +635,11 @@ class ASTStringUtils { return std::string(); } - std::string GetGateQubitParamName(const std::string &S) const { - if (S.find("ast-gate-qubit-param-") != std::string::npos) { + std::string GetGateOperandParamName(const std::string &S) const { + if (S.find("ast-gate-operand-param-") != std::string::npos) { std::string::size_type E = S.find_last_of('-'); if (E != std::string::npos) { - std::string QS = S.substr(std::strlen("ast-gate-qubit-param-"), E); + std::string QS = S.substr(std::strlen("ast-gate-operand-param-"), E); E = QS.find_last_of('-'); return QS.substr(0, E); } diff --git a/include/qasm/AST/ASTSymbolTable.h b/include/qasm/AST/ASTSymbolTable.h index 4359977..a0d3863 100644 --- a/include/qasm/AST/ASTSymbolTable.h +++ b/include/qasm/AST/ASTSymbolTable.h @@ -725,7 +725,8 @@ class ASTSymbolTable { Id->SetSymbolTableEntry(DSTE); return true; } else if (Ty == ASTTypeQubit || Ty == ASTTypeQubitContainer || - Ty == ASTTypeQubitContainerAlias) { + Ty == ASTTypeQubitContainerAlias || Ty == ASTTypeQumode || + Ty == ASTTypeQumodeContainer) { map_iterator QI = QSTM.find(Id->GetName()); if (QI != QSTM.end()) { if ((*QI).second && (*QI).second->GetValueType() == Ty && @@ -1136,7 +1137,8 @@ class ASTSymbolTable { return false; } } else if (Ty == ASTTypeQubit || Ty == ASTTypeQubitContainer || - Ty == ASTTypeQubitContainerAlias) { + Ty == ASTTypeQubitContainerAlias || Ty == ASTTypeQumode || + Ty == ASTTypeQumodeContainer) { map_iterator QI = QSTM.find(Id->GetName()); if (QI != QSTM.end()) { if ((*QI).second && (*QI).second->GetValueType() == Ty && @@ -1419,7 +1421,8 @@ class ASTSymbolTable { Id->SetSymbolTableEntry((*GI).second); return true; } else if (Ty == ASTTypeQubit || Ty == ASTTypeQubitContainer || - Ty == ASTTypeQubitContainerAlias) { + Ty == ASTTypeQubitContainerAlias || Ty == ASTTypeQumode || + Ty == ASTTypeQumodeContainer) { map_iterator QI = QSTM.find(Id->GetName()); if (QI != QSTM.end()) { (*QI).second = STE; @@ -2025,7 +2028,8 @@ class ASTSymbolTable { Id->SetSymbolTableEntry((*GI).second); return true; } else if (Ty == ASTTypeQubit || Ty == ASTTypeQubitContainer || - Ty == ASTTypeQubitContainerAlias) { + Ty == ASTTypeQubitContainerAlias || Ty == ASTTypeQumode || + Ty == ASTTypeQumodeContainer) { map_iterator QI = QSTM.find(Id->GetName()); if (QI != QSTM.end()) { (*QI).second = STE; @@ -2378,6 +2382,7 @@ class ASTSymbolTable { case ASTTypeCCXGate: case ASTTypeCNotGate: case ASTTypeHadamardGate: + case ASTTypeDispGate: case ASTTypeUGate: case ASTTypeDefcal: case ASTTypeDefcalGroup: @@ -2386,7 +2391,9 @@ class ASTSymbolTable { case ASTTypeQubit: case ASTTypeQubitContainer: case ASTTypeQubitContainerAlias: - case ASTTypeGateQubitParam: + case ASTTypeQumode: + case ASTTypeQumodeContainer: + case ASTTypeGateOperandParam: break; default: return (*CI).second; @@ -2452,6 +2459,7 @@ class ASTSymbolTable { case ASTTypeCCXGate: case ASTTypeCNotGate: case ASTTypeHadamardGate: + case ASTTypeDispGate: case ASTTypeUGate: case ASTTypeDefcal: case ASTTypeDefcalGroup: @@ -2460,7 +2468,9 @@ class ASTSymbolTable { case ASTTypeQubit: case ASTTypeQubitContainer: case ASTTypeQubitContainerAlias: - case ASTTypeGateQubitParam: + case ASTTypeQumode: + case ASTTypeQumodeContainer: + case ASTTypeGateOperandParam: break; default: { map_iterator CI = CSTM.find(S); @@ -2683,6 +2693,7 @@ class ASTSymbolTable { case ASTTypeCCXGate: case ASTTypeCXGate: case ASTTypeHadamardGate: + case ASTTypeDispGate: case ASTTypeUGate: case ASTTypeGate: { GI = GSTM.find(S); @@ -2821,7 +2832,9 @@ class ASTSymbolTable { } break; case ASTTypeQubit: case ASTTypeQubitContainer: - case ASTTypeQubitContainerAlias: { + case ASTTypeQubitContainerAlias: + case ASTTypeQumode: + case ASTTypeQumodeContainer: { map_iterator QI = QSTM.find(S); if (QI != QSTM.end()) { @@ -2841,6 +2854,19 @@ class ASTSymbolTable { return (*QI).second; } break; + case ASTTypeQumode: + case ASTTypeQumodeContainer: + if ((*QI).second && + ((*QI).second->GetValueType() == ASTTypeQumode || + (*QI).second->GetValueType() == ASTTypeQumodeContainer) && + ((*QI).second->GetIdentifier()->GetBits() == Bits || Bits == 0)) { + return (*QI).second; + } else if (ASTStringUtils::Instance().IsQCElement(S)) { + if ((*QI).second && (*QI).second->GetValueType() == Ty && + Bits <= (*QI).second->GetIdentifier()->GetBits()) + return (*QI).second; + } + break; default: if (ASTStringUtils::Instance().IsIndexed(S)) { if ((*QI).second && (*QI).second->GetValueType() == Ty && @@ -2861,7 +2887,7 @@ class ASTSymbolTable { return nullptr; } break; - case ASTTypeGateQubitParam: { + case ASTTypeGateOperandParam: { std::pair R = STM.equal_range(S); if (R.first != STM.end()) { @@ -3065,6 +3091,7 @@ class ASTSymbolTable { case ASTTypeCCXGate: case ASTTypeCNotGate: case ASTTypeHadamardGate: + case ASTTypeDispGate: case ASTTypeUGate: case ASTTypeGate: case ASTTypeDefcal: @@ -3074,7 +3101,9 @@ class ASTSymbolTable { case ASTTypeQubit: case ASTTypeQubitContainer: case ASTTypeQubitContainerAlias: - case ASTTypeGateQubitParam: + case ASTTypeQumode: + case ASTTypeQumodeContainer: + case ASTTypeGateOperandParam: break; default: { if (ASTDefcalContextBuilder::Instance().InOpenContext()) { @@ -3094,6 +3123,7 @@ class ASTSymbolTable { case ASTTypeCCXGate: case ASTTypeCNotGate: case ASTTypeHadamardGate: + case ASTTypeDispGate: case ASTTypeUGate: SI = GSTM.find(S); if (SI != GSTM.end()) @@ -3102,6 +3132,8 @@ class ASTSymbolTable { case ASTTypeQubit: case ASTTypeQubitContainer: case ASTTypeQubitContainerAlias: + case ASTTypeQumode: + case ASTTypeQumodeContainer: SI = QSTM.find(S); if (SI != QSTM.end()) return (*SI).second; @@ -3555,8 +3587,8 @@ class ASTSymbolTable { if (QI != LSTM.end()) { if ((*QI).second && ((*QI).second->GetIdentifier()->GetSymbolType() == - ASTTypeGateQubitParam || - (*QI).second->GetValueType() == ASTTypeGateQubitParam)) + ASTTypeGateOperandParam || + (*QI).second->GetValueType() == ASTTypeGateOperandParam)) LSTM.erase(Q); } } @@ -3564,10 +3596,10 @@ class ASTSymbolTable { void EraseLocalQubitParam(const ASTIdentifierNode *Id) { assert(Id && "Invalid ASTIdentifierNode argument!"); - assert(Id->GetSymbolType() == ASTTypeGateQubitParam && - "Identifier Type is not an ASTTypeGateQubitParam!"); + assert(Id->GetSymbolType() == ASTTypeGateOperandParam && + "Identifier Type is not an ASTTypeGateOperandParam!"); - if (Id->GetSymbolType() == ASTTypeGateQubitParam) + if (Id->GetSymbolType() == ASTTypeGateOperandParam) EraseLocalQubitParam(Id->GetName()); } @@ -3602,7 +3634,7 @@ class ASTSymbolTable { ((*QI).second->GetValueType() == ASTTypeQubit || (*QI).second->GetValueType() == ASTTypeQubitContainer || (*QI).second->GetValueType() == ASTTypeQubitContainerAlias || - (*QI).second->GetValueType() == ASTTypeGateQubitParam)) { + (*QI).second->GetValueType() == ASTTypeGateOperandParam)) { LSTM.erase(QI); } } @@ -3614,8 +3646,8 @@ class ASTSymbolTable { EraseGateLocalQubit(Id->GetName()); } - void EraseGateQubitParam(const std::string &Q, unsigned Bits, ASTType Ty) { - if (Ty != ASTTypeGateQubitParam) + void EraseGateOperandParam(const std::string &Q, unsigned Bits, ASTType Ty) { + if (Ty != ASTTypeGateOperandParam) return; map_iterator QI = QSTM.find(Q); @@ -3651,9 +3683,9 @@ class ASTSymbolTable { } } - void EraseGateQubitParam(const ASTIdentifierNode *Id) { + void EraseGateOperandParam(const ASTIdentifierNode *Id) { assert(Id && "Invalid ASTIdentifierNode argument!"); - EraseGateQubitParam(Id->GetName(), Id->GetBits(), Id->GetSymbolType()); + EraseGateOperandParam(Id->GetName(), Id->GetBits(), Id->GetSymbolType()); } void LocalScope(const std::string &S, unsigned NumBits, ASTType Ty) { @@ -3688,6 +3720,7 @@ class ASTSymbolTable { case ASTTypeCCXGate: case ASTTypeCXGate: case ASTTypeHadamardGate: + case ASTTypeDispGate: case ASTTypeUGate: case ASTTypeGate: { std::stringstream M; @@ -3837,6 +3870,7 @@ class ASTSymbolTable { case ASTTypeCCXGate: case ASTTypeCXGate: case ASTTypeHadamardGate: + case ASTTypeDispGate: case ASTTypeUGate: case ASTTypeGate: M << "Declared Gates cannot be erased."; @@ -3911,7 +3945,8 @@ class ASTSymbolTable { } } else { if (Ty == ASTTypeQubit || Ty == ASTTypeQubitContainer || - Ty == ASTTypeGateQubitParam || Ty == ASTTypeQubitContainerAlias) { + Ty == ASTTypeGateOperandParam || Ty == ASTTypeQubitContainerAlias || + Ty == ASTTypeQumode || Ty == ASTTypeQumodeContainer) { map_iterator QI = QSTM.find(S); if (QI != QSTM.end()) { } @@ -3936,7 +3971,7 @@ class ASTSymbolTable { } else if ((*I).first == S && (*I).second->GetIdentifier()->GetBits() == Bits && (Ty == ASTTypeQubit || Ty == ASTTypeQubitContainer || - Ty == ASTTypeGateQubitParam) && + Ty == ASTTypeGateOperandParam) && ((*I).second->GetValueType() == Ty || (*I).second->GetValueType() == ASTTypeUndefined)) { IV.push_back(I); @@ -5171,8 +5206,9 @@ class ASTSymbolTable { case ASTTypeCXGate: case ASTTypeCCXGate: case ASTTypeCNotGate: + case ASTTypeDispGate: case ASTTypeUGate: - case ASTTypeGateQubitParam: + case ASTTypeGateOperandParam: case ASTTypeKernel: case ASTTypeFunction: case ASTTypeFunctionDeclaration: @@ -5245,7 +5281,9 @@ class ASTSymbolTable { if (Id->GetSymbolType() == ASTTypeQubit || Id->GetSymbolType() == ASTTypeQubitContainer || - Id->GetSymbolType() == ASTTypeQubitContainerAlias) { + Id->GetSymbolType() == ASTTypeQubitContainerAlias || + Id->GetSymbolType() == ASTTypeQumode || + Id->GetSymbolType() == ASTTypeQumodeContainer) { UI = QSTM.find(Id->GetName()); if (UI != QSTM.end()) { MIX = XQSTM; @@ -5371,7 +5409,8 @@ class ASTSymbolTable { EraseFromMap(UI, MIX); return true; } else if (Ty == ASTTypeQubit || Ty == ASTTypeQubitContainer || - Ty == ASTTypeQubitContainerAlias) { + Ty == ASTTypeQubitContainerAlias || Ty == ASTTypeQumode || + Ty == ASTTypeQumodeContainer) { map_iterator QI = QSTM.find(Id->GetName()); if (QI != QSTM.end()) { if ((*UI).second == (*QI).second && @@ -5390,6 +5429,12 @@ class ASTSymbolTable { case ASTTypeQubitContainer: QT = "QubitContainer"; break; + case ASTTypeQumode: + QT = "Qumode"; + break; + case ASTTypeQumodeContainer: + QT = "QumodeContainer"; + break; default: QT = "QubitContainer alias "; break; @@ -5627,6 +5672,7 @@ class ASTSymbolTable { case ASTTypeCXGate: case ASTTypeCCXGate: case ASTTypeCNotGate: + case ASTTypeDispGate: case ASTTypeUGate: case ASTTypeFunction: case ASTTypeDefcal: @@ -5688,7 +5734,7 @@ class ASTSymbolTable { goto Found; } - if (Ty == ASTTypeGateQubitParam) { + if (Ty == ASTTypeGateOperandParam) { UI = GSTM.find(Id->GetName()); if (UI != GLSTM.end()) { MIX = XGSTM; @@ -5828,7 +5874,7 @@ class ASTSymbolTable { return true; } - bool TransferGateQubitParam(const ASTIdentifierNode *Id) { + bool TransferGateOperandParam(const ASTIdentifierNode *Id) { assert(Id && "Invalid ASTIdentifierNode argument!"); map_iterator GI = GLSTM.find(Id->GetName()); @@ -6039,7 +6085,7 @@ class ASTSymbolTable { return true; } - void EraseGateQubitParam(const std::string &Id) { + void EraseGateOperandParam(const std::string &Id) { assert(!Id.empty() && "Invalid ASTIdentifierNode argument!"); map_iterator GI = GSTM.find(Id); diff --git a/include/qasm/AST/ASTTypeDiscovery.h b/include/qasm/AST/ASTTypeDiscovery.h index 4a6f227..89624a2 100644 --- a/include/qasm/AST/ASTTypeDiscovery.h +++ b/include/qasm/AST/ASTTypeDiscovery.h @@ -73,7 +73,9 @@ #include #include +#include #include +#include namespace QASM { @@ -91,8 +93,8 @@ class ASTTypeDiscovery { protected: bool InReDeclarationContext(const ASTIdentifierNode *Id, ASTType CTy, const ASTDeclarationContext *DCX) const; - bool IsGateQubitParam(const ASTIdentifierNode *Id, ASTType CTy, ASTType PTy, - const ASTDeclarationContext *DCX) const; + bool IsGateOperandParam(const ASTIdentifierNode *Id, ASTType CTy, ASTType PTy, + const ASTDeclarationContext *DCX) const; bool IsGateAngleParam(const ASTIdentifierNode *Id, ASTType CTy, ASTType PTy, const ASTDeclarationContext *DCX) const; bool IsGateAngleParam(const std::string &S, ASTType CTy, ASTType PTy, @@ -163,6 +165,18 @@ class ASTTypeDiscovery { void ValidateDefcalQubitArgs(const ASTAnyTypeList *ATL, const ASTDefcalGroupNode *DG) const; + + /// Call-site type checks for fully-typed gate declarations. + /// Returns false and emits diagnostics on mismatch. + /// \p TemplateArgs optional explicit `gatecall[…](…)` template arguments. + /// On success, \p OutBound (if non-null) receives one entry per Decl + /// TemplateParam (explicit or inferred). Caller attaches these to the call + /// Gate via SetTemplateParamBounds — do not overwrite body `N` STEs. + bool ValidateTypedGateCall( + const ASTToken *TK, const ASTGateNode *Decl, + const ASTArgumentNodeList &ANL, const ASTAnyTypeList &ATL, + const ASTExpressionList *TemplateArgs = nullptr, + std::vector> *OutBound = nullptr) const; }; } // namespace QASM diff --git a/include/qasm/AST/ASTTypeEnums.h b/include/qasm/AST/ASTTypeEnums.h index 3acab8a..1379ce1 100644 --- a/include/qasm/AST/ASTTypeEnums.h +++ b/include/qasm/AST/ASTTypeEnums.h @@ -155,6 +155,9 @@ enum ASTType : unsigned { ASTTypeGateControl, ASTTypeGateControlStatement, ASTTypeGateDeclaration, + ASTTypeGateFockControl, + ASTTypeGateFockNegControl, + ASTTypeGateFor, ASTTypeGateGPhaseExpression, ASTTypeGateGPhaseStatement, ASTTypeGateInverse, @@ -164,7 +167,7 @@ enum ASTType : unsigned { ASTTypeGateParam, ASTTypeGatePower, ASTTypeGatePowerStatement, - ASTTypeGateQubitParam, + ASTTypeGateOperandParam, ASTTypeGateQualifier, ASTTypeGateOpNode, ASTTypeGateOpList, @@ -181,6 +184,7 @@ enum ASTType : unsigned { ASTTypeGoTo, ASTTypeGPhaseExpression, ASTTypeGPhaseStatement, + ASTTypeDispGate, ASTTypeHadamardGate, ASTTypeIdentifier, ASTTypeIdentifierList, @@ -288,6 +292,8 @@ enum ASTType : unsigned { ASTTypeQubitContainerAlias, ASTTypeQubitMap, ASTTypeQubits, + ASTTypeQumode, + ASTTypeQumodeContainer, ASTTypeRegister, ASTTypeReset, ASTTypeRestrict, @@ -334,6 +340,8 @@ enum ASTType : unsigned { ASTTypeTypeExpression, ASTTypeTypeQualifier, ASTTypeUGate, + ASTTypeUnitary, //adding a data type Unitary KH + ASTTypeUnitaryAttribute, ASTTypeUInt, ASTTypeULong, ASTTypeUnaryOp, @@ -487,6 +495,7 @@ enum GateKind : unsigned { ASTGateKindCNOT, ASTGateKindH, ASTGateKindU, + ASTGateKindDisp, ASTGateKindLambda, ASTGateKindPhi, ASTGateKindTheta diff --git a/include/qasm/AST/ASTTypeSystemBuilder.h b/include/qasm/AST/ASTTypeSystemBuilder.h index 371e2bc..a72dcec 100644 --- a/include/qasm/AST/ASTTypeSystemBuilder.h +++ b/include/qasm/AST/ASTTypeSystemBuilder.h @@ -49,6 +49,7 @@ class ASTTypeSystemBuilder { protected: void CreateASTBuiltinCXGate() const; void CreateASTBuiltinUGate() const; + void CreateASTBuiltinDispGate() const; void CreateASTReservedAngles() const; void CreateASTReservedMPDecimalValues() const; diff --git a/include/qasm/AST/ASTTypes.h b/include/qasm/AST/ASTTypes.h index d86983b..4fefcd7 100644 --- a/include/qasm/AST/ASTTypes.h +++ b/include/qasm/AST/ASTTypes.h @@ -3277,7 +3277,10 @@ class ASTComplexExpressionNode : public ASTExpressionNode { virtual void print() const override { std::cout << "" << std::endl; - BOP->print(); + if (EType == ASTTypeBinaryOp && BOP) + BOP->print(); + else if (EType == ASTTypeUnaryOp && UOP) + UOP->print(); std::cout << "" << std::endl; } @@ -3537,6 +3540,14 @@ class ASTMPComplexNode : public ASTExpressionNode { virtual const ASTExpressionNode *GetExpression() const { return Expr; } + /// Attach a non-evaluated complex expression tree (e.g. `alpha/2`). + /// Leaves the numeric value as NaN; used so gate Params keep the expression + /// for unrolling without forcing Evaluate (real/imag literal form). + virtual void AttachExpression(const ASTComplexExpressionNode *E) { + Expr = E; + NE = true; + } + virtual const ASTFunctionCallNode *GetFunctionCall() const { return FC; } virtual const ASTIdentifierNode *GetIdentifier() const override { @@ -3991,6 +4002,8 @@ class ASTUnaryOpStatementNode : public ASTStatementNode { class ASTGateNode; class ASTGateControlNode; class ASTGateNegControlNode; +class ASTGateFockControlNode; +class ASTGateFockNegControlNode; class ASTGatePowerNode; class ASTGateInverseNode; class ASTGPhaseExpressionNode; @@ -4037,6 +4050,12 @@ class ASTGateOpNode : public ASTStatementNode { explicit ASTGateOpNode(const ASTIdentifierNode *Id, const ASTGateNegControlNode *GNCN); + explicit ASTGateOpNode(const ASTIdentifierNode *Id, + const ASTGateFockControlNode *GFCN); + + explicit ASTGateOpNode(const ASTIdentifierNode *Id, + const ASTGateFockNegControlNode *GFNCN); + explicit ASTGateOpNode(const ASTIdentifierNode *Id, const ASTGatePowerNode *GPN); @@ -4130,6 +4149,18 @@ class ASTGateQOpNode : public ASTGateOpNode { explicit ASTGateQOpNode(const ASTGateNegControlNode *GNCN); + explicit ASTGateQOpNode(const ASTIdentifierNode *Id, + const ASTGateFockControlNode *GFCN) + : ASTGateOpNode(Id, GFCN) {} + + explicit ASTGateQOpNode(const ASTGateFockControlNode *GFCN); + + explicit ASTGateQOpNode(const ASTIdentifierNode *Id, + const ASTGateFockNegControlNode *GFNCN) + : ASTGateOpNode(Id, GFNCN) {} + + explicit ASTGateQOpNode(const ASTGateFockNegControlNode *GFNCN); + explicit ASTGateQOpNode(const ASTIdentifierNode *Id, const ASTGatePowerNode *GPN) : ASTGateOpNode(Id, GPN) {} diff --git a/include/qasm/AST/ASTUnitary.h b/include/qasm/AST/ASTUnitary.h new file mode 100644 index 0000000..87e40db --- /dev/null +++ b/include/qasm/AST/ASTUnitary.h @@ -0,0 +1,78 @@ +/* -*- coding: utf-8 -*- + * + * Copyright 2022 IBM RESEARCH. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0. + */ + +#ifndef __QASM_AST_UNITARY_H +#define __QASM_AST_UNITARY_H + +#include +#include + +namespace QASM { + +// class ASTUnitaryNode : public ASTExpressionNode { +class ASTInitializerList; // forward declaration +class ASTUnitaryNode : public ASTGateNode { +private: + ASTUnitaryNode() = delete; + const ASTInitializerList *INL; // initializer list for unitary matrix + +public: + // unitary u; + explicit ASTUnitaryNode(const ASTIdentifierNode *Id) + // : ASTExpressionNode(Id, ASTTypeUnitary) {} + : ASTGateNode(Id), INL(nullptr) {} + + // unitary u = {{1, 0}, {0, 1}}; + ASTUnitaryNode(const ASTIdentifierNode *Id, + const ASTInitializerList *IL) + : ASTGateNode(Id), INL(IL) {} + + // Existing gate-call constructor + ASTUnitaryNode(const ASTIdentifierNode *Id, + const ASTArgumentNodeList &AL, + const ASTAnyTypeList &QL, + bool IsGateCall = false) + : ASTGateNode(Id, AL, QL, IsGateCall), INL(nullptr) {} + + + virtual ~ASTUnitaryNode() = default; + + virtual ASTType GetASTType() const override { + return ASTTypeUnitary; + } + + virtual ASTSemaType GetSemaType() const override { + return SemaTypeExpression; + } + + virtual bool HasInitializerList() const { + return INL != nullptr; + } + + virtual const ASTInitializerList *GetInitializerList() const { + return INL; + } + //added this block of code + virtual ASTUnitaryNode * + CloneCall(const ASTIdentifierNode *Id, + const ASTArgumentNodeList &AL, + const ASTAnyTypeList &QL) override; + + + virtual void Mangle() override; + + virtual const ASTIdentifierNode *GetIdentifier() const override { + // return ASTExpressionNode::Ident; + return ASTGateNode::GetIdentifier(); + } + + virtual void print() const override; +}; + +} // namespace QASM + +#endif \ No newline at end of file diff --git a/include/qasm/AST/ASTUnitaryAttribute.h b/include/qasm/AST/ASTUnitaryAttribute.h new file mode 100644 index 0000000..e4036ea --- /dev/null +++ b/include/qasm/AST/ASTUnitaryAttribute.h @@ -0,0 +1,65 @@ +/* -*- coding: utf-8 -*- + * + * Licensed under the Apache License, Version 2.0. + */ + +#ifndef __QASM_AST_UNITARY_ATTRIBUTE_H +#define __QASM_AST_UNITARY_ATTRIBUTE_H + +#include + +namespace QASM { + +enum ASTUnitaryAttributeKind { + ASTUnitaryAttributeBumper, + ASTUnitaryAttributeBumperMax +}; + + +class ASTUnitaryAttributeNode : public ASTStatementNode { +private: + const ASTUnitaryAttributeKind AttributeKind; + ASTOpType OpType; + + ASTUnitaryAttributeNode() = delete; + +public: + ASTUnitaryAttributeNode(const ASTIdentifierNode *Target, + const ASTUnitaryAttributeKind AttributeKind, + const ASTExpressionNode *Value, + ASTOpType OpType); + + virtual ~ASTUnitaryAttributeNode() = default; + + virtual ASTType GetASTType() const override { + return ASTTypeUnitaryAttribute; + } + + virtual ASTSemaType GetSemaType() const override { + return SemaTypeStatement; + } + + virtual const ASTIdentifierNode *GetTarget() const { + return GetIdentifier(); + } + + virtual ASTUnitaryAttributeKind GetAttributeKind() const { + return AttributeKind; +} + + virtual const ASTExpressionNode *GetValue() const { + return GetExpression(); + } + + virtual ASTOpType GetOpType() const { + return OpType; + } + + virtual void print() const override; + + virtual void push(ASTBase * /* unused */) override {} +}; + +} // namespace QASM + +#endif \ No newline at end of file diff --git a/include/qasm/AST/ASTUtils.h b/include/qasm/AST/ASTUtils.h index 9cfdcc6..fd4a0bc 100644 --- a/include/qasm/AST/ASTUtils.h +++ b/include/qasm/AST/ASTUtils.h @@ -69,8 +69,16 @@ class ASTUtils { Ty == ASTTypeQubitContainerAlias; } + bool IsQumodeType(ASTType Ty) const { + return Ty == ASTTypeQumode || Ty == ASTTypeQumodeContainer; + } + + bool IsQuantumRegisterType(ASTType Ty) const { + return IsQubitType(Ty) || IsQumodeType(Ty); + } + bool IsQubitParamType(ASTType Ty) const { - return IsQubitType(Ty) || Ty == ASTTypeGateQubitParam; + return IsQuantumRegisterType(Ty) || Ty == ASTTypeGateOperandParam; } bool IsAngleType(ASTType Ty) const { diff --git a/include/qasm/AST/ASTValue.h b/include/qasm/AST/ASTValue.h index 2c29592..d4dd55a 100644 --- a/include/qasm/AST/ASTValue.h +++ b/include/qasm/AST/ASTValue.h @@ -82,8 +82,7 @@ class ASTValue : public ASTBase { try { return std::any_cast<__ConvertTo>(Value.first); } catch (const std::bad_any_cast &E) { - // FIXME: Use Diagnostic subsystem. - std::cerr << "ASTValue caught " << E.what() << std::endl; + (void)E; Error = true; } diff --git a/include/qasm/AST/README.ASTProductionFactory.txt b/include/qasm/AST/README.ASTProductionFactory.txt index 794de76..0ee54e7 100644 --- a/include/qasm/AST/README.ASTProductionFactory.txt +++ b/include/qasm/AST/README.ASTProductionFactory.txt @@ -235,3 +235,15 @@ misc. warnings: 6000 misc. errors: 7000 ------------------------------- + +Fork-local (SQMS / qumode fork): + Reserve 10000+ so new upstream rules in 1xxx–9xxx cannot collide. + +qumode: 10000 +qumode[n] (int size): 10001 +qumode[n] (id size): 10002 +gate angle-array literal: 10010 +builtin disp gate call: 10020 +fully-typed gate decl: 10030 + +------------------------------- diff --git a/lib/AST/ASTArraySubscript.cpp b/lib/AST/ASTArraySubscript.cpp index 640bda1..a6de733 100644 --- a/lib/AST/ASTArraySubscript.cpp +++ b/lib/AST/ASTArraySubscript.cpp @@ -31,6 +31,16 @@ using DiagLevel = QASM::QasmDiagnosticEmitter::DiagLevel; std::string ASTArraySubscriptNode::AsIndexedString() const { std::stringstream S; + // Prefer the induction / index identifier name over a numeric stand-in. + if (IsInductionVariable() && GetInductionVariable()) { + S << '[' << GetInductionVariable()->GetName() << ']'; + return S.str(); + } + if (IsIndexIdentifier() && GetIndexIdentifier()) { + S << '[' << GetIndexIdentifier()->GetName() << ']'; + return S.str(); + } + switch (EType) { case ASTTypeIdentifier: S << '[' << ID->GetName() << ']'; diff --git a/lib/AST/ASTBuilder.cpp b/lib/AST/ASTBuilder.cpp index f82cd05..ed6129c 100644 --- a/lib/AST/ASTBuilder.cpp +++ b/lib/AST/ASTBuilder.cpp @@ -42,6 +42,7 @@ #include #include #include +// #include #include #include @@ -2296,7 +2297,7 @@ ASTIdentifierNode *ASTBuilder::CreateASTIdentifierNode( ASTTypeSystemBuilder::Instance().IsImplicitAngle(Id)) { ASTIdentifierNode *IDN = nullptr; - if (Type != ASTTypeAngle && Type != ASTTypeGateQubitParam) + if (Type != ASTTypeAngle && Type != ASTTypeGateOperandParam) Type = ASTTypeAngle; // ASTTypeSystemBuilder will create the reserved pi, tau and euler @@ -2673,6 +2674,22 @@ ASTIdentifierNode *ASTBuilder::CreateLocalScopeASTIdentifierNode( return nullptr; } + // Do not clobber an existing typed classical gate formal (e.g. complex + // alpha) by re-inserting the same name as ASTTypeGateOperandParam. + if (const ASTSymbolTableEntry *Any = + ASTSymbolTable::Instance().FindLocal(Id)) { + ASTType ETy = Any->GetIdentifier()->GetSymbolType(); + if (Type == ASTTypeGateOperandParam && + (ETy == ASTTypeMPComplex || ETy == ASTTypeFloat || + ETy == ASTTypeDouble || ETy == ASTTypeMPDecimal || ETy == ASTTypeInt || + ETy == ASTTypeUInt || ETy == ASTTypeMPInteger || + ETy == ASTTypeMPUInteger || ETy == ASTTypeBool || + ETy == ASTTypeBitset || ETy == ASTTypeDuration || + ETy == ASTTypeAngle)) { + return const_cast(Any->GetIdentifier()); + } + } + const ASTSymbolTableEntry *LSTE = ASTSymbolTable::Instance().FindLocalSymbol(Id, Bits, Type); if (LSTE) { @@ -2755,7 +2772,7 @@ ASTIdentifierNode *ASTBuilder::FindASTIdentifierNode(const std::string &Id) { if (STE) return const_cast(STE->GetIdentifier()); - STE = ASTSymbolTable::Instance().Lookup(Id, 1U, ASTTypeGateQubitParam); + STE = ASTSymbolTable::Instance().Lookup(Id, 1U, ASTTypeGateOperandParam); if (STE) return const_cast(STE->GetIdentifier()); @@ -2769,6 +2786,11 @@ ASTIdentifierNode *ASTBuilder::FindASTIdentifierNode(const std::string &Id) { Id, ASTAngleNode::AngleBits, ASTTypeAngle)) { return const_cast(STE->GetIdentifier()); } + // Fully-typed gate formals (e.g. complex[float[64]] alpha) live in LSTM + // under their declared type, not ASTTypeAngle. + if (const ASTSymbolTableEntry *LSTE = + ASTSymbolTable::Instance().FindLocal(Id)) + return const_cast(LSTE->GetIdentifier()); } if (ASTTypeSystemBuilder::Instance().IsReservedAngle(Id)) @@ -2795,7 +2817,7 @@ ASTIdentifierNode *ASTBuilder::FindASTIdentifierNode(const std::string &Id) { return STE ? const_cast(STE->GetIdentifier()) : nullptr; } break; - case ASTTypeGateQubitParam: { + case ASTTypeGateOperandParam: { if (ASTIdentifierTypeController::Instance().InQubitList()) { STE = ASTSymbolTable::Instance().Lookup(Id, 1U, CTy); return STE ? const_cast(STE->GetIdentifier()) @@ -4745,7 +4767,7 @@ ASTBuilder::CreateASTQubitContainerNode(const ASTIdentifierNode *Id, const std::string &IDS = Id->GetName(); ASTType ITy = Id->GetSymbolTableEntry()->GetValueType(); - if (Id->GetSymbolType() == ASTTypeGateQubitParam) + if (Id->GetSymbolType() == ASTTypeGateOperandParam) Id->SetBits(1U); ASTSymbolTableEntry *STE = @@ -4798,7 +4820,7 @@ ASTBuilder::CreateASTQubitContainerNode(const ASTIdentifierNode *Id, break; case ASTTypeQubitContainer: case ASTTypeQubitContainerAlias: - case ASTTypeGateQubitParam: + case ASTTypeGateOperandParam: break; case ASTTypeQubitArray: if (Id->IsIndexed() || Id->IsReference()) { @@ -4939,6 +4961,181 @@ ASTBuilder::CreateASTQubitContainerNode(const ASTIdentifierNode *Id, return QCN; } +ASTQumodeContainerNode * +ASTBuilder::CreateASTQumodeContainerNode(const ASTIdentifierNode *Id, + unsigned NumBits) { + assert(Id && "Invalid ASTIdentifierNode argument!"); + + const std::string &IDS = Id->GetName(); + ASTType ITy = Id->GetSymbolTableEntry()->GetValueType(); + + ASTSymbolTableEntry *STE = + const_cast(Id->GetSymbolTableEntry()); + if (!STE) + STE = ASTSymbolTable::Instance().Lookup(IDS, NumBits, Id->GetSymbolType()); + if (!STE && Id->GetBits() == 0) { + STE = ASTSymbolTable::Instance().Lookup(IDS, Id->GetBits(), ITy); + Id->SetBits(NumBits); + } + + if (!STE) { + std::stringstream M; + M << "Failed to locate Identifier " << IDS << " in the Symbol Table!"; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(Id), M.str(), DiagLevel::Error); + return nullptr; + } + + if (STE->GetIdentifier() != Id) { + std::stringstream M; + M << "Inconsistent SymbolTable ASTIdentifierNode."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(Id), M.str(), DiagLevel::ICE); + return nullptr; + } + + if (Id->GetBits() == 0U && ITy == ASTTypeQumodeContainer) + STE->ResetValue(); + + if (Id->GetBits() != NumBits) + Id->SetBits(NumBits); + + ASTSymbolTable::Instance().TransferQubit(Id, NumBits, ITy); + + switch (STE->GetValueType()) { + case ASTTypeInt: + case ASTTypeFloat: + case ASTTypeDouble: + case ASTTypeQumode: + case ASTTypeBitset: + case ASTTypeUndefined: + case ASTTypeIdentifier: + STE->ResetValue(); + STE->SetValueType(ASTTypeQumodeContainer); + break; + case ASTTypeQumodeContainer: + break; + default: { + std::stringstream M; + M << "ASTIdentifier " << IDS << " exists in the SymbolTable " + << "with a different Type (" << PrintTypeEnum(STE->GetValueType()) + << " vs. " << PrintTypeEnum(ASTTypeQumodeContainer) << ")."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(), M.str(), DiagLevel::Error); + return nullptr; + } break; + } + + ASTSymbolTableEntry *QSTE = + const_cast(Id->GetSymbolTableEntry()); + + if (QSTE) { + if (QSTE->HasValue()) { + ASTQumodeContainerNode *QCN = + QSTE->GetValue()->GetValue(); + assert(QCN && + "Invalid ASTQumodeContainerNode obtained from the SymbolTable!"); + + if (QCN->Size() != Id->GetBits()) { + std::stringstream M; + M << "Existing ASTQumodeContainerNode does not have the width " + << "requested (" << QCN->Size() << " vs. " << Id->GetBits() << ")."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(), M.str(), + DiagLevel::Warning); + } + + const_cast(Id)->SetSymbolTableEntry(QSTE); + return QCN; + } + } else { + QSTE = new ASTSymbolTableEntry(Id, ASTTypeQumodeContainer); + assert(QSTE && "Could not create a valid ASTSymbolTable Entry!"); + } + + ASTQumodeContainerNode *QCN = new ASTQumodeContainerNode(Id, NumBits); + assert(QCN && "Unable to create an ASTQumodeContainerNode!"); + + QSTE->ResetValue(); + QSTE->SetValue(new ASTValue<>(QCN, ASTTypeQumodeContainer), + ASTTypeQumodeContainer); + assert(QSTE->HasValue() && + "ASTQumodeContainerNode SymbolTable Entry has no Value!"); + + const_cast(Id)->SetSymbolTableEntry(QSTE); + + std::stringstream QS; + std::stringstream QSS; + ASTQumodeNode *QBN; + + for (unsigned I = 0; I < NumBits; ++I) { + QS.clear(); + QS.str(""); + + if (IDS[0] == '%' || IDS[0] == '$') + QS << IDS << ':' << I; + else + QS << '%' << IDS << ':' << I; + + ASTIdentifierNode *QId = ASTBuilder::Instance().CreateASTIdentifierNode( + QS.str(), 1U, ASTTypeQumode); + assert(QId && "Could not create a valid ASTIdentifierNode!"); + + ASTSymbolTableEntry *QQSTE = + ASTSymbolTable::Instance().Lookup(QId, 1U, ASTTypeQumode); + if (!QQSTE) { + ASTSymbolTable::Instance().Insert(QId, 1U, ASTTypeQumode); + QQSTE = ASTSymbolTable::Instance().Lookup(QId, 1U, ASTTypeQumode); + } + + assert(QQSTE && "Could not obtain or create a valid ASTQumodeNode " + "SymbolTable Entry!"); + + if (QQSTE->HasValue()) { + QBN = QQSTE->GetValue()->GetValue(); + assert(QBN && "Invalid SymbolTable Entry ASTQumodeNode Value!"); + + QBN->Mangle(); + QCN->AddQubit(QBN); + } else { + QBN = ASTBuilder::CreateASTQumodeNode(QId, I); + assert(QBN && "Could not create a valid ASTQumodeNode!"); + + QBN->Mangle(); + QCN->AddQubit(QBN); + } + + QSS.str(""); + QSS.clear(); + if (IDS[0] == '%' || IDS[0] == '$') + QSS << IDS.substr(1); + else + QSS << IDS; + QSS << '[' << I << ']'; + + ASTIdentifierRefNode *IdR = new ASTIdentifierRefNode(QSS.str(), QId, 1U); + assert(IdR && "Could not create a valid ASTIdentifierRefNode!"); + + ASTSymbolTableEntry *XSTE = new ASTSymbolTableEntry(IdR, ASTTypeQumode); + assert(XSTE && "Could not create a valid ASTSymbolTableEntry!"); + + XSTE->ResetValue(); + XSTE->SetValue(new ASTValue<>(QBN, ASTTypeQumode), ASTTypeQumode); + assert(XSTE->HasValue() && "ASTQumode SymbolTable Entry has no Value!"); + + if (!ASTSymbolTable::Instance().Insert(IdR, XSTE)) { + std::stringstream M; + M << "Failure inserting qumode " << QSS.str() << " into the SymbolTable."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(QId), M.str(), + DiagLevel::Error); + } + } + + QCN->Mangle(); + return QCN; +} + ASTQubitContainerNode * ASTBuilder::CreateASTQubitContainerNode(const ASTIdentifierNode *Id, const std::vector &QV) { @@ -5496,6 +5693,46 @@ ASTQubitNode *ASTBuilder::CreateASTQubitNode(const ASTIdentifierNode *Id, return QN; } +ASTQumodeNode *ASTBuilder::CreateASTQumodeNode(const ASTIdentifierNode *Id, + unsigned Index) { + assert(Id && "Invalid ASTIdentifierNode argument!"); + + ASTSymbolTableEntry *STE = nullptr; + const std::string &IDS = Id->GetName(); + + if (!(STE = ASTSymbolTable::Instance().Lookup(IDS))) { + std::stringstream M; + M << "Failed to locate Identifier " << IDS << " in the Symbol Table!"; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(), M.str(), DiagLevel::Error); + return nullptr; + } + + if (STE->GetValueType() != ASTTypeQumode && + STE->GetValueType() != ASTTypeUndefined && + STE->GetValueType() != ASTTypeIdentifier) { + std::stringstream M; + M << "Identifier " << IDS << " exists in the SymbolTable with a " + << "different Type! (" << PrintTypeEnum(STE->GetValueType()) << " vs. " + << PrintTypeEnum(ASTTypeQumode) << ")."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(), M.str(), DiagLevel::Error); + return nullptr; + } + + ASTSymbolTable::Instance().TransferQubit(Id, 1, ASTTypeQumode); + + ASTQumodeNode *QN = new ASTQumodeNode(Id, Index); + assert(QN && "Unable to create an ASTQumodeNode!"); + + STE->ResetValue(); + STE->SetValue(new ASTValue<>(QN, ASTTypeQumode), ASTTypeQumode); + assert(STE->HasValue() && "ASTQumode SymbolTable Entry has no Value!"); + + const_cast(Id)->SetSymbolTableEntry(STE); + return QN; +} + ASTResultNode *ASTBuilder::CreateASTResultNode(const ASTIdentifierNode *Id, ASTType RTy, unsigned NumBits, ASTSignbit SB) { @@ -7987,6 +8224,11 @@ ASTGateNode *ASTBuilder::CreateASTGateNode(const ASTIdentifierNode *Id, assert(STE && "Could not create a valid ASTUGateNode SymbolTableEntry!"); STE->SetGlobalScope(); break; + case ASTGateKindDisp: + STE = new ASTSymbolTableEntry(Id, ASTTypeDispGate); + assert(STE && "Could not create a valid ASTDispGateNode SymbolTableEntry!"); + STE->SetGlobalScope(); + break; default: STE = new ASTSymbolTableEntry(Id, ASTTypeGate); assert(STE && "Could not create a valid ASTGateNode SymbolTableEntry!"); @@ -8037,6 +8279,13 @@ ASTGateNode *ASTBuilder::CreateASTGateNode(const ASTIdentifierNode *Id, STE->SetValue(new ASTValue<>(GN, ASTTypeUGate), ASTTypeUGate); assert(STE->HasValue() && "UGate ASTGateNode has no Value!"); break; + case ASTGateKindDisp: + GN = new ASTDispGateNode(Id, PL, IL, false, OL); + assert(GN && "Could not create a valid ASTDispGateNode!"); + STE->ResetValue(); + STE->SetValue(new ASTValue<>(GN, ASTTypeDispGate), ASTTypeDispGate); + assert(STE->HasValue() && "DispGate ASTGateNode has no Value!"); + break; default: GN = new ASTGateNode(Id, PL, IL, false, OL); assert(GN && "Could not create a valid Generic ASTGateNode!"); @@ -8113,6 +8362,11 @@ ASTGateNode *ASTBuilder::CreateASTGateNode(const ASTIdentifierNode *Id, assert(STE && "Could not create a valid ASTUGateNode SymbolTableEntry!"); STE->SetGlobalScope(); break; + case ASTGateKindDisp: + STE = new ASTSymbolTableEntry(Id, ASTTypeDispGate); + assert(STE && "Could not create a valid ASTDispGateNode SymbolTableEntry!"); + STE->SetGlobalScope(); + break; default: STE = new ASTSymbolTableEntry(Id, ASTTypeGate); assert(STE && "Could not create a valid ASTGateNode SymbolTableEntry!"); @@ -8163,6 +8417,13 @@ ASTGateNode *ASTBuilder::CreateASTGateNode(const ASTIdentifierNode *Id, STE->SetValue(new ASTValue<>(GN, ASTTypeUGate), ASTTypeUGate); assert(STE->HasValue() && "UGate ASTGateNode has no Value!"); break; + case ASTGateKindDisp: + GN = new ASTDispGateNode(Id, AL, QL, false, OL); + assert(GN && "Could not create a valid ASTDispGateNode!"); + STE->ResetValue(); + STE->SetValue(new ASTValue<>(GN, ASTTypeDispGate), ASTTypeDispGate); + assert(STE->HasValue() && "DispGate ASTGateNode has no Value!"); + break; default: GN = new ASTGateNode(Id, AL, QL, false, OL); assert(GN && "Could not create a valid Generic ASTGateNode!"); @@ -8834,6 +9095,46 @@ ASTDelayNode *ASTBuilder::CreateASTDelayNode(const ASTIdentifierNode *Id, return DDN; } +ASTUnitaryNode *ASTBuilder::CreateASTUnitaryNode(const ASTIdentifierNode *Id) { + assert(Id && "Invalid ASTIdentifierNode Unitary argument!"); + + ASTSymbolTableEntry *STE = ASTSymbolTable::Instance().Lookup(Id); + assert(STE && "Could not retrieve a valid Unitary SymbolTable Entry!"); + + ASTUnitaryNode *UN = new ASTUnitaryNode(Id); + assert(UN && "Could not create a valid ASTUnitaryNode!"); + + STE->ResetValue(); + STE->SetValue(new ASTValue<>(UN, ASTTypeUnitary), ASTTypeUnitary); + assert(STE->HasValue() && "Unitary SymbolTable Entry has no Value!"); + + const_cast(Id)->SetSymbolTableEntry(STE); + + UN->Mangle(); + return UN; +} + +ASTUnitaryNode *ASTBuilder::CreateASTUnitaryNode(const ASTIdentifierNode *Id, const ASTInitializerList *IL) { + assert(Id && "Invalid ASTIdentifierNode Unitary argument!"); + assert(IL && "Invalid ASTInitializerList Unitary argument!"); + + ASTSymbolTableEntry *STE = ASTSymbolTable::Instance().Lookup(Id); + assert(STE && "Could not retrieve a valid Unitary SymbolTable Entry!"); + + ASTUnitaryNode *UN = new ASTUnitaryNode(Id, IL); + assert(UN && "Could not create a valid ASTUnitaryNode!"); + + STE->ResetValue(); + STE->SetValue(new ASTValue<>(UN, ASTTypeUnitary), ASTTypeUnitary); + assert(STE->HasValue() && "Unitary SymbolTable Entry has no Value!"); + + const_cast(Id)->SetSymbolTableEntry(STE); + + UN->Mangle(); + return UN; +} + + ASTStretchNode *ASTBuilder::CreateASTStretchNode(const ASTIdentifierNode *Id) { assert(Id && "Invalid ASTIdentifierNode Stretch argument!"); @@ -10150,6 +10451,15 @@ ASTBuilder::CreateASTMPDecimalArrayNode(const ASTIdentifierNode *Id, ASTSymbolTable::Instance().Lookup(Id, Bits, ASTTypeMPDecimalArray); if (!STE) STE = ASTSymbolTable::Instance().Lookup(Id, 0, ASTTypeMPDecimalArray); + if (!STE) + STE = const_cast(Id->GetSymbolTableEntry()); + if (!STE) { + STE = new ASTSymbolTableEntry(const_cast(Id), + ASTTypeMPDecimalArray); + assert(STE && "Could not create a SymbolTable Entry!"); + const_cast(Id)->SetSymbolTableEntry(STE); + ASTSymbolTable::Instance().InsertLocal(Id, STE); + } assert(STE && "Could not retrieve a valid SymbolTable Entry!"); ASTArrayNode *ARN = new ASTMPDecimalArrayNode(Id, Bits, MPBits); diff --git a/lib/AST/ASTCallExpr.cpp b/lib/AST/ASTCallExpr.cpp index f5a6b66..b636d7f 100644 --- a/lib/AST/ASTCallExpr.cpp +++ b/lib/AST/ASTCallExpr.cpp @@ -83,6 +83,7 @@ void ASTCallExpressionNode::Mangle() { switch (CallType) { case ASTTypeGate: + case ASTTypeUnitary: M.TypeIdentifier(ASTTypeGateCall, GetIdentifier()->GetName()); break; case ASTTypeDefcal: diff --git a/lib/AST/ASTDefcal.cpp b/lib/AST/ASTDefcal.cpp index ff56f78..0e5fb20 100644 --- a/lib/AST/ASTDefcal.cpp +++ b/lib/AST/ASTDefcal.cpp @@ -1686,8 +1686,8 @@ void ASTDefcalNode::ToDefcalParamSymbolTable(const ASTIdentifierNode *Id, ASTSymbolTable::Instance().EraseLocalSymbol(Id->GetName(), Id->GetBits(), Id->GetSymbolType()); } else { - if (Id->GetSymbolType() == ASTTypeGateQubitParam) - ASTSymbolTable::Instance().EraseGateQubitParam( + if (Id->GetSymbolType() == ASTTypeGateOperandParam) + ASTSymbolTable::Instance().EraseGateOperandParam( Id->GetName(), Id->GetBits(), Id->GetSymbolType()); } diff --git a/lib/AST/ASTGateOpBuilder.cpp b/lib/AST/ASTGateOpBuilder.cpp index 8c2b74f..4888cd5 100644 --- a/lib/AST/ASTGateOpBuilder.cpp +++ b/lib/AST/ASTGateOpBuilder.cpp @@ -16,6 +16,7 @@ * ============================================================================= */ +#include #include #include #include @@ -26,6 +27,15 @@ namespace QASM { ASTGateQOpList *ASTGateOpBuilder::GLP; ASTGateOpBuilder ASTGateOpBuilder::B; +std::vector ASTGateOpBuilder::GLV; + +// GateEOp construction always creates an op node; bare GateUOp relies on that +// append. Under ctrl/negctrl the modifier statement is the list entry, so skip +// appending the target here to avoid a bare sibling duplicate. +static void AppendUnlessControlTarget(ASTGateQOpNode *Op) { + if (!ASTGateContextBuilder::Instance().InControlModifier()) + ASTGateOpBuilder::Instance().Append(Op); +} ASTGateQOpNode * ASTGateOpBuilder::CreateASTQGateOpNode(const ASTIdentifierNode *Id, @@ -36,7 +46,7 @@ ASTGateOpBuilder::CreateASTQGateOpNode(const ASTIdentifierNode *Id, ASTGateQOpNode *QG = new ASTGateQOpNode(Id, GateNode); assert(QG && "Failed to create an ASTHGateOpNode!"); - ASTGateOpBuilder::Instance().Append(QG); + AppendUnlessControlTarget(QG); return QG; } @@ -49,7 +59,7 @@ ASTGateOpBuilder::CreateASTGenericGateOpNode(const ASTIdentifierNode *Id, ASTGenericGateOpNode *GG = new ASTGenericGateOpNode(Id, GateNode); assert(GG && "Failed to create an ASTGenericGateOpNode!"); - ASTGateOpBuilder::Instance().Append(GG); + AppendUnlessControlTarget(GG); return GG; } @@ -61,7 +71,7 @@ ASTGenericGateOpNode *ASTGateOpBuilder::CreateASTGenericDefcalOpNode( ASTGenericGateOpNode *GG = new ASTGenericGateOpNode(Id, DefcalNode); assert(GG && "Failed to create an ASTGenericGateOpNode!"); - ASTGateOpBuilder::Instance().Append(GG); + AppendUnlessControlTarget(GG); return GG; } @@ -74,7 +84,7 @@ ASTGateOpBuilder::CreateASTHGateOpNode(const ASTIdentifierNode *Id, ASTHGateOpNode *HG = new ASTHGateOpNode(Id, GateNode); assert(HG && "Failed to create an ASTHGateOpNode!"); - ASTGateOpBuilder::Instance().Append(HG); + AppendUnlessControlTarget(HG); return HG; } @@ -87,7 +97,7 @@ ASTGateOpBuilder::CreateASTCXGateOpNode(const ASTIdentifierNode *Id, ASTCXGateOpNode *CXG = new ASTCXGateOpNode(Id, GateNode); assert(CXG && "Failed to create an ASTCXGateOpNode!"); - ASTGateOpBuilder::Instance().Append(CXG); + AppendUnlessControlTarget(CXG); return CXG; } @@ -100,7 +110,7 @@ ASTGateOpBuilder::CreateASTCCXGateOpNode(const ASTIdentifierNode *Id, ASTCCXGateOpNode *CCXG = new ASTCCXGateOpNode(Id, GateNode); assert(CCXG && "Failed to create an ASTCCXGateOpNode!"); - ASTGateOpBuilder::Instance().Append(CCXG); + AppendUnlessControlTarget(CCXG); return CCXG; } @@ -113,7 +123,7 @@ ASTGateOpBuilder::CreateASTCNotGateOpNode(const ASTIdentifierNode *Id, ASTCNotGateOpNode *CNG = new ASTCNotGateOpNode(Id, GateNode); assert(CNG && "Failed to create an ASTCNotGateOpNode!"); - ASTGateOpBuilder::Instance().Append(CNG); + AppendUnlessControlTarget(CNG); return CNG; } @@ -126,7 +136,7 @@ ASTGateOpBuilder::CreateASTUGateOpNode(const ASTIdentifierNode *Id, ASTUGateOpNode *UG = new ASTUGateOpNode(Id, GateNode); assert(UG && "Failed to create an ASTUGateOpNode!"); - ASTGateOpBuilder::Instance().Append(UG); + AppendUnlessControlTarget(UG); return UG; } diff --git a/lib/AST/ASTGateQubitParamBuilder.cpp b/lib/AST/ASTGateOperandParamBuilder.cpp similarity index 77% rename from lib/AST/ASTGateQubitParamBuilder.cpp rename to lib/AST/ASTGateOperandParamBuilder.cpp index 510e584..6c20e36 100644 --- a/lib/AST/ASTGateQubitParamBuilder.cpp +++ b/lib/AST/ASTGateOperandParamBuilder.cpp @@ -16,18 +16,18 @@ * ============================================================================= */ -#include +#include #include #include namespace QASM { -ASTIdentifierList ASTGateQubitParamBuilder::IL; -ASTGateQubitParamBuilder ASTGateQubitParamBuilder::GQB; -ASTIdentifierList *ASTGateQubitParamBuilder::ILP; -std::vector ASTGateQubitParamBuilder::ILV; +ASTIdentifierList ASTGateOperandParamBuilder::IL; +ASTGateOperandParamBuilder ASTGateOperandParamBuilder::GQB; +ASTIdentifierList *ASTGateOperandParamBuilder::ILP; +std::vector ASTGateOperandParamBuilder::ILV; -void ASTGateQubitParamBuilder::ReleaseQubits() { +void ASTGateOperandParamBuilder::ReleaseQubits() { for (ASTIdentifierList::const_iterator I = ILP->begin(); I != ILP->end(); ++I) { const ASTSymbolTableEntry *STE = ASTSymbolTable::Instance().LookupLocal(*I); @@ -35,7 +35,7 @@ void ASTGateQubitParamBuilder::ReleaseQubits() { switch (STE->GetValueType()) { default: break; - case ASTTypeGateQubitParam: + case ASTTypeGateOperandParam: ASTSymbolTable::Instance().EraseLocalQubit((*I)->GetName()); break; } @@ -43,7 +43,7 @@ void ASTGateQubitParamBuilder::ReleaseQubits() { } } -void ASTGateQubitParamBuilder::SetGateLocal() { +void ASTGateOperandParamBuilder::SetGateLocal() { for (ASTIdentifierList::iterator I = ILP->begin(); I != ILP->end(); ++I) { ASTSymbolTableEntry *STE = const_cast( ASTSymbolTable::Instance().LookupLocal(*I)); @@ -57,9 +57,9 @@ void ASTGateQubitParamBuilder::SetGateLocal() { (*I)->SetBits(1); (*I)->SetGateLocal(); (*I)->SetLocalScope(); - (*I)->SetSymbolType(ASTTypeGateQubitParam); + (*I)->SetSymbolType(ASTTypeGateOperandParam); STE->SetLocalScope(); - STE->SetValueType(ASTTypeGateQubitParam); + STE->SetValueType(ASTTypeGateOperandParam); break; } } diff --git a/lib/AST/ASTGateOps.cpp b/lib/AST/ASTGateOps.cpp index cad5603..c7f6861 100644 --- a/lib/AST/ASTGateOps.cpp +++ b/lib/AST/ASTGateOps.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -69,6 +70,16 @@ ASTGateOpNode::ASTGateOpNode(const ASTIdentifierNode *Id, : ASTStatementNode(Id, GNCN), IsDefcal(false), MTy(GNCN->GetASTType()), OTy(GNCN ? GNCN->GetASTType() : ASTTypeGateNegControl) {} +ASTGateOpNode::ASTGateOpNode(const ASTIdentifierNode *Id, + const ASTGateFockControlNode *GFCN) + : ASTStatementNode(Id, GFCN), IsDefcal(false), MTy(GFCN->GetASTType()), + OTy(GFCN ? GFCN->GetASTType() : ASTTypeGateFockControl) {} + +ASTGateOpNode::ASTGateOpNode(const ASTIdentifierNode *Id, + const ASTGateFockNegControlNode *GFNCN) + : ASTStatementNode(Id, GFNCN), IsDefcal(false), MTy(GFNCN->GetASTType()), + OTy(GFNCN ? GFNCN->GetASTType() : ASTTypeGateFockNegControl) {} + ASTGateOpNode::ASTGateOpNode(const ASTIdentifierNode *Id, const ASTGatePowerNode *GPN) : ASTStatementNode(Id, GPN), IsDefcal(false), MTy(GPN->GetASTType()), @@ -171,6 +182,12 @@ ASTGateQOpNode::ASTGateQOpNode(const ASTGateControlNode *GCN) ASTGateQOpNode::ASTGateQOpNode(const ASTGateNegControlNode *GNCN) : ASTGateOpNode(GNCN->GetIdentifier(), GNCN) {} +ASTGateQOpNode::ASTGateQOpNode(const ASTGateFockControlNode *GFCN) + : ASTGateOpNode(GFCN->GetIdentifier(), GFCN) {} + +ASTGateQOpNode::ASTGateQOpNode(const ASTGateFockNegControlNode *GFNCN) + : ASTGateOpNode(GFNCN->GetIdentifier(), GFNCN) {} + ASTGateQOpNode::ASTGateQOpNode(const ASTGatePowerNode *GPN) : ASTGateOpNode(GPN->GetIdentifier(), GPN) {} @@ -647,9 +664,9 @@ void ASTGateGPhaseExpressionNode::Mangle() { } assert(QSTE && "Could not obtain a valid SymbolTable Entry!"); - ASTGateQubitParamNode *GQP = - QSTE->GetValue()->GetValue(); - assert(GQP && "Could not obtain a valid ASTGateQubitParamNode!"); + ASTGateOperandParamNode *GQP = + QSTE->GetValue()->GetValue(); + assert(GQP && "Could not obtain a valid ASTGateOperandParamNode!"); GQP->Mangle(); } diff --git a/lib/AST/ASTGateType.cpp b/lib/AST/ASTGateType.cpp new file mode 100644 index 0000000..f59df04 --- /dev/null +++ b/lib/AST/ASTGateType.cpp @@ -0,0 +1,365 @@ +/* -*- coding: utf-8 -*- + * + * Copyright 2023 IBM RESEARCH. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +#include +#include +#include +#include +#include + +#include +#include +#include + +namespace QASM { + +namespace { + +ASTType ResolveCallClassicalArgType(const ASTArgumentNode *Arg) { + assert(Arg && "Invalid ASTArgumentNode!"); + ASTType Ty = Arg->GetValueType(); + if (Ty != ASTTypeIdentifier && Ty != ASTTypeIdentifierRef) + return Ty; + + try { + const ASTExpressionNode *EN = + std::any_cast(Arg->GetValue()); + if (!EN) + return Ty; + const ASTIdentifierNode *Id = EN->DynCast(); + if (!Id) + return Ty; + + const ASTSymbolTableEntry *STE = + ASTSymbolTable::Instance().FindLocal(Id->GetName()); + if (!STE) + STE = ASTSymbolTable::Instance().FindGlobal(Id->GetName()); + if (!STE) + STE = ASTSymbolTable::Instance().FindAngle(Id->GetName()); + if (!STE) + STE = Id->GetSymbolTableEntry(); + if (STE) + return STE->GetValueType(); + } catch (...) { + } + return Ty; +} + +ASTType ResolveElementType(const ASTExpressionNode *EN) { + assert(EN && "Invalid ASTExpressionNode!"); + ASTType ElTy = EN->GetASTType(); + if (ElTy == ASTTypeIdentifier || ElTy == ASTTypeIdentifierRef) { + if (const ASTIdentifierNode *EId = EN->GetIdentifier()) { + ElTy = EId->GetSymbolType(); + if (const ASTSymbolTableEntry *ESTE = EId->GetSymbolTableEntry()) + ElTy = ESTE->GetValueType(); + } + } + return ElTy; +} + +bool IsComplexCompatibleCallArg(ASTType ArgTy) { + switch (ArgTy) { + case ASTTypeMPComplex: + case ASTTypeComplexExpression: + case ASTTypeBinaryOp: + case ASTTypeUnaryOp: + case ASTTypeFloat: + case ASTTypeDouble: + case ASTTypeMPDecimal: + case ASTTypeInt: + case ASTTypeUInt: + case ASTTypeMPInteger: + case ASTTypeMPUInteger: + case ASTTypeAngle: + case ASTTypeLambdaAngle: + case ASTTypePhiAngle: + case ASTTypeThetaAngle: + return true; + default: + return false; + } +} + +bool IsScalarCompatibleCallArg(ASTType ArgTy) { + switch (ArgTy) { + case ASTTypeFloat: + case ASTTypeDouble: + case ASTTypeMPDecimal: + case ASTTypeInt: + case ASTTypeUInt: + case ASTTypeMPInteger: + case ASTTypeMPUInteger: + case ASTTypeBool: + case ASTTypeBitset: + case ASTTypeDuration: + case ASTTypeAngle: + case ASTTypeLambdaAngle: + case ASTTypePhiAngle: + case ASTTypeThetaAngle: + case ASTTypeBinaryOp: + case ASTTypeUnaryOp: + return true; + default: + return false; + } +} + +std::optional LiteralArraySize(const ASTArgumentNode *Arg) { + if (!Arg || !Arg->IsExpression()) + return std::nullopt; + + const ASTExpressionNode *AEN = nullptr; + try { + AEN = std::any_cast(Arg->GetValue()); + } catch (...) { + } + if (!AEN) { + try { + AEN = std::any_cast(Arg->GetValue()); + } catch (...) { + return std::nullopt; + } + } + if (!AEN) + return std::nullopt; + if (const ASTAngleArrayNode *AAN = + dynamic_cast(AEN)) + return AAN->Size(); + if (const ASTMPComplexArrayNode *CAN = + dynamic_cast(AEN)) + return CAN->Size(); + if (const ASTArrayNode *ARN = dynamic_cast(AEN)) + return ARN->Size(); + return std::nullopt; +} + +const ASTIdentifierNode *CallArgIdentifier(const ASTArgumentNode *Arg) { + if (!Arg || !Arg->IsExpression()) + return nullptr; + const ASTExpressionNode *EN = nullptr; + try { + EN = std::any_cast(Arg->GetValue()); + } catch (...) { + } + if (!EN) { + try { + EN = std::any_cast(Arg->GetValue()); + } catch (...) { + return nullptr; + } + } + if (!EN) + return nullptr; + return EN->DynCast(); +} + +const ASTSymbolTableEntry *LookupArgSymbol(const ASTIdentifierNode *Id) { + if (!Id) + return nullptr; + const ASTSymbolTableEntry *STE = + ASTSymbolTable::Instance().FindLocal(Id->GetName()); + if (!STE) + STE = ASTSymbolTable::Instance().FindGlobal(Id->GetName()); + if (!STE) + STE = ASTSymbolTable::Instance().FindAngle(Id->GetName()); + if (!STE) + STE = Id->GetSymbolTableEntry(); + return STE; +} + +const ASTArrayNode *ArrayNodeFromSTE(const ASTSymbolTableEntry *STE) { + if (!STE || !STE->HasValue()) + return nullptr; + switch (STE->GetValueType()) { + case ASTTypeAngleArray: + case ASTTypeFloatArray: + case ASTTypeMPDecimalArray: + case ASTTypeMPComplexArray: + case ASTTypeIntArray: + case ASTTypeBoolArray: + case ASTTypeCBitArray: + case ASTTypeQubitArray: + case ASTTypeDurationArray: + return STE->GetValue()->GetValue(); + default: + return nullptr; + } +} + +/// Size of a call arg that is an array literal *or* a named array variable. +std::optional CallArgArraySize(const ASTArgumentNode *Arg) { + if (std::optional Lit = LiteralArraySize(Arg)) + return Lit; + const ASTIdentifierNode *Id = CallArgIdentifier(Arg); + if (!Id) + return std::nullopt; + const ASTArrayNode *ARN = ArrayNodeFromSTE(LookupArgSymbol(Id)); + if (!ARN || ARN->Size() == 0U) + return std::nullopt; + return ARN->Size(); +} + +/// Named array with a declared type but no initializer list. +bool CallArgUninitializedArray(const ASTArgumentNode *Arg) { + const ASTIdentifierNode *Id = CallArgIdentifier(Arg); + if (!Id) + return false; + const ASTArrayNode *ARN = ArrayNodeFromSTE(LookupArgSymbol(Id)); + return ARN && !ARN->HasInitializerList(); +} + +} // namespace + +bool ASTGateType::IsRealArrayFamily() const { + return Ty == ASTTypeAngleArray || Ty == ASTTypeFloatArray || + Ty == ASTTypeMPDecimalArray; +} + +bool ASTGateType::IsComplexArray() const { return Ty == ASTTypeMPComplexArray; } + +bool ASTGateType::IsArray() const { + return IsRealArrayFamily() || IsComplexArray(); +} + +bool ASTGateType::IsComplexScalar() const { return Ty == ASTTypeMPComplex; } + +bool ASTGateType::IsRealScalarFamily() const { + switch (Ty) { + case ASTTypeFloat: + case ASTTypeDouble: + case ASTTypeMPDecimal: + case ASTTypeInt: + case ASTTypeUInt: + case ASTTypeMPInteger: + case ASTTypeMPUInteger: + case ASTTypeBool: + case ASTTypeBitset: + case ASTTypeDuration: + case ASTTypeAngle: + case ASTTypeLambdaAngle: + case ASTTypePhiAngle: + case ASTTypeThetaAngle: + return true; + default: + return false; + } +} + +ASTGateType ASTGateType::ClassifyFormal(ASTType Ty, + std::optional Size) { + if (Ty == ASTTypeAngleArray || Ty == ASTTypeFloatArray || + Ty == ASTTypeMPDecimalArray || Ty == ASTTypeMPComplexArray) + return ASTGateType(Ty, Size); + return ASTGateType(Ty, std::nullopt); +} + +ASTGateType ASTGateType::ClassifyArg(const ASTArgumentNode *Arg) { + assert(Arg && "Invalid ASTArgumentNode!"); + ASTType Ty = ResolveCallClassicalArgType(Arg); + std::optional SZ = CallArgArraySize(Arg); + if (Ty == ASTTypeAngleArray || Ty == ASTTypeFloatArray || + Ty == ASTTypeMPDecimalArray || Ty == ASTTypeMPComplexArray) + return ASTGateType(Ty, SZ); + return ASTGateType(Ty, std::nullopt); +} + +bool ASTGateType::ArgIsUninitializedArray(const ASTArgumentNode *Arg) { + return CallArgUninitializedArray(Arg); +} + +const ASTIdentifierNode * +ASTGateType::ArgIdentifier(const ASTArgumentNode *Arg) { + return CallArgIdentifier(Arg); +} + +bool ASTGateType::Compatible(const ASTGateType &F, const ASTGateType &A) { + if (F.HasArraySize() && A.HasArraySize() && + F.GetArraySize() != A.GetArraySize()) + return false; + + if (F.IsComplexScalar()) { + if (A.IsRealArrayFamily() || A.IsComplexArray()) + return false; + return IsComplexCompatibleCallArg(A.GetType()); + } + + if (F.IsRealArrayFamily()) { + if (A.IsComplexArray()) + return false; + return A.IsRealArrayFamily(); + } + + if (F.IsComplexArray()) + return A.IsComplexArray() || A.IsRealArrayFamily(); + + if (F.IsRealScalarFamily()) { + if (A.IsArray() || A.IsComplexScalar() || + A.GetType() == ASTTypeComplexExpression) + return false; + return IsScalarCompatibleCallArg(A.GetType()); + } + + return false; +} + +bool ASTGateType::ArgHasComplexElements(const ASTArgumentNode *Arg) { + if (!Arg || !Arg->IsExpression()) + return false; + + const ASTExpressionNode *AEN = nullptr; + try { + AEN = std::any_cast(Arg->GetValue()); + } catch (...) { + } + if (!AEN) { + try { + AEN = std::any_cast(Arg->GetValue()); + } catch (...) { + return false; + } + } + if (!AEN) + return false; + const ASTAngleArrayNode *AAN = dynamic_cast(AEN); + if (!AAN) + return false; + for (unsigned J = 0; J < AAN->Size(); ++J) { + const ASTAngleNode *AN = AAN->GetElement(J); + if (AN && + ASTExpressionValidator::Instance().IsComplexType(AN->GetExprType())) + return true; + } + return false; +} + +bool ASTGateType::ExpressionListHasComplex(const ASTExpressionList *EL) { + if (!EL) + return false; + for (ASTExpressionList::const_iterator I = EL->begin(); I != EL->end(); ++I) { + const ASTExpressionNode *EN = dynamic_cast(*I); + if (!EN) + continue; + if (ASTExpressionValidator::Instance().IsComplexType( + ResolveElementType(EN))) + return true; + } + return false; +} + +} // namespace QASM diff --git a/lib/AST/ASTGates.cpp b/lib/AST/ASTGates.cpp index 3a69454..f7ac55d 100644 --- a/lib/AST/ASTGates.cpp +++ b/lib/AST/ASTGates.cpp @@ -22,9 +22,11 @@ #include #include #include +#include #include #include #include +#include #include #include #include @@ -45,9 +47,225 @@ ASTGateQOpList ASTGateQOpList::EmptyDefault; ASTGateContextBuilder ASTGateContextBuilder::GCB; bool ASTGateContextBuilder::GCS = false; +unsigned ASTGateContextBuilder::CMDepth = 0U; +const ASTToken *ASTGateContextBuilder::CMTok = nullptr; + +ASTGateTemplateParamBuilder ASTGateTemplateParamBuilder::TPB; using DiagLevel = QASM::QasmDiagnosticEmitter::DiagLevel; +namespace { + +bool IsDispGateIdentifier(const ASTIdentifierNode *Id) { + return Id && + (Id->GetName() == u8"disp" || Id->GetSymbolType() == ASTTypeDispGate); +} + +bool ExpressionInvolvesComplex(const ASTExpressionNode *EN) { + if (!EN) + return false; + + switch (EN->GetASTType()) { + case ASTTypeMPComplex: + case ASTTypeComplexExpression: + return true; + case ASTTypeIdentifier: + case ASTTypeIdentifierRef: { + const ASTIdentifierNode *XId = EN->GetIdentifier(); + if (!XId) + return false; + if (XId->GetSymbolType() == ASTTypeMPComplex || + XId->GetSymbolType() == ASTTypeMPComplexArray) + return true; + if (const ASTSymbolTableEntry *STE = XId->GetSymbolTableEntry()) + return STE->GetValueType() == ASTTypeMPComplex || + STE->GetValueType() == ASTTypeMPComplexArray; + return false; + } + case ASTTypeBinaryOp: { + const ASTBinaryOpNode *B = dynamic_cast(EN); + return B && (ExpressionInvolvesComplex(B->GetLeft()) || + ExpressionInvolvesComplex(B->GetRight())); + } + case ASTTypeUnaryOp: { + const ASTUnaryOpNode *U = dynamic_cast(EN); + return U && ExpressionInvolvesComplex(U->GetExpression()); + } + case ASTTypeOpndTy: { + const ASTOperandNode *Op = dynamic_cast(EN); + if (!Op) + return false; + if (Op->IsIdentifier()) { + const ASTIdentifierNode *TId = Op->GetTargetIdentifier(); + if (!TId) + return false; + if (TId->GetSymbolType() == ASTTypeMPComplex || + TId->GetSymbolType() == ASTTypeMPComplexArray) + return true; + if (const ASTSymbolTableEntry *STE = TId->GetSymbolTableEntry()) + return STE->GetValueType() == ASTTypeMPComplex || + STE->GetValueType() == ASTTypeMPComplexArray; + return false; + } + return ExpressionInvolvesComplex(Op->GetExpression()); + } + default: + return false; + } +} + +bool PreferComplexGateParam(const ASTIdentifierNode *GateId, + const ASTExpressionNode *EN) { + return IsDispGateIdentifier(GateId) || ExpressionInvolvesComplex(EN); +} + +} // namespace + +ASTMPComplexNode * +ASTGateNode::MaterializeComplexParamExpr(unsigned Index, + const ASTExpressionNode *EN) { + assert(EN && "Invalid expression for complex gate Param!"); + + std::stringstream SCN; + SCN << ASTDemangler::TypeName(ASTTypeMPComplex) << Index; + ASTIdentifierNode *CId = ASTBuilder::Instance().CreateASTIdentifierNode( + SCN.str(), ASTMPComplexNode::DefaultBits, ASTTypeMPComplex); + assert(CId && "Could not create a Complex ASTIdentifierNode!"); + + std::stringstream CES; + CES << "complexexpression" << Index; + ASTIdentifierNode *CEId = ASTBuilder::Instance().CreateASTIdentifierNode( + CES.str(), ASTMPComplexNode::DefaultBits, ASTTypeComplexExpression); + assert(CEId && "Could not create a ComplexExpression ASTIdentifierNode!"); + + ASTComplexExpressionNode *CE = nullptr; + if (const ASTBinaryOpNode *BOP = dynamic_cast(EN)) + CE = ASTBuilder::Instance().CreateASTComplexExpressionNode(CEId, BOP); + else if (const ASTUnaryOpNode *UOP = dynamic_cast(EN)) + CE = ASTBuilder::Instance().CreateASTComplexExpressionNode(CEId, UOP); + assert(CE && "Could not create a valid ASTComplexExpressionNode!"); + + // Keep Expr without Evaluate: alpha/2 is not a real+imag literal pair. + ASTMPComplexNode *MPC = ASTBuilder::Instance().CreateASTMPComplexNode( + CId, ASTMPComplexNode::DefaultBits); + assert(MPC && "Could not create a valid ASTMPComplexNode!"); + MPC->AttachExpression(CE); + + CId->SetPolymorphicName(SCN.str()); + MPC->Mangle(); + MPC->MangleLiteral(); + ToGateParamSymbolTable(CId, CId->GetSymbolTableEntry()); + return MPC; +} + +bool ASTGateNode::FormalWantsComplex(unsigned Index) const { + if (Index < FormalParamTypes.size() && + FormalParamTypes[Index] == ASTTypeMPComplex) + return true; + // Builtin disp always expects a complex scalar at parameter 0. + if (GateCall && IsDispGateIdentifier(GetIdentifier()) && Index == 0U) + return true; + return false; +} + +bool ASTGateNode::FormalWantsFloatScalar(unsigned Index) const { + if (Index >= FormalParamTypes.size()) + return false; + ASTType T = FormalParamTypes[Index]; + return T == ASTTypeFloat || T == ASTTypeDouble || T == ASTTypeMPDecimal; +} + +bool ASTGateNode::FormalWantsFloatArray(unsigned Index) const { + if (Index >= FormalParamTypes.size()) + return false; + ASTType T = FormalParamTypes[Index]; + return T == ASTTypeFloatArray || T == ASTTypeMPDecimalArray; +} + +ASTMPDecimalArrayNode * +ASTGateNode::MaterializeMPDecimalArrayFromAngles(unsigned Index, + const ASTAngleArrayNode *AAN) { + assert(AAN && "Invalid AngleArray for float-array materialization!"); + + const unsigned Bits = ASTMPDecimalNode::DefaultBits; + std::vector Decimals; + Decimals.reserve(AAN->Size()); + + for (unsigned I = 0; I < AAN->Size(); ++I) { + const ASTAngleNode *AN = AAN->GetElement(I); + assert(AN && "AngleArray element is null!"); + + std::stringstream SN; + SN << "ast-gate-array-mpdecimal-" << Index << '-' << I; + ASTIdentifierNode *EId = ASTBuilder::Instance().CreateASTIdentifierNode( + SN.str(), Bits, ASTTypeMPDecimal); + assert(EId && "Could not create an MPDecimal ASTIdentifierNode!"); + + ASTMPDecimalNode *MPD = nullptr; + if (AN->IsExpression()) { + const ASTExpressionNode *E = AN->GetExpression(); + assert(E && "Angle expression is null!"); + MPD = ASTBuilder::Instance().CreateASTMPDecimalNodeFromExpression( + EId, Bits, E); + } else { + MPD = ASTBuilder::Instance().CreateASTMPDecimalNode(EId, Bits, + AN->GetMPValue()); + } + assert(MPD && "Could not materialize MPDecimal from AngleArray element!"); + + MPD->Mangle(); + MPD->MangleLiteral(); + Decimals.push_back(MPD); + } + + std::stringstream ArrName; + ArrName << "ast-gate-mpdecimal-array-lit-" << Decimals.size(); + ASTIdentifierNode *ArrId = + new ASTIdentifierNode(ArrName.str(), ASTTypeMPDecimalArray, + static_cast(Decimals.size())); + assert(ArrId && "Could not create an MPDecimal Array ASTIdentifierNode!"); + ArrId->SetPolymorphicName("gatearraympdecimal"); + + ASTMPDecimalArrayNode *MDAN = + new ASTMPDecimalArrayNode(ArrId, Decimals, Bits); + assert(MDAN && "Could not create a valid ASTMPDecimalArrayNode!"); + MDAN->Mangle(); + (void)Index; + return MDAN; +} + +ASTMPComplexNode * +ASTGateNode::MaterializeComplexFromReal(unsigned Index, + const ASTMPDecimalNode *R) { + assert(R && "Invalid real part for complex gate Param!"); + + std::stringstream SCN; + SCN << ASTDemangler::TypeName(ASTTypeMPComplex) << Index; + ASTIdentifierNode *CId = ASTBuilder::Instance().CreateASTIdentifierNode( + SCN.str(), ASTMPComplexNode::DefaultBits, ASTTypeMPComplex); + assert(CId && "Could not create a Complex ASTIdentifierNode!"); + + std::stringstream ISN; + ISN << "complex-im-" << Index; + ASTIdentifierNode *IId = ASTBuilder::Instance().CreateASTIdentifierNode( + ISN.str(), ASTMPDecimalNode::DefaultBits, ASTTypeMPDecimal); + assert(IId && "Could not create an Imaginary ASTIdentifierNode!"); + + ASTMPDecimalNode *Imag = ASTBuilder::Instance().CreateASTMPDecimalNode( + IId, ASTMPDecimalNode::DefaultBits, 0.0); + assert(Imag && "Could not create a zero imaginary ASTMPDecimalNode!"); + + ASTMPComplexNode *MPC = ASTBuilder::Instance().CreateASTMPComplexNode( + CId, R, Imag, ASTOpTypeAdd, ASTMPComplexNode::DefaultBits); + assert(MPC && "Could not create a valid ASTMPComplexNode!"); + + CId->SetPolymorphicName(SCN.str()); + MPC->Mangle(); + MPC->MangleLiteral(); + ToGateParamSymbolTable(CId, CId->GetSymbolTableEntry()); + return MPC; +} + void ASTGateNode::ToGateParamSymbolTable(const ASTIdentifierNode *Id, const ASTSymbolTableEntry *STE) { assert(Id && "Invalid ASTIdentifierNode argument!"); @@ -119,9 +337,9 @@ void ASTGateNode::ToGateParamSymbolTable(const ASTIdentifierNode *Id, } ASTSymbolTableEntry * -ASTGateNode::MangleGateQubitParam(ASTIdentifierNode *Id, - ASTSymbolTableEntry *&STE, unsigned IX, - unsigned Bits, unsigned QBits) { +ASTGateNode::MangleGateOperandParam(ASTIdentifierNode *Id, + ASTSymbolTableEntry *&STE, unsigned IX, + unsigned Bits, unsigned QBits) { assert(Id && "Invalid ASTIdentifierNode argument!"); if (!STE) { @@ -156,34 +374,34 @@ ASTGateNode::MangleGateQubitParam(ASTIdentifierNode *Id, QN->Mangle(); } break; - case ASTTypeGateQubitParam: { - ASTGateQubitParamNode *QPN = nullptr; + case ASTTypeGateOperandParam: { + ASTGateOperandParamNode *QPN = nullptr; if (!STE->HasValue()) { - QPN = new ASTGateQubitParamNode(Id, IX, Bits, QNS.str()); - assert(QPN && "Could not create a valid ASTQubitParamNode!"); + QPN = new ASTGateOperandParamNode(Id, IX, Bits, QNS.str()); + assert(QPN && "Could not create a valid ASTGateOperandParamNode!"); STE->ResetValue(); STE->SetValue(new ASTValue<>(QPN, QTy), QTy); assert(STE->HasValue() && "Qubit SymbolTable Entry has no Value!"); } else { - QPN = STE->GetValue()->GetValue(); + QPN = STE->GetValue()->GetValue(); if (!QPN) { std::map::iterator QI = GSTM.find(Id->GetName()); if (QI == GSTM.end()) { - QPN = new ASTGateQubitParamNode(Id, IX, Bits, QNS.str()); - assert(QPN && "Could not create a valid ASTQubitParamNode!"); + QPN = new ASTGateOperandParamNode(Id, IX, Bits, QNS.str()); + assert(QPN && "Could not create a valid ASTGateOperandParamNode!"); STE->ResetValue(); STE->SetValue(new ASTValue<>(QPN, QTy), QTy); assert(STE->HasValue() && "Qubit SymbolTable Entry has no Value!"); - } else if ((*QI).second->GetValueType() == ASTTypeGateQubitParam) { - QPN = (*QI).second->GetValue()->GetValue(); - assert(QPN && "Could not create a valid ASTGateQubitParamNode!"); + } else if ((*QI).second->GetValueType() == ASTTypeGateOperandParam) { + QPN = (*QI).second->GetValue()->GetValue(); + assert(QPN && "Could not create a valid ASTGateOperandParamNode!"); } else { std::stringstream M; M << "Identifier '" << Id->GetName() << "' already exists " << "in the Gate's SymbolTable but with a different Type (" << PrintTypeEnum((*QI).second->GetValueType()) << " vs. " - << PrintTypeEnum(ASTTypeGateQubitParam) << ")."; + << PrintTypeEnum(ASTTypeGateOperandParam) << ")."; QasmDiagnosticEmitter::Instance().EmitDiagnostic( DIAGLineCounter::Instance().GetLocation(Id), M.str(), DiagLevel::ICE); @@ -224,6 +442,36 @@ ASTGateNode::MangleGateQubitParam(ASTIdentifierNode *Id, assert(QCAN && "Could not obtain a valid ASTQubitContainerAliasNode!"); QCAN->Mangle(); } break; + case ASTTypeQumode: { + ASTQumodeNode *QN = nullptr; + if (!STE->HasValue()) { + QN = new ASTQumodeNode(Id, IX, QNS.str()); + assert(QN && "Could not create a valid ASTQumodeNode!"); + STE->ResetValue(); + STE->SetValue(new ASTValue<>(QN, QTy), QTy); + assert(STE->HasValue() && "Qumode SymbolTable Entry has no Value!"); + } else { + QN = STE->GetValue()->GetValue(); + assert(QN && "Could not obtain a valid ASTQumodeNode!"); + } + + QN->Mangle(); + } break; + case ASTTypeQumodeContainer: { + ASTQumodeContainerNode *QCN = nullptr; + if (!STE->HasValue()) { + QCN = new ASTQumodeContainerNode(Id, Bits == 0U ? 1U : Bits); + assert(QCN && "Could not create a valid ASTQumodeContainerNode!"); + STE->ResetValue(); + STE->SetValue(new ASTValue<>(QCN, QTy), QTy); + assert(STE->HasValue() && "Qumode SymbolTable Entry has no Value!"); + } else { + QCN = STE->GetValue()->GetValue(); + assert(QCN && "Could not obtain a valid ASTQumodeContainerNode!"); + } + + QCN->Mangle(); + } break; default: { std::stringstream M; M << "Impossible initialization of gate qubit parameter from " @@ -409,8 +657,8 @@ void ASTGateNode::ClearLocalGateSymbols() const { std::map::const_iterator MI; for (MI = GSTM.begin(); MI != GSTM.end(); ++MI) { if ((*MI).second) { - if ((*MI).second->GetValueType() == ASTTypeGateQubitParam) - ASTSymbolTable::Instance().EraseGateQubitParam( + if ((*MI).second->GetValueType() == ASTTypeGateOperandParam) + ASTSymbolTable::Instance().EraseGateOperandParam( (*MI).second->GetIdentifier()); ASTSymbolTable::Instance().EraseLocalSymbol( @@ -418,20 +666,46 @@ void ASTGateNode::ClearLocalGateSymbols() const { (*MI).second->GetIdentifier()->GetBits(), (*MI).second->GetValueType()); } else { - ASTSymbolTable::Instance().EraseGateQubitParam((*MI).first); + ASTSymbolTable::Instance().EraseGateOperandParam((*MI).first); ASTSymbolTable::Instance().EraseLocalSymbol((*MI).first); } } } -void ASTGateNode::ClearGateQubits() const { - for (std::vector::const_iterator QI = Qubits.begin(); - QI != Qubits.end(); ++QI) { +ASTType ASTGateNode::ResolveOperandQuantumType(const ASTIdentifierNode *QId, + unsigned Index) const { + if (Index < FormalQuantumTypes.size()) { + const ASTType FTy = FormalQuantumTypes[Index]; + if (FTy == ASTTypeQubit || FTy == ASTTypeQumode) + return FTy; + } + + if (QId) { + const ASTType PTy = QId->GetPolymorphicType(); + if (PTy == ASTTypeQubit || PTy == ASTTypeQumode) + return PTy; + + const ASTType STy = QId->GetSymbolType(); + if (STy == ASTTypeQumode || STy == ASTTypeQumodeContainer) + return ASTTypeQumode; + if (STy == ASTTypeQubit || STy == ASTTypeQubitContainer || + STy == ASTTypeQubitContainerAlias) + return ASTTypeQubit; + } + + return ASTTypeQubit; +} + +void ASTGateNode::ClearGateOperands() const { + for (std::vector::const_iterator QI = Operands.begin(); + QI != Operands.end(); ++QI) { switch ((*QI)->GetASTType()) { case ASTTypeQubit: case ASTTypeQubitContainer: case ASTTypeQubitContainerAlias: - case ASTTypeGateQubitParam: + case ASTTypeQumode: + case ASTTypeQumodeContainer: + case ASTTypeGateOperandParam: ASTSymbolTable::Instance().EraseGateLocalQubit((*QI)->GetName()); break; default: @@ -487,7 +761,7 @@ void ASTGateNode::MaterializeBuiltinUGate(const ASTIdentifierNode *GId, AId->SetSymbolTableEntry(STE); ToGateParamSymbolTable(AId, STE); - Params.push_back(AN); + AddParam(ASTTypeAngle, AN); ASTSymbolTable::Instance().EraseLocalAngle(AId); } @@ -496,7 +770,7 @@ void ASTGateNode::MaterializeBuiltinUGate(const ASTIdentifierNode *GId, assert(QId && "Invalid Qubit ASTIdentifierNode!"); ASTSymbolTableEntry *STE = ASTSymbolTable::Instance().Lookup( - QId->GetName(), QId->GetBits(), ASTTypeGateQubitParam); + QId->GetName(), QId->GetBits(), ASTTypeGateOperandParam); assert(STE && "UGate Qubit Parameter has no SymbolTable Entry!"); QId->SetDeclarationContext(DCX); @@ -505,9 +779,9 @@ void ASTGateNode::MaterializeBuiltinUGate(const ASTIdentifierNode *GId, STE->SetLocalScope(); QId->SetSymbolTableEntry(STE); - MaterializeGateQubitParam(QId); - QCParams.push_back(STE); - STE = MangleGateQubitParam(QId, STE, 0, QId->GetBits(), QId->GetBits()); + MaterializeGateOperandParam(QId); + OperandParams.push_back(STE); + STE = MangleGateOperandParam(QId, STE, 0, QId->GetBits(), QId->GetBits()); ToGateParamSymbolTable(QId, STE); ASTSymbolTable::Instance().EraseLocalQubitParam(QId); } @@ -516,10 +790,17 @@ void ASTGateNode::MaterializeBuiltinUGate(const ASTIdentifierNode *GId, ASTGateNode::ASTGateNode(const ASTIdentifierNode *Id, const ASTArgumentNodeList &AL, const ASTAnyTypeList &QL, bool IsGateCall, - const ASTGateQOpList &OL) - : ASTExpressionNode(Id, ASTTypeGate), Params(), Qubits(), QCParams(), + const ASTGateQOpList &OL, + const std::vector *CallFormalParamTypes) + : ASTExpressionNode(Id, ASTTypeGate), Params(), Operands(), OperandParams(), OpList(OL), Ctrl(nullptr), GDId(IsGateCall ? nullptr : Id), GSTM(), - ControlType(ASTTypeUndefined), Opaque(false), GateCall(IsGateCall) { + ControlType(ASTTypeUndefined), Opaque(false), GateCall(IsGateCall), + FullyTyped(false), FormalParamTypes(), FormalParamArraySizes(), + FormalQuantumTypes(), TemplateParams(), + FormalParamArraySizeTemplateIndices() { + if (CallFormalParamTypes) + FormalParamTypes = *CallFormalParamTypes; + unsigned C = 0; std::set PNS; std::vector NQV; @@ -572,6 +853,179 @@ ASTGateNode::ASTGateNode(const ASTIdentifierNode *Id, DiagLevel::Error); } + // Complex variables are stored as-is; do not coerce to Angle. + if (XSTE && XSTE->HasValue() && + XSTE->GetValueType() == ASTTypeMPComplex) { + ASTMPComplexNode *XMPC = + XSTE->GetValue()->GetValue(); + assert(XMPC && "Could not obtain a valid ASTMPComplexNode!"); + + std::stringstream SCN; + SCN << ASTDemangler::TypeName(ASTTypeMPComplex) << C; + ASTIdentifierNode *CId = + ASTBuilder::Instance().CreateASTIdentifierNode( + SCN.str(), ASTMPComplexNode::DefaultBits, ASTTypeMPComplex); + assert(CId && "Could not create a Complex ASTIdentifierNode!"); + + ASTMPComplexNode *MPC = ASTBuilder::Instance().CreateASTMPComplexNode( + CId, XMPC, ASTMPComplexNode::DefaultBits); + assert(MPC && "Could not create a valid ASTMPComplexNode!"); + + CId->SetPolymorphicName(ID->GetName()); + MPC->Mangle(); + MPC->MangleLiteral(); + ToGateParamSymbolTable(CId, CId->GetSymbolTableEntry()); + AddParam(ASTTypeMPComplex, MPC); + PNS.insert(MPC->GetName()); + break; + } + + // Typed complex formal: promote real scalar identifiers to real+0i. + if (IsGateCall && FormalWantsComplex(C) && XSTE && XSTE->HasValue()) { + const ASTMPDecimalNode *R = nullptr; + ASTMPDecimalNode *OwnedR = nullptr; + if (XSTE->GetValueType() == ASTTypeMPDecimal) { + R = XSTE->GetValue()->GetValue(); + } else if (XSTE->GetValueType() == ASTTypeFloat) { + const ASTFloatNode *FLT = + XSTE->GetValue()->GetValue(); + if (FLT) { + std::stringstream RSN; + RSN << "complex-re-" << C; + ASTIdentifierNode *RId = + ASTBuilder::Instance().CreateASTIdentifierNode( + RSN.str(), ASTMPDecimalNode::DefaultBits, + ASTTypeMPDecimal); + OwnedR = ASTBuilder::Instance().CreateASTMPDecimalNode( + RId, ASTMPDecimalNode::DefaultBits, + static_cast(FLT->GetValue())); + R = OwnedR; + } + } else if (XSTE->GetValueType() == ASTTypeDouble) { + const ASTDoubleNode *DBL = + XSTE->GetValue()->GetValue(); + if (DBL) { + std::stringstream RSN; + RSN << "complex-re-" << C; + ASTIdentifierNode *RId = + ASTBuilder::Instance().CreateASTIdentifierNode( + RSN.str(), ASTMPDecimalNode::DefaultBits, + ASTTypeMPDecimal); + OwnedR = ASTBuilder::Instance().CreateASTMPDecimalNode( + RId, ASTMPDecimalNode::DefaultBits, DBL->GetValue()); + R = OwnedR; + } + } + if (R) { + ASTMPComplexNode *MPC = MaterializeComplexFromReal(C, R); + assert(MPC && "Could not materialize complex Param from id!"); + AddParam(ASTTypeMPComplex, MPC); + PNS.insert(MPC->GetName()); + break; + } + (void)OwnedR; + } + + // Named array / float-scalar args: keep type-faithful Params. + if (XSTE && XSTE->HasValue()) { + const ASTType VT = XSTE->GetValueType(); + if (VT == ASTTypeMPDecimalArray || VT == ASTTypeFloatArray || + VT == ASTTypeAngleArray || VT == ASTTypeMPComplexArray) { + ASTExpressionNode *Arr = nullptr; + if (VT == ASTTypeMPDecimalArray) + Arr = XSTE->GetValue()->GetValue(); + else if (VT == ASTTypeFloatArray) + Arr = XSTE->GetValue()->GetValue(); + else if (VT == ASTTypeAngleArray) + Arr = XSTE->GetValue()->GetValue(); + else + Arr = XSTE->GetValue()->GetValue(); + if (!Arr) { + if (ASTArrayNode *ARN = + XSTE->GetValue()->GetValue()) + Arr = ARN; + } + assert(Arr && "Named array gate arg has no array node!"); + if (IsGateCall && FormalWantsFloatArray(C) && + VT == ASTTypeAngleArray) { + ASTMPDecimalArrayNode *MDAN = MaterializeMPDecimalArrayFromAngles( + C, dynamic_cast(Arr)); + assert(MDAN && "Could not convert named AngleArray arg!"); + AddParam(ASTTypeMPDecimalArray, MDAN); + PNS.insert(MDAN->GetName()); + } else { + AddParam(VT, Arr); + PNS.insert(Arr->GetName()); + } + PNS.insert(ID->GetName()); + ID->SetNoQubit(true); + break; + } + + if (IsGateCall && FormalWantsFloatScalar(C) && + (VT == ASTTypeFloat || VT == ASTTypeDouble || + VT == ASTTypeMPDecimal)) { + if (VT == ASTTypeMPDecimal) { + ASTMPDecimalNode *R = + XSTE->GetValue()->GetValue(); + assert(R && "Named MPDecimal gate arg is null!"); + AddParam(ASTTypeMPDecimal, R); + PNS.insert(R->GetName()); + } else if (VT == ASTTypeFloat) { + ASTFloatNode *FLT = XSTE->GetValue()->GetValue(); + assert(FLT && "Named Float gate arg is null!"); + if (FormalParamTypes[C] == ASTTypeFloat) { + AddParam(ASTTypeFloat, FLT); + PNS.insert(FLT->GetName()); + } else { + std::stringstream RSN; + RSN << "ast-gate-mpdecimal-" << C; + ASTIdentifierNode *RId = + ASTBuilder::Instance().CreateASTIdentifierNode( + RSN.str(), ASTMPDecimalNode::DefaultBits, + ASTTypeMPDecimal); + ASTMPDecimalNode *R = + ASTBuilder::Instance().CreateASTMPDecimalNode( + RId, ASTMPDecimalNode::DefaultBits, + static_cast(FLT->GetValue())); + assert(R && "Could not promote Float id to MPDecimal!"); + R->Mangle(); + R->MangleLiteral(); + ToGateParamSymbolTable(RId, RId->GetSymbolTableEntry()); + AddParam(ASTTypeMPDecimal, R); + PNS.insert(R->GetName()); + } + } else { + ASTDoubleNode *DBL = + XSTE->GetValue()->GetValue(); + assert(DBL && "Named Double gate arg is null!"); + if (FormalParamTypes[C] == ASTTypeDouble) { + AddParam(ASTTypeDouble, DBL); + PNS.insert(DBL->GetName()); + } else { + std::stringstream RSN; + RSN << "ast-gate-mpdecimal-" << C; + ASTIdentifierNode *RId = + ASTBuilder::Instance().CreateASTIdentifierNode( + RSN.str(), ASTMPDecimalNode::DefaultBits, + ASTTypeMPDecimal); + ASTMPDecimalNode *R = + ASTBuilder::Instance().CreateASTMPDecimalNode( + RId, ASTMPDecimalNode::DefaultBits, DBL->GetValue()); + assert(R && "Could not promote Double id to MPDecimal!"); + R->Mangle(); + R->MangleLiteral(); + ToGateParamSymbolTable(RId, RId->GetSymbolTableEntry()); + AddParam(ASTTypeMPDecimal, R); + PNS.insert(R->GetName()); + } + } + PNS.insert(ID->GetName()); + ID->SetNoQubit(true); + break; + } + } + ASTAngleNode *XAN = nullptr; bool IMPC = false; @@ -628,7 +1082,7 @@ ASTGateNode::ASTGateNode(const ASTIdentifierNode *Id, ASTAngleNodeBuilder::Instance().Insert(AN); ASTAngleNodeBuilder::Instance().Append(AN); - Params.push_back(AN); + AddParam(ASTTypeAngle, AN); if (XAN && IMPC) delete XAN; @@ -657,6 +1111,32 @@ ASTGateNode::ASTGateNode(const ASTIdentifierNode *Id, const ASTBinaryOpNode *BOP = EN->DynCast(); assert(BOP && "Failed to dynamic_cast to a BinaryOpNode!"); + if (IsGateCall && + (PreferComplexGateParam(Id, BOP) || FormalWantsComplex(C))) { + ASTMPComplexNode *MPC = MaterializeComplexParamExpr(C, BOP); + assert(MPC && "Could not materialize complex gate Param!"); + AddParam(ASTTypeMPComplex, MPC); + PNS.insert(MPC->GetName()); + break; + } + + if (IsGateCall && FormalWantsFloatScalar(C)) { + std::stringstream RSN; + RSN << "ast-gate-mpdecimal-" << C; + ASTIdentifierNode *RId = + ASTBuilder::Instance().CreateASTIdentifierNode( + RSN.str(), ASTMPDecimalNode::DefaultBits, ASTTypeMPDecimal); + assert(RId && "Could not create an MPDecimal ASTIdentifierNode!"); + ASTMPDecimalNode *R = + ASTBuilder::Instance().CreateASTMPDecimalNodeFromExpression( + RId, ASTMPDecimalNode::DefaultBits, BOP); + assert(R && "Could not materialize MPDecimal Param from BinaryOp!"); + ToGateParamSymbolTable(RId, RId->GetSymbolTableEntry()); + AddParam(ASTTypeMPDecimal, R); + PNS.insert(R->GetName()); + break; + } + const ASTIdentifierNode *BId = BOP->GetIdentifier(); assert(BId && "Invalid ASTIdentifierNode for ASTBinaryOpNode!"); @@ -690,7 +1170,7 @@ ASTGateNode::ASTGateNode(const ASTIdentifierNode *Id, AId->GetSymbolType()); } - Params.push_back(AN); + AddParam(ASTTypeAngle, AN); PNS.insert(AN->GetName()); } catch (const std::bad_any_cast &E) { std::stringstream M; @@ -713,6 +1193,32 @@ ASTGateNode::ASTGateNode(const ASTIdentifierNode *Id, const ASTUnaryOpNode *UOP = EN->DynCast(); assert(UOP && "Failed to dynamic_cast to an UnaryOpNode!"); + if (IsGateCall && + (PreferComplexGateParam(Id, UOP) || FormalWantsComplex(C))) { + ASTMPComplexNode *MPC = MaterializeComplexParamExpr(C, UOP); + assert(MPC && "Could not materialize complex gate Param!"); + AddParam(ASTTypeMPComplex, MPC); + PNS.insert(MPC->GetName()); + break; + } + + if (IsGateCall && FormalWantsFloatScalar(C)) { + std::stringstream RSN; + RSN << "ast-gate-mpdecimal-" << C; + ASTIdentifierNode *RId = + ASTBuilder::Instance().CreateASTIdentifierNode( + RSN.str(), ASTMPDecimalNode::DefaultBits, ASTTypeMPDecimal); + assert(RId && "Could not create an MPDecimal ASTIdentifierNode!"); + ASTMPDecimalNode *R = + ASTBuilder::Instance().CreateASTMPDecimalNodeFromExpression( + RId, ASTMPDecimalNode::DefaultBits, UOP); + assert(R && "Could not materialize MPDecimal Param from UnaryOp!"); + ToGateParamSymbolTable(RId, RId->GetSymbolTableEntry()); + AddParam(ASTTypeMPDecimal, R); + PNS.insert(R->GetName()); + break; + } + const ASTIdentifierNode *UId = UOP->GetIdentifier(); assert(UId && "Invalid ASTIdentifierNode for ASTUnaryOpNode!"); @@ -743,7 +1249,7 @@ ASTGateNode::ASTGateNode(const ASTIdentifierNode *Id, AId->GetSymbolType()); } - Params.push_back(AN); + AddParam(ASTTypeAngle, AN); PNS.insert(AN->GetName()); } catch (const std::bad_any_cast &E) { std::stringstream M; @@ -769,6 +1275,25 @@ ASTGateNode::ASTGateNode(const ASTIdentifierNode *Id, const ASTIdentifierNode *ID = INT->GetIdentifier(); assert(ID && "Invalid ASTIdentifierNode for ASTIntNode!"); + if (IsGateCall && FormalWantsComplex(C)) { + std::stringstream RSN; + RSN << "complex-re-" << C; + ASTIdentifierNode *RId = + ASTBuilder::Instance().CreateASTIdentifierNode( + RSN.str(), ASTMPDecimalNode::DefaultBits, ASTTypeMPDecimal); + assert(RId && "Could not create a Real ASTIdentifierNode!"); + ASTMPDecimalNode *R = ASTBuilder::Instance().CreateASTMPDecimalNode( + RId, ASTMPDecimalNode::DefaultBits, + static_cast(INT->IsSigned() ? INT->GetSignedValue() + : INT->GetUnsignedValue())); + assert(R && "Could not create real ASTMPDecimalNode!"); + ASTMPComplexNode *MPC = MaterializeComplexFromReal(C, R); + assert(MPC && "Could not materialize complex Param from int!"); + AddParam(ASTTypeMPComplex, MPC); + PNS.insert(MPC->GetName()); + break; + } + if (INT->GetSignedValue() > static_cast(M_PI * 2)) { std::stringstream M; M << "Angle value exceeds 2pi."; @@ -803,7 +1328,7 @@ ASTGateNode::ASTGateNode(const ASTIdentifierNode *Id, AId->GetSymbolType()); } - Params.push_back(AN); + AddParam(ASTTypeAngle, AN); PNS.insert(AN->GetName()); } catch (const std::bad_any_cast &E) { std::stringstream M; @@ -829,6 +1354,49 @@ ASTGateNode::ASTGateNode(const ASTIdentifierNode *Id, const ASTIdentifierNode *ID = FLT->GetIdentifier(); assert(ID && "Invalid ASTIdentifierNode for ASTFloatNode!"); + if (IsGateCall && FormalWantsComplex(C)) { + std::stringstream RSN; + RSN << "complex-re-" << C; + ASTIdentifierNode *RId = + ASTBuilder::Instance().CreateASTIdentifierNode( + RSN.str(), ASTMPDecimalNode::DefaultBits, ASTTypeMPDecimal); + assert(RId && "Could not create a Real ASTIdentifierNode!"); + ASTMPDecimalNode *R = ASTBuilder::Instance().CreateASTMPDecimalNode( + RId, ASTMPDecimalNode::DefaultBits, + static_cast(FLT->GetValue())); + assert(R && "Could not create real ASTMPDecimalNode!"); + ASTMPComplexNode *MPC = MaterializeComplexFromReal(C, R); + assert(MPC && "Could not materialize complex Param from float!"); + AddParam(ASTTypeMPComplex, MPC); + PNS.insert(MPC->GetName()); + break; + } + + if (IsGateCall && FormalWantsFloatScalar(C)) { + ASTType FTy = FormalParamTypes[C]; + if (FTy == ASTTypeFloat) { + AddParam(ASTTypeFloat, const_cast(FLT)); + PNS.insert(FLT->GetName()); + break; + } + std::stringstream RSN; + RSN << "ast-gate-mpdecimal-" << C; + ASTIdentifierNode *RId = + ASTBuilder::Instance().CreateASTIdentifierNode( + RSN.str(), ASTMPDecimalNode::DefaultBits, ASTTypeMPDecimal); + assert(RId && "Could not create an MPDecimal ASTIdentifierNode!"); + ASTMPDecimalNode *R = ASTBuilder::Instance().CreateASTMPDecimalNode( + RId, ASTMPDecimalNode::DefaultBits, + static_cast(FLT->GetValue())); + assert(R && "Could not create MPDecimal Param from float!"); + R->Mangle(); + R->MangleLiteral(); + ToGateParamSymbolTable(RId, RId->GetSymbolTableEntry()); + AddParam(ASTTypeMPDecimal, R); + PNS.insert(R->GetName()); + break; + } + if (FLT->GetValue() > static_cast(M_PI * 2)) { std::stringstream M; M << "Angle value exceeds 2pi."; @@ -863,7 +1431,7 @@ ASTGateNode::ASTGateNode(const ASTIdentifierNode *Id, AId->GetSymbolType()); } - Params.push_back(AN); + AddParam(ASTTypeAngle, AN); PNS.insert(AN->GetName()); } catch (const std::bad_any_cast &E) { std::stringstream M; @@ -889,6 +1457,47 @@ ASTGateNode::ASTGateNode(const ASTIdentifierNode *Id, const ASTIdentifierNode *ID = DBL->GetIdentifier(); assert(ID && "Invalid ASTIdentifierNode for ASTDoubleNode!"); + if (IsGateCall && FormalWantsComplex(C)) { + std::stringstream RSN; + RSN << "complex-re-" << C; + ASTIdentifierNode *RId = + ASTBuilder::Instance().CreateASTIdentifierNode( + RSN.str(), ASTMPDecimalNode::DefaultBits, ASTTypeMPDecimal); + assert(RId && "Could not create a Real ASTIdentifierNode!"); + ASTMPDecimalNode *R = ASTBuilder::Instance().CreateASTMPDecimalNode( + RId, ASTMPDecimalNode::DefaultBits, DBL->GetValue()); + assert(R && "Could not create real ASTMPDecimalNode!"); + ASTMPComplexNode *MPC = MaterializeComplexFromReal(C, R); + assert(MPC && "Could not materialize complex Param from double!"); + AddParam(ASTTypeMPComplex, MPC); + PNS.insert(MPC->GetName()); + break; + } + + if (IsGateCall && FormalWantsFloatScalar(C)) { + ASTType FTy = FormalParamTypes[C]; + if (FTy == ASTTypeDouble) { + AddParam(ASTTypeDouble, const_cast(DBL)); + PNS.insert(DBL->GetName()); + break; + } + std::stringstream RSN; + RSN << "ast-gate-mpdecimal-" << C; + ASTIdentifierNode *RId = + ASTBuilder::Instance().CreateASTIdentifierNode( + RSN.str(), ASTMPDecimalNode::DefaultBits, ASTTypeMPDecimal); + assert(RId && "Could not create an MPDecimal ASTIdentifierNode!"); + ASTMPDecimalNode *R = ASTBuilder::Instance().CreateASTMPDecimalNode( + RId, ASTMPDecimalNode::DefaultBits, DBL->GetValue()); + assert(R && "Could not create MPDecimal Param from double!"); + R->Mangle(); + R->MangleLiteral(); + ToGateParamSymbolTable(RId, RId->GetSymbolTableEntry()); + AddParam(ASTTypeMPDecimal, R); + PNS.insert(R->GetName()); + break; + } + if (DBL->GetValue() > static_cast(M_PI * 2)) { std::stringstream M; M << "Angle value exceeds 2pi."; @@ -924,7 +1533,7 @@ ASTGateNode::ASTGateNode(const ASTIdentifierNode *Id, AId->GetSymbolType()); } - Params.push_back(AN); + AddParam(ASTTypeAngle, AN); PNS.insert(AN->GetName()); } catch (const std::bad_any_cast &E) { std::stringstream M; @@ -993,7 +1602,7 @@ ASTGateNode::ASTGateNode(const ASTIdentifierNode *Id, AId->GetSymbolType()); } - Params.push_back(AN); + AddParam(ASTTypeAngle, AN); PNS.insert(AN->GetName()); } catch (const std::bad_any_cast &E) { std::stringstream M; @@ -1020,6 +1629,20 @@ ASTGateNode::ASTGateNode(const ASTIdentifierNode *Id, const ASTIdentifierNode *ID = MPD->GetIdentifier()->GetIdentifier(); assert(ID && "Invalid ASTIdentifierNode for ASTMPDecimalNode!"); + if (IsGateCall && FormalWantsComplex(C)) { + ASTMPComplexNode *MPC = MaterializeComplexFromReal(C, MPD); + assert(MPC && "Could not materialize complex Param from MPDecimal!"); + AddParam(ASTTypeMPComplex, MPC); + PNS.insert(MPC->GetName()); + break; + } + + if (IsGateCall && FormalWantsFloatScalar(C)) { + AddParam(ASTTypeMPDecimal, const_cast(MPD)); + PNS.insert(MPD->GetName()); + break; + } + mpfr_t MP2PI; mpfr_init2(MP2PI, MPD->GetBits()); (void)mpfr_const_pi(MP2PI, MPFR_RNDN); @@ -1059,7 +1682,7 @@ ASTGateNode::ASTGateNode(const ASTIdentifierNode *Id, AId->GetSymbolType()); } - Params.push_back(AN); + AddParam(ASTTypeAngle, AN); PNS.insert(AN->GetName()); } catch (const std::bad_any_cast &E) { std::stringstream M; @@ -1110,7 +1733,7 @@ ASTGateNode::ASTGateNode(const ASTIdentifierNode *Id, ASTSymbolTable::Instance().TransferAngleToLSTM(AId, AId->GetBits(), AId->GetSymbolType()); ASTSymbolTable::Instance().EraseLocalAngle(AId); - Params.push_back(AN); + AddParam(ASTTypeAngle, AN); PNS.insert(AN->GetName()); } catch (const std::bad_any_cast &E) { std::stringstream M; @@ -1124,6 +1747,167 @@ ASTGateNode::ASTGateNode(const ASTIdentifierNode *Id, DIAGLineCounter::Instance().GetLocation(), M.str(), DiagLevel::ICE); } } break; + case ASTTypeAngleArray: { + try { + ASTExpressionNode *EN = nullptr; + try { + EN = const_cast( + std::any_cast((*I)->GetValue())); + } catch (const std::bad_any_cast &) { + EN = std::any_cast((*I)->GetValue()); + } + assert(EN && "Failed to any_cast to an ExpressionNode!"); + + ASTAngleArrayNode *AAN = dynamic_cast(EN); + assert(AAN && "Failed to dynamic_cast to an ASTAngleArrayNode!"); + + if (IsGateCall && FormalWantsFloatArray(C)) { + ASTMPDecimalArrayNode *MDAN = + MaterializeMPDecimalArrayFromAngles(C, AAN); + assert(MDAN && + "Could not materialize MPDecimalArray from AngleArray!"); + // float[64] formals use MPDecimalArray; Params match + // FormalParamTypes. + AddParam(ASTTypeMPDecimalArray, MDAN); + PNS.insert(MDAN->GetName()); + } else { + AddParam(ASTTypeAngleArray, AAN); + PNS.insert(AAN->GetName()); + } + } catch (const std::bad_any_cast &E) { + std::stringstream M; + M << "std::bad_any_cast caught at index " << C << ": " << E.what(); + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(), M.str(), DiagLevel::ICE); + } catch (...) { + std::stringstream M; + M << "Unknown exception caught at index " << C << "."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(), M.str(), DiagLevel::ICE); + } + } break; + case ASTTypeFloatArray: { + try { + ASTExpressionNode *EN = nullptr; + try { + EN = const_cast( + std::any_cast((*I)->GetValue())); + } catch (const std::bad_any_cast &) { + EN = std::any_cast((*I)->GetValue()); + } + assert(EN && "Failed to any_cast to an ExpressionNode!"); + + ASTFloatArrayNode *FAN = dynamic_cast(EN); + assert(FAN && "Failed to dynamic_cast to an ASTFloatArrayNode!"); + + AddParam(ASTTypeFloatArray, FAN); + PNS.insert(FAN->GetName()); + } catch (const std::bad_any_cast &E) { + std::stringstream M; + M << "std::bad_any_cast caught at index " << C << ": " << E.what(); + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(), M.str(), DiagLevel::ICE); + } catch (...) { + std::stringstream M; + M << "Unknown exception caught at index " << C << "."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(), M.str(), DiagLevel::ICE); + } + } break; + case ASTTypeMPDecimalArray: { + try { + ASTExpressionNode *EN = nullptr; + try { + EN = const_cast( + std::any_cast((*I)->GetValue())); + } catch (const std::bad_any_cast &) { + EN = std::any_cast((*I)->GetValue()); + } + assert(EN && "Failed to any_cast to an ExpressionNode!"); + + ASTMPDecimalArrayNode *MDAN = dynamic_cast(EN); + assert(MDAN && "Failed to dynamic_cast to an ASTMPDecimalArrayNode!"); + + AddParam(ASTTypeMPDecimalArray, MDAN); + PNS.insert(MDAN->GetName()); + } catch (const std::bad_any_cast &E) { + std::stringstream M; + M << "std::bad_any_cast caught at index " << C << ": " << E.what(); + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(), M.str(), DiagLevel::ICE); + } catch (...) { + std::stringstream M; + M << "Unknown exception caught at index " << C << "."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(), M.str(), DiagLevel::ICE); + } + } break; + case ASTTypeMPComplexArray: { + try { + ASTExpressionNode *EN = nullptr; + try { + EN = const_cast( + std::any_cast((*I)->GetValue())); + } catch (const std::bad_any_cast &) { + EN = std::any_cast((*I)->GetValue()); + } + assert(EN && "Failed to any_cast to an ExpressionNode!"); + + ASTMPComplexArrayNode *CAN = dynamic_cast(EN); + assert(CAN && "Failed to dynamic_cast to an ASTMPComplexArrayNode!"); + + AddParam(ASTTypeMPComplexArray, CAN); + PNS.insert(CAN->GetName()); + } catch (const std::bad_any_cast &E) { + std::stringstream M; + M << "std::bad_any_cast caught at index " << C << ": " << E.what(); + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(), M.str(), DiagLevel::ICE); + } catch (...) { + std::stringstream M; + M << "Unknown exception caught at index " << C << "."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(), M.str(), DiagLevel::ICE); + } + } break; + case ASTTypeComplexExpression: { + try { + const ASTExpressionNode *EN = + std::any_cast((*I)->GetValue()); + assert(EN && "Failed to any_cast to an ExpressionNode!"); + + const ASTComplexExpressionNode *CEN = + dynamic_cast(EN); + assert(CEN && "Failed to dynamic_cast to an ASTComplexExpressionNode!"); + + std::stringstream SCN; + SCN << ASTDemangler::TypeName(ASTTypeMPComplex) << C; + ASTIdentifierNode *CId = ASTBuilder::Instance().CreateASTIdentifierNode( + SCN.str(), ASTMPComplexNode::DefaultBits, ASTTypeMPComplex); + assert(CId && "Could not create a Complex ASTIdentifierNode!"); + + ASTMPComplexNode *MPC = ASTBuilder::Instance().CreateASTMPComplexNode( + CId, CEN, ASTMPComplexNode::DefaultBits); + assert(MPC && "Could not create a valid ASTMPComplexNode!"); + + CId->SetPolymorphicName(SCN.str()); + MPC->Mangle(); + MPC->MangleLiteral(); + ToGateParamSymbolTable(CId, CId->GetSymbolTableEntry()); + AddParam(ASTTypeMPComplex, MPC); + PNS.insert(MPC->GetName()); + } catch (const std::bad_any_cast &E) { + std::stringstream M; + M << "std::bad_any_cast caught at index " << C << ": " << E.what(); + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(), M.str(), DiagLevel::ICE); + } catch (...) { + std::stringstream M; + M << "Unknown exception caught at index " << C << "."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(), M.str(), DiagLevel::ICE); + } + } break; default: break; } @@ -1131,7 +1915,87 @@ ASTGateNode::ASTGateNode(const ASTIdentifierNode *Id, ++C; } - if (C != Params.size()) { + const bool IsDispCall = + IsGateCall && + (Id->GetName() == u8"disp" || Id->GetSymbolType() == ASTTypeDispGate); + if (IsDispCall) { + for (std::size_t PI = 0; PI < Params.size(); ++PI) { + if (Params[PI].Ty == ASTTypeAngleArray || + Params[PI].Ty == ASTTypeMPComplexArray) { + std::stringstream M; + M << "The disp gate expects a complex parameter, not an array."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(Id), M.str(), + DiagLevel::Error); + return; + } + } + + // Promote leftover scalar/angle params to complex. + // Expression-backed angles (BinaryOp/UnaryOp) keep their Expr tree; + // only constant/numeric angles become real+0i. + std::vector Promoted; + Promoted.reserve(Params.size()); + unsigned PromoIX = 0; + for (std::size_t PI = 0; PI < Params.size(); ++PI) { + if (Params[PI].Ty == ASTTypeMPComplex) { + Promoted.push_back(Params[PI]); + continue; + } + + ASTAngleNode *AN = dynamic_cast(Params[PI].Expr); + assert(AN && "Invalid ASTAngleNode in disp gate Params!"); + + const ASTExpressionNode *AEx = AN->GetExpression(); + if (AEx && (AEx->GetASTType() == ASTTypeBinaryOp || + AEx->GetASTType() == ASTTypeUnaryOp)) { + ASTMPComplexNode *MPC = MaterializeComplexParamExpr(PromoIX, AEx); + assert(MPC && "Could not materialize complex Param from angle Expr!"); + Promoted.emplace_back(ASTTypeMPComplex, MPC); + ++PromoIX; + continue; + } + + std::stringstream SCN; + SCN << ASTDemangler::TypeName(ASTTypeMPComplex) << PromoIX; + ASTIdentifierNode *CId = ASTBuilder::Instance().CreateASTIdentifierNode( + SCN.str(), ASTMPComplexNode::DefaultBits, ASTTypeMPComplex); + assert(CId && "Could not create a Complex ASTIdentifierNode!"); + + std::stringstream ISN; + ISN << "disp-im-" << PromoIX; + ASTIdentifierNode *IId = ASTBuilder::Instance().CreateASTIdentifierNode( + ISN.str(), ASTMPDecimalNode::DefaultBits, ASTTypeMPDecimal); + assert(IId && "Could not create an Imaginary ASTIdentifierNode!"); + + ASTMPDecimalNode *R = AN->AsMPDecimal(); + assert(R && "Could not obtain real part from ASTAngleNode!"); + ASTMPDecimalNode *Imag = ASTBuilder::Instance().CreateASTMPDecimalNode( + IId, ASTMPDecimalNode::DefaultBits, 0.0); + assert(Imag && "Could not create a zero imaginary ASTMPDecimalNode!"); + + ASTMPComplexNode *MPC = ASTBuilder::Instance().CreateASTMPComplexNode( + CId, R, Imag, ASTOpTypeAdd, ASTMPComplexNode::DefaultBits); + assert(MPC && "Could not create a valid ASTMPComplexNode!"); + + CId->SetPolymorphicName(SCN.str()); + MPC->Mangle(); + MPC->MangleLiteral(); + ToGateParamSymbolTable(CId, CId->GetSymbolTableEntry()); + Promoted.emplace_back(ASTTypeMPComplex, MPC); + ++PromoIX; + } + Params.swap(Promoted); + + if (C != Params.size() || GetNumComplexParams() != C) { + std::stringstream M; + M << "The disp gate expects exactly one complex parameter."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(Id), M.str(), + DiagLevel::Error); + return; + } + } else if (C != Params.size()) { std::stringstream M; M << C << " inconsistent parameters in the gate call for the " @@ -1175,19 +2039,19 @@ ASTGateNode::ASTGateNode(const ASTIdentifierNode *Id, assert(QSTE && "Gate Qubit Argument has no SymbolTable Entry!"); if (!QSTE->HasValue()) { - ASTGateQubitParamNode *QPN = - new ASTGateQubitParamNode(QId, C, QId->GetBits(), QId->GetName()); - assert(QPN && "Could not create a valid ASTGateQubitParamNode!"); + ASTGateOperandParamNode *QPN = new ASTGateOperandParamNode( + QId, C, QId->GetBits(), QId->GetName()); + assert(QPN && "Could not create a valid ASTGateOperandParamNode!"); QPN->Mangle(); QSTE->ResetValue(); - QSTE->SetValue(new ASTValue<>(QPN, ASTTypeGateQubitParam), - ASTTypeGateQubitParam); + QSTE->SetValue(new ASTValue<>(QPN, ASTTypeGateOperandParam), + ASTTypeGateOperandParam); } assert(QSTE->HasValue() && "Gate Qubit Parameter SymbolTable Entry has no Value!"); - QCParams.push_back(QSTE); + OperandParams.push_back(QSTE); } catch (const std::bad_any_cast &E) { std::stringstream M; M << "std::bad_any_cast caught at index " << C << ": " << E.what(); @@ -1215,11 +2079,13 @@ ASTGateNode::ASTGateNode(const ASTIdentifierNode *Id, assert(QSTE->HasValue() && "Gate Qubit Argument SymbolTable Entry has no Value!"); - QCParams.push_back(QSTE); + OperandParams.push_back(QSTE); if (IdR->IsInductionVariable()) - QCParamIds.insert(std::make_pair(C, IdR->GetInductionVariable())); + OperandParamIds.insert( + std::make_pair(C, IdR->GetInductionVariable())); else if (IdR->IsIndexedIdentifier()) - QCParamIds.insert(std::make_pair(C, IdR->GetIndexedIdentifier())); + OperandParamIds.insert( + std::make_pair(C, IdR->GetIndexedIdentifier())); } catch (const std::bad_any_cast &E) { std::stringstream M; M << "std::bad_any_cast caught at index " << C << ": " << E.what(); @@ -1244,7 +2110,7 @@ ASTGateNode::ASTGateNode(const ASTIdentifierNode *Id, ++C; } - assert(C == QCParams.size() && "Inconsistent number of Qubit Parameters!"); + assert(C == OperandParams.size() && "Inconsistent number of OperandParams!"); Mangle(); } @@ -1252,9 +2118,12 @@ ASTGateNode::ASTGateNode(const ASTIdentifierNode *Id, const ASTParameterList &PL, const ASTIdentifierList &IL, bool IsGateCall, const ASTGateQOpList &OL) - : ASTExpressionNode(Id, ASTTypeGate), Params(), Qubits(), QCParams(), + : ASTExpressionNode(Id, ASTTypeGate), Params(), Operands(), OperandParams(), OpList(OL), Ctrl(nullptr), GDId(IsGateCall ? nullptr : Id), GSTM(), - ControlType(ASTTypeUndefined), Opaque(false), GateCall(IsGateCall) { + ControlType(ASTTypeUndefined), Opaque(false), GateCall(IsGateCall), + FullyTyped(false), FormalParamTypes(), FormalParamArraySizes(), + FormalQuantumTypes(), TemplateParams(), + FormalParamArraySizeTemplateIndices() { unsigned C = 0; std::set PNS; std::vector NQV; @@ -1268,6 +2137,194 @@ ASTGateNode::ASTGateNode(const ASTIdentifierNode *Id, ASTParameter *AP = dynamic_cast(*I); assert(AP && "Could not dynamic_cast to an ASTParameter!"); + // Explicitly typed classical formals (fully-typed gate decls). + if (const ASTDeclarationNode *PDN = AP->GetDeclaration()) { + ASTType PTy = PDN->GetASTType(); + // Prefer the Identifier's bound symbol type when the Decl wrapper + // reports a generic/expression type for array formals. + if (const ASTIdentifierNode *PId = AP->GetIdentifier()) { + ASTType STy = PId->GetSymbolType(); + if (STy == ASTTypeMPComplexArray || STy == ASTTypeAngleArray || + STy == ASTTypeFloatArray || STy == ASTTypeMPDecimalArray) + PTy = STy; + } + if (PTy == ASTTypeMPComplex) { + const ASTIdentifierNode *CId = AP->GetIdentifier(); + assert(CId && "Typed complex gate param has no Identifier!"); + + ASTSymbolTableEntry *CSTE = + const_cast(CId->GetSymbolTableEntry()); + if (!CSTE) + CSTE = ASTSymbolTable::Instance().Lookup( + CId->GetName(), CId->GetBits(), ASTTypeMPComplex); + assert(CSTE && CSTE->HasValue() && + "Typed complex gate param has no SymbolTable Entry!"); + + ASTMPComplexNode *MPC = + CSTE->GetValue()->GetValue(); + assert(MPC && "Could not obtain a valid ASTMPComplexNode!"); + + ToGateParamSymbolTable(CId, CSTE); + if (CId) + const_cast(CId)->SetNoQubit(true); + AddParam(ASTTypeMPComplex, MPC); + PNS.insert(AP->GetName()); + PNS.insert(CId->GetName()); + ++C; + continue; + } + + if (PTy == ASTTypeAngleArray || PTy == ASTTypeFloatArray || + PTy == ASTTypeMPDecimalArray || PTy == ASTTypeMPComplexArray) { + const ASTIdentifierNode *AId = AP->GetIdentifier(); + assert(AId && "Typed array gate param has no Identifier!"); + + ASTSymbolTableEntry *ASTE = + const_cast(AId->GetSymbolTableEntry()); + if (!ASTE) + ASTE = ASTSymbolTable::Instance().Lookup(AId->GetName(), + AId->GetBits(), PTy); + assert(ASTE && ASTE->HasValue() && + "Typed array gate param has no SymbolTable Entry!"); + + // Erase the formal from LSTM before publishing to GSTM so later + // TransferLocalContextSymbols / InsertLocal cannot collide. + ASTSymbolTable::Instance().EraseLocal(AId, AId->GetBits(), PTy); + ASTSymbolTable::Instance().EraseLocalSymbol(AId, AId->GetBits(), PTy); + + // Keep declared STE identity for body lookup (thetas[i] / alphas[i]). + ToGateParamSymbolTable(AId, ASTE); + if (AId) + const_cast(AId)->SetNoQubit(true); + + if (PTy == ASTTypeMPComplexArray) { + ASTMPComplexArrayNode *CAN = + ASTE->GetValue()->GetValue(); + if (!CAN) { + ASTArrayNode *ARN = ASTE->GetValue()->GetValue(); + CAN = dynamic_cast(ARN); + } + if (!CAN && PDN->GetExpression()) + CAN = dynamic_cast( + const_cast(PDN->GetExpression())); + assert(CAN && "Typed complex-array gate param is not an " + "ASTMPComplexArrayNode!"); + AddParam(ASTTypeMPComplexArray, CAN); + } else if (PTy == ASTTypeAngleArray) { + ASTAngleArrayNode *AAN = + ASTE->GetValue()->GetValue(); + if (!AAN) { + ASTArrayNode *ARN = ASTE->GetValue()->GetValue(); + AAN = dynamic_cast(ARN); + } + if (!AAN && PDN->GetExpression()) + AAN = dynamic_cast( + const_cast(PDN->GetExpression())); + assert(AAN && "Could not obtain a valid ASTAngleArrayNode!"); + AddParam(ASTTypeAngleArray, AAN); + } else { + // FloatArray / MPDecimalArray: store the declared array in Params + // (type-faithful). Do not synthesize a .gatearray AngleArray view. + ASTArrayNode *ARN = ASTE->GetValue()->GetValue(); + if (!ARN) { + if (PTy == ASTTypeMPDecimalArray) + ARN = ASTE->GetValue()->GetValue(); + else if (PTy == ASTTypeFloatArray) + ARN = ASTE->GetValue()->GetValue(); + } + if (!ARN && PDN->GetExpression()) + ARN = dynamic_cast( + const_cast(PDN->GetExpression())); + assert(ARN && "Typed array gate param is not an ASTArrayNode!"); + AddParam(PTy, ARN); + } + + PNS.insert(AP->GetName()); + PNS.insert(AId->GetName()); + ++C; + continue; + } + + if (PTy == ASTTypeFloat || PTy == ASTTypeDouble || + PTy == ASTTypeMPDecimal) { + // Type-faithful Params: keep the declared float/decimal binding. + const ASTIdentifierNode *PId = AP->GetIdentifier(); + assert(PId && "Typed classical gate param has no Identifier!"); + + ASTSymbolTableEntry *PSTE = + const_cast(PId->GetSymbolTableEntry()); + if (!PSTE) + PSTE = ASTSymbolTable::Instance().Lookup(PId->GetName(), + PId->GetBits(), PTy); + assert(PSTE && PSTE->HasValue() && + "Typed float/decimal gate param has no SymbolTable Entry!"); + + ToGateParamSymbolTable(PId, PSTE); + if (PId) + const_cast(PId)->SetNoQubit(true); + + ASTExpressionNode *EN = nullptr; + if (PTy == ASTTypeMPDecimal) + EN = PSTE->GetValue()->GetValue(); + else if (PTy == ASTTypeFloat) + EN = PSTE->GetValue()->GetValue(); + else + EN = PSTE->GetValue()->GetValue(); + if (!EN && PDN->GetExpression()) + EN = const_cast(PDN->GetExpression()); + assert(EN && "Typed float/decimal gate param has no value node!"); + + AddParam(PTy, EN); + PNS.insert(AP->GetName()); + PNS.insert(PId->GetName()); + ++C; + continue; + } + + if (PTy == ASTTypeInt || PTy == ASTTypeUInt || PTy == ASTTypeMPInteger || + PTy == ASTTypeMPUInteger || PTy == ASTTypeBool || + PTy == ASTTypeBitset || PTy == ASTTypeDuration) { + // Non-float classical scalars still use an angle carrier so existing + // gate-body angle machinery keeps working (Phase 1 scope). + const ASTIdentifierNode *PId = AP->GetIdentifier(); + assert(PId && "Typed classical gate param has no Identifier!"); + + ASTIdentifierNode *AId = ASTBuilder::Instance().CreateASTIdentifierNode( + AP->GetName() + ".gateparam", ASTAngleNode::AngleBits, + ASTTypeAngle); + assert(AId && "Could not create an Angle ASTIdentifierNode!"); + AId->SetPolymorphicName(AP->GetName()); + + ASTAngleType ATy = ASTAngleNode::DetermineAngleType(AP->GetName()); + ASTAngleNode *AN = ASTBuilder::Instance().CreateASTAngleNode( + AId, ATy, ASTAngleNode::AngleBits); + assert(AN && "Could not create a valid ASTAngleNode!"); + + AN->SetGateParamName(AP->GetName()); + ASTSymbolTableEntry *ASTE = ASTSymbolTable::Instance().Lookup( + AId, AId->GetBits(), AId->GetSymbolType()); + assert(ASTE && "Angle ASTIdentifierNode has no SymbolTable Entry!"); + AId->SetLocalScope(); + ASTE->SetLocalScope(); + AId->SetSymbolTableEntry(ASTE); + AN->Mangle(); + AN->MangleLiteral(); + ToGateParamSymbolTable(AId, ASTE); + + // Also publish under the formal name used in the gate body. + ToGateParamSymbolTable(PId, PId->GetSymbolTableEntry()); + + AddParam(ASTTypeAngle, AN); + PNS.insert(AP->GetName()); + PNS.insert(AN->GetName()); + ++C; + continue; + } + + // ASTTypeAngle and untyped (implicit-angle) NamedTypeDecls fall through + // to the historical angle materialization path below. + } + ASTSymbolTableEntry *ASTE = nullptr; ASTAngleNode *AN = nullptr; @@ -1365,7 +2422,7 @@ ASTGateNode::ASTGateNode(const ASTIdentifierNode *Id, PId->SetNoQubit(true); } - Params.push_back(AN); + AddParam(ASTTypeAngle, AN); PNS.insert(AP->GetName()); PNS.insert(AN->GetName()); ++C; @@ -1381,9 +2438,13 @@ ASTGateNode::ASTGateNode(const ASTIdentifierNode *Id, return; } - for (std::vector::const_iterator I = Params.begin(); - I != Params.end(); ++I) { - const ASTIdentifierNode *AId = (*I)->GetIdentifier(); + for (std::size_t I = 0; I < Params.size(); ++I) { + if (Params[I].Ty != ASTTypeAngle) + continue; + ASTAngleNode *AN = dynamic_cast(Params[I].Expr); + if (!AN) + continue; + const ASTIdentifierNode *AId = AN->GetIdentifier(); assert(AId && "Invalid ASTIdentifierNode!"); ASTSymbolTable::Instance().EraseLocalAngle(AId->GetName(), AId->GetBits(), @@ -1415,7 +2476,7 @@ ASTGateNode::ASTGateNode(const ASTIdentifierNode *Id, continue; } - MaterializeGateQubitParam(QId); + MaterializeGateOperandParam(QId); ASTSymbolTableEntry *STE = nullptr; std::map::iterator QI = @@ -1443,7 +2504,7 @@ ASTGateNode::ASTGateNode(const ASTIdentifierNode *Id, QId->SetLocalScope(); QId->SetBits(1); STE->SetLocalScope(); - STE->SetValueType(ASTTypeGateQubitParam); + STE->SetValueType(ASTTypeGateOperandParam); } QId->SetLocalScope(); @@ -1477,8 +2538,16 @@ ASTGateNode::ASTGateNode(const ASTIdentifierNode *Id, QBits = 1U; } } break; + case ASTTypeQumodeContainer: { + if (ASTQumodeContainerNode *QCN = + STE->GetValue()->GetValue()) { + Bits = QCN->Size(); + QBits = 1U; + } + } break; case ASTTypeQubit: - case ASTTypeGateQubitParam: + case ASTTypeQumode: + case ASTTypeGateOperandParam: Bits = QBits = 1U; break; default: @@ -1487,10 +2556,10 @@ ASTGateNode::ASTGateNode(const ASTIdentifierNode *Id, if (STE) { STE->SetLocalScope(); - QCParams.push_back(STE); + OperandParams.push_back(STE); } - STE = MangleGateQubitParam(QId, STE, C, Bits, QBits); + STE = MangleGateOperandParam(QId, STE, C, Bits, QBits); ToGateParamSymbolTable(QId, STE); if (IdR) @@ -1501,7 +2570,9 @@ ASTGateNode::ASTGateNode(const ASTIdentifierNode *Id, case ASTTypeQubit: case ASTTypeQubitContainer: case ASTTypeQubitContainerAlias: - case ASTTypeGateQubitParam: + case ASTTypeQumode: + case ASTTypeQumodeContainer: + case ASTTypeGateOperandParam: break; default: continue; @@ -1514,21 +2585,30 @@ ASTGateNode::ASTGateNode(const ASTIdentifierNode *Id, // Do not insert the gate identifier into the qubit param's // ast identifier. It will cause scope resolution conflicts. std::stringstream QS; - QS << "ast-gate-qubit-param-" << QId->GetName() << '-' << C; + QS << "ast-gate-operand-param-" << QId->GetName() << '-' << C; ASTIdentifierNode *QBId = - new ASTIdentifierNode(QS.str(), ASTTypeGateQubitParam, 0U); + new ASTIdentifierNode(QS.str(), ASTTypeGateOperandParam, 0U); assert(QBId && "Could not create a valid Qubit ASTIdentifierNode!"); QBId->SetPolymorphicName(QId->GetName()); - Qubits.push_back(new ASTQubitNode(QBId, C, QId->GetName())); - Qubits.back()->Mangle(); - ASTQubitNodeBuilder::Instance().Append(Qubits.back()); + + const ASTType OpQTy = ResolveOperandQuantumType(QId, C); + ASTQubitNode *OpN = nullptr; + if (OpQTy == ASTTypeQumode) + OpN = new ASTQumodeNode(QBId, C, QId->GetName()); + else + OpN = new ASTQubitNode(QBId, C, QId->GetName()); + assert(OpN && "Could not create a valid gate Operand node!"); + + Operands.push_back(OpN); + Operands.back()->Mangle(); + ASTQubitNodeBuilder::Instance().Append(Operands.back()); ASTSymbolTable::Instance().EraseGateLocalQubit(QId->GetName()); ++C; } - assert(C == Qubits.size() && "Inconsistent number of Qubits!"); + assert(C == Operands.size() && "Inconsistent number of Operands!"); OL.TransferToSymbolTable(GSTM); Mangle(); @@ -1549,48 +2629,108 @@ void ASTGateNode::print() const { << "" << std::endl; } + std::cout << "" << std::boolalpha << FullyTyped << "" + << std::endl; + + // Source order: gate name[TemplateParams](Params) quantum-operands + if (!TemplateParams.empty()) { + std::cout << "" << std::endl; + for (std::size_t I = 0; I < TemplateParams.size(); ++I) { + std::cout << "" << std::endl; + std::cout << "" << PrintTypeEnum(TemplateParams[I].Ty) << "" + << std::endl; + std::cout << "" << TemplateParams[I].Name << "" << std::endl; + // Decl: NaN placeholder (like angle Params). Call: bound value. + // Body identifiers named Name are not overwritten. + if (TemplateParams[I].HasBound()) + std::cout << "" << std::dec << *TemplateParams[I].Bound + << "" << std::endl; + else + std::cout << "NaN" << std::endl; + std::cout << "" << std::endl; + } + std::cout << "" << std::endl; + } + + if (!FormalParamTypes.empty()) { + std::cout << "" << std::endl; + for (std::size_t I = 0; I < FormalParamTypes.size(); ++I) { + std::cout << "" << std::endl; + std::cout << "" << PrintTypeEnum(FormalParamTypes[I]) << "" + << std::endl; + if (I < FormalParamArraySizes.size() && FormalParamArraySizes[I] != 0U) + std::cout << "" << std::dec << FormalParamArraySizes[I] + << "" << std::endl; + if (I < FormalParamArraySizeTemplateIndices.size() && + FormalParamArraySizeTemplateIndices[I] != + static_cast(~0U) && + FormalParamArraySizeTemplateIndices[I] < TemplateParams.size()) + std::cout << "" + << TemplateParams[FormalParamArraySizeTemplateIndices[I]].Name + << "" << std::endl; + std::cout << "" << std::endl; + } + std::cout << "" << std::endl; + } + + if (!FormalQuantumTypes.empty()) { + std::cout << "" << std::endl; + for (std::size_t I = 0; I < FormalQuantumTypes.size(); ++I) + std::cout << "" << PrintTypeEnum(FormalQuantumTypes[I]) << "" + << std::endl; + std::cout << "" << std::endl; + } + if (!Params.empty()) { std::cout << "" << std::endl; - for (std::vector::const_iterator I = Params.begin(); - I != Params.end(); ++I) - (*I)->print(); + for (std::size_t I = 0; I < Params.size(); ++I) { + std::cout << "" << std::endl; + std::cout << "" << PrintTypeEnum(Params[I].Ty) << "" + << std::endl; + if (Params[I].Expr) + Params[I].Expr->print(); + std::cout << "" << std::endl; + } std::cout << "" << std::endl; } - if (!Qubits.empty()) { - std::cout << "" << std::endl; - for (std::vector::const_iterator I = Qubits.begin(); - I != Qubits.end(); ++I) + if (!Operands.empty()) { + std::cout << "" << std::endl; + for (std::vector::const_iterator I = Operands.begin(); + I != Operands.end(); ++I) (*I)->print(); - std::cout << "" << std::endl; + std::cout << "" << std::endl; } - if (!QCParams.empty() && Qubits.empty()) { - std::cout << "" << std::endl; + // Always print OperandParams when present (decls and calls). Call consumers + // use these names with FormalQuantumTypes; Operands may be empty. + if (!OperandParams.empty()) { + std::cout << "" << std::endl; unsigned XC = 0; std::map::const_iterator MI; for (std::vector::const_iterator I = - QCParams.begin(); - I != QCParams.end(); ++I) { + OperandParams.begin(); + I != OperandParams.end(); ++I) { const ASTIdentifierNode *QId = (*I)->GetIdentifier(); assert(QId && "Invalid ASTIdentifierNode obtained from the SymbolTable Entry!"); - std::cout << "" << std::endl; + std::cout << "" << std::endl; const std::string &QN = QId->GetName(); - MI = QCParamIds.find(XC); - if (MI != QCParamIds.end() && ASTStringUtils::Instance().IsIndexed(QN)) { + MI = OperandParamIds.find(XC); + if (MI != OperandParamIds.end() && + ASTStringUtils::Instance().IsIndexed(QN)) { std::string BN = ASTStringUtils::Instance().GetIdentifierBase(QN); std::cout << "" << BN << '[' << (*MI).second->GetName() << ']' << "" << std::endl; } else { std::cout << "" << QId->GetName() << "" << std::endl; } - std::cout << "" << std::endl; + std::cout << "" << std::endl; ++XC; } - std::cout << "" << std::endl; + std::cout << "" << std::endl; } if (!OpList.Empty()) @@ -2303,6 +3443,8 @@ GateKind ASTGateNode::DetermineGateKind(const std::string &GN) { return ASTGateKindH; else if (GN == u8"U") return ASTGateKindU; + else if (GN == u8"disp") + return ASTGateKindDisp; std::string N = ASTStringUtils::Instance().ToLower(GN); @@ -2321,7 +3463,7 @@ ASTType ASTGateNode::DetermineGateType(const std::string &GN) { return ASTTypeGate; } -void ASTGateNode::MaterializeGateQubitParam(ASTIdentifierNode *Id) { +void ASTGateNode::MaterializeGateOperandParam(ASTIdentifierNode *Id) { assert(Id && "Invalid ASTIdentifierNode argument!"); const ASTDeclarationContext *CTX = Id->GetDeclarationContext(); @@ -2347,19 +3489,19 @@ void ASTGateNode::MaterializeGateQubitParam(ASTIdentifierNode *Id) { } if (Id->GetSymbolType() == ASTTypeUndefined) { - Id->SetSymbolType(ASTTypeGateQubitParam); + Id->SetSymbolType(ASTTypeGateOperandParam); Id->SetBits(1U); Id->SetLocalScope(); - STE->SetValueType(ASTTypeGateQubitParam); + STE->SetValueType(ASTTypeGateOperandParam); STE->SetLocalScope(); } - if (Id->GetSymbolType() == ASTTypeGateQubitParam) { + if (Id->GetSymbolType() == ASTTypeGateOperandParam) { unsigned Bits = 1U; if (ASTStringUtils::Instance().IsIndexed(Id->GetName())) Bits = ASTStringUtils::Instance().GetIdentifierIndex(Id->GetName()); assert(!ASTIdentifierNode::InvalidBits(Bits) && - "Invalid number of bits for ASTGateQubitParam!"); + "Invalid number of bits for ASTGateOperandParam!"); if (!GSTM.insert(std::make_pair(Id->GetName(), STE)).second) { std::stringstream M; @@ -2368,6 +3510,17 @@ void ASTGateNode::MaterializeGateQubitParam(ASTIdentifierNode *Id) { DIAGLineCounter::Instance().GetLocation(Id), M.str(), DiagLevel::ICE); } + ASTSymbolTable::Instance().EraseLocalSymbol(Id, Id->GetBits(), + Id->GetSymbolType()); + } else if (ASTUtils::Instance().IsQuantumRegisterType(Id->GetSymbolType())) { + // Fully-typed gate operands may RestoreType() back to qubit/qumode. + if (!GSTM.insert(std::make_pair(Id->GetName(), STE)).second) { + std::stringstream M; + M << "Failure inserting quantum Param into the Gate Symbol Table."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(Id), M.str(), DiagLevel::ICE); + } + ASTSymbolTable::Instance().EraseLocalSymbol(Id, Id->GetBits(), Id->GetSymbolType()); } else { @@ -2409,7 +3562,8 @@ ASTGateNode *ASTGateNode::CloneCall(const ASTIdentifierNode *Id, GId->SetSymbolTableEntry( const_cast(Id->GetSymbolTableEntry())); - ASTGateNode *RG = new ASTGateNode(GId, AL, QL, true); + ASTGateNode *RG = new ASTGateNode( + GId, AL, QL, true, ASTGateQOpList::EmptyDefault, &FormalParamTypes); assert(RG && "Could not create a valid ASTGateNode!"); RG->OpList = OpList; @@ -2418,6 +3572,11 @@ ASTGateNode *ASTGateNode::CloneCall(const ASTIdentifierNode *Id, RG->ControlType = ControlType; RG->Opaque = Opaque; RG->GateCall = true; + RG->FullyTyped = FullyTyped; + RG->FormalParamArraySizes = FormalParamArraySizes; + RG->FormalQuantumTypes = FormalQuantumTypes; + RG->TemplateParams = TemplateParams; + RG->FormalParamArraySizeTemplateIndices = FormalParamArraySizeTemplateIndices; RG->Mangle(); return RG; } @@ -2446,6 +3605,30 @@ ASTUGateNode *ASTUGateNode::CloneCall(const ASTIdentifierNode *Id, return RG; } +ASTDispGateNode *ASTDispGateNode::CloneCall(const ASTIdentifierNode *Id, + const ASTArgumentNodeList &AL, + const ASTAnyTypeList &QL) { + assert(Id && "Invalid ASTIdentifierNode argument!"); + + ASTIdentifierNode *GId = + GateCallIdentifier(Id->GetName(), Id->GetSymbolType(), Id->GetBits()); + assert(GId && "Could not create a valid Gate ASTIdentifierNode!"); + + GId->SetSymbolTableEntry( + const_cast(Id->GetSymbolTableEntry())); + ASTDispGateNode *RG = new ASTDispGateNode(GId, AL, QL, true); + assert(RG && "Could not create a valid ASTDispGateNode!"); + + RG->OpList = OpList; + RG->GDId = Id; + RG->Void = Void; + RG->ControlType = ControlType; + RG->Opaque = Opaque; + RG->GateCall = true; + RG->Mangle(); + return RG; +} + ASTCXGateNode *ASTCXGateNode::CloneCall(const ASTIdentifierNode *Id, const ASTArgumentNodeList &AL, const ASTAnyTypeList &QL) { @@ -2602,67 +3785,81 @@ void ASTGateNode::Mangle() { if (GateCall) { unsigned X = 0; - if (!Params.empty()) { - for (unsigned I = 0; I < Params.size(); ++I) { - if (Params[I]->IsExpression()) { - if (const ASTExpressionNode *EXN = Params[I]->GetExpression()) { + for (unsigned I = 0; I < Params.size(); ++I) { + ASTExpressionNode *EN = Params[I].Expr; + assert(EN && "Invalid classical gate call parameter!"); + + if (ASTAngleNode *AN = dynamic_cast(EN)) { + if (AN->IsExpression()) { + if (const ASTExpressionNode *EXN = AN->GetExpression()) { switch (EXN->GetASTType()) { case ASTTypeBinaryOp: { const ASTBinaryOpNode *BOP = dynamic_cast(EXN); assert(BOP && "Invalid dynamic_cast to an ASTBinaryOpNode!"); - M.GateArg(I, ASTStringUtils::Instance().SanitizeMangled( + M.GateArg(X, ASTStringUtils::Instance().SanitizeMangled( BOP->GetMangledName())); - X = I; } break; case ASTTypeUnaryOp: { const ASTUnaryOpNode *UOP = dynamic_cast(EXN); assert(UOP && "Invalid dynamic_cast to an ASTUnaryOpNode!"); - M.GateArg(I, ASTStringUtils::Instance().SanitizeMangled( + M.GateArg(X, ASTStringUtils::Instance().SanitizeMangled( UOP->GetMangledName())); - X = I; } break; default: - M.GateArg(I, ASTStringUtils::Instance().SanitizeMangled( - Params[I]->GetMangledName())); - X = I; + M.GateArg(X, ASTStringUtils::Instance().SanitizeMangled( + AN->GetMangledName())); break; } + } else { + M.GateArg(X, ASTStringUtils::Instance().SanitizeMangled( + AN->GetMangledName())); } } else { - M.GateArg(I, ASTStringUtils::Instance().SanitizeMangled( - Params[I]->GetMangledName())); - X = I; + M.GateArg(X, ASTStringUtils::Instance().SanitizeMangled( + AN->GetMangledName())); } + } else { + if (EN->GetMangledName().empty()) + EN->Mangle(); + M.GateArg(X, ASTStringUtils::Instance().SanitizeMangled( + EN->GetMangledName())); } - - X += 1U; + ++X; } - if (!QCParams.empty()) { - for (unsigned I = 0; I < QCParams.size(); ++I) { - M.GateArg(X + I, ASTStringUtils::Instance().SanitizeMangled( - QCParams[I]->GetIdentifier()->GetMangledName())); + if (!OperandParams.empty()) { + for (unsigned I = 0; I < OperandParams.size(); ++I) { + M.GateArg(X + I, + ASTStringUtils::Instance().SanitizeMangled( + OperandParams[I]->GetIdentifier()->GetMangledName())); } } } else { + // Definition: encode classical formals then quantum formals. unsigned X = 0; - if (!Params.empty()) { - for (unsigned I = 0; I < Params.size(); ++I) { - M.GateParam(I, ASTStringUtils::Instance().SanitizeMangled( - Params[I]->GetMangledName())); - X = I; - } - - X += 1U; - } - if (!Qubits.empty()) { - for (unsigned I = 0; I < Qubits.size(); ++I) { - M.GateParam(X + I, ASTTypeQubit, 1U, - Qubits[I]->GetIdentifier()->GetGateParamName()); - } + auto EmitSanitizedParam = [&M, &X](ASTExpressionNode *Node) { + assert(Node && "Invalid gate formal for mangling!"); + if (Node->GetMangledName().empty()) + Node->Mangle(); + M.GateParam(X, ASTStringUtils::Instance().SanitizeMangled( + Node->GetMangledName())); + ++X; + }; + + for (std::size_t I = 0; I < Params.size(); ++I) + EmitSanitizedParam(Params[I].Expr); + + for (unsigned I = 0; I < Operands.size(); ++I) { + const ASTIdentifierNode *QId = nullptr; + if (I < OperandParams.size() && OperandParams[I]) + QId = OperandParams[I]->GetIdentifier(); + const ASTType QTy = ResolveOperandQuantumType(QId, I); + + M.GateParam(X + I, QTy, 1U, + Operands[I]->GetIdentifier()->GetGateParamName()); } } @@ -2739,4 +3936,200 @@ bool ASTGateQOpList::TransferToSymbolTable( return true; } +void ASTGateFockControlNode::Mangle() { + ASTMangler M; + M.Start(); + M.TypeIdentifier(GetASTType(), GetName()); + switch (LevelType) { + case ASTTypeInt: + if (I) { + const std::string &MN = I->GetMangledName(); + M.Identifier(MN.empty() ? I->GetName() : MN); + } + break; + case ASTTypeIdentifier: + if (ID) { + const std::string &MN = ID->GetMangledName(); + M.Identifier(MN.empty() ? ID->GetName() : MN); + } + break; + case ASTTypeBinaryOp: + if (BOP) { + const std::string &MN = BOP->GetMangledName(); + M.Identifier(MN.empty() ? BOP->GetName() : MN); + } + break; + case ASTTypeUnaryOp: + if (UOP) { + const std::string &MN = UOP->GetMangledName(); + M.Identifier(MN.empty() ? UOP->GetName() : MN); + } + break; + default: + break; + } + switch (TType) { + case ASTTypeGate: + if (GN) + M.Identifier(GN->GetMangledName()); + break; + case ASTTypeGateQOpNode: + if (GQN) + M.Identifier(GQN->GetMangledName()); + break; + case ASTTypeGateGPhaseExpression: + if (GGEN) + M.Identifier(GGEN->GetMangledName()); + break; + default: + break; + } + M.End(); + const_cast(GetIdentifier()) + ->SetMangledName(M.AsString()); +} + +void ASTGateFockNegControlNode::Mangle() { + ASTMangler M; + M.Start(); + M.TypeIdentifier(GetASTType(), GetName()); + switch (LevelType) { + case ASTTypeInt: + if (I) { + const std::string &MN = I->GetMangledName(); + M.Identifier(MN.empty() ? I->GetName() : MN); + } + break; + case ASTTypeIdentifier: + if (ID) { + const std::string &MN = ID->GetMangledName(); + M.Identifier(MN.empty() ? ID->GetName() : MN); + } + break; + case ASTTypeBinaryOp: + if (BOP) { + const std::string &MN = BOP->GetMangledName(); + M.Identifier(MN.empty() ? BOP->GetName() : MN); + } + break; + case ASTTypeUnaryOp: + if (UOP) { + const std::string &MN = UOP->GetMangledName(); + M.Identifier(MN.empty() ? UOP->GetName() : MN); + } + break; + default: + break; + } + switch (TType) { + case ASTTypeGate: + if (GN) + M.Identifier(GN->GetMangledName()); + break; + case ASTTypeGateQOpNode: + if (GQN) + M.Identifier(GQN->GetMangledName()); + break; + case ASTTypeGateGPhaseExpression: + if (GGEN) + M.Identifier(GGEN->GetMangledName()); + break; + default: + break; + } + M.End(); + const_cast(GetIdentifier()) + ->SetMangledName(M.AsString()); +} + +void ASTGateFockControlNode::print() const { + std::cout << "" << std::endl; + std::cout << "" << std::endl; + switch (LevelType) { + case ASTTypeInt: + if (I) + I->print(); + break; + case ASTTypeIdentifier: + if (ID) + ID->print(); + break; + case ASTTypeBinaryOp: + if (BOP) + BOP->print(); + break; + case ASTTypeUnaryOp: + if (UOP) + UOP->print(); + break; + default: + break; + } + std::cout << "" << std::endl; + std::cout << "" << std::endl; + switch (TType) { + case ASTTypeGate: + if (GN) + GN->print(); + break; + case ASTTypeGateQOpNode: + if (GQN) + GQN->print(); + break; + case ASTTypeGateGPhaseExpression: + if (GGEN) + GGEN->print(); + break; + default: + break; + } + std::cout << "" << std::endl; + std::cout << "" << std::endl; +} + +void ASTGateFockNegControlNode::print() const { + std::cout << "" << std::endl; + std::cout << "" << std::endl; + switch (LevelType) { + case ASTTypeInt: + if (I) + I->print(); + break; + case ASTTypeIdentifier: + if (ID) + ID->print(); + break; + case ASTTypeBinaryOp: + if (BOP) + BOP->print(); + break; + case ASTTypeUnaryOp: + if (UOP) + UOP->print(); + break; + default: + break; + } + std::cout << "" << std::endl; + std::cout << "" << std::endl; + switch (TType) { + case ASTTypeGate: + if (GN) + GN->print(); + break; + case ASTTypeGateQOpNode: + if (GQN) + GQN->print(); + break; + case ASTTypeGateGPhaseExpression: + if (GGEN) + GGEN->print(); + break; + default: + break; + } + std::cout << "" << std::endl; + std::cout << "" << std::endl; +} + } // namespace QASM diff --git a/lib/AST/ASTIdentifier.cpp b/lib/AST/ASTIdentifier.cpp index d3a8e08..41b1f88 100644 --- a/lib/AST/ASTIdentifier.cpp +++ b/lib/AST/ASTIdentifier.cpp @@ -148,7 +148,7 @@ ASTIdentifierNode __attribute__((init_priority(201))) ASTIdentifierNode::Qubit("qubit", ASTTypeQubit, 1U); ASTIdentifierNode __attribute__((init_priority(201))) -ASTIdentifierNode::QubitParam("qubitparam", ASTTypeGateQubitParam, 1U); +ASTIdentifierNode::OperandParam("operandparam", ASTTypeGateOperandParam, 1U); ASTIdentifierNode __attribute__((init_priority(201))) ASTIdentifierNode::QCAlias("qubitcontaineralias", ASTTypeQubitContainerAlias, @@ -922,9 +922,19 @@ ASTType ASTIdentifierRefNode::ResolveReferenceType(ASTType ITy) const { case ASTTypeQubitContainerAlias: return ASTTypeQubitContainer; break; + case ASTTypeQumode: + return ASTTypeQumode; + break; + case ASTTypeQumodeContainer: + return ASTTypeQumodeContainer; + break; case ASTTypeAngle: return ASTTypeAngle; break; + case ASTTypeGate: + // Template call sugar: `foo[3](…)` is an indexed gate name. + return ASTTypeGate; + break; case ASTTypeOpenPulseFrameArray: return ASTTypeOpenPulseFrame; break; diff --git a/lib/AST/ASTIdentifierTypeController.cpp b/lib/AST/ASTIdentifierTypeController.cpp index d2654ce..af5c11b 100644 --- a/lib/AST/ASTIdentifierTypeController.cpp +++ b/lib/AST/ASTIdentifierTypeController.cpp @@ -16,9 +16,11 @@ * ============================================================================= */ +#include #include #include #include +#include #include #include #include @@ -179,6 +181,7 @@ void ASTIdentifierTypeController::CheckIsCallable( case ASTTypeDefcalCallExpression: case ASTTypeFunctionCallExpression: case ASTTypeKernelCallExpression: + case ASTTypeUnitary: return; break; default: @@ -243,7 +246,7 @@ void ASTIdentifierTypeController::CheckIsHardwareQubit( } } -void ASTIdentifierTypeController::CheckGateQubitParamType( +void ASTIdentifierTypeController::CheckGateOperandParamType( const ASTIdentifierNode *Id) const { assert(Id && "Invalid ASTIdentifierNode argument!"); @@ -267,8 +270,8 @@ void ASTIdentifierTypeController::CheckGateQubitParamType( } if (Id->IsGlobalScope()) { - if (Id->GetSymbolType() == ASTTypeGateQubitParam) { - if (!ASTSymbolTable::Instance().TransferGateQubitParam(Id)) { + if (Id->GetSymbolType() == ASTTypeGateOperandParam) { + if (!ASTSymbolTable::Instance().TransferGateOperandParam(Id)) { std::stringstream M; M << "Transfer of Gate Qubit Parameter " << Id->GetName() << " failed."; QasmDiagnosticEmitter::Instance().EmitDiagnostic( @@ -288,7 +291,8 @@ void ASTIdentifierTypeController::CheckGateQubitParamType( } if (Id->GetSymbolType() != ASTTypeUndefined && - Id->GetSymbolType() != ASTTypeGateQubitParam) { + Id->GetSymbolType() != ASTTypeGateOperandParam && + !ASTUtils::Instance().IsQuantumRegisterType(Id->GetSymbolType())) { std::stringstream M; M << "Symbol " << Id->GetName() << " already exists with type " << PrintTypeEnum(Id->GetSymbolType()) << '.'; @@ -308,12 +312,12 @@ void ASTIdentifierTypeController::CheckGateQubitParamType( } } -void ASTIdentifierTypeController::CheckGateQubitParamType( +void ASTIdentifierTypeController::CheckGateOperandParamType( const ASTIdentifierList &IL) const { if (!IL.Empty()) for (ASTIdentifierList::const_iterator LI = IL.begin(); LI != IL.end(); ++LI) - CheckGateQubitParamType(*LI); + CheckGateOperandParamType(*LI); } bool ASTIdentifierTypeController::TypeScopeIsAlwaysGlobal( @@ -328,21 +332,38 @@ bool ASTIdentifierTypeController::IsFunctionArgument( assert(TK && "Invalid ASTToken argument!"); assert(Id && "Invalid ASTIdentifierNode argument!"); assert(CTX && "Invalid ASTDeclarationContext argument!"); + (void)Id; + + if (!ASTExpressionValidator::Instance().IsFunctionType(CTX->GetContextType())) + return false; + + // Array NamedTypeDecls reduce after the formal Identifier is shifted, so + // the previous token is the name — not ',' / ')'. Allow while still in the + // parameter list (seen '(', not yet '{'). + if (ASTExpressionValidator::Instance().IsArrayType(Ty)) + return SeenLParen() && !SeenLBrace(); + + uint32_t TIX = ASTTokenFactory::GetCurrentIndex() - 1; + const ASTToken *ITK = ASTTokenFactory::GetToken(TIX); + assert(ITK && "Could not obtain a valid ASTToken!"); + const std::string &TKS = ITK->GetString(); + return TKS[0] == u8',' || TKS[0] == u8')'; +} - if (ASTExpressionValidator::Instance().IsFunctionType( - CTX->GetContextType())) { - uint32_t TIX = ASTTokenFactory::GetCurrentIndex() - 1; - const ASTToken *ITK = ASTTokenFactory::GetToken(TIX); - assert(ITK && "Could not obtain a valid ASTToken!"); - - const std::string &TKS = ITK->GetString(); - if (ASTExpressionValidator::Instance().IsArrayType(Ty)) - return (TKS[0] == u8',' || TKS[0] == u8')') && !SeenLBrace(); +bool ASTIdentifierTypeController::IsGateParameterArgument(const ASTToken *TK, + ASTType Ty) const { + assert(TK && "Invalid ASTToken argument!"); + (void)TK; - return TKS[0] == u8',' || TKS[0] == u8')'; - } + if (!ASTGateContextBuilder::Instance().InOpenContext()) + return false; + if (!InAngleList() || SeenLBrace()) + return false; + if (!ASTExpressionValidator::Instance().IsArrayType(Ty)) + return false; - return false; + // Same as function arrays: reduction happens on the formal Identifier. + return SeenLParen() && !SeenLBrace(); } } // namespace QASM diff --git a/lib/AST/ASTMangler.cpp b/lib/AST/ASTMangler.cpp index 348abdd..14db4d2 100644 --- a/lib/AST/ASTMangler.cpp +++ b/lib/AST/ASTMangler.cpp @@ -406,9 +406,18 @@ void ASTMangler::Init() { {"QCa", 3}, }, // # [ '_'] qubit container alias { - ASTTypeGateQubitParam, + ASTTypeQumode, + {"QM", 2}, + }, // # [ '_'] qumode + { + ASTTypeQumodeContainer, + {"QMC", 3}, + }, // # [ '_'] qumode container + { + ASTTypeGateOperandParam, {"GQP", 3}, - }, // gate qubit parameter + }, // legacy mangling tag GQP (Gate Qubit Param); type is + // GateOperandParam { ASTTypeQReg, {"RQ", 2}, @@ -874,6 +883,7 @@ void ASTMangler::TypeSize(ASTType Ty, unsigned SZ) { case ASTTypeBitset: case ASTTypeQubitContainer: case ASTTypeQubitContainerAlias: + case ASTTypeQumodeContainer: case ASTTypeCReg: case ASTTypeQReg: case ASTTypeHash: @@ -1097,9 +1107,11 @@ void ASTMangler::TypeIdentifier(ASTType Ty, unsigned TS, case ASTTypeCReg: case ASTTypeQReg: case ASTTypeQubit: + case ASTTypeQumode: case ASTTypeQubitContainer: case ASTTypeQubitContainerAlias: - case ASTTypeGateQubitParam: + case ASTTypeQumodeContainer: + case ASTTypeGateOperandParam: case ASTTypeBool: case ASTTypeInt: case ASTTypeUInt: @@ -1621,9 +1633,9 @@ void ASTDemangler::Init() { {"qubitcontaineralias", 19}, }, { - ASTTypeGateQubitParam, + ASTTypeGateOperandParam, {"gatequbitparam", 15}, - }, + }, // legacy demangle key for GQP (GateOperandParam) { ASTTypeQReg, {"qreg", 4}, @@ -2684,7 +2696,7 @@ const char *ASTDemangler::ParseType(const char *N, ASTDemangled *DMP) { NP += 2; break; case 'Q': - DMP->TD.Ty = ASTTypeGateQubitParam; + DMP->TD.Ty = ASTTypeGateOperandParam; NP += 2; break; case 'o': @@ -2975,7 +2987,7 @@ const char *ASTDemangler::ParseType(const char *N, ASTDemangled *DMP) { case ASTTypeQubit: case ASTTypeQubitContainer: case ASTTypeQubitContainerAlias: - case ASTTypeGateQubitParam: + case ASTTypeGateOperandParam: break; default: if ((NP = ValidateEndOfExpression(NP))) @@ -3530,7 +3542,7 @@ const char *ASTDemangler::ParseParam(const char *S, ASTType Ty, } else if ((PDM->TD.Ty == ASTTypeQubit || PDM->TD.Ty == ASTTypeQubitContainer) && Ty == ASTTypeGateParam) { - PDM->TD.Ty = ASTTypeGateQubitParam; + PDM->TD.Ty = ASTTypeGateOperandParam; } else if (PDM->TD.Ty == ASTTypeAngle && Ty == ASTTypeGateParam) { PDM->TD.Ty = ASTTypeGateAngleParam; } @@ -5354,7 +5366,7 @@ std::string ASTDemangler::AsString() { case ASTTypeQubit: case ASTTypeQubitContainer: case ASTTypeQubitContainerAlias: - case ASTTypeGateQubitParam: + case ASTTypeGateOperandParam: DeserializeQubit(SR); if (InCalBlock) SR << " }"; @@ -5477,7 +5489,7 @@ void ASTDemangler::DeserializeDefcal(std::stringstream &SR) { case ASTTypeQubit: case ASTTypeQubitContainer: case ASTTypeQubitContainerAlias: - case ASTTypeGateQubitParam: + case ASTTypeGateOperandParam: SR << ' ' << DMP->TD.Name; PC = true; break; @@ -5801,7 +5813,7 @@ void ASTDemangler::DeserializeGate(std::stringstream &SR) { SR << TDMM[ASTTypeAngle].Token() << '[' << DMP->TD.UBits << ']' << ' ' << DMP->TD.Name; break; - case ASTTypeGateQubitParam: + case ASTTypeGateOperandParam: SR << DMP->TD.Name; break; default: @@ -6200,7 +6212,7 @@ void ASTDemangler::DeserializeNonScalar(std::stringstream &SR, SR << '[' << DMG.TD.UBits << ']'; SR << ' '; break; - case ASTTypeGateQubitParam: + case ASTTypeGateOperandParam: SR << DMG.TD.Name; if (DMG.TD.IX != static_cast(~0x0)) SR << '[' << DMG.TD.IX << ']'; @@ -6466,7 +6478,7 @@ void ASTDemangler::DeserializeBinaryOp( case ASTTypeQubit: case ASTTypeQubitContainer: case ASTTypeQubitContainerAlias: - case ASTTypeGateQubitParam: + case ASTTypeGateOperandParam: case ASTTypeBoundQubit: case ASTTypeUnboundQubit: case ASTTypeDelay: @@ -6578,7 +6590,7 @@ void ASTDemangler::DeserializeQubit(std::stringstream &SR) { SR << '[' << DM.TD.UBits << ']'; SR << ' ' << DM.TD.Name; break; - case ASTTypeGateQubitParam: + case ASTTypeGateOperandParam: SR << DM.TD.Name; if (DM.TD.IX != static_cast(~0x0)) SR << '[' << DM.TD.IX << ']'; diff --git a/lib/AST/ASTObjectTracker.cpp b/lib/AST/ASTObjectTracker.cpp index cbc0a40..bf48cd4 100644 --- a/lib/AST/ASTObjectTracker.cpp +++ b/lib/AST/ASTObjectTracker.cpp @@ -207,7 +207,7 @@ void ASTObjectTracker::Release() { ASTFunctionStatementBuilder::Instance().Clear(); ASTGateNodeBuilder::Instance().Clear(); ASTGateOpBuilder::Instance().Clear(); - ASTGateQubitParamBuilder::Instance().Clear(); + ASTGateOperandParamBuilder::Instance().Clear(); ASTIdentifierBuilder::Instance().Clear(); ASTIfStatementTracker::Instance().Clear(); ASTIntegerListBuilder::Instance().Clear(); diff --git a/lib/AST/ASTProductionFactory.cpp b/lib/AST/ASTProductionFactory.cpp index 4d48394..edb7b45 100644 --- a/lib/AST/ASTProductionFactory.cpp +++ b/lib/AST/ASTProductionFactory.cpp @@ -38,13 +38,16 @@ #include #include #include -#include +#include #include +#include +#include #include #include #include #include #include +#include #include #include #include @@ -59,6 +62,8 @@ #include #include #include +#include +#include #include #include #include @@ -69,6 +74,7 @@ #include #include #include +#include #include namespace QASM { @@ -104,6 +110,7 @@ unsigned ASTProductionFactory::GetVariantBits( return static_cast(~0x0); } + ASTDeclarationNode * ASTProductionFactory::ProductionRule_1000(const ASTToken *TK, const ASTIdentifierNode *QId) const { @@ -6595,6 +6602,43 @@ ASTStringNode *ASTProductionFactory::ProductionRule_816(const ASTToken *ITK, return SN; } +ASTStringNode * +ASTProductionFactory::ProductionRule_816( + const ASTIdentifierNode *Id, + const ASTToken *STK, + bool D) const { + + assert(Id && "Invalid ASTIdentifierNode argument!"); + assert(STK && "Invalid ASTToken argument!"); + + if (STK->GetString().find(u8' ') != std::string::npos) { + std::stringstream M; + M << "Malformed aggregate type element suffix."; + + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(STK), + M.str(), + DiagLevel::Error); + + return ASTStringNode::ExpressionError(M.str()); + } + + std::stringstream S; + + if (D) + S << Id->GetName() << '.' << STK->GetString(); + else + S << Id->GetName() << STK->GetString(); + + ASTStringNode *SN = new ASTStringNode(S.str()); + assert(SN && "Could not create a valid ASTStringNode!"); + + SN->SetLocation(STK->GetLocation()); + SN->Mangle(); + + return SN; +} + ASTCBitNode * ASTProductionFactory::ProductionRule_817(const ASTToken *TK, const ASTIdentifierNode *IId) const { @@ -7287,7 +7331,9 @@ ASTArrayNode *ASTProductionFactory::ProductionRule_821( Id->SetLocation(TK->GetLocation()); ASTSymbolTable::Instance().LocalScope(Id, Bits, Ty); - ASTArrayNode *AN = ConstructASTArray(Id, TK, Ty, Bits, 1U, Unsigned); + // TyBits 0 ⇒ ConstructASTArray uses per-type defaults (e.g. AngleBits). + // Do not pass 1: that forces 1-bit angle/mpdecimal elements. + ASTArrayNode *AN = ConstructASTArray(Id, TK, Ty, Bits, 0U, Unsigned); if (AN->IsError()) return AN; @@ -7691,14 +7737,123 @@ ASTArrayNode *ASTProductionFactory::ProductionRule_821( return AN; } +// Gate/function parameter lists provisionally type identifiers as Angle. +// Array NamedTypeDecls must rebind that provisional type before construction. +static bool RebindProvisionalArrayIdentifier(const ASTIdentifierNode *Id, + ASTType Ty, unsigned Bits) { + assert(Id && "Invalid ASTIdentifierNode argument!"); + ASTType Cur = Id->GetSymbolType(); + if (Cur == Ty) + return true; + + if (Cur != ASTTypeAngle && Cur != ASTTypeUndefined) { + std::stringstream M; + M << "Identifier '" << Id->GetName() << "' has type " << PrintTypeEnum(Cur) + << ", but array declaration requires " << PrintTypeEnum(Ty) << "."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(Id), M.str(), DiagLevel::Error); + return false; + } + + ASTIdentifierNode *MId = const_cast(Id); + ASTSymbolTableEntry *STE = MId->GetSymbolTableEntry(); + if (!STE) + STE = ASTSymbolTable::Instance().Lookup(MId, MId->GetBits(), Cur); + + if (Cur == ASTTypeAngle) + ASTSymbolTable::Instance().EraseLocalAngle(MId); + + MId->SetSymbolType(Ty); + MId->SetBits(Bits); + if (!STE) { + STE = new ASTSymbolTableEntry(MId, Ty); + assert(STE && "Could not create a SymbolTable Entry for array formal!"); + } else { + STE->SetValueType(Ty); + } + MId->SetSymbolTableEntry(STE); + STE->SetLocalScope(); + + // LocalScope() only relocates matching entries; insert explicitly so + // CreateAST*ArrayNode Lookup(name, bits, Ty) succeeds. + if (!ASTSymbolTable::Instance().InsertLocal(MId, STE)) { + // Already present under this name — update in place via InsertLocal. + } + return true; +} + +static bool AllowArrayInCurrentContext(const ASTToken *TK, + const ASTIdentifierNode *Id, ASTType Ty, + const ASTDeclarationContext *CTX) { + if (ASTScopeController::Instance().CheckArrayContextType( + CTX->GetContextType())) + return true; + if (ASTIdentifierTypeController::Instance().IsFunctionArgument(TK, Id, Ty, + CTX)) + return true; + if (ASTIdentifierTypeController::Instance().IsGateParameterArgument(TK, Ty)) + return true; + + // Fallback: callable parameter lists provisionally open gate/function + // context before the declaration context type is set. Array formals are + // reduced on the Identifier token, so allow them until '{' is seen. + if (ASTExpressionValidator::Instance().IsArrayType(Ty) && + !ASTIdentifierTypeController::Instance().SeenLBrace() && + ASTIdentifierTypeController::Instance().SeenLParen() && + (ASTGateContextBuilder::Instance().InOpenContext() || + ASTFunctionContextBuilder::Instance().InOpenContext())) + return true; + + // Last resort for typed gate formals: declaration context already Gate. + if (ASTExpressionValidator::Instance().IsArrayType(Ty) && + (CTX->GetContextType() == ASTTypeGate || + CTX->GetContextType() == ASTTypeGateDeclaration) && + !ASTIdentifierTypeController::Instance().SeenLBrace()) + return true; + + return false; +} + +/// Resolve array length from Integer or Identifier. Gate template params +/// (`uint N`) use a placeholder size of 1 and return the template name. +static unsigned ResolveArrayLengthBits( + const std::variant &II, + std::string *SizeTemplateName) { + if (SizeTemplateName) + SizeTemplateName->clear(); + if (II.index() == 1) { + if (const ASTIdentifierNode *IId = std::get<1>(II)) { + if (ASTGateTemplateParamBuilder::Instance().IsTemplateParam( + IId->GetName())) { + if (SizeTemplateName) + *SizeTemplateName = IId->GetName(); + return 1U; + } + } + } + switch (II.index()) { + case 0: + if (const ASTIntNode *IIN = std::get<0>(II)) + return ASTUtils::Instance().GetUnsignedValue(IIN); + return 0U; + case 1: + if (const ASTIdentifierNode *IId = std::get<1>(II)) { + ASTScopeController::Instance().CheckIdentifier(IId); + return ASTUtils::Instance().GetUnsignedValue(IId); + } + return 0U; + default: + break; + } + return static_cast(~0x0); +} + ASTArrayNode *ASTProductionFactory::ProductionRule_822( const ASTToken *TK, const ASTIdentifierNode *Id, const std::variant &II, ASTType Ty, bool Unsigned) const { assert(TK && "Invalid ASTToken argument!"); assert(Id && "Invalid ASTIdentifierNode argument!"); - assert(Id->GetSymbolType() == Ty && - "Inconsistent ASTIdentifierNode <-> array symbol type!"); ASTScopeController::Instance().CheckScopeAndUndefined(Id); @@ -7706,19 +7861,17 @@ ASTArrayNode *ASTProductionFactory::ProductionRule_822( ASTDeclarationContextTracker::Instance().GetCurrentContext(); assert(CTX && "Could not obtain a valid ASTDeclarationContext!"); - ASTType CTy = CTX->GetContextType(); - if (!ASTScopeController::Instance().CheckArrayContextType(CTy) && - !ASTIdentifierTypeController::Instance().IsFunctionArgument(TK, Id, Ty, - CTX)) { + if (!AllowArrayInCurrentContext(TK, Id, Ty, CTX)) { std::stringstream M; - M << "Arrays cannot be declared within an " << PrintTypeEnum(CTy) - << " declaration context."; + M << "Arrays cannot be declared within an " + << PrintTypeEnum(CTX->GetContextType()) << " declaration context."; QasmDiagnosticEmitter::Instance().EmitDiagnostic( DIAGLineCounter::Instance().GetLocation(TK), M.str(), DiagLevel::Error); return ArrayConstructionError(Ty, TK, M.str()); } - unsigned Bits = ASTProductionFactory::Instance().GetVariantBits(II); + std::string SizeTemplate; + unsigned Bits = ResolveArrayLengthBits(II, &SizeTemplate); if (ASTIdentifierNode::InvalidBits(Bits)) { std::stringstream M; M << "Invalid number of bits for array expression."; @@ -7728,6 +7881,9 @@ ASTArrayNode *ASTProductionFactory::ProductionRule_822( } Id->SetBits(Bits); + if (!RebindProvisionalArrayIdentifier(Id, Ty, Bits)) + return ArrayConstructionError(Ty, TK, + "Inconsistent array identifier type."); if (!ASTDeclarationContextTracker::Instance().IsGlobalContext(CTX)) { if (!ASTSymbolTable::Instance().TransferLocalUndefinedSymbol(Id, Bits, @@ -7741,8 +7897,12 @@ ASTArrayNode *ASTProductionFactory::ProductionRule_822( } } - ASTArrayNode *AN = ConstructASTArray(Id, TK, Ty, Bits, 1U, Unsigned); + // TyBits 0 ⇒ ConstructASTArray uses per-type defaults (e.g. AngleBits). + // Do not pass 1: that forces 1-bit angle/mpdecimal elements. + ASTArrayNode *AN = ConstructASTArray(Id, TK, Ty, Bits, 0U, Unsigned); AN->SetLocation(TK->GetLocation()); + if (!SizeTemplate.empty()) + AN->SetSizeTemplateName(SizeTemplate); AN->Mangle(); return AN; } @@ -7753,8 +7913,6 @@ ASTArrayNode *ASTProductionFactory::ProductionRule_822( const ASTStringNode *TS, ASTType Ty) const { assert(TK && "Invalid ASTToken argument!"); assert(Id && "Invalid ASTIdentifierNode argument!"); - assert(Id->GetSymbolType() == Ty && - "Inconsistent ASTIdentifierNode <-> array symbol type!"); assert(TS && "Invalid ASTStringNode argument!"); ASTScopeController::Instance().CheckScopeAndUndefined(Id); @@ -7763,11 +7921,10 @@ ASTArrayNode *ASTProductionFactory::ProductionRule_822( ASTDeclarationContextTracker::Instance().GetCurrentContext(); assert(CTX && "Could not obtain a valid ASTDeclarationContext!"); - ASTType CTy = CTX->GetContextType(); - if (!ASTScopeController::Instance().CheckArrayContextType(CTy)) { + if (!AllowArrayInCurrentContext(TK, Id, Ty, CTX)) { std::stringstream M; - M << "Arrays cannot be declared within an " << PrintTypeEnum(CTy) - << " declaration context."; + M << "Arrays cannot be declared within an " + << PrintTypeEnum(CTX->GetContextType()) << " declaration context."; QasmDiagnosticEmitter::Instance().EmitDiagnostic( DIAGLineCounter::Instance().GetLocation(TK), M.str(), DiagLevel::Error); return ArrayConstructionError(Ty, TK, M.str()); @@ -7783,6 +7940,9 @@ ASTArrayNode *ASTProductionFactory::ProductionRule_822( } Id->SetBits(Bits); + if (!RebindProvisionalArrayIdentifier(Id, Ty, Bits)) + return ArrayConstructionError(Ty, TK, + "Inconsistent array identifier type."); if (!ASTDeclarationContextTracker::Instance().IsGlobalContext(CTX)) { if (!ASTSymbolTable::Instance().TransferLocalUndefinedSymbol(Id, Bits, @@ -7818,8 +7978,6 @@ ASTArrayNode *ASTProductionFactory::ProductionRule_822( const ASTStringNode *TS, ASTType Ty) const { assert(TK && "Invalid ASTToken argument!"); assert(Id && "Invalid ASTIdentifierNode argument!"); - assert(Id->GetSymbolType() == Ty && - "Inconsistent ASTIdentifierNode <-> array symbol type!"); assert(TS && "Invalid ASTStringNode argument!"); ASTScopeController::Instance().CheckScopeAndUndefined(Id); @@ -7828,11 +7986,10 @@ ASTArrayNode *ASTProductionFactory::ProductionRule_822( ASTDeclarationContextTracker::Instance().GetCurrentContext(); assert(CTX && "Could not obtain a valid ASTDeclarationContext!"); - ASTType CTy = CTX->GetContextType(); - if (!ASTScopeController::Instance().CheckArrayContextType(CTy)) { + if (!AllowArrayInCurrentContext(TK, Id, Ty, CTX)) { std::stringstream M; - M << "Arrays cannot be declared within an " << PrintTypeEnum(CTy) - << " declaration context."; + M << "Arrays cannot be declared within an " + << PrintTypeEnum(CTX->GetContextType()) << " declaration context."; QasmDiagnosticEmitter::Instance().EmitDiagnostic( DIAGLineCounter::Instance().GetLocation(TK), M.str(), DiagLevel::Error); return ArrayConstructionError(Ty, TK, M.str()); @@ -7848,6 +8005,9 @@ ASTArrayNode *ASTProductionFactory::ProductionRule_822( } Id->SetBits(Bits); + if (!RebindProvisionalArrayIdentifier(Id, Ty, Bits)) + return ArrayConstructionError(Ty, TK, + "Inconsistent array identifier type."); unsigned DBits = ASTProductionFactory::Instance().GetVariantBits(DX); if (ASTIdentifierNode::InvalidBits(DBits)) { @@ -7892,8 +8052,6 @@ ASTArrayNode *ASTProductionFactory::ProductionRule_822( const ASTDurationOfNode *DON, ASTType Ty) const { assert(TK && "Invalid ASTToken argument!"); assert(Id && "Invalid ASTIdentifierNode argument!"); - assert(Id->GetSymbolType() == Ty && - "Inconsistent ASTIdentifierNode <-> array symbol type!"); assert(DON && "Invalid ASTDurationOfNode argument!"); ASTScopeController::Instance().CheckScopeAndUndefined(Id); @@ -7902,11 +8060,10 @@ ASTArrayNode *ASTProductionFactory::ProductionRule_822( ASTDeclarationContextTracker::Instance().GetCurrentContext(); assert(CTX && "Could not obtain a valid ASTDeclarationContext!"); - ASTType CTy = CTX->GetContextType(); - if (!ASTScopeController::Instance().CheckArrayContextType(CTy)) { + if (!AllowArrayInCurrentContext(TK, Id, Ty, CTX)) { std::stringstream M; - M << "Arrays cannot be declared within an " << PrintTypeEnum(CTy) - << " declaration context."; + M << "Arrays cannot be declared within an " + << PrintTypeEnum(CTX->GetContextType()) << " declaration context."; QasmDiagnosticEmitter::Instance().EmitDiagnostic( DIAGLineCounter::Instance().GetLocation(TK), M.str(), DiagLevel::Error); return ArrayConstructionError(Ty, TK, M.str()); @@ -7922,6 +8079,9 @@ ASTArrayNode *ASTProductionFactory::ProductionRule_822( } Id->SetBits(Bits); + if (!RebindProvisionalArrayIdentifier(Id, Ty, Bits)) + return ArrayConstructionError(Ty, TK, + "Inconsistent array identifier type."); if (!ASTDeclarationContextTracker::Instance().IsGlobalContext(CTX)) { if (!ASTSymbolTable::Instance().TransferLocalUndefinedSymbol(Id, Bits, @@ -7957,8 +8117,6 @@ ASTArrayNode *ASTProductionFactory::ProductionRule_822( const ASTDurationOfNode *DON, ASTType Ty) const { assert(TK && "Invalid ASTToken argument!"); assert(Id && "Invalid ASTIdentifierNode argument!"); - assert(Id->GetSymbolType() == Ty && - "Inconsistent ASTIdentifierNode <-> array symbol type!"); assert(DON && "Invalid ASTDurationOfNode argument!"); ASTScopeController::Instance().CheckScopeAndUndefined(Id); @@ -7967,11 +8125,10 @@ ASTArrayNode *ASTProductionFactory::ProductionRule_822( ASTDeclarationContextTracker::Instance().GetCurrentContext(); assert(CTX && "Could not obtain a valid ASTDeclarationContext!"); - ASTType CTy = CTX->GetContextType(); - if (!ASTScopeController::Instance().CheckArrayContextType(CTy)) { + if (!AllowArrayInCurrentContext(TK, Id, Ty, CTX)) { std::stringstream M; - M << "Arrays cannot be declared within an " << PrintTypeEnum(CTy) - << " declaration context."; + M << "Arrays cannot be declared within an " + << PrintTypeEnum(CTX->GetContextType()) << " declaration context."; QasmDiagnosticEmitter::Instance().EmitDiagnostic( DIAGLineCounter::Instance().GetLocation(TK), M.str(), DiagLevel::Error); return ArrayConstructionError(Ty, TK, M.str()); @@ -7987,6 +8144,9 @@ ASTArrayNode *ASTProductionFactory::ProductionRule_822( } Id->SetBits(Bits); + if (!RebindProvisionalArrayIdentifier(Id, Ty, Bits)) + return ArrayConstructionError(Ty, TK, + "Inconsistent array identifier type."); unsigned DBits = ASTProductionFactory::Instance().GetVariantBits(DX); if (ASTIdentifierNode::InvalidBits(DBits)) { @@ -8032,8 +8192,6 @@ ASTArrayNode *ASTProductionFactory::ProductionRule_822( ASTType Ty, bool Unsigned) const { assert(TK && "Invalid ASTToken argument!"); assert(Id && "Invalid ASTIdentifierNode argument!"); - assert(Id->GetSymbolType() == Ty && - "Inconsistent ASTIdentifierNode <-> array symbol type!"); ASTScopeController::Instance().CheckScopeAndUndefined(Id); @@ -8041,17 +8199,17 @@ ASTArrayNode *ASTProductionFactory::ProductionRule_822( ASTDeclarationContextTracker::Instance().GetCurrentContext(); assert(CTX && "Could not obtain a valid ASTDeclarationContext!"); - ASTType CTy = CTX->GetContextType(); - if (!ASTScopeController::Instance().CheckArrayContextType(CTy)) { + if (!AllowArrayInCurrentContext(TK, Id, Ty, CTX)) { std::stringstream M; - M << "Arrays cannot be declared within an " << PrintTypeEnum(CTy) - << " declaration context."; + M << "Arrays cannot be declared within an " + << PrintTypeEnum(CTX->GetContextType()) << " declaration context."; QasmDiagnosticEmitter::Instance().EmitDiagnostic( DIAGLineCounter::Instance().GetLocation(TK), M.str(), DiagLevel::Error); return ArrayConstructionError(Ty, TK, M.str()); } - unsigned Bits = ASTProductionFactory::Instance().GetVariantBits(II); + std::string SizeTemplate; + unsigned Bits = ResolveArrayLengthBits(II, &SizeTemplate); if (ASTIdentifierNode::InvalidBits(Bits)) { std::stringstream M; M << "Invalid number of bits for array expression."; @@ -8061,6 +8219,9 @@ ASTArrayNode *ASTProductionFactory::ProductionRule_822( } Id->SetBits(Bits); + if (!RebindProvisionalArrayIdentifier(Id, Ty, Bits)) + return ArrayConstructionError(Ty, TK, + "Inconsistent array identifier type."); unsigned TyBits = ASTProductionFactory::Instance().GetVariantBits(CX); if (ASTIdentifierNode::InvalidBits(TyBits)) { @@ -8085,6 +8246,8 @@ ASTArrayNode *ASTProductionFactory::ProductionRule_822( ASTArrayNode *AN = ConstructASTArray(Id, TK, Ty, Bits, TyBits, Unsigned); AN->SetLocation(TK->GetLocation()); + if (!SizeTemplate.empty()) + AN->SetSizeTemplateName(SizeTemplate); AN->Mangle(); return AN; } @@ -8097,8 +8260,6 @@ ASTArrayNode *ASTProductionFactory::ProductionRule_822( ASTType Ty, bool Unsigned) const { assert(TK && "Invalid ASTToken argument!"); assert(Id && "Invalid ASTIdentifierNode argument!"); - assert(Id->GetSymbolType() == Ty && - "Inconsistent ASTIdentifierNode <-> array symbol type!"); ASTScopeController::Instance().CheckScopeAndUndefined(Id); @@ -8106,11 +8267,10 @@ ASTArrayNode *ASTProductionFactory::ProductionRule_822( ASTDeclarationContextTracker::Instance().GetCurrentContext(); assert(CTX && "Could not obtain a valid ASTDeclarationContext!"); - ASTType CTy = CTX->GetContextType(); - if (!ASTScopeController::Instance().CheckArrayContextType(CTy)) { + if (!AllowArrayInCurrentContext(TK, Id, Ty, CTX)) { std::stringstream M; - M << "Arrays cannot be declared within an " << PrintTypeEnum(CTy) - << " declaration context."; + M << "Arrays cannot be declared within an " + << PrintTypeEnum(CTX->GetContextType()) << " declaration context."; QasmDiagnosticEmitter::Instance().EmitDiagnostic( DIAGLineCounter::Instance().GetLocation(TK), M.str(), DiagLevel::Error); return ArrayConstructionError(Ty, TK, M.str()); @@ -8126,6 +8286,9 @@ ASTArrayNode *ASTProductionFactory::ProductionRule_822( } Id->SetBits(Bits); + if (!RebindProvisionalArrayIdentifier(Id, Ty, Bits)) + return ArrayConstructionError(Ty, TK, + "Inconsistent array identifier type."); unsigned TyBits = ASTProductionFactory::Instance().GetVariantBits(CX); if (ASTIdentifierNode::InvalidBits(TyBits)) { @@ -15411,6 +15574,38 @@ ASTProductionFactory::ProductionRule_450(const ASTToken *TK, return BOP; } +ASTUnitaryAttributeNode * +ASTProductionFactory::ProductionRule_1465( + const ASTToken *TK, + const ASTIdentifierNode *Target, + ASTUnitaryAttributeKind AttributeKind, + const ASTExpressionNode *Value, + ASTOpType OpType) const { + + assert(TK && "Invalid ASTToken argument!"); + assert(Target && "Invalid unitary attribute target!"); + assert((AttributeKind == ASTUnitaryAttributeBumper || + AttributeKind == ASTUnitaryAttributeBumperMax) && + "Invalid unitary attribute identifier!"); + assert(Value && "Invalid unitary attribute value!"); + + assert((OpType == ASTOpTypeAssign || + OpType == ASTOpTypeAddAssign) && + "Invalid unitary attribute assignment operator!"); + + ASTUnitaryAttributeNode *UAN = + new ASTUnitaryAttributeNode(Target, AttributeKind, Value, OpType); + + assert(UAN && + "Could not create a valid ASTUnitaryAttributeNode!"); + + UAN->SetLocation(TK->GetLocation()); + + ASTStatementBuilder::Instance().Append(UAN); + + return UAN; +} + ASTBinaryOpNode * ASTProductionFactory::ProductionRule_451(const ASTToken *TK, const ASTIdentifierNode *Id, @@ -17058,6 +17253,7 @@ ASTProductionFactory::ProductionRule_1250(const ASTToken *TK, case ASTTypeCCXGate: case ASTTypeCNotGate: case ASTTypeHadamardGate: + case ASTTypeDispGate: case ASTTypeUGate: case ASTTypeDefcal: case ASTTypeDefcalGroup: @@ -17120,6 +17316,7 @@ ASTProductionFactory::ProductionRule_1251(const ASTToken *TK, case ASTTypeCCXGate: case ASTTypeCNotGate: case ASTTypeHadamardGate: + case ASTTypeDispGate: case ASTTypeUGate: case ASTTypeDefcal: case ASTTypeDefcalGroup: @@ -17933,19 +18130,17 @@ ASTProductionFactory::ProductionRule_1102(const ASTToken *TK, } ASTDeclarationNode * -ASTProductionFactory::ProductionRule_1103(const ASTToken *TK, - const ASTIdentifierNode *DId, - const ASTExpressionNode *EN) const { +ASTProductionFactory::ProductionRule_10000(const ASTToken *TK, + const ASTIdentifierNode *DId) const { + assert(TK && "Invalid ASTToken argument!"); assert(DId && "Invalid ASTIdentifierNode argument!"); - assert(EN && "Invalid ASTExpressionNode argument!"); - - if (DId->IsReference() && DId->IsUnresolvedLValue()) - DId = const_cast(DId->GetIdentifier()); + unsigned Bits = DId->GetBits() == 0 ? 1 : DId->GetBits(); + DId->SetBits(Bits); if (!ASTSymbolTable::Instance().TransferUndefinedSymbol( - DId, 1, ASTTypeQubitContainer)) { + DId, Bits, ASTTypeQumodeContainer)) { std::stringstream M; - M << "Could not transfer Symbol Table Entry for ASTTypeQubitContainer."; + M << "Could not transfer Symbol Table Entry for ASTTypeQumodeContainer."; QasmDiagnosticEmitter::Instance().EmitDiagnostic( DIAGLineCounter::Instance().GetLocation(DId), M.str(), DiagLevel::ICE); return ASTDeclarationNode::DeclarationError(DId, M.str()); @@ -17961,169 +18156,424 @@ ASTProductionFactory::ProductionRule_1103(const ASTToken *TK, return ASTDeclarationNode::DeclarationError(DId, M.str()); } - const ASTIdentifierNode *QId = EN->GetIdentifier(); + ASTQumodeContainerNode *QCN = + ASTBuilder::Instance().CreateASTQumodeContainerNode(DId, Bits); + assert(QCN && "Could not create a valid ASTQumodeContainerNode!"); - if (!QId) { - std::stringstream M; - M << "Qubits cannot be initialized from an " - << PrintTypeEnum(EN->GetASTType()) << " expression."; - QasmDiagnosticEmitter::Instance().EmitDiagnostic( - DIAGLineCounter::Instance().GetLocation(), M.str(), DiagLevel::Error); - return ASTDeclarationNode::DeclarationError(DId, M.str()); - } + QCN->SetLocation(DId->GetLocation()); + QCN->Mangle(); + ASTDeclarationNode *DN = + new ASTDeclarationNode(DId, QCN, ASTTypeQumodeContainer, false); + assert(DN && "Could not create a valid ASTDeclarationNode!"); - ASTSymbolTableEntry *STE = ASTSymbolTable::Instance().Lookup( - QId, QId->GetBits(), QId->GetSymbolType()); - assert(STE && "Could not retrieve a valid SymbolTable Entry!"); - assert(STE->HasValue() && "SymbolTable Entry has no Value!"); + DN->SetLocation(TK->GetLocation()); + ASTStatementBuilder::Instance().Append(DN); + ASTDeclarationBuilder::Instance().Append(DN); + return DN; +} - ASTQubitContainerNode *QCN = nullptr; +ASTDeclarationNode * // adding a data type Unitary KH +ASTProductionFactory::ProductionRule_10003(const ASTToken *TK, + const ASTIdentifierNode *DId) const { + assert(TK && "Invalid ASTToken argument!"); + assert(DId && "Invalid ASTIdentifierNode argument!"); - switch (STE->GetValueType()) { - case ASTTypeQubitArray: { - ASTQubitArrayNode *QAN = dynamic_cast( - STE->GetValue()->GetValue()); - assert(QAN && "Could not retrieve a valid ASTQubitArrayNode!"); + unsigned Bits = DId->GetBits() == 0 ? 1 : DId->GetBits(); + DId->SetBits(Bits); - auto Index = QId->GetBits(); - QAN->ValidateIndex(Index, QId->GetLocation()); - QCN = QAN->GetElement(Index); - assert(QCN && "Could not dynamic_cast to an ASTQubitContainerNode!"); - } break; - case ASTTypeQubitContainer: { - QCN = STE->GetValue()->GetValue(); - assert(QCN && "Could not obtain a valid ASTQubitContainerNode!"); - } break; - case ASTTypeQubit: { - ASTQubitNode *QN = STE->GetValue()->GetValue(); - if (QN) { - QCN = new ASTQubitContainerNode(QN->GetIdentifier(), 1U); - assert(QCN && "Could not create a valid ASTQubitContainerNode!"); - } else { - QCN = STE->GetValue()->GetValue(); - assert(QCN && "Could not obtain a valid ASTQubitContainerNode!"); - } - } break; - default: { + if (!ASTSymbolTable::Instance().TransferUndefinedSymbol(DId, Bits, + ASTTypeUnitary)) { std::stringstream M; - M << "Impossible initialization assignment of an ASTQubitContainer " - << "from an " << PrintTypeEnum(STE->GetValueType()) << "."; + M << "Could not transfer Symbol Table Entry for ASTTypeUnitary."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( - DIAGLineCounter::Instance().GetLocation(DId), M.str(), - DiagLevel::Error); + DIAGLineCounter::Instance().GetLocation(DId), M.str(), DiagLevel::ICE); + return ASTDeclarationNode::DeclarationError(DId, M.str()); - } break; } - if (!QCN) { + if (ASTDeclarationBuilder::Instance().DeclAlreadyExists(DId)) { std::stringstream M; - M << "Impossible initialization assignment of an ASTQubitContainer " - << "from an " << PrintTypeEnum(STE->GetValueType()) << "."; + M << "Declaration " << DId->GetName() << " shadows a previous declaration."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( DIAGLineCounter::Instance().GetLocation(DId), M.str(), DiagLevel::Error); + return ASTDeclarationNode::DeclarationError(DId, M.str()); } - // Qubits cannot be copied. This is a shallow clone of the same - // Qubits as the LHS. - ASTQubitContainerNode *NQCN = - ASTBuilder::Instance().CreateASTQubitContainerNode(DId, 1, - QCN->CloneQubits()); - assert(NQCN && "Could not create a valid ASTQubitContainerNode!"); + ASTUnitaryNode *UN = ASTBuilder::Instance().CreateASTUnitaryNode(DId); + + assert(UN && "Could not create a valid ASTUnitaryNode!"); + + UN->SetLocation(DId->GetLocation()); + UN->Mangle(); - NQCN->SetLocation(DId->GetLocation()); - NQCN->Mangle(); ASTDeclarationNode *DN = - new ASTDeclarationNode(DId, NQCN, ASTTypeQubitContainer, false); - assert(DN && "Could not create a valid ASTQubitContainerNode!"); + new ASTDeclarationNode(DId, UN, ASTTypeUnitary, false); + + assert(DN && "Could not create a valid ASTDeclarationNode!"); DN->SetLocation(TK->GetLocation()); ASTStatementBuilder::Instance().Append(DN); ASTDeclarationBuilder::Instance().Append(DN); + return DN; } -ASTDeclarationNode *ASTProductionFactory::ProductionRule_1104( - const ASTToken *TK, const ASTIdentifierNode *DId, - const ASTFunctionCallStatementNode *FC) const { - assert(TK && "Invalid ASTToken argument!"); - assert(DId && "Invalid ASTIdentifierNode argument!"); - assert(FC && "Invalid ASTFunctionCallStatementNode argument!"); - - const ASTFunctionCallNode *EN = FC->GetFunctionCall(); - assert(EN && "Could not obtain a valid ASTFunctionCallNode!"); - std::stringstream M; - M << "A Function cannot return Qubits."; - QasmDiagnosticEmitter::Instance().EmitDiagnostic( - DIAGLineCounter::Instance().GetLocation(EN), M.str(), DiagLevel::Error); - return ASTDeclarationNode::DeclarationError(DId, M.str()); -} +ASTDeclarationNode * +ASTProductionFactory::ProductionRule_10004( + const ASTToken *TK, + const ASTIdentifierNode *DId, + const ASTInitializerList *IL) const { -ASTDeclarationNode *ASTProductionFactory::ProductionRule_1105( - const ASTToken *TK, const ASTIdentifierNode *DId, const ASTIntNode *IXd, - const ASTExpressionNode *EN) const { assert(TK && "Invalid ASTToken argument!"); assert(DId && "Invalid ASTIdentifierNode argument!"); - assert(IXd && "Invalid ASTIntNode Qubit Size argument!"); - assert(EN && "Invalid ASTExpressionNode argument!"); - - unsigned Bits = ASTUtils::Instance().GetUnsignedValue(IXd); - assert(!ASTIdentifierNode::InvalidBits(Bits) && "Invalid number of bits!"); + assert(IL && "Invalid ASTInitializerList argument!"); - if (DId->IsReference() && DId->IsUnresolvedLValue()) { - DId = const_cast(DId->GetIdentifier()); - Bits = DId->GetBits(); - assert(!ASTIdentifierNode::InvalidBits(Bits) && "Invalid number of bits!"); - } + unsigned Bits = DId->GetBits() == 0 ? 1 : DId->GetBits(); + DId->SetBits(Bits); if (!ASTSymbolTable::Instance().TransferUndefinedSymbol( - DId, Bits, ASTTypeQubitContainer)) { + DId, Bits, ASTTypeUnitary)) { + std::stringstream M; - M << "Could not transfer Symbol Table Entry for ASTTypeQubitContainer."; + M << "Could not transfer Symbol Table Entry for ASTTypeUnitary."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( - DIAGLineCounter::Instance().GetLocation(DId), M.str(), DiagLevel::ICE); + DIAGLineCounter::Instance().GetLocation(DId), + M.str(), + DiagLevel::ICE); + return ASTDeclarationNode::DeclarationError(DId, M.str()); } if (ASTDeclarationBuilder::Instance().DeclAlreadyExists(DId)) { std::stringstream M; - M << "Declaration " << DId->GetName() << " shadows a " - << "previous declaration."; + M << "Declaration " << DId->GetName() + << " shadows a previous declaration."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( - DIAGLineCounter::Instance().GetLocation(DId), M.str(), + DIAGLineCounter::Instance().GetLocation(DId), + M.str(), DiagLevel::Error); + return ASTDeclarationNode::DeclarationError(DId, M.str()); } - const ASTIdentifierNode *QId = EN->GetIdentifier(); + ASTUnitaryNode *UN = + ASTBuilder::Instance().CreateASTUnitaryNode(DId, IL); - if (!QId) { - std::stringstream M; - M << "Qubits cannot be initialized from an " - << PrintTypeEnum(EN->GetASTType()) << " expression."; - QasmDiagnosticEmitter::Instance().EmitDiagnostic( - DIAGLineCounter::Instance().GetLocation(EN), M.str(), DiagLevel::Error); - return ASTDeclarationNode::DeclarationError(DId, M.str()); - } + assert(UN && "Could not create a valid ASTUnitaryNode!"); - ASTSymbolTableEntry *STE = ASTSymbolTable::Instance().Lookup( - QId, QId->GetBits(), QId->GetSymbolType()); - assert(STE && "Could not retrieve a valid SymbolTable Entry!"); - assert(STE->HasValue() && "SymbolTable Entry has no Value!"); + UN->SetLocation(DId->GetLocation()); + UN->Mangle(); - switch (STE->GetValueType()) { - case ASTTypeQubit: - case ASTTypeQubitContainer: - break; - default: { - std::stringstream M; - M << "Impossible initialization assignment for an ASTQubitContainer " - << "from an " << PrintTypeEnum(STE->GetValueType()); - QasmDiagnosticEmitter::Instance().EmitDiagnostic( - DIAGLineCounter::Instance().GetLocation(EN), M.str(), DiagLevel::Error); - return ASTDeclarationNode::DeclarationError(DId, M.str()); + ASTDeclarationNode *DN = + new ASTDeclarationNode(DId, UN, ASTTypeUnitary, false); + + assert(DN && "Could not create a valid ASTDeclarationNode!"); + + DN->SetLocation(TK->GetLocation()); + + ASTStatementBuilder::Instance().Append(DN); + ASTDeclarationBuilder::Instance().Append(DN); + + return DN; +} + +ASTDeclarationNode * +ASTProductionFactory::ProductionRule_10001(const ASTToken *TK, + const ASTIdentifierNode *DId, + const ASTIntNode *BI) const { + assert(TK && "Invalid ASTToken argument!"); + assert(DId && "Invalid ASTIdentifierNode argument!"); + assert(BI && "Invalid ASTIntegerNode argument!"); + + unsigned Bits = ASTUtils::Instance().GetUnsignedValue(BI); + assert(!ASTIdentifierNode::InvalidBits(Bits) && + "Invalid number of bits for ASTQumodeContainerNode!"); + + DId->SetBits(Bits); + if (!ASTSymbolTable::Instance().TransferUndefinedSymbol( + DId, Bits, ASTTypeQumodeContainer)) { + std::stringstream M; + M << "Could not transfer Symbol Table Entry for ASTTypeQumodeContainer."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(DId), M.str(), DiagLevel::ICE); + return ASTDeclarationNode::DeclarationError(DId, M.str()); + } + + if (ASTDeclarationBuilder::Instance().DeclAlreadyExists(DId)) { + std::stringstream M; + M << "Declaration " << DId->GetName() << " shadows a " + << "previous declaration."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(DId), M.str(), + DiagLevel::Error); + return ASTDeclarationNode::DeclarationError(DId, M.str()); + } + + ASTQumodeContainerNode *QCN = + ASTBuilder::Instance().CreateASTQumodeContainerNode(DId, Bits); + assert(QCN && "Could not create a valid ASTQumodeContainerNode!"); + + QCN->SetLocation(DId->GetLocation()); + QCN->Mangle(); + ASTDeclarationNode *DN = + new ASTDeclarationNode(DId, QCN, ASTTypeQumodeContainer, false); + assert(DN && "Could not create a valid ASTDeclarationNode!"); + + DN->SetLocation(TK->GetLocation()); + ASTStatementBuilder::Instance().Append(DN); + ASTDeclarationBuilder::Instance().Append(DN); + return DN; +} + +ASTDeclarationNode * +ASTProductionFactory::ProductionRule_10002(const ASTToken *TK, + const ASTIdentifierNode *DId, + const ASTIdentifierNode *IXd) const { + assert(TK && "Invalid ASTToken argument!"); + assert(DId && "Invalid ASTIdentifierNode argument!"); + assert(IXd && "Invalid Qumode Index ASTIdentifierNode!"); + + ASTScopeController::Instance().CheckUndefined(IXd); + ASTScopeController::Instance().CheckOutOfScope(IXd); + + unsigned Bits = ASTUtils::Instance().GetUnsignedValue(IXd); + assert(!ASTIdentifierNode::InvalidBits(Bits) && + "Invalid number of bits for Index Identifier!"); + + if (!ASTSymbolTable::Instance().TransferUndefinedSymbol( + DId, Bits, ASTTypeQumodeContainer)) { + std::stringstream M; + M << "Could not transfer Symbol Table Entry for ASTTypeQumodeContainer."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(DId), M.str(), DiagLevel::ICE); + return ASTDeclarationNode::DeclarationError(DId, M.str()); + } + + if (ASTDeclarationBuilder::Instance().DeclAlreadyExists(DId)) { + std::stringstream M; + M << "Declaration " << DId->GetName() << " shadows a " + << "previous declaration."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(DId), M.str(), + DiagLevel::Error); + return ASTDeclarationNode::DeclarationError(DId, M.str()); + } + + ASTQumodeContainerNode *QCN = + ASTBuilder::Instance().CreateASTQumodeContainerNode(DId, Bits); + assert(QCN && "Could not create a valid ASTQumodeContainerNode!"); + + QCN->SetLocation(DId->GetLocation()); + QCN->Mangle(); + ASTDeclarationNode *DN = + new ASTDeclarationNode(DId, QCN, ASTTypeQumodeContainer, false); + assert(DN && "Could not create a valid ASTDeclarationNode!"); + + DN->SetLocation(TK->GetLocation()); + ASTStatementBuilder::Instance().Append(DN); + ASTDeclarationBuilder::Instance().Append(DN); + return DN; +} + +ASTDeclarationNode * +ASTProductionFactory::ProductionRule_1103(const ASTToken *TK, + const ASTIdentifierNode *DId, + const ASTExpressionNode *EN) const { + assert(DId && "Invalid ASTIdentifierNode argument!"); + assert(EN && "Invalid ASTExpressionNode argument!"); + + if (DId->IsReference() && DId->IsUnresolvedLValue()) + DId = const_cast(DId->GetIdentifier()); + + if (!ASTSymbolTable::Instance().TransferUndefinedSymbol( + DId, 1, ASTTypeQubitContainer)) { + std::stringstream M; + M << "Could not transfer Symbol Table Entry for ASTTypeQubitContainer."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(DId), M.str(), DiagLevel::ICE); + return ASTDeclarationNode::DeclarationError(DId, M.str()); + } + + if (ASTDeclarationBuilder::Instance().DeclAlreadyExists(DId)) { + std::stringstream M; + M << "Declaration " << DId->GetName() << " shadows a " + << "previous declaration."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(DId), M.str(), + DiagLevel::Error); + return ASTDeclarationNode::DeclarationError(DId, M.str()); + } + + const ASTIdentifierNode *QId = EN->GetIdentifier(); + + if (!QId) { + std::stringstream M; + M << "Qubits cannot be initialized from an " + << PrintTypeEnum(EN->GetASTType()) << " expression."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(), M.str(), DiagLevel::Error); + return ASTDeclarationNode::DeclarationError(DId, M.str()); + } + + ASTSymbolTableEntry *STE = ASTSymbolTable::Instance().Lookup( + QId, QId->GetBits(), QId->GetSymbolType()); + assert(STE && "Could not retrieve a valid SymbolTable Entry!"); + assert(STE->HasValue() && "SymbolTable Entry has no Value!"); + + ASTQubitContainerNode *QCN = nullptr; + + switch (STE->GetValueType()) { + case ASTTypeQubitArray: { + ASTQubitArrayNode *QAN = dynamic_cast( + STE->GetValue()->GetValue()); + assert(QAN && "Could not retrieve a valid ASTQubitArrayNode!"); + + auto Index = QId->GetBits(); + QAN->ValidateIndex(Index, QId->GetLocation()); + QCN = QAN->GetElement(Index); + assert(QCN && "Could not dynamic_cast to an ASTQubitContainerNode!"); + } break; + case ASTTypeQubitContainer: { + QCN = STE->GetValue()->GetValue(); + assert(QCN && "Could not obtain a valid ASTQubitContainerNode!"); + } break; + case ASTTypeQubit: { + ASTQubitNode *QN = STE->GetValue()->GetValue(); + if (QN) { + QCN = new ASTQubitContainerNode(QN->GetIdentifier(), 1U); + assert(QCN && "Could not create a valid ASTQubitContainerNode!"); + } else { + QCN = STE->GetValue()->GetValue(); + assert(QCN && "Could not obtain a valid ASTQubitContainerNode!"); + } + } break; + default: { + std::stringstream M; + M << "Impossible initialization assignment of an ASTQubitContainer " + << "from an " << PrintTypeEnum(STE->GetValueType()) << "."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(DId), M.str(), + DiagLevel::Error); + return ASTDeclarationNode::DeclarationError(DId, M.str()); + } break; + } + + if (!QCN) { + std::stringstream M; + M << "Impossible initialization assignment of an ASTQubitContainer " + << "from an " << PrintTypeEnum(STE->GetValueType()) << "."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(DId), M.str(), + DiagLevel::Error); + return ASTDeclarationNode::DeclarationError(DId, M.str()); + } + + // Qubits cannot be copied. This is a shallow clone of the same + // Qubits as the LHS. + ASTQubitContainerNode *NQCN = + ASTBuilder::Instance().CreateASTQubitContainerNode(DId, 1, + QCN->CloneQubits()); + assert(NQCN && "Could not create a valid ASTQubitContainerNode!"); + + NQCN->SetLocation(DId->GetLocation()); + NQCN->Mangle(); + ASTDeclarationNode *DN = + new ASTDeclarationNode(DId, NQCN, ASTTypeQubitContainer, false); + assert(DN && "Could not create a valid ASTQubitContainerNode!"); + + DN->SetLocation(TK->GetLocation()); + ASTStatementBuilder::Instance().Append(DN); + ASTDeclarationBuilder::Instance().Append(DN); + return DN; +} + +ASTDeclarationNode *ASTProductionFactory::ProductionRule_1104( + const ASTToken *TK, const ASTIdentifierNode *DId, + const ASTFunctionCallStatementNode *FC) const { + assert(TK && "Invalid ASTToken argument!"); + assert(DId && "Invalid ASTIdentifierNode argument!"); + assert(FC && "Invalid ASTFunctionCallStatementNode argument!"); + + const ASTFunctionCallNode *EN = FC->GetFunctionCall(); + assert(EN && "Could not obtain a valid ASTFunctionCallNode!"); + + std::stringstream M; + M << "A Function cannot return Qubits."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(EN), M.str(), DiagLevel::Error); + return ASTDeclarationNode::DeclarationError(DId, M.str()); +} + +ASTDeclarationNode *ASTProductionFactory::ProductionRule_1105( + const ASTToken *TK, const ASTIdentifierNode *DId, const ASTIntNode *IXd, + const ASTExpressionNode *EN) const { + assert(TK && "Invalid ASTToken argument!"); + assert(DId && "Invalid ASTIdentifierNode argument!"); + assert(IXd && "Invalid ASTIntNode Qubit Size argument!"); + assert(EN && "Invalid ASTExpressionNode argument!"); + + unsigned Bits = ASTUtils::Instance().GetUnsignedValue(IXd); + assert(!ASTIdentifierNode::InvalidBits(Bits) && "Invalid number of bits!"); + + if (DId->IsReference() && DId->IsUnresolvedLValue()) { + DId = const_cast(DId->GetIdentifier()); + Bits = DId->GetBits(); + assert(!ASTIdentifierNode::InvalidBits(Bits) && "Invalid number of bits!"); + } + + if (!ASTSymbolTable::Instance().TransferUndefinedSymbol( + DId, Bits, ASTTypeQubitContainer)) { + std::stringstream M; + M << "Could not transfer Symbol Table Entry for ASTTypeQubitContainer."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(DId), M.str(), DiagLevel::ICE); + return ASTDeclarationNode::DeclarationError(DId, M.str()); + } + + if (ASTDeclarationBuilder::Instance().DeclAlreadyExists(DId)) { + std::stringstream M; + M << "Declaration " << DId->GetName() << " shadows a " + << "previous declaration."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(DId), M.str(), + DiagLevel::Error); + return ASTDeclarationNode::DeclarationError(DId, M.str()); + } + + const ASTIdentifierNode *QId = EN->GetIdentifier(); + + if (!QId) { + std::stringstream M; + M << "Qubits cannot be initialized from an " + << PrintTypeEnum(EN->GetASTType()) << " expression."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(EN), M.str(), DiagLevel::Error); + return ASTDeclarationNode::DeclarationError(DId, M.str()); + } + + ASTSymbolTableEntry *STE = ASTSymbolTable::Instance().Lookup( + QId, QId->GetBits(), QId->GetSymbolType()); + assert(STE && "Could not retrieve a valid SymbolTable Entry!"); + assert(STE->HasValue() && "SymbolTable Entry has no Value!"); + + switch (STE->GetValueType()) { + case ASTTypeQubit: + case ASTTypeQubitContainer: + break; + default: { + std::stringstream M; + M << "Impossible initialization assignment for an ASTQubitContainer " + << "from an " << PrintTypeEnum(STE->GetValueType()); + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(EN), M.str(), DiagLevel::Error); + return ASTDeclarationNode::DeclarationError(DId, M.str()); } break; } @@ -20003,10 +20453,10 @@ ASTDeclarationNode *ASTProductionFactory::ProductionRule_5000( return DN; } -static void MaterializeGateQubitParams(const ASTToken *TK, - ASTIdentifierList *QIL, - ASTIdentifierList &LQIL, - const ASTDeclarationContext *CTX) { +static void MaterializeGateOperandParams(const ASTToken *TK, + ASTIdentifierList *QIL, + ASTIdentifierList &LQIL, + const ASTDeclarationContext *CTX) { assert(QIL && "Invalid ASTIdentifierList argument!"); assert(CTX && "Invalid ASTDeclarationContext argument!"); @@ -20015,7 +20465,7 @@ static void MaterializeGateQubitParams(const ASTToken *TK, for (ASTIdentifierList::iterator II = QIL->begin(); II != QIL->end(); ++II) { ASTSymbolTableEntry *QSTE = (*II)->GetSymbolTableEntry(); if (QSTE && QSTE->HasValue()) { - if (QSTE->GetValue()->GetASTType() == ASTTypeGateQubitParam) { + if (QSTE->GetValue()->GetASTType() == ASTTypeGateOperandParam) { (*II)->SetDeclarationContext(CTX); (*II)->SetGateLocal(true); (*II)->SetLocalScope(); @@ -20025,7 +20475,7 @@ static void MaterializeGateQubitParams(const ASTToken *TK, ASTProductionFactory::Instance().ProductionRule_1507( TK, (*II)->GetName()); assert(QId && - "Could not create a valid GateQubitParam ASTIdentifierNode!"); + "Could not create a valid GateOperandParam ASTIdentifierNode!"); QId->SetDeclarationContext(CTX); QId->SetGateLocal(true); @@ -20034,7 +20484,7 @@ static void MaterializeGateQubitParams(const ASTToken *TK, (*II)->RestoreType(); } } else if (QSTE && !QSTE->HasValue()) { - if (QSTE->GetValueType() == ASTTypeGateQubitParam) { + if (QSTE->GetValueType() == ASTTypeGateOperandParam) { ASTIdentifierNode *QId = *II; QId->SetDeclarationContext(CTX); QId->SetGateLocal(true); @@ -20046,7 +20496,7 @@ static void MaterializeGateQubitParams(const ASTToken *TK, ASTProductionFactory::Instance().ProductionRule_1507( TK, (*II)->GetName()); assert(QId && - "Could not create a valid GateQubitParam ASTIdentifierNode!"); + "Could not create a valid GateOperandParam ASTIdentifierNode!"); QId->SetDeclarationContext(CTX); QId->SetGateLocal(true); @@ -20059,7 +20509,7 @@ static void MaterializeGateQubitParams(const ASTToken *TK, ASTProductionFactory::Instance().ProductionRule_1507( TK, (*II)->GetName()); assert(QId && - "Could not create a valid GateQubitParam ASTIdentifierNode!"); + "Could not create a valid GateOperandParam ASTIdentifierNode!"); QId->SetDeclarationContext(CTX); QId->SetGateLocal(true); @@ -20076,7 +20526,7 @@ ASTGateDeclarationNode *ASTProductionFactory::ProductionRule_1430( assert(TK && "Invalid ASTToken argument!"); assert(GId && "Invalid ASTIdentifierNode argument!"); assert(DL && "Invalid ASTDeclarationList argument!"); - assert(QIL && "Invalid GateQubitParamList argument!"); + assert(QIL && "Invalid GateOperandParamList argument!"); assert(GOL && "Invalid ASTGateQOpList argument!"); ASTDeclarationContext *CTX = @@ -20151,8 +20601,8 @@ ASTGateDeclarationNode *ASTProductionFactory::ProductionRule_1430( ASTIdentifierList LQIL; - MaterializeGateQubitParams(TK, QIL, LQIL, CTX); - ASTIdentifierTypeController::Instance().CheckGateQubitParamType(LQIL); + MaterializeGateOperandParams(TK, QIL, LQIL, CTX); + ASTIdentifierTypeController::Instance().CheckGateOperandParamType(LQIL); ASTParameterList *PAL = new ASTParameterList(DL); assert(PAL && "Could not create a valid ASTParameterList!"); @@ -20177,7 +20627,7 @@ ASTGateDeclarationNode *ASTProductionFactory::ProductionRule_1430( return ASTGateDeclarationNode::DeclarationError(GId, M.str()); } - ASTGateQubitParamBuilder::Instance().SetGateLocal(); + ASTGateOperandParamBuilder::Instance().SetGateLocal(); PAL->SetLocalScope(); for (ASTParameterList::iterator PI = PAL->begin(); PI != PAL->end(); ++PI) { @@ -20229,9 +20679,9 @@ ASTGateDeclarationNode *ASTProductionFactory::ProductionRule_1430( QIL->Clear(); PAL->DeleteSymbols(); PAL->Clear(); - ASTGateQubitParamBuilder::Instance().ReleaseQubits(); + ASTGateOperandParamBuilder::Instance().ReleaseQubits(); ASTGateContextBuilder::Instance().CloseContext(); - GTN->ClearGateQubits(); + GTN->ClearGateOperands(); GTN->ClearLocalGateSymbols(); ASTDeclarationContextTracker::Instance().PopCurrentContext(); ASTIdentifierTypeController::Instance().StopAngleList(); @@ -20246,7 +20696,7 @@ ASTGateDeclarationNode *ASTProductionFactory::ProductionRule_1431( ASTGateQOpList *GOL) const { assert(TK && "Invalid ASTToken argument!"); assert(GId && "Invalid ASTIdentifierNode argument!"); - assert(QIL && "Invalid GateQubitParamList argument!"); + assert(QIL && "Invalid GateOperandParamList argument!"); assert(GOL && "Invalid ASTGateQOpList argument!"); ASTDeclarationContext *CTX = @@ -20310,8 +20760,8 @@ ASTGateDeclarationNode *ASTProductionFactory::ProductionRule_1431( ASTIdentifierList LQIL; - MaterializeGateQubitParams(TK, QIL, LQIL, CTX); - ASTIdentifierTypeController::Instance().CheckGateQubitParamType(LQIL); + MaterializeGateOperandParams(TK, QIL, LQIL, CTX); + ASTIdentifierTypeController::Instance().CheckGateOperandParamType(LQIL); ASTParameterList *PAL = new ASTParameterList(); assert(PAL && "Could not create a valid ASTParameterList!"); @@ -20328,7 +20778,7 @@ ASTGateDeclarationNode *ASTProductionFactory::ProductionRule_1431( return ASTGateDeclarationNode::DeclarationError(GId, M.str()); } - ASTGateQubitParamBuilder::Instance().SetGateLocal(); + ASTGateOperandParamBuilder::Instance().SetGateLocal(); std::stringstream M; const ASTDeclarationContext *GCX = @@ -20359,9 +20809,9 @@ ASTGateDeclarationNode *ASTProductionFactory::ProductionRule_1431( ASTGateQubitTracker::Instance().Erase(); QIL->DeleteSymbols(); QIL->Clear(); - ASTGateQubitParamBuilder::Instance().ReleaseQubits(); + ASTGateOperandParamBuilder::Instance().ReleaseQubits(); ASTGateContextBuilder::Instance().CloseContext(); - GTN->ClearGateQubits(); + GTN->ClearGateOperands(); GTN->ClearLocalGateSymbols(); ASTDeclarationContextTracker::Instance().PopCurrentContext(); ASTIdentifierTypeController::Instance().StopAngleList(); @@ -20374,7 +20824,7 @@ ASTGateDeclarationNode *ASTProductionFactory::ProductionRule_1431( ASTGateDeclarationNode *ASTProductionFactory::ProductionRule_1432( const ASTToken *TK, ASTIdentifierList *QIL, const ASTLocation &Loc, ASTGateQOpList *GL) const { - assert(QIL && "Invalid ASTGateQubitParamList CX Gate argument!"); + assert(QIL && "Invalid ASTGateOperandParamList CX Gate argument!"); assert(GL && "Invalid ASTGateQOpList CX Gate argument!"); ASTDeclarationContext *CTX = @@ -20414,10 +20864,10 @@ ASTGateDeclarationNode *ASTProductionFactory::ProductionRule_1432( ASTIdentifierList LQIL; - MaterializeGateQubitParams(TK, QIL, LQIL, CTX); - ASTIdentifierTypeController::Instance().CheckGateQubitParamType(LQIL); + MaterializeGateOperandParams(TK, QIL, LQIL, CTX); + ASTIdentifierTypeController::Instance().CheckGateOperandParamType(LQIL); - ASTGateQubitParamBuilder::Instance().SetGateLocal(); + ASTGateOperandParamBuilder::Instance().SetGateLocal(); std::stringstream M; ASTParameterList PL; @@ -20449,9 +20899,9 @@ ASTGateDeclarationNode *ASTProductionFactory::ProductionRule_1432( QIL->DeleteSymbols(); QIL->Clear(); - ASTGateQubitParamBuilder::Instance().ReleaseQubits(); + ASTGateOperandParamBuilder::Instance().ReleaseQubits(); ASTGateContextBuilder::Instance().CloseContext(); - CXG->ClearGateQubits(); + CXG->ClearGateOperands(); CXG->ClearLocalGateSymbols(); ASTDeclarationContextTracker::Instance().PopCurrentContext(); ASTIdentifierTypeController::Instance().StopAngleList(); @@ -20467,7 +20917,7 @@ ASTGateDeclarationNode *ASTProductionFactory::ProductionRule_1433( assert(TK && "Invalid ASTToken argument!"); assert(GS && "Invalid string argument!"); assert(!GS->empty() && "Invalid string argument!"); - assert(QIL && "Invalid ASTGateQubitParamList Hadamard Gate argument!"); + assert(QIL && "Invalid ASTGateOperandParamList Hadamard Gate argument!"); assert(GL && "Invalid ASTGateQOpList Hadamard Gate argument!"); std::string CX = "CX"; @@ -20528,9 +20978,9 @@ ASTGateDeclarationNode *ASTProductionFactory::ProductionRule_1433( ASTIdentifierList LQIL; - MaterializeGateQubitParams(TK, QIL, LQIL, CTX); - ASTIdentifierTypeController::Instance().CheckGateQubitParamType(LQIL); - ASTGateQubitParamBuilder::Instance().SetGateLocal(); + MaterializeGateOperandParams(TK, QIL, LQIL, CTX); + ASTIdentifierTypeController::Instance().CheckGateOperandParamType(LQIL); + ASTGateOperandParamBuilder::Instance().SetGateLocal(); const ASTDeclarationContext *CXG = ASTDeclarationContextTracker::Instance().GetGlobalContext(); @@ -20567,9 +21017,9 @@ ASTGateDeclarationNode *ASTProductionFactory::ProductionRule_1433( QIL->DeleteSymbols(); QIL->Clear(); - ASTGateQubitParamBuilder::Instance().ReleaseQubits(); + ASTGateOperandParamBuilder::Instance().ReleaseQubits(); ASTGateContextBuilder::Instance().CloseContext(); - GTN->ClearGateQubits(); + GTN->ClearGateOperands(); GTN->ClearLocalGateSymbols(); ASTDeclarationContextTracker::Instance().PopCurrentContext(); ASTIdentifierTypeController::Instance().StopAngleList(); @@ -20586,7 +21036,7 @@ ASTGateDeclarationNode *ASTProductionFactory::ProductionRule_1434( assert(GS && "Invalid string argument!"); assert(!GS->empty() && "Invalid string argument!"); assert(DL && "Invalid ASTDeclarationList argument!"); - assert(QIL && "Invalid ASTGateQubitParamList Hadamard Gate argument!"); + assert(QIL && "Invalid ASTGateOperandParamList Hadamard Gate argument!"); assert(GOL && "Invalid ASTGateQOpList Hadamard Gate argument!"); ASTDeclarationContext *CTX = @@ -20650,7 +21100,7 @@ ASTGateDeclarationNode *ASTProductionFactory::ProductionRule_1434( return ASTGateDeclarationNode::DeclarationError(GId, M.str()); } - ASTGateQubitParamBuilder::Instance().SetGateLocal(); + ASTGateOperandParamBuilder::Instance().SetGateLocal(); PAL->SetLocalScope(); for (ASTParameterList::iterator PI = PAL->begin(); PI != PAL->end(); ++PI) { @@ -20683,8 +21133,8 @@ ASTGateDeclarationNode *ASTProductionFactory::ProductionRule_1434( ASTIdentifierList LQIL; - MaterializeGateQubitParams(TK, QIL, LQIL, CTX); - ASTIdentifierTypeController::Instance().CheckGateQubitParamType(LQIL); + MaterializeGateOperandParams(TK, QIL, LQIL, CTX); + ASTIdentifierTypeController::Instance().CheckGateOperandParamType(LQIL); const ASTDeclarationContext *GCX = ASTDeclarationContextTracker::Instance().GetGlobalContext(); @@ -20717,9 +21167,9 @@ ASTGateDeclarationNode *ASTProductionFactory::ProductionRule_1434( QIL->Clear(); PAL->DeleteSymbols(); PAL->Clear(); - ASTGateQubitParamBuilder::Instance().ReleaseQubits(); + ASTGateOperandParamBuilder::Instance().ReleaseQubits(); ASTGateContextBuilder::Instance().CloseContext(); - GTN->ClearGateQubits(); + GTN->ClearGateOperands(); GTN->ClearLocalGateSymbols(); ASTDeclarationContextTracker::Instance().PopCurrentContext(); ASTIdentifierTypeController::Instance().StopAngleList(); @@ -20766,7 +21216,7 @@ ASTGateDeclarationNode *ASTProductionFactory::ProductionRule_1435( std::string GN = ASTStringUtils::Instance().ToUpper(GId->GetName()); if (GN == "U" || GN == "CX" || GN == "CCX" || GN == "CNOT" || GN == "H" || - GN == "HADAMARD") { + GN == "HADAMARD" || GN == "DISP") { std::stringstream M; M << "A Standard Universal Gate [" << GN.c_str() << "] cannot have its own Opaque Re-Declaration!"; @@ -20795,7 +21245,7 @@ ASTGateDeclarationNode *ASTProductionFactory::ProductionRule_1435( PAL->SetLocation(TK->GetLocation()); PAL->SetLocalScope(); - ASTGateQubitParamBuilder::Instance().SetGateLocal(); + ASTGateOperandParamBuilder::Instance().SetGateLocal(); for (ASTParameterList::iterator PI = PAL->begin(); PI != PAL->end(); ++PI) { ASTParameter *P = dynamic_cast(*PI); @@ -20827,8 +21277,8 @@ ASTGateDeclarationNode *ASTProductionFactory::ProductionRule_1435( ASTIdentifierList LQIL; - MaterializeGateQubitParams(TK, QIL, LQIL, CTX); - ASTIdentifierTypeController::Instance().CheckGateQubitParamType(LQIL); + MaterializeGateOperandParams(TK, QIL, LQIL, CTX); + ASTIdentifierTypeController::Instance().CheckGateOperandParamType(LQIL); const ASTDeclarationContext *GCX = ASTDeclarationContextTracker::Instance().GetGlobalContext(); @@ -20855,12 +21305,12 @@ ASTGateDeclarationNode *ASTProductionFactory::ProductionRule_1435( DN->SetDeclarationContext(GCX); ASTDeclarationBuilder::Instance().Append(DN); ASTGateQubitTracker::Instance().Erase(); - ASTGateQubitParamBuilder::Instance().ReleaseQubits(); + ASTGateOperandParamBuilder::Instance().ReleaseQubits(); PAL->DeleteSymbols(); PAL->Clear(); QIL->DeleteSymbols(); QIL->Clear(); - ASTGateQubitParamBuilder::Instance().ReleaseQubits(); + ASTGateOperandParamBuilder::Instance().ReleaseQubits(); ASTGateContextBuilder::Instance().CloseContext(); ASTDeclarationContextTracker::Instance().PopCurrentContext(); ASTIdentifierTypeController::Instance().StopAngleList(); @@ -20907,7 +21357,7 @@ ASTProductionFactory::ProductionRule_1436(const ASTToken *TK, std::string GN = ASTStringUtils::Instance().ToUpper(GId->GetName()); if (GN == "U" || GN == "CX" || GN == "CCX" || GN == "CNOT" || GN == "H" || - GN == "HADAMARD") { + GN == "HADAMARD" || GN == "DISP") { std::stringstream M; M << "A Standard Universal Gate [" << GN.c_str() << "] cannot have its own Opaque Re-Declaration!"; @@ -20944,8 +21394,8 @@ ASTProductionFactory::ProductionRule_1436(const ASTToken *TK, ASTIdentifierList LQIL; - MaterializeGateQubitParams(TK, QIL, LQIL, CTX); - ASTIdentifierTypeController::Instance().CheckGateQubitParamType(LQIL); + MaterializeGateOperandParams(TK, QIL, LQIL, CTX); + ASTIdentifierTypeController::Instance().CheckGateOperandParamType(LQIL); const ASTDeclarationContext *GCX = ASTDeclarationContextTracker::Instance().GetGlobalContext(); @@ -20956,7 +21406,7 @@ ASTProductionFactory::ProductionRule_1436(const ASTToken *TK, PAL->SetLocation(TK->GetLocation()); PAL->SetLocalScope(); - ASTGateQubitParamBuilder::Instance().SetGateLocal(); + ASTGateOperandParamBuilder::Instance().SetGateLocal(); ASTGateNode *GTN = ASTBuilder::Instance().CreateASTGateNode(GId, GK, *PAL, LQIL, GOL); @@ -20980,12 +21430,12 @@ ASTProductionFactory::ProductionRule_1436(const ASTToken *TK, DN->SetDeclarationContext(GCX); ASTDeclarationBuilder::Instance().Append(DN); ASTGateQubitTracker::Instance().Erase(); - ASTGateQubitParamBuilder::Instance().ReleaseQubits(); + ASTGateOperandParamBuilder::Instance().ReleaseQubits(); PAL->DeleteSymbols(); PAL->Clear(); QIL->DeleteSymbols(); QIL->Clear(); - ASTGateQubitParamBuilder::Instance().ReleaseQubits(); + ASTGateOperandParamBuilder::Instance().ReleaseQubits(); ASTGateContextBuilder::Instance().CloseContext(); ASTDeclarationContextTracker::Instance().PopCurrentContext(); ASTIdentifierTypeController::Instance().StopAngleList(); @@ -22067,7 +22517,7 @@ ASTProductionFactory::ProductionRule_1480(const ASTToken *TK, assert(QCAN && "Could not obtain a valid ASTQubitContainerAliasNode!"); QCAN->Mangle(); } break; - case ASTTypeGateQubitParam: { + case ASTTypeGateOperandParam: { std::stringstream M; M << "Attempting to reset a Gate Qubit Parameter."; QasmDiagnosticEmitter::Instance().EmitDiagnostic( @@ -23195,12 +23645,13 @@ ASTProductionFactory::ProductionRule_1507(const ASTToken *TK, assert(TK && "Invalid ASTToken argument!"); assert(!N.empty() && "Invalid Identifier Name!"); - ASTIdentifierNode *QId = new ASTIdentifierNode(N, ASTTypeGateQubitParam, 1U); - assert(QId && "Could not create a valid GateQubitParam ASTIdentifierNode!"); + ASTIdentifierNode *QId = + new ASTIdentifierNode(N, ASTTypeGateOperandParam, 1U); + assert(QId && "Could not create a valid GateOperandParam ASTIdentifierNode!"); ASTSymbolTableEntry *STE = - new ASTSymbolTableEntry(QId, ASTTypeGateQubitParam); - assert(STE && "Could not create a valid GateQubitParam SymbolTable Entry!"); + new ASTSymbolTableEntry(QId, ASTTypeGateOperandParam); + assert(STE && "Could not create a valid GateOperandParam SymbolTable Entry!"); STE->ResetValue(); STE->SetLocalScope(); @@ -23208,7 +23659,8 @@ ASTProductionFactory::ProductionRule_1507(const ASTToken *TK, QId->SetLocalScope(); ASTType CTy = ASTIdentifierTypeController::Instance().GetCurrentType(); ASTIdentifierTypeController::Instance().SetPreviousType(CTy); - ASTIdentifierTypeController::Instance().SetCurrentType(ASTTypeGateQubitParam); + ASTIdentifierTypeController::Instance().SetCurrentType( + ASTTypeGateOperandParam); return QId; } @@ -23237,6 +23689,26 @@ ASTProductionFactory::ProductionRule_1520(const ASTToken *TK, assert(TK && "Invalid ASTToken argument!"); assert(IId && "Invalid ASTIdentifierNode argument!"); + // Loop induction vars are not compile-time constants. Build the subscript + // from the induction Identifier so AsIndexedString() yields `[i]` (not `[0]` + // from a stand-in IntNode value). Array resolution still uses element 0 only + // as a type stand-in when IsInductionVariable(). + const ASTDeclarationContext *DCX = + ASTDeclarationContextTracker::Instance().GetCurrentContext(); + const bool InFor = DCX && DCX->GetContextType() == ASTTypeForStatement; + if (IId->IsInductionVariable() || + (InFor && (IId->GetSymbolType() == ASTTypeInt || + IId->GetSymbolType() == ASTTypeUInt || + IId->GetSymbolType() == ASTTypeMPInteger || + IId->GetSymbolType() == ASTTypeMPUInteger))) { + const_cast(IId)->SetInductionVariable(true); + ASTArraySubscriptNode *ASN = new ASTArraySubscriptNode(IId); + assert(ASN && "Could not create a valid ASTArraySubscriptNode!"); + ASN->SetInductionVariable(IId); + ASN->SetLocation(TK->GetLocation()); + return ASN; + } + std::variant IIV; @@ -25709,6 +26181,7 @@ ASTIfStatementNode *ASTProductionFactory::ProductionRule_3000( case ASTTypeCCXGate: case ASTTypeCNotGate: case ASTTypeHadamardGate: + case ASTTypeDispGate: case ASTTypeUGate: case ASTTypeDefcal: case ASTTypeKernel: @@ -25961,6 +26434,7 @@ ASTIfStatementNode *ASTProductionFactory::ProductionRule_3001( case ASTTypeCCXGate: case ASTTypeCNotGate: case ASTTypeHadamardGate: + case ASTTypeDispGate: case ASTTypeUGate: case ASTTypeDefcal: case ASTTypeKernel: @@ -28702,6 +29176,65 @@ ASTForStatementNode *ASTProductionFactory::ProductionRule_3211( return FSN; } +static ASTStatementList * +GateQOpListToStatementList(const ASTGateQOpList *Body) { + ASTStatementList *SL = new ASTStatementList(); + assert(SL && "Could not create a valid ASTStatementList!"); + if (!Body) + return SL; + for (ASTGateQOpList::const_iterator I = Body->begin(); I != Body->end(); ++I) + SL->Append(*I); + return SL; +} + +ASTGateQOpNode *ASTProductionFactory::ProductionRule_3220( + const ASTToken *TK, ASTIdentifierNode *LId, + ASTForLoopRangeExpressionNode *FLR, ASTGateQOpList *Body) const { + assert(TK && "Invalid ASTToken argument!"); + assert(LId && "Invalid ASTIdentifierNode argument!"); + assert(FLR && "Invalid ASTForLoopRangeExpressionNode argument!"); + assert(Body && "Invalid ASTGateQOpList argument!"); + + ASTStatementList *SL = GateQOpListToStatementList(Body); + ASTForStatementNode *FSN = ProductionRule_3204(TK, LId, FLR, SL); + if (!FSN || FSN->IsError()) { + std::stringstream M; + M << (FSN ? FSN->GetError() : "Could not create gate-body for statement."); + return ASTGateQOpNode::StatementError(M.str()); + } + + ASTGateForOpNode *GFN = + new ASTGateForOpNode(ASTIdentifierNode::GateQOp.Clone(), FSN); + assert(GFN && "Could not create a valid ASTGateForOpNode!"); + GFN->SetLocation(TK->GetLocation()); + GFN->Mangle(); + return GFN; +} + +ASTGateQOpNode *ASTProductionFactory::ProductionRule_3221( + const ASTToken *TK, ASTIdentifierNode *LId, ASTIntegerList *IL, + ASTGateQOpList *Body) const { + assert(TK && "Invalid ASTToken argument!"); + assert(LId && "Invalid ASTIdentifierNode argument!"); + assert(IL && "Invalid ASTIntegerList argument!"); + assert(Body && "Invalid ASTGateQOpList argument!"); + + ASTStatementList *SL = GateQOpListToStatementList(Body); + ASTForStatementNode *FSN = ProductionRule_3200(TK, LId, IL, SL); + if (!FSN || FSN->IsError()) { + std::stringstream M; + M << (FSN ? FSN->GetError() : "Could not create gate-body for statement."); + return ASTGateQOpNode::StatementError(M.str()); + } + + ASTGateForOpNode *GFN = + new ASTGateForOpNode(ASTIdentifierNode::GateQOp.Clone(), FSN); + assert(GFN && "Could not create a valid ASTGateForOpNode!"); + GFN->SetLocation(TK->GetLocation()); + GFN->Mangle(); + return GFN; +} + ASTWhileStatementNode *ASTProductionFactory::ProductionRule_3300( const ASTToken *TK, ASTExpressionNode *EN, ASTStatementList *SL) const { assert(TK && "Invalid ASTToken argument!"); @@ -28839,13 +29372,13 @@ ASTDoWhileStatementNode *ASTProductionFactory::ProductionRule_3400( return DWSN; } -static bool TransferGateQubitParams(const ASTAnyTypeList &ATL) { +static bool TransferGateOperandParams(const ASTAnyTypeList &ATL) { for (unsigned I = 0; I < ATL.Size(); ++I) { const ASTIdentifierNode *AId = nullptr; if (ATL.IsIdentifier(I) && (AId = ATL.GetIdentifier(I)) != nullptr) { switch (AId->GetSymbolType()) { - case ASTTypeGateQubitParam: - if (!ASTSymbolTable::Instance().TransferGateQubitParam(AId)) + case ASTTypeGateOperandParam: + if (!ASTSymbolTable::Instance().TransferGateOperandParam(AId)) return false; break; default: @@ -28930,12 +29463,46 @@ ASTGateQOpNode *ValidateQubitArgs(const ASTAnyTypeList &ATL) { switch (ASTE->GetValueType()) { case ASTTypeQubit: { if (ASTE->HasValue()) { - ASTQubitNode *QN = ASTE->GetValue()->GetValue(); - assert(QN && "Invalid ASTQubitNode obtained from the SymbolTable!"); + ASTQubitNode *QN = ASTE->GetValue()->GetValue(); + assert(QN && "Invalid ASTQubitNode obtained from the SymbolTable!"); + + if (!QN) { + std::stringstream M; + M << "ASTQubitNode without a valid SymbolTable Entry."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(AId), M.str(), + DiagLevel::ICE); + return ASTGateQOpNode::StatementError(AId, M.str()); + } + } + } break; + case ASTTypeQubitContainer: { + if (ASTE->HasValue()) { + ASTQubitContainerNode *QCN = + ASTE->GetValue()->GetValue(); + assert( + QCN && + "Invalid ASTQubitContainerNode obtained from the SymbolTable!"); + + if (!QCN) { + std::stringstream M; + M << "ASTQubitContainerNode without a valid SymbolTable Entry."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(AId), M.str(), + DiagLevel::ICE); + return ASTGateQOpNode::StatementError(AId, M.str()); + } + } + } break; + case ASTTypeQumode: { + if (ASTE->HasValue()) { + ASTQumodeNode *QN = ASTE->GetValue()->GetValue(); + assert(QN && + "Invalid ASTQumodeNode obtained from the SymbolTable!"); if (!QN) { std::stringstream M; - M << "ASTQubitNode without a valid SymbolTable Entry."; + M << "ASTQumodeNode without a valid SymbolTable Entry."; QasmDiagnosticEmitter::Instance().EmitDiagnostic( DIAGLineCounter::Instance().GetLocation(AId), M.str(), DiagLevel::ICE); @@ -28943,17 +29510,16 @@ ASTGateQOpNode *ValidateQubitArgs(const ASTAnyTypeList &ATL) { } } } break; - case ASTTypeQubitContainer: { + case ASTTypeQumodeContainer: { if (ASTE->HasValue()) { - ASTQubitContainerNode *QCN = - ASTE->GetValue()->GetValue(); - assert( - QCN && - "Invalid ASTQubitContainerNode obtained from the SymbolTable!"); + ASTQumodeContainerNode *QCN = + ASTE->GetValue()->GetValue(); + assert(QCN && "Invalid ASTQumodeContainerNode obtained from the " + "SymbolTable!"); if (!QCN) { std::stringstream M; - M << "ASTQubitContainerNode without a valid SymbolTable Entry."; + M << "ASTQumodeContainerNode without a valid SymbolTable Entry."; QasmDiagnosticEmitter::Instance().EmitDiagnostic( DIAGLineCounter::Instance().GetLocation(AId), M.str(), DiagLevel::ICE); @@ -28961,8 +29527,8 @@ ASTGateQOpNode *ValidateQubitArgs(const ASTAnyTypeList &ATL) { } } } break; - case ASTTypeGateQubitParam: { - if (!ASTSymbolTable::Instance().TransferGateQubitParam(AId)) { + case ASTTypeGateOperandParam: { + if (!ASTSymbolTable::Instance().TransferGateOperandParam(AId)) { std::stringstream M; M << "Failure transferring scope of Gate Qubit Parameter."; QasmDiagnosticEmitter::Instance().EmitDiagnostic( @@ -28987,6 +29553,10 @@ ASTGateQOpNode *ValidateQubitArgs(const ASTAnyTypeList &ATL) { ASTE = ASTSymbolTable::Instance().LookupLocal( AIdR->GetName(), AIdR->GetBits(), ASTTypeQubit); } + if (!ASTE && AIdR->GetSymbolType() == ASTTypeQumodeContainer) { + ASTE = ASTSymbolTable::Instance().LookupLocal( + AIdR->GetName(), AIdR->GetBits(), ASTTypeQumode); + } if (!ASTE) { std::stringstream M; @@ -29055,7 +29625,56 @@ ASTGateQOpNode *ValidateQubitArgs(const ASTAnyTypeList &ATL) { } } } break; - case ASTTypeGateQubitParam: + case ASTTypeQumode: { + if (ASTE->HasValue()) { + ASTQumodeNode *QN = ASTE->GetValue()->GetValue(); + assert(QN && + "Invalid ASTQumodeNode obtained from the SymbolTable!"); + + if (!QN) { + std::stringstream M; + M << "ASTQumodeNode without a valid SymbolTable Entry."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(AIdR), M.str(), + DiagLevel::ICE); + return ASTGateQOpNode::StatementError(AIdR->GetIdentifier(), + M.str()); + } + } + } break; + case ASTTypeQumodeContainer: { + if (ASTE->HasValue()) { + ASTQumodeContainerNode *QCN = + ASTE->GetValue()->GetValue(); + assert(QCN && "Invalid ASTQumodeContainerNode obtained from the " + "SymbolTable!"); + + if (!QCN) { + std::stringstream M; + M << "ASTQumodeContainerNode without a valid SymbolTable Entry."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(AIdR), M.str(), + DiagLevel::ICE); + return ASTGateQOpNode::StatementError(AIdR->GetIdentifier(), + M.str()); + } + + ASTQubitNode *QN = QCN->GetQubit(AIdR->GetIndex()); + assert(QN && "Invalid ASTQubitNode obtained from the " + "ASTQumodeContainerNode!"); + if (!QN) { + std::stringstream M; + M << "Invalid ASTQubitNode obtained from the " + "ASTQumodeContainerNode."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(AIdR), M.str(), + DiagLevel::ICE); + return ASTGateQOpNode::StatementError(AIdR->GetIdentifier(), + M.str()); + } + } + } break; + case ASTTypeGateOperandParam: break; default: break; @@ -29395,12 +30014,28 @@ static ASTGateQOpNode *CreateDefcalGroupCall(const ASTToken *TK, return RD; } -static ASTGateQOpNode *CreateGateCall(const ASTToken *TK, - const ASTSymbolTableEntry *STE, - const ASTIdentifierNode *Id, - const ASTArgumentNodeList &ANL, - const ASTAnyTypeList &ATL) { - ASTGateNode *GN = STE->GetValue()->GetValue(); +static ASTGateQOpNode * +CreateGateCall(const ASTToken *TK, const ASTSymbolTableEntry *STE, + const ASTIdentifierNode *Id, const ASTArgumentNodeList &ANL, + const ASTAnyTypeList &ATL, + const ASTExpressionList *TemplateArgs = nullptr) { + // ASTGateNode *GN = STE->GetValue()->GetValue(); + ASTGateNode *GN = nullptr; + + switch (STE->GetValueType()) { + case ASTTypeGate: + GN = STE->GetValue()->GetValue(); + break; + + case ASTTypeUnitary: { + ASTUnitaryNode *UN = STE->GetValue()->GetValue(); + GN = UN; + break; + } + + default: + break; + } if (!GN) { std::stringstream M; M << "Invalid ASTGateNode " << Id->GetName() << " used in constructing " @@ -29410,6 +30045,32 @@ static ASTGateQOpNode *CreateGateCall(const ASTToken *TK, return nullptr; } + if (GN->IsFullyTyped()) { + std::vector> TemplateBounds; + if (!ASTTypeDiscovery::Instance().ValidateTypedGateCall( + TK, GN, ANL, ATL, TemplateArgs, &TemplateBounds)) { + return ASTGateQOpNode::StatementError(Id, "Typed gate call argument " + "type mismatch."); + } + + ASTGateNode *GGN = GN->CloneCall(Id, ANL, ATL); + assert(GGN && "Could not create a valid ASTGateNode call!"); + // Store bindings on the call TemplateParams only — do not overwrite body + // identifiers named N (OpList is shared with the definition; N may appear + // many times). Same pattern as Params: formals stay placeholders in the + // body; call-site values live on the call Gate. + GGN->SetTemplateParamBounds(TemplateBounds); + + ASTGateNodeBuilder::Instance().Append(GGN); + ASTGateQOpNode *RG = + ASTGateOpBuilder::Instance().CreateASTGenericGateOpNode(Id, GGN); + assert(RG && "Failed to create a valid ASTGenericGateOpNode!"); + + RG->SetLocation(TK->GetLocation()); + RG->Mangle(); + return RG; + } + ASTGateNode *GGN = GN->CloneCall(Id, ANL, ATL); assert(GGN && "Could not create a valid ASTGateNode call!"); @@ -29423,10 +30084,10 @@ static ASTGateQOpNode *CreateGateCall(const ASTToken *TK, return RG; } -static ASTGateQOpNode *CreateQOpNodeCall(const ASTToken *TK, - const ASTIdentifierNode *Id, - const ASTArgumentNodeList &ANL, - const ASTAnyTypeList &ATL) { +static ASTGateQOpNode * +CreateQOpNodeCall(const ASTToken *TK, const ASTIdentifierNode *Id, + const ASTArgumentNodeList &ANL, const ASTAnyTypeList &ATL, + const ASTExpressionList *TemplateArgs = nullptr) { const ASTSymbolTableEntry *STE = ASTSymbolTable::Instance().Lookup(Id, Id->GetBits(), Id->GetSymbolType()); if (!STE) { @@ -29455,7 +30116,8 @@ static ASTGateQOpNode *CreateQOpNodeCall(const ASTToken *TK, RQO = CreateDefcalGroupCall(TK, Id, ANL, ATL); break; case ASTTypeGate: - RQO = CreateGateCall(TK, STE, Id, ANL, ATL); + case ASTTypeUnitary: + RQO = CreateGateCall(TK, STE, Id, ANL, ATL, TemplateArgs); break; case ASTTypeCXGate: RQO = CreateCXGateCall(TK, Id, ANL, ATL); @@ -29472,6 +30134,22 @@ static ASTGateQOpNode *CreateQOpNodeCall(const ASTToken *TK, case ASTTypeUGate: RQO = CreateUGateCall(TK, Id, ANL, ATL); break; + case ASTTypeDispGate: { + ASTDispGateNode *GN = dynamic_cast( + STE->GetValue()->GetValue()); + assert(GN && "Invalid Disp ASTGateNode obtained from the SymbolTable!"); + ASTDispGateNode *DGN = GN->CloneCall(Id, ANL, ATL); + assert(DGN && "Could not create a valid ASTDispGateNode!"); + DGN->SetLocation(TK->GetLocation()); + DGN->Mangle(); + ASTGateNodeBuilder::Instance().Append(DGN); + ASTGateQOpNode *RG = + ASTGateOpBuilder::Instance().CreateASTGenericGateOpNode(Id, DGN); + assert(RG && "Failed to create a valid ASTGenericGateOpNode!"); + RG->SetLocation(TK->GetLocation()); + RG->Mangle(); + RQO = RG; + } break; case ASTTypeFunction: { std::stringstream M; M << "A GateQOpNode cannot materialize a function call."; @@ -29495,21 +30173,54 @@ static ASTGateQOpNode *CreateQOpNodeCall(const ASTToken *TK, ASTGateQOpNode *ASTProductionFactory::ProductionRule_3500( const ASTToken *TK, const ASTIdentifierNode *Id, const ASTArgumentNodeList *ANL, const ASTAnyTypeList *ATL) const { + return ProductionRule_3500(TK, Id, nullptr, ANL, ATL); +} + +ASTGateQOpNode *ASTProductionFactory::ProductionRule_3500( + const ASTToken *TK, const ASTIdentifierNode *Id, + const ASTExpressionList *TemplateArgs, const ASTArgumentNodeList *ANL, + const ASTAnyTypeList *ATL) const { assert(TK && "Invalid ASTToken argument!"); assert(Id && "Invalid ASTIdentifierNode argument!"); assert(ANL && "Invalid ASTArgumentNodeList argument!"); assert(ATL && "Invalid ASTAnyTypeList argument!"); + // `foo[3](…)` parses as an indexed Identifier on a gate; rewrite to template + // args on the base gate name (square-bracket template call sugar). + const ASTExpressionList *ResolvedTemplateArgs = TemplateArgs; + const ASTIdentifierNode *CallId = Id; + ASTExpressionList *OwnedTemplateArgs = nullptr; + + if (const ASTIdentifierRefNode *IdR = + dynamic_cast(Id)) { + const ASTIdentifierNode *Base = IdR->GetIdentifier(); + if (Base && Base->GetSymbolType() == ASTTypeGate) { + CallId = Base; + if (!ResolvedTemplateArgs) { + const ASTArraySubscriptNode *ASN = IdR->GetArraySubscriptNode(); + if (ASN) { + OwnedTemplateArgs = ASTExpressionBuilder::Instance().NewList(); + ASTIntNode *IN = + new ASTIntNode(static_cast(ASN->GetIndex())); + assert(IN && "Could not create template arg ASTIntNode!"); + OwnedTemplateArgs->Append(IN); + ResolvedTemplateArgs = OwnedTemplateArgs; + } + } + } + } + ASTIdentifierTypeController::Instance().SetCurrentType(ASTTypeGateCall); - ASTScopeController::Instance().CheckOutOfScope(Id); - ASTIdentifierTypeController::Instance().CheckIsCallable(Id); + ASTScopeController::Instance().CheckOutOfScope(CallId); + ASTIdentifierTypeController::Instance().CheckIsCallable(CallId); - if (!TransferGateQubitParams(*ATL)) { + if (!TransferGateOperandParams(*ATL)) { std::stringstream M; M << "Failure transferring scope of Gate Qubit Parameter."; QasmDiagnosticEmitter::Instance().EmitDiagnostic( - DIAGLineCounter::Instance().GetLocation(Id), M.str(), DiagLevel::ICE); - return ASTGateQOpNode::StatementError(Id, M.str()); + DIAGLineCounter::Instance().GetLocation(CallId), M.str(), + DiagLevel::ICE); + return ASTGateQOpNode::StatementError(CallId, M.str()); } if (ASTGateQOpNode *QOp = ValidateQubitArgs(*ATL)) { @@ -29523,27 +30234,27 @@ ASTGateQOpNode *ASTProductionFactory::ProductionRule_3500( ASTGateQOpNode *RQO = nullptr; ASTType CTy = ASTTypeGate; - if (Id->GetName() == "cx") { - RQO = CreateCXGateCall(TK, Id, *ANL, *ATL); - } else if (Id->GetName() == "ccx") { - RQO = CreateCCXGateCall(TK, Id, *ANL, *ATL); - } else if (Id->GetName() == "cnot") { - RQO = CreateCNOTGateCall(TK, Id, *ANL, *ATL); - } else if (Id->GetName() == "h") { - RQO = CreateHadamardGateCall(TK, Id, *ANL, *ATL); + if (CallId->GetName() == "cx") { + RQO = CreateCXGateCall(TK, CallId, *ANL, *ATL); + } else if (CallId->GetName() == "ccx") { + RQO = CreateCCXGateCall(TK, CallId, *ANL, *ATL); + } else if (CallId->GetName() == "cnot") { + RQO = CreateCNOTGateCall(TK, CallId, *ANL, *ATL); + } else if (CallId->GetName() == "h") { + RQO = CreateHadamardGateCall(TK, CallId, *ANL, *ATL); } else { - RQO = CreateQOpNodeCall(TK, Id, *ANL, *ATL); - CTy = Id->GetSymbolType(); + RQO = CreateQOpNodeCall(TK, CallId, *ANL, *ATL, ResolvedTemplateArgs); + CTy = CallId->GetSymbolType(); } assert(RQO && "Could not create a valid Gate Call!"); - if (!ValidateQubitArgs(Id, ATL)) { + if (!ValidateQubitArgs(CallId, ATL)) { std::stringstream M; M << "Failure validating Qubit arguments."; QasmDiagnosticEmitter::Instance().EmitDiagnostic( DIAGLineCounter::Instance().GetLocation(TK), M.str(), DiagLevel::Error); - return ASTGateQOpNode::StatementError(Id, M.str()); + return ASTGateQOpNode::StatementError(CallId, M.str()); } RQO->SetLocation(TK->GetLocation()); @@ -29799,17 +30510,235 @@ ASTProductionFactory::ProductionRule_3505(const ASTToken *TK, ASTIdentifierTypeController::Instance().SetCurrentType(ASTTypeGateCall); for (unsigned I = 0; I < ATL->Size(); ++I) { - if (ATL->IsIdentifier(I)) { - const ASTIdentifierNode *QId = ATL->GetIdentifier(I); - assert(QId && "Invalid Qubit ASTIdentifierNode from ASTAnyTypeList!"); + if (ATL->IsIdentifier(I)) { + const ASTIdentifierNode *QId = ATL->GetIdentifier(I); + assert(QId && "Invalid Qubit ASTIdentifierNode from ASTAnyTypeList!"); + + if (!ASTStringUtils::Instance().IsBoundQubit(QId->GetName())) + QId->SetGateLocal(true); + } + } + + ASTIdentifierNode *Id = ASTBuilder::Instance().FindASTIdentifierNode( + TK->GetString(), ASTGateNode::GateBits, ASTTypeCCXGate); + if (!Id) { + std::stringstream M; + M << "A Gate (" << TK->GetString() << ") without a definition " + << "cannot materialize a Gate call expression."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(TK), M.str(), DiagLevel::Error); + return ASTGateQOpNode::StatementError(M.str()); + } + + const ASTSymbolTableEntry *STE = ASTSymbolTable::Instance().FindGate(Id); + if (!STE) { + std::stringstream M; + M << TK->GetString() << " Gate has no SymbolTable Entry."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(TK), M.str(), DiagLevel::Error); + return ASTGateQOpNode::StatementError(Id, M.str()); + } + + if (!STE->HasValue()) { + std::stringstream M; + M << TK->GetString() << " Gate SymbolTable Entry has no Value."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(TK), M.str(), DiagLevel::Error); + return ASTGateQOpNode::StatementError(Id, M.str()); + } + + ASTCNotGateNode *CNG = dynamic_cast( + STE->GetValue()->GetValue()); + assert(CNG && "Could not obtain a valid CNot Gate ASTCNotGateNode!"); + + ASTCNotGateNode *CNGC = CNG->CloneCall(Id, *ANL, *ATL); + assert(CNGC && "Could not obtain a valid CNot Gate ASTCNotGateNode!"); + + CNGC->SetLocation(TK->GetLocation()); + CNGC->Mangle(); + + ASTGateQOpNode *RG = + ASTGateOpBuilder::Instance().CreateASTCNotGateOpNode(Id, CNGC); + assert(RG && "Could not create a valid ASTCNotGateOpNode!"); + + RG->SetLocation(TK->GetLocation()); + RG->Mangle(); + + ASTGateContextBuilder::Instance().CloseContext(); + ASTIdentifierTypeController::Instance().Reset(); + return RG; +} + +ASTGateQOpNode * +ASTProductionFactory::ProductionRule_3506(const ASTToken *TK, + const ASTArgumentNodeList *ANL, + const ASTAnyTypeList *ATL) const { + assert(TK && "Invalid ASTToken argument!"); + assert(ANL && "Invalid ASTArgumentNodeList argument!"); + assert(ATL && "Invalid ASTAnyTypeList argument!"); + + ASTIdentifierTypeController::Instance().SetCurrentType(ASTTypeGateCall); + + if (ATL->Size() != 1U) { + std::stringstream M; + M << "The h gate accepts exactly one qubit parameter."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(TK), M.str(), DiagLevel::Error); + return ASTGateQOpNode::StatementError(M.str()); + } + + for (unsigned I = 0; I < ATL->Size(); ++I) { + if (ATL->IsIdentifier(I)) { + const ASTIdentifierNode *QId = ATL->GetIdentifier(I); + assert(QId && "Invalid Qubit ASTIdentifierNode from ASTAnyTypeList!"); + + if (!ASTStringUtils::Instance().IsBoundQubit(QId->GetName())) + QId->SetGateLocal(true); + } + } + + ASTIdentifierNode *Id = ASTBuilder::Instance().FindASTIdentifierNode( + TK->GetString(), ASTGateNode::GateBits, ASTTypeCCXGate); + if (!Id) { + std::stringstream M; + M << "A Gate (" << TK->GetString() << ") without a definition " + << "cannot materialize a Gate call expression."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(TK), M.str(), DiagLevel::Error); + return ASTGateQOpNode::StatementError(M.str()); + } + + const ASTSymbolTableEntry *STE = ASTSymbolTable::Instance().FindGate(Id); + if (!STE) { + std::stringstream M; + M << TK->GetString() << " Gate has no SymbolTable Entry."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(TK), M.str(), DiagLevel::Error); + return ASTGateQOpNode::StatementError(Id, M.str()); + } + + if (!STE->HasValue()) { + std::stringstream M; + M << TK->GetString() << " Gate SymbolTable Entry has no Value."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(TK), M.str(), DiagLevel::Error); + return ASTGateQOpNode::StatementError(Id, M.str()); + } + + ASTHadamardGateNode *HDG = dynamic_cast( + STE->GetValue()->GetValue()); + assert(HDG && "Could not obtain a valid H Gate ASTHadamardGateNode!"); + + ASTHadamardGateNode *CHDG = HDG->CloneCall(Id, *ANL, *ATL); + assert(CHDG && "Could not obtain a valid H Gate ASTHadamardGateNode!"); + + CHDG->SetLocation(TK->GetLocation()); + CHDG->Mangle(); + + ASTGateQOpNode *RG = + ASTGateOpBuilder::Instance().CreateASTHGateOpNode(Id, CHDG); + assert(RG && "Could not create a valid ASTCNotGateOpNode!"); + + RG->SetLocation(TK->GetLocation()); + RG->Mangle(); + + ASTGateContextBuilder::Instance().CloseContext(); + ASTIdentifierTypeController::Instance().Reset(); + return RG; +} + +ASTGateQOpNode * +ASTProductionFactory::ProductionRule_10020(const ASTToken *TK, + const ASTArgumentNodeList *ANL, + const ASTAnyTypeList *ATL) const { + assert(TK && "Invalid ASTToken argument!"); + assert(ANL && "Invalid ASTArgumentNodeList argument!"); + assert(ATL && "Invalid ASTAnyTypeList argument!"); + + ASTIdentifierTypeController::Instance().SetCurrentType(ASTTypeGateCall); + + if (ANL->Size() != 1U) { + std::stringstream M; + M << "The disp gate expects exactly one complex parameter."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(TK), M.str(), DiagLevel::Error); + return ASTGateQOpNode::StatementError(M.str()); + } + + // Like U under ctrl/negctrl: the full operand list is attached to the + // GateEOp before the modifier wraps it. Controls come first; the last + // operand is the disp target and must be a qumode. Extra leading operands + // are only legal while parsing under ctrl/negctrl. + if (ATL->Size() < 1U) { + std::stringstream M; + M << "The disp gate expects a qumode target operand."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(TK), M.str(), DiagLevel::Error); + return ASTGateQOpNode::StatementError(M.str()); + } + + if (ATL->Size() > 1U && + !ASTGateContextBuilder::Instance().InControlModifier()) { + std::stringstream M; + M << "The disp gate expects exactly one qumode operand; use " + "ctrl/negctrl for controlled forms."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(TK), M.str(), DiagLevel::Error); + return ASTGateQOpNode::StatementError(M.str()); + } + + for (unsigned I = 0; I < ATL->Size(); ++I) { + const ASTIdentifierNode *QId = nullptr; + if (ATL->IsIdentifier(I)) + QId = ATL->GetIdentifier(I); + else if (ATL->IsIdentifierRef(I)) + QId = ATL->GetIdentifierRef(I); - if (!ASTStringUtils::Instance().IsBoundQubit(QId->GetName())) - QId->SetGateLocal(true); + if (!QId) { + std::stringstream M; + M << "The disp gate expects quantum identifier operands."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(TK), M.str(), + DiagLevel::Error); + return ASTGateQOpNode::StatementError(M.str()); + } + + if (!ASTStringUtils::Instance().IsBoundQubit(QId->GetName())) + QId->SetGateLocal(true); + + // Prefer the declared quantum-register entry; gate-call parsing may + // have reclassified the identifier as ASTTypeGateOperandParam. + const ASTSymbolTableEntry *QSTE = ASTSymbolTable::Instance().FindQubit(QId); + if (!QSTE) + QSTE = QId->GetSymbolTableEntry(); + ASTType QTy = QSTE ? QSTE->GetValueType() : QId->GetSymbolType(); + + const bool IsTarget = (I + 1U == ATL->Size()); + if (IsTarget) { + if (!ASTUtils::Instance().IsQumodeType(QTy) && + QTy != ASTTypeGateOperandParam) { + std::stringstream M; + M << "The disp gate target must be a qumode, but '" << QId->GetName() + << "' has type " << PrintTypeEnum(QTy) << "."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(QId), M.str(), + DiagLevel::Error); + return ASTGateQOpNode::StatementError(QId, M.str()); + } + } else if (!ASTUtils::Instance().IsQubitType(QTy) && + QTy != ASTTypeGateOperandParam) { + std::stringstream M; + M << "Control operands of disp must be qubits, but '" << QId->GetName() + << "' has type " << PrintTypeEnum(QTy) << "."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(QId), M.str(), + DiagLevel::Error); + return ASTGateQOpNode::StatementError(QId, M.str()); } } ASTIdentifierNode *Id = ASTBuilder::Instance().FindASTIdentifierNode( - TK->GetString(), ASTGateNode::GateBits, ASTTypeCCXGate); + TK->GetString(), ASTGateNode::GateBits, ASTTypeDispGate); if (!Id) { std::stringstream M; M << "A Gate (" << TK->GetString() << ") without a definition " @@ -29820,35 +30749,36 @@ ASTProductionFactory::ProductionRule_3505(const ASTToken *TK, } const ASTSymbolTableEntry *STE = ASTSymbolTable::Instance().FindGate(Id); - if (!STE) { + if (!STE || !STE->HasValue()) { std::stringstream M; - M << TK->GetString() << " Gate has no SymbolTable Entry."; + M << TK->GetString() << " Gate has no SymbolTable Entry Value."; QasmDiagnosticEmitter::Instance().EmitDiagnostic( DIAGLineCounter::Instance().GetLocation(TK), M.str(), DiagLevel::Error); return ASTGateQOpNode::StatementError(Id, M.str()); } - if (!STE->HasValue()) { + ASTDispGateNode *DGN = dynamic_cast( + STE->GetValue()->GetValue()); + assert(DGN && "Could not obtain a valid DispGate ASTGateNode!"); + + ASTDispGateNode *DGA = DGN->CloneCall(Id, *ANL, *ATL); + assert(DGA && "Failed to create an ASTDispGateNode!"); + + if (DGA->GetNumComplexParams() != 1U) { std::stringstream M; - M << TK->GetString() << " Gate SymbolTable Entry has no Value."; + M << "The disp gate expects exactly one complex parameter."; QasmDiagnosticEmitter::Instance().EmitDiagnostic( DIAGLineCounter::Instance().GetLocation(TK), M.str(), DiagLevel::Error); return ASTGateQOpNode::StatementError(Id, M.str()); } - ASTCNotGateNode *CNG = dynamic_cast( - STE->GetValue()->GetValue()); - assert(CNG && "Could not obtain a valid CNot Gate ASTCNotGateNode!"); - - ASTCNotGateNode *CNGC = CNG->CloneCall(Id, *ANL, *ATL); - assert(CNGC && "Could not obtain a valid CNot Gate ASTCNotGateNode!"); - - CNGC->SetLocation(TK->GetLocation()); - CNGC->Mangle(); + DGA->SetLocation(TK->GetLocation()); + DGA->Mangle(); + ASTGateNodeBuilder::Instance().Append(DGA); ASTGateQOpNode *RG = - ASTGateOpBuilder::Instance().CreateASTCNotGateOpNode(Id, CNGC); - assert(RG && "Could not create a valid ASTCNotGateOpNode!"); + ASTGateOpBuilder::Instance().CreateASTGenericGateOpNode(Id, DGA); + assert(RG && "Failed to create a valid ASTGenericGateOpNode!"); RG->SetLocation(TK->GetLocation()); RG->Mangle(); @@ -29858,82 +30788,383 @@ ASTProductionFactory::ProductionRule_3505(const ASTToken *TK, return RG; } -ASTGateQOpNode * -ASTProductionFactory::ProductionRule_3506(const ASTToken *TK, - const ASTArgumentNodeList *ANL, - const ASTAnyTypeList *ATL) const { - assert(TK && "Invalid ASTToken argument!"); - assert(ANL && "Invalid ASTArgumentNodeList argument!"); - assert(ATL && "Invalid ASTAnyTypeList argument!"); +static bool IsExplicitClassicalGateParamType(ASTType Ty) { + switch (Ty) { + case ASTTypeInt: + case ASTTypeUInt: + case ASTTypeFloat: + case ASTTypeDouble: + case ASTTypeMPInteger: + case ASTTypeMPUInteger: + case ASTTypeMPDecimal: + case ASTTypeMPComplex: + case ASTTypeBool: + case ASTTypeBitset: + case ASTTypeDuration: + case ASTTypeAngle: + case ASTTypeLambdaAngle: + case ASTTypePhiAngle: + case ASTTypeThetaAngle: + case ASTTypeAngleArray: + case ASTTypeFloatArray: + case ASTTypeMPDecimalArray: + case ASTTypeIntArray: + case ASTTypeMPIntegerArray: + case ASTTypeBoolArray: + case ASTTypeMPComplexArray: + case ASTTypeDurationArray: + case ASTTypeCBitArray: + // Includes explicit `angle` NamedTypeDecls. Bare Identifier formals also + // become ASTTypeAngle and are accepted here when paired with typed + // quantum operands (fully-typed path); legacy bare-qubit gates stay on + // ProductionRule_1430 / 1431 without call-site checks. + return true; + default: + return false; + } +} - ASTIdentifierTypeController::Instance().SetCurrentType(ASTTypeGateCall); +ASTGateDeclarationNode *ASTProductionFactory::ProductionRule_10030( + const ASTToken *TK, const ASTIdentifierNode *GId, ASTDeclarationList *DL, + ASTIdentifierList *QIL, ASTGateQOpList *GOL) const { + assert(TK && "Invalid ASTToken argument!"); + assert(GId && "Invalid ASTIdentifierNode argument!"); + assert(DL && "Invalid ASTDeclarationList argument!"); + assert(QIL && "Invalid GateOperandParamList argument!"); + assert(GOL && "Invalid ASTGateQOpList argument!"); - if (ATL->Size() != 1U) { + if (DL->Empty()) { std::stringstream M; - M << "The h gate accepts exactly one qubit parameter."; + M << "Fully-typed gate declarations require at least one explicitly " + "typed classical parameter."; QasmDiagnosticEmitter::Instance().EmitDiagnostic( DIAGLineCounter::Instance().GetLocation(TK), M.str(), DiagLevel::Error); - return ASTGateQOpNode::StatementError(M.str()); + return ASTGateDeclarationNode::DeclarationError(GId, M.str()); } - for (unsigned I = 0; I < ATL->Size(); ++I) { - if (ATL->IsIdentifier(I)) { - const ASTIdentifierNode *QId = ATL->GetIdentifier(I); - assert(QId && "Invalid Qubit ASTIdentifierNode from ASTAnyTypeList!"); + for (ASTDeclarationList::const_iterator DI = DL->begin(); DI != DL->end(); + ++DI) { + const ASTDeclarationNode *DN = *DI; + assert(DN && "Invalid ASTDeclarationNode in typed gate parameter list!"); + ASTType PTy = DN->GetASTType(); + if (!IsExplicitClassicalGateParamType(PTy)) { + std::stringstream M; + M << "Fully-typed gate parameter '" << DN->GetName() + << "' must have an explicit classical type (got " << PrintTypeEnum(PTy) + << ")."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(DN), M.str(), + DiagLevel::Error); + return ASTGateDeclarationNode::DeclarationError(GId, M.str()); + } + } - if (!ASTStringUtils::Instance().IsBoundQubit(QId->GetName())) - QId->SetGateLocal(true); + for (ASTIdentifierList::const_iterator II = QIL->begin(); II != QIL->end(); + ++II) { + const ASTIdentifierNode *QId = *II; + assert(QId && "Invalid quantum operand in typed gate declaration!"); + ASTType PTy = QId->GetPolymorphicType(); + if (PTy != ASTTypeQubit && PTy != ASTTypeQumode) { + std::stringstream M; + M << "Fully-typed gate operands must be declared as qubit or qumode " + "(operand '" + << QId->GetName() << "')."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(QId), M.str(), + DiagLevel::Error); + return ASTGateDeclarationNode::DeclarationError(GId, M.str()); } } - ASTIdentifierNode *Id = ASTBuilder::Instance().FindASTIdentifierNode( - TK->GetString(), ASTGateNode::GateBits, ASTTypeCCXGate); - if (!Id) { + std::vector FormalParamTypes; + FormalParamTypes.reserve(DL->Size()); + std::vector FormalParamArraySizes; + FormalParamArraySizes.reserve(DL->Size()); + std::vector FormalParamArraySizeTemplateIndices; + FormalParamArraySizeTemplateIndices.reserve(DL->Size()); + for (ASTDeclarationList::const_iterator DI = DL->begin(); DI != DL->end(); + ++DI) { + const ASTDeclarationNode *DN = *DI; + ASTType PTy = DN->GetASTType(); + if (const ASTIdentifierNode *PId = DN->GetIdentifier()) { + ASTType STy = PId->GetSymbolType(); + if (STy == ASTTypeMPComplexArray || STy == ASTTypeAngleArray || + STy == ASTTypeFloatArray || STy == ASTTypeMPDecimalArray) + PTy = STy; + } + FormalParamTypes.push_back(PTy); + + unsigned ArrSZ = 0U; + unsigned ArrTemplateIdx = static_cast(~0U); + if (PTy == ASTTypeAngleArray || PTy == ASTTypeFloatArray || + PTy == ASTTypeMPDecimalArray || PTy == ASTTypeMPComplexArray) { + if (const ASTExpressionNode *EX = DN->GetExpression()) { + if (const ASTArrayNode *ARN = dynamic_cast(EX)) { + if (ARN->HasSizeTemplate()) { + ArrTemplateIdx = ASTGateTemplateParamBuilder::Instance().IndexOf( + ARN->GetSizeTemplateName()); + ArrSZ = 0U; + } else { + ArrSZ = ARN->Size(); + } + } + } + } + FormalParamArraySizes.push_back(ArrSZ); + FormalParamArraySizeTemplateIndices.push_back(ArrTemplateIdx); + } + + std::vector FormalQuantumTypes; + FormalQuantumTypes.reserve(QIL->Size()); + for (ASTIdentifierList::const_iterator II = QIL->begin(); II != QIL->end(); + ++II) + FormalQuantumTypes.push_back((*II)->GetPolymorphicType()); + + // Same AST construction path as the untyped-operand GateDecl form. + ASTGateDeclarationNode *GDN = ProductionRule_1430(TK, GId, DL, QIL, GOL); + if (!GDN || GDN->IsError()) { + ASTGateTemplateParamBuilder::Instance().Clear(); + return GDN; + } + + ASTGateNode *GN = const_cast(GDN->GetGateNode()); + assert(GN && "Fully-typed gate declaration has no ASTGateNode!"); + GN->SetFormalParamTypes(FormalParamTypes); + GN->SetFormalParamArraySizes(FormalParamArraySizes); + GN->SetFormalParamArraySizeTemplateIndices( + FormalParamArraySizeTemplateIndices); + GN->SetTemplateParams(ASTGateTemplateParamBuilder::Instance().GetParams()); + GN->SetFormalQuantumTypes(FormalQuantumTypes); + GN->SetFullyTyped(true); + // Construction mangled before Formal* was attached; refresh the name. + GN->Mangle(); + ASTGateTemplateParamBuilder::Instance().Clear(); + return GDN; +} + +void ASTProductionFactory::ProductionRule_10031( + const ASTToken *TK, const ASTIdentifierNode *Id) const { + assert(TK && "Invalid ASTToken argument!"); + assert(Id && "Invalid ASTIdentifierNode argument!"); + + if (ASTGateTemplateParamBuilder::Instance().IsTemplateParam(Id->GetName())) { std::stringstream M; - M << "A Gate (" << TK->GetString() << ") without a definition " - << "cannot materialize a Gate call expression."; + M << "Duplicate gate template parameter '" << Id->GetName() << "'."; QasmDiagnosticEmitter::Instance().EmitDiagnostic( - DIAGLineCounter::Instance().GetLocation(TK), M.str(), DiagLevel::Error); - return ASTGateQOpNode::StatementError(M.str()); + DIAGLineCounter::Instance().GetLocation(Id), M.str(), DiagLevel::Error); + return; } - const ASTSymbolTableEntry *STE = ASTSymbolTable::Instance().FindGate(Id); + // Record the name first so TypeDiscovery / array-size resolution can see it. + ASTGateTemplateParamBuilder::Instance().Add(ASTTypeInt, Id->GetName()); + + ASTIdentifierNode *IId = const_cast(Id); + ASTType CurTy = IId->GetSymbolType(); + + // Template params are often provisionally typed as gate operand params / + // undefined during Identifier discovery. Rebind to a gate-local unsigned int + // so body uses like `ctrl[N]` resolve. + if (CurTy != ASTTypeInt && CurTy != ASTTypeUInt) { + ASTSymbolTable::Instance().EraseGateOperandParam(IId); + ASTSymbolTable::Instance().EraseLocal(IId, IId->GetBits(), CurTy); + ASTSymbolTable::Instance().EraseLocalSymbol(IId->GetName()); + IId = ASTBuilder::Instance().CreateASTIdentifierNode( + Id->GetName(), ASTIntNode::IntBits, ASTTypeInt); + if (!IId) { + std::stringstream M; + M << "Could not create identifier for gate template parameter '" + << Id->GetName() << "'."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(Id), M.str(), + DiagLevel::Error); + return; + } + } + + IId->SetBits(ASTIntNode::IntBits); + IId->SetGateLocal(true); + IId->SetLocalScope(); + + ASTSymbolTableEntry *STE = + const_cast(IId->GetSymbolTableEntry()); if (!STE) { - std::stringstream M; - M << TK->GetString() << " Gate has no SymbolTable Entry."; - QasmDiagnosticEmitter::Instance().EmitDiagnostic( - DIAGLineCounter::Instance().GetLocation(TK), M.str(), DiagLevel::Error); - return ASTGateQOpNode::StatementError(Id, M.str()); + STE = + ASTSymbolTable::Instance().Lookup(IId, ASTIntNode::IntBits, ASTTypeInt); + } + if (!STE) { + STE = new ASTSymbolTableEntry(IId, ASTTypeInt); + assert(STE && "Could not create SymbolTable Entry for template param!"); + IId->SetSymbolTableEntry(STE); + IId->SetHasSymbolTableEntry(true); + STE->SetLocalScope(); + ASTSymbolTable::Instance().InsertLocal(IId, STE); } - if (!STE->HasValue()) { + if (!STE->HasValue() || STE->GetValueType() != ASTTypeInt) { + ASTIntNode *IN = ASTBuilder::Instance().CreateASTIntNode(IId, uint32_t(0U)); + if (!IN) { + // CreateASTIntNode may fail if Lookup disagrees; build manually. + IN = new ASTIntNode(IId, uint32_t(0U)); + STE->ResetValue(); + STE->SetValue(new ASTValue<>(IN, ASTTypeInt), ASTTypeInt); + IId->SetSymbolTableEntry(STE); + IN->Mangle(); + } + IN->SetLocation(TK->GetLocation()); + } + + // CreateASTIntNode MangleLiteral() embeds the stand-in 0 as + // `_QLj32_0EEE_`, which looks like a compile-time literal zero. Unbound + // template formals are a NaN analogue (like angle Params); keep the + // numeric placeholder on the IntNode but make MangledLiteralName track + // the named formal (same pattern as angle `lambda`). + if (IId->GetMangledName().empty()) { + if (STE->HasValue()) { + if (ASTIntNode *IN = STE->GetValue()->GetValue()) + IN->Mangle(); + } + } + if (!IId->GetMangledName().empty()) + IId->SetMangledLiteralName(IId->GetMangledName()); +} + +ASTExpressionNode * +ASTProductionFactory::ProductionRule_10010(const ASTExpressionList *EL) const { + assert(EL && "Invalid ASTExpressionList argument!"); + + if (EL->Empty()) { std::stringstream M; - M << TK->GetString() << " Gate SymbolTable Entry has no Value."; + M << "Gate array parameter cannot be empty."; QasmDiagnosticEmitter::Instance().EmitDiagnostic( - DIAGLineCounter::Instance().GetLocation(TK), M.str(), DiagLevel::Error); - return ASTGateQOpNode::StatementError(Id, M.str()); + DIAGLineCounter::Instance().GetLocation(), M.str(), DiagLevel::Error); + return ASTAngleArrayNode::ExpressionError(M.str()); } - ASTHadamardGateNode *HDG = dynamic_cast( - STE->GetValue()->GetValue()); - assert(HDG && "Could not obtain a valid H Gate ASTHadamardGateNode!"); + auto ResolveElementType = [](const ASTExpressionNode *EN) -> ASTType { + ASTType ElTy = EN->GetASTType(); + if (ElTy == ASTTypeIdentifier || ElTy == ASTTypeIdentifierRef) { + if (const ASTIdentifierNode *EId = EN->GetIdentifier()) { + ElTy = EId->GetSymbolType(); + if (const ASTSymbolTableEntry *ESTE = EId->GetSymbolTableEntry()) + ElTy = ESTE->GetValueType(); + } + } + return ElTy; + }; - ASTHadamardGateNode *CHDG = HDG->CloneCall(Id, *ANL, *ATL); - assert(CHDG && "Could not obtain a valid H Gate ASTHadamardGateNode!"); + // Same classification used at call-site validation (ASTGateType). + bool HasComplex = ASTGateType::ExpressionListHasComplex(EL); - CHDG->SetLocation(TK->GetLocation()); - CHDG->Mangle(); + if (HasComplex) { + ASTMPComplexList CXL(*EL); + if (CXL.Size() != EL->Size()) { + std::stringstream M; + M << "Could not construct a complex array from gate array literal."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(), M.str(), DiagLevel::Error); + return ASTMPComplexArrayNode::ExpressionError(M.str(), nullptr); + } - ASTGateQOpNode *RG = - ASTGateOpBuilder::Instance().CreateASTHGateOpNode(Id, CHDG); - assert(RG && "Could not create a valid ASTCNotGateOpNode!"); + std::vector Complexes; + Complexes.reserve(CXL.Size()); + for (unsigned I = 0; I < CXL.Size(); ++I) { + ASTMPComplexNode *MPC = CXL.GetComplex(I); + if (!MPC) { + std::stringstream M; + M << "Invalid complex expression in gate array parameter at index " << I + << "."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(), M.str(), + DiagLevel::Error); + return ASTMPComplexArrayNode::ExpressionError(M.str(), nullptr); + } + MPC->Mangle(); + Complexes.push_back(MPC); + } - RG->SetLocation(TK->GetLocation()); - RG->Mangle(); + std::stringstream ArrName; + ArrName << "ast-gate-complex-array-lit-" << Complexes.size(); + ASTIdentifierNode *ArrId = + new ASTIdentifierNode(ArrName.str(), ASTTypeMPComplexArray, + static_cast(Complexes.size())); + assert(ArrId && "Could not create a Complex Array ASTIdentifierNode!"); - ASTGateContextBuilder::Instance().CloseContext(); - ASTIdentifierTypeController::Instance().Reset(); - return RG; + ArrId->SetPolymorphicName("gatearraycomplex"); + ASTMPComplexArrayNode *CAN = new ASTMPComplexArrayNode( + ArrId, Complexes, ASTMPComplexNode::DefaultBits); + assert(CAN && "Could not create a valid ASTMPComplexArrayNode!"); + + CAN->Mangle(); + return CAN; + } + + std::vector Angles; + Angles.reserve(EL->Size()); + unsigned C = 0; + + for (ASTExpressionList::const_iterator I = EL->begin(); I != EL->end(); ++I) { + const ASTExpressionNode *EN = dynamic_cast(*I); + if (!EN) { + std::stringstream M; + M << "Invalid expression in gate angle-array parameter at index " << C + << "."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(), M.str(), DiagLevel::Error); + return ASTAngleArrayNode::ExpressionError(M.str()); + } + + ASTType ElTy = ResolveElementType(EN); + if (ASTExpressionValidator::Instance().IsComplexType(ElTy)) { + std::stringstream M; + M << "Complex value is not valid as element " << C + << " of a real/angle gate array parameter."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(EN), M.str(), + DiagLevel::Error); + return ASTAngleArrayNode::ExpressionError(M.str()); + } + + std::stringstream SAN; + SAN << "ast-gate-array-angle-" << C; + ASTIdentifierNode *AId = ASTBuilder::Instance().CreateASTIdentifierNode( + SAN.str(), ASTAngleNode::AngleBits, ASTTypeAngle); + assert(AId && "Could not create an Angle ASTIdentifierNode!"); + + ASTAngleType ATy = ASTAngleNode::DetermineAngleType(AId->GetName()); + ASTAngleNode *AN = ASTBuilder::Instance().CreateASTAngleNodeFromExpression( + AId, EN, ATy, ASTAngleNode::AngleBits); + if (!AN) { + std::stringstream M; + M << "Could not convert gate angle-array element at index " << C + << " to an angle."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(EN), M.str(), + DiagLevel::Error); + return ASTAngleArrayNode::ExpressionError(M.str()); + } + + AN->SetGateParamName(AId->GetName()); + AId->SetPolymorphicName(AId->GetName()); + AN->Mangle(); + AN->MangleLiteral(); + ASTAngleNodeBuilder::Instance().Insert(AN); + ASTAngleNodeBuilder::Instance().Append(AN); + Angles.push_back(AN); + ++C; + } + + std::stringstream ArrName; + ArrName << "ast-gate-angle-array-lit-" << Angles.size(); + ASTIdentifierNode *ArrId = new ASTIdentifierNode( + ArrName.str(), ASTTypeAngleArray, static_cast(Angles.size())); + assert(ArrId && "Could not create an Array ASTIdentifierNode!"); + + ArrId->SetPolymorphicName("gatearrayangle"); + ASTAngleArrayNode *AAN = new ASTAngleArrayNode(ArrId, Angles); + assert(AAN && "Could not create a valid ASTAngleArrayNode!"); + + AAN->Mangle(); + return AAN; } ASTGateQOpNode *ASTProductionFactory::ProductionRule_3507( @@ -30229,7 +31460,7 @@ ASTProductionFactory::ProductionRule_3854(const ASTToken *TK, assert(QSTE && "Could not obtain a valid SymbolTable Entry!"); if (!QSTE) { std::stringstream M; - M << "Could not obtain a valid ASTGateQubitParam SymbolTable Entry."; + M << "Could not obtain a valid ASTGateOperandParam SymbolTable Entry."; QasmDiagnosticEmitter::Instance().EmitDiagnostic( DIAGLineCounter::Instance().GetLocation(TK), M.str(), DiagLevel::ICE); @@ -30242,12 +31473,12 @@ ASTProductionFactory::ProductionRule_3854(const ASTToken *TK, QSTE->SetLocalScope(); if (!QSTE->HasValue()) { - ASTGateQubitParamNode *QPN = new ASTGateQubitParamNode( + ASTGateOperandParamNode *QPN = new ASTGateOperandParamNode( QId, QIX++, QId->GetBits(), QId->GetName()); - assert(QPN && "Could not create a valid ASTGateQubitParamNode!"); + assert(QPN && "Could not create a valid ASTGateOperandParamNode!"); if (!QPN) { std::stringstream M; - M << "Could not create a valid ASTGateQubitParamNode."; + M << "Could not create a valid ASTGateOperandParamNode."; QasmDiagnosticEmitter::Instance().EmitDiagnostic( DIAGLineCounter::Instance().GetLocation(TK), M.str(), DiagLevel::ICE); @@ -30256,12 +31487,12 @@ ASTProductionFactory::ProductionRule_3854(const ASTToken *TK, QPN->SetDeclarationContext(CTX); QSTE->ResetValue(); - QSTE->SetValue(new ASTValue<>(QPN, ASTTypeGateQubitParam), - ASTTypeGateQubitParam); + QSTE->SetValue(new ASTValue<>(QPN, ASTTypeGateOperandParam), + ASTTypeGateOperandParam); assert(QSTE->HasValue() && "SymbolTable Entry has no Value!"); if (!QSTE->HasValue()) { std::stringstream M; - M << "ASTGateQubitParam SymbolTable Entry has no Value."; + M << "ASTGateOperandParam SymbolTable Entry has no Value."; QasmDiagnosticEmitter::Instance().EmitDiagnostic( DIAGLineCounter::Instance().GetLocation(TK), M.str(), DiagLevel::ICE); @@ -30467,4 +31698,82 @@ ASTProductionFactory::ProductionRule_8001(const ASTToken *TK, return EN; } +ASTGateFockControlNode *ASTProductionFactory::ProductionRule_3855( + const ASTToken *TK, const ASTGateQOpNode *GQN, + const ASTExpressionNode *Level) const { + assert(TK && "Invalid ASTToken argument!"); + assert(GQN && "Invalid ASTGateQOpNode argument!"); + assert(Level && "Invalid Fock level expression!"); + + switch (Level->GetASTType()) { + case ASTTypeInt: + case ASTTypeUInt: + return ProductionRule_3855(TK, GQN, + dynamic_cast(Level)); + case ASTTypeBinaryOp: + return ProductionRule_3855(TK, GQN, + dynamic_cast(Level)); + case ASTTypeUnaryOp: + return ProductionRule_3855(TK, GQN, + dynamic_cast(Level)); + case ASTTypeIdentifier: { + const ASTIdentifierNode *Id = Level->GetIdentifier(); + if (!Id) { + std::stringstream M; + M << "Invalid identifier Fock level expression."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(TK), M.str(), DiagLevel::ICE); + return ASTGateFockControlNode::ExpressionError(M.str()); + } + return ProductionRule_3855(TK, GQN, Id); + } + default: { + std::stringstream M; + M << "Unsupported Fock level expression type."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(TK), M.str(), DiagLevel::Error); + return ASTGateFockControlNode::ExpressionError(M.str()); + } + } +} + +ASTGateFockNegControlNode *ASTProductionFactory::ProductionRule_3856( + const ASTToken *TK, const ASTGateQOpNode *GQN, + const ASTExpressionNode *Level) const { + assert(TK && "Invalid ASTToken argument!"); + assert(GQN && "Invalid ASTGateQOpNode argument!"); + assert(Level && "Invalid Fock level expression!"); + + switch (Level->GetASTType()) { + case ASTTypeInt: + case ASTTypeUInt: + return ProductionRule_3856(TK, GQN, + dynamic_cast(Level)); + case ASTTypeBinaryOp: + return ProductionRule_3856(TK, GQN, + dynamic_cast(Level)); + case ASTTypeUnaryOp: + return ProductionRule_3856(TK, GQN, + dynamic_cast(Level)); + case ASTTypeIdentifier: { + const ASTIdentifierNode *Id = Level->GetIdentifier(); + if (!Id) { + std::stringstream M; + M << "Invalid identifier Fock level expression."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(TK), M.str(), DiagLevel::ICE); + return ASTGateFockNegControlNode::ExpressionError(M.str()); + } + return ProductionRule_3856(TK, GQN, Id); + } + default: { + std::stringstream M; + M << "Unsupported Fock level expression type."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(TK), M.str(), DiagLevel::Error); + return ASTGateFockNegControlNode::ExpressionError(M.str()); + } + } +} + } // namespace QASM diff --git a/lib/AST/ASTQubit.cpp b/lib/AST/ASTQubit.cpp index d25e6a2..a83c4a5 100644 --- a/lib/AST/ASTQubit.cpp +++ b/lib/AST/ASTQubit.cpp @@ -43,11 +43,24 @@ void ASTQubitNode::print() const { std::cout << "" << GetMangledName() << "" << std::endl; if (!GQN.empty()) - std::cout << "" << GQN << "" << std::endl; + std::cout << "" << GQN << "" + << std::endl; std::cout << "" << Index << "" << std::endl; std::cout << "" << std::endl; } +void ASTQumodeNode::print() const { + std::cout << "" << std::endl; + std::cout << "" << GetName() << "" << std::endl; + std::cout << "" << GetMangledName() << "" + << std::endl; + if (!GetGateOperandName().empty()) + std::cout << "" << GetGateOperandName() + << "" << std::endl; + std::cout << "" << GetIndex() << "" << std::endl; + std::cout << "" << std::endl; +} + static bool FillRangeQubitVector(const std::vector &IV, const std::vector &QV, std::vector &AV) { @@ -463,7 +476,7 @@ void ASTQubitContainerAliasNode::Mangle() { GetIdentifier()->SetMangledName(M.AsString()); } -void ASTGateQubitParamNode::Mangle() { +void ASTGateOperandParamNode::Mangle() { ASTMangler M; M.Start(); M.TypeIdentifier(GetASTType(), GetBits(), GetName()); diff --git a/lib/AST/ASTScopeController.cpp b/lib/AST/ASTScopeController.cpp index 2c0fc5c..129856c 100644 --- a/lib/AST/ASTScopeController.cpp +++ b/lib/AST/ASTScopeController.cpp @@ -804,18 +804,36 @@ void ASTScopeController::CheckDeclaration(const ASTIdentifierNode *Id) const { case ASTTypeLambdaAngle: case ASTTypePhiAngle: case ASTTypeThetaAngle: { - std::string BIS = - ASTStringUtils::Instance().GetIdentifierBase(Id->GetName()); - STE = ASTSymbolTable::Instance().FindAngle(BIS); + // Indexed angle-array elements are stored under the full name in + // ASTM (e.g. thetas[0]); the base may be an AngleArray, not Angle. + STE = ASTSymbolTable::Instance().FindAngle(Id); if (STE) { IId = STE->GetIdentifier(); ITy = IId->GetSymbolType(); } else { - STE = ASTSymbolTable::Instance().FindLocalSymbol( - BIS, ASTIntNode::IntBits, ASTTypeAngle); + std::string BIS = + ASTStringUtils::Instance().GetIdentifierBase(Id->GetName()); + STE = ASTSymbolTable::Instance().FindAngle(BIS); if (STE) { IId = STE->GetIdentifier(); ITy = IId->GetSymbolType(); + } else { + STE = ASTSymbolTable::Instance().FindLocalSymbol( + BIS, ASTIntNode::IntBits, ASTTypeAngle); + if (STE) { + IId = STE->GetIdentifier(); + ITy = IId->GetSymbolType(); + } else { + STE = ASTSymbolTable::Instance().FindLocalSymbol( + BIS, ASTTypeAngleArray); + if (!STE) + STE = ASTSymbolTable::Instance().FindGlobalSymbol( + BIS, ASTTypeAngleArray); + if (STE) { + IId = STE->GetIdentifier(); + ITy = IId->GetSymbolType(); + } + } } } } break; @@ -980,6 +998,20 @@ void ASTScopeController::CheckDeclaration(const ASTIdentifierNode *Id) const { const ASTSymbolTableEntry *STE = ASTSymbolTable::Instance().FindLocalSymbol(Id); + // Angle identifiers (including angle-array element refs like thetas[0]) + // are published into ASTM by Insert(), not LSTM. + if (!STE) { + switch (Id->GetSymbolType()) { + case ASTTypeAngle: + case ASTTypeLambdaAngle: + case ASTTypePhiAngle: + case ASTTypeThetaAngle: + STE = ASTSymbolTable::Instance().FindAngle(Id); + break; + default: + break; + } + } if (!STE) { std::stringstream M; M << "Unknown Identifier '" << Id->GetName() << "' at current scope."; @@ -998,6 +1030,21 @@ void ASTScopeController::CheckDeclaration(const ASTIdentifierNode *Id) const { STE->GetContext()->GetIndex() <= Id->GetDeclarationContext()->GetIndex()) return; + + // Angle refs may be rebound across gates under the same ASTM key; + // accept a live matching entry even when the Identifier pointer differs. + if (STE->GetValueType() == Id->GetSymbolType() && + (Id->GetSymbolType() == ASTTypeAngle || + Id->GetSymbolType() == ASTTypeLambdaAngle || + Id->GetSymbolType() == ASTTypePhiAngle || + Id->GetSymbolType() == ASTTypeThetaAngle) && + STE->GetIdentifier() && + STE->GetIdentifier()->GetName() == Id->GetName() && + STE->GetIdentifier()->GetBits() == Id->GetBits() && + Id->GetBits() > 0U && STE->GetContext() && + STE->GetContext()->IsAlive() && Id->GetDeclarationContext() && + Id->GetDeclarationContext()->IsAlive()) + return; } std::vector DV = diff --git a/lib/AST/ASTTypeDiscovery.cpp b/lib/AST/ASTTypeDiscovery.cpp index 55daf50..4e000b1 100644 --- a/lib/AST/ASTTypeDiscovery.cpp +++ b/lib/AST/ASTTypeDiscovery.cpp @@ -26,6 +26,8 @@ #include #include #include +#include +#include #include #include #include @@ -39,6 +41,7 @@ #include #include +#include #include namespace QASM { @@ -257,7 +260,7 @@ bool ASTTypeDiscovery::InReDeclarationContext( return SLB && DAE; } -bool ASTTypeDiscovery::IsGateQubitParam( +bool ASTTypeDiscovery::IsGateOperandParam( const ASTIdentifierNode *Id, ASTType CTy, ASTType PTy, const ASTDeclarationContext *DCX) const { assert(Id && "Invalid ASTIdentifierNode argument!"); @@ -267,6 +270,25 @@ bool ASTTypeDiscovery::IsGateQubitParam( !ASTGateContextBuilder::Instance().InOpenContext()) return false; + // Typed classical formals must not be reclassified as gate qubit params. + switch (Id->GetSymbolType()) { + case ASTTypeMPComplex: + case ASTTypeFloat: + case ASTTypeDouble: + case ASTTypeMPDecimal: + case ASTTypeInt: + case ASTTypeUInt: + case ASTTypeMPInteger: + case ASTTypeMPUInteger: + case ASTTypeBool: + case ASTTypeBitset: + case ASTTypeDuration: + case ASTTypeAngle: + return false; + default: + break; + } + if (ASTIdentifierTypeController::Instance().SeenLBrace() && IsCallable(Id)) return false; @@ -292,34 +314,35 @@ bool ASTTypeDiscovery::IsGateQubitParam( if (TKS[0] == u8',' || TKS[0] == u8'{') { ASTIdentifierTypeController::Instance().SetCurrentType( - ASTTypeGateQubitParam); + ASTTypeGateOperandParam); return true; } } if ((CTy == ASTTypeUndefined && PTy == ASTTypeGate && !ASTIdentifierTypeController::Instance().SeenLBrace()) && - (CTy == ASTTypeGateQubitParam && - (PTy == ASTTypeGateQubitParam || PTy == ASTTypeUndefined || + (CTy == ASTTypeGateOperandParam && + (PTy == ASTTypeGateOperandParam || PTy == ASTTypeUndefined || PTy == ASTTypeGate))) { ASTIdentifierTypeController::Instance().SetCurrentType( - ASTTypeGateQubitParam); + ASTTypeGateOperandParam); ASTIdentifierTypeController::Instance().SetPreviousType( - ASTTypeGateQubitParam); + ASTTypeGateOperandParam); return true; } else if (ASTIdentifierTypeController::Instance().SeenLBrace() && ((CTy == ASTTypeUndefined && PTy == ASTTypeGate) || - (CTy == ASTTypeGateQubitParam && PTy == ASTTypeGateQubitParam))) { + (CTy == ASTTypeGateOperandParam && + PTy == ASTTypeGateOperandParam))) { ASTIdentifierTypeController::Instance().SetCurrentType(ASTTypeUndefined); ASTIdentifierTypeController::Instance().SetPreviousType( - ASTTypeGateQubitParam); + ASTTypeGateOperandParam); return true; - } else if (CTy == ASTTypeGateQubitParam && PTy == ASTTypeUndefined && + } else if (CTy == ASTTypeGateOperandParam && PTy == ASTTypeUndefined && !ASTIdentifierTypeController::Instance().SeenLBrace()) { ASTIdentifierTypeController::Instance().SetCurrentType( - ASTTypeGateQubitParam); + ASTTypeGateOperandParam); ASTIdentifierTypeController::Instance().SetPreviousType( - ASTTypeGateQubitParam); + ASTTypeGateOperandParam); return true; } @@ -336,6 +359,24 @@ bool ASTTypeDiscovery::IsGateAngleParam( !ASTGateContextBuilder::Instance().InOpenContext()) return false; + // Already-typed classical formals must not be redeclared as angles. + switch (Id->GetSymbolType()) { + case ASTTypeMPComplex: + case ASTTypeFloat: + case ASTTypeDouble: + case ASTTypeMPDecimal: + case ASTTypeInt: + case ASTTypeUInt: + case ASTTypeMPInteger: + case ASTTypeMPUInteger: + case ASTTypeBool: + case ASTTypeBitset: + case ASTTypeDuration: + return false; + default: + break; + } + if (ASTTypeSystemBuilder::Instance().IsReservedAngle(Id->GetName())) return false; @@ -361,8 +402,8 @@ bool ASTTypeDiscovery::IsGateAngleParam( return true; } else if (ASTIdentifierTypeController::Instance().SeenLParen() && ASTIdentifierTypeController::Instance().SeenRParen() && - (CTy == ASTTypeGate || CTy == ASTTypeGateQubitParam || - PTy == ASTTypeGate || PTy == ASTTypeGateQubitParam)) { + (CTy == ASTTypeGate || CTy == ASTTypeGateOperandParam || + PTy == ASTTypeGate || PTy == ASTTypeGateOperandParam)) { uint32_t TIX = ASTTokenFactory::GetCurrentIndex() - 1; const ASTToken *ITK = ASTTokenFactory::GetToken(TIX); assert(ITK && "Could not obtain a valid ASTToken!"); @@ -436,7 +477,8 @@ ASTIdentifierNode *ASTTypeDiscovery::CreateLocalASTIdentifierNodeRedeclaration( W = true; break; case ASTTypeGate: - if (ASTGateBraceMatcher::Instance().IsZero() && Ty != ASTTypeGateQubitParam) + if (ASTGateBraceMatcher::Instance().IsZero() && + Ty != ASTTypeGateOperandParam) W = true; break; case ASTTypeDefcal: @@ -546,10 +588,21 @@ ASTTypeDiscovery::ResolveASTIdentifier(const ASTToken *TK, ASTIdentifierTypeController::Instance().InAngleList()) { Id = ASTBuilder::Instance().FindASTIdentifierNode( S, ASTAngleNode::AngleBits, ASTTypeAngle); + // Typed classical gate formals are not angles; still resolve them by name. + if (!Id && ASTGateContextBuilder::Instance().InOpenContext()) { + if (const ASTSymbolTableEntry *LSTE = + ASTSymbolTable::Instance().FindLocal(S)) + Id = const_cast(LSTE->GetIdentifier()); + } } else { Id = ASTBuilder::Instance().FindASTIdentifierNode(S); } + // Gate template params (`uint N`) may appear as array sizes; reuse the + // existing symbol instead of attempting a typed re-declaration. + if (Id && ASTGateTemplateParamBuilder::Instance().IsTemplateParam(S)) + return Id; + const ASTToken *LTK = ASTTokenFactory::GetLastToken(); const ASTToken *PTK = ASTTokenFactory::GetPreviousToken(); const ASTDeclarationContext *DCX = @@ -560,6 +613,26 @@ ASTTypeDiscovery::ResolveASTIdentifier(const ASTToken *TK, ASTDeclarationContextTracker::Instance().GetGlobalContext(); assert(GCX && "Could not obtain a valid Global ASTDeclarationContext!"); + // Inside `[…]`, CurrentType is often still the array/base type. Prefer an + // in-scope for-loop induction int named S over a typed re-declaration. + if (ASTIdentifierTypeController::Instance().SeenLBracket() && + DCX->GetContextType() == ASTTypeForStatement) { + if (Id && Id->IsInductionVariable()) + return Id; + if (const ASTSymbolTableEntry *LSTE = + ASTSymbolTable::Instance().FindLocal(S)) { + const ASTType LTy = LSTE->GetValueType(); + if (LTy == ASTTypeInt || LTy == ASTTypeUInt || LTy == ASTTypeMPInteger || + LTy == ASTTypeMPUInteger) { + Id = const_cast(LSTE->GetIdentifier()); + if (Id) { + Id->SetInductionVariable(true); + return Id; + } + } + } + } + if (Id) { ASTType CTy = ASTIdentifierTypeController::Instance().GetCurrentType(); ASTType PTy = ASTIdentifierTypeController::Instance().GetPreviousType(); @@ -628,12 +701,12 @@ ASTTypeDiscovery::ResolveASTIdentifier(const ASTToken *TK, ASTRedeclarationController::Instance().AllowRedeclarations(false); if (LTK && LTK->GetInt() == Parser::token::TOK_IN && - CTy == ASTTypeForStatement && PTy == ASTTypeForStatement) + CTy == ASTTypeForStatement) RId->SetInductionVariable(true); return RId; } - } else if (IsGateQubitParam(Id, CTy, PTy, DCX)) { - ASTType QTy = ASTTypeGateQubitParam; + } else if (IsGateOperandParam(Id, CTy, PTy, DCX)) { + ASTType QTy = ASTTypeGateOperandParam; ASTIdentifierNode *RId = CreateLocalASTIdentifierNodeRedeclaration( Id, ASTTypeSystemBuilder::Instance().GetTypeBits(QTy), QTy, DCX, TK); assert(RId && "Could not create a valid ASTIdentifierNode!"); @@ -760,7 +833,7 @@ ASTTypeDiscovery::ResolveASTIdentifier(const ASTToken *TK, Id->GetSymbolType()); return Id; break; - case ASTTypeGateQubitParam: + case ASTTypeGateOperandParam: assert(Id->GetSymbolTableEntry() && "Invalid SymbolTable Entry for Gate ASTIdentifierNode!"); ASTIdentifierTypeController::Instance().SetCurrentType( @@ -786,7 +859,7 @@ ASTTypeDiscovery::ResolveASTIdentifier(const ASTToken *TK, } } break; case ASTTypeAngle: - if (Id->GetSymbolType() == ASTTypeGateQubitParam) { + if (Id->GetSymbolType() == ASTTypeGateOperandParam) { assert(Id->GetSymbolTableEntry() && "Invalid SymbolTable Entry for Gate ASTIdentifierNode!"); ASTIdentifierTypeController::Instance().SetCurrentType( @@ -837,7 +910,7 @@ ASTTypeDiscovery::ResolveASTIdentifier(const ASTToken *TK, ASTFunctionContextBuilder::Instance().InOpenContext() || ASTKernelContextBuilder::Instance().InOpenContext()) { if (ASTIdentifierTypeController::Instance().InQubitList()) { - if (Id->GetSymbolType() == ASTTypeGateQubitParam) { + if (Id->GetSymbolType() == ASTTypeGateOperandParam) { if (!Id->GetSymbolTableEntry()) { ASTSymbolTableEntry *STE = new ASTSymbolTableEntry(Id, Id->GetSymbolType()); @@ -893,18 +966,33 @@ ASTTypeDiscovery::ResolveASTIdentifier(const ASTToken *TK, } } break; case ASTTypeForStatement: + // Only when both Current and Previous are For (induction binding window). + // After `in`, Current may be For again; do not mark every Id (e.g. d[i]). if (PTy == ASTTypeForStatement) Id->SetInductionVariable(true); break; default: { if (ASTGateContextBuilder::Instance().InOpenContext() && - (Id->GetSymbolType() == ASTTypeGateQubitParam || + (Id->GetSymbolType() == ASTTypeGateOperandParam || Id->GetSymbolType() == ASTTypeAngle || - Id->GetSymbolType() == ASTTypeGate)) { + Id->GetSymbolType() == ASTTypeGate || + Id->GetSymbolType() == ASTTypeMPComplex || + Id->GetSymbolType() == ASTTypeFloat || + Id->GetSymbolType() == ASTTypeDouble || + Id->GetSymbolType() == ASTTypeMPDecimal || + Id->GetSymbolType() == ASTTypeInt || + Id->GetSymbolType() == ASTTypeUInt || + Id->GetSymbolType() == ASTTypeMPInteger || + Id->GetSymbolType() == ASTTypeMPUInteger || + Id->GetSymbolType() == ASTTypeBool || + Id->GetSymbolType() == ASTTypeBitset || + Id->GetSymbolType() == ASTTypeDuration)) { return Id; } else if (ASTGateContextBuilder::Instance().InOpenContext() && (Id->GetSymbolType() == ASTTypeQubit || - Id->GetSymbolType() == ASTTypeQubitContainer)) { + Id->GetSymbolType() == ASTTypeQubitContainer || + Id->GetSymbolType() == ASTTypeQumode || + Id->GetSymbolType() == ASTTypeQumodeContainer)) { std::string YB = DIAGLineBuffer::Instance().GetBuffer(); if (ASTFunctionContextBuilder::Instance().InOpenContext() || @@ -932,7 +1020,7 @@ ASTTypeDiscovery::ResolveASTIdentifier(const ASTToken *TK, if (LP == std::string::npos && RP == std::string::npos) { ASTSymbolTable::Instance().EraseLocalSymbol(Id->GetName()); Id = ASTBuilder::Instance().CreateASTIdentifierNode( - Id->GetName(), 1U, ASTTypeGateQubitParam); + Id->GetName(), 1U, ASTTypeGateOperandParam); assert(Id && "Could not create a valid ASTIdentifierNode!"); Id->SetLocalScope(); @@ -940,7 +1028,7 @@ ASTTypeDiscovery::ResolveASTIdentifier(const ASTToken *TK, } else if (LP != std::string::npos && RP != std::string::npos) { ASTSymbolTable::Instance().EraseLocalSymbol(Id->GetName()); Id = ASTBuilder::Instance().CreateASTIdentifierNode( - Id->GetName(), 1U, ASTTypeGateQubitParam); + Id->GetName(), 1U, ASTTypeGateOperandParam); assert(Id && "Could not create a valid ASTIdentifierNode!"); Id->SetLocalScope(); @@ -1153,7 +1241,7 @@ ASTTypeDiscovery::ResolveASTIdentifier(const ASTToken *TK, const std::string &TKS = ITK->GetString(); if (TKS[0] == u8'{' || TKS[0] == u8',') { Id = ASTBuilder::Instance().CreateLocalScopeASTIdentifierNode( - S, 1U, ASTTypeGateQubitParam, DCX, TK); + S, 1U, ASTTypeGateOperandParam, DCX, TK); assert(Id && "Could not create a valid ASTIdentifierNode!"); Id->SetLocation(TK->GetLocation()); Id->SetDeclarationContext(DCX); @@ -1178,7 +1266,7 @@ ASTTypeDiscovery::ResolveASTIdentifier(const ASTToken *TK, const std::string &TKS = ITK->GetString(); if (TKS[0] == u8'{' || TKS[0] == u8',') { Id = ASTBuilder::Instance().CreateLocalScopeASTIdentifierNode( - S, 1U, ASTTypeGateQubitParam, DCX, TK); + S, 1U, ASTTypeGateOperandParam, DCX, TK); assert(Id && "Could not create a valid ASTIdentifierNode!"); Id->SetLocation(TK->GetLocation()); Id->SetDeclarationContext(DCX); @@ -1195,7 +1283,7 @@ ASTTypeDiscovery::ResolveASTIdentifier(const ASTToken *TK, (ASTIdentifierTypeController::Instance().IsGateType(PTy) || PTy == ASTTypeUndefined) && (ASTIdentifierTypeController::Instance().IsGateType(CTy) || - CTy == ASTTypeGateQubitParam) && + CTy == ASTTypeGateOperandParam) && !ASTTypeSystemBuilder::Instance().IsImplicitAngle(S) && !ASTTypeSystemBuilder::Instance().IsReservedAngle(S)) { uint32_t TIX = ASTTokenFactory::GetCurrentIndex() - 1; @@ -1205,7 +1293,7 @@ ASTTypeDiscovery::ResolveASTIdentifier(const ASTToken *TK, const std::string &TKS = ITK->GetString(); if (TKS[0] == u8'{' || TKS[0] == u8',') { Id = ASTBuilder::Instance().CreateLocalScopeASTIdentifierNode( - S, 1U, ASTTypeGateQubitParam, DCX, TK); + S, 1U, ASTTypeGateOperandParam, DCX, TK); assert(Id && "Could not create a valid ASTIdentifierNode!"); Id->SetLocation(TK->GetLocation()); Id->SetDeclarationContext(DCX); @@ -1222,7 +1310,7 @@ ASTTypeDiscovery::ResolveASTIdentifier(const ASTToken *TK, (ASTIdentifierTypeController::Instance().IsGateType(PTy) || PTy == ASTTypeUndefined) && (ASTIdentifierTypeController::Instance().IsGateType(CTy) || - CTy == ASTTypeGateQubitParam) && + CTy == ASTTypeGateOperandParam) && !ASTTypeSystemBuilder::Instance().IsImplicitAngle(S) && !ASTTypeSystemBuilder::Instance().IsReservedAngle(S)) { uint32_t TIX = ASTTokenFactory::GetCurrentIndex() - 1; @@ -1232,7 +1320,7 @@ ASTTypeDiscovery::ResolveASTIdentifier(const ASTToken *TK, const std::string &TKS = ITK->GetString(); if (TKS[0] == u8'{' || TKS[0] == u8',') { Id = ASTBuilder::Instance().CreateLocalScopeASTIdentifierNode( - S, 1U, ASTTypeGateQubitParam, DCX, TK); + S, 1U, ASTTypeGateOperandParam, DCX, TK); assert(Id && "Could not create a valid ASTIdentifierNode!"); Id->SetLocation(TK->GetLocation()); Id->SetDeclarationContext(DCX); @@ -1256,7 +1344,7 @@ ASTTypeDiscovery::ResolveASTIdentifier(const ASTToken *TK, const std::string &TKS = ITK->GetString(); if (TKS[0] == u8'{' || TKS[0] == u8',') { Id = ASTBuilder::Instance().CreateLocalScopeASTIdentifierNode( - S, 1U, ASTTypeGateQubitParam, DCX, TK); + S, 1U, ASTTypeGateOperandParam, DCX, TK); assert(Id && "Could not create a valid ASTIdentifierNode!"); Id->SetLocation(TK->GetLocation()); Id->SetDeclarationContext(DCX); @@ -1336,11 +1424,11 @@ ASTTypeDiscovery::ResolveASTIdentifier(const ASTToken *TK, ASTIdentifierTypeController::Instance().StopAngleList(); ASTIdentifierTypeController::Instance().SetCurrentType( - ASTTypeGateQubitParam); + ASTTypeGateOperandParam); } } else if (ASTIdentifierTypeController::Instance().InQubitList()) { Id = ASTBuilder::Instance().CreateLocalScopeASTIdentifierNode( - S, 1U, ASTTypeGateQubitParam, DCX, TK); + S, 1U, ASTTypeGateOperandParam, DCX, TK); assert(Id && "Could not create a valid ASTIdentifierNode!"); if (ASTIdentifierTypeController::Instance().SeenLBrace()) { uint32_t TIX = ASTTokenFactory::GetCurrentIndex() - 1; @@ -1352,9 +1440,9 @@ ASTTypeDiscovery::ResolveASTIdentifier(const ASTToken *TK, ASTIdentifierTypeController::Instance().StopQubitList(); ASTIdentifierTypeController::Instance().SetCurrentType( - ASTTypeGateQubitParam); + ASTTypeGateOperandParam); ASTIdentifierTypeController::Instance().SetPreviousType( - ASTTypeGateQubitParam); + ASTTypeGateOperandParam); } } else if (ASTGateContextBuilder::Instance().InOpenContext() && ASTIdentifierTypeController::Instance().IsGateType(CTy)) { @@ -1383,16 +1471,16 @@ ASTTypeDiscovery::ResolveASTIdentifier(const ASTToken *TK, } } else if (ASTIdentifierTypeController::Instance().InQubitList()) { switch (CTy) { - case ASTTypeGateQubitParam: + case ASTTypeGateOperandParam: Id = ASTBuilder::Instance().CreateLocalScopeASTIdentifierNode( - S, 1U, ASTTypeGateQubitParam, DCX, TK); + S, 1U, ASTTypeGateOperandParam, DCX, TK); assert(Id && "Could not create a valid ASTIdentifierNode!"); Id->SetLocation(TK->GetLocation()); ASTIdentifierTypeController::Instance().SetCurrentType( - ASTTypeGateQubitParam); + ASTTypeGateOperandParam); ASTIdentifierTypeController::Instance().SetPreviousType( - ASTTypeGateQubitParam); + ASTTypeGateOperandParam); if (ASTIdentifierTypeController::Instance().SeenLBrace()) { uint32_t TIX = ASTTokenFactory::GetCurrentIndex() - 1; @@ -1471,6 +1559,7 @@ ASTTypeDiscovery::ResolveASTIdentifier(const ASTToken *TK, case ASTTypeCCXGate: case ASTTypeCXGate: case ASTTypeHadamardGate: + case ASTTypeDispGate: case ASTTypeUGate: Id = ASTBuilder::Instance().CreateASTIdentifierNode( S, ASTGateNode::GateBits, ASTTypeGate); @@ -1586,6 +1675,10 @@ ASTTypeDiscovery::ResolveASTIdentifier(const ASTToken *TK, assert(Id && "Could not create a valid ASTIdentifierNode!"); Id->SetLocation(TK->GetLocation()); break; + case ASTTypeQumodeContainer: + Id = ASTBuilder::Instance().CreateASTIdentifierNode(S, 0, CTy); + assert(Id && "Could not create a valid ASTIdentifierNode!"); + break; case ASTTypeQubitContainer: Id = ASTBuilder::Instance().CreateASTIdentifierNode(S, 0, CTy); assert(Id && "Could not create a valid ASTIdentifierNode!"); @@ -1610,7 +1703,7 @@ ASTTypeDiscovery::ResolveASTIdentifier(const ASTToken *TK, assert(Id && "Could not create a valid ASTIdentifierNode!"); } else { Id = ASTBuilder::Instance().CreateASTIdentifierNode( - S, 1U, ASTTypeGateQubitParam); + S, 1U, ASTTypeGateOperandParam); } assert(Id && "Could not create a valid ASTIdentifierNode!"); @@ -1659,7 +1752,22 @@ ASTTypeDiscovery::ResolveASTIdentifier(const ASTToken *TK, STE = new ASTSymbolTableEntry(Id, Id->GetSymbolType()); assert(STE && "Could not create a valid SymbolTable Entry!"); } - } else if (PTy == ASTTypeArray) { + } else if (CTy == ASTTypeForStatement && + DCX->GetContextType() == ASTTypeForStatement) { + // Bind induction before the PTy==Array arm: a gate formal + // `array[...]` can leave PreviousType==Array and would otherwise + // swallow `for i` and type `i` as an array. + CTy = ASTTypeInt; + Id = ASTBuilder::Instance().CreateASTIdentifierNode( + S, ASTIntNode::IntBits, CTy); + assert(Id && "Could not create a valid ASTIdentifierNode!"); + + Id->SetLocation(TK->GetLocation()); + Id->SetInductionVariable(true); + ASTIdentifierTypeController::Instance().SetCurrentType(ASTTypeUndefined); + ASTIdentifierTypeController::Instance().SetPreviousType(CTy); + } else if (PTy == ASTTypeArray && CTy != ASTTypeForStatement && + CTy != ASTTypeWhileStatement) { ASTType NTy = ASTTypeUndefined; switch (CTy) { @@ -1863,17 +1971,6 @@ ASTTypeDiscovery::ResolveASTIdentifier(const ASTToken *TK, } CTy = NTy; - } else if (CTy == ASTTypeForStatement && PTy == ASTTypeForStatement && - DCX->GetContextType() == ASTTypeForStatement) { - CTy = ASTTypeInt; - Id = ASTBuilder::Instance().CreateASTIdentifierNode( - S, ASTIntNode::IntBits, CTy); - assert(Id && "Could not create a valid ASTIdentifierNode!"); - - Id->SetLocation(TK->GetLocation()); - Id->SetInductionVariable(true); - ASTIdentifierTypeController::Instance().SetCurrentType(ASTTypeUndefined); - ASTIdentifierTypeController::Instance().SetPreviousType(CTy); } else if (CTy == ASTTypeWhileStatement && PTy == ASTTypeWhileStatement && DCX->GetContextType() == ASTTypeWhileStatement) { ASTIdentifierTypeController::Instance().SetCurrentType(ASTTypeUndefined); @@ -1896,6 +1993,17 @@ ASTTypeDiscovery::ResolveASTIdentifier(const ASTToken *TK, assert(Id && "Could not create a valid ASTIdentifierNode!"); Id->SetLocation(TK->GetLocation()); break; + case ASTTypeQumodeContainer: + Id = ASTBuilder::Instance().CreateASTIdentifierNode(S, 0U, CTy); + assert(Id && "Could not create a valid ASTIdentifierNode!"); + Id->SetLocation(TK->GetLocation()); + break; + case ASTTypeQumode: + CTy = ASTTypeQumodeContainer; + Id = ASTBuilder::Instance().CreateASTIdentifierNode(S, 1U, CTy); + assert(Id && "Could not create a valid ASTIdentifierNode!"); + Id->SetLocation(TK->GetLocation()); + break; case ASTTypeQubitContainer: Id = ASTBuilder::Instance().CreateASTIdentifierNode(S, 0U, CTy); assert(Id && "Could not create a valid ASTIdentifierNode!"); @@ -2159,8 +2267,22 @@ ASTIdentifierRefNode *ResolveASTIdentifierRef( __AT *A = dynamic_cast<__AT *>(STE->GetValue()->GetValue()); assert(A && "Could not dynamic_cast to a valid array node!"); - A->ValidateIndex(IX, ASN->GetLocation()); - __ET *E = A->GetElement(IX); + __ET *E = nullptr; + if (ASN && ASN->IsInductionVariable()) { + // Index is a loop induction variable (runtime); do not validate the + // sentinel IX (~0). Use element 0 only as a type/size stand-in. + if (A->Size() == 0) { + std::stringstream M; + M << "Cannot index an empty array."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + ASN->GetLocation(), M.str(), DiagLevel::Error); + return ASTIdentifierRefNode::IdentifierError(M.str()); + } + E = A->GetElement(0); + } else { + A->ValidateIndex(IX, ASN->GetLocation()); + E = A->GetElement(IX); + } assert(E && "Could not obtain a valid array element!"); unsigned Bits = static_cast(~0x0); @@ -2199,29 +2321,47 @@ ASTIdentifierRefNode *ResolveASTIdentifierRef( assert(!ASTIdentifierNode::InvalidBits(Bits) && "Invalid number of bits for array element!"); + // IdentifierRef ctor takes a bit-width slot; induction leaves IX as ~0 + // (InvalidBits). Use element Bits as the ctor width; SetIndex(IS) still + // derives Index from the name (`thetas[i]` → leave Index as ~0). + const unsigned CtorBits = + (ASN && ASN->IsInductionVariable() && ASTIdentifierNode::InvalidBits(IX)) + ? Bits + : IX; + ASTSymbolTableEntry *XSTE = ASTSymbolTable::Instance().Lookup(S, Bits, A->GetElementType()); if (XSTE && XSTE->GetIdentifier()->IsReference()) { - if (ASN->IsInductionVariable()) { - ASTIdentifierRefNode *IdR = new ASTIdentifierRefNode( - US, S, A->GetElementType(), XSTE->GetIdentifier(), IX, true, XSTE, - ASN, ASL); - assert(IdR && "Could not create a valid ASTIdentifierRefNode!"); - IdR->SetSymbolTableEntry(XSTE); - IdR->SetPolymorphicName(S); - IdR->SetDeclarationContext(DCX); - IdR->SetMangledName(ASTMangler::MangleIdentifier(IdR)); - return IdR; - } + // Do not reuse element refs from a dead/prior gate or declaration + // context (ASTM keeps angle names across gates). + const ASTDeclarationContext *XCX = XSTE->GetContext(); + const bool Reusable = XCX && XCX->IsAlive() && DCX && + (XCX == DCX || XCX->GetIndex() == DCX->GetIndex()); + if (Reusable) { + if (ASN->IsInductionVariable()) { + ASTIdentifierRefNode *IdR = new ASTIdentifierRefNode( + US, S, A->GetElementType(), XSTE->GetIdentifier(), CtorBits, true, + XSTE, ASN, ASL); + assert(IdR && "Could not create a valid ASTIdentifierRefNode!"); + IdR->SetBits(Bits); + IdR->SetSymbolTableEntry(XSTE); + IdR->SetPolymorphicName(S); + IdR->SetDeclarationContext(DCX); + IdR->SetMangledName(ASTMangler::MangleIdentifier(IdR)); + return IdR; + } - return dynamic_cast(XSTE->GetIdentifier()); + return dynamic_cast(XSTE->GetIdentifier()); + } } - ASTIdentifierRefNode *IdR = new ASTIdentifierRefNode( - US, S, A->GetElementType(), A->GetIdentifier(), IX, true, STE, ASN, ASL); + ASTIdentifierRefNode *IdR = + new ASTIdentifierRefNode(US, S, A->GetElementType(), A->GetIdentifier(), + CtorBits, true, STE, ASN, ASL); assert(IdR && "Could not create a valid ASTIdentifierRefNode!"); + IdR->SetBits(Bits); IdR->SetPolymorphicName(S); IdR->SetDeclarationContext(DCX); IdR->SetMangledName(ASTMangler::MangleIdentifier(IdR)); @@ -2660,15 +2800,17 @@ ASTIdentifierRefNode *ASTTypeDiscovery::ResolveASTIdentifierRef( return IdR; } break; case ASTTypeQubitContainer: { - ASTSymbolTableEntry *STE = + ASTSymbolTableEntry *BaseSTE = ASTSymbolTable::Instance().Lookup(US, ASTTypeQubitContainer); + ASTSymbolTableEntry *STE = BaseSTE; if (!STE) { STE = ASTSymbolTable::Instance().Lookup(IS, 1U, ASTTypeQubitContainer); if (STE && STE->GetIdentifier()->IsReference()) { if (ASN->IsInductionVariable() || ASN->IsIndexIdentifier()) { + const unsigned RefBits = ASTIdentifierNode::InvalidBits(IX) ? 1U : IX; ASTIdentifierRefNode *IdR = new ASTIdentifierRefNode( - US, IS, ASTTypeQubitContainer, STE->GetIdentifier(), IX, true, - STE, ASN, ASL); + US, IS, ASTTypeQubitContainer, STE->GetIdentifier(), RefBits, + true, STE, ASN, ASL); assert(IdR && "Could not create a valid ASTIdentifierRefNode!"); IdR->SetSymbolTableEntry(STE); return IdR; @@ -2679,9 +2821,11 @@ ASTIdentifierRefNode *ASTTypeDiscovery::ResolveASTIdentifierRef( STE = ASTSymbolTable::Instance().Lookup(IS, 1U, ASTTypeQubit); if (STE && STE->GetIdentifier()->IsReference()) { if (ASN->IsInductionVariable() || ASN->IsIndexIdentifier()) { + const unsigned RefBits = + ASTIdentifierNode::InvalidBits(IX) ? 1U : IX; ASTIdentifierRefNode *IdR = new ASTIdentifierRefNode( - US, IS, ASTTypeQubitContainer, STE->GetIdentifier(), IX, true, - STE, ASN, ASL); + US, IS, ASTTypeQubitContainer, STE->GetIdentifier(), RefBits, + true, STE, ASN, ASL); assert(IdR && "Could not create a valid ASTIdentifierRefNode!"); IdR->SetSymbolTableEntry(STE); return IdR; @@ -2694,9 +2838,10 @@ ASTIdentifierRefNode *ASTTypeDiscovery::ResolveASTIdentifierRef( STE = ASTSymbolTable::Instance().Lookup(IS, 1U, ASTTypeQubitContainer); if (STE && STE->GetIdentifier()->IsReference()) { if (ASN->IsInductionVariable() || ASN->IsIndexIdentifier()) { + const unsigned RefBits = ASTIdentifierNode::InvalidBits(IX) ? 1U : IX; ASTIdentifierRefNode *IdR = new ASTIdentifierRefNode( - US, IS, ASTTypeQubitContainer, STE->GetIdentifier(), IX, true, - STE, ASN, ASL); + US, IS, ASTTypeQubitContainer, STE->GetIdentifier(), RefBits, + true, STE, ASN, ASL); assert(IdR && "Could not create a valid ASTIdentifierRefNode!"); IdR->SetSymbolTableEntry(STE); return IdR; @@ -2705,10 +2850,145 @@ ASTIdentifierRefNode *ASTTypeDiscovery::ResolveASTIdentifierRef( return dynamic_cast(STE->GetIdentifier()); } else { STE = ASTSymbolTable::Instance().Lookup(IS, 1U, ASTTypeQubit); + if (STE && STE->GetIdentifier()->IsReference()) { + if (ASN->IsInductionVariable() || ASN->IsIndexIdentifier()) { + const unsigned RefBits = + ASTIdentifierNode::InvalidBits(IX) ? 1U : IX; + ASTIdentifierRefNode *IdR = new ASTIdentifierRefNode( + US, IS, ASTTypeQubitContainer, STE->GetIdentifier(), RefBits, + true, STE, ASN, ASL); + assert(IdR && "Could not create a valid ASTIdentifierRefNode!"); + IdR->SetSymbolTableEntry(STE); + return IdR; + } + + return dynamic_cast(STE->GetIdentifier()); + } + } + } + + // Symbolic / induction index: do not CreateASTIdentifierNode(US, …) — + // US is already the container. Build a reference named `US[i]` with its + // own SymbolTable entry (do not reuse the container's STE). + if (BaseSTE && ASN && + (ASN->IsInductionVariable() || ASN->IsIndexIdentifier())) { + const unsigned RefBits = ASTIdentifierNode::InvalidBits(IX) ? 1U : IX; + ASTIdentifierRefNode *XIdR = new ASTIdentifierRefNode( + US, IS, ASTTypeQubitContainer, BaseSTE->GetIdentifier(), RefBits, + true, BaseSTE, ASN, ASL); + assert(XIdR && "Could not create a valid ASTIdentifierRefNode!"); + + ASTSymbolTableEntry *XSTE = new ASTSymbolTableEntry(XIdR, ASTTypeQubit); + assert(XSTE && "Could not create a valid ASTSymbolTableEntry!"); + XSTE->SetContext( + ASTDeclarationContextTracker::Instance().GetCurrentContext()); + XSTE->SetLocalScope(); + if (BaseSTE->HasValue()) { + if (ASTQubitContainerNode *QCN = + BaseSTE->GetValue()->GetValue()) { + if (QCN->Size() > 0) { + XSTE->SetValue(new ASTValue<>(QCN->GetQubit(0), ASTTypeQubit), + ASTTypeQubit, true); + } + } + } + XIdR->SetSymbolTableEntry(XSTE); + XIdR->SetMangledName(ASTMangler::MangleIdentifier(XIdR)); + if (!ASTSymbolTable::Instance().Insert(XIdR, XSTE)) { + std::stringstream M; + M << "Failure inserting identifier reference into the " + << "Local SymbolTable."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(BaseSTE->GetIdentifier()), + M.str(), DiagLevel::Error); + return ASTIdentifierRefNode::IdentifierError(M.str()); + } + return XIdR; + } + + // Induction / symbolic indices leave IX as ~0; Create rejects InvalidBits. + // Use a 1-bit stand-in for the synthetic element identifier only — the + // reference name stays `base[i]` via IS / ASN. + const unsigned CreateBits = + (ASN && (ASN->IsInductionVariable() || ASN->IsIndexIdentifier()) && + ASTIdentifierNode::InvalidBits(IX)) + ? 1U + : IX; + + Id = ASTBuilder::Instance().CreateASTIdentifierNode(US, CreateBits, + ASTTypeQubitContainer); + assert(Id && "Could not create a valid ASTIdentifierNode!"); + assert(Id->GetSymbolTableEntry() && + "ASTIdentifierNode without an ASTSymbolTableEntry!"); + + ASTIdentifierRefNode *XIdR = + new ASTIdentifierRefNode(US, IS, ASTTypeQubitContainer, Id, CreateBits, + true, Id->GetSymbolTableEntry(), ASN, ASL); + assert(XIdR && "Could not create a valid ASTIdentifierRefNode!"); + + XIdR->SetMangledName(ASTMangler::MangleIdentifier(XIdR)); + if (!ASTSymbolTable::Instance().Insert(Id, Id->GetSymbolTableEntry())) { + std::stringstream M; + M << "Failure inserting into the SymbolTable."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(Id), M.str(), + DiagLevel::Error); + return ASTIdentifierRefNode::IdentifierError(M.str()); + } + + return XIdR; + } break; + case ASTTypeQumode: + case ASTTypeQumodeContainer: { + ASTSymbolTableEntry *STE = + ASTSymbolTable::Instance().Lookup(US, ASTTypeQumodeContainer); + if (!STE) { + STE = ASTSymbolTable::Instance().Lookup(IS, 1U, ASTTypeQumodeContainer); + if (STE && STE->GetIdentifier()->IsReference()) { + if (ASN->IsInductionVariable() || ASN->IsIndexIdentifier()) { + ASTIdentifierRefNode *IdR = new ASTIdentifierRefNode( + US, IS, ASTTypeQumodeContainer, STE->GetIdentifier(), IX, true, + STE, ASN, ASL); + assert(IdR && "Could not create a valid ASTIdentifierRefNode!"); + IdR->SetSymbolTableEntry(STE); + return IdR; + } + + return dynamic_cast(STE->GetIdentifier()); + } else { + STE = ASTSymbolTable::Instance().Lookup(IS, 1U, ASTTypeQumode); + if (STE && STE->GetIdentifier()->IsReference()) { + if (ASN->IsInductionVariable() || ASN->IsIndexIdentifier()) { + ASTIdentifierRefNode *IdR = new ASTIdentifierRefNode( + US, IS, ASTTypeQumodeContainer, STE->GetIdentifier(), IX, true, + STE, ASN, ASL); + assert(IdR && "Could not create a valid ASTIdentifierRefNode!"); + IdR->SetSymbolTableEntry(STE); + return IdR; + } + + return dynamic_cast(STE->GetIdentifier()); + } + } + } else { + STE = ASTSymbolTable::Instance().Lookup(IS, 1U, ASTTypeQumodeContainer); + if (STE && STE->GetIdentifier()->IsReference()) { + if (ASN->IsInductionVariable() || ASN->IsIndexIdentifier()) { + ASTIdentifierRefNode *IdR = new ASTIdentifierRefNode( + US, IS, ASTTypeQumodeContainer, STE->GetIdentifier(), IX, true, + STE, ASN, ASL); + assert(IdR && "Could not create a valid ASTIdentifierRefNode!"); + IdR->SetSymbolTableEntry(STE); + return IdR; + } + + return dynamic_cast(STE->GetIdentifier()); + } else { + STE = ASTSymbolTable::Instance().Lookup(IS, 1U, ASTTypeQumode); if (STE && STE->GetIdentifier()->IsReference()) { if (ASN->IsInductionVariable() || ASN->IsIndexIdentifier()) { ASTIdentifierRefNode *IdR = new ASTIdentifierRefNode( - US, IS, ASTTypeQubitContainer, STE->GetIdentifier(), IX, true, + US, IS, ASTTypeQumodeContainer, STE->GetIdentifier(), IX, true, STE, ASN, ASL); assert(IdR && "Could not create a valid ASTIdentifierRefNode!"); IdR->SetSymbolTableEntry(STE); @@ -2720,14 +3000,56 @@ ASTIdentifierRefNode *ASTTypeDiscovery::ResolveASTIdentifierRef( } } + // Fall back: resolve via %name:index element created at declaration. + if (ASTSymbolTableEntry *CSTE = + ASTSymbolTable::Instance().Lookup(US, ASTTypeQumodeContainer)) { + ASTQumodeContainerNode *QCN = + CSTE->GetValue()->GetValue(); + assert(QCN && "Could not obtain a valid ASTQumodeContainerNode!"); + + std::string QIS = "%"; + QIS += ASTStringUtils::Instance().IndexedIdentifierToQCElement(IS); + ASTSymbolTableEntry *XSTE = + ASTSymbolTable::Instance().Lookup(QIS, 1U, ASTTypeQumode); + if (XSTE) { + if (XSTE->GetIdentifier()->IsReference()) + return dynamic_cast(XSTE->GetIdentifier()); + + if (ASTSymbolTableEntry *RSTE = + ASTSymbolTable::Instance().Lookup(IS, 1U, ASTTypeQumode)) { + return dynamic_cast(RSTE->GetIdentifier()); + } + + ASTIdentifierRefNode *IdR = + new ASTIdentifierRefNode(IS, XSTE->GetIdentifier(), 1U); + assert(IdR && "Could not create a valid ASTIdentifierRefNode!"); + + IdR->SetBits(1U); + IdR->SetMangledName(ASTMangler::MangleIdentifier(IdR)); + IdR->SetArraySubscriptList(ASL); + IdR->SetSymbolTableEntry(XSTE); + + if (!ASTSymbolTable::Instance().Insert(IdR, XSTE)) { + std::stringstream M; + M << "Failure inserting into the SymbolTable."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(XSTE->GetIdentifier()), + M.str(), DiagLevel::Error); + return ASTIdentifierRefNode::IdentifierError(M.str()); + } + + return IdR; + } + } + Id = ASTBuilder::Instance().CreateASTIdentifierNode(US, IX, - ASTTypeQubitContainer); + ASTTypeQumodeContainer); assert(Id && "Could not create a valid ASTIdentifierNode!"); assert(Id->GetSymbolTableEntry() && "ASTIdentifierNode without an ASTSymbolTableEntry!"); ASTIdentifierRefNode *XIdR = - new ASTIdentifierRefNode(US, IS, ASTTypeQubitContainer, Id, IX, true, + new ASTIdentifierRefNode(US, IS, ASTTypeQumodeContainer, Id, IX, true, Id->GetSymbolTableEntry(), ASN, ASL); assert(XIdR && "Could not create a valid ASTIdentifierRefNode!"); @@ -2791,6 +3113,17 @@ ASTIdentifierRefNode *ASTTypeDiscovery::ResolveASTIdentifierRef( M << "Unknown Identifier '" << US << "'."; QasmDiagnosticEmitter::Instance().EmitDiagnostic( DIAGLineCounter::Instance().GetLocation(), M.str(), DiagLevel::Error); + } else if (CTy == ASTTypeGate) { + // `gatecall[N](…)`: keep as an indexed ref; ProductionRule_3500 rewrites + // the subscript into template arguments. + ASTIdentifierRefNode *IdR = new ASTIdentifierRefNode( + US, IS, ASTTypeGate, Id, /*NumBits=*/0U, /*LV=*/true, + const_cast(Id->GetSymbolTableEntry()), ASN, + ASL); + assert(IdR && "Could not create a valid ASTIdentifierRefNode!"); + IdR->SetArraySubscriptNode(ASN); + IdR->SetArraySubscriptList(ASL); + return IdR; } else { M << "Type " << PrintTypeEnum(CTy) << " cannot be indexed " << "with C-style array index operator."; @@ -2815,12 +3148,13 @@ void ASTTypeDiscovery::ValidateGateQubitArgs(const ASTAnyTypeList *ATL, assert(ATL && "Invalid ASTAnyTypeList argument!"); assert(G && "Invalid ASTGateNode argument!"); - if ((G->GetNumQubits() == 0 || G->GetNumQCParams() == 0) || - (G->GetNumQubits() > ATL->Size() && G->GetNumQCParams() > ATL->Size())) { + if ((G->GetNumOperands() == 0 || G->GetNumOperandParams() == 0) || + (G->GetNumOperands() > ATL->Size() && + G->GetNumOperandParams() > ATL->Size())) { std::stringstream M; - M << "Number of Gate Qubit params (" << G->GetName() - << ") does not match the number of Qubit arguments provided (" - << G->GetNumQubits() << ")."; + M << "Number of gate operands (" << G->GetName() + << ") does not match the number of quantum arguments provided (" + << G->GetNumOperands() << ")."; QasmDiagnosticEmitter::Instance().EmitDiagnostic( DIAGLineCounter::Instance().GetLocation(G), M.str(), DiagLevel::Warning); @@ -2847,4 +3181,260 @@ void ASTTypeDiscovery::ValidateDefcalQubitArgs( } } +bool ASTTypeDiscovery::ValidateTypedGateCall( + const ASTToken *TK, const ASTGateNode *Decl, const ASTArgumentNodeList &ANL, + const ASTAnyTypeList &ATL, const ASTExpressionList *TemplateArgs, + std::vector> *OutBound) const { + assert(TK && "Invalid ASTToken argument!"); + assert(Decl && "Invalid ASTGateNode argument!"); + + if (!Decl->IsFullyTyped()) + return true; + + const std::vector &FPT = Decl->GetFormalParamTypes(); + const std::vector &FPSZ = Decl->GetFormalParamArraySizes(); + const std::vector &FPSTI = + Decl->GetFormalParamArraySizeTemplateIndices(); + const std::vector &TPs = Decl->GetTemplateParams(); + const std::vector &FQT = Decl->GetFormalQuantumTypes(); + + if (ANL.Size() != FPT.size()) { + std::stringstream M; + M << "Gate '" << Decl->GetName() << "' expects " << FPT.size() + << " classical parameter(s), but " << ANL.Size() << " were provided."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(TK), M.str(), DiagLevel::Error); + return false; + } + + if (ATL.Size() != FQT.size()) { + std::stringstream M; + M << "Gate '" << Decl->GetName() << "' expects " << FQT.size() + << " quantum operand(s), but " << ATL.Size() << " were provided."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(TK), M.str(), DiagLevel::Error); + return false; + } + + // Bind gate template parameters (explicit `[…]` or infer from array size). + std::vector> Bound(TPs.size()); + const bool HasExplicit = + TemplateArgs && !TemplateArgs->Empty() && !TPs.empty(); + if (HasExplicit) { + if (TemplateArgs->Size() != TPs.size()) { + std::stringstream M; + M << "Gate '" << Decl->GetName() << "' expects " << TPs.size() + << " template argument(s), but " << TemplateArgs->Size() + << " were provided."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(TK), M.str(), + DiagLevel::Error); + return false; + } + unsigned TI = 0; + for (ASTExpressionList::const_iterator EI = TemplateArgs->begin(); + EI != TemplateArgs->end(); ++EI, ++TI) { + const ASTExpressionNode *EN = + dynamic_cast(*EI); + unsigned V = 0U; + bool Ok = false; + if (const ASTIntNode *IN = dynamic_cast(EN)) { + V = IN->IsSigned() ? static_cast(IN->GetSignedValue()) + : IN->GetUnsignedValue(); + Ok = true; + } else if (EN) { + if (const ASTIdentifierNode *IId = EN->GetIdentifier()) { + unsigned UV = ASTUtils::Instance().GetUnsignedValue(IId); + if (!ASTIdentifierNode::InvalidBits(UV)) { + V = UV; + Ok = true; + } + } + } + if (!Ok) { + std::stringstream M; + M << "Gate template argument for '" << TPs[TI].Name + << "' must be a compile-time unsigned integer."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(TK), M.str(), + DiagLevel::Error); + return false; + } + Bound[TI] = V; + } + } else if (!TPs.empty()) { + for (unsigned I = 0; I < FPT.size(); ++I) { + if (I >= FPSTI.size() || FPSTI[I] == static_cast(~0U)) + continue; + unsigned TI = FPSTI[I]; + if (TI >= Bound.size()) + continue; + if (ASTGateType::ArgIsUninitializedArray(ANL[I])) { + const ASTIdentifierNode *AId = ASTGateType::ArgIdentifier(ANL[I]); + std::stringstream M; + M << "Variable '" << (AId ? AId->GetName() : "") + << "' used before assigned."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(TK), M.str(), + DiagLevel::Error); + return false; + } + ASTGateType A = ASTGateType::ClassifyArg(ANL[I]); + if (!A.HasArraySize()) { + std::stringstream M; + M << "Cannot infer template parameter '" << TPs[TI].Name + << "' for gate '" << Decl->GetName() + << "'; pass an array literal, a sized array variable, or an " + "explicit template argument."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(TK), M.str(), + DiagLevel::Error); + return false; + } + unsigned SZ = A.GetArraySize(); + if (Bound[TI] && *Bound[TI] != SZ) { + std::stringstream M; + M << "Conflicting inferred values for template parameter '" + << TPs[TI].Name << "' on gate '" << Decl->GetName() << "' (" + << *Bound[TI] << " vs " << SZ << ")."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(TK), M.str(), + DiagLevel::Error); + return false; + } + Bound[TI] = SZ; + } + for (std::size_t TI = 0; TI < TPs.size(); ++TI) { + if (!Bound[TI]) { + std::stringstream M; + M << "Cannot infer template parameter '" << TPs[TI].Name + << "' for gate '" << Decl->GetName() + << "'; provide an explicit template argument."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(TK), M.str(), + DiagLevel::Error); + return false; + } + } + } else if (TemplateArgs && !TemplateArgs->Empty()) { + std::stringstream M; + M << "Gate '" << Decl->GetName() << "' does not take template arguments."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(TK), M.str(), DiagLevel::Error); + return false; + } + + for (unsigned I = 0; I < FPT.size(); ++I) { + const ASTArgumentNode *Arg = ANL[I]; + assert(Arg && "Invalid classical gate call argument!"); + + if (ASTGateType::ArgIsUninitializedArray(Arg)) { + const ASTIdentifierNode *AId = ASTGateType::ArgIdentifier(Arg); + std::stringstream M; + M << "Variable '" << (AId ? AId->GetName() : "") + << "' used before assigned."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(TK), M.str(), + DiagLevel::Error); + return false; + } + + std::optional FormalSZ; + if (I < FPSZ.size() && FPSZ[I] > 0U) + FormalSZ = FPSZ[I]; + else if (I < FPSTI.size() && FPSTI[I] != static_cast(~0U) && + FPSTI[I] < Bound.size() && Bound[FPSTI[I]]) + FormalSZ = *Bound[FPSTI[I]]; + + ASTGateType F = ASTGateType::ClassifyFormal(FPT[I], FormalSZ); + ASTGateType A = ASTGateType::ClassifyArg(Arg); + ASTType ArgTy = A.GetType(); + ASTType ExpTy = F.GetType(); + + if (!ASTGateType::Compatible(F, A)) { + std::stringstream M; + if (F.HasArraySize() && A.HasArraySize() && + F.GetArraySize() != A.GetArraySize()) { + M << "Gate '" << Decl->GetName() << "' parameter " << I + << " expects an array of size " << F.GetArraySize() + << ", but got size " << A.GetArraySize() << "."; + } else if (F.IsComplexScalar()) { + M << "Gate '" << Decl->GetName() << "' parameter " << I + << " expects a complex value, but got " << PrintTypeEnum(ArgTy) + << "."; + } else if (F.IsRealArrayFamily()) { + M << "Gate '" << Decl->GetName() << "' parameter " << I + << " expects a real array, but got " << PrintTypeEnum(ArgTy) << "."; + } else if (F.IsComplexArray()) { + M << "Gate '" << Decl->GetName() << "' parameter " << I + << " expects a complex array, but got " << PrintTypeEnum(ArgTy) + << "."; + } else if (F.IsRealScalarFamily()) { + M << "Gate '" << Decl->GetName() << "' parameter " << I << " expects " + << PrintTypeEnum(ExpTy) << ", but got " << PrintTypeEnum(ArgTy) + << "."; + } else { + M << "Unsupported fully-typed classical formal type " + << PrintTypeEnum(ExpTy) << " on gate '" << Decl->GetName() << "'."; + } + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(TK), M.str(), + DiagLevel::Error); + return false; + } + + if (F.IsRealArrayFamily() && ASTGateType::ArgHasComplexElements(Arg)) { + std::stringstream M; + M << "Gate '" << Decl->GetName() << "' parameter " << I + << " expects a real array, but an element is a complex expression."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(TK), M.str(), + DiagLevel::Error); + return false; + } + } + + for (unsigned I = 0; I < FQT.size(); ++I) { + const ASTIdentifierNode *QId = nullptr; + if (ATL.IsIdentifier(I)) + QId = ATL.GetIdentifier(I); + else if (ATL.IsIdentifierRef(I)) + QId = ATL.GetIdentifierRef(I); + + if (!QId) { + std::stringstream M; + M << "Gate '" << Decl->GetName() << "' operand " << I + << " must be a quantum identifier."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(TK), M.str(), + DiagLevel::Error); + return false; + } + + const ASTSymbolTableEntry *QSTE = ASTSymbolTable::Instance().FindQubit(QId); + if (!QSTE) + QSTE = QId->GetSymbolTableEntry(); + ASTType ArgTy = QSTE ? QSTE->GetValueType() : QId->GetSymbolType(); + ASTType ExpTy = FQT[I]; + + const bool Ok = + (ExpTy == ASTTypeQubit && ASTUtils::Instance().IsQubitType(ArgTy)) || + (ExpTy == ASTTypeQumode && ASTUtils::Instance().IsQumodeType(ArgTy)); + if (!Ok) { + std::stringstream M; + M << "Gate '" << Decl->GetName() << "' operand " << I << " expects " + << PrintTypeEnum(ExpTy) << ", but '" << QId->GetName() << "' has type " + << PrintTypeEnum(ArgTy) << "."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation(QId), M.str(), + DiagLevel::Error); + return false; + } + } + + if (OutBound) + *OutBound = std::move(Bound); + return true; +} + } // namespace QASM diff --git a/lib/AST/ASTTypeEnums.cpp b/lib/AST/ASTTypeEnums.cpp index 06fd07a..fe7dcc5 100644 --- a/lib/AST/ASTTypeEnums.cpp +++ b/lib/AST/ASTTypeEnums.cpp @@ -411,6 +411,15 @@ const char *PrintTypeEnum(ASTType Type) { case ASTTypeGateControlStatement: return "ASTTypeGateControlStatement"; break; + case ASTTypeGateFockControl: + return "ASTTypeGateFockControl"; + break; + case ASTTypeGateFockNegControl: + return "ASTTypeGateFockNegControl"; + break; + case ASTTypeGateFor: + return "ASTTypeGateFor"; + break; case ASTTypeGateNegControl: return "ASTTypeGateNegControl"; break; @@ -441,8 +450,8 @@ const char *PrintTypeEnum(ASTType Type) { case ASTTypeGatePowerStatement: return "ASTTypeGatePowerStatement"; break; - case ASTTypeGateQubitParam: - return "ASTTypeGateQubitParam"; + case ASTTypeGateOperandParam: + return "ASTTypeGateOperandParam"; break; case ASTTypeGateQualifier: return "ASTTypeGateQualifier"; @@ -492,6 +501,8 @@ const char *PrintTypeEnum(ASTType Type) { case ASTTypeGPhaseStatement: return "ASTTypeGPhaseStatement"; break; + case ASTTypeDispGate: + return "ASTTypeDispGate"; case ASTTypeHadamardGate: return "ASTTypeHadamardGate"; break; @@ -813,6 +824,12 @@ const char *PrintTypeEnum(ASTType Type) { case ASTTypeQubits: return "ASTTypeQubits"; break; + case ASTTypeQumode: + return "ASTTypeQumode"; + break; + case ASTTypeQumodeContainer: + return "ASTTypeQumodeContainer"; + break; case ASTTypeRegister: return "ASTTypeRegister"; break; @@ -951,6 +968,10 @@ const char *PrintTypeEnum(ASTType Type) { case ASTTypeUGate: return "ASTTypeUGate"; break; + case ASTTypeUnitary: // adding a data type Unitary KH + return "ASTTypeUnitary"; + break; + case ASTTypeUnaryOp: return "ASTTypeUnaryOp"; break; @@ -984,6 +1005,9 @@ const char *PrintTypeEnum(ASTType Type) { case ASTTypeULong: return "ASTTypeULong"; break; + case ASTTypeUnitaryAttribute: + return "ASTTypeUnitaryAttribute"; + break; case ASTTypeUTF8: return "ASTTypeUTF8"; break; @@ -1788,9 +1812,24 @@ const char *PrintParserToken(unsigned Token) { case token::TOK_QUBITS: return "TOK_QUBITS"; break; + case token::TOK_QUMODE: + return "TOK_QUMODE"; + break; case token::TOK_U: return "TOK_U"; break; + case token::TOK_DISP: + return "TOK_DISP"; + break; + case token::TOK_BUMPER: + return "TOK_BUMPER"; + + case token::TOK_BUMPER_MAX: + return "TOK_BUMPER_MAX"; + + case token::TOK_UNITARY: //adding a data type Unitary KH + return "TOK_UNITARY"; + break; case token::TOK_ANGLE: return "TOK_ANGLE"; break; @@ -2208,6 +2247,9 @@ const char *PrintGateKind(GateKind GK) { case ASTGateKindU: return "U"; break; + case ASTGateKindDisp: + return "Disp"; + break; case ASTGateKindLambda: return "Lambda"; break; diff --git a/lib/AST/ASTTypeSpecifier.cpp b/lib/AST/ASTTypeSpecifier.cpp index 0db9cba..4748824 100644 --- a/lib/AST/ASTTypeSpecifier.cpp +++ b/lib/AST/ASTTypeSpecifier.cpp @@ -89,11 +89,16 @@ ASTType ASTTypeSpecifierNode::ResolveASTType(int Token) const { case token::TOK_QUBIT: return ASTTypeQubit; break; + case token::TOK_QUMODE: + return ASTTypeQumode; + break; case token::TOK_QUBITS: return ASTTypeQubits; break; case token::TOK_U: return ASTTypeUGate; + case token::TOK_DISP: + return ASTTypeDispGate; break; case token::TOK_GATE: return ASTTypeGate; @@ -213,6 +218,9 @@ const char *ASTTypeSpecifierNode::ResolveASTTypeName() const { case ASTTypeQubits: return "qubits"; break; + case ASTTypeDispGate: + return "disp"; + break; case ASTTypeUGate: return "U"; break; diff --git a/lib/AST/ASTTypeSystemBuilder.cpp b/lib/AST/ASTTypeSystemBuilder.cpp index f0e0416..8cf2f88 100644 --- a/lib/AST/ASTTypeSystemBuilder.cpp +++ b/lib/AST/ASTTypeSystemBuilder.cpp @@ -54,7 +54,7 @@ #include #include #include -#include +#include #include #include #include @@ -107,7 +107,7 @@ void ASTTypeSystemBuilder::Init() { ASTSwitchUnscopedStatementBuilder::Instance().Init(); ASTDoWhileStatementBuilder::Instance().Init(); ASTWhileStatementBuilder::Instance().Init(); - ASTGateQubitParamBuilder::Instance().Init(); + ASTGateOperandParamBuilder::Instance().Init(); ASTParameterBuilder::Instance().Init(); ASTGateOpBuilder::Instance().Init(); ASTQubitConcatListBuilder::Instance().Init(); @@ -268,7 +268,7 @@ void ASTTypeSystemBuilder::Init() { ASTTypeGPhaseStatement, ASTGPhaseStatementNode::GPhaseStmtBits, }, - {ASTTypeGateQubitParam, 1U}, + {ASTTypeGateOperandParam, 1U}, { ASTTypeIdentifier, ASTIdentifierNode::IdentifierBits, @@ -335,6 +335,14 @@ void ASTTypeSystemBuilder::Init() { ASTTypeQubitContainerAlias, ASTQubitContainerAliasNode::QubitContainerAliasBits, }, + { + ASTTypeQumode, + ASTQubitNode::QubitBits, + }, + { + ASTTypeQumodeContainer, + ASTQubitContainerNode::QubitContainerBits, + }, { ASTTypeResult, ASTResultNode::ResultBits, @@ -472,6 +480,7 @@ void ASTTypeSystemBuilder::Init() { if (BGM.empty()) { BGM = { "U", + "disp", }; } @@ -563,6 +572,7 @@ void ASTTypeSystemBuilder::Init() { ASTTypeSystemBuilder::Instance().CreateASTReservedAngles(); ASTTypeSystemBuilder::Instance().CreateASTReservedMPDecimalValues(); ASTTypeSystemBuilder::Instance().CreateASTBuiltinUGate(); + ASTTypeSystemBuilder::Instance().CreateASTBuiltinDispGate(); ASTTypeSystemBuilder::Instance().CreateASTBuiltinCXGate(); ASTDefcalGrammarBuilder::Instance().SetCurrent("openpulse"); @@ -620,10 +630,10 @@ void ASTTypeSystemBuilder::CreateASTBuiltinUGate() const { GPL.Append(Phi); ASTIdentifierNode *QId = ASTBuilder::Instance().CreateASTIdentifierNode( - "q", 1U, ASTTypeGateQubitParam); + "q", 1U, ASTTypeGateOperandParam); assert(QId && "Could not create a valid Qubit ASTIdentifierNode!"); - ASTIdentifierTypeController::Instance().CheckGateQubitParamType(QId); + ASTIdentifierTypeController::Instance().CheckGateOperandParamType(QId); QId->SetGateLocal(true); QId->SetLocalScope(); QIL.Append(QId); @@ -644,7 +654,57 @@ void ASTTypeSystemBuilder::CreateASTBuiltinUGate() const { ASTSymbolTable::Instance().EraseLocalAngle(LambdaId); ASTSymbolTable::Instance().EraseLocalAngle(ThetaId); ASTSymbolTable::Instance().EraseLocalAngle(PhiId); - ASTGateQubitParamBuilder::Instance().ReleaseQubits(); + ASTGateOperandParamBuilder::Instance().ReleaseQubits(); + ASTGateContextBuilder::Instance().CloseContext(); + ASTDeclarationContextTracker::Instance().PopCurrentContext(); +} + +void ASTTypeSystemBuilder::CreateASTBuiltinDispGate() const { + ASTParameterList GPL; + ASTIdentifierList QIL; + + ASTDeclarationContextTracker::Instance().CreateContext(ASTTypeGate); + + // Formal classical parameter name for documentation/mangling of the + // definition; call sites always materialize a complex ComplexParam. + ASTIdentifierNode *AlphaId = ASTBuilder::Instance().CreateASTIdentifierNode( + u8"alpha", ASTAngleNode::AngleBits, ASTTypeAngle); + assert(AlphaId && "Could not create a valid alpha ASTIdentifierNode!"); + + AlphaId->SetPolymorphicName(u8"alpha"); + AlphaId->SetGateLocal(true); + AlphaId->SetLocalScope(); + + ASTAngleNode *Alpha = ASTBuilder::Instance().CreateASTAngleNode( + AlphaId, ASTAngleNode::DetermineAngleType(u8"alpha"), + ASTAngleNode::AngleBits); + assert(Alpha && "Could not create a valid alpha ASTAngleNode!"); + GPL.Append(Alpha); + + ASTIdentifierNode *QId = ASTBuilder::Instance().CreateASTIdentifierNode( + "qm", 1U, ASTTypeGateOperandParam); + assert(QId && "Could not create a valid Qumode ASTIdentifierNode!"); + + ASTIdentifierTypeController::Instance().CheckGateOperandParamType(QId); + QId->SetGateLocal(true); + QId->SetLocalScope(); + QIL.Append(QId); + + ASTIdentifierNode *DId = ASTBuilder::Instance().CreateASTIdentifierNode( + u8"disp", ASTGateNode::GateBits, ASTTypeDispGate); + assert(DId && "Could not create a valid DispGate ASTIdentifierNode!"); + + DId->SetPolymorphicName("disp"); + ASTGateNode *DGN = + ASTBuilder::Instance().CreateASTGateNode(DId, ASTGateKindDisp, GPL, QIL); + assert(DGN && "Could not create a valid DispGate ASTGateNode!"); + + DGN->Mangle(); + ASTGateQubitTracker::Instance().Erase(); + QIL.DeleteSymbols(); + GPL.DeleteSymbols(); + ASTSymbolTable::Instance().EraseLocalAngle(AlphaId); + ASTGateOperandParamBuilder::Instance().ReleaseQubits(); ASTGateContextBuilder::Instance().CloseContext(); ASTDeclarationContextTracker::Instance().PopCurrentContext(); } @@ -659,19 +719,19 @@ void ASTTypeSystemBuilder::CreateASTBuiltinCXGate() const { ASTDeclarationContextTracker::Instance().CreateContext(ASTTypeGate); ASTIdentifierNode *CId = ASTBuilder::Instance().CreateASTIdentifierNode( - "c", 1U, ASTTypeGateQubitParam); + "c", 1U, ASTTypeGateOperandParam); assert(CId && "Could not create a valid Qubit ASTIdentifierNode!"); - ASTIdentifierTypeController::Instance().CheckGateQubitParamType(CId); + ASTIdentifierTypeController::Instance().CheckGateOperandParamType(CId); CId->SetGateLocal(true); CId->SetLocalScope(); QIL.Append(CId); ASTIdentifierNode *TId = ASTBuilder::Instance().CreateASTIdentifierNode( - "t", 1U, ASTTypeGateQubitParam); + "t", 1U, ASTTypeGateOperandParam); assert(TId && "Could not create a valid Qubit ASTIdentifierNode!"); - ASTIdentifierTypeController::Instance().CheckGateQubitParamType(TId); + ASTIdentifierTypeController::Instance().CheckGateOperandParamType(TId); TId->SetGateLocal(true); TId->SetLocalScope(); QIL.Append(TId); @@ -689,7 +749,7 @@ void ASTTypeSystemBuilder::CreateASTBuiltinCXGate() const { ASTGateQubitTracker::Instance().Erase(); QIL.DeleteSymbols(); GPL.DeleteSymbols(); - ASTGateQubitParamBuilder::Instance().ReleaseQubits(); + ASTGateOperandParamBuilder::Instance().ReleaseQubits(); ASTGateContextBuilder::Instance().CloseContext(); ASTDeclarationContextTracker::Instance().PopCurrentContext(); } diff --git a/lib/AST/ASTUnitary.cpp b/lib/AST/ASTUnitary.cpp new file mode 100644 index 0000000..35ce461 --- /dev/null +++ b/lib/AST/ASTUnitary.cpp @@ -0,0 +1,74 @@ +/* -*- coding: utf-8 -*- + * + * Copyright 2022 IBM RESEARCH. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + */ + +#include +#include +#include +#include +#include + +namespace QASM { + +void ASTUnitaryNode::Mangle() { + ASTMangler M; + M.Start(); + M.TypeIdentifier(GetASTType(), GetName()); + M.EndExpression(); + M.End(); + + const_cast(GetIdentifier()) + ->SetMangledName(M.AsString()); +} + + +ASTUnitaryNode * +ASTUnitaryNode::CloneCall(const ASTIdentifierNode *Id, + const ASTArgumentNodeList &AL, + const ASTAnyTypeList &QL) { + assert(Id && "Invalid ASTIdentifierNode argument!"); + + ASTIdentifierNode *UId = + GateCallIdentifier(Id->GetName(), + Id->GetSymbolType(), + Id->GetBits()); + + assert(UId && + "Could not create a valid Unitary Call ASTIdentifierNode!"); + + UId->SetSymbolTableEntry( + const_cast(Id->GetSymbolTableEntry())); + + ASTUnitaryNode *RU = new ASTUnitaryNode(UId, AL, QL, true); + + assert(RU && "Could not create a valid ASTUnitaryNode call!"); + + RU->OpList = OpList; + RU->GDId = Id; + RU->Void = Void; + RU->ControlType = ControlType; + RU->Opaque = Opaque; + RU->GateCall = true; + + RU->Mangle(); + return RU; +} + +void ASTUnitaryNode::print() const { + std::cout << "" << std::endl; + std::cout << "" << GetName() << "" << std::endl; + std::cout << "" << GetMangledName() << "" + << std::endl; + + if (INL) + INL->print(); + + std::cout << "" << std::endl; +} + + +} // namespace QASM \ No newline at end of file diff --git a/lib/AST/ASTUnitaryAttribute.cpp b/lib/AST/ASTUnitaryAttribute.cpp new file mode 100644 index 0000000..06c5aab --- /dev/null +++ b/lib/AST/ASTUnitaryAttribute.cpp @@ -0,0 +1,73 @@ +/* -*- coding: utf-8 -*- + * + * Licensed under the Apache License, Version 2.0. + */ + +#include + +#include +#include + +namespace QASM { + +ASTUnitaryAttributeNode::ASTUnitaryAttributeNode( + const ASTIdentifierNode *Target, + ASTUnitaryAttributeKind AttrKind, + const ASTExpressionNode *Value, + ASTOpType Op) + : ASTStatementNode(Target, Value), + AttributeKind(AttrKind), + OpType(Op) { + + assert(Target && "Invalid unitary attribute target!"); + assert(Value && "Invalid unitary attribute value!"); + + assert((Op == ASTOpTypeAssign || + Op == ASTOpTypeAddAssign) && + "Invalid unitary attribute assignment operator!"); +} +void ASTUnitaryAttributeNode::print() const { + std::cout << "" << std::endl; + + std::cout << ""; + if (GetTarget()) + std::cout << GetTarget()->GetName(); + std::cout << "" << std::endl; + + std::cout << ""; + + switch (AttributeKind) { + case ASTUnitaryAttributeBumper: + std::cout << "bumper"; + break; + case ASTUnitaryAttributeBumperMax: + std::cout << "bumper_max"; + break; + } + + std::cout << "" << std::endl; + + std::cout << ""; + + switch (OpType) { + case ASTOpTypeAssign: + std::cout << "="; + break; + case ASTOpTypeAddAssign: + std::cout << "+="; + break; + default: + std::cout << "unknown"; + break; + } + + std::cout << "" << std::endl; + + std::cout << "" << std::endl; + if (GetValue()) + GetValue()->print(); + std::cout << "" << std::endl; + + std::cout << "" << std::endl; +} +} // namespace QASM \ No newline at end of file diff --git a/lib/AST/CMakeLists.txt b/lib/AST/CMakeLists.txt index 870186a..84cdbd4 100644 --- a/lib/AST/CMakeLists.txt +++ b/lib/AST/CMakeLists.txt @@ -38,7 +38,8 @@ set(OPENQASM_AST_SOURCES ASTGateOpBuilder.cpp ASTGateOps.cpp ASTGates.cpp - ASTGateQubitParamBuilder.cpp + ASTGateType.cpp + ASTGateOperandParamBuilder.cpp ASTGateQubitTracker.cpp ASTHeapSizeController.cpp ASTIdentifierBuilder.cpp @@ -95,6 +96,8 @@ set(OPENQASM_AST_SOURCES ASTTypeEnums.cpp ASTTypeSpecifier.cpp ASTTypeSystemBuilder.cpp + ASTUnitaryAttribute.cpp + ASTUnitary.cpp ASTUtils.cpp ASTExpressionEvaluator.cpp ASTExpressionValidator.cpp) diff --git a/lib/Frontend/QasmDiagnosticEmitter.cpp b/lib/Frontend/QasmDiagnosticEmitter.cpp index 219a36f..ebe1bbb 100644 --- a/lib/Frontend/QasmDiagnosticEmitter.cpp +++ b/lib/Frontend/QasmDiagnosticEmitter.cpp @@ -83,3 +83,10 @@ void QasmDiagnosticEmitter::EmitDiagnostic(ASTLocation Loc, } } // namespace QASM + + +// output example +// QasmDiagnosticEmitter::EmitDiagnostic( +// location, +// "Expected ';' after declaration.", (prints error message) +// DiagLevel::Error); (notes level of serverity) \ No newline at end of file diff --git a/lib/Frontend/QasmDriver.cpp b/lib/Frontend/QasmDriver.cpp index 70a9d63..00ba3f1 100644 --- a/lib/Frontend/QasmDriver.cpp +++ b/lib/Frontend/QasmDriver.cpp @@ -28,7 +28,7 @@ namespace QASM { int ASTDriver::ExecParse(std::istream &In) { - if (!In.good()) { + if (!In.good()) { //this is just checking that the input stream is readable std::cerr << "Error: Bad Translation Unit!" << std::endl; return 1; } @@ -41,14 +41,14 @@ int ASTDriver::ExecParse(std::istream &In) { In.rdbuf()->pubseekpos(0, In.in); S.reset(); - S = std::make_unique(&In); + S = std::make_unique(&In); //make the lexer scanner P.reset(); - P = std::make_unique(*S, *this); + P = std::make_unique(*S, *this); //make the parser - int R = P->parse(); + int R = P->parse(); //run parser - if (R != 0 || QasmDiagnosticEmitter::Instance().HasErrors()) { + if (R != 0 || QasmDiagnosticEmitter::Instance().HasErrors()) { //check parser for errors std::stringstream M; M << "Compilation terminated with " << QasmDiagnosticEmitter::Instance().GetNumErrors() << " errors."; @@ -67,7 +67,7 @@ int ASTDriver::Parse(std::istream &In) { } if (In.eof()) { - std::cerr << "Error: Already at EOF?" << std::endl; + std::cerr << "Error: Already at EOF?" << std::endl; //EOF means end of file, ie we've already read the stream return 1; } @@ -85,7 +85,7 @@ int ASTDriver::Parse(const char *InFile) { return Parse(In); } -void ASTDriver::IncrementWords(const std::string &Word) { +void ASTDriver::IncrementWords(const std::string &Word) { //this just collects stats on the scanner Chars += Word.size(); IncrementWords(); diff --git a/lib/Frontend/QasmPP.cpp b/lib/Frontend/QasmPP.cpp index e24791f..497b52a 100644 --- a/lib/Frontend/QasmPP.cpp +++ b/lib/Frontend/QasmPP.cpp @@ -390,7 +390,7 @@ bool QasmPreprocessor::Preprocess(std::ifstream &InFile) { PBuf->pubseekpos(0, InFile.in); char *Buffer = new char[Size + 8]; (void)memset(Buffer, 0, Size + 8); - PBuf->sgetn(Buffer, Size - 1); + PBuf->sgetn(Buffer, Size); WorkFile << Buffer << "\n"; WorkFile.flush(); @@ -566,7 +566,7 @@ bool QasmPreprocessor::Preprocess(std::ifstream &InFile) { PBuf->pubseekpos(0, Tmpfile.in); Buffer = new char[Size + 8]; (void)memset(Buffer, 0, Size + 8); - PBuf->sgetn(Buffer, Size - 1); + PBuf->sgetn(Buffer, Size); WorkFile.flush(); WorkFile.close(); diff --git a/lib/Parser/QasmParser.y b/lib/Parser/QasmParser.y index c802403..a0bd4b8 100644 --- a/lib/Parser/QasmParser.y +++ b/lib/Parser/QasmParser.y @@ -38,6 +38,7 @@ namespace QASM { class ASTDriver; class ASTScanner; + class ASTUnitaryAttributeNode; } #ifndef YY_NULLPTR @@ -56,6 +57,8 @@ #include #include #include +#include +#include #include #include #include @@ -105,8 +108,9 @@ #include #include #include -#include +#include #include +#include #include #include #include @@ -145,6 +149,7 @@ #include #include #include +#include // OpenPulse #include @@ -509,6 +514,8 @@ int readinput() { QASM::ASTGateControlNode* GateControlNode; QASM::ASTGateNegControlNode* GateNegControlNode; + QASM::ASTGateFockControlNode* GateFockControlNode; + QASM::ASTGateFockNegControlNode* GateFockNegControlNode; QASM::ASTGateInverseNode* GateInverseNode; QASM::ASTGatePowerNode* GatePowerNode; QASM::ASTGPhaseExpressionNode* GPhaseNode; @@ -583,6 +590,7 @@ int readinput() { QASM::ASTPowNode* PowNode; QASM::ASTDefcalGrammarNode* DefcalGrammarNode; + QASM::ASTUnitaryAttributeNode *UnitaryAttributeNode; QASM::ASTUnaryOpNode* UnaryOpNode; QASM::ASTBinaryOpNode* BinaryOpNode; @@ -600,6 +608,8 @@ int readinput() { %token TOK_TYPEDEF_NAME %token TOK_CREG TOK_QREG TOK_CNOT TOK_HADAMARD %token TOK_CCX TOK_CX TOK_QUBIT TOK_BOUND_QUBIT TOK_UNBOUND_QUBIT +%token TOK_QUMODE TOK_UNITARY TOK_DISP //adding a data type Unitary KH +%token TOK_BUMPER TOK_BUMPER_MAX %token TOK_QUBITS TOK_U TOK_ANGLE TOK_FIXED %token TOK_DIRTY TOK_OPAQUE TOK_RESET %token TOK_IBMQASM @@ -725,8 +735,12 @@ int readinput() { %type CastExpr %type GateCtrlExpr %type GateNegCtrlExpr +%type GateFockCtrlExpr GateFockGPhaseExpr +%type GateFockNegCtrlExpr +%type FockLevelExpr FockLevelPrimary FockLevelTerm %type GateInvExpr %type GatePowExpr +%type CtrlNAt NegCtrlNAt %type BoxStmt %type GPhaseStmt %type GateCtrlExprStmt @@ -737,6 +751,7 @@ int readinput() { %type GateQOp GateCtrlStmt GateNegCtrlStmt GateInvStmt GatePowStmt GateGPhaseStmt + GateFockGPhaseStmt GateForStmt %type GateUOp %type GateEOp %type Barrier @@ -769,14 +784,16 @@ int readinput() { %type ElseStmtList ElseStmtListImpl %type KernelStmtList KernelStmtListImpl %type DefcalStmtList DefcalStmtListImpl -%type GateOpList +%type GateOpList GateForBody %type ExprList ExprListImpl %type IntegerList IntegerListImpl %type QubitConcatList QubitConcatListImpl %type AnyList AnyListImpl %type IdentifierList IdentifierListImpl %type StringList StringListImpl -%type GateQubitParamList GateQubitParamListImpl +%type GateOperandParamList GateOperandParamListImpl + GateTypedQuantumOperandList + GateTypedQuantumOperandListImpl %type ArgsList %type NamedTypeDeclList NamedTypeDeclListImpl @@ -804,6 +821,7 @@ int readinput() { %type FunctionCallStmtExpr FunctionCallStmt %type DefcalGrammarDecl +%type UnitaryAttributeAssign %type UnaryOp %type BinaryOpSelfAssign BinaryOpAssign BinaryOpPrePost BinaryOp BinaryOpExpr @@ -1467,6 +1485,9 @@ Statement } | Newline { } + | UnitaryAttributeAssign ';' { + $$ = $1; + } ; OpenPulseStatement @@ -1785,6 +1806,26 @@ Decl $$ = ASTProductionFactory::Instance().ProductionRule_1104(GET_TOKEN(6), $5, $7); } + | TOK_QUMODE Identifier ';' { + $$ = ASTProductionFactory::Instance().ProductionRule_10000(GET_TOKEN(2), $2); + } + | TOK_QUMODE '[' Integer ']' Identifier ';' { + $$ = ASTProductionFactory::Instance().ProductionRule_10001(GET_TOKEN(5), + $5, $3); + } + | TOK_QUMODE '[' Identifier ']' Identifier ';' { + $$ = ASTProductionFactory::Instance().ProductionRule_10002(GET_TOKEN(5), + $5, $3); + } + | TOK_UNITARY Identifier ';' { + $$ = ASTProductionFactory::Instance() .ProductionRule_10003(GET_TOKEN(2), $2); +} + + | TOK_UNITARY Identifier '=' '{' InitializerList '}' ';' { + $$ = ASTProductionFactory::Instance() + .ProductionRule_10004(GET_TOKEN(7), $2, $5); + } + | TOK_LET Identifier '=' TOK_IDENTIFIER '[' TOK_INTEGER_CONSTANT ',' IntegerList ']' ';' { $$ = ASTProductionFactory::Instance().ProductionRule_1150($2, $4, $6, $8); @@ -2083,35 +2124,76 @@ FuncDecl ; GateDecl - : TOK_GATE Identifier '(' NamedTypeDeclList ')' GateQubitParamList '{' GateOpList '}' { + : TOK_GATE TOK_IDENTIFIER '(' NamedTypeDeclList ')' GateOperandParamList '{' GateOpList '}' { + /* Bare TOK_IDENTIFIER: Identifier allows `name[i]`, which steals `gate + foo[uint N]` template syntax. */ + ASTIdentifierNode* Id = + ASTProductionFactory::Instance().ProductionRule_1500(GET_TOKEN(7), *$2); $$ = ASTProductionFactory::Instance().ProductionRule_1430(GET_TOKEN(8), - $2, $4, $6, $8); + Id, $4, $6, $8); } - | TOK_GATE Identifier GateQubitParamList '{' GateOpList '}' { + | TOK_GATE TOK_IDENTIFIER GateOperandParamList '{' GateOpList '}' { + ASTIdentifierNode* Id = + ASTProductionFactory::Instance().ProductionRule_1500(GET_TOKEN(4), *$2); $$ = ASTProductionFactory::Instance().ProductionRule_1431(GET_TOKEN(5), - $2, $3, $5); - } - | TOK_GATE TOK_CX GateQubitParamList '{' GateOpList '}' { + Id, $3, $5); + } + /* Fully-typed gate declaration: classical NamedTypeDecl params (validated + explicitly typed in ProductionRule_10030) + typed quantum operands. + Lookahead after ')' is TOK_QUBIT / TOK_QUMODE (vs bare Identifier for + the OQ3 untyped-operand production above). */ + | TOK_GATE TOK_IDENTIFIER '(' NamedTypeDeclList ')' GateTypedQuantumOperandList '{' GateOpList '}' { + ASTGateTemplateParamBuilder::Instance().Clear(); + ASTIdentifierNode* Id = + ASTProductionFactory::Instance().ProductionRule_1500(GET_TOKEN(7), *$2); + $$ = ASTProductionFactory::Instance().ProductionRule_10030(GET_TOKEN(8), + Id, $4, $6, $8); + } + | TOK_GATE TOK_IDENTIFIER '[' { + ASTGateTemplateParamBuilder::Instance().Clear(); + } GateTemplateParamList ']' '(' NamedTypeDeclList ')' GateTypedQuantumOperandList '{' GateOpList '}' { + /* Mid-rule counts as a symbol: $4. TOK_GATE is yystack_[12]. */ + ASTIdentifierNode* Id = + ASTProductionFactory::Instance().ProductionRule_1500(GET_TOKEN(11), *$2); + $$ = ASTProductionFactory::Instance().ProductionRule_10030(GET_TOKEN(12), + Id, $8, $10, $12); + } + | TOK_GATE TOK_CX GateOperandParamList '{' GateOpList '}' { $$ = ASTProductionFactory::Instance().ProductionRule_1432(GET_TOKEN(5), $3, GET_TOKEN(4)->GetLocation(), $5); } - | TOK_GATE TOK_HADAMARD GateQubitParamList '{' GateOpList '}' { + | TOK_GATE TOK_HADAMARD GateOperandParamList '{' GateOpList '}' { $$ = ASTProductionFactory::Instance().ProductionRule_1433(GET_TOKEN(5), $2, GET_TOKEN(4)->GetLocation(), $3, $5); } - | TOK_GATE TOK_HADAMARD '(' NamedTypeDeclList ')' GateQubitParamList '{' GateOpList '}' { + | TOK_GATE TOK_HADAMARD '(' NamedTypeDeclList ')' GateOperandParamList '{' GateOpList '}' { $$ = ASTProductionFactory::Instance().ProductionRule_1434(GET_TOKEN(8), $2, GET_TOKEN(7)->GetLocation(), $4, $6, $8); } ; +/* GateTemplateOpen removed: templated GateDecl clears the builder in a + mid-rule action after '[' so IndexedSubscript cannot steal the bracket. */ + + +GateTemplateParamList + : GateTemplateParam + | GateTemplateParamList ',' GateTemplateParam + ; + +GateTemplateParam + : TOK_UINT Identifier { + ASTProductionFactory::Instance().ProductionRule_10031(GET_TOKEN(1), $2); + } + ; + OpaqueDecl - : TOK_OPAQUE Identifier '(' NamedTypeDeclList ')' GateQubitParamList ';' { + : TOK_OPAQUE Identifier '(' NamedTypeDeclList ')' GateOperandParamList ';' { $$ = ASTProductionFactory::Instance().ProductionRule_1435(GET_TOKEN(6), $2, $4, $6); } - | TOK_OPAQUE Identifier GateQubitParamList ';' { + | TOK_OPAQUE Identifier GateOperandParamList ';' { $$ = ASTProductionFactory::Instance().ProductionRule_1436(GET_TOKEN(3), $2, $3); } @@ -2207,6 +2289,33 @@ BinaryOpAssign } ; +UnitaryAttributeAssign + : Identifier '.' TOK_BUMPER '=' Expr { + $$ = ASTProductionFactory::Instance().ProductionRule_1465( + GET_TOKEN(4), + $1, + ASTUnitaryAttributeBumper, + $5, + ASTOpTypeAssign); + } + | Identifier '.' TOK_BUMPER TOK_ADD_ASSIGN Expr { + $$ = ASTProductionFactory::Instance().ProductionRule_1465( + GET_TOKEN(4), + $1, + ASTUnitaryAttributeBumper, + $5, + ASTOpTypeAddAssign); + } + | Identifier '.' TOK_BUMPER_MAX '=' Expr { + $$ = ASTProductionFactory::Instance().ProductionRule_1465( + GET_TOKEN(4), + $1, + ASTUnitaryAttributeBumperMax, + $5, + ASTOpTypeAssign); + } + ; + BinaryOpSelfAssign : Expr TOK_RIGHT_SHIFT_ASSIGN Expr { $$ = ASTProductionFactory::Instance().ProductionRule_580(GET_TOKEN(2), $1, @@ -3556,6 +3665,27 @@ GateOpList ASTGateOpBuilder::Instance().Append(GCS); } + | GateOpList GateFockCtrlExpr { + ASTGateFockControlNode* GFCN = $2; + assert(GFCN && "Invalid ASTGateFockControlNode argument!"); + + ASTGateQOpNode* GQN = new ASTGateQOpNode(GFCN); + assert(GQN && "Could not create a valid ASTGateQOpNode!"); + + ASTGateOpBuilder::Instance().Append(GQN); + } + | GateOpList GateFockGPhaseExpr { + ASTGateFockControlNode* GFCN = $2; + assert(GFCN && "Invalid ASTGateFockControlNode argument!"); + + ASTGateQOpNode* GQN = new ASTGateQOpNode(GFCN); + assert(GQN && "Could not create a valid ASTGateQOpNode!"); + + ASTGateOpBuilder::Instance().Append(GQN); + } + | GateOpList GateFockGPhaseStmt { + ASTGateOpBuilder::Instance().Append($2); + } | GateOpList GateNegCtrlExpr { ASTGateNegControlNode* GNCN = $2; assert(GNCN && "Invalid ASTGateNegControlNode argument!"); @@ -3571,6 +3701,15 @@ GateOpList ASTGateOpBuilder::Instance().Append(GCS); } + | GateOpList GateFockNegCtrlExpr { + ASTGateFockNegControlNode* GFNCN = $2; + assert(GFNCN && "Invalid ASTGateFockNegControlNode argument!"); + + ASTGateQOpNode* GQN = new ASTGateQOpNode(GFNCN); + assert(GQN && "Could not create a valid ASTGateQOpNode!"); + + ASTGateOpBuilder::Instance().Append(GQN); + } | GateOpList GateInvExpr { ASTGateInverseNode* GIN = $2; assert(GIN && "Invalid ASTGateInverseNode argument!"); @@ -3628,6 +3767,29 @@ GateOpList | GateOpList FileDirective { // Ignored. Only used by the Preprocessor and DIAGLineCounter. } + | GateOpList GateForStmt { + ASTGateOpBuilder::Instance().Append($2); + } + ; + +GateForBody + : '{' { + ASTGateOpBuilder::Instance().PushList(); + } GateOpList '}' { + $$ = ASTGateOpBuilder::Instance().PopList(); + assert($$ && "Invalid nested GateOpList for gate-body for!"); + } + ; + +GateForStmt + : TOK_FOR Identifier TOK_IN '[' ForLoopRangeExpr ']' GateForBody { + $$ = ASTProductionFactory::Instance().ProductionRule_3220(GET_TOKEN(6), $2, + $5, $7); + } + | TOK_FOR Identifier TOK_IN '[' IntegerList ']' GateForBody { + $$ = ASTProductionFactory::Instance().ProductionRule_3221(GET_TOKEN(6), $2, + $5, $7); + } ; GateQOp @@ -3669,6 +3831,10 @@ GateEOp $$ = ASTProductionFactory::Instance().ProductionRule_3506(GET_TOKEN(2), $2, $3); } + | TOK_DISP ArgsList AnyList { + $$ = ASTProductionFactory::Instance().ProductionRule_10020(GET_TOKEN(2), + $2, $3); + } ; GateUOp @@ -3682,6 +3848,11 @@ ArgsList $$ = ASTArgumentNodeBuilder::Instance().NewList(); } | '(' ExprList ')' { + /* ExprList already accepts ComplexInitializerExpr (`… im`), nested + FunctionCallArg, and `[…]` array literals as elements — so mixed + calls like foo([a,b], theta) work without a separate GateCallArg + list (which stole the Identifier '(' … ')' LR state from function + calls and broke assign-from-call / nested gate args). */ $$ = ASTArgumentNodeBuilder::Instance().List(); *$$ = $2; } @@ -3764,48 +3935,104 @@ StringListImpl } ; -GateQubitParamList - : GateQubitParamListImpl Identifier { - assert($1 && "Invalid GateQubitParamListImpl!"); +GateOperandParamList + : GateOperandParamListImpl Identifier { + assert($1 && "Invalid GateOperandParamListImpl!"); ASTIdentifierNode* Id = $2; assert(Id && "Invalid ASTIdentifierNode argument!"); Id->SetPolymorphicType(Id->GetSymbolType()); - Id->SetSymbolType(ASTTypeGateQubitParam); + Id->SetSymbolType(ASTTypeGateOperandParam); Id->SetBits(1U); Id->SetLocalScope(); $1->Append(Id); } ; -GateQubitParamListImpl +GateOperandParamListImpl : %empty { - $$ = ASTGateQubitParamBuilder::Instance().NewList(); + $$ = ASTGateOperandParamBuilder::Instance().NewList(); } - | GateQubitParamListImpl Identifier ',' { - assert($1 && "Invalid GateQubitParamListImpl!"); + | GateOperandParamListImpl Identifier ',' { + assert($1 && "Invalid GateOperandParamListImpl!"); ASTIdentifierNode* Id = $2; assert(Id && "Invalid ASTIdentifierNode argument!"); Id->SetPolymorphicType(Id->GetSymbolType()); - Id->SetSymbolType(ASTTypeGateQubitParam); + Id->SetSymbolType(ASTTypeGateOperandParam); Id->SetBits(1U); Id->SetLocalScope(); $1->Append(Id); } - | GateQubitParamListImpl Identifier { - assert($1 && "Invalid GateQubitParamListImpl!"); + | GateOperandParamListImpl Identifier { + assert($1 && "Invalid GateOperandParamListImpl!"); ASTIdentifierNode* Id = $2; assert(Id && "Invalid ASTIdentifierNode argument!"); Id->SetPolymorphicType(Id->GetSymbolType()); - Id->SetSymbolType(ASTTypeGateQubitParam); + Id->SetSymbolType(ASTTypeGateOperandParam); Id->SetBits(1U); Id->SetLocalScope(); $1->Append($2); } ; +/* Quantum operands for fully-typed gate decls: qubit/qumode keyword required. + PolymorphicType records the declared quantum kind; SymbolType stays + ASTTypeGateOperandParam for existing gate-formal machinery. */ +GateTypedQuantumOperandList + : GateTypedQuantumOperandListImpl TOK_QUBIT Identifier { + assert($1 && "Invalid GateTypedQuantumOperandListImpl!"); + ASTIdentifierNode* Id = $3; + assert(Id && "Invalid ASTIdentifierNode argument!"); + Id->SetPolymorphicType(ASTTypeQubit); + Id->SetSymbolType(ASTTypeGateOperandParam); + Id->SetBits(1U); + Id->SetLocalScope(); + $1->Append(Id); + $$ = $1; + } + | GateTypedQuantumOperandListImpl TOK_QUMODE Identifier { + assert($1 && "Invalid GateTypedQuantumOperandListImpl!"); + ASTIdentifierNode* Id = $3; + assert(Id && "Invalid ASTIdentifierNode argument!"); + Id->SetPolymorphicType(ASTTypeQumode); + Id->SetSymbolType(ASTTypeGateOperandParam); + Id->SetBits(1U); + Id->SetLocalScope(); + $1->Append(Id); + $$ = $1; + } + ; + +GateTypedQuantumOperandListImpl + : %empty { + $$ = ASTGateOperandParamBuilder::Instance().NewList(); + } + | GateTypedQuantumOperandListImpl TOK_QUBIT Identifier ',' { + assert($1 && "Invalid GateTypedQuantumOperandListImpl!"); + ASTIdentifierNode* Id = $3; + assert(Id && "Invalid ASTIdentifierNode argument!"); + Id->SetPolymorphicType(ASTTypeQubit); + Id->SetSymbolType(ASTTypeGateOperandParam); + Id->SetBits(1U); + Id->SetLocalScope(); + $1->Append(Id); + $$ = $1; + } + | GateTypedQuantumOperandListImpl TOK_QUMODE Identifier ',' { + assert($1 && "Invalid GateTypedQuantumOperandListImpl!"); + ASTIdentifierNode* Id = $3; + assert(Id && "Invalid ASTIdentifierNode argument!"); + Id->SetPolymorphicType(ASTTypeQumode); + Id->SetSymbolType(ASTTypeGateOperandParam); + Id->SetBits(1U); + Id->SetLocalScope(); + $1->Append(Id); + $$ = $1; + } + ; + AnyList : AnyListImpl Identifier { $$ = ASTAnyTypeBuilder::Instance().List(); @@ -3949,6 +4176,10 @@ ExprList $1->Append($2); $$ = $1; } + | ExprListImpl '[' ExprList ']' { + $1->Append(ASTProductionFactory::Instance().ProductionRule_10010($3)); + $$ = $1; + } | ExprListImpl ImplicitDuration { $1->Append($2); $$ = $1; @@ -3969,6 +4200,10 @@ ExprListImpl $1->Append($2); $$ = $1; } + | ExprListImpl '[' ExprList ']' ',' { + $1->Append(ASTProductionFactory::Instance().ProductionRule_10010($3)); + $$ = $1; + } | ExprListImpl BinaryOpAssign ',' { $1->Append($2); $$ = $1; @@ -4751,16 +4986,18 @@ IndexedUnboundQubit ; ComplexCReal - : TOK_IDENTIFIER '.' TOK_CREAL { - $$ = ASTProductionFactory::Instance().ProductionRule_816(GET_TOKEN(2), - GET_TOKEN(0)); + : Identifier '.' TOK_CREAL { + $$ = ASTProductionFactory::Instance().ProductionRule_816( + $1, + GET_TOKEN(2)); } ; ComplexCImag - : TOK_IDENTIFIER '.' TOK_CIMAG { - $$ = ASTProductionFactory::Instance().ProductionRule_816(GET_TOKEN(2), - GET_TOKEN(0)); + : Identifier '.' TOK_CIMAG { + $$ = ASTProductionFactory::Instance().ProductionRule_816( + $1, + GET_TOKEN(2)); } ; @@ -6113,6 +6350,11 @@ ArrayExpr $8, $5, ASTTypeMPDecimalArray); } + | TOK_ARRAY '[' TOK_FLOAT '[' Integer ']' ',' Identifier ']' Identifier { + $$ = ASTProductionFactory::Instance().ProductionRule_822(GET_TOKEN(9), $10, + $8, $5, + ASTTypeMPDecimalArray); + } | TOK_ARRAY '[' TOK_FLOAT '[' Integer ']' ',' Integer ',' Integer ']' Identifier { $$ = ASTProductionFactory::Instance().ProductionRule_822(GET_TOKEN(11), $12, $8, $5, $10, @@ -6830,6 +7072,13 @@ ForLoopRangeExpr $1, $4, ASTOpTypeRightShiftAssign); } + // Bare end bound: `for i in [0:N]` (desugar end as N+0). + | IntegerList Identifier { + ASTIntNode *Zero = new ASTIntNode(static_cast(0)); + $$ = ASTProductionFactory::Instance().ProductionRule_860(GET_TOKEN(1), $2, + $1, Zero, + ASTOpTypeAdd); + } ; GPhaseExpr @@ -6851,47 +7100,165 @@ GPhaseStmt ; GateCtrlExpr - : TOK_CTRL TOK_ASSOCIATION_OP GateEOp { - $$ = ASTProductionFactory::Instance().ProductionRule_3850(GET_TOKEN(2), $3); + : CtrlAt GateEOp { + $$ = ASTProductionFactory::Instance().ProductionRule_3850( + ASTGateContextBuilder::Instance().GetControlModifierToken(), $2); + ASTGateContextBuilder::Instance().ExitControlModifier(); } - | TOK_CTRL '(' Integer ')' TOK_ASSOCIATION_OP GateEOp { - $$ = ASTProductionFactory::Instance().ProductionRule_3850(GET_TOKEN(5), - $6, $3); + | CtrlNAt GateEOp { + $$ = ASTProductionFactory::Instance().ProductionRule_3850( + ASTGateContextBuilder::Instance().GetControlModifierToken(), $2, $1); + ASTGateContextBuilder::Instance().ExitControlModifier(); } - | TOK_CTRL TOK_ASSOCIATION_OP GateCtrlExpr { - $$ = ASTProductionFactory::Instance().ProductionRule_3850(GET_TOKEN(2), $3); + | CtrlAt GateCtrlExpr { + $$ = ASTProductionFactory::Instance().ProductionRule_3850( + ASTGateContextBuilder::Instance().GetControlModifierToken(), $2); + ASTGateContextBuilder::Instance().ExitControlModifier(); } - | TOK_CTRL '(' Integer ')' TOK_ASSOCIATION_OP GateCtrlExpr { - $$ = ASTProductionFactory::Instance().ProductionRule_3850(GET_TOKEN(5), - $6, $3); + | CtrlNAt GateCtrlExpr { + $$ = ASTProductionFactory::Instance().ProductionRule_3850( + ASTGateContextBuilder::Instance().GetControlModifierToken(), $2, $1); + ASTGateContextBuilder::Instance().ExitControlModifier(); } - | TOK_CTRL TOK_ASSOCIATION_OP GateNegCtrlExpr { - $$ = ASTProductionFactory::Instance().ProductionRule_3850(GET_TOKEN(2), $3); + | CtrlAt GateNegCtrlExpr { + $$ = ASTProductionFactory::Instance().ProductionRule_3850( + ASTGateContextBuilder::Instance().GetControlModifierToken(), $2); + ASTGateContextBuilder::Instance().ExitControlModifier(); } - | TOK_CTRL '(' Integer ')' TOK_ASSOCIATION_OP GateNegCtrlExpr { - $$ = ASTProductionFactory::Instance().ProductionRule_3850(GET_TOKEN(5), - $6, $3); + | CtrlNAt GateNegCtrlExpr { + $$ = ASTProductionFactory::Instance().ProductionRule_3850( + ASTGateContextBuilder::Instance().GetControlModifierToken(), $2, $1); + ASTGateContextBuilder::Instance().ExitControlModifier(); } - | TOK_CTRL TOK_ASSOCIATION_OP GateGPhaseExpr { - $$ = ASTProductionFactory::Instance().ProductionRule_3850(GET_TOKEN(2), $3); + | CtrlAt GateGPhaseExpr { + $$ = ASTProductionFactory::Instance().ProductionRule_3850( + ASTGateContextBuilder::Instance().GetControlModifierToken(), $2); + ASTGateContextBuilder::Instance().ExitControlModifier(); } - | TOK_CTRL '(' Integer ')' TOK_ASSOCIATION_OP GateGPhaseExpr { - $$ = ASTProductionFactory::Instance().ProductionRule_3850(GET_TOKEN(5), - $6, $3); + | CtrlNAt GateGPhaseExpr { + $$ = ASTProductionFactory::Instance().ProductionRule_3850( + ASTGateContextBuilder::Instance().GetControlModifierToken(), $2, $1); + ASTGateContextBuilder::Instance().ExitControlModifier(); } - | TOK_CTRL TOK_ASSOCIATION_OP GateInvExpr { - $$ = ASTProductionFactory::Instance().ProductionRule_3850(GET_TOKEN(2), $3); + | CtrlAt GateInvExpr { + $$ = ASTProductionFactory::Instance().ProductionRule_3850( + ASTGateContextBuilder::Instance().GetControlModifierToken(), $2); + ASTGateContextBuilder::Instance().ExitControlModifier(); } - | TOK_CTRL '(' Integer ')' TOK_ASSOCIATION_OP GateInvExpr { - $$ = ASTProductionFactory::Instance().ProductionRule_3850(GET_TOKEN(5), - $6, $3); + | CtrlNAt GateInvExpr { + $$ = ASTProductionFactory::Instance().ProductionRule_3850( + ASTGateContextBuilder::Instance().GetControlModifierToken(), $2, $1); + ASTGateContextBuilder::Instance().ExitControlModifier(); } - | TOK_CTRL TOK_ASSOCIATION_OP GatePowExpr { - $$ = ASTProductionFactory::Instance().ProductionRule_3850(GET_TOKEN(2), $3); + | CtrlAt GatePowExpr { + $$ = ASTProductionFactory::Instance().ProductionRule_3850( + ASTGateContextBuilder::Instance().GetControlModifierToken(), $2); + ASTGateContextBuilder::Instance().ExitControlModifier(); } - | TOK_CTRL '(' Integer ')' TOK_ASSOCIATION_OP GatePowExpr { - $$ = ASTProductionFactory::Instance().ProductionRule_3850(GET_TOKEN(5), - $6, $3); + | CtrlNAt GatePowExpr { + $$ = ASTProductionFactory::Instance().ProductionRule_3850( + ASTGateContextBuilder::Instance().GetControlModifierToken(), $2, $1); + ASTGateContextBuilder::Instance().ExitControlModifier(); + } + ; + +CtrlAt + : TOK_CTRL TOK_ASSOCIATION_OP { + ASTGateContextBuilder::Instance().EnterControlModifier(GET_TOKEN(1)); + } + ; + +CtrlNAt + : TOK_CTRL '(' Integer ')' TOK_ASSOCIATION_OP { + $$ = $3; + ASTGateContextBuilder::Instance().EnterControlModifier(GET_TOKEN(4)); + } + ; + +// Dedicated Fock level grammar — do not reuse BinaryOpExpr/Expr (those merge +// with assignment / comparison and refuse `N-1` inside brackets). +FockLevelPrimary + : Integer { + $$ = $1; + } + | Identifier { + $$ = ASTProductionFactory::Instance().ProductionRule_8001(GET_TOKEN(0), $1); + } + | '(' FockLevelExpr ')' { + $$ = $2; + } + | '-' FockLevelPrimary { + $$ = ASTBuilder::Instance().CreateASTUnaryOpNode( + "ast-fock-level", $2, ASTOpTypeNegative); + } + ; + +FockLevelTerm + : FockLevelPrimary { + $$ = $1; + } + | FockLevelTerm TOK_MUL_OP FockLevelPrimary { + $$ = ASTBuilder::Instance().CreateASTBinaryOpNode( + "ast-fock-level", $1, $3, ASTOpTypeMul); + } + | FockLevelTerm TOK_DIV_OP FockLevelPrimary { + $$ = ASTBuilder::Instance().CreateASTBinaryOpNode( + "ast-fock-level", $1, $3, ASTOpTypeDiv); + } + ; + +FockLevelExpr + : FockLevelTerm { + $$ = $1; + } + | FockLevelExpr TOK_ADD_OP FockLevelTerm { + $$ = ASTBuilder::Instance().CreateASTBinaryOpNode( + "ast-fock-level", $1, $3, ASTOpTypeAdd); + } + | FockLevelExpr '-' FockLevelTerm { + $$ = ASTBuilder::Instance().CreateASTBinaryOpNode( + "ast-fock-level", $1, $3, ASTOpTypeSub); + } + // Flex longest-match glues "-" onto a following numeral (`N-1` → id, int -1). + // Treat that as addition of the already-signed literal (i.e. subtraction). + | FockLevelExpr Integer { + if (!$2 || !$2->IsSigned() || $2->GetSignedValue() >= 0) { + std::stringstream M; + M << "Expected a binary operator in Fock level expression."; + QasmDiagnosticEmitter::Instance().EmitDiagnostic( + DIAGLineCounter::Instance().GetLocation($2), M.str(), DiagLevel::Error); + YYERROR; + } + $$ = ASTBuilder::Instance().CreateASTBinaryOpNode( + "ast-fock-level", $1, $2, ASTOpTypeAdd); + } + ; + +// Fock-level control: `ctrl[FockLevelExpr] @ …` +GateFockCtrlExpr + : TOK_CTRL '[' FockLevelExpr ']' TOK_ASSOCIATION_OP GateEOp { + ASTGateContextBuilder::Instance().EnterControlModifier(GET_TOKEN(5)); + $$ = ASTProductionFactory::Instance().ProductionRule_3855( + ASTGateContextBuilder::Instance().GetControlModifierToken(), $6, $3); + ASTGateContextBuilder::Instance().ExitControlModifier(); + } + ; + +GateFockGPhaseExpr + : TOK_CTRL '[' FockLevelExpr ']' TOK_ASSOCIATION_OP GPhaseExpr IdentifierList { + ASTGateContextBuilder::Instance().EnterControlModifier(GET_TOKEN(6)); + ASTGateGPhaseExpressionNode* GGEN = + ASTProductionFactory::Instance().ProductionRule_3854( + ASTGateContextBuilder::Instance().GetControlModifierToken(), $6, $7); + $$ = ASTProductionFactory::Instance().ProductionRule_3855( + ASTGateContextBuilder::Instance().GetControlModifierToken(), GGEN, $3); + ASTGateContextBuilder::Instance().ExitControlModifier(); + } + ; + +GateFockGPhaseStmt + : GateFockGPhaseExpr ';' { + $$ = new ASTGateQOpNode($1); } ; @@ -6910,40 +7277,77 @@ GateCtrlExprStmt ; GateNegCtrlExpr - : TOK_NEGCTRL TOK_ASSOCIATION_OP GateEOp { - $$ = ASTProductionFactory::Instance().ProductionRule_3851(GET_TOKEN(2), $3); + : NegCtrlAt GateEOp { + $$ = ASTProductionFactory::Instance().ProductionRule_3851( + ASTGateContextBuilder::Instance().GetControlModifierToken(), $2); + ASTGateContextBuilder::Instance().ExitControlModifier(); } - | TOK_NEGCTRL '(' Integer ')' TOK_ASSOCIATION_OP GateEOp { - $$ = ASTProductionFactory::Instance().ProductionRule_3851(GET_TOKEN(5), - $6, $3); + | NegCtrlNAt GateEOp { + $$ = ASTProductionFactory::Instance().ProductionRule_3851( + ASTGateContextBuilder::Instance().GetControlModifierToken(), $2, $1); + ASTGateContextBuilder::Instance().ExitControlModifier(); } - | TOK_NEGCTRL TOK_ASSOCIATION_OP GateNegCtrlExpr { - $$ = ASTProductionFactory::Instance().ProductionRule_3851(GET_TOKEN(2), $3); + | NegCtrlAt GateNegCtrlExpr { + $$ = ASTProductionFactory::Instance().ProductionRule_3851( + ASTGateContextBuilder::Instance().GetControlModifierToken(), $2); + ASTGateContextBuilder::Instance().ExitControlModifier(); } - | TOK_NEGCTRL '(' Integer ')' TOK_ASSOCIATION_OP GateNegCtrlExpr { - $$ = ASTProductionFactory::Instance().ProductionRule_3851(GET_TOKEN(5), - $6, $3); + | NegCtrlNAt GateNegCtrlExpr { + $$ = ASTProductionFactory::Instance().ProductionRule_3851( + ASTGateContextBuilder::Instance().GetControlModifierToken(), $2, $1); + ASTGateContextBuilder::Instance().ExitControlModifier(); } - | TOK_NEGCTRL TOK_ASSOCIATION_OP GateGPhaseExpr { - $$ = ASTProductionFactory::Instance().ProductionRule_3851(GET_TOKEN(2), $3); + | NegCtrlAt GateGPhaseExpr { + $$ = ASTProductionFactory::Instance().ProductionRule_3851( + ASTGateContextBuilder::Instance().GetControlModifierToken(), $2); + ASTGateContextBuilder::Instance().ExitControlModifier(); } - | TOK_NEGCTRL '(' Integer ')' TOK_ASSOCIATION_OP GateGPhaseExpr { - $$ = ASTProductionFactory::Instance().ProductionRule_3851(GET_TOKEN(5), - $6, $3); + | NegCtrlNAt GateGPhaseExpr { + $$ = ASTProductionFactory::Instance().ProductionRule_3851( + ASTGateContextBuilder::Instance().GetControlModifierToken(), $2, $1); + ASTGateContextBuilder::Instance().ExitControlModifier(); } - | TOK_NEGCTRL TOK_ASSOCIATION_OP GateInvExpr { - $$ = ASTProductionFactory::Instance().ProductionRule_3851(GET_TOKEN(2), $3); + | NegCtrlAt GateInvExpr { + $$ = ASTProductionFactory::Instance().ProductionRule_3851( + ASTGateContextBuilder::Instance().GetControlModifierToken(), $2); + ASTGateContextBuilder::Instance().ExitControlModifier(); } - | TOK_NEGCTRL '(' Integer ')' TOK_ASSOCIATION_OP GateInvExpr { - $$ = ASTProductionFactory::Instance().ProductionRule_3851(GET_TOKEN(5), - $6, $3); + | NegCtrlNAt GateInvExpr { + $$ = ASTProductionFactory::Instance().ProductionRule_3851( + ASTGateContextBuilder::Instance().GetControlModifierToken(), $2, $1); + ASTGateContextBuilder::Instance().ExitControlModifier(); } - | TOK_NEGCTRL TOK_ASSOCIATION_OP GatePowExpr { - $$ = ASTProductionFactory::Instance().ProductionRule_3851(GET_TOKEN(2), $3); + | NegCtrlAt GatePowExpr { + $$ = ASTProductionFactory::Instance().ProductionRule_3851( + ASTGateContextBuilder::Instance().GetControlModifierToken(), $2); + ASTGateContextBuilder::Instance().ExitControlModifier(); } - | TOK_NEGCTRL '(' Integer ')' TOK_ASSOCIATION_OP GatePowExpr { - $$ = ASTProductionFactory::Instance().ProductionRule_3851(GET_TOKEN(5), - $6, $3); + | NegCtrlNAt GatePowExpr { + $$ = ASTProductionFactory::Instance().ProductionRule_3851( + ASTGateContextBuilder::Instance().GetControlModifierToken(), $2, $1); + ASTGateContextBuilder::Instance().ExitControlModifier(); + } + ; + +NegCtrlAt + : TOK_NEGCTRL TOK_ASSOCIATION_OP { + ASTGateContextBuilder::Instance().EnterControlModifier(GET_TOKEN(1)); + } + ; + +NegCtrlNAt + : TOK_NEGCTRL '(' Integer ')' TOK_ASSOCIATION_OP { + $$ = $3; + ASTGateContextBuilder::Instance().EnterControlModifier(GET_TOKEN(4)); + } + ; + +GateFockNegCtrlExpr + : TOK_NEGCTRL '[' FockLevelExpr ']' TOK_ASSOCIATION_OP GateEOp { + ASTGateContextBuilder::Instance().EnterControlModifier(GET_TOKEN(5)); + $$ = ASTProductionFactory::Instance().ProductionRule_3856( + ASTGateContextBuilder::Instance().GetControlModifierToken(), $6, $3); + ASTGateContextBuilder::Instance().ExitControlModifier(); } ; diff --git a/lib/Parser/QasmScanner.l b/lib/Parser/QasmScanner.l index 51795a9..0111f53 100644 --- a/lib/Parser/QasmScanner.l +++ b/lib/Parser/QasmScanner.l @@ -179,11 +179,13 @@ inline void reset_colno() { } \ } -#define sym_type(ident) token::TOK_IDENTIFIER +#define sym_type(ident) token::TOK_IDENTIFIER //dead, unused code, delete in a later push request extern void yyerror(const char* msg); extern int readinput(); +//error message functions + void token_error() { std::cerr << "Error: Unrecognized token at line " << QASM::DIAGLineCounter::Instance().GetLineCount() @@ -205,6 +207,9 @@ void comment_error(const char* msg) { std::cerr << ": " << yytext << std::endl; } + + + %} %option debug @@ -333,14 +338,49 @@ void comment_error(const char* msg) { } "qubit" { - yylval->Tok = ASTTokenFactory::Create(yytext, token::TOK_QUBIT); + yylval->Tok = ASTTokenFactory::Create(yytext, token::TOK_QUBIT); // when we reach the sequence "qubit q;" quibt is recognized as a known sequence and a token object is created + assert(yylval->Tok && "Could not create a valid ASTToken!"); //checking the token was created successfully + yylval->Token = yylval->Tok->GetInt(); // store token ID + yylval->String = yylval->Tok->GetStringAddress(); //store token address + yylval->Tok->SetLocation(DIAGLineCounter::Instance().GetLineCount(), //save where the loction appeared in the source file + prev_yycolno + 1); + ASTTokenFactory::Register(yylval->Tok, yylval->Tok->GetIndex()); //store token in registry + QASM::ASTIdentifierTypeController::Instance().SetCurrentType(ASTTypeQubit); //IMPORTANT this sets the identifier type. so when we see qubit q; we know moving forward that q is type ASTTypeQubit + return yylval->Tok->GetInt(); //return int corresponding to Tok_QUBIT (we then use that number when matching a rule) +} + +"qumode" { +yylval->Tok = ASTTokenFactory::Create(yytext, token::TOK_QUMODE); assert(yylval->Tok && "Could not create a valid ASTToken!"); yylval->Token = yylval->Tok->GetInt(); yylval->String = yylval->Tok->GetStringAddress(); yylval->Tok->SetLocation(DIAGLineCounter::Instance().GetLineCount(), prev_yycolno + 1); ASTTokenFactory::Register(yylval->Tok, yylval->Tok->GetIndex()); - QASM::ASTIdentifierTypeController::Instance().SetCurrentType(ASTTypeQubit); + QASM::ASTIdentifierTypeController::Instance().SetCurrentType(ASTTypeQumode); + return yylval->Tok->GetInt(); +} + +"unitary" { //adding a data type Unitary KH + yylval->Tok = + ASTTokenFactory::Create(yytext, token::TOK_UNITARY); + + assert(yylval->Tok && "Could not create a valid ASTToken!"); + + yylval->Token = yylval->Tok->GetInt(); + yylval->String = yylval->Tok->GetStringAddress(); + + yylval->Tok->SetLocation( + DIAGLineCounter::Instance().GetLineCount(), + prev_yycolno + 1); + + ASTTokenFactory::Register( + yylval->Tok, + yylval->Tok->GetIndex()); + + QASM::ASTIdentifierTypeController::Instance() + .SetCurrentType(ASTTypeUnitary); + return yylval->Tok->GetInt(); } @@ -359,6 +399,21 @@ void comment_error(const char* msg) { return yylval->Tok->GetInt(); } +"disp" { + ASTGateContextBuilder::Instance().OpenContext(); + yylval->Tok = ASTTokenFactory::Create(yytext, token::TOK_DISP); + assert(yylval->Tok && "Could not create a valid ASTToken!"); + yylval->Token = yylval->Tok->GetInt(); + yylval->String = yylval->Tok->GetStringAddress(); + yylval->Tok->SetLocation(DIAGLineCounter::Instance().GetLineCount(), + prev_yycolno + 1); + ASTTokenFactory::Register(yylval->Tok, yylval->Tok->GetIndex()); + QASM::ASTIdentifierTypeController::Instance().Reset(); + QASM::ASTIdentifierTypeController::Instance().SetCurrentType(ASTTypeDispGate); + QASM::ASTIdentifierTypeController::Instance().StartQubitList(); + return yylval->Tok->GetInt(); +} + "gate" { ASTGateContextBuilder::Instance().OpenContext(); yylval->Tok = ASTTokenFactory::Create(yytext, token::TOK_GATE); @@ -1005,7 +1060,7 @@ void comment_error(const char* msg) { yylval->Tok->SetLocation(DIAGLineCounter::Instance().GetLineCount(), prev_yycolno + 1); ASTTokenFactory::Register(yylval->Tok, yylval->Tok->GetIndex()); - return token::TOK_IDENTIFIER; + return token::TOK_IDENTIFIER; //simply telling the parser to parse the tok_delta as it would a TOk_IDENTIFER. the AST tree will still see TOK_DELTA } "Ε" { @@ -2961,6 +3016,44 @@ $[a-zA-Z_][0-9]+ { ASTTokenFactory::Register(yylval->Tok, yylval->Tok->GetIndex()); return yylval->Tok->GetInt(); } +"bumper_max" { + yylval->Tok = + ASTTokenFactory::Create(yytext, token::TOK_BUMPER_MAX); + assert(yylval->Tok && "Could not create a valid ASTToken!"); + + yylval->Token = yylval->Tok->GetInt(); + yylval->String = yylval->Tok->GetStringAddress(); + + yylval->Tok->SetLocation( + DIAGLineCounter::Instance().GetLineCount(), + prev_yycolno + 1); + + ASTTokenFactory::Register( + yylval->Tok, + yylval->Tok->GetIndex()); + + return yylval->Tok->GetInt(); +} + +"bumper" { + yylval->Tok = + ASTTokenFactory::Create(yytext, token::TOK_BUMPER); + assert(yylval->Tok && "Could not create a valid ASTToken!"); + + yylval->Token = yylval->Tok->GetInt(); + yylval->String = yylval->Tok->GetStringAddress(); + + yylval->Tok->SetLocation( + DIAGLineCounter::Instance().GetLineCount(), + prev_yycolno + 1); + + ASTTokenFactory::Register( + yylval->Tok, + yylval->Tok->GetIndex()); + + return yylval->Tok->GetInt(); +} + {L}{A}* { yylval->Tok = ASTTokenFactory::Create(yytext, token::TOK_IDENTIFIER); @@ -3113,6 +3206,16 @@ $[a-zA-Z_][0-9]+ { return yylval->Tok->GetInt(); } +%[0-9a-zA-Z_]+ { + yylval->Tok = ASTTokenFactory::Create(yytext, token::TOK_IDENTIFIER); + assert(yylval->Tok && "Could not create a valid ASTToken!"); + yylval->Token = yylval->Tok->GetInt(); + yylval->String = yylval->Tok->GetStringAddress(); + yylval->Tok->SetLocation(DIAGLineCounter::Instance().GetLineCount(), + prev_yycolno + 1); + ASTTokenFactory::Register(yylval->Tok, yylval->Tok->GetIndex()); + return yylval->Tok->GetInt(); +} {HP}{H}+{IS}? { yylval->Tok = ASTTokenFactory::Create(yytext, token::TOK_INTEGER_CONSTANT); assert(yylval->Tok && "Could not create a valid ASTToken!"); @@ -3717,7 +3820,7 @@ $[a-zA-Z_][0-9]+ { ASTType CTy = ASTIdentifierTypeController::Instance().GetCurrentType(); switch (CTy) { - case ASTTypeGateQubitParam: + case ASTTypeGateOperandParam: break; default: ASTIdentifierTypeController::Instance().StopContextRecord(); @@ -3996,17 +4099,6 @@ $[a-zA-Z_][0-9]+ { return yylval->Tok->GetInt(); } -%[0-9a-zA-Z_]+ { - yylval->Tok = ASTTokenFactory::Create(yytext, token::TOK_IDENTIFIER); - assert(yylval->Tok && "Could not create a valid ASTToken!"); - yylval->Token = yylval->Tok->GetInt(); - yylval->String = yylval->Tok->GetStringAddress(); - yylval->Tok->SetLocation(DIAGLineCounter::Instance().GetLineCount(), - prev_yycolno + 1); - ASTTokenFactory::Register(yylval->Tok, yylval->Tok->GetIndex()); - return yylval->Tok->GetInt(); -} - "<" { yylval->Tok = ASTTokenFactory::Create(yytext, token::TOK_LT_OP); assert(yylval->Tok && "Could not create a valid ASTToken!"); diff --git a/project-status-mtlau-260803.md b/project-status-mtlau-260803.md new file mode 100644 index 0000000..9079f5c --- /dev/null +++ b/project-status-mtlau-260803.md @@ -0,0 +1,103 @@ +# Project Status (2026-08-03) +Mu-Te Lau + +This file documents the status of the project, as of 2026-08-03, focusing on the +tasks I'm in charge of. + +# Stable Features +The following features work as expected: + +- `qumode` declarations: mirrors qubit declaration syntaxes + ```qasm + qumode qm; + qumode[3] qms; + ``` +- Basic qumode gates: displacement, SNAP, ECD gates + - `disp(alpha) qm;` + - `snap[N]([theta_0, theta_1, theta_2,...]) qm;` + - `ecd(alpha) qb, qm;` + - A type system is implemented along with the gate declaration syntaxes. + CV gates (`disp` / `snap` / `ecd`) are no longer declared via `opaque`. + - [docs/gates.md#type-errors-at-call-sites](docs/gates.md#type-errors-at-call-sites) + lists the types of errors that the type system can catch. + +The AST subtrees of qumodes and gate calls are considered stable and not +expected to change much. With these, I believe the compiler has enough data to +build the program level IR. + + +# Work-In-Progress Features +The following features are implemented, but the syntax and the ASTs are not stable yet. +- Gate declaration syntaxes: see [docs/gates.md#gate-declaration-syntax](docs/gates.md#gate-declaration-syntax) + for more details. + - Typed gate template parameters (`uint N` as array length) with call-site + inference from array literals / declared named-array sizes and explicit + `gatecall[N](…)`; uninitialized named arrays reject as used-before-assigned. + - We proposed using angle brackets for template parameters. I decided to use + square brackets instead to avoid parsing issues. See + [docs/gates.md#syntax-change-for-template-parameters](docs/gates.md#syntax-change-for-template-parameters) + for more details. +- Fock-level `ctrl[…]` / `negctrl[…]` (distinct from qubit `ctrl(n)`): level may + be an integer, identifier, or expression (`ctrl[3]`, `ctrl[N]`, `ctrl[N-1]`); + see [docs/gates.md#fock-level-ctrl-negctrl](docs/gates.md#fock-level-ctrl-negctrl). +- Gate-body `for` (`GateForStmt` / `ASTGateForOpNode`); SNAP is a real typed + definition in `cvgates.inc`. + +These features are implemented to support a stable gate call AST, as the +subtrees of gate declarations and gate calls are intimately related. +To be specific: +- The gate signature (names, template params, params, operands) is largely + stable in terms of AST shapes, but the frontend syntax is not. +- Treat everything inside the gate body as unstable, including the syntax and the ASTs. + +# Not Implemented: Gate-Level IR +Ended up not having time to implement it. +I decided that a proper type system and gate declaration syntax are +more important to implement first, since gate declarations and gate calls ASTs +are tightly related. Also, it would fortify the parser by allowing it to catch +type errors at call sites. + +In addition, I believe the implementation of gate-level IR can be delayed. +For single-qumode programs, the DAG view that the gate-level IR would provide +is not useful yet. I believe the S+D Unitary decomposition pass can be applied +to the program level IR, and it wouldn't be too hard to migrate that pass to +the gate level IR after we have that. + +# Known Issues +- Proposed array literal syntax conflicts with the OQ3 standard ([Issue #13](https://github.com/paragon-lab/qe-qasm-qumode-version/issues/13)). +- Several bugs/gaps in the codebase. All the bugs I have encountered and have + not fixed yet are on the GitHub issues. Here are some of the more important + ones: + - Expression parsing is fragile and not reusable ([Issue #12](https://github.com/paragon-lab/qe-qasm-qumode-version/issues/12)). + - Duplicate declarations are not guarded ([Issue #7](https://github.com/paragon-lab/qe-qasm-qumode-version/issues/7)). + - Some AST components still use `Qubit` in names even though those paths also + cover qumodes / generic quantum formals + ([Issue #14](https://github.com/paragon-lab/qe-qasm-qumode-version/issues/14)). + - Array literals cannot be assigned to a variable ([Issue #11](https://github.com/paragon-lab/qe-qasm-qumode-version/issues/11)). +- Unit tests only check whether the parser accepts/rejects input; they do not + validate AST correctness. At some point we will probably want tests that + check AST structure too. + +# Some Other Notes +The things I'm not in charge of, but could be useful to note. Feel free to fix +these or post issues for them. + +## Unitary / bumper feature gaps +- Lack of way to specify the precision of unitary decompositions + (maybe `u.precision`?) +- What if `bumper` and `bumper_max` are simultaneously specified? + ```qasm + u.bumper = 4; + u.bumper_max = 3; // outright contradictory + ``` + ```qasm + // which statement should the compiler honor? Should we just disallow this? + u.bumper = 4; + u.bumper_max = 5; + ``` + +## Testing / tooling +- Unitary unit tests under `tests/src/unitary/` are not wired up to ctest. To + wire them up, add tests in `tests/CMakeLists.txt`. I'd suggest adding both + tests that should succeed and tests that should fail. You can find examples + on how to do this in `tests/CMakeLists.txt`. diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..8dc6cf1 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,9 @@ +[project] +name = "qe-qasm-dev" +version = "0.0.0" +description = "Development tooling for the qe-qasm C++ parser" +requires-python = ">=3.10" +dependencies = [] + +[dependency-groups] +dev = ["cmake", "conan<2.0", "pre-commit", "setuptools_scm>=6.0,<8.0"] diff --git a/qumode_openqasm_syntax_reference.md b/qumode_openqasm_syntax_reference.md new file mode 100644 index 0000000..dc60346 --- /dev/null +++ b/qumode_openqasm_syntax_reference.md @@ -0,0 +1,503 @@ +# Bosonic OpenQASM Syntax Reference + +This guide describes the current user-facing syntax for qubit and +bosonic/qumode programs in the extended OpenQASM frontend. It is +intended for scientists writing programs and experiments rather than +developers modifying the parser. + +## 1. Basic Program Structure + +A program begins with the OpenQASM version declaration. + +``` qasm +OPENQASM 3.0; +``` + +To use the bosonic gate definitions provided by the project: + +``` qasm +include "cvgates.inc"; +``` + +When running the parser, provide the include directory with `-I`: + +``` bash +./bin/QasmParser -I ../../tests/include ../../tests/src/qumode/example.qasm +``` + +The preprocessor searches the directories supplied with `-I` for +included files. + +------------------------------------------------------------------------ + +## 2. Qubits + +A `qubit` represents a two-level quantum system. + +### Single qubit + +``` qasm +qubit qb; +``` + +### Qubit register + +``` qasm +qubit[3] qb; +``` + +This declares three addressable qubits: + +``` qasm +qb[0] +qb[1] +qb[2] +``` + +### Applying gates to qubits + +Standard qubit gates use normal OpenQASM gate syntax: + +``` qasm +qubit qb; + +x qb; +z qb; +h qb; +``` + +For a qubit register, an individual qubit can be selected by index: + +``` qasm +qubit[3] qb; + +x qb[0]; +z qb[1]; +h qb[2]; +``` + +Two-qubit gates can operate on selected qubits: + +``` qasm +qubit[2] qb; + +cx qb[0], qb[1]; +``` + +Qubit indices select individual qubits in a register. + +------------------------------------------------------------------------ + +## 3. Qumodes + +A `qumode` represents a bosonic mode. + +### Single qumode + +``` qasm +qumode qm; +``` + +### Qumode register + +``` qasm +qumode[3] qm; +``` + +This declares three addressable qumodes: + +``` qasm +qm[0] +qm[1] +qm[2] +``` + +A qumode index selects a **mode**, not a Fock level. + +For example: + +``` qasm +disp(0.5) qm[1]; +``` + +means "apply the displacement gate to the second qumode." + +It does **not** mean "apply displacement to Fock level 1." + +------------------------------------------------------------------------ + +## 4. Displacement Gate --- `disp` + +`disp` applies a displacement operation to a qumode. + +### Syntax + +``` qasm +disp(alpha) qm; +``` + +or, for a specific mode in a register: + +``` qasm +disp(alpha) qm[index]; +``` + +`alpha` may be complex. + +### Examples + +``` qasm +qumode qm; + +disp(0.5) qm; +``` + +``` qasm +qumode[2] qm; + +disp(0.3 + 0.5 im) qm[0]; +``` + +The target of `disp` must be a qumode. + +------------------------------------------------------------------------ + +## 5. SNAP Gate --- `snap` + +The SNAP gate applies independently specified phases to Fock levels of a +qumode. + +The current gate definition is parameterized by the number of supplied +phase angles: + +``` qasm +gate snap[uint N](array[angle, N] thetas) qumode qm { + for i in [0:N] { + ctrl[i] @ gphase(thetas[i]) qm; + } +} +``` + +### Syntax + +``` qasm +snap[N]([theta0, theta1, ..., thetaN-1]) qm; +``` + +### Example + +``` qasm +qumode qm; + +snap[3]([pi/2, 0, pi/3]) qm; +``` + +For a qumode register: + +``` qasm +qumode[2] qm; + +snap[3]([pi/2, 0, pi/3]) qm[1]; +``` + +Here: + +- `qm[1]` selects **which qumode** receives the SNAP gate. +- `[pi/2, 0, pi/3]` supplies the phase angles associated with the SNAP + operation's Fock-level controls. +- `3` specifies the size of the angle array. + +Do not use the qumode index to represent a Fock level. + +------------------------------------------------------------------------ + +## 6. Unitary Type + +A `unitary` represents a user-defined unitary operation. + +### Declaration + +``` qasm +unitary u; +``` + +### Declaration with matrix initialization + +``` qasm +unitary v = {{1, 0}, {0, 1}}; +``` + +### Applying a unitary to a qubit + +``` qasm +qubit qb; +unitary u; + +u qb; +``` + +A register element can also be selected: + +``` qasm +qubit[2] qb; +unitary u; + +u qb[0]; +``` + +### Applying a unitary to a qumode + +``` qasm +qumode qm; +unitary u; + +u qm; +``` + +or: + +``` qasm +qumode[2] qm; +unitary u; + +u qm[1]; +``` + +The extended frontend supports unitary operands for both qubits and +qumodes. + +------------------------------------------------------------------------ + +## 7. Bumper States + +Bumper states are associated with a `unitary` and are used when +synthesizing the unitary in a larger bosonic Hilbert space. + +Bumper information is specified using attributes on the unitary. + +### Set a bumper value + +``` qasm +u.bumper = 4; +``` + +### Add another bumper value + +``` qasm +u.bumper += 5; +``` + +For example: + +``` qasm +unitary u; + +u.bumper = 4; +u.bumper += 5; +``` + +### Reset the bumper specification + +A new assignment replaces the previous bumper specification: + +``` qasm +u.bumper = 2; +``` + +### Set a maximum number of bumper states + +``` qasm +u.bumper_max = 3; +``` + +### Example + +``` qasm +unitary u; + +u.bumper = 4; +u.bumper += 5; +u.bumper_max = 3; +``` + +The available syntax is: + +``` qasm +u.bumper = value; +u.bumper += value; +u.bumper_max = value; +``` + +If no bumper attribute is supplied, bumper-state selection is left to +the later compilation/synthesis stage. + +------------------------------------------------------------------------ + +## 8. Qubit vs. Qumode Operations + +Qubits and qumodes are different operand types. Operations should be +applied to the type they are defined to accept. + + Operation Qubit Qumode + --------------- ------- -------- + `x` Yes No + `z` Yes No + `h` Yes No + `cx` / `cnot` Yes No + `disp` No Yes + `snap` No Yes + `unitary` Yes Yes + +Examples: + +``` qasm +qubit qb; +qumode qm; +unitary u; + +x qb; +disp(0.5) qm; +snap[3]([pi/2, 0, pi/3]) qm; + +u qb; +u qm; +``` + +------------------------------------------------------------------------ + +## 9. Register Indexing + +Qubit and qumode registers use similar indexing syntax, but the indices +mean different things. + +### Qubit register + +``` qasm +qubit[3] qb; +``` + +Then: + +``` qasm +qb[0] +qb[1] +qb[2] +``` + +select individual qubits. + +### Qumode register + +``` qasm +qumode[3] qm; +``` + +Then: + +``` qasm +qm[0] +qm[1] +qm[2] +``` + +select individual bosonic modes. + +A qumode index does **not** select a Fock level. + +For example: + +``` qasm +snap[3]([pi/2, 0, pi/3]) qm[1]; +``` + +selects `qm[1]` as the target mode. The SNAP parameters determine the +Fock-level-dependent phases. + +------------------------------------------------------------------------ + +## 10. Complete Example + +``` qasm +OPENQASM 3.0; + +include "cvgates.inc"; + +qubit[2] qb; +qumode[2] qm; + +unitary u = {{1, 0}, {0, 1}}; + +u.bumper = 4; +u.bumper += 5; + +x qb[0]; +z qb[1]; + +disp(0.3 + 0.5 im) qm[0]; + +snap[3]([pi/2, 0, pi/3]) qm[1]; + +u qb[0]; +u qm[1]; +``` + +Run the program with the include directory supplied to the parser: + +``` bash +./bin/QasmParser -I ../../tests/include ../../tests/src/qumode/example.qasm +``` + +------------------------------------------------------------------------ + +## 11. Quick Reference + +``` qasm +// Qubit +qubit qb; +qubit[3] qb; + +// Qubit register indexing +qb[0]; + +// Standard qubit gates +x qb; +z qb; +h qb; +cx qb[0], qb[1]; + +// Qumode +qumode qm; +qumode[3] qm; + +// Qumode register indexing +qm[0]; + +// Displacement +disp(0.5) qm; +disp(0.3 + 0.5 im) qm[0]; + +// SNAP +snap[3]([pi/2, 0, pi/3]) qm; +snap[3]([pi/2, 0, pi/3]) qm[1]; + +// Unitary declaration +unitary u; +unitary v = {{1, 0}, {0, 1}}; + +// Unitary application +u qb; +u qm; + +// Bumper attributes +u.bumper = 4; +u.bumper += 5; +u.bumper = 2; +u.bumper_max = 3; +``` + +## Notes + +This document describes the current user-facing syntax of the extended +OpenQASM frontend. Later compiler stages may impose additional semantic +or hardware-specific restrictions on unitary synthesis, bumper-state +allocation, and physical gate execution. diff --git a/syntax-changes.md b/syntax-changes.md new file mode 100644 index 0000000..79fe86e --- /dev/null +++ b/syntax-changes.md @@ -0,0 +1,171 @@ +This issue documents the syntax changes from the OPENQASM 3.0 specification and +the reasons. + +# (WIP) File Header +OPENQASM files always start with a `OPENQASM` header: +```bison +// Original +// Example: `OPENQASM 3.0;` +version: OPENQASM VersionSpecifier SEMICOLON; +``` +We define our own header to differentiate our input language from OPENQASM. +The word `SEQCQASM` is kinda a placeholder---we can discuss what it should be. +```bison +// Updated +// Example: `SEQCQASM 3.0;` +SEQCQASM: "SEQCQASM"; +version: SEQCQASM VersionSpecifier SEMICOLON; +``` + +# Quantum Resource Declaration +We'd like to support `qumode` as a distinct resource type alongside `qubit`. +For example: +```qasm +qubit qb; +qubit[5] qbs; +qumode qm; +qumode[7] qms; + +// Element selection mirrors qubits: +disp(0.3 + 0.5 im) qms[0]; +snap([pi/2, 0, 0.3]) qms[1]; +ecd(0.5) qb[0], qms[0]; +``` + +To support this, we added `qumode` as a token: +```bison +// lib/Parser/QasmParser.y +%token TOK_QUMODE +``` +We extended the declaration statement grammar as follows: +```bison +// lib/Parser/QasmParser.y +Decl + : ... + | TOK_QUMODE Identifier ';' { + $$ = ASTProductionFactory::Instance().ProductionRule_10000(GET_TOKEN(2), $2); + } + | TOK_QUMODE '[' Integer ']' Identifier ';' { + $$ = ASTProductionFactory::Instance().ProductionRule_10001(GET_TOKEN(5), $5, $3); + } + | TOK_QUMODE '[' Identifier ']' Identifier ';' { + $$ = ASTProductionFactory::Instance().ProductionRule_10002(GET_TOKEN(5), $5, $3); + } +``` + +# Gate Calls +We need to minimally support the following new gates: +```qasm +qubit qb; qumode qm; + +// displacement gate +disp(alpha) qm; +// SNAP gate +snap([theta0,...,thetak]) qm; +// ECD gate +ecd(alpha) qb, qm; +``` +This necessitates the following changes: + +## 1. Passing array as gate parameters +The SNAP gate can take an arbitrary number of parameters. To make this explicit, +we require that these parameters be passed in as an array: +```qasm +snap([theta0,...,thetak]) qm; +``` +This is supported by the following addition to the grammar: +```bison +ArgList + : ... + | '(' '[' ExprList ']' ')' { + $$ = ASTArgumentNodeBuilder::Instance().NewList(); + ASTAngleArrayNode *AAN = + ASTProductionFactory::Instance().ProductionRule_10010($3); + $$->Append(AAN); + } +``` +Currently, we only allow gates to either take a fixed number of parameters or +an array of parameters. + +## 2. Passing qumodes as gate operands +The gate call syntax supports `qumode` operands as well as `qubit` +operands (and mixed operands, e.g. ECD). Currently, no type checking is done, +so both `ecd(alpha) qb, qm` and `ecd(alpha) qm, qb` are allowed. However, +only `ecd(alpha) qb, qm` is considered valid syntax. +Typed operand checking requires revising the gate definition +syntax (also see [Gate Declarations](#gate-declarations-low-priority)). + +## 3. Passing complex numbers as gate parameters +The displacement gate and ECD gate can take complex numbers as parameters: +```qasm +disp(0.3+0.5im) qm; +ecd(0.5-0.3im) qb, qm; + +disp(0.3) qm; // promoted to complex 0.3+0im for builtin disp +ecd(-0.5im) qb, qm; +``` +Complex literals use OpenQASM's `im` suffix. Gate calls store complex args in +`ComplexParams` (parallel to angle `Params` / `ArrayParams`). + +## 4. Builtin CV gates +`disp` is a builtin gate (`TOK_DISP` / `ASTTypeDispGate`): +- exactly one classical parameter, always materialized as complex + (real scalars are promoted to `real+0im`) +- last quantum operand is the target and must be a `qumode` + (a bare qubit target is rejected) +- leading operands are control qubits and are only legal under + `ctrl`/`negctrl`, e.g. `ctrl @ disp(alpha) qb, qm` + (bare `disp(alpha) qb, qm` is rejected) + +SNAP remains an opaque stub in `cvgates.inc` until it becomes a builtin +or gain typed gate-declaration syntax. + + +# (WIP) Unitary Declarations + +```qasm +unitary u = [ + [(1+i)/2, (1-i)/2, 0], + [(1-i)/2, (1+i)/2, 0], + [0, 0, 1], +]; + +qumode qm; +// unitary can be applied as a gate +u qm; +``` + + +# (WIP) Fields (for bumper states and etc.) + +Sometimes we want to attach additional information to a variable. For example, +suppose we want to attach the number of bumper states that is used when +decomposing the unitary into a sequence of gates: +```qasm +u.bumper = 4; +``` + + +# Gate Declarations (Low-priority) + +The addition of qumode gates may necessitate the parameters and operands to be +typed. gate declarations. For example, may be something like the following: +```qasm +gate snap[uint N](array[phases, N] thetas) qumode qm { + for i in [0:N] { + ctrl[i] @ gphase(thetas[i]) qm; // controls the i-th Fock level + } +} + +gate ecd(complex[float] alpha) qubit ctrl, qumode target { + negctrl @ disp(-alpha/2) ctrl, target; + ctrl @ disp(alpha/2) ctrl, target; +} +``` +New components: +- types for parameters, +- types for gate operands, +- `ctrl` modifier for qumodes + +Backward compatibility with OPENQASM 3.0 could be a problem here---we may still +want to be able to `include` OPENQASM 3.0 headers like `stdgates.inc`. diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 3882ac8..903e2f1 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -686,3 +686,93 @@ add_test(NAME t00338 COMMAND ${BASH} -c "${OPENQASM_TEST_PROGRAM} -I${OPENQASM_TEST_INCDIR} ${OPENQASM_TEST_SRCDIR}/test-array-17.qasm > ${CMAKE_BINARY_DIR}/tests/test-array-17.qasm.out 2>&1") add_test(NAME t00339 COMMAND ${BASH} -c "${OPENQASM_TEST_PROGRAM} -I${OPENQASM_TEST_INCDIR} ${OPENQASM_TEST_SRCDIR}/test-array-18.qasm > ${CMAKE_BINARY_DIR}/tests/test-array-18.qasm.out 2>&1") + +# ----------------------------------------------------------------------------- +# Qumode tests +# ----------------------------------------------------------------------------- + +file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/tests/qumode) + +add_test(NAME qumode-t00001 + COMMAND ${BASH} -c "${OPENQASM_TEST_PROGRAM} -I${OPENQASM_TEST_INCDIR} ${OPENQASM_TEST_SRCDIR}/qumode/qumode-decl.qasm > ${CMAKE_BINARY_DIR}/tests/qumode/qumode-decl.qasm.out 2>&1") + +add_test(NAME qumode-t00002 + COMMAND ${BASH} -c "${OPENQASM_TEST_PROGRAM} -I${OPENQASM_TEST_INCDIR} ${OPENQASM_TEST_SRCDIR}/qumode/snap-array-param.qasm > ${CMAKE_BINARY_DIR}/tests/qumode/snap-array-param.qasm.out 2>&1") + +add_test(NAME qumode-t00003 + COMMAND ${BASH} -c "${OPENQASM_TEST_PROGRAM} -I${OPENQASM_TEST_INCDIR} ${OPENQASM_TEST_SRCDIR}/qumode/ecd-mixed.qasm > ${CMAKE_BINARY_DIR}/tests/qumode/ecd-mixed.qasm.out 2>&1") + +add_test(NAME qumode-t00004 + COMMAND ${BASH} -c "${OPENQASM_TEST_PROGRAM} -I${OPENQASM_TEST_INCDIR} ${OPENQASM_TEST_SRCDIR}/qumode/disp-complex.qasm > ${CMAKE_BINARY_DIR}/tests/qumode/disp-complex.qasm.out 2>&1") + +add_test(NAME qumode-t00005 + COMMAND ${BASH} -c "${OPENQASM_TEST_PROGRAM} -I${OPENQASM_TEST_INCDIR} ${OPENQASM_TEST_SRCDIR}/qumode/disp-qubit-reject.qasm > ${CMAKE_BINARY_DIR}/tests/qumode/disp-qubit-reject.qasm.out 2>&1; test $? -ne 0") + +add_test(NAME qumode-t00006 + COMMAND ${BASH} -c "${OPENQASM_TEST_PROGRAM} -I${OPENQASM_TEST_INCDIR} ${OPENQASM_TEST_SRCDIR}/qumode/disp-ctrl.qasm > ${CMAKE_BINARY_DIR}/tests/qumode/disp-ctrl.qasm.out 2>&1") + +add_test(NAME qumode-t00007 + COMMAND ${BASH} -c "${OPENQASM_TEST_PROGRAM} -I${OPENQASM_TEST_INCDIR} ${OPENQASM_TEST_SRCDIR}/qumode/disp-ctrl-required.qasm > ${CMAKE_BINARY_DIR}/tests/qumode/disp-ctrl-required.qasm.out 2>&1; test $? -ne 0") + +add_test(NAME qumode-t00008 + COMMAND ${BASH} -c "${OPENQASM_TEST_PROGRAM} -I${OPENQASM_TEST_INCDIR} ${OPENQASM_TEST_SRCDIR}/qumode/qumode-index.qasm > ${CMAKE_BINARY_DIR}/tests/qumode/qumode-index.qasm.out 2>&1") + +add_test(NAME qumode-t00009 + COMMAND ${BASH} -c "${OPENQASM_TEST_PROGRAM} -I${OPENQASM_TEST_INCDIR} ${OPENQASM_TEST_SRCDIR}/qumode/ecd-param-reject.qasm > ${CMAKE_BINARY_DIR}/tests/qumode/ecd-param-reject.qasm.out 2>&1; test $? -ne 0") + +add_test(NAME qumode-t00010 + COMMAND ${BASH} -c "${OPENQASM_TEST_PROGRAM} -I${OPENQASM_TEST_INCDIR} ${OPENQASM_TEST_SRCDIR}/qumode/ecd-operand-reject.qasm > ${CMAKE_BINARY_DIR}/tests/qumode/ecd-operand-reject.qasm.out 2>&1; test $? -ne 0") + +add_test(NAME qumode-t00011 + COMMAND ${BASH} -c "${OPENQASM_TEST_PROGRAM} -I${OPENQASM_TEST_INCDIR} ${OPENQASM_TEST_SRCDIR}/qumode/ecd-operand-order-reject.qasm > ${CMAKE_BINARY_DIR}/tests/qumode/ecd-operand-order-reject.qasm.out 2>&1; test $? -ne 0") + +add_test(NAME qumode-t00012 + COMMAND ${BASH} -c "${OPENQASM_TEST_PROGRAM} -I${OPENQASM_TEST_INCDIR} ${OPENQASM_TEST_SRCDIR}/qumode/array-elem-complex-reject.qasm > ${CMAKE_BINARY_DIR}/tests/qumode/array-elem-complex-reject.qasm.out 2>&1; test $? -ne 0") + +add_test(NAME qumode-t00013 + COMMAND ${BASH} -c "${OPENQASM_TEST_PROGRAM} -I${OPENQASM_TEST_INCDIR} ${OPENQASM_TEST_SRCDIR}/qumode/complex-array-param.qasm > ${CMAKE_BINARY_DIR}/tests/qumode/complex-array-param.qasm.out 2>&1") + +add_test(NAME qumode-t00014 + COMMAND ${BASH} -c "${OPENQASM_TEST_PROGRAM} -I${OPENQASM_TEST_INCDIR} ${OPENQASM_TEST_SRCDIR}/qumode/float-array-param.qasm > ${CMAKE_BINARY_DIR}/tests/qumode/float-array-param.qasm.out 2>&1") + +add_test(NAME qumode-t00015 + COMMAND ${BASH} -c "${OPENQASM_TEST_PROGRAM} -I${OPENQASM_TEST_INCDIR} ${OPENQASM_TEST_SRCDIR}/qumode/array-size-mismatch-reject.qasm > ${CMAKE_BINARY_DIR}/tests/qumode/array-size-mismatch-reject.qasm.out 2>&1; test $? -ne 0") + +add_test(NAME qumode-t00016 + COMMAND ${BASH} -c "${OPENQASM_TEST_PROGRAM} -I${OPENQASM_TEST_INCDIR} ${OPENQASM_TEST_SRCDIR}/qumode/angle-scalar-param.qasm > ${CMAKE_BINARY_DIR}/tests/qumode/angle-scalar-param.qasm.out 2>&1") + +add_test(NAME qumode-t00017 + COMMAND ${BASH} -c "${OPENQASM_TEST_PROGRAM} -I${OPENQASM_TEST_INCDIR} ${OPENQASM_TEST_SRCDIR}/qumode/angle-array-param.qasm > ${CMAKE_BINARY_DIR}/tests/qumode/angle-array-param.qasm.out 2>&1") + +add_test(NAME qumode-t00018 + COMMAND ${BASH} -c "${OPENQASM_TEST_PROGRAM} -I${OPENQASM_TEST_INCDIR} ${OPENQASM_TEST_SRCDIR}/qumode/multi-angle-array-param.qasm > ${CMAKE_BINARY_DIR}/tests/qumode/multi-angle-array-param.qasm.out 2>&1") + +add_test(NAME qumode-t00019 + COMMAND ${BASH} -c "${OPENQASM_TEST_PROGRAM} -I${OPENQASM_TEST_INCDIR} ${OPENQASM_TEST_SRCDIR}/qumode/array-size-mismatch-param1-reject.qasm > ${CMAKE_BINARY_DIR}/tests/qumode/array-size-mismatch-param1-reject.qasm.out 2>&1; test $? -ne 0") + +add_test(NAME qumode-t00020 + COMMAND ${BASH} -c "${OPENQASM_TEST_PROGRAM} -I${OPENQASM_TEST_INCDIR} ${OPENQASM_TEST_SRCDIR}/qumode/gate-template-array-param.qasm > ${CMAKE_BINARY_DIR}/tests/qumode/gate-template-array-param.qasm.out 2>&1") + +add_test(NAME qumode-t00021 + COMMAND ${BASH} -c "${OPENQASM_TEST_PROGRAM} -I${OPENQASM_TEST_INCDIR} ${OPENQASM_TEST_SRCDIR}/qumode/gate-template-size-mismatch-reject.qasm > ${CMAKE_BINARY_DIR}/tests/qumode/gate-template-size-mismatch-reject.qasm.out 2>&1; test $? -ne 0") + +add_test(NAME qumode-t00022 + COMMAND ${BASH} -c "${OPENQASM_TEST_PROGRAM} -I${OPENQASM_TEST_INCDIR} ${OPENQASM_TEST_SRCDIR}/qumode/gate-template-infer-fail-reject.qasm > ${CMAKE_BINARY_DIR}/tests/qumode/gate-template-infer-fail-reject.qasm.out 2>&1; test $? -ne 0") + +add_test(NAME qumode-t00023 + COMMAND ${BASH} -c "${OPENQASM_TEST_PROGRAM} -I${OPENQASM_TEST_INCDIR} ${OPENQASM_TEST_SRCDIR}/qumode/gate-template-conflict-reject.qasm > ${CMAKE_BINARY_DIR}/tests/qumode/gate-template-conflict-reject.qasm.out 2>&1; test $? -ne 0") + +add_test(NAME qumode-t00024 + COMMAND ${BASH} -c "${OPENQASM_TEST_PROGRAM} -I${OPENQASM_TEST_INCDIR} ${OPENQASM_TEST_SRCDIR}/qumode/gate-template-unused-reject.qasm > ${CMAKE_BINARY_DIR}/tests/qumode/gate-template-unused-reject.qasm.out 2>&1; test $? -ne 0") + +add_test(NAME qumode-t00025 + COMMAND ${BASH} -c "${OPENQASM_TEST_PROGRAM} -I${OPENQASM_TEST_INCDIR} ${OPENQASM_TEST_SRCDIR}/qumode/fock-ctrl-literal.qasm > ${CMAKE_BINARY_DIR}/tests/qumode/fock-ctrl-literal.qasm.out 2>&1") + +add_test(NAME qumode-t00026 + COMMAND ${BASH} -c "${OPENQASM_TEST_PROGRAM} -I${OPENQASM_TEST_INCDIR} ${OPENQASM_TEST_SRCDIR}/qumode/fock-ctrl-template.qasm > ${CMAKE_BINARY_DIR}/tests/qumode/fock-ctrl-template.qasm.out 2>&1") + +add_test(NAME qumode-t00027 + COMMAND ${BASH} -c "${OPENQASM_TEST_PROGRAM} -I${OPENQASM_TEST_INCDIR} ${OPENQASM_TEST_SRCDIR}/qumode/fock-ctrl-template-expr.qasm > ${CMAKE_BINARY_DIR}/tests/qumode/fock-ctrl-template-expr.qasm.out 2>&1") + +add_test(NAME qumode-t00028 + COMMAND ${BASH} -c "${OPENQASM_TEST_PROGRAM} -I${OPENQASM_TEST_INCDIR} ${OPENQASM_TEST_SRCDIR}/qumode/gate-for-fock.qasm > ${CMAKE_BINARY_DIR}/tests/qumode/gate-for-fock.qasm.out 2>&1") diff --git a/tests/include/cvgates.inc b/tests/include/cvgates.inc new file mode 100644 index 0000000..ae392fa --- /dev/null +++ b/tests/include/cvgates.inc @@ -0,0 +1,14 @@ +// CV / qumode gate definitions. +// disp is a builtin gate with the following signature: +// gate disp(complex[float[64]] alpha) qumode qm; + +gate snap[uint N](array[angle, N] thetas) qumode qm { + for i in [0:N] { + ctrl[i] @ gphase(thetas[i]) qm; + } +} + +gate ecd(complex[float[64]] alpha) qubit qb, qumode qm { + negctrl @ disp(-alpha/2) qb, qm; + ctrl @ disp(alpha/2) qb, qm; +} diff --git a/tests/src/qumode/angle-array-param.qasm b/tests/src/qumode/angle-array-param.qasm new file mode 100644 index 0000000..040d98e --- /dev/null +++ b/tests/src/qumode/angle-array-param.qasm @@ -0,0 +1,21 @@ +OPENQASM 3.0; + +// Positive: array[angle, N] formals support body indexing (like float arrays). +gate rz3a(array[angle, 3] thetas) qubit q { + ctrl @ gphase(thetas[0]) q; + ctrl @ gphase(thetas[1]) q; + ctrl @ gphase(thetas[2]) q; +} + +// Scalar angle before array formal; second gate reuses thetas[i] ASTM keys. +gate rz3b(angle alpha, array[angle, 3] thetas) qubit q { + ctrl @ gphase(alpha) q; + ctrl @ gphase(thetas[0]) q; + ctrl @ gphase(thetas[1]) q; + ctrl @ gphase(thetas[2]) q; +} + +qubit[3] q; + +rz3a([pi/2, 0, 0.3]) q[0]; +rz3b(pi/4, [pi/2, 0, 0.3]) q[0]; diff --git a/tests/src/qumode/angle-scalar-param.qasm b/tests/src/qumode/angle-scalar-param.qasm new file mode 100644 index 0000000..62b399a --- /dev/null +++ b/tests/src/qumode/angle-scalar-param.qasm @@ -0,0 +1,18 @@ +OPENQASM 3.0; + +// Explicit `angle` is a valid fully-typed classical formal (alongside arrays). +gate foo(array[float[64], 3] thetas, angle alpha) qubit q { + ctrl @ gphase(thetas[0]) q; + ctrl @ gphase(thetas[1]) q; + ctrl @ gphase(thetas[2]) q; + ctrl @ gphase(alpha) q; +} + +gate bar(angle alpha) qubit q { + ctrl @ gphase(alpha) q; +} + +qubit q; + +bar(pi/4) q; +foo([pi/2, 0, 0.3], pi/4) q; diff --git a/tests/src/qumode/array-elem-complex-reject.qasm b/tests/src/qumode/array-elem-complex-reject.qasm new file mode 100644 index 0000000..a532843 --- /dev/null +++ b/tests/src/qumode/array-elem-complex-reject.qasm @@ -0,0 +1,10 @@ +OPENQASM 3.0; + +gate g(array[float[64], 3] thetas) qubit q { + ctrl @ gphase(thetas[0]) q; +} + +qubit q; + +// Negative: float/angle array elements must be real, not complex. +g([pi/2, 0, 0.3 + 0.5 im]) q; diff --git a/tests/src/qumode/array-size-mismatch-param1-reject.qasm b/tests/src/qumode/array-size-mismatch-param1-reject.qasm new file mode 100644 index 0000000..ebf1949 --- /dev/null +++ b/tests/src/qumode/array-size-mismatch-param1-reject.qasm @@ -0,0 +1,11 @@ +OPENQASM 3.0; + +gate baz(array[angle, 3] alphas, array[angle, 2] thetas) qubit q { + ctrl @ gphase(alphas[0]) q; + ctrl @ gphase(thetas[0]) q; +} + +qubit q; + +// Negative: second formal expects size 2, literal has size 3. +baz([pi/2, 0, 0.3], [pi/4, 0.7, 0.2]) q; diff --git a/tests/src/qumode/array-size-mismatch-reject.qasm b/tests/src/qumode/array-size-mismatch-reject.qasm new file mode 100644 index 0000000..375f33a --- /dev/null +++ b/tests/src/qumode/array-size-mismatch-reject.qasm @@ -0,0 +1,12 @@ +OPENQASM 3.0; + +gate rz3(array[float[64], 3] thetas) qubit q { + ctrl @ gphase(thetas[0]) q; + ctrl @ gphase(thetas[1]) q; + ctrl @ gphase(thetas[2]) q; +} + +qubit q; + +// Negative: formal size 3, literal size 2. +rz3([pi/2, 0]) q; diff --git a/tests/src/qumode/complex-array-param.qasm b/tests/src/qumode/complex-array-param.qasm new file mode 100644 index 0000000..f9ce165 --- /dev/null +++ b/tests/src/qumode/complex-array-param.qasm @@ -0,0 +1,13 @@ +OPENQASM 3.0; + +include "cvgates.inc"; + +gate disp3(array[complex[float[64]], 3] alphas) qumode a, qumode b, qumode c { + disp(alphas[0]) a; + disp(alphas[1]) b; + disp(alphas[2]) c; +} + +qumode[3] qm; + +disp3([0.3 + 0.5 im, 0.2 + 0.4 im, 0.1 + 0.3 im]) qm[0], qm[1], qm[2]; diff --git a/tests/src/qumode/disp-complex.qasm b/tests/src/qumode/disp-complex.qasm new file mode 100644 index 0000000..1da242e --- /dev/null +++ b/tests/src/qumode/disp-complex.qasm @@ -0,0 +1,11 @@ +OPENQASM 3.0; + +qumode qm; +qubit qb; + +disp(3+4im) qm; +disp(0.3 + 0.5 im) qm; +disp(0.3) qm; + +complex[float[64]] c = 0.3 + 0.5 im; +disp(c) qm; diff --git a/tests/src/qumode/disp-ctrl-required.qasm b/tests/src/qumode/disp-ctrl-required.qasm new file mode 100644 index 0000000..5b03a50 --- /dev/null +++ b/tests/src/qumode/disp-ctrl-required.qasm @@ -0,0 +1,7 @@ +OPENQASM 3.0; + +qubit qb; +qumode qm; + +// Negative: controlled operand list requires ctrl/negctrl. +disp(0.5 + 0.3im) qb, qm; diff --git a/tests/src/qumode/disp-ctrl.qasm b/tests/src/qumode/disp-ctrl.qasm new file mode 100644 index 0000000..9df0252 --- /dev/null +++ b/tests/src/qumode/disp-ctrl.qasm @@ -0,0 +1,9 @@ +OPENQASM 3.0; + +qubit qb; +qubit q0; +qubit q1; +qumode qm; + +ctrl @ disp(0.5 + 0.3im) qb, qm; +ctrl(2) @ disp(0.3) q0, q1, qm; diff --git a/tests/src/qumode/disp-qubit-reject.qasm b/tests/src/qumode/disp-qubit-reject.qasm new file mode 100644 index 0000000..d800e72 --- /dev/null +++ b/tests/src/qumode/disp-qubit-reject.qasm @@ -0,0 +1,7 @@ +OPENQASM 3.0; + +qubit qb; +qumode qm; + +// Negative: qubit operand must be rejected. +disp(0.3) qb; diff --git a/tests/src/qumode/ecd-mixed.qasm b/tests/src/qumode/ecd-mixed.qasm new file mode 100644 index 0000000..94c91fb --- /dev/null +++ b/tests/src/qumode/ecd-mixed.qasm @@ -0,0 +1,9 @@ +OPENQASM 3.0; + +include "cvgates.inc"; + +qubit qb; +qumode qm; + +ecd(0.5) qb, qm; +snap([pi/2, 0, pi/3]) qm; diff --git a/tests/src/qumode/ecd-operand-order-reject.qasm b/tests/src/qumode/ecd-operand-order-reject.qasm new file mode 100644 index 0000000..1bfd0af --- /dev/null +++ b/tests/src/qumode/ecd-operand-order-reject.qasm @@ -0,0 +1,9 @@ +OPENQASM 3.0; + +include "cvgates.inc"; + +qubit[2] qb; +qumode[2] qm; + +// Negative: operand order must match (qubit, qumode). +ecd(0.3 + 0.5 im) qm[0], qb[0]; diff --git a/tests/src/qumode/ecd-operand-reject.qasm b/tests/src/qumode/ecd-operand-reject.qasm new file mode 100644 index 0000000..164185e --- /dev/null +++ b/tests/src/qumode/ecd-operand-reject.qasm @@ -0,0 +1,9 @@ +OPENQASM 3.0; + +include "cvgates.inc"; + +qubit[2] qb; +qumode[2] qm; + +// Negative: first operand must be qubit (got qumode). +ecd(0.3 + 0.5 im) qm[0], qm[1]; diff --git a/tests/src/qumode/ecd-param-reject.qasm b/tests/src/qumode/ecd-param-reject.qasm new file mode 100644 index 0000000..4ab2ce6 --- /dev/null +++ b/tests/src/qumode/ecd-param-reject.qasm @@ -0,0 +1,9 @@ +OPENQASM 3.0; + +include "cvgates.inc"; + +qubit[2] qb; +qumode[2] qm; + +// Negative: classical arg must be complex-compatible, not an angle array. +ecd([pi/2, 0, 0.3]) qb[0], qm[0]; diff --git a/tests/src/qumode/float-array-param.qasm b/tests/src/qumode/float-array-param.qasm new file mode 100644 index 0000000..5a20282 --- /dev/null +++ b/tests/src/qumode/float-array-param.qasm @@ -0,0 +1,11 @@ +OPENQASM 3.0; + +gate rz3(array[float[64], 3] thetas) qubit q { + ctrl @ gphase(thetas[0]) q; + ctrl @ gphase(thetas[1]) q; + ctrl @ gphase(thetas[2]) q; +} + +qubit[3] q; + +rz3([pi/2, 0, 0.3]) q[0]; diff --git a/tests/src/qumode/fock-ctrl-literal.qasm b/tests/src/qumode/fock-ctrl-literal.qasm new file mode 100644 index 0000000..2d608da --- /dev/null +++ b/tests/src/qumode/fock-ctrl-literal.qasm @@ -0,0 +1,8 @@ +OPENQASM 3.0; + +gate fock_phase(angle a) qumode qm { + ctrl[3] @ gphase(a) qm; +} + +qumode qm; +fock_phase(pi/2) qm; diff --git a/tests/src/qumode/fock-ctrl-template-expr.qasm b/tests/src/qumode/fock-ctrl-template-expr.qasm new file mode 100644 index 0000000..a462ecb --- /dev/null +++ b/tests/src/qumode/fock-ctrl-template-expr.qasm @@ -0,0 +1,10 @@ +OPENQASM 3.0; + +// Fock level may be an expression (e.g. N-1), not only a bare id/literal. +gate foo[uint N](array[float[64], N] thetas) qumode qm { + ctrl[N-1] @ gphase(pi/2) qm; + ctrl[(N-1)*2/3] @ gphase(pi/4) qm; +} + +qumode qm; +foo[3]([0.1, 0.2, 0.3]) qm; diff --git a/tests/src/qumode/fock-ctrl-template.qasm b/tests/src/qumode/fock-ctrl-template.qasm new file mode 100644 index 0000000..bb68dd5 --- /dev/null +++ b/tests/src/qumode/fock-ctrl-template.qasm @@ -0,0 +1,9 @@ +OPENQASM 3.0; + +// Template param N visible in body as Fock level (literal/identifier only). +gate foo[uint N](array[float[64], N] thetas) qumode qm { + ctrl[N] @ gphase(pi/2) qm; +} + +qumode qm; +foo[3]([0.1, 0.2, 0.3]) qm; diff --git a/tests/src/qumode/gate-for-fock.qasm b/tests/src/qumode/gate-for-fock.qasm new file mode 100644 index 0000000..7966903 --- /dev/null +++ b/tests/src/qumode/gate-for-fock.qasm @@ -0,0 +1,13 @@ +OPENQASM 3.0; + +include "cvgates.inc"; + +// Gate-body for with Fock ctrl and template range end. +gate snap_body[uint N](array[float[64], N] thetas) qumode qm { + for i in [0:N] { + ctrl[i] @ gphase(thetas[i]) qm; + } +} + +qumode qm; +snap_body[3]([0.1, 0.2, 0.3]) qm; diff --git a/tests/src/qumode/gate-template-array-param.qasm b/tests/src/qumode/gate-template-array-param.qasm new file mode 100644 index 0000000..21e16dd --- /dev/null +++ b/tests/src/qumode/gate-template-array-param.qasm @@ -0,0 +1,9 @@ +OPENQASM 3.0; + +// Template uint N as array length; call-site inference from literal arity. +gate foo[uint N](array[float[64], N] thetas) qubit q { +} + +qubit q; +foo([pi/2, 0, 0.3]) q; +foo[3]([pi/2, 0, 0.3]) q; diff --git a/tests/src/qumode/gate-template-conflict-reject.qasm b/tests/src/qumode/gate-template-conflict-reject.qasm new file mode 100644 index 0000000..c4e8038 --- /dev/null +++ b/tests/src/qumode/gate-template-conflict-reject.qasm @@ -0,0 +1,8 @@ +OPENQASM 3.0; + +// Same template N on two array formals; conflicting literal arities. +gate foo[uint N](array[angle, N] alphas, array[angle, N] betas) qubit q { +} + +qubit q; +foo([pi/2, pi/2, pi/2], [pi/2, pi/2]) q; diff --git a/tests/src/qumode/gate-template-infer-fail-reject.qasm b/tests/src/qumode/gate-template-infer-fail-reject.qasm new file mode 100644 index 0000000..f3de1d6 --- /dev/null +++ b/tests/src/qumode/gate-template-infer-fail-reject.qasm @@ -0,0 +1,10 @@ +OPENQASM 3.0; + +// Named array is declared with size 3 (enough to infer N) but never assigned. +// Expect: "Variable 'a' used before assigned." +gate foo[uint N](array[float[64], N] thetas) qubit q { +} + +array[float[64], 3] a; +qubit q; +foo(a) q; diff --git a/tests/src/qumode/gate-template-size-mismatch-reject.qasm b/tests/src/qumode/gate-template-size-mismatch-reject.qasm new file mode 100644 index 0000000..35dc2f6 --- /dev/null +++ b/tests/src/qumode/gate-template-size-mismatch-reject.qasm @@ -0,0 +1,7 @@ +OPENQASM 3.0; + +gate foo[uint N](array[float[64], N] thetas) qubit q { +} + +qubit q; +foo[2]([pi/2, 0, 0.3]) q; diff --git a/tests/src/qumode/gate-template-unused-reject.qasm b/tests/src/qumode/gate-template-unused-reject.qasm new file mode 100644 index 0000000..3015471 --- /dev/null +++ b/tests/src/qumode/gate-template-unused-reject.qasm @@ -0,0 +1,8 @@ +OPENQASM 3.0; + +// Template N never appears as an array size — nothing to infer from. +gate foo[uint N](angle alpha) qubit q { +} + +qubit q; +foo(pi/2) q; diff --git a/tests/src/qumode/multi-angle-array-param.qasm b/tests/src/qumode/multi-angle-array-param.qasm new file mode 100644 index 0000000..5ca5dc8 --- /dev/null +++ b/tests/src/qumode/multi-angle-array-param.qasm @@ -0,0 +1,14 @@ +OPENQASM 3.0; + +// Positive: two angle-array formals with different sizes. +gate baz(array[angle, 3] alphas, array[angle, 2] thetas) qubit q { + ctrl @ gphase(alphas[0]) q; + ctrl @ gphase(alphas[1]) q; + ctrl @ gphase(alphas[2]) q; + ctrl @ gphase(thetas[0]) q; + ctrl @ gphase(thetas[1]) q; +} + +qubit q; + +baz([pi/2, 0, 0.3], [pi/4, 0.7]) q; diff --git a/tests/src/qumode/qumode-decl.qasm b/tests/src/qumode/qumode-decl.qasm new file mode 100644 index 0000000..1aab963 --- /dev/null +++ b/tests/src/qumode/qumode-decl.qasm @@ -0,0 +1,7 @@ +OPENQASM 3.0; + +qubit q; +qubit[3] qs; + +qumode qm; +qumode[5] qms; diff --git a/tests/src/qumode/qumode-index.qasm b/tests/src/qumode/qumode-index.qasm new file mode 100644 index 0000000..dcdcc28 --- /dev/null +++ b/tests/src/qumode/qumode-index.qasm @@ -0,0 +1,12 @@ +OPENQASM 3.0; + +include "cvgates.inc"; + +qumode[2] qm; + +disp(0.3 + 0.5 im) qm[0]; +snap([pi/2, 0, 0.3]) qm[1]; + +qubit qb; + +ecd(0.3 + 0.5 im) qb[0], qm[0]; diff --git a/tests/src/qumode/snap-array-param.qasm b/tests/src/qumode/snap-array-param.qasm new file mode 100644 index 0000000..3ae9cf8 --- /dev/null +++ b/tests/src/qumode/snap-array-param.qasm @@ -0,0 +1,9 @@ +OPENQASM 3.0; + +include "cvgates.inc"; + +qumode qm; + +snap([pi/2, 0, pi/3]) qm; +snap([pi/2, 0, pi/3, pi/4]) qm; +snap([pi/2]) qm; diff --git a/tests/src/unitary/unitary_bumper.qasm b/tests/src/unitary/unitary_bumper.qasm new file mode 100644 index 0000000..c28745d --- /dev/null +++ b/tests/src/unitary/unitary_bumper.qasm @@ -0,0 +1,6 @@ +OPENQASM 3.0; + +unitary u; + +u.bumper = 4; +u.bumper += 5; \ No newline at end of file diff --git a/tests/src/unitary/unitary_bumperMax.qasm b/tests/src/unitary/unitary_bumperMax.qasm new file mode 100644 index 0000000..3936ef8 --- /dev/null +++ b/tests/src/unitary/unitary_bumperMax.qasm @@ -0,0 +1,10 @@ +OPENQASM 3.0; + +unitary u; +unitary v; + +u.bumper = 4; +u.bumper += 5; +u.bumper = 2; + +v.bumper_max = 3; \ No newline at end of file diff --git a/tests/src/unitary/unitary_bumperMaxError.qasm b/tests/src/unitary/unitary_bumperMaxError.qasm new file mode 100644 index 0000000..e661bae --- /dev/null +++ b/tests/src/unitary/unitary_bumperMaxError.qasm @@ -0,0 +1,19 @@ +OPENQASM 3.0; + +unitary u; + +u.bumper_max += 3; //should throw a syntax error, unexpected TOK_ADD_ASSIGN, expecting '=' + + + + + + + +unitary v; + +v.bumper = 1 +v.bumper += 2 //(must define bumper first) + + +r.bumper_max +=3 //never works \ No newline at end of file diff --git a/tests/src/unitary/unitary_bumper_default.qasm b/tests/src/unitary/unitary_bumper_default.qasm new file mode 100644 index 0000000..700ab7b --- /dev/null +++ b/tests/src/unitary/unitary_bumper_default.qasm @@ -0,0 +1,16 @@ +OPENQASM 3.0; + +unitary automatic; +unitary exact; +unitary capped; + +exact.bumper = 4; +capped.bumper_max = 3; + + +unitary u; + +automatic = [...] //look into the posibility of implementing this + +// how do I assign this as a data type unitary? +// check if u is actually a unitary diff --git a/tests/src/unitary/unitary_creation.qasm b/tests/src/unitary/unitary_creation.qasm new file mode 100644 index 0000000..e7e6c78 --- /dev/null +++ b/tests/src/unitary/unitary_creation.qasm @@ -0,0 +1,11 @@ +OPENQASM 3.0; + +unitary u = { + {1, 0}, + {0, 1}, + {2, 3}, + {3, 2} +}; + + + diff --git a/tests/src/unitary/unitary_declaration.qasm b/tests/src/unitary/unitary_declaration.qasm new file mode 100644 index 0000000..304addd --- /dev/null +++ b/tests/src/unitary/unitary_declaration.qasm @@ -0,0 +1,3 @@ +OPENQASM 3.0; + +unitary u; \ No newline at end of file diff --git a/tests/src/unitary/unitary_gateOperand.qasm b/tests/src/unitary/unitary_gateOperand.qasm new file mode 100644 index 0000000..016e010 --- /dev/null +++ b/tests/src/unitary/unitary_gateOperand.qasm @@ -0,0 +1,5 @@ +OPENQASM 3.0; +unitary u; +qumode q; + +u q; \ No newline at end of file diff --git a/tests/src/unitary/unitary_redeclare.qasm b/tests/src/unitary/unitary_redeclare.qasm new file mode 100644 index 0000000..51e5e36 --- /dev/null +++ b/tests/src/unitary/unitary_redeclare.qasm @@ -0,0 +1,9 @@ +OPENQASM 3.0; +// unitary u; +// unitary u; + +// qumode q; +// qumode q; + +qubit q; +qubit q; \ No newline at end of file diff --git a/uv.lock b/uv.lock new file mode 100644 index 0000000..56dab7e --- /dev/null +++ b/uv.lock @@ -0,0 +1,690 @@ +version = 1 +revision = 3 +requires-python = ">=3.10" + +[[package]] +name = "bottle" +version = "0.12.25" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/fd/04/1c09ab851a52fe6bc063fd0df758504edede5cc741bd2e807bf434a09215/bottle-0.12.25.tar.gz", hash = "sha256:e1a9c94970ae6d710b3fb4526294dfeb86f2cb4a81eff3a4b98dc40fb0e5e021", size = 74231, upload-time = "2023-03-04T15:34:18.083Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/bb/1f/5977ea88c6a3df6199db97d320e5da816d415d1eb75a987a1f6823d5cc9d/bottle-0.12.25-py3-none-any.whl", hash = "sha256:d6f15f9d422670b7c073d63bd8d287b135388da187a0f3e3c19293626ce034ea", size = 90181, upload-time = "2023-03-04T15:34:16.243Z" }, +] + +[[package]] +name = "certifi" +version = "2026.6.17" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/c9/c7/424b75da314c1045981bd9777432fad05a9e0c69daa4ed7e308bbaffe405/certifi-2026.6.17.tar.gz", hash = "sha256:024c88eeec92ca068db80f02b8b07c9cef7b9fe261d1d535abfd5abd6f6af432", size = 134594, upload-time = "2026-06-17T10:31:07.894Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/ef/2f/c5464532e965badff2f4c4c1a3a83f5697f0d7c407ed0cda44aaa99bb451/certifi-2026.6.17-py3-none-any.whl", hash = "sha256:2227dcbaafe0d2f59279d1762ddddc37783ed4354594f194ffc31d20f41fc3db", size = 133289, upload-time = "2026-06-17T10:31:06.348Z" }, +] + +[[package]] +name = "cfgv" +version = "3.5.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/4e/b5/721b8799b04bf9afe054a3899c6cf4e880fcf8563cc71c15610242490a0c/cfgv-3.5.0.tar.gz", hash = "sha256:d5b1034354820651caa73ede66a6294d6e95c1b00acc5e9b098e917404669132", size = 7334, upload-time = "2025-11-19T20:55:51.612Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/db/3c/33bac158f8ab7f89b2e59426d5fe2e4f63f7ed25df84c036890172b412b5/cfgv-3.5.0-py2.py3-none-any.whl", hash = "sha256:a8dc6b26ad22ff227d2634a65cb388215ce6cc96bbcc5cfde7641ae87e8dacc0", size = 7445, upload-time = "2025-11-19T20:55:50.744Z" }, +] + +[[package]] +name = "charset-normalizer" +version = "3.4.7" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/e7/a1/67fe25fac3c7642725500a3f6cfe5821ad557c3abb11c9d20d12c7008d3e/charset_normalizer-3.4.7.tar.gz", hash = "sha256:ae89db9e5f98a11a4bf50407d4363e7b09b31e55bc117b4f7d80aab97ba009e5", size = 144271, upload-time = "2026-04-02T09:28:39.342Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/26/08/0f303cb0b529e456bb116f2d50565a482694fbb94340bf56d44677e7ed03/charset_normalizer-3.4.7-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:cdd68a1fb318e290a2077696b7eb7a21a49163c455979c639bf5a5dcdc46617d", size = 315182, upload-time = "2026-04-02T09:25:40.673Z" }, + { url = "https://files.pythonhosted.org/packages/24/47/b192933e94b546f1b1fe4df9cc1f84fcdbf2359f8d1081d46dd029b50207/charset_normalizer-3.4.7-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:e17b8d5d6a8c47c85e68ca8379def1303fd360c3e22093a807cd34a71cd082b8", size = 209329, upload-time = "2026-04-02T09:25:42.354Z" }, + { url = "https://files.pythonhosted.org/packages/c2/b4/01fa81c5ca6141024d89a8fc15968002b71da7f825dd14113207113fabbd/charset_normalizer-3.4.7-cp310-cp310-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:511ef87c8aec0783e08ac18565a16d435372bc1ac25a91e6ac7f5ef2b0bff790", size = 231230, upload-time = "2026-04-02T09:25:44.281Z" }, + { url = "https://files.pythonhosted.org/packages/20/f7/7b991776844dfa058017e600e6e55ff01984a063290ca5622c0b63162f68/charset_normalizer-3.4.7-cp310-cp310-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:007d05ec7321d12a40227aae9e2bc6dca73f3cb21058999a1df9e193555a9dcc", size = 225890, upload-time = "2026-04-02T09:25:45.475Z" }, + { url = "https://files.pythonhosted.org/packages/20/e7/bed0024a0f4ab0c8a9c64d4445f39b30c99bd1acd228291959e3de664247/charset_normalizer-3.4.7-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:cf29836da5119f3c8a8a70667b0ef5fdca3bb12f80fd06487cfa575b3909b393", size = 216930, upload-time = "2026-04-02T09:25:46.58Z" }, + { url = "https://files.pythonhosted.org/packages/e2/ab/b18f0ab31cdd7b3ddb8bb76c4a414aeb8160c9810fdf1bc62f269a539d87/charset_normalizer-3.4.7-cp310-cp310-manylinux_2_31_armv7l.whl", hash = "sha256:12d8baf840cc7889b37c7c770f478adea7adce3dcb3944d02ec87508e2dcf153", size = 202109, upload-time = "2026-04-02T09:25:48.031Z" }, + { url = "https://files.pythonhosted.org/packages/82/e5/7e9440768a06dfb3075936490cb82dbf0ee20a133bf0dd8551fa096914ec/charset_normalizer-3.4.7-cp310-cp310-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:d560742f3c0d62afaccf9f41fe485ed69bd7661a241f86a3ef0f0fb8b1a397af", size = 214684, upload-time = "2026-04-02T09:25:49.245Z" }, + { url = "https://files.pythonhosted.org/packages/71/94/8c61d8da9f062fdf457c80acfa25060ec22bf1d34bbeaca4350f13bcfd07/charset_normalizer-3.4.7-cp310-cp310-musllinux_1_2_aarch64.whl", hash = "sha256:b14b2d9dac08e28bb8046a1a0434b1750eb221c8f5b87a68f4fa11a6f97b5e34", size = 212785, upload-time = "2026-04-02T09:25:50.671Z" }, + { url = "https://files.pythonhosted.org/packages/66/cd/6e9889c648e72c0ab2e5967528bb83508f354d706637bc7097190c874e13/charset_normalizer-3.4.7-cp310-cp310-musllinux_1_2_armv7l.whl", hash = "sha256:bc17a677b21b3502a21f66a8cc64f5bfad4df8a0b8434d661666f8ce90ac3af1", size = 203055, upload-time = "2026-04-02T09:25:51.802Z" }, + { url = "https://files.pythonhosted.org/packages/92/2e/7a951d6a08aefb7eb8e1b54cdfb580b1365afdd9dd484dc4bee9e5d8f258/charset_normalizer-3.4.7-cp310-cp310-musllinux_1_2_ppc64le.whl", hash = "sha256:750e02e074872a3fad7f233b47734166440af3cdea0add3e95163110816d6752", size = 232502, upload-time = "2026-04-02T09:25:53.388Z" }, + { url = "https://files.pythonhosted.org/packages/58/d5/abcf2d83bf8e0a1286df55cd0dc1d49af0da4282aa77e986df343e7de124/charset_normalizer-3.4.7-cp310-cp310-musllinux_1_2_riscv64.whl", hash = "sha256:4e5163c14bffd570ef2affbfdd77bba66383890797df43dc8b4cc7d6f500bf53", size = 214295, upload-time = "2026-04-02T09:25:54.765Z" }, + { url = "https://files.pythonhosted.org/packages/47/3a/7d4cd7ed54be99973a0dc176032cba5cb1f258082c31fa6df35cff46acfc/charset_normalizer-3.4.7-cp310-cp310-musllinux_1_2_s390x.whl", hash = "sha256:6ed74185b2db44f41ef35fd1617c5888e59792da9bbc9190d6c7300617182616", size = 227145, upload-time = "2026-04-02T09:25:55.904Z" }, + { url = "https://files.pythonhosted.org/packages/1d/98/3a45bf8247889cf28262ebd3d0872edff11565b2a1e3064ccb132db3fbb0/charset_normalizer-3.4.7-cp310-cp310-musllinux_1_2_x86_64.whl", hash = "sha256:94e1885b270625a9a828c9793b4d52a64445299baa1fea5a173bf1d3dd9a1a5a", size = 218884, upload-time = "2026-04-02T09:25:57.074Z" }, + { url = "https://files.pythonhosted.org/packages/ad/80/2e8b7f8915ed5c9ef13aa828d82738e33888c485b65ebf744d615040c7ea/charset_normalizer-3.4.7-cp310-cp310-win32.whl", hash = "sha256:6785f414ae0f3c733c437e0f3929197934f526d19dfaa75e18fdb4f94c6fb374", size = 148343, upload-time = "2026-04-02T09:25:58.199Z" }, + { url = "https://files.pythonhosted.org/packages/35/1b/3b8c8c77184af465ee9ad88b5aea46ea6b2e1f7b9dc9502891e37af21e30/charset_normalizer-3.4.7-cp310-cp310-win_amd64.whl", hash = "sha256:6696b7688f54f5af4462118f0bfa7c1621eeb87154f77fa04b9295ce7a8f2943", size = 159174, upload-time = "2026-04-02T09:25:59.322Z" }, + { url = "https://files.pythonhosted.org/packages/be/c1/feb40dca40dbb21e0a908801782d9288c64fc8d8e562c2098e9994c8c21b/charset_normalizer-3.4.7-cp310-cp310-win_arm64.whl", hash = "sha256:66671f93accb62ed07da56613636f3641f1a12c13046ce91ffc923721f23c008", size = 147805, upload-time = "2026-04-02T09:26:00.756Z" }, + { url = "https://files.pythonhosted.org/packages/c2/d7/b5b7020a0565c2e9fa8c09f4b5fa6232feb326b8c20081ccded47ea368fd/charset_normalizer-3.4.7-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:7641bb8895e77f921102f72833904dcd9901df5d6d72a2ab8f31d04b7e51e4e7", size = 309705, upload-time = "2026-04-02T09:26:02.191Z" }, + { url = "https://files.pythonhosted.org/packages/5a/53/58c29116c340e5456724ecd2fff4196d236b98f3da97b404bc5e51ac3493/charset_normalizer-3.4.7-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:202389074300232baeb53ae2569a60901f7efadd4245cf3a3bf0617d60b439d7", size = 206419, upload-time = "2026-04-02T09:26:03.583Z" }, + { url = "https://files.pythonhosted.org/packages/b2/02/e8146dc6591a37a00e5144c63f29fb7c97a734ea8a111190783c0e60ab63/charset_normalizer-3.4.7-cp311-cp311-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:30b8d1d8c52a48c2c5690e152c169b673487a2a58de1ec7393196753063fcd5e", size = 227901, upload-time = "2026-04-02T09:26:04.738Z" }, + { url = "https://files.pythonhosted.org/packages/fb/73/77486c4cd58f1267bf17db420e930c9afa1b3be3fe8c8b8ebbebc9624359/charset_normalizer-3.4.7-cp311-cp311-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:532bc9bf33a68613fd7d65e4b1c71a6a38d7d42604ecf239c77392e9b4e8998c", size = 222742, upload-time = "2026-04-02T09:26:06.36Z" }, + { url = "https://files.pythonhosted.org/packages/a1/fa/f74eb381a7d94ded44739e9d94de18dc5edc9c17fb8c11f0a6890696c0a9/charset_normalizer-3.4.7-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:2fe249cb4651fd12605b7288b24751d8bfd46d35f12a20b1ba33dea122e690df", size = 214061, upload-time = "2026-04-02T09:26:08.347Z" }, + { url = "https://files.pythonhosted.org/packages/dc/92/42bd3cefcf7687253fb86694b45f37b733c97f59af3724f356fa92b8c344/charset_normalizer-3.4.7-cp311-cp311-manylinux_2_31_armv7l.whl", hash = "sha256:65bcd23054beab4d166035cabbc868a09c1a49d1efe458fe8e4361215df40265", size = 199239, upload-time = "2026-04-02T09:26:09.823Z" }, + { url = "https://files.pythonhosted.org/packages/4c/3d/069e7184e2aa3b3cddc700e3dd267413dc259854adc3380421c805c6a17d/charset_normalizer-3.4.7-cp311-cp311-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:08e721811161356f97b4059a9ba7bafb23ea5ee2255402c42881c214e173c6b4", size = 210173, upload-time = "2026-04-02T09:26:10.953Z" }, + { url = "https://files.pythonhosted.org/packages/62/51/9d56feb5f2e7074c46f93e0ebdbe61f0848ee246e2f0d89f8e20b89ebb8f/charset_normalizer-3.4.7-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:e060d01aec0a910bdccb8be71faf34e7799ce36950f8294c8bf612cba65a2c9e", size = 209841, upload-time = "2026-04-02T09:26:12.142Z" }, + { url = "https://files.pythonhosted.org/packages/d2/59/893d8f99cc4c837dda1fe2f1139079703deb9f321aabcb032355de13b6c7/charset_normalizer-3.4.7-cp311-cp311-musllinux_1_2_armv7l.whl", hash = "sha256:38c0109396c4cfc574d502df99742a45c72c08eff0a36158b6f04000043dbf38", size = 200304, upload-time = "2026-04-02T09:26:13.711Z" }, + { url = "https://files.pythonhosted.org/packages/7d/1d/ee6f3be3464247578d1ed5c46de545ccc3d3ff933695395c402c21fa6b77/charset_normalizer-3.4.7-cp311-cp311-musllinux_1_2_ppc64le.whl", hash = "sha256:1c2a768fdd44ee4a9339a9b0b130049139b8ce3c01d2ce09f67f5a68048d477c", size = 229455, upload-time = "2026-04-02T09:26:14.941Z" }, + { url = "https://files.pythonhosted.org/packages/54/bb/8fb0a946296ea96a488928bdce8ef99023998c48e4713af533e9bb98ef07/charset_normalizer-3.4.7-cp311-cp311-musllinux_1_2_riscv64.whl", hash = "sha256:1a87ca9d5df6fe460483d9a5bbf2b18f620cbed41b432e2bddb686228282d10b", size = 210036, upload-time = "2026-04-02T09:26:16.478Z" }, + { url = "https://files.pythonhosted.org/packages/9a/bc/015b2387f913749f82afd4fcba07846d05b6d784dd16123cb66860e0237d/charset_normalizer-3.4.7-cp311-cp311-musllinux_1_2_s390x.whl", hash = "sha256:d635aab80466bc95771bb78d5370e74d36d1fe31467b6b29b8b57b2a3cd7d22c", size = 224739, upload-time = "2026-04-02T09:26:17.751Z" }, + { url = "https://files.pythonhosted.org/packages/17/ab/63133691f56baae417493cba6b7c641571a2130eb7bceba6773367ab9ec5/charset_normalizer-3.4.7-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:ae196f021b5e7c78e918242d217db021ed2a6ace2bc6ae94c0fc596221c7f58d", size = 216277, upload-time = "2026-04-02T09:26:18.981Z" }, + { url = "https://files.pythonhosted.org/packages/06/6d/3be70e827977f20db77c12a97e6a9f973631a45b8d186c084527e53e77a4/charset_normalizer-3.4.7-cp311-cp311-win32.whl", hash = "sha256:adb2597b428735679446b46c8badf467b4ca5f5056aae4d51a19f9570301b1ad", size = 147819, upload-time = "2026-04-02T09:26:20.295Z" }, + { url = "https://files.pythonhosted.org/packages/20/d9/5f67790f06b735d7c7637171bbfd89882ad67201891b7275e51116ed8207/charset_normalizer-3.4.7-cp311-cp311-win_amd64.whl", hash = "sha256:8e385e4267ab76874ae30db04c627faaaf0b509e1ccc11a95b3fc3e83f855c00", size = 159281, upload-time = "2026-04-02T09:26:21.74Z" }, + { url = "https://files.pythonhosted.org/packages/ca/83/6413f36c5a34afead88ce6f66684d943d91f233d76dd083798f9602b75ae/charset_normalizer-3.4.7-cp311-cp311-win_arm64.whl", hash = "sha256:d4a48e5b3c2a489fae013b7589308a40146ee081f6f509e047e0e096084ceca1", size = 147843, upload-time = "2026-04-02T09:26:22.901Z" }, + { url = "https://files.pythonhosted.org/packages/0c/eb/4fc8d0a7110eb5fc9cc161723a34a8a6c200ce3b4fbf681bc86feee22308/charset_normalizer-3.4.7-cp312-cp312-macosx_10_13_universal2.whl", hash = "sha256:eca9705049ad3c7345d574e3510665cb2cf844c2f2dcfe675332677f081cbd46", size = 311328, upload-time = "2026-04-02T09:26:24.331Z" }, + { url = "https://files.pythonhosted.org/packages/f8/e3/0fadc706008ac9d7b9b5be6dc767c05f9d3e5df51744ce4cc9605de7b9f4/charset_normalizer-3.4.7-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:6178f72c5508bfc5fd446a5905e698c6212932f25bcdd4b47a757a50605a90e2", size = 208061, upload-time = "2026-04-02T09:26:25.568Z" }, + { url = "https://files.pythonhosted.org/packages/42/f0/3dd1045c47f4a4604df85ec18ad093912ae1344ac706993aff91d38773a2/charset_normalizer-3.4.7-cp312-cp312-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:e1421b502d83040e6d7fb2fb18dff63957f720da3d77b2fbd3187ceb63755d7b", size = 229031, upload-time = "2026-04-02T09:26:26.865Z" }, + { url = "https://files.pythonhosted.org/packages/dc/67/675a46eb016118a2fbde5a277a5d15f4f69d5f3f5f338e5ee2f8948fcf43/charset_normalizer-3.4.7-cp312-cp312-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:edac0f1ab77644605be2cbba52e6b7f630731fc42b34cb0f634be1a6eface56a", size = 225239, upload-time = "2026-04-02T09:26:28.044Z" }, + { url = "https://files.pythonhosted.org/packages/4b/f8/d0118a2f5f23b02cd166fa385c60f9b0d4f9194f574e2b31cef350ad7223/charset_normalizer-3.4.7-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:5649fd1c7bade02f320a462fdefd0b4bd3ce036065836d4f42e0de958038e116", size = 216589, upload-time = "2026-04-02T09:26:29.239Z" }, + { url = "https://files.pythonhosted.org/packages/b1/f1/6d2b0b261b6c4ceef0fcb0d17a01cc5bc53586c2d4796fa04b5c540bc13d/charset_normalizer-3.4.7-cp312-cp312-manylinux_2_31_armv7l.whl", hash = "sha256:203104ed3e428044fd943bc4bf45fa73c0730391f9621e37fe39ecf477b128cb", size = 202733, upload-time = "2026-04-02T09:26:30.5Z" }, + { url = "https://files.pythonhosted.org/packages/6f/c0/7b1f943f7e87cc3db9626ba17807d042c38645f0a1d4415c7a14afb5591f/charset_normalizer-3.4.7-cp312-cp312-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:298930cec56029e05497a76988377cbd7457ba864beeea92ad7e844fe74cd1f1", size = 212652, upload-time = "2026-04-02T09:26:31.709Z" }, + { url = "https://files.pythonhosted.org/packages/38/dd/5a9ab159fe45c6e72079398f277b7d2b523e7f716acc489726115a910097/charset_normalizer-3.4.7-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:708838739abf24b2ceb208d0e22403dd018faeef86ddac04319a62ae884c4f15", size = 211229, upload-time = "2026-04-02T09:26:33.282Z" }, + { url = "https://files.pythonhosted.org/packages/d5/ff/531a1cad5ca855d1c1a8b69cb71abfd6d85c0291580146fda7c82857caa1/charset_normalizer-3.4.7-cp312-cp312-musllinux_1_2_armv7l.whl", hash = "sha256:0f7eb884681e3938906ed0434f20c63046eacd0111c4ba96f27b76084cd679f5", size = 203552, upload-time = "2026-04-02T09:26:34.845Z" }, + { url = "https://files.pythonhosted.org/packages/c1/4c/a5fb52d528a8ca41f7598cb619409ece30a169fbdf9cdce592e53b46c3a6/charset_normalizer-3.4.7-cp312-cp312-musllinux_1_2_ppc64le.whl", hash = "sha256:4dc1e73c36828f982bfe79fadf5919923f8a6f4df2860804db9a98c48824ce8d", size = 230806, upload-time = "2026-04-02T09:26:36.152Z" }, + { url = "https://files.pythonhosted.org/packages/59/7a/071feed8124111a32b316b33ae4de83d36923039ef8cf48120266844285b/charset_normalizer-3.4.7-cp312-cp312-musllinux_1_2_riscv64.whl", hash = "sha256:aed52fea0513bac0ccde438c188c8a471c4e0f457c2dd20cdbf6ea7a450046c7", size = 212316, upload-time = "2026-04-02T09:26:37.672Z" }, + { url = "https://files.pythonhosted.org/packages/fd/35/f7dba3994312d7ba508e041eaac39a36b120f32d4c8662b8814dab876431/charset_normalizer-3.4.7-cp312-cp312-musllinux_1_2_s390x.whl", hash = "sha256:fea24543955a6a729c45a73fe90e08c743f0b3334bbf3201e6c4bc1b0c7fa464", size = 227274, upload-time = "2026-04-02T09:26:38.93Z" }, + { url = "https://files.pythonhosted.org/packages/8a/2d/a572df5c9204ab7688ec1edc895a73ebded3b023bb07364710b05dd1c9be/charset_normalizer-3.4.7-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:bb6d88045545b26da47aa879dd4a89a71d1dce0f0e549b1abcb31dfe4a8eac49", size = 218468, upload-time = "2026-04-02T09:26:40.17Z" }, + { url = "https://files.pythonhosted.org/packages/86/eb/890922a8b03a568ca2f336c36585a4713c55d4d67bf0f0c78924be6315ca/charset_normalizer-3.4.7-cp312-cp312-win32.whl", hash = "sha256:2257141f39fe65a3fdf38aeccae4b953e5f3b3324f4ff0daf9f15b8518666a2c", size = 148460, upload-time = "2026-04-02T09:26:41.416Z" }, + { url = "https://files.pythonhosted.org/packages/35/d9/0e7dffa06c5ab081f75b1b786f0aefc88365825dfcd0ac544bdb7b2b6853/charset_normalizer-3.4.7-cp312-cp312-win_amd64.whl", hash = "sha256:5ed6ab538499c8644b8a3e18debabcd7ce684f3fa91cf867521a7a0279cab2d6", size = 159330, upload-time = "2026-04-02T09:26:42.554Z" }, + { url = "https://files.pythonhosted.org/packages/9e/5d/481bcc2a7c88ea6b0878c299547843b2521ccbc40980cb406267088bc701/charset_normalizer-3.4.7-cp312-cp312-win_arm64.whl", hash = "sha256:56be790f86bfb2c98fb742ce566dfb4816e5a83384616ab59c49e0604d49c51d", size = 147828, upload-time = "2026-04-02T09:26:44.075Z" }, + { url = "https://files.pythonhosted.org/packages/c1/3b/66777e39d3ae1ddc77ee606be4ec6d8cbd4c801f65e5a1b6f2b11b8346dd/charset_normalizer-3.4.7-cp313-cp313-macosx_10_13_universal2.whl", hash = "sha256:f496c9c3cc02230093d8330875c4c3cdfc3b73612a5fd921c65d39cbcef08063", size = 309627, upload-time = "2026-04-02T09:26:45.198Z" }, + { url = "https://files.pythonhosted.org/packages/2e/4e/b7f84e617b4854ade48a1b7915c8ccfadeba444d2a18c291f696e37f0d3b/charset_normalizer-3.4.7-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:0ea948db76d31190bf08bd371623927ee1339d5f2a0b4b1b4a4439a65298703c", size = 207008, upload-time = "2026-04-02T09:26:46.824Z" }, + { url = "https://files.pythonhosted.org/packages/c4/bb/ec73c0257c9e11b268f018f068f5d00aa0ef8c8b09f7753ebd5f2880e248/charset_normalizer-3.4.7-cp313-cp313-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:a277ab8928b9f299723bc1a2dabb1265911b1a76341f90a510368ca44ad9ab66", size = 228303, upload-time = "2026-04-02T09:26:48.397Z" }, + { url = "https://files.pythonhosted.org/packages/85/fb/32d1f5033484494619f701e719429c69b766bfc4dbc61aa9e9c8c166528b/charset_normalizer-3.4.7-cp313-cp313-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:3bec022aec2c514d9cf199522a802bd007cd588ab17ab2525f20f9c34d067c18", size = 224282, upload-time = "2026-04-02T09:26:49.684Z" }, + { url = "https://files.pythonhosted.org/packages/fa/07/330e3a0dda4c404d6da83b327270906e9654a24f6c546dc886a0eb0ffb23/charset_normalizer-3.4.7-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:e044c39e41b92c845bc815e5ae4230804e8e7bc29e399b0437d64222d92809dd", size = 215595, upload-time = "2026-04-02T09:26:50.915Z" }, + { url = "https://files.pythonhosted.org/packages/e3/7c/fc890655786e423f02556e0216d4b8c6bcb6bdfa890160dc66bf52dee468/charset_normalizer-3.4.7-cp313-cp313-manylinux_2_31_armv7l.whl", hash = "sha256:f495a1652cf3fbab2eb0639776dad966c2fb874d79d87ca07f9d5f059b8bd215", size = 201986, upload-time = "2026-04-02T09:26:52.197Z" }, + { url = "https://files.pythonhosted.org/packages/d8/97/bfb18b3db2aed3b90cf54dc292ad79fdd5ad65c4eae454099475cbeadd0d/charset_normalizer-3.4.7-cp313-cp313-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:e712b419df8ba5e42b226c510472b37bd57b38e897d3eca5e8cfd410a29fa859", size = 211711, upload-time = "2026-04-02T09:26:53.49Z" }, + { url = "https://files.pythonhosted.org/packages/6f/a5/a581c13798546a7fd557c82614a5c65a13df2157e9ad6373166d2a3e645d/charset_normalizer-3.4.7-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:7804338df6fcc08105c7745f1502ba68d900f45fd770d5bdd5288ddccb8a42d8", size = 210036, upload-time = "2026-04-02T09:26:54.975Z" }, + { url = "https://files.pythonhosted.org/packages/8c/bf/b3ab5bcb478e4193d517644b0fb2bf5497fbceeaa7a1bc0f4d5b50953861/charset_normalizer-3.4.7-cp313-cp313-musllinux_1_2_armv7l.whl", hash = "sha256:481551899c856c704d58119b5025793fa6730adda3571971af568f66d2424bb5", size = 202998, upload-time = "2026-04-02T09:26:56.303Z" }, + { url = "https://files.pythonhosted.org/packages/e7/4e/23efd79b65d314fa320ec6017b4b5834d5c12a58ba4610aa353af2e2f577/charset_normalizer-3.4.7-cp313-cp313-musllinux_1_2_ppc64le.whl", hash = "sha256:f59099f9b66f0d7145115e6f80dd8b1d847176df89b234a5a6b3f00437aa0832", size = 230056, upload-time = "2026-04-02T09:26:57.554Z" }, + { url = "https://files.pythonhosted.org/packages/b9/9f/1e1941bc3f0e01df116e68dc37a55c4d249df5e6fa77f008841aef68264f/charset_normalizer-3.4.7-cp313-cp313-musllinux_1_2_riscv64.whl", hash = "sha256:f59ad4c0e8f6bba240a9bb85504faa1ab438237199d4cce5f622761507b8f6a6", size = 211537, upload-time = "2026-04-02T09:26:58.843Z" }, + { url = "https://files.pythonhosted.org/packages/80/0f/088cbb3020d44428964a6c97fe1edfb1b9550396bf6d278330281e8b709c/charset_normalizer-3.4.7-cp313-cp313-musllinux_1_2_s390x.whl", hash = "sha256:3dedcc22d73ec993f42055eff4fcfed9318d1eeb9a6606c55892a26964964e48", size = 226176, upload-time = "2026-04-02T09:27:00.437Z" }, + { url = "https://files.pythonhosted.org/packages/6a/9f/130394f9bbe06f4f63e22641d32fc9b202b7e251c9aef4db044324dac493/charset_normalizer-3.4.7-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:64f02c6841d7d83f832cd97ccf8eb8a906d06eb95d5276069175c696b024b60a", size = 217723, upload-time = "2026-04-02T09:27:02.021Z" }, + { url = "https://files.pythonhosted.org/packages/73/55/c469897448a06e49f8fa03f6caae97074fde823f432a98f979cc42b90e69/charset_normalizer-3.4.7-cp313-cp313-win32.whl", hash = "sha256:4042d5c8f957e15221d423ba781e85d553722fc4113f523f2feb7b188cc34c5e", size = 148085, upload-time = "2026-04-02T09:27:03.192Z" }, + { url = "https://files.pythonhosted.org/packages/5d/78/1b74c5bbb3f99b77a1715c91b3e0b5bdb6fe302d95ace4f5b1bec37b0167/charset_normalizer-3.4.7-cp313-cp313-win_amd64.whl", hash = "sha256:3946fa46a0cf3e4c8cb1cc52f56bb536310d34f25f01ca9b6c16afa767dab110", size = 158819, upload-time = "2026-04-02T09:27:04.454Z" }, + { url = "https://files.pythonhosted.org/packages/68/86/46bd42279d323deb8687c4a5a811fd548cb7d1de10cf6535d099877a9a9f/charset_normalizer-3.4.7-cp313-cp313-win_arm64.whl", hash = "sha256:80d04837f55fc81da168b98de4f4b797ef007fc8a79ab71c6ec9bc4dd662b15b", size = 147915, upload-time = "2026-04-02T09:27:05.971Z" }, + { url = "https://files.pythonhosted.org/packages/97/c8/c67cb8c70e19ef1960b97b22ed2a1567711de46c4ddf19799923adc836c2/charset_normalizer-3.4.7-cp314-cp314-macosx_10_15_universal2.whl", hash = "sha256:c36c333c39be2dbca264d7803333c896ab8fa7d4d6f0ab7edb7dfd7aea6e98c0", size = 309234, upload-time = "2026-04-02T09:27:07.194Z" }, + { url = "https://files.pythonhosted.org/packages/99/85/c091fdee33f20de70d6c8b522743b6f831a2f1cd3ff86de4c6a827c48a76/charset_normalizer-3.4.7-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:1c2aed2e5e41f24ea8ef1590b8e848a79b56f3a5564a65ceec43c9d692dc7d8a", size = 208042, upload-time = "2026-04-02T09:27:08.749Z" }, + { url = "https://files.pythonhosted.org/packages/87/1c/ab2ce611b984d2fd5d86a5a8a19c1ae26acac6bad967da4967562c75114d/charset_normalizer-3.4.7-cp314-cp314-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:54523e136b8948060c0fa0bc7b1b50c32c186f2fceee897a495406bb6e311d2b", size = 228706, upload-time = "2026-04-02T09:27:09.951Z" }, + { url = "https://files.pythonhosted.org/packages/a8/29/2b1d2cb00bf085f59d29eb773ce58ec2d325430f8c216804a0a5cd83cbca/charset_normalizer-3.4.7-cp314-cp314-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:715479b9a2802ecac752a3b0efa2b0b60285cf962ee38414211abdfccc233b41", size = 224727, upload-time = "2026-04-02T09:27:11.175Z" }, + { url = "https://files.pythonhosted.org/packages/47/5c/032c2d5a07fe4d4855fea851209cca2b6f03ebeb6d4e3afdb3358386a684/charset_normalizer-3.4.7-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:bd6c2a1c7573c64738d716488d2cdd3c00e340e4835707d8fdb8dc1a66ef164e", size = 215882, upload-time = "2026-04-02T09:27:12.446Z" }, + { url = "https://files.pythonhosted.org/packages/2c/c2/356065d5a8b78ed04499cae5f339f091946a6a74f91e03476c33f0ab7100/charset_normalizer-3.4.7-cp314-cp314-manylinux_2_31_armv7l.whl", hash = "sha256:c45e9440fb78f8ddabcf714b68f936737a121355bf59f3907f4e17721b9d1aae", size = 200860, upload-time = "2026-04-02T09:27:13.721Z" }, + { url = "https://files.pythonhosted.org/packages/0c/cd/a32a84217ced5039f53b29f460962abb2d4420def55afabe45b1c3c7483d/charset_normalizer-3.4.7-cp314-cp314-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:3534e7dcbdcf757da6b85a0bbf5b6868786d5982dd959b065e65481644817a18", size = 211564, upload-time = "2026-04-02T09:27:15.272Z" }, + { url = "https://files.pythonhosted.org/packages/44/86/58e6f13ce26cc3b8f4a36b94a0f22ae2f00a72534520f4ae6857c4b81f89/charset_normalizer-3.4.7-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:e8ac484bf18ce6975760921bb6148041faa8fef0547200386ea0b52b5d27bf7b", size = 211276, upload-time = "2026-04-02T09:27:16.834Z" }, + { url = "https://files.pythonhosted.org/packages/8f/fe/d17c32dc72e17e155e06883efa84514ca375f8a528ba2546bee73fc4df81/charset_normalizer-3.4.7-cp314-cp314-musllinux_1_2_armv7l.whl", hash = "sha256:a5fe03b42827c13cdccd08e6c0247b6a6d4b5e3cdc53fd1749f5896adcdc2356", size = 201238, upload-time = "2026-04-02T09:27:18.229Z" }, + { url = "https://files.pythonhosted.org/packages/6a/29/f33daa50b06525a237451cdb6c69da366c381a3dadcd833fa5676bc468b3/charset_normalizer-3.4.7-cp314-cp314-musllinux_1_2_ppc64le.whl", hash = "sha256:2d6eb928e13016cea4f1f21d1e10c1cebd5a421bc57ddf5b1142ae3f86824fab", size = 230189, upload-time = "2026-04-02T09:27:19.445Z" }, + { url = "https://files.pythonhosted.org/packages/b6/6e/52c84015394a6a0bdcd435210a7e944c5f94ea1055f5cc5d56c5fe368e7b/charset_normalizer-3.4.7-cp314-cp314-musllinux_1_2_riscv64.whl", hash = "sha256:e74327fb75de8986940def6e8dee4f127cc9752bee7355bb323cc5b2659b6d46", size = 211352, upload-time = "2026-04-02T09:27:20.79Z" }, + { url = "https://files.pythonhosted.org/packages/8c/d7/4353be581b373033fb9198bf1da3cf8f09c1082561e8e922aa7b39bf9fe8/charset_normalizer-3.4.7-cp314-cp314-musllinux_1_2_s390x.whl", hash = "sha256:d6038d37043bced98a66e68d3aa2b6a35505dc01328cd65217cefe82f25def44", size = 227024, upload-time = "2026-04-02T09:27:22.063Z" }, + { url = "https://files.pythonhosted.org/packages/30/45/99d18aa925bd1740098ccd3060e238e21115fffbfdcb8f3ece837d0ace6c/charset_normalizer-3.4.7-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:7579e913a5339fb8fa133f6bbcfd8e6749696206cf05acdbdca71a1b436d8e72", size = 217869, upload-time = "2026-04-02T09:27:23.486Z" }, + { url = "https://files.pythonhosted.org/packages/5c/05/5ee478aa53f4bb7996482153d4bfe1b89e0f087f0ab6b294fcf92d595873/charset_normalizer-3.4.7-cp314-cp314-win32.whl", hash = "sha256:5b77459df20e08151cd6f8b9ef8ef1f961ef73d85c21a555c7eed5b79410ec10", size = 148541, upload-time = "2026-04-02T09:27:25.146Z" }, + { url = "https://files.pythonhosted.org/packages/48/77/72dcb0921b2ce86420b2d79d454c7022bf5be40202a2a07906b9f2a35c97/charset_normalizer-3.4.7-cp314-cp314-win_amd64.whl", hash = "sha256:92a0a01ead5e668468e952e4238cccd7c537364eb7d851ab144ab6627dbbe12f", size = 159634, upload-time = "2026-04-02T09:27:26.642Z" }, + { url = "https://files.pythonhosted.org/packages/c6/a3/c2369911cd72f02386e4e340770f6e158c7980267da16af8f668217abaa0/charset_normalizer-3.4.7-cp314-cp314-win_arm64.whl", hash = "sha256:67f6279d125ca0046a7fd386d01b311c6363844deac3e5b069b514ba3e63c246", size = 148384, upload-time = "2026-04-02T09:27:28.271Z" }, + { url = "https://files.pythonhosted.org/packages/94/09/7e8a7f73d24dba1f0035fbbf014d2c36828fc1bf9c88f84093e57d315935/charset_normalizer-3.4.7-cp314-cp314t-macosx_10_15_universal2.whl", hash = "sha256:effc3f449787117233702311a1b7d8f59cba9ced946ba727bdc329ec69028e24", size = 330133, upload-time = "2026-04-02T09:27:29.474Z" }, + { url = "https://files.pythonhosted.org/packages/8d/da/96975ddb11f8e977f706f45cddd8540fd8242f71ecdb5d18a80723dcf62c/charset_normalizer-3.4.7-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:fbccdc05410c9ee21bbf16a35f4c1d16123dcdeb8a1d38f33654fa21d0234f79", size = 216257, upload-time = "2026-04-02T09:27:30.793Z" }, + { url = "https://files.pythonhosted.org/packages/e5/e8/1d63bf8ef2d388e95c64b2098f45f84758f6d102a087552da1485912637b/charset_normalizer-3.4.7-cp314-cp314t-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:733784b6d6def852c814bce5f318d25da2ee65dd4839a0718641c696e09a2960", size = 234851, upload-time = "2026-04-02T09:27:32.44Z" }, + { url = "https://files.pythonhosted.org/packages/9b/40/e5ff04233e70da2681fa43969ad6f66ca5611d7e669be0246c4c7aaf6dc8/charset_normalizer-3.4.7-cp314-cp314t-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:a89c23ef8d2c6b27fd200a42aa4ac72786e7c60d40efdc76e6011260b6e949c4", size = 233393, upload-time = "2026-04-02T09:27:34.03Z" }, + { url = "https://files.pythonhosted.org/packages/be/c1/06c6c49d5a5450f76899992f1ee40b41d076aee9279b49cf9974d2f313d5/charset_normalizer-3.4.7-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:6c114670c45346afedc0d947faf3c7f701051d2518b943679c8ff88befe14f8e", size = 223251, upload-time = "2026-04-02T09:27:35.369Z" }, + { url = "https://files.pythonhosted.org/packages/2b/9f/f2ff16fb050946169e3e1f82134d107e5d4ae72647ec8a1b1446c148480f/charset_normalizer-3.4.7-cp314-cp314t-manylinux_2_31_armv7l.whl", hash = "sha256:a180c5e59792af262bf263b21a3c49353f25945d8d9f70628e73de370d55e1e1", size = 206609, upload-time = "2026-04-02T09:27:36.661Z" }, + { url = "https://files.pythonhosted.org/packages/69/d5/a527c0cd8d64d2eab7459784fb4169a0ac76e5a6fc5237337982fd61347e/charset_normalizer-3.4.7-cp314-cp314t-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:3c9a494bc5ec77d43cea229c4f6db1e4d8fe7e1bbffa8b6f0f0032430ff8ab44", size = 220014, upload-time = "2026-04-02T09:27:38.019Z" }, + { url = "https://files.pythonhosted.org/packages/7e/80/8a7b8104a3e203074dc9aa2c613d4b726c0e136bad1cc734594b02867972/charset_normalizer-3.4.7-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:8d828b6667a32a728a1ad1d93957cdf37489c57b97ae6c4de2860fa749b8fc1e", size = 218979, upload-time = "2026-04-02T09:27:39.37Z" }, + { url = "https://files.pythonhosted.org/packages/02/9a/b759b503d507f375b2b5c153e4d2ee0a75aa215b7f2489cf314f4541f2c0/charset_normalizer-3.4.7-cp314-cp314t-musllinux_1_2_armv7l.whl", hash = "sha256:cf1493cd8607bec4d8a7b9b004e699fcf8f9103a9284cc94962cb73d20f9d4a3", size = 209238, upload-time = "2026-04-02T09:27:40.722Z" }, + { url = "https://files.pythonhosted.org/packages/c2/4e/0f3f5d47b86bdb79256e7290b26ac847a2832d9a4033f7eb2cd4bcf4bb5b/charset_normalizer-3.4.7-cp314-cp314t-musllinux_1_2_ppc64le.whl", hash = "sha256:0c96c3b819b5c3e9e165495db84d41914d6894d55181d2d108cc1a69bfc9cce0", size = 236110, upload-time = "2026-04-02T09:27:42.33Z" }, + { url = "https://files.pythonhosted.org/packages/96/23/bce28734eb3ed2c91dcf93abeb8a5cf393a7b2749725030bb630e554fdd8/charset_normalizer-3.4.7-cp314-cp314t-musllinux_1_2_riscv64.whl", hash = "sha256:752a45dc4a6934060b3b0dab47e04edc3326575f82be64bc4fc293914566503e", size = 219824, upload-time = "2026-04-02T09:27:43.924Z" }, + { url = "https://files.pythonhosted.org/packages/2c/6f/6e897c6984cc4d41af319b077f2f600fc8214eb2fe2d6bcb79141b882400/charset_normalizer-3.4.7-cp314-cp314t-musllinux_1_2_s390x.whl", hash = "sha256:8778f0c7a52e56f75d12dae53ae320fae900a8b9b4164b981b9c5ce059cd1fcb", size = 233103, upload-time = "2026-04-02T09:27:45.348Z" }, + { url = "https://files.pythonhosted.org/packages/76/22/ef7bd0fe480a0ae9b656189ec00744b60933f68b4f42a7bb06589f6f576a/charset_normalizer-3.4.7-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:ce3412fbe1e31eb81ea42f4169ed94861c56e643189e1e75f0041f3fe7020abe", size = 225194, upload-time = "2026-04-02T09:27:46.706Z" }, + { url = "https://files.pythonhosted.org/packages/c5/a7/0e0ab3e0b5bc1219bd80a6a0d4d72ca74d9250cb2382b7c699c147e06017/charset_normalizer-3.4.7-cp314-cp314t-win32.whl", hash = "sha256:c03a41a8784091e67a39648f70c5f97b5b6a37f216896d44d2cdcb82615339a0", size = 159827, upload-time = "2026-04-02T09:27:48.053Z" }, + { url = "https://files.pythonhosted.org/packages/7a/1d/29d32e0fb40864b1f878c7f5a0b343ae676c6e2b271a2d55cc3a152391da/charset_normalizer-3.4.7-cp314-cp314t-win_amd64.whl", hash = "sha256:03853ed82eeebbce3c2abfdbc98c96dc205f32a79627688ac9a27370ea61a49c", size = 174168, upload-time = "2026-04-02T09:27:49.795Z" }, + { url = "https://files.pythonhosted.org/packages/de/32/d92444ad05c7a6e41fb2036749777c163baf7a0301a040cb672d6b2b1ae9/charset_normalizer-3.4.7-cp314-cp314t-win_arm64.whl", hash = "sha256:c35abb8bfff0185efac5878da64c45dafd2b37fb0383add1be155a763c1f083d", size = 153018, upload-time = "2026-04-02T09:27:51.116Z" }, + { url = "https://files.pythonhosted.org/packages/db/8f/61959034484a4a7c527811f4721e75d02d653a35afb0b6054474d8185d4c/charset_normalizer-3.4.7-py3-none-any.whl", hash = "sha256:3dce51d0f5e7951f8bb4900c257dad282f49190fdbebecd4ba99bcc41fef404d", size = 61958, upload-time = "2026-04-02T09:28:37.794Z" }, +] + +[[package]] +name = "cmake" +version = "4.3.2" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/76/07/f1d6f7bcf056a139352cc2972f92a92005ac0ee98103165b1f620873b196/cmake-4.3.2.tar.gz", hash = "sha256:5f47f5f00910c474662d09a0516413c6e9750bde73cdc52dea3988102a274e06", size = 36969, upload-time = "2026-04-23T21:51:35.982Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/82/15/4c8980d5ceef53f0c490425f5b8e47f3ff863348400b0ea5ba4e349119f1/cmake-4.3.2-py3-none-macosx_10_10_universal2.whl", hash = "sha256:f8f570813753ed4564928cf45c4c13c31e46b3e66b1a07fe695cb9f7b7af185e", size = 52883814, upload-time = "2026-04-23T21:50:16.764Z" }, + { url = "https://files.pythonhosted.org/packages/bc/50/2f336143dbcf5eca7c2d7e86273a84ef60231a0b7cfa33143d964c62f250/cmake-4.3.2-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:ca739ab0d8960261fdb1bb6e1e6c16b9cd033ae0a98341483cc233ba7c81b22b", size = 29578008, upload-time = "2026-04-23T21:50:21.965Z" }, + { url = "https://files.pythonhosted.org/packages/52/e9/4b571a24924b5bdbd5c0b0fbb0b6b1008eb6472ceb9f23bca9e08e09632e/cmake-4.3.2-py3-none-manylinux2014_i686.manylinux_2_17_i686.whl", hash = "sha256:2b81038453a40aed73f8d28185c4c3ef43c3a91a7ff1577ce08e498769ecfe16", size = 30676971, upload-time = "2026-04-23T21:50:25.395Z" }, + { url = "https://files.pythonhosted.org/packages/a1/d4/87f91ba2030c862a27a5b2df42e4e80d3244910acd10aa4cdcd0111820a9/cmake-4.3.2-py3-none-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:8add046a4ef7c606d8e0a444050415054c7da3b8535b2c8ce1f03e265dda098d", size = 30462837, upload-time = "2026-04-23T21:50:28.785Z" }, + { url = "https://files.pythonhosted.org/packages/21/ee/5475cd861db5e8e22fd6b3fd323a67f8f62df487163f72bc281739309bcf/cmake-4.3.2-py3-none-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:7105a5411bbc405242677d29222812028566aafac3f78fda08c1717f03e5ca2a", size = 28377235, upload-time = "2026-04-23T21:50:32.144Z" }, + { url = "https://files.pythonhosted.org/packages/63/cd/1008be054420fd759b73d3328326d047ea693c3910a55cb2a597d911baee/cmake-4.3.2-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:339655b93289c1b03c6a72523d46d3b0d19dc51406d3a90f8eefcbec525cb271", size = 29512079, upload-time = "2026-04-23T21:50:36.295Z" }, + { url = "https://files.pythonhosted.org/packages/13/c4/e7c3649c4941927aff24c464090c4ce7f1f24167077f1b8aff3994def88d/cmake-4.3.2-py3-none-manylinux_2_31_armv7l.whl", hash = "sha256:ea95db137fd27f420d5e149c41e1f7621e786869afa3ca0fe18301df9e066607", size = 26628649, upload-time = "2026-04-23T21:50:40.047Z" }, + { url = "https://files.pythonhosted.org/packages/5a/05/ee3b002e0e7303a36e1f3c52e18d004fe089076a0e7b38df5e64a2328e88/cmake-4.3.2-py3-none-manylinux_2_31_riscv64.whl", hash = "sha256:3947bc5973ca3846c76486993abd0fba0cb9119300d58ed9173a672d1eef505b", size = 26769012, upload-time = "2026-04-23T21:50:44.237Z" }, + { url = "https://files.pythonhosted.org/packages/4d/a6/4e42625ce96197ffd72bb6a0e9c02d64506ee3075dd801219bb44fd9dcf7/cmake-4.3.2-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:bc316be89fa43c265697c3b9ffcebde977bcc4515974372cc460c974f458ff98", size = 38595561, upload-time = "2026-04-23T21:50:48.601Z" }, + { url = "https://files.pythonhosted.org/packages/bd/5b/80ab6fa7aceff0af186a844b6a53c3022e9775467804a1ce2ec3aafb02b3/cmake-4.3.2-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:d10648929eb3294449ceae7a7c0b9714ca445280ddc25c209f427e7a07c6f3a9", size = 35226159, upload-time = "2026-04-23T21:50:53.968Z" }, + { url = "https://files.pythonhosted.org/packages/10/e3/73fc202fb943221a7ce78a5374c7a73093d26af85378ddab9c04586dc98b/cmake-4.3.2-py3-none-musllinux_1_2_i686.whl", hash = "sha256:a69e629e6cd973e1f9b11d247d116acb47b35cdd8e39aee4b04b9040851cd8a0", size = 41262833, upload-time = "2026-04-23T21:50:59.402Z" }, + { url = "https://files.pythonhosted.org/packages/c4/d3/3ef79820bfbcd5b51ef3b8029fc9c96da363daa11aae02ddd82df08fa446/cmake-4.3.2-py3-none-musllinux_1_2_ppc64le.whl", hash = "sha256:95e0ff31a692d12130f33d1467d0074f8314cf3a79940694896de9367b6e4fae", size = 40437896, upload-time = "2026-04-23T21:51:04.304Z" }, + { url = "https://files.pythonhosted.org/packages/f9/a8/8a1147fa26a3c1564bf654b744baeb2b8c0efccfde04190d3f9222c27bde/cmake-4.3.2-py3-none-musllinux_1_2_riscv64.whl", hash = "sha256:67775407b963385a7942dd56f0567ef3c75453c6336654aeafe43165d78648bb", size = 35492662, upload-time = "2026-04-23T21:51:08.982Z" }, + { url = "https://files.pythonhosted.org/packages/78/96/42a744beb4c9f6e459f1a57162f391a9941f31850048fc461e88095f98da/cmake-4.3.2-py3-none-musllinux_1_2_s390x.whl", hash = "sha256:aae70bb95762f6da20131cf72da6322557ff6784968755d201d42a44cd9494e5", size = 37723238, upload-time = "2026-04-23T21:51:13.595Z" }, + { url = "https://files.pythonhosted.org/packages/06/4c/513a73685feef886c824982b6618bb3cc7e7ac8579b34f1fe043bce11af5/cmake-4.3.2-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:b1c5c292b1189e48d01f0bed01ed800c31eed967afd033c4beabff9cc97209f2", size = 38554155, upload-time = "2026-04-23T21:51:18.153Z" }, + { url = "https://files.pythonhosted.org/packages/14/aa/35b387f6cc0990247195109b04523a1c05dbb4f0fd0bae28e7f34c4a1e6f/cmake-4.3.2-py3-none-win32.whl", hash = "sha256:3c55f0c61c70642d9e7f6b4fc638622027f045b388e357d74efcca4a7111e4aa", size = 37819702, upload-time = "2026-04-23T21:51:22.933Z" }, + { url = "https://files.pythonhosted.org/packages/96/8d/7ceb7223d274e88d621ce00f2160ae74aead18a3d36f61b8fb52cbe6b7ca/cmake-4.3.2-py3-none-win_amd64.whl", hash = "sha256:78049aac277aabe376d8e82993f0be234d086d0e8ad4708755d5a209a04e1138", size = 41272507, upload-time = "2026-04-23T21:51:27.93Z" }, + { url = "https://files.pythonhosted.org/packages/69/4f/fa4da5330b63d5ce7909892005eced21d1fca58d022ed6b40f216f6f6c52/cmake-4.3.2-py3-none-win_arm64.whl", hash = "sha256:b218d636a99fa0eb23713d37d3e3c3a9c0e707e0579b46780ff908acef229386", size = 39613878, upload-time = "2026-04-23T21:51:33.041Z" }, +] + +[[package]] +name = "colorama" +version = "0.4.6" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/d8/53/6f443c9a4a8358a93a6792e2acffb9d9d5cb0a5cfd8802644b7b1c9a02e4/colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44", size = 27697, upload-time = "2022-10-25T02:36:22.414Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/d1/d6/3965ed04c63042e047cb6a3e6ed1a63a35087b6a609aa3a15ed8ac56c221/colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6", size = 25335, upload-time = "2022-10-25T02:36:20.889Z" }, +] + +[[package]] +name = "conan" +version = "1.66.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "bottle" }, + { name = "colorama" }, + { name = "distro", marker = "sys_platform == 'linux' or sys_platform == 'linux2'" }, + { name = "fasteners" }, + { name = "jinja2" }, + { name = "node-semver" }, + { name = "patch-ng" }, + { name = "pluginbase" }, + { name = "pygments" }, + { name = "pyjwt" }, + { name = "python-dateutil" }, + { name = "pyyaml" }, + { name = "requests" }, + { name = "six" }, + { name = "tqdm" }, + { name = "urllib3" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/ee/e8/0893952ee0c0f78100a7da72aeb81f68925933ecbb730bfd664e7a4c6f1f/conan-1.66.0.tar.gz", hash = "sha256:04d2ad0f6ec6f055d95fa0a157b55fdea9328ae67f51b11e7d26e9d9d2f76ab9", size = 789962, upload-time = "2024-12-02T17:38:36.056Z" } + +[[package]] +name = "distlib" +version = "0.4.3" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/c9/02/bd72be9134d25ed783ecbbc38a539ffaefbf90c78418c7fb7229600dbac7/distlib-0.4.3.tar.gz", hash = "sha256:f152097224a0ae24be5a0f6bae1b9359af82133bce63f98a95f86cae1aede9ed", size = 615141, upload-time = "2026-06-12T08:04:52.847Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/02/08/9c41fb51ab5b43eb21674aff13df270e8ba6c4b29c8624e328dc7a9482af/distlib-0.4.3-py2.py3-none-any.whl", hash = "sha256:4b0ce306c966eb73bc3a7b6abad017c556dadd92c44701562cd528ac7fde4d5b", size = 470628, upload-time = "2026-06-12T08:04:50.506Z" }, +] + +[[package]] +name = "distro" +version = "1.8.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/4b/89/eaa3a3587ebf8bed93e45aa79be8c2af77d50790d15b53f6dfc85b57f398/distro-1.8.0.tar.gz", hash = "sha256:02e111d1dc6a50abb8eed6bf31c3e48ed8b0830d1ea2a1b78c61765c2513fdd8", size = 59428, upload-time = "2022-10-10T15:30:33.395Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/f4/2c/c90a3adaf0ddb70afe193f5ebfb539612af57cffe677c3126be533df3098/distro-1.8.0-py3-none-any.whl", hash = "sha256:99522ca3e365cac527b44bde033f64c6945d90eb9f769703caaec52b09bbd3ff", size = 20315, upload-time = "2022-10-10T15:30:26.903Z" }, +] + +[[package]] +name = "fasteners" +version = "0.20" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/2d/18/7881a99ba5244bfc82f06017316ffe93217dbbbcfa52b887caa1d4f2a6d3/fasteners-0.20.tar.gz", hash = "sha256:55dce8792a41b56f727ba6e123fcaee77fd87e638a6863cec00007bfea84c8d8", size = 25087, upload-time = "2025-08-11T10:19:37.785Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/51/ac/e5d886f892666d2d1e5cb8c1a41146e1d79ae8896477b1153a21711d3b44/fasteners-0.20-py3-none-any.whl", hash = "sha256:9422c40d1e350e4259f509fb2e608d6bc43c0136f79a00db1b49046029d0b3b7", size = 18702, upload-time = "2025-08-11T10:19:35.716Z" }, +] + +[[package]] +name = "filelock" +version = "3.29.4" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/e6/dc/be6cbe99670cd6e4ad387123647cb08e0c32975e223f82551e914c5568a6/filelock-3.29.4.tar.gz", hash = "sha256:10cdb3656fc44541cdf30652a93fb10ec6b05325620eb316bd26893e4201538a", size = 63028, upload-time = "2026-06-13T16:12:00.744Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/13/37/a065dc3bd6e49423a6532c642ca7378d3f467b1ef44c2800c937af7f9739/filelock-3.29.4-py3-none-any.whl", hash = "sha256:dac1648087d5115554850d113e7dd8c83ab2d38e3435dde2d4f163847e57b767", size = 42757, upload-time = "2026-06-13T16:11:59.582Z" }, +] + +[[package]] +name = "identify" +version = "2.6.19" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/52/63/51723b5f116cc04b061cb6f5a561790abf249d25931d515cd375e063e0f4/identify-2.6.19.tar.gz", hash = "sha256:6be5020c38fcb07da56c53733538a3081ea5aa70d36a156f83044bfbf9173842", size = 99567, upload-time = "2026-04-17T18:39:50.265Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/94/84/d9273cd09688070a6523c4aee4663a8538721b2b755c4962aafae0011e72/identify-2.6.19-py2.py3-none-any.whl", hash = "sha256:20e6a87f786f768c092a721ad107fc9df0eb89347be9396cadf3f4abbd1fb78a", size = 99397, upload-time = "2026-04-17T18:39:49.221Z" }, +] + +[[package]] +name = "idna" +version = "3.18" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/cd/63/9496c57188a2ee585e0f1db071d75089a11e98aa86eb99d9d7618fc1edce/idna-3.18.tar.gz", hash = "sha256:ffb385a7e039654cef1ab9ef32c6fafe283c0c0467bba1d9029738ce4a14a848", size = 196711, upload-time = "2026-06-02T14:34:07.794Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/1e/5e/d4e9f1a599fb8e573b7b87160658329fbf28d19eac2718f51fc3def3aa5a/idna-3.18-py3-none-any.whl", hash = "sha256:7f952cbe720b688055e3f87de14f5c3e5fdaa8bc3928985c4077ca689de849a2", size = 65455, upload-time = "2026-06-02T14:34:06.319Z" }, +] + +[[package]] +name = "jinja2" +version = "3.1.6" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "markupsafe" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/df/bf/f7da0350254c0ed7c72f3e33cef02e048281fec7ecec5f032d4aac52226b/jinja2-3.1.6.tar.gz", hash = "sha256:0137fb05990d35f1275a587e9aee6d56da821fc83491a0fb838183be43f66d6d", size = 245115, upload-time = "2025-03-05T20:05:02.478Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/62/a1/3d680cbfd5f4b8f15abc1d571870c5fc3e594bb582bc3b64ea099db13e56/jinja2-3.1.6-py3-none-any.whl", hash = "sha256:85ece4451f492d0c13c5dd7c13a64681a86afae63a5f347908daf103ce6d2f67", size = 134899, upload-time = "2025-03-05T20:05:00.369Z" }, +] + +[[package]] +name = "markupsafe" +version = "3.0.3" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/7e/99/7690b6d4034fffd95959cbe0c02de8deb3098cc577c67bb6a24fe5d7caa7/markupsafe-3.0.3.tar.gz", hash = "sha256:722695808f4b6457b320fdc131280796bdceb04ab50fe1795cd540799ebe1698", size = 80313, upload-time = "2025-09-27T18:37:40.426Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/e8/4b/3541d44f3937ba468b75da9eebcae497dcf67adb65caa16760b0a6807ebb/markupsafe-3.0.3-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:2f981d352f04553a7171b8e44369f2af4055f888dfb147d55e42d29e29e74559", size = 11631, upload-time = "2025-09-27T18:36:05.558Z" }, + { url = "https://files.pythonhosted.org/packages/98/1b/fbd8eed11021cabd9226c37342fa6ca4e8a98d8188a8d9b66740494960e4/markupsafe-3.0.3-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:e1c1493fb6e50ab01d20a22826e57520f1284df32f2d8601fdd90b6304601419", size = 12057, upload-time = "2025-09-27T18:36:07.165Z" }, + { url = "https://files.pythonhosted.org/packages/40/01/e560d658dc0bb8ab762670ece35281dec7b6c1b33f5fbc09ebb57a185519/markupsafe-3.0.3-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:1ba88449deb3de88bd40044603fafffb7bc2b055d626a330323a9ed736661695", size = 22050, upload-time = "2025-09-27T18:36:08.005Z" }, + { url = "https://files.pythonhosted.org/packages/af/cd/ce6e848bbf2c32314c9b237839119c5a564a59725b53157c856e90937b7a/markupsafe-3.0.3-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:f42d0984e947b8adf7dd6dde396e720934d12c506ce84eea8476409563607591", size = 20681, upload-time = "2025-09-27T18:36:08.881Z" }, + { url = "https://files.pythonhosted.org/packages/c9/2a/b5c12c809f1c3045c4d580b035a743d12fcde53cf685dbc44660826308da/markupsafe-3.0.3-cp310-cp310-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:c0c0b3ade1c0b13b936d7970b1d37a57acde9199dc2aecc4c336773e1d86049c", size = 20705, upload-time = "2025-09-27T18:36:10.131Z" }, + { url = "https://files.pythonhosted.org/packages/cf/e3/9427a68c82728d0a88c50f890d0fc072a1484de2f3ac1ad0bfc1a7214fd5/markupsafe-3.0.3-cp310-cp310-musllinux_1_2_aarch64.whl", hash = "sha256:0303439a41979d9e74d18ff5e2dd8c43ed6c6001fd40e5bf2e43f7bd9bbc523f", size = 21524, upload-time = "2025-09-27T18:36:11.324Z" }, + { url = "https://files.pythonhosted.org/packages/bc/36/23578f29e9e582a4d0278e009b38081dbe363c5e7165113fad546918a232/markupsafe-3.0.3-cp310-cp310-musllinux_1_2_riscv64.whl", hash = "sha256:d2ee202e79d8ed691ceebae8e0486bd9a2cd4794cec4824e1c99b6f5009502f6", size = 20282, upload-time = "2025-09-27T18:36:12.573Z" }, + { url = "https://files.pythonhosted.org/packages/56/21/dca11354e756ebd03e036bd8ad58d6d7168c80ce1fe5e75218e4945cbab7/markupsafe-3.0.3-cp310-cp310-musllinux_1_2_x86_64.whl", hash = "sha256:177b5253b2834fe3678cb4a5f0059808258584c559193998be2601324fdeafb1", size = 20745, upload-time = "2025-09-27T18:36:13.504Z" }, + { url = "https://files.pythonhosted.org/packages/87/99/faba9369a7ad6e4d10b6a5fbf71fa2a188fe4a593b15f0963b73859a1bbd/markupsafe-3.0.3-cp310-cp310-win32.whl", hash = "sha256:2a15a08b17dd94c53a1da0438822d70ebcd13f8c3a95abe3a9ef9f11a94830aa", size = 14571, upload-time = "2025-09-27T18:36:14.779Z" }, + { url = "https://files.pythonhosted.org/packages/d6/25/55dc3ab959917602c96985cb1253efaa4ff42f71194bddeb61eb7278b8be/markupsafe-3.0.3-cp310-cp310-win_amd64.whl", hash = "sha256:c4ffb7ebf07cfe8931028e3e4c85f0357459a3f9f9490886198848f4fa002ec8", size = 15056, upload-time = "2025-09-27T18:36:16.125Z" }, + { url = "https://files.pythonhosted.org/packages/d0/9e/0a02226640c255d1da0b8d12e24ac2aa6734da68bff14c05dd53b94a0fc3/markupsafe-3.0.3-cp310-cp310-win_arm64.whl", hash = "sha256:e2103a929dfa2fcaf9bb4e7c091983a49c9ac3b19c9061b6d5427dd7d14d81a1", size = 13932, upload-time = "2025-09-27T18:36:17.311Z" }, + { url = "https://files.pythonhosted.org/packages/08/db/fefacb2136439fc8dd20e797950e749aa1f4997ed584c62cfb8ef7c2be0e/markupsafe-3.0.3-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:1cc7ea17a6824959616c525620e387f6dd30fec8cb44f649e31712db02123dad", size = 11631, upload-time = "2025-09-27T18:36:18.185Z" }, + { url = "https://files.pythonhosted.org/packages/e1/2e/5898933336b61975ce9dc04decbc0a7f2fee78c30353c5efba7f2d6ff27a/markupsafe-3.0.3-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:4bd4cd07944443f5a265608cc6aab442e4f74dff8088b0dfc8238647b8f6ae9a", size = 12058, upload-time = "2025-09-27T18:36:19.444Z" }, + { url = "https://files.pythonhosted.org/packages/1d/09/adf2df3699d87d1d8184038df46a9c80d78c0148492323f4693df54e17bb/markupsafe-3.0.3-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:6b5420a1d9450023228968e7e6a9ce57f65d148ab56d2313fcd589eee96a7a50", size = 24287, upload-time = "2025-09-27T18:36:20.768Z" }, + { url = "https://files.pythonhosted.org/packages/30/ac/0273f6fcb5f42e314c6d8cd99effae6a5354604d461b8d392b5ec9530a54/markupsafe-3.0.3-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:0bf2a864d67e76e5c9a34dc26ec616a66b9888e25e7b9460e1c76d3293bd9dbf", size = 22940, upload-time = "2025-09-27T18:36:22.249Z" }, + { url = "https://files.pythonhosted.org/packages/19/ae/31c1be199ef767124c042c6c3e904da327a2f7f0cd63a0337e1eca2967a8/markupsafe-3.0.3-cp311-cp311-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:bc51efed119bc9cfdf792cdeaa4d67e8f6fcccab66ed4bfdd6bde3e59bfcbb2f", size = 21887, upload-time = "2025-09-27T18:36:23.535Z" }, + { url = "https://files.pythonhosted.org/packages/b2/76/7edcab99d5349a4532a459e1fe64f0b0467a3365056ae550d3bcf3f79e1e/markupsafe-3.0.3-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:068f375c472b3e7acbe2d5318dea141359e6900156b5b2ba06a30b169086b91a", size = 23692, upload-time = "2025-09-27T18:36:24.823Z" }, + { url = "https://files.pythonhosted.org/packages/a4/28/6e74cdd26d7514849143d69f0bf2399f929c37dc2b31e6829fd2045b2765/markupsafe-3.0.3-cp311-cp311-musllinux_1_2_riscv64.whl", hash = "sha256:7be7b61bb172e1ed687f1754f8e7484f1c8019780f6f6b0786e76bb01c2ae115", size = 21471, upload-time = "2025-09-27T18:36:25.95Z" }, + { url = "https://files.pythonhosted.org/packages/62/7e/a145f36a5c2945673e590850a6f8014318d5577ed7e5920a4b3448e0865d/markupsafe-3.0.3-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:f9e130248f4462aaa8e2552d547f36ddadbeaa573879158d721bbd33dfe4743a", size = 22923, upload-time = "2025-09-27T18:36:27.109Z" }, + { url = "https://files.pythonhosted.org/packages/0f/62/d9c46a7f5c9adbeeeda52f5b8d802e1094e9717705a645efc71b0913a0a8/markupsafe-3.0.3-cp311-cp311-win32.whl", hash = "sha256:0db14f5dafddbb6d9208827849fad01f1a2609380add406671a26386cdf15a19", size = 14572, upload-time = "2025-09-27T18:36:28.045Z" }, + { url = "https://files.pythonhosted.org/packages/83/8a/4414c03d3f891739326e1783338e48fb49781cc915b2e0ee052aa490d586/markupsafe-3.0.3-cp311-cp311-win_amd64.whl", hash = "sha256:de8a88e63464af587c950061a5e6a67d3632e36df62b986892331d4620a35c01", size = 15077, upload-time = "2025-09-27T18:36:29.025Z" }, + { url = "https://files.pythonhosted.org/packages/35/73/893072b42e6862f319b5207adc9ae06070f095b358655f077f69a35601f0/markupsafe-3.0.3-cp311-cp311-win_arm64.whl", hash = "sha256:3b562dd9e9ea93f13d53989d23a7e775fdfd1066c33494ff43f5418bc8c58a5c", size = 13876, upload-time = "2025-09-27T18:36:29.954Z" }, + { url = "https://files.pythonhosted.org/packages/5a/72/147da192e38635ada20e0a2e1a51cf8823d2119ce8883f7053879c2199b5/markupsafe-3.0.3-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:d53197da72cc091b024dd97249dfc7794d6a56530370992a5e1a08983ad9230e", size = 11615, upload-time = "2025-09-27T18:36:30.854Z" }, + { url = "https://files.pythonhosted.org/packages/9a/81/7e4e08678a1f98521201c3079f77db69fb552acd56067661f8c2f534a718/markupsafe-3.0.3-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:1872df69a4de6aead3491198eaf13810b565bdbeec3ae2dc8780f14458ec73ce", size = 12020, upload-time = "2025-09-27T18:36:31.971Z" }, + { url = "https://files.pythonhosted.org/packages/1e/2c/799f4742efc39633a1b54a92eec4082e4f815314869865d876824c257c1e/markupsafe-3.0.3-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:3a7e8ae81ae39e62a41ec302f972ba6ae23a5c5396c8e60113e9066ef893da0d", size = 24332, upload-time = "2025-09-27T18:36:32.813Z" }, + { url = "https://files.pythonhosted.org/packages/3c/2e/8d0c2ab90a8c1d9a24f0399058ab8519a3279d1bd4289511d74e909f060e/markupsafe-3.0.3-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:d6dd0be5b5b189d31db7cda48b91d7e0a9795f31430b7f271219ab30f1d3ac9d", size = 22947, upload-time = "2025-09-27T18:36:33.86Z" }, + { url = "https://files.pythonhosted.org/packages/2c/54/887f3092a85238093a0b2154bd629c89444f395618842e8b0c41783898ea/markupsafe-3.0.3-cp312-cp312-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:94c6f0bb423f739146aec64595853541634bde58b2135f27f61c1ffd1cd4d16a", size = 21962, upload-time = "2025-09-27T18:36:35.099Z" }, + { url = "https://files.pythonhosted.org/packages/c9/2f/336b8c7b6f4a4d95e91119dc8521402461b74a485558d8f238a68312f11c/markupsafe-3.0.3-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:be8813b57049a7dc738189df53d69395eba14fb99345e0a5994914a3864c8a4b", size = 23760, upload-time = "2025-09-27T18:36:36.001Z" }, + { url = "https://files.pythonhosted.org/packages/32/43/67935f2b7e4982ffb50a4d169b724d74b62a3964bc1a9a527f5ac4f1ee2b/markupsafe-3.0.3-cp312-cp312-musllinux_1_2_riscv64.whl", hash = "sha256:83891d0e9fb81a825d9a6d61e3f07550ca70a076484292a70fde82c4b807286f", size = 21529, upload-time = "2025-09-27T18:36:36.906Z" }, + { url = "https://files.pythonhosted.org/packages/89/e0/4486f11e51bbba8b0c041098859e869e304d1c261e59244baa3d295d47b7/markupsafe-3.0.3-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:77f0643abe7495da77fb436f50f8dab76dbc6e5fd25d39589a0f1fe6548bfa2b", size = 23015, upload-time = "2025-09-27T18:36:37.868Z" }, + { url = "https://files.pythonhosted.org/packages/2f/e1/78ee7a023dac597a5825441ebd17170785a9dab23de95d2c7508ade94e0e/markupsafe-3.0.3-cp312-cp312-win32.whl", hash = "sha256:d88b440e37a16e651bda4c7c2b930eb586fd15ca7406cb39e211fcff3bf3017d", size = 14540, upload-time = "2025-09-27T18:36:38.761Z" }, + { url = "https://files.pythonhosted.org/packages/aa/5b/bec5aa9bbbb2c946ca2733ef9c4ca91c91b6a24580193e891b5f7dbe8e1e/markupsafe-3.0.3-cp312-cp312-win_amd64.whl", hash = "sha256:26a5784ded40c9e318cfc2bdb30fe164bdb8665ded9cd64d500a34fb42067b1c", size = 15105, upload-time = "2025-09-27T18:36:39.701Z" }, + { url = "https://files.pythonhosted.org/packages/e5/f1/216fc1bbfd74011693a4fd837e7026152e89c4bcf3e77b6692fba9923123/markupsafe-3.0.3-cp312-cp312-win_arm64.whl", hash = "sha256:35add3b638a5d900e807944a078b51922212fb3dedb01633a8defc4b01a3c85f", size = 13906, upload-time = "2025-09-27T18:36:40.689Z" }, + { url = "https://files.pythonhosted.org/packages/38/2f/907b9c7bbba283e68f20259574b13d005c121a0fa4c175f9bed27c4597ff/markupsafe-3.0.3-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:e1cf1972137e83c5d4c136c43ced9ac51d0e124706ee1c8aa8532c1287fa8795", size = 11622, upload-time = "2025-09-27T18:36:41.777Z" }, + { url = "https://files.pythonhosted.org/packages/9c/d9/5f7756922cdd676869eca1c4e3c0cd0df60ed30199ffd775e319089cb3ed/markupsafe-3.0.3-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:116bb52f642a37c115f517494ea5feb03889e04df47eeff5b130b1808ce7c219", size = 12029, upload-time = "2025-09-27T18:36:43.257Z" }, + { url = "https://files.pythonhosted.org/packages/00/07/575a68c754943058c78f30db02ee03a64b3c638586fba6a6dd56830b30a3/markupsafe-3.0.3-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:133a43e73a802c5562be9bbcd03d090aa5a1fe899db609c29e8c8d815c5f6de6", size = 24374, upload-time = "2025-09-27T18:36:44.508Z" }, + { url = "https://files.pythonhosted.org/packages/a9/21/9b05698b46f218fc0e118e1f8168395c65c8a2c750ae2bab54fc4bd4e0e8/markupsafe-3.0.3-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:ccfcd093f13f0f0b7fdd0f198b90053bf7b2f02a3927a30e63f3ccc9df56b676", size = 22980, upload-time = "2025-09-27T18:36:45.385Z" }, + { url = "https://files.pythonhosted.org/packages/7f/71/544260864f893f18b6827315b988c146b559391e6e7e8f7252839b1b846a/markupsafe-3.0.3-cp313-cp313-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:509fa21c6deb7a7a273d629cf5ec029bc209d1a51178615ddf718f5918992ab9", size = 21990, upload-time = "2025-09-27T18:36:46.916Z" }, + { url = "https://files.pythonhosted.org/packages/c2/28/b50fc2f74d1ad761af2f5dcce7492648b983d00a65b8c0e0cb457c82ebbe/markupsafe-3.0.3-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:a4afe79fb3de0b7097d81da19090f4df4f8d3a2b3adaa8764138aac2e44f3af1", size = 23784, upload-time = "2025-09-27T18:36:47.884Z" }, + { url = "https://files.pythonhosted.org/packages/ed/76/104b2aa106a208da8b17a2fb72e033a5a9d7073c68f7e508b94916ed47a9/markupsafe-3.0.3-cp313-cp313-musllinux_1_2_riscv64.whl", hash = "sha256:795e7751525cae078558e679d646ae45574b47ed6e7771863fcc079a6171a0fc", size = 21588, upload-time = "2025-09-27T18:36:48.82Z" }, + { url = "https://files.pythonhosted.org/packages/b5/99/16a5eb2d140087ebd97180d95249b00a03aa87e29cc224056274f2e45fd6/markupsafe-3.0.3-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:8485f406a96febb5140bfeca44a73e3ce5116b2501ac54fe953e488fb1d03b12", size = 23041, upload-time = "2025-09-27T18:36:49.797Z" }, + { url = "https://files.pythonhosted.org/packages/19/bc/e7140ed90c5d61d77cea142eed9f9c303f4c4806f60a1044c13e3f1471d0/markupsafe-3.0.3-cp313-cp313-win32.whl", hash = "sha256:bdd37121970bfd8be76c5fb069c7751683bdf373db1ed6c010162b2a130248ed", size = 14543, upload-time = "2025-09-27T18:36:51.584Z" }, + { url = "https://files.pythonhosted.org/packages/05/73/c4abe620b841b6b791f2edc248f556900667a5a1cf023a6646967ae98335/markupsafe-3.0.3-cp313-cp313-win_amd64.whl", hash = "sha256:9a1abfdc021a164803f4d485104931fb8f8c1efd55bc6b748d2f5774e78b62c5", size = 15113, upload-time = "2025-09-27T18:36:52.537Z" }, + { url = "https://files.pythonhosted.org/packages/f0/3a/fa34a0f7cfef23cf9500d68cb7c32dd64ffd58a12b09225fb03dd37d5b80/markupsafe-3.0.3-cp313-cp313-win_arm64.whl", hash = "sha256:7e68f88e5b8799aa49c85cd116c932a1ac15caaa3f5db09087854d218359e485", size = 13911, upload-time = "2025-09-27T18:36:53.513Z" }, + { url = "https://files.pythonhosted.org/packages/e4/d7/e05cd7efe43a88a17a37b3ae96e79a19e846f3f456fe79c57ca61356ef01/markupsafe-3.0.3-cp313-cp313t-macosx_10_13_x86_64.whl", hash = "sha256:218551f6df4868a8d527e3062d0fb968682fe92054e89978594c28e642c43a73", size = 11658, upload-time = "2025-09-27T18:36:54.819Z" }, + { url = "https://files.pythonhosted.org/packages/99/9e/e412117548182ce2148bdeacdda3bb494260c0b0184360fe0d56389b523b/markupsafe-3.0.3-cp313-cp313t-macosx_11_0_arm64.whl", hash = "sha256:3524b778fe5cfb3452a09d31e7b5adefeea8c5be1d43c4f810ba09f2ceb29d37", size = 12066, upload-time = "2025-09-27T18:36:55.714Z" }, + { url = "https://files.pythonhosted.org/packages/bc/e6/fa0ffcda717ef64a5108eaa7b4f5ed28d56122c9a6d70ab8b72f9f715c80/markupsafe-3.0.3-cp313-cp313t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:4e885a3d1efa2eadc93c894a21770e4bc67899e3543680313b09f139e149ab19", size = 25639, upload-time = "2025-09-27T18:36:56.908Z" }, + { url = "https://files.pythonhosted.org/packages/96/ec/2102e881fe9d25fc16cb4b25d5f5cde50970967ffa5dddafdb771237062d/markupsafe-3.0.3-cp313-cp313t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:8709b08f4a89aa7586de0aadc8da56180242ee0ada3999749b183aa23df95025", size = 23569, upload-time = "2025-09-27T18:36:57.913Z" }, + { url = "https://files.pythonhosted.org/packages/4b/30/6f2fce1f1f205fc9323255b216ca8a235b15860c34b6798f810f05828e32/markupsafe-3.0.3-cp313-cp313t-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:b8512a91625c9b3da6f127803b166b629725e68af71f8184ae7e7d54686a56d6", size = 23284, upload-time = "2025-09-27T18:36:58.833Z" }, + { url = "https://files.pythonhosted.org/packages/58/47/4a0ccea4ab9f5dcb6f79c0236d954acb382202721e704223a8aafa38b5c8/markupsafe-3.0.3-cp313-cp313t-musllinux_1_2_aarch64.whl", hash = "sha256:9b79b7a16f7fedff2495d684f2b59b0457c3b493778c9eed31111be64d58279f", size = 24801, upload-time = "2025-09-27T18:36:59.739Z" }, + { url = "https://files.pythonhosted.org/packages/6a/70/3780e9b72180b6fecb83a4814d84c3bf4b4ae4bf0b19c27196104149734c/markupsafe-3.0.3-cp313-cp313t-musllinux_1_2_riscv64.whl", hash = "sha256:12c63dfb4a98206f045aa9563db46507995f7ef6d83b2f68eda65c307c6829eb", size = 22769, upload-time = "2025-09-27T18:37:00.719Z" }, + { url = "https://files.pythonhosted.org/packages/98/c5/c03c7f4125180fc215220c035beac6b9cb684bc7a067c84fc69414d315f5/markupsafe-3.0.3-cp313-cp313t-musllinux_1_2_x86_64.whl", hash = "sha256:8f71bc33915be5186016f675cd83a1e08523649b0e33efdb898db577ef5bb009", size = 23642, upload-time = "2025-09-27T18:37:01.673Z" }, + { url = "https://files.pythonhosted.org/packages/80/d6/2d1b89f6ca4bff1036499b1e29a1d02d282259f3681540e16563f27ebc23/markupsafe-3.0.3-cp313-cp313t-win32.whl", hash = "sha256:69c0b73548bc525c8cb9a251cddf1931d1db4d2258e9599c28c07ef3580ef354", size = 14612, upload-time = "2025-09-27T18:37:02.639Z" }, + { url = "https://files.pythonhosted.org/packages/2b/98/e48a4bfba0a0ffcf9925fe2d69240bfaa19c6f7507b8cd09c70684a53c1e/markupsafe-3.0.3-cp313-cp313t-win_amd64.whl", hash = "sha256:1b4b79e8ebf6b55351f0d91fe80f893b4743f104bff22e90697db1590e47a218", size = 15200, upload-time = "2025-09-27T18:37:03.582Z" }, + { url = "https://files.pythonhosted.org/packages/0e/72/e3cc540f351f316e9ed0f092757459afbc595824ca724cbc5a5d4263713f/markupsafe-3.0.3-cp313-cp313t-win_arm64.whl", hash = "sha256:ad2cf8aa28b8c020ab2fc8287b0f823d0a7d8630784c31e9ee5edea20f406287", size = 13973, upload-time = "2025-09-27T18:37:04.929Z" }, + { url = "https://files.pythonhosted.org/packages/33/8a/8e42d4838cd89b7dde187011e97fe6c3af66d8c044997d2183fbd6d31352/markupsafe-3.0.3-cp314-cp314-macosx_10_13_x86_64.whl", hash = "sha256:eaa9599de571d72e2daf60164784109f19978b327a3910d3e9de8c97b5b70cfe", size = 11619, upload-time = "2025-09-27T18:37:06.342Z" }, + { url = "https://files.pythonhosted.org/packages/b5/64/7660f8a4a8e53c924d0fa05dc3a55c9cee10bbd82b11c5afb27d44b096ce/markupsafe-3.0.3-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:c47a551199eb8eb2121d4f0f15ae0f923d31350ab9280078d1e5f12b249e0026", size = 12029, upload-time = "2025-09-27T18:37:07.213Z" }, + { url = "https://files.pythonhosted.org/packages/da/ef/e648bfd021127bef5fa12e1720ffed0c6cbb8310c8d9bea7266337ff06de/markupsafe-3.0.3-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:f34c41761022dd093b4b6896d4810782ffbabe30f2d443ff5f083e0cbbb8c737", size = 24408, upload-time = "2025-09-27T18:37:09.572Z" }, + { url = "https://files.pythonhosted.org/packages/41/3c/a36c2450754618e62008bf7435ccb0f88053e07592e6028a34776213d877/markupsafe-3.0.3-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:457a69a9577064c05a97c41f4e65148652db078a3a509039e64d3467b9e7ef97", size = 23005, upload-time = "2025-09-27T18:37:10.58Z" }, + { url = "https://files.pythonhosted.org/packages/bc/20/b7fdf89a8456b099837cd1dc21974632a02a999ec9bf7ca3e490aacd98e7/markupsafe-3.0.3-cp314-cp314-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:e8afc3f2ccfa24215f8cb28dcf43f0113ac3c37c2f0f0806d8c70e4228c5cf4d", size = 22048, upload-time = "2025-09-27T18:37:11.547Z" }, + { url = "https://files.pythonhosted.org/packages/9a/a7/591f592afdc734f47db08a75793a55d7fbcc6902a723ae4cfbab61010cc5/markupsafe-3.0.3-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:ec15a59cf5af7be74194f7ab02d0f59a62bdcf1a537677ce67a2537c9b87fcda", size = 23821, upload-time = "2025-09-27T18:37:12.48Z" }, + { url = "https://files.pythonhosted.org/packages/7d/33/45b24e4f44195b26521bc6f1a82197118f74df348556594bd2262bda1038/markupsafe-3.0.3-cp314-cp314-musllinux_1_2_riscv64.whl", hash = "sha256:0eb9ff8191e8498cca014656ae6b8d61f39da5f95b488805da4bb029cccbfbaf", size = 21606, upload-time = "2025-09-27T18:37:13.485Z" }, + { url = "https://files.pythonhosted.org/packages/ff/0e/53dfaca23a69fbfbbf17a4b64072090e70717344c52eaaaa9c5ddff1e5f0/markupsafe-3.0.3-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:2713baf880df847f2bece4230d4d094280f4e67b1e813eec43b4c0e144a34ffe", size = 23043, upload-time = "2025-09-27T18:37:14.408Z" }, + { url = "https://files.pythonhosted.org/packages/46/11/f333a06fc16236d5238bfe74daccbca41459dcd8d1fa952e8fbd5dccfb70/markupsafe-3.0.3-cp314-cp314-win32.whl", hash = "sha256:729586769a26dbceff69f7a7dbbf59ab6572b99d94576a5592625d5b411576b9", size = 14747, upload-time = "2025-09-27T18:37:15.36Z" }, + { url = "https://files.pythonhosted.org/packages/28/52/182836104b33b444e400b14f797212f720cbc9ed6ba34c800639d154e821/markupsafe-3.0.3-cp314-cp314-win_amd64.whl", hash = "sha256:bdc919ead48f234740ad807933cdf545180bfbe9342c2bb451556db2ed958581", size = 15341, upload-time = "2025-09-27T18:37:16.496Z" }, + { url = "https://files.pythonhosted.org/packages/6f/18/acf23e91bd94fd7b3031558b1f013adfa21a8e407a3fdb32745538730382/markupsafe-3.0.3-cp314-cp314-win_arm64.whl", hash = "sha256:5a7d5dc5140555cf21a6fefbdbf8723f06fcd2f63ef108f2854de715e4422cb4", size = 14073, upload-time = "2025-09-27T18:37:17.476Z" }, + { url = "https://files.pythonhosted.org/packages/3c/f0/57689aa4076e1b43b15fdfa646b04653969d50cf30c32a102762be2485da/markupsafe-3.0.3-cp314-cp314t-macosx_10_13_x86_64.whl", hash = "sha256:1353ef0c1b138e1907ae78e2f6c63ff67501122006b0f9abad68fda5f4ffc6ab", size = 11661, upload-time = "2025-09-27T18:37:18.453Z" }, + { url = "https://files.pythonhosted.org/packages/89/c3/2e67a7ca217c6912985ec766c6393b636fb0c2344443ff9d91404dc4c79f/markupsafe-3.0.3-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:1085e7fbddd3be5f89cc898938f42c0b3c711fdcb37d75221de2666af647c175", size = 12069, upload-time = "2025-09-27T18:37:19.332Z" }, + { url = "https://files.pythonhosted.org/packages/f0/00/be561dce4e6ca66b15276e184ce4b8aec61fe83662cce2f7d72bd3249d28/markupsafe-3.0.3-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:1b52b4fb9df4eb9ae465f8d0c228a00624de2334f216f178a995ccdcf82c4634", size = 25670, upload-time = "2025-09-27T18:37:20.245Z" }, + { url = "https://files.pythonhosted.org/packages/50/09/c419f6f5a92e5fadde27efd190eca90f05e1261b10dbd8cbcb39cd8ea1dc/markupsafe-3.0.3-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:fed51ac40f757d41b7c48425901843666a6677e3e8eb0abcff09e4ba6e664f50", size = 23598, upload-time = "2025-09-27T18:37:21.177Z" }, + { url = "https://files.pythonhosted.org/packages/22/44/a0681611106e0b2921b3033fc19bc53323e0b50bc70cffdd19f7d679bb66/markupsafe-3.0.3-cp314-cp314t-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:f190daf01f13c72eac4efd5c430a8de82489d9cff23c364c3ea822545032993e", size = 23261, upload-time = "2025-09-27T18:37:22.167Z" }, + { url = "https://files.pythonhosted.org/packages/5f/57/1b0b3f100259dc9fffe780cfb60d4be71375510e435efec3d116b6436d43/markupsafe-3.0.3-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:e56b7d45a839a697b5eb268c82a71bd8c7f6c94d6fd50c3d577fa39a9f1409f5", size = 24835, upload-time = "2025-09-27T18:37:23.296Z" }, + { url = "https://files.pythonhosted.org/packages/26/6a/4bf6d0c97c4920f1597cc14dd720705eca0bf7c787aebc6bb4d1bead5388/markupsafe-3.0.3-cp314-cp314t-musllinux_1_2_riscv64.whl", hash = "sha256:f3e98bb3798ead92273dc0e5fd0f31ade220f59a266ffd8a4f6065e0a3ce0523", size = 22733, upload-time = "2025-09-27T18:37:24.237Z" }, + { url = "https://files.pythonhosted.org/packages/14/c7/ca723101509b518797fedc2fdf79ba57f886b4aca8a7d31857ba3ee8281f/markupsafe-3.0.3-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:5678211cb9333a6468fb8d8be0305520aa073f50d17f089b5b4b477ea6e67fdc", size = 23672, upload-time = "2025-09-27T18:37:25.271Z" }, + { url = "https://files.pythonhosted.org/packages/fb/df/5bd7a48c256faecd1d36edc13133e51397e41b73bb77e1a69deab746ebac/markupsafe-3.0.3-cp314-cp314t-win32.whl", hash = "sha256:915c04ba3851909ce68ccc2b8e2cd691618c4dc4c4232fb7982bca3f41fd8c3d", size = 14819, upload-time = "2025-09-27T18:37:26.285Z" }, + { url = "https://files.pythonhosted.org/packages/1a/8a/0402ba61a2f16038b48b39bccca271134be00c5c9f0f623208399333c448/markupsafe-3.0.3-cp314-cp314t-win_amd64.whl", hash = "sha256:4faffd047e07c38848ce017e8725090413cd80cbc23d86e55c587bf979e579c9", size = 15426, upload-time = "2025-09-27T18:37:27.316Z" }, + { url = "https://files.pythonhosted.org/packages/70/bc/6f1c2f612465f5fa89b95bead1f44dcb607670fd42891d8fdcd5d039f4f4/markupsafe-3.0.3-cp314-cp314t-win_arm64.whl", hash = "sha256:32001d6a8fc98c8cb5c947787c5d08b0a50663d139f1305bac5885d98d9b40fa", size = 14146, upload-time = "2025-09-27T18:37:28.327Z" }, +] + +[[package]] +name = "node-semver" +version = "0.6.1" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/f1/4e/1d9a619dcfd9f42d0e874a5b47efa0923e84829886e6a47b45328a1f32f1/node-semver-0.6.1.tar.gz", hash = "sha256:4016f7c1071b0493f18db69ea02d3763e98a633606d7c7beca811e53b5ac66b7", size = 10972, upload-time = "2018-11-24T11:55:01.423Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/08/51/6cf3a2b18ca35cbe4ad3c7538a7c3dc0cb24e71629fb16e729c137d06432/node_semver-0.6.1-py3-none-any.whl", hash = "sha256:d4bf83873894591a0cbb6591910d96917fbadc9731e8e39e782d3a2fbc2b841e", size = 10937, upload-time = "2018-11-24T11:54:59.787Z" }, +] + +[[package]] +name = "nodeenv" +version = "1.10.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/24/bf/d1bda4f6168e0b2e9e5958945e01910052158313224ada5ce1fb2e1113b8/nodeenv-1.10.0.tar.gz", hash = "sha256:996c191ad80897d076bdfba80a41994c2b47c68e224c542b48feba42ba00f8bb", size = 55611, upload-time = "2025-12-20T14:08:54.006Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/88/b2/d0896bdcdc8d28a7fc5717c305f1a861c26e18c05047949fb371034d98bd/nodeenv-1.10.0-py2.py3-none-any.whl", hash = "sha256:5bb13e3eed2923615535339b3c620e76779af4cb4c6a90deccc9e36b274d3827", size = 23438, upload-time = "2025-12-20T14:08:52.782Z" }, +] + +[[package]] +name = "packaging" +version = "26.2" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/d7/f1/e7a6dd94a8d4a5626c03e4e99c87f241ba9e350cd9e6d75123f992427270/packaging-26.2.tar.gz", hash = "sha256:ff452ff5a3e828ce110190feff1178bb1f2ea2281fa2075aadb987c2fb221661", size = 228134, upload-time = "2026-04-24T20:15:23.917Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/df/b2/87e62e8c3e2f4b32e5fe99e0b86d576da1312593b39f47d8ceef365e95ed/packaging-26.2-py3-none-any.whl", hash = "sha256:5fc45236b9446107ff2415ce77c807cee2862cb6fac22b8a73826d0693b0980e", size = 100195, upload-time = "2026-04-24T20:15:22.081Z" }, +] + +[[package]] +name = "patch-ng" +version = "1.17.4" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/c1/b2/ad3cd464101435fdf642d20e0e5e782b4edaef1affdf2adfc5c75660225b/patch-ng-1.17.4.tar.gz", hash = "sha256:627abc5bd723c8b481e96849b9734b10065426224d4d22cd44137004ac0d4ace", size = 17395, upload-time = "2020-03-18T15:01:49.128Z" } + +[[package]] +name = "platformdirs" +version = "4.10.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/d7/47/e4501f49c178ae1d9f4a75073fda4204f52647993f075a9db4d14930e0c5/platformdirs-4.10.0.tar.gz", hash = "sha256:31e761a6a0ca04faf7353ea759bdba55652be214725111e5aac52dfa29d4bef7", size = 31224, upload-time = "2026-05-28T03:32:53.587Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/81/e6/cd9575ac904136b3cbf7aa7ee819ef86eedb7274e46f230e94ea4342e729/platformdirs-4.10.0-py3-none-any.whl", hash = "sha256:fb516cdb12eb0d857d0cd85a7c57cea4d060bee4578d6cf5a14dfdf8cbf8784a", size = 22743, upload-time = "2026-05-28T03:32:52.175Z" }, +] + +[[package]] +name = "pluginbase" +version = "1.0.1" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/f3/07/753451e80d2b0bf3bceec1162e8d23638ac3cb18d1c38ad340c586e90b42/pluginbase-1.0.1.tar.gz", hash = "sha256:ff6c33a98fce232e9c73841d787a643de574937069f0d18147028d70d7dee287", size = 43588, upload-time = "2021-05-16T16:25:40.715Z" } + +[[package]] +name = "pre-commit" +version = "4.6.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "cfgv" }, + { name = "identify" }, + { name = "nodeenv" }, + { name = "pyyaml" }, + { name = "virtualenv" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/8e/22/2de9408ac81acbb8a7d05d4cc064a152ccf33b3d480ebe0cd292153db239/pre_commit-4.6.0.tar.gz", hash = "sha256:718d2208cef53fdc38206e40524a6d4d9576d103eb16f0fec11c875e7716e9d9", size = 198525, upload-time = "2026-04-21T20:31:41.613Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/80/6e/4b28b62ecb6aae56769c34a8ff1d661473ec1e9519e2d5f8b2c150086b26/pre_commit-4.6.0-py2.py3-none-any.whl", hash = "sha256:e2cf246f7299edcabcf15f9b0571fdce06058527f0a06535068a86d38089f29b", size = 226472, upload-time = "2026-04-21T20:31:40.092Z" }, +] + +[[package]] +name = "pygments" +version = "2.20.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/c3/b2/bc9c9196916376152d655522fdcebac55e66de6603a76a02bca1b6414f6c/pygments-2.20.0.tar.gz", hash = "sha256:6757cd03768053ff99f3039c1a36d6c0aa0b263438fcab17520b30a303a82b5f", size = 4955991, upload-time = "2026-03-29T13:29:33.898Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/f4/7e/a72dd26f3b0f4f2bf1dd8923c85f7ceb43172af56d63c7383eb62b332364/pygments-2.20.0-py3-none-any.whl", hash = "sha256:81a9e26dd42fd28a23a2d169d86d7ac03b46e2f8b59ed4698fb4785f946d0176", size = 1231151, upload-time = "2026-03-29T13:29:30.038Z" }, +] + +[[package]] +name = "pyjwt" +version = "2.13.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "typing-extensions", marker = "python_full_version < '3.11'" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/3b/81/58d0ac84e1ef3a3843791d6954d94c0b33d526c75eeb1efbce9d0a4c4077/pyjwt-2.13.0.tar.gz", hash = "sha256:41571c89ca91598c79e8ef18a2d07367d4810fbbd6f637794879baf1b7703423", size = 107515, upload-time = "2026-05-21T19:54:36.618Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/a3/5e/ecf12fdb62546d64385c158514e9b2b671f7832108ef2ecd2020ce0af2d1/pyjwt-2.13.0-py3-none-any.whl", hash = "sha256:66adcc2aff09b3f1bbd95fc1e1577df8ac8723c978552fd43304c8a290ac5728", size = 31274, upload-time = "2026-05-21T19:54:35.362Z" }, +] + +[[package]] +name = "python-dateutil" +version = "2.9.0.post0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "six" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/66/c0/0c8b6ad9f17a802ee498c46e004a0eb49bc148f2fd230864601a86dcf6db/python-dateutil-2.9.0.post0.tar.gz", hash = "sha256:37dd54208da7e1cd875388217d5e00ebd4179249f90fb72437e91a35459a0ad3", size = 342432, upload-time = "2024-03-01T18:36:20.211Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/ec/57/56b9bcc3c9c6a792fcbaf139543cee77261f3651ca9da0c93f5c1221264b/python_dateutil-2.9.0.post0-py2.py3-none-any.whl", hash = "sha256:a8b2bc7bffae282281c8140a97d3aa9c14da0b136dfe83f850eea9a5f7470427", size = 229892, upload-time = "2024-03-01T18:36:18.57Z" }, +] + +[[package]] +name = "python-discovery" +version = "1.4.2" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "filelock" }, + { name = "platformdirs" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/0b/1a/cbbaf13b730abb0a16b964d984e19f2fe520c21a4dc664051359a3f5a9e7/python_discovery-1.4.2.tar.gz", hash = "sha256:8f3746c4b4968d22afbb97d36e1a0e5b66e6c0f297290f2e95f05b9b8bf18690", size = 70277, upload-time = "2026-06-11T16:10:42.383Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/1a/82/a70006589557f267f15bd384c0642ad49f0d97b690c3a05b166b9dcbad3b/python_discovery-1.4.2-py3-none-any.whl", hash = "sha256:475803f53b7b2ed6e490e27373f9d8340f7d2eebf9acdaf645d7d714c97bb500", size = 33886, upload-time = "2026-06-11T16:10:41.192Z" }, +] + +[[package]] +name = "pyyaml" +version = "6.0.3" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/05/8e/961c0007c59b8dd7729d542c61a4d537767a59645b82a0b521206e1e25c2/pyyaml-6.0.3.tar.gz", hash = "sha256:d76623373421df22fb4cf8817020cbb7ef15c725b9d5e45f17e189bfc384190f", size = 130960, upload-time = "2025-09-25T21:33:16.546Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/f4/a0/39350dd17dd6d6c6507025c0e53aef67a9293a6d37d3511f23ea510d5800/pyyaml-6.0.3-cp310-cp310-macosx_10_13_x86_64.whl", hash = "sha256:214ed4befebe12df36bcc8bc2b64b396ca31be9304b8f59e25c11cf94a4c033b", size = 184227, upload-time = "2025-09-25T21:31:46.04Z" }, + { url = "https://files.pythonhosted.org/packages/05/14/52d505b5c59ce73244f59c7a50ecf47093ce4765f116cdb98286a71eeca2/pyyaml-6.0.3-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:02ea2dfa234451bbb8772601d7b8e426c2bfa197136796224e50e35a78777956", size = 174019, upload-time = "2025-09-25T21:31:47.706Z" }, + { url = "https://files.pythonhosted.org/packages/43/f7/0e6a5ae5599c838c696adb4e6330a59f463265bfa1e116cfd1fbb0abaaae/pyyaml-6.0.3-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:b30236e45cf30d2b8e7b3e85881719e98507abed1011bf463a8fa23e9c3e98a8", size = 740646, upload-time = "2025-09-25T21:31:49.21Z" }, + { url = "https://files.pythonhosted.org/packages/2f/3a/61b9db1d28f00f8fd0ae760459a5c4bf1b941baf714e207b6eb0657d2578/pyyaml-6.0.3-cp310-cp310-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:66291b10affd76d76f54fad28e22e51719ef9ba22b29e1d7d03d6777a9174198", size = 840793, upload-time = "2025-09-25T21:31:50.735Z" }, + { url = "https://files.pythonhosted.org/packages/7a/1e/7acc4f0e74c4b3d9531e24739e0ab832a5edf40e64fbae1a9c01941cabd7/pyyaml-6.0.3-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:9c7708761fccb9397fe64bbc0395abcae8c4bf7b0eac081e12b809bf47700d0b", size = 770293, upload-time = "2025-09-25T21:31:51.828Z" }, + { url = "https://files.pythonhosted.org/packages/8b/ef/abd085f06853af0cd59fa5f913d61a8eab65d7639ff2a658d18a25d6a89d/pyyaml-6.0.3-cp310-cp310-musllinux_1_2_aarch64.whl", hash = "sha256:418cf3f2111bc80e0933b2cd8cd04f286338bb88bdc7bc8e6dd775ebde60b5e0", size = 732872, upload-time = "2025-09-25T21:31:53.282Z" }, + { url = "https://files.pythonhosted.org/packages/1f/15/2bc9c8faf6450a8b3c9fc5448ed869c599c0a74ba2669772b1f3a0040180/pyyaml-6.0.3-cp310-cp310-musllinux_1_2_x86_64.whl", hash = "sha256:5e0b74767e5f8c593e8c9b5912019159ed0533c70051e9cce3e8b6aa699fcd69", size = 758828, upload-time = "2025-09-25T21:31:54.807Z" }, + { url = "https://files.pythonhosted.org/packages/a3/00/531e92e88c00f4333ce359e50c19b8d1de9fe8d581b1534e35ccfbc5f393/pyyaml-6.0.3-cp310-cp310-win32.whl", hash = "sha256:28c8d926f98f432f88adc23edf2e6d4921ac26fb084b028c733d01868d19007e", size = 142415, upload-time = "2025-09-25T21:31:55.885Z" }, + { url = "https://files.pythonhosted.org/packages/2a/fa/926c003379b19fca39dd4634818b00dec6c62d87faf628d1394e137354d4/pyyaml-6.0.3-cp310-cp310-win_amd64.whl", hash = "sha256:bdb2c67c6c1390b63c6ff89f210c8fd09d9a1217a465701eac7316313c915e4c", size = 158561, upload-time = "2025-09-25T21:31:57.406Z" }, + { url = "https://files.pythonhosted.org/packages/6d/16/a95b6757765b7b031c9374925bb718d55e0a9ba8a1b6a12d25962ea44347/pyyaml-6.0.3-cp311-cp311-macosx_10_13_x86_64.whl", hash = "sha256:44edc647873928551a01e7a563d7452ccdebee747728c1080d881d68af7b997e", size = 185826, upload-time = "2025-09-25T21:31:58.655Z" }, + { url = "https://files.pythonhosted.org/packages/16/19/13de8e4377ed53079ee996e1ab0a9c33ec2faf808a4647b7b4c0d46dd239/pyyaml-6.0.3-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:652cb6edd41e718550aad172851962662ff2681490a8a711af6a4d288dd96824", size = 175577, upload-time = "2025-09-25T21:32:00.088Z" }, + { url = "https://files.pythonhosted.org/packages/0c/62/d2eb46264d4b157dae1275b573017abec435397aa59cbcdab6fc978a8af4/pyyaml-6.0.3-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:10892704fc220243f5305762e276552a0395f7beb4dbf9b14ec8fd43b57f126c", size = 775556, upload-time = "2025-09-25T21:32:01.31Z" }, + { url = "https://files.pythonhosted.org/packages/10/cb/16c3f2cf3266edd25aaa00d6c4350381c8b012ed6f5276675b9eba8d9ff4/pyyaml-6.0.3-cp311-cp311-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:850774a7879607d3a6f50d36d04f00ee69e7fc816450e5f7e58d7f17f1ae5c00", size = 882114, upload-time = "2025-09-25T21:32:03.376Z" }, + { url = "https://files.pythonhosted.org/packages/71/60/917329f640924b18ff085ab889a11c763e0b573da888e8404ff486657602/pyyaml-6.0.3-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:b8bb0864c5a28024fac8a632c443c87c5aa6f215c0b126c449ae1a150412f31d", size = 806638, upload-time = "2025-09-25T21:32:04.553Z" }, + { url = "https://files.pythonhosted.org/packages/dd/6f/529b0f316a9fd167281a6c3826b5583e6192dba792dd55e3203d3f8e655a/pyyaml-6.0.3-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:1d37d57ad971609cf3c53ba6a7e365e40660e3be0e5175fa9f2365a379d6095a", size = 767463, upload-time = "2025-09-25T21:32:06.152Z" }, + { url = "https://files.pythonhosted.org/packages/f2/6a/b627b4e0c1dd03718543519ffb2f1deea4a1e6d42fbab8021936a4d22589/pyyaml-6.0.3-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:37503bfbfc9d2c40b344d06b2199cf0e96e97957ab1c1b546fd4f87e53e5d3e4", size = 794986, upload-time = "2025-09-25T21:32:07.367Z" }, + { url = "https://files.pythonhosted.org/packages/45/91/47a6e1c42d9ee337c4839208f30d9f09caa9f720ec7582917b264defc875/pyyaml-6.0.3-cp311-cp311-win32.whl", hash = "sha256:8098f252adfa6c80ab48096053f512f2321f0b998f98150cea9bd23d83e1467b", size = 142543, upload-time = "2025-09-25T21:32:08.95Z" }, + { url = "https://files.pythonhosted.org/packages/da/e3/ea007450a105ae919a72393cb06f122f288ef60bba2dc64b26e2646fa315/pyyaml-6.0.3-cp311-cp311-win_amd64.whl", hash = "sha256:9f3bfb4965eb874431221a3ff3fdcddc7e74e3b07799e0e84ca4a0f867d449bf", size = 158763, upload-time = "2025-09-25T21:32:09.96Z" }, + { url = "https://files.pythonhosted.org/packages/d1/33/422b98d2195232ca1826284a76852ad5a86fe23e31b009c9886b2d0fb8b2/pyyaml-6.0.3-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:7f047e29dcae44602496db43be01ad42fc6f1cc0d8cd6c83d342306c32270196", size = 182063, upload-time = "2025-09-25T21:32:11.445Z" }, + { url = "https://files.pythonhosted.org/packages/89/a0/6cf41a19a1f2f3feab0e9c0b74134aa2ce6849093d5517a0c550fe37a648/pyyaml-6.0.3-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:fc09d0aa354569bc501d4e787133afc08552722d3ab34836a80547331bb5d4a0", size = 173973, upload-time = "2025-09-25T21:32:12.492Z" }, + { url = "https://files.pythonhosted.org/packages/ed/23/7a778b6bd0b9a8039df8b1b1d80e2e2ad78aa04171592c8a5c43a56a6af4/pyyaml-6.0.3-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:9149cad251584d5fb4981be1ecde53a1ca46c891a79788c0df828d2f166bda28", size = 775116, upload-time = "2025-09-25T21:32:13.652Z" }, + { url = "https://files.pythonhosted.org/packages/65/30/d7353c338e12baef4ecc1b09e877c1970bd3382789c159b4f89d6a70dc09/pyyaml-6.0.3-cp312-cp312-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:5fdec68f91a0c6739b380c83b951e2c72ac0197ace422360e6d5a959d8d97b2c", size = 844011, upload-time = "2025-09-25T21:32:15.21Z" }, + { url = "https://files.pythonhosted.org/packages/8b/9d/b3589d3877982d4f2329302ef98a8026e7f4443c765c46cfecc8858c6b4b/pyyaml-6.0.3-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:ba1cc08a7ccde2d2ec775841541641e4548226580ab850948cbfda66a1befcdc", size = 807870, upload-time = "2025-09-25T21:32:16.431Z" }, + { url = "https://files.pythonhosted.org/packages/05/c0/b3be26a015601b822b97d9149ff8cb5ead58c66f981e04fedf4e762f4bd4/pyyaml-6.0.3-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:8dc52c23056b9ddd46818a57b78404882310fb473d63f17b07d5c40421e47f8e", size = 761089, upload-time = "2025-09-25T21:32:17.56Z" }, + { url = "https://files.pythonhosted.org/packages/be/8e/98435a21d1d4b46590d5459a22d88128103f8da4c2d4cb8f14f2a96504e1/pyyaml-6.0.3-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:41715c910c881bc081f1e8872880d3c650acf13dfa8214bad49ed4cede7c34ea", size = 790181, upload-time = "2025-09-25T21:32:18.834Z" }, + { url = "https://files.pythonhosted.org/packages/74/93/7baea19427dcfbe1e5a372d81473250b379f04b1bd3c4c5ff825e2327202/pyyaml-6.0.3-cp312-cp312-win32.whl", hash = "sha256:96b533f0e99f6579b3d4d4995707cf36df9100d67e0c8303a0c55b27b5f99bc5", size = 137658, upload-time = "2025-09-25T21:32:20.209Z" }, + { url = "https://files.pythonhosted.org/packages/86/bf/899e81e4cce32febab4fb42bb97dcdf66bc135272882d1987881a4b519e9/pyyaml-6.0.3-cp312-cp312-win_amd64.whl", hash = "sha256:5fcd34e47f6e0b794d17de1b4ff496c00986e1c83f7ab2fb8fcfe9616ff7477b", size = 154003, upload-time = "2025-09-25T21:32:21.167Z" }, + { url = "https://files.pythonhosted.org/packages/1a/08/67bd04656199bbb51dbed1439b7f27601dfb576fb864099c7ef0c3e55531/pyyaml-6.0.3-cp312-cp312-win_arm64.whl", hash = "sha256:64386e5e707d03a7e172c0701abfb7e10f0fb753ee1d773128192742712a98fd", size = 140344, upload-time = "2025-09-25T21:32:22.617Z" }, + { url = "https://files.pythonhosted.org/packages/d1/11/0fd08f8192109f7169db964b5707a2f1e8b745d4e239b784a5a1dd80d1db/pyyaml-6.0.3-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:8da9669d359f02c0b91ccc01cac4a67f16afec0dac22c2ad09f46bee0697eba8", size = 181669, upload-time = "2025-09-25T21:32:23.673Z" }, + { url = "https://files.pythonhosted.org/packages/b1/16/95309993f1d3748cd644e02e38b75d50cbc0d9561d21f390a76242ce073f/pyyaml-6.0.3-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:2283a07e2c21a2aa78d9c4442724ec1eb15f5e42a723b99cb3d822d48f5f7ad1", size = 173252, upload-time = "2025-09-25T21:32:25.149Z" }, + { url = "https://files.pythonhosted.org/packages/50/31/b20f376d3f810b9b2371e72ef5adb33879b25edb7a6d072cb7ca0c486398/pyyaml-6.0.3-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:ee2922902c45ae8ccada2c5b501ab86c36525b883eff4255313a253a3160861c", size = 767081, upload-time = "2025-09-25T21:32:26.575Z" }, + { url = "https://files.pythonhosted.org/packages/49/1e/a55ca81e949270d5d4432fbbd19dfea5321eda7c41a849d443dc92fd1ff7/pyyaml-6.0.3-cp313-cp313-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:a33284e20b78bd4a18c8c2282d549d10bc8408a2a7ff57653c0cf0b9be0afce5", size = 841159, upload-time = "2025-09-25T21:32:27.727Z" }, + { url = "https://files.pythonhosted.org/packages/74/27/e5b8f34d02d9995b80abcef563ea1f8b56d20134d8f4e5e81733b1feceb2/pyyaml-6.0.3-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:0f29edc409a6392443abf94b9cf89ce99889a1dd5376d94316ae5145dfedd5d6", size = 801626, upload-time = "2025-09-25T21:32:28.878Z" }, + { url = "https://files.pythonhosted.org/packages/f9/11/ba845c23988798f40e52ba45f34849aa8a1f2d4af4b798588010792ebad6/pyyaml-6.0.3-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:f7057c9a337546edc7973c0d3ba84ddcdf0daa14533c2065749c9075001090e6", size = 753613, upload-time = "2025-09-25T21:32:30.178Z" }, + { url = "https://files.pythonhosted.org/packages/3d/e0/7966e1a7bfc0a45bf0a7fb6b98ea03fc9b8d84fa7f2229e9659680b69ee3/pyyaml-6.0.3-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:eda16858a3cab07b80edaf74336ece1f986ba330fdb8ee0d6c0d68fe82bc96be", size = 794115, upload-time = "2025-09-25T21:32:31.353Z" }, + { url = "https://files.pythonhosted.org/packages/de/94/980b50a6531b3019e45ddeada0626d45fa85cbe22300844a7983285bed3b/pyyaml-6.0.3-cp313-cp313-win32.whl", hash = "sha256:d0eae10f8159e8fdad514efdc92d74fd8d682c933a6dd088030f3834bc8e6b26", size = 137427, upload-time = "2025-09-25T21:32:32.58Z" }, + { url = "https://files.pythonhosted.org/packages/97/c9/39d5b874e8b28845e4ec2202b5da735d0199dbe5b8fb85f91398814a9a46/pyyaml-6.0.3-cp313-cp313-win_amd64.whl", hash = "sha256:79005a0d97d5ddabfeeea4cf676af11e647e41d81c9a7722a193022accdb6b7c", size = 154090, upload-time = "2025-09-25T21:32:33.659Z" }, + { url = "https://files.pythonhosted.org/packages/73/e8/2bdf3ca2090f68bb3d75b44da7bbc71843b19c9f2b9cb9b0f4ab7a5a4329/pyyaml-6.0.3-cp313-cp313-win_arm64.whl", hash = "sha256:5498cd1645aa724a7c71c8f378eb29ebe23da2fc0d7a08071d89469bf1d2defb", size = 140246, upload-time = "2025-09-25T21:32:34.663Z" }, + { url = "https://files.pythonhosted.org/packages/9d/8c/f4bd7f6465179953d3ac9bc44ac1a8a3e6122cf8ada906b4f96c60172d43/pyyaml-6.0.3-cp314-cp314-macosx_10_13_x86_64.whl", hash = "sha256:8d1fab6bb153a416f9aeb4b8763bc0f22a5586065f86f7664fc23339fc1c1fac", size = 181814, upload-time = "2025-09-25T21:32:35.712Z" }, + { url = "https://files.pythonhosted.org/packages/bd/9c/4d95bb87eb2063d20db7b60faa3840c1b18025517ae857371c4dd55a6b3a/pyyaml-6.0.3-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:34d5fcd24b8445fadc33f9cf348c1047101756fd760b4dacb5c3e99755703310", size = 173809, upload-time = "2025-09-25T21:32:36.789Z" }, + { url = "https://files.pythonhosted.org/packages/92/b5/47e807c2623074914e29dabd16cbbdd4bf5e9b2db9f8090fa64411fc5382/pyyaml-6.0.3-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:501a031947e3a9025ed4405a168e6ef5ae3126c59f90ce0cd6f2bfc477be31b7", size = 766454, upload-time = "2025-09-25T21:32:37.966Z" }, + { url = "https://files.pythonhosted.org/packages/02/9e/e5e9b168be58564121efb3de6859c452fccde0ab093d8438905899a3a483/pyyaml-6.0.3-cp314-cp314-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:b3bc83488de33889877a0f2543ade9f70c67d66d9ebb4ac959502e12de895788", size = 836355, upload-time = "2025-09-25T21:32:39.178Z" }, + { url = "https://files.pythonhosted.org/packages/88/f9/16491d7ed2a919954993e48aa941b200f38040928474c9e85ea9e64222c3/pyyaml-6.0.3-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:c458b6d084f9b935061bc36216e8a69a7e293a2f1e68bf956dcd9e6cbcd143f5", size = 794175, upload-time = "2025-09-25T21:32:40.865Z" }, + { url = "https://files.pythonhosted.org/packages/dd/3f/5989debef34dc6397317802b527dbbafb2b4760878a53d4166579111411e/pyyaml-6.0.3-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:7c6610def4f163542a622a73fb39f534f8c101d690126992300bf3207eab9764", size = 755228, upload-time = "2025-09-25T21:32:42.084Z" }, + { url = "https://files.pythonhosted.org/packages/d7/ce/af88a49043cd2e265be63d083fc75b27b6ed062f5f9fd6cdc223ad62f03e/pyyaml-6.0.3-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:5190d403f121660ce8d1d2c1bb2ef1bd05b5f68533fc5c2ea899bd15f4399b35", size = 789194, upload-time = "2025-09-25T21:32:43.362Z" }, + { url = "https://files.pythonhosted.org/packages/23/20/bb6982b26a40bb43951265ba29d4c246ef0ff59c9fdcdf0ed04e0687de4d/pyyaml-6.0.3-cp314-cp314-win_amd64.whl", hash = "sha256:4a2e8cebe2ff6ab7d1050ecd59c25d4c8bd7e6f400f5f82b96557ac0abafd0ac", size = 156429, upload-time = "2025-09-25T21:32:57.844Z" }, + { url = "https://files.pythonhosted.org/packages/f4/f4/a4541072bb9422c8a883ab55255f918fa378ecf083f5b85e87fc2b4eda1b/pyyaml-6.0.3-cp314-cp314-win_arm64.whl", hash = "sha256:93dda82c9c22deb0a405ea4dc5f2d0cda384168e466364dec6255b293923b2f3", size = 143912, upload-time = "2025-09-25T21:32:59.247Z" }, + { url = "https://files.pythonhosted.org/packages/7c/f9/07dd09ae774e4616edf6cda684ee78f97777bdd15847253637a6f052a62f/pyyaml-6.0.3-cp314-cp314t-macosx_10_13_x86_64.whl", hash = "sha256:02893d100e99e03eda1c8fd5c441d8c60103fd175728e23e431db1b589cf5ab3", size = 189108, upload-time = "2025-09-25T21:32:44.377Z" }, + { url = "https://files.pythonhosted.org/packages/4e/78/8d08c9fb7ce09ad8c38ad533c1191cf27f7ae1effe5bb9400a46d9437fcf/pyyaml-6.0.3-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:c1ff362665ae507275af2853520967820d9124984e0f7466736aea23d8611fba", size = 183641, upload-time = "2025-09-25T21:32:45.407Z" }, + { url = "https://files.pythonhosted.org/packages/7b/5b/3babb19104a46945cf816d047db2788bcaf8c94527a805610b0289a01c6b/pyyaml-6.0.3-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:6adc77889b628398debc7b65c073bcb99c4a0237b248cacaf3fe8a557563ef6c", size = 831901, upload-time = "2025-09-25T21:32:48.83Z" }, + { url = "https://files.pythonhosted.org/packages/8b/cc/dff0684d8dc44da4d22a13f35f073d558c268780ce3c6ba1b87055bb0b87/pyyaml-6.0.3-cp314-cp314t-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:a80cb027f6b349846a3bf6d73b5e95e782175e52f22108cfa17876aaeff93702", size = 861132, upload-time = "2025-09-25T21:32:50.149Z" }, + { url = "https://files.pythonhosted.org/packages/b1/5e/f77dc6b9036943e285ba76b49e118d9ea929885becb0a29ba8a7c75e29fe/pyyaml-6.0.3-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:00c4bdeba853cc34e7dd471f16b4114f4162dc03e6b7afcc2128711f0eca823c", size = 839261, upload-time = "2025-09-25T21:32:51.808Z" }, + { url = "https://files.pythonhosted.org/packages/ce/88/a9db1376aa2a228197c58b37302f284b5617f56a5d959fd1763fb1675ce6/pyyaml-6.0.3-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:66e1674c3ef6f541c35191caae2d429b967b99e02040f5ba928632d9a7f0f065", size = 805272, upload-time = "2025-09-25T21:32:52.941Z" }, + { url = "https://files.pythonhosted.org/packages/da/92/1446574745d74df0c92e6aa4a7b0b3130706a4142b2d1a5869f2eaa423c6/pyyaml-6.0.3-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:16249ee61e95f858e83976573de0f5b2893b3677ba71c9dd36b9cf8be9ac6d65", size = 829923, upload-time = "2025-09-25T21:32:54.537Z" }, + { url = "https://files.pythonhosted.org/packages/f0/7a/1c7270340330e575b92f397352af856a8c06f230aa3e76f86b39d01b416a/pyyaml-6.0.3-cp314-cp314t-win_amd64.whl", hash = "sha256:4ad1906908f2f5ae4e5a8ddfce73c320c2a1429ec52eafd27138b7f1cbe341c9", size = 174062, upload-time = "2025-09-25T21:32:55.767Z" }, + { url = "https://files.pythonhosted.org/packages/f1/12/de94a39c2ef588c7e6455cfbe7343d3b2dc9d6b6b2f40c4c6565744c873d/pyyaml-6.0.3-cp314-cp314t-win_arm64.whl", hash = "sha256:ebc55a14a21cb14062aa4162f906cd962b28e2e9ea38f9b4391244cd8de4ae0b", size = 149341, upload-time = "2025-09-25T21:32:56.828Z" }, +] + +[[package]] +name = "qe-qasm-dev" +version = "0.0.0" +source = { virtual = "." } + +[package.dev-dependencies] +dev = [ + { name = "cmake" }, + { name = "conan" }, + { name = "pre-commit" }, + { name = "setuptools-scm" }, +] + +[package.metadata] + +[package.metadata.requires-dev] +dev = [ + { name = "cmake" }, + { name = "conan", specifier = "<2.0" }, + { name = "pre-commit" }, + { name = "setuptools-scm", specifier = ">=6.0,<8.0" }, +] + +[[package]] +name = "requests" +version = "2.34.2" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "certifi" }, + { name = "charset-normalizer" }, + { name = "idna" }, + { name = "urllib3" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/ac/c3/e2a2b89f2d3e2179abd6d00ebd70bff6273f37fb3e0cc209f48b39d00cbf/requests-2.34.2.tar.gz", hash = "sha256:f288924cae4e29463698d6d60bc6a4da69c89185ad1e0bcc4104f584e960b9ed", size = 142856, upload-time = "2026-05-14T19:25:27.735Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/a0/f4/c67b0b3f1b9245e8d266f0f112c500d50e5b4e83cb6f3b71b6528104182a/requests-2.34.2-py3-none-any.whl", hash = "sha256:2a0d60c172f83ac6ab31e4554906c0f3b3588d37b5cb939b1c061f4907e278e0", size = 73075, upload-time = "2026-05-14T19:25:26.443Z" }, +] + +[[package]] +name = "setuptools" +version = "82.0.1" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/4f/db/cfac1baf10650ab4d1c111714410d2fbb77ac5a616db26775db562c8fab2/setuptools-82.0.1.tar.gz", hash = "sha256:7d872682c5d01cfde07da7bccc7b65469d3dca203318515ada1de5eda35efbf9", size = 1152316, upload-time = "2026-03-09T12:47:17.221Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/9d/76/f789f7a86709c6b087c5a2f52f911838cad707cc613162401badc665acfe/setuptools-82.0.1-py3-none-any.whl", hash = "sha256:a59e362652f08dcd477c78bb6e7bd9d80a7995bc73ce773050228a348ce2e5bb", size = 1006223, upload-time = "2026-03-09T12:47:15.026Z" }, +] + +[[package]] +name = "setuptools-scm" +version = "7.1.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "packaging" }, + { name = "setuptools" }, + { name = "tomli", marker = "python_full_version < '3.11'" }, + { name = "typing-extensions" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/98/12/2c1e579bb968759fc512391473340d0661b1a8c96a59fb7c65b02eec1321/setuptools_scm-7.1.0.tar.gz", hash = "sha256:6c508345a771aad7d56ebff0e70628bf2b0ec7573762be9960214730de278f27", size = 71904, upload-time = "2022-12-17T16:07:06.396Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/1d/66/8f42c941be949ef2b22fe905d850c794e7c170a526023612aad5f3a121ad/setuptools_scm-7.1.0-py3-none-any.whl", hash = "sha256:73988b6d848709e2af142aa48c986ea29592bbcfca5375678064708205253d8e", size = 43829, upload-time = "2022-12-17T16:07:04.715Z" }, +] + +[[package]] +name = "six" +version = "1.16.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/71/39/171f1c67cd00715f190ba0b100d606d440a28c93c7714febeca8b79af85e/six-1.16.0.tar.gz", hash = "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926", size = 34041, upload-time = "2021-05-05T14:18:18.379Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/d9/5a/e7c31adbe875f2abbb91bd84cf2dc52d792b5a01506781dbcf25c91daf11/six-1.16.0-py2.py3-none-any.whl", hash = "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254", size = 11053, upload-time = "2021-05-05T14:18:17.237Z" }, +] + +[[package]] +name = "tomli" +version = "2.4.1" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/22/de/48c59722572767841493b26183a0d1cc411d54fd759c5607c4590b6563a6/tomli-2.4.1.tar.gz", hash = "sha256:7c7e1a961a0b2f2472c1ac5b69affa0ae1132c39adcb67aba98568702b9cc23f", size = 17543, upload-time = "2026-03-25T20:22:03.828Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/f4/11/db3d5885d8528263d8adc260bb2d28ebf1270b96e98f0e0268d32b8d9900/tomli-2.4.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:f8f0fc26ec2cc2b965b7a3b87cd19c5c6b8c5e5f436b984e85f486d652285c30", size = 154704, upload-time = "2026-03-25T20:21:10.473Z" }, + { url = "https://files.pythonhosted.org/packages/6d/f7/675db52c7e46064a9aa928885a9b20f4124ecb9bc2e1ce74c9106648d202/tomli-2.4.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:4ab97e64ccda8756376892c53a72bd1f964e519c77236368527f758fbc36a53a", size = 149454, upload-time = "2026-03-25T20:21:12.036Z" }, + { url = "https://files.pythonhosted.org/packages/61/71/81c50943cf953efa35bce7646caab3cf457a7d8c030b27cfb40d7235f9ee/tomli-2.4.1-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:96481a5786729fd470164b47cdb3e0e58062a496f455ee41b4403be77cb5a076", size = 237561, upload-time = "2026-03-25T20:21:13.098Z" }, + { url = "https://files.pythonhosted.org/packages/48/c1/f41d9cb618acccca7df82aaf682f9b49013c9397212cb9f53219e3abac37/tomli-2.4.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:5a881ab208c0baf688221f8cecc5401bd291d67e38a1ac884d6736cbcd8247e9", size = 243824, upload-time = "2026-03-25T20:21:14.569Z" }, + { url = "https://files.pythonhosted.org/packages/22/e4/5a816ecdd1f8ca51fb756ef684b90f2780afc52fc67f987e3c61d800a46d/tomli-2.4.1-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:47149d5bd38761ac8be13a84864bf0b7b70bc051806bc3669ab1cbc56216b23c", size = 242227, upload-time = "2026-03-25T20:21:15.712Z" }, + { url = "https://files.pythonhosted.org/packages/6b/49/2b2a0ef529aa6eec245d25f0c703e020a73955ad7edf73e7f54ddc608aa5/tomli-2.4.1-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:ec9bfaf3ad2df51ace80688143a6a4ebc09a248f6ff781a9945e51937008fcbc", size = 247859, upload-time = "2026-03-25T20:21:17.001Z" }, + { url = "https://files.pythonhosted.org/packages/83/bd/6c1a630eaca337e1e78c5903104f831bda934c426f9231429396ce3c3467/tomli-2.4.1-cp311-cp311-win32.whl", hash = "sha256:ff2983983d34813c1aeb0fa89091e76c3a22889ee83ab27c5eeb45100560c049", size = 97204, upload-time = "2026-03-25T20:21:18.079Z" }, + { url = "https://files.pythonhosted.org/packages/42/59/71461df1a885647e10b6bb7802d0b8e66480c61f3f43079e0dcd315b3954/tomli-2.4.1-cp311-cp311-win_amd64.whl", hash = "sha256:5ee18d9ebdb417e384b58fe414e8d6af9f4e7a0ae761519fb50f721de398dd4e", size = 108084, upload-time = "2026-03-25T20:21:18.978Z" }, + { url = "https://files.pythonhosted.org/packages/b8/83/dceca96142499c069475b790e7913b1044c1a4337e700751f48ed723f883/tomli-2.4.1-cp311-cp311-win_arm64.whl", hash = "sha256:c2541745709bad0264b7d4705ad453b76ccd191e64aa6f0fc66b69a293a45ece", size = 95285, upload-time = "2026-03-25T20:21:20.309Z" }, + { url = "https://files.pythonhosted.org/packages/c1/ba/42f134a3fe2b370f555f44b1d72feebb94debcab01676bf918d0cb70e9aa/tomli-2.4.1-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:c742f741d58a28940ce01d58f0ab2ea3ced8b12402f162f4d534dfe18ba1cd6a", size = 155924, upload-time = "2026-03-25T20:21:21.626Z" }, + { url = "https://files.pythonhosted.org/packages/dc/c7/62d7a17c26487ade21c5422b646110f2162f1fcc95980ef7f63e73c68f14/tomli-2.4.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:7f86fd587c4ed9dd76f318225e7d9b29cfc5a9d43de44e5754db8d1128487085", size = 150018, upload-time = "2026-03-25T20:21:23.002Z" }, + { url = "https://files.pythonhosted.org/packages/5c/05/79d13d7c15f13bdef410bdd49a6485b1c37d28968314eabee452c22a7fda/tomli-2.4.1-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:ff18e6a727ee0ab0388507b89d1bc6a22b138d1e2fa56d1ad494586d61d2eae9", size = 244948, upload-time = "2026-03-25T20:21:24.04Z" }, + { url = "https://files.pythonhosted.org/packages/10/90/d62ce007a1c80d0b2c93e02cab211224756240884751b94ca72df8a875ca/tomli-2.4.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:136443dbd7e1dee43c68ac2694fde36b2849865fa258d39bf822c10e8068eac5", size = 253341, upload-time = "2026-03-25T20:21:25.177Z" }, + { url = "https://files.pythonhosted.org/packages/1a/7e/caf6496d60152ad4ed09282c1885cca4eea150bfd007da84aea07bcc0a3e/tomli-2.4.1-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:5e262d41726bc187e69af7825504c933b6794dc3fbd5945e41a79bb14c31f585", size = 248159, upload-time = "2026-03-25T20:21:26.364Z" }, + { url = "https://files.pythonhosted.org/packages/99/e7/c6f69c3120de34bbd882c6fba7975f3d7a746e9218e56ab46a1bc4b42552/tomli-2.4.1-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:5cb41aa38891e073ee49d55fbc7839cfdb2bc0e600add13874d048c94aadddd1", size = 253290, upload-time = "2026-03-25T20:21:27.46Z" }, + { url = "https://files.pythonhosted.org/packages/d6/2f/4a3c322f22c5c66c4b836ec58211641a4067364f5dcdd7b974b4c5da300c/tomli-2.4.1-cp312-cp312-win32.whl", hash = "sha256:da25dc3563bff5965356133435b757a795a17b17d01dbc0f42fb32447ddfd917", size = 98141, upload-time = "2026-03-25T20:21:28.492Z" }, + { url = "https://files.pythonhosted.org/packages/24/22/4daacd05391b92c55759d55eaee21e1dfaea86ce5c571f10083360adf534/tomli-2.4.1-cp312-cp312-win_amd64.whl", hash = "sha256:52c8ef851d9a240f11a88c003eacb03c31fc1c9c4ec64a99a0f922b93874fda9", size = 108847, upload-time = "2026-03-25T20:21:29.386Z" }, + { url = "https://files.pythonhosted.org/packages/68/fd/70e768887666ddd9e9f5d85129e84910f2db2796f9096aa02b721a53098d/tomli-2.4.1-cp312-cp312-win_arm64.whl", hash = "sha256:f758f1b9299d059cc3f6546ae2af89670cb1c4d48ea29c3cacc4fe7de3058257", size = 95088, upload-time = "2026-03-25T20:21:30.677Z" }, + { url = "https://files.pythonhosted.org/packages/07/06/b823a7e818c756d9a7123ba2cda7d07bc2dd32835648d1a7b7b7a05d848d/tomli-2.4.1-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:36d2bd2ad5fb9eaddba5226aa02c8ec3fa4f192631e347b3ed28186d43be6b54", size = 155866, upload-time = "2026-03-25T20:21:31.65Z" }, + { url = "https://files.pythonhosted.org/packages/14/6f/12645cf7f08e1a20c7eb8c297c6f11d31c1b50f316a7e7e1e1de6e2e7b7e/tomli-2.4.1-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:eb0dc4e38e6a1fd579e5d50369aa2e10acfc9cace504579b2faabb478e76941a", size = 149887, upload-time = "2026-03-25T20:21:33.028Z" }, + { url = "https://files.pythonhosted.org/packages/5c/e0/90637574e5e7212c09099c67ad349b04ec4d6020324539297b634a0192b0/tomli-2.4.1-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:c7f2c7f2b9ca6bdeef8f0fa897f8e05085923eb091721675170254cbc5b02897", size = 243704, upload-time = "2026-03-25T20:21:34.51Z" }, + { url = "https://files.pythonhosted.org/packages/10/8f/d3ddb16c5a4befdf31a23307f72828686ab2096f068eaf56631e136c1fdd/tomli-2.4.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:f3c6818a1a86dd6dca7ddcaaf76947d5ba31aecc28cb1b67009a5877c9a64f3f", size = 251628, upload-time = "2026-03-25T20:21:36.012Z" }, + { url = "https://files.pythonhosted.org/packages/e3/f1/dbeeb9116715abee2485bf0a12d07a8f31af94d71608c171c45f64c0469d/tomli-2.4.1-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:d312ef37c91508b0ab2cee7da26ec0b3ed2f03ce12bd87a588d771ae15dcf82d", size = 247180, upload-time = "2026-03-25T20:21:37.136Z" }, + { url = "https://files.pythonhosted.org/packages/d3/74/16336ffd19ed4da28a70959f92f506233bd7cfc2332b20bdb01591e8b1d1/tomli-2.4.1-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:51529d40e3ca50046d7606fa99ce3956a617f9b36380da3b7f0dd3dd28e68cb5", size = 251674, upload-time = "2026-03-25T20:21:38.298Z" }, + { url = "https://files.pythonhosted.org/packages/16/f9/229fa3434c590ddf6c0aa9af64d3af4b752540686cace29e6281e3458469/tomli-2.4.1-cp313-cp313-win32.whl", hash = "sha256:2190f2e9dd7508d2a90ded5ed369255980a1bcdd58e52f7fe24b8162bf9fedbd", size = 97976, upload-time = "2026-03-25T20:21:39.316Z" }, + { url = "https://files.pythonhosted.org/packages/6a/1e/71dfd96bcc1c775420cb8befe7a9d35f2e5b1309798f009dca17b7708c1e/tomli-2.4.1-cp313-cp313-win_amd64.whl", hash = "sha256:8d65a2fbf9d2f8352685bc1364177ee3923d6baf5e7f43ea4959d7d8bc326a36", size = 108755, upload-time = "2026-03-25T20:21:40.248Z" }, + { url = "https://files.pythonhosted.org/packages/83/7a/d34f422a021d62420b78f5c538e5b102f62bea616d1d75a13f0a88acb04a/tomli-2.4.1-cp313-cp313-win_arm64.whl", hash = "sha256:4b605484e43cdc43f0954ddae319fb75f04cc10dd80d830540060ee7cd0243cd", size = 95265, upload-time = "2026-03-25T20:21:41.219Z" }, + { url = "https://files.pythonhosted.org/packages/3c/fb/9a5c8d27dbab540869f7c1f8eb0abb3244189ce780ba9cd73f3770662072/tomli-2.4.1-cp314-cp314-macosx_10_15_x86_64.whl", hash = "sha256:fd0409a3653af6c147209d267a0e4243f0ae46b011aa978b1080359fddc9b6cf", size = 155726, upload-time = "2026-03-25T20:21:42.23Z" }, + { url = "https://files.pythonhosted.org/packages/62/05/d2f816630cc771ad836af54f5001f47a6f611d2d39535364f148b6a92d6b/tomli-2.4.1-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:a120733b01c45e9a0c34aeef92bf0cf1d56cfe81ed9d47d562f9ed591a9828ac", size = 149859, upload-time = "2026-03-25T20:21:43.386Z" }, + { url = "https://files.pythonhosted.org/packages/ce/48/66341bdb858ad9bd0ceab5a86f90eddab127cf8b046418009f2125630ecb/tomli-2.4.1-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:559db847dc486944896521f68d8190be1c9e719fced785720d2216fe7022b662", size = 244713, upload-time = "2026-03-25T20:21:44.474Z" }, + { url = "https://files.pythonhosted.org/packages/df/6d/c5fad00d82b3c7a3ab6189bd4b10e60466f22cfe8a08a9394185c8a8111c/tomli-2.4.1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:01f520d4f53ef97964a240a035ec2a869fe1a37dde002b57ebc4417a27ccd853", size = 252084, upload-time = "2026-03-25T20:21:45.62Z" }, + { url = "https://files.pythonhosted.org/packages/00/71/3a69e86f3eafe8c7a59d008d245888051005bd657760e96d5fbfb0b740c2/tomli-2.4.1-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:7f94b27a62cfad8496c8d2513e1a222dd446f095fca8987fceef261225538a15", size = 247973, upload-time = "2026-03-25T20:21:46.937Z" }, + { url = "https://files.pythonhosted.org/packages/67/50/361e986652847fec4bd5e4a0208752fbe64689c603c7ae5ea7cb16b1c0ca/tomli-2.4.1-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:ede3e6487c5ef5d28634ba3f31f989030ad6af71edfb0055cbbd14189ff240ba", size = 256223, upload-time = "2026-03-25T20:21:48.467Z" }, + { url = "https://files.pythonhosted.org/packages/8c/9a/b4173689a9203472e5467217e0154b00e260621caa227b6fa01feab16998/tomli-2.4.1-cp314-cp314-win32.whl", hash = "sha256:3d48a93ee1c9b79c04bb38772ee1b64dcf18ff43085896ea460ca8dec96f35f6", size = 98973, upload-time = "2026-03-25T20:21:49.526Z" }, + { url = "https://files.pythonhosted.org/packages/14/58/640ac93bf230cd27d002462c9af0d837779f8773bc03dee06b5835208214/tomli-2.4.1-cp314-cp314-win_amd64.whl", hash = "sha256:88dceee75c2c63af144e456745e10101eb67361050196b0b6af5d717254dddf7", size = 109082, upload-time = "2026-03-25T20:21:50.506Z" }, + { url = "https://files.pythonhosted.org/packages/d5/2f/702d5e05b227401c1068f0d386d79a589bb12bf64c3d2c72ce0631e3bc49/tomli-2.4.1-cp314-cp314-win_arm64.whl", hash = "sha256:b8c198f8c1805dc42708689ed6864951fd2494f924149d3e4bce7710f8eb5232", size = 96490, upload-time = "2026-03-25T20:21:51.474Z" }, + { url = "https://files.pythonhosted.org/packages/45/4b/b877b05c8ba62927d9865dd980e34a755de541eb65fffba52b4cc495d4d2/tomli-2.4.1-cp314-cp314t-macosx_10_15_x86_64.whl", hash = "sha256:d4d8fe59808a54658fcc0160ecfb1b30f9089906c50b23bcb4c69eddc19ec2b4", size = 164263, upload-time = "2026-03-25T20:21:52.543Z" }, + { url = "https://files.pythonhosted.org/packages/24/79/6ab420d37a270b89f7195dec5448f79400d9e9c1826df982f3f8e97b24fd/tomli-2.4.1-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:7008df2e7655c495dd12d2a4ad038ff878d4ca4b81fccaf82b714e07eae4402c", size = 160736, upload-time = "2026-03-25T20:21:53.674Z" }, + { url = "https://files.pythonhosted.org/packages/02/e0/3630057d8eb170310785723ed5adcdfb7d50cb7e6455f85ba8a3deed642b/tomli-2.4.1-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:1d8591993e228b0c930c4bb0db464bdad97b3289fb981255d6c9a41aedc84b2d", size = 270717, upload-time = "2026-03-25T20:21:55.129Z" }, + { url = "https://files.pythonhosted.org/packages/7a/b4/1613716072e544d1a7891f548d8f9ec6ce2faf42ca65acae01d76ea06bb0/tomli-2.4.1-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:734e20b57ba95624ecf1841e72b53f6e186355e216e5412de414e3c51e5e3c41", size = 278461, upload-time = "2026-03-25T20:21:56.228Z" }, + { url = "https://files.pythonhosted.org/packages/05/38/30f541baf6a3f6df77b3df16b01ba319221389e2da59427e221ef417ac0c/tomli-2.4.1-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:8a650c2dbafa08d42e51ba0b62740dae4ecb9338eefa093aa5c78ceb546fcd5c", size = 274855, upload-time = "2026-03-25T20:21:57.653Z" }, + { url = "https://files.pythonhosted.org/packages/77/a3/ec9dd4fd2c38e98de34223b995a3b34813e6bdadf86c75314c928350ed14/tomli-2.4.1-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:504aa796fe0569bb43171066009ead363de03675276d2d121ac1a4572397870f", size = 283144, upload-time = "2026-03-25T20:21:59.089Z" }, + { url = "https://files.pythonhosted.org/packages/ef/be/605a6261cac79fba2ec0c9827e986e00323a1945700969b8ee0b30d85453/tomli-2.4.1-cp314-cp314t-win32.whl", hash = "sha256:b1d22e6e9387bf4739fbe23bfa80e93f6b0373a7f1b96c6227c32bef95a4d7a8", size = 108683, upload-time = "2026-03-25T20:22:00.214Z" }, + { url = "https://files.pythonhosted.org/packages/12/64/da524626d3b9cc40c168a13da8335fe1c51be12c0a63685cc6db7308daae/tomli-2.4.1-cp314-cp314t-win_amd64.whl", hash = "sha256:2c1c351919aca02858f740c6d33adea0c5deea37f9ecca1cc1ef9e884a619d26", size = 121196, upload-time = "2026-03-25T20:22:01.169Z" }, + { url = "https://files.pythonhosted.org/packages/5a/cd/e80b62269fc78fc36c9af5a6b89c835baa8af28ff5ad28c7028d60860320/tomli-2.4.1-cp314-cp314t-win_arm64.whl", hash = "sha256:eab21f45c7f66c13f2a9e0e1535309cee140182a9cdae1e041d02e47291e8396", size = 100393, upload-time = "2026-03-25T20:22:02.137Z" }, + { url = "https://files.pythonhosted.org/packages/7b/61/cceae43728b7de99d9b847560c262873a1f6c98202171fd5ed62640b494b/tomli-2.4.1-py3-none-any.whl", hash = "sha256:0d85819802132122da43cb86656f8d1f8c6587d54ae7dcaf30e90533028b49fe", size = 14583, upload-time = "2026-03-25T20:22:03.012Z" }, +] + +[[package]] +name = "tqdm" +version = "4.68.3" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "colorama", marker = "sys_platform == 'win32'" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/87/d7/0535a28b1f5f24f6612fb3ff1e89fb1a8d160fee0f976e0aa6803862134b/tqdm-4.68.3.tar.gz", hash = "sha256:00dfa48452b6b6cfae3dd9885636c23d3422d1ec97c66d96818cbd5e0821d482", size = 170596, upload-time = "2026-06-17T07:36:52.105Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/d8/8e/bb97bb0c71802080bfc8952937d174e49cfc50de5c951dd47b2496f0dcdb/tqdm-4.68.3-py3-none-any.whl", hash = "sha256:39832cc2def2789a6f29df83f172db7416cea70052c0907a57801c5f2fdccb03", size = 78337, upload-time = "2026-06-17T07:36:50.132Z" }, +] + +[[package]] +name = "typing-extensions" +version = "4.15.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/72/94/1a15dd82efb362ac84269196e94cf00f187f7ed21c242792a923cdb1c61f/typing_extensions-4.15.0.tar.gz", hash = "sha256:0cea48d173cc12fa28ecabc3b837ea3cf6f38c6d1136f85cbaaf598984861466", size = 109391, upload-time = "2025-08-25T13:49:26.313Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/18/67/36e9267722cc04a6b9f15c7f3441c2363321a3ea07da7ae0c0707beb2a9c/typing_extensions-4.15.0-py3-none-any.whl", hash = "sha256:f0fa19c6845758ab08074a0cfa8b7aecb71c999ca73d62883bc25cc018c4e548", size = 44614, upload-time = "2025-08-25T13:49:24.86Z" }, +] + +[[package]] +name = "urllib3" +version = "1.26.20" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/e4/e8/6ff5e6bc22095cfc59b6ea711b687e2b7ed4bdb373f7eeec370a97d7392f/urllib3-1.26.20.tar.gz", hash = "sha256:40c2dc0c681e47eb8f90e7e27bf6ff7df2e677421fd46756da1161c39ca70d32", size = 307380, upload-time = "2024-08-29T15:43:11.37Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/33/cf/8435d5a7159e2a9c83a95896ed596f68cf798005fe107cc655b5c5c14704/urllib3-1.26.20-py2.py3-none-any.whl", hash = "sha256:0ed14ccfbf1c30a9072c7ca157e4319b70d65f623e91e7b32fadb2853431016e", size = 144225, upload-time = "2024-08-29T15:43:08.921Z" }, +] + +[[package]] +name = "virtualenv" +version = "21.5.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "distlib" }, + { name = "filelock" }, + { name = "platformdirs" }, + { name = "python-discovery" }, + { name = "typing-extensions", marker = "python_full_version < '3.11'" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/f1/a5/81f987504738e6defeed61ec1c47e2aefab3c35d8eeb87e1b3f38cf28254/virtualenv-21.5.1.tar.gz", hash = "sha256:dca3bf98275a59c652b69d68e73433e597d977c2da9198882479d1a7188009c8", size = 4578798, upload-time = "2026-06-16T16:23:58.603Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/2c/02/3623e6169bed617ed1e2d372f7c69f92ec28d54c4dfc997055c8578ec148/virtualenv-21.5.1-py3-none-any.whl", hash = "sha256:55aa670b67bbfb991b03fda39bd3276d92c419d702376e98c5df1c9989a26783", size = 4558820, upload-time = "2026-06-16T16:23:56.963Z" }, +]