pstatmnt.pas 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Does the parsing of the statements
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit pstatmnt;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. tokens,node;
  22. function statement_block(starttoken : ttoken) : tnode;
  23. { reads an assembler block }
  24. function assembler_block : tnode;
  25. implementation
  26. uses
  27. { common }
  28. cutils,cclasses,
  29. { global }
  30. globtype,globals,verbose,constexp,
  31. systems,
  32. { aasm }
  33. cpubase,aasmbase,aasmtai,aasmdata,
  34. { symtable }
  35. symconst,symbase,symtype,symdef,symsym,symtable,defutil,defcmp,
  36. paramgr,symutil,
  37. { pass 1 }
  38. pass_1,htypechk,
  39. nutils,nbas,nmat,nadd,ncal,nmem,nset,ncnv,ninl,ncon,nld,nflw,
  40. { parser }
  41. scanner,
  42. pbase,pexpr,
  43. { codegen }
  44. procinfo,cgbase,
  45. { assembler reader }
  46. rabase,
  47. { wide- and unicodestrings}
  48. widestr
  49. ;
  50. function statement : tnode;forward;
  51. function if_statement : tnode;
  52. var
  53. ex,if_a,else_a : tnode;
  54. begin
  55. consume(_IF);
  56. ex:=comp_expr(true,false);
  57. consume(_THEN);
  58. if token<>_ELSE then
  59. if_a:=statement
  60. else
  61. if_a:=nil;
  62. if try_to_consume(_ELSE) then
  63. else_a:=statement
  64. else
  65. else_a:=nil;
  66. result:=cifnode.create(ex,if_a,else_a);
  67. end;
  68. { creates a block (list) of statements, til the next END token }
  69. function statements_til_end : tnode;
  70. var
  71. first,last : tstatementnode;
  72. begin
  73. first:=nil;
  74. while token<>_END do
  75. begin
  76. if first=nil then
  77. begin
  78. last:=cstatementnode.create(statement,nil);
  79. first:=last;
  80. end
  81. else
  82. begin
  83. last.right:=cstatementnode.create(statement,nil);
  84. last:=tstatementnode(last.right);
  85. end;
  86. if not try_to_consume(_SEMICOLON) then
  87. break;
  88. consume_emptystats;
  89. end;
  90. consume(_END);
  91. statements_til_end:=cblocknode.create(first);
  92. end;
  93. function case_statement : tnode;
  94. var
  95. casedef : tdef;
  96. caseexpr,p : tnode;
  97. blockid : longint;
  98. hl1,hl2 : TConstExprInt;
  99. sl1,sl2 : tstringconstnode;
  100. casedeferror, caseofstring : boolean;
  101. casenode : tcasenode;
  102. begin
  103. consume(_CASE);
  104. caseexpr:=comp_expr(true,false);
  105. { determines result type }
  106. do_typecheckpass(caseexpr);
  107. { variants must be accepted, but first they must be converted to integer }
  108. if caseexpr.resultdef.typ=variantdef then
  109. begin
  110. caseexpr:=ctypeconvnode.create_internal(caseexpr,sinttype);
  111. do_typecheckpass(caseexpr);
  112. end;
  113. set_varstate(caseexpr,vs_read,[vsf_must_be_valid]);
  114. casedeferror:=false;
  115. casedef:=caseexpr.resultdef;
  116. { case of string must be rejected in delphi-, }
  117. { tp7/bp7-, mac-compatibility modes. }
  118. caseofstring :=
  119. ([m_delphi, m_mac, m_tp7] * current_settings.modeswitches = []) and
  120. is_string(casedef);
  121. if (not assigned(casedef)) or
  122. ( not(is_ordinal(casedef)) and (not caseofstring) ) then
  123. begin
  124. CGMessage(type_e_ordinal_or_string_expr_expected);
  125. { create a correct tree }
  126. caseexpr.free;
  127. caseexpr:=cordconstnode.create(0,u32inttype,false);
  128. { set error flag so no rangechecks are done }
  129. casedeferror:=true;
  130. end;
  131. { Create casenode }
  132. casenode:=ccasenode.create(caseexpr);
  133. consume(_OF);
  134. { Parse all case blocks }
  135. blockid:=0;
  136. repeat
  137. { maybe an instruction has more case labels }
  138. repeat
  139. p:=expr(true);
  140. if is_widechar(casedef) then
  141. begin
  142. if (p.nodetype=rangen) then
  143. begin
  144. trangenode(p).left:=ctypeconvnode.create(trangenode(p).left,cwidechartype);
  145. trangenode(p).right:=ctypeconvnode.create(trangenode(p).right,cwidechartype);
  146. do_typecheckpass(trangenode(p).left);
  147. do_typecheckpass(trangenode(p).right);
  148. end
  149. else
  150. begin
  151. p:=ctypeconvnode.create(p,cwidechartype);
  152. do_typecheckpass(p);
  153. end;
  154. end;
  155. hl1:=0;
  156. hl2:=0;
  157. sl1:=nil;
  158. sl2:=nil;
  159. if (p.nodetype=rangen) then
  160. begin
  161. { type check for string case statements }
  162. if caseofstring and
  163. is_conststring_or_constcharnode(trangenode(p).left) and
  164. is_conststring_or_constcharnode(trangenode(p).right) then
  165. begin
  166. { we need stringconstnodes, even if expression contains single chars }
  167. sl1 := get_string_value(trangenode(p).left, tstringdef(casedef));
  168. sl2 := get_string_value(trangenode(p).right, tstringdef(casedef));
  169. if sl1.fullcompare(sl2) > 0 then
  170. CGMessage(parser_e_case_lower_less_than_upper_bound);
  171. end
  172. { type checking for ordinal case statements }
  173. else if (not caseofstring) and
  174. is_subequal(casedef, trangenode(p).left.resultdef) and
  175. is_subequal(casedef, trangenode(p).right.resultdef) then
  176. begin
  177. hl1:=get_ordinal_value(trangenode(p).left);
  178. hl2:=get_ordinal_value(trangenode(p).right);
  179. if hl1>hl2 then
  180. CGMessage(parser_e_case_lower_less_than_upper_bound);
  181. if not casedeferror then
  182. begin
  183. testrange(casedef,hl1,false,false);
  184. testrange(casedef,hl2,false,false);
  185. end;
  186. end
  187. else
  188. CGMessage(parser_e_case_mismatch);
  189. if caseofstring then
  190. casenode.addlabel(blockid,sl1,sl2)
  191. else
  192. casenode.addlabel(blockid,hl1,hl2);
  193. end
  194. else
  195. begin
  196. { type check for string case statements }
  197. if (caseofstring and (not is_conststring_or_constcharnode(p))) or
  198. { type checking for ordinal case statements }
  199. ((not caseofstring) and (not is_subequal(casedef, p.resultdef))) then
  200. CGMessage(parser_e_case_mismatch);
  201. if caseofstring then
  202. begin
  203. sl1:=get_string_value(p, tstringdef(casedef));
  204. casenode.addlabel(blockid,sl1,sl1);
  205. end
  206. else
  207. begin
  208. hl1:=get_ordinal_value(p);
  209. if not casedeferror then
  210. testrange(casedef,hl1,false,false);
  211. casenode.addlabel(blockid,hl1,hl1);
  212. end;
  213. end;
  214. p.free;
  215. sl1.free;
  216. sl2.free;
  217. if token=_COMMA then
  218. consume(_COMMA)
  219. else
  220. break;
  221. until false;
  222. consume(_COLON);
  223. { add instruction block }
  224. casenode.addblock(blockid,statement);
  225. { next block }
  226. inc(blockid);
  227. if not(token in [_ELSE,_OTHERWISE,_END]) then
  228. consume(_SEMICOLON);
  229. until (token in [_ELSE,_OTHERWISE,_END]);
  230. if (token in [_ELSE,_OTHERWISE]) then
  231. begin
  232. if not try_to_consume(_ELSE) then
  233. consume(_OTHERWISE);
  234. casenode.addelseblock(statements_til_end);
  235. end
  236. else
  237. consume(_END);
  238. result:=casenode;
  239. end;
  240. function repeat_statement : tnode;
  241. var
  242. first,last,p_e : tnode;
  243. begin
  244. consume(_REPEAT);
  245. first:=nil;
  246. while token<>_UNTIL do
  247. begin
  248. if first=nil then
  249. begin
  250. last:=cstatementnode.create(statement,nil);
  251. first:=last;
  252. end
  253. else
  254. begin
  255. tstatementnode(last).right:=cstatementnode.create(statement,nil);
  256. last:=tstatementnode(last).right;
  257. end;
  258. if not try_to_consume(_SEMICOLON) then
  259. break;
  260. consume_emptystats;
  261. end;
  262. consume(_UNTIL);
  263. first:=cblocknode.create(first);
  264. p_e:=comp_expr(true,false);
  265. result:=cwhilerepeatnode.create(p_e,first,false,true);
  266. end;
  267. function while_statement : tnode;
  268. var
  269. p_e,p_a : tnode;
  270. begin
  271. consume(_WHILE);
  272. p_e:=comp_expr(true,false);
  273. consume(_DO);
  274. p_a:=statement;
  275. result:=cwhilerepeatnode.create(p_e,p_a,true,false);
  276. end;
  277. function for_statement : tnode;
  278. procedure check_range(hp:tnode; fordef: tdef);
  279. begin
  280. if (hp.nodetype=ordconstn) and
  281. (fordef.typ<>errordef) then
  282. testrange(fordef,tordconstnode(hp).value,false,true);
  283. end;
  284. function for_loop_create(hloopvar: tnode): tnode;
  285. var
  286. hp,
  287. hblock,
  288. hto,hfrom : tnode;
  289. backward : boolean;
  290. loopvarsym : tabstractvarsym;
  291. begin
  292. { Check loop variable }
  293. loopvarsym:=nil;
  294. { variable must be an ordinal, int64 is not allowed for 32bit targets }
  295. if not(is_ordinal(hloopvar.resultdef))
  296. {$ifndef cpu64bitaddr}
  297. or is_64bitint(hloopvar.resultdef)
  298. {$endif not cpu64bitaddr}
  299. then
  300. MessagePos(hloopvar.fileinfo,type_e_ordinal_expr_expected);
  301. hp:=hloopvar;
  302. while assigned(hp) and
  303. (
  304. { record/object fields and array elements are allowed }
  305. { in tp7 mode only }
  306. (
  307. (m_tp7 in current_settings.modeswitches) and
  308. (
  309. ((hp.nodetype=subscriptn) and
  310. ((tsubscriptnode(hp).left.resultdef.typ=recorddef) or
  311. is_object(tsubscriptnode(hp).left.resultdef))
  312. ) or
  313. { constant array index }
  314. (
  315. (hp.nodetype=vecn) and
  316. is_constintnode(tvecnode(hp).right)
  317. )
  318. )
  319. ) or
  320. { equal typeconversions }
  321. (
  322. (hp.nodetype=typeconvn) and
  323. (ttypeconvnode(hp).convtype=tc_equal)
  324. )
  325. ) do
  326. begin
  327. { Use the recordfield for loopvarsym }
  328. if not assigned(loopvarsym) and
  329. (hp.nodetype=subscriptn) then
  330. loopvarsym:=tsubscriptnode(hp).vs;
  331. hp:=tunarynode(hp).left;
  332. end;
  333. if assigned(hp) and
  334. (hp.nodetype=loadn) then
  335. begin
  336. case tloadnode(hp).symtableentry.typ of
  337. staticvarsym,
  338. localvarsym,
  339. paravarsym :
  340. begin
  341. { we need a simple loadn:
  342. 1. The load must be in a global symtable or
  343. in the same level as the para of the current proc.
  344. 2. value variables (no const,out or var)
  345. 3. No threadvar, readonly or typedconst
  346. }
  347. if (
  348. (tloadnode(hp).symtable.symtablelevel=main_program_level) or
  349. (tloadnode(hp).symtable.symtablelevel=current_procinfo.procdef.parast.symtablelevel)
  350. ) and
  351. (tabstractvarsym(tloadnode(hp).symtableentry).varspez=vs_value) and
  352. ([vo_is_thread_var,vo_is_typed_const] * tabstractvarsym(tloadnode(hp).symtableentry).varoptions=[]) then
  353. begin
  354. { Assigning for-loop variable is only allowed in tp7 and macpas }
  355. if ([m_tp7,m_mac] * current_settings.modeswitches = []) then
  356. begin
  357. if not assigned(loopvarsym) then
  358. loopvarsym:=tabstractvarsym(tloadnode(hp).symtableentry);
  359. include(loopvarsym.varoptions,vo_is_loop_counter);
  360. end;
  361. end
  362. else
  363. begin
  364. { Typed const is allowed in tp7 }
  365. if not(m_tp7 in current_settings.modeswitches) or
  366. not(vo_is_typed_const in tabstractvarsym(tloadnode(hp).symtableentry).varoptions) then
  367. MessagePos(hp.fileinfo,type_e_illegal_count_var);
  368. end;
  369. end;
  370. else
  371. MessagePos(hp.fileinfo,type_e_illegal_count_var);
  372. end;
  373. end
  374. else
  375. MessagePos(hloopvar.fileinfo,type_e_illegal_count_var);
  376. hfrom:=comp_expr(true,false);
  377. if try_to_consume(_DOWNTO) then
  378. backward:=true
  379. else
  380. begin
  381. consume(_TO);
  382. backward:=false;
  383. end;
  384. hto:=comp_expr(true,false);
  385. consume(_DO);
  386. { Check if the constants fit in the range }
  387. check_range(hfrom,hloopvar.resultdef);
  388. check_range(hto,hloopvar.resultdef);
  389. { first set the varstate for from and to, so
  390. uses of loopvar in those expressions will also
  391. trigger a warning when it is not used yet. This
  392. needs to be done before the instruction block is
  393. parsed to have a valid hloopvar }
  394. typecheckpass(hfrom);
  395. set_varstate(hfrom,vs_read,[vsf_must_be_valid]);
  396. typecheckpass(hto);
  397. set_varstate(hto,vs_read,[vsf_must_be_valid]);
  398. typecheckpass(hloopvar);
  399. { in two steps, because vs_readwritten may turn on vsf_must_be_valid }
  400. { for some subnodes }
  401. set_varstate(hloopvar,vs_written,[]);
  402. set_varstate(hloopvar,vs_read,[vsf_must_be_valid]);
  403. { ... now the instruction block }
  404. hblock:=statement;
  405. { variable is not used for loop counter anymore }
  406. if assigned(loopvarsym) then
  407. exclude(loopvarsym.varoptions,vo_is_loop_counter);
  408. result:=cfornode.create(hloopvar,hfrom,hto,hblock,backward);
  409. end;
  410. function for_in_loop_create(hloopvar: tnode): tnode;
  411. var
  412. expr: tnode;
  413. begin
  414. expr:=comp_expr(true,false);
  415. consume(_DO);
  416. set_varstate(hloopvar,vs_written,[]);
  417. set_varstate(hloopvar,vs_read,[vsf_must_be_valid]);
  418. result:=create_for_in_loop(hloopvar,statement,expr);
  419. expr.free;
  420. end;
  421. var
  422. hloopvar: tnode;
  423. begin
  424. { parse loop header }
  425. consume(_FOR);
  426. hloopvar:=factor(false,false);
  427. valid_for_loopvar(hloopvar,true);
  428. if try_to_consume(_ASSIGNMENT) then
  429. result:=for_loop_create(hloopvar)
  430. else if try_to_consume(_IN) then
  431. result:=for_in_loop_create(hloopvar)
  432. else
  433. consume(_ASSIGNMENT); // fail
  434. end;
  435. function _with_statement : tnode;
  436. var
  437. p : tnode;
  438. i : longint;
  439. st : TSymtable;
  440. newblock : tblocknode;
  441. newstatement : tstatementnode;
  442. calltempnode,
  443. tempnode : ttempcreatenode;
  444. valuenode,
  445. hp,
  446. refnode : tnode;
  447. hdef : tdef;
  448. extendeddef : tabstractrecorddef;
  449. helperdef : tobjectdef;
  450. hasimplicitderef : boolean;
  451. withsymtablelist : TFPObjectList;
  452. procedure pushobjchild(withdef,obj:tobjectdef);
  453. var
  454. parenthelperdef : tobjectdef;
  455. begin
  456. if not assigned(obj) then
  457. exit;
  458. pushobjchild(withdef,obj.childof);
  459. { we need to look for helpers that were defined for the parent
  460. class as well }
  461. search_last_objectpascal_helper(obj,current_structdef,parenthelperdef);
  462. { push the symtables of the helper's parents in reverse order }
  463. if assigned(parenthelperdef) then
  464. pushobjchild(withdef,parenthelperdef.childof);
  465. { keep the original tobjectdef as owner, because that is used for
  466. visibility of the symtable }
  467. st:=twithsymtable.create(withdef,obj.symtable.SymList,refnode.getcopy);
  468. symtablestack.push(st);
  469. withsymtablelist.add(st);
  470. { push the symtable of the helper }
  471. if assigned(parenthelperdef) then
  472. begin
  473. st:=twithsymtable.create(withdef,parenthelperdef.symtable.SymList,refnode.getcopy);
  474. symtablestack.push(st);
  475. withsymtablelist.add(st);
  476. end;
  477. end;
  478. begin
  479. p:=comp_expr(true,false);
  480. do_typecheckpass(p);
  481. if (p.nodetype=vecn) and
  482. (nf_memseg in p.flags) then
  483. CGMessage(parser_e_no_with_for_variable_in_other_segments);
  484. { "with procvar" can never mean anything, so always try
  485. to call it in case it returns a record/object/... }
  486. maybe_call_procvar(p,false);
  487. if (p.resultdef.typ in [objectdef,recorddef,classrefdef]) then
  488. begin
  489. newblock:=nil;
  490. valuenode:=nil;
  491. tempnode:=nil;
  492. { ignore nodes that don't add instructions in the tree }
  493. hp:=p;
  494. while { equal type conversions }
  495. (
  496. (hp.nodetype=typeconvn) and
  497. (ttypeconvnode(hp).convtype=tc_equal)
  498. ) or
  499. { constant array index }
  500. (
  501. (hp.nodetype=vecn) and
  502. (tvecnode(hp).right.nodetype=ordconstn)
  503. ) do
  504. hp:=tunarynode(hp).left;
  505. if (hp.nodetype=loadn) and
  506. (
  507. (tloadnode(hp).symtable=current_procinfo.procdef.localst) or
  508. (tloadnode(hp).symtable=current_procinfo.procdef.parast) or
  509. (tloadnode(hp).symtable.symtabletype in [staticsymtable,globalsymtable])
  510. ) and
  511. { MacPas objects are mapped to classes, and the MacPas compilers
  512. interpret with-statements with MacPas objects the same way
  513. as records (the object referenced by the with-statement
  514. must remain constant)
  515. }
  516. not(is_class(hp.resultdef) and
  517. (m_mac in current_settings.modeswitches)) then
  518. begin
  519. { simple load, we can reference direct }
  520. refnode:=p;
  521. end
  522. else
  523. begin
  524. calltempnode:=nil;
  525. { complex load, load in temp first }
  526. newblock:=internalstatements(newstatement);
  527. { when we can't take the address of p, load it in a temp }
  528. { since we may need its address later on }
  529. if not valid_for_addr(p,false) then
  530. begin
  531. calltempnode:=ctempcreatenode.create(p.resultdef,p.resultdef.size,tt_persistent,true);
  532. addstatement(newstatement,calltempnode);
  533. addstatement(newstatement,cassignmentnode.create(
  534. ctemprefnode.create(calltempnode),
  535. p));
  536. p:=ctemprefnode.create(calltempnode);
  537. typecheckpass(p);
  538. end;
  539. { several object types have implicit dereferencing }
  540. hasimplicitderef:=is_implicit_pointer_object_type(p.resultdef) or
  541. (p.resultdef.typ = classrefdef);
  542. if hasimplicitderef then
  543. hdef:=p.resultdef
  544. else
  545. hdef:=tpointerdef.create(p.resultdef);
  546. { load address of the value in a temp }
  547. tempnode:=ctempcreatenode.create_withnode(hdef,sizeof(pint),tt_persistent,true,p);
  548. typecheckpass(tnode(tempnode));
  549. valuenode:=p;
  550. refnode:=ctemprefnode.create(tempnode);
  551. fillchar(refnode.fileinfo,sizeof(tfileposinfo),0);
  552. { add address call for valuenode and deref for refnode if this
  553. is not done implicitly }
  554. if not hasimplicitderef then
  555. begin
  556. valuenode:=caddrnode.create_internal_nomark(valuenode);
  557. refnode:=cderefnode.create(refnode);
  558. fillchar(refnode.fileinfo,sizeof(tfileposinfo),0);
  559. end;
  560. addstatement(newstatement,tempnode);
  561. addstatement(newstatement,cassignmentnode.create(
  562. ctemprefnode.create(tempnode),
  563. valuenode));
  564. typecheckpass(refnode);
  565. end;
  566. { do we have a helper for this type? }
  567. if p.resultdef.typ=classrefdef then
  568. extendeddef:=tobjectdef(tclassrefdef(p.resultdef).pointeddef)
  569. else
  570. extendeddef:=tabstractrecorddef(p.resultdef);
  571. search_last_objectpascal_helper(extendeddef,current_structdef,helperdef);
  572. { Note: the symtable of the helper is pushed after the following
  573. "case", the symtables of the helper's parents are passed in
  574. the "case" branches }
  575. withsymtablelist:=TFPObjectList.create(true);
  576. case p.resultdef.typ of
  577. objectdef :
  578. begin
  579. { push symtables of all parents in reverse order }
  580. pushobjchild(tobjectdef(p.resultdef),tobjectdef(p.resultdef).childof);
  581. { push symtables of all parents of the helper in reverse order }
  582. if assigned(helperdef) then
  583. pushobjchild(helperdef,helperdef.childof);
  584. { push object symtable }
  585. st:=twithsymtable.Create(tobjectdef(p.resultdef),tobjectdef(p.resultdef).symtable.SymList,refnode);
  586. symtablestack.push(st);
  587. withsymtablelist.add(st);
  588. end;
  589. classrefdef :
  590. begin
  591. { push symtables of all parents in reverse order }
  592. pushobjchild(tobjectdef(tclassrefdef(p.resultdef).pointeddef),tobjectdef(tclassrefdef(p.resultdef).pointeddef).childof);
  593. { push symtables of all parents of the helper in reverse order }
  594. if assigned(helperdef) then
  595. pushobjchild(helperdef,helperdef.childof);
  596. { push object symtable }
  597. st:=twithsymtable.Create(tobjectdef(tclassrefdef(p.resultdef).pointeddef),tobjectdef(tclassrefdef(p.resultdef).pointeddef).symtable.SymList,refnode);
  598. symtablestack.push(st);
  599. withsymtablelist.add(st);
  600. end;
  601. recorddef :
  602. begin
  603. { push symtables of all parents of the helper in reverse order }
  604. if assigned(helperdef) then
  605. pushobjchild(helperdef,helperdef.childof);
  606. { push record symtable }
  607. st:=twithsymtable.create(trecorddef(p.resultdef),trecorddef(p.resultdef).symtable.SymList,refnode);
  608. symtablestack.push(st);
  609. withsymtablelist.add(st);
  610. end;
  611. else
  612. internalerror(200601271);
  613. end;
  614. { push helper symtable }
  615. if assigned(helperdef) then
  616. begin
  617. st:=twithsymtable.Create(helperdef,helperdef.symtable.SymList,refnode.getcopy);
  618. symtablestack.push(st);
  619. withsymtablelist.add(st);
  620. end;
  621. if try_to_consume(_COMMA) then
  622. p:=_with_statement()
  623. else
  624. begin
  625. consume(_DO);
  626. if token<>_SEMICOLON then
  627. p:=statement
  628. else
  629. p:=cnothingnode.create;
  630. end;
  631. { remove symtables in reverse order from the stack }
  632. for i:=withsymtablelist.count-1 downto 0 do
  633. symtablestack.pop(TSymtable(withsymtablelist[i]));
  634. withsymtablelist.free;
  635. // p:=cwithnode.create(right,twithsymtable(withsymtable),levelcount,refnode);
  636. { Finalize complex withnode with destroy of temp }
  637. if assigned(newblock) then
  638. begin
  639. addstatement(newstatement,p);
  640. if assigned(tempnode) then
  641. addstatement(newstatement,ctempdeletenode.create(tempnode));
  642. if assigned(calltempnode) then
  643. addstatement(newstatement,ctempdeletenode.create(calltempnode));
  644. p:=newblock;
  645. end;
  646. result:=p;
  647. end
  648. else
  649. begin
  650. p.free;
  651. Message(parser_e_false_with_expr);
  652. { try to recover from error }
  653. if try_to_consume(_COMMA) then
  654. begin
  655. hp:=_with_statement();
  656. if (hp=nil) then; { remove warning about unused }
  657. end
  658. else
  659. begin
  660. consume(_DO);
  661. { ignore all }
  662. if token<>_SEMICOLON then
  663. statement;
  664. end;
  665. result:=nil;
  666. end;
  667. end;
  668. function with_statement : tnode;
  669. begin
  670. consume(_WITH);
  671. with_statement:=_with_statement();
  672. end;
  673. function raise_statement : tnode;
  674. var
  675. p,pobj,paddr,pframe : tnode;
  676. begin
  677. pobj:=nil;
  678. paddr:=nil;
  679. pframe:=nil;
  680. consume(_RAISE);
  681. if not(token in endtokens) then
  682. begin
  683. { object }
  684. pobj:=comp_expr(true,false);
  685. if try_to_consume(_AT) then
  686. begin
  687. paddr:=comp_expr(true,false);
  688. if try_to_consume(_COMMA) then
  689. pframe:=comp_expr(true,false);
  690. end;
  691. end
  692. else
  693. begin
  694. if (block_type<>bt_except) then
  695. Message(parser_e_no_reraise_possible);
  696. end;
  697. p:=craisenode.create(pobj,paddr,pframe);
  698. raise_statement:=p;
  699. end;
  700. function try_statement : tnode;
  701. var
  702. p_try_block,p_finally_block,first,last,
  703. p_default,p_specific,hp : tnode;
  704. ot : tDef;
  705. sym : tlocalvarsym;
  706. old_block_type : tblock_type;
  707. excepTSymtable : TSymtable;
  708. objname,objrealname : TIDString;
  709. srsym : tsym;
  710. srsymtable : TSymtable;
  711. t:ttoken;
  712. unit_found:boolean;
  713. oldcurrent_exceptblock: integer;
  714. begin
  715. include(current_procinfo.flags,pi_uses_exceptions);
  716. p_default:=nil;
  717. p_specific:=nil;
  718. { read statements to try }
  719. consume(_TRY);
  720. first:=nil;
  721. inc(exceptblockcounter);
  722. oldcurrent_exceptblock := current_exceptblock;
  723. current_exceptblock := exceptblockcounter;
  724. while (token<>_FINALLY) and (token<>_EXCEPT) do
  725. begin
  726. if first=nil then
  727. begin
  728. last:=cstatementnode.create(statement,nil);
  729. first:=last;
  730. end
  731. else
  732. begin
  733. tstatementnode(last).right:=cstatementnode.create(statement,nil);
  734. last:=tstatementnode(last).right;
  735. end;
  736. if not try_to_consume(_SEMICOLON) then
  737. break;
  738. consume_emptystats;
  739. end;
  740. p_try_block:=cblocknode.create(first);
  741. if try_to_consume(_FINALLY) then
  742. begin
  743. inc(exceptblockcounter);
  744. current_exceptblock := exceptblockcounter;
  745. p_finally_block:=statements_til_end;
  746. try_statement:=ctryfinallynode.create(p_try_block,p_finally_block);
  747. end
  748. else
  749. begin
  750. consume(_EXCEPT);
  751. old_block_type:=block_type;
  752. block_type:=bt_except;
  753. inc(exceptblockcounter);
  754. current_exceptblock := exceptblockcounter;
  755. ot:=generrordef;
  756. p_specific:=nil;
  757. if (idtoken=_ON) then
  758. { catch specific exceptions }
  759. begin
  760. repeat
  761. consume(_ON);
  762. if token=_ID then
  763. begin
  764. objname:=pattern;
  765. objrealname:=orgpattern;
  766. { can't use consume_sym here, because we need already
  767. to check for the colon }
  768. searchsym(objname,srsym,srsymtable);
  769. consume(_ID);
  770. { is a explicit name for the exception given ? }
  771. if try_to_consume(_COLON) then
  772. begin
  773. consume_sym(srsym,srsymtable);
  774. if (srsym.typ=typesym) and
  775. is_class(ttypesym(srsym).typedef) then
  776. begin
  777. ot:=ttypesym(srsym).typedef;
  778. sym:=tlocalvarsym.create(objrealname,vs_value,ot,[]);
  779. end
  780. else
  781. begin
  782. sym:=tlocalvarsym.create(objrealname,vs_value,generrordef,[]);
  783. if (srsym.typ=typesym) then
  784. Message1(type_e_class_type_expected,ttypesym(srsym).typedef.typename)
  785. else
  786. Message1(type_e_class_type_expected,ot.typename);
  787. end;
  788. excepTSymtable:=tstt_excepTSymtable.create;
  789. excepTSymtable.insert(sym);
  790. symtablestack.push(excepTSymtable);
  791. end
  792. else
  793. begin
  794. { check if type is valid, must be done here because
  795. with "e: Exception" the e is not necessary }
  796. { support unit.identifier }
  797. unit_found:=try_consume_unitsym(srsym,srsymtable,t,false);
  798. if srsym=nil then
  799. begin
  800. identifier_not_found(orgpattern);
  801. srsym:=generrorsym;
  802. end;
  803. if unit_found then
  804. consume(t);
  805. { check if type is valid, must be done here because
  806. with "e: Exception" the e is not necessary }
  807. if (srsym.typ=typesym) and
  808. is_class(ttypesym(srsym).typedef) then
  809. ot:=ttypesym(srsym).typedef
  810. else
  811. begin
  812. ot:=generrordef;
  813. if (srsym.typ=typesym) then
  814. Message1(type_e_class_type_expected,ttypesym(srsym).typedef.typename)
  815. else
  816. Message1(type_e_class_type_expected,ot.typename);
  817. end;
  818. excepTSymtable:=nil;
  819. end;
  820. end
  821. else
  822. consume(_ID);
  823. consume(_DO);
  824. hp:=connode.create(nil,statement);
  825. if ot.typ=errordef then
  826. begin
  827. hp.free;
  828. hp:=cerrornode.create;
  829. end;
  830. if p_specific=nil then
  831. begin
  832. last:=hp;
  833. p_specific:=last;
  834. end
  835. else
  836. begin
  837. tonnode(last).left:=hp;
  838. last:=tonnode(last).left;
  839. end;
  840. { set the informations }
  841. { only if the creation of the onnode was succesful, it's possible }
  842. { that last and hp are errornodes (JM) }
  843. if last.nodetype = onn then
  844. begin
  845. tonnode(last).excepttype:=tobjectdef(ot);
  846. tonnode(last).excepTSymtable:=excepTSymtable;
  847. end;
  848. { remove exception symtable }
  849. if assigned(excepTSymtable) then
  850. begin
  851. symtablestack.pop(excepTSymtable);
  852. if last.nodetype <> onn then
  853. excepTSymtable.free;
  854. end;
  855. if not try_to_consume(_SEMICOLON) then
  856. break;
  857. consume_emptystats;
  858. until (token in [_END,_ELSE]);
  859. if try_to_consume(_ELSE) then
  860. begin
  861. { catch the other exceptions }
  862. p_default:=statements_til_end;
  863. end
  864. else
  865. consume(_END);
  866. end
  867. else
  868. begin
  869. { catch all exceptions }
  870. p_default:=statements_til_end;
  871. end;
  872. block_type:=old_block_type;
  873. try_statement:=ctryexceptnode.create(p_try_block,p_specific,p_default);
  874. end;
  875. current_exceptblock := oldcurrent_exceptblock;
  876. end;
  877. function _asm_statement : tnode;
  878. var
  879. asmstat : tasmnode;
  880. Marker : tai;
  881. reg : tregister;
  882. asmreader : tbaseasmreader;
  883. begin
  884. Inside_asm_statement:=true;
  885. if assigned(asmmodeinfos[current_settings.asmmode]) then
  886. begin
  887. asmreader:=asmmodeinfos[current_settings.asmmode]^.casmreader.create;
  888. asmstat:=casmnode.create(asmreader.assemble as TAsmList);
  889. asmreader.free;
  890. end
  891. else
  892. Message(parser_f_assembler_reader_not_supported);
  893. { Mark procedure that it has assembler blocks }
  894. include(current_procinfo.flags,pi_has_assembler_block);
  895. { Read first the _ASM statement }
  896. consume(_ASM);
  897. { END is read, got a list of changed registers? }
  898. if try_to_consume(_LECKKLAMMER) then
  899. begin
  900. {$ifdef cpunofpu}
  901. asmstat.used_regs_fpu:=[0..first_int_imreg-1];
  902. {$else cpunofpu}
  903. asmstat.used_regs_fpu:=[0..first_fpu_imreg-1];
  904. {$endif cpunofpu}
  905. if token<>_RECKKLAMMER then
  906. begin
  907. if po_assembler in current_procinfo.procdef.procoptions then
  908. Message(parser_w_register_list_ignored);
  909. repeat
  910. { it's possible to specify the modified registers }
  911. reg:=std_regnum_search(lower(cstringpattern));
  912. if reg<>NR_NO then
  913. begin
  914. if (getregtype(reg)=R_INTREGISTER) and not(po_assembler in current_procinfo.procdef.procoptions) then
  915. include(asmstat.used_regs_int,getsupreg(reg));
  916. end
  917. else
  918. Message(asmr_e_invalid_register);
  919. consume(_CSTRING);
  920. if not try_to_consume(_COMMA) then
  921. break;
  922. until false;
  923. end;
  924. consume(_RECKKLAMMER);
  925. end
  926. else
  927. begin
  928. asmstat.used_regs_int:=paramanager.get_volatile_registers_int(current_procinfo.procdef.proccalloption);
  929. asmstat.used_regs_fpu:=paramanager.get_volatile_registers_fpu(current_procinfo.procdef.proccalloption);
  930. end;
  931. { mark the start and the end of the assembler block
  932. this is needed for the optimizer }
  933. If Assigned(AsmStat.p_asm) Then
  934. Begin
  935. Marker := Tai_Marker.Create(mark_AsmBlockStart);
  936. AsmStat.p_asm.Insert(Marker);
  937. Marker := Tai_Marker.Create(mark_AsmBlockEnd);
  938. AsmStat.p_asm.Concat(Marker);
  939. End;
  940. Inside_asm_statement:=false;
  941. _asm_statement:=asmstat;
  942. end;
  943. function statement : tnode;
  944. var
  945. p,
  946. code : tnode;
  947. filepos : tfileposinfo;
  948. srsym : tsym;
  949. srsymtable : TSymtable;
  950. s : TIDString;
  951. begin
  952. filepos:=current_tokenpos;
  953. case token of
  954. _GOTO :
  955. begin
  956. if not(cs_support_goto in current_settings.moduleswitches) then
  957. Message(sym_e_goto_and_label_not_supported);
  958. consume(_GOTO);
  959. if (token<>_INTCONST) and (token<>_ID) then
  960. begin
  961. Message(sym_e_label_not_found);
  962. code:=cerrornode.create;
  963. end
  964. else
  965. begin
  966. if token=_ID then
  967. consume_sym(srsym,srsymtable)
  968. else
  969. begin
  970. if token<>_INTCONST then
  971. internalerror(201008021);
  972. { strip leading 0's in iso mode }
  973. if m_iso in current_settings.modeswitches then
  974. while pattern[1]='0' do
  975. delete(pattern,1,1);
  976. searchsym(pattern,srsym,srsymtable);
  977. if srsym=nil then
  978. begin
  979. identifier_not_found(pattern);
  980. srsym:=generrorsym;
  981. srsymtable:=nil;
  982. end;
  983. consume(token);
  984. end;
  985. if srsym.typ<>labelsym then
  986. begin
  987. Message(sym_e_id_is_no_label_id);
  988. code:=cerrornode.create;
  989. end
  990. else
  991. begin
  992. { goto outside the current scope? }
  993. if srsym.owner<>current_procinfo.procdef.localst then
  994. begin
  995. { allowed? }
  996. if not(m_non_local_goto in current_settings.modeswitches) then
  997. Message(parser_e_goto_outside_proc);
  998. end;
  999. code:=cgotonode.create(tlabelsym(srsym));
  1000. tgotonode(code).labelsym:=tlabelsym(srsym);
  1001. { set flag that this label is used }
  1002. tlabelsym(srsym).used:=true;
  1003. end;
  1004. end;
  1005. end;
  1006. _BEGIN :
  1007. code:=statement_block(_BEGIN);
  1008. _IF :
  1009. code:=if_statement;
  1010. _CASE :
  1011. code:=case_statement;
  1012. _REPEAT :
  1013. code:=repeat_statement;
  1014. _WHILE :
  1015. code:=while_statement;
  1016. _FOR :
  1017. code:=for_statement;
  1018. _WITH :
  1019. code:=with_statement;
  1020. _TRY :
  1021. code:=try_statement;
  1022. _RAISE :
  1023. code:=raise_statement;
  1024. { semicolons,else until and end are ignored }
  1025. _SEMICOLON,
  1026. _ELSE,
  1027. _UNTIL,
  1028. _END:
  1029. code:=cnothingnode.create;
  1030. _FAIL :
  1031. begin
  1032. if (current_procinfo.procdef.proctypeoption<>potype_constructor) then
  1033. Message(parser_e_fail_only_in_constructor);
  1034. consume(_FAIL);
  1035. code:=call_fail_node;
  1036. end;
  1037. _ASM :
  1038. code:=_asm_statement;
  1039. _EOF :
  1040. Message(scan_f_end_of_file);
  1041. else
  1042. begin
  1043. { don't typecheck yet, because that will also simplify, which may
  1044. result in not detecting certain kinds of syntax errors --
  1045. see mantis #15594 }
  1046. p:=expr(false);
  1047. { save the pattern here for latter usage, the label could be "000",
  1048. even if we read an expression, the pattern is still valid if it's really
  1049. a label (FK)
  1050. if you want to mess here, take care of
  1051. tests/webtbs/tw3546.pp
  1052. }
  1053. s:=pattern;
  1054. { When a colon follows a intconst then transform it into a label }
  1055. if (p.nodetype=ordconstn) and
  1056. try_to_consume(_COLON) then
  1057. begin
  1058. { in iso mode, 0003: is equal to 3: }
  1059. if m_iso in current_settings.modeswitches then
  1060. searchsym(tostr(tordconstnode(p).value),srsym,srsymtable)
  1061. else
  1062. searchsym(s,srsym,srsymtable);
  1063. p.free;
  1064. if assigned(srsym) and
  1065. (srsym.typ=labelsym) then
  1066. begin
  1067. if tlabelsym(srsym).defined then
  1068. Message(sym_e_label_already_defined);
  1069. if symtablestack.top.symtablelevel<>srsymtable.symtablelevel then
  1070. begin
  1071. tlabelsym(srsym).nonlocal:=true;
  1072. exclude(current_procinfo.procdef.procoptions,po_inline);
  1073. end;
  1074. if tlabelsym(srsym).nonlocal and
  1075. (current_procinfo.procdef.proctypeoption in [potype_unitinit,potype_unitfinalize]) then
  1076. Message(sym_e_interprocgoto_into_init_final_code_not_allowed);
  1077. tlabelsym(srsym).defined:=true;
  1078. p:=clabelnode.create(nil,tlabelsym(srsym));
  1079. tlabelsym(srsym).code:=p;
  1080. end
  1081. else
  1082. begin
  1083. Message1(sym_e_label_used_and_not_defined,s);
  1084. p:=cnothingnode.create;
  1085. end;
  1086. end;
  1087. if p.nodetype=labeln then
  1088. begin
  1089. { the pointer to the following instruction }
  1090. { isn't a very clean way }
  1091. if token in endtokens then
  1092. tlabelnode(p).left:=cnothingnode.create
  1093. else
  1094. tlabelnode(p).left:=statement();
  1095. { be sure to have left also typecheckpass }
  1096. typecheckpass(tlabelnode(p).left);
  1097. end
  1098. else
  1099. { change a load of a procvar to a call. this is also
  1100. supported in fpc mode }
  1101. if p.nodetype in [vecn,derefn,typeconvn,subscriptn,loadn] then
  1102. maybe_call_procvar(p,false);
  1103. { blockn support because a read/write is changed into a blocknode }
  1104. { with a separate statement for each read/write operation (JM) }
  1105. { the same is true for val() if the third parameter is not 32 bit }
  1106. if not(p.nodetype in [nothingn,errorn,calln,ifn,assignn,breakn,inlinen,
  1107. continuen,labeln,blockn,exitn]) or
  1108. ((p.nodetype=inlinen) and
  1109. not is_void(p.resultdef)) or
  1110. ((p.nodetype=calln) and
  1111. (assigned(tcallnode(p).procdefinition)) and
  1112. (tcallnode(p).procdefinition.proctypeoption=potype_operator)) then
  1113. Message(parser_e_illegal_expression);
  1114. if not assigned(p.resultdef) then
  1115. do_typecheckpass(p);
  1116. { Specify that we don't use the value returned by the call.
  1117. This is used for :
  1118. - dispose of temp stack space
  1119. - dispose on FPU stack
  1120. - extended syntax checking }
  1121. if (p.nodetype=calln) then
  1122. begin
  1123. exclude(tcallnode(p).callnodeflags,cnf_return_value_used);
  1124. { in $x- state, the function result must not be ignored }
  1125. if not(cs_extsyntax in current_settings.moduleswitches) and
  1126. not(is_void(p.resultdef)) and
  1127. { can be nil in case there was an error in the expression }
  1128. assigned(tcallnode(p).procdefinition) and
  1129. not((tcallnode(p).procdefinition.proctypeoption=potype_constructor) and
  1130. is_object(tprocdef(tcallnode(p).procdefinition).struct)) then
  1131. Message(parser_e_illegal_expression);
  1132. end;
  1133. code:=p;
  1134. end;
  1135. end;
  1136. if assigned(code) then
  1137. begin
  1138. typecheckpass(code);
  1139. code.fileinfo:=filepos;
  1140. end;
  1141. statement:=code;
  1142. end;
  1143. function statement_block(starttoken : ttoken) : tnode;
  1144. var
  1145. first,last : tnode;
  1146. filepos : tfileposinfo;
  1147. begin
  1148. first:=nil;
  1149. filepos:=current_tokenpos;
  1150. consume(starttoken);
  1151. while not(token in [_END,_FINALIZATION]) do
  1152. begin
  1153. if first=nil then
  1154. begin
  1155. last:=cstatementnode.create(statement,nil);
  1156. first:=last;
  1157. end
  1158. else
  1159. begin
  1160. tstatementnode(last).right:=cstatementnode.create(statement,nil);
  1161. last:=tstatementnode(last).right;
  1162. end;
  1163. if (token in [_END,_FINALIZATION]) then
  1164. break
  1165. else
  1166. begin
  1167. { if no semicolon, then error and go on }
  1168. if token<>_SEMICOLON then
  1169. begin
  1170. consume(_SEMICOLON);
  1171. consume_all_until(_SEMICOLON);
  1172. end;
  1173. consume(_SEMICOLON);
  1174. end;
  1175. consume_emptystats;
  1176. end;
  1177. { don't consume the finalization token, it is consumed when
  1178. reading the finalization block, but allow it only after
  1179. an initalization ! }
  1180. if (starttoken<>_INITIALIZATION) or (token<>_FINALIZATION) then
  1181. consume(_END);
  1182. last:=cblocknode.create(first);
  1183. last.fileinfo:=filepos;
  1184. statement_block:=last;
  1185. end;
  1186. function assembler_block : tnode;
  1187. var
  1188. p : tnode;
  1189. {$ifndef arm}
  1190. locals : longint;
  1191. {$endif arm}
  1192. srsym : tsym;
  1193. begin
  1194. { Rename the funcret so that recursive calls are possible }
  1195. if not is_void(current_procinfo.procdef.returndef) then
  1196. begin
  1197. srsym:=TSym(current_procinfo.procdef.localst.Find(current_procinfo.procdef.procsym.name));
  1198. if assigned(srsym) then
  1199. srsym.realname:='$hiddenresult';
  1200. end;
  1201. { delphi uses register calling for assembler methods }
  1202. if (m_delphi in current_settings.modeswitches) and
  1203. (po_assembler in current_procinfo.procdef.procoptions) and
  1204. not(po_hascallingconvention in current_procinfo.procdef.procoptions) then
  1205. current_procinfo.procdef.proccalloption:=pocall_register;
  1206. { force the asm statement }
  1207. if token<>_ASM then
  1208. consume(_ASM);
  1209. include(current_procinfo.flags,pi_is_assembler);
  1210. p:=_asm_statement;
  1211. {$if not(defined(sparc)) and not(defined(arm)) and not(defined(avr))}
  1212. if (po_assembler in current_procinfo.procdef.procoptions) then
  1213. begin
  1214. { set the framepointer to esp for assembler functions when the
  1215. following conditions are met:
  1216. - if the are no local variables and parameters (except the allocated result)
  1217. - no reference to the result variable (refcount<=1)
  1218. - result is not stored as parameter
  1219. - target processor has optional frame pointer save
  1220. (vm, i386, vm only currently)
  1221. }
  1222. locals:=tabstractlocalsymtable(current_procinfo.procdef.parast).count_locals;
  1223. if (current_procinfo.procdef.localst.symtabletype=localsymtable) then
  1224. inc(locals,tabstractlocalsymtable(current_procinfo.procdef.localst).count_locals);
  1225. if (locals=0) and
  1226. not (current_procinfo.procdef.owner.symtabletype in [ObjectSymtable,recordsymtable]) and
  1227. (not assigned(current_procinfo.procdef.funcretsym) or
  1228. (tabstractvarsym(current_procinfo.procdef.funcretsym).refs<=1)) and
  1229. not(paramanager.ret_in_param(current_procinfo.procdef.returndef,current_procinfo.procdef.proccalloption)) then
  1230. begin
  1231. { Only need to set the framepointer, the locals will
  1232. be inserted with the correct reference in tcgasmnode.pass_generate_code }
  1233. current_procinfo.framepointer:=NR_STACK_POINTER_REG;
  1234. end;
  1235. end;
  1236. {$endif not(defined(sparc)) and not(defined(arm)) and not(defined(avr))}
  1237. { Flag the result as assigned when it is returned in a
  1238. register.
  1239. }
  1240. if assigned(current_procinfo.procdef.funcretsym) and
  1241. (not paramanager.ret_in_param(current_procinfo.procdef.returndef,current_procinfo.procdef.proccalloption)) then
  1242. tabstractvarsym(current_procinfo.procdef.funcretsym).varstate:=vs_initialised;
  1243. { because the END is already read we need to get the
  1244. last_endtoken_filepos here (PFV) }
  1245. last_endtoken_filepos:=current_tokenpos;
  1246. assembler_block:=p;
  1247. end;
  1248. end.