Skip to content

Commit 8996af8

Browse files
committed
Support for C spec definitions
Signed-off-by: worksofliam <[email protected]>
1 parent 006ea8f commit 8996af8

File tree

5 files changed

+59
-8
lines changed

5 files changed

+59
-8
lines changed

language/models/cache.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,7 @@ export default class Cache {
9999
return (lines.length >= 1 ? lines[0] : 0);
100100
}
101101

102-
/**
103-
*
104-
* @param {string} name
105-
* @returns {Declaration}
106-
*/
107-
find(name) {
102+
find(name: string, includeProcedure?: string): Declaration|undefined {
108103
name = name.toUpperCase();
109104

110105
const fileStructs = this.files.flatMap(file => file.subItems);
@@ -127,6 +122,14 @@ export default class Cache {
127122
if (found) return found;
128123
}
129124

125+
if (includeProcedure) {
126+
const procedureScope = this.procedures.find(proc => proc.name.toUpperCase() === includeProcedure);
127+
if (procedureScope) {
128+
const found = procedureScope.scope.find(name);
129+
if (found) return found;
130+
}
131+
}
132+
130133
if (allStructs.length > 0) {
131134
for (const def of allStructs) {
132135
if (def.keyword[`QUALIFIED`] !== true) {
@@ -136,7 +139,7 @@ export default class Cache {
136139
}
137140
}
138141

139-
return null;
142+
return;
140143
}
141144

142145
findDefinition(lineNumber, word) {

language/models/fixed.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ export function parseCLine(lineNumber, lineIndex, content) {
6060
const extended = content.substr(35);
6161
const result = content.substr(49, 14);
6262

63+
const fieldLength = content.substr(63, 5);
64+
const fieldDecimals = content.substr(68, 2);
65+
6366
const ind1 = content.substr(70, 2);
6467
const ind2 = content.substr(72, 2);
6568
const ind3 = content.substr(74, 2);
@@ -71,6 +74,10 @@ export function parseCLine(lineNumber, lineIndex, content) {
7174
factor2: calculateToken(lineNumber, lineIndex+35, factor2),
7275
result: calculateToken(lineNumber, lineIndex+49, result),
7376
extended: calculateToken(lineNumber, lineIndex+35, extended),
77+
78+
fieldLength: calculateToken(lineNumber, lineIndex+63, fieldLength),
79+
fieldDecimals: calculateToken(lineNumber, lineIndex+68, fieldDecimals),
80+
7481
ind1: calculateToken(lineNumber, lineIndex+70, ind1, `special-ind`),
7582
ind2: calculateToken(lineNumber, lineIndex+72, ind2, `special-ind`),
7683
ind3: calculateToken(lineNumber, lineIndex+74, ind3, `special-ind`)

language/parser.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,6 +1300,31 @@ export default class Parser {
13001300
...fromToken(cSpec.factor2),
13011301
...fromToken(cSpec.result),
13021302
);
1303+
1304+
if (cSpec.result && cSpec.fieldLength) {
1305+
// This means we need to dynamically define this field
1306+
const fieldName = cSpec.result.value;
1307+
// Don't redefine this field.
1308+
if (!scopes[0].find(fieldName, currentProcName)) {
1309+
const fieldLength = parseInt(cSpec.fieldLength.value);
1310+
const decimals = cSpec.fieldDecimals ? parseInt(cSpec.fieldDecimals.value) : undefined;
1311+
const type = decimals !== undefined ? `PACKED`: `CHAR`;
1312+
1313+
currentItem = new Declaration(`variable`);
1314+
currentItem.name = fieldName;
1315+
currentItem.keyword = {[type]: `${fieldLength}${decimals !== undefined ? `:${decimals}` : ``}`};
1316+
currentItem.position = {
1317+
path: fileUri,
1318+
line: lineNumber
1319+
};
1320+
currentItem.range = {
1321+
start: lineNumber,
1322+
end: lineNumber
1323+
};
1324+
1325+
scope.variables.push(currentItem);
1326+
}
1327+
}
13031328
}
13041329

13051330
potentialName = cSpec.factor1 ? cSpec.factor1.value : ``;

tests/suite/fixed.test.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,16 @@ test('plist_test', async () => {
11441144

11451145
const cache = await parser.getDocs(uri, lines, { ignoreCache: true, withIncludes: true });
11461146

1147-
expect(cache.variables.length).to.equal(0);
1147+
expect(cache.variables.length).toBe(11);
1148+
1149+
const atPGMID = cache.find(`@PGMID`);
1150+
expect(atPGMID.keyword[`CHAR`]).toBe(`10`);
1151+
1152+
const atSON = cache.find(`@SQN`);
1153+
expect(atSON.keyword[`PACKED`]).toBe(`2:0`);
1154+
1155+
const atPVSELECTION = cache.find(`@PVSELECTION`);
1156+
expect(atPVSELECTION.keyword[`CHAR`]).toBe(`256`);
11481157
});
11491158

11501159
test(`range test 2`, async () => {

tests/suite/references.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,9 @@ test('references_15_fixed_4', async () => {
895895
const r_transf = cache.find(`r_transf`);
896896
expect(r_transf.references.length).toBe(3);
897897
expect(r_transf.references.every(ref => lines.substring(ref.offset.position, ref.offset.end) === `r_transf`)).toBe(true);
898+
899+
const r_long_lue = cache.find(`r_long_lue`);
900+
expect(r_long_lue.references.length).toBe(1);
898901
});
899902

900903
test('references_16_fixed_5', async () => {
@@ -1117,6 +1120,10 @@ test('references_16_fixed_5', async () => {
11171120
const mntJtot = cache.find(`mntJtot`);
11181121
expect(mntJtot.references.length).toBe(2);
11191122
expect(mntJtot.references.every(ref => lines.substring(ref.offset.position, ref.offset.end) === `mntJtot`)).toBe(true);
1123+
1124+
const syde = cache.find(`syde`);
1125+
expect(syde.references.length).toBe(2);
1126+
expect(syde.references.every(ref => lines.substring(ref.offset.position, ref.offset.end) === `syde`)).toBe(true);
11201127
});
11211128

11221129
test('references_17_fixed_6', async () => {

0 commit comments

Comments
 (0)