pexpr.pas 88 KB

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