Skip to content

Commit

Permalink
Correction of BUG in subroutine parser
Browse files Browse the repository at this point in the history
  • Loading branch information
marcsosduma authored and nberth committed Apr 9, 2024
1 parent ba251cf commit b6180e1
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/parser.c.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const versionRegex = /\/\*\sGenerated by\s+cobc\s([0-9a-z\-\.]+)\s+\*\//i;
const subroutineRegex = /\sPerform\s/i;
const frame_ptrFindRegex = /frame\_ptr\-\-\;/;
const fixOlderFormat = /cob\_trace\_stmt/;
const programExit = /\/\*\sProgram\s\exit\s+\*\//i;

globalThis.varOccurs = [];

Expand Down Expand Up @@ -75,6 +76,8 @@ export class SourceMap {

private parse(fileC: string): void {
let nat = fileC;
let hasProgramExit = false;

if (!nativePath.isAbsolute(fileC)) {
nat = nativePathFromPath.resolve(this.cwd, fileC);
fileC = nativePath.resolve(this.cwd, fileC);
Expand Down Expand Up @@ -116,9 +119,9 @@ export class SourceMap {
}
// fix new codegen
match = procedureFixRegex.exec(line);
if (match && this.lines.length > 0) {
if (match && this.lines.length > 0 && !hasProgramExit) {
let isOldFormat = fixOlderFormat.exec(this.lineBefore);
if(this.isVersion2_2_or_3_1_1 || !isOldFormat){ // Is it in the old format?
if(fileNameCompare(this.lines[this.lines.length - 1].fileCobol, fileCobol) && (this.isVersion2_2_or_3_1_1 || !isOldFormat)){ // Is it in the old format?
let line = this.lines.pop();
line.lineC = parseInt(match[1]);
this.lines.push(line);
Expand Down Expand Up @@ -173,6 +176,10 @@ export class SourceMap {
}
}
this.lineBefore = line;
match = programExit.exec(line);
if (match) {
hasProgramExit=true;;
}
lineNumber++;
}
}
Expand Down

0 comments on commit b6180e1

Please sign in to comment.