pexpr.pas 89 KB

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