diff options
| author | _ov4 <ov4@ov4.org> | 2026-10-21 05:43:35 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-10-21 05:43:35 +0000 |
| commit | dd5bbae055fd34ce2e12ef63f8a261c6b15dc83e (patch) | |
| tree | 757e367daacf92c50148eb42d7bda97ba33ed3fb /tests | |
| parent | c682f983b0dce3acba76d1f08719a26b9c52c5ec (diff) | |
feat(parser): parse TEMPLATE declarations, template ids and parameter packs
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/i/template-unused/case.json | 1 | ||||
| -rw-r--r-- | tests/i/template-unused/expected.txt | 1 | ||||
| -rw-r--r-- | tests/i/template-unused/lib.cps | 48 | ||||
| -rw-r--r-- | tests/i/template-unused/notes.md | 5 | ||||
| -rw-r--r-- | tests/i/template-unused/program.cps | 2 | ||||
| -rw-r--r-- | tests/iii/template-header-errors/case.json | 36 | ||||
| -rw-r--r-- | tests/iii/template-header-errors/program.cps | 39 | ||||
| -rw-r--r-- | tests/iii/template-pack-errors/case.json | 32 | ||||
| -rw-r--r-- | tests/iii/template-pack-errors/program.cps | 32 |
9 files changed, 196 insertions, 0 deletions
diff --git a/tests/i/template-unused/case.json b/tests/i/template-unused/case.json new file mode 100644 index 0000000..3415f39 --- /dev/null +++ b/tests/i/template-unused/case.json @@ -0,0 +1 @@ +{"sources": ["program.cps", "lib.cps"]} diff --git a/tests/i/template-unused/expected.txt b/tests/i/template-unused/expected.txt new file mode 100644 index 0000000..7f8f011 --- /dev/null +++ b/tests/i/template-unused/expected.txt @@ -0,0 +1 @@ +7 diff --git a/tests/i/template-unused/lib.cps b/tests/i/template-unused/lib.cps new file mode 100644 index 0000000..3de8ac3 --- /dev/null +++ b/tests/i/template-unused/lib.cps @@ -0,0 +1,48 @@ +TEMPLATE <T> +FUNCTION Identity(Value : T) RETURNS T + IF Value < Value THEN + RETURN (T)Value + ENDIF + RETURN Value +ENDFUNCTION + +TEMPLATE <T, Rest...> +OVERLOAD PROCEDURE Visit(First : T, Others : Rest...) + OUTPUT Identity<T>(First) + CALL Visit<Rest...>(Others...) + Visit<Box<Pair<INTEGER,REAL>>>(Others...) +ENDPROCEDURE + +TEMPLATE <T> +CLASS Box + PRIVATE Value : T + PUBLIC PROCEDURE NEW(V : T) + Value <- V + ENDPROCEDURE + PUBLIC FUNCTION Get() RETURNS T + RETURN Value + ENDFUNCTION + PUBLIC FUNCTION AsBox(V : Box<T>) RETURNS Box<T> + RETURN (Box<T>)V + ENDFUNCTION +ENDCLASS + +TEMPLATE <A, B> +CLASS Pair + Left : A + Right : B +ENDCLASS + +TEMPLATE <T, Rest...> +CLASS Bundle + PUBLIC PROCEDURE Send(Values : Rest...) + CALL Visit(Values...) + ENDPROCEDURE +ENDCLASS + +TEMPLATE <T> +PROCEDURE NestedTypes(Value : Box<Box<T>>) + DECLARE Other : Box<Pair<T,REAL>> + Other <- NEW Box<Pair<T,REAL>>() + Value <- (Box<Box<T>>)Value +ENDPROCEDURE diff --git a/tests/i/template-unused/notes.md b/tests/i/template-unused/notes.md new file mode 100644 index 0000000..c3ff7fd --- /dev/null +++ b/tests/i/template-unused/notes.md @@ -0,0 +1,5 @@ +# template-unused + +Human review: pending. Expected output was independently traced by AI, not captured from cpsc. + +Basis: TEMPLATE is a project extension. The library holds unused function, class and variadic templates, including casts, nested type ids, explicit calls and pack forwarding. Their bodies are parsed without being emitted or counted as top-level code. The entry unit prints INTEGER 7. diff --git a/tests/i/template-unused/program.cps b/tests/i/template-unused/program.cps new file mode 100644 index 0000000..d8b89a2 --- /dev/null +++ b/tests/i/template-unused/program.cps @@ -0,0 +1,2 @@ +INCLUDE "lib.cps" +OUTPUT 7 diff --git a/tests/iii/template-header-errors/case.json b/tests/iii/template-header-errors/case.json new file mode 100644 index 0000000..f74cc0d --- /dev/null +++ b/tests/iii/template-header-errors/case.json @@ -0,0 +1,36 @@ +{ + "errors": [ + { + "reason": "Duplicate template parameter", + "line": 1 + }, + { + "reason": "template parameter pack must be last", + "line": 6 + }, + { + "reason": "only one parameter pack", + "line": 10 + }, + { + "reason": "TEMPLATE cannot prefix TYPE", + "line": 14 + }, + { + "reason": "Operator templates are not supported", + "line": 17 + }, + { + "reason": "TEMPLATE declarations are only allowed at top level", + "line": 23 + }, + { + "reason": "TEMPLATE declarations are only allowed at top level", + "line": 30 + }, + { + "reason": "Expected '<' after TEMPLATE", + "line": 35 + } + ] +} diff --git a/tests/iii/template-header-errors/program.cps b/tests/iii/template-header-errors/program.cps new file mode 100644 index 0000000..73c34a2 --- /dev/null +++ b/tests/iii/template-header-errors/program.cps @@ -0,0 +1,39 @@ +TEMPLATE <T, t> +FUNCTION Duplicate(Value : T) RETURNS T + RETURN Value +ENDFUNCTION + +TEMPLATE <Rest..., T> +PROCEDURE NotLast() +ENDPROCEDURE + +TEMPLATE <A..., B...> +PROCEDURE TwoPacks() +ENDPROCEDURE + +TEMPLATE <T> +TYPE Alias = ^T + +TEMPLATE <T> +OVERLOAD FUNCTION OPERATOR+(Value : T) RETURNS T + RETURN Value +ENDFUNCTION + +IF TRUE THEN + TEMPLATE <T> + PROCEDURE Nested(Value : T) + OUTPUT 99 + ENDPROCEDURE +ENDIF + +CLASS Outer + TEMPLATE <T> + PROCEDURE Member(Value : T) + ENDPROCEDURE +ENDCLASS + +TEMPLATE <> +PROCEDURE Empty() +ENDPROCEDURE + +OUTPUT 0 diff --git a/tests/iii/template-pack-errors/case.json b/tests/iii/template-pack-errors/case.json new file mode 100644 index 0000000..53b5a23 --- /dev/null +++ b/tests/iii/template-pack-errors/case.json @@ -0,0 +1,32 @@ +{ + "errors": [ + { + "reason": "A pack parameter must be last", + "line": 2 + }, + { + "reason": "pack parameter must use the current template pack and cannot be ARRAY", + "line": 6 + }, + { + "reason": "pack parameter must use the current template pack and cannot be ARRAY", + "line": 10 + }, + { + "reason": "parameter pack must be expanded", + "line": 15 + }, + { + "reason": "Only a parameter pack may be expanded", + "line": 20 + }, + { + "reason": "Only the current template parameter pack may use", + "line": 25 + }, + { + "reason": "template parameter pack requires", + "line": 29 + } + ] +} diff --git a/tests/iii/template-pack-errors/program.cps b/tests/iii/template-pack-errors/program.cps new file mode 100644 index 0000000..51ffa46 --- /dev/null +++ b/tests/iii/template-pack-errors/program.cps @@ -0,0 +1,32 @@ +TEMPLATE <Rest...> +PROCEDURE NotLast(Values : Rest..., Extra : INTEGER) +ENDPROCEDURE + +TEMPLATE <Rest...> +PROCEDURE ArrayPack(Values : ARRAY OF Rest...) +ENDPROCEDURE + +TEMPLATE <T> +PROCEDURE WrongPack(Values : T...) +ENDPROCEDURE + +TEMPLATE <Rest...> +PROCEDURE BarePack(Values : Rest...) + OUTPUT Values +ENDPROCEDURE + +TEMPLATE <T> +PROCEDURE ScalarExpansion(Value : T) + CALL Missing(Value...) +ENDPROCEDURE + +TEMPLATE <T> +PROCEDURE WrongTypeExpansion(Value : T) + CALL Missing<T...>(Value) +ENDPROCEDURE + +TEMPLATE <Rest...> +PROCEDURE MissingDots(Values : Rest) +ENDPROCEDURE + +OUTPUT 0 |
