circuitscript 0.0.38 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/BaseVisitor.js +69 -46
- package/dist/cjs/SymbolValidatorVisitor.js +1 -1
- package/dist/cjs/antlr/CircuitScriptLexer.js +80 -80
- package/dist/cjs/antlr/CircuitScriptParser.js +580 -613
- package/dist/cjs/builtinMethods.js +32 -10
- package/dist/cjs/draw_symbols.js +375 -233
- package/dist/cjs/execute.js +142 -131
- package/dist/cjs/export.js +2 -4
- package/dist/cjs/geometry.js +52 -19
- package/dist/cjs/globals.js +14 -9
- package/dist/cjs/helpers.js +16 -3
- package/dist/cjs/layout.js +143 -151
- package/dist/cjs/logger.js +8 -1
- package/dist/cjs/objects/ClassComponent.js +22 -22
- package/dist/cjs/objects/ExecutionScope.js +10 -4
- package/dist/cjs/objects/Frame.js +4 -1
- package/dist/cjs/objects/ParamDefinition.js +120 -4
- package/dist/cjs/objects/PinDefinition.js +1 -4
- package/dist/cjs/objects/types.js +41 -0
- package/dist/cjs/render.js +41 -110
- package/dist/cjs/sizing.js +33 -7
- package/dist/cjs/utils.js +92 -2
- package/dist/cjs/visitor.js +279 -284
- package/dist/esm/BaseVisitor.mjs +70 -47
- package/dist/esm/SymbolValidatorVisitor.mjs +1 -1
- package/dist/esm/antlr/CircuitScriptLexer.mjs +80 -80
- package/dist/esm/antlr/CircuitScriptParser.mjs +580 -613
- package/dist/esm/builtinMethods.mjs +29 -10
- package/dist/esm/draw_symbols.mjs +381 -238
- package/dist/esm/execute.mjs +144 -133
- package/dist/esm/export.mjs +2 -4
- package/dist/esm/geometry.mjs +52 -19
- package/dist/esm/globals.mjs +13 -8
- package/dist/esm/helpers.mjs +17 -4
- package/dist/esm/layout.mjs +144 -153
- package/dist/esm/logger.mjs +8 -1
- package/dist/esm/objects/ClassComponent.mjs +21 -26
- package/dist/esm/objects/ExecutionScope.mjs +10 -4
- package/dist/esm/objects/Frame.mjs +4 -1
- package/dist/esm/objects/ParamDefinition.mjs +119 -3
- package/dist/esm/objects/PinDefinition.mjs +0 -2
- package/dist/esm/objects/types.mjs +42 -0
- package/dist/esm/render.mjs +44 -113
- package/dist/esm/sizing.mjs +34 -8
- package/dist/esm/utils.mjs +86 -1
- package/dist/esm/visitor.mjs +281 -286
- package/dist/types/BaseVisitor.d.ts +3 -2
- package/dist/types/antlr/CircuitScriptParser.d.ts +5 -3
- package/dist/types/draw_symbols.d.ts +81 -49
- package/dist/types/execute.d.ts +16 -11
- package/dist/types/geometry.d.ts +31 -19
- package/dist/types/globals.d.ts +15 -10
- package/dist/types/helpers.d.ts +2 -1
- package/dist/types/layout.d.ts +22 -21
- package/dist/types/logger.d.ts +1 -1
- package/dist/types/objects/ClassComponent.d.ts +19 -16
- package/dist/types/objects/ExecutionScope.d.ts +2 -1
- package/dist/types/objects/Frame.d.ts +5 -3
- package/dist/types/objects/ParamDefinition.d.ts +31 -2
- package/dist/types/objects/PinDefinition.d.ts +0 -2
- package/dist/types/objects/types.d.ts +7 -2
- package/dist/types/render.d.ts +2 -1
- package/dist/types/utils.d.ts +9 -1
- package/dist/types/visitor.d.ts +5 -5
- package/libs/lib.cst +102 -32
- package/package.json +7 -3
package/dist/cjs/visitor.js
CHANGED
|
@@ -17,9 +17,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
17
17
|
super(...arguments);
|
|
18
18
|
this.visitKeyword_assignment_expr = (ctx) => {
|
|
19
19
|
const id = ctx.ID().getText();
|
|
20
|
-
const
|
|
21
|
-
this.visit(ctxDataExpr);
|
|
22
|
-
const value = this.getResult(ctxDataExpr);
|
|
20
|
+
const value = this.visitResult(ctx.data_expr());
|
|
23
21
|
this.setResult(ctx, [id, value]);
|
|
24
22
|
};
|
|
25
23
|
this.visitPin_select_expr = (ctx) => {
|
|
@@ -35,56 +33,48 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
35
33
|
this.setResult(ctx, value);
|
|
36
34
|
};
|
|
37
35
|
this.visitAdd_component_expr = (ctx) => {
|
|
38
|
-
const
|
|
39
|
-
this.visit(ctxDataWithAssignmentExpr);
|
|
40
|
-
const [component, pinValue] = this.getResult(ctxDataWithAssignmentExpr);
|
|
36
|
+
const [component, pinValue] = this.visitResult(ctx.data_expr_with_assignment());
|
|
41
37
|
this.getExecutor().addComponentExisting(component, pinValue);
|
|
42
38
|
};
|
|
43
39
|
this.visitAt_component_expr = (ctx) => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const ctxComponentSelectExpr = ctx.component_select_expr();
|
|
49
|
-
this.visit(ctxComponentSelectExpr);
|
|
50
|
-
const [component, pin] = this.getResult(ctxComponentSelectExpr);
|
|
51
|
-
this.getExecutor().atComponent(component, pin, {
|
|
52
|
-
addSequence: true
|
|
53
|
-
});
|
|
54
|
-
}
|
|
40
|
+
const [component, pin] = this.visitResult(ctx.component_select_expr());
|
|
41
|
+
this.getExecutor().atComponent(component, pin, {
|
|
42
|
+
addSequence: true
|
|
43
|
+
});
|
|
55
44
|
return this.getExecutor().getCurrentPoint();
|
|
56
45
|
};
|
|
57
46
|
this.visitTo_component_expr = (ctx) => {
|
|
58
|
-
|
|
59
|
-
this.
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
ctx.component_select_expr().forEach(item => {
|
|
63
|
-
this.visit(item);
|
|
64
|
-
const [component, pin] = this.getResult(item);
|
|
65
|
-
this.getExecutor().toComponent(component, pin, {
|
|
66
|
-
addSequence: true
|
|
67
|
-
});
|
|
47
|
+
ctx.component_select_expr().forEach(item => {
|
|
48
|
+
const [component, pin] = this.visitResult(item);
|
|
49
|
+
this.getExecutor().toComponent(component, pin, {
|
|
50
|
+
addSequence: true
|
|
68
51
|
});
|
|
69
|
-
}
|
|
52
|
+
});
|
|
70
53
|
return this.getExecutor().getCurrentPoint();
|
|
71
54
|
};
|
|
72
55
|
this.visitComponent_select_expr = (ctx) => {
|
|
73
56
|
const ctxDataExprWithAssigment = ctx.data_expr_with_assignment();
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
57
|
+
let componentPin = null;
|
|
58
|
+
if (ctx.Point()) {
|
|
59
|
+
const [component, pin,] = this.getExecutor().getPointBlockLocation();
|
|
60
|
+
componentPin = [component, pin];
|
|
61
|
+
}
|
|
62
|
+
else if (ctxDataExprWithAssigment) {
|
|
63
|
+
componentPin = this.visitResult(ctxDataExprWithAssigment);
|
|
77
64
|
}
|
|
78
65
|
else {
|
|
79
66
|
const component = this.getExecutor().scope.currentComponent;
|
|
80
67
|
let pinId = null;
|
|
81
68
|
const ctxPinSelectExpr = ctx.pin_select_expr();
|
|
82
69
|
if (ctxPinSelectExpr) {
|
|
83
|
-
this.
|
|
84
|
-
pinId = this.getResult(ctxPinSelectExpr);
|
|
70
|
+
pinId = this.visitResult(ctxPinSelectExpr);
|
|
85
71
|
}
|
|
86
|
-
|
|
72
|
+
if (pinId === null) {
|
|
73
|
+
this.throwWithContext(ctx, "Could not resolve pin");
|
|
74
|
+
}
|
|
75
|
+
componentPin = [component, pinId];
|
|
87
76
|
}
|
|
77
|
+
this.setResult(ctx, componentPin);
|
|
88
78
|
};
|
|
89
79
|
this.visitPath_blocks = (ctx) => {
|
|
90
80
|
const blocks = ctx.path_block_inner();
|
|
@@ -123,7 +113,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
123
113
|
this.visitCreate_component_expr = (ctx) => {
|
|
124
114
|
const properties = this.getPropertyExprList(ctx.property_expr());
|
|
125
115
|
const pins = this.parseCreateComponentPins(properties.get('pins'));
|
|
126
|
-
let instanceName = this.getExecutor().getUniqueInstanceName(
|
|
116
|
+
let instanceName = this.getExecutor().getUniqueInstanceName();
|
|
127
117
|
const propParams = properties.get('params');
|
|
128
118
|
const params = this.parseCreateComponentParams(propParams);
|
|
129
119
|
if (params.length > 0) {
|
|
@@ -145,29 +135,51 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
145
135
|
properties.get('copy') : false;
|
|
146
136
|
const width = properties.has('width') ?
|
|
147
137
|
properties.get('width') : null;
|
|
148
|
-
const
|
|
149
|
-
properties.get('
|
|
138
|
+
const height = properties.has('height') ?
|
|
139
|
+
properties.get('height') : null;
|
|
140
|
+
const angle = properties.has(globals_js_1.ParamKeys.angle) ?
|
|
141
|
+
properties.get(globals_js_1.ParamKeys.angle) : null;
|
|
150
142
|
const followWireOrientation = properties.has('followWireOrientation') ?
|
|
151
143
|
properties.get('followWireOrientation') : true;
|
|
152
144
|
const props = {
|
|
153
|
-
arrange, display, type, width, copy,
|
|
145
|
+
arrange, display, type, width, height, copy,
|
|
154
146
|
angle, followWireOrientation
|
|
155
147
|
};
|
|
156
148
|
const createdComponent = this.getExecutor().createComponent(instanceName, pins, params, props);
|
|
157
149
|
this.setResult(ctx, createdComponent);
|
|
158
150
|
};
|
|
159
151
|
this.visitCreate_graphic_expr = (ctx) => {
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
152
|
+
const ctxId = ctx.ID();
|
|
153
|
+
const paramIds = [];
|
|
154
|
+
if (ctxId !== null) {
|
|
155
|
+
const varName = ctxId.getText();
|
|
156
|
+
paramIds.push(varName);
|
|
157
|
+
this.getExecutor().scope.variables.set(varName, {});
|
|
158
|
+
}
|
|
159
|
+
const executor = this.getExecutor();
|
|
160
|
+
const stack = [...this.executionStack];
|
|
161
|
+
const drawing = new draw_symbols_js_1.SymbolDrawingCommands(variables => {
|
|
162
|
+
if (variables && paramIds.length > 0) {
|
|
163
|
+
const obj = {};
|
|
164
|
+
variables.forEach((value, key) => {
|
|
165
|
+
obj[key] = value;
|
|
166
|
+
});
|
|
167
|
+
executor.scope.variables.set(paramIds[0], obj);
|
|
168
|
+
}
|
|
169
|
+
const currentStack = this.executionStack.splice(0);
|
|
170
|
+
this.executionStack.push(...stack);
|
|
171
|
+
const graphicsExpressionsCtx = ctx.graphic_expressions_block();
|
|
172
|
+
const commands = this.visitResult(graphicsExpressionsCtx);
|
|
173
|
+
this.executionStack.splice(0);
|
|
174
|
+
this.executionStack.push(...currentStack);
|
|
175
|
+
return commands;
|
|
176
|
+
});
|
|
164
177
|
drawing.source = ctx.getText();
|
|
165
178
|
this.setResult(ctx, drawing);
|
|
166
179
|
};
|
|
167
180
|
this.visitGraphic_expressions_block = (ctx) => {
|
|
168
181
|
const commands = ctx.graphic_expr().reduce((accum, item) => {
|
|
169
|
-
this.
|
|
170
|
-
const [commandName, parameters] = this.getResult(item);
|
|
182
|
+
const [commandName, parameters] = this.visitResult(item);
|
|
171
183
|
if (commandName === draw_symbols_js_1.PlaceHolderCommands.for) {
|
|
172
184
|
accum = accum.concat(parameters);
|
|
173
185
|
}
|
|
@@ -182,7 +194,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
182
194
|
}
|
|
183
195
|
return accum;
|
|
184
196
|
}, []);
|
|
185
|
-
accum.push([commandName, positionParams, keywordParams]);
|
|
197
|
+
accum.push([commandName, positionParams, keywordParams, item]);
|
|
186
198
|
}
|
|
187
199
|
return accum;
|
|
188
200
|
}, []);
|
|
@@ -200,18 +212,15 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
200
212
|
let parameters = [];
|
|
201
213
|
const ctxNestedProperties = ctx.nested_properties_inner();
|
|
202
214
|
if (ctxNestedProperties) {
|
|
203
|
-
this.
|
|
204
|
-
const nestedKeyValues = this.getResult(ctxNestedProperties);
|
|
215
|
+
const nestedKeyValues = this.visitResult(ctxNestedProperties);
|
|
205
216
|
nestedKeyValues.forEach((value, key) => {
|
|
206
217
|
parameters.push(['keyword', key, value]);
|
|
207
218
|
});
|
|
208
219
|
}
|
|
209
220
|
else {
|
|
210
|
-
|
|
211
|
-
this.visit(ctxParameters);
|
|
212
|
-
parameters = this.getResult(ctxParameters);
|
|
221
|
+
parameters = this.visitResult(ctx.parameters());
|
|
213
222
|
}
|
|
214
|
-
if (commandName ===
|
|
223
|
+
if (commandName === draw_symbols_js_1.PlaceHolderCommands.label) {
|
|
215
224
|
parameters.forEach(item => {
|
|
216
225
|
if (item[0] == 'keyword' && item[1] === 'portType') {
|
|
217
226
|
if (item[2] === 'in') {
|
|
@@ -227,9 +236,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
227
236
|
};
|
|
228
237
|
this.visitGraphicForExpr = (ctx) => {
|
|
229
238
|
const forVariableNames = ctx.ID().map(item => item.getText());
|
|
230
|
-
const
|
|
231
|
-
this.visit(ctxDataExpr);
|
|
232
|
-
const listItems = this.getResult(ctxDataExpr);
|
|
239
|
+
const listItems = this.visitResult(ctx.data_expr());
|
|
233
240
|
let keepLooping = true;
|
|
234
241
|
let counter = 0;
|
|
235
242
|
let allCommands = [];
|
|
@@ -242,9 +249,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
242
249
|
useValueArray.forEach((value, index) => {
|
|
243
250
|
this.getExecutor().scope.variables.set(forVariableNames[index], value);
|
|
244
251
|
});
|
|
245
|
-
const
|
|
246
|
-
this.visit(graphicsExpressionsCtx);
|
|
247
|
-
const commands = this.getResult(graphicsExpressionsCtx);
|
|
252
|
+
const commands = this.visitResult(ctx.graphic_expressions_block());
|
|
248
253
|
allCommands = allCommands.concat(commands);
|
|
249
254
|
counter += 1;
|
|
250
255
|
}
|
|
@@ -256,8 +261,10 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
256
261
|
};
|
|
257
262
|
this.visitCreate_module_expr = (ctx) => {
|
|
258
263
|
const properties = this.getPropertyExprList(ctx.property_expr());
|
|
259
|
-
const
|
|
260
|
-
const
|
|
264
|
+
const modulePorts = this.parseCreateModulePorts(properties.get('ports'));
|
|
265
|
+
const { [globals_js_1.SymbolPinSide.Left]: leftPorts, [globals_js_1.SymbolPinSide.Right]: rightPorts, [globals_js_1.SymbolPinSide.Top]: topPorts, [globals_js_1.SymbolPinSide.Bottom]: bottomPorts } = modulePorts;
|
|
266
|
+
const allPorts = [...leftPorts, ...rightPorts,
|
|
267
|
+
...topPorts, ...bottomPorts].filter(item => {
|
|
261
268
|
return !(Array.isArray(item));
|
|
262
269
|
});
|
|
263
270
|
const nameToPinId = new Map();
|
|
@@ -265,65 +272,44 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
265
272
|
nameToPinId.set(portName, index + 1);
|
|
266
273
|
return new PinDefinition_js_1.PinDefinition(index + 1, PinDefinition_js_1.PinIdType.Int, portName, PinTypes_js_1.PinTypes.Any);
|
|
267
274
|
});
|
|
268
|
-
const
|
|
269
|
-
if (Array.isArray(item)) {
|
|
270
|
-
return item;
|
|
271
|
-
}
|
|
272
|
-
else {
|
|
273
|
-
return nameToPinId.get(item);
|
|
274
|
-
}
|
|
275
|
-
});
|
|
276
|
-
const arrangeRightItems = rightPorts.map(item => {
|
|
277
|
-
if (Array.isArray(item)) {
|
|
278
|
-
return item;
|
|
279
|
-
}
|
|
280
|
-
else {
|
|
281
|
-
return nameToPinId.get(item);
|
|
282
|
-
}
|
|
283
|
-
});
|
|
284
|
-
const arrange = new Map();
|
|
285
|
-
if (arrangeLeftItems.length > 0) {
|
|
286
|
-
arrange.set('left', arrangeLeftItems);
|
|
287
|
-
}
|
|
288
|
-
if (arrangeRightItems.length > 0) {
|
|
289
|
-
arrange.set('right', arrangeRightItems);
|
|
290
|
-
}
|
|
275
|
+
const arrange = this.getArrangePropFromModulePorts(modulePorts, nameToPinId);
|
|
291
276
|
const width = properties.has('width') ?
|
|
292
277
|
properties.get('width') : null;
|
|
278
|
+
const height = properties.has('height') ?
|
|
279
|
+
properties.get('height') : null;
|
|
293
280
|
const blankParams = [];
|
|
294
281
|
const props = {
|
|
295
|
-
arrange, width
|
|
282
|
+
arrange, width, height,
|
|
283
|
+
copy: false,
|
|
284
|
+
followWireOrientation: true,
|
|
296
285
|
};
|
|
297
|
-
const moduleInstanceName = this.getExecutor().getUniqueInstanceName(
|
|
298
|
-
const
|
|
299
|
-
|
|
286
|
+
const moduleInstanceName = this.getExecutor().getUniqueInstanceName();
|
|
287
|
+
const moduleComponent = this.getExecutor().createComponent(moduleInstanceName, tmpPorts, blankParams, props, true);
|
|
288
|
+
moduleComponent.typeProp = globals_js_1.ComponentTypes.module;
|
|
300
289
|
const ctxPropertyBlock = ctx.property_block_expr();
|
|
301
290
|
if (ctxPropertyBlock) {
|
|
302
291
|
const [firstBlock] = ctxPropertyBlock;
|
|
303
|
-
this.
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
this.expandModuleContains(createdComponent, this.getExecutor().netNamespace);
|
|
292
|
+
const [keyName, expressionsBlock] = this.visitResult(firstBlock);
|
|
293
|
+
if (keyName === globals_js_1.ModuleContainsKeyword) {
|
|
294
|
+
moduleComponent.moduleContainsExpressions = expressionsBlock;
|
|
295
|
+
this.expandModuleContains(moduleComponent, this.getExecutor().netNamespace);
|
|
308
296
|
}
|
|
309
297
|
}
|
|
310
|
-
|
|
298
|
+
if (moduleComponent.moduleContainsExpressions === undefined) {
|
|
299
|
+
throw 'Module has no `contains` block defined!';
|
|
300
|
+
}
|
|
301
|
+
this.setResult(ctx, moduleComponent);
|
|
311
302
|
};
|
|
312
303
|
this.visitProperty_block_expr = (ctx) => {
|
|
313
|
-
const
|
|
314
|
-
this.visit(tmpCtx);
|
|
315
|
-
const keyName = this.getResult(tmpCtx);
|
|
304
|
+
const keyName = this.visitResult(ctx.property_key_expr());
|
|
316
305
|
const expressionsBlock = ctx.expressions_block();
|
|
317
306
|
this.setResult(ctx, [keyName, expressionsBlock]);
|
|
318
307
|
};
|
|
319
308
|
this.visitProperty_expr = (ctx) => {
|
|
320
|
-
const
|
|
321
|
-
const
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
const keyName = this.getResult(ctxPropertyKeyExpr);
|
|
325
|
-
const value = this.getResult(ctxPropertyValueExpr);
|
|
326
|
-
if (value instanceof types_js_1.UndeclaredReference) {
|
|
309
|
+
const keyName = this.visitResult(ctx.property_key_expr());
|
|
310
|
+
const value = this.visitResult(ctx.property_value_expr());
|
|
311
|
+
if (value instanceof types_js_1.UndeclaredReference && (value.reference.parentValue === undefined
|
|
312
|
+
&& value.reference.value === undefined)) {
|
|
327
313
|
throw value.throwMessage();
|
|
328
314
|
}
|
|
329
315
|
const map = new Map();
|
|
@@ -333,14 +319,11 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
333
319
|
this.visitSingle_line_property = (ctx) => {
|
|
334
320
|
let value;
|
|
335
321
|
if (ctx.data_expr().length === 1) {
|
|
336
|
-
|
|
337
|
-
this.visit(ctxFirst);
|
|
338
|
-
value = this.getResult(ctxFirst);
|
|
322
|
+
value = this.visitResult(ctx.data_expr(0));
|
|
339
323
|
}
|
|
340
324
|
else {
|
|
341
325
|
value = ctx.data_expr().map(item => {
|
|
342
|
-
this.
|
|
343
|
-
return this.getResult(item);
|
|
326
|
+
return this.visitResult(item);
|
|
344
327
|
});
|
|
345
328
|
}
|
|
346
329
|
this.setResult(ctx, value);
|
|
@@ -348,8 +331,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
348
331
|
this.visitNested_properties_inner = (ctx) => {
|
|
349
332
|
const result = new Map();
|
|
350
333
|
ctx.property_expr().forEach((item) => {
|
|
351
|
-
this.
|
|
352
|
-
const property = this.getResult(item);
|
|
334
|
+
const property = this.visitResult(item);
|
|
353
335
|
for (const [key, value] of property) {
|
|
354
336
|
result.set(key, value);
|
|
355
337
|
}
|
|
@@ -357,9 +339,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
357
339
|
this.setResult(ctx, result);
|
|
358
340
|
};
|
|
359
341
|
this.visitNested_properties = (ctx) => {
|
|
360
|
-
|
|
361
|
-
this.visit(ctxNested);
|
|
362
|
-
this.setResult(ctx, this.getResult(ctxNested));
|
|
342
|
+
this.setResult(ctx, this.visitResult(ctx.nested_properties_inner()));
|
|
363
343
|
};
|
|
364
344
|
this.visitProperty_key_expr = (ctx) => {
|
|
365
345
|
const ctxID = ctx.ID();
|
|
@@ -379,30 +359,32 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
379
359
|
};
|
|
380
360
|
this.visitData_expr_with_assignment = (ctx) => {
|
|
381
361
|
let component = null;
|
|
362
|
+
let componentCtx = null;
|
|
382
363
|
const ctxDataExpr = ctx.data_expr();
|
|
383
364
|
const ctxAssignmentExpr = ctx.assignment_expr();
|
|
384
365
|
if (ctxDataExpr) {
|
|
385
|
-
this.
|
|
386
|
-
|
|
366
|
+
component = this.visitResult(ctxDataExpr);
|
|
367
|
+
componentCtx = ctxDataExpr;
|
|
387
368
|
if (component === null || component === undefined) {
|
|
388
|
-
|
|
369
|
+
this.throwWithContext(ctxDataExpr, "Could not find component: " + ctxDataExpr.getText());
|
|
389
370
|
}
|
|
390
371
|
}
|
|
391
372
|
else if (ctxAssignmentExpr) {
|
|
392
|
-
this.
|
|
393
|
-
|
|
373
|
+
component = this.visitResult(ctxAssignmentExpr);
|
|
374
|
+
componentCtx = ctxAssignmentExpr;
|
|
394
375
|
}
|
|
395
376
|
if (component instanceof ClassComponent_js_1.ClassComponent
|
|
396
377
|
&& component.copyProp) {
|
|
397
378
|
component = this.getExecutor().copyComponent(component);
|
|
398
379
|
}
|
|
399
|
-
if (component instanceof types_js_1.
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
380
|
+
if (component instanceof types_js_1.UndeclaredReference) {
|
|
381
|
+
const { reference: { trailers = [], parentValue = null } } = component;
|
|
382
|
+
if (parentValue instanceof ClassComponent_js_1.ClassComponent
|
|
383
|
+
&& trailers.length > 0
|
|
384
|
+
&& trailers[0] === globals_js_1.ModuleContainsKeyword) {
|
|
385
|
+
component = parentValue;
|
|
386
|
+
this.placeModuleContains(component);
|
|
387
|
+
}
|
|
406
388
|
}
|
|
407
389
|
if (component && component instanceof ClassComponent_js_1.ClassComponent) {
|
|
408
390
|
const modifiers = ctx.component_modifier_expr();
|
|
@@ -412,43 +394,29 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
412
394
|
const ctxID2 = modifier.ID(1);
|
|
413
395
|
let result = null;
|
|
414
396
|
if (ctxValueExpr) {
|
|
415
|
-
this.
|
|
416
|
-
result = this.getResult(ctxValueExpr);
|
|
397
|
+
result = this.visitResult(ctxValueExpr);
|
|
417
398
|
}
|
|
418
399
|
else if (ctxID2) {
|
|
419
400
|
result = ctxID2.getText();
|
|
420
401
|
}
|
|
421
402
|
let shouldIgnoreWireOrientation = false;
|
|
422
|
-
if (modifierText ===
|
|
403
|
+
if (modifierText === globals_js_1.ParamKeys.flip) {
|
|
423
404
|
const flipValue = result;
|
|
424
405
|
if (flipValue.indexOf('x') !== -1) {
|
|
425
|
-
component.setParam(
|
|
406
|
+
component.setParam(globals_js_1.ParamKeys.flipX, 1);
|
|
426
407
|
shouldIgnoreWireOrientation = true;
|
|
427
408
|
}
|
|
428
409
|
if (flipValue.indexOf('y') !== -1) {
|
|
429
|
-
component.setParam(
|
|
410
|
+
component.setParam(globals_js_1.ParamKeys.flipY, 1);
|
|
430
411
|
shouldIgnoreWireOrientation = true;
|
|
431
412
|
}
|
|
432
413
|
}
|
|
433
|
-
else if (modifierText ===
|
|
434
|
-
|
|
435
|
-
component.setParam('angle', angleValue);
|
|
414
|
+
else if (modifierText === globals_js_1.ParamKeys.angle) {
|
|
415
|
+
component.setParam(globals_js_1.ParamKeys.angle, result);
|
|
436
416
|
shouldIgnoreWireOrientation = true;
|
|
437
417
|
}
|
|
438
418
|
else if (modifierText === 'anchor') {
|
|
439
|
-
|
|
440
|
-
&& component.displayProp instanceof draw_symbols_js_1.SymbolDrawingCommands) {
|
|
441
|
-
const commands = (component.displayProp)
|
|
442
|
-
.getCommands();
|
|
443
|
-
commands.forEach(command => {
|
|
444
|
-
const positionParams = command[1];
|
|
445
|
-
const keywordParams = command[2];
|
|
446
|
-
if (command[0] === draw_symbols_js_1.PlaceHolderCommands.label
|
|
447
|
-
&& positionParams[0] === 'value') {
|
|
448
|
-
keywordParams.set('anchor', result);
|
|
449
|
-
}
|
|
450
|
-
});
|
|
451
|
-
}
|
|
419
|
+
component.setParam('anchor', result);
|
|
452
420
|
}
|
|
453
421
|
if (shouldIgnoreWireOrientation) {
|
|
454
422
|
component.useWireOrientationAngle = false;
|
|
@@ -458,8 +426,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
458
426
|
let pinValue = null;
|
|
459
427
|
const ctxPinSelectExpr = ctx.pin_select_expr();
|
|
460
428
|
if (ctxPinSelectExpr) {
|
|
461
|
-
this.
|
|
462
|
-
pinValue = this.getResult(ctxPinSelectExpr);
|
|
429
|
+
pinValue = this.visitResult(ctxPinSelectExpr);
|
|
463
430
|
}
|
|
464
431
|
else {
|
|
465
432
|
if (component instanceof ClassComponent_js_1.ClassComponent) {
|
|
@@ -467,30 +434,29 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
467
434
|
}
|
|
468
435
|
else {
|
|
469
436
|
const undeclaredRef = component;
|
|
470
|
-
|
|
437
|
+
this.throwWithContext(componentCtx, 'Invalid component: ' + undeclaredRef.reference.name);
|
|
471
438
|
}
|
|
472
439
|
}
|
|
473
440
|
this.setResult(ctx, [component, pinValue]);
|
|
474
441
|
};
|
|
475
442
|
this.visitUnaryOperatorExpr = (ctx) => {
|
|
476
|
-
this.
|
|
477
|
-
let value = this.getResult(ctx.data_expr());
|
|
443
|
+
let value = this.visitResult(ctx.data_expr());
|
|
478
444
|
const unaryOp = ctx.unary_operator();
|
|
479
445
|
if (unaryOp) {
|
|
480
446
|
if (unaryOp.Not()) {
|
|
481
447
|
if (typeof value === "boolean") {
|
|
482
448
|
value = !value;
|
|
483
449
|
}
|
|
484
|
-
else if (
|
|
485
|
-
value = (value === 0) ?
|
|
450
|
+
else if (value instanceof ParamDefinition_js_1.NumericValue) {
|
|
451
|
+
value = (value.toNumber() === 0) ? true : false;
|
|
486
452
|
}
|
|
487
453
|
else {
|
|
488
454
|
throw "Failed to do Not operator";
|
|
489
455
|
}
|
|
490
456
|
}
|
|
491
457
|
else if (unaryOp.Minus()) {
|
|
492
|
-
if (
|
|
493
|
-
value =
|
|
458
|
+
if (value instanceof ParamDefinition_js_1.NumericValue) {
|
|
459
|
+
value = value.neg();
|
|
494
460
|
}
|
|
495
461
|
else {
|
|
496
462
|
throw "Failed to do Negation operator";
|
|
@@ -505,16 +471,13 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
505
471
|
const ctxCreateGraphicExpr = ctx.create_graphic_expr();
|
|
506
472
|
const ctxCreateModuleExpr = ctx.create_module_expr();
|
|
507
473
|
if (ctxCreateComponentExpr) {
|
|
508
|
-
this.
|
|
509
|
-
value = this.getResult(ctxCreateComponentExpr);
|
|
474
|
+
value = this.visitResult(ctxCreateComponentExpr);
|
|
510
475
|
}
|
|
511
476
|
else if (ctxCreateGraphicExpr) {
|
|
512
|
-
this.
|
|
513
|
-
value = this.getResult(ctxCreateGraphicExpr);
|
|
477
|
+
value = this.visitResult(ctxCreateGraphicExpr);
|
|
514
478
|
}
|
|
515
479
|
else if (ctxCreateModuleExpr) {
|
|
516
|
-
this.
|
|
517
|
-
value = this.getResult(ctxCreateModuleExpr);
|
|
480
|
+
value = this.visitResult(ctxCreateModuleExpr);
|
|
518
481
|
}
|
|
519
482
|
else {
|
|
520
483
|
throw "Invalid data expression";
|
|
@@ -524,10 +487,14 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
524
487
|
this.visitBinaryOperatorExpr = (ctx) => {
|
|
525
488
|
const ctx0 = ctx.data_expr(0);
|
|
526
489
|
const ctx1 = ctx.data_expr(1);
|
|
527
|
-
this.
|
|
528
|
-
this.
|
|
529
|
-
|
|
530
|
-
|
|
490
|
+
let value1 = this.visitResult(ctx0);
|
|
491
|
+
let value2 = this.visitResult(ctx1);
|
|
492
|
+
if (value1 instanceof ParamDefinition_js_1.NumericValue) {
|
|
493
|
+
value1 = value1.toNumber();
|
|
494
|
+
}
|
|
495
|
+
if (value2 instanceof ParamDefinition_js_1.NumericValue) {
|
|
496
|
+
value2 = value2.toNumber();
|
|
497
|
+
}
|
|
531
498
|
const binaryOperatorType = ctx.binary_operator();
|
|
532
499
|
let result = null;
|
|
533
500
|
if (binaryOperatorType.Equals()) {
|
|
@@ -553,60 +520,87 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
553
520
|
this.visitLogicalOperatorExpr = (ctx) => {
|
|
554
521
|
const ctx0 = ctx.data_expr(0);
|
|
555
522
|
const ctx1 = ctx.data_expr(1);
|
|
556
|
-
this.
|
|
557
|
-
|
|
523
|
+
let value1 = this.visitResult(ctx0);
|
|
524
|
+
if (value1 instanceof ParamDefinition_js_1.NumericValue) {
|
|
525
|
+
value1 = value1.toNumber();
|
|
526
|
+
}
|
|
558
527
|
let value2 = false;
|
|
559
528
|
let skipNext = false;
|
|
560
|
-
|
|
529
|
+
const isLogicalOr = ctx.LogicalOr();
|
|
530
|
+
if (isLogicalOr && value1) {
|
|
561
531
|
skipNext = true;
|
|
562
532
|
}
|
|
563
533
|
if (!skipNext) {
|
|
564
|
-
this.
|
|
565
|
-
value2
|
|
534
|
+
value2 = this.visitResult(ctx1);
|
|
535
|
+
if (value2 instanceof ParamDefinition_js_1.NumericValue) {
|
|
536
|
+
value2 = value2.toNumber();
|
|
537
|
+
}
|
|
566
538
|
}
|
|
567
539
|
let result = null;
|
|
568
540
|
if (ctx.LogicalAnd()) {
|
|
569
541
|
result = value1 && value2;
|
|
570
542
|
}
|
|
571
|
-
else if (
|
|
543
|
+
else if (isLogicalOr) {
|
|
572
544
|
result = value1 || value2;
|
|
573
545
|
}
|
|
546
|
+
if (typeof result === "number") {
|
|
547
|
+
result = (0, ParamDefinition_js_1.numeric)(result);
|
|
548
|
+
}
|
|
574
549
|
this.setResult(ctx, result);
|
|
575
550
|
};
|
|
576
551
|
this.visitMultiplyExpr = (ctx) => {
|
|
577
552
|
const value1 = this.resolveDataExpr(ctx.data_expr(0));
|
|
578
553
|
const value2 = this.resolveDataExpr(ctx.data_expr(1));
|
|
554
|
+
const operator = new ParamDefinition_js_1.NumberOperator();
|
|
555
|
+
const tmpValue1 = operator.prepare(value1);
|
|
556
|
+
const tmpValue2 = operator.prepare(value2);
|
|
579
557
|
let result = null;
|
|
580
558
|
if (ctx.Multiply()) {
|
|
581
|
-
result =
|
|
559
|
+
result = operator.multiply(tmpValue1, tmpValue2);
|
|
582
560
|
}
|
|
583
561
|
else if (ctx.Divide()) {
|
|
584
|
-
result =
|
|
562
|
+
result = operator.divide(tmpValue1, tmpValue2);
|
|
585
563
|
}
|
|
586
564
|
else if (ctx.Modulus()) {
|
|
587
|
-
result =
|
|
565
|
+
result = operator.modulus(tmpValue1, tmpValue2);
|
|
588
566
|
}
|
|
589
567
|
this.setResult(ctx, result);
|
|
590
568
|
};
|
|
591
569
|
this.visitAdditionExpr = (ctx) => {
|
|
592
570
|
const value1 = this.resolveDataExpr(ctx.data_expr(0));
|
|
593
571
|
const value2 = this.resolveDataExpr(ctx.data_expr(1));
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
572
|
+
if (ctx.Addition() && (typeof value1 === 'string' || typeof value2 === 'string')) {
|
|
573
|
+
let tmpValue1 = value1;
|
|
574
|
+
if (value1 instanceof ParamDefinition_js_1.NumericValue) {
|
|
575
|
+
tmpValue1 = value1.toDisplayString();
|
|
576
|
+
}
|
|
577
|
+
let tmpValue2 = value2;
|
|
578
|
+
if (value2 instanceof ParamDefinition_js_1.NumericValue) {
|
|
579
|
+
tmpValue2 = value2.toDisplayString();
|
|
580
|
+
}
|
|
581
|
+
const result = tmpValue1 + tmpValue2;
|
|
582
|
+
this.setResult(ctx, result);
|
|
597
583
|
}
|
|
598
|
-
else
|
|
599
|
-
|
|
584
|
+
else {
|
|
585
|
+
const operator = new ParamDefinition_js_1.NumberOperator();
|
|
586
|
+
const tmpValue1 = operator.prepare(value1);
|
|
587
|
+
const tmpValue2 = operator.prepare(value2);
|
|
588
|
+
let result = null;
|
|
589
|
+
if (ctx.Addition()) {
|
|
590
|
+
result = operator.addition(tmpValue1, tmpValue2);
|
|
591
|
+
}
|
|
592
|
+
else if (ctx.Minus()) {
|
|
593
|
+
result = operator.subtraction(tmpValue1, tmpValue2);
|
|
594
|
+
}
|
|
595
|
+
this.setResult(ctx, result);
|
|
600
596
|
}
|
|
601
|
-
this.setResult(ctx, result);
|
|
602
597
|
};
|
|
603
598
|
this.visitFunction_def_expr = (ctx) => {
|
|
604
599
|
const functionName = ctx.ID().getText();
|
|
605
600
|
let funcDefinedParameters = [];
|
|
606
601
|
const ctxFunctionArgsExpr = ctx.function_args_expr();
|
|
607
602
|
if (ctxFunctionArgsExpr) {
|
|
608
|
-
this.
|
|
609
|
-
funcDefinedParameters = this.getResult(ctxFunctionArgsExpr);
|
|
603
|
+
funcDefinedParameters = this.visitResult(ctxFunctionArgsExpr);
|
|
610
604
|
}
|
|
611
605
|
const executionStack = this.executionStack;
|
|
612
606
|
const functionCounter = { counter: 0 };
|
|
@@ -637,12 +631,9 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
637
631
|
this.setResult(ctx, result);
|
|
638
632
|
};
|
|
639
633
|
this.visitAt_block_pin_expr = (ctx) => {
|
|
640
|
-
const
|
|
641
|
-
this.visit(ctxPinSelectExpr2);
|
|
642
|
-
const atPin = this.getResult(ctxPinSelectExpr2);
|
|
634
|
+
const atPin = this.visitResult(ctx.pin_select_expr2());
|
|
643
635
|
const executor = this.getExecutor();
|
|
644
|
-
const currentComponent = executor.
|
|
645
|
-
const currentPin = executor.scope.currentPin;
|
|
636
|
+
const [currentComponent, currentPin] = executor.getCurrentPoint();
|
|
646
637
|
executor.atComponent(currentComponent, atPin, {
|
|
647
638
|
addSequence: true
|
|
648
639
|
});
|
|
@@ -704,8 +695,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
704
695
|
useValue = Number(ctxIntegerValue);
|
|
705
696
|
}
|
|
706
697
|
else if (ctxDataExpr) {
|
|
707
|
-
this.
|
|
708
|
-
useValue = this.getResult(ctxDataExpr);
|
|
698
|
+
useValue = this.visitResult(ctxDataExpr);
|
|
709
699
|
}
|
|
710
700
|
if (useValue !== null) {
|
|
711
701
|
this.setResult(ctx, [direction, new helpers_js_1.UnitDimension(useValue)]);
|
|
@@ -717,8 +707,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
717
707
|
this.visitWire_expr = (ctx) => {
|
|
718
708
|
const wireAtomExpr = ctx.wire_atom_expr();
|
|
719
709
|
const segments = wireAtomExpr.map(wireSegment => {
|
|
720
|
-
this.
|
|
721
|
-
return this.getResult(wireSegment);
|
|
710
|
+
return this.visitResult(wireSegment);
|
|
722
711
|
});
|
|
723
712
|
this.getExecutor().addWire(segments);
|
|
724
713
|
};
|
|
@@ -727,18 +716,12 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
727
716
|
return this.getExecutor().addPoint(ID.getText());
|
|
728
717
|
};
|
|
729
718
|
this.visitProperty_set_expr = (ctx) => {
|
|
730
|
-
const
|
|
731
|
-
this.
|
|
732
|
-
const result = this.getResult(ctxDataExpr);
|
|
733
|
-
const ctxAtomExpr = ctx.atom_expr();
|
|
734
|
-
this.visit(ctxAtomExpr);
|
|
735
|
-
const resolvedProperty = this.getResult(ctxAtomExpr);
|
|
719
|
+
const result = this.visitResult(ctx.data_expr());
|
|
720
|
+
const resolvedProperty = this.visitResult(ctx.atom_expr());
|
|
736
721
|
this.getExecutor().setProperty(resolvedProperty, result);
|
|
737
722
|
};
|
|
738
723
|
this.visitDouble_dot_property_set_expr = (ctx) => {
|
|
739
|
-
const
|
|
740
|
-
this.visit(ctxDataExpr);
|
|
741
|
-
const result = this.getResult(ctxDataExpr);
|
|
724
|
+
const result = this.visitResult(ctx.data_expr());
|
|
742
725
|
const propertyName = ctx.ID().getText();
|
|
743
726
|
this.getExecutor().setProperty('..' + propertyName, result);
|
|
744
727
|
};
|
|
@@ -760,8 +743,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
760
743
|
const hasPlus = ctx.Addition();
|
|
761
744
|
const ctxDataExpr = ctx.data_expr();
|
|
762
745
|
if (ctxDataExpr) {
|
|
763
|
-
this.
|
|
764
|
-
dataValue = this.getResult(ctxDataExpr);
|
|
746
|
+
dataValue = this.visitResult(ctxDataExpr);
|
|
765
747
|
if (dataValue instanceof types_js_1.UndeclaredReference) {
|
|
766
748
|
netNamespace = "/" + dataValue.reference.name;
|
|
767
749
|
}
|
|
@@ -778,19 +760,19 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
778
760
|
this.setResult(ctx, (hasPlus ? "+" : "") + netNamespace);
|
|
779
761
|
};
|
|
780
762
|
this.visitIf_expr = (ctx) => {
|
|
781
|
-
const
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
763
|
+
const result = this.visitResult(ctx.data_expr());
|
|
764
|
+
let resultValue = result;
|
|
765
|
+
if (result instanceof types_js_1.UndeclaredReference) {
|
|
766
|
+
resultValue = false;
|
|
767
|
+
}
|
|
768
|
+
if (resultValue) {
|
|
785
769
|
this.visit(ctx.expressions_block());
|
|
786
770
|
}
|
|
787
771
|
else {
|
|
788
772
|
const ctxInnerIfExprs = ctx.if_inner_expr();
|
|
789
773
|
let innerIfWasTrue = false;
|
|
790
774
|
for (let i = 0; i < ctxInnerIfExprs.length; i++) {
|
|
791
|
-
const
|
|
792
|
-
this.visit(tmpCtx);
|
|
793
|
-
const innerResult = this.getResult(tmpCtx);
|
|
775
|
+
const innerResult = this.visitResult(ctxInnerIfExprs[i]);
|
|
794
776
|
if (innerResult) {
|
|
795
777
|
innerIfWasTrue = true;
|
|
796
778
|
break;
|
|
@@ -805,9 +787,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
805
787
|
}
|
|
806
788
|
};
|
|
807
789
|
this.visitIf_inner_expr = (ctx) => {
|
|
808
|
-
const
|
|
809
|
-
this.visit(ctxDataExpr);
|
|
810
|
-
const result = this.getResult(ctxDataExpr);
|
|
790
|
+
const result = this.visitResult(ctx.data_expr());
|
|
811
791
|
if (result) {
|
|
812
792
|
this.visit(ctx.expressions_block());
|
|
813
793
|
}
|
|
@@ -819,8 +799,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
819
799
|
this.log('enter while loop');
|
|
820
800
|
this.getExecutor().addBreakContext(ctx);
|
|
821
801
|
while (keepLooping) {
|
|
822
|
-
this.
|
|
823
|
-
const result = this.getResult(dataExpr);
|
|
802
|
+
const result = this.visitResult(dataExpr);
|
|
824
803
|
if (result) {
|
|
825
804
|
this.visit(ctx.expressions_block());
|
|
826
805
|
keepLooping = true;
|
|
@@ -845,10 +824,9 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
845
824
|
this.log('exit while loop');
|
|
846
825
|
};
|
|
847
826
|
this.visitFor_expr = (ctx) => {
|
|
827
|
+
this.log('in for loop');
|
|
848
828
|
const forVariableNames = ctx.ID().map(item => item.getText());
|
|
849
|
-
const
|
|
850
|
-
this.visit(ctxDataExpr);
|
|
851
|
-
const listItems = this.getResult(ctxDataExpr);
|
|
829
|
+
const listItems = this.visitResult(ctx.data_expr());
|
|
852
830
|
this.getExecutor().addBreakContext(ctx);
|
|
853
831
|
let keepLooping = true;
|
|
854
832
|
let counter = 0;
|
|
@@ -865,6 +843,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
865
843
|
keepLooping = true;
|
|
866
844
|
const currentResult = this.getResult(ctx) ?? {};
|
|
867
845
|
const { breakSignal = false, continueSignal = false } = currentResult;
|
|
846
|
+
this.log('condition result: ', breakSignal, continueSignal);
|
|
868
847
|
if (breakSignal && !continueSignal) {
|
|
869
848
|
keepLooping = false;
|
|
870
849
|
}
|
|
@@ -895,11 +874,12 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
895
874
|
this.getExecutor().log('expanding module `contains`');
|
|
896
875
|
const executionStack = this.executionStack;
|
|
897
876
|
const resolveNet = this.createNetResolver(executionStack);
|
|
898
|
-
const
|
|
877
|
+
const executor = this.getExecutor();
|
|
878
|
+
const executionContextName = executor.namespace + "_"
|
|
899
879
|
+ component.instanceName
|
|
900
880
|
+ '_' + component.moduleCounter;
|
|
901
881
|
const tmpNamespace = this.getNetNamespace(netNamespace, "+/" + component.instanceName + "_" + component.moduleCounter);
|
|
902
|
-
const newExecutor = this.enterNewChildContext(executionStack,
|
|
882
|
+
const newExecutor = this.enterNewChildContext(executionStack, executor, executionContextName, { netNamespace: tmpNamespace }, [], []);
|
|
903
883
|
component.moduleCounter += 1;
|
|
904
884
|
newExecutor.resolveNet = resolveNet;
|
|
905
885
|
this.visit(component.moduleContainsExpressions);
|
|
@@ -917,9 +897,9 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
917
897
|
});
|
|
918
898
|
const pinIdToPortMap = new Map();
|
|
919
899
|
moduleComponent.modulePinIdToPortMap = pinIdToPortMap;
|
|
920
|
-
for (const [
|
|
921
|
-
if (component._copyID !== null && component.typeProp ===
|
|
922
|
-
const portName = component.parameters.get(
|
|
900
|
+
for (const [, component] of executionContext.scope.instances) {
|
|
901
|
+
if (component._copyID !== null && component.typeProp === globals_js_1.ComponentTypes.port) {
|
|
902
|
+
const portName = component.parameters.get(globals_js_1.ParamKeys.net_name);
|
|
923
903
|
const modulePinId = modulePinMapping.get(portName);
|
|
924
904
|
pinIdToPortMap.set(modulePinId, component);
|
|
925
905
|
const portType = (0, utils_js_1.getPortType)(component);
|
|
@@ -929,7 +909,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
929
909
|
}
|
|
930
910
|
}
|
|
931
911
|
placeModuleContains(moduleComponent) {
|
|
932
|
-
if (moduleComponent.typeProp ===
|
|
912
|
+
if (moduleComponent.typeProp === globals_js_1.ComponentTypes.module
|
|
933
913
|
&& moduleComponent.moduleContainsExpressions) {
|
|
934
914
|
this.log('place module `contains`');
|
|
935
915
|
this.getExecutor().mergeScope(moduleComponent.moduleExecutionContext.scope, moduleComponent.moduleExecutionContextName);
|
|
@@ -941,17 +921,28 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
941
921
|
}
|
|
942
922
|
}
|
|
943
923
|
resolveDataExpr(data_expr) {
|
|
944
|
-
this.
|
|
945
|
-
const value = this.getResult(data_expr);
|
|
924
|
+
const value = this.visitResult(data_expr);
|
|
946
925
|
if (value instanceof types_js_1.UndeclaredReference) {
|
|
947
|
-
|
|
926
|
+
this.throwWithContext(data_expr, value.throwMessage());
|
|
927
|
+
}
|
|
928
|
+
else if (value instanceof types_js_1.DeclaredReference) {
|
|
929
|
+
return this.resolveDataValue(value);
|
|
948
930
|
}
|
|
949
931
|
return value;
|
|
950
932
|
}
|
|
933
|
+
resolveDataValue(reference) {
|
|
934
|
+
const { value } = reference;
|
|
935
|
+
if (value instanceof ParamDefinition_js_1.NumericValue) {
|
|
936
|
+
return value.toDisplayString();
|
|
937
|
+
}
|
|
938
|
+
else {
|
|
939
|
+
return value;
|
|
940
|
+
}
|
|
941
|
+
}
|
|
951
942
|
parseCreateComponentPins(pinData) {
|
|
952
943
|
const pins = [];
|
|
953
|
-
if (
|
|
954
|
-
const lastPin = pinData;
|
|
944
|
+
if (pinData instanceof ParamDefinition_js_1.NumericValue) {
|
|
945
|
+
const lastPin = pinData.toNumber();
|
|
955
946
|
for (let i = 0; i < lastPin; i++) {
|
|
956
947
|
const pinId = i + 1;
|
|
957
948
|
pins.push(new PinDefinition_js_1.PinDefinition(pinId, PinDefinition_js_1.PinIdType.Int, pinId.toString()));
|
|
@@ -987,30 +978,49 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
987
978
|
else {
|
|
988
979
|
pinName = pinDef;
|
|
989
980
|
}
|
|
981
|
+
this.log('pins', pinId, pinIdType, pinName, pinType, altPinNames);
|
|
990
982
|
pins.push(new PinDefinition_js_1.PinDefinition(pinId, pinIdType, pinName, pinType, altPinNames));
|
|
991
983
|
}
|
|
992
984
|
}
|
|
993
985
|
return pins;
|
|
994
986
|
}
|
|
995
987
|
parseCreateModulePorts(portsDefinition) {
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
988
|
+
return {
|
|
989
|
+
left: this.getPortItems(portsDefinition, globals_js_1.SymbolPinSide.Left),
|
|
990
|
+
right: this.getPortItems(portsDefinition, globals_js_1.SymbolPinSide.Right),
|
|
991
|
+
top: this.getPortItems(portsDefinition, globals_js_1.SymbolPinSide.Top),
|
|
992
|
+
bottom: this.getPortItems(portsDefinition, globals_js_1.SymbolPinSide.Bottom),
|
|
993
|
+
};
|
|
994
|
+
}
|
|
995
|
+
getArrangePropFromModulePorts(modulePorts, nameToPinId) {
|
|
996
|
+
const keys = [globals_js_1.SymbolPinSide.Left, globals_js_1.SymbolPinSide.Right, globals_js_1.SymbolPinSide.Top, globals_js_1.SymbolPinSide.Bottom];
|
|
997
|
+
const arrangeProp = new Map();
|
|
998
|
+
keys.forEach(key => {
|
|
999
|
+
if (modulePorts[key]) {
|
|
1000
|
+
const items = modulePorts[key].map(item => {
|
|
1001
|
+
if (Array.isArray(item)) {
|
|
1002
|
+
return item;
|
|
1003
|
+
}
|
|
1004
|
+
else {
|
|
1005
|
+
return (0, ParamDefinition_js_1.numeric)(nameToPinId.get(item));
|
|
1006
|
+
}
|
|
1007
|
+
});
|
|
1008
|
+
if (items.length > 0) {
|
|
1009
|
+
arrangeProp.set(key, items);
|
|
1010
|
+
}
|
|
1002
1011
|
}
|
|
1003
|
-
}
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1012
|
+
});
|
|
1013
|
+
return arrangeProp;
|
|
1014
|
+
}
|
|
1015
|
+
getPortItems(portsDefinition, key) {
|
|
1016
|
+
let tmpItems = [];
|
|
1017
|
+
if (portsDefinition.has(key)) {
|
|
1018
|
+
tmpItems = portsDefinition.get(key);
|
|
1019
|
+
if (!Array.isArray(tmpItems)) {
|
|
1020
|
+
tmpItems = [tmpItems];
|
|
1008
1021
|
}
|
|
1009
1022
|
}
|
|
1010
|
-
return
|
|
1011
|
-
left: leftItems,
|
|
1012
|
-
right: rightItems
|
|
1013
|
-
};
|
|
1023
|
+
return tmpItems;
|
|
1014
1024
|
}
|
|
1015
1025
|
parseCreateComponentParams(params) {
|
|
1016
1026
|
const result = [];
|
|
@@ -1089,8 +1099,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
1089
1099
|
const nets = executor.scope.getNets();
|
|
1090
1100
|
return {
|
|
1091
1101
|
sequence,
|
|
1092
|
-
nets
|
|
1093
|
-
components: Array.from(executor.scope.instances.values())
|
|
1102
|
+
nets
|
|
1094
1103
|
};
|
|
1095
1104
|
}
|
|
1096
1105
|
annotateComponents() {
|
|
@@ -1099,16 +1108,11 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
1099
1108
|
const instances = this.getExecutor().scope.instances;
|
|
1100
1109
|
const toAnnotate = [];
|
|
1101
1110
|
for (const [, instance] of instances) {
|
|
1111
|
+
if (instance.typeProp === globals_js_1.ComponentTypes.net
|
|
1112
|
+
|| instance.typeProp == globals_js_1.ComponentTypes.graphic) {
|
|
1113
|
+
continue;
|
|
1114
|
+
}
|
|
1102
1115
|
if (instance.assignedRefDes === null) {
|
|
1103
|
-
if (instance.typeProp === globals_js_1.ComponentTypes.label ||
|
|
1104
|
-
instance.typeProp === globals_js_1.ComponentTypes.net ||
|
|
1105
|
-
instance.typeProp === globals_js_1.ComponentTypes.point) {
|
|
1106
|
-
continue;
|
|
1107
|
-
}
|
|
1108
|
-
if (instance.typeProp === null) {
|
|
1109
|
-
this.log('Instance has no type:', instance.instanceName, ' assuming connector');
|
|
1110
|
-
instance.typeProp = 'conn';
|
|
1111
|
-
}
|
|
1112
1116
|
if (instance.parameters.has('refdes')) {
|
|
1113
1117
|
const refdes = instance.parameters.get('refdes');
|
|
1114
1118
|
if (refdes) {
|
|
@@ -1122,7 +1126,10 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
1122
1126
|
}
|
|
1123
1127
|
}
|
|
1124
1128
|
toAnnotate.forEach(instance => {
|
|
1125
|
-
const
|
|
1129
|
+
const useTypeProp = instance.typeProp ?? 'conn';
|
|
1130
|
+
instance.typeProp === null
|
|
1131
|
+
&& this.log('Instance has no type:', instance.instanceName, ' assuming connector');
|
|
1132
|
+
const newRefDes = annotater.getAnnotation(useTypeProp);
|
|
1126
1133
|
if (newRefDes !== null) {
|
|
1127
1134
|
instance.assignedRefDes = newRefDes;
|
|
1128
1135
|
this.log(newRefDes, '-', instance.instanceName);
|
|
@@ -1140,10 +1147,14 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
1140
1147
|
let frameComponent = null;
|
|
1141
1148
|
if (document && document[Frame_js_1.FrameParamKeys.SheetType]) {
|
|
1142
1149
|
frameComponent = document[Frame_js_1.FrameParamKeys.SheetType];
|
|
1143
|
-
baseScope.frames.
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1150
|
+
const sheets = baseScope.frames.filter(item => {
|
|
1151
|
+
return item.frameType === globals_js_1.FrameType.Sheet;
|
|
1152
|
+
});
|
|
1153
|
+
const totalSheets = sheets.length;
|
|
1154
|
+
sheets.forEach((item, index) => {
|
|
1155
|
+
item.parameters.set(Frame_js_1.FrameParamKeys.SheetType, frameComponent)
|
|
1156
|
+
.set(Frame_js_1.FrameParamKeys.SheetNumber, index + 1)
|
|
1157
|
+
.set(Frame_js_1.FrameParamKeys.SheetTotal, totalSheets);
|
|
1147
1158
|
});
|
|
1148
1159
|
}
|
|
1149
1160
|
return {
|
|
@@ -1168,25 +1179,10 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
1168
1179
|
}
|
|
1169
1180
|
return result;
|
|
1170
1181
|
}
|
|
1171
|
-
setComponentOrientation(component, pin, orientation) {
|
|
1172
|
-
if (this.acceptedDirections.indexOf(orientation) !== -1) {
|
|
1173
|
-
component.setParam('_addDirection', orientation);
|
|
1174
|
-
component.setParam('_addPin', pin);
|
|
1175
|
-
}
|
|
1176
|
-
else {
|
|
1177
|
-
throw "Invalid modifier for orientation";
|
|
1178
|
-
}
|
|
1179
|
-
}
|
|
1180
|
-
setComponentFlip(component, flipValue) {
|
|
1181
|
-
if (this.acceptedFlip.indexOf(flipValue) !== -1) {
|
|
1182
|
-
component.setParam(flipValue, 1);
|
|
1183
|
-
}
|
|
1184
|
-
}
|
|
1185
1182
|
getPropertyExprList(items) {
|
|
1186
1183
|
const properties = new Map();
|
|
1187
1184
|
items.forEach((item) => {
|
|
1188
|
-
this.
|
|
1189
|
-
const result = this.getResult(item);
|
|
1185
|
+
const result = this.visitResult(item);
|
|
1190
1186
|
for (const [key, value] of result) {
|
|
1191
1187
|
properties.set(key, value);
|
|
1192
1188
|
}
|
|
@@ -1196,14 +1192,14 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
1196
1192
|
}
|
|
1197
1193
|
exports.ParserVisitor = ParserVisitor;
|
|
1198
1194
|
const ComponentRefDesPrefixes = {
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1195
|
+
res: 'R',
|
|
1196
|
+
cap: 'C',
|
|
1197
|
+
ind: 'L',
|
|
1198
|
+
diode: 'D',
|
|
1199
|
+
conn: 'J',
|
|
1200
|
+
transistor: 'Q',
|
|
1201
|
+
relay: 'K',
|
|
1202
|
+
ic: 'U',
|
|
1207
1203
|
'?': '?',
|
|
1208
1204
|
};
|
|
1209
1205
|
class ComponentAnnotater {
|
|
@@ -1213,7 +1209,6 @@ class ComponentAnnotater {
|
|
|
1213
1209
|
for (const key in ComponentRefDesPrefixes) {
|
|
1214
1210
|
this.counter[key] = 1;
|
|
1215
1211
|
}
|
|
1216
|
-
this.counter['?'] = 1;
|
|
1217
1212
|
}
|
|
1218
1213
|
getAnnotation(type) {
|
|
1219
1214
|
if (this.counter[type] === undefined && type.length <= 2) {
|
|
@@ -1231,7 +1226,7 @@ class ComponentAnnotater {
|
|
|
1231
1226
|
return null;
|
|
1232
1227
|
}
|
|
1233
1228
|
let attempts = 100;
|
|
1234
|
-
let proposedName;
|
|
1229
|
+
let proposedName = "";
|
|
1235
1230
|
while (attempts >= 0) {
|
|
1236
1231
|
proposedName = ComponentRefDesPrefixes[type] + this.counter[type];
|
|
1237
1232
|
this.counter[type]++;
|