Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
969dd8b
Refactor Clava to conform to the changes introduced by the new weaver…
lm-sousa May 23, 2026
cc26684
Refactor ACxxWeaverJoinPoint into CxxJoinpoint, simplifying the hiera…
lm-sousa May 23, 2026
e48da23
Remove ACxxWeaverJoinPoint from .gitignore since it no longer exists
lm-sousa May 23, 2026
40f8087
Update CxxSpec to use the new weaverPrefix descriptor
lm-sousa May 24, 2026
11079a5
Refactor joinpoint methods to use *Impl methods for consistency
lm-sousa May 24, 2026
a5eecee
Remove Copilot instructions document from the repository
lm-sousa May 29, 2026
361ace4
Add LLM Skill for Clava scripts
lm-sousa May 29, 2026
933de9b
Refactor BatchParser to simplify error handling and remove unused Cla…
lm-sousa May 29, 2026
c889032
rafactor: Reflect recent changes of 'instanceOf', 'equals' and 'toSt…
lm-sousa May 29, 2026
943e08c
Update tsconfig.json to include "types" for node and jest
lm-sousa May 29, 2026
d4e5a8b
fix: update TS JP wrappers with the new version of the builder script…
lm-sousa May 29, 2026
9bb0c87
refactor: remove unused InitializationStyle enum from the project
lm-sousa May 30, 2026
4e9b490
fix: rectify CxxCudaKernelCall's class name
lm-sousa Jun 1, 2026
6f2da8b
fix: update mainClass for generateWeaver task to use the new CLI class
lm-sousa Jun 1, 2026
4b6efd4
fix: update generics in various classes because they are the cause of…
lm-sousa Jun 2, 2026
174ae4d
fix: use OpKind.assign for outlined return plumbing
lm-sousa Sep 4, 2026
f913c34
refactor: remove leftover "around" string aliases in CxxActions inser…
lm-sousa Sep 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .codex/skills/clava-scripting/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
name: clava-scripting
description: Create, update, and explain Clava/LARA scripts in TypeScript using Clava-JS and Lara-JS APIs, including Query/Selector usage, joinpoint selection and filters, and AST transformations. Use for Clava script authoring, joinpoint queries, or refactoring code via Clava/Lara weaver APIs.
---

# Clava Scripting

## Overview

Write and modify Clava scripts in TypeScript using Clava/Lara APIs for joinpoint selection and AST transformations.

## Quick Start

Use ESM imports with `.js` extensions, select joinpoints with `Query`, and transform with Clava APIs.

```ts
import Query from "@specs-feup/lara/api/weaver/Query.js";
import { FunctionJp } from "@specs-feup/clava/api/Joinpoints.js";

const $fn = Query.search(FunctionJp, { isImplementation: true }).first();
if ($fn) $fn.clone(`${$fn.name}_clone`);
```

## Workflow

1. Identify joinpoints and attributes.
Use the generated joinpoint wrappers in `@specs-feup/clava/api/Joinpoints.js` and check `Joinpoints.ts` for default attributes and available fields.

2. Select joinpoints with Query/Selector.
Use `Query.search`, `Query.searchFrom`, `Query.searchFromInclusive`, `Query.childrenFrom`, and `Selector.scope`. Filters accept strings, regex, predicate functions, or objects keyed by attributes. `Selector` is iterable and methods like `.get()`, `.first()`, and `.chain()` consume the current selection.

3. Transform and emit code.
Use joinpoint methods like `.clone()`, `.replaceWith()`, `.addParam()`, `.setReturnType()`, and factories in `ClavaJoinPoints` for new nodes. Use `Query.root().code` or `Clava.writeCode()` to inspect or emit output.

## References

- `references/query-api.md` for Query/Selector behavior and filters.
- `references/clava-apis.md` for key Clava/Lara API entry points and file locations.
- `references/examples.md` for real scripts and test patterns.
4 changes: 4 additions & 0 deletions .codex/skills/clava-scripting/agents/openai.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
interface:
display_name: "Clava Scripting"
short_description: "Write and edit Clava/Lara scripts"
default_prompt: "Use $clava-scripting to draft a Clava TypeScript script that queries joinpoints and applies a transformation."
33 changes: 33 additions & 0 deletions .codex/skills/clava-scripting/references/clava-apis.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Clava and Lara API Entry Points

Use this to locate the right TypeScript APIs and understand where functionality lives.

## Clava-JS APIs (this repo)

- Joinpoint wrappers (generated): `Clava-JS/src-api/Joinpoints.ts`
- Joinpoint factories/utilities: `Clava-JS/src-api/clava/ClavaJoinPoints.ts`
- Core Clava utilities and AST stack: `Clava-JS/src-api/clava/Clava.ts`
- Common passes/opts built on Query: `Clava-JS/src-api/clava/opt`, `Clava-JS/src-api/clava/pass`

Imports typically use:
- `@specs-feup/clava/api/Joinpoints.js`
- `@specs-feup/clava/api/clava/ClavaJoinPoints.js`
- `@specs-feup/clava/api/clava/Clava.js`

## Lara-JS APIs (sibling repo)

- Query API: `../lara/Lara-JS/src-api/weaver/Query.ts`
- Selector behavior and filters: `../lara/Lara-JS/src-api/weaver/Selector.ts`
- Weaver utilities: `../lara/Lara-JS/src-api/weaver/Weaver.ts`

If the Lara-JS repo is not a sibling of Clava, search for `Lara-JS/src-api/weaver/Query.ts`.

Imports typically use:
- `@specs-feup/lara/api/weaver/Query.js`
- `@specs-feup/lara/api/weaver/Weaver.js`

## Notes

- Joinpoint wrappers expose attributes and methods specific to each type.
- `ClavaJoinPoints` provides factory helpers for types, statements, expressions, and declarations.
- Use `.code` on joinpoints (or `Query.root().code`) to inspect generated code quickly.
28 changes: 28 additions & 0 deletions .codex/skills/clava-scripting/references/examples.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Script Examples and Patterns

Use these files for concrete patterns and idioms.

## Weaver tests (JS, but patterns apply to TS)

- `ClavaWeaver/resources/clava/test/weaver/Function2.js`
- Select function, clone it, change return type, replace body, add param.

- `ClavaWeaver/resources/clava/test/weaver/Clone.js`
- Clone all functions with definitions and print file code.

- `ClavaWeaver/resources/clava/test/weaver/Field.js`
- Navigate record fields and read attributes like `isPublic`.

- `ClavaWeaver/resources/clava/test/issues/Issue168.js`
- Normalize loops and decompose statements using `NormalizeToSubset` and `StatementDecomposer`.

- `ClavaWeaver/resources/clava/test/issues/Issue_aiq_1.js`
- Filter loops by kind, inspect condition relation.

## API tests

- `ClavaWeaver/resources/clava/test/api/ClavaJoinPointsTest.js`
- Large catalog of `ClavaJoinPoints` factory helpers.

- `Clava-JS/src-api/Query.test.ts`
- Query chaining, `.scope()`, `.chain()`, and regex selection.
47 changes: 47 additions & 0 deletions .codex/skills/clava-scripting/references/query-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Query and Selector API

Use this when writing or debugging joinpoint selection logic.

## Primary sources

- Query API: `../lara/Lara-JS/src-api/weaver/Query.ts` (sibling worktree)
- Selector behavior: `../lara/Lara-JS/src-api/weaver/Selector.ts` (sibling worktree)
- Query usage tests: `Clava-JS/src-api/Query.test.ts`

If the Lara-JS repo is not a sibling of Clava, search for `Lara-JS/src-api/weaver/Query.ts`.

## Core patterns

- `Query.root()` returns the root joinpoint.
- `Query.search(Type, filter?, traversal?)` starts from root.
- `Query.searchFrom($base, Type?, filter?, traversal?)` searches below a base node (exclusive).
- `Query.searchFromInclusive($base, Type?, filter?, traversal?)` includes the base node.
- `Query.childrenFrom($base, Type?, filter?)` searches direct children.
- `Selector.scope(Type?, filter?)` searches inside the scope of the previously selected nodes.

## Filters

Filters accept:
- A string or regex applied to the default attribute for that joinpoint type.
- A predicate function `(jp) => boolean`.
- An object with attribute names as keys and values of string/regex/predicate.

Default attributes are defined in the joinpoint wrappers and can be resolved via `Weaver.getDefaultAttribute()`.

## Selector consumption

`Selector` is iterable and is consumed by `for..of`, `.get()`, `.first()`, and `.chain()`.
Use `.chain()` when you need the full chain map (e.g., `loop`, `loop_0`, `loop_1`).

## Minimal examples

```ts
for (const $fn of Query.search(FunctionJp, { isImplementation: true })) {
// $fn is a joinpoint instance
}

const chains = Query.search(FunctionJp, "query_loop")
.search(Loop)
.search(Loop)
.chain();
```
100 changes: 0 additions & 100 deletions .github/copilot-instructions.md

This file was deleted.

Loading
Loading