psub.pas 92 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767
  1. {
  2. $Id$
  3. Copyright (c) 1998 by Florian Klaempfl, Daniel Mantione
  4. Does the parsing of the procedures/functions
  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 psub;
  19. interface
  20. uses
  21. cobjects,
  22. symconst,symtable;
  23. const
  24. pd_global = $1; { directive must be global }
  25. pd_body = $2; { directive needs a body }
  26. pd_implemen = $4; { directive can be used implementation section }
  27. pd_interface = $8; { directive can be used interface section }
  28. pd_object = $10; { directive can be used object declaration }
  29. pd_procvar = $20; { directive can be used procvar declaration }
  30. pd_notobject = $40;{ directive can not be used object declaration }
  31. procedure compile_proc_body(const proc_names:Tstringcontainer;
  32. make_global,parent_has_class:boolean);
  33. procedure parse_proc_head(options:tproctypeoption);
  34. procedure parse_proc_dec;
  35. procedure parse_var_proc_directives(var sym : ptypesym);
  36. procedure parse_object_proc_directives(var sym : pprocsym);
  37. procedure read_proc;
  38. implementation
  39. uses
  40. globtype,systems,tokens,
  41. strings,globals,verbose,files,
  42. scanner,aasm,tree,types,
  43. import,gendef,
  44. hcodegen,temp_gen,pass_1,cpubase,cpuasm
  45. {$ifndef NOPASS2}
  46. ,pass_2
  47. {$endif}
  48. {$ifdef GDB}
  49. ,gdb
  50. {$endif GDB}
  51. {$ifdef i386}
  52. ,tgeni386
  53. {$ifndef newcg}
  54. ,cgai386
  55. {$endif newcg}
  56. {$ifndef NoOpt}
  57. ,aopt386
  58. {$endif}
  59. {$endif}
  60. {$ifdef m68k}
  61. ,tgen68k,cga68k
  62. {$endif}
  63. { parser specific stuff }
  64. ,pbase,pdecl,pexpr,pstatmnt
  65. {$ifdef newcg}
  66. ,tgcpu,convtree,cgobj,tgeni386 { for the new code generator tgeni386 is only a dummy }
  67. {$endif newcg}
  68. ;
  69. var
  70. realname:string; { contains the real name of a procedure as it's typed }
  71. procedure formal_parameter_list;
  72. {
  73. handle_procvar needs the same changes
  74. }
  75. var
  76. sc : Pstringcontainer;
  77. s : string;
  78. storetokenpos : tfileposinfo;
  79. p : Pdef;
  80. hsym : psym;
  81. hvs,
  82. vs : Pvarsym;
  83. hs1,hs2 : string;
  84. varspez : Tvarspez;
  85. inserthigh : boolean;
  86. begin
  87. consume(_LKLAMMER);
  88. inc(testcurobject);
  89. repeat
  90. if try_to_consume(_VAR) then
  91. varspez:=vs_var
  92. else
  93. if try_to_consume(_CONST) then
  94. varspez:=vs_const
  95. else
  96. varspez:=vs_value;
  97. inserthigh:=false;
  98. readtypesym:=nil;
  99. if idtoken=_SELF then
  100. begin
  101. { we parse the defintion in the class definition }
  102. if assigned(procinfo._class) and procinfo._class^.is_class then
  103. begin
  104. {$ifndef UseNiceNames}
  105. hs2:=hs2+'$'+'self';
  106. {$else UseNiceNames}
  107. hs2:=hs2+tostr(length('self'))+'self';
  108. {$endif UseNiceNames}
  109. vs:=new(Pvarsym,init('@',procinfo._class));
  110. vs^.varspez:=vs_var;
  111. { insert the sym in the parasymtable }
  112. aktprocsym^.definition^.parast^.insert(vs);
  113. {$ifdef INCLUDEOK}
  114. include(aktprocsym^.definition^.procoptions,po_containsself);
  115. {$else}
  116. aktprocsym^.definition^.procoptions:=aktprocsym^.definition^.procoptions+[po_containsself];
  117. {$endif}
  118. inc(procinfo.ESI_offset,vs^.address);
  119. consume(idtoken);
  120. consume(_COLON);
  121. p:=single_type(hs1);
  122. if assigned(readtypesym) then
  123. aktprocsym^.definition^.concattypesym(readtypesym,vs_value)
  124. else
  125. aktprocsym^.definition^.concatdef(p,vs_value);
  126. CheckTypes(p,procinfo._class);
  127. end
  128. else
  129. consume(_ID);
  130. end
  131. else
  132. begin
  133. { read identifiers }
  134. sc:=idlist;
  135. { read type declaration, force reading for value and const paras }
  136. if (token=_COLON) or (varspez=vs_value) then
  137. begin
  138. consume(_COLON);
  139. { check for an open array }
  140. if token=_ARRAY then
  141. begin
  142. consume(_ARRAY);
  143. consume(_OF);
  144. { define range and type of range }
  145. p:=new(Parraydef,init(0,-1,s32bitdef));
  146. { array of const ? }
  147. if (token=_CONST) and (m_objpas in aktmodeswitches) then
  148. begin
  149. consume(_CONST);
  150. srsym:=nil;
  151. if assigned(objpasunit) then
  152. getsymonlyin(objpasunit,'TVARREC');
  153. if not assigned(srsym) then
  154. InternalError(1234124);
  155. Parraydef(p)^.definition:=ptypesym(srsym)^.definition;
  156. Parraydef(p)^.IsArrayOfConst:=true;
  157. hs1:='array_of_const';
  158. end
  159. else
  160. begin
  161. { define field type }
  162. Parraydef(p)^.definition:=single_type(hs1);
  163. hs1:='array_of_'+hs1;
  164. { we don't need the typesym anymore }
  165. readtypesym:=nil;
  166. end;
  167. inserthigh:=true;
  168. end
  169. { open string ? }
  170. else if (varspez=vs_var) and
  171. (
  172. (
  173. ((token=_STRING) or (idtoken=_SHORTSTRING)) and
  174. (cs_openstring in aktmoduleswitches) and
  175. not(cs_ansistrings in aktlocalswitches)
  176. ) or
  177. (idtoken=_OPENSTRING)) then
  178. begin
  179. consume(token);
  180. p:=openshortstringdef;
  181. hs1:='openstring';
  182. inserthigh:=true;
  183. end
  184. { everything else }
  185. else
  186. p:=single_type(hs1);
  187. end
  188. else
  189. begin
  190. {$ifndef UseNiceNames}
  191. hs1:='$$$';
  192. {$else UseNiceNames}
  193. hs1:='var';
  194. {$endif UseNiceNames}
  195. p:=cformaldef;
  196. { }
  197. end;
  198. hs2:=aktprocsym^.definition^.mangledname;
  199. storetokenpos:=tokenpos;
  200. while not sc^.empty do
  201. begin
  202. {$ifndef UseNiceNames}
  203. hs2:=hs2+'$'+hs1;
  204. {$else UseNiceNames}
  205. hs2:=hs2+tostr(length(hs1))+hs1;
  206. {$endif UseNiceNames}
  207. s:=sc^.get_with_tokeninfo(tokenpos);
  208. if assigned(readtypesym) then
  209. begin
  210. aktprocsym^.definition^.concattypesym(readtypesym,varspez);
  211. vs:=new(Pvarsym,initsym(s,readtypesym))
  212. end
  213. else
  214. begin
  215. aktprocsym^.definition^.concatdef(p,varspez);
  216. vs:=new(Pvarsym,init(s,p));
  217. end;
  218. vs^.varspez:=varspez;
  219. { we have to add this to avoid var param to be in registers !!!}
  220. if (varspez in [vs_var,vs_const]) and push_addr_param(p) then
  221. {$ifdef INCLUDEOK}
  222. include(vs^.varoptions,vo_regable);
  223. {$else}
  224. vs^.varoptions:=vs^.varoptions+[vo_regable];
  225. {$endif}
  226. { search for duplicate ids in object members/methods }
  227. { but only the current class, I don't know why ... }
  228. { at least TP and Delphi do it in that way (FK) }
  229. if assigned(procinfo._class) and
  230. (lexlevel=normal_function_level) then
  231. begin
  232. hsym:=procinfo._class^.symtable^.search(vs^.name);
  233. if assigned(hsym) then
  234. DuplicateSym(hsym);
  235. end;
  236. { do we need a local copy }
  237. if (varspez=vs_value) and push_addr_param(p) and
  238. not(is_open_array(p) or is_array_of_const(p)) then
  239. vs^.setname('val'+vs^.name);
  240. { insert the sym in the parasymtable }
  241. aktprocsym^.definition^.parast^.insert(vs);
  242. { also need to push a high value? }
  243. if inserthigh then
  244. begin
  245. hvs:=new(Pvarsym,init('high'+s,s32bitdef));
  246. hvs^.varspez:=vs_const;
  247. aktprocsym^.definition^.parast^.insert(hvs);
  248. end;
  249. end;
  250. dispose(sc,done);
  251. tokenpos:=storetokenpos;
  252. end;
  253. aktprocsym^.definition^.setmangledname(hs2);
  254. until not try_to_consume(_SEMICOLON);
  255. dec(testcurobject);
  256. consume(_RKLAMMER);
  257. end;
  258. procedure parse_proc_head(options:tproctypeoption);
  259. var sp:stringid;
  260. pd:Pprocdef;
  261. paramoffset:longint;
  262. sym:Psym;
  263. hs:string;
  264. st : psymtable;
  265. overloaded_level:word;
  266. procstartfilepos : tfileposinfo;
  267. begin
  268. { Save the position where this procedure really starts and set col to 1 which
  269. looks nicer }
  270. procstartfilepos:=aktfilepos;
  271. procstartfilepos.column:=1;
  272. if (options=potype_operator) then
  273. begin
  274. sp:=overloaded_names[optoken];
  275. realname:=sp;
  276. end
  277. else
  278. begin
  279. sp:=pattern;
  280. realname:=orgpattern;
  281. consume(_ID);
  282. end;
  283. { method ? }
  284. if not(parse_only) and try_to_consume(_POINT) then
  285. begin
  286. getsym(sp,true);
  287. sym:=srsym;
  288. { qualifier is class name ? }
  289. if (sym^.typ<>typesym) or
  290. (ptypesym(sym)^.definition^.deftype<>objectdef) then
  291. begin
  292. Message(parser_e_class_id_expected);
  293. aktprocsym:=nil;
  294. consume(_ID);
  295. end
  296. else
  297. begin
  298. { used to allow private syms to be seen }
  299. aktobjectdef:=pobjectdef(ptypesym(sym)^.definition);
  300. sp:=pattern;
  301. realname:=orgpattern;
  302. consume(_ID);
  303. procinfo._class:=pobjectdef(ptypesym(sym)^.definition);
  304. aktprocsym:=pprocsym(procinfo._class^.symtable^.search(sp));
  305. {The procedure has been found. So it is
  306. a global one. Set the flags to mark this.}
  307. procinfo.flags:=procinfo.flags or pi_is_global;
  308. aktobjectdef:=nil;
  309. { we solve this below }
  310. if not(assigned(aktprocsym)) then
  311. Message(parser_e_methode_id_expected);
  312. end;
  313. end
  314. else
  315. begin
  316. { check for constructor/destructor which is not allowed here }
  317. if (not parse_only) and
  318. (options in [potype_constructor,potype_destructor]) then
  319. Message(parser_e_constructors_always_objects);
  320. aktprocsym:=pprocsym(symtablestack^.search(sp));
  321. if lexlevel=normal_function_level then
  322. {$ifdef UseNiceNames}
  323. hs:=procprefix+'_'+tostr(length(sp))+sp
  324. {$else UseNiceNames}
  325. hs:=procprefix+'_'+sp
  326. {$endif UseNiceNames}
  327. else
  328. {$ifdef UseNiceNames}
  329. hs:=lowercase(procprefix)+'_'+tostr(length(sp))+sp;
  330. {$else UseNiceNames}
  331. hs:=procprefix+'_$'+sp;
  332. {$endif UseNiceNames}
  333. if not(parse_only) then
  334. begin
  335. {The procedure we prepare for is in the implementation
  336. part of the unit we compile. It is also possible that we
  337. are compiling a program, which is also some kind of
  338. implementaion part.
  339. We need to find out if the procedure is global. If it is
  340. global, it is in the global symtable.}
  341. if not assigned(aktprocsym) then
  342. begin
  343. {Search the procedure in the global symtable.}
  344. aktprocsym:=Pprocsym(search_a_symtable(sp,globalsymtable));
  345. if assigned(aktprocsym) then
  346. begin
  347. {Check if it is a procedure.}
  348. if aktprocsym^.typ<>procsym then
  349. DuplicateSym(aktprocsym);
  350. {The procedure has been found. So it is
  351. a global one. Set the flags to mark this.}
  352. procinfo.flags:=procinfo.flags or pi_is_global;
  353. end;
  354. end;
  355. end;
  356. end;
  357. { problem with procedures inside methods }
  358. {$ifndef UseNiceNames}
  359. if assigned(procinfo._class) then
  360. if (pos('_$$_',procprefix)=0) then
  361. hs:=procprefix+'_$$_'+procinfo._class^.objname^+'_$$_'+sp
  362. else
  363. hs:=procprefix+'_$'+sp;
  364. {$else UseNiceNames}
  365. if assigned(procinfo._class) then
  366. if (pos('_5Class_',procprefix)=0) then
  367. hs:=procprefix+'_5Class_'+procinfo._class^.name^+'_'+tostr(length(sp))+sp
  368. else
  369. hs:=procprefix+'_'+tostr(length(sp))+sp;
  370. {$endif UseNiceNames}
  371. if assigned(aktprocsym) then
  372. begin
  373. { Check if overloading is enabled }
  374. if not(m_fpc in aktmodeswitches) then
  375. begin
  376. if aktprocsym^.typ<>procsym then
  377. begin
  378. DuplicateSym(aktprocsym);
  379. { try to recover by creating a new aktprocsym }
  380. aktprocsym:=new(pprocsym,init(sp));
  381. end
  382. else
  383. begin
  384. if not(aktprocsym^.definition^.forwarddef) then
  385. Message(parser_e_procedure_overloading_is_off);
  386. end;
  387. end
  388. else
  389. begin
  390. { Check if the overloaded sym is realy a procsym }
  391. if aktprocsym^.typ<>procsym then
  392. begin
  393. Message1(parser_e_overloaded_no_procedure,aktprocsym^.name);
  394. { try to recover by creating a new aktprocsym }
  395. aktprocsym:=new(pprocsym,init(sp));
  396. end;
  397. end;
  398. end
  399. else
  400. begin
  401. { create a new procsym and set the real filepos }
  402. aktprocsym:=new(pprocsym,init(sp));
  403. { for operator we have only one definition for each overloaded
  404. operation }
  405. if (options=potype_operator) then
  406. begin
  407. { the only problem is that nextoverloaded might not be in a unit
  408. known for the unit itself }
  409. if assigned(overloaded_operators[optoken]) then
  410. aktprocsym^.definition:=overloaded_operators[optoken]^.definition;
  411. end;
  412. symtablestack^.insert(aktprocsym);
  413. end;
  414. st:=symtablestack;
  415. pd:=new(pprocdef,init);
  416. pd^.symtablelevel:=symtablestack^.symtablelevel;
  417. if assigned(procinfo._class) then
  418. pd^._class := procinfo._class;
  419. { set the options from the caller (podestructor or poconstructor) }
  420. pd^.proctypeoption:=options;
  421. { calculate the offset of the parameters }
  422. paramoffset:=8;
  423. { calculate frame pointer offset }
  424. if lexlevel>normal_function_level then
  425. begin
  426. procinfo.framepointer_offset:=paramoffset;
  427. inc(paramoffset,target_os.size_of_pointer);
  428. { this is needed to get correct framepointer push for local
  429. forward functions !! }
  430. pd^.parast^.symtablelevel:=lexlevel;
  431. end;
  432. if assigned (Procinfo._Class) and
  433. not(Procinfo._Class^.is_class) and
  434. (pd^.proctypeoption in [potype_constructor,potype_destructor]) then
  435. inc(paramoffset,target_os.size_of_pointer);
  436. { self pointer offset }
  437. { self isn't pushed in nested procedure of methods }
  438. if assigned(procinfo._class) and (lexlevel=normal_function_level) then
  439. begin
  440. procinfo.ESI_offset:=paramoffset;
  441. if assigned(aktprocsym^.definition) and
  442. not(po_containsself in aktprocsym^.definition^.procoptions) then
  443. inc(paramoffset,target_os.size_of_pointer);
  444. end;
  445. { destructor flag ? }
  446. if assigned (Procinfo._Class) and
  447. procinfo._class^.is_class and
  448. (pd^.proctypeoption=potype_destructor) then
  449. inc(paramoffset,target_os.size_of_pointer);
  450. procinfo.call_offset:=paramoffset;
  451. pd^.parast^.datasize:=0;
  452. pd^.nextoverloaded:=aktprocsym^.definition;
  453. aktprocsym^.definition:=pd;
  454. aktprocsym^.definition^.fileinfo:=procstartfilepos;
  455. aktprocsym^.definition^.setmangledname(hs);
  456. aktprocsym^.definition^.procsym:=aktprocsym;
  457. { update also the current filepos for aktprocsym }
  458. aktprocsym^.fileinfo:=procstartfilepos;
  459. if not parse_only then
  460. begin
  461. overloaded_level:=0;
  462. { we need another procprefix !!! }
  463. { count, but only those in the same unit !!}
  464. while assigned(pd) and
  465. (pd^.owner^.symtabletype in [globalsymtable,staticsymtable]) do
  466. begin
  467. { only count already implemented functions }
  468. if not(pd^.forwarddef) then
  469. inc(overloaded_level);
  470. pd:=pd^.nextoverloaded;
  471. end;
  472. if overloaded_level>0 then
  473. procprefix:=hs+'$'+tostr(overloaded_level)+'$'
  474. else
  475. procprefix:=hs+'$';
  476. end;
  477. { this must also be inserted in the right symtable !! PM }
  478. { otherwise we get subbtle problems with
  479. definitions of args defs in staticsymtable for
  480. implementation of a global method }
  481. if token=_LKLAMMER then
  482. formal_parameter_list;
  483. { so we only restore the symtable now }
  484. symtablestack:=st;
  485. if (options=potype_operator) then
  486. overloaded_operators[optoken]:=aktprocsym;
  487. end;
  488. procedure parse_proc_dec;
  489. var
  490. hs : string;
  491. isclassmethod : boolean;
  492. begin
  493. inc(lexlevel);
  494. { read class method }
  495. if token=_CLASS then
  496. begin
  497. consume(_CLASS);
  498. isclassmethod:=true;
  499. end
  500. else
  501. isclassmethod:=false;
  502. case token of
  503. _FUNCTION : begin
  504. consume(_FUNCTION);
  505. parse_proc_head(potype_none);
  506. if token<>_COLON then
  507. begin
  508. if not(aktprocsym^.definition^.forwarddef) or
  509. (m_repeat_forward in aktmodeswitches) then
  510. begin
  511. consume(_COLON);
  512. consume_all_until(_SEMICOLON);
  513. end;
  514. end
  515. else
  516. begin
  517. consume(_COLON);
  518. inc(testcurobject);
  519. aktprocsym^.definition^.retdef:=single_type(hs);
  520. aktprocsym^.definition^.test_if_fpu_result;
  521. dec(testcurobject);
  522. end;
  523. end;
  524. _PROCEDURE : begin
  525. consume(_PROCEDURE);
  526. parse_proc_head(potype_none);
  527. aktprocsym^.definition^.retdef:=voiddef;
  528. end;
  529. _CONSTRUCTOR : begin
  530. consume(_CONSTRUCTOR);
  531. parse_proc_head(potype_constructor);
  532. if assigned(procinfo._class) and
  533. procinfo._class^.is_class then
  534. begin
  535. { CLASS constructors return the created instance }
  536. aktprocsym^.definition^.retdef:=procinfo._class;
  537. end
  538. else
  539. begin
  540. { OBJECT constructors return a boolean }
  541. {$IfDef GDB}
  542. { GDB doesn't like unnamed types !}
  543. aktprocsym^.definition^.retdef:=globaldef('boolean');
  544. {$else GDB}
  545. aktprocsym^.definition^.retdef:=new(porddef,init(bool8bit,0,1));
  546. {$Endif GDB}
  547. end;
  548. end;
  549. _DESTRUCTOR : begin
  550. consume(_DESTRUCTOR);
  551. parse_proc_head(potype_destructor);
  552. aktprocsym^.definition^.retdef:=voiddef;
  553. end;
  554. _OPERATOR : begin
  555. if lexlevel>normal_function_level then
  556. Message(parser_e_no_local_operator);
  557. consume(_OPERATOR);
  558. if not(token in [_PLUS..last_overloaded]) then
  559. Message(parser_e_overload_operator_failed);
  560. optoken:=token;
  561. consume(Token);
  562. procinfo.flags:=procinfo.flags or pi_operator;
  563. parse_proc_head(potype_operator);
  564. if token<>_ID then
  565. begin
  566. opsym:=nil;
  567. if not(m_result in aktmodeswitches) then
  568. consume(_ID);
  569. end
  570. else
  571. begin
  572. opsym:=new(pvarsym,init(pattern,voiddef));
  573. consume(_ID);
  574. end;
  575. if not try_to_consume(_COLON) then
  576. begin
  577. consume(_COLON);
  578. aktprocsym^.definition^.retdef:=generrordef;
  579. consume_all_until(_SEMICOLON);
  580. end
  581. else
  582. begin
  583. aktprocsym^.definition^.retdef:=
  584. single_type(hs);
  585. aktprocsym^.definition^.test_if_fpu_result;
  586. if (optoken in [_EQUAL,_GT,_LT,_GTE,_LTE]) and
  587. ((aktprocsym^.definition^.retdef^.deftype<>
  588. orddef) or (porddef(aktprocsym^.definition^.
  589. retdef)^.typ<>bool8bit)) then
  590. Message(parser_e_comparative_operator_return_boolean);
  591. if assigned(opsym) then
  592. opsym^.definition:=aktprocsym^.definition^.retdef;
  593. { We need to add the retrun type in the mangledname
  594. to allow overloading with just different results !! (PM) }
  595. aktprocsym^.definition^.setmangledname(
  596. aktprocsym^.definition^.mangledname+'$$'+hs);
  597. end;
  598. end;
  599. end;
  600. if isclassmethod and
  601. assigned(aktprocsym) then
  602. {$ifdef INCLUDEOK}
  603. include(aktprocsym^.definition^.procoptions,po_classmethod);
  604. {$else}
  605. aktprocsym^.definition^.procoptions:=aktprocsym^.definition^.procoptions+[po_classmethod];
  606. {$endif}
  607. consume(_SEMICOLON);
  608. dec(lexlevel);
  609. end;
  610. {****************************************************************************
  611. Procedure directive handlers
  612. ****************************************************************************}
  613. {$ifdef tp}
  614. {$F+}
  615. {$endif}
  616. procedure pd_far(const procnames:Tstringcontainer);
  617. begin
  618. Message(parser_w_proc_far_ignored);
  619. end;
  620. procedure pd_near(const procnames:Tstringcontainer);
  621. begin
  622. Message(parser_w_proc_near_ignored);
  623. end;
  624. procedure pd_export(const procnames:Tstringcontainer);
  625. begin
  626. if assigned(procinfo._class) then
  627. Message(parser_e_methods_dont_be_export);
  628. if lexlevel<>normal_function_level then
  629. Message(parser_e_dont_nest_export);
  630. { only os/2 needs this }
  631. if target_info.target=target_i386_os2 then
  632. begin
  633. procnames.insert(realname);
  634. procinfo.exported:=true;
  635. if cs_link_deffile in aktglobalswitches then
  636. deffile.AddExport(aktprocsym^.definition^.mangledname);
  637. end;
  638. end;
  639. procedure pd_inline(const procnames:Tstringcontainer);
  640. begin
  641. if not(cs_support_inline in aktmoduleswitches) then
  642. Message(parser_e_proc_inline_not_supported);
  643. end;
  644. procedure pd_forward(const procnames:Tstringcontainer);
  645. begin
  646. aktprocsym^.definition^.forwarddef:=true;
  647. {$ifdef INCLUDEOK}
  648. include(aktprocsym^.symoptions,sp_forwarddef);
  649. {$else}
  650. aktprocsym^.symoptions:=aktprocsym^.symoptions+[sp_forwarddef];
  651. {$endif}
  652. end;
  653. procedure pd_stdcall(const procnames:Tstringcontainer);
  654. begin
  655. end;
  656. procedure pd_safecall(const procnames:Tstringcontainer);
  657. begin
  658. end;
  659. procedure pd_alias(const procnames:Tstringcontainer);
  660. begin
  661. consume(_COLON);
  662. procnames.insert(get_stringconst);
  663. end;
  664. procedure pd_asmname(const procnames:Tstringcontainer);
  665. begin
  666. aktprocsym^.definition^.setmangledname(target_os.Cprefix+pattern);
  667. if token=_CCHAR then
  668. consume(_CCHAR)
  669. else
  670. consume(_CSTRING);
  671. { we don't need anything else }
  672. aktprocsym^.definition^.forwarddef:=false;
  673. end;
  674. procedure pd_intern(const procnames:Tstringcontainer);
  675. begin
  676. consume(_COLON);
  677. aktprocsym^.definition^.extnumber:=get_intconst;
  678. end;
  679. procedure pd_system(const procnames:Tstringcontainer);
  680. begin
  681. aktprocsym^.definition^.setmangledname(realname);
  682. end;
  683. procedure pd_abstract(const procnames:Tstringcontainer);
  684. begin
  685. if (po_virtualmethod in aktprocsym^.definition^.procoptions) then
  686. {$ifdef INCLUDEOK}
  687. include(aktprocsym^.definition^.procoptions,po_abstractmethod)
  688. {$else}
  689. aktprocsym^.definition^.procoptions:=aktprocsym^.definition^.procoptions+[po_abstractmethod]
  690. {$endif}
  691. else
  692. Message(parser_e_only_virtual_methods_abstract);
  693. { the method is defined }
  694. aktprocsym^.definition^.forwarddef:=false;
  695. end;
  696. procedure pd_virtual(const procnames:Tstringcontainer);
  697. begin
  698. if (aktprocsym^.definition^.proctypeoption=potype_constructor) and
  699. not(aktprocsym^.definition^._class^.is_class) then
  700. Message(parser_e_constructor_cannot_be_not_virtual);
  701. end;
  702. procedure pd_static(const procnames:Tstringcontainer);
  703. begin
  704. if (cs_static_keyword in aktmoduleswitches) then
  705. begin
  706. {$ifdef INCLUDEOK}
  707. include(aktprocsym^.symoptions,sp_static);
  708. include(aktprocsym^.definition^.procoptions,po_staticmethod);
  709. {$else}
  710. aktprocsym^.symoptions:=aktprocsym^.symoptions+[sp_static];
  711. aktprocsym^.definition^.procoptions:=aktprocsym^.definition^.procoptions+[po_staticmethod];
  712. {$endif}
  713. end;
  714. end;
  715. procedure pd_override(const procnames:Tstringcontainer);
  716. begin
  717. if not(aktprocsym^.definition^._class^.is_class) then
  718. Message(parser_e_no_object_override);
  719. end;
  720. procedure pd_message(const procnames:Tstringcontainer);
  721. var
  722. pt : ptree;
  723. begin
  724. { check parameter type }
  725. if not(po_containsself in aktprocsym^.definition^.procoptions) and
  726. (assigned(aktprocsym^.definition^.para1^.next) or
  727. (aktprocsym^.definition^.para1^.paratyp<>vs_var)) then
  728. Message(parser_e_ill_msg_param);
  729. pt:=comp_expr(true);
  730. do_firstpass(pt);
  731. if pt^.treetype=stringconstn then
  732. begin
  733. {$ifdef INCLUDEOK}
  734. include(aktprocsym^.definition^.procoptions,po_msgstr);
  735. {$else}
  736. aktprocsym^.definition^.procoptions:=aktprocsym^.definition^.procoptions+[po_msgstr];
  737. {$endif}
  738. aktprocsym^.definition^.messageinf.str:=strnew(pt^.value_str);
  739. end
  740. else
  741. if is_constintnode(pt) then
  742. begin
  743. {$ifdef INCLUDEOK}
  744. include(aktprocsym^.definition^.procoptions,po_msgint);
  745. {$else}
  746. aktprocsym^.definition^.procoptions:=aktprocsym^.definition^.procoptions+[po_msgint];
  747. {$endif}
  748. aktprocsym^.definition^.messageinf.i:=pt^.value;
  749. end
  750. else
  751. Message(parser_e_ill_msg_expr);
  752. disposetree(pt);
  753. end;
  754. procedure pd_cdecl(const procnames:Tstringcontainer);
  755. begin
  756. if aktprocsym^.definition^.deftype<>procvardef then
  757. aktprocsym^.definition^.setmangledname(target_os.Cprefix+realname);
  758. end;
  759. procedure pd_register(const procnames:Tstringcontainer);
  760. begin
  761. Message(parser_w_proc_register_ignored);
  762. end;
  763. procedure pd_syscall(const procnames:Tstringcontainer);
  764. begin
  765. aktprocsym^.definition^.forwarddef:=false;
  766. aktprocsym^.definition^.extnumber:=get_intconst;
  767. end;
  768. procedure pd_external(const procnames:Tstringcontainer);
  769. {
  770. If import_dll=nil the procedure is assumed to be in another
  771. object file. In that object file it should have the name to
  772. which import_name is pointing to. Otherwise, the procedure is
  773. assumed to be in the DLL to which import_dll is pointing to. In
  774. that case either import_nr<>0 or import_name<>nil is true, so
  775. the procedure is either imported by number or by name. (DM)
  776. }
  777. var
  778. import_dll,
  779. import_name : string;
  780. import_nr : word;
  781. begin
  782. aktprocsym^.definition^.forwarddef:=false;
  783. { If the procedure should be imported from a DLL, a constant string follows.
  784. This isn't really correct, an contant string expression follows
  785. so we check if an semicolon follows, else a string constant have to
  786. follow (FK) }
  787. import_nr:=0;
  788. import_name:='';
  789. if not(token=_SEMICOLON) and not(idtoken=_NAME) then
  790. begin
  791. import_dll:=get_stringconst;
  792. if (idtoken=_NAME) then
  793. begin
  794. consume(_NAME);
  795. import_name:=get_stringconst;
  796. end;
  797. if (idtoken=_INDEX) then
  798. begin
  799. {After the word index follows the index number in the DLL.}
  800. consume(_INDEX);
  801. import_nr:=get_intconst;
  802. end;
  803. if (import_nr=0) and (import_name='') then
  804. {if (aktprocsym^.definition^.options and pocdecl)<>0 then
  805. import_name:=aktprocsym^.definition^.mangledname
  806. else
  807. Message(parser_w_empty_import_name);}
  808. { this should work both for win32 and Linux !! PM }
  809. import_name:=realname;
  810. if not(current_module^.uses_imports) then
  811. begin
  812. current_module^.uses_imports:=true;
  813. importlib^.preparelib(current_module^.modulename^);
  814. end;
  815. if not(m_repeat_forward in aktmodeswitches) then
  816. begin
  817. { we can only have one overloaded here ! }
  818. if assigned(aktprocsym^.definition^.nextoverloaded) then
  819. importlib^.importprocedure(aktprocsym^.definition^.nextoverloaded^.mangledname,
  820. import_dll,import_nr,import_name)
  821. else
  822. importlib^.importprocedure(aktprocsym^.mangledname,import_dll,import_nr,import_name);
  823. end
  824. else
  825. importlib^.importprocedure(aktprocsym^.mangledname,import_dll,import_nr,import_name);
  826. end
  827. else
  828. begin
  829. if (idtoken=_NAME) then
  830. begin
  831. consume(_NAME);
  832. import_name:=get_stringconst;
  833. aktprocsym^.definition^.setmangledname(import_name);
  834. end
  835. else
  836. begin
  837. { external shouldn't override the cdecl/system name }
  838. if not (pocall_clearstack in aktprocsym^.definition^.proccalloptions) then
  839. aktprocsym^.definition^.setmangledname(aktprocsym^.name);
  840. end;
  841. end;
  842. end;
  843. {$ifdef TP}
  844. {$F-}
  845. {$endif}
  846. function parse_proc_direc(const proc_names:Tstringcontainer;var pdflags:word):boolean;
  847. {
  848. Parse the procedure directive, returns true if a correct directive is found
  849. }
  850. const
  851. namelength=15;
  852. type
  853. pd_handler=procedure(const procnames:Tstringcontainer);
  854. proc_dir_rec=record
  855. idtok : ttoken;
  856. pd_flags : longint;
  857. handler : pd_handler;
  858. pocall : tproccalloptions;
  859. pooption : tprocoptions;
  860. mutexclpocall : tproccalloptions;
  861. mutexclpotype : tproctypeoptions;
  862. mutexclpo : tprocoptions;
  863. end;
  864. const
  865. {Should contain the number of procedure directives we support.}
  866. num_proc_directives=29;
  867. proc_direcdata:array[1..num_proc_directives] of proc_dir_rec=
  868. (
  869. (
  870. idtok:_ABSTRACT;
  871. pd_flags : pd_interface+pd_object;
  872. handler : {$ifndef TP}@{$endif}pd_abstract;
  873. pocall : [];
  874. pooption : [po_abstractmethod];
  875. mutexclpocall : [pocall_internproc,pocall_inline];
  876. mutexclpotype : [potype_constructor,potype_destructor];
  877. mutexclpo : [po_exports,po_interrupt,po_external]
  878. ),(
  879. idtok:_ALIAS;
  880. pd_flags : pd_implemen+pd_body;
  881. handler : {$ifndef TP}@{$endif}pd_alias;
  882. pocall : [];
  883. pooption : [];
  884. mutexclpocall : [pocall_inline];
  885. mutexclpotype : [];
  886. mutexclpo : [po_external]
  887. ),(
  888. idtok:_ASMNAME;
  889. pd_flags : pd_interface+pd_implemen;
  890. handler : {$ifndef TP}@{$endif}pd_asmname;
  891. pocall : [pocall_cdecl,pocall_clearstack];
  892. pooption : [po_external];
  893. mutexclpocall : [pocall_internproc];
  894. mutexclpotype : [];
  895. mutexclpo : [po_external]
  896. ),(
  897. idtok:_ASSEMBLER;
  898. pd_flags : pd_implemen+pd_body;
  899. handler : nil;
  900. pocall : [];
  901. pooption : [po_assembler];
  902. mutexclpocall : [];
  903. mutexclpotype : [];
  904. mutexclpo : [po_external]
  905. ),(
  906. idtok:_CDECL;
  907. pd_flags : pd_interface+pd_implemen+pd_body+pd_procvar;
  908. handler : {$ifndef TP}@{$endif}pd_cdecl;
  909. pocall : [pocall_cdecl,pocall_clearstack];
  910. pooption : [po_savestdregs];
  911. mutexclpocall : [pocall_internproc,pocall_leftright,pocall_inline];
  912. mutexclpotype : [];
  913. mutexclpo : [po_assembler,po_external]
  914. ),(
  915. idtok:_DYNAMIC;
  916. pd_flags : pd_interface+pd_object;
  917. handler : {$ifndef TP}@{$endif}pd_virtual;
  918. pocall : [];
  919. pooption : [po_virtualmethod];
  920. mutexclpocall : [pocall_internproc,pocall_inline];
  921. mutexclpotype : [];
  922. mutexclpo : [po_exports,po_interrupt,po_external]
  923. ),(
  924. idtok:_EXPORT;
  925. pd_flags : pd_body+pd_global+pd_interface+pd_implemen{??};
  926. handler : {$ifndef TP}@{$endif}pd_export;
  927. pocall : [];
  928. pooption : [po_exports];
  929. mutexclpocall : [pocall_internproc,pocall_inline];
  930. mutexclpotype : [];
  931. mutexclpo : [po_external,po_interrupt]
  932. ),(
  933. idtok:_EXTERNAL;
  934. pd_flags : pd_implemen+pd_interface;
  935. handler : {$ifndef TP}@{$endif}pd_external;
  936. pocall : [];
  937. pooption : [po_external];
  938. mutexclpocall : [pocall_internproc,pocall_inline,pocall_palmossyscall];
  939. mutexclpotype : [];
  940. mutexclpo : [po_exports,po_interrupt,po_assembler]
  941. ),(
  942. idtok:_FAR;
  943. pd_flags : pd_implemen+pd_body+pd_interface+pd_procvar;
  944. handler : {$ifndef TP}@{$endif}pd_far;
  945. pocall : [];
  946. pooption : [];
  947. mutexclpocall : [pocall_internproc,pocall_inline];
  948. mutexclpotype : [];
  949. mutexclpo : []
  950. ),(
  951. idtok:_FORWARD;
  952. pd_flags : pd_implemen;
  953. handler : {$ifndef TP}@{$endif}pd_forward;
  954. pocall : [];
  955. pooption : [];
  956. mutexclpocall : [pocall_internproc,pocall_inline];
  957. mutexclpotype : [];
  958. mutexclpo : [po_external]
  959. ),(
  960. idtok:_INLINE;
  961. pd_flags : pd_implemen+pd_body;
  962. handler : {$ifndef TP}@{$endif}pd_inline;
  963. pocall : [pocall_inline];
  964. pooption : [];
  965. mutexclpocall : [pocall_internproc];
  966. mutexclpotype : [potype_constructor,potype_destructor];
  967. mutexclpo : [po_exports,po_external,po_interrupt]
  968. ),(
  969. idtok:_INTERNCONST;
  970. pd_flags : pd_implemen+pd_body;
  971. handler : {$ifndef TP}@{$endif}pd_intern;
  972. pocall : [pocall_internconst];
  973. pooption : [];
  974. mutexclpocall : [pocall_internproc];
  975. mutexclpotype : [potype_operator];
  976. mutexclpo : []
  977. ),(
  978. idtok:_INTERNPROC;
  979. pd_flags : pd_implemen;
  980. handler : {$ifndef TP}@{$endif}pd_intern;
  981. pocall : [pocall_internproc];
  982. pooption : [];
  983. mutexclpocall : [pocall_internconst,pocall_inline,pocall_clearstack,pocall_leftright,pocall_cdecl];
  984. mutexclpotype : [potype_constructor,potype_destructor,potype_operator];
  985. mutexclpo : [po_exports,po_external,po_interrupt,po_assembler,po_iocheck]
  986. ),(
  987. idtok:_INTERRUPT;
  988. pd_flags : pd_implemen+pd_body;
  989. handler : nil;
  990. pocall : [];
  991. pooption : [po_interrupt];
  992. mutexclpocall : [pocall_internproc,pocall_cdecl,pocall_clearstack,pocall_leftright,pocall_inline];
  993. mutexclpotype : [potype_constructor,potype_destructor,potype_operator];
  994. mutexclpo : [po_external]
  995. ),(
  996. idtok:_IOCHECK;
  997. pd_flags : pd_implemen+pd_body;
  998. handler : nil;
  999. pocall : [];
  1000. pooption : [po_iocheck];
  1001. mutexclpocall : [pocall_internproc];
  1002. mutexclpotype : [];
  1003. mutexclpo : [po_external]
  1004. ),(
  1005. idtok:_MESSAGE;
  1006. pd_flags : pd_interface+pd_object;
  1007. handler : {$ifndef TP}@{$endif}pd_message;
  1008. pocall : [];
  1009. pooption : []; { can be po_msgstr or po_msgint }
  1010. mutexclpocall : [pocall_inline,pocall_internproc];
  1011. mutexclpotype : [potype_constructor,potype_destructor,potype_operator];
  1012. mutexclpo : [po_interrupt,po_external]
  1013. ),(
  1014. idtok:_NEAR;
  1015. pd_flags : pd_implemen+pd_body+pd_procvar;
  1016. handler : {$ifndef TP}@{$endif}pd_near;
  1017. pocall : [];
  1018. pooption : [];
  1019. mutexclpocall : [pocall_internproc];
  1020. mutexclpotype : [];
  1021. mutexclpo : []
  1022. ),(
  1023. idtok:_OVERRIDE;
  1024. pd_flags : pd_interface+pd_object;
  1025. handler : {$ifndef TP}@{$endif}pd_override;
  1026. pocall : [];
  1027. pooption : [po_overridingmethod,po_virtualmethod];
  1028. mutexclpocall : [pocall_inline,pocall_internproc];
  1029. mutexclpotype : [];
  1030. mutexclpo : [po_exports,po_external,po_interrupt]
  1031. ),(
  1032. idtok:_PASCAL;
  1033. pd_flags : pd_implemen+pd_body+pd_procvar;
  1034. handler : nil;
  1035. pocall : [pocall_leftright];
  1036. pooption : [];
  1037. mutexclpocall : [pocall_internproc];
  1038. mutexclpotype : [];
  1039. mutexclpo : [po_external]
  1040. ),(
  1041. idtok:_POPSTACK;
  1042. pd_flags : pd_interface+pd_implemen+pd_body+pd_procvar;
  1043. handler : nil;
  1044. pocall : [pocall_clearstack];
  1045. pooption : [];
  1046. mutexclpocall : [pocall_inline,pocall_internproc];
  1047. mutexclpotype : [];
  1048. mutexclpo : [po_assembler,po_external]
  1049. ),(
  1050. idtok:_PUBLIC;
  1051. pd_flags : pd_implemen+pd_body+pd_global+pd_notobject;
  1052. handler : nil;
  1053. pocall : [];
  1054. pooption : [];
  1055. mutexclpocall : [pocall_internproc,pocall_inline];
  1056. mutexclpotype : [];
  1057. mutexclpo : [po_external]
  1058. ),(
  1059. idtok:_REGISTER;
  1060. pd_flags : pd_interface+pd_implemen+pd_body+pd_procvar;
  1061. handler : {$ifndef TP}@{$endif}pd_register;
  1062. pocall : [pocall_register];
  1063. pooption : [];
  1064. mutexclpocall : [pocall_leftright,pocall_cdecl,pocall_internproc];
  1065. mutexclpotype : [];
  1066. mutexclpo : [po_external]
  1067. ),(
  1068. idtok:_SAFECALL;
  1069. pd_flags : pd_interface+pd_implemen+pd_body+pd_procvar;
  1070. handler : {$ifndef TP}@{$endif}pd_safecall;
  1071. pocall : [pocall_safecall];
  1072. pooption : [po_savestdregs];
  1073. mutexclpocall : [pocall_leftright,pocall_cdecl,pocall_internproc,pocall_inline];
  1074. mutexclpotype : [];
  1075. mutexclpo : [po_external]
  1076. ),(
  1077. idtok:_SAVEREGISTERS;
  1078. pd_flags : pd_interface+pd_implemen+pd_body+pd_procvar;
  1079. handler : nil;
  1080. pocall : [];
  1081. pooption : [po_saveregisters];
  1082. mutexclpocall : [pocall_internproc];
  1083. mutexclpotype : [];
  1084. mutexclpo : [po_external]
  1085. ),(
  1086. idtok:_STATIC;
  1087. pd_flags : pd_interface+pd_object;
  1088. handler : {$ifndef TP}@{$endif}pd_static;
  1089. pocall : [];
  1090. pooption : [po_staticmethod];
  1091. mutexclpocall : [pocall_inline,pocall_internproc];
  1092. mutexclpotype : [potype_constructor,potype_destructor];
  1093. mutexclpo : [po_external,po_interrupt,po_exports]
  1094. ),(
  1095. idtok:_STDCALL;
  1096. pd_flags : pd_interface+pd_implemen+pd_body+pd_procvar;
  1097. handler : {$ifndef TP}@{$endif}pd_stdcall;
  1098. pocall : [pocall_stdcall];
  1099. pooption : [po_savestdregs];
  1100. mutexclpocall : [pocall_leftright,pocall_cdecl,pocall_inline,pocall_internproc];
  1101. mutexclpotype : [];
  1102. mutexclpo : [po_external]
  1103. ),(
  1104. idtok:_SYSCALL;
  1105. pd_flags : pd_interface;
  1106. handler : {$ifndef TP}@{$endif}pd_syscall;
  1107. pocall : [pocall_palmossyscall];
  1108. pooption : [];
  1109. mutexclpocall : [pocall_cdecl,pocall_inline,pocall_internproc];
  1110. mutexclpotype : [];
  1111. mutexclpo : [po_external,po_assembler,po_interrupt,po_exports]
  1112. ),(
  1113. idtok:_SYSTEM;
  1114. pd_flags : pd_implemen;
  1115. handler : {$ifndef TP}@{$endif}pd_system;
  1116. pocall : [pocall_clearstack];
  1117. pooption : [];
  1118. mutexclpocall : [pocall_leftright,pocall_inline,pocall_internproc];
  1119. mutexclpotype : [];
  1120. mutexclpo : [po_external,po_assembler,po_interrupt]
  1121. ),(
  1122. idtok:_VIRTUAL;
  1123. pd_flags : pd_interface+pd_object;
  1124. handler : {$ifndef TP}@{$endif}pd_virtual;
  1125. pocall : [];
  1126. pooption : [po_virtualmethod];
  1127. mutexclpocall : [pocall_inline,pocall_internproc];
  1128. mutexclpotype : [];
  1129. mutexclpo : [po_external,po_interrupt,po_exports]
  1130. )
  1131. );
  1132. var
  1133. p : longint;
  1134. found : boolean;
  1135. name : string;
  1136. begin
  1137. parse_proc_direc:=false;
  1138. name:=pattern;
  1139. found:=false;
  1140. for p:=1 to num_proc_directives do
  1141. if proc_direcdata[p].idtok=idtoken then
  1142. begin
  1143. found:=true;
  1144. break;
  1145. end;
  1146. { Check if the procedure directive is known }
  1147. if not found then
  1148. begin
  1149. { parsing a procvar type the name can be any
  1150. next variable !! }
  1151. if (pdflags and (pd_procvar or pd_object))=0 then
  1152. Message1(parser_w_unknown_proc_directive_ignored,name);
  1153. exit;
  1154. end;
  1155. { static needs a special treatment }
  1156. if (idtoken=_STATIC) and not (cs_static_keyword in aktmoduleswitches) then
  1157. exit;
  1158. { Conflicts between directives ? }
  1159. if (aktprocsym^.definition^.proctypeoption in proc_direcdata[p].mutexclpotype) or
  1160. ((aktprocsym^.definition^.proccalloptions*proc_direcdata[p].mutexclpocall)<>[]) or
  1161. ((aktprocsym^.definition^.procoptions*proc_direcdata[p].mutexclpo)<>[]) then
  1162. begin
  1163. Message1(parser_e_proc_dir_conflict,name);
  1164. exit;
  1165. end;
  1166. { Check if the directive is only for objects }
  1167. if ((proc_direcdata[p].pd_flags and pd_object)<>0) and
  1168. not assigned(aktprocsym^.definition^._class) then
  1169. begin
  1170. exit;
  1171. end;
  1172. { check if method and directive not for object public }
  1173. if ((proc_direcdata[p].pd_flags and pd_notobject)<>0) and
  1174. assigned(aktprocsym^.definition^._class) then
  1175. begin
  1176. exit;
  1177. end;
  1178. { consume directive, and turn flag on }
  1179. consume(token);
  1180. parse_proc_direc:=true;
  1181. { Check the pd_flags if the directive should be allowed }
  1182. if ((pdflags and pd_interface)<>0) and
  1183. ((proc_direcdata[p].pd_flags and pd_interface)=0) then
  1184. begin
  1185. Message1(parser_e_proc_dir_not_allowed_in_interface,name);
  1186. exit;
  1187. end;
  1188. if ((pdflags and pd_implemen)<>0) and
  1189. ((proc_direcdata[p].pd_flags and pd_implemen)=0) then
  1190. begin
  1191. Message1(parser_e_proc_dir_not_allowed_in_implementation,name);
  1192. exit;
  1193. end;
  1194. if ((pdflags and pd_procvar)<>0) and
  1195. ((proc_direcdata[p].pd_flags and pd_procvar)=0) then
  1196. begin
  1197. Message1(parser_e_proc_dir_not_allowed_in_procvar,name);
  1198. exit;
  1199. end;
  1200. { Return the new pd_flags }
  1201. if (proc_direcdata[p].pd_flags and pd_body)=0 then
  1202. pdflags:=pdflags and (not pd_body);
  1203. if (proc_direcdata[p].pd_flags and pd_global)<>0 then
  1204. pdflags:=pdflags or pd_global;
  1205. { Add the correct flag }
  1206. aktprocsym^.definition^.proccalloptions:=aktprocsym^.definition^.proccalloptions+proc_direcdata[p].pocall;
  1207. aktprocsym^.definition^.procoptions:=aktprocsym^.definition^.procoptions+proc_direcdata[p].pooption;
  1208. { Adjust positions of args for cdecl or stdcall }
  1209. if (aktprocsym^.definition^.deftype=procdef) and
  1210. (([pocall_cdecl,pocall_stdcall]*aktprocsym^.definition^.proccalloptions)<>[]) then
  1211. aktprocsym^.definition^.parast^.set_alignment(target_os.size_of_longint);
  1212. { Call the handler }
  1213. if pointer({$ifndef FPC}@{$endif}proc_direcdata[p].handler)<>nil then
  1214. proc_direcdata[p].handler(proc_names);
  1215. end;
  1216. {***************************************************************************}
  1217. function check_identical(var p : pprocdef) : boolean;
  1218. {
  1219. Search for idendical definitions,
  1220. if there is a forward, then kill this.
  1221. Returns the result of the forward check.
  1222. Removed from unter_dec to keep the source readable
  1223. }
  1224. var
  1225. hd,pd : Pprocdef;
  1226. storeparast : psymtable;
  1227. ad,fd : psym;
  1228. s : string;
  1229. begin
  1230. check_identical:=false;
  1231. p:=nil;
  1232. pd:=aktprocsym^.definition;
  1233. if assigned(pd) then
  1234. begin
  1235. { Is there an overload/forward ? }
  1236. if assigned(pd^.nextoverloaded) then
  1237. begin
  1238. { walk the procdef list }
  1239. while (assigned(pd)) and (assigned(pd^.nextoverloaded)) do
  1240. begin
  1241. if not(m_repeat_forward in aktmodeswitches) or
  1242. (equal_paras(aktprocsym^.definition^.para1,pd^.nextoverloaded^.para1,false) and
  1243. { for operators equal_paras is not enough !! }
  1244. ((aktprocsym^.definition^.proctypeoption<>potype_operator) or (optoken<>_ASSIGNMENT) or
  1245. is_equal(pd^.nextoverloaded^.retdef,aktprocsym^.definition^.retdef))) then
  1246. begin
  1247. if pd^.nextoverloaded^.forwarddef then
  1248. { remove the forward definition but don't delete it, }
  1249. { the symtable is the owner !! }
  1250. begin
  1251. hd:=pd^.nextoverloaded;
  1252. { Check if the procedure type and return type are correct }
  1253. if (hd^.proctypeoption<>aktprocsym^.definition^.proctypeoption) or
  1254. (not(is_equal(hd^.retdef,aktprocsym^.definition^.retdef)) and
  1255. (m_repeat_forward in aktmodeswitches)) then
  1256. begin
  1257. Message1(parser_e_header_dont_match_forward,aktprocsym^.demangledName);
  1258. exit;
  1259. end;
  1260. { Check calling convention, no check for internconst,internproc which
  1261. are only defined in interface or implementation }
  1262. if (hd^.proccalloptions-[pocall_internconst,pocall_internproc]<>
  1263. aktprocsym^.definition^.proccalloptions-[pocall_internconst,pocall_internproc]) then
  1264. begin
  1265. { only trigger an error, becuase it doesn't hurt }
  1266. Message(parser_e_call_convention_dont_match_forward);
  1267. end;
  1268. { manglednames are equal? }
  1269. hd^.count:=false;
  1270. if (m_repeat_forward in aktmodeswitches) or
  1271. aktprocsym^.definition^.haspara then
  1272. begin
  1273. if (hd^.mangledname<>aktprocsym^.definition^.mangledname) then
  1274. begin
  1275. { When overloading is not possible then we issue an error }
  1276. if not(m_repeat_forward in aktmodeswitches) then
  1277. begin
  1278. Message1(parser_e_header_dont_match_forward,aktprocsym^.demangledName);
  1279. exit;
  1280. end;
  1281. if not(po_external in aktprocsym^.definition^.procoptions) then
  1282. Message2(parser_n_interface_name_diff_implementation_name,hd^.mangledname,
  1283. aktprocsym^.definition^.mangledname);
  1284. { reset the mangledname of the interface part to be sure }
  1285. { this is wrong because the mangled name might have been used already !! }
  1286. if hd^.is_used then
  1287. renameasmsymbol(hd^.mangledname,aktprocsym^.definition^.mangledname);
  1288. hd^.setmangledname(aktprocsym^.definition^.mangledname);
  1289. { so we need to keep the name of interface !!
  1290. No!!!! The procedure directives can change the mangledname.
  1291. I fixed this by first calling check_identical and then doing
  1292. the proc directives, but this is not a good solution.(DM)}
  1293. { this is also wrong (PM)
  1294. aktprocsym^.definition^.setmangledname(hd^.mangledname);}
  1295. end
  1296. else
  1297. begin
  1298. { If mangled names are equal, therefore }
  1299. { they have the same number of parameters }
  1300. { Therefore we can check the name of these }
  1301. { parameters... }
  1302. if hd^.forwarddef and aktprocsym^.definition^.forwarddef then
  1303. begin
  1304. Message1(parser_e_function_already_declared_public_forward,aktprocsym^.demangledName);
  1305. Check_identical:=true;
  1306. { Remove other forward from the list to reduce errors }
  1307. pd^.nextoverloaded:=pd^.nextoverloaded^.nextoverloaded;
  1308. exit;
  1309. end;
  1310. ad:=psym(hd^.parast^.symindex^.first);
  1311. fd:=psym(aktprocsym^.definition^.parast^.symindex^.first);
  1312. if assigned(ad) and assigned(fd) then
  1313. begin
  1314. while assigned(ad) and assigned(fd) do
  1315. begin
  1316. s:=ad^.name;
  1317. if s<>fd^.name then
  1318. begin
  1319. Message3(parser_e_header_different_var_names,
  1320. aktprocsym^.name,s,fd^.name);
  1321. break;
  1322. end;
  1323. { it is impossible to have a nil pointer }
  1324. { for only one parameter - since they }
  1325. { have the same number of parameters. }
  1326. { Left = next parameter. }
  1327. ad:=psym(ad^.left);
  1328. fd:=psym(fd^.left);
  1329. end;
  1330. end;
  1331. end;
  1332. end;
  1333. { also the call_offset }
  1334. hd^.parast^.address_fixup:=aktprocsym^.definition^.parast^.address_fixup;
  1335. hd^.count:=true;
  1336. { remove pd^.nextoverloaded from the list }
  1337. { and add aktprocsym^.definition }
  1338. pd^.nextoverloaded:=pd^.nextoverloaded^.nextoverloaded;
  1339. hd^.nextoverloaded:=aktprocsym^.definition^.nextoverloaded;
  1340. { Alert! All fields of aktprocsym^.definition that are modified
  1341. by the procdir handlers must be copied here!.}
  1342. hd^.forwarddef:=false;
  1343. hd^.proccalloptions:=hd^.proccalloptions + aktprocsym^.definition^.proccalloptions;
  1344. hd^.procoptions:=hd^.procoptions + aktprocsym^.definition^.procoptions;
  1345. if aktprocsym^.definition^.extnumber=-1 then
  1346. aktprocsym^.definition^.extnumber:=hd^.extnumber
  1347. else
  1348. if hd^.extnumber=-1 then
  1349. hd^.extnumber:=aktprocsym^.definition^.extnumber;
  1350. { switch parast for warning in implementation PM }
  1351. if (m_repeat_forward in aktmodeswitches) or
  1352. aktprocsym^.definition^.haspara then
  1353. begin
  1354. storeparast:=hd^.parast;
  1355. hd^.parast:=aktprocsym^.definition^.parast;
  1356. aktprocsym^.definition^.parast:=storeparast;
  1357. end;
  1358. if pd=aktprocsym^.definition then
  1359. p:=nil
  1360. else
  1361. p:=pd;
  1362. aktprocsym^.definition:=hd;
  1363. check_identical:=true;
  1364. end
  1365. else
  1366. { abstract methods aren't forward defined, but this }
  1367. { needs another error message }
  1368. if not(po_abstractmethod in pd^.nextoverloaded^.procoptions) then
  1369. Message(parser_e_overloaded_have_same_parameters)
  1370. else
  1371. Message(parser_e_abstract_no_definition);
  1372. break;
  1373. end;
  1374. pd:=pd^.nextoverloaded;
  1375. end;
  1376. end
  1377. else
  1378. begin
  1379. { there is no overloaded, so its always identical with itself }
  1380. check_identical:=true;
  1381. end;
  1382. end;
  1383. { insert opsym only in the right symtable }
  1384. if ((procinfo.flags and pi_operator)<>0) and assigned(opsym)
  1385. and not parse_only then
  1386. begin
  1387. if ret_in_param(aktprocsym^.definition^.retdef) then
  1388. begin
  1389. pprocdef(aktprocsym^.definition)^.parast^.insert(opsym);
  1390. { this increases the data size }
  1391. { correct this to get the right ret $value }
  1392. dec(pprocdef(aktprocsym^.definition)^.parast^.datasize,opsym^.getpushsize);
  1393. { this allows to read the funcretoffset }
  1394. opsym^.address:=-4;
  1395. opsym^.varspez:=vs_var;
  1396. end
  1397. else
  1398. pprocdef(aktprocsym^.definition)^.localst^.insert(opsym);
  1399. end;
  1400. end;
  1401. procedure compile_proc_body(const proc_names:Tstringcontainer;
  1402. make_global,parent_has_class:boolean);
  1403. {
  1404. Compile the body of a procedure
  1405. }
  1406. var
  1407. oldexitlabel,oldexit2label : pasmlabel;
  1408. oldfaillabel,oldquickexitlabel:Pasmlabel;
  1409. _class,hp:Pobjectdef;
  1410. { switches can change inside the procedure }
  1411. entryswitches, exitswitches : tlocalswitches;
  1412. { code for the subroutine as tree }
  1413. {$ifdef newcg}
  1414. code:pnode;
  1415. {$else newcg}
  1416. code:ptree;
  1417. {$endif newcg}
  1418. { size of the local strackframe }
  1419. stackframe:longint;
  1420. { true when no stackframe is required }
  1421. nostackframe:boolean;
  1422. { number of bytes which have to be cleared by RET }
  1423. parasize:longint;
  1424. { filepositions }
  1425. entrypos,
  1426. savepos,
  1427. exitpos : tfileposinfo;
  1428. begin
  1429. { calculate the lexical level }
  1430. inc(lexlevel);
  1431. if lexlevel>32 then
  1432. Message(parser_e_too_much_lexlevel);
  1433. { static is also important for local procedures !! }
  1434. if (po_staticmethod in aktprocsym^.definition^.procoptions) then
  1435. allow_only_static:=true
  1436. else if (lexlevel=normal_function_level) then
  1437. allow_only_static:=false;
  1438. { save old labels }
  1439. oldexitlabel:=aktexitlabel;
  1440. oldexit2label:=aktexit2label;
  1441. oldquickexitlabel:=quickexitlabel;
  1442. oldfaillabel:=faillabel;
  1443. { get new labels }
  1444. getlabel(aktexitlabel);
  1445. getlabel(aktexit2label);
  1446. { exit for fail in constructors }
  1447. if (aktprocsym^.definition^.proctypeoption=potype_constructor) then
  1448. begin
  1449. getlabel(faillabel);
  1450. getlabel(quickexitlabel);
  1451. end;
  1452. { reset break and continue labels }
  1453. in_except_block:=false;
  1454. aktbreaklabel:=nil;
  1455. aktcontinuelabel:=nil;
  1456. { insert symtables for the class, by only if it is no nested function }
  1457. if assigned(procinfo._class) and not(parent_has_class) then
  1458. begin
  1459. { insert them in the reverse order ! }
  1460. hp:=nil;
  1461. repeat
  1462. _class:=procinfo._class;
  1463. while _class^.childof<>hp do
  1464. _class:=_class^.childof;
  1465. hp:=_class;
  1466. _class^.symtable^.next:=symtablestack;
  1467. symtablestack:=_class^.symtable;
  1468. until hp=procinfo._class;
  1469. end;
  1470. { insert parasymtable in symtablestack}
  1471. { only if lexlevel > 1 !!! global symtable should be right after staticsymtazble
  1472. for checking of same names used in interface and implementation !! }
  1473. if lexlevel>=normal_function_level then
  1474. begin
  1475. aktprocsym^.definition^.parast^.next:=symtablestack;
  1476. symtablestack:=aktprocsym^.definition^.parast;
  1477. symtablestack^.symtablelevel:=lexlevel;
  1478. end;
  1479. { insert localsymtable in symtablestack}
  1480. aktprocsym^.definition^.localst^.next:=symtablestack;
  1481. symtablestack:=aktprocsym^.definition^.localst;
  1482. symtablestack^.symtablelevel:=lexlevel;
  1483. { constant symbols are inserted in this symboltable }
  1484. constsymtable:=symtablestack;
  1485. { reset the temporary memory }
  1486. cleartempgen;
  1487. {$ifdef newcg}
  1488. tg.usedinproc:=[];
  1489. {$else newcg}
  1490. { no registers are used }
  1491. usedinproc:=0;
  1492. {$endif newcg}
  1493. { save entry info }
  1494. entrypos:=aktfilepos;
  1495. entryswitches:=aktlocalswitches;
  1496. {$ifdef newcg}
  1497. { parse the code ... }
  1498. if (po_assembler in aktprocsym^.definition^.procoptions) then
  1499. code:=convtree2node(assembler_block)
  1500. else
  1501. code:=convtree2node(block(current_module^.islibrary));
  1502. {$else newcg}
  1503. { parse the code ... }
  1504. if (po_assembler in aktprocsym^.definition^.procoptions) then
  1505. code:=assembler_block
  1506. else
  1507. code:=block(current_module^.islibrary);
  1508. {$endif newcg}
  1509. { get a better entry point }
  1510. if assigned(code) then
  1511. entrypos:=code^.fileinfo;
  1512. { save exit info }
  1513. exitswitches:=aktlocalswitches;
  1514. exitpos:=last_endtoken_filepos;
  1515. { save current filepos }
  1516. savepos:=aktfilepos;
  1517. {When we are called to compile the body of a unit, aktprocsym should
  1518. point to the unit initialization. If the unit has no initialization,
  1519. aktprocsym=nil. But in that case code=nil. hus we should check for
  1520. code=nil, when we use aktprocsym.}
  1521. { set the framepointer to esp for assembler functions }
  1522. { but only if the are no local variables }
  1523. { already done in assembler_block }
  1524. {$ifdef newcg}
  1525. tg.setfirsttemp(procinfo.firsttemp);
  1526. {$else newcg}
  1527. setfirsttemp(procinfo.firsttemp);
  1528. {$endif newcg}
  1529. { ... and generate assembler }
  1530. { but set the right switches for entry !! }
  1531. aktlocalswitches:=entryswitches;
  1532. {$ifndef NOPASS2}
  1533. {$ifdef newcg}
  1534. tg.setfirsttemp(procinfo.firsttemp);
  1535. {$else newcg}
  1536. if assigned(code) then
  1537. generatecode(code);
  1538. {$endif newcg}
  1539. { set switches to status at end of procedure }
  1540. aktlocalswitches:=exitswitches;
  1541. if assigned(code) then
  1542. begin
  1543. aktprocsym^.definition^.code:=code;
  1544. { the procedure is now defined }
  1545. aktprocsym^.definition^.forwarddef:=false;
  1546. {$ifdef newcg}
  1547. aktprocsym^.definition^.usedregisters:=tg.usedinproc;
  1548. {$else newcg}
  1549. aktprocsym^.definition^.usedregisters:=usedinproc;
  1550. {$endif newcg}
  1551. end;
  1552. {$ifdef newcg}
  1553. stackframe:=tg.gettempsize;
  1554. {$else newcg}
  1555. stackframe:=gettempsize;
  1556. {$endif newcg}
  1557. { first generate entry code with the correct position and switches }
  1558. aktfilepos:=entrypos;
  1559. aktlocalswitches:=entryswitches;
  1560. {$ifdef newcg}
  1561. if assigned(code) then
  1562. cg^.g_entrycode(procinfo.aktentrycode,proc_names,make_global,stackframe,parasize,nostackframe,false);
  1563. {$else newcg}
  1564. if assigned(code) then
  1565. genentrycode(procinfo.aktentrycode,proc_names,make_global,stackframe,parasize,nostackframe,false);
  1566. {$endif newcg}
  1567. { now generate exit code with the correct position and switches }
  1568. aktfilepos:=exitpos;
  1569. aktlocalswitches:=exitswitches;
  1570. if assigned(code) then
  1571. begin
  1572. {$ifdef newcg}
  1573. cg^.g_exitcode(procinfo.aktexitcode,parasize,nostackframe,false);
  1574. {$else newcg}
  1575. genexitcode(procinfo.aktexitcode,parasize,nostackframe,false);
  1576. {$endif newcg}
  1577. procinfo.aktproccode^.insertlist(procinfo.aktentrycode);
  1578. procinfo.aktproccode^.concatlist(procinfo.aktexitcode);
  1579. {$ifdef i386}
  1580. {$ifndef NoOpt}
  1581. if (cs_optimize in aktglobalswitches) and
  1582. { do not optimize pure assembler procedures }
  1583. ((procinfo.flags and pi_is_assembler)=0) then
  1584. Optimize(procinfo.aktproccode);
  1585. {$endif NoOpt}
  1586. {$endif}
  1587. { save local data (casetable) also in the same file }
  1588. if assigned(procinfo.aktlocaldata) and
  1589. (not procinfo.aktlocaldata^.empty) then
  1590. begin
  1591. procinfo.aktproccode^.concat(new(pai_section,init(sec_data)));
  1592. procinfo.aktproccode^.concatlist(procinfo.aktlocaldata);
  1593. end;
  1594. { now we can insert a cut }
  1595. if (cs_smartlink in aktmoduleswitches) then
  1596. codesegment^.concat(new(pai_cut,init));
  1597. { add the procedure to the codesegment }
  1598. codesegment^.concatlist(procinfo.aktproccode);
  1599. end;
  1600. {$else}
  1601. if assigned(code) then
  1602. firstpass(code);
  1603. {$endif NOPASS2}
  1604. { ... remove symbol tables, for the browser leave the static table }
  1605. { if (cs_browser in aktmoduleswitches) and (symtablestack^.symtabletype=staticsymtable) then
  1606. symtablestack^.next:=symtablestack^.next^.next
  1607. else }
  1608. if lexlevel>=normal_function_level then
  1609. symtablestack:=symtablestack^.next^.next
  1610. else
  1611. symtablestack:=symtablestack^.next;
  1612. { ... check for unused symbols }
  1613. { but only if there is no asm block }
  1614. if assigned(code) then
  1615. begin
  1616. if (Errorcount=0) then
  1617. begin
  1618. aktprocsym^.definition^.localst^.check_forwards;
  1619. aktprocsym^.definition^.localst^.checklabels;
  1620. end;
  1621. if (procinfo.flags and pi_uses_asm)=0 then
  1622. begin
  1623. { not for unit init, becuase the var can be used in finalize,
  1624. it will be done in proc_unit }
  1625. if not(aktprocsym^.definition^.proctypeoption in [potype_unitinit,potype_unitfinalize]) then
  1626. aktprocsym^.definition^.localst^.allsymbolsused;
  1627. aktprocsym^.definition^.parast^.allsymbolsused;
  1628. end;
  1629. end;
  1630. { the local symtables can be deleted, but the parast }
  1631. { doesn't, (checking definitons when calling a }
  1632. { function }
  1633. { not for a inline procedure !! (PM) }
  1634. { at lexlevel = 1 localst is the staticsymtable itself }
  1635. { so no dispose here !! }
  1636. if assigned(code) and
  1637. not(cs_browser in aktmoduleswitches) and
  1638. not(pocall_inline in aktprocsym^.definition^.proccalloptions) then
  1639. begin
  1640. if lexlevel>=normal_function_level then
  1641. dispose(aktprocsym^.definition^.localst,done);
  1642. aktprocsym^.definition^.localst:=nil;
  1643. end;
  1644. { only now we can remove the temps }
  1645. resettempgen;
  1646. { remove code tree, if not inline procedure }
  1647. if assigned(code) and not(pocall_inline in aktprocsym^.definition^.proccalloptions) then
  1648. {$ifdef newcg}
  1649. dispose(code,done);
  1650. {$else newcg}
  1651. disposetree(code);
  1652. {$endif newcg}
  1653. { remove class member symbol tables }
  1654. while symtablestack^.symtabletype=objectsymtable do
  1655. symtablestack:=symtablestack^.next;
  1656. { restore filepos, the switches are already set }
  1657. aktfilepos:=savepos;
  1658. { free labels }
  1659. freelabel(aktexitlabel);
  1660. freelabel(aktexit2label);
  1661. if (aktprocsym^.definition^.proctypeoption=potype_constructor) then
  1662. begin
  1663. freelabel(faillabel);
  1664. freelabel(quickexitlabel);
  1665. end;
  1666. { restore labels }
  1667. aktexitlabel:=oldexitlabel;
  1668. aktexit2label:=oldexit2label;
  1669. quickexitlabel:=oldquickexitlabel;
  1670. faillabel:=oldfaillabel;
  1671. { reset to normal non static function }
  1672. if (lexlevel=normal_function_level) then
  1673. allow_only_static:=false;
  1674. { previous lexlevel }
  1675. dec(lexlevel);
  1676. end;
  1677. procedure parse_proc_directives(Anames:Pstringcontainer;var pdflags:word);
  1678. {
  1679. Parse the procedure directives. It does not matter if procedure directives
  1680. are written using ;procdir; or ['procdir'] syntax.
  1681. }
  1682. var
  1683. res : boolean;
  1684. begin
  1685. while token in [_ID,_LECKKLAMMER] do
  1686. begin
  1687. if try_to_consume(_LECKKLAMMER) then
  1688. begin
  1689. repeat
  1690. parse_proc_direc(Anames^,pdflags);
  1691. until not try_to_consume(_COMMA);
  1692. consume(_RECKKLAMMER);
  1693. { we always expect at least '[];' }
  1694. res:=true;
  1695. end
  1696. else
  1697. res:=parse_proc_direc(Anames^,pdflags);
  1698. { A procedure directive is always followed by a semicolon }
  1699. if res then
  1700. consume(_SEMICOLON)
  1701. else
  1702. break;
  1703. end;
  1704. end;
  1705. procedure parse_var_proc_directives(var sym : ptypesym);
  1706. var
  1707. anames : pstringcontainer;
  1708. pdflags : word;
  1709. oldsym : pprocsym;
  1710. begin
  1711. oldsym:=aktprocsym;
  1712. anames:=new(pstringcontainer,init);
  1713. pdflags:=pd_procvar;
  1714. { we create a temporary aktprocsym to read the directives }
  1715. aktprocsym:=new(pprocsym,init(sym^.name));
  1716. { aktprocsym^.definition:=pprocdef(sym^.definition);
  1717. this breaks the rule for TESTOBJEXT !! }
  1718. pabstractprocdef(aktprocsym^.definition):=pabstractprocdef(sym^.definition);
  1719. { names should never be used anyway }
  1720. inc(lexlevel);
  1721. parse_proc_directives(anames,pdflags);
  1722. dec(lexlevel);
  1723. aktprocsym^.definition:=nil;
  1724. dispose(aktprocsym,done);
  1725. dispose(anames,done);
  1726. aktprocsym:=oldsym;
  1727. end;
  1728. procedure parse_object_proc_directives(var sym : pprocsym);
  1729. var
  1730. anames : pstringcontainer;
  1731. pdflags : word;
  1732. begin
  1733. pdflags:=pd_object;
  1734. anames:=new(pstringcontainer,init);
  1735. inc(lexlevel);
  1736. parse_proc_directives(anames,pdflags);
  1737. dec(lexlevel);
  1738. dispose(anames,done);
  1739. if (po_containsself in aktprocsym^.definition^.procoptions) and
  1740. (([po_msgstr,po_msgint]*aktprocsym^.definition^.procoptions)=[]) then
  1741. Message(parser_e_self_in_non_message_handler);
  1742. end;
  1743. procedure checkvaluepara(p:pnamedindexobject);{$ifndef FPC}far;{$endif}
  1744. var
  1745. vs : pvarsym;
  1746. s : string;
  1747. begin
  1748. with pvarsym(p)^ do
  1749. begin
  1750. if copy(name,1,3)='val' then
  1751. begin
  1752. s:=Copy(name,4,255);
  1753. if not(po_assembler in aktprocsym^.definition^.procoptions) then
  1754. begin
  1755. vs:=new(Pvarsym,init(s,definition));
  1756. vs^.fileinfo:=fileinfo;
  1757. vs^.varspez:=varspez;
  1758. aktprocsym^.definition^.localst^.insert(vs);
  1759. vs^.islocalcopy:=true;
  1760. vs^.varstate:=vs_used;
  1761. localvarsym:=vs;
  1762. end
  1763. else
  1764. begin
  1765. aktprocsym^.definition^.parast^.rename(name,s);
  1766. end;
  1767. end;
  1768. end;
  1769. end;
  1770. procedure read_proc;
  1771. {
  1772. Parses the procedure directives, then parses the procedure body, then
  1773. generates the code for it
  1774. }
  1775. var
  1776. oldprefix : string;
  1777. oldprocsym : Pprocsym;
  1778. oldprocinfo : tprocinfo;
  1779. oldconstsymtable : Psymtable;
  1780. oldfilepos : tfileposinfo;
  1781. names : Pstringcontainer;
  1782. pdflags : word;
  1783. prevdef,stdef : pprocdef;
  1784. begin
  1785. { save old state }
  1786. oldprocsym:=aktprocsym;
  1787. oldprefix:=procprefix;
  1788. oldconstsymtable:=constsymtable;
  1789. oldprocinfo:=procinfo;
  1790. { create a new procedure }
  1791. new(names,init);
  1792. codegen_newprocedure;
  1793. with procinfo do
  1794. begin
  1795. parent:=@oldprocinfo;
  1796. { clear flags }
  1797. flags:=0;
  1798. { standard frame pointer }
  1799. framepointer:=frame_pointer;
  1800. funcret_is_valid:=false;
  1801. { is this a nested function of a method ? }
  1802. _class:=oldprocinfo._class;
  1803. end;
  1804. parse_proc_dec;
  1805. { set the default function options }
  1806. if parse_only then
  1807. begin
  1808. {$ifdef INCLUDEOK}
  1809. include(aktprocsym^.symoptions,sp_forwarddef);
  1810. {$else}
  1811. aktprocsym^.symoptions:=aktprocsym^.symoptions+[sp_forwarddef];
  1812. {$endif}
  1813. aktprocsym^.definition^.forwarddef:=true;
  1814. { set also the interface flag, for better error message when the
  1815. implementation doesn't much this header }
  1816. aktprocsym^.definition^.interfacedef:=true;
  1817. pdflags:=pd_interface;
  1818. end
  1819. else
  1820. begin
  1821. pdflags:=pd_body;
  1822. if current_module^.in_implementation then
  1823. pdflags:=pdflags or pd_implemen;
  1824. if (not current_module^.is_unit) or (cs_smartlink in aktmoduleswitches) then
  1825. pdflags:=pdflags or pd_global;
  1826. procinfo.exported:=false;
  1827. aktprocsym^.definition^.forwarddef:=false;
  1828. end;
  1829. { parse the directives that may follow }
  1830. inc(lexlevel);
  1831. parse_proc_directives(names,pdflags);
  1832. dec(lexlevel);
  1833. { set aktfilepos to the beginning of the function declaration }
  1834. oldfilepos:=aktfilepos;
  1835. aktfilepos:=aktprocsym^.definition^.fileinfo;
  1836. { search for forward declarations }
  1837. if not check_identical(prevdef) then
  1838. begin
  1839. { A method must be forward defined (in the object declaration) }
  1840. if assigned(procinfo._class) and (not assigned(oldprocinfo._class)) then
  1841. Message(parser_e_header_dont_match_any_member);
  1842. { Give a better error if there is a forward def in the interface and only
  1843. a single implementation }
  1844. if (not aktprocsym^.definition^.forwarddef) and
  1845. assigned(aktprocsym^.definition^.nextoverloaded) and
  1846. aktprocsym^.definition^.nextoverloaded^.forwarddef and
  1847. aktprocsym^.definition^.nextoverloaded^.interfacedef and
  1848. not(assigned(aktprocsym^.definition^.nextoverloaded^.nextoverloaded)) then
  1849. Message1(parser_e_header_dont_match_forward,aktprocsym^.demangledName)
  1850. else
  1851. begin
  1852. { check the global flag }
  1853. if (procinfo.flags and pi_is_global)<>0 then
  1854. Message(parser_e_overloaded_must_be_all_global);
  1855. end
  1856. end;
  1857. { set return type here, becuase the aktprocsym^.definition can be
  1858. changed by check_identical (PFV) }
  1859. procinfo.retdef:=aktprocsym^.definition^.retdef;
  1860. { pointer to the return value ? }
  1861. if ret_in_param(procinfo.retdef) then
  1862. begin
  1863. procinfo.retoffset:=procinfo.call_offset;
  1864. inc(procinfo.call_offset,target_os.size_of_pointer);
  1865. end;
  1866. { allows to access the parameters of main functions in nested functions }
  1867. aktprocsym^.definition^.parast^.address_fixup:=procinfo.call_offset;
  1868. { when it is a value para and it needs a local copy then rename
  1869. the parameter and insert a copy in the localst. This is not done
  1870. for assembler procedures }
  1871. if (not parse_only) and (not aktprocsym^.definition^.forwarddef) then
  1872. aktprocsym^.definition^.parast^.foreach({$ifndef TP}@{$endif}checkvaluepara);
  1873. { restore file pos }
  1874. aktfilepos:=oldfilepos;
  1875. { compile procedure when a body is needed }
  1876. if (pdflags and pd_body)<>0 then
  1877. begin
  1878. Message1(parser_p_procedure_start,aktprocsym^.demangledname);
  1879. names^.insert(aktprocsym^.definition^.mangledname);
  1880. { set _FAIL as keyword if constructor }
  1881. if (aktprocsym^.definition^.proctypeoption=potype_constructor) then
  1882. tokeninfo^[_FAIL].keyword:=m_all;
  1883. if assigned(aktprocsym^.definition^._class) then
  1884. tokeninfo^[_SELF].keyword:=m_all;
  1885. compile_proc_body(names^,((pdflags and pd_global)<>0),assigned(oldprocinfo._class));
  1886. { reset _FAIL as normal }
  1887. if (aktprocsym^.definition^.proctypeoption=potype_constructor) then
  1888. tokeninfo^[_FAIL].keyword:=m_none;
  1889. if assigned(aktprocsym^.definition^._class) and (lexlevel=main_program_level) then
  1890. tokeninfo^[_SELF].keyword:=m_none;
  1891. consume(_SEMICOLON);
  1892. end;
  1893. { close }
  1894. dispose(names,done);
  1895. codegen_doneprocedure;
  1896. { Restore old state }
  1897. constsymtable:=oldconstsymtable;
  1898. { from now on all refernece to mangledname means
  1899. that the function is already used }
  1900. aktprocsym^.definition^.count:=true;
  1901. { restore the interface order to maintain CRC values PM }
  1902. if assigned(prevdef) and assigned(aktprocsym^.definition^.nextoverloaded) then
  1903. begin
  1904. stdef:=aktprocsym^.definition;
  1905. aktprocsym^.definition:=stdef^.nextoverloaded;
  1906. stdef^.nextoverloaded:=prevdef^.nextoverloaded;
  1907. prevdef^.nextoverloaded:=stdef;
  1908. end;
  1909. aktprocsym:=oldprocsym;
  1910. procprefix:=oldprefix;
  1911. procinfo:=oldprocinfo;
  1912. opsym:=nil;
  1913. end;
  1914. end.
  1915. {
  1916. $Log$
  1917. Revision 1.18 1999-09-02 18:47:45 daniel
  1918. * Could not compile with TP, some arrays moved to heap
  1919. * NOAG386BIN default for TP
  1920. * AG386* files were not compatible with TP, fixed.
  1921. Revision 1.17 1999/08/30 10:17:57 peter
  1922. * fixed crash in psub
  1923. * ansistringcompare fixed
  1924. * support for #$0b8
  1925. Revision 1.16 1999/08/27 10:41:46 pierre
  1926. * pi_is_global was missing for global methods
  1927. + code to restore overloaded list order
  1928. (necessary to get same CRC values after interface and after
  1929. implementation)
  1930. Revision 1.15 1999/08/19 13:02:11 pierre
  1931. + label faillabel added for _FAIL support
  1932. Revision 1.14 1999/08/10 16:24:44 pierre
  1933. * linking to C code with cdecl;external; was broken
  1934. Revision 1.13 1999/08/10 12:37:44 pierre
  1935. + procsym field of tprocdef set
  1936. Revision 1.12 1999/08/05 16:53:06 peter
  1937. * V_Fatal=1, all other V_ are also increased
  1938. * Check for local procedure when assigning procvar
  1939. * fixed comment parsing because directives
  1940. * oldtp mode directives better supported
  1941. * added some messages to errore.msg
  1942. Revision 1.11 1999/08/04 13:03:01 jonas
  1943. * all tokens now start with an underscore
  1944. * PowerPC compiles!!
  1945. Revision 1.10 1999/08/04 00:23:20 florian
  1946. * renamed i386asm and i386base to cpuasm and cpubase
  1947. Revision 1.9 1999/08/03 22:03:05 peter
  1948. * moved bitmask constants to sets
  1949. * some other type/const renamings
  1950. Revision 1.8 1999/08/03 17:09:42 florian
  1951. * the alpha compiler can be compiled now
  1952. Revision 1.7 1999/08/02 21:29:01 florian
  1953. * the main branch psub.pas is now used for
  1954. newcg compiler
  1955. Revision 1.6 1999/07/27 23:42:16 peter
  1956. * indirect type referencing is now allowed
  1957. Revision 1.5 1999/07/26 09:42:15 florian
  1958. * bugs 494-496 fixed
  1959. Revision 1.4 1999/07/11 20:10:24 peter
  1960. * merged
  1961. Revision 1.3 1999/07/02 13:02:24 peter
  1962. * merged
  1963. Revision 1.2 1999/06/17 13:19:56 pierre
  1964. * merged from 0_99_12 branch
  1965. Revision 1.1.2.4 1999/07/11 20:07:39 peter
  1966. * message crash fixed
  1967. * no error if self is used with non-string message
  1968. Revision 1.1.2.3 1999/07/11 20:04:05 pierre
  1969. * fix for problem with external without parameters in Delphi mode
  1970. Revision 1.1.2.2 1999/07/02 12:59:52 peter
  1971. * fixed parsing of message directive
  1972. Revision 1.1.2.1 1999/06/17 12:44:47 pierre
  1973. * solve problems related to assignment overloading
  1974. * support Delphi syntax for operator
  1975. * avoid problems if local procedure in operator
  1976. Revision 1.1 1999/06/11 13:21:37 peter
  1977. * reinserted
  1978. Revision 1.153 1999/06/02 22:44:14 pierre
  1979. * previous wrong log corrected
  1980. Revision 1.152 1999/06/02 22:25:46 pierre
  1981. * changed $ifdef FPC @ into $ifndef TP
  1982. Revision 1.151 1999/06/01 22:47:06 pierre
  1983. * problem with static keyword solved
  1984. Revision 1.150 1999/06/01 14:45:53 peter
  1985. * @procvar is now always needed for FPC
  1986. Revision 1.149 1999/05/31 16:42:31 peter
  1987. * interfacedef flag for procdef if it's defined in the interface, to
  1988. make a difference with 'forward;' directive forwarddef. Fixes 253
  1989. Revision 1.148 1999/05/27 19:44:52 peter
  1990. * removed oldasm
  1991. * plabel -> pasmlabel
  1992. * -a switches to source writing automaticly
  1993. * assembler readers OOPed
  1994. * asmsymbol automaticly external
  1995. * jumptables and other label fixes for asm readers
  1996. Revision 1.147 1999/05/24 08:55:27 florian
  1997. * non working safecall directiv implemented, I don't know if we
  1998. need it
  1999. Revision 1.146 1999/05/23 18:42:11 florian
  2000. * better error recovering in typed constants
  2001. * some problems with arrays of const fixed, some problems
  2002. due my previous
  2003. - the location type of array constructor is now LOC_MEM
  2004. - the pushing of high fixed
  2005. - parameter copying fixed
  2006. - zero temp. allocation removed
  2007. * small problem in the assembler writers fixed:
  2008. ref to nil wasn't written correctly
  2009. Revision 1.145 1999/05/21 13:55:09 peter
  2010. * NEWLAB for label as symbol
  2011. Revision 1.144 1999/05/18 14:15:55 peter
  2012. * containsself fixes
  2013. * checktypes()
  2014. Revision 1.143 1999/05/17 21:57:13 florian
  2015. * new temporary ansistring handling
  2016. Revision 1.142 1999/05/17 15:06:38 pierre
  2017. * fixes for object type check
  2018. Revision 1.141 1999/05/13 21:59:39 peter
  2019. * removed oldppu code
  2020. * warning if objpas is loaded from uses
  2021. * first things for new deref writing
  2022. Revision 1.140 1999/05/12 22:36:12 florian
  2023. * override isn't allowed in objects!
  2024. Revision 1.139 1999/05/10 09:01:41 peter
  2025. * small message fixes
  2026. Revision 1.138 1999/05/09 12:46:24 peter
  2027. + hint where a duplicate sym is already defined
  2028. Revision 1.137 1999/05/08 19:48:45 peter
  2029. * better error message if declaration doesn't match forward
  2030. Revision 1.136 1999/05/08 15:26:15 peter
  2031. * print also manglednames when changed
  2032. Revision 1.135 1999/05/06 10:12:10 peter
  2033. * fixed operator result offset which destroyed parast^.datasize
  2034. Revision 1.134 1999/05/01 13:24:36 peter
  2035. * merged nasm compiler
  2036. * old asm moved to oldasm/
  2037. Revision 1.133 1999/04/28 11:12:03 peter
  2038. * fixed crash with self pointer
  2039. Revision 1.132 1999/04/28 06:02:09 florian
  2040. * changes of Bruessel:
  2041. + message handler can now take an explicit self
  2042. * typinfo fixed: sometimes the type names weren't written
  2043. * the type checking for pointer comparisations and subtraction
  2044. and are now more strict (was also buggy)
  2045. * small bug fix to link.pas to support compiling on another
  2046. drive
  2047. * probable bug in popt386 fixed: call/jmp => push/jmp
  2048. transformation didn't count correctly the jmp references
  2049. + threadvar support
  2050. * warning if ln/sqrt gets an invalid constant argument
  2051. Revision 1.131 1999/04/26 13:31:44 peter
  2052. * release storenumber,double_checksum
  2053. Revision 1.130 1999/04/21 09:43:49 peter
  2054. * storenumber works
  2055. * fixed some typos in double_checksum
  2056. + incompatible types type1 and type2 message (with storenumber)
  2057. Revision 1.129 1999/04/20 14:39:07 daniel
  2058. *** empty log message ***
  2059. Revision 1.125 1999/04/14 09:14:55 peter
  2060. * first things to store the symbol/def number in the ppu
  2061. Revision 1.124 1999/04/07 15:31:13 pierre
  2062. * all formaldefs are now a sinlge definition
  2063. cformaldef (this was necessary for double_checksum)
  2064. + small part of double_checksum code
  2065. Revision 1.123 1999/04/06 11:21:58 peter
  2066. * more use of ttoken
  2067. Revision 1.122 1999/03/31 13:55:16 peter
  2068. * assembler inlining working for ag386bin
  2069. Revision 1.121 1999/03/26 00:05:39 peter
  2070. * released valintern
  2071. + deffile is now removed when compiling is finished
  2072. * ^( compiles now correct
  2073. + static directive
  2074. * shrd fixed
  2075. Revision 1.120 1999/03/24 23:17:18 peter
  2076. * fixed bugs 212,222,225,227,229,231,233
  2077. Revision 1.119 1999/03/05 09:46:18 pierre
  2078. * public problem for methods
  2079. Revision 1.118 1999/03/05 01:14:24 pierre
  2080. * bug0198 : call conventions for methods
  2081. not yet implemented is the control of same calling convention
  2082. for virtual and child's virtual
  2083. * msgstr and msgint only created if message was found
  2084. who implemented this by the way ?
  2085. it leaks lots of plabels !!!! (check with heaptrc !)
  2086. Revision 1.117 1999/03/04 13:55:47 pierre
  2087. * some m68k fixes (still not compilable !)
  2088. * new(tobj) does not give warning if tobj has no VMT !
  2089. Revision 1.116 1999/03/01 15:40:52 peter
  2090. * external name <str> didn't concatexternal()
  2091. Revision 1.115 1999/03/01 13:31:58 pierre
  2092. * external used before implemented problem fixed
  2093. Revision 1.114 1999/02/24 00:59:15 peter
  2094. * small updates for ag386bin
  2095. Revision 1.113 1999/02/23 18:29:21 pierre
  2096. * win32 compilation error fix
  2097. + some work for local browser (not cl=omplete yet)
  2098. Revision 1.112 1999/02/22 13:07:03 pierre
  2099. + -b and -bl options work !
  2100. + cs_local_browser ($L+) is disabled if cs_browser ($Y+)
  2101. is not enabled when quitting global section
  2102. * local vars and procedures are not yet stored into PPU
  2103. Revision 1.111 1999/02/22 02:15:33 peter
  2104. * updates for ag386bin
  2105. Revision 1.110 1999/02/16 12:23:19 pierre
  2106. * nested forward procedure bug solved
  2107. Revision 1.109 1999/02/15 10:07:06 pierre
  2108. * memory leaks due to last commit solved
  2109. Revision 1.108 1999/02/11 09:46:27 pierre
  2110. * fix for normal method calls inside static methods :
  2111. WARNING there were both parser and codegen errors !!
  2112. added static_call boolean to calln tree
  2113. Revision 1.107 1999/02/10 11:27:39 pierre
  2114. * overloaded function locals problem bug0213
  2115. Revision 1.106 1999/02/08 11:29:05 pierre
  2116. * fix for bug0214
  2117. several problems where combined
  2118. search_class_member did not set srsymtable
  2119. => in do_member_read the call node got a wrong symtable
  2120. in cg386cal the vmt was pushed twice without chacking if it exists
  2121. now %esi is set to zero and pushed if not vmt
  2122. (not very efficient but should work !)
  2123. Revision 1.105 1999/02/05 12:51:20 florian
  2124. + openstring id is now supported
  2125. Revision 1.104 1999/02/03 09:26:44 pierre
  2126. + better reference for args of procs
  2127. Revision 1.103 1999/02/02 11:04:37 florian
  2128. * class destructors fixed, class instances weren't disposed correctly
  2129. Revision 1.102 1999/01/21 22:10:46 peter
  2130. * fixed array of const
  2131. * generic platform independent high() support
  2132. Revision 1.101 1999/01/20 14:18:38 pierre
  2133. * bugs related to mangledname solved
  2134. - linux external without name
  2135. -external procs already used
  2136. (added count and is_used boolean fiels in tprocvar)
  2137. Revision 1.100 1999/01/20 10:20:19 peter
  2138. * don't make localvar copies for assembler procedures
  2139. Revision 1.99 1999/01/19 15:59:40 pierre
  2140. * fix for function a;
  2141. Revision 1.98 1999/01/19 12:16:07 peter
  2142. * NOPASS2 now calls firstpass
  2143. Revision 1.97 1999/01/14 11:35:30 daniel
  2144. * Fixed manglednames
  2145. Revision 1.96 1998/12/30 13:41:10 peter
  2146. * released valuepara
  2147. Revision 1.95 1998/12/30 10:36:39 michael
  2148. + Delphi also allows external in interface section
  2149. Revision 1.94 1998/12/29 18:48:26 jonas
  2150. + optimize pascal code surrounding assembler blocks
  2151. Revision 1.93 1998/12/28 15:44:49 peter
  2152. + NOPASS2 define
  2153. Revision 1.92 1998/12/11 00:03:39 peter
  2154. + globtype,tokens,version unit splitted from globals
  2155. Revision 1.91 1998/11/27 14:50:42 peter
  2156. + open strings, $P switch support
  2157. Revision 1.90 1998/11/18 17:45:27 peter
  2158. * fixes for VALUEPARA
  2159. Revision 1.89 1998/11/18 15:44:15 peter
  2160. * VALUEPARA for tp7 compatible value parameters
  2161. Revision 1.88 1998/11/16 15:40:30 pierre
  2162. * mangling name and -So bugs solved
  2163. Revision 1.87 1998/11/16 11:29:02 pierre
  2164. * stackcheck removed for i386_win32
  2165. * exportlist does not crash at least !!
  2166. (was need for tests dir !)z
  2167. Revision 1.86 1998/11/16 10:13:54 peter
  2168. * label defines are checked at the end of the proc
  2169. Revision 1.85 1998/11/13 15:40:26 pierre
  2170. + added -Se in Makefile cvstest target
  2171. + lexlevel cleanup
  2172. normal_function_level main_program_level and unit_init_level defined
  2173. * tins_cache grown to A_EMMS (gave range check error in asm readers)
  2174. (test added in code !)
  2175. * -Un option was wrong
  2176. * _FAIL and _SELF only keyword inside
  2177. constructors and methods respectively
  2178. Revision 1.84 1998/11/10 10:09:13 peter
  2179. * va_list -> array of const
  2180. Revision 1.83 1998/11/09 11:44:34 peter
  2181. + va_list for printf support
  2182. Revision 1.82 1998/10/29 11:35:53 florian
  2183. * some dll support for win32
  2184. * fixed assembler writing for PalmOS
  2185. Revision 1.81 1998/10/28 18:26:16 pierre
  2186. * removed some erros after other errors (introduced by useexcept)
  2187. * stabs works again correctly (for how long !)
  2188. Revision 1.80 1998/10/27 13:45:37 pierre
  2189. * classes get a vmt allways
  2190. * better error info (tried to remove
  2191. several error strings introduced by the tpexcept handling)
  2192. Revision 1.79 1998/10/23 00:09:43 peter
  2193. * fixed message for forward declaration
  2194. Revision 1.78 1998/10/20 13:10:37 peter
  2195. * fixed crash when aktprocsym<>procsym
  2196. Revision 1.77 1998/10/20 08:06:55 pierre
  2197. * several memory corruptions due to double freemem solved
  2198. => never use p^.loc.location:=p^.left^.loc.location;
  2199. + finally I added now by default
  2200. that ra386dir translates global and unit symbols
  2201. + added a first field in tsymtable and
  2202. a nextsym field in tsym
  2203. (this allows to obtain ordered type info for
  2204. records and objects in gdb !)
  2205. Revision 1.76 1998/10/19 08:55:02 pierre
  2206. * wrong stabs info corrected once again !!
  2207. + variable vmt offset with vmt field only if required
  2208. implemented now !!!
  2209. Revision 1.75 1998/10/16 08:51:48 peter
  2210. + target_os.stackalignment
  2211. + stack can be aligned at 2 or 4 byte boundaries
  2212. Revision 1.74 1998/10/14 20:39:21 florian
  2213. * syscall for PalmOs fixed
  2214. Revision 1.73 1998/10/12 12:20:56 pierre
  2215. + added tai_const_symbol_offset
  2216. for r : pointer = @var.field;
  2217. * better message for different arg names on implementation
  2218. of function
  2219. Revision 1.72 1998/10/08 23:29:03 peter
  2220. * -vu shows unit info, -vt shows tried/used files
  2221. Revision 1.71 1998/10/08 17:17:28 pierre
  2222. * current_module old scanner tagged as invalid if unit is recompiled
  2223. + added ppheap for better info on tracegetmem of heaptrc
  2224. (adds line column and file index)
  2225. * several memory leaks removed ith help of heaptrc !!
  2226. Revision 1.70 1998/10/08 13:48:49 peter
  2227. * fixed memory leaks for do nothing source
  2228. * fixed unit interdependency
  2229. Revision 1.69 1998/10/05 21:33:27 peter
  2230. * fixed 161,165,166,167,168
  2231. Revision 1.68 1998/09/29 11:31:30 florian
  2232. * better error recovering when the object type of procedure tobject.method
  2233. isn't found
  2234. Revision 1.67 1998/09/26 17:45:39 peter
  2235. + idtoken and only one token table
  2236. Revision 1.66 1998/09/24 23:49:16 peter
  2237. + aktmodeswitches
  2238. Revision 1.65 1998/09/24 11:08:14 florian
  2239. * small problem in _proc_header with array of const fixed:
  2240. getsymonlyin doesn't set srsym to nil
  2241. Revision 1.64 1998/09/23 15:39:12 pierre
  2242. * browser bugfixes
  2243. was adding a reference when looking for the symbol
  2244. if -bSYM_NAME was used
  2245. Revision 1.63 1998/09/22 17:13:50 pierre
  2246. + browsing updated and developed
  2247. records and objects fields are also stored
  2248. Revision 1.62 1998/09/22 15:37:21 peter
  2249. + array of const start
  2250. Revision 1.61 1998/09/21 08:45:20 pierre
  2251. + added vmt_offset in tobjectdef.write for fututre use
  2252. (first steps to have objects without vmt if no virtual !!)
  2253. + added fpu_used field for tabstractprocdef :
  2254. sets this level to 2 if the functions return with value in FPU
  2255. (is then set to correct value at parsing of implementation)
  2256. THIS MIGHT refuse some code with FPU expression too complex
  2257. that were accepted before and even in some cases
  2258. that don't overflow in fact
  2259. ( like if f : float; is a forward that finally in implementation
  2260. only uses one fpu register !!)
  2261. Nevertheless I think that it will improve security on
  2262. FPU operations !!
  2263. * most other changes only for UseBrowser code
  2264. (added symtable references for record and objects)
  2265. local switch for refs to args and local of each function
  2266. (static symtable still missing)
  2267. UseBrowser still not stable and probably broken by
  2268. the definition hash array !!
  2269. Revision 1.60 1998/09/17 09:42:42 peter
  2270. + pass_2 for cg386
  2271. * Message() -> CGMessage() for pass_1/pass_2
  2272. Revision 1.59 1998/09/15 14:05:25 jonas
  2273. * fixed optimizer incompatibilities with freelabel code in psub
  2274. Revision 1.58 1998/09/14 21:27:41 peter
  2275. - freelabel calls, becuase they are instable with -O2
  2276. Revision 1.57 1998/09/14 10:38:27 peter
  2277. * pd_alias now uses get_stringconst
  2278. Revision 1.56 1998/09/14 10:29:38 daniel
  2279. * Fixed memory leaks.
  2280. Revision 1.55 1998/09/09 11:50:56 pierre
  2281. * forward def are not put in record or objects
  2282. + added check for forwards also in record and objects
  2283. * dummy parasymtable for unit initialization removed from
  2284. symtable stack
  2285. Revision 1.54 1998/09/04 08:42:05 peter
  2286. * updated some error messages
  2287. Revision 1.53 1998/09/01 17:39:51 peter
  2288. + internal constant functions
  2289. Revision 1.52 1998/09/01 09:07:12 peter
  2290. * m68k fixes, splitted cg68k like cgi386
  2291. Revision 1.51 1998/09/01 07:54:21 pierre
  2292. * UseBrowser a little updated (might still be buggy !!)
  2293. * bug in psub.pas in function specifier removed
  2294. * stdcall allowed in interface and in implementation
  2295. (FPC will not yet complain if it is missing in either part
  2296. because stdcall is only a dummy !!)
  2297. Revision 1.50 1998/08/31 12:26:31 peter
  2298. * m68k and palmos updates from surebugfixes
  2299. Revision 1.49 1998/08/25 12:42:43 pierre
  2300. * CDECL changed to CVAR for variables
  2301. specifications are read in structures also
  2302. + started adding GPC compatibility mode ( option -Sp)
  2303. * names changed to lowercase
  2304. Revision 1.48 1998/08/21 08:43:30 pierre
  2305. * pocdecl and poclearstack are now different
  2306. external must but written as last specification
  2307. Revision 1.47 1998/08/20 09:26:44 pierre
  2308. + funcret setting in underproc testing
  2309. compile with _dTEST_FUNCRET
  2310. Revision 1.46 1998/08/19 18:04:55 peter
  2311. * fixed current_module^.in_implementation flag
  2312. Revision 1.45 1998/08/13 10:58:38 peter
  2313. * fixed function reading for -So which was not correct after my previous
  2314. fix for bug 147
  2315. Revision 1.44 1998/08/10 14:50:18 peter
  2316. + localswitches, moduleswitches, globalswitches splitting
  2317. Revision 1.43 1998/08/10 09:58:33 peter
  2318. * Fixed function b; in -So mode
  2319. Revision 1.42 1998/07/30 16:07:11 florian
  2320. * try ... expect <statement> end; works now
  2321. Revision 1.41 1998/07/23 19:31:19 jonas
  2322. * split the optimizer
  2323. Revision 1.40 1998/07/21 11:16:24 florian
  2324. * bug0147 fixed
  2325. Revision 1.39 1998/07/14 21:46:54 peter
  2326. * updated messages file
  2327. Revision 1.38 1998/07/14 14:46:57 peter
  2328. * released NEWINPUT
  2329. Revision 1.37 1998/07/10 13:12:53 peter
  2330. * carls patch
  2331. Revision 1.36 1998/07/10 13:06:53 michael
  2332. + Carls patch. Checked make cycle.
  2333. Revision 1.35 1998/07/10 00:00:01 peter
  2334. * fixed ttypesym bug finally
  2335. * fileinfo in the symtable and better using for unused vars
  2336. Revision 1.34 1998/07/07 11:20:05 peter
  2337. + NEWINPUT for a better inputfile and scanner object
  2338. Revision 1.33 1998/06/15 15:38:08 pierre
  2339. * small bug in systems.pas corrected
  2340. + operators in different units better hanlded
  2341. Revision 1.32 1998/06/13 00:10:13 peter
  2342. * working browser and newppu
  2343. * some small fixes against crashes which occured in bp7 (but not in
  2344. fpc?!)
  2345. Revision 1.31 1998/06/10 17:04:05 michael
  2346. + Fix for reading untyped const parameters
  2347. Revision 1.30 1998/06/09 16:01:50 pierre
  2348. + added procedure directive parsing for procvars
  2349. (accepted are popstack cdecl and pascal)
  2350. + added C vars with the following syntax
  2351. var C calias 'true_c_name';(can be followed by external)
  2352. reason is that you must add the Cprefix
  2353. which is target dependent
  2354. Revision 1.29 1998/06/08 22:59:51 peter
  2355. * smartlinking works for win32
  2356. * some defines to exclude some compiler parts
  2357. Revision 1.28 1998/06/08 13:13:45 pierre
  2358. + temporary variables now in temp_gen.pas unit
  2359. because it is processor independent
  2360. * mppc68k.bat modified to undefine i386 and support_mmx
  2361. (which are defaults for i386)
  2362. Revision 1.27 1998/06/05 17:47:30 peter
  2363. * some better uses clauses
  2364. Revision 1.26 1998/06/05 14:37:36 pierre
  2365. * fixes for inline for operators
  2366. * inline procedure more correctly restricted
  2367. Revision 1.25 1998/06/04 23:51:54 peter
  2368. * m68k compiles
  2369. + .def file creation moved to gendef.pas so it could also be used
  2370. for win32
  2371. Revision 1.24 1998/06/04 09:55:44 pierre
  2372. * demangled name of procsym reworked to become independant of the mangling scheme
  2373. Revision 1.23 1998/05/28 17:26:51 peter
  2374. * fixed -R switch, it didn't work after my previous akt/init patch
  2375. * fixed bugs 110,130,136
  2376. Revision 1.22 1998/05/28 14:40:27 peter
  2377. * fixes for newppu, remake3 works now with it
  2378. Revision 1.21 1998/05/23 01:21:25 peter
  2379. + aktasmmode, aktoptprocessor, aktoutputformat
  2380. + smartlink per module $SMARTLINK-/+ (like MMX) and moved to aktswitches
  2381. + $LIBNAME to set the library name where the unit will be put in
  2382. * splitted cgi386 a bit (codeseg to large for bp7)
  2383. * nasm, tasm works again. nasm moved to ag386nsm.pas
  2384. Revision 1.20 1998/05/21 19:33:34 peter
  2385. + better procedure directive handling and only one table
  2386. Revision 1.19 1998/05/20 09:42:36 pierre
  2387. + UseTokenInfo now default
  2388. * unit in interface uses and implementation uses gives error now
  2389. * only one error for unknown symbol (uses lastsymknown boolean)
  2390. the problem came from the label code !
  2391. + first inlined procedures and function work
  2392. (warning there might be allowed cases were the result is still wrong !!)
  2393. * UseBrower updated gives a global list of all position of all used symbols
  2394. with switch -gb
  2395. Revision 1.18 1998/05/11 13:07:56 peter
  2396. + $ifdef NEWPPU for the new ppuformat
  2397. + $define GDB not longer required
  2398. * removed all warnings and stripped some log comments
  2399. * no findfirst/findnext anymore to remove smartlink *.o files
  2400. Revision 1.17 1998/05/06 18:36:54 peter
  2401. * tai_section extended with code,data,bss sections and enumerated type
  2402. * ident 'compiled by FPC' moved to pmodules
  2403. * small fix for smartlink
  2404. Revision 1.16 1998/05/06 08:38:47 pierre
  2405. * better position info with UseTokenInfo
  2406. UseTokenInfo greatly simplified
  2407. + added check for changed tree after first time firstpass
  2408. (if we could remove all the cases were it happen
  2409. we could skip all firstpass if firstpasscount > 1)
  2410. Only with ExtDebug
  2411. Revision 1.15 1998/05/04 17:54:28 peter
  2412. + smartlinking works (only case jumptable left todo)
  2413. * redesign of systems.pas to support assemblers and linkers
  2414. + Unitname is now also in the PPU-file, increased version to 14
  2415. Revision 1.14 1998/05/01 09:01:24 florian
  2416. + correct semantics of private and protected
  2417. * small fix in variable scope:
  2418. a id can be used in a parameter list of a method, even it is used in
  2419. an anchestor class as field id
  2420. Revision 1.13 1998/04/30 15:59:42 pierre
  2421. * GDB works again better :
  2422. correct type info in one pass
  2423. + UseTokenInfo for better source position
  2424. * fixed one remaining bug in scanner for line counts
  2425. * several little fixes
  2426. Revision 1.12 1998/04/29 10:34:00 pierre
  2427. + added some code for ansistring (not complete nor working yet)
  2428. * corrected operator overloading
  2429. * corrected nasm output
  2430. + started inline procedures
  2431. + added starstarn : use ** for exponentiation (^ gave problems)
  2432. + started UseTokenInfo cond to get accurate positions
  2433. Revision 1.11 1998/04/27 23:10:28 peter
  2434. + new scanner
  2435. * $makelib -> if smartlink
  2436. * small filename fixes pmodule.setfilename
  2437. * moved import from files.pas -> import.pas
  2438. Revision 1.10 1998/04/21 10:16:48 peter
  2439. * patches from strasbourg
  2440. * objects is not used anymore in the fpc compiled version
  2441. Revision 1.9 1998/04/13 22:20:36 florian
  2442. + stricter checking for duplicate id, solves also bug0097
  2443. Revision 1.8 1998/04/13 21:15:42 florian
  2444. * error handling of pass_1 and cgi386 fixed
  2445. * the following bugs fixed: 0117, 0118, 0119 and 0129, 0122 was already
  2446. fixed, verified
  2447. Revision 1.7 1998/04/13 08:42:52 florian
  2448. * call by reference and call by value open arrays fixed
  2449. Revision 1.6 1998/04/10 15:39:48 florian
  2450. * more fixes to get classes.pas compiled
  2451. Revision 1.5 1998/04/10 14:41:43 peter
  2452. * removed some Hints
  2453. * small speed optimization for AsmLn
  2454. Revision 1.4 1998/04/08 16:58:05 pierre
  2455. * several bugfixes
  2456. ADD ADC and AND are also sign extended
  2457. nasm output OK (program still crashes at end
  2458. and creates wrong assembler files !!)
  2459. procsym types sym in tdef removed !!
  2460. }