pexpr.pas 92 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495
  1. {
  2. $Id$
  3. Copyright (c) 1998 by Florian Klaempfl
  4. Does parsing of expression for Free Pascal
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit pexpr;
  19. interface
  20. uses symtable,tree;
  21. { reads a whole expression }
  22. function expr : ptree;
  23. { reads an expression without assignements and .. }
  24. function comp_expr(accept_equal : boolean):Ptree;
  25. { reads a single factor }
  26. function factor(getaddr : boolean) : ptree;
  27. { the ID token has to be consumed before calling this function }
  28. procedure do_member_read(getaddr : boolean;const sym : psym;var p1 : ptree;
  29. var pd : pdef;var again : boolean);
  30. function get_intconst:longint;
  31. function get_stringconst:string;
  32. implementation
  33. uses
  34. globtype,systems,tokens,
  35. cobjects,globals,scanner,aasm,pass_1,
  36. hcodegen,types,verbose,strings,tccal
  37. { parser specific stuff }
  38. ,pbase,pdecl
  39. { processor specific stuff }
  40. {$ifdef i386}
  41. ,i386base
  42. {$endif}
  43. {$ifdef m68k}
  44. ,m68k
  45. {$endif}
  46. ;
  47. const allow_type : boolean = true;
  48. function parse_paras(_colon,in_prop_paras : boolean) : ptree;
  49. var
  50. p1,p2 : ptree;
  51. end_of_paras : ttoken;
  52. begin
  53. if in_prop_paras then
  54. end_of_paras:=RECKKLAMMER
  55. else
  56. end_of_paras:=RKLAMMER;
  57. if token=end_of_paras then
  58. begin
  59. parse_paras:=nil;
  60. exit;
  61. end;
  62. p2:=nil;
  63. inc(parsing_para_level);
  64. while true do
  65. begin
  66. p1:=comp_expr(true);
  67. p2:=gencallparanode(p1,p2);
  68. { it's for the str(l:5,s); }
  69. if _colon and (token=COLON) then
  70. begin
  71. consume(COLON);
  72. p1:=comp_expr(true);
  73. p2:=gencallparanode(p1,p2);
  74. p2^.is_colon_para:=true;
  75. if token=COLON then
  76. begin
  77. consume(COLON);
  78. p1:=comp_expr(true);
  79. p2:=gencallparanode(p1,p2);
  80. p2^.is_colon_para:=true;
  81. end
  82. end;
  83. if token=COMMA then
  84. consume(COMMA)
  85. else
  86. break;
  87. end;
  88. dec(parsing_para_level);
  89. parse_paras:=p2;
  90. end;
  91. procedure check_tp_procvar(var p : ptree);
  92. var
  93. p1 : ptree;
  94. Store_valid : boolean;
  95. begin
  96. if (m_tp_procvar in aktmodeswitches) and
  97. { (not afterassignment) and }
  98. (not in_args) and
  99. (p^.treetype in [loadn]) then
  100. begin
  101. { support if procvar then for tp7 and many other expression like this }
  102. Store_valid:=Must_be_valid;
  103. Must_be_valid:=false;
  104. firstpass(p);
  105. Must_be_valid:=Store_valid;
  106. if p^.resulttype^.deftype=procvardef then
  107. begin
  108. p1:=gencallnode(nil,nil);
  109. p1^.right:=p;
  110. p1^.resulttype:=pprocvardef(p^.resulttype)^.retdef;
  111. firstpass(p1);
  112. p:=p1;
  113. end;
  114. end;
  115. end;
  116. function statement_syssym(l : longint;var pd : pdef) : ptree;
  117. var
  118. p1,p2,paras : ptree;
  119. prev_in_args : boolean;
  120. Store_valid : boolean;
  121. begin
  122. prev_in_args:=in_args;
  123. Store_valid:=Must_be_valid;
  124. case l of
  125. in_ord_x :
  126. begin
  127. consume(LKLAMMER);
  128. in_args:=true;
  129. Must_be_valid:=true;
  130. p1:=comp_expr(true);
  131. consume(RKLAMMER);
  132. do_firstpass(p1);
  133. p1:=geninlinenode(in_ord_x,false,p1);
  134. do_firstpass(p1);
  135. statement_syssym := p1;
  136. pd:=p1^.resulttype;
  137. end;
  138. in_break :
  139. begin
  140. statement_syssym:=genzeronode(breakn);
  141. pd:=voiddef;
  142. end;
  143. in_continue :
  144. begin
  145. statement_syssym:=genzeronode(continuen);
  146. pd:=voiddef;
  147. end;
  148. in_typeof_x :
  149. begin
  150. consume(LKLAMMER);
  151. in_args:=true;
  152. {allow_type:=true;}
  153. p1:=comp_expr(true);
  154. {allow_type:=false;}
  155. consume(RKLAMMER);
  156. pd:=voidpointerdef;
  157. if p1^.treetype=typen then
  158. begin
  159. if (p1^.typenodetype=nil) then
  160. begin
  161. Message(type_e_mismatch);
  162. statement_syssym:=genzeronode(errorn);
  163. end
  164. else
  165. if p1^.typenodetype^.deftype=objectdef then
  166. begin
  167. { we can use resulttype in pass_2 (PM) }
  168. p1^.resulttype:=p1^.typenodetype;
  169. statement_syssym:=geninlinenode(in_typeof_x,false,p1);
  170. end
  171. else
  172. begin
  173. Message(type_e_mismatch);
  174. disposetree(p1);
  175. statement_syssym:=genzeronode(errorn);
  176. end;
  177. end
  178. else { not a type node }
  179. begin
  180. Must_be_valid:=false;
  181. do_firstpass(p1);
  182. if (p1^.resulttype=nil) then
  183. begin
  184. Message(type_e_mismatch);
  185. disposetree(p1);
  186. statement_syssym:=genzeronode(errorn)
  187. end
  188. else
  189. if p1^.resulttype^.deftype=objectdef then
  190. statement_syssym:=geninlinenode(in_typeof_x,false,p1)
  191. else
  192. begin
  193. Message(type_e_mismatch);
  194. statement_syssym:=genzeronode(errorn);
  195. disposetree(p1);
  196. end;
  197. end;
  198. end;
  199. in_sizeof_x :
  200. begin
  201. consume(LKLAMMER);
  202. in_args:=true;
  203. {allow_type:=true;}
  204. p1:=comp_expr(true);
  205. {allow_type:=false; }
  206. consume(RKLAMMER);
  207. pd:=s32bitdef;
  208. if p1^.treetype=typen then
  209. begin
  210. statement_syssym:=genordinalconstnode(p1^.typenodetype^.size,pd);
  211. { p1 not needed !}
  212. disposetree(p1);
  213. end
  214. else
  215. begin
  216. Must_be_valid:=false;
  217. do_firstpass(p1);
  218. if ((p1^.resulttype^.deftype=objectdef) and
  219. ((pobjectdef(p1^.resulttype)^.options and oo_hasconstructor)<>0)) or
  220. is_open_array(p1^.resulttype) or
  221. is_open_string(p1^.resulttype) then
  222. statement_syssym:=geninlinenode(in_sizeof_x,false,p1)
  223. else
  224. begin
  225. statement_syssym:=genordinalconstnode(p1^.resulttype^.size,pd);
  226. { p1 not needed !}
  227. disposetree(p1);
  228. end;
  229. end;
  230. end;
  231. in_assigned_x :
  232. begin
  233. consume(LKLAMMER);
  234. in_args:=true;
  235. p1:=comp_expr(true);
  236. Must_be_valid:=true;
  237. do_firstpass(p1);
  238. case p1^.resulttype^.deftype of
  239. pointerdef,
  240. procvardef,
  241. classrefdef : ;
  242. objectdef : if not(pobjectdef(p1^.resulttype)^.isclass) then
  243. Message(parser_e_illegal_parameter_list);
  244. else
  245. Message(parser_e_illegal_parameter_list);
  246. end;
  247. p2:=gencallparanode(p1,nil);
  248. p2:=geninlinenode(in_assigned_x,false,p2);
  249. consume(RKLAMMER);
  250. pd:=booldef;
  251. statement_syssym:=p2;
  252. end;
  253. in_ofs_x :
  254. begin
  255. consume(LKLAMMER);
  256. in_args:=true;
  257. p1:=comp_expr(true);
  258. p1:=gensinglenode(addrn,p1);
  259. Must_be_valid:=false;
  260. do_firstpass(p1);
  261. { Ofs() returns a longint, not a pointer }
  262. p1^.resulttype:=u32bitdef;
  263. pd:=p1^.resulttype;
  264. consume(RKLAMMER);
  265. statement_syssym:=p1;
  266. end;
  267. in_addr_x :
  268. begin
  269. consume(LKLAMMER);
  270. in_args:=true;
  271. p1:=comp_expr(true);
  272. p1:=gensinglenode(addrn,p1);
  273. Must_be_valid:=false;
  274. do_firstpass(p1);
  275. pd:=p1^.resulttype;
  276. consume(RKLAMMER);
  277. statement_syssym:=p1;
  278. end;
  279. in_seg_x :
  280. begin
  281. consume(LKLAMMER);
  282. in_args:=true;
  283. p1:=comp_expr(true);
  284. do_firstpass(p1);
  285. if p1^.location.loc<>LOC_REFERENCE then
  286. Message(cg_e_illegal_expression);
  287. p1:=genordinalconstnode(0,s32bitdef);
  288. Must_be_valid:=false;
  289. pd:=s32bitdef;
  290. consume(RKLAMMER);
  291. statement_syssym:=p1;
  292. end;
  293. in_high_x,
  294. in_low_x :
  295. begin
  296. consume(LKLAMMER);
  297. in_args:=true;
  298. {allow_type:=true;}
  299. p1:=comp_expr(true);
  300. {allow_type:=false;}
  301. do_firstpass(p1);
  302. if p1^.treetype=typen then
  303. p1^.resulttype:=p1^.typenodetype;
  304. Must_be_valid:=false;
  305. p2:=geninlinenode(l,false,p1);
  306. consume(RKLAMMER);
  307. pd:=s32bitdef;
  308. statement_syssym:=p2;
  309. end;
  310. in_succ_x,
  311. in_pred_x :
  312. begin
  313. consume(LKLAMMER);
  314. in_args:=true;
  315. p1:=comp_expr(true);
  316. do_firstpass(p1);
  317. Must_be_valid:=false;
  318. p2:=geninlinenode(l,false,p1);
  319. consume(RKLAMMER);
  320. pd:=p1^.resulttype;
  321. statement_syssym:=p2;
  322. end;
  323. in_inc_x,
  324. in_dec_x :
  325. begin
  326. consume(LKLAMMER);
  327. in_args:=true;
  328. p1:=comp_expr(true);
  329. Must_be_valid:=false;
  330. if token=COMMA then
  331. begin
  332. consume(COMMA);
  333. p2:=gencallparanode(comp_expr(true),nil);
  334. end
  335. else
  336. p2:=nil;
  337. p2:=gencallparanode(p1,p2);
  338. statement_syssym:=geninlinenode(l,false,p2);
  339. consume(RKLAMMER);
  340. pd:=voiddef;
  341. end;
  342. in_concat_x :
  343. begin
  344. consume(LKLAMMER);
  345. in_args:=true;
  346. p2:=nil;
  347. while true do
  348. begin
  349. p1:=comp_expr(true);
  350. Must_be_valid:=true;
  351. do_firstpass(p1);
  352. if not((p1^.resulttype^.deftype=stringdef) or
  353. ((p1^.resulttype^.deftype=orddef) and
  354. (porddef(p1^.resulttype)^.typ=uchar))) then
  355. Message(parser_e_illegal_parameter_list);
  356. if p2<>nil then
  357. p2:=gennode(addn,p2,p1)
  358. else
  359. p2:=p1;
  360. if token=COMMA then
  361. consume(COMMA)
  362. else
  363. break;
  364. end;
  365. consume(RKLAMMER);
  366. pd:=cshortstringdef;
  367. statement_syssym:=p2;
  368. end;
  369. in_read_x,
  370. in_readln_x :
  371. begin
  372. if token=LKLAMMER then
  373. begin
  374. consume(LKLAMMER);
  375. in_args:=true;
  376. Must_be_valid:=false;
  377. paras:=parse_paras(false,false);
  378. consume(RKLAMMER);
  379. end
  380. else
  381. paras:=nil;
  382. pd:=voiddef;
  383. p1:=geninlinenode(l,false,paras);
  384. do_firstpass(p1);
  385. statement_syssym := p1;
  386. end;
  387. in_write_x,
  388. in_writeln_x :
  389. begin
  390. if token=LKLAMMER then
  391. begin
  392. consume(LKLAMMER);
  393. in_args:=true;
  394. Must_be_valid:=true;
  395. paras:=parse_paras(true,false);
  396. consume(RKLAMMER);
  397. end
  398. else
  399. paras:=nil;
  400. pd:=voiddef;
  401. p1 := geninlinenode(l,false,paras);
  402. do_firstpass(p1);
  403. statement_syssym := p1;
  404. end;
  405. in_str_x_string :
  406. begin
  407. consume(LKLAMMER);
  408. in_args:=true;
  409. paras:=parse_paras(true,false);
  410. consume(RKLAMMER);
  411. p1 := geninlinenode(l,false,paras);
  412. do_firstpass(p1);
  413. statement_syssym := p1;
  414. pd:=voiddef;
  415. end;
  416. {$IfnDef OLDVAL}
  417. in_val_x:
  418. Begin
  419. consume(LKLAMMER);
  420. in_args := true;
  421. p1:= gencallparanode(comp_expr(true), nil);
  422. Must_be_valid := False;
  423. consume(COMMA);
  424. p2 := gencallparanode(comp_expr(true),p1);
  425. if (token = COMMA) then
  426. Begin
  427. consume(COMMA);
  428. p2 := gencallparanode(comp_expr(true),p2)
  429. End;
  430. consume(RKLAMMER);
  431. p2 := geninlinenode(l,false,p2);
  432. do_firstpass(p2);
  433. statement_syssym := p2;
  434. pd := voiddef;
  435. End;
  436. {$EndIf OLDVAL}
  437. in_include_x_y,
  438. in_exclude_x_y :
  439. begin
  440. consume(LKLAMMER);
  441. in_args:=true;
  442. p1:=comp_expr(true);
  443. Must_be_valid:=false;
  444. consume(COMMA);
  445. p2:=comp_expr(true);
  446. statement_syssym:=geninlinenode(l,false,gencallparanode(p1,gencallparanode(p2,nil)));
  447. consume(RKLAMMER);
  448. pd:=voiddef;
  449. end;
  450. in_assert_x_y :
  451. begin
  452. consume(LKLAMMER);
  453. in_args:=true;
  454. p1:=comp_expr(true);
  455. if token=COMMA then
  456. begin
  457. consume(COMMA);
  458. p2:=comp_expr(true);
  459. end
  460. else
  461. begin
  462. { then insert an empty string }
  463. p2:=genstringconstnode('');
  464. end;
  465. statement_syssym:=geninlinenode(l,false,gencallparanode(p1,gencallparanode(p2,nil)));
  466. consume(RKLAMMER);
  467. pd:=voiddef;
  468. end;
  469. else
  470. internalerror(15);
  471. end;
  472. in_args:=prev_in_args;
  473. Must_be_valid:=Store_valid;
  474. end;
  475. { reads the parameter for a subroutine call }
  476. procedure do_proc_call(getaddr : boolean;var again : boolean;var p1:Ptree;var pd:Pdef);
  477. var
  478. prev_in_args : boolean;
  479. prevafterassn : boolean;
  480. begin
  481. prev_in_args:=in_args;
  482. prevafterassn:=afterassignment;
  483. afterassignment:=false;
  484. { want we only determine the address of }
  485. { a subroutine ? }
  486. if not(getaddr) then
  487. begin
  488. if token=LKLAMMER then
  489. begin
  490. consume(LKLAMMER);
  491. in_args:=true;
  492. p1^.left:=parse_paras(false,false);
  493. consume(RKLAMMER);
  494. end
  495. else p1^.left:=nil;
  496. { do firstpass because we need the }
  497. { result type }
  498. do_firstpass(p1);
  499. end
  500. else
  501. begin
  502. { address operator @: }
  503. p1^.left:=nil;
  504. { forget pd }
  505. pd:=nil;
  506. if (p1^.symtableproc^.symtabletype=withsymtable) and
  507. (p1^.symtableproc^.defowner^.deftype=objectdef) then
  508. begin
  509. p1^.methodpointer:=getcopy(pwithsymtable(p1^.symtableproc)^.withrefnode);
  510. end;
  511. { no postfix operators }
  512. again:=false;
  513. end;
  514. pd:=p1^.resulttype;
  515. in_args:=prev_in_args;
  516. afterassignment:=prevafterassn;
  517. end;
  518. procedure handle_procvar(procvar : pprocvardef;var t : ptree);
  519. var
  520. hp : ptree;
  521. begin
  522. hp:=nil;
  523. if (proc_to_procvar_equal(pprocsym(t^.symtableentry)^.definition,procvar)) then
  524. begin
  525. if ((procvar^.options and pomethodpointer)<>0) then
  526. hp:=genloadmethodcallnode(pprocsym(t^.symtableprocentry),t^.symtable,getcopy(t^.methodpointer))
  527. else
  528. hp:=genloadcallnode(pprocsym(t^.symtableprocentry),t^.symtable);
  529. end;
  530. if assigned(hp) then
  531. begin
  532. disposetree(t);
  533. t:=hp;
  534. end;
  535. end;
  536. { the following procedure handles the access to a property symbol }
  537. procedure handle_propertysym(sym : psym;st : psymtable;var p1 : ptree;
  538. var pd : pdef);
  539. var
  540. paras : ptree;
  541. p2 : ptree;
  542. begin
  543. paras:=nil;
  544. { property parameters? }
  545. if token=LECKKLAMMER then
  546. begin
  547. consume(LECKKLAMMER);
  548. paras:=parse_paras(false,true);
  549. consume(RECKKLAMMER);
  550. end;
  551. { indexed property }
  552. if (ppropertysym(sym)^.options and ppo_indexed)<>0 then
  553. begin
  554. p2:=genordinalconstnode(ppropertysym(sym)^.index,s32bitdef);
  555. paras:=gencallparanode(p2,paras);
  556. end;
  557. { we need only a write property if a := follows }
  558. { if not(afterassignment) and not(in_args) then }
  559. if token=ASSIGNMENT then
  560. begin
  561. { write property: }
  562. { no result }
  563. pd:=voiddef;
  564. if assigned(ppropertysym(sym)^.writeaccesssym) then
  565. begin
  566. if ppropertysym(sym)^.writeaccesssym^.typ=procsym then
  567. begin
  568. { generate the method call }
  569. p1:=genmethodcallnode(pprocsym(
  570. ppropertysym(sym)^.writeaccesssym),st,p1);
  571. { we know the procedure to call, so
  572. force the usage of that procedure }
  573. p1^.procdefinition:=pprocdef(ppropertysym(sym)^.writeaccessdef);
  574. p1^.left:=paras;
  575. consume(ASSIGNMENT);
  576. { read the expression }
  577. getprocvar:=ppropertysym(sym)^.proptype^.deftype=procvardef;
  578. p2:=comp_expr(true);
  579. if getprocvar then
  580. begin
  581. if (p2^.treetype=calln) then
  582. handle_procvar(pprocvardef(ppropertysym(sym)^.proptype),p2)
  583. else
  584. if (p2^.treetype=typeconvn) and
  585. (p2^.left^.treetype=calln) then
  586. handle_procvar(pprocvardef(ppropertysym(sym)^.proptype),p2^.left);
  587. end;
  588. p1^.left:=gencallparanode(p2,p1^.left);
  589. getprocvar:=false;
  590. end
  591. else if ppropertysym(sym)^.writeaccesssym^.typ=varsym then
  592. begin
  593. if assigned(paras) then
  594. message(parser_e_no_paras_allowed);
  595. { subscribed access? }
  596. if p1=nil then
  597. p1:=genloadnode(pvarsym(ppropertysym(sym)^.writeaccesssym),st)
  598. else
  599. p1:=gensubscriptnode(pvarsym(ppropertysym(sym)^.writeaccesssym),p1);
  600. consume(ASSIGNMENT);
  601. { read the expression }
  602. p2:=comp_expr(true);
  603. p1:=gennode(assignn,p1,p2);
  604. end
  605. else
  606. begin
  607. p1:=genzeronode(errorn);
  608. Message(parser_e_no_procedure_to_access_property);
  609. end;
  610. end
  611. else
  612. begin
  613. p1:=genzeronode(errorn);
  614. Message(parser_e_no_procedure_to_access_property);
  615. end;
  616. end
  617. else
  618. begin
  619. { read property: }
  620. pd:=ppropertysym(sym)^.proptype;
  621. if assigned(ppropertysym(sym)^.readaccesssym) then
  622. begin
  623. if ppropertysym(sym)^.readaccesssym^.typ=varsym then
  624. begin
  625. if assigned(paras) then
  626. message(parser_e_no_paras_allowed);
  627. { subscribed access? }
  628. if p1=nil then
  629. p1:=genloadnode(pvarsym(ppropertysym(sym)^.readaccesssym),st)
  630. else
  631. p1:=gensubscriptnode(pvarsym(ppropertysym(sym)^.readaccesssym),p1);
  632. end
  633. else if ppropertysym(sym)^.readaccesssym^.typ=procsym then
  634. begin
  635. { generate the method call }
  636. p1:=genmethodcallnode(pprocsym(ppropertysym(sym)^.readaccesssym),st,p1);
  637. { we know the procedure to call, so
  638. force the usage of that procedure }
  639. p1^.procdefinition:=pprocdef(ppropertysym(sym)^.readaccessdef);
  640. { insert paras }
  641. p1^.left:=paras;
  642. end
  643. else
  644. begin
  645. p1:=genzeronode(errorn);
  646. Message(type_e_mismatch);
  647. end;
  648. end
  649. else
  650. begin
  651. { error, no function to read property }
  652. p1:=genzeronode(errorn);
  653. Message(parser_e_no_procedure_to_access_property);
  654. end;
  655. end;
  656. end;
  657. { the ID token has to be consumed before calling this function }
  658. procedure do_member_read(getaddr : boolean;const sym : psym;var p1 : ptree;
  659. var pd : pdef;var again : boolean);
  660. var
  661. static_name : string;
  662. isclassref : boolean;
  663. begin
  664. if sym=nil then
  665. begin
  666. { pattern is still valid unless
  667. there is another ID just after the ID of sym }
  668. Message1(sym_e_id_no_member,pattern);
  669. disposetree(p1);
  670. p1:=genzeronode(errorn);
  671. { try to clean up }
  672. pd:=generrordef;
  673. again:=false;
  674. end
  675. else
  676. begin
  677. isclassref:=pd^.deftype=classrefdef;
  678. { check protected and private members }
  679. { please leave this code as it is, }
  680. { it has now the same behaviaor as TP/Delphi }
  681. if ((sym^.properties and sp_private)<>0) and
  682. (pobjectdef(pd)^.owner^.symtabletype=unitsymtable) then
  683. Message(parser_e_cant_access_private_member);
  684. if ((sym^.properties and sp_protected)<>0) and
  685. (pobjectdef(pd)^.owner^.symtabletype=unitsymtable) then
  686. begin
  687. if assigned(aktprocsym^.definition^._class) then
  688. begin
  689. if not aktprocsym^.definition^._class^.isrelated(
  690. pobjectdef(sym^.owner^.defowner)) then
  691. Message(parser_e_cant_access_protected_member);
  692. end
  693. else
  694. Message(parser_e_cant_access_protected_member);
  695. end;
  696. { we assume, that only procsyms and varsyms are in an object }
  697. { symbol table, for classes, properties are allowed }
  698. case sym^.typ of
  699. procsym:
  700. begin
  701. p1:=genmethodcallnode(pprocsym(sym),srsymtable,p1);
  702. do_proc_call(getaddr or
  703. (getprocvar and
  704. (m_tp_procvar in aktmodeswitches) and
  705. proc_to_procvar_equal(pprocsym(sym)^.definition,getprocvardef))
  706. ,again,p1,pd);
  707. { now we know the real method e.g. we can check for }
  708. { a class method }
  709. if isclassref and ((p1^.procdefinition^.options and (poclassmethod or poconstructor))=0) then
  710. Message(parser_e_only_class_methods_via_class_ref);
  711. end;
  712. varsym:
  713. begin
  714. if isclassref then
  715. Message(parser_e_only_class_methods_via_class_ref);
  716. if (sym^.properties and sp_static)<>0 then
  717. begin
  718. { static_name:=lower(srsymtable^.name^)+'_'+sym^.name;
  719. this is wrong for static field in with symtable (PM) }
  720. static_name:=lower(srsym^.owner^.name^)+'_'+sym^.name;
  721. getsym(static_name,true);
  722. disposetree(p1);
  723. p1:=genloadnode(pvarsym(srsym),srsymtable);
  724. end
  725. else
  726. p1:=gensubscriptnode(pvarsym(sym),p1);
  727. pd:=pvarsym(sym)^.definition;
  728. end;
  729. propertysym:
  730. begin
  731. if isclassref then
  732. Message(parser_e_only_class_methods_via_class_ref);
  733. handle_propertysym(sym,srsymtable,p1,pd);
  734. end;
  735. else internalerror(16);
  736. end;
  737. end;
  738. end;
  739. {****************************************************************************
  740. Factor
  741. ****************************************************************************}
  742. function factor(getaddr : boolean) : ptree;
  743. var
  744. l : longint;
  745. oldp1,
  746. p1,p2,p3 : ptree;
  747. code : integer;
  748. pd,pd2 : pdef;
  749. possible_error,
  750. unit_specific,
  751. again : boolean;
  752. sym : pvarsym;
  753. classh : pobjectdef;
  754. d : bestreal;
  755. static_name : string;
  756. propsym : ppropertysym;
  757. filepos : tfileposinfo;
  758. {---------------------------------------------
  759. Is_func_ret
  760. ---------------------------------------------}
  761. function is_func_ret(sym : psym) : boolean;
  762. var
  763. p : pprocinfo;
  764. storesymtablestack : psymtable;
  765. begin
  766. is_func_ret:=false;
  767. if (sym^.typ<>funcretsym) and ((procinfo.flags and pi_operator)=0) then
  768. exit;
  769. p:=@procinfo;
  770. while system.assigned(p) do
  771. begin
  772. { is this an access to a function result ? }
  773. if assigned(p^.funcretsym) and
  774. ((pfuncretsym(sym)=p^.funcretsym) or
  775. ((pvarsym(sym)=opsym) and
  776. ((p^.flags and pi_operator)<>0))) and
  777. (p^.retdef<>pdef(voiddef)) and
  778. (token<>LKLAMMER) and
  779. (not ((m_tp in aktmodeswitches) and
  780. (afterassignment or in_args))) then
  781. begin
  782. if ((pvarsym(sym)=opsym) and
  783. ((p^.flags and pi_operator)<>0)) then
  784. inc(opsym^.refs);
  785. if ((pvarsym(sym)=opsym) and
  786. ((p^.flags and pi_operator)<>0)) then
  787. inc(opsym^.refs);
  788. p1:=genzeronode(funcretn);
  789. pd:=p^.retdef;
  790. p1^.funcretprocinfo:=p;
  791. p1^.retdef:=pd;
  792. is_func_ret:=true;
  793. exit;
  794. end;
  795. p:=p^.parent;
  796. end;
  797. { we must use the function call }
  798. if(sym^.typ=funcretsym) then
  799. begin
  800. storesymtablestack:=symtablestack;
  801. symtablestack:=srsymtable^.next;
  802. getsym(sym^.name,true);
  803. if srsym^.typ<>procsym then
  804. Message(cg_e_illegal_expression);
  805. symtablestack:=storesymtablestack;
  806. end;
  807. end;
  808. {---------------------------------------------
  809. Factor_read_id
  810. ---------------------------------------------}
  811. procedure factor_read_id;
  812. var
  813. pc : pchar;
  814. len : longint;
  815. begin
  816. { allow post fix operators }
  817. again:=true;
  818. if (m_result in aktmodeswitches) and
  819. (idtoken=_RESULT) and
  820. assigned(aktprocsym) and
  821. (procinfo.retdef<>pdef(voiddef)) then
  822. begin
  823. consume(ID);
  824. p1:=genzeronode(funcretn);
  825. pd:=procinfo.retdef;
  826. p1^.funcretprocinfo:=pointer(@procinfo);
  827. p1^.retdef:=pd;
  828. end
  829. else
  830. begin
  831. if lastsymknown then
  832. begin
  833. srsym:=lastsrsym;
  834. srsymtable:=lastsrsymtable;
  835. lastsymknown:=false;
  836. end
  837. else
  838. getsym(pattern,true);
  839. consume(ID);
  840. if not is_func_ret(srsym) then
  841. { else it's a normal symbol }
  842. begin
  843. { is it defined like UNIT.SYMBOL ? }
  844. if srsym^.typ=unitsym then
  845. begin
  846. consume(POINT);
  847. getsymonlyin(punitsym(srsym)^.unitsymtable,pattern);
  848. unit_specific:=true;
  849. consume(ID);
  850. end
  851. else
  852. unit_specific:=false;
  853. if not assigned(srsym) then
  854. Begin
  855. p1:=genzeronode(errorn);
  856. { try to clean up }
  857. pd:=generrordef;
  858. end
  859. else
  860. Begin
  861. { check semantics of private }
  862. if (srsym^.typ in [propertysym,procsym,varsym]) and
  863. (srsymtable^.symtabletype=objectsymtable) then
  864. begin
  865. if ((srsym^.properties and sp_private)<>0) and
  866. (pobjectdef(srsym^.owner^.defowner)^.owner^.symtabletype=unitsymtable) then
  867. Message(parser_e_cant_access_private_member);
  868. end;
  869. case srsym^.typ of
  870. absolutesym : begin
  871. p1:=genloadnode(pvarsym(srsym),srsymtable);
  872. pd:=pabsolutesym(srsym)^.definition;
  873. end;
  874. varsym : begin
  875. { are we in a class method ? }
  876. if (srsymtable^.symtabletype=objectsymtable) and
  877. assigned(aktprocsym) and
  878. ((aktprocsym^.definition^.options and poclassmethod)<>0) then
  879. Message(parser_e_only_class_methods);
  880. if (srsym^.properties and sp_static)<>0 then
  881. begin
  882. static_name:=lower(srsym^.owner^.name^)+'_'+srsym^.name;
  883. getsym(static_name,true);
  884. end;
  885. p1:=genloadnode(pvarsym(srsym),srsymtable);
  886. if pvarsym(srsym)^.is_valid=0 then
  887. begin
  888. p1^.is_first := true;
  889. { set special between first loaded until checked in firstpass }
  890. pvarsym(srsym)^.is_valid:=2;
  891. end;
  892. pd:=pvarsym(srsym)^.definition;
  893. end;
  894. typedconstsym : begin
  895. p1:=gentypedconstloadnode(ptypedconstsym(srsym),srsymtable);
  896. pd:=ptypedconstsym(srsym)^.definition;
  897. end;
  898. syssym : p1:=statement_syssym(psyssym(srsym)^.number,pd);
  899. typesym : begin
  900. pd:=ptypesym(srsym)^.definition;
  901. if not assigned(pd) then
  902. begin
  903. pd:=generrordef;
  904. again:=false;
  905. end
  906. else
  907. { if we read a type declaration }
  908. { we have to return the type and }
  909. { nothing else }
  910. if block_type=bt_type then
  911. begin
  912. p1:=gentypenode(pd);
  913. { here we can also set resulttype !! }
  914. p1^.resulttype:=pd;
  915. pd:=voiddef;
  916. end
  917. else { not type block }
  918. begin
  919. if token=LKLAMMER then
  920. begin
  921. consume(LKLAMMER);
  922. p1:=comp_expr(true);
  923. consume(RKLAMMER);
  924. p1:=gentypeconvnode(p1,pd);
  925. p1^.explizit:=true;
  926. end
  927. else { not LKLAMMER}
  928. if (token=POINT) and
  929. (pd^.deftype=objectdef) and
  930. not(pobjectdef(pd)^.isclass) then
  931. begin
  932. consume(POINT);
  933. if assigned(procinfo._class) then
  934. begin
  935. if procinfo._class^.isrelated(pobjectdef(pd)) then
  936. begin
  937. p1:=gentypenode(pd);
  938. p1^.resulttype:=pd;
  939. srsymtable:=pobjectdef(pd)^.publicsyms;
  940. sym:=pvarsym(srsymtable^.search(pattern));
  941. { search also in inherited methods }
  942. while sym=nil do
  943. begin
  944. pd:=pobjectdef(pd)^.childof;
  945. srsymtable:=pobjectdef(pd)^.publicsyms;
  946. sym:=pvarsym(srsymtable^.search(pattern));
  947. end;
  948. consume(ID);
  949. do_member_read(false,sym,p1,pd,again);
  950. end
  951. else
  952. begin
  953. Message(parser_e_no_super_class);
  954. pd:=generrordef;
  955. again:=false;
  956. end;
  957. end
  958. else
  959. begin
  960. { allows @TObject.Load }
  961. { also allows static methods and variables }
  962. p1:=genzeronode(typen);
  963. p1^.resulttype:=pd;
  964. { srsymtable:=pobjectdef(pd)^.publicsyms;
  965. sym:=pvarsym(srsymtable^.search(pattern)); }
  966. { TP allows also @TMenu.Load if Load is only }
  967. { defined in an anchestor class }
  968. sym:=pvarsym(search_class_member(pobjectdef(pd),pattern));
  969. if not assigned(sym) then
  970. Message1(sym_e_id_no_member,pattern)
  971. else if not(getaddr) and ((sym^.properties and sp_static)=0) then
  972. Message(sym_e_only_static_in_static)
  973. else
  974. begin
  975. consume(ID);
  976. do_member_read(getaddr,sym,p1,pd,again);
  977. end;
  978. end;
  979. end
  980. else
  981. begin
  982. { class reference ? }
  983. if (pd^.deftype=objectdef)
  984. and pobjectdef(pd)^.isclass then
  985. begin
  986. p1:=gentypenode(pd);
  987. p1^.resulttype:=pd;
  988. pd:=new(pclassrefdef,init(pd));
  989. p1:=gensinglenode(loadvmtn,p1);
  990. p1^.resulttype:=pd;
  991. end
  992. else
  993. begin
  994. { generate a type node }
  995. { (for typeof etc) }
  996. if allow_type then
  997. begin
  998. p1:=gentypenode(pd);
  999. { here we must use typenodetype explicitly !! PM
  1000. p1^.resulttype:=pd; }
  1001. pd:=voiddef;
  1002. end
  1003. else
  1004. Message(parser_e_no_type_not_allowed_here);
  1005. end;
  1006. end;
  1007. end;
  1008. end;
  1009. enumsym : begin
  1010. p1:=genenumnode(penumsym(srsym));
  1011. pd:=p1^.resulttype;
  1012. end;
  1013. constsym : begin
  1014. case pconstsym(srsym)^.consttype of
  1015. constint :
  1016. p1:=genordinalconstnode(pconstsym(srsym)^.value,s32bitdef);
  1017. conststring :
  1018. begin
  1019. len:=pconstsym(srsym)^.len;
  1020. if not(cs_ansistrings in aktlocalswitches) and (len>255) then
  1021. len:=255;
  1022. getmem(pc,len+1);
  1023. move(pchar(pconstsym(srsym)^.value)^,pc^,len);
  1024. pc[len]:=#0;
  1025. p1:=genpcharconstnode(pc,len);
  1026. end;
  1027. constchar :
  1028. p1:=genordinalconstnode(pconstsym(srsym)^.value,cchardef);
  1029. constreal :
  1030. p1:=genrealconstnode(pbestreal(pconstsym(srsym)^.value)^,bestrealdef^);
  1031. constbool :
  1032. p1:=genordinalconstnode(pconstsym(srsym)^.value,booldef);
  1033. constset :
  1034. p1:=gensetconstnode(pconstset(pconstsym(srsym)^.value),
  1035. psetdef(pconstsym(srsym)^.definition));
  1036. constord :
  1037. p1:=genordinalconstnode(pconstsym(srsym)^.value,
  1038. pconstsym(srsym)^.definition);
  1039. constnil :
  1040. p1:=genzeronode(niln);
  1041. end;
  1042. pd:=p1^.resulttype;
  1043. end;
  1044. procsym : begin
  1045. { are we in a class method ? }
  1046. possible_error:=(srsymtable^.symtabletype=objectsymtable) and
  1047. assigned(aktprocsym) and
  1048. ((aktprocsym^.definition^.options and poclassmethod)<>0);
  1049. p1:=gencallnode(pprocsym(srsym),srsymtable);
  1050. p1^.unit_specific:=unit_specific;
  1051. do_proc_call(getaddr or
  1052. (getprocvar and
  1053. (m_tp_procvar in aktmodeswitches) and
  1054. proc_to_procvar_equal(pprocsym(srsym)^.definition,getprocvardef)),
  1055. again,p1,pd);
  1056. if possible_error and
  1057. ((p1^.procdefinition^.options and poclassmethod)=0) then
  1058. Message(parser_e_only_class_methods);
  1059. end;
  1060. propertysym : begin
  1061. { access to property in a method }
  1062. { are we in a class method ? }
  1063. if (srsymtable^.symtabletype=objectsymtable) and
  1064. assigned(aktprocsym) and
  1065. ((aktprocsym^.definition^.options and poclassmethod)<>0) then
  1066. Message(parser_e_only_class_methods);
  1067. { no method pointer }
  1068. p1:=nil;
  1069. handle_propertysym(srsym,srsymtable,p1,pd);
  1070. end;
  1071. errorsym : begin
  1072. p1:=genzeronode(errorn);
  1073. pd:=generrordef;
  1074. if token=LKLAMMER then
  1075. begin
  1076. consume(LKLAMMER);
  1077. parse_paras(false,false);
  1078. consume(RKLAMMER);
  1079. end;
  1080. end;
  1081. else
  1082. begin
  1083. p1:=genzeronode(errorn);
  1084. pd:=generrordef;
  1085. Message(cg_e_illegal_expression);
  1086. end;
  1087. end; { end case }
  1088. end;
  1089. end;
  1090. end;
  1091. end;
  1092. {---------------------------------------------
  1093. Factor_Read_Set
  1094. ---------------------------------------------}
  1095. { Read a set between [] }
  1096. function factor_read_set:ptree;
  1097. var
  1098. p1,
  1099. lastp,
  1100. buildp : ptree;
  1101. begin
  1102. buildp:=nil;
  1103. { be sure that a least one arrayconstructn is used, also for an
  1104. empty [] }
  1105. if token=RECKKLAMMER then
  1106. buildp:=gennode(arrayconstructn,nil,buildp)
  1107. else
  1108. begin
  1109. while true do
  1110. begin
  1111. p1:=comp_expr(true);
  1112. if token=POINTPOINT then
  1113. begin
  1114. consume(POINTPOINT);
  1115. p2:=comp_expr(true);
  1116. p1:=gennode(arrayconstructrangen,p1,p2);
  1117. end;
  1118. { insert at the end of the tree, to get the correct order }
  1119. if not assigned(buildp) then
  1120. begin
  1121. buildp:=gennode(arrayconstructn,p1,nil);
  1122. lastp:=buildp;
  1123. end
  1124. else
  1125. begin
  1126. lastp^.right:=gennode(arrayconstructn,p1,nil);
  1127. lastp:=lastp^.right;
  1128. end;
  1129. { there could be more elements }
  1130. if token=COMMA then
  1131. consume(COMMA)
  1132. else
  1133. break;
  1134. end;
  1135. end;
  1136. factor_read_set:=buildp;
  1137. end;
  1138. {---------------------------------------------
  1139. Helpers
  1140. ---------------------------------------------}
  1141. procedure check_tokenpos;
  1142. begin
  1143. if (p1<>oldp1) then
  1144. begin
  1145. if assigned(p1) then
  1146. set_tree_filepos(p1,filepos);
  1147. oldp1:=p1;
  1148. filepos:=tokenpos;
  1149. end;
  1150. end;
  1151. {---------------------------------------------
  1152. PostFixOperators
  1153. ---------------------------------------------}
  1154. procedure postfixoperators;
  1155. var
  1156. store_static : boolean;
  1157. { p1 and p2 must contain valid value_str }
  1158. begin
  1159. check_tokenpos;
  1160. while again do
  1161. begin
  1162. { prevent crashes with unknown types }
  1163. if not assigned(pd) then
  1164. begin
  1165. { try to recover }
  1166. repeat
  1167. case token of
  1168. CARET:
  1169. consume(CARET);
  1170. POINT:
  1171. begin
  1172. consume(POINT);
  1173. consume(ID);
  1174. end;
  1175. LECKKLAMMER:
  1176. begin
  1177. repeat
  1178. consume(token);
  1179. until token in [RECKKLAMMER,SEMICOLON];
  1180. end;
  1181. else
  1182. break;
  1183. end;
  1184. until false;
  1185. exit;
  1186. end;
  1187. { handle token }
  1188. case token of
  1189. CARET:
  1190. begin
  1191. consume(CARET);
  1192. if (pd^.deftype<>pointerdef) then
  1193. begin
  1194. { ^ as binary operator is a problem!!!! (FK) }
  1195. again:=false;
  1196. Message(cg_e_invalid_qualifier);
  1197. disposetree(p1);
  1198. p1:=genzeronode(errorn);
  1199. end
  1200. else
  1201. begin
  1202. p1:=gensinglenode(derefn,p1);
  1203. pd:=ppointerdef(pd)^.definition;
  1204. end;
  1205. end;
  1206. LECKKLAMMER:
  1207. begin
  1208. if (pd^.deftype=objectdef) and pobjectdef(pd)^.isclass then
  1209. begin
  1210. { default property }
  1211. propsym:=search_default_property(pobjectdef(pd));
  1212. if not(assigned(propsym)) then
  1213. begin
  1214. disposetree(p1);
  1215. p1:=genzeronode(errorn);
  1216. again:=false;
  1217. message(parser_e_no_default_property_available);
  1218. end
  1219. else
  1220. handle_propertysym(propsym,propsym^.owner,p1,pd);
  1221. end
  1222. else
  1223. begin
  1224. consume(LECKKLAMMER);
  1225. repeat
  1226. case pd^.deftype of
  1227. pointerdef:
  1228. begin
  1229. p2:=comp_expr(true);
  1230. p1:=gennode(vecn,p1,p2);
  1231. pd:=ppointerdef(pd)^.definition;
  1232. end;
  1233. stringdef : begin
  1234. p2:=comp_expr(true);
  1235. p1:=gennode(vecn,p1,p2);
  1236. pd:=cchardef
  1237. end;
  1238. arraydef : begin
  1239. p2:=comp_expr(true);
  1240. { support SEG:OFS for go32v2 Mem[] }
  1241. if (target_info.target=target_i386_go32v2) and
  1242. (p1^.treetype=loadn) and
  1243. assigned(p1^.symtableentry) and
  1244. assigned(p1^.symtableentry^.owner^.name) and
  1245. (p1^.symtableentry^.owner^.name^='SYSTEM') and
  1246. ((p1^.symtableentry^.name='MEM') or
  1247. (p1^.symtableentry^.name='MEMW') or
  1248. (p1^.symtableentry^.name='MEML')) then
  1249. begin
  1250. if (token=COLON) then
  1251. begin
  1252. consume(COLON);
  1253. p3:=gennode(muln,genordinalconstnode($10,s32bitdef),p2);
  1254. p2:=comp_expr(true);
  1255. p2:=gennode(addn,p2,p3);
  1256. p1:=gennode(vecn,p1,p2);
  1257. p1^.memseg:=true;
  1258. p1^.memindex:=true;
  1259. end
  1260. else
  1261. begin
  1262. p1:=gennode(vecn,p1,p2);
  1263. p1^.memindex:=true;
  1264. end;
  1265. end
  1266. else
  1267. p1:=gennode(vecn,p1,p2);
  1268. pd:=parraydef(pd)^.definition;
  1269. end;
  1270. else
  1271. begin
  1272. Message(cg_e_invalid_qualifier);
  1273. disposetree(p1);
  1274. p1:=genzeronode(errorn);
  1275. again:=false;
  1276. end;
  1277. end;
  1278. if token=COMMA then
  1279. consume(COMMA)
  1280. else
  1281. break;
  1282. until false;
  1283. consume(RECKKLAMMER);
  1284. end;
  1285. end;
  1286. POINT : begin
  1287. consume(POINT);
  1288. if (pd^.deftype=pointerdef) and
  1289. (m_autoderef in aktmodeswitches) then
  1290. begin
  1291. p1:=gensinglenode(derefn,p1);
  1292. pd:=ppointerdef(pd)^.definition;
  1293. end;
  1294. case pd^.deftype of
  1295. recorddef:
  1296. begin
  1297. sym:=pvarsym(precdef(pd)^.symtable^.search(pattern));
  1298. if sym=nil then
  1299. begin
  1300. Message1(sym_e_illegal_field,pattern);
  1301. disposetree(p1);
  1302. p1:=genzeronode(errorn);
  1303. end
  1304. else
  1305. begin
  1306. p1:=gensubscriptnode(sym,p1);
  1307. pd:=sym^.definition;
  1308. end;
  1309. consume(ID);
  1310. end;
  1311. classrefdef:
  1312. begin
  1313. classh:=pobjectdef(pclassrefdef(pd)^.definition);
  1314. sym:=nil;
  1315. while assigned(classh) do
  1316. begin
  1317. sym:=pvarsym(classh^.publicsyms^.search(pattern));
  1318. srsymtable:=classh^.publicsyms;
  1319. if assigned(sym) then
  1320. break;
  1321. classh:=classh^.childof;
  1322. end;
  1323. consume(ID);
  1324. do_member_read(getaddr,sym,p1,pd,again);
  1325. end;
  1326. objectdef:
  1327. begin
  1328. classh:=pobjectdef(pd);
  1329. sym:=nil;
  1330. store_static:=allow_only_static;
  1331. allow_only_static:=false;
  1332. while assigned(classh) do
  1333. begin
  1334. sym:=pvarsym(classh^.publicsyms^.search(pattern));
  1335. srsymtable:=classh^.publicsyms;
  1336. if assigned(sym) then
  1337. break;
  1338. classh:=classh^.childof;
  1339. end;
  1340. allow_only_static:=store_static;
  1341. consume(ID);
  1342. do_member_read(getaddr,sym,p1,pd,again);
  1343. end;
  1344. pointerdef:
  1345. begin
  1346. Message(cg_e_invalid_qualifier);
  1347. if ppointerdef(pd)^.definition^.deftype in [recorddef,objectdef,classrefdef] then
  1348. Message(parser_h_maybe_deref_caret_missing);
  1349. end;
  1350. else
  1351. begin
  1352. Message(cg_e_invalid_qualifier);
  1353. disposetree(p1);
  1354. p1:=genzeronode(errorn);
  1355. end;
  1356. end;
  1357. end;
  1358. else
  1359. begin
  1360. { is this a procedure variable ? }
  1361. if assigned(pd) then
  1362. begin
  1363. if (pd^.deftype=procvardef) then
  1364. begin
  1365. if getprocvar and is_equal(pd,getprocvardef) then
  1366. again:=false
  1367. else
  1368. if (token=LKLAMMER) or
  1369. ((pprocvardef(pd)^.para1=nil) and
  1370. (not((token in [ASSIGNMENT,UNEQUAL,EQUAL]))) and
  1371. (not afterassignment) and
  1372. (not in_args)) then
  1373. begin
  1374. { do this in a strange way }
  1375. { it's not a clean solution }
  1376. p2:=p1;
  1377. p1:=gencallnode(nil,nil);
  1378. p1^.right:=p2;
  1379. p1^.unit_specific:=unit_specific;
  1380. p1^.symtableprocentry:=pprocsym(sym);
  1381. if token=LKLAMMER then
  1382. begin
  1383. consume(LKLAMMER);
  1384. p1^.left:=parse_paras(false,false);
  1385. consume(RKLAMMER);
  1386. end;
  1387. pd:=pprocvardef(pd)^.retdef;
  1388. { proc():= is never possible }
  1389. if token=ASSIGNMENT then
  1390. begin
  1391. Message(cg_e_illegal_expression);
  1392. p1:=genzeronode(errorn);
  1393. again:=false;
  1394. end;
  1395. p1^.resulttype:=pd;
  1396. end
  1397. else
  1398. again:=false;
  1399. p1^.resulttype:=pd;
  1400. end
  1401. else
  1402. again:=false;
  1403. end
  1404. else
  1405. again:=false;
  1406. end;
  1407. end;
  1408. check_tokenpos;
  1409. end; { while again }
  1410. end;
  1411. {---------------------------------------------
  1412. Factor (Main)
  1413. ---------------------------------------------}
  1414. begin
  1415. oldp1:=nil;
  1416. p1:=nil;
  1417. filepos:=tokenpos;
  1418. if token=ID then
  1419. begin
  1420. factor_read_id;
  1421. { handle post fix operators }
  1422. postfixoperators;
  1423. end
  1424. else
  1425. case token of
  1426. _NEW : begin
  1427. consume(_NEW);
  1428. consume(LKLAMMER);
  1429. {allow_type:=true;}
  1430. p1:=factor(false);
  1431. {allow_type:=false;}
  1432. if p1^.treetype<>typen then
  1433. begin
  1434. Message(type_e_type_id_expected);
  1435. disposetree(p1);
  1436. pd:=generrordef;
  1437. end
  1438. else
  1439. pd:=p1^.typenodetype;
  1440. pd2:=pd;
  1441. if (pd^.deftype<>pointerdef) then
  1442. Message(type_e_pointer_type_expected)
  1443. else if {(ppointerdef(pd)^.definition^.deftype<>objectdef)}
  1444. token=RKLAMMER then
  1445. begin
  1446. if (ppointerdef(pd)^.definition^.deftype=objectdef) and
  1447. ((pobjectdef(ppointerdef(pd)^.definition)^.options and oo_hasvmt) <> 0) then
  1448. Message(parser_w_use_extended_syntax_for_objects);
  1449. p1:=gensinglenode(newn,nil);
  1450. p1^.resulttype:=pd2;
  1451. consume(RKLAMMER);
  1452. (*Message(parser_e_pointer_to_class_expected);
  1453. { if an error occurs, read til the end of
  1454. the new statement }
  1455. p1:=genzeronode(errorn);
  1456. l:=1;
  1457. while true do
  1458. begin
  1459. case token of
  1460. LKLAMMER : inc(l);
  1461. RKLAMMER : dec(l);
  1462. end;
  1463. consume(token);
  1464. if l=0 then
  1465. break;
  1466. end;*)
  1467. end
  1468. else
  1469. begin
  1470. disposetree(p1);
  1471. p1:=genzeronode(hnewn);
  1472. p1^.resulttype:=ppointerdef(pd)^.definition;
  1473. consume(COMMA);
  1474. afterassignment:=false;
  1475. { determines the current object defintion }
  1476. classh:=pobjectdef(ppointerdef(pd)^.definition);
  1477. { check for an abstract class }
  1478. if (classh^.options and oo_is_abstract)<>0 then
  1479. Message(sym_e_no_instance_of_abstract_object);
  1480. { search the constructor also in the symbol tables of
  1481. the parents }
  1482. { no constructor found }
  1483. sym:=nil;
  1484. while assigned(classh) do
  1485. begin
  1486. sym:=pvarsym(classh^.publicsyms^.search(pattern));
  1487. srsymtable:=classh^.publicsyms;
  1488. if assigned(sym) then
  1489. break;
  1490. classh:=classh^.childof;
  1491. end;
  1492. consume(ID);
  1493. do_member_read(false,sym,p1,pd,again);
  1494. if (p1^.treetype<>calln) or
  1495. (assigned(p1^.procdefinition) and
  1496. ((p1^.procdefinition^.options and poconstructor)=0)) then
  1497. Message(parser_e_expr_have_to_be_constructor_call);
  1498. p1:=gensinglenode(newn,p1);
  1499. { set the resulttype }
  1500. p1^.resulttype:=pd2;
  1501. consume(RKLAMMER);
  1502. end;
  1503. end;
  1504. _SELF : begin
  1505. again:=true;
  1506. consume(_SELF);
  1507. if not assigned(procinfo._class) then
  1508. begin
  1509. p1:=genzeronode(errorn);
  1510. pd:=generrordef;
  1511. again:=false;
  1512. Message(parser_e_self_not_in_method);
  1513. end
  1514. else
  1515. begin
  1516. if (aktprocsym^.definition^.options and poclassmethod)<>0 then
  1517. begin
  1518. { self in class methods is a class reference type }
  1519. pd:=new(pclassrefdef,init(procinfo._class));
  1520. p1:=genselfnode(pd);
  1521. p1^.resulttype:=pd;
  1522. end
  1523. else
  1524. begin
  1525. p1:=genselfnode(procinfo._class);
  1526. p1^.resulttype:=procinfo._class;
  1527. end;
  1528. pd:=p1^.resulttype;
  1529. postfixoperators;
  1530. end;
  1531. end;
  1532. _INHERITED : begin
  1533. again:=true;
  1534. consume(_INHERITED);
  1535. if assigned(procinfo._class) then
  1536. begin
  1537. classh:=procinfo._class^.childof;
  1538. while assigned(classh) do
  1539. begin
  1540. srsymtable:=pobjectdef(classh)^.publicsyms;
  1541. sym:=pvarsym(srsymtable^.search(pattern));
  1542. if assigned(sym) then
  1543. begin
  1544. p1:=genzeronode(typen);
  1545. p1^.resulttype:=classh;
  1546. pd:=p1^.resulttype;
  1547. consume(ID);
  1548. do_member_read(false,sym,p1,pd,again);
  1549. break;
  1550. end;
  1551. classh:=classh^.childof;
  1552. end;
  1553. if classh=nil then
  1554. begin
  1555. Message1(sym_e_id_no_member,pattern);
  1556. again:=false;
  1557. pd:=generrordef;
  1558. p1:=genzeronode(errorn);
  1559. end;
  1560. end
  1561. else
  1562. begin
  1563. Message(parser_e_generic_methods_only_in_methods);
  1564. again:=false;
  1565. pd:=generrordef;
  1566. p1:=genzeronode(errorn);
  1567. end;
  1568. postfixoperators;
  1569. end;
  1570. INTCONST : begin
  1571. valint(pattern,l,code);
  1572. if code<>0 then
  1573. begin
  1574. val(pattern,d,code);
  1575. if code<>0 then
  1576. begin
  1577. Message(cg_e_invalid_integer);
  1578. consume(INTCONST);
  1579. l:=1;
  1580. p1:=genordinalconstnode(l,s32bitdef);
  1581. end
  1582. else
  1583. begin
  1584. consume(INTCONST);
  1585. p1:=genrealconstnode(d,bestrealdef^);
  1586. end;
  1587. end
  1588. else
  1589. begin
  1590. consume(INTCONST);
  1591. p1:=genordinalconstnode(l,s32bitdef);
  1592. end;
  1593. end;
  1594. REALNUMBER : begin
  1595. val(pattern,d,code);
  1596. if code<>0 then
  1597. begin
  1598. Message(parser_e_error_in_real);
  1599. d:=1.0;
  1600. end;
  1601. consume(REALNUMBER);
  1602. p1:=genrealconstnode(d,bestrealdef^);
  1603. end;
  1604. _STRING : begin
  1605. pd:=stringtype;
  1606. { STRING can be also a type cast }
  1607. if token=LKLAMMER then
  1608. begin
  1609. consume(LKLAMMER);
  1610. p1:=comp_expr(true);
  1611. consume(RKLAMMER);
  1612. p1:=gentypeconvnode(p1,pd);
  1613. p1^.explizit:=true;
  1614. { handle postfix operators here e.g. string(a)[10] }
  1615. again:=true;
  1616. postfixoperators;
  1617. end
  1618. else
  1619. p1:=gentypenode(pd);
  1620. end;
  1621. _FILE : begin
  1622. pd:=cfiledef;
  1623. consume(_FILE);
  1624. { FILE can be also a type cast }
  1625. if token=LKLAMMER then
  1626. begin
  1627. consume(LKLAMMER);
  1628. p1:=comp_expr(true);
  1629. consume(RKLAMMER);
  1630. p1:=gentypeconvnode(p1,pd);
  1631. p1^.explizit:=true;
  1632. { handle postfix operators here e.g. string(a)[10] }
  1633. again:=true;
  1634. postfixoperators;
  1635. end
  1636. else
  1637. p1:=gentypenode(pd);
  1638. end;
  1639. CSTRING : begin
  1640. p1:=genstringconstnode(pattern);
  1641. consume(CSTRING);
  1642. end;
  1643. CCHAR : begin
  1644. p1:=genordinalconstnode(ord(pattern[1]),cchardef);
  1645. consume(CCHAR);
  1646. end;
  1647. KLAMMERAFFE : begin
  1648. consume(KLAMMERAFFE);
  1649. p1:=factor(true);
  1650. p1:=gensinglenode(addrn,p1);
  1651. end;
  1652. LKLAMMER : begin
  1653. consume(LKLAMMER);
  1654. p1:=comp_expr(true);
  1655. consume(RKLAMMER);
  1656. { it's not a good solution }
  1657. { but (a+b)^ makes some problems }
  1658. if token in [CARET,POINT,LECKKLAMMER] then
  1659. begin
  1660. { we need the resulttype }
  1661. { of the expression in pd }
  1662. do_firstpass(p1);
  1663. pd:=p1^.resulttype;
  1664. again:=true;
  1665. postfixoperators;
  1666. end;
  1667. end;
  1668. LECKKLAMMER : begin
  1669. consume(LECKKLAMMER);
  1670. p1:=factor_read_set;
  1671. consume(RECKKLAMMER);
  1672. end;
  1673. PLUS : begin
  1674. consume(PLUS);
  1675. p1:=factor(false);
  1676. end;
  1677. MINUS : begin
  1678. consume(MINUS);
  1679. p1:=factor(false);
  1680. p1:=gensinglenode(umminusn,p1);
  1681. end;
  1682. _NOT : begin
  1683. consume(_NOT);
  1684. p1:=factor(false);
  1685. p1:=gensinglenode(notn,p1);
  1686. end;
  1687. _TRUE : begin
  1688. consume(_TRUE);
  1689. p1:=genordinalconstnode(1,booldef);
  1690. end;
  1691. _FALSE : begin
  1692. consume(_FALSE);
  1693. p1:=genordinalconstnode(0,booldef);
  1694. end;
  1695. _NIL : begin
  1696. consume(_NIL);
  1697. p1:=genzeronode(niln);
  1698. end;
  1699. else
  1700. begin
  1701. p1:=genzeronode(errorn);
  1702. consume(token);
  1703. Message(cg_e_illegal_expression);
  1704. end;
  1705. end;
  1706. { generate error node if no node is created }
  1707. if not assigned(p1) then
  1708. p1:=genzeronode(errorn);
  1709. { tp7 procvar handling }
  1710. if (m_tp_procvar in aktmodeswitches) then
  1711. check_tp_procvar(p1);
  1712. factor:=p1;
  1713. check_tokenpos;
  1714. end;
  1715. {****************************************************************************
  1716. Sub_Expr
  1717. ****************************************************************************}
  1718. type
  1719. Toperator_precedence=(opcompare,opaddition,opmultiply);
  1720. Ttok2nodeRec=record
  1721. tok : ttoken;
  1722. nod : ttreetyp;
  1723. end;
  1724. const
  1725. tok2nodes=23;
  1726. tok2node:array[1..tok2nodes] of ttok2noderec=(
  1727. (tok:PLUS ;nod:addn),
  1728. (tok:MINUS ;nod:subn),
  1729. (tok:STAR ;nod:muln),
  1730. (tok:SLASH ;nod:slashn),
  1731. (tok:EQUAL ;nod:equaln),
  1732. (tok:GT ;nod:gtn),
  1733. (tok:LT ;nod:ltn),
  1734. (tok:GTE ;nod:gten),
  1735. (tok:LTE ;nod:lten),
  1736. (tok:SYMDIF ;nod:symdifn),
  1737. (tok:STARSTAR;nod:starstarn),
  1738. (tok:CARET ;nod:caretn),
  1739. (tok:UNEQUAL ;nod:unequaln),
  1740. (tok:_AS ;nod:asn),
  1741. (tok:_IN ;nod:inn),
  1742. (tok:_IS ;nod:isn),
  1743. (tok:_OR ;nod:orn),
  1744. (tok:_AND ;nod:andn),
  1745. (tok:_DIV ;nod:divn),
  1746. (tok:_MOD ;nod:modn),
  1747. (tok:_SHL ;nod:shln),
  1748. (tok:_SHR ;nod:shrn),
  1749. (tok:_XOR ;nod:xorn)
  1750. );
  1751. operator_levels:array[Toperator_precedence] of set of Ttoken=
  1752. ([LT,LTE,GT,GTE,EQUAL,UNEQUAL,_IN,_IS],
  1753. [PLUS,MINUS,_OR,_XOR],
  1754. [CARET,SYMDIF,STARSTAR,STAR,SLASH,_DIV,_MOD,_AND,_SHL,_SHR,_AS]);
  1755. function sub_expr(pred_level:Toperator_precedence;accept_equal : boolean):Ptree;
  1756. {Reads a subexpression while the operators are of the current precedence
  1757. level, or any higher level. Replaces the old term, simpl_expr and
  1758. simpl2_expr.}
  1759. var
  1760. low,high,mid : longint;
  1761. p1,p2 : Ptree;
  1762. oldt : Ttoken;
  1763. filepos : tfileposinfo;
  1764. begin
  1765. if pred_level=opmultiply then
  1766. p1:=factor(false)
  1767. else
  1768. p1:=sub_expr(succ(pred_level),true);
  1769. repeat
  1770. if (token in operator_levels[pred_level]) and
  1771. ((token<>EQUAL) or accept_equal) then
  1772. begin
  1773. oldt:=token;
  1774. filepos:=tokenpos;
  1775. consume(token);
  1776. if pred_level=opmultiply then
  1777. p2:=factor(false)
  1778. else
  1779. p2:=sub_expr(succ(pred_level),true);
  1780. low:=1;
  1781. high:=tok2nodes;
  1782. while (low<high) do
  1783. begin
  1784. mid:=(low+high+1) shr 1;
  1785. if oldt<tok2node[mid].tok then
  1786. high:=mid-1
  1787. else
  1788. low:=mid;
  1789. end;
  1790. if tok2node[high].tok=oldt then
  1791. p1:=gennode(tok2node[high].nod,p1,p2)
  1792. else
  1793. p1:=gennode(nothingn,p1,p2);
  1794. set_tree_filepos(p1,filepos);
  1795. end
  1796. else
  1797. break;
  1798. until false;
  1799. sub_expr:=p1;
  1800. end;
  1801. function comp_expr(accept_equal : boolean):Ptree;
  1802. var
  1803. oldafterassignment : boolean;
  1804. p1 : ptree;
  1805. begin
  1806. oldafterassignment:=afterassignment;
  1807. afterassignment:=true;
  1808. p1:=sub_expr(opcompare,accept_equal);
  1809. afterassignment:=oldafterassignment;
  1810. comp_expr:=p1;
  1811. end;
  1812. function expr : ptree;
  1813. var
  1814. p1,p2 : ptree;
  1815. oldafterassignment : boolean;
  1816. oldp1 : ptree;
  1817. filepos : tfileposinfo;
  1818. begin
  1819. oldafterassignment:=afterassignment;
  1820. p1:=sub_expr(opcompare,true);
  1821. filepos:=tokenpos;
  1822. if (m_tp_procvar in aktmodeswitches) and
  1823. (token<>ASSIGNMENT) then
  1824. check_tp_procvar(p1);
  1825. if token in [ASSIGNMENT,_PLUSASN,_MINUSASN,_STARASN,_SLASHASN] then
  1826. afterassignment:=true;
  1827. oldp1:=p1;
  1828. case token of
  1829. POINTPOINT : begin
  1830. consume(POINTPOINT);
  1831. p2:=sub_expr(opcompare,true);
  1832. p1:=gennode(rangen,p1,p2);
  1833. end;
  1834. ASSIGNMENT : begin
  1835. consume(ASSIGNMENT);
  1836. { avoid a firstpass of a procedure if
  1837. it must be assigned to a procvar }
  1838. { should be recursive for a:=b:=c !!! }
  1839. if (p1^.resulttype<>nil) and (p1^.resulttype^.deftype=procvardef) then
  1840. begin
  1841. getprocvar:=true;
  1842. getprocvardef:=pprocvardef(p1^.resulttype);
  1843. end;
  1844. p2:=sub_expr(opcompare,true);
  1845. if getprocvar then
  1846. begin
  1847. if (p2^.treetype=calln) then
  1848. handle_procvar(getprocvardef,p2)
  1849. else
  1850. { also allow p:= proc(t); !! (PM) }
  1851. if (p2^.treetype=typeconvn) and
  1852. (p2^.left^.treetype=calln) then
  1853. handle_procvar(getprocvardef,p2^.left);
  1854. end;
  1855. getprocvar:=false;
  1856. p1:=gennode(assignn,p1,p2);
  1857. end;
  1858. { this is the code for C like assignements }
  1859. { from an improvement of Peter Schaefer }
  1860. _PLUSASN : begin
  1861. consume(_PLUSASN );
  1862. p2:=sub_expr(opcompare,true);
  1863. p1:=gennode(assignn,p1,gennode(addn,getcopy(p1),p2));
  1864. { was first
  1865. p1:=gennode(assignn,p1,gennode(addn,p1,p2));
  1866. but disposetree assumes that we have a real
  1867. *** tree *** }
  1868. end;
  1869. _MINUSASN : begin
  1870. consume(_MINUSASN );
  1871. p2:=sub_expr(opcompare,true);
  1872. p1:=gennode(assignn,p1,gennode(subn,getcopy(p1),p2));
  1873. end;
  1874. _STARASN : begin
  1875. consume(_STARASN );
  1876. p2:=sub_expr(opcompare,true);
  1877. p1:=gennode(assignn,p1,gennode(muln,getcopy(p1),p2));
  1878. end;
  1879. _SLASHASN : begin
  1880. consume(_SLASHASN );
  1881. p2:=sub_expr(opcompare,true);
  1882. p1:=gennode(assignn,p1,gennode(slashn,getcopy(p1),p2));
  1883. end;
  1884. end;
  1885. afterassignment:=oldafterassignment;
  1886. if p1<>oldp1 then
  1887. set_tree_filepos(p1,filepos);
  1888. expr:=p1;
  1889. end;
  1890. function get_intconst:longint;
  1891. {Reads an expression, tries to evalute it and check if it is an integer
  1892. constant. Then the constant is returned.}
  1893. var
  1894. p:Ptree;
  1895. begin
  1896. p:=comp_expr(true);
  1897. do_firstpass(p);
  1898. if not codegenerror then
  1899. begin
  1900. if (p^.treetype<>ordconstn) and
  1901. (p^.resulttype^.deftype=orddef) and
  1902. not(Porddef(p^.resulttype)^.typ in [uvoid,uchar,bool8bit,bool16bit,bool32bit]) then
  1903. Message(cg_e_illegal_expression)
  1904. else
  1905. get_intconst:=p^.value;
  1906. end;
  1907. disposetree(p);
  1908. end;
  1909. function get_stringconst:string;
  1910. {Reads an expression, tries to evaluate it and checks if it is a string
  1911. constant. Then the constant is returned.}
  1912. var
  1913. p:Ptree;
  1914. begin
  1915. get_stringconst:='';
  1916. p:=comp_expr(true);
  1917. do_firstpass(p);
  1918. if p^.treetype<>stringconstn then
  1919. begin
  1920. if (p^.treetype=ordconstn) and is_char(p^.resulttype) then
  1921. get_stringconst:=char(p^.value)
  1922. else
  1923. Message(cg_e_illegal_expression);
  1924. end
  1925. else
  1926. get_stringconst:=strpas(p^.value_str);
  1927. disposetree(p);
  1928. end;
  1929. end.
  1930. {
  1931. $Log$
  1932. Revision 1.116 1999-06-26 00:24:53 pierre
  1933. * mereg from fixes-0_99_12 branch
  1934. Revision 1.112.2.4 1999/06/26 00:22:30 pierre
  1935. * wrong warnings in -So mode suppressed
  1936. Revision 1.112.2.3 1999/06/17 12:51:44 pierre
  1937. * changed is_assignment_overloaded into
  1938. function assignment_overloaded : pprocdef
  1939. to allow overloading of assignment with only different result type
  1940. Revision 1.112.2.2 1999/06/15 18:54:52 peter
  1941. * more procvar fixes
  1942. Revision 1.112.2.1 1999/06/13 22:38:09 peter
  1943. * tp_procvar check for loading of procvars when getaddr=false
  1944. Revision 1.112 1999/06/02 22:44:11 pierre
  1945. * previous wrong log corrected
  1946. Revision 1.111 1999/06/02 22:25:43 pierre
  1947. * changed $ifdef FPC @ into $ifndef TP
  1948. * changes for correct procvar handling under tp mode
  1949. Revision 1.110 1999/06/01 19:27:55 peter
  1950. * better checks for procvar and methodpointer
  1951. Revision 1.109 1999/05/27 19:44:46 peter
  1952. * removed oldasm
  1953. * plabel -> pasmlabel
  1954. * -a switches to source writing automaticly
  1955. * assembler readers OOPed
  1956. * asmsymbol automaticly external
  1957. * jumptables and other label fixes for asm readers
  1958. Revision 1.108 1999/05/18 14:15:54 peter
  1959. * containsself fixes
  1960. * checktypes()
  1961. Revision 1.107 1999/05/18 09:52:18 peter
  1962. * procedure of object and addrn fixes
  1963. Revision 1.106 1999/05/16 17:06:31 peter
  1964. * remove firstcallparan which looks obsolete
  1965. Revision 1.105 1999/05/12 22:36:09 florian
  1966. * override isn't allowed in objects!
  1967. Revision 1.104 1999/05/07 10:35:23 florian
  1968. * first fix for a problem with method pointer properties, still doesn't work
  1969. with WITH
  1970. Revision 1.103 1999/05/06 21:40:16 peter
  1971. * fixed crash
  1972. Revision 1.101 1999/05/06 09:05:21 peter
  1973. * generic write_float and str_float
  1974. * fixed constant float conversions
  1975. Revision 1.100 1999/05/04 21:44:57 florian
  1976. * changes to compile it with Delphi 4.0
  1977. Revision 1.99 1999/05/01 13:24:31 peter
  1978. * merged nasm compiler
  1979. * old asm moved to oldasm/
  1980. Revision 1.98 1999/04/26 18:29:56 peter
  1981. * farpointerdef moved into pointerdef.is_far
  1982. Revision 1.97 1999/04/19 09:27:48 peter
  1983. * removed my property fix
  1984. Revision 1.96 1999/04/19 09:13:47 peter
  1985. * class property without write support
  1986. Revision 1.95 1999/04/19 06:10:08 florian
  1987. * property problem fixed: a propertysym is only a write
  1988. access if it is followed by a assignment token
  1989. Revision 1.94 1999/04/17 13:12:17 peter
  1990. * addr() internal
  1991. Revision 1.93 1999/04/15 09:00:08 peter
  1992. * fixed property write
  1993. Revision 1.92 1999/04/08 20:59:43 florian
  1994. * fixed problem with default properties which are a class
  1995. * case bug (from the mailing list with -O2) fixed, the
  1996. distance of the case labels can be greater than the positive
  1997. range of a longint => it is now a dword for fpc
  1998. Revision 1.91 1999/04/06 11:21:56 peter
  1999. * more use of ttoken
  2000. Revision 1.90 1999/03/31 13:55:12 peter
  2001. * assembler inlining working for ag386bin
  2002. Revision 1.89 1999/03/26 00:05:36 peter
  2003. * released valintern
  2004. + deffile is now removed when compiling is finished
  2005. * ^( compiles now correct
  2006. + static directive
  2007. * shrd fixed
  2008. Revision 1.88 1999/03/24 23:17:15 peter
  2009. * fixed bugs 212,222,225,227,229,231,233
  2010. Revision 1.87 1999/03/16 17:52:52 jonas
  2011. * changes for internal Val code (do a "make cycle OPT=-dvalintern" to test)
  2012. * in cgi386inl: also range checking for subrange types (compile with "-dreadrangecheck")
  2013. * in cgai386: also small fixes to emitrangecheck
  2014. Revision 1.86 1999/03/04 13:55:44 pierre
  2015. * some m68k fixes (still not compilable !)
  2016. * new(tobj) does not give warning if tobj has no VMT !
  2017. Revision 1.85 1999/02/22 15:09:39 florian
  2018. * behaviaor of PROTECTED and PRIVATE fixed, works now like TP/Delphi
  2019. Revision 1.84 1999/02/22 02:15:26 peter
  2020. * updates for ag386bin
  2021. Revision 1.83 1999/02/11 09:46:25 pierre
  2022. * fix for normal method calls inside static methods :
  2023. WARNING there were both parser and codegen errors !!
  2024. added static_call boolean to calln tree
  2025. Revision 1.82 1999/01/28 14:06:47 florian
  2026. * small fix for method pointers
  2027. * found the annoying strpas bug, mainly nested call to type cast which
  2028. use ansistrings crash
  2029. Revision 1.81 1999/01/27 00:13:55 florian
  2030. * "procedure of object"-stuff fixed
  2031. Revision 1.80 1999/01/21 16:41:01 pierre
  2032. * fix for constructor inside with statements
  2033. Revision 1.79 1998/12/30 22:15:48 peter
  2034. + farpointer type
  2035. * absolutesym now also stores if its far
  2036. Revision 1.78 1998/12/11 00:03:32 peter
  2037. + globtype,tokens,version unit splitted from globals
  2038. Revision 1.77 1998/12/04 10:18:09 florian
  2039. * some stuff for procedures of object added
  2040. * bug with overridden virtual constructors fixed (reported by Italo Gomes)
  2041. Revision 1.76 1998/11/27 14:50:40 peter
  2042. + open strings, $P switch support
  2043. Revision 1.75 1998/11/25 19:12:51 pierre
  2044. * var:=new(pointer_type) support added
  2045. Revision 1.74 1998/11/13 10:18:11 peter
  2046. + nil constants
  2047. Revision 1.73 1998/11/05 12:02:52 peter
  2048. * released useansistring
  2049. * removed -Sv, its now available in fpc modes
  2050. Revision 1.72 1998/11/04 10:11:41 peter
  2051. * ansistring fixes
  2052. Revision 1.71 1998/10/22 23:57:29 peter
  2053. * fixed filedef for typenodetype
  2054. Revision 1.70 1998/10/21 15:12:54 pierre
  2055. * bug fix for IOCHECK inside a procedure with iocheck modifier
  2056. * removed the GPF for unexistant overloading
  2057. (firstcall was called with procedinition=nil !)
  2058. * changed typen to what Florian proposed
  2059. gentypenode(p : pdef) sets the typenodetype field
  2060. and resulttype is only set if inside bt_type block !
  2061. Revision 1.69 1998/10/20 15:10:19 pierre
  2062. * type ptree only allowed inside expression
  2063. if following sizeof typeof low high or as first arg of new !!
  2064. Revision 1.68 1998/10/20 11:15:44 pierre
  2065. * calling of private method allowed inside child object method
  2066. Revision 1.67 1998/10/19 08:54:57 pierre
  2067. * wrong stabs info corrected once again !!
  2068. + variable vmt offset with vmt field only if required
  2069. implemented now !!!
  2070. Revision 1.66 1998/10/15 15:13:28 pierre
  2071. + added oo_hasconstructor and oo_hasdestructor
  2072. for objects options
  2073. Revision 1.65 1998/10/13 13:10:24 peter
  2074. * new style for m68k/i386 infos and enums
  2075. Revision 1.64 1998/10/12 12:20:55 pierre
  2076. + added tai_const_symbol_offset
  2077. for r : pointer = @var.field;
  2078. * better message for different arg names on implementation
  2079. of function
  2080. Revision 1.63 1998/10/12 10:28:30 florian
  2081. + auto dereferencing of pointers to structured types in delphi mode
  2082. Revision 1.62 1998/10/12 10:05:41 peter
  2083. * fixed mem leak with arrayconstrutor
  2084. Revision 1.61 1998/10/05 13:57:15 peter
  2085. * crash preventions
  2086. Revision 1.60 1998/10/05 12:32:46 peter
  2087. + assert() support
  2088. Revision 1.59 1998/10/01 14:56:24 peter
  2089. * crash preventions
  2090. Revision 1.58 1998/09/30 07:40:35 florian
  2091. * better error recovering
  2092. Revision 1.57 1998/09/28 16:18:16 florian
  2093. * two fixes to get ansi strings work
  2094. Revision 1.56 1998/09/26 17:45:36 peter
  2095. + idtoken and only one token table
  2096. Revision 1.55 1998/09/24 23:49:10 peter
  2097. + aktmodeswitches
  2098. Revision 1.54 1998/09/23 15:46:39 florian
  2099. * problem with with and classes fixed
  2100. Revision 1.53 1998/09/23 09:58:54 peter
  2101. * first working array of const things
  2102. Revision 1.52 1998/09/20 09:38:45 florian
  2103. * hasharray for defs fixed
  2104. * ansistring code generation corrected (init/final, assignement)
  2105. Revision 1.51 1998/09/18 16:03:43 florian
  2106. * some changes to compile with Delphi
  2107. Revision 1.50 1998/09/17 13:41:18 pierre
  2108. sizeof(TPOINT) problem
  2109. Revision 1.49.2.1 1998/09/17 08:42:31 pierre
  2110. TPOINT sizeof fix
  2111. Revision 1.49 1998/09/09 11:50:53 pierre
  2112. * forward def are not put in record or objects
  2113. + added check for forwards also in record and objects
  2114. * dummy parasymtable for unit initialization removed from
  2115. symtable stack
  2116. Revision 1.48 1998/09/07 22:25:53 peter
  2117. * fixed str(boolean,string) which was allowed
  2118. * fixed write(' ':<int expression>) only constants where allowed :(
  2119. Revision 1.47 1998/09/07 18:46:10 peter
  2120. * update smartlinking, uses getdatalabel
  2121. * renamed ptree.value vars to value_str,value_real,value_set
  2122. Revision 1.46 1998/09/04 08:42:03 peter
  2123. * updated some error messages
  2124. Revision 1.45 1998/09/01 17:39:49 peter
  2125. + internal constant functions
  2126. Revision 1.44 1998/08/28 10:54:24 peter
  2127. * fixed smallset generation from elements, it has never worked before!
  2128. Revision 1.43 1998/08/23 16:07:24 florian
  2129. * internalerror with mod/div fixed
  2130. Revision 1.42 1998/08/21 14:08:50 pierre
  2131. + TEST_FUNCRET now default (old code removed)
  2132. works also for m68k (at least compiles)
  2133. Revision 1.41 1998/08/20 21:36:39 peter
  2134. * fixed 'with object do' bug
  2135. Revision 1.40 1998/08/20 09:26:41 pierre
  2136. + funcret setting in underproc testing
  2137. compile with _dTEST_FUNCRET
  2138. Revision 1.39 1998/08/18 16:48:48 pierre
  2139. * bug for -So proc assignment to p^rocvar fixed
  2140. Revision 1.38 1998/08/18 14:17:09 pierre
  2141. * bug about assigning the return value of a function to
  2142. a procvar fixed : warning
  2143. assigning a proc to a procvar need @ in FPC mode !!
  2144. * missing file/line info restored
  2145. Revision 1.37 1998/08/18 09:24:43 pierre
  2146. * small warning position bug fixed
  2147. * support_mmx switches splitting was missing
  2148. * rhide error and warning output corrected
  2149. Revision 1.36 1998/08/15 16:50:29 peter
  2150. * fixed proc()=expr which was not allowed anymore by my previous fix
  2151. Revision 1.35 1998/08/14 18:18:46 peter
  2152. + dynamic set contruction
  2153. * smallsets are now working (always longint size)
  2154. Revision 1.34 1998/08/13 11:00:12 peter
  2155. * fixed procedure<>procedure construct
  2156. Revision 1.33 1998/08/11 15:31:39 peter
  2157. * write extended to ppu file
  2158. * new version 0.99.7
  2159. Revision 1.32 1998/08/11 14:05:32 peter
  2160. * fixed sizeof(array of char)
  2161. Revision 1.31 1998/08/10 14:50:11 peter
  2162. + localswitches, moduleswitches, globalswitches splitting
  2163. Revision 1.30 1998/07/28 21:52:54 florian
  2164. + implementation of raise and try..finally
  2165. + some misc. exception stuff
  2166. Revision 1.29 1998/07/27 21:57:13 florian
  2167. * fix to allow tv like stream registration:
  2168. @tmenu.load doesn't work if load had parameters or if load was only
  2169. declared in an anchestor class of tmenu
  2170. Revision 1.28 1998/07/14 21:46:51 peter
  2171. * updated messages file
  2172. Revision 1.27 1998/06/25 14:04:23 peter
  2173. + internal inc/dec
  2174. Revision 1.26 1998/06/09 16:01:46 pierre
  2175. + added procedure directive parsing for procvars
  2176. (accepted are popstack cdecl and pascal)
  2177. + added C vars with the following syntax
  2178. var C calias 'true_c_name';(can be followed by external)
  2179. reason is that you must add the Cprefix
  2180. which is target dependent
  2181. Revision 1.25 1998/06/05 14:37:33 pierre
  2182. * fixes for inline for operators
  2183. * inline procedure more correctly restricted
  2184. Revision 1.24 1998/06/04 23:51:52 peter
  2185. * m68k compiles
  2186. + .def file creation moved to gendef.pas so it could also be used
  2187. for win32
  2188. Revision 1.23 1998/06/04 09:55:40 pierre
  2189. * demangled name of procsym reworked to become independant of the mangling scheme
  2190. Revision 1.22 1998/06/02 17:03:03 pierre
  2191. * with node corrected for objects
  2192. * small bugs for SUPPORT_MMX fixed
  2193. Revision 1.21 1998/05/27 19:45:05 peter
  2194. * symtable.pas splitted into includefiles
  2195. * symtable adapted for $ifdef NEWPPU
  2196. Revision 1.20 1998/05/26 07:53:59 pierre
  2197. * bug fix for empty sets (nil pd was dereferenced )
  2198. Revision 1.19 1998/05/25 17:11:43 pierre
  2199. * firstpasscount bug fixed
  2200. now all is already set correctly the first time
  2201. under EXTDEBUG try -gp to skip all other firstpasses
  2202. it works !!
  2203. * small bug fixes
  2204. - for smallsets with -dTESTSMALLSET
  2205. - some warnings removed (by correcting code !)
  2206. Revision 1.18 1998/05/23 01:21:20 peter
  2207. + aktasmmode, aktoptprocessor, aktoutputformat
  2208. + smartlink per module $SMARTLINK-/+ (like MMX) and moved to aktswitches
  2209. + $LIBNAME to set the library name where the unit will be put in
  2210. * splitted cgi386 a bit (codeseg to large for bp7)
  2211. * nasm, tasm works again. nasm moved to ag386nsm.pas
  2212. Revision 1.17 1998/05/22 12:37:03 carl
  2213. * crash bugfix (patched msanually to main branch)
  2214. Revision 1.16 1998/05/21 19:33:32 peter
  2215. + better procedure directive handling and only one table
  2216. Revision 1.15 1998/05/20 09:42:35 pierre
  2217. + UseTokenInfo now default
  2218. * unit in interface uses and implementation uses gives error now
  2219. * only one error for unknown symbol (uses lastsymknown boolean)
  2220. the problem came from the label code !
  2221. + first inlined procedures and function work
  2222. (warning there might be allowed cases were the result is still wrong !!)
  2223. * UseBrower updated gives a global list of all position of all used symbols
  2224. with switch -gb
  2225. Revision 1.14 1998/05/11 13:07:56 peter
  2226. + $ifdef NEWPPU for the new ppuformat
  2227. + $define GDB not longer required
  2228. * removed all warnings and stripped some log comments
  2229. * no findfirst/findnext anymore to remove smartlink *.o files
  2230. Revision 1.13 1998/05/06 08:38:45 pierre
  2231. * better position info with UseTokenInfo
  2232. UseTokenInfo greatly simplified
  2233. + added check for changed tree after first time firstpass
  2234. (if we could remove all the cases were it happen
  2235. we could skip all firstpass if firstpasscount > 1)
  2236. Only with ExtDebug
  2237. Revision 1.12 1998/05/05 12:05:42 florian
  2238. * problems with properties fixed
  2239. * crash fixed: i:=l when i and l are undefined, was a problem with
  2240. implementation of private/protected
  2241. Revision 1.11 1998/05/04 11:22:26 florian
  2242. * problem with DOM solved: it crashes when accessing a property in a method
  2243. Revision 1.10 1998/05/01 16:38:45 florian
  2244. * handling of private and protected fixed
  2245. + change_keywords_to_tp implemented to remove
  2246. keywords which aren't supported by tp
  2247. * break and continue are now symbols of the system unit
  2248. + widestring, longstring and ansistring type released
  2249. Revision 1.9 1998/04/29 10:33:58 pierre
  2250. + added some code for ansistring (not complete nor working yet)
  2251. * corrected operator overloading
  2252. * corrected nasm output
  2253. + started inline procedures
  2254. + added starstarn : use ** for exponentiation (^ gave problems)
  2255. + started UseTokenInfo cond to get accurate positions
  2256. Revision 1.8 1998/04/14 23:27:03 florian
  2257. + exclude/include with constant second parameter added
  2258. Revision 1.7 1998/04/09 23:02:15 florian
  2259. * small problems solved to get remake3 work
  2260. Revision 1.6 1998/04/09 22:16:35 florian
  2261. * problem with previous REGALLOC solved
  2262. * improved property support
  2263. Revision 1.5 1998/04/08 10:26:09 florian
  2264. * correct error handling of virtual constructors
  2265. * problem with new type declaration handling fixed
  2266. Revision 1.4 1998/04/07 22:45:05 florian
  2267. * bug0092, bug0115 and bug0121 fixed
  2268. + packed object/class/array
  2269. Revision 1.3 1998/04/07 13:19:46 pierre
  2270. * bugfixes for reset_gdb_info
  2271. in MEM parsing for go32v2
  2272. better external symbol creation
  2273. support for rhgdb.exe (lowercase file names)
  2274. }