pexpr.pas 93 KB

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