Skip to content
Open

Ts6 #246

Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions .codex/skills/clava-scripting/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ Write and modify Clava scripts in TypeScript using Clava/Lara APIs for joinpoint
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";
import Query from "@specs-feup/lara/api/weaver/Query.ts";
import { FunctionJp } from "@specs-feup/clava/api/Joinpoints.ts";

const $fn = Query.search(FunctionJp, { isImplementation: true }).first();
if ($fn) $fn.clone(`${$fn.name}_clone`);
Expand All @@ -24,7 +24,7 @@ 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.
Use the generated joinpoint wrappers in `@specs-feup/clava/api/Joinpoints.ts` 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.
Expand Down
26 changes: 13 additions & 13 deletions .codex/skills/clava-scripting/references/clava-apis.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@ Use this to locate the right TypeScript APIs and understand where functionality

## 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`
- Joinpoint wrappers (generated): `Clava-JS/api/Joinpoints.ts`
- Joinpoint factories/utilities: `Clava-JS/api/clava/ClavaJoinPoints.ts`
- Core Clava utilities and AST stack: `Clava-JS/api/clava/Clava.ts`
- Common passes/opts built on Query: `Clava-JS/api/clava/opt`, `Clava-JS/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`
- `@specs-feup/clava/api/Joinpoints.ts`
- `@specs-feup/clava/api/clava/ClavaJoinPoints.ts`
- `@specs-feup/clava/api/clava/Clava.ts`

## 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`
- Query API: `../lara/Lara-JS/api/weaver/Query.ts`
- Selector behavior and filters: `../lara/Lara-JS/api/weaver/Selector.ts`
- Weaver utilities: `../lara/Lara-JS/api/weaver/Weaver.ts`

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

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

## Notes

Expand Down
2 changes: 1 addition & 1 deletion .codex/skills/clava-scripting/references/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ Use these files for concrete patterns and idioms.
- `ClavaWeaver/resources/clava/test/api/ClavaJoinPointsTest.js`
- Large catalog of `ClavaJoinPoints` factory helpers.

- `Clava-JS/src-api/Query.test.ts`
- `Clava-JS/api/Query.test.ts`
- Query chaining, `.scope()`, `.chain()`, and regex selection.
8 changes: 4 additions & 4 deletions .codex/skills/clava-scripting/references/query-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ 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`
- Query API: `../lara/Lara-JS/api/weaver/Query.ts` (sibling worktree)
- Selector behavior: `../lara/Lara-JS/api/weaver/Selector.ts` (sibling worktree)
- Query usage tests: `Clava-JS/api/Query.test.ts`

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

## Core patterns

Expand Down
25 changes: 7 additions & 18 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ jobs:
fail-fast: false
matrix:
#node-version: ['latest', '22.x', '20.x']
node-version: ['22.x', '20.x']
node-version: ['25.x', '24.x']
os: [ubuntu-latest, windows-latest, macos-latest]

runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -197,7 +197,7 @@ jobs:

- name: Setup js workspace
run: |
echo '{ "name": "SPeCS Workspace", "type": "module", "workspaces": [ "clava/Clava-JS", "lara-framework/Lara-JS" ] }' > package.json
echo '{ "name": "SPeCS Workspace", "type": "module", "workspaces": [ "clava/Clava-JS", "lara-framework/Lara-JS" ], "overrides": { "node-gyp": "^12.1.0" } }' > package.json
npm install

- name: Build Lara-JS
Expand All @@ -223,25 +223,14 @@ jobs:

# Only on ubuntu-latest
- name: Publish JS
if: matrix.os == 'ubuntu-latest' && matrix.node-version == '22.x'
if: github.event_name == 'push' && github.ref == 'refs/heads/staging' && matrix.os == 'ubuntu-latest' && matrix.node-version == '25.x'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Restore stable publishing for master pushes

For a release push to refs/heads/master, this condition now skips the only repository workflow containing npm publish; the remaining command publishes staging prereleases under the staging tag only. Consequently, even a master commit with a deliberately bumped package version can no longer publish the stable latest package as the previous branch explicitly did.

Useful? React with 👍 / 👎.

run: |
cd clava/Clava-JS
npm whoami
echo "Attempt to publish while running on ${{ matrix.os }} and Node.js ${{matrix.node-version}}"
if [[ "${{ github.event_name }}" == "push" ]]; then
if [ "${{ github.ref }}" == "refs/heads/staging" ]; then
echo "Publishing from staging, creating timestamped prerelease and updating tag 'staging'"
TIMESTAMP=$(date +"%Y%m%d%H%M")
npm version prerelease --preid="$TIMESTAMP"
npm publish --tag staging --access public
elif [ "${{ github.ref }}" == "refs/heads/master" ]; then
echo "Publishing from main, assumes version was changed before publishing"
npm publish
else
echo "Not master or staging branches, not publishing even if it is a push event"
fi
else
echo "Not a push event, skipping publish."
fi
echo "Publishing from staging, creating timestamped prerelease and updating tag 'staging'"
TIMESTAMP=$(date +"%Y%m%d%H%M")
npm version prerelease --preid="$TIMESTAMP"
npm publish --tag staging --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
2 changes: 0 additions & 2 deletions Clava-JS/.gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
##### User-added #####
woven_code/
/api
/code
package-lock.json
java-binaries

Expand Down
2 changes: 1 addition & 1 deletion Clava-JS/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Clava source-to-source compiler running on top of Node.js.

Current version only works on Node 20 and 22.
Current version works on Node >=24.

To test Clava-JS you can try the [Clava project template](https://github.com/specs-feup/clava-project-template).

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {
registerSourceCode,
registerSourceCodes,
} from "@specs-feup/lara/jest/jestHelpers.js";
import Query from "@specs-feup/lara/api/weaver/Query.js";
import { FunctionJp } from "@specs-feup/clava/api/Joinpoints.js";
import ClavaJoinPoints from "@specs-feup/clava/api/clava/ClavaJoinPoints.js";
} from "@specs-feup/lara/jest/jestHelpers.ts";
import Query from "@specs-feup/lara/api/weaver/Query.ts";
import { FunctionJp } from "./Joinpoints.ts";
import ClavaJoinPoints from "./clava/ClavaJoinPoints.ts";

const code187 = `
int foo(int a);
Expand Down
212 changes: 124 additions & 88 deletions Clava-JS/src-api/Joinpoints.ts → Clava-JS/api/Joinpoints.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
///////////////////////////////////////////////////
// This file is generated by build-interfaces.js //
// This file is generated by build-interfaces.ts //
///////////////////////////////////////////////////

import {
Expand All @@ -8,7 +8,7 @@
wrapJoinPoint,
unwrapJoinPoint,
InsertPosition,
} from "@specs-feup/lara/api/LaraJoinPoint.js";
} from "@specs-feup/lara/api/LaraJoinPoint.ts";

type PrivateMapper = {
"Joinpoint": typeof Joinpoint,
Expand Down Expand Up @@ -1833,7 +1833,7 @@
get condDecl(): Vardecl { return wrapJoinPoint(this._javaObject.condDecl()) }
get else(): Scope { return wrapJoinPoint(this._javaObject._else()) }
set else(value: Statement) { this._javaObject.setElse(unwrapJoinPoint(value)); }
get then(): Scope { return wrapJoinPoint(this._javaObject.then()) }

Check failure on line 1836 in Clava-JS/api/Joinpoints.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Do not add `then` to a class.

See more on https://sonarcloud.io/project/issues?id=specs-feup_clava&issues=AaBKHpzDwlePz8ThOo4k&open=AaBKHpzDwlePz8ThOo4k&pullRequest=246
set then(value: Statement) { this._javaObject.setThen(unwrapJoinPoint(value)); }
/**
* Sets the condition of the if
Expand Down Expand Up @@ -2805,92 +2805,128 @@
get underlyingType(): Type { return wrapJoinPoint(this._javaObject.underlyingType()) }
}

export enum StorageClass {
NONE = "none",
AUTO = "auto",
EXTERN = "extern",
PRIVATE_EXTERN = "private_extern",
REGISTER = "register",
STATIC = "static",
}

export enum Relation {
LE = "le",
LT = "lt",
GE = "ge",
GT = "gt",
EQ = "eq",
NE = "ne",
}

export enum LoopKind {
for = "for",
while = "while",
dowhile = "dowhile",
foreach = "foreach",
}

export enum ExpressionUse {
read = "read",
write = "write",
readwrite = "readwrite",
}

export enum OpKind {
ptr_mem_d = "ptr_mem_d",
ptr_mem_i = "ptr_mem_i",
mul = "mul",
div = "div",
rem = "rem",
add = "add",
sub = "sub",
shl = "shl",
shr = "shr",
cmp = "cmp",
lt = "lt",
gt = "gt",
le = "le",
ge = "ge",
eq = "eq",
ne = "ne",
and = "and",
xor = "xor",
or = "or",
l_and = "l_and",
l_or = "l_or",
assign = "assign",
mul_assign = "mul_assign",
div_assign = "div_assign",
rem_assign = "rem_assign",
add_assign = "add_assign",
sub_assign = "sub_assign",
shl_assign = "shl_assign",
shr_assign = "shr_assign",
and_assign = "and_assign",
xor_assign = "xor_assign",
or_assign = "or_assign",
comma = "comma",
post_inc = "post_inc",
post_dec = "post_dec",
pre_inc = "pre_inc",
pre_dec = "pre_dec",
addr_of = "addr_of",
deref = "deref",
plus = "plus",
minus = "minus",
not = "not",
l_not = "l_not",
real = "real",
imag = "imag",
extension = "extension",
cowait = "cowait",
ternary = "ternary",
}

export enum WrapperStatementKind {
comment = "comment",
pragma = "pragma",
}
/**
* This is supposed to be an enum, but Node.js v25 does bot support TS' enums, only erasable-syntax.
* Revert to an enum when Node.js supports it, or when we move to a different engine that supports it.
* This and the "type" declaration below.
*/
export const StorageClass = {
NONE: "none",
AUTO: "auto",
EXTERN: "extern",
PRIVATE_EXTERN: "private_extern",
REGISTER: "register",
STATIC: "static",
} as const;
export type StorageClass = typeof StorageClass[keyof typeof StorageClass];

/**
* This is supposed to be an enum, but Node.js v25 does bot support TS' enums, only erasable-syntax.
* Revert to an enum when Node.js supports it, or when we move to a different engine that supports it.
* This and the "type" declaration below.
*/
export const Relation = {
LE: "le",
LT: "lt",
GE: "ge",
GT: "gt",
EQ: "eq",
NE: "ne",
} as const;
export type Relation = typeof Relation[keyof typeof Relation];

/**
* This is supposed to be an enum, but Node.js v25 does bot support TS' enums, only erasable-syntax.
* Revert to an enum when Node.js supports it, or when we move to a different engine that supports it.
* This and the "type" declaration below.
*/
export const LoopKind = {
for: "for",
while: "while",
dowhile: "dowhile",
foreach: "foreach",
} as const;
export type LoopKind = typeof LoopKind[keyof typeof LoopKind];

/**
* This is supposed to be an enum, but Node.js v25 does bot support TS' enums, only erasable-syntax.
* Revert to an enum when Node.js supports it, or when we move to a different engine that supports it.
* This and the "type" declaration below.
*/
export const ExpressionUse = {
read: "read",
write: "write",
readwrite: "readwrite",
} as const;
export type ExpressionUse = typeof ExpressionUse[keyof typeof ExpressionUse];

/**
* This is supposed to be an enum, but Node.js v25 does bot support TS' enums, only erasable-syntax.
* Revert to an enum when Node.js supports it, or when we move to a different engine that supports it.
* This and the "type" declaration below.
*/
export const OpKind = {
ptr_mem_d: "ptr_mem_d",
ptr_mem_i: "ptr_mem_i",
mul: "mul",
div: "div",
rem: "rem",
add: "add",
sub: "sub",
shl: "shl",
shr: "shr",
cmp: "cmp",
lt: "lt",
gt: "gt",
le: "le",
ge: "ge",
eq: "eq",
ne: "ne",
and: "and",
xor: "xor",
or: "or",
l_and: "l_and",
l_or: "l_or",
assign: "assign",
mul_assign: "mul_assign",
div_assign: "div_assign",
rem_assign: "rem_assign",
add_assign: "add_assign",
sub_assign: "sub_assign",
shl_assign: "shl_assign",
shr_assign: "shr_assign",
and_assign: "and_assign",
xor_assign: "xor_assign",
or_assign: "or_assign",
comma: "comma",
post_inc: "post_inc",
post_dec: "post_dec",
pre_inc: "pre_inc",
pre_dec: "pre_dec",
addr_of: "addr_of",
deref: "deref",
plus: "plus",
minus: "minus",
not: "not",
l_not: "l_not",
real: "real",
imag: "imag",
extension: "extension",
cowait: "cowait",
ternary: "ternary",
} as const;
export type OpKind = typeof OpKind[keyof typeof OpKind];

/**
* This is supposed to be an enum, but Node.js v25 does bot support TS' enums, only erasable-syntax.
* Revert to an enum when Node.js supports it, or when we move to a different engine that supports it.
* This and the "type" declaration below.
*/
export const WrapperStatementKind = {
comment: "comment",
pragma: "pragma",
} as const;
export type WrapperStatementKind = typeof WrapperStatementKind[keyof typeof WrapperStatementKind];

const JoinpointMapper = {
joinpoint: Joinpoint,
Expand Down
Loading
Loading