circuitscript 0.1.8 → 0.1.10
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 +7 -6
- package/dist/cjs/antlr/CircuitScriptParser.js +141 -123
- package/dist/cjs/builtinMethods.js +15 -0
- package/dist/cjs/draw_symbols.js +3 -0
- package/dist/cjs/execute.js +90 -2
- package/dist/cjs/helpers.js +1 -0
- package/dist/cjs/layout.js +33 -44
- package/dist/cjs/objects/ClassComponent.js +1 -0
- package/dist/cjs/objects/ExecutionScope.js +5 -4
- package/dist/cjs/utils.js +57 -14
- package/dist/cjs/visitor.js +99 -39
- package/dist/esm/BaseVisitor.js +7 -6
- package/dist/esm/antlr/CircuitScriptParser.js +141 -123
- package/dist/esm/builtinMethods.js +15 -0
- package/dist/esm/draw_symbols.js +4 -1
- package/dist/esm/execute.js +91 -3
- package/dist/esm/helpers.js +2 -1
- package/dist/esm/layout.js +34 -45
- package/dist/esm/objects/ClassComponent.js +1 -0
- package/dist/esm/objects/ExecutionScope.js +5 -4
- package/dist/esm/utils.js +54 -13
- package/dist/esm/visitor.js +100 -40
- package/dist/types/BaseVisitor.d.ts +3 -1
- package/dist/types/antlr/CircuitScriptParser.d.ts +2 -1
- package/dist/types/execute.d.ts +6 -1
- package/dist/types/objects/ClassComponent.d.ts +1 -0
- package/dist/types/objects/ExecutionScope.d.ts +3 -2
- package/dist/types/utils.d.ts +9 -1
- package/dist/types/visitor.d.ts +2 -0
- package/package.json +1 -1
package/dist/cjs/execute.js
CHANGED
|
@@ -15,7 +15,7 @@ const helpers_js_1 = require("./helpers.js");
|
|
|
15
15
|
const draw_symbols_js_1 = require("./draw_symbols.js");
|
|
16
16
|
const utils_js_1 = require("./utils.js");
|
|
17
17
|
class ExecutionContext {
|
|
18
|
-
constructor(name, namespace, netNamespace, executionLevel = 0, indentLevel = 0, silent = false, logger, parent) {
|
|
18
|
+
constructor(name, namespace, netNamespace, executionLevel = 0, indentLevel = 0, silent = false, logger, warnings, parent) {
|
|
19
19
|
this.tmpPointId = 0;
|
|
20
20
|
this.resolveNet = null;
|
|
21
21
|
this.stopFurtherExpressions = false;
|
|
@@ -23,6 +23,7 @@ class ExecutionContext {
|
|
|
23
23
|
this.silent = false;
|
|
24
24
|
this.__functionCache = {};
|
|
25
25
|
this.componentAngleFollowsWire = true;
|
|
26
|
+
this.warnings = [];
|
|
26
27
|
this.name = name;
|
|
27
28
|
this.namespace = namespace;
|
|
28
29
|
this.netNamespace = netNamespace;
|
|
@@ -34,6 +35,14 @@ class ExecutionContext {
|
|
|
34
35
|
this.silent = silent;
|
|
35
36
|
this.log('create new execution context', this.namespace, this.name, this.scope.indentLevel);
|
|
36
37
|
this.parentContext = parent;
|
|
38
|
+
this.warnings = warnings;
|
|
39
|
+
}
|
|
40
|
+
logWarning(message, context, fileName) {
|
|
41
|
+
this.warnings.push({
|
|
42
|
+
message,
|
|
43
|
+
ctx: context,
|
|
44
|
+
fileName,
|
|
45
|
+
});
|
|
37
46
|
}
|
|
38
47
|
log(...params) {
|
|
39
48
|
const indentOutput = ''.padStart(this.scope.indentLevel * 4, ' ');
|
|
@@ -120,7 +129,6 @@ class ExecutionContext {
|
|
|
120
129
|
pins.forEach((pin) => {
|
|
121
130
|
component.pins.set(pin.id, pin);
|
|
122
131
|
});
|
|
123
|
-
component.arrangeProps = props.arrange ?? null;
|
|
124
132
|
component.displayProp = props.display ?? null;
|
|
125
133
|
component.widthProp = props.width ?? null;
|
|
126
134
|
component.heightProp = props.height ?? null;
|
|
@@ -133,6 +141,33 @@ class ExecutionContext {
|
|
|
133
141
|
useAngle += 360;
|
|
134
142
|
}
|
|
135
143
|
}
|
|
144
|
+
if (props.display === null && props.arrange === null) {
|
|
145
|
+
const tmpArrangeLeft = [];
|
|
146
|
+
const tmpArrangeRight = [];
|
|
147
|
+
pins.forEach((pin, index) => {
|
|
148
|
+
const useArray = (index % 2 === 0) ? tmpArrangeLeft : tmpArrangeRight;
|
|
149
|
+
useArray.push((0, ParamDefinition_js_1.numeric)(pin.id));
|
|
150
|
+
});
|
|
151
|
+
const arrangeProp = new Map([
|
|
152
|
+
[globals_js_1.SymbolPinSide.Left, tmpArrangeLeft],
|
|
153
|
+
[globals_js_1.SymbolPinSide.Right, tmpArrangeRight]
|
|
154
|
+
]);
|
|
155
|
+
props.arrange = arrangeProp;
|
|
156
|
+
}
|
|
157
|
+
if (props.arrange !== null) {
|
|
158
|
+
component.arrangeProps = this.removeArrangePropDuplicates(props.arrange);
|
|
159
|
+
const arrangePropPins = this.getArrangePropPins(component.arrangeProps).map(item => {
|
|
160
|
+
return item.toNumber();
|
|
161
|
+
});
|
|
162
|
+
pins.forEach(pin => {
|
|
163
|
+
if (arrangePropPins.indexOf(pin.id) === -1) {
|
|
164
|
+
this.logWarning(`Pin ${pin.id} is not specified in arrange property`);
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
component.arrangeProps = null;
|
|
170
|
+
}
|
|
136
171
|
component.angleProp = useAngle ?? 0;
|
|
137
172
|
component.followWireOrientationProp = props.followWireOrientation;
|
|
138
173
|
const paramsMap = new Map();
|
|
@@ -176,6 +211,59 @@ class ExecutionContext {
|
|
|
176
211
|
this.log('add symbol', instanceName, '[' + pinsOutput.join(', ') + ']');
|
|
177
212
|
return component;
|
|
178
213
|
}
|
|
214
|
+
removeArrangePropDuplicates(arrangeProp) {
|
|
215
|
+
const sides = [
|
|
216
|
+
globals_js_1.SymbolPinSide.Left,
|
|
217
|
+
globals_js_1.SymbolPinSide.Right,
|
|
218
|
+
globals_js_1.SymbolPinSide.Top,
|
|
219
|
+
globals_js_1.SymbolPinSide.Bottom
|
|
220
|
+
];
|
|
221
|
+
const result = new Map();
|
|
222
|
+
const seenIds = [];
|
|
223
|
+
sides.forEach(side => {
|
|
224
|
+
let items = arrangeProp.get(side) ?? [];
|
|
225
|
+
if (!Array.isArray(items)) {
|
|
226
|
+
items = [items];
|
|
227
|
+
}
|
|
228
|
+
const uniqueItems = [];
|
|
229
|
+
items.forEach(item => {
|
|
230
|
+
if (item instanceof ParamDefinition_js_1.NumericValue) {
|
|
231
|
+
if (seenIds.indexOf(item.toNumber()) === -1) {
|
|
232
|
+
seenIds.push(item.toNumber());
|
|
233
|
+
uniqueItems.push(item);
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
this.logWarning(`Pin ${item.toNumber()} specified more than once in arrange property`);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
uniqueItems.push(item);
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
result.set(side, uniqueItems);
|
|
244
|
+
});
|
|
245
|
+
return result;
|
|
246
|
+
}
|
|
247
|
+
getArrangePropPins(arrangeProps) {
|
|
248
|
+
const pins = [];
|
|
249
|
+
const sides = [
|
|
250
|
+
globals_js_1.SymbolPinSide.Left,
|
|
251
|
+
globals_js_1.SymbolPinSide.Right,
|
|
252
|
+
globals_js_1.SymbolPinSide.Top,
|
|
253
|
+
globals_js_1.SymbolPinSide.Bottom
|
|
254
|
+
];
|
|
255
|
+
sides.forEach(side => {
|
|
256
|
+
const items = arrangeProps.get(side);
|
|
257
|
+
if (items) {
|
|
258
|
+
items.forEach(item => {
|
|
259
|
+
if (item instanceof ParamDefinition_js_1.NumericValue) {
|
|
260
|
+
pins.push(item);
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
return pins;
|
|
266
|
+
}
|
|
179
267
|
printPoint(extra = '') {
|
|
180
268
|
let netString = globals_js_1.NoNetText;
|
|
181
269
|
if (this.scope.currentComponent === null || this.scope.currentPin === null) {
|
package/dist/cjs/helpers.js
CHANGED
|
@@ -195,6 +195,7 @@ async function renderScript(scriptData, outputPath, options) {
|
|
|
195
195
|
visitor.log('reading file');
|
|
196
196
|
visitor.log('done reading file');
|
|
197
197
|
const { tree, parser, parserTimeTaken, lexerTimeTaken } = await (0, parser_js_1.parseFileWithVisitor)(visitor, scriptData);
|
|
198
|
+
(0, utils_js_1.printWarnings)(visitor.getWarnings());
|
|
198
199
|
showStats && console.log('Lexing took:', lexerTimeTaken);
|
|
199
200
|
showStats && console.log('Parsing took:', parserTimeTaken);
|
|
200
201
|
if (dumpNets) {
|
package/dist/cjs/layout.js
CHANGED
|
@@ -1084,52 +1084,39 @@ function generateLayoutPinDefinition(component) {
|
|
|
1084
1084
|
const pins = component.pins;
|
|
1085
1085
|
const symbolPinDefinitions = [];
|
|
1086
1086
|
const existingPinIds = Array.from(pins.keys());
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
pinId: existingPinIds[i],
|
|
1094
|
-
text: pin.name,
|
|
1095
|
-
position: pinPosition,
|
|
1096
|
-
pinType: pin.pinType,
|
|
1097
|
-
});
|
|
1087
|
+
const arrangeProps = component.arrangeProps ?? [];
|
|
1088
|
+
const addedPins = [];
|
|
1089
|
+
for (const [key, items] of arrangeProps) {
|
|
1090
|
+
let useItems;
|
|
1091
|
+
if (!Array.isArray(items)) {
|
|
1092
|
+
useItems = [items];
|
|
1098
1093
|
}
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
const addedPins = [];
|
|
1102
|
-
for (const [key, items] of component.arrangeProps) {
|
|
1103
|
-
let useItems;
|
|
1104
|
-
if (!Array.isArray(items)) {
|
|
1105
|
-
useItems = [items];
|
|
1106
|
-
}
|
|
1107
|
-
else {
|
|
1108
|
-
useItems = [...items];
|
|
1109
|
-
}
|
|
1110
|
-
useItems.forEach(pinId => {
|
|
1111
|
-
if (pinId instanceof ParamDefinition_js_1.NumericValue) {
|
|
1112
|
-
const pinIdValue = pinId.toNumber();
|
|
1113
|
-
if (existingPinIds.indexOf(pinIdValue) !== -1) {
|
|
1114
|
-
const pin = pins.get(pinIdValue);
|
|
1115
|
-
symbolPinDefinitions.push({
|
|
1116
|
-
side: key,
|
|
1117
|
-
pinId: pinIdValue,
|
|
1118
|
-
text: pin.name,
|
|
1119
|
-
position: pin.position,
|
|
1120
|
-
pinType: pin.pinType,
|
|
1121
|
-
});
|
|
1122
|
-
addedPins.push(pinIdValue);
|
|
1123
|
-
}
|
|
1124
|
-
}
|
|
1125
|
-
});
|
|
1094
|
+
else {
|
|
1095
|
+
useItems = [...items];
|
|
1126
1096
|
}
|
|
1127
|
-
|
|
1128
|
-
|
|
1097
|
+
useItems.forEach(pinId => {
|
|
1098
|
+
if (pinId instanceof ParamDefinition_js_1.NumericValue) {
|
|
1099
|
+
const pinIdValue = pinId.toNumber();
|
|
1100
|
+
if (existingPinIds.indexOf(pinIdValue) !== -1) {
|
|
1101
|
+
const pin = pins.get(pinIdValue);
|
|
1102
|
+
symbolPinDefinitions.push({
|
|
1103
|
+
side: key,
|
|
1104
|
+
pinId: pinIdValue,
|
|
1105
|
+
text: pin.name,
|
|
1106
|
+
position: pin.position,
|
|
1107
|
+
pinType: pin.pinType,
|
|
1108
|
+
});
|
|
1109
|
+
addedPins.push(pinIdValue);
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1129
1112
|
});
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1113
|
+
}
|
|
1114
|
+
const unplacedPins = existingPinIds.filter(pinId => {
|
|
1115
|
+
return addedPins.indexOf(pinId) === -1;
|
|
1116
|
+
});
|
|
1117
|
+
if (unplacedPins.length > 0) {
|
|
1118
|
+
component._unplacedPins = unplacedPins;
|
|
1119
|
+
console.warn("Warning: There are unplaced pins: " + unplacedPins);
|
|
1133
1120
|
}
|
|
1134
1121
|
return symbolPinDefinitions;
|
|
1135
1122
|
}
|
|
@@ -1486,7 +1473,9 @@ function CalculatePinPositions(component) {
|
|
|
1486
1473
|
tmpSymbol.refreshDrawing();
|
|
1487
1474
|
const pins = component.pins;
|
|
1488
1475
|
pins.forEach((value, key) => {
|
|
1489
|
-
|
|
1476
|
+
if (component._unplacedPins.indexOf(key) === -1) {
|
|
1477
|
+
pinPositionMapping.set(key, tmpSymbol.pinPosition(key));
|
|
1478
|
+
}
|
|
1490
1479
|
});
|
|
1491
1480
|
return pinPositionMapping;
|
|
1492
1481
|
}
|
|
@@ -132,12 +132,13 @@ class ExecutionScope {
|
|
|
132
132
|
exitContext() {
|
|
133
133
|
return this.contextStack.pop();
|
|
134
134
|
}
|
|
135
|
-
findPropertyKeyTree() {
|
|
135
|
+
findPropertyKeyTree(visitor) {
|
|
136
136
|
const keyNames = [];
|
|
137
137
|
for (let i = this.contextStack.length - 1; i >= 0; i--) {
|
|
138
138
|
const ctx = this.contextStack[i];
|
|
139
139
|
if (ctx instanceof CircuitScriptParser_js_1.Property_key_exprContext) {
|
|
140
|
-
|
|
140
|
+
const result = visitor.visitResult(ctx);
|
|
141
|
+
keyNames.push([ctx, result]);
|
|
141
142
|
}
|
|
142
143
|
else if (typeof ctx === 'number') {
|
|
143
144
|
keyNames.push(['index', ctx]);
|
|
@@ -151,9 +152,9 @@ class ExecutionScope {
|
|
|
151
152
|
popOnPropertyHandler() {
|
|
152
153
|
return this.onPropertyHandler.pop();
|
|
153
154
|
}
|
|
154
|
-
triggerPropertyHandler(value, valueCtx) {
|
|
155
|
+
triggerPropertyHandler(visitor, value, valueCtx) {
|
|
155
156
|
const lastHandler = this.onPropertyHandler[this.onPropertyHandler.length - 1];
|
|
156
|
-
const propertyTree = this.findPropertyKeyTree();
|
|
157
|
+
const propertyTree = this.findPropertyKeyTree(visitor);
|
|
157
158
|
lastHandler && lastHandler(propertyTree, value, valueCtx);
|
|
158
159
|
}
|
|
159
160
|
}
|
package/dist/cjs/utils.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RenderError = exports.RuntimeExecutionError = exports.ParseError = exports.ParseSyntaxError = exports.BaseError = exports.getBlockTypeString = exports.generateDebugSequenceAction = exports.sequenceActionString = exports.areasOverlap = exports.isPointWithinArea = exports.resolveToNumericValue = exports.getNumberExponentialText = exports.getNumberExponential = exports.combineMaps = exports.throwWithTokenRange = exports.throwWithToken = exports.throwWithContext = exports.roundValue = exports.getPortType = exports.getBoundsSize = exports.toNearestGrid = exports.resizeToNearestGrid = exports.printBounds = exports.resizeBounds = exports.SimpleStopwatch = void 0;
|
|
3
|
+
exports.printWarnings = exports.RenderError = exports.RuntimeExecutionError = exports.ParseError = exports.ParseSyntaxError = exports.getLinePositionAsString = exports.BaseError = exports.getBlockTypeString = exports.generateDebugSequenceAction = exports.sequenceActionString = exports.areasOverlap = exports.isPointWithinArea = exports.resolveToNumericValue = exports.getNumberExponentialText = exports.getNumberExponential = exports.combineMaps = exports.throwWithTokenRange = exports.throwWithToken = exports.throwWithContext = exports.roundValue = exports.getPortType = exports.getBoundsSize = exports.toNearestGrid = exports.resizeToNearestGrid = exports.printBounds = exports.resizeBounds = exports.SimpleStopwatch = void 0;
|
|
4
4
|
const big_js_1 = require("big.js");
|
|
5
|
+
const antlr4ng_1 = require("antlr4ng");
|
|
5
6
|
const ClassComponent_js_1 = require("./objects/ClassComponent.js");
|
|
6
7
|
const ParamDefinition_js_1 = require("./objects/ParamDefinition.js");
|
|
7
8
|
const ExecutionScope_js_1 = require("./objects/ExecutionScope.js");
|
|
@@ -260,32 +261,55 @@ function getBlockTypeString(type) {
|
|
|
260
261
|
}
|
|
261
262
|
exports.getBlockTypeString = getBlockTypeString;
|
|
262
263
|
class BaseError extends Error {
|
|
263
|
-
constructor(message,
|
|
264
|
+
constructor(message, startTokenOrCtx, endToken, filePath) {
|
|
264
265
|
super(message);
|
|
265
266
|
this.name = 'BaseError';
|
|
266
267
|
this.message = message;
|
|
267
|
-
|
|
268
|
-
|
|
268
|
+
if (startTokenOrCtx instanceof antlr4ng_1.ParserRuleContext) {
|
|
269
|
+
this.startToken = startTokenOrCtx.start;
|
|
270
|
+
this.endToken = startTokenOrCtx.stop;
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
this.startToken = startTokenOrCtx;
|
|
274
|
+
this.endToken = endToken;
|
|
275
|
+
}
|
|
269
276
|
this.filePath = filePath;
|
|
270
277
|
}
|
|
271
278
|
toString() {
|
|
272
279
|
const parts = [this.name];
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
}
|
|
280
|
-
else {
|
|
281
|
-
parts.push(` at ${line}:${column}`);
|
|
282
|
-
}
|
|
280
|
+
const linePosition = getLinePositionAsString({
|
|
281
|
+
start: this.startToken,
|
|
282
|
+
stop: this.endToken
|
|
283
|
+
});
|
|
284
|
+
if (linePosition !== null) {
|
|
285
|
+
parts.push(linePosition);
|
|
283
286
|
}
|
|
284
287
|
parts.push(`: ${this.message}`);
|
|
285
288
|
return parts.join('');
|
|
286
289
|
}
|
|
287
290
|
}
|
|
288
291
|
exports.BaseError = BaseError;
|
|
292
|
+
function getLinePositionAsString(ctx) {
|
|
293
|
+
if (ctx === null || ctx === undefined) {
|
|
294
|
+
return null;
|
|
295
|
+
}
|
|
296
|
+
const startToken = ctx.start;
|
|
297
|
+
const endToken = ctx.stop;
|
|
298
|
+
let result = null;
|
|
299
|
+
if (startToken) {
|
|
300
|
+
const { line, column } = startToken;
|
|
301
|
+
if (endToken && (endToken.line !== startToken.line || endToken.column !== startToken.column)) {
|
|
302
|
+
const endLine = endToken.line;
|
|
303
|
+
const endColumn = endToken.column + (endToken.stop - endToken.start);
|
|
304
|
+
result = ` at ${line}:${column}-${endLine}:${endColumn}`;
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
result = ` at ${line}:${column}`;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return result;
|
|
311
|
+
}
|
|
312
|
+
exports.getLinePositionAsString = getLinePositionAsString;
|
|
289
313
|
class ParseSyntaxError extends BaseError {
|
|
290
314
|
constructor() {
|
|
291
315
|
super(...arguments);
|
|
@@ -315,3 +339,22 @@ class RenderError extends Error {
|
|
|
315
339
|
}
|
|
316
340
|
}
|
|
317
341
|
exports.RenderError = RenderError;
|
|
342
|
+
function printWarnings(warnings) {
|
|
343
|
+
const warningMessages = [];
|
|
344
|
+
warnings.forEach(item => {
|
|
345
|
+
const { message } = item;
|
|
346
|
+
const linePosition = getLinePositionAsString(item.ctx);
|
|
347
|
+
const parts = [message];
|
|
348
|
+
if (linePosition !== null) {
|
|
349
|
+
parts.push(linePosition);
|
|
350
|
+
}
|
|
351
|
+
const finalMessage = parts.join('');
|
|
352
|
+
if (warningMessages.indexOf(finalMessage) === -1) {
|
|
353
|
+
warningMessages.push(finalMessage);
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
warningMessages.forEach(message => {
|
|
357
|
+
console.log(`Warning: ${message}`);
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
exports.printWarnings = printWarnings;
|
package/dist/cjs/visitor.js
CHANGED
|
@@ -52,7 +52,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
54
|
catch (err) {
|
|
55
|
-
throw new utils_js_1.RuntimeExecutionError(err.message, ctx
|
|
55
|
+
throw new utils_js_1.RuntimeExecutionError(err.message, ctx);
|
|
56
56
|
}
|
|
57
57
|
});
|
|
58
58
|
return this.getExecutor().getCurrentPoint();
|
|
@@ -120,6 +120,24 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
120
120
|
};
|
|
121
121
|
this.visitCreate_component_expr = (ctx) => {
|
|
122
122
|
const scope = this.getScope();
|
|
123
|
+
const definedPinIds = [];
|
|
124
|
+
const arrangedPinIds = [];
|
|
125
|
+
const checkPinExistsAndNotDuplicated = (pinId, ctx) => {
|
|
126
|
+
if (definedPinIds.indexOf(pinId) === -1) {
|
|
127
|
+
this.warnings.push({
|
|
128
|
+
message: `Invalid pin ${pinId}`, ctx
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
if (arrangedPinIds.indexOf(pinId) !== -1) {
|
|
132
|
+
this.warnings.push({
|
|
133
|
+
message: `Pin ${pinId} specified more than once`,
|
|
134
|
+
ctx,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
arrangedPinIds.push(pinId);
|
|
138
|
+
};
|
|
139
|
+
let didDefineArrangeProp = false;
|
|
140
|
+
let didDefineDisplayProp = false;
|
|
123
141
|
scope.setOnPropertyHandler((path, value, ctx) => {
|
|
124
142
|
if (path.length === 1) {
|
|
125
143
|
const [, keyName] = path[0];
|
|
@@ -132,9 +150,25 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
132
150
|
case 'height':
|
|
133
151
|
this.validateNumeric(value, ctx);
|
|
134
152
|
break;
|
|
153
|
+
case 'display':
|
|
154
|
+
if (didDefineArrangeProp) {
|
|
155
|
+
throw new utils_js_1.RuntimeExecutionError("arrange property has already been defined", ctx);
|
|
156
|
+
}
|
|
157
|
+
didDefineDisplayProp = true;
|
|
158
|
+
break;
|
|
159
|
+
case 'arrange':
|
|
160
|
+
if (didDefineDisplayProp) {
|
|
161
|
+
throw new utils_js_1.RuntimeExecutionError("display property already defined", ctx);
|
|
162
|
+
}
|
|
163
|
+
didDefineArrangeProp = true;
|
|
164
|
+
break;
|
|
135
165
|
case 'pins':
|
|
136
166
|
if (!(value instanceof Map)) {
|
|
137
167
|
this.validateNumeric(value, ctx);
|
|
168
|
+
const numPins = value.toNumber();
|
|
169
|
+
for (let i = 0; i < numPins; i++) {
|
|
170
|
+
definedPinIds.push(i + 1);
|
|
171
|
+
}
|
|
138
172
|
}
|
|
139
173
|
break;
|
|
140
174
|
case 'copy':
|
|
@@ -145,7 +179,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
145
179
|
this.validateBoolean(value, ctx);
|
|
146
180
|
}
|
|
147
181
|
else {
|
|
148
|
-
throw new utils_js_1.RuntimeExecutionError("Invalid value for 'copy' property", ctx
|
|
182
|
+
throw new utils_js_1.RuntimeExecutionError("Invalid value for 'copy' property", ctx);
|
|
149
183
|
}
|
|
150
184
|
break;
|
|
151
185
|
}
|
|
@@ -155,20 +189,26 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
155
189
|
if (keyName === 'arrange') {
|
|
156
190
|
const [sideKeyCtx, sideKeyName] = path[1];
|
|
157
191
|
if (globals_js_1.ValidPinSides.indexOf(sideKeyName) === -1) {
|
|
158
|
-
throw new utils_js_1.RuntimeExecutionError(`Invalid side ${sideKeyName} in arrange`, sideKeyCtx
|
|
192
|
+
throw new utils_js_1.RuntimeExecutionError(`Invalid side ${sideKeyName} in arrange`, sideKeyCtx);
|
|
159
193
|
}
|
|
160
194
|
else {
|
|
161
|
-
if (path.length
|
|
195
|
+
if (path.length === 2 && value instanceof ParamDefinition_js_1.NumericValue) {
|
|
196
|
+
checkPinExistsAndNotDuplicated(value.toNumber(), ctx);
|
|
197
|
+
}
|
|
198
|
+
else if (path.length > 2 && path[2][0] === 'index') {
|
|
162
199
|
if (Array.isArray(value)) {
|
|
163
200
|
const goodBlank = value.length === 1 &&
|
|
164
201
|
value[0] instanceof ParamDefinition_js_1.NumericValue;
|
|
165
202
|
if (!goodBlank) {
|
|
166
|
-
throw new utils_js_1.RuntimeExecutionError(`Invalid blank specifier`, ctx
|
|
203
|
+
throw new utils_js_1.RuntimeExecutionError(`Invalid blank specifier`, ctx);
|
|
167
204
|
}
|
|
168
205
|
}
|
|
169
206
|
else {
|
|
170
207
|
if (!(value instanceof ParamDefinition_js_1.NumericValue)) {
|
|
171
|
-
throw new utils_js_1.RuntimeExecutionError(`Invalid numeric value for arrange.${sideKeyName}`, ctx
|
|
208
|
+
throw new utils_js_1.RuntimeExecutionError(`Invalid numeric value for arrange.${sideKeyName}`, ctx);
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
checkPinExistsAndNotDuplicated(value.toNumber(), ctx);
|
|
172
212
|
}
|
|
173
213
|
}
|
|
174
214
|
}
|
|
@@ -189,10 +229,12 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
189
229
|
}
|
|
190
230
|
else if (keyName === 'pins') {
|
|
191
231
|
if (path.length === 2) {
|
|
232
|
+
const idName = path[1][1];
|
|
233
|
+
definedPinIds.push(idName);
|
|
192
234
|
if (value.length === 2) {
|
|
193
235
|
const [pinType,] = value;
|
|
194
236
|
if (pinType instanceof types_js_1.UndeclaredReference) {
|
|
195
|
-
throw new utils_js_1.RuntimeExecutionError(`Invalid pin type: ${pinType.reference.name}`, ctx
|
|
237
|
+
throw new utils_js_1.RuntimeExecutionError(`Invalid pin type: ${pinType.reference.name}`, ctx);
|
|
196
238
|
}
|
|
197
239
|
}
|
|
198
240
|
}
|
|
@@ -421,7 +463,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
421
463
|
this.getScope().enterContext(ctxValue);
|
|
422
464
|
const keyName = this.visitResult(ctxKey);
|
|
423
465
|
const value = this.visitResult(ctxValue);
|
|
424
|
-
scope.triggerPropertyHandler(value, ctxValue);
|
|
466
|
+
scope.triggerPropertyHandler(this, value, ctxValue);
|
|
425
467
|
this.getScope().exitContext();
|
|
426
468
|
this.getScope().exitContext();
|
|
427
469
|
if (value instanceof types_js_1.UndeclaredReference && (value.reference.parentValue === undefined
|
|
@@ -442,7 +484,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
442
484
|
value = ctx.data_expr().map((item, index) => {
|
|
443
485
|
this.getScope().enterContext(index);
|
|
444
486
|
const result = this.visitResult(item);
|
|
445
|
-
this.getScope().triggerPropertyHandler(result, item);
|
|
487
|
+
this.getScope().triggerPropertyHandler(this, result, item);
|
|
446
488
|
this.getScope().exitContext();
|
|
447
489
|
return result;
|
|
448
490
|
});
|
|
@@ -840,7 +882,21 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
840
882
|
};
|
|
841
883
|
this.visitPoint_expr = (ctx) => {
|
|
842
884
|
const ID = ctx.ID();
|
|
843
|
-
|
|
885
|
+
const ctxData = ctx.data_expr();
|
|
886
|
+
let pointValue;
|
|
887
|
+
if (ctxData) {
|
|
888
|
+
const resultValue = this.visitResult(ctxData);
|
|
889
|
+
if (typeof resultValue === 'string') {
|
|
890
|
+
pointValue = resultValue;
|
|
891
|
+
}
|
|
892
|
+
else {
|
|
893
|
+
throw new utils_js_1.RuntimeExecutionError('Invalid value for point');
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
else if (ID) {
|
|
897
|
+
pointValue = ID.getText();
|
|
898
|
+
}
|
|
899
|
+
return this.getExecutor().addPoint(pointValue);
|
|
844
900
|
};
|
|
845
901
|
this.visitProperty_set_expr = (ctx) => {
|
|
846
902
|
const result = this.visitResult(ctx.data_expr());
|
|
@@ -1069,45 +1125,46 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
1069
1125
|
parseCreateComponentPins(pinData) {
|
|
1070
1126
|
const pins = [];
|
|
1071
1127
|
if (pinData instanceof ParamDefinition_js_1.NumericValue) {
|
|
1128
|
+
const tmpMap = new Map();
|
|
1072
1129
|
const lastPin = pinData.toNumber();
|
|
1073
1130
|
for (let i = 0; i < lastPin; i++) {
|
|
1074
1131
|
const pinId = i + 1;
|
|
1075
|
-
|
|
1132
|
+
tmpMap.set(pinId, (0, ParamDefinition_js_1.numeric)(pinId));
|
|
1076
1133
|
}
|
|
1134
|
+
pinData = tmpMap;
|
|
1077
1135
|
}
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
}
|
|
1097
|
-
}
|
|
1098
|
-
else {
|
|
1099
|
-
pinName = pinDef[0];
|
|
1100
|
-
if (pinDef.length > 1) {
|
|
1101
|
-
altPinNames = pinDef.slice(1);
|
|
1102
|
-
}
|
|
1136
|
+
pinData = pinData ?? [];
|
|
1137
|
+
for (const [pinId, pinDef] of pinData) {
|
|
1138
|
+
let pinIdType = PinDefinition_js_1.PinIdType.Int;
|
|
1139
|
+
let pinType = PinTypes_js_1.PinTypes.Any;
|
|
1140
|
+
let pinName = null;
|
|
1141
|
+
let altPinNames = [];
|
|
1142
|
+
if (typeof pinId === 'string') {
|
|
1143
|
+
pinIdType = PinDefinition_js_1.PinIdType.Str;
|
|
1144
|
+
}
|
|
1145
|
+
if (Array.isArray(pinDef)) {
|
|
1146
|
+
const firstValue = pinDef[0];
|
|
1147
|
+
if (firstValue.type
|
|
1148
|
+
&& firstValue.type === globals_js_1.ReferenceTypes.pinType
|
|
1149
|
+
&& this.pinTypes.indexOf(firstValue.value) !== -1) {
|
|
1150
|
+
pinType = firstValue.value;
|
|
1151
|
+
pinName = pinDef[1];
|
|
1152
|
+
if (pinDef.length > 2) {
|
|
1153
|
+
altPinNames = pinDef.slice(2);
|
|
1103
1154
|
}
|
|
1104
1155
|
}
|
|
1105
1156
|
else {
|
|
1106
|
-
pinName = pinDef;
|
|
1157
|
+
pinName = pinDef[0];
|
|
1158
|
+
if (pinDef.length > 1) {
|
|
1159
|
+
altPinNames = pinDef.slice(1);
|
|
1160
|
+
}
|
|
1107
1161
|
}
|
|
1108
|
-
this.log('pins', pinId, pinIdType, pinName, pinType, altPinNames);
|
|
1109
|
-
pins.push(new PinDefinition_js_1.PinDefinition(pinId, pinIdType, pinName, pinType, altPinNames));
|
|
1110
1162
|
}
|
|
1163
|
+
else {
|
|
1164
|
+
pinName = pinDef;
|
|
1165
|
+
}
|
|
1166
|
+
this.log('pins', pinId, pinIdType, pinName, pinType, altPinNames);
|
|
1167
|
+
pins.push(new PinDefinition_js_1.PinDefinition(pinId, pinIdType, pinName, pinType, altPinNames));
|
|
1111
1168
|
}
|
|
1112
1169
|
return pins;
|
|
1113
1170
|
}
|
|
@@ -1316,6 +1373,9 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
1316
1373
|
});
|
|
1317
1374
|
return properties;
|
|
1318
1375
|
}
|
|
1376
|
+
getWarnings() {
|
|
1377
|
+
return this.warnings;
|
|
1378
|
+
}
|
|
1319
1379
|
}
|
|
1320
1380
|
exports.ParserVisitor = ParserVisitor;
|
|
1321
1381
|
const ComponentRefDesPrefixes = {
|