pexpr.pas 88 KB

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