circuitscript 0.0.22 → 0.0.25
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 +487 -0
- package/dist/cjs/SemanticTokenVisitor.js +218 -0
- package/dist/cjs/SymbolValidatorVisitor.js +233 -0
- package/dist/cjs/antlr/CircuitScriptLexer.js +302 -0
- package/dist/cjs/antlr/CircuitScriptParser.js +5128 -0
- package/dist/cjs/antlr/CircuitScriptVisitor.js +7 -0
- package/dist/cjs/draw_symbols.js +819 -0
- package/dist/cjs/execute.js +778 -0
- package/{src/export.ts → dist/cjs/export.js} +34 -56
- package/dist/cjs/fonts.js +4 -0
- package/dist/cjs/geometry.js +450 -0
- package/dist/cjs/globals.js +60 -0
- package/dist/cjs/helpers.js +269 -0
- package/dist/cjs/index.js +31 -0
- package/{src/layout.ts → dist/cjs/layout.js} +421 -1002
- package/dist/cjs/lexer.js +111 -0
- package/dist/cjs/logger.js +17 -0
- package/dist/cjs/main.js +82 -0
- package/dist/cjs/objects/ClassComponent.js +145 -0
- package/dist/cjs/objects/ExecutionScope.js +135 -0
- package/dist/cjs/objects/Frame.js +22 -0
- package/{src/objects/Net.ts → dist/cjs/objects/Net.js} +9 -24
- package/dist/cjs/objects/ParamDefinition.js +42 -0
- package/dist/cjs/objects/PinDefinition.js +31 -0
- package/dist/cjs/objects/PinTypes.js +11 -0
- package/dist/cjs/objects/Wire.js +9 -0
- package/dist/cjs/objects/types.js +15 -0
- package/dist/cjs/parser.js +70 -0
- package/dist/cjs/regenerate-tests.js +23 -0
- package/dist/cjs/render.js +155 -0
- package/{src/server.ts → dist/cjs/server.js} +15 -21
- package/dist/cjs/sizing.js +105 -0
- package/{src/utils.ts → dist/cjs/utils.js} +25 -35
- package/dist/cjs/validate.js +81 -0
- package/dist/cjs/visitor.js +844 -0
- package/dist/esm/BaseVisitor.mjs +488 -0
- package/dist/esm/SemanticTokenVisitor.mjs +215 -0
- package/dist/esm/SymbolValidatorVisitor.mjs +222 -0
- package/dist/esm/antlr/CircuitScriptLexer.mjs +276 -0
- package/dist/esm/antlr/CircuitScriptParser.mjs +5038 -0
- package/{build/src/antlr/CircuitScriptVisitor.js → dist/esm/antlr/CircuitScriptVisitor.mjs} +8 -3
- package/{build/src/draw_symbols.js → dist/esm/draw_symbols.mjs} +78 -33
- package/{build/src/execute.js → dist/esm/execute.mjs} +59 -60
- package/{build/src/export.js → dist/esm/export.mjs} +2 -2
- package/{build/src/geometry.js → dist/esm/geometry.mjs} +31 -15
- package/dist/esm/helpers.mjs +252 -0
- package/dist/esm/index.mjs +15 -0
- package/{build/src/layout.js → dist/esm/layout.mjs} +19 -11
- package/{build/src/lexer.js → dist/esm/lexer.mjs} +10 -10
- package/{build/src/main.js → dist/esm/main.mjs} +9 -14
- package/{build/src/objects/ClassComponent.js → dist/esm/objects/ClassComponent.mjs} +6 -3
- package/{build/src/objects/ExecutionScope.js → dist/esm/objects/ExecutionScope.mjs} +1 -0
- package/{build/src/objects/PinDefinition.js → dist/esm/objects/PinDefinition.mjs} +1 -1
- package/dist/esm/objects/types.mjs +12 -0
- package/dist/esm/parser.mjs +64 -0
- package/{build/src/regenerate-tests.js → dist/esm/regenerate-tests.mjs} +1 -1
- package/{build/src/render.js → dist/esm/render.mjs} +7 -24
- package/{build/src/sizing.js → dist/esm/sizing.mjs} +22 -8
- package/{src/main.ts → dist/esm/validate.mjs} +31 -62
- package/dist/esm/visitor.mjs +838 -0
- package/dist/types/BaseVisitor.d.ts +69 -0
- package/dist/types/SemanticTokenVisitor.d.ts +36 -0
- package/dist/types/SymbolValidatorVisitor.d.ts +61 -0
- package/{build/src → dist/types}/antlr/CircuitScriptLexer.d.ts +28 -27
- package/dist/types/antlr/CircuitScriptParser.d.ts +719 -0
- package/{build/src → dist/types}/antlr/CircuitScriptVisitor.d.ts +69 -59
- package/{build/src → dist/types}/draw_symbols.d.ts +11 -2
- package/{build/src → dist/types}/execute.d.ts +6 -9
- package/{build/src → dist/types}/geometry.d.ts +5 -1
- package/dist/types/helpers.d.ts +40 -0
- package/dist/types/index.d.ts +15 -0
- package/{build/src → dist/types}/layout.d.ts +10 -10
- package/{build/src → dist/types}/lexer.d.ts +2 -2
- package/{build/src → dist/types}/objects/ClassComponent.d.ts +2 -2
- package/{build/src → dist/types}/objects/ExecutionScope.d.ts +4 -1
- package/{build/src → dist/types}/objects/PinDefinition.d.ts +1 -1
- package/{build/src → dist/types}/objects/types.d.ts +5 -0
- package/dist/types/parser.d.ts +25 -0
- package/{build/src → dist/types}/render.d.ts +1 -1
- package/{build/src → dist/types}/sizing.d.ts +3 -1
- package/dist/types/validate.d.ts +2 -0
- package/dist/types/visitor.d.ts +80 -0
- package/libs/lib.cst +0 -2
- package/package.json +38 -15
- package/.editorconfig +0 -15
- package/.eslintignore +0 -1
- package/.eslintrc.json +0 -27
- package/.gitlab-ci.yml +0 -81
- package/.prettierignore +0 -8
- package/.prettierrc +0 -16
- package/__tests__/expectedResults.ts +0 -657
- package/__tests__/helpers.ts +0 -82
- package/__tests__/parseScripts.ts +0 -593
- package/__tests__/renderData/script1.cst +0 -58
- package/__tests__/renderData/script1.cst.svg +0 -1
- package/__tests__/renderData/script2.cst +0 -16
- package/__tests__/renderData/script2.cst.svg +0 -1
- package/__tests__/renderData/script3.cst +0 -30
- package/__tests__/renderData/script3.cst.svg +0 -1
- package/__tests__/renderData/script4.cst +0 -54
- package/__tests__/renderData/script4.cst.svg +0 -1
- package/__tests__/renderData/script5.cst +0 -23
- package/__tests__/renderData/script5.cst.svg +0 -1
- package/__tests__/renderData/script6.cst +0 -28
- package/__tests__/renderData/script6.cst.svg +0 -1
- package/__tests__/renderData/script7.cst +0 -26
- package/__tests__/renderData/script7.cst.svg +0 -1
- package/__tests__/renderData/script8.cst +0 -37
- package/__tests__/renderData/script8.cst.svg +0 -1
- package/__tests__/testCLI.ts +0 -68
- package/__tests__/testMathOps.ts +0 -36
- package/__tests__/testMergeWires.ts +0 -141
- package/__tests__/testParse.ts +0 -263
- package/__tests__/testRender.ts +0 -38
- package/build/src/antlr/CircuitScriptLexer.js +0 -287
- package/build/src/antlr/CircuitScriptParser.d.ts +0 -674
- package/build/src/antlr/CircuitScriptParser.js +0 -4841
- package/build/src/helpers.d.ts +0 -1
- package/build/src/helpers.js +0 -73
- package/build/src/objects/types.js +0 -6
- package/build/src/parser.js +0 -69
- package/build/src/visitor.d.ts +0 -133
- package/build/src/visitor.js +0 -1154
- package/documentation.md +0 -238
- package/examples/example_arduino_uno.cst +0 -1146
- package/examples/example_garden_pump.cst +0 -567
- package/examples/lib.cst +0 -185
- package/jest.config.js +0 -23
- package/refresh.html +0 -42
- package/server.cjs +0 -50
- package/src/antlr/CircuitScript.g4 +0 -209
- package/src/antlr/CircuitScriptLexer.ts +0 -317
- package/src/antlr/CircuitScriptParser.ts +0 -4979
- package/src/antlr/CircuitScriptVisitor.ts +0 -420
- package/src/draw_symbols.ts +0 -1085
- package/src/execute.ts +0 -1227
- package/src/fonts.ts +0 -1
- package/src/geometry.ts +0 -638
- package/src/globals.ts +0 -67
- package/src/helpers.ts +0 -114
- package/src/lexer.ts +0 -151
- package/src/logger.ts +0 -17
- package/src/objects/ClassComponent.ts +0 -223
- package/src/objects/ExecutionScope.ts +0 -201
- package/src/objects/Frame.ts +0 -20
- package/src/objects/ParamDefinition.ts +0 -49
- package/src/objects/PinDefinition.ts +0 -49
- package/src/objects/PinTypes.ts +0 -7
- package/src/objects/Wire.ts +0 -19
- package/src/objects/types.ts +0 -66
- package/src/parser.ts +0 -106
- package/src/regenerate-tests.ts +0 -25
- package/src/render.ts +0 -260
- package/src/sizing.ts +0 -96
- package/src/visitor.ts +0 -1691
- package/tsconfig.json +0 -27
- package/tsconfig.release.json +0 -8
- /package/{build/src/fonts.js → dist/esm/fonts.mjs} +0 -0
- /package/{build/src/globals.js → dist/esm/globals.mjs} +0 -0
- /package/{build/src/logger.js → dist/esm/logger.mjs} +0 -0
- /package/{build/src/objects/Frame.js → dist/esm/objects/Frame.mjs} +0 -0
- /package/{build/src/objects/Net.js → dist/esm/objects/Net.mjs} +0 -0
- /package/{build/src/objects/ParamDefinition.js → dist/esm/objects/ParamDefinition.mjs} +0 -0
- /package/{build/src/objects/PinTypes.js → dist/esm/objects/PinTypes.mjs} +0 -0
- /package/{build/src/objects/Wire.js → dist/esm/objects/Wire.mjs} +0 -0
- /package/{build/src/server.js → dist/esm/server.mjs} +0 -0
- /package/{build/src/utils.js → dist/esm/utils.mjs} +0 -0
- /package/{build/src → dist/types}/export.d.ts +0 -0
- /package/{build/src → dist/types}/fonts.d.ts +0 -0
- /package/{build/src → dist/types}/globals.d.ts +0 -0
- /package/{build/src → dist/types}/logger.d.ts +0 -0
- /package/{build/src → dist/types}/main.d.ts +0 -0
- /package/{build/src → dist/types}/objects/Frame.d.ts +0 -0
- /package/{build/src → dist/types}/objects/Net.d.ts +0 -0
- /package/{build/src → dist/types}/objects/ParamDefinition.d.ts +0 -0
- /package/{build/src → dist/types}/objects/PinTypes.d.ts +0 -0
- /package/{build/src → dist/types}/objects/Wire.d.ts +0 -0
- /package/{build/src → dist/types}/regenerate-tests.d.ts +0 -0
- /package/{build/src → dist/types}/server.d.ts +0 -0
- /package/{build/src → dist/types}/utils.d.ts +0 -0
|
@@ -0,0 +1,838 @@
|
|
|
1
|
+
import { isNetOnlyComponent } from './execute.mjs';
|
|
2
|
+
import { ClassComponent } from './objects/ClassComponent.mjs';
|
|
3
|
+
import { NumericValue, ParamDefinition, } from './objects/ParamDefinition.mjs';
|
|
4
|
+
import { PinDefinition, PinIdType } from './objects/PinDefinition.mjs';
|
|
5
|
+
import { PinTypes } from './objects/PinTypes.mjs';
|
|
6
|
+
import { UndeclaredReference } from './objects/types.mjs';
|
|
7
|
+
import { BlockTypes, ComponentTypes, NoNetText } from './globals.mjs';
|
|
8
|
+
import { SymbolDrawingCommands } from './draw_symbols.mjs';
|
|
9
|
+
import { BaseVisitor } from './BaseVisitor.mjs';
|
|
10
|
+
export class ParserVisitor extends BaseVisitor {
|
|
11
|
+
visitKeyword_assignment_expr = (ctx) => {
|
|
12
|
+
const id = ctx.ID().getText();
|
|
13
|
+
const ctxDataExpr = ctx.data_expr();
|
|
14
|
+
this.visit(ctxDataExpr);
|
|
15
|
+
const value = this.getResult(ctxDataExpr);
|
|
16
|
+
this.setResult(ctx, [id, value]);
|
|
17
|
+
};
|
|
18
|
+
visitPin_select_expr = (ctx) => {
|
|
19
|
+
let value = null;
|
|
20
|
+
const ctxIntegerValue = ctx.INTEGER_VALUE();
|
|
21
|
+
const ctxStringValue = ctx.STRING_VALUE();
|
|
22
|
+
if (ctxIntegerValue) {
|
|
23
|
+
value = Number(ctxIntegerValue.getText());
|
|
24
|
+
}
|
|
25
|
+
else if (ctxStringValue) {
|
|
26
|
+
value = this.prepareStringValue(ctxStringValue.getText());
|
|
27
|
+
}
|
|
28
|
+
this.setResult(ctx, value);
|
|
29
|
+
};
|
|
30
|
+
visitAdd_component_expr = (ctx) => {
|
|
31
|
+
const ctxDataWithAssignmentExpr = ctx.data_expr_with_assignment();
|
|
32
|
+
this.setParam(ctxDataWithAssignmentExpr, { clone: false });
|
|
33
|
+
this.visit(ctxDataWithAssignmentExpr);
|
|
34
|
+
const [component, pinValue] = this.getResult(ctxDataWithAssignmentExpr);
|
|
35
|
+
return this.getExecutor().addComponentExisting(component, pinValue);
|
|
36
|
+
};
|
|
37
|
+
visitAt_component_expr = (ctx) => {
|
|
38
|
+
if (ctx.Point()) {
|
|
39
|
+
this.getExecutor().atPointBlock();
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
const ctxComponentSelectExpr = ctx.component_select_expr();
|
|
43
|
+
this.visit(ctxComponentSelectExpr);
|
|
44
|
+
const [component, pin] = this.getResult(ctxComponentSelectExpr);
|
|
45
|
+
this.getExecutor().atComponent(component, pin, {
|
|
46
|
+
addSequence: true
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return this.getExecutor().getCurrentPoint();
|
|
50
|
+
};
|
|
51
|
+
visitTo_component_expr = (ctx) => {
|
|
52
|
+
if (ctx.Point()) {
|
|
53
|
+
this.getExecutor().toPointBlock();
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
ctx.component_select_expr().forEach(item => {
|
|
57
|
+
this.visit(item);
|
|
58
|
+
const [component, pin] = this.getResult(item);
|
|
59
|
+
this.getExecutor().toComponent(component, pin, {
|
|
60
|
+
addSequence: true
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return this.getExecutor().getCurrentPoint();
|
|
65
|
+
};
|
|
66
|
+
visitComponent_select_expr = (ctx) => {
|
|
67
|
+
const ctxDataExprWithAssigment = ctx.data_expr_with_assignment();
|
|
68
|
+
if (ctxDataExprWithAssigment) {
|
|
69
|
+
this.visit(ctxDataExprWithAssigment);
|
|
70
|
+
this.setResult(ctx, this.getResult(ctxDataExprWithAssigment));
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
const component = this.getExecutor().scope.currentComponent;
|
|
74
|
+
let pinId = null;
|
|
75
|
+
const ctxPinSelectExpr = ctx.pin_select_expr();
|
|
76
|
+
if (ctxPinSelectExpr) {
|
|
77
|
+
this.visit(ctxPinSelectExpr);
|
|
78
|
+
pinId = this.getResult(ctxPinSelectExpr);
|
|
79
|
+
}
|
|
80
|
+
this.setResult(ctx, [component, pinId]);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
visitPath_blocks = (ctx) => {
|
|
84
|
+
const blocks = ctx.path_block_inner();
|
|
85
|
+
let blockIndex = 0;
|
|
86
|
+
let blockType = BlockTypes.Branch;
|
|
87
|
+
let prevBlockType = null;
|
|
88
|
+
blocks.forEach((block, index) => {
|
|
89
|
+
if (block.Branch()) {
|
|
90
|
+
blockType = BlockTypes.Branch;
|
|
91
|
+
}
|
|
92
|
+
else if (block.Join()) {
|
|
93
|
+
blockType = BlockTypes.Join;
|
|
94
|
+
}
|
|
95
|
+
else if (block.Parallel()) {
|
|
96
|
+
blockType = BlockTypes.Parallel;
|
|
97
|
+
}
|
|
98
|
+
else if (block.Point()) {
|
|
99
|
+
blockType = BlockTypes.Point;
|
|
100
|
+
}
|
|
101
|
+
if (prevBlockType !== blockType) {
|
|
102
|
+
if (index > 0) {
|
|
103
|
+
this.getExecutor().exitBlocks();
|
|
104
|
+
}
|
|
105
|
+
this.getExecutor().enterBlocks(blockType);
|
|
106
|
+
blockIndex = 0;
|
|
107
|
+
}
|
|
108
|
+
this.getExecutor().enterBlock(blockIndex);
|
|
109
|
+
this.visit(block);
|
|
110
|
+
this.getExecutor().exitBlock(blockIndex);
|
|
111
|
+
blockIndex += 1;
|
|
112
|
+
prevBlockType = blockType;
|
|
113
|
+
});
|
|
114
|
+
this.getExecutor().exitBlocks();
|
|
115
|
+
return this.getExecutor().getCurrentPoint();
|
|
116
|
+
};
|
|
117
|
+
visitCreate_component_expr = (ctx) => {
|
|
118
|
+
const properties = this.getPropertyExprList(ctx.property_expr());
|
|
119
|
+
const pins = this.parseCreateComponentPins(properties.get('pins'));
|
|
120
|
+
let instanceName = this.getExecutor().getUniqueInstanceName('');
|
|
121
|
+
const propParams = properties.get('params');
|
|
122
|
+
const params = this.parseCreateComponentParams(propParams);
|
|
123
|
+
if (params.length > 0) {
|
|
124
|
+
const firstParam = params[0];
|
|
125
|
+
const paramValue = firstParam.paramValue;
|
|
126
|
+
let appendValue = paramValue.toString();
|
|
127
|
+
if (paramValue instanceof NumericValue) {
|
|
128
|
+
appendValue = paramValue.value;
|
|
129
|
+
}
|
|
130
|
+
instanceName += '_' + appendValue;
|
|
131
|
+
}
|
|
132
|
+
const arrange = properties.has('arrange') ?
|
|
133
|
+
properties.get('arrange') : null;
|
|
134
|
+
const display = properties.has('display') ?
|
|
135
|
+
properties.get('display') : null;
|
|
136
|
+
const type = properties.has('type') ?
|
|
137
|
+
properties.get('type') : null;
|
|
138
|
+
const width = properties.has('width') ?
|
|
139
|
+
properties.get('width') : null;
|
|
140
|
+
const props = {
|
|
141
|
+
arrange,
|
|
142
|
+
display,
|
|
143
|
+
type,
|
|
144
|
+
width,
|
|
145
|
+
};
|
|
146
|
+
this.setResult(ctx, this.getExecutor().createComponent(instanceName, pins, params, props));
|
|
147
|
+
};
|
|
148
|
+
visitCreate_graphic_expr = (ctx) => {
|
|
149
|
+
const commands = ctx.sub_expr().reduce((accum, item) => {
|
|
150
|
+
this.visit(item);
|
|
151
|
+
const [commandName, parameters] = this.getResult(item);
|
|
152
|
+
const keywordParams = new Map();
|
|
153
|
+
const positionParams = parameters.reduce((accum, [argType, name, value]) => {
|
|
154
|
+
if (argType === 'position') {
|
|
155
|
+
accum.push(value);
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
keywordParams.set(name, value);
|
|
159
|
+
}
|
|
160
|
+
return accum;
|
|
161
|
+
}, []);
|
|
162
|
+
accum.push([commandName, positionParams, keywordParams]);
|
|
163
|
+
return accum;
|
|
164
|
+
}, []);
|
|
165
|
+
const drawing = new SymbolDrawingCommands(commands);
|
|
166
|
+
drawing.source = ctx.getText();
|
|
167
|
+
this.setResult(ctx, drawing);
|
|
168
|
+
};
|
|
169
|
+
visitSub_expr = (ctx) => {
|
|
170
|
+
let commandName = null;
|
|
171
|
+
const command = ctx._command;
|
|
172
|
+
if (command) {
|
|
173
|
+
commandName = command.text;
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
throw "Invalid command!";
|
|
177
|
+
}
|
|
178
|
+
const ctxParameters = ctx.parameters();
|
|
179
|
+
this.visit(ctxParameters);
|
|
180
|
+
const parameters = this.getResult(ctxParameters);
|
|
181
|
+
this.setResult(ctx, [commandName, parameters]);
|
|
182
|
+
};
|
|
183
|
+
visitProperty_expr = (ctx) => {
|
|
184
|
+
const ctxPropertyKeyExpr = ctx.property_key_expr();
|
|
185
|
+
const ctxPropertyValueExpr = ctx.property_value_expr();
|
|
186
|
+
this.visit(ctxPropertyKeyExpr);
|
|
187
|
+
this.visit(ctxPropertyValueExpr);
|
|
188
|
+
const keyName = this.getResult(ctxPropertyKeyExpr);
|
|
189
|
+
const value = this.getResult(ctxPropertyValueExpr);
|
|
190
|
+
const map = new Map();
|
|
191
|
+
map.set(keyName, value);
|
|
192
|
+
this.setResult(ctx, map);
|
|
193
|
+
};
|
|
194
|
+
visitSingle_line_property = (ctx) => {
|
|
195
|
+
let value;
|
|
196
|
+
if (ctx.data_expr().length === 1) {
|
|
197
|
+
const ctxFirst = ctx.data_expr(0);
|
|
198
|
+
this.visit(ctxFirst);
|
|
199
|
+
value = this.getResult(ctxFirst);
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
value = ctx.data_expr().map(item => {
|
|
203
|
+
this.visit(item);
|
|
204
|
+
return this.getResult(item);
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
this.setResult(ctx, value);
|
|
208
|
+
};
|
|
209
|
+
visitNested_properties = (ctx) => {
|
|
210
|
+
const result = new Map();
|
|
211
|
+
ctx.property_expr().forEach((item) => {
|
|
212
|
+
this.visit(item);
|
|
213
|
+
const property = this.getResult(item);
|
|
214
|
+
for (const [key, value] of property) {
|
|
215
|
+
result.set(key, value);
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
this.setResult(ctx, result);
|
|
219
|
+
};
|
|
220
|
+
visitProperty_key_expr = (ctx) => {
|
|
221
|
+
const ctxID = ctx.ID();
|
|
222
|
+
const ctxIntegerValue = ctx.INTEGER_VALUE();
|
|
223
|
+
const ctxStringValue = ctx.STRING_VALUE();
|
|
224
|
+
let result = null;
|
|
225
|
+
if (ctxID) {
|
|
226
|
+
result = ctxID.getText();
|
|
227
|
+
}
|
|
228
|
+
else if (ctxIntegerValue) {
|
|
229
|
+
result = Number(ctxIntegerValue.getText());
|
|
230
|
+
}
|
|
231
|
+
else if (ctxStringValue) {
|
|
232
|
+
result = this.prepareStringValue(ctxStringValue.getText());
|
|
233
|
+
}
|
|
234
|
+
this.setResult(ctx, result);
|
|
235
|
+
};
|
|
236
|
+
visitData_expr_with_assignment = (ctx) => {
|
|
237
|
+
let component = null;
|
|
238
|
+
const ctxDataExpr = ctx.data_expr();
|
|
239
|
+
const ctxAssignmentExpr = ctx.assignment_expr();
|
|
240
|
+
if (ctxDataExpr) {
|
|
241
|
+
this.visit(ctxDataExpr);
|
|
242
|
+
component = this.getResult(ctxDataExpr);
|
|
243
|
+
if (component === null || component === undefined) {
|
|
244
|
+
throw "Could not find component: " + ctxDataExpr.getText();
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
else if (ctxAssignmentExpr) {
|
|
248
|
+
this.visit(ctxAssignmentExpr);
|
|
249
|
+
component = this.getResult(ctxAssignmentExpr);
|
|
250
|
+
}
|
|
251
|
+
let allowClone = true;
|
|
252
|
+
if (this.hasParam(ctx)) {
|
|
253
|
+
const { clone } = this.getParam(ctx);
|
|
254
|
+
allowClone = clone;
|
|
255
|
+
}
|
|
256
|
+
if (allowClone && component instanceof ClassComponent
|
|
257
|
+
&& isNetOnlyComponent(component)) {
|
|
258
|
+
component = this.getExecutor().cloneComponent(component);
|
|
259
|
+
}
|
|
260
|
+
if (component && component instanceof ClassComponent) {
|
|
261
|
+
const modifiers = ctx.component_modifier_expr();
|
|
262
|
+
modifiers.forEach(modifier => {
|
|
263
|
+
const modifierText = modifier.ID(0).getText();
|
|
264
|
+
const ctxValueExpr = modifier.value_expr();
|
|
265
|
+
const ctxID2 = modifier.ID(1);
|
|
266
|
+
let result = null;
|
|
267
|
+
if (ctxValueExpr) {
|
|
268
|
+
this.visit(ctxValueExpr);
|
|
269
|
+
result = this.getResult(ctxValueExpr);
|
|
270
|
+
}
|
|
271
|
+
else if (ctxID2) {
|
|
272
|
+
result = ctxID2.getText();
|
|
273
|
+
}
|
|
274
|
+
if (modifierText === 'flip') {
|
|
275
|
+
const flipValue = result;
|
|
276
|
+
if (flipValue.indexOf('x') !== -1) {
|
|
277
|
+
component.setParam('flipX', 1);
|
|
278
|
+
}
|
|
279
|
+
if (flipValue.indexOf('y') !== -1) {
|
|
280
|
+
component.setParam('flipY', 1);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
else if (modifierText === 'angle') {
|
|
284
|
+
const angleValue = Number(result);
|
|
285
|
+
component.setParam('angle', angleValue);
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
let pinValue = null;
|
|
290
|
+
const ctxPinSelectExpr = ctx.pin_select_expr();
|
|
291
|
+
if (ctxPinSelectExpr) {
|
|
292
|
+
this.visit(ctxPinSelectExpr);
|
|
293
|
+
pinValue = this.getResult(ctxPinSelectExpr);
|
|
294
|
+
}
|
|
295
|
+
else {
|
|
296
|
+
pinValue = component.getDefaultPin();
|
|
297
|
+
}
|
|
298
|
+
this.setResult(ctx, [component, pinValue]);
|
|
299
|
+
};
|
|
300
|
+
visitUnaryOperatorExpr = (ctx) => {
|
|
301
|
+
this.visit(ctx.data_expr());
|
|
302
|
+
let value = this.getResult(ctx.data_expr());
|
|
303
|
+
const unaryOp = ctx.unary_operator();
|
|
304
|
+
if (unaryOp) {
|
|
305
|
+
if (unaryOp.Not()) {
|
|
306
|
+
if (typeof value === "boolean") {
|
|
307
|
+
value = !value;
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
throw "Failed to do Not operator";
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
else if (unaryOp.Minus()) {
|
|
314
|
+
if (typeof value === 'number') {
|
|
315
|
+
value = -value;
|
|
316
|
+
}
|
|
317
|
+
else {
|
|
318
|
+
throw "Failed to do Negation operator";
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
this.setResult(ctx, value);
|
|
323
|
+
};
|
|
324
|
+
visitDataExpr = (ctx) => {
|
|
325
|
+
let value;
|
|
326
|
+
const ctxCreateComponentExpr = ctx.create_component_expr();
|
|
327
|
+
const ctxCreateGraphicExpr = ctx.create_graphic_expr();
|
|
328
|
+
if (ctxCreateComponentExpr) {
|
|
329
|
+
this.visit(ctxCreateComponentExpr);
|
|
330
|
+
value = this.getResult(ctxCreateComponentExpr);
|
|
331
|
+
}
|
|
332
|
+
else if (ctxCreateGraphicExpr) {
|
|
333
|
+
this.visit(ctxCreateGraphicExpr);
|
|
334
|
+
value = this.getResult(ctxCreateGraphicExpr);
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
throw "Invalid data expression";
|
|
338
|
+
}
|
|
339
|
+
this.setResult(ctx, value);
|
|
340
|
+
};
|
|
341
|
+
visitBinaryOperatorExpr = (ctx) => {
|
|
342
|
+
const ctx0 = ctx.data_expr(0);
|
|
343
|
+
const ctx1 = ctx.data_expr(1);
|
|
344
|
+
this.visit(ctx0);
|
|
345
|
+
this.visit(ctx1);
|
|
346
|
+
const value1 = this.getResult(ctx0);
|
|
347
|
+
const value2 = this.getResult(ctx1);
|
|
348
|
+
const binaryOperatorType = ctx.binary_operator();
|
|
349
|
+
let result = null;
|
|
350
|
+
if (binaryOperatorType.Equals()) {
|
|
351
|
+
result = value1 == value2;
|
|
352
|
+
}
|
|
353
|
+
else if (binaryOperatorType.NotEquals()) {
|
|
354
|
+
result = value1 != value2;
|
|
355
|
+
}
|
|
356
|
+
this.setResult(ctx, result);
|
|
357
|
+
};
|
|
358
|
+
visitMultiplyExpr = (ctx) => {
|
|
359
|
+
this.visit(ctx.data_expr(0));
|
|
360
|
+
this.visit(ctx.data_expr(1));
|
|
361
|
+
const value1 = this.getResult(ctx.data_expr(0));
|
|
362
|
+
const value2 = this.getResult(ctx.data_expr(1));
|
|
363
|
+
let result = null;
|
|
364
|
+
if (ctx.Multiply()) {
|
|
365
|
+
result = value1 * value2;
|
|
366
|
+
}
|
|
367
|
+
else if (ctx.Divide()) {
|
|
368
|
+
result = value1 / value2;
|
|
369
|
+
}
|
|
370
|
+
this.setResult(ctx, result);
|
|
371
|
+
};
|
|
372
|
+
visitAdditionExpr = (ctx) => {
|
|
373
|
+
this.visit(ctx.data_expr(0));
|
|
374
|
+
this.visit(ctx.data_expr(1));
|
|
375
|
+
const value1 = this.getResult(ctx.data_expr(0));
|
|
376
|
+
const value2 = this.getResult(ctx.data_expr(1));
|
|
377
|
+
let result = null;
|
|
378
|
+
if (ctx.Addition()) {
|
|
379
|
+
result = value1 + value2;
|
|
380
|
+
}
|
|
381
|
+
else if (ctx.Minus()) {
|
|
382
|
+
result = value1 - value2;
|
|
383
|
+
}
|
|
384
|
+
this.setResult(ctx, result);
|
|
385
|
+
};
|
|
386
|
+
visitFunction_def_expr = (ctx) => {
|
|
387
|
+
const functionName = ctx.ID().getText();
|
|
388
|
+
let funcDefinedParameters = [];
|
|
389
|
+
const ctxFunctionArgsExpr = ctx.function_args_expr();
|
|
390
|
+
if (ctxFunctionArgsExpr) {
|
|
391
|
+
this.visit(ctxFunctionArgsExpr);
|
|
392
|
+
funcDefinedParameters = this.getResult(ctxFunctionArgsExpr);
|
|
393
|
+
}
|
|
394
|
+
const executionStack = this.executionStack;
|
|
395
|
+
const functionCounter = { counter: 0 };
|
|
396
|
+
const resolveNet = this.createNetResolver(this.executionStack);
|
|
397
|
+
const __runFunc = (passedInParameters, options) => {
|
|
398
|
+
const executionContextName = functionName + '_' + functionCounter['counter'];
|
|
399
|
+
const newExecutor = this.enterNewChildContext(executionStack, this.getExecutor(), executionContextName, options, funcDefinedParameters, passedInParameters);
|
|
400
|
+
functionCounter['counter'] += 1;
|
|
401
|
+
newExecutor.resolveNet = resolveNet;
|
|
402
|
+
const returnValue = this.runExpressions(newExecutor, ctx.function_expr());
|
|
403
|
+
const lastExecution = executionStack.pop();
|
|
404
|
+
const nextLastExecution = executionStack[executionStack.length - 1];
|
|
405
|
+
nextLastExecution.mergeScope(lastExecution.scope, executionContextName);
|
|
406
|
+
return [lastExecution, returnValue];
|
|
407
|
+
};
|
|
408
|
+
this.getExecutor().createFunction(functionName, __runFunc);
|
|
409
|
+
};
|
|
410
|
+
visitPin_select_expr2 = (ctx) => {
|
|
411
|
+
const ctxStringValue = ctx.STRING_VALUE();
|
|
412
|
+
const ctxIntegerValue = ctx.INTEGER_VALUE();
|
|
413
|
+
let result = null;
|
|
414
|
+
if (ctxStringValue) {
|
|
415
|
+
result = this.prepareStringValue(ctxStringValue.getText());
|
|
416
|
+
}
|
|
417
|
+
else if (ctxIntegerValue) {
|
|
418
|
+
result = Number(ctxIntegerValue.getText());
|
|
419
|
+
}
|
|
420
|
+
this.setResult(ctx, result);
|
|
421
|
+
};
|
|
422
|
+
visitAt_block_pin_expr = (ctx) => {
|
|
423
|
+
const ctxPinSelectExpr2 = ctx.pin_select_expr2();
|
|
424
|
+
this.visit(ctxPinSelectExpr2);
|
|
425
|
+
const atPin = this.getResult(ctxPinSelectExpr2);
|
|
426
|
+
const executor = this.getExecutor();
|
|
427
|
+
const currentComponent = executor.scope.currentComponent;
|
|
428
|
+
const currentPin = executor.scope.currentPin;
|
|
429
|
+
executor.atComponent(currentComponent, atPin, {
|
|
430
|
+
addSequence: true
|
|
431
|
+
});
|
|
432
|
+
executor.log('at block pin expressions');
|
|
433
|
+
const ctxAtBlockSimple = ctx.at_block_pin_expression_simple();
|
|
434
|
+
const ctxAtBlockComplex = ctx.at_block_pin_expression_complex();
|
|
435
|
+
if (ctxAtBlockSimple) {
|
|
436
|
+
this.visit(ctxAtBlockSimple);
|
|
437
|
+
}
|
|
438
|
+
else if (ctxAtBlockComplex) {
|
|
439
|
+
this.visit(ctxAtBlockComplex);
|
|
440
|
+
}
|
|
441
|
+
executor.log('end at block pin expressions');
|
|
442
|
+
executor.atComponent(currentComponent, currentPin);
|
|
443
|
+
};
|
|
444
|
+
visitAt_block = (ctx) => {
|
|
445
|
+
const executor = this.getExecutor();
|
|
446
|
+
executor.log('entering at block');
|
|
447
|
+
this.visit(ctx.at_component_expr());
|
|
448
|
+
const currentComponent = executor.scope.currentComponent;
|
|
449
|
+
const currentPin = executor.scope.currentPin;
|
|
450
|
+
executor.scope.indentLevel += 1;
|
|
451
|
+
ctx.at_block_expressions().forEach(expression => {
|
|
452
|
+
this.visit(expression);
|
|
453
|
+
});
|
|
454
|
+
executor.scope.indentLevel -= 1;
|
|
455
|
+
executor.scope.currentComponent = currentComponent;
|
|
456
|
+
executor.scope.currentPin = currentPin;
|
|
457
|
+
executor.log('leaving at block');
|
|
458
|
+
};
|
|
459
|
+
visitAt_block_pin_expression_simple = (ctx) => {
|
|
460
|
+
const ctxExpression = ctx.expression();
|
|
461
|
+
if (ctxExpression) {
|
|
462
|
+
this.visit(ctxExpression);
|
|
463
|
+
}
|
|
464
|
+
else if (ctx.NOT_CONNECTED()) {
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
};
|
|
468
|
+
visitAt_block_pin_expression_complex = (ctx) => {
|
|
469
|
+
ctx.expression().forEach(item => {
|
|
470
|
+
this.visit(item);
|
|
471
|
+
});
|
|
472
|
+
};
|
|
473
|
+
visitWire_expr_direction_only = (ctx) => {
|
|
474
|
+
const value = ctx.ID().getText();
|
|
475
|
+
if (value === 'auto' || value === 'auto_') {
|
|
476
|
+
this.setResult(ctx, [value]);
|
|
477
|
+
}
|
|
478
|
+
else {
|
|
479
|
+
throw 'Invalid direction for wire';
|
|
480
|
+
}
|
|
481
|
+
};
|
|
482
|
+
visitWire_expr_direction_value = (ctx) => {
|
|
483
|
+
const direction = ctx.ID().getText();
|
|
484
|
+
if (this.acceptedDirections.indexOf(direction) !== -1) {
|
|
485
|
+
let useValue = null;
|
|
486
|
+
const ctxIntegerValue = ctx.INTEGER_VALUE();
|
|
487
|
+
const ctxDataExpr = ctx.data_expr();
|
|
488
|
+
if (ctxIntegerValue) {
|
|
489
|
+
useValue = Number(ctxIntegerValue);
|
|
490
|
+
}
|
|
491
|
+
else if (ctxDataExpr) {
|
|
492
|
+
this.visit(ctxDataExpr);
|
|
493
|
+
useValue = this.getResult(ctxDataExpr);
|
|
494
|
+
}
|
|
495
|
+
if (useValue !== null) {
|
|
496
|
+
this.setResult(ctx, [direction, useValue]);
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
throw "Invalid direction or value for wire";
|
|
501
|
+
};
|
|
502
|
+
visitWire_expr = (ctx) => {
|
|
503
|
+
const wireAtomExpr = ctx.wire_atom_expr();
|
|
504
|
+
const segments = wireAtomExpr.map(wireSegment => {
|
|
505
|
+
this.visit(wireSegment);
|
|
506
|
+
return this.getResult(wireSegment);
|
|
507
|
+
});
|
|
508
|
+
this.getExecutor().addWire(segments);
|
|
509
|
+
};
|
|
510
|
+
visitPoint_expr = (ctx) => {
|
|
511
|
+
const ID = ctx.ID();
|
|
512
|
+
return this.getExecutor().addPoint(ID.getText());
|
|
513
|
+
};
|
|
514
|
+
visitProperty_set_expr = (ctx) => {
|
|
515
|
+
const ctxDataExpr = ctx.data_expr();
|
|
516
|
+
this.visit(ctxDataExpr);
|
|
517
|
+
const result = this.getResult(ctxDataExpr);
|
|
518
|
+
const ctxAtomExpr = ctx.atom_expr();
|
|
519
|
+
this.visit(ctxAtomExpr);
|
|
520
|
+
const resolvedProperty = this.getResult(ctxAtomExpr);
|
|
521
|
+
this.getExecutor().setProperty(resolvedProperty, result);
|
|
522
|
+
};
|
|
523
|
+
visitDouble_dot_property_set_expr = (ctx) => {
|
|
524
|
+
const ctxDataExpr = ctx.data_expr();
|
|
525
|
+
this.visit(ctxDataExpr);
|
|
526
|
+
const result = this.getResult(ctxDataExpr);
|
|
527
|
+
const propertyName = ctx.ID().getText();
|
|
528
|
+
this.getExecutor().setProperty('..' + propertyName, result);
|
|
529
|
+
};
|
|
530
|
+
visitFrame_expr = (ctx) => {
|
|
531
|
+
const frameId = this.getExecutor().enterFrame();
|
|
532
|
+
this.runExpressions(this.getExecutor(), ctx.expression());
|
|
533
|
+
this.getExecutor().exitFrame(frameId);
|
|
534
|
+
};
|
|
535
|
+
visitNet_namespace_expr = (ctx) => {
|
|
536
|
+
let dataValue = null;
|
|
537
|
+
let netNamespace = null;
|
|
538
|
+
const hasPlus = ctx.Addition();
|
|
539
|
+
const ctxDataExpr = ctx.data_expr();
|
|
540
|
+
if (ctxDataExpr) {
|
|
541
|
+
this.visit(ctxDataExpr);
|
|
542
|
+
dataValue = this.getResult(ctxDataExpr);
|
|
543
|
+
if (dataValue instanceof UndeclaredReference) {
|
|
544
|
+
netNamespace = "/" + dataValue.reference.name;
|
|
545
|
+
}
|
|
546
|
+
else if (typeof dataValue === "string") {
|
|
547
|
+
netNamespace = "/" + dataValue;
|
|
548
|
+
}
|
|
549
|
+
else {
|
|
550
|
+
throw "Failed to resolve net namespace value";
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
else {
|
|
554
|
+
netNamespace = "/";
|
|
555
|
+
}
|
|
556
|
+
this.setResult(ctx, (hasPlus ? "+" : "") + netNamespace);
|
|
557
|
+
};
|
|
558
|
+
pinTypes = [
|
|
559
|
+
PinTypes.Any,
|
|
560
|
+
PinTypes.IO,
|
|
561
|
+
PinTypes.Input,
|
|
562
|
+
PinTypes.Output,
|
|
563
|
+
PinTypes.Power,
|
|
564
|
+
];
|
|
565
|
+
parseCreateComponentPins(pinData) {
|
|
566
|
+
const pins = [];
|
|
567
|
+
if (typeof pinData === 'number') {
|
|
568
|
+
const lastPin = pinData;
|
|
569
|
+
for (let i = 0; i < lastPin; i++) {
|
|
570
|
+
const pinId = i + 1;
|
|
571
|
+
pins.push(new PinDefinition(pinId, PinIdType.Int, pinId.toString()));
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
else if (pinData instanceof Map) {
|
|
575
|
+
for (const [pinId, pinDef] of pinData) {
|
|
576
|
+
let pinIdType = PinIdType.Int;
|
|
577
|
+
let pinType = PinTypes.Any;
|
|
578
|
+
let pinName = null;
|
|
579
|
+
let altPinNames = [];
|
|
580
|
+
if (typeof pinId === 'string') {
|
|
581
|
+
pinIdType = PinIdType.Str;
|
|
582
|
+
}
|
|
583
|
+
if (Array.isArray(pinDef)) {
|
|
584
|
+
const firstValue = pinDef[0];
|
|
585
|
+
if (this.pinTypes.indexOf(firstValue) !== -1) {
|
|
586
|
+
pinType = firstValue;
|
|
587
|
+
pinName = pinDef[1];
|
|
588
|
+
if (pinDef.length > 2) {
|
|
589
|
+
altPinNames = pinDef.slice(2);
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
else {
|
|
593
|
+
pinName = pinDef[0];
|
|
594
|
+
if (pinDef.length > 1) {
|
|
595
|
+
altPinNames = pinDef.slice(1);
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
else {
|
|
600
|
+
pinName = pinDef;
|
|
601
|
+
}
|
|
602
|
+
pins.push(new PinDefinition(pinId, pinIdType, pinName, pinType, altPinNames));
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
return pins;
|
|
606
|
+
}
|
|
607
|
+
parseCreateComponentParams(params) {
|
|
608
|
+
const result = [];
|
|
609
|
+
if (params) {
|
|
610
|
+
for (const [key, value] of params) {
|
|
611
|
+
result.push(new ParamDefinition(key, value));
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
return result;
|
|
615
|
+
}
|
|
616
|
+
printNets() {
|
|
617
|
+
this.getExecutor().scope.printNets();
|
|
618
|
+
}
|
|
619
|
+
dumpNets() {
|
|
620
|
+
return this.getExecutor().scope.dumpNets();
|
|
621
|
+
}
|
|
622
|
+
dumpUniqueNets() {
|
|
623
|
+
const nets = this.getExecutor().scope.getNets();
|
|
624
|
+
return nets.reduce((accum, [, , net]) => {
|
|
625
|
+
accum.push(net);
|
|
626
|
+
return accum;
|
|
627
|
+
}, []);
|
|
628
|
+
}
|
|
629
|
+
dumpVariables() {
|
|
630
|
+
return this.getExecutor().scope.variables;
|
|
631
|
+
}
|
|
632
|
+
dumpInstances() {
|
|
633
|
+
return this.getExecutor().scope.instances;
|
|
634
|
+
}
|
|
635
|
+
dump2() {
|
|
636
|
+
const instances = this.getExecutor().scope.instances;
|
|
637
|
+
const items = [];
|
|
638
|
+
for (const [instanceName, instance] of instances) {
|
|
639
|
+
if (instance.assignedRefDes === null) {
|
|
640
|
+
continue;
|
|
641
|
+
}
|
|
642
|
+
const pinNets = this.resolveNets(this.getExecutor().scope, instance);
|
|
643
|
+
const componentItem = {
|
|
644
|
+
name: instanceName,
|
|
645
|
+
refdes: instance.assignedRefDes,
|
|
646
|
+
pins: {},
|
|
647
|
+
};
|
|
648
|
+
pinNets.forEach((item) => {
|
|
649
|
+
componentItem.pins[item.pin.id] = item.netName;
|
|
650
|
+
});
|
|
651
|
+
items.push(componentItem);
|
|
652
|
+
}
|
|
653
|
+
return items;
|
|
654
|
+
}
|
|
655
|
+
getNetList() {
|
|
656
|
+
const netlist = [];
|
|
657
|
+
const instances = this.getExecutor().scope.instances;
|
|
658
|
+
for (const [instanceName, instance] of instances) {
|
|
659
|
+
const pinNets = this.resolveNets(this.getExecutor().scope, instance);
|
|
660
|
+
const componentItem = {
|
|
661
|
+
instanceName,
|
|
662
|
+
instance,
|
|
663
|
+
pins: {},
|
|
664
|
+
};
|
|
665
|
+
pinNets.forEach((item) => {
|
|
666
|
+
componentItem.pins[item.pin.id] = {
|
|
667
|
+
netName: item.netName,
|
|
668
|
+
netBaseName: item.netBaseName
|
|
669
|
+
};
|
|
670
|
+
});
|
|
671
|
+
netlist.push(componentItem);
|
|
672
|
+
}
|
|
673
|
+
return netlist;
|
|
674
|
+
}
|
|
675
|
+
getGraph() {
|
|
676
|
+
const executor = this.getExecutor();
|
|
677
|
+
const fullSequence = executor.scope.sequence;
|
|
678
|
+
const tmpNet = executor.scope.getNet(executor.scope.componentRoot, 1);
|
|
679
|
+
const sequence = (tmpNet === null)
|
|
680
|
+
? fullSequence.slice(1) : fullSequence;
|
|
681
|
+
const nets = executor.scope.getNets();
|
|
682
|
+
return {
|
|
683
|
+
sequence,
|
|
684
|
+
nets,
|
|
685
|
+
components: Array.from(executor.scope.instances.values())
|
|
686
|
+
};
|
|
687
|
+
}
|
|
688
|
+
annotateComponents() {
|
|
689
|
+
this.log('===== annotate components =====');
|
|
690
|
+
const annotater = new ComponentAnnotater();
|
|
691
|
+
const instances = this.getExecutor().scope.instances;
|
|
692
|
+
const toAnnotate = [];
|
|
693
|
+
for (const [, instance] of instances) {
|
|
694
|
+
if (instance.assignedRefDes === null) {
|
|
695
|
+
if (instance.typeProp === ComponentTypes.label ||
|
|
696
|
+
instance.typeProp === ComponentTypes.net ||
|
|
697
|
+
instance.typeProp === ComponentTypes.point) {
|
|
698
|
+
continue;
|
|
699
|
+
}
|
|
700
|
+
if (instance.typeProp === null) {
|
|
701
|
+
this.log('Instance has no type:', instance.instanceName, ' assuming connector');
|
|
702
|
+
instance.typeProp = 'conn';
|
|
703
|
+
}
|
|
704
|
+
if (instance.parameters.has('refdes')) {
|
|
705
|
+
const refdes = instance.parameters.get('refdes');
|
|
706
|
+
if (refdes) {
|
|
707
|
+
instance.assignedRefDes = refdes;
|
|
708
|
+
annotater.trackRefDes(refdes);
|
|
709
|
+
this.log(refdes, '-', instance.instanceName);
|
|
710
|
+
continue;
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
toAnnotate.push(instance);
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
toAnnotate.forEach(instance => {
|
|
717
|
+
const newRefDes = annotater.getAnnotation(instance.typeProp);
|
|
718
|
+
if (newRefDes !== null) {
|
|
719
|
+
instance.assignedRefDes = newRefDes;
|
|
720
|
+
this.log(newRefDes, '-', instance.instanceName);
|
|
721
|
+
}
|
|
722
|
+
else {
|
|
723
|
+
this.log('Failed to annotate:', instance.instanceName);
|
|
724
|
+
}
|
|
725
|
+
});
|
|
726
|
+
this.log('===== annotate done =====');
|
|
727
|
+
this.log('');
|
|
728
|
+
}
|
|
729
|
+
resolveNets(scope, instance) {
|
|
730
|
+
const result = [];
|
|
731
|
+
for (const [pinId, pin] of instance.pins) {
|
|
732
|
+
let netName = NoNetText;
|
|
733
|
+
let netBaseName = NoNetText;
|
|
734
|
+
if (scope.hasNet(instance, pinId)) {
|
|
735
|
+
const netObject = scope.getNet(instance, pinId);
|
|
736
|
+
netName = netObject.namespace + netObject.name;
|
|
737
|
+
netBaseName = netObject.baseName;
|
|
738
|
+
}
|
|
739
|
+
result.push({
|
|
740
|
+
pin: pin,
|
|
741
|
+
netName: netName,
|
|
742
|
+
netBaseName,
|
|
743
|
+
});
|
|
744
|
+
}
|
|
745
|
+
return result;
|
|
746
|
+
}
|
|
747
|
+
setComponentOrientation(component, pin, orientation) {
|
|
748
|
+
if (this.acceptedDirections.indexOf(orientation) !== -1) {
|
|
749
|
+
component.setParam('_addDirection', orientation);
|
|
750
|
+
component.setParam('_addPin', pin);
|
|
751
|
+
}
|
|
752
|
+
else {
|
|
753
|
+
throw "Invalid modifier for orientation";
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
setComponentFlip(component, flipValue) {
|
|
757
|
+
if (this.acceptedFlip.indexOf(flipValue) !== -1) {
|
|
758
|
+
component.setParam(flipValue, 1);
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
getPropertyExprList(items) {
|
|
762
|
+
const properties = new Map();
|
|
763
|
+
items.forEach((item) => {
|
|
764
|
+
this.visit(item);
|
|
765
|
+
const result = this.getResult(item);
|
|
766
|
+
for (const [key, value] of result) {
|
|
767
|
+
properties.set(key, value);
|
|
768
|
+
}
|
|
769
|
+
});
|
|
770
|
+
return properties;
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
const ComponentRefDesPrefixes = {
|
|
774
|
+
'res': 'R',
|
|
775
|
+
'cap': 'C',
|
|
776
|
+
'ind': 'L',
|
|
777
|
+
'diode': 'D',
|
|
778
|
+
'conn': 'J',
|
|
779
|
+
'transistor': 'Q',
|
|
780
|
+
'relay': 'K',
|
|
781
|
+
'ic': 'U',
|
|
782
|
+
'?': '?',
|
|
783
|
+
};
|
|
784
|
+
class ComponentAnnotater {
|
|
785
|
+
counter = {};
|
|
786
|
+
existingRefDes = [];
|
|
787
|
+
constructor() {
|
|
788
|
+
for (const key in ComponentRefDesPrefixes) {
|
|
789
|
+
this.counter[key] = 1;
|
|
790
|
+
}
|
|
791
|
+
this.counter['?'] = 1;
|
|
792
|
+
}
|
|
793
|
+
getAnnotation(type) {
|
|
794
|
+
if (this.counter[type] === undefined && type.length <= 2) {
|
|
795
|
+
for (const [, value] of Object.entries(ComponentRefDesPrefixes)) {
|
|
796
|
+
if (value === type) {
|
|
797
|
+
throw "Refdes prefix is already in use!";
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
if (ComponentRefDesPrefixes[type] === undefined) {
|
|
801
|
+
ComponentRefDesPrefixes[type] = type;
|
|
802
|
+
this.counter[type] = 1;
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
let attempts = 100;
|
|
806
|
+
let proposedName;
|
|
807
|
+
while (attempts >= 0) {
|
|
808
|
+
proposedName = ComponentRefDesPrefixes[type] + this.counter[type];
|
|
809
|
+
this.counter[type]++;
|
|
810
|
+
if (this.existingRefDes.indexOf(proposedName) === -1) {
|
|
811
|
+
break;
|
|
812
|
+
}
|
|
813
|
+
attempts--;
|
|
814
|
+
}
|
|
815
|
+
if (attempts === 0) {
|
|
816
|
+
throw "Annotation failed!";
|
|
817
|
+
}
|
|
818
|
+
return proposedName;
|
|
819
|
+
}
|
|
820
|
+
trackRefDes(name) {
|
|
821
|
+
this.existingRefDes.push(name);
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
export class VisitorExecutionException {
|
|
825
|
+
errorMessage;
|
|
826
|
+
context;
|
|
827
|
+
constructor(context, errorMessage) {
|
|
828
|
+
this.errorMessage = errorMessage;
|
|
829
|
+
this.context = context;
|
|
830
|
+
}
|
|
831
|
+
print(scriptData) {
|
|
832
|
+
const startPoint = this.context.start.start;
|
|
833
|
+
const endPoint = this.context.stop.stop + 1;
|
|
834
|
+
console.log('Error at line ' +
|
|
835
|
+
this.context.start.line + "," + this.context.start.column + ": "
|
|
836
|
+
+ scriptData.slice(startPoint, endPoint) + " - " + this.errorMessage);
|
|
837
|
+
}
|
|
838
|
+
}
|