pexpr.pas 89 KB

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