|
@@ -28,7 +28,7 @@ unit scanner;
|
|
interface
|
|
interface
|
|
|
|
|
|
uses
|
|
uses
|
|
- globals,files;
|
|
|
|
|
|
+ cobjects,globals,files;
|
|
|
|
|
|
const
|
|
const
|
|
{$ifdef TP}
|
|
{$ifdef TP}
|
|
@@ -135,15 +135,6 @@ unit scanner;
|
|
destructor done;
|
|
destructor done;
|
|
end;
|
|
end;
|
|
|
|
|
|
-{$ifdef UseTokenInfo}
|
|
|
|
-
|
|
|
|
- ttokeninfo = record
|
|
|
|
- token : ttoken;
|
|
|
|
- fi : tfileposinfo;
|
|
|
|
- end;
|
|
|
|
- ptokeninfo = ^ttokeninfo;
|
|
|
|
-{$endif UseTokenInfo}
|
|
|
|
-
|
|
|
|
var
|
|
var
|
|
c : char;
|
|
c : char;
|
|
orgpattern,
|
|
orgpattern,
|
|
@@ -162,6 +153,15 @@ unit scanner;
|
|
preprocstack : ppreprocstack;
|
|
preprocstack : ppreprocstack;
|
|
|
|
|
|
|
|
|
|
|
|
+{$ifdef UseTokenInfo}
|
|
|
|
+ type
|
|
|
|
+ ttokeninfo = record
|
|
|
|
+ token : ttoken;
|
|
|
|
+ fi : tfileposinfo;
|
|
|
|
+ end;
|
|
|
|
+ ptokeninfo = ^ttokeninfo;
|
|
|
|
+{$endif UseTokenInfo}
|
|
|
|
+
|
|
{public}
|
|
{public}
|
|
procedure syntaxerror(const s : string);
|
|
procedure syntaxerror(const s : string);
|
|
{$ifndef UseTokenInfo}
|
|
{$ifndef UseTokenInfo}
|
|
@@ -170,6 +170,9 @@ unit scanner;
|
|
function yylex : ptokeninfo;
|
|
function yylex : ptokeninfo;
|
|
{$endif UseTokenInfo}
|
|
{$endif UseTokenInfo}
|
|
function asmgetchar : char;
|
|
function asmgetchar : char;
|
|
|
|
+ function get_current_col : longint;
|
|
|
|
+ procedure get_cur_file_pos(var fileinfo : tfileposinfo);
|
|
|
|
+ procedure set_cur_file_pos(const fileinfo : tfileposinfo);
|
|
|
|
|
|
procedure InitScanner(const fn: string);
|
|
procedure InitScanner(const fn: string);
|
|
procedure DoneScanner(testendif:boolean);
|
|
procedure DoneScanner(testendif:boolean);
|
|
@@ -178,13 +181,14 @@ unit scanner;
|
|
implementation
|
|
implementation
|
|
|
|
|
|
uses
|
|
uses
|
|
- dos,cobjects,verbose,pbase,
|
|
|
|
|
|
+ dos,verbose,pbase,
|
|
symtable,switches,link;
|
|
symtable,switches,link;
|
|
|
|
|
|
var
|
|
var
|
|
{ this is usefull to get the write filename
|
|
{ this is usefull to get the write filename
|
|
for the last instruction of an include file !}
|
|
for the last instruction of an include file !}
|
|
FileHasChanged : Boolean;
|
|
FileHasChanged : Boolean;
|
|
|
|
+ status : tcompilestatus;
|
|
|
|
|
|
|
|
|
|
{*****************************************************************************
|
|
{*****************************************************************************
|
|
@@ -350,6 +354,8 @@ unit scanner;
|
|
current_module^.current_inputfile^.close;
|
|
current_module^.current_inputfile^.close;
|
|
{ load next module }
|
|
{ load next module }
|
|
current_module^.current_inputfile:=current_module^.current_inputfile^.next;
|
|
current_module^.current_inputfile:=current_module^.current_inputfile^.next;
|
|
|
|
+ current_module^.current_index:=current_module^.current_inputfile^.ref_index;
|
|
|
|
+ status.currentsource:=current_module^.current_inputfile^.name^+current_module^.current_inputfile^.ext^;
|
|
inputbuffer:=current_module^.current_inputfile^.buf;
|
|
inputbuffer:=current_module^.current_inputfile^.buf;
|
|
inputpointer:=inputbuffer+current_module^.current_inputfile^.bufpos;
|
|
inputpointer:=inputbuffer+current_module^.current_inputfile^.bufpos;
|
|
end;
|
|
end;
|
|
@@ -361,11 +367,11 @@ unit scanner;
|
|
|
|
|
|
procedure linebreak;
|
|
procedure linebreak;
|
|
var
|
|
var
|
|
- status : tcompilestatus;
|
|
|
|
cur : char;
|
|
cur : char;
|
|
begin
|
|
begin
|
|
cur:=c;
|
|
cur:=c;
|
|
- if byte(inputpointer^)=0 then
|
|
|
|
|
|
+ if (byte(inputpointer^)=0) and
|
|
|
|
+ current_module^.current_inputfile^.filenotatend then
|
|
begin
|
|
begin
|
|
reload;
|
|
reload;
|
|
if byte(cur)+byte(c)<>23 then
|
|
if byte(cur)+byte(c)<>23 then
|
|
@@ -382,7 +388,8 @@ unit scanner;
|
|
totalcompiledlines:=abslines;
|
|
totalcompiledlines:=abslines;
|
|
currentline:=current_module^.current_inputfile^.line_no
|
|
currentline:=current_module^.current_inputfile^.line_no
|
|
+current_module^.current_inputfile^.line_count;
|
|
+current_module^.current_inputfile^.line_count;
|
|
- currentsource:=current_module^.current_inputfile^.name^+current_module^.current_inputfile^.ext^;
|
|
|
|
|
|
+ { you call strcopy here at each line !!! }
|
|
|
|
+ {currentsource:=current_module^.current_inputfile^.name^+current_module^.current_inputfile^.ext^;}
|
|
totallines:=0;
|
|
totallines:=0;
|
|
end;
|
|
end;
|
|
if compilestatusproc(status) then
|
|
if compilestatusproc(status) then
|
|
@@ -419,16 +426,9 @@ unit scanner;
|
|
readstring[i]:=c;
|
|
readstring[i]:=c;
|
|
end;
|
|
end;
|
|
{ get next char }
|
|
{ get next char }
|
|
- c:=inputpointer^;
|
|
|
|
- if c=#0 then
|
|
|
|
- reload
|
|
|
|
- else
|
|
|
|
- inc(longint(inputpointer));
|
|
|
|
|
|
+ readchar;
|
|
end;
|
|
end;
|
|
readstring[0]:=chr(i);
|
|
readstring[0]:=chr(i);
|
|
- { was the next char a linebreak ? }
|
|
|
|
- if c in [#10,#13] then
|
|
|
|
- linebreak;
|
|
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
@@ -472,16 +472,12 @@ unit scanner;
|
|
readnumber[i]:=c;
|
|
readnumber[i]:=c;
|
|
end;
|
|
end;
|
|
{ get next char }
|
|
{ get next char }
|
|
- c:=inputpointer^;
|
|
|
|
- if c=#0 then
|
|
|
|
- reload
|
|
|
|
- else
|
|
|
|
- inc(longint(inputpointer));
|
|
|
|
|
|
+ readchar;
|
|
end;
|
|
end;
|
|
readnumber[0]:=chr(i);
|
|
readnumber[0]:=chr(i);
|
|
{ was the next char a linebreak ? }
|
|
{ was the next char a linebreak ? }
|
|
- if c in [#10,#13] then
|
|
|
|
- linebreak;
|
|
|
|
|
|
+ { if c in [#10,#13] then
|
|
|
|
+ linebreak; }
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
@@ -526,13 +522,14 @@ unit scanner;
|
|
begin
|
|
begin
|
|
while c in [' ',#9..#13] do
|
|
while c in [' ',#9..#13] do
|
|
begin
|
|
begin
|
|
- c:=inputpointer^;
|
|
|
|
|
|
+ readchar;
|
|
|
|
+ {c:=inputpointer^;
|
|
if c=#0 then
|
|
if c=#0 then
|
|
reload
|
|
reload
|
|
else
|
|
else
|
|
inc(longint(inputpointer));
|
|
inc(longint(inputpointer));
|
|
if c in [#10,#13] then
|
|
if c in [#10,#13] then
|
|
- linebreak;
|
|
|
|
|
|
+ linebreak; }
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
@@ -561,13 +558,12 @@ unit scanner;
|
|
else
|
|
else
|
|
found:=0;
|
|
found:=0;
|
|
end;
|
|
end;
|
|
- c:=inputpointer^;
|
|
|
|
|
|
+ readchar;
|
|
|
|
+ {c:=inputpointer^;
|
|
if c=#0 then
|
|
if c=#0 then
|
|
reload
|
|
reload
|
|
else
|
|
else
|
|
- inc(longint(inputpointer));
|
|
|
|
- if c in [#10,#13] then
|
|
|
|
- linebreak;
|
|
|
|
|
|
+ inc(longint(inputpointer));}
|
|
until (found=2);
|
|
until (found=2);
|
|
end;
|
|
end;
|
|
|
|
|
|
@@ -588,14 +584,14 @@ unit scanner;
|
|
'}' : dec_comment_level;
|
|
'}' : dec_comment_level;
|
|
#26 : Message(scan_f_end_of_file);
|
|
#26 : Message(scan_f_end_of_file);
|
|
end;
|
|
end;
|
|
- c:=inputpointer^;
|
|
|
|
|
|
+ readchar;
|
|
|
|
+ {c:=inputpointer^;
|
|
if c=#0 then
|
|
if c=#0 then
|
|
reload
|
|
reload
|
|
else
|
|
else
|
|
- inc(longint(inputpointer));
|
|
|
|
- if c in [#10,#13] then
|
|
|
|
- linebreak;
|
|
|
|
|
|
+ inc(longint(inputpointer));}
|
|
end;
|
|
end;
|
|
|
|
+ {if (c=#10) or (c=#13) then linebreak;}
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
@@ -651,13 +647,12 @@ unit scanner;
|
|
else
|
|
else
|
|
found:=0;
|
|
found:=0;
|
|
end;
|
|
end;
|
|
- c:=inputpointer^;
|
|
|
|
|
|
+ readchar;
|
|
|
|
+ {c:=inputpointer^;
|
|
if c=#0 then
|
|
if c=#0 then
|
|
reload
|
|
reload
|
|
else
|
|
else
|
|
- inc(longint(inputpointer));
|
|
|
|
- if c in [#10,#13] then
|
|
|
|
- linebreak;
|
|
|
|
|
|
+ inc(longint(inputpointer));}
|
|
until (found=2);
|
|
until (found=2);
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
@@ -672,6 +667,7 @@ unit scanner;
|
|
y : ttoken;
|
|
y : ttoken;
|
|
{$ifdef UseTokenInfo}
|
|
{$ifdef UseTokenInfo}
|
|
newyylex : ptokeninfo;
|
|
newyylex : ptokeninfo;
|
|
|
|
+ line,column : longint;
|
|
{$endif UseTokenInfo}
|
|
{$endif UseTokenInfo}
|
|
code : word;
|
|
code : word;
|
|
l : longint;
|
|
l : longint;
|
|
@@ -683,6 +679,10 @@ unit scanner;
|
|
exit_label;
|
|
exit_label;
|
|
{$endif UseTokenInfo}
|
|
{$endif UseTokenInfo}
|
|
begin
|
|
begin
|
|
|
|
+{$ifdef UseTokenInfo}
|
|
|
|
+ line:=current_module^.current_inputfile^.line_no;
|
|
|
|
+ column:=get_current_col;
|
|
|
|
+{$endif UseTokenInfo}
|
|
{ was the last character a point ? }
|
|
{ was the last character a point ? }
|
|
{ this code is needed because the scanner if there is a 1. found if }
|
|
{ this code is needed because the scanner if there is a 1. found if }
|
|
{ this is a floating point number or range like 1..3 }
|
|
{ this is a floating point number or range like 1..3 }
|
|
@@ -717,6 +717,11 @@ unit scanner;
|
|
until false;
|
|
until false;
|
|
|
|
|
|
lasttokenpos:=longint(inputpointer);
|
|
lasttokenpos:=longint(inputpointer);
|
|
|
|
+{$ifdef UseTokenInfo}
|
|
|
|
+ line:=current_module^.current_inputfile^.line_no;
|
|
|
|
+ column:=get_current_col;
|
|
|
|
+ { will become line:=lasttokenpos ??;}
|
|
|
|
+{$endif UseTokenInfo}
|
|
case c of
|
|
case c of
|
|
'_','A'..'Z',
|
|
'_','A'..'Z',
|
|
'a'..'z' : begin
|
|
'a'..'z' : begin
|
|
@@ -741,7 +746,9 @@ unit scanner;
|
|
hp:=new(pinputfile,init('','Macro '+pattern,''));
|
|
hp:=new(pinputfile,init('','Macro '+pattern,''));
|
|
hp^.next:=current_module^.current_inputfile;
|
|
hp^.next:=current_module^.current_inputfile;
|
|
current_module^.current_inputfile:=hp;
|
|
current_module^.current_inputfile:=hp;
|
|
|
|
+ status.currentsource:=current_module^.current_inputfile^.name^;
|
|
current_module^.sourcefiles.register_file(hp);
|
|
current_module^.sourcefiles.register_file(hp);
|
|
|
|
+ current_module^.current_index:=hp^.ref_index;
|
|
{ set an own buffer }
|
|
{ set an own buffer }
|
|
getmem(hp2,mac^.buflen+1);
|
|
getmem(hp2,mac^.buflen+1);
|
|
current_module^.current_inputfile^.setbuf(hp2,mac^.buflen+1);
|
|
current_module^.current_inputfile^.setbuf(hp2,mac^.buflen+1);
|
|
@@ -1087,7 +1094,7 @@ unit scanner;
|
|
{$ifndef UseTokenInfo}
|
|
{$ifndef UseTokenInfo}
|
|
yylex:=DOUBLEADDR;
|
|
yylex:=DOUBLEADDR;
|
|
{$else UseTokenInfo}
|
|
{$else UseTokenInfo}
|
|
- yylex:=DOUBLEADDR;
|
|
|
|
|
|
+ y:=DOUBLEADDR;
|
|
{$endif UseTokenInfo}
|
|
{$endif UseTokenInfo}
|
|
end
|
|
end
|
|
else
|
|
else
|
|
@@ -1287,8 +1294,9 @@ unit scanner;
|
|
exit_label:
|
|
exit_label:
|
|
new(newyylex);
|
|
new(newyylex);
|
|
newyylex^.token:=y;
|
|
newyylex^.token:=y;
|
|
- newyylex^.fi.infile:=current_module^.current_inputfile;
|
|
|
|
- newyylex^.fi.line:=current_module^.current_inputfile^.line_no;
|
|
|
|
|
|
+ newyylex^.fi.fileindex:=current_module^.current_index;
|
|
|
|
+ newyylex^.fi.line:=line;
|
|
|
|
+ newyylex^.fi.column:=column;
|
|
yylex:=newyylex;
|
|
yylex:=newyylex;
|
|
{$endif UseTokenInfo}
|
|
{$endif UseTokenInfo}
|
|
end;
|
|
end;
|
|
@@ -1352,6 +1360,8 @@ unit scanner;
|
|
current_module^.current_inputfile:=new(pinputfile,init(d,n,e));
|
|
current_module^.current_inputfile:=new(pinputfile,init(d,n,e));
|
|
current_module^.current_inputfile^.reset;
|
|
current_module^.current_inputfile^.reset;
|
|
current_module^.sourcefiles.register_file(current_module^.current_inputfile);
|
|
current_module^.sourcefiles.register_file(current_module^.current_inputfile);
|
|
|
|
+ current_module^.current_index:=current_module^.current_inputfile^.ref_index;
|
|
|
|
+ status.currentsource:=current_module^.current_inputfile^.name^+current_module^.current_inputfile^.ext^;
|
|
if ioresult<>0 then
|
|
if ioresult<>0 then
|
|
Message(scan_f_cannot_open_input);
|
|
Message(scan_f_cannot_open_input);
|
|
inputbuffer:=current_module^.current_inputfile^.buf;
|
|
inputbuffer:=current_module^.current_inputfile^.buf;
|
|
@@ -1363,6 +1373,27 @@ unit scanner;
|
|
s_point:=false;
|
|
s_point:=false;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+ procedure get_cur_file_pos(var fileinfo : tfileposinfo);
|
|
|
|
+
|
|
|
|
+ begin
|
|
|
|
+ fileinfo.line:=current_module^.current_inputfile^.line_no;
|
|
|
|
+ {fileinfo.fileindex:=current_module^.current_inputfile^.ref_index;}
|
|
|
|
+ { should allways be the same !! }
|
|
|
|
+ fileinfo.fileindex:=current_module^.current_index;
|
|
|
|
+ fileinfo.column:=get_current_col;
|
|
|
|
+ end;
|
|
|
|
+
|
|
|
|
+ procedure set_cur_file_pos(const fileinfo : tfileposinfo);
|
|
|
|
+
|
|
|
|
+ begin
|
|
|
|
+ current_module^.current_index:=fileinfo.fileindex;
|
|
|
|
+ current_module^.current_inputfile:=
|
|
|
|
+ pinputfile(current_module^.sourcefiles.get_file(fileinfo.fileindex));
|
|
|
|
+ current_module^.current_inputfile^.line_no:=fileinfo.line;
|
|
|
|
+ {fileinfo.fileindex:=current_module^.current_inputfile^.ref_index;}
|
|
|
|
+ { should allways be the same !! }
|
|
|
|
+ { fileinfo.column:=get_current_col; }
|
|
|
|
+ end;
|
|
|
|
|
|
procedure DoneScanner(testendif:boolean);
|
|
procedure DoneScanner(testendif:boolean);
|
|
var
|
|
var
|
|
@@ -1385,7 +1416,14 @@ unit scanner;
|
|
end.
|
|
end.
|
|
{
|
|
{
|
|
$Log$
|
|
$Log$
|
|
- Revision 1.13 1998-04-29 13:42:27 peter
|
|
|
|
|
|
+ Revision 1.14 1998-04-30 15:59:42 pierre
|
|
|
|
+ * GDB works again better :
|
|
|
|
+ correct type info in one pass
|
|
|
|
+ + UseTokenInfo for better source position
|
|
|
|
+ * fixed one remaining bug in scanner for line counts
|
|
|
|
+ * several little fixes
|
|
|
|
+
|
|
|
|
+ Revision 1.13 1998/04/29 13:42:27 peter
|
|
+ $IOCHECKS and $ALIGN to test already, other will follow soon
|
|
+ $IOCHECKS and $ALIGN to test already, other will follow soon
|
|
* fixed the wrong linecounting with comments
|
|
* fixed the wrong linecounting with comments
|
|
|
|
|