Forráskód Böngészése

Use ES2015 default parameters

Lutz Roeder 2 hónapja
szülő
commit
3541c229fd

+ 7 - 11
source/acuity.js

@@ -159,28 +159,24 @@ acuity.Node = class {
 
 acuity.Argument = class {
 
-    constructor(name, value, type, visible) {
+    constructor(name, value, type = null, visible = true) {
         this.name = name;
         this.value = value;
-        if (type) {
-            this.type = type;
-        }
-        if (visible === false) {
-            this.visible = false;
-        }
+        this.type = type;
+        this.visible = visible;
     }
 };
 
 acuity.Value = class {
 
-    constructor(name, type, quantization, initializer) {
+    constructor(name, type = null, quantization = null, initializer = null) {
         if (typeof name !== 'string') {
             throw new acuity.Error(`Invalid value identifier '${JSON.stringify(name)}'.`);
         }
         this.name = name;
-        this.type = type || null;
-        this.quantization = quantization || null;
-        this.initializer = initializer || null;
+        this.type = type;
+        this.quantization = quantization;
+        this.initializer = initializer;
     }
 };
 

+ 4 - 4
source/armnn.js

@@ -202,10 +202,10 @@ armnn.Node = class {
 
 armnn.Argument = class {
 
-    constructor(name, value, type) {
+    constructor(name, value, type = null) {
         this.name = name;
         this.value = value;
-        this.type = type || null;
+        this.type = type;
     }
 };
 
@@ -234,9 +234,9 @@ armnn.Value = class {
 
 armnn.Tensor = class {
 
-    constructor(tensor, category) {
+    constructor(tensor, category = '') {
         this.type = new armnn.TensorType(tensor.info);
-        this.category = category || '';
+        this.category = category;
         const data = tensor.data.data.slice(0);
         this.values = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
     }

+ 5 - 5
source/barracuda.js

@@ -79,19 +79,19 @@ barracuda.Graph = class {
 
 barracuda.Argument = class {
 
-    constructor(name, value, type) {
+    constructor(name, value, type = null) {
         this.name = name;
         this.value = value;
-        this.type = type || null;
+        this.type = type;
     }
 };
 
 barracuda.Value = class {
 
-    constructor(name, type, initializer) {
+    constructor(name, type = null, initializer = null) {
         this.name = name;
-        this.type = type || null;
-        this.initializer = initializer || null;
+        this.type = type;
+        this.initializer = initializer;
     }
 };
 

+ 2 - 2
source/bigdl.js

@@ -82,10 +82,10 @@ bigdl.Graph = class {
 
 bigdl.Argument = class {
 
-    constructor(name, value, type) {
+    constructor(name, value, type = null) {
         this.name = name;
         this.value = value;
-        this.type = type || null;
+        this.type = type;
     }
 };
 

+ 6 - 6
source/caffe.js

@@ -316,23 +316,23 @@ caffe.Graph = class {
 
 caffe.Argument = class {
 
-    constructor(name, value, type, visible) {
+    constructor(name, value, type = null, visible = true) {
         this.name = name;
         this.value = value;
-        this.type = type || null;
-        this.visible = visible !== false;
+        this.type = type;
+        this.visible = visible;
     }
 };
 
 caffe.Value = class {
 
-    constructor(name, type, initializer) {
+    constructor(name, type = null, initializer = null) {
         if (typeof name !== 'string') {
             throw new caffe.Error(`Invalid value identifier '${JSON.stringify(name)}'.`);
         }
         this.name = name;
-        this.type = type || null;
-        this.initializer = initializer || null;
+        this.type = type;
+        this.initializer = initializer;
     }
 };
 

+ 5 - 5
source/caffe2.js

@@ -328,24 +328,24 @@ caffe2.Graph = class {
 
 caffe2.Argument = class {
 
-    constructor(name, value, type, visible) {
+    constructor(name, value, type = null, visible = true) {
         this.name = name;
         this.value = value;
-        this.type = type || null;
-        this.visible = visible !== false;
+        this.type = type;
+        this.visible = visible;
     }
 };
 
 caffe2.Value = class {
 
-    constructor(name, type, initializer) {
+    constructor(name, type, initializer = null) {
         if (typeof name !== 'string') {
             throw new caffe2.Error(`Invalid value identifier '${JSON.stringify(name)}'.`);
         }
         this.name = name;
         this.type = !type && initializer ? initializer.type : type;
         this.quantization = initializer && initializer.quantization ? initializer.quantization : null;
-        this.initializer = initializer || null;
+        this.initializer = initializer;
     }
 };
 

+ 3 - 3
source/circle.js

@@ -395,11 +395,11 @@ circle.Node = class {
 
 circle.Argument = class {
 
-    constructor(name, value, type, visible) {
+    constructor(name, value, type = null, visible = true) {
         this.name = name;
         this.value = value;
-        this.type = type || null;
-        this.visible = visible !== false;
+        this.type = type;
+        this.visible = visible;
     }
 };
 

+ 3 - 3
source/cntk.js

@@ -230,11 +230,11 @@ cntk.Graph = class {
 
 cntk.Argument = class {
 
-    constructor(name, value, type, visible) {
+    constructor(name, value, type = null, visible = true) {
         this.name = name;
         this.value = value;
-        this.type = type || null;
-        this.visible = visible !== false;
+        this.type = type;
+        this.visible = visible;
     }
 };
 

+ 6 - 6
source/coreml.js

@@ -268,24 +268,24 @@ coreml.Graph = class {
 
 coreml.Argument = class {
 
-    constructor(name, value, type, visible) {
+    constructor(name, value, type = null, visible = true) {
         this.name = name;
         this.value = value;
-        this.type = type || null;
-        this.visible = visible !== false;
+        this.type = type;
+        this.visible = visible;
     }
 };
 
 coreml.Value = class {
 
-    constructor(name, type, description, initializer) {
+    constructor(name, type, description = null, initializer = null) {
         if (typeof name !== 'string') {
             throw new coreml.Error(`Invalid value identifier '${JSON.stringify(name)}'.`);
         }
         this.name = name;
         this.type = !type && initializer ? initializer.type : type;
-        this.description = description || null;
-        this.initializer = initializer || null;
+        this.description = description;
+        this.initializer = initializer;
         this.quantization = initializer ? initializer.quantization : null;
     }
 };

+ 3 - 3
source/darknet.js

@@ -779,11 +779,11 @@ darknet.Graph = class {
 
 darknet.Argument = class {
 
-    constructor(name, value, type, visible) {
+    constructor(name, value, type = null, visible = true) {
         this.name = name;
         this.value = value;
-        this.type = type || null;
-        this.visible = visible !== false;
+        this.type = type;
+        this.visible = visible;
 
     }
 };

+ 2 - 4
source/dl4j.js

@@ -143,12 +143,10 @@ dl4j.Graph = class {
 
 dl4j.Argument = class {
 
-    constructor(name, value, visible) {
+    constructor(name, value, visible = true) {
         this.name = name;
         this.value = value;
-        if (visible === false) {
-            this.visible = false;
-        }
+        this.visible = visible;
     }
 };
 

+ 2 - 2
source/dlc.js

@@ -125,10 +125,10 @@ dlc.Graph = class {
 
 dlc.Argument = class {
 
-    constructor(name, value, type) {
+    constructor(name, value, type = null) {
         this.name = name;
         this.value = value;
-        this.type = type || null;
+        this.type = type;
     }
 };
 

+ 3 - 3
source/dnn.js

@@ -105,13 +105,13 @@ dnn.Argument = class {
 
 dnn.Value = class {
 
-    constructor(name, type, initializer, quantization) {
+    constructor(name, type = null, initializer = null, quantization = null) {
         if (typeof name !== 'string') {
             throw new dnn.Error(`Invalid value identifier '${JSON.stringify(name)}'.`);
         }
         this.name = name;
-        this.type = type || null;
-        this.initializer = initializer || null;
+        this.type = type;
+        this.initializer = initializer;
         if (quantization) {
             this.quantization = {
                 type: 'lookup',

+ 1 - 1
source/dot.js

@@ -205,7 +205,7 @@ dot.Graph = class {
 
 dot.Argument = class {
 
-    constructor(name, value, type) {
+    constructor(name, value, type = null) {
         this.name = name;
         this.value = value;
         this.type = type;

+ 6 - 6
source/espresso.js

@@ -120,24 +120,24 @@ espresso.Graph = class {
 
 espresso.Argument = class {
 
-    constructor(name, value, type, visible) {
+    constructor(name, value, type = null, visible = true) {
         this.name = name;
         this.value = value;
-        this.type = type || null;
-        this.visible = visible !== false;
+        this.type = type;
+        this.visible = visible;
     }
 };
 
 espresso.Value = class {
 
-    constructor(name, type, description, initializer) {
+    constructor(name, type, description = null, initializer = null) {
         if (typeof name !== 'string') {
             throw new espresso.Error(`Invalid value identifier '${JSON.stringify(name)}'.`);
         }
         this.name = name;
         this.type = !type && initializer ? initializer.type : type;
-        this.description = description || null;
-        this.initializer = initializer || null;
+        this.description = description;
+        this.initializer = initializer;
         this.quantization = initializer ? initializer.quantization : null;
     }
 };

+ 28 - 28
source/executorch.js

@@ -130,23 +130,23 @@ executorch.Graph = class {
 
 executorch.Argument = class {
 
-    constructor(name, value, type, visible) {
+    constructor(name, value, type = null, visible = true) {
         this.name = name;
         this.value = value;
-        this.type = type || null;
-        this.visible = visible !== false;
+        this.type = type;
+        this.visible = visible;
     }
 };
 
 executorch.Value = class Value {
 
-    constructor(name, type, initializer) {
+    constructor(name, type, initializer = null) {
         if (typeof name !== 'string') {
             throw new executorch.Error(`Invalid value identifier '${JSON.stringify(name)}'.`);
         }
         this.name = name;
         this.type = initializer && initializer.type ? initializer.type : type || null;
-        this.initializer = initializer || null;
+        this.initializer = initializer;
     }
 };
 
@@ -280,8 +280,8 @@ executorch.TensorType = class {
 
 executorch.TensorShape = class {
 
-    constructor(dimensions) {
-        this.dimensions = dimensions || [];
+    constructor(dimensions = []) {
+        this.dimensions = dimensions;
     }
 
     toString() {
@@ -584,23 +584,23 @@ xnnpack.Node = class {
 
 xnnpack.Argument = class {
 
-    constructor(name, value, type, visible) {
+    constructor(name, value, type = null, visible = true) {
         this.name = name;
         this.value = value;
-        this.type = type || null;
-        this.visible = visible !== false;
+        this.type = type;
+        this.visible = visible;
     }
 };
 
 xnnpack.Value = class Value {
 
-    constructor(name, type, initializer) {
+    constructor(name, type, initializer = null) {
         if (typeof name !== 'string') {
             throw new executorch.Error(`Invalid value identifier '${JSON.stringify(name)}'.`);
         }
         this.name = name;
         this.type = initializer && initializer.type ? initializer.type : type || null;
-        this.initializer = initializer || null;
+        this.initializer = initializer;
     }
 };
 
@@ -668,8 +668,8 @@ xnnpack.TensorType = class {
 
 xnnpack.TensorShape = class {
 
-    constructor(dimensions) {
-        this.dimensions = dimensions || [];
+    constructor(dimensions = []) {
+        this.dimensions = dimensions;
     }
 
     toString() {
@@ -839,23 +839,23 @@ vulkan.Node = class {
 
 vulkan.Argument = class {
 
-    constructor(name, value, type, visible) {
+    constructor(name, value, type = null, visible = true) {
         this.name = name;
         this.value = value;
-        this.type = type || null;
-        this.visible = visible !== false;
+        this.type = type;
+        this.visible = visible;
     }
 };
 
 vulkan.Value = class Value {
 
-    constructor(name, type, initializer) {
+    constructor(name, type, initializer = null) {
         if (typeof name !== 'string') {
             throw new executorch.Error(`Invalid value identifier '${JSON.stringify(name)}'.`);
         }
         this.name = name;
         this.type = initializer && initializer.type ? initializer.type : type || null;
-        this.initializer = initializer || null;
+        this.initializer = initializer;
     }
 };
 
@@ -877,8 +877,8 @@ vulkan.TensorType = class {
 
 vulkan.TensorShape = class {
 
-    constructor(dimensions) {
-        this.dimensions = dimensions || [];
+    constructor(dimensions = []) {
+        this.dimensions = dimensions;
     }
 
     toString() {
@@ -1206,23 +1206,23 @@ ethosu.Graph = class {
 
 ethosu.Argument = class {
 
-    constructor(name, value, type, visible) {
+    constructor(name, value, type = null, visible = true) {
         this.name = name;
         this.value = value;
-        this.type = type || null;
-        this.visible = visible !== false;
+        this.type = type;
+        this.visible = visible;
     }
 };
 
 ethosu.Value = class Value {
 
-    constructor(name, type, initializer) {
+    constructor(name, type, initializer = null) {
         if (typeof name !== 'string') {
             throw new executorch.Error(`Invalid value identifier '${JSON.stringify(name)}'.`);
         }
         this.name = name;
         this.type = initializer && initializer.type ? initializer.type : type || null;
-        this.initializer = initializer || null;
+        this.initializer = initializer;
     }
 };
 
@@ -1246,8 +1246,8 @@ ethosu.TensorType = class {
 
 ethosu.TensorShape = class {
 
-    constructor(dimensions) {
-        this.dimensions = dimensions || [];
+    constructor(dimensions = []) {
+        this.dimensions = dimensions;
     }
 
     toString() {

+ 2 - 2
source/flax.js

@@ -99,13 +99,13 @@ flax.Argument = class {
 
 flax.Value = class {
 
-    constructor(name, initializer) {
+    constructor(name, initializer = null) {
         if (typeof name !== 'string') {
             throw new flax.Error(`Invalid value identifier '${JSON.stringify(name)}'.`);
         }
         this.name = name;
         this.type = initializer ? initializer.type : null;
-        this.initializer = initializer || null;
+        this.initializer = initializer;
     }
 };
 

+ 2 - 2
source/gguf.js

@@ -81,9 +81,9 @@ gguf.Model = class {
 
 gguf.Graph = class {
 
-    constructor(graph, type) {
+    constructor(graph, type = '') {
         this.name = graph.type;
-        this.type = type || '';
+        this.type = type;
         this.nodes = [];
         this.inputs = [];
         this.outputs = [];

+ 3 - 3
source/hailo.js

@@ -108,11 +108,11 @@ hailo.Graph = class {
 
 hailo.Argument = class {
 
-    constructor(name, value, type, visible) {
+    constructor(name, value, type = null, visible = true) {
         this.name = name;
         this.value = value;
-        this.type = type || null;
-        this.visible = visible !== false;
+        this.type = type;
+        this.visible = visible;
     }
 };
 

+ 2 - 2
source/hickle.js

@@ -89,13 +89,13 @@ hickle.Argument = class {
 
 hickle.Value = class {
 
-    constructor(name, type, initializer) {
+    constructor(name, type, initializer = null) {
         if (typeof name !== 'string') {
             throw new hickle.Error(`Invalid value identifier '${JSON.stringify(name)}'.`);
         }
         this.name = name;
         this.type = !type && initializer ? initializer.type : type;
-        this.initializer = initializer || null;
+        this.initializer = initializer;
     }
 };
 

+ 1 - 1
source/kann.js

@@ -134,7 +134,7 @@ kann.Node = class {
 
 kann.Argument = class {
 
-    constructor(name, value, type) {
+    constructor(name, value, type = null) {
         this.name = name;
         this.value = value;
         this.type = type;

+ 5 - 5
source/keras.js

@@ -885,24 +885,24 @@ keras.Graph = class {
 
 keras.Argument = class {
 
-    constructor(name, value, type, visible) {
+    constructor(name, value, type = null, visible = true) {
         this.name = name;
         this.value = value;
-        this.type = type || null;
-        this.visible = visible !== false;
+        this.type = type;
+        this.visible = visible;
     }
 };
 
 keras.Value = class {
 
-    constructor(name, type, initializer) {
+    constructor(name, type, initializer = null) {
         if (typeof name !== 'string') {
             throw new keras.Error(`Invalid value identifier '${JSON.stringify(name)}'.`);
         }
         this.name = name;
         this.type = !type && initializer ? initializer.type  : type;
         this.quantization = initializer && initializer.quantization ? initializer.quantization : null;
-        this.initializer = initializer || null;
+        this.initializer = initializer;
     }
 };
 

+ 2 - 2
source/lasagne.js

@@ -74,10 +74,10 @@ lasagne.Graph = class {
 
 lasagne.Argument = class {
 
-    constructor(name, value, type) {
+    constructor(name, value, type = null) {
         this.name = name;
         this.value = value;
-        this.type = type || null;
+        this.type = type;
     }
 };
 

+ 2 - 2
source/lightgbm.js

@@ -74,10 +74,10 @@ lightgbm.Graph = class {
 
 lightgbm.Argument = class {
 
-    constructor(name, value, type) {
+    constructor(name, value, type = null) {
         this.name = name;
         this.value = value;
-        this.type = type || null;
+        this.type = type;
     }
 };
 

+ 2 - 2
source/mediapipe.js

@@ -193,12 +193,12 @@ mediapipe.Argument = class {
 
 mediapipe.Value = class {
 
-    constructor(name, type) {
+    constructor(name, type = null) {
         if (typeof name !== 'string') {
             throw new mediapipe.Error(`Invalid value identifier '${JSON.stringify(name)}'.`);
         }
         this.name = name;
-        this.type = type || null;
+        this.type = type;
     }
 };
 

+ 3 - 3
source/megengine.js

@@ -403,11 +403,11 @@ megengine.Graph = class {
 
 megengine.Argument = class {
 
-    constructor(name, value, type, visible) {
+    constructor(name, value, type = null, visible = true) {
         this.name = name;
         this.value = value;
-        this.type = type || null;
-        this.visible = visible !== false;
+        this.type = type;
+        this.visible = visible;
     }
 };
 

+ 296 - 196
source/mlir.js

@@ -53,9 +53,10 @@ mlir.ModelFactory = class {
         switch (context.type) {
             case 'mlir.text': {
                 const decoder = await context.read('text.decoder');
-                const parser = new mlir.Parser(decoder, metadata);
-                const obj = await parser.read();
-                return new mlir.Model(metadata, obj);
+                const state = new mlir.ParserState();
+                const parser = new mlir.Parser(state, decoder, metadata);
+                const block = await parser.parse();
+                return new mlir.Model(metadata, block, state.attributeAliasDefinitions);
             }
             case 'mlir.binary': {
                 const reader = await context.read('binary');
@@ -72,11 +73,11 @@ mlir.ModelFactory = class {
 
 mlir.Model = class {
 
-    constructor(metadata, obj) {
+    constructor(metadata, block, attributeAliasDefinitions) {
         this.format = 'MLIR';
         this.modules = [];
         this.metadata = [];
-        for (const op of obj.operations) {
+        for (const op of block.operations) {
             if (op.name.endsWith('.func')) {
                 const graph = new mlir.Graph(metadata, op);
                 this.modules.push(graph);
@@ -94,15 +95,13 @@ mlir.Model = class {
                 }
             }
         }
-        if (obj.definitions) {
-            for (const attribute of obj.definitions) {
-                let value = attribute.type;
-                if (!value) {
-                    value = typeof attribute.value === 'string' ? attribute.value : JSON.stringify(attribute.value);
-                }
-                const metadata = new mlir.Argument(attribute.name, value, 'attribute');
-                this.metadata.push(metadata);
+        for (const [name, attribute] of attributeAliasDefinitions) {
+            let value = attribute.type;
+            if (!value) {
+                value = typeof attribute.value === 'string' ? attribute.value : JSON.stringify(attribute.value);
             }
+            const metadata = new mlir.Argument(name, value, 'attribute');
+            this.metadata.push(metadata);
         }
     }
 };
@@ -300,10 +299,10 @@ mlir.Graph = class {
 
 mlir.Argument = class {
 
-    constructor(name, value, type) {
+    constructor(name, value, type = null) {
         this.name = name;
         this.value = value;
-        this.type = type || null;
+        this.type = type;
         // Normalize common type aliases and accept extended MLIR types
         if (this.type) {
             // Convert mlir.Type objects to strings for high-level usage
@@ -862,15 +861,20 @@ mlir.Tokenizer = class {
     }
 };
 
+mlir.ParserState = class {
+    constructor() {
+        this.defaultDialectStack = ['builtin'];
+        this.attributeAliasDefinitions = new Map();
+        this.typeAliasDefinitions = new Map();
+    }
+};
+
 mlir.Parser = class {
 
-    constructor(decoder, metadata) {
+    constructor(state, decoder, metadata) {
         this._tokenizer = new mlir.Tokenizer(decoder);
         this._token = this._tokenizer.read();
-        this._state = {
-            defaultDialectStack: ['builtin']
-        };
-        this._typeAliases = new Map();
+        this._state = state;
         this._dialects = new Map();
         const operations = metadata.operations;
         this._dialects.set('builtin', new mlir.BuiltinDialect(operations));
@@ -1014,6 +1018,7 @@ mlir.Parser = class {
         this._redirect = new Map([
             ['builtin.func', 'func.func'],
             ['builtin.constant', 'arith.constant'],
+            ['func.constant', 'arith.constant'],
             ['builtin.return', 'func.return'],
             ['builtin.select', 'arith.select'],
             ['scf.select', 'arith.select'],
@@ -1068,52 +1073,28 @@ mlir.Parser = class {
         ]);
     }
 
-    async read() {
-        return this.parse();
-    }
-
-    parse() {
+    async parse() {
+        // Reference: Parser.cpp TopLevelOperationParser::parse
         // https://mlir.llvm.org/docs/LangRef/#top-level-productions
         const block = {
-            operations: [],
-            definitions: []
+            operations: []
         };
         while (true) {
             if (this.match('eof')) {
                 break;
             }
-            if (this.match('#')) { // attribute-alias-def
-                const name = this.expect();
-                this.expect('=');
-                // Handle pre-2020 bare affine map syntax: (dims) [symbols] -> (results)
-                // Changed to affine_map<...> in llvm/llvm-project@4268e4f4b84b (Jan 2020) to avoid conflicts with function types.
-                let value = null;
-                if (this.match('(')) {
-                    const dims = this.skip('(', ')');
-                    const symbols = this.match('[') ? this.skip('[', ']') : '';
-                    this.expect('->');
-                    const results = this.match('(') ? this.skip('(', ')') : '';
-                    value = { value: `affine_map<${dims}${symbols} -> ${results}>`, name: 'affine_map' };
-                } else {
-                    value = this.parseAttribute();
-                }
-                block.definitions.push({ name, value });
+            if (this.match('#')) {
+                // Reference: parseAttributeAliasDef stores in state.symbols.attributeAliasDefinitions
+                this.parseAttributeAliasDef();
                 continue;
             }
-            if (this.match('!')) { // type-alias-def
-                const name = this.expect('!');
-                this.expect('=');
-                const type = this.parseType();
-                block.definitions.push({ name, type });
-                this._typeAliases.set(name, type);
+            if (this.match('!')) {
+                // Reference: parseTypeAliasDef stores in state.symbols.typeAliasDefinitions
+                this.parseTypeAliasDef();
                 continue;
             }
-            if (this.match('{-#')) { // file metadata
-                this.expect('{-#');
-                while (!this.match('#-}') && !this.match('eof')) {
-                    this._token = this._tokenizer.read();
-                }
-                this.expect('#-}');
+            if (this.match('{-#')) {
+                this.parseFileMetadataDictionary();
                 continue;
             }
             const op = this.parseOperation();
@@ -1122,6 +1103,48 @@ mlir.Parser = class {
         return block;
     }
 
+    // Reference: Parser.cpp parseAttributeAliasDef lines 2695-2725
+    // attribute-alias-def ::= '#' alias-name `=` attribute-value
+    parseAttributeAliasDef() {
+        const aliasName = this.expect();
+        this.expect('=');
+        // Handle pre-2020 bare affine map syntax: (dims) [symbols] -> (results)
+        // Changed to affine_map<...> in llvm/llvm-project@4268e4f4b84b (Jan 2020)
+        let attr = null;
+        if (this.match('(')) {
+            const dims = this.skip('(', ')');
+            const symbols = this.match('[') ? this.skip('[', ']') : '';
+            this.expect('->');
+            const results = this.match('(') ? this.skip('(', ')') : '';
+            attr = { value: `affine_map<${dims}${symbols} -> ${results}>`, name: 'affine_map' };
+        } else {
+            // Reference: Attribute attr = parseAttribute();
+            attr = this.parseAttribute();
+        }
+        // Reference: state.symbols.attributeAliasDefinitions[aliasName] = attr;
+        this._state.attributeAliasDefinitions.set(aliasName, attr);
+    }
+
+    // Reference: Parser.cpp parseTypeAliasDef lines 2727-2757
+    // type-alias-def ::= '!' alias-name `=` type
+    parseTypeAliasDef() {
+        const aliasName = this.expect('!');
+        this.expect('=');
+        const type = this.parseType();
+        // Reference: state.symbols.typeAliasDefinitions[aliasName] = type;
+        this._state.typeAliasDefinitions.set(aliasName, type);
+    }
+
+    // Reference: Parser.cpp parseFileMetadataDictionary
+    // file-metadata-dict ::= '{-#' file-metadata-entry* `#-}'
+    parseFileMetadataDictionary() {
+        this.expect('{-#');
+        while (!this.match('#-}') && !this.match('eof')) {
+            this._token = this._tokenizer.read();
+        }
+        this.expect('#-}');
+    }
+
     parseFunctionArgumentList(allowVariadic) {
         const inputs = [];
         let isVariadic = false;
@@ -1654,33 +1677,36 @@ mlir.Parser = class {
             const location = {};
             this.expect('(');
             if (this.match('string')) {
-                const str = this.expect('string');
-                if (this.match('(')) {
-                    location.name = str;
-                    this.expect('(');
-                    location.child = this.parseLocationContent();
+                const text = this.expect('string');
+                let content = `"${text}"`;
+                if (this.accept('(')) {
+                    const child = this.parseLocationContent();
                     this.expect(')');
-                } else {
-                    location.file = str;
+                    content += `(${child})`;
+                } else if (this.accept(':')) {
+                    const line = this.expect('int');
+                    content += `:${line}`;
                     if (this.accept(':')) {
-                        location.line = this.expect('int');
-                        if (this.accept(':')) {
-                            location.col = this.expect('int');
-                            if (this.accept('id', 'to')) {
+                        const col = this.expect('int');
+                        content += `:${col}`;
+                        if (this.accept('id', 'to')) {
+                            if (this.accept(':')) {
+                                const endLine = this.expect('int');
+                                content += ` to:${endLine}`;
                                 if (this.accept(':')) {
-                                    location.endLine = this.expect('int');
-                                    if (this.accept(':')) {
-                                        location.endCol = this.expect('int');
-                                    }
+                                    const endCol = this.expect('int');
+                                    content += `:${endCol}`;
                                 }
                             }
                         }
                     }
                 }
+                location.value = `loc(${content})`;
             } else if (this.match('#')) {
-                location.alias = this.expect();
+                const alias = this.expect();
+                location.value = `loc(${alias})`;
             } else if (this.accept('id', 'unknown')) {
-                location.unknown = true;
+                location.value = 'loc(unknown)';
             } else if (this.accept('id', 'callsite')) {
                 this.expect('(');
                 location.type = 'callsite';
@@ -2302,7 +2328,7 @@ mlir.Parser = class {
 
     // Reference: DialectSymbolParser.cpp parseExtendedType
     parseExtendedType() {
-        return this.parseExtendedSymbol('!', this._typeAliases, (dialectName, symbolData) => {
+        return this.parseExtendedSymbol('!', this._state.typeAliasDefinitions, (dialectName, symbolData) => {
             if (!this._dialects.has(dialectName)) {
                 throw new mlir.Error(`Unsupported dialect '${dialectName}' ${this.location()}`);
             }
@@ -2589,42 +2615,39 @@ mlir.Parser = class {
         return null;
     }
 
-    // Reference: AttributeParser.cpp parseAttribute
-    parseAttribute(/* type */) {
+    // Reference: AttributeParser.cpp parseAttribute(Type type = {})
+    // When type is null (default), parse `: type` suffix for int/float/string
+    // When type is provided, use it directly without parsing suffix
+    parseAttribute(type = null) {
         // Parse an AffineMap or IntegerSet attribute.
         if (this.match('id', 'affine_map') || this.match('id', 'affine_set')) {
             const name = this.expect();
             const args = this.skip('<', '>');
-            return { name, args };
+            return { value: `${name}${args}` };
         }
         // Parse an array attribute.
+        // Reference: AttributeParser.cpp lines 73-84
         if (this.match('[')) {
             this.expect('[');
             const elements = [];
             while (!this.accept(']')) {
+                // Reference: elements.push_back(parseAttribute());
                 const item = this.parseAttribute();
-                // Handle optional type annotation (e.g., 8 : index)
-                if (this.accept(':')) {
-                    item.type = this.parseType();
-                }
                 elements.push(item.value);
                 this.accept(',');
             }
             // Handle special `[a] x [b]` syntax (dialect-specific)
             if (this.accept('id', 'x')) {
-                const list = [Array.from(elements)];
+                const value = [Array.from(elements)];
                 this.expect('[');
                 const second = [];
                 while (!this.accept(']')) {
                     const item = this.parseAttribute();
-                    if (this.accept(':')) {
-                        item.type = this.parseType();
-                    }
                     second.push(item.value);
                     this.accept(',');
                 }
-                list.push(second);
-                return { value: list };
+                value.push(second);
+                return { value };
             }
             return { value: elements };
         }
@@ -2634,25 +2657,37 @@ mlir.Parser = class {
             return { value, type: new mlir.PrimitiveType('i1') };
         }
         // Parse a dense elements attribute.
-        // Reference: AttributeParser.cpp parseDenseElementsAttr
+        // Reference: AttributeParser.cpp parseDenseElementsAttr(Type attrType)
+        // Format: dense<literal> : type  (type suffix only if attrType not provided)
         if (this.match('id', 'dense')) {
             this.expect('id');
             this.expect('<');
-            if (this.accept('>')) {
-                return { value: null, type: 'dense' };
+            let value = null;
+            if (!this.accept('>')) {
+                const literalParser = new mlir.TensorLiteralParser(this);
+                value = literalParser.parse(/* allowHex */ true);
+                this.expect('>');
             }
-            const literalParser = new mlir.TensorLiteralParser(this);
-            const value = literalParser.parse(/* allowHex */ true);
-            this.expect('>');
-            return { value, type: 'dense' };
+            // Reference: if (!attrType) { parseToken(Token::colon); attrType = parseType(); }
+            if (!type) {
+                this.expect(':');
+                type = this.parseType();
+            }
+            return { value, type };
         }
         // Parse a dense resource elements attribute.
+        // Reference: AttributeParser.cpp parseDenseResourceElementsAttr(Type attrType)
+        // Format: dense_resource<handle> : type  (type suffix only if attrType not provided)
         if (this.match('id', 'dense_resource')) {
             this.expect('id');
             this.expect('<');
-            const resourceHandle = this.expect();
+            const value = this.expect();
             this.expect('>');
-            return { value: resourceHandle, type: 'dense' };
+            if (!type) {
+                this.expect(':');
+                type = this.parseType();
+            }
+            return { value, type };
         }
         // Parse a dense array attribute.
         if (this.match('id', 'array')) {
@@ -2674,36 +2709,49 @@ mlir.Parser = class {
         if (this.match('{')) {
             const attributes = [];
             this.parseAttributeDict(attributes);
-            const obj = {};
+            const value = {};
             for (const attribute of attributes) {
-                obj[attribute.name] = attribute.value;
+                value[attribute.name] = attribute.value;
             }
-            return { value: obj };
+            return { value };
         }
         // Parse an extended attribute, i.e. alias or dialect attribute.
         if (this.match('#')) {
             return this.parseExtendedAttr();
         }
+        const parseType = (type, defaultType) => {
+            if (type) {
+                return type;
+            }
+            return this.accept(':') ? this.parseType() : defaultType;
+        };
         // Parse floating point attribute.
+        // Reference: AttributeParser.cpp parseFloatAttr
         if (this.match('float')) {
             const value = this.expect();
-            return { value, type: new mlir.PrimitiveType('f64') };
+            type = parseType(type, new mlir.PrimitiveType('f64'));
+            return { value, type };
         }
         // Parse integer attribute.
+        // Reference: AttributeParser.cpp parseDecOrHexAttr lines 406-418
         if (this.match('int')) {
             const value = this.expect();
-            return { value, type: new mlir.PrimitiveType('i64') };
+            type = parseType(type, new mlir.PrimitiveType('i64'));
+            return { value, type };
         }
         // Parse negative number.
+        // Reference: AttributeParser.cpp parseAttribute case Token::minus
         if (this.match('keyword', '-')) {
             this.expect();
             if (this.match('int')) {
                 const value = `-${this.expect()}`;
-                return { value, type: new mlir.PrimitiveType('i64') };
+                type = parseType(type, new mlir.PrimitiveType('i64'));
+                return { value, type };
             }
             if (this.match('float')) {
                 const value = `-${this.expect()}`;
-                return { value, type: new mlir.PrimitiveType('f64') };
+                type = parseType(type, new mlir.PrimitiveType('f64'));
+                return { value, type };
             }
             throw new mlir.Error(`Expected integer or float after '-' ${this.location()}`);
         }
@@ -2712,23 +2760,30 @@ mlir.Parser = class {
             return this.parseLocation();
         }
         // Parse a sparse elements attribute.
-        // Reference: AttributeParser.cpp parseSparseElementsAttr
+        // Reference: AttributeParser.cpp parseSparseElementsAttr(Type attrType)
+        // Format: sparse<indices, values> : type  (type suffix only if attrType not provided)
         if (this.match('id', 'sparse')) {
             this.expect('id');
             this.expect('<');
+            let indices = null;
+            let values = null;
             // Parse empty sparse: sparse<>
-            if (this.accept('>')) {
-                return { value: { indices: null, values: null }, type: 'sparse' };
-            }
-            // Parse indices (no hex allowed)
-            const indiceParser = new mlir.TensorLiteralParser(this);
-            const indices = indiceParser.parse(/* allowHex */ false);
-            this.expect(',');
-            // Parse values (hex allowed)
-            const valuesParser = new mlir.TensorLiteralParser(this);
-            const values = valuesParser.parse(/* allowHex */ true);
-            this.expect('>');
-            return { value: { indices, values }, type: 'sparse' };
+            if (!this.accept('>')) {
+                // Parse indices (no hex allowed)
+                const indiceParser = new mlir.TensorLiteralParser(this);
+                indices = indiceParser.parse(/* allowHex */ false);
+                this.expect(',');
+                // Parse values (hex allowed)
+                const valuesParser = new mlir.TensorLiteralParser(this);
+                values = valuesParser.parse(/* allowHex */ true);
+                this.expect('>');
+            }
+            let sparseType = type;
+            if (!sparseType) {
+                this.expect(':');
+                sparseType = this.parseType();
+            }
+            return { value: { indices, values }, type: sparseType };
         }
         // Parse a strided layout attribute.
         if (this.match('id', 'strided')) {
@@ -2737,15 +2792,26 @@ mlir.Parser = class {
             return { value: `strided${body}`, type: 'strided' };
         }
         // Parse a distinct attribute.
+        // Reference: AttributeParser.cpp parseDistinctAttr
+        // Format: distinct[id]<attribute>
         if (this.match('id', 'distinct')) {
             this.expect('id');
-            const body = this.skip('[', ']');
-            return { value: `distinct${body}`, type: 'distinct' };
+            const id = this.skip('[', ']');
+            this.expect('<');
+            let referencedAttr = null;
+            if (!this.match('>')) {
+                // Reference: referencedAttr = parseAttribute(type);
+                referencedAttr = this.parseAttribute();
+            }
+            this.expect('>');
+            return { value: `distinct${id}`, referencedAttr, type: 'distinct' };
         }
         // Parse a string attribute.
+        // Reference: AttributeParser.cpp case Token::string lines 160-168
         if (this.match('string')) {
             const value = this.expect();
-            return { value, type: new mlir.PrimitiveType('string') };
+            type = parseType(type, new mlir.PrimitiveType('string'));
+            return { value, type };
         }
         // Parse a symbol reference attribute.
         if (this.match('@')) {
@@ -2796,9 +2862,9 @@ mlir.Parser = class {
             return { value };
         }
         // Reference: AttributeParser.cpp default case - try to parse a type attribute
-        const type = this.parseOptionalType();
-        if (type) {
-            return { value: type, type: 'type' };
+        const typeAttr = this.parseOptionalType();
+        if (typeAttr) {
+            return { value: typeAttr, type: 'type' };
         }
         throw new mlir.Error(`Unexpected attribute token '${this._token.value}' ${this.location()}`);
     }
@@ -3889,6 +3955,27 @@ mlir.Dialect = class {
         this.registerCustomAttribute('AnyAttrOf', this._parseAnyAttrOf.bind(this));
         this.registerCustomAttribute('ArrayAttr', this._parseArrayAttr.bind(this));
         this.registerCustomAttribute('TypedArrayAttrBase', this._parseArrayAttr.bind(this));
+        // Register integer attribute types - parse without : type suffix
+        // Reference: for typed attributes, the type is known so no suffix needed
+        this.registerCustomAttribute('I64Attr', this._parseIntegerAttr.bind(this, 'i64'));
+        this.registerCustomAttribute('I32Attr', this._parseIntegerAttr.bind(this, 'i32'));
+        this.registerCustomAttribute('I16Attr', this._parseIntegerAttr.bind(this, 'i16'));
+        this.registerCustomAttribute('I8Attr', this._parseIntegerAttr.bind(this, 'i8'));
+        this.registerCustomAttribute('I1Attr', this._parseIntegerAttr.bind(this, 'i1'));
+        this.registerCustomAttribute('SI64Attr', this._parseIntegerAttr.bind(this, 'si64'));
+        this.registerCustomAttribute('SI32Attr', this._parseIntegerAttr.bind(this, 'si32'));
+        this.registerCustomAttribute('UI64Attr', this._parseIntegerAttr.bind(this, 'ui64'));
+        this.registerCustomAttribute('UI32Attr', this._parseIntegerAttr.bind(this, 'ui32'));
+        this.registerCustomAttribute('IndexAttr', this._parseIntegerAttr.bind(this, 'index'));
+        // Register float attribute types
+        this.registerCustomAttribute('F64Attr', this._parseFloatAttr.bind(this, 'f64'));
+        this.registerCustomAttribute('F32Attr', this._parseFloatAttr.bind(this, 'f32'));
+        this.registerCustomAttribute('F16Attr', this._parseFloatAttr.bind(this, 'f16'));
+        this.registerCustomAttribute('BF16Attr', this._parseFloatAttr.bind(this, 'bf16'));
+        // String attributes - pass string type to prevent : type suffix parsing
+        this.registerCustomAttribute('StrAttr', this._parseStrAttr.bind(this));
+        // Level attribute - parse as index to prevent : type suffix parsing
+        this.registerCustomAttribute('LevelAttr', this._parseIntegerAttr.bind(this, 'index'));
         this.registerCustomType('Optional', this._parseOptional.bind(this));
         for (const metadata of operations.get(name) || []) {
             const op = { metadata };
@@ -4401,6 +4488,7 @@ mlir.Dialect = class {
                 if (attrType && attrType !== 'Attribute') {
                     attrValue = this._parseCustomAttributeWithFallback(parser, attrType);
                 } else {
+                    // In assembly format, don't parse : type suffix (default parseTypeSuffix = false)
                     attrValue = parser.parseAttribute();
                 }
                 if (attrValue) {
@@ -4977,25 +5065,10 @@ mlir.Dialect = class {
         return this._parseCustomAttributeWithFallback(parser, baseType);
     }
 
+    // Reference: TypedAttrInterface attributes parse via parseAttribute()
+    // parseAttribute handles `: type` suffix internally when type is null
     _parseTypedAttrInterface(parser) {
-        if (parser.match('#')) {
-            const attr = parser.parseAttribute();
-            // Handle typed attribute with trailing : type
-            if (parser.accept(':')) {
-                const type = parser.parseType();
-                attr.type = type;
-            }
-            return attr;
-        }
-        const value = parser.parseAttribute();
-        if (parser.accept(':')) {
-            const type = parser.parseType();
-            if (value && value.value !== undefined) {
-                return { value: value.value, attrType: type };
-            }
-            return { value, attrType: type };
-        }
-        return value;
+        return parser.parseAttribute();
     }
 
     _parseUnitAttr() {
@@ -5010,6 +5083,28 @@ mlir.Dialect = class {
         return null;
     }
 
+    // Parse typed integer attribute (I64Attr, I32Attr, etc.)
+    // Reference: for typed attributes, the type is known so no : type suffix parsing
+    _parseIntegerAttr(typeName, parser) {
+        const type = new mlir.PrimitiveType(typeName);
+        // Use parseAttribute with the known type to avoid suffix parsing
+        return parser.parseAttribute(type);
+    }
+
+    // Parse typed float attribute (F64Attr, F32Attr, etc.)
+    _parseFloatAttr(typeName, parser) {
+        const type = new mlir.PrimitiveType(typeName);
+        // Use parseAttribute with the known type to avoid suffix parsing
+        return parser.parseAttribute(type);
+    }
+
+    // Parse string attribute (StrAttr)
+    // Pass string type to prevent : type suffix parsing
+    _parseStrAttr(parser) {
+        const type = new mlir.PrimitiveType('string');
+        return parser.parseAttribute(type);
+    }
+
     _parseDynamicIndexList(parser, op, args) {
         // Determine delimiter from args (default to square brackets for backward compatibility)
         // Args format: [$dynamic_basis, $static_basis, $scalable_basis, "::mlir::AsmParser::Delimiter::Paren"]
@@ -6348,7 +6443,8 @@ mlir.MemRefDialect = class extends mlir.Dialect {
             if (parser.accept('id', 'uninitialized')) {
                 op.attributes.push({ name: initialValueArg, value: 'uninitialized' });
             } else {
-                const initialValue = parser.parseAttribute();
+                // Pass the type to parseAttribute to suppress : type suffix parsing
+                const initialValue = parser.parseAttribute(type);
                 op.attributes.push({ name: initialValueArg, value: initialValue });
             }
         }
@@ -8103,14 +8199,15 @@ mlir.StreamDialect = class extends mlir.IREEDialect {
         } while (parser.accept(','));
     }
 
-    // Parse: @entry_point or [@entry_point1, @entry_point2]
+    // Parse: @entry_point or {@entry_point1, @entry_point2}
+    // Reference: StreamOps.cpp parseDispatchEntryPoints
     _parseDispatchEntryPoints(parser, op /*, args */) {
-        if (parser.accept('[')) {
+        if (parser.accept('{')) {
             do {
                 const symbol = parser.expect('@');
                 op.attributes.push({ name: 'entry_point', value: symbol });
             } while (parser.accept(','));
-            parser.expect(']');
+            parser.expect('}');
         } else {
             const symbol = parser.expect('@');
             op.attributes.push({ name: 'entry_point', value: symbol });
@@ -9937,18 +10034,12 @@ mlir.SPIRVDialect = class extends mlir.Dialect {
             }
             return true;
         }
+        // Reference: ControlFlowOps.cpp BranchConditionalOp::parse
+        // Format: spirv.BranchConditional %cond [trueWeight, falseWeight]?, ^trueTarget(args)?, ^falseTarget(args)?
         if (opName === 'spirv.BranchConditional' || opName === 'spv.BranchConditional') {
             const condition = parser.parseAttribute();
             op.operands.push(condition);
-            parser.expect(',');
-            if (!op.successors) {
-                op.successors = [];
-            }
-            const trueLabel = parser.expect('^');
-            op.successors.push({ label: trueLabel });
-            parser.expect(',');
-            const falseLabel = parser.expect('^');
-            op.successors.push({ label: falseLabel });
+            // Parse optional branch weights [trueWeight, falseWeight]
             if (parser.accept('[')) {
                 const weights = [];
                 while (!parser.match(']')) {
@@ -9962,6 +10053,59 @@ mlir.SPIRVDialect = class extends mlir.Dialect {
                     op.attributes.push({ name: 'branch_weights', value: weights });
                 }
             }
+            parser.expect(',');
+            if (!op.successors) {
+                op.successors = [];
+            }
+            // Parse true branch successor
+            const trueLabel = parser.expect('^');
+            const trueSucc = { label: trueLabel };
+            if (parser.accept('(')) {
+                trueSucc.arguments = [];
+                while (!parser.match(')') && !parser.match(':')) {
+                    if (parser.match('%')) {
+                        trueSucc.arguments.push({ value: parser.expect('%') });
+                        parser.accept(',');
+                    } else {
+                        break;
+                    }
+                }
+                if (parser.accept(':')) {
+                    let idx = 0;
+                    while (!parser.match(')') && idx < trueSucc.arguments.length) {
+                        trueSucc.arguments[idx].type = parser.parseType().toString();
+                        idx++;
+                        parser.accept(',');
+                    }
+                }
+                parser.expect(')');
+            }
+            op.successors.push(trueSucc);
+            parser.expect(',');
+            // Parse false branch successor
+            const falseLabel = parser.expect('^');
+            const falseSucc = { label: falseLabel };
+            if (parser.accept('(')) {
+                falseSucc.arguments = [];
+                while (!parser.match(')') && !parser.match(':')) {
+                    if (parser.match('%')) {
+                        falseSucc.arguments.push({ value: parser.expect('%') });
+                        parser.accept(',');
+                    } else {
+                        break;
+                    }
+                }
+                if (parser.accept(':')) {
+                    let idx = 0;
+                    while (!parser.match(')') && idx < falseSucc.arguments.length) {
+                        falseSucc.arguments[idx].type = parser.parseType().toString();
+                        idx++;
+                        parser.accept(',');
+                    }
+                }
+                parser.expect(')');
+            }
+            op.successors.push(falseSucc);
             return true;
         }
         if (opName === 'spirv.CompositeConstruct' || opName === 'spv.CompositeConstruct') {
@@ -10157,50 +10301,6 @@ mlir.SPIRVDialect = class extends mlir.Dialect {
             }
             return true;
         }
-        if (opName === 'spirv.BranchConditional' || opName === 'spv.BranchConditional') {
-            op.operands = parser.parseArguments();
-
-            // Parse successors
-            if (parser.match('^')) {
-                op.successors = [];
-                while (parser.match('^')) {
-                    const successor = {};
-                    successor.label = parser.expect('^');
-                    // Parse successor arguments with types
-                    // Format: ^label(%val1, %val2, ... : type1, type2, ...)
-                    if (parser.accept('(')) {
-                        successor.arguments = [];
-                        // Parse all values first
-                        while (!parser.match(':') && !parser.match(')')) {
-                            if (parser.match('%')) {
-                                const arg = {};
-                                arg.value = parser.expect('%');
-                                successor.arguments.push(arg);
-                                parser.accept(',');
-                            } else {
-                                break;
-                            }
-                        }
-                        // Parse types if present
-                        if (parser.accept(':')) {
-                            let idx = 0;
-                            while (idx < successor.arguments.length && !parser.match(')')) {
-                                const type = parser.parseType();
-                                successor.arguments[idx].type = type;
-                                idx++;
-                                parser.accept(',');
-                            }
-                        }
-                        parser.accept(')');
-                    }
-                    op.successors.push(successor);
-                    if (!parser.accept(',')) {
-                        break;
-                    }
-                }
-            }
-            return true;
-        }
         // spirv.CompositeInsert with 'into' keyword
         // Format: spirv.CompositeInsert %object, %composite[indices] : object-type into composite-type
         if (opName === 'spirv.CompositeInsert' || opName === 'spv.CompositeInsert') {

+ 2 - 2
source/mlnet.js

@@ -115,10 +115,10 @@ mlnet.Module = class {
 
 mlnet.Argument = class {
 
-    constructor(name, value, type) {
+    constructor(name, value, type = null) {
         this.name = name;
         this.value = value;
-        this.type = type || null;
+        this.type = type;
     }
 };
 

+ 4 - 4
source/mnn.js

@@ -247,19 +247,19 @@ mnn.Node = class {
 
 mnn.Argument = class {
 
-    constructor(name, value, type) {
+    constructor(name, value, type = null) {
         this.name = name;
         this.value = value;
-        this.type = type || null;
+        this.type = type;
     }
 };
 
 mnn.Value = class {
 
-    constructor(name, type, initializer) {
+    constructor(name, type, initializer = null) {
         this.name = name;
         this.type = !type && initializer ? initializer.type : type;
-        this.initializer = initializer || null;
+        this.initializer = initializer;
     }
 };
 

+ 6 - 6
source/mslite.js

@@ -169,19 +169,19 @@ mslite.Node = class {
 
 mslite.Argument = class {
 
-    constructor(name, value, type) {
+    constructor(name, value, type = null) {
         this.name = name;
         this.value = value;
-        this.type = type || null;
+        this.type = type;
     }
 };
 
 mslite.Value = class {
 
-    constructor(name, tensor, initializer) {
+    constructor(name, tensor, initializer = null) {
         this.name = name;
         this.type = initializer ? initializer.type : new mslite.TensorType(tensor.dataType, tensor.dims);
-        this.initializer = initializer || null;
+        this.initializer = initializer;
         if (Array.isArray(tensor.quantParams) && tensor.quantParams.length > 0) {
             this.quantization = {
                 type: 'linear',
@@ -199,10 +199,10 @@ mslite.Value = class {
 
 mslite.Tensor = class {
 
-    constructor(type, data) {
+    constructor(type, data = null) {
         this.type = type;
         this.encoding = type.dataType === 'string' ? '|' : '<';
-        this._data = data || null;
+        this._data = data;
     }
 
     get values() {

+ 5 - 5
source/mxnet.js

@@ -434,23 +434,23 @@ mxnet.Graph = class {
 
 mxnet.Argument = class {
 
-    constructor(name, value, type, visible) {
+    constructor(name, value, type = null, visible = true) {
         this.name = name;
         this.value = value;
-        this.type = type || null;
-        this.visible = visible !== false;
+        this.type = type;
+        this.visible = visible;
     }
 };
 
 mxnet.Value = class {
 
-    constructor(name, type, initializer) {
+    constructor(name, type, initializer = null) {
         if (typeof name !== 'string') {
             throw new mxnet.Error(`Invalid value identifier '${JSON.stringify(name)}'.`);
         }
         this.name = !name && initializer && initializer.name ? initializer.name : name;
         this.type = !type && initializer && initializer.type ? initializer.type : type;
-        this.initializer = initializer || null;
+        this.initializer = initializer;
     }
 };
 

+ 2 - 2
source/ncnn.js

@@ -271,13 +271,13 @@ ncnn.Argument = class {
 
 ncnn.Value = class {
 
-    constructor(name, type, initializer) {
+    constructor(name, type, initializer = null) {
         if (typeof name !== 'string') {
             throw new ncnn.Error(`Invalid value identifier '${JSON.stringify(name)}'.`);
         }
         this.name = name;
         this.type = initializer ? initializer.type : type;
-        this.initializer = initializer || null;
+        this.initializer = initializer;
         this.quantization = initializer ? initializer.quantization : null;
     }
 };

+ 8 - 8
source/nnabla.js

@@ -179,30 +179,30 @@ nnabla.Graph = class {
 
 nnabla.Argument = class {
 
-    constructor(name, value, type, visible) {
+    constructor(name, value, type = null, visible = true) {
         this.name = name;
         this.value = value;
-        this.type = type || null;
-        this.visible = visible !== false;
+        this.type = type;
+        this.visible = visible;
     }
 };
 
 nnabla.Value = class {
 
-    constructor(name, type, initializer) {
+    constructor(name, type, initializer = null) {
         this.name = name;
         this.type = !type && initializer && initializer.type ? initializer.type : type;
-        this.initializer = initializer || null;
+        this.initializer = initializer;
     }
 };
 
 nnabla.Node = class {
 
-    constructor(metadata, func, attributes, inputs, outputs) {
+    constructor(metadata, func, attributes = [], inputs = [], outputs = []) {
         this.name = func.name;
         this.type = metadata.type(func.type) || { name: func.type, type: func.type };
-        this.attributes = attributes || [];
-        this.outputs = outputs || [];
+        this.attributes = attributes;
+        this.outputs = outputs;
         this.chain = [];
         // "nonlinearity" does not match metadata type
         const get_nonlinearity = (name) => {

+ 2 - 2
source/numpy.js

@@ -100,13 +100,13 @@ numpy.Argument = class {
 
 numpy.Value = class {
 
-    constructor(name, initializer) {
+    constructor(name, initializer = null) {
         if (typeof name !== 'string') {
             throw new numpy.Error(`Invalid value identifier '${JSON.stringify(name)}'.`);
         }
         this.name = name;
         this.type = initializer.type;
-        this.initializer = initializer || null;
+        this.initializer = initializer;
     }
 };
 

+ 3 - 3
source/om.js

@@ -258,7 +258,7 @@ om.Node = class {
 
 om.Argument = class {
 
-    constructor(name, value, type) {
+    constructor(name, value, type = null) {
         this.name = name;
         this.value = value;
         this.type = type;
@@ -267,13 +267,13 @@ om.Argument = class {
 
 om.Value = class {
 
-    constructor(name, type, initializer) {
+    constructor(name, type, initializer = null) {
         if (typeof name !== 'string') {
             throw new om.Error(`Invalid value identifier '${JSON.stringify(name)}'.`);
         }
         this.name = name;
         this.type = initializer ? initializer.type : type;
-        this.initializer = initializer || null;
+        this.initializer = initializer;
     }
 };
 

+ 5 - 5
source/onednn.js

@@ -199,22 +199,22 @@ onednn.Node = class {
 
 onednn.Argument = class {
 
-    constructor(name, value, type) {
+    constructor(name, value, type = null) {
         this.name = name;
         this.value = value;
-        this.type = type || null;
+        this.type = type;
     }
 };
 
 onednn.Value = class {
 
-    constructor(name, type, initializer) {
+    constructor(name, type = null, initializer = null) {
         if (typeof name !== 'string') {
             throw new onednn.Error(`Invalid value identifier '${JSON.stringify(name)}'.`);
         }
         this.name = name;
-        this.type = type || null;
-        this.initializer = initializer || null;
+        this.type = type;
+        this.initializer = initializer;
     }
 };
 

+ 15 - 15
source/onnx.js

@@ -251,25 +251,25 @@ onnx.Graph = class {
 
 onnx.Argument = class {
 
-    constructor(name, value, type, description, visible) {
+    constructor(name, value, type = null, description = null, visible = true) {
         this.name = name;
         this.value = value;
-        this.type = type || null;
-        this.description = description || null;
-        this.visible = visible !== false;
+        this.type = type;
+        this.description = description;
+        this.visible = visible;
     }
 };
 
 onnx.Value = class {
 
-    constructor(name, type, initializer, annotation, description) {
+    constructor(name, type = null, initializer = null, annotation = null, description = '') {
         if (typeof name !== 'string') {
             throw new onnx.Error(`Invalid value identifier '${JSON.stringify(name)}'.`);
         }
         this._name = name;
-        this._type = type || null;
-        this._initializer = initializer || null;
-        this._description = description || '';
+        this._type = type;
+        this._initializer = initializer;
+        this._description = description;
         this._quantization = annotation ? { type: 'annotation', value: annotation } : null;
     }
 
@@ -447,8 +447,8 @@ onnx.Group = class {
 
 onnx.Tensor = class {
 
-    constructor(context, tensor, category) {
-        this._category = category || null;
+    constructor(context, tensor, category = null) {
+        this._category = category;
         if (tensor.indices && tensor.values) {
             this._name = tensor.values.name || '';
             this._type = context.createTensorType(tensor.values.data_type, tensor.dims, 'sparse');
@@ -649,11 +649,11 @@ onnx.Tensor = class {
 
 onnx.TensorType = class {
 
-    constructor(dataType, shape, layout, denotation) {
+    constructor(dataType, shape, layout = null, denotation = null) {
         this._dataType = dataType;
         this._shape = shape;
-        this._layout = layout || null;
-        this._denotation = denotation || null;
+        this._layout = layout;
+        this._denotation = denotation;
     }
 
     get dataType() {
@@ -1624,12 +1624,12 @@ onnx.ProtoReader = class {
         return undefined;
     }
 
-    constructor(context, encoding, type, offset) {
+    constructor(context, encoding, type, offset = 0) {
         this.name = 'onnx.proto';
         this.context = context;
         this.encoding = encoding;
         this.type = type;
-        this.offset = offset || 0;
+        this.offset = offset;
         this.locations = new Map();
     }
 

+ 5 - 5
source/openvino.js

@@ -762,23 +762,23 @@ openvino.Node = class {
 
 openvino.Argument = class {
 
-    constructor(name, value, type, visible) {
+    constructor(name, value, type = null, visible = true) {
         this.name = name;
         this.value = value;
-        this.type = type || null;
-        this.visible = visible !== false;
+        this.type = type;
+        this.visible = visible;
     }
 };
 
 openvino.Value = class {
 
-    constructor(name, type, initializer) {
+    constructor(name, type, initializer = null) {
         if (typeof name !== 'string') {
             throw new openvino.Error(`Invalid value identifier '${JSON.stringify(name)}'.`);
         }
         this.name = name;
         this.type = initializer ? initializer.type : type;
-        this.initializer = initializer || null;
+        this.initializer = initializer;
     }
 };
 

+ 4 - 4
source/paddle.js

@@ -433,13 +433,13 @@ paddle.Argument = class {
 
 paddle.Value = class {
 
-    constructor(name, type, initializer) {
+    constructor(name, type, initializer = null) {
         if (typeof name !== 'string') {
             throw new paddle.Error(`Invalid value identifier '${JSON.stringify(name)}'.`);
         }
         this.name = name;
         this.type = !type && initializer ? initializer.type : type;
-        this.initializer = initializer || null;
+        this.initializer = initializer;
     }
 };
 
@@ -586,10 +586,10 @@ paddle.Node = class {
 
 paddle.Tensor = class {
 
-    constructor(type, data, category) {
+    constructor(type, data, category = '') {
         this.type = type;
         this.values = data;
-        this.category = category || '';
+        this.category = category;
     }
 };
 

+ 7 - 7
source/pickle.js

@@ -60,8 +60,8 @@ pickle.Model = class {
 
 pickle.Module = class {
 
-    constructor(type, obj) {
-        this.type = type || '';
+    constructor(type = '', obj = null) {
+        this.type = type;
         this.inputs = [];
         this.outputs = [];
         this.nodes = [];
@@ -168,23 +168,23 @@ pickle.Node = class {
 
 pickle.Argument = class {
 
-    constructor(name, value, type, visible) {
+    constructor(name, value, type = null, visible = true) {
         this.name = name.toString();
         this.value = value;
-        this.type = type || null;
-        this.visible = visible !== false;
+        this.type = type;
+        this.visible = visible;
     }
 };
 
 pickle.Value = class {
 
-    constructor(name, type, initializer) {
+    constructor(name, type, initializer = null) {
         if (typeof name !== 'string') {
             throw new pickle.Error(`Invalid value identifier '${JSON.stringify(name)}'.`);
         }
         this.name = name;
         this.type = initializer && initializer.type ? initializer.type : type || null;
-        this.initializer = initializer || null;
+        this.initializer = initializer;
     }
 };
 

+ 2 - 2
source/protobuf.js

@@ -474,11 +474,11 @@ protobuf.BinaryReader = class {
 
 protobuf.BufferReader = class extends protobuf.BinaryReader {
 
-    constructor(buffer, offset) {
+    constructor(buffer, offset = 0) {
         super();
         this._buffer = buffer;
         this._length = buffer.length;
-        this._position = offset || 0;
+        this._position = offset;
         this._view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
     }
 

+ 9 - 9
source/pytorch.js

@@ -70,11 +70,11 @@ pytorch.Model = class {
 
 pytorch.Graph = class {
 
-    constructor(execution, metadata, type, name, module) {
+    constructor(execution, metadata, type, name = '', module = null) {
         this.nodes = [];
         this.inputs = [];
         this.outputs = [];
-        this.name = name || '';
+        this.name = name;
         this.type = type;
         const values = new Map();
         values.map = (name, type, tensor) => {
@@ -321,24 +321,24 @@ pytorch.Graph = class {
 
 pytorch.Argument = class {
 
-    constructor(name, value, type, visible) {
+    constructor(name, value, type = null, visible = true) {
         this.name = name;
         this.value = value;
-        this.type = type || null;
-        this.visible = visible !== false;
+        this.type = type;
+        this.visible = visible;
     }
 };
 
 pytorch.Value = class Value {
 
-    constructor(name, type, quantization, initializer) {
+    constructor(name, type, quantization, initializer = null) {
         if (typeof name !== 'string') {
             throw new pytorch.Error(`Invalid value identifier '${JSON.stringify(name)}'.`);
         }
         this.name = name;
         this.type = initializer && initializer.type ? initializer.type : type || null;
         this.quantization = quantization;
-        this.initializer = initializer || null;
+        this.initializer = initializer;
     }
 };
 
@@ -982,8 +982,8 @@ pytorch.TensorType = class {
 
 pytorch.TensorShape = class {
 
-    constructor(dimensions) {
-        this.dimensions = dimensions || [];
+    constructor(dimensions = []) {
+        this.dimensions = dimensions;
     }
 
     toString() {

+ 2 - 2
source/qnn.js

@@ -144,11 +144,11 @@ qnn.Graph = class {
 
 qnn.Argument = class {
 
-    constructor(name, value, type, visible) {
+    constructor(name, value, type = null, visible = true) {
         this.name = name;
         this.value = value;
         this.type = type;
-        this.visible = visible !== false;
+        this.visible = visible;
     }
 };
 

+ 3 - 3
source/rknn.js

@@ -222,13 +222,13 @@ rknn.Argument = class {
 
 rknn.Value = class {
 
-    constructor(name, type, initializer) {
+    constructor(name, type = null, initializer = null) {
         if (typeof name !== 'string') {
             throw new rknn.Error(`Invalid value identifier '${JSON.stringify(name)}'.`);
         }
         this.name = name;
-        this.type = type || null;
-        this.initializer = initializer || null;
+        this.type = type;
+        this.initializer = initializer;
     }
 };
 

+ 6 - 6
source/sklearn.js

@@ -100,8 +100,8 @@ sklearn.Model = class {
 
 sklearn.Module = class {
 
-    constructor(metadata, name, obj) {
-        this.name = name || '';
+    constructor(metadata, name = '', obj = null) {
+        this.name = name;
         this.nodes = [];
         this.inputs = [];
         this.outputs = [];
@@ -112,23 +112,23 @@ sklearn.Module = class {
 
 sklearn.Argument = class {
 
-    constructor(name, value, type, visible) {
+    constructor(name, value, type = null, visible = true) {
         this.name = name;
         this.value = value;
         this.type = type;
-        this.visible = visible !== false;
+        this.visible = visible;
     }
 };
 
 sklearn.Value = class {
 
-    constructor(name, type, initializer) {
+    constructor(name, type, initializer = null) {
         if (typeof name !== 'string') {
             throw new sklearn.Error(`Invalid value identifier '${JSON.stringify(name)}'.`);
         }
         this.name = name;
         this.type = initializer ? initializer.type : type;
-        this.initializer = initializer || null;
+        this.initializer = initializer;
     }
 };
 

+ 3 - 3
source/tengine.js

@@ -61,11 +61,11 @@ tengine.Graph = class {
 
 tengine.Argument = class {
 
-    constructor(name, value, type, visible) {
+    constructor(name, value, type = null, visible = true) {
         this.name = name;
         this.value = value;
-        this.type = type || null;
-        this.visible = visible !== false;
+        this.type = type;
+        this.visible = visible;
     }
 };
 

+ 10 - 10
source/text.js

@@ -91,7 +91,7 @@ text.Decoder.String = class {
 text.Decoder.Utf8 = class {
 
     constructor(buffer, position, fatal) {
-        this.position = position || 0;
+        this.position = position;
         this.buffer = buffer;
         this.fatal = fatal;
     }
@@ -156,7 +156,7 @@ text.Decoder.Utf8 = class {
 text.Decoder.Latin1 = class {
 
     constructor(buffer, position) {
-        this.position = position || 0;
+        this.position = position;
         this.buffer = buffer;
     }
 
@@ -176,9 +176,9 @@ text.Decoder.Latin1 = class {
 
 text.Decoder.Utf16LE = class {
 
-    constructor(buffer, position) {
+    constructor(buffer, position = 0) {
         this.buffer = buffer;
-        this.position = position || 0;
+        this.position = position;
         this.length = buffer.length;
     }
 
@@ -208,9 +208,9 @@ text.Decoder.Utf16LE = class {
 
 text.Decoder.Utf16BE = class {
 
-    constructor(buffer, position) {
+    constructor(buffer, position = 0) {
         this.buffer = buffer;
-        this.position = position || 0;
+        this.position = position;
         this.length = buffer.length;
     }
 
@@ -240,9 +240,9 @@ text.Decoder.Utf16BE = class {
 
 text.Decoder.Utf32LE = class {
 
-    constructor(buffer, position) {
+    constructor(buffer, position = 0) {
         this.buffer = buffer;
-        this.position = position || 0;
+        this.position = position;
         this.length = buffer.length;
     }
 
@@ -269,9 +269,9 @@ text.Decoder.Utf32LE = class {
 
 text.Decoder.Utf32BE = class {
 
-    constructor(buffer, position) {
+    constructor(buffer, position = 0) {
         this.buffer = buffer;
-        this.position = position || 0;
+        this.position = position;
         this.length = buffer.length;
     }
 

+ 7 - 7
source/tf.js

@@ -834,23 +834,23 @@ tf.Signature = class {
 
 tf.Argument = class {
 
-    constructor(name, value, type, visible) {
+    constructor(name, value, type = null, visible = true) {
         this.name = name;
         this.value = value;
-        this.type = type || null;
-        this.visible = visible !== false;
+        this.type = type;
+        this.visible = visible;
     }
 };
 
 tf.Value = class {
 
-    constructor(name, type, initializer) {
+    constructor(name, type, initializer = null) {
         if (typeof name !== 'string') {
             throw new tf.Error(`Invalid value identifier '${JSON.stringify(name)}'.`);
         }
         this.name = name;
         this.type = !type && initializer ? initializer.type : type;
-        this.initializer = initializer || null;
+        this.initializer = initializer;
     }
 };
 
@@ -1110,9 +1110,9 @@ tf.Node = class {
 
 tf.Tensor = class {
 
-    constructor(tensor, name, category) {
+    constructor(tensor, name, category = null) {
         this.name = name;
-        this.category = category || null;
+        this.category = category;
         if (tensor) {
             this.type = new tf.TensorType(tensor.dtype, tensor.tensor_shape || tensor.tensorShape);
             this._tensor = tensor;

+ 3 - 3
source/tflite.js

@@ -403,11 +403,11 @@ tflite.Node = class {
 
 tflite.Argument = class {
 
-    constructor(name, value, type, visible) {
+    constructor(name, value, type = null, visible = true) {
         this.name = name;
         this.value = value;
-        this.type = type || null;
-        this.visible = visible !== false;
+        this.type = type;
+        this.visible = visible;
     }
 };
 

+ 4 - 4
source/tnn.js

@@ -109,23 +109,23 @@ tnn.Graph = class {
 
 tnn.Argument = class {
 
-    constructor(name, value, type, visible) {
+    constructor(name, value, type = null, visible = true) {
         this.name = name;
         this.value = value;
         this.type = type;
-        this.visible = visible !== false;
+        this.visible = visible;
     }
 };
 
 tnn.Value = class {
 
-    constructor(name, type, initializer) {
+    constructor(name, type, initializer = null) {
         if (typeof name !== 'string') {
             throw new tnn.Error(`Invalid value identifier '${JSON.stringify(name)}'.`);
         }
         this.name = name;
         this.type = initializer ? initializer.type : type;
-        this.initializer = initializer || null;
+        this.initializer = initializer;
     }
 };
 

+ 3 - 3
source/torch.js

@@ -70,11 +70,11 @@ torch.Graph = class {
 
 torch.Argument = class {
 
-    constructor(name, value, type, visible) {
+    constructor(name, value, type = null, visible = true) {
         this.name = name;
         this.value = value;
-        this.type = type || null;
-        this.visible = visible !== false;
+        this.type = type;
+        this.visible = visible;
     }
 };
 

+ 2 - 2
source/transformers.js

@@ -172,10 +172,10 @@ transformers.Object = class {
 
 transformers.Argument = class {
 
-    constructor(name, value, type) {
+    constructor(name, value, type = null) {
         this.name = name;
         this.value = value;
-        this.type = type || null;
+        this.type = type;
     }
 };
 

+ 5 - 5
source/tvm.js

@@ -187,23 +187,23 @@ tvm.Graph = class {
 
 tvm.Argument = class {
 
-    constructor(name, value, type, visible) {
+    constructor(name, value, type = null, visible = true) {
         this.name = name;
         this.value = value;
-        this.type = type || null;
-        this.visible = visible !== false;
+        this.type = type;
+        this.visible = visible;
     }
 };
 
 tvm.Value = class {
 
-    constructor(name, type, initializer) {
+    constructor(name, type, initializer = null) {
         if (typeof name !== 'string') {
             throw new tvm.Error(`Invalid value identifier '${JSON.stringify(name)}'.`);
         }
         this.name = !name && initializer && initializer.name ? initializer.name : name;
         this.type = !type && initializer && initializer.type ? initializer.type : type;
-        this.initializer = initializer || null;
+        this.initializer = initializer;
     }
 };
 

+ 5 - 7
source/uff.js

@@ -137,24 +137,22 @@ uff.Graph = class {
 
 uff.Argument = class {
 
-    constructor(name, value, type) {
+    constructor(name, value, type = null) {
         this.name = name;
         this.value = value;
-        if (type) {
-            this.type = type;
-        }
+        this.type = type;
     }
 };
 
 uff.Value = class {
 
-    constructor(name, type, initializer) {
+    constructor(name, type = null, initializer = null) {
         if (typeof name !== 'string') {
             throw new uff.Error(`Invalid value identifier '${JSON.stringify(name)}'.`);
         }
         this.name = name;
-        this.type = type || null;
-        this.initializer = initializer || null;
+        this.type = type;
+        this.initializer = initializer;
     }
 };
 

+ 1 - 1
source/view.js

@@ -5578,7 +5578,7 @@ metadata.Attachment.Container = class {
 
 metadata.Argument = class {
 
-    constructor(name, value, type) {
+    constructor(name, value, type = null) {
         this.name = name;
         this.value = value;
         this.type = type;

+ 3 - 3
source/xmodel.js

@@ -81,11 +81,11 @@ xmodel.Graph = class {
 
 xmodel.Argument = class {
 
-    constructor(name, value, type, visible) {
+    constructor(name, value, type = null, visible = true) {
         this.name = name;
         this.value = value;
-        this.type = type || null;
-        this.visible = visible !== false;
+        this.type = type;
+        this.visible = visible;
     }
 };