Use 32-bit representation for line numbers.

C99 and later specify that line numbers set via #line can be up to 2147483647, so they need to be represented as (at least) a 32-bit value.
This commit is contained in:
Stephen Heumann 2022-10-22 18:54:46 -05:00
parent 760c932fea
commit 65ec29ee3e
6 changed files with 45 additions and 27 deletions

View File

@ -488,9 +488,9 @@ var
infoStringGS: gsosOutString; {language specific command line info}
intLabel: integer; {last used label number}
languageNumber: integer; {our language number}
lastLine: 0..maxint; {last line number used by pc_nam}
lastLine: 0..maxint4; {last line number used by pc_nam}
liDCBGS: getLInfoDCBGS; {get/set LInfo DCB}
lineNumber: 0..maxint; {source line number}
lineNumber: 0..maxint4; {source line number}
nameFound: boolean; {has a pc_nam been generated?}
nextLocalLabel: integer; {next available local data label number}
numErrors: integer; {number of errors in the program}

View File

@ -277,7 +277,7 @@ function MakeCompoundLiteral(tp: typePtr): identPtr; extern;
{ tp - the type of the compound literal }
procedure AutoInit (variable: identPtr; line: integer;
procedure AutoInit (variable: identPtr; line: longint;
isCompoundLiteral: boolean); extern;
{ generate code to initialize an auto variable }

View File

@ -18,7 +18,7 @@ uses CCommon, MM, Scanner, Symbol, CGI;
{$segment 'SCANNER'}
const
symFileVersion = 30; {version number of .sym file format}
symFileVersion = 31; {version number of .sym file format}
var
inhibitHeader: boolean; {should .sym includes be blocked?}
@ -800,7 +800,7 @@ procedure EndInclude {chPtr: ptr};
p_keep: WriteLongString(@pragmaKeepFile^.theString);
p_line: begin
WriteWord(lineNumber);
WriteLong(lineNumber);
WriteLongString(@sourceFileGS.theString);
end;
@ -1456,7 +1456,7 @@ var
end;
p_line: begin
lineNumber := ReadWord;
lineNumber := ReadLong;
lsPtr := ReadLongString;
sourceFileGS.theString.size := lsPtr^.length;
for i := 1 to sourceFileGS.theString.size do

View File

@ -47,7 +47,7 @@ function TypeName: typePtr;
{ returns: a pointer to the type }
procedure AutoInit (variable: identPtr; line: integer;
procedure AutoInit (variable: identPtr; line: longint;
isCompoundLiteral: boolean);
{ generate code to initialize an auto variable }
@ -408,7 +408,7 @@ NextToken; {remove the rbracech token}
end; {EndCompoundStatement}
procedure RecordLineNumber (lineNumber: integer);
procedure RecordLineNumber (lineNumber: longint);
{ generate debug code to record the line number as specified }
@ -421,11 +421,11 @@ if (lastLine <> lineNumber) or changedSourceFile then begin
if changedSourceFile then begin
newSourceFileGS := pointer(Malloc(sizeof(gsosOutString)));
newSourceFileGS^ := sourceFileGS;
Gen2Name(pc_lnm, lineNumber, ord(debugType), pointer(newSourceFileGS));
Gen2Name(pc_lnm, ord(lineNumber), ord(debugType), pointer(newSourceFileGS));
changedSourceFile := false;
end {if}
else
Gen2Name(pc_lnm, lineNumber, ord(debugType), nil);
Gen2Name(pc_lnm, ord(lineNumber), ord(debugType), nil);
end; {if}
end; {RecordLineNumber}
@ -3510,7 +3510,7 @@ var
tp: typePtr; {for tracing type lists}
tk: tokenType; {work token}
typeFound: boolean; {has some type specifier been found?}
startLine: integer; {line where this declaration starts}
startLine: longint; {line where this declaration starts}
declSpecifiers: declSpecifiersRecord; {type & specifiers for the declaration}
@ -4382,7 +4382,7 @@ case statementList^.kind of
end; {DoStatement}
procedure AutoInit {variable: identPtr; line: integer;
procedure AutoInit {variable: identPtr; line: longint;
isCompoundLiteral: boolean};
{ generate code to initialize an auto variable }

View File

@ -533,7 +533,7 @@ la3 stz ch
beq lb1
jsl WriteLine
stz wroteLine
inc lineNumber
inc4 lineNumber
move4 chPtr,firstPtr
lb1 anop
@ -596,6 +596,10 @@ lb4 lda [p1],Y
ldy #4+maxPath+4+maxPath+4
lda [fp],Y
sta lineNumber
iny
iny
lda [fp],Y
sta lineNumber+2
! ReadFile;
jsl ReadFile
! eofPtr := pointer(ord4(bofPtr) + ffDCBGS.fileLength);
@ -603,7 +607,7 @@ lb4 lda [p1],Y
! chPtr := pointer(ord4(bofPtr) + fp^.disp);
! includeChPtr := chPtr;
! firstPtr := chPtr;
ldy #4+maxPath+4+maxPath+4+2
ldy #4+maxPath+4+maxPath+4+4
clc
lda bofPtr
adc [fp],Y
@ -648,7 +652,7 @@ lb5 anop
beq lb6
jsl WriteLine
stz wroteLine
inc lineNumber
inc4 lineNumber
move4 chPtr,firstPtr
lb6 anop
! needWriteLine := charKinds[ord(ch)] = ch_eol;
@ -772,7 +776,7 @@ lc2b move4 chPtr,p1
bne lc3
jsl WriteLine
stz wroteLine
inc lineNumber
inc4 lineNumber
add4 chPtr,#1,firstPtr
lc3 anop
! chPtr := pointer(ord4(chPtr)+1);

View File

@ -190,7 +190,7 @@ const
type
errorType = record {record of a single error}
num: integer; {error number}
line: integer; {line number}
line: longint; {line number}
col: integer; {column number}
end;
@ -201,7 +201,7 @@ type
next: filePtr; {next file in include stack}
name: gsosOutString; {name of the file}
sname: gsosOutString; {name of the file for __FILE__}
lineNumber: integer; {line number at the #include}
lineNumber: longint; {line number at the #include}
disp: longint; {disp of next character to process}
end;
@ -253,7 +253,7 @@ var
flagOverflows: boolean; {flag numeric overflows?}
gettingFileName: boolean; {are we in GetFileName?}
lastWasReturn: boolean; {was the last character an eol?}
lineStr: string[5]; {string form of __LINE__}
lineStr: string[10]; {string form of __LINE__}
ifList: ifPtr; {points to the top prep. parse record}
includeChPtr: ptr; {chPtr at start of current token}
includeCount: 0..maxint; {nested include files (for EndInclude)}
@ -271,7 +271,7 @@ var
skipping: boolean; {skipping tokens?}
timeStr: longStringPtr; {macro time string}
tokenColumn: 0..maxint; {column number at start of this token}
tokenLine: 0..maxint; {line number at start of this token}
tokenLine: 0..maxint4; {line number at start of this token}
tokenList: tokenListRecordPtr; {token putback buffer}
tokenStart: ptr; {pointer to the first char in the token}
tokenEnd: ptr; {pointer to the first char past the token}
@ -573,8 +573,11 @@ if list or (numErr <> 0) then begin
with errors[i] do begin
if line = lineNumber then begin
write(' ');
if lineNumber >= 10000 then
write(' ');
while lineNumber >= 10000 do begin
lineNumber := lineNumber div 10;
write(' ');
end; {while}
lineNumber := line;
cp := firstPtr;
for cl := 1 to col-1 do begin
if cp^ = HT then
@ -1829,11 +1832,18 @@ if macro^.readOnly then begin {handle special macros}
case macro^.algorithm of
1: begin {__LINE__}
token.kind := intconst;
if lineNumber <= maxint then begin
token.kind := intconst;
token.class := intconstant;
token.ival := ord(lineNumber);
end {if}
else begin
token.kind := longconst;
token.class := longconstant;
token.lval := lineNumber;
end; {else}
token.numString := @lineStr;
token.class := intconstant;
token.ival := lineNumber;
lineStr := cnvis(token.ival);
lineStr := cnvis(lineNumber);
tokenStart := @lineStr[1];
tokenEnd := pointer(ord4(tokenStart)+length(lineStr));
end;
@ -2403,7 +2413,7 @@ var
lReportEOL: boolean; {local copy of reportEOL}
tSkipping: boolean; {temp copy of the skipping variable}
val: integer; {expression value}
nextLineNumber: integer; {number for next line}
nextLineNumber: longint; {number for next line}
function Defined: boolean;
@ -3281,6 +3291,10 @@ if ch in ['a','d','e','i','l','p','u','w'] then begin
nextLineNumber := token.ival;
NextToken;
end {if}
else if token.kind = longconst then begin
nextLineNumber := token.lval;
NextToken;
end {if}
else
Error(18);
if (token.kind = stringconst)