pexpr.pas 87 KB

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