globstat.pas 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. {
  2. Copyright (c) 2012 by the FPC development team
  3. Contains functionality to save/restore the global compiler state when
  4. switching between the compilation of different units.
  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. }
  18. unit globstat;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. globtype,tokens,globals,
  23. aasmdata,
  24. dbgbase,
  25. symbase,symsym,
  26. fmodule,
  27. scanner,scandir,
  28. procinfo;
  29. type
  30. pglobalstate=^tglobalstate;
  31. tglobalstate=record
  32. { scanner }
  33. oldidtoken,
  34. oldtoken : ttoken;
  35. oldtokenpos : tfileposinfo;
  36. oldc : char;
  37. oldpattern,
  38. oldorgpattern : string;
  39. old_block_type : tblock_type;
  40. { symtable }
  41. oldsymtablestack,
  42. oldmacrosymtablestack : TSymtablestack;
  43. oldaktprocsym : tprocsym;
  44. { cg }
  45. oldparse_only : boolean;
  46. { akt.. things }
  47. oldcurrent_filepos : tfileposinfo;
  48. old_current_module : tmodule;
  49. oldcurrent_procinfo : tprocinfo;
  50. old_settings : tsettings;
  51. old_switchesstatestack : tswitchesstatestack;
  52. old_switchesstatestackpos : Integer;
  53. old_verbosity : longint;
  54. { only saved/restored if "full" is true }
  55. old_asmdata : tasmdata;
  56. old_debuginfo : tdebuginfo;
  57. old_scanner : tscannerfile;
  58. old_parser_file : string;
  59. end;
  60. procedure save_global_state(out state:tglobalstate;full:boolean);
  61. procedure restore_global_state(const state:tglobalstate;full:boolean);
  62. implementation
  63. uses
  64. pbase,comphook;
  65. procedure save_global_state(out state:tglobalstate;full:boolean);
  66. begin
  67. with state do
  68. begin
  69. old_current_module:=current_module;
  70. { save symtable state }
  71. oldsymtablestack:=symtablestack;
  72. oldmacrosymtablestack:=macrosymtablestack;
  73. oldcurrent_procinfo:=current_procinfo;
  74. { save scanner state }
  75. oldc:=c;
  76. oldpattern:=pattern;
  77. oldorgpattern:=orgpattern;
  78. oldtoken:=token;
  79. oldidtoken:=idtoken;
  80. old_block_type:=block_type;
  81. oldtokenpos:=current_tokenpos;
  82. old_switchesstatestack:=switchesstatestack;
  83. old_switchesstatestackpos:=switchesstatestackpos;
  84. { save cg }
  85. oldparse_only:=parse_only;
  86. { save akt... state }
  87. { handle the postponed case first }
  88. //flushpendingswitchesstate;
  89. oldcurrent_filepos:=current_filepos;
  90. old_settings:=current_settings;
  91. old_verbosity:=status.verbosity;
  92. if full then
  93. begin
  94. old_asmdata:=current_asmdata;
  95. old_debuginfo:=current_debuginfo;
  96. old_parser_file:=parser_current_file;
  97. old_scanner:=current_scanner;
  98. end;
  99. end;
  100. end;
  101. procedure restore_global_state(const state:tglobalstate;full:boolean);
  102. begin
  103. with state do
  104. begin
  105. { restore scanner }
  106. c:=oldc;
  107. pattern:=oldpattern;
  108. orgpattern:=oldorgpattern;
  109. token:=oldtoken;
  110. idtoken:=oldidtoken;
  111. current_tokenpos:=oldtokenpos;
  112. block_type:=old_block_type;
  113. switchesstatestack:=old_switchesstatestack;
  114. switchesstatestackpos:=old_switchesstatestackpos;
  115. { restore cg }
  116. parse_only:=oldparse_only;
  117. { restore symtable state }
  118. symtablestack:=oldsymtablestack;
  119. macrosymtablestack:=oldmacrosymtablestack;
  120. current_procinfo:=oldcurrent_procinfo;
  121. current_filepos:=oldcurrent_filepos;
  122. current_settings:=old_settings;
  123. status.verbosity:=old_verbosity;
  124. if full then
  125. begin
  126. current_module:=old_current_module; {!}
  127. current_asmdata:=old_asmdata;
  128. current_debuginfo:=old_debuginfo;
  129. current_scanner:=old_scanner;
  130. parser_current_file:=old_parser_file;
  131. end;
  132. end;
  133. end;
  134. end.