Skip to content

Commit 1ba0627

Browse files
authored
Merge pull request #369 from codefori/fix/subroutine_with_vars
Fix handling of fixed-format variables in subroutines
2 parents e7aa6dc + 57406e7 commit 1ba0627

File tree

2 files changed

+88
-7
lines changed

2 files changed

+88
-7
lines changed

language/parser.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,19 +1375,19 @@ export default class Parser {
13751375
const decimals = cSpec.fieldDecimals ? parseInt(cSpec.fieldDecimals.value) : undefined;
13761376
const type = decimals !== undefined ? `PACKED`: `CHAR`;
13771377

1378-
currentItem = new Declaration(`variable`);
1379-
currentItem.name = fieldName;
1380-
currentItem.keyword = {[type]: `${fieldLength}${decimals !== undefined ? `:${decimals}` : ``}`};
1381-
currentItem.position = {
1378+
currentSub = new Declaration(`variable`);
1379+
currentSub.name = fieldName;
1380+
currentSub.keyword = {[type]: `${fieldLength}${decimals !== undefined ? `:${decimals}` : ``}`};
1381+
currentSub.position = {
13821382
path: fileUri,
13831383
range: cSpec.result.range
13841384
};
1385-
currentItem.range = {
1385+
currentSub.range = {
13861386
start: lineNumber,
13871387
end: lineNumber
13881388
};
13891389

1390-
scope.variables.push(currentItem);
1390+
scope.variables.push(currentSub);
13911391
}
13921392
}
13931393
}

tests/suite/fixed.test.ts

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1220,4 +1220,85 @@ test(`test document build up`, async () => {
12201220
document += c;
12211221
await parser.getDocs(uri, document, { ignoreCache: true, withIncludes: true, collectReferences: true });
12221222
}
1223-
})
1223+
});
1224+
1225+
test('subroutine with C spec definitions', async () => {
1226+
const lines = [
1227+
`0005 D NY S 3 0 DIM(12) CTDATA PERRCD(12) ASCEND NORMAL YEARS`,
1228+
`0006 D LY S 3 0 DIM(12) CTDATA PERRCD(12) ASCEND LEAP YEARS`,
1229+
` C* parameters to program`,
1230+
` C *ENTRY PLIST`,
1231+
` C PARM PDATE 6 0 input`,
1232+
` C PARM PJDATE 6 0 output`,
1233+
``,
1234+
`0033 C MOVE PDATE DATE 6 0`,
1235+
`0034 C EXSR SRCJUL`,
1236+
`0035 C MOVE JDATE6 PJDATE `,
1237+
`0036 C MOVE '1' *INLR`,
1238+
`0041 C****************************************************************`,
1239+
`0042 C* *`,
1240+
`0043 C* Routine to calculate a Julian Date from a \`MMDDYY\` date *`,
1241+
`0044 C* *`,
1242+
` C* JULIAN DATE FORMAT: *`,
1243+
` C* POS 1 - century 1 = 1900s, 2 = 2000s *`,
1244+
` C* POS 2-3 - two digit year *`,
1245+
`0045 C* POS 4-6 - number of days in the current year *`,
1246+
`0044 C* *`,
1247+
`0046 C* Uses compile time arrays 'LY' abd 'NY' for days of the *`,
1248+
`0047 C* year before the indexed month for leap years vs normal yrs *`,
1249+
`0048 C* *`,
1250+
`0049 C* DATE TO BE CALCULATED FROM MUST BE PASSED TO THIS *`,
1251+
`0050 C* ROUTINE VIA A 6 BYTE FIELD NAMED 'DATE' WITH FORMAT 'MMDDYR'*`,
1252+
`0051 C* THIS ROUTINE WILL RETURN A 6 BYTE FIELD NAMED 'JDATE' *`,
1253+
`0052 C* *`,
1254+
`0053 C* OTHER FIELDS USED BY THIS ROUTINE ARE. *`,
1255+
`0054 C* - DAY1 - DAYS1 - MODAY - MO1 - YEAR1 - X - *`,
1256+
`0055 C* *`,
1257+
`0056 C* INDICATORS USED BY THIS ROUTINE ARE. *`,
1258+
`0057 C* - 80 - *`,
1259+
`0058 C* *`,
1260+
`0059 C SRCJUL BEGSR *`,
1261+
`0060 C MOVEL DATE MODAY 4 0 *`,
1262+
`0061 C MOVE DATE YEAR1 2 0 *`,
1263+
`0062 C MOVEL MODAY MO1 2 0 *`,
1264+
`0063 C MOVE MODAY DAY1 2 0 *`,
1265+
`0064 C YEAR1 DIV 4 X 2 0 *`,
1266+
`0065 C MVR X 80 LEAP YEAR*`,
1267+
`0066 C 80LY(MO1) ADD DAY1 DAYS1 5 0 *`,
1268+
`0067 C N80NY(MO1) ADD DAY1 DAYS1 *`,
1269+
`0068 C MOVE DAYS1 JDATE 5 0 *`,
1270+
`0069 C MOVEL YEAR1 JDATE *`,
1271+
` C EXSR SRCEN`,
1272+
`0068 C MOVE DAYS1 JDATE6 6 0 *`,
1273+
`0069 C MOVEL YEAR3 JDATE6 *`,
1274+
`0070 C ENDSR *`,
1275+
`0071 C* *`,
1276+
`0072 C****************************************************************`,
1277+
` C*-------------------------------------------------------------------`,
1278+
`GDG C*-- CALCULATE CENTURY FROM FIELD YEAR1 ---`,
1279+
`0059 C SRCen BEGSR *`,
1280+
`GDG C YEAR1 COMP 40 8383 *`,
1281+
`GDG C 83 MOVE 2 YRCEN 1 0 *`,
1282+
`GDG C 83 MOVE 20 YRSTR 2 0 *`,
1283+
`GDG C N83 MOVE 1 YRCEN 1 0 *`,
1284+
`GDG C N83 MOVE 19 YRSTR 2 0 *`,
1285+
`GDG C MOVE YEAR1 YEAR3 3 0`,
1286+
`GDG C MOVEL YRCEN YEAR3`,
1287+
`GDG C SETOFF 83`,
1288+
`GDG C ENDSR *`,
1289+
` C****************************************************************`,
1290+
`** COMPILE TIME ARRAY WITH NORMAL YEAR DATA`,
1291+
`000031059090120151181212243273304334`,
1292+
`** COMPILE TIME DATA FOR LEAP YEARS`,
1293+
`000031060091121152182213244274305335 `,
1294+
].join(`\n`);
1295+
1296+
const cache = await parser.getDocs(uri, lines, { ignoreCache: true, collectReferences: true });
1297+
1298+
expect(cache.subroutines.length).toBe(2);
1299+
expect(cache.variables.length).toBe(16);
1300+
1301+
const SRCJUL = cache.find(`SRCJUL`);
1302+
expect(SRCJUL).toBeDefined();
1303+
expect(SRCJUL.references.length).toBe(2);
1304+
});

0 commit comments

Comments
 (0)