psub.pas 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Florian Klaempfl, Daniel Mantione
  4. Does the parsing and codegeneration at subroutine level
  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 psub;
  19. {$i defines.inc}
  20. interface
  21. procedure compile_proc_body(make_global,parent_has_class:boolean);
  22. { reads the declaration blocks }
  23. procedure read_declarations(islibrary : boolean);
  24. { reads declarations in the interface part of a unit }
  25. procedure read_interface_declarations;
  26. implementation
  27. uses
  28. { common }
  29. cutils,cclasses,
  30. { global }
  31. globtype,globals,tokens,verbose,comphook,
  32. systems,
  33. { aasm }
  34. cpubase,aasm,
  35. { symtable }
  36. symconst,symbase,symdef,symsym,symtable,types,
  37. ppu,fmodule,
  38. { pass 1 }
  39. node,
  40. nbas,
  41. { pass 2 }
  42. {$ifndef NOPASS2}
  43. pass_1,pass_2,
  44. {$endif}
  45. { parser }
  46. scanner,
  47. pbase,pstatmnt,pdecl,pdecsub,pexports,
  48. { codegen }
  49. tgcpu,hcodegen
  50. {$ifdef newcg}
  51. ,cgbase
  52. ,cgobj
  53. {$ifndef NOOPT}
  54. ,aopt
  55. {$endif}
  56. {$else}
  57. ,temp_gen
  58. {$ifdef i386}
  59. ,cgai386
  60. {$ifndef NOOPT}
  61. ,aopt386
  62. {$endif}
  63. {$endif}
  64. {$endif}
  65. ;
  66. {****************************************************************************
  67. PROCEDURE/FUNCTION BODY PARSING
  68. ****************************************************************************}
  69. function block(islibrary : boolean) : tnode;
  70. var
  71. funcretsym : tfuncretsym;
  72. storepos : tfileposinfo;
  73. begin
  74. { do we have an assembler block without the po_assembler?
  75. we should allow this for Delphi compatibility (PFV) }
  76. if (token=_ASM) and (m_delphi in aktmodeswitches) then
  77. include(aktprocsym.definition.procoptions,po_assembler);
  78. { Handle assembler block different }
  79. if (po_assembler in aktprocsym.definition.procoptions) then
  80. begin
  81. read_declarations(false);
  82. block:=assembler_block;
  83. exit;
  84. end;
  85. if not is_void(procinfo^.returntype.def) then
  86. begin
  87. { if the current is a function aktprocsym is non nil }
  88. { and there is a local symtable set }
  89. storepos:=akttokenpos;
  90. akttokenpos:=aktprocsym.fileinfo;
  91. funcretsym:=tfuncretsym.create(aktprocsym.name,procinfo);
  92. { insert in local symtable }
  93. symtablestack.insert(funcretsym);
  94. akttokenpos:=storepos;
  95. if ret_in_acc(procinfo^.returntype.def) or (procinfo^.returntype.def.deftype=floatdef) then
  96. procinfo^.return_offset:=-funcretsym.address;
  97. procinfo^.funcretsym:=funcretsym;
  98. { insert result also if support is on }
  99. if (m_result in aktmodeswitches) then
  100. begin
  101. procinfo^.resultfuncretsym:=tfuncretsym.create('RESULT',procinfo);
  102. symtablestack.insert(procinfo^.resultfuncretsym);
  103. end;
  104. end;
  105. read_declarations(islibrary);
  106. { temporary space is set, while the BEGIN of the procedure }
  107. if (symtablestack.symtabletype=localsymtable) then
  108. procinfo^.firsttemp_offset := -symtablestack.datasize
  109. else
  110. procinfo^.firsttemp_offset := 0;
  111. { space for the return value }
  112. { !!!!! this means that we can not set the return value
  113. in a subfunction !!!!! }
  114. { because we don't know yet where the address is }
  115. if not is_void(procinfo^.returntype.def) then
  116. begin
  117. if ret_in_acc(procinfo^.returntype.def) or (procinfo^.returntype.def.deftype=floatdef) then
  118. begin
  119. { the space has been set in the local symtable }
  120. procinfo^.return_offset:=-funcretsym.address;
  121. if ((procinfo^.flags and pi_operator)<>0) and
  122. assigned(otsym) then
  123. otsym.address:=-procinfo^.return_offset;
  124. { eax is modified by a function }
  125. {$ifndef newcg}
  126. {$ifdef i386}
  127. usedinproc:=usedinproc or ($80 shr byte(R_EAX));
  128. if is_64bitint(procinfo^.returntype.def) then
  129. usedinproc:=usedinproc or ($80 shr byte(R_EDX))
  130. {$endif}
  131. {$ifdef m68k}
  132. usedinproc:=usedinproc + [accumulator];
  133. if is_64bitint(procinfo^.returntype.def) then
  134. usedinproc:=usedinproc + [scratch_reg];
  135. {$endif}
  136. {$endif newcg}
  137. end;
  138. end;
  139. {Unit initialization?.}
  140. if (lexlevel=unit_init_level) and (current_module.is_unit)
  141. or islibrary then
  142. begin
  143. if (token=_END) then
  144. begin
  145. consume(_END);
  146. { We need at least a node, else the entry/exit code is not
  147. generated and thus no PASCALMAIN symbol which we need (PFV) }
  148. if islibrary then
  149. block:=cnothingnode.create
  150. else
  151. block:=nil;
  152. end
  153. else
  154. begin
  155. if token=_INITIALIZATION then
  156. begin
  157. current_module.flags:=current_module.flags or uf_init;
  158. block:=statement_block(_INITIALIZATION);
  159. end
  160. else if (token=_FINALIZATION) then
  161. begin
  162. if (current_module.flags and uf_finalize)<>0 then
  163. block:=statement_block(_FINALIZATION)
  164. else
  165. begin
  166. { can we allow no INITIALIZATION for DLL ??
  167. I think it should work PM }
  168. block:=nil;
  169. exit;
  170. end;
  171. end
  172. else
  173. begin
  174. current_module.flags:=current_module.flags or uf_init;
  175. block:=statement_block(_BEGIN);
  176. end;
  177. end;
  178. end
  179. else
  180. block:=statement_block(_BEGIN);
  181. end;
  182. {****************************************************************************
  183. PROCEDURE/FUNCTION COMPILING
  184. ****************************************************************************}
  185. procedure compile_proc_body(make_global,parent_has_class:boolean);
  186. {
  187. Compile the body of a procedure
  188. }
  189. var
  190. oldexitlabel,oldexit2label : tasmlabel;
  191. oldfaillabel,oldquickexitlabel:tasmlabel;
  192. _class,hp:tobjectdef;
  193. { switches can change inside the procedure }
  194. entryswitches, exitswitches : tlocalswitches;
  195. oldaktmaxfpuregisters,localmaxfpuregisters : longint;
  196. { code for the subroutine as tree }
  197. code:tnode;
  198. { size of the local strackframe }
  199. stackframe:longint;
  200. { true when no stackframe is required }
  201. nostackframe:boolean;
  202. { number of bytes which have to be cleared by RET }
  203. parasize:longint;
  204. { filepositions }
  205. entrypos,
  206. savepos,
  207. exitpos : tfileposinfo;
  208. begin
  209. { calculate the lexical level }
  210. inc(lexlevel);
  211. if lexlevel>32 then
  212. Message(parser_e_too_much_lexlevel);
  213. { static is also important for local procedures !! }
  214. if (po_staticmethod in aktprocsym.definition.procoptions) then
  215. allow_only_static:=true
  216. else if (lexlevel=normal_function_level) then
  217. allow_only_static:=false;
  218. { save old labels }
  219. oldexitlabel:=aktexitlabel;
  220. oldexit2label:=aktexit2label;
  221. oldquickexitlabel:=quickexitlabel;
  222. oldfaillabel:=faillabel;
  223. { get new labels }
  224. getlabel(aktexitlabel);
  225. getlabel(aktexit2label);
  226. { exit for fail in constructors }
  227. if (aktprocsym.definition.proctypeoption=potype_constructor) then
  228. begin
  229. getlabel(faillabel);
  230. getlabel(quickexitlabel);
  231. end;
  232. { reset break and continue labels }
  233. block_type:=bt_general;
  234. aktbreaklabel:=nil;
  235. aktcontinuelabel:=nil;
  236. { insert symtables for the class, by only if it is no nested function }
  237. if assigned(procinfo^._class) and not(parent_has_class) then
  238. begin
  239. { insert them in the reverse order ! }
  240. hp:=nil;
  241. repeat
  242. _class:=procinfo^._class;
  243. while _class.childof<>hp do
  244. _class:=_class.childof;
  245. hp:=_class;
  246. _class.symtable.next:=symtablestack;
  247. symtablestack:=_class.symtable;
  248. until hp=procinfo^._class;
  249. end;
  250. { insert parasymtable in symtablestack}
  251. { only if lexlevel > 1 !!! global symtable should be right after staticsymtazble
  252. for checking of same names used in interface and implementation !! }
  253. if lexlevel>=normal_function_level then
  254. begin
  255. aktprocsym.definition.parast.next:=symtablestack;
  256. symtablestack:=aktprocsym.definition.parast;
  257. symtablestack.symtablelevel:=lexlevel;
  258. end;
  259. { insert localsymtable in symtablestack}
  260. aktprocsym.definition.localst.next:=symtablestack;
  261. symtablestack:=aktprocsym.definition.localst;
  262. symtablestack.symtablelevel:=lexlevel;
  263. { constant symbols are inserted in this symboltable }
  264. constsymtable:=symtablestack;
  265. { reset the temporary memory }
  266. cleartempgen;
  267. {$ifdef newcg}
  268. tg.usedinproc:=[];
  269. {$else newcg}
  270. {$ifdef i386}
  271. { no registers are used }
  272. usedinproc:=0;
  273. {$else}
  274. usedinproc := [];
  275. {$endif}
  276. {$endif newcg}
  277. { save entry info }
  278. entrypos:=aktfilepos;
  279. entryswitches:=aktlocalswitches;
  280. localmaxfpuregisters:=aktmaxfpuregisters;
  281. { parse the code ... }
  282. code:=block(current_module.islibrary);
  283. { get a better entry point }
  284. if assigned(code) then
  285. entrypos:=code.fileinfo;
  286. { save exit info }
  287. exitswitches:=aktlocalswitches;
  288. exitpos:=last_endtoken_filepos;
  289. { save current filepos }
  290. savepos:=aktfilepos;
  291. {When we are called to compile the body of a unit, aktprocsym should
  292. point to the unit initialization. If the unit has no initialization,
  293. aktprocsym=nil. But in that case code=nil. hus we should check for
  294. code=nil, when we use aktprocsym.}
  295. { set the framepointer to esp for assembler functions }
  296. { but only if the are no local variables }
  297. { already done in assembler_block }
  298. {$ifdef newcg}
  299. tg.setfirsttemp(procinfo^.firsttemp_offset);
  300. {$else newcg}
  301. setfirsttemp(procinfo^.firsttemp_offset);
  302. {$endif newcg}
  303. { ... and generate assembler }
  304. { but set the right switches for entry !! }
  305. aktlocalswitches:=entryswitches;
  306. oldaktmaxfpuregisters:=aktmaxfpuregisters;
  307. aktmaxfpuregisters:=localmaxfpuregisters;
  308. if assigned(code) then
  309. begin
  310. { the procedure is now defined }
  311. aktprocsym.definition.forwarddef:=false;
  312. { only generate the code if no type errors are found, else
  313. finish at least the type checking pass }
  314. {$ifndef NOPASS2}
  315. if (status.errorcount=0) then
  316. begin
  317. generatecode(code);
  318. aktprocsym.definition.code:=code;
  319. {$ifdef newcg}
  320. stackframe:=tg.gettempsize;
  321. {$else newcg}
  322. stackframe:=gettempsize;
  323. {$endif newcg}
  324. { first generate entry code with the correct position and switches }
  325. aktfilepos:=entrypos;
  326. aktlocalswitches:=entryswitches;
  327. {$ifdef newcg}
  328. cg^.g_entrycode(procinfo^.aktentrycode,proc_names,make_global,stackframe,parasize,nostackframe,false);
  329. {$else newcg}
  330. genentrycode(procinfo^.aktentrycode,make_global,stackframe,parasize,nostackframe,false);
  331. {$endif newcg}
  332. { FPC_POPADDRSTACK destroys all registers (JM) }
  333. if (procinfo^.flags and (pi_needs_implicit_finally or pi_uses_exceptions)) <> 0 then
  334. begin
  335. {$ifdef i386}
  336. usedinproc := $ff;
  337. {$else}
  338. usedinproc := ALL_REGISTERS;
  339. {$endif}
  340. end;
  341. { now generate exit code with the correct position and switches }
  342. aktfilepos:=exitpos;
  343. aktlocalswitches:=exitswitches;
  344. {$ifdef newcg}
  345. cg^.g_exitcode(procinfo^.aktexitcode,parasize,nostackframe,false);
  346. {$else newcg}
  347. genexitcode(procinfo^.aktexitcode,parasize,nostackframe,false);
  348. {$endif newcg}
  349. { now all the registers used are known }
  350. {$ifdef newcg}
  351. aktprocsym.definition.usedregisters:=tg.usedinproc;
  352. {$else newcg}
  353. aktprocsym.definition.usedregisters:=usedinproc;
  354. {$endif newcg}
  355. procinfo^.aktproccode.insertlist(procinfo^.aktentrycode);
  356. procinfo^.aktproccode.concatlist(procinfo^.aktexitcode);
  357. {$ifdef i386}
  358. {$ifndef NoOpt}
  359. if (cs_optimize in aktglobalswitches) and
  360. { do not optimize pure assembler procedures }
  361. ((procinfo^.flags and pi_is_assembler)=0) then
  362. Optimize(procinfo^.aktproccode);
  363. {$endif NoOpt}
  364. {$endif i386}
  365. { save local data (casetable) also in the same file }
  366. if assigned(procinfo^.aktlocaldata) and
  367. (not procinfo^.aktlocaldata.empty) then
  368. begin
  369. procinfo^.aktproccode.concat(Tai_section.Create(sec_data));
  370. procinfo^.aktproccode.concatlist(procinfo^.aktlocaldata);
  371. procinfo^.aktproccode.concat(Tai_section.Create(sec_code));
  372. end;
  373. { add the procedure to the codesegment }
  374. if (cs_create_smart in aktmoduleswitches) then
  375. codeSegment.concat(Tai_cut.Create);
  376. codeSegment.concatlist(procinfo^.aktproccode);
  377. end
  378. else
  379. do_resulttypepass(code);
  380. {$else NOPASS2}
  381. do_resulttypepass(code);
  382. {$endif NOPASS2}
  383. end;
  384. { ... remove symbol tables }
  385. if lexlevel>=normal_function_level then
  386. symtablestack:=symtablestack.next.next
  387. else
  388. symtablestack:=symtablestack.next;
  389. { ... check for unused symbols }
  390. { but only if there is no asm block }
  391. if assigned(code) then
  392. begin
  393. if (Errorcount=0) then
  394. begin
  395. tstoredsymtable(aktprocsym.definition.localst).check_forwards;
  396. tstoredsymtable(aktprocsym.definition.localst).checklabels;
  397. end;
  398. if (procinfo^.flags and pi_uses_asm)=0 then
  399. begin
  400. { not for unit init, becuase the var can be used in finalize,
  401. it will be done in proc_unit }
  402. if not(aktprocsym.definition.proctypeoption
  403. in [potype_proginit,potype_unitinit,potype_unitfinalize]) then
  404. tstoredsymtable(aktprocsym.definition.localst).allsymbolsused;
  405. tstoredsymtable(aktprocsym.definition.parast).allsymbolsused;
  406. end;
  407. end;
  408. { the local symtables can be deleted, but the parast }
  409. { doesn't, (checking definitons when calling a }
  410. { function }
  411. { not for a inline procedure !! (PM) }
  412. { at lexlevel = 1 localst is the staticsymtable itself }
  413. { so no dispose here !! }
  414. if assigned(code) and
  415. not(cs_browser in aktmoduleswitches) and
  416. not(pocall_inline in aktprocsym.definition.proccalloptions) then
  417. begin
  418. if lexlevel>=normal_function_level then
  419. aktprocsym.definition.localst.free;
  420. aktprocsym.definition.localst:=nil;
  421. end;
  422. {$ifdef newcg}
  423. { all registers can be used again }
  424. tg.resetusableregisters;
  425. { only now we can remove the temps }
  426. tg.resettempgen;
  427. {$else newcg}
  428. { all registers can be used again }
  429. resetusableregisters;
  430. { only now we can remove the temps }
  431. resettempgen;
  432. {$endif newcg}
  433. { remove code tree, if not inline procedure }
  434. if assigned(code) and not(pocall_inline in aktprocsym.definition.proccalloptions) then
  435. code.free;
  436. { remove class member symbol tables }
  437. while symtablestack.symtabletype=objectsymtable do
  438. symtablestack:=symtablestack.next;
  439. aktmaxfpuregisters:=oldaktmaxfpuregisters;
  440. { restore filepos, the switches are already set }
  441. aktfilepos:=savepos;
  442. { restore labels }
  443. aktexitlabel:=oldexitlabel;
  444. aktexit2label:=oldexit2label;
  445. quickexitlabel:=oldquickexitlabel;
  446. faillabel:=oldfaillabel;
  447. { reset to normal non static function }
  448. if (lexlevel=normal_function_level) then
  449. allow_only_static:=false;
  450. { previous lexlevel }
  451. dec(lexlevel);
  452. end;
  453. {****************************************************************************
  454. PROCEDURE/FUNCTION PARSING
  455. ****************************************************************************}
  456. procedure checkvaluepara(p:tnamedindexitem);
  457. var
  458. vs : tvarsym;
  459. s : string;
  460. begin
  461. with tvarsym(p) do
  462. begin
  463. if copy(name,1,3)='val' then
  464. begin
  465. s:=Copy(name,4,255);
  466. if not(po_assembler in aktprocsym.definition.procoptions) then
  467. begin
  468. vs:=tvarsym.create(s,vartype);
  469. vs.fileinfo:=fileinfo;
  470. vs.varspez:=varspez;
  471. aktprocsym.definition.localst.insert(vs);
  472. include(vs.varoptions,vo_is_local_copy);
  473. vs.varstate:=vs_assigned;
  474. localvarsym:=vs;
  475. inc(refs); { the para was used to set the local copy ! }
  476. { warnings only on local copy ! }
  477. varstate:=vs_used;
  478. end
  479. else
  480. begin
  481. aktprocsym.definition.parast.rename(name,s);
  482. end;
  483. end;
  484. end;
  485. end;
  486. procedure read_proc;
  487. {
  488. Parses the procedure directives, then parses the procedure body, then
  489. generates the code for it
  490. }
  491. var
  492. oldprefix : string;
  493. oldprocsym : tprocsym;
  494. oldprocinfo : pprocinfo;
  495. oldconstsymtable : tsymtable;
  496. oldfilepos : tfileposinfo;
  497. pdflags : word;
  498. prevdef,stdef : tprocdef;
  499. begin
  500. { save old state }
  501. oldprocsym:=aktprocsym;
  502. oldprefix:=procprefix;
  503. oldconstsymtable:=constsymtable;
  504. oldprocinfo:=procinfo;
  505. { create a new procedure }
  506. codegen_newprocedure;
  507. with procinfo^ do
  508. begin
  509. parent:=oldprocinfo;
  510. { clear flags }
  511. flags:=0;
  512. { standard frame pointer }
  513. framepointer:=frame_pointer;
  514. { funcret_is_valid:=false; }
  515. funcret_state:=vs_declared;
  516. { is this a nested function of a method ? }
  517. if assigned(oldprocinfo) then
  518. _class:=oldprocinfo^._class;
  519. end;
  520. parse_proc_dec;
  521. procinfo^.sym:=aktprocsym;
  522. procinfo^.def:=aktprocsym.definition;
  523. { set the default function options }
  524. if parse_only then
  525. begin
  526. aktprocsym.definition.forwarddef:=true;
  527. { set also the interface flag, for better error message when the
  528. implementation doesn't much this header }
  529. aktprocsym.definition.interfacedef:=true;
  530. pdflags:=pd_interface;
  531. end
  532. else
  533. begin
  534. pdflags:=pd_body;
  535. if current_module.in_implementation then
  536. pdflags:=pdflags or pd_implemen;
  537. if (not current_module.is_unit) or (cs_create_smart in aktmoduleswitches) then
  538. pdflags:=pdflags or pd_global;
  539. procinfo^.exported:=false;
  540. aktprocsym.definition.forwarddef:=false;
  541. end;
  542. { parse the directives that may follow }
  543. inc(lexlevel);
  544. parse_proc_directives(pdflags);
  545. dec(lexlevel);
  546. { hint directives, these can be separated by semicolons here,
  547. that need to be handled here with a loop (PFV) }
  548. while try_consume_hintdirective(aktprocsym.symoptions) do
  549. Consume(_SEMICOLON);
  550. { set aktfilepos to the beginning of the function declaration }
  551. oldfilepos:=aktfilepos;
  552. aktfilepos:=aktprocsym.definition.fileinfo;
  553. { search for forward declarations }
  554. if not check_identical_proc(prevdef) then
  555. begin
  556. { A method must be forward defined (in the object declaration) }
  557. if assigned(procinfo^._class) and (not assigned(oldprocinfo^._class)) then
  558. begin
  559. Message1(parser_e_header_dont_match_any_member,
  560. aktprocsym.definition.fullprocname);
  561. aktprocsym.write_parameter_lists(aktprocsym.definition);
  562. end
  563. else
  564. begin
  565. { Give a better error if there is a forward def in the interface and only
  566. a single implementation }
  567. if (not aktprocsym.definition.forwarddef) and
  568. assigned(aktprocsym.definition.nextoverloaded) and
  569. aktprocsym.definition.nextoverloaded.forwarddef and
  570. aktprocsym.definition.nextoverloaded.interfacedef and
  571. not(assigned(aktprocsym.definition.nextoverloaded.nextoverloaded)) then
  572. begin
  573. Message1(parser_e_header_dont_match_forward,
  574. aktprocsym.definition.fullprocname);
  575. aktprocsym.write_parameter_lists(aktprocsym.definition);
  576. end
  577. else
  578. begin
  579. { check the global flag }
  580. if (procinfo^.flags and pi_is_global)<>0 then
  581. Message(parser_e_overloaded_must_be_all_global);
  582. end;
  583. end;
  584. end;
  585. { set return type here, becuase the aktprocsym.definition can be
  586. changed by check_identical_proc (PFV) }
  587. procinfo^.returntype.def:=aktprocsym.definition.rettype.def;
  588. {$ifdef i386}
  589. if (po_interrupt in aktprocsym.definition.procoptions) then
  590. begin
  591. { we push Flags and CS as long
  592. to cope with the IRETD
  593. and we save 6 register + 4 selectors }
  594. inc(procinfo^.para_offset,8+6*4+4*2);
  595. end;
  596. {$endif i386}
  597. { pointer to the return value ? }
  598. if ret_in_param(procinfo^.returntype.def) then
  599. begin
  600. procinfo^.return_offset:=procinfo^.para_offset;
  601. inc(procinfo^.para_offset,target_info.size_of_pointer);
  602. end;
  603. { allows to access the parameters of main functions in nested functions }
  604. aktprocsym.definition.parast.address_fixup:=procinfo^.para_offset;
  605. { when it is a value para and it needs a local copy then rename
  606. the parameter and insert a copy in the localst. This is not done
  607. for assembler procedures }
  608. if (not parse_only) and (not aktprocsym.definition.forwarddef) then
  609. aktprocsym.definition.parast.foreach_static({$ifdef FPCPROCVAR}@{$endif}checkvaluepara);
  610. { restore file pos }
  611. aktfilepos:=oldfilepos;
  612. { compile procedure when a body is needed }
  613. if (pdflags and pd_body)<>0 then
  614. begin
  615. Message1(parser_p_procedure_start,
  616. aktprocsym.definition.fullprocname);
  617. aktprocsym.definition.aliasnames.insert(aktprocsym.definition.mangledname);
  618. { set _FAIL as keyword if constructor }
  619. if (aktprocsym.definition.proctypeoption=potype_constructor) then
  620. tokeninfo^[_FAIL].keyword:=m_all;
  621. if assigned(aktprocsym.definition._class) then
  622. tokeninfo^[_SELF].keyword:=m_all;
  623. compile_proc_body(((pdflags and pd_global)<>0),assigned(oldprocinfo^._class));
  624. { reset _FAIL as normal }
  625. if (aktprocsym.definition.proctypeoption=potype_constructor) then
  626. tokeninfo^[_FAIL].keyword:=m_none;
  627. if assigned(aktprocsym.definition._class) and (lexlevel=main_program_level) then
  628. tokeninfo^[_SELF].keyword:=m_none;
  629. consume(_SEMICOLON);
  630. end;
  631. { close }
  632. codegen_doneprocedure;
  633. { Restore old state }
  634. constsymtable:=oldconstsymtable;
  635. { from now on all refernece to mangledname means
  636. that the function is already used }
  637. aktprocsym.definition.count:=true;
  638. { restore the interface order to maintain CRC values PM }
  639. if assigned(prevdef) and assigned(aktprocsym.definition.nextoverloaded) then
  640. begin
  641. stdef:=aktprocsym.definition;
  642. aktprocsym.definition:=stdef.nextoverloaded;
  643. stdef.nextoverloaded:=prevdef.nextoverloaded;
  644. prevdef.nextoverloaded:=stdef;
  645. end;
  646. aktprocsym:=oldprocsym;
  647. procprefix:=oldprefix;
  648. procinfo:=oldprocinfo;
  649. otsym:=nil;
  650. end;
  651. {****************************************************************************
  652. DECLARATION PARSING
  653. ****************************************************************************}
  654. procedure read_declarations(islibrary : boolean);
  655. procedure Not_supported_for_inline(t : ttoken);
  656. begin
  657. if assigned(aktprocsym) and
  658. (pocall_inline in aktprocsym.definition.proccalloptions) then
  659. Begin
  660. Message1(parser_w_not_supported_for_inline,tokenstring(t));
  661. Message(parser_w_inlining_disabled);
  662. exclude(aktprocsym.definition.proccalloptions,pocall_inline);
  663. End;
  664. end;
  665. begin
  666. repeat
  667. case token of
  668. _LABEL:
  669. begin
  670. Not_supported_for_inline(token);
  671. label_dec;
  672. end;
  673. _CONST:
  674. begin
  675. Not_supported_for_inline(token);
  676. const_dec;
  677. end;
  678. _TYPE:
  679. begin
  680. Not_supported_for_inline(token);
  681. type_dec;
  682. end;
  683. _VAR:
  684. var_dec;
  685. _THREADVAR:
  686. threadvar_dec;
  687. _CONSTRUCTOR,_DESTRUCTOR,
  688. _FUNCTION,_PROCEDURE,_OPERATOR,_CLASS:
  689. begin
  690. Not_supported_for_inline(token);
  691. read_proc;
  692. end;
  693. _RESOURCESTRING:
  694. resourcestring_dec;
  695. _EXPORTS:
  696. begin
  697. Not_supported_for_inline(token);
  698. { here we should be at lexlevel 1, no ? PM }
  699. if (lexlevel<>main_program_level) or
  700. (current_module.is_unit) then
  701. begin
  702. Message(parser_e_syntax_error);
  703. consume_all_until(_SEMICOLON);
  704. end
  705. else if islibrary or (target_info.target=target_i386_WIN32)
  706. or (target_info.target=target_i386_Netware) then // AD
  707. read_exports;
  708. end
  709. else break;
  710. end;
  711. until false;
  712. end;
  713. procedure read_interface_declarations;
  714. begin
  715. {Since the body is now parsed at lexlevel 1, and the declarations
  716. must be parsed at the same lexlevel we increase the lexlevel.}
  717. inc(lexlevel);
  718. repeat
  719. case token of
  720. _CONST :
  721. const_dec;
  722. _TYPE :
  723. type_dec;
  724. _VAR :
  725. var_dec;
  726. _THREADVAR :
  727. threadvar_dec;
  728. _RESOURCESTRING:
  729. resourcestring_dec;
  730. _FUNCTION,
  731. _PROCEDURE,
  732. _OPERATOR :
  733. read_proc;
  734. else
  735. break;
  736. end;
  737. until false;
  738. dec(lexlevel);
  739. end;
  740. end.
  741. {
  742. $Log$
  743. Revision 1.33 2001-06-03 21:57:37 peter
  744. + hint directive parsing support
  745. Revision 1.32 2001/04/21 12:03:12 peter
  746. * m68k updates merged from fixes branch
  747. Revision 1.31 2001/04/18 22:01:57 peter
  748. * registration of targets and assemblers
  749. Revision 1.30 2001/04/14 14:05:47 peter
  750. * better skipping of secondpass if error
  751. Revision 1.29 2001/04/13 23:49:24 peter
  752. * when errors are found don't generate code, but still run the
  753. resulttype pass
  754. Revision 1.28 2001/04/13 17:59:03 peter
  755. * don't generate code when there is already an error
  756. Revision 1.27 2001/04/13 01:22:13 peter
  757. * symtable change to classes
  758. * range check generation and errors fixed, make cycle DEBUG=1 works
  759. * memory leaks fixed
  760. Revision 1.26 2001/04/02 21:20:34 peter
  761. * resulttype rewrite
  762. Revision 1.25 2001/02/26 19:44:53 peter
  763. * merged generic m68k updates from fixes branch
  764. Revision 1.24 2000/12/25 00:07:27 peter
  765. + new tlinkedlist class (merge of old tstringqueue,tcontainer and
  766. tlinkedlist objects)
  767. Revision 1.23 2000/11/29 00:30:37 florian
  768. * unused units removed from uses clause
  769. * some changes for widestrings
  770. Revision 1.22 2000/11/08 16:38:24 jonas
  771. * if a procedure uses exceptions (be it implicit or explicit), the
  772. usedregisters are set to all (because FPC_POPADDRSTACK doesn't save
  773. any registers) ("merged", fixes make cycle woth -Or)
  774. Revision 1.21 2000/11/01 23:04:38 peter
  775. * tprocdef.fullprocname added for better casesensitve writing of
  776. procedures
  777. Revision 1.20 2000/10/31 22:02:50 peter
  778. * symtable splitted, no real code changes
  779. Revision 1.19 2000/10/24 22:21:25 peter
  780. * set usedregisters after writing entry and exit code (merged)
  781. Revision 1.18 2000/10/21 18:16:12 florian
  782. * a lot of changes:
  783. - basic dyn. array support
  784. - basic C++ support
  785. - some work for interfaces done
  786. ....
  787. Revision 1.17 2000/10/15 07:47:51 peter
  788. * unit names and procedure names are stored mixed case
  789. Revision 1.16 2000/10/14 10:14:52 peter
  790. * moehrendorf oct 2000 rewrite
  791. Revision 1.15 2000/09/24 21:33:47 peter
  792. * message updates merges
  793. Revision 1.14 2000/09/24 21:19:51 peter
  794. * delphi compile fixes
  795. Revision 1.13 2000/09/24 15:06:24 peter
  796. * use defines.inc
  797. Revision 1.12 2000/09/10 20:11:07 peter
  798. * overload checking in implementation removed (merged)
  799. Revision 1.11 2000/09/04 20:15:19 peter
  800. * fixed operator overloading
  801. Revision 1.10 2000/08/27 16:11:52 peter
  802. * moved some util functions from globals,cobjects to cutils
  803. * splitted files into finput,fmodule
  804. Revision 1.9 2000/08/16 18:33:54 peter
  805. * splitted namedobjectitem.next into indexnext and listnext so it
  806. can be used in both lists
  807. * don't allow "word = word" type definitions (merged)
  808. Revision 1.8 2000/08/13 12:54:56 peter
  809. * class member decl wrong then no other error after it
  810. * -vb has now also line numbering
  811. * -vb is also used for interface/implementation different decls and
  812. doesn't list the current function (merged)
  813. Revision 1.7 2000/08/08 19:28:57 peter
  814. * memdebug/memory patches (merged)
  815. * only once illegal directive (merged)
  816. Revision 1.6 2000/08/06 19:39:28 peter
  817. * default parameters working !
  818. Revision 1.5 2000/08/06 14:17:15 peter
  819. * overload fixes (merged)
  820. Revision 1.4 2000/07/30 17:04:43 peter
  821. * merged fixes
  822. Revision 1.3 2000/07/13 12:08:27 michael
  823. + patched to 1.1.0 with former 1.09patch from peter
  824. Revision 1.2 2000/07/13 11:32:46 michael
  825. + removed logs
  826. }