2
0

globstat.pas 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. { only saved/restored if "full" is true }
  54. old_asmdata : tasmdata;
  55. old_debuginfo : tdebuginfo;
  56. old_scanner : tscannerfile;
  57. old_parser_file : string;
  58. end;
  59. procedure save_global_state(out state:tglobalstate;full:boolean);
  60. procedure restore_global_state(const state:tglobalstate;full:boolean);
  61. implementation
  62. uses
  63. pbase;
  64. procedure save_global_state(out state:tglobalstate;full:boolean);
  65. begin
  66. with state do
  67. begin
  68. old_current_module:=current_module;
  69. { save symtable state }
  70. oldsymtablestack:=symtablestack;
  71. oldmacrosymtablestack:=macrosymtablestack;
  72. oldcurrent_procinfo:=current_procinfo;
  73. { save scanner state }
  74. oldc:=c;
  75. oldpattern:=pattern;
  76. oldorgpattern:=orgpattern;
  77. oldtoken:=token;
  78. oldidtoken:=idtoken;
  79. old_block_type:=block_type;
  80. oldtokenpos:=current_tokenpos;
  81. old_switchesstatestack:=switchesstatestack;
  82. old_switchesstatestackpos:=switchesstatestackpos;
  83. { save cg }
  84. oldparse_only:=parse_only;
  85. { save akt... state }
  86. { handle the postponed case first }
  87. //flushpendingswitchesstate;
  88. oldcurrent_filepos:=current_filepos;
  89. old_settings:=current_settings;
  90. if full then
  91. begin
  92. old_asmdata:=current_asmdata;
  93. old_debuginfo:=current_debuginfo;
  94. old_parser_file:=parser_current_file;
  95. old_scanner:=current_scanner;
  96. end;
  97. end;
  98. end;
  99. procedure restore_global_state(const state:tglobalstate;full:boolean);
  100. begin
  101. with state do
  102. begin
  103. { restore scanner }
  104. c:=oldc;
  105. pattern:=oldpattern;
  106. orgpattern:=oldorgpattern;
  107. token:=oldtoken;
  108. idtoken:=oldidtoken;
  109. current_tokenpos:=oldtokenpos;
  110. block_type:=old_block_type;
  111. switchesstatestack:=old_switchesstatestack;
  112. switchesstatestackpos:=old_switchesstatestackpos;
  113. { restore cg }
  114. parse_only:=oldparse_only;
  115. { restore symtable state }
  116. symtablestack:=oldsymtablestack;
  117. macrosymtablestack:=oldmacrosymtablestack;
  118. current_procinfo:=oldcurrent_procinfo;
  119. current_filepos:=oldcurrent_filepos;
  120. current_settings:=old_settings;
  121. if full then
  122. begin
  123. current_module:=old_current_module; {!}
  124. current_asmdata:=old_asmdata;
  125. current_debuginfo:=old_debuginfo;
  126. current_scanner:=old_scanner;
  127. parser_current_file:=old_parser_file;
  128. end;
  129. end;
  130. end;
  131. end.