|
@@ -1,8 +1,17 @@
|
|
|
|
|
+
|
|
|
import Node from './Node.js';
|
|
import Node from './Node.js';
|
|
|
import { getLengthFromType } from './NodeUtils.js';
|
|
import { getLengthFromType } from './NodeUtils.js';
|
|
|
|
|
|
|
|
/** @module StructTypeNode **/
|
|
/** @module StructTypeNode **/
|
|
|
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * Generates a layout for struct members.
|
|
|
|
|
+ * This function takes an object representing struct members and returns an array of member layouts.
|
|
|
|
|
+ * Each member layout includes the member's name, type, and whether it is atomic.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param {Object.<string, string|Object>} members - An object where keys are member names and values are either types (as strings) or objects with type and atomic properties.
|
|
|
|
|
+ * @returns {Array.<{name: string, type: string, atomic: boolean}>} An array of member layouts.
|
|
|
|
|
+ */
|
|
|
function getMembersLayout( members ) {
|
|
function getMembersLayout( members ) {
|
|
|
|
|
|
|
|
return Object.entries( members ).map( ( [ name, value ] ) => {
|
|
return Object.entries( members ).map( ( [ name, value ] ) => {
|
|
@@ -19,6 +28,14 @@ function getMembersLayout( members ) {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * Represents a struct type node in the node-based system.
|
|
|
|
|
+ * This class is used to define and manage the layout and types of struct members.
|
|
|
|
|
+ * It extends the base Node class and provides methods to get the length of the struct,
|
|
|
|
|
+ * retrieve member types, and generate the struct type for a builder.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @augments Node
|
|
|
|
|
+ */
|
|
|
class StructTypeNode extends Node {
|
|
class StructTypeNode extends Node {
|
|
|
|
|
|
|
|
static get type() {
|
|
static get type() {
|
|
@@ -27,17 +44,48 @@ class StructTypeNode extends Node {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Creates an instance of StructTypeNode.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param {Object} membersLayout - The layout of the members for the struct.
|
|
|
|
|
+ * @param {string} [name=null] - The optional name of the struct.
|
|
|
|
|
+ */
|
|
|
constructor( membersLayout, name = null ) {
|
|
constructor( membersLayout, name = null ) {
|
|
|
|
|
|
|
|
super( 'struct' );
|
|
super( 'struct' );
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * The layout of the members for the struct
|
|
|
|
|
+ *
|
|
|
|
|
+ * @type {Array.<{name: string, type: string, atomic: boolean}>}
|
|
|
|
|
+ */
|
|
|
this.membersLayout = getMembersLayout( membersLayout );
|
|
this.membersLayout = getMembersLayout( membersLayout );
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * The name of the struct.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @type {String}
|
|
|
|
|
+ * @default null
|
|
|
|
|
+ */
|
|
|
this.name = name;
|
|
this.name = name;
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * This flag can be used for type testing.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @type {Boolean}
|
|
|
|
|
+ * @readonly
|
|
|
|
|
+ * @default true
|
|
|
|
|
+ */
|
|
|
this.isStructLayoutNode = true;
|
|
this.isStructLayoutNode = true;
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Returns the length of the struct.
|
|
|
|
|
+ * The length is calculated by summing the lengths of the struct's members.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @returns {Number} The length of the struct.
|
|
|
|
|
+ */
|
|
|
getLength() {
|
|
getLength() {
|
|
|
|
|
|
|
|
let length = 0;
|
|
let length = 0;
|