pstatmnt.pas 52 KB

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