renameVarrefsInFunc
On this page

renameVarrefsInFunc()

Function in IR

Renames variable references in the body of f.

import { renameVarrefsInFunc } from 'typeshade'

The signature, the description and the examples come from the compiler's own source at commit 26de7be8.

Syntax

function renameVarrefsInFunc(
f: FuncDecl,
rename: (name: string) => string | undefined,
): FuncDecl

Parameters

f FuncDecl

The function whose body is rewritten.

rename (name: string) => string | undefined

Maps a current variable name to its new name, or returns undefined to keep the current name.

Return value

FuncDecl

A copy of f with the renamed body, or f itself when no reference was renamed.

Description

Every variable reference (an expression with op: 'varref') is passed to rename by name. When rename returns a string, the reference is re-pointed at that name; when it returns undefined, the reference is kept as is. Unchanged references keep their original objects, and f itself is returned when no name changed (see rewriteExprsInFunc).

Examples

Example

// Point reads of the `u` uniform block at `u_split`.
const g = renameVarrefsInFunc(f, (name) =>
name === 'u' ? 'u_split' : undefined,
)

See also

Source

src/core/passes/rename-varrefs.ts, line 198, at commit 26de7be8

Edit this page Report a problem