browser.pas 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. {
  2. $Id$
  3. Copyright (c) 1996-98 by Florian Klaempfl
  4. This unit implements a browser object
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. }
  17. unit browser;
  18. interface
  19. uses globals,cobjects,files;
  20. type
  21. pref = ^tref;
  22. tref = object
  23. nextref : pref;
  24. posinfo : tfileposinfo;
  25. moduleindex : word;
  26. constructor init(ref : pref;pos : pfileposinfo);
  27. constructor load(var ref : pref;fileindex : word;line,column : longint);
  28. destructor done; virtual;
  29. function get_file_line : string;
  30. end;
  31. { simple method to chain all refs }
  32. procedure add_new_ref(var ref : pref;pos : pfileposinfo);
  33. function get_source_file(moduleindex,fileindex : word) : pinputfile;
  34. { one big problem remains for overloaded procedure }
  35. { we should be able to separate them }
  36. { this might be feasable in pass_1 }
  37. implementation
  38. uses scanner,verbose;
  39. constructor tref.init(ref :pref;pos : pfileposinfo);
  40. begin
  41. nextref:=nil;
  42. if ref<>nil then
  43. ref^.nextref:=@self;
  44. if assigned(pos) then
  45. posinfo:=pos^;
  46. if current_module<>nil then
  47. begin
  48. moduleindex:=current_module^.unit_index;
  49. end;
  50. end;
  51. constructor tref.load(var ref : pref;fileindex : word;line,column : longint);
  52. begin
  53. moduleindex:=current_module^.unit_index;
  54. if assigned(ref) then
  55. ref^.nextref:=@self;
  56. nextref:=nil;
  57. posinfo.fileindex:=fileindex;
  58. posinfo.line:=line;
  59. posinfo.column:=column;
  60. ref:=@self;
  61. end;
  62. destructor tref.done;
  63. var
  64. inputfile : pinputfile;
  65. begin
  66. inputfile:=get_source_file(moduleindex,posinfo.fileindex);
  67. if inputfile<>nil then
  68. dec(inputfile^.ref_count);
  69. end;
  70. function tref.get_file_line : string;
  71. var
  72. inputfile : pinputfile;
  73. begin
  74. get_file_line:='';
  75. inputfile:=get_source_file(moduleindex,posinfo.fileindex);
  76. if assigned(inputfile) then
  77. if Use_Rhide then
  78. get_file_line:=globals.lowercase(inputfile^.name^+inputfile^.ext^)
  79. +':'+tostr(posinfo.line)+':'+tostr(posinfo.column)+':'
  80. else
  81. get_file_line:=inputfile^.name^+inputfile^.ext^
  82. +'('+tostr(posinfo.line)+','+tostr(posinfo.column)+')'
  83. else
  84. if Use_Rhide then
  85. get_file_line:='file_unknown:'
  86. +tostr(posinfo.line)+':'+tostr(posinfo.column)+':'
  87. else
  88. get_file_line:='file_unknown('
  89. +tostr(posinfo.line)+','+tostr(posinfo.column)+')'
  90. end;
  91. procedure add_new_ref(var ref : pref;pos : pfileposinfo);
  92. var
  93. newref : pref;
  94. begin
  95. new(newref,init(ref,pos));
  96. ref:=newref;
  97. end;
  98. function get_source_file(moduleindex,fileindex : word) : pinputfile;
  99. var
  100. hp : pmodule;
  101. f : pinputfile;
  102. begin
  103. hp:=pmodule(loaded_units.first);
  104. while assigned(hp) and (hp^.unit_index<>moduleindex) do
  105. hp:=pmodule(hp^.next);
  106. get_source_file:=nil;
  107. if not assigned(hp) then
  108. exit;
  109. f:=pinputfile(hp^.sourcefiles.files);
  110. while assigned(f) do
  111. begin
  112. if f^.ref_index=fileindex then
  113. begin
  114. get_source_file:=f;
  115. exit;
  116. end;
  117. f:=pinputfile(f^._next);
  118. end;
  119. end;
  120. end.
  121. {
  122. $Log$
  123. Revision 1.3 1998-05-20 09:42:32 pierre
  124. + UseTokenInfo now default
  125. * unit in interface uses and implementation uses gives error now
  126. * only one error for unknown symbol (uses lastsymknown boolean)
  127. the problem came from the label code !
  128. + first inlined procedures and function work
  129. (warning there might be allowed cases were the result is still wrong !!)
  130. * UseBrower updated gives a global list of all position of all used symbols
  131. with switch -gb
  132. Revision 1.2 1998/04/30 15:59:39 pierre
  133. * GDB works again better :
  134. correct type info in one pass
  135. + UseTokenInfo for better source position
  136. * fixed one remaining bug in scanner for line counts
  137. * several little fixes
  138. Revision 1.1.1.1 1998/03/25 11:18:12 root
  139. * Restored version
  140. Revision 1.5 1998/03/10 16:27:36 pierre
  141. * better line info in stabs debug
  142. * symtabletype and lexlevel separated into two fields of tsymtable
  143. + ifdef MAKELIB for direct library output, not complete
  144. + ifdef CHAINPROCSYMS for overloaded seach across units, not fully
  145. working
  146. + ifdef TESTFUNCRET for setting func result in underfunction, not
  147. working
  148. Revision 1.4 1998/03/10 01:17:15 peter
  149. * all files have the same header
  150. * messages are fully implemented, EXTDEBUG uses Comment()
  151. + AG... files for the Assembler generation
  152. Revision 1.3 1998/03/02 01:48:06 peter
  153. * renamed target_DOS to target_GO32V1
  154. + new verbose system, merged old errors and verbose units into one new
  155. verbose.pas, so errors.pas is obsolete
  156. Revision 1.2 1998/02/13 10:34:37 daniel
  157. * Made Motorola version compilable.
  158. * Fixed optimizer
  159. Revision 1.1.1.1 1997/11/27 08:32:51 michael
  160. FPC Compiler CVS start
  161. }