📄 AST.js
¶
📊 Analysis Summary¶
Metric | Count |
---|---|
🔧 Functions | 5 |
🧱 Classes | 28 |
📦 Imports | 1 |
📊 Variables & Constants | 1 |
📚 Table of Contents¶
🛠️ File Location:¶
📂 examples/jsm/transpiler/AST.js
📦 Imports¶
Name | Source |
---|---|
toFloatType |
./TranspilerUtils.js |
Variables & Constants¶
Name | Type | Kind | Value | Exported |
---|---|---|---|---|
array |
this[Extract<keyof this, string>] & a... |
let/var | this[ key ] |
✗ |
Functions¶
ASTNode.getType(): any
¶
Returns: any
ASTNode.getParent(parents: any[]): any
¶
Parameters:
parents
any[]
Returns: any
Calls:
parents.push
this.parent.getParent
Code
ASTNode.initialize(): void
¶
Returns: void
Calls:
Array.isArray
Code
Operator.getType(): any
¶
Returns: any
Calls:
this.left.getType
this.right.getType
toFloatType (from ./TranspilerUtils.js)
Code
Accessor.getType(): any
¶
Returns: any
Calls:
this.linker.reference.getType
super.getType
Code
Classes¶
ASTNode
¶
Class Code
export class ASTNode {
constructor() {
this.isASTNode = true;
this.linker = {
reference: null,
accesses: [],
assignments: []
};
this.parent = null;
}
get isNumericExpression() {
return false;
}
get hasAssignment() {
if ( this.isAssignment === true ) {
return true;
}
if ( this.parent === null ) {
return false;
}
return this.parent.hasAssignment;
}
getType() {
return this.type || null;
}
getParent( parents = [] ) {
if ( this.parent === null ) {
return parents;
}
parents.push( this.parent );
return this.parent.getParent( parents );
}
initialize() {
for ( const key in this ) {
if ( this[ key ] && this[ key ].isASTNode ) {
this[ key ].parent = this;
} else if ( Array.isArray( this[ key ] ) ) {
const array = this[ key ];
for ( const item of array ) {
if ( item && item.isASTNode ) {
item.parent = this;
}
}
}
}
}
}
Methods¶
getType(): any
¶
getParent(parents: any[]): any
¶
Code
initialize(): void
¶
Code
Comment
¶
Class Code
Program
¶
Class Code
VariableDeclaration
¶
Class Code
export class VariableDeclaration extends ASTNode {
constructor( type, name, value = null, next = null, immutable = false ) {
super();
this.type = type;
this.name = name;
this.value = value;
this.next = next;
this.immutable = immutable;
this.isVariableDeclaration = true;
this.initialize();
}
get isAssignment() {
return this.value !== null;
}
}
Uniform
¶
Class Code
Varying
¶
Class Code
FunctionParameter
¶
Class Code
FunctionDeclaration
¶
Class Code
Expression
¶
Class Code
Ternary
¶
Class Code
Operator
¶
Class Code
export class Operator extends ASTNode {
constructor( type, left, right ) {
super();
this.type = type;
this.left = left;
this.right = right;
this.isOperator = true;
this.initialize();
}
get isAssignment() {
return /^(=|\+=|-=|\*=|\/=|%=|<<=|>>=|>>>=|&=|\^=|\|=)$/.test( this.type );
}
get isNumericExpression() {
if ( this.left.isNumericExpression && this.right.isNumericExpression ) {
return true;
}
return false;
}
getType() {
const leftType = this.left.getType();
const rightType = this.right.getType();
if ( leftType === rightType ) {
return leftType;
} else if ( toFloatType( leftType ) === toFloatType( rightType ) ) {
return toFloatType( leftType );
}
return null;
}
}
Methods¶
getType(): any
¶
Code
Unary
¶
Class Code
export class Unary extends ASTNode {
constructor( type, expression, after = false ) {
super();
this.type = type;
this.expression = expression;
this.after = after;
this.isUnary = true;
this.initialize();
}
get isAssignment() {
return /^(\+\+|--)$/.test( this.type );
}
get isNumericExpression() {
if ( this.expression.isNumber ) {
return true;
}
return false;
}
}